Skip to content

Commit

Permalink
MDEV-27199: Remove FIL_PAGE_FILE_FLUSH_LSN
Browse files Browse the repository at this point in the history
The only purpose of the field FIL_PAGE_FILE_FLUSH_LSN was to
store the log sequence number for a new ib_logfile0 when the
InnoDB redo log was missing at startup.

Because FIL_PAGE_FILE_FLUSH_LSN no longer serves any purpose,
we will stop updating it. The writes of that field were inherently
risky, because they were not covered by neither the redo log nor
the doublewrite buffer.

Warning: After MDEV-14425 and before this change, users could perform
a clean shutdown of the server, replace the ib_logfile0 with a
0-length file, and expect a valid log file to be created on the
next server startup. After this change, if the FIL_PAGE_FILE_FLUSH_LSN
had ever been updated in the past, the server would still create a
log file in such a scenario, but possibly with an incorrect (too small)
LSN. Users should not manipulate log files directly!
  • Loading branch information
dr-m committed Jan 21, 2022
1 parent 88d9fbb commit b07920b
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 73 deletions.
42 changes: 0 additions & 42 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1382,48 +1382,6 @@ void fil_set_max_space_id_if_bigger(uint32_t max_id)
mysql_mutex_unlock(&fil_system.mutex);
}

/** Write the flushed LSN to the page header of the first page in the
system tablespace.
@param[in] lsn flushed LSN
@return DB_SUCCESS or error number */
dberr_t
fil_write_flushed_lsn(
lsn_t lsn)
{
byte* buf;
ut_ad(!srv_read_only_mode);

if (!fil_system.sys_space->acquire()) {
return DB_ERROR;
}

buf = static_cast<byte*>(aligned_malloc(srv_page_size, srv_page_size));

auto fio = fil_system.sys_space->io(IORequestRead, 0, srv_page_size,
buf);

if (fio.err == DB_SUCCESS) {
mach_write_to_8(buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
lsn);

uint32_t fsp_flags = mach_read_from_4(
buf + FSP_HEADER_OFFSET + FSP_SPACE_FLAGS);

if (fil_space_t::full_crc32(fsp_flags)) {
buf_flush_assign_full_crc32_checksum(buf);
}

fio = fil_system.sys_space->io(IORequestWrite,
0, srv_page_size, buf);
fil_flush_file_spaces();
} else {
fil_system.sys_space->release();
}

aligned_free(buf);
return fio.err;
}

/** Acquire a tablespace reference.
@param id tablespace identifier
@return tablespace
Expand Down
3 changes: 0 additions & 3 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18229,9 +18229,6 @@ checkpoint_now_set(THD*, st_mysql_sys_var*, void*, const void *save)
(lsn= log_sys.get_lsn(std::memory_order_acquire)))
log_make_checkpoint();

if (dberr_t err= fil_write_flushed_lsn(lsn))
sql_print_warning("innodb_checkpoint_now_set failed: %d", err);

mysql_mutex_lock(&LOCK_global_system_variables);
}

Expand Down
9 changes: 0 additions & 9 deletions storage/innobase/include/fil0fil.h
Original file line number Diff line number Diff line change
Expand Up @@ -1593,15 +1593,6 @@ Sets the max tablespace id counter if the given number is bigger than the
previous value. */
void fil_set_max_space_id_if_bigger(uint32_t max_id);

/** Write the flushed LSN to the page header of the first page in the
system tablespace.
@param[in] lsn flushed LSN
@return DB_SUCCESS or error number */
dberr_t
fil_write_flushed_lsn(
lsn_t lsn)
MY_ATTRIBUTE((warn_unused_result));

MY_ATTRIBUTE((warn_unused_result))
/** Delete a tablespace and associated .ibd file.
@param id tablespace identifier
Expand Down
9 changes: 0 additions & 9 deletions storage/innobase/log/log0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,15 +1032,6 @@ ATTRIBUTE_COLD void logs_empty_and_mark_files_at_shutdown()

srv_shutdown_lsn = lsn;

if (!srv_read_only_mode) {
dberr_t err = fil_write_flushed_lsn(lsn);

if (err != DB_SUCCESS) {
ib::error() << "Writing flushed lsn " << lsn
<< " failed; error=" << err;
}
}

/* Make some checks that the server really is quiet */
ut_ad(!srv_any_background_activity());

Expand Down
12 changes: 2 additions & 10 deletions storage/innobase/srv/srv0start.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,7 @@ dberr_t srv_start(bool create_new_db)

buf_flush_sync();

const lsn_t lsn{log_sys.get_lsn()};
err = fil_write_flushed_lsn(lsn);
if (err == DB_SUCCESS) {
err = create_log_file_rename(lsn, logfile0);
}
err = create_log_file_rename(log_sys.get_lsn(), logfile0);

if (err != DB_SUCCESS) {
return(srv_init_abort(err));
Expand Down Expand Up @@ -1381,15 +1377,11 @@ dberr_t srv_start(bool create_new_db)
/* Close the redo log file, so that we can replace it */
log_sys.close_file();

err = fil_write_flushed_lsn(lsn);

DBUG_EXECUTE_IF("innodb_log_abort_5",
return(srv_init_abort(DB_ERROR)););
DBUG_PRINT("ib_log", ("After innodb_log_abort_5"));

if (err == DB_SUCCESS) {
err = create_log_file(false, lsn, logfile0);
}
err = create_log_file(false, lsn, logfile0);

if (err == DB_SUCCESS) {
err = create_log_file_rename(lsn, logfile0);
Expand Down

0 comments on commit b07920b

Please sign in to comment.