Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
educg-net-25737-2462428
HHFDB-770
Commits
835ea5bc
Commit
835ea5bc
authored
10 months ago
by
lilp
Browse files
Options
Download
Patches
Plain Diff
fix: 优化内存泄漏
parent
76f3affa
performance-test/memError-lock
performance-test/ix-test
performance-test/memError
performance-test/memError-1g
performance-test/memError-1s
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/transaction/transaction_manager.cpp
+27
-3
src/transaction/transaction_manager.cpp
with
27 additions
and
3 deletions
+27
-3
src/transaction/transaction_manager.cpp
+
27
−
3
View file @
835ea5bc
...
...
@@ -50,12 +50,26 @@ void TransactionManager::commit(Transaction *txn, LogManager *log_manager) {
// 1. 写入提交事务日志并设置事务的prev_lsn
auto
*
commit_log_
=
new
BACLogRecord
(
txn
->
get_transaction_id
(),
txn
->
get_prev_lsn
(),
LogType
::
commit
);
txn
->
set_prev_lsn
(
log_manager
->
flush_log_to_disk
(
commit_log_
));
delete
commit_log_
;
// 2. 释放事务持有的所有锁
for
(
auto
const
&
lock
:
*
(
txn
->
get_lock_set
()))
{
lock_manager_
->
unlock
(
txn
,
lock
);
}
auto
table_write_set
=
txn
->
get_write_set
();
// 释放table_write_rcd的rcd占有的内存
for
(
const
auto
&
table_write_rcd
:
*
table_write_set
)
{
delete
table_write_rcd
;
}
table_write_set
->
clear
();
auto
index_write_set
=
txn
->
get_index_write_set
();
// 释放index_write_rcd的rcd占有的内存
for
(
const
auto
&
index_write_rcd
:
*
index_write_set
)
{
delete
index_write_rcd
;
}
index_write_set
->
clear
();
delete
commit_log_
;
// 3. 更新事务状态为已提交
txn
->
set_state
(
TransactionState
::
COMMITTED
);
...
...
@@ -94,6 +108,11 @@ void TransactionManager::abort(Transaction *txn, LogManager *log_manager) {
// 避免内存泄露
delete
write_rcd
;
}
// 释放table_write_rcd的rcd占有的内存
for
(
const
auto
&
table_write_rcd
:
*
table_write_set
)
{
delete
table_write_rcd
;
}
table_write_set
->
clear
();
auto
index_write_set
=
txn
->
get_index_write_set
();
...
...
@@ -107,7 +126,7 @@ void TransactionManager::abort(Transaction *txn, LogManager *log_manager) {
case
WType
::
INSERT_TUPLE
:
{
for
(
auto
&
index
:
indexes
)
{
auto
ih
=
sm_manager_
->
ihs_
.
at
(
sm_manager_
->
get_ix_manager
()
->
get_index_name
(
table_name
,
index
.
cols
)).
get
();
sm_manager_
->
get_ix_manager
()
->
get_index_name
(
table_name
,
index
.
cols
)).
get
();
ih
->
delete_entry
(
index_write_rcd
->
GetKey
(),
txn
);
}
break
;
...
...
@@ -115,7 +134,7 @@ void TransactionManager::abort(Transaction *txn, LogManager *log_manager) {
case
WType
::
DELETE_TUPLE
:
{
for
(
auto
&
index
:
indexes
)
{
auto
ih
=
sm_manager_
->
ihs_
.
at
(
sm_manager_
->
get_ix_manager
()
->
get_index_name
(
table_name
,
index
.
cols
)).
get
();
sm_manager_
->
get_ix_manager
()
->
get_index_name
(
table_name
,
index
.
cols
)).
get
();
ih
->
insert_entry
(
index_write_rcd
->
GetKey
(),
index_write_rcd
->
GetRid
(),
txn
);
}
break
;
...
...
@@ -130,6 +149,11 @@ void TransactionManager::abort(Transaction *txn, LogManager *log_manager) {
// 避免内存泄露
delete
index_write_rcd
;
}
// 释放index_write_rcd的rcd占有的内存
for
(
const
auto
&
index_write_rcd
:
*
index_write_set
)
{
delete
index_write_rcd
;
}
index_write_set
->
clear
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets