-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
MDEV-26138: Fix switch case statement in trx_flush_log_if_needed_low() #1873
MDEV-26138: Fix switch case statement in trx_flush_log_if_needed_low() #1873
Conversation
|
@sidhujagdeep thank you for your contribution. BSD-new license is great so please just ignore the CLA-bot. It looks good to me but I'll let our innodb experts be the final approval. |
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.
Please do the suggested changes
storage/innobase/trx/trx0trx.cc
Outdated
@@ -1560,6 +1560,9 @@ trx_flush_log_if_needed_low( | |||
|
|||
switch (srv_flush_log_at_trx_commit) { | |||
case 3: | |||
/* Write the log and optionally flush it to disk */ |
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.
Can you change like below:
- case 3:
case 2:
/* Write the log but do not flush it to disk */
flush = false;
/* fall through */
case 1:
+ case 3:
/* Write the log and optionally flush it to disk */
log_write_up_to(lsn, flush);
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.
Thanks for the feedback. I have update code as suggested.
@sidhujagdeep Thank you for noticing this! I see that @janlindstrom in 2e814d4 overlooked the change that had been made by @knielsen in 288eeb3 (MDEV-232). I think that @andrelkin and @sujatha-s need to participate in deciding what should be done and in which major versions of MariaDB. Given that What is the actual benefit of supporting the setting 3, or the harm of not supporting it? |
After some internal discussion, it does look like that it is easiest to apply this fix. In the 10.6 branch, I tested the following: diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc
index 66ca04bbf04..74e5be5a231 100644
--- a/storage/innobase/trx/trx0trx.cc
+++ b/storage/innobase/trx/trx0trx.cc
@@ -1135,8 +1135,8 @@ static void trx_flush_log_if_needed_low(lsn_t lsn, trx_state_t trx_state)
if (log_sys.get_flushed_lsn() > lsn)
return;
- bool flush= srv_file_flush_method != SRV_NOSYNC &&
- srv_flush_log_at_trx_commit == 1;
+ const bool flush= srv_file_flush_method != SRV_NOSYNC &&
+ (srv_flush_log_at_trx_commit & 1);
if (trx_state == TRX_STATE_PREPARED)
{ I hope that we will be able to streamline this logic in a separate fix. I am not convinced that MDEV-232 and MDEV-532 are working correctly; the |
b322c33
to
f81976d
Compare
Thank you @dr-m for looking through the change and history of this bug. I have updated the code as per feedback provided by @Thirunarayanan |
In commit 2e814d4 on MariaDB 10.2 the switch case statement in trx_flush_log_if_needed_low() regressed. Since 10.2 this code was refactored to have switches in descending order, so value of 3 for innodb_flush_log_at_trx_commit is behaving the same as value of 2, that is no FSYNC is being enforced during COMMIT phase. The switch should however not be empty and cases 2 and 3 should not have the identical contents. As per documentation, setting innodb_flush_log_at_trx_commit to 3 should do FSYNC to disk if innodb_flush_log_at_trx_commit is set to 3. This fixes the regression so that the switch statement again does what users expect the setting should do. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
76cecb0
to
d0f8ea9
Compare
42b9daa is the 10.6 version of this. |
Description
In commit 2e814d4 on MariaDB 10.2
the switch case statement in trx_flush_log_if_needed_low() regressed.
Since 10.2 this code was refactored to have switches in descending
order, so value of 3 for innodb_flush_log_at_trx_commit is behaving
the same as value of 2, that is no FSYNC is being enforced during
COMMIT phase. The switch should however not be empty and cases 2 and 3
should not have the identical contents.
As per documentation, setting innodb_flush_log_at_trx_commit to 3
should do FSYNC to disk if innodb_flush_log_at_trx_commit is set to 3.
This fixes the regression so that the switch statement again does
what users expect the setting should do.
How can this PR be tested?
Start the server with values
2
and3
forinnodb_flush_log_at_trx_commit
and expect different behaviour.Basing the PR against the correct MariaDB version
Regression was introduced in MariaDB 10.2.2. This PR targets the 10.2 branch.
Backward compatibility
This bugfix restores previous behaviour.
Copyright
All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.