[MDEV-27812] Allow innodb_log_file_size to change without server restart Created: 2022-02-11 Updated: 2024-02-02 Resolved: 2022-03-02 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Fix Version/s: | 10.9.0 |
| Type: | Task | Priority: | Critical |
| Reporter: | Marko Mäkelä | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Preview_10.9, usability | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
Currently, if the parameters of the redo log change, InnoDB in the MariaDB Community Server will rebuild the redo log at server startup. MariaDB Enterprise Server 10.5 and 10.6 allow dynamic tuning of the redo log parameters, rebuilding the redo log in a crash-safe manner without restarting the server.
Before Log resizing is tied to checkpoints. We can start writing a second redo log ib_logfile101 with the requested new size, starting from something close to the last written log sequence number. On log checkpoint completion, we can switch files, provided that the checkpoint LSN was not earlier than the start LSN of the resized log file. When resizing to a small log file during a heavy write workload, multiple checkpoints may be necessary. While technically it would be possible to rebuild the log for changing innodb_encrypt_log, this task does not implement it, because it would require a non-trivial transformation between the log record streams that are being written to the current log file (ib_logfile0) and the future log file (ib_logfile101 that will replace ib_logfile0). Rebuilding the log file will obviously cause disruption to mariadb-backup --backup, because the old log file will stop receiving writes once the server has switched to another log file. This could be addressed in MDEV-14992 by letting the server provide a log record stream directly. |
| Comments |
| Comment by Marko Mäkelä [ 2022-02-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
wlad, please review. Edit: The MoveFileEx() failure on Windows that prevented log resizing from succeeding was fixed by closing both file handles before the rename operation, and reopening ib_logfile0 afterwards (on Windows only). We already did something similar when resizing the log on server startup. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I initiated a non-PMEM test with 30×10000 runs of the test (which does normal restart and kill and restart across log resizing).
I thought that it was 30×1000, which would have taken a few hours. I aborted it here. To run it on /dev/shm while having libpmem installed, I applied the following patch:
The PMEM based log resizing was much easier to get working. I will force-push the branch to address some review comments. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Log resizing will as a byproduct perform ‘log scrubbing’, which was an old MariaDB feature that was removed | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Vaintroub [ 2022-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Looks ok to me | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
wlad, thank you. Since your review, I had to refine the code a bit in the SET GLOBAL innodb_log_file_size update callback. The mtr based test that I conducted a few days ago was only ensuring that the resized log is restart-safe and crash-safe. mleich produced rr replay traces and some core dumps for several race conditions that occurred when multiple threads were attempting to change the size concurrently, while some of the connections were being killed. I will wait for his final verdict before pushing this. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-02-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
There were some problems with the log file wrap-around. I developed the following test to exercise that code. The idea of this test is to generate varying-length mini-transaction log from 2 DML connections while another connection is alternating the log file size between the two smallest allowed values, to maximize the probability of log buffer wrap-around events.
This test would be killed by mtr after 15 minutes (900 seconds) both with and without PMEM. I was only able to repeat the problems when running multiple instances of the test concurrently, and without using rr record:
After some fixes, the implementation survived the my tests for 2×15 minutes with PMEM, and another 2×15 minutes without PMEM. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-03-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Starting, aborting and finishing the log resizing has to be protected by all of flush_lock, write_lock, and exclusive log_sys.latch to avoid race conditions with concurrent log_write_up_to(). Sufficient locking was in place in log_sys.resize_abort() since quite a time. The race conditions in starting and finishing the resizing were fixed today. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Matthias Leich [ 2022-03-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-07-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
For the record, MySQL 8.0.30 includes a conceptually similar change to the MariaDB one (fixup 1, 2): |