Skip to content

Commit

Permalink
MDEV-19584 Allocate recv_sys statically
Browse files Browse the repository at this point in the history
There is only one InnoDB crash recovery subsystem.
Allocating recv_sys statically removes one level of pointer indirection
and makes code more readable, and removes the awkward initialization of
recv_sys->dblwr.

recv_sys_t::create(): Replaces recv_sys_init().

recv_sys_t::debug_free(): Replaces recv_sys_debug_free().

recv_sys_t::close(): Replaces recv_sys_close().

recv_sys_t::add(): Replaces recv_add_to_hash_table().

recv_sys_t::empty(): Replaces recv_sys_empty_hash().
  • Loading branch information
dr-m committed May 24, 2019
1 parent 592fe95 commit 5d2619b
Show file tree
Hide file tree
Showing 15 changed files with 419 additions and 411 deletions.
20 changes: 10 additions & 10 deletions extra/mariabackup/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last)
log_block,
scanned_lsn + data_len);

recv_sys->scanned_lsn = scanned_lsn + data_len;
recv_sys.scanned_lsn = scanned_lsn + data_len;

if (data_len == OS_FILE_LOG_BLOCK_SIZE) {
/* We got a full log block. */
Expand Down Expand Up @@ -2719,13 +2719,13 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last)
static bool xtrabackup_copy_logfile(bool last = false)
{
ut_a(dst_log_file != NULL);
ut_ad(recv_sys != NULL);
ut_ad(recv_sys.is_initialised());

lsn_t start_lsn;
lsn_t end_lsn;

recv_sys->parse_start_lsn = log_copy_scanned_lsn;
recv_sys->scanned_lsn = log_copy_scanned_lsn;
recv_sys.parse_start_lsn = log_copy_scanned_lsn;
recv_sys.scanned_lsn = log_copy_scanned_lsn;

start_lsn = ut_uint64_align_down(log_copy_scanned_lsn,
OS_FILE_LOG_BLOCK_SIZE);
Expand All @@ -2748,15 +2748,15 @@ static bool xtrabackup_copy_logfile(bool last = false)
if (lsn == start_lsn) {
start_lsn = 0;
} else {
mutex_enter(&recv_sys->mutex);
mutex_enter(&recv_sys.mutex);
start_lsn = xtrabackup_copy_log(start_lsn, lsn, last);
mutex_exit(&recv_sys->mutex);
mutex_exit(&recv_sys.mutex);
}

log_mutex_exit();

if (!start_lsn) {
msg(recv_sys->found_corrupt_log
msg(recv_sys.found_corrupt_log
? "xtrabackup_copy_logfile() failed: corrupt log."
: "xtrabackup_copy_logfile() failed.");
return true;
Expand Down Expand Up @@ -4071,7 +4071,7 @@ static bool xtrabackup_backup_func()

ut_crc32_init();
crc_init();
recv_sys_init();
recv_sys.create();

#ifdef WITH_INNODB_DISALLOW_WRITES
srv_allow_writes_event = os_event_create(0);
Expand Down Expand Up @@ -4231,7 +4231,7 @@ static bool xtrabackup_backup_func()

/* copy log file by current position */
log_copy_scanned_lsn = checkpoint_lsn_start;
recv_sys->recovered_lsn = log_copy_scanned_lsn;
recv_sys.recovered_lsn = log_copy_scanned_lsn;
log_optimized_ddl_op = backup_optimized_ddl_op;

if (xtrabackup_copy_logfile())
Expand Down Expand Up @@ -5471,7 +5471,7 @@ static bool xtrabackup_prepare_func(char** argv)
sync_check_init();
ut_d(sync_check_enable());
ut_crc32_init();
recv_sys_init();
recv_sys.create();
log_sys.create();
recv_recovery_on = true;

Expand Down
12 changes: 6 additions & 6 deletions storage/innobase/buf/buf0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,10 @@ buf_madvise_do_dump()
srv_log_buffer_size * 2,
MADV_DODUMP);
}
/* mirrors recv_sys_init() */
if (recv_sys->buf)
/* mirrors recv_sys_t::create() */
if (recv_sys.buf)
{
ret+= madvise(recv_sys->buf, recv_sys->len, MADV_DODUMP);
ret+= madvise(recv_sys.buf, recv_sys.len, MADV_DODUMP);
}

buf_pool_mutex_enter_all();
Expand Down Expand Up @@ -1770,7 +1770,7 @@ buf_chunk_not_freed(
== block->page.newest_modification);
ut_ad(block->page.oldest_modification == 0
|| block->page.oldest_modification
== recv_sys->recovered_lsn
== recv_sys.recovered_lsn
|| srv_force_recovery
== SRV_FORCE_NO_LOG_REDO);
ut_ad(block->page.buf_fix_count == 0);
Expand Down Expand Up @@ -5571,9 +5571,9 @@ buf_page_create(
mtr);
}

mutex_exit(&recv_sys->mutex);
mutex_exit(&recv_sys.mutex);
block = buf_page_get_with_no_latch(page_id, zip_size, mtr);
mutex_enter(&recv_sys->mutex);
mutex_enter(&recv_sys.mutex);
return block;
}

Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ buf_dblwr_init_or_load_pages(
byte* doublewrite;
byte* unaligned_read_buf;
ibool reset_space_ids = FALSE;
recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
recv_dblwr_t& recv_dblwr = recv_sys.dblwr;

/* We do the file i/o past the buffer pool */

Expand Down Expand Up @@ -523,7 +523,7 @@ buf_dblwr_process()
ulint page_no_dblwr = 0;
byte* read_buf;
byte* unaligned_read_buf;
recv_dblwr_t& recv_dblwr = recv_sys->dblwr;
recv_dblwr_t& recv_dblwr = recv_sys.dblwr;

if (!buf_dblwr) {
return;
Expand Down
10 changes: 5 additions & 5 deletions storage/innobase/buf/buf0flu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3034,21 +3034,21 @@ DECLARE_THREAD(buf_flush_page_cleaner_coordinator)(void*)
" See the man page of setpriority().";
}
/* Signal that setpriority() has been attempted. */
os_event_set(recv_sys->flush_end);
os_event_set(recv_sys.flush_end);
#endif /* UNIV_LINUX */

do {
/* treat flushing requests during recovery. */
ulint n_flushed_lru = 0;
ulint n_flushed_list = 0;

os_event_wait(recv_sys->flush_start);
os_event_wait(recv_sys.flush_start);

if (!recv_writer_thread_active) {
break;
}

switch (recv_sys->flush_type) {
switch (recv_sys.flush_type) {
case BUF_FLUSH_LRU:
/* Flush pages from end of LRU if required */
pc_request(0, LSN_MAX);
Expand All @@ -3069,8 +3069,8 @@ DECLARE_THREAD(buf_flush_page_cleaner_coordinator)(void*)
ut_ad(0);
}

os_event_reset(recv_sys->flush_start);
os_event_set(recv_sys->flush_end);
os_event_reset(recv_sys.flush_start);
os_event_set(recv_sys.flush_end);
} while (recv_writer_thread_active);

os_event_wait(buf_flush_event);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4413,7 +4413,7 @@ fil_aio_wait(

ut_ad(type.is_read());
if (recv_recovery_is_on() && !srv_force_recovery) {
recv_sys->found_corrupt_fs = true;
recv_sys.found_corrupt_fs = true;
}

if (fil_space_t* space = fil_space_acquire_for_io(space_id)) {
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fsp/fsp0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ Datafile::restore_from_doublewrite()
}

/* Find if double write buffer contains page_no of given space id. */
const byte* page = recv_sys->dblwr.find_page(m_space_id, 0);
const byte* page = recv_sys.dblwr.find_page(m_space_id, 0);
const page_id_t page_id(m_space_id, 0);

if (page == NULL) {
Expand Down
54 changes: 33 additions & 21 deletions storage/innobase/include/log0recv.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ Initiates the rollback of active transactions. */
void
recv_recovery_rollback_active(void);
/*===============================*/
/** Clean up after recv_sys_init() */
void
recv_sys_close();
/** Initialize the redo log recovery subsystem. */
void
recv_sys_init();
/********************************************************//**
Frees the recovery system. */
void
recv_sys_debug_free(void);
/*=====================*/

/********************************************************//**
Reset the state of the recovery system variables. */
Expand All @@ -105,7 +94,7 @@ enum store_t {


/** Adds data from a new log block to the parsing buffer of recv_sys if
recv_sys->parse_start_lsn is non-zero.
recv_sys.parse_start_lsn is non-zero.
@param[in] log_block log block to add
@param[in] scanned_lsn lsn of how far we were able to find
data in this log block
Expand Down Expand Up @@ -201,14 +190,11 @@ struct recv_sys_t{
buf_flush_t flush_type;/*!< type of the flush request.
BUF_FLUSH_LRU: flush end of LRU, keeping free blocks.
BUF_FLUSH_LIST: flush all of blocks. */
ibool apply_log_recs;
/*!< this is TRUE when log rec application to
pages is allowed; this flag tells the
i/o-handler if it should do log record
application */
ibool apply_batch_on;
/*!< this is TRUE when a log rec application
batch is running */
/** whether recv_recover_page(), invoked from buf_page_io_complete(),
should apply log records*/
bool apply_log_recs;
/** whether recv_apply_hashed_log_recs() is running */
bool apply_batch_on;
byte* buf; /*!< buffer for parsing log records */
size_t buf_size; /*!< size of buf */
ulint len; /*!< amount of data in buf */
Expand Down Expand Up @@ -262,6 +248,32 @@ struct recv_sys_t{
/** Lastly added LSN to the hash table of log records. */
lsn_t last_stored_lsn;

/** Initialize the redo log recovery subsystem. */
void create();

/** Free most recovery data structures. */
void debug_free();

/** Clean up after create() */
void close();

bool is_initialised() const { return buf_size != 0; }

/** Store a redo log record for applying.
@param type record type
@param space tablespace identifier
@param page_no page number
@param body record body
@param rec_end end of record
@param lsn start LSN of the mini-transaction
@param end_lsn end LSN of the mini-transaction */
inline void add(mlog_id_t type, ulint space, ulint page_no,
byte* body, byte* rec_end, lsn_t lsn,
lsn_t end_lsn);

/** Empty a fully processed set of stored redo log records. */
inline void empty();

/** Determine whether redo log recovery progress should be reported.
@param[in] time the current time
@return whether progress should be reported
Expand All @@ -278,7 +290,7 @@ struct recv_sys_t{
};

/** The recovery system */
extern recv_sys_t* recv_sys;
extern recv_sys_t recv_sys;

/** TRUE when applying redo log records during crash recovery; FALSE
otherwise. Note that this is FALSE while a background thread is
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/log/log0log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1609,11 +1609,11 @@ logs_empty_and_mark_files_at_shutdown(void)
} else {
ut_ad(!srv_dict_stats_thread_active);
}
if (recv_sys && recv_sys->flush_start) {
if (recv_sys.flush_start) {
/* This is in case recv_writer_thread was never
started, or buf_flush_page_cleaner_coordinator
failed to notice its termination. */
os_event_set(recv_sys->flush_start);
os_event_set(recv_sys.flush_start);
}
}
#define COUNT_INTERVAL 600U
Expand Down Expand Up @@ -1951,7 +1951,7 @@ void log_t::close()
if (!srv_read_only_mode && srv_scrub_log)
os_event_destroy(log_scrub_event);

recv_sys_close();
recv_sys.close();
}

/******************************************************//**
Expand Down
Loading

0 comments on commit 5d2619b

Please sign in to comment.