-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async rollback prepared transactions during binlog crash recovery #3030
base: 10.6
Are you sure you want to change the base?
Conversation
ca55ea8
to
8ffe07f
Compare
mysql-test/suite/binlog/t/binlog_recover_async_rollback_trx.test
Outdated
Show resolved
Hide resolved
mysql-test/suite/binlog/t/binlog_recover_async_rollback_trx.test
Outdated
Show resolved
Hide resolved
mysql-test/suite/binlog/t/binlog_recover_async_rollback_trx.test
Outdated
Show resolved
Hide resolved
@SongLibing are you ok to finish this? |
Sorry for the delay. I have been very busy these days. I can probably finish the update in next week. |
f7758d1
to
6c1a4e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is a step forward, but I think that it could be simplified further.
771d19e
to
5105774
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is definitely moving to the right direction, but some details still need to be sorted out. Did you file an MDEV ticket for this?
5105774
to
038784a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the patch 5105774, I only looked at the non-InnoDB parts in detail.
I think the patch looks solid, it does all the things already I would expect it to do. I had one suggestion to clarify the comments on the new handlerton calls introduced.
This part of the commit message I did not understand:
"With this patch, background rollback thread will not exit unless ddl log
recovery is finished. It guarantees that all recovered prepared transactions
which reverted to active state will be rolled back by the background thread."
Maybe you can elaborate/explain how this patch relates to the ddl log recovery?
It is not related to ddl log in the latest patch, the comment message has been updated. |
038784a
to
8e2f081
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
606b059
to
07e6743
Compare
07e6743
to
0783240
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good work LiBing!
I have two points to raise.
133465d
to
c590cc0
Compare
Looks good. Thanks LiBing! |
Sorry, in the last comment I meant a mere approval. |
crash recovery Summary ======= When doing server recovery, the active transactions will be rolled back by InnoDB background rollback thread automatically. The prepared transactions will be committed or rolled back accordingly by binlog recovery. Binlog recovery is done in main thread before the server can provide service to users. If there is a big transaction to rollback, the server will not available for a long time. This patch provides a way to rollback the prepared transactions asynchronously. Thus the rollback will not block server startup. Design ====== - Handler::recover_rollback_by_xid() This patch provides a new handler interface to rollback transactions in recover phase. InnoDB just set the transaction's state to active. Then the transaction will be rolled back by the background rollback thread. - Handler::signal_tc_log_recover_done() This function is called after tc log is opened(typically binlog opened) has done. When this function is called, all transactions will be rolled back have been reverted to ACTIVE state. Thus it starts rollback thread to rollback the transactions. - Background rollback thread With this patch, background rollback thread is defered to run until binlog recovery is finished. It is started by innobase_tc_log_recovery_done().
c590cc0
to
d31208d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, the InnoDB part of this looks mostly OK now. I think that we should try to clean up the shutdown logic a bit more, to avoid any potential race condition.
I did not check the changes outside InnoDB, and I did not compile the code or run the test case.
@@ -418,6 +420,7 @@ class rw_trx_hash_t | |||
(trx_state_eq(trx, TRX_STATE_ACTIVE) && | |||
(!srv_was_started || | |||
srv_read_only_mode || | |||
!trx_rollback_is_active || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we fail to invoke rollback_all_recovered_task.wait()
in logs_empty_and_mark_files_at_shutdown()
or srv_shutdown_threads()
. It seems that this added condition might introduce a resource leak if the rollback is still running during shutdown. I would suggest to replace the following code in logs_empty_and_mark_files_at_shutdown()
:
/* We need these threads to stop early in shutdown. */
const char* thread_name = srv_fast_shutdown != 2
&& trx_rollback_is_active
? "rollback of recovered transactions" : nullptr;
with something like this (note: I hope that it will not hang if there was no prior call to srv_thread_pool->submit_task(&rollback_all_recovered_task)
in case startup was aborted due to some error):
if (srv_fast_shutdown != 2) {
rollback_all_recovered_task.wait();
ut_ad(!trx_rollback_is_active);
}
This logic will have to be tested with various values of innodb_force_recovery
and innodb_fast_shutdown
.
I would also suggest to minimize the references to trx_rollback_is_active
in other code. Ideally we would only have a few ut_ad(!trx_rollback_is_active)
where appropriate.
OPTION(WITH_ASYNC_BINLOG_ROLLBACK | ||
"Rollback prepared transactions asynchronously at binlog recovery" OFF) | ||
IF(WITH_ASYNC_BINLOG_ROLLBACK) | ||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DASYNC_BINLOG_ROLLBACK") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the change to CMAKE_C_FLAGS
? All affected files seem to be C++.
MDEV-33853 Async rollback prepared transactions during binlog
crash recovery
Summary
When doing server recovery, the active transactions will be rolled
back by InnoDB background rollback thread automatically. The
prepared transactions will be committed or rolled back accordingly
by binlog recovery. Binlog recovery is done in main thread before
the server can provide service to users. If there is a big
transaction to rollback, the server will not available for a long
time.
This patch provides a way to rollback the prepared transactions
asynchronously. Thus the rollback will not block server startup.
Design
Handler::recover_rollback_by_xid()
This patch provides a new handler interface to rollback transactions
in recover phase. InnoDB just set the transaction's state to active.
Then the transaction will be rolled back by the background rollback
thread.
Handler::signal_tc_log_recover_done()
This function is called after tc log is opened(typically binlog opened)
has done. When this function is called, all transactions will be rolled
back have been reverted to ACTIVE state. Thus it starts rollback thread
to rollback the transactions.
Background rollback thread
With this patch, background rollback thread is defered to run until binlog
recovery is finished. It is started by innobase_tc_log_recovery_done().
Description
TODO: fill description here
How can this PR be tested?
TODO: modify the automated test suite to verify that the PR causes MariaDB to behave as intended.
Consult the documentation on "Writing good test cases".
If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.
Basing the PR against the correct MariaDB version
PR quality check