[MDEV-33112] innodb_undo_log_truncate=ON is blocking page writes Created: 2023-12-22  Updated: 2024-01-10  Resolved: 2024-01-10

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3, 11.4
Fix Version/s: 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3, 11.3.2, 11.4.1

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 1
Labels: performance

Issue Links:
Blocks
is blocked by MDEV-25491 Race condition between DROP TABLE and... Closed
Relates
relates to MDEV-33213 History list is not shrunk unless the... Closed
relates to MDEV-13564 TRUNCATE TABLE and undo tablespace tr... Closed
relates to MDEV-14795 InnoDB system tablespace cannot be sh... Closed
relates to MDEV-15528 Avoid writing freed InnoDB pages Closed
relates to MDEV-33009 Server hangs for a long time with inn... Closed

 Description   

The implementation of innodb_undo_log_truncate=ON in trx_purge_truncate_history() is interfering with log checkpoint and page write performance.

Before MDEV-13564, we used the MySQL 5.7 implementation, which would force a full flush of the entire buffer pool and a sharp log checkpoint. In MDEV-13564 we changed it so that only the pages of the being-truncated undo tablespace would be removed from the buffer pool, but no log checkpoint would be needed.

There is a less intrusive, lazy approach: We can actually let the 'garbage' undo log pages remain in the buffer pool, just like we do on DROP TABLE or DROP INDEX or when freeing pages in any operation: Simply, if the newest modification to a page (FIL_PAGE_LSN) is older than the LSN of the latest tablespace rebuild, we will discard the page, just like in MDEV-15528 we do for pages whose underlying file page has been freed. With this approach, there is no need for trx_purge_truncate_history() to traverse the buffer pool.

For the similar case of shrinking the InnoDB system tablespace (MDEV-14795), there would not be a complete tablespace rebuild (like there is with innodb_undo_log_truncate=ON), so we must only discard pages that are beyond the end of the current tablespace size; their FIL_PAGE_LSN must be older than the latest LSN of shrinking the FSP_SIZE. I think that we can do that by relaxing the logic around invoking fil_invalid_page_access_msg() in fil_space_t::io().



 Comments   
Comment by Marko Mäkelä [ 2023-12-22 ]

I realized that if we do not acquire exclusive latches on all affected pages before the function fil_truncate_prepare() is invoked, then we would reintroduce the corruption bug MDEV-32757. This is because buf_flush_page_cleaner() would start skipping any writes to the undo tablespace and could advance the log checkpoint before the undo tablespace truncation has finished.

In MDEV-25491 (MariaDB Server 10.6) the function fil_truncate_prepare() was removed, which simplifies things. I think that we should target 10.6 and not 10.5.

Comment by Matthias Leich [ 2024-01-04 ]

origin/10.6-MDEV-33112 599d7a378a36f9dc335018c65f8643e80061aab2 2023-12-23T18:44:53+02:00
performed well in RQG testing. No new problems.

Comment by Vladislav Lesin [ 2024-01-09 ]

Looks good to me.

Comment by Marko Mäkelä [ 2024-01-10 ]

axel had to work around MDEV-33213 while running the performance tests for this. I will work on that next.

Generated at Thu Feb 08 10:36:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.