summaryrefslogtreecommitdiff
path: root/storage/innobase/srv/srv0start.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/innobase/srv/srv0start.cc')
-rw-r--r--storage/innobase/srv/srv0start.cc141
1 files changed, 77 insertions, 64 deletions
diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc
index 988ddf1a759..eb508409e58 100644
--- a/storage/innobase/srv/srv0start.cc
+++ b/storage/innobase/srv/srv0start.cc
@@ -3,7 +3,7 @@
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2008, Google Inc.
Copyright (c) 2009, Percona Inc.
-Copyright (c) 2013, 2017, MariaDB Corporation.
+Copyright (c) 2013, 2018, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -87,7 +87,6 @@ Created 2/16/1996 Heikki Tuuri
#include "dict0load.h"
#include "dict0stats_bg.h"
#include "que0que.h"
-#include "usr0sess.h"
#include "lock0lock.h"
#include "trx0roll.h"
#include "trx0purge.h"
@@ -684,8 +683,8 @@ srv_undo_tablespace_open(
dberr_t err = DB_ERROR;
char undo_name[sizeof "innodb_undo000"];
- ut_snprintf(undo_name, sizeof(undo_name),
- "innodb_undo%03u", static_cast<unsigned>(space_id));
+ snprintf(undo_name, sizeof(undo_name),
+ "innodb_undo%03u", static_cast<unsigned>(space_id));
if (!srv_file_check_mode(name)) {
ib::error() << "UNDO tablespaces must be " <<
@@ -763,7 +762,7 @@ srv_check_undo_redo_logs_exists()
/* Check if any undo tablespaces exist */
for (ulint i = 1; i <= srv_undo_tablespaces; ++i) {
- ut_snprintf(
+ snprintf(
name, sizeof(name),
"%s%cundo%03zu",
srv_undo_dir, OS_PATH_SEPARATOR,
@@ -860,7 +859,7 @@ srv_undo_tablespaces_init(bool create_new_db)
DBUG_EXECUTE_IF("innodb_undo_upgrade",
space_id = i + 3;);
- ut_snprintf(
+ snprintf(
name, sizeof(name),
"%s%cundo%03zu",
srv_undo_dir, OS_PATH_SEPARATOR, space_id);
@@ -922,10 +921,10 @@ srv_undo_tablespaces_init(bool create_new_db)
char name[OS_FILE_MAX_PATH];
- ut_snprintf(name, sizeof(name),
- "%s%cundo%03zu",
- srv_undo_dir, OS_PATH_SEPARATOR,
- undo_tablespace_ids[i]);
+ snprintf(name, sizeof(name),
+ "%s%cundo%03zu",
+ srv_undo_dir, OS_PATH_SEPARATOR,
+ undo_tablespace_ids[i]);
os_file_delete(innodb_data_file_key, name);
@@ -955,7 +954,7 @@ srv_undo_tablespaces_init(bool create_new_db)
for (i = 0; i < n_undo_tablespaces; ++i) {
char name[OS_FILE_MAX_PATH];
- ut_snprintf(
+ snprintf(
name, sizeof(name),
"%s%cundo%03zu",
srv_undo_dir, OS_PATH_SEPARATOR,
@@ -993,7 +992,7 @@ srv_undo_tablespaces_init(bool create_new_db)
for (i = prev_space_id + 1; i < TRX_SYS_N_RSEGS; ++i) {
char name[OS_FILE_MAX_PATH];
- ut_snprintf(
+ snprintf(
name, sizeof(name),
"%s%cundo%03zu", srv_undo_dir, OS_PATH_SEPARATOR, i);
@@ -1058,7 +1057,6 @@ srv_undo_tablespaces_init(bool create_new_db)
/* Step-1: Initialize the tablespace header and rsegs header. */
mtr_t mtr;
- trx_sysf_t* sys_header;
mtr_start(&mtr);
/* Turn off REDO logging. We are in server start mode and fixing
@@ -1067,7 +1065,11 @@ srv_undo_tablespaces_init(bool create_new_db)
as part of the current recovery process. We surely don't need
that as this is fix-up action parallel to REDO logging. */
mtr_set_log_mode(&mtr, MTR_LOG_NO_REDO);
- sys_header = trx_sysf_get(&mtr);
+ buf_block_t* sys_header = trx_sysf_get(&mtr);
+ if (!sys_header) {
+ mtr.commit();
+ return DB_CORRUPTION;
+ }
for (undo::undo_spaces_t::const_iterator it
= undo::Truncate::s_fix_up_spaces.begin();
@@ -1082,13 +1084,10 @@ srv_undo_tablespaces_init(bool create_new_db)
mtr_x_lock(fil_space_get_latch(*it, NULL), &mtr);
for (ulint i = 0; i < TRX_SYS_N_RSEGS; i++) {
-
- ulint space_id = trx_sysf_rseg_get_space(
- sys_header, i, &mtr);
-
- if (space_id == *it) {
+ if (trx_sysf_rseg_get_space(sys_header, i)
+ == *it) {
trx_rseg_header_create(
- *it, ULINT_MAX, i, &mtr);
+ *it, i, sys_header, &mtr);
}
}
@@ -1097,22 +1096,19 @@ srv_undo_tablespaces_init(bool create_new_db)
mtr_commit(&mtr);
/* Step-2: Flush the dirty pages from the buffer pool. */
- trx_t* trx = trx_allocate_for_background();
-
for (undo::undo_spaces_t::const_iterator it
= undo::Truncate::s_fix_up_spaces.begin();
it != undo::Truncate::s_fix_up_spaces.end();
++it) {
-
- buf_LRU_flush_or_remove_pages(TRX_SYS_SPACE, trx);
-
- buf_LRU_flush_or_remove_pages(*it, trx);
+ FlushObserver dummy(TRX_SYS_SPACE, NULL, NULL);
+ buf_LRU_flush_or_remove_pages(TRX_SYS_SPACE, &dummy);
+ FlushObserver dummy2(*it, NULL, NULL);
+ buf_LRU_flush_or_remove_pages(*it, &dummy2);
/* Remove the truncate redo log file. */
undo::Truncate undo_trunc;
undo_trunc.done_logging(*it);
}
- trx_free_for_background(trx);
}
return(DB_SUCCESS);
@@ -1266,7 +1262,7 @@ srv_shutdown_all_bg_threads()
if (srv_start_state_is_set(SRV_START_STATE_LOCK_SYS)) {
/* a. Let the lock timeout thread exit */
- os_event_set(lock_sys->timeout_event);
+ os_event_set(lock_sys.timeout_event);
}
if (!srv_read_only_mode) {
@@ -1374,6 +1370,7 @@ srv_init_abort_low(
" with error " << ut_strerr(err);
}
+ srv_shutdown_bg_undo_sources();
srv_shutdown_all_bg_threads();
return(err);
}
@@ -1408,13 +1405,16 @@ srv_prepare_to_delete_redo_log_files(
{
ib::info info;
- if (srv_log_file_size == 0) {
+ if (srv_log_file_size == 0
+ || (log_sys->log.format
+ & ~LOG_HEADER_FORMAT_ENCRYPTED)
+ != LOG_HEADER_FORMAT_CURRENT) {
info << "Upgrading redo log: ";
} else if (n_files != srv_n_log_files
|| srv_log_file_size
!= srv_log_file_size_requested) {
if (srv_encrypt_log
- == log_sys->is_encrypted()) {
+ == (my_bool)log_sys->is_encrypted()) {
info << (srv_encrypt_log
? "Resizing encrypted"
: "Resizing");
@@ -1438,6 +1438,7 @@ srv_prepare_to_delete_redo_log_files(
<< " bytes; LSN=" << flushed_lsn;
}
+ srv_start_lsn = flushed_lsn;
/* Flush the old log files. */
log_mutex_exit();
@@ -1648,7 +1649,7 @@ innobase_start_or_create_for_mysql()
+ 1 /* dict_stats_thread */
+ 1 /* fts_optimize_thread */
+ 1 /* recv_writer_thread */
- + 1 /* trx_rollback_or_clean_all_recovered */
+ + 1 /* trx_rollback_all_recovered */
+ 128 /* added as margin, for use of
InnoDB Memcached etc. */
+ max_connections
@@ -1852,7 +1853,7 @@ innobase_start_or_create_for_mysql()
log_sys_init();
recv_sys_init();
- lock_sys_create(srv_lock_table_size);
+ lock_sys.create(srv_lock_table_size);
/* Create i/o-handler threads: */
@@ -2140,7 +2141,7 @@ files_checked:
dict_stats_thread_init();
}
- trx_sys_create();
+ trx_sys.create();
if (create_new_db) {
ut_a(!srv_read_only_mode);
@@ -2170,7 +2171,7 @@ files_checked:
All the remaining rollback segments will be created later,
after the double write buffer has been created. */
trx_sys_create_sys_pages();
- trx_sys_init_at_db_start();
+ trx_lists_init_at_db_start();
err = dict_create();
@@ -2217,17 +2218,28 @@ files_checked:
recv_sys->dblwr.pages.clear();
- if (err == DB_SUCCESS) {
- /* Initialize the change buffer. */
- err = dict_boot();
- }
-
if (err != DB_SUCCESS) {
return(srv_init_abort(err));
}
- /* This must precede recv_apply_hashed_log_recs(true). */
- trx_sys_init_at_db_start();
+ switch (srv_operation) {
+ case SRV_OPERATION_NORMAL:
+ case SRV_OPERATION_RESTORE_EXPORT:
+ /* Initialize the change buffer. */
+ err = dict_boot();
+ if (err != DB_SUCCESS) {
+ return(srv_init_abort(err));
+ }
+ /* fall through */
+ case SRV_OPERATION_RESTORE:
+ /* This must precede
+ recv_apply_hashed_log_recs(true). */
+ trx_lists_init_at_db_start();
+ break;
+ case SRV_OPERATION_RESTORE_DELTA:
+ case SRV_OPERATION_BACKUP:
+ ut_ad(!"wrong mariabackup mode");
+ }
if (srv_force_recovery < SRV_FORCE_NO_LOG_REDO) {
/* Apply the hashed log records to the
@@ -2307,7 +2319,7 @@ files_checked:
}
/* recv_recovery_from_checkpoint_finish needs trx lists which
- are initialized in trx_sys_init_at_db_start(). */
+ are initialized in trx_lists_init_at_db_start(). */
recv_recovery_from_checkpoint_finish();
@@ -2331,7 +2343,7 @@ files_checked:
== SRV_OPERATION_RESTORE;
/* Delete subsequent log files. */
delete_log_files(logfilename, dirnamelen,
- srv_n_log_files_found, trunc);
+ (uint)srv_n_log_files_found, trunc);
if (trunc) {
/* Truncate the first log file. */
strcpy(logfilename + dirnamelen,
@@ -2353,7 +2365,11 @@ files_checked:
/* Leave the redo log alone. */
} else if (srv_log_file_size_requested == srv_log_file_size
&& srv_n_log_files_found == srv_n_log_files
- && log_sys->is_encrypted() == srv_encrypt_log) {
+ && log_sys->log.format
+ == (srv_encrypt_log
+ ? LOG_HEADER_FORMAT_CURRENT
+ | LOG_HEADER_FORMAT_ENCRYPTED
+ : LOG_HEADER_FORMAT_CURRENT)) {
/* No need to upgrade or resize the redo log. */
} else {
/* Prepare to delete the old redo log files */
@@ -2451,7 +2467,7 @@ files_checked:
The data dictionary latch should guarantee that there is at
most one data dictionary transaction active at a time. */
if (srv_force_recovery < SRV_FORCE_NO_TRX_UNDO) {
- trx_rollback_or_clean_recovered(FALSE);
+ trx_rollback_recovered(false);
}
/* Fix-up truncate of tables in the system tablespace
@@ -2549,7 +2565,7 @@ files_checked:
lock_wait_timeout_thread,
NULL, thread_ids + 2 + SRV_MAX_N_IO_THREADS);
thread_started[2 + SRV_MAX_N_IO_THREADS] = true;
- lock_sys->timeout_thread_active = true;
+ lock_sys.timeout_thread_active = true;
/* Create the thread which warns of long semaphore waits */
srv_error_monitor_active = true;
@@ -2567,7 +2583,8 @@ files_checked:
srv_start_state |= SRV_START_STATE_LOCK_SYS
| SRV_START_STATE_MONITOR;
- ut_a(trx_purge_state() == PURGE_STATE_INIT);
+ ut_ad(srv_force_recovery >= SRV_FORCE_NO_UNDO_LOG_SCAN
+ || trx_purge_state() == PURGE_STATE_INIT);
if (srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
srv_undo_sources = true;
@@ -2621,8 +2638,6 @@ files_checked:
srv_start_state_set(SRV_START_STATE_MASTER);
}
- srv_is_being_started = false;
-
if (!srv_read_only_mode && srv_operation == SRV_OPERATION_NORMAL
&& srv_force_recovery < SRV_FORCE_NO_BACKGROUND) {
@@ -2647,9 +2662,11 @@ files_checked:
srv_start_state_set(SRV_START_STATE_PURGE);
} else {
- purge_sys->state = PURGE_STATE_DISABLED;
+ purge_sys.state = PURGE_STATE_DISABLED;
}
+ srv_is_being_started = false;
+
if (!srv_read_only_mode) {
/* wake main loop of page cleaner up */
os_event_set(buf_flush_event);
@@ -2657,8 +2674,9 @@ files_checked:
if (srv_print_verbose_log) {
ib::info() << INNODB_VERSION_STR
- << " started; log sequence number "
- << srv_start_lsn;
+ << " started; log sequence number "
+ << srv_start_lsn
+ << "; transaction id " << trx_sys.get_max_trx_id();
}
if (srv_force_recovery > 0) {
@@ -2815,10 +2833,10 @@ innodb_shutdown()
ut_ad(dict_stats_event || !srv_was_started || srv_read_only_mode);
ut_ad(dict_sys || !srv_was_started);
- ut_ad(trx_sys || !srv_was_started);
+ ut_ad(trx_sys.is_initialised() || !srv_was_started);
ut_ad(buf_dblwr || !srv_was_started || srv_read_only_mode
|| srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO);
- ut_ad(lock_sys || !srv_was_started);
+ ut_ad(lock_sys.is_initialised() || !srv_was_started);
#ifdef BTR_CUR_HASH_ADAPT
ut_ad(btr_search_sys || !srv_was_started);
#endif /* BTR_CUR_HASH_ADAPT */
@@ -2853,18 +2871,12 @@ innodb_shutdown()
if (log_sys) {
log_shutdown();
}
- if (trx_sys) {
- trx_sys_close();
- }
- UT_DELETE(purge_sys);
- purge_sys = NULL;
+ trx_sys.close();
+ purge_sys.close();
if (buf_dblwr) {
buf_dblwr_free();
}
- if (lock_sys) {
- lock_sys_close();
- }
-
+ lock_sys.close();
trx_pool_close();
/* We don't create these mutexes in RO mode because we don't create
@@ -2909,7 +2921,8 @@ innodb_shutdown()
if (srv_was_started && srv_print_verbose_log) {
ib::info() << "Shutdown completed; log sequence number "
- << srv_shutdown_lsn;
+ << srv_shutdown_lsn
+ << "; transaction id " << trx_sys.get_max_trx_id();
}
srv_start_state = SRV_START_STATE_NONE;