Commit acd23da4 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-30479 optimization: Invoke recv_sys_t::trim() earlier

recv_sys_t::parse(): Discard old page-level redo log when parsing
a TRIM_PAGES record.

recv_sys_t::apply(): trim() was invoked in parse() already.

recv_sys_t::truncated_undo_spaces[]: Only store the size, no LSN.
parent 461402a5
......@@ -266,15 +266,9 @@ struct recv_sys_t
@param lsn log sequence number of the shrink operation */
inline void trim(const page_id_t page_id, lsn_t lsn);
/** Undo tablespaces for which truncate has been logged
(indexed by page_id_t::space() - srv_undo_space_id_start) */
struct trunc
{
/** log sequence number of FILE_CREATE, or 0 if none */
lsn_t lsn;
/** truncated size of the tablespace, or 0 if not truncated */
unsigned pages;
} truncated_undo_spaces[127];
/** Truncated undo tablespace size for which truncate has been logged
(indexed by page_id_t::space() - srv_undo_space_id_start), or 0 */
unsigned truncated_undo_spaces[127];
public:
/** The contents of the doublewrite buffer */
......
......@@ -1949,8 +1949,10 @@ bool recv_sys_t::parse(lsn_t checkpoint_lsn, store_t *store, bool apply)
goto record_corrupted;
static_assert(UT_ARR_SIZE(truncated_undo_spaces) ==
TRX_SYS_MAX_UNDO_SPACES, "compatibility");
truncated_undo_spaces[space_id - srv_undo_space_id_start]=
{ recovered_lsn, page_no };
/* The entire undo tablespace will be reinitialized by
innodb_undo_log_truncate=ON. Discard old log for all pages. */
trim({space_id, 0}, recovered_lsn);
truncated_undo_spaces[space_id - srv_undo_space_id_start]= page_no;
if (undo_space_trunc)
undo_space_trunc(space_id);
#endif
......@@ -2675,17 +2677,15 @@ void recv_sys_t::apply(bool last_batch)
for (auto id= srv_undo_tablespaces_open; id--;)
{
const trunc& t= truncated_undo_spaces[id];
if (t.lsn)
if (unsigned pages= truncated_undo_spaces[id])
{
trim(page_id_t(id + srv_undo_space_id_start, 0), t.lsn);
if (fil_space_t *space = fil_space_get(id + srv_undo_space_id_start))
if (fil_space_t *space= fil_space_get(id + srv_undo_space_id_start))
{
ut_ad(UT_LIST_GET_LEN(space->chain) == 1);
fil_node_t *file= UT_LIST_GET_FIRST(space->chain);
ut_ad(file->is_open());
os_file_truncate(file->name, file->handle,
os_offset_t{t.pages} << srv_page_size_shift, true);
os_offset_t{pages} << srv_page_size_shift, true);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment