diff options
Diffstat (limited to 'extra/mariabackup')
23 files changed, 210 insertions, 390 deletions
diff --git a/extra/mariabackup/CMakeLists.txt b/extra/mariabackup/CMakeLists.txt index 8562ded85a1..be2d78b504e 100644 --- a/extra/mariabackup/CMakeLists.txt +++ b/extra/mariabackup/CMakeLists.txt @@ -40,6 +40,10 @@ IF(NOT HAVE_SYSTEM_REGEX) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/pcre) ENDIF() +IF(WITH_WSREP) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/wsrep) +ENDIF() + ADD_DEFINITIONS(-UMYSQL_SERVER) ######################################################################## # xtrabackup binary diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index 1db5eb16a52..a31668a9642 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -57,7 +57,6 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include "backup_copy.h" #include "backup_mysql.h" #include <btr0btr.h> -#include "xb0xb.h" #define ROCKSDB_BACKUP_DIR "#rocksdb" @@ -642,12 +641,10 @@ int mkdirp(const char *pathname, int Flags, myf MyFlags) { char *parent, *p; - int len = strlen(pathname) + 1; /* make a parent directory path */ - if (!(parent= (char *)malloc(len))) + if (!(parent= strdup(pathname))) return(-1); - memcpy(parent, pathname, len); for (p = parent + strlen(parent); !is_path_separator(*p) && p != parent; p--) ; diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc index 843ebf2663e..236acce2483 100644 --- a/extra/mariabackup/backup_mysql.cc +++ b/extra/mariabackup/backup_mysql.cc @@ -48,6 +48,7 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include <limits> #include "common.h" #include "xtrabackup.h" +#include "srv0srv.h" #include "mysql_version.h" #include "backup_copy.h" #include "backup_mysql.h" @@ -791,7 +792,7 @@ wait_for_no_updates(MYSQL *connection, uint timeout, uint threshold) static os_thread_ret_t -kill_query_thread( +DECLARE_THREAD(kill_query_thread)( /*===============*/ void *arg __attribute__((unused))) { @@ -1460,7 +1461,7 @@ operator<<(std::ostream& s, const escape_and_quote& eq) s << '\''; size_t len = strlen(eq.str); char* escaped = (char *)alloca(2 * len + 1); - len = mysql_real_escape_string(eq.mysql, escaped, eq.str, len); + len = mysql_real_escape_string(eq.mysql, escaped, eq.str, (ulong)len); s << std::string(escaped, len); s << '\''; return s; diff --git a/extra/mariabackup/changed_page_bitmap.cc b/extra/mariabackup/changed_page_bitmap.cc index 373af9451f9..fcfb33c500a 100644 --- a/extra/mariabackup/changed_page_bitmap.cc +++ b/extra/mariabackup/changed_page_bitmap.cc @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA #include "common.h" #include "xtrabackup.h" +#include "srv0srv.h" /* TODO: copy-pasted shared definitions from the XtraDB bitmap write code. Remove these on the first opportunity, i.e. single-binary XtraBackup. */ diff --git a/extra/mariabackup/crc/crc-intel-pclmul.c b/extra/mariabackup/crc/crc-intel-pclmul.c index 8fdac31892a..cf4f3ef4380 100644 --- a/extra/mariabackup/crc/crc-intel-pclmul.c +++ b/extra/mariabackup/crc/crc-intel-pclmul.c @@ -57,7 +57,7 @@ typedef uint8_t byte; #if __GNUC__ >= 4 && defined(__x86_64__) && defined(HAVE_CLMUL_INSTRUCTION) -#if _GCRY_GCC_VERSION >= 40400 /* 4.4 */ +#if defined(_GCRY_GCC_VERSION) && _GCRY_GCC_VERSION >= 40400 /* 4.4 */ /* Prevent compiler from issuing SSE instructions between asm blocks. */ # pragma GCC target("no-sse") #endif diff --git a/extra/mariabackup/datasink.cc b/extra/mariabackup/datasink.cc index 4235a46ea00..29bdc061014 100644 --- a/extra/mariabackup/datasink.cc +++ b/extra/mariabackup/datasink.cc @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ +#include <my_global.h> #include <my_base.h> #include "common.h" #include "datasink.h" diff --git a/extra/mariabackup/ds_archive.cc b/extra/mariabackup/ds_archive.cc index 3826029e120..c8fcfa1f5f5 100644 --- a/extra/mariabackup/ds_archive.cc +++ b/extra/mariabackup/ds_archive.cc @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ +#include <my_global.h> #include <my_base.h> #include <archive.h> #include <archive_entry.h> diff --git a/extra/mariabackup/ds_buffer.cc b/extra/mariabackup/ds_buffer.cc index e906edc9e84..720a329c238 100644 --- a/extra/mariabackup/ds_buffer.cc +++ b/extra/mariabackup/ds_buffer.cc @@ -23,7 +23,7 @@ Writes to the destination datasink are guaranteed to not be smaller than a specified buffer size (DS_DEFAULT_BUFFER_SIZE by default), with the only exception for the last write for a file. */ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include "ds_buffer.h" #include "common.h" diff --git a/extra/mariabackup/ds_compress.cc b/extra/mariabackup/ds_compress.cc index fb4f3a75bb6..487718e2ac0 100644 --- a/extra/mariabackup/ds_compress.cc +++ b/extra/mariabackup/ds_compress.cc @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ +#include <my_global.h> #include <mysql_version.h> #include <my_base.h> #include <quicklz.h> diff --git a/extra/mariabackup/ds_local.cc b/extra/mariabackup/ds_local.cc index 0f13ddfe9a9..a6d6be988b1 100644 --- a/extra/mariabackup/ds_local.cc +++ b/extra/mariabackup/ds_local.cc @@ -18,8 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ -#include <my_config.h> -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include <mysys_err.h> #include "common.h" diff --git a/extra/mariabackup/ds_stdout.cc b/extra/mariabackup/ds_stdout.cc index 9398482feb9..85dbb83865b 100644 --- a/extra/mariabackup/ds_stdout.cc +++ b/extra/mariabackup/ds_stdout.cc @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ +#include <my_global.h> #include <my_base.h> #include <mysys_err.h> #include "common.h" diff --git a/extra/mariabackup/ds_tmpfile.cc b/extra/mariabackup/ds_tmpfile.cc index ddb23bf469d..22dff165aa0 100644 --- a/extra/mariabackup/ds_tmpfile.cc +++ b/extra/mariabackup/ds_tmpfile.cc @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA /* Do all writes to temporary files first, then pipe them to the specified datasink in a serialized way in deinit(). */ +#include <my_global.h> #include <my_base.h> #include "common.h" #include "datasink.h" @@ -90,22 +91,8 @@ tmpfile_open(ds_ctxt_t *ctxt, const char *path, /* Create a temporary file in tmpdir. The file will be automatically removed on close. Code copied from mysql_tmpfile(). */ fd = create_temp_file(tmp_path,xtrabackup_tmpdir, - "xbtemp", -#ifdef __WIN__ - O_BINARY | O_TRUNC | O_SEQUENTIAL | - O_TEMPORARY | O_SHORT_LIVED | -#endif /* __WIN__ */ - O_CREAT | O_EXCL | O_RDWR, - MYF(MY_WME)); - -#ifndef __WIN__ - if (fd >= 0) { - /* On Windows, open files cannot be removed, but files can be - created with the O_TEMPORARY flag to the same effect - ("delete on close"). */ - unlink(tmp_path); - } -#endif /* !__WIN__ */ + "xbtemp", O_BINARY | O_SEQUENTIAL, + MYF(MY_WME | MY_TEMPORARY)); if (fd < 0) { return NULL; diff --git a/extra/mariabackup/ds_xbstream.cc b/extra/mariabackup/ds_xbstream.cc index 105c89d05f7..5a753b08474 100644 --- a/extra/mariabackup/ds_xbstream.cc +++ b/extra/mariabackup/ds_xbstream.cc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include "common.h" #include "datasink.h" diff --git a/extra/mariabackup/encryption_plugin.cc b/extra/mariabackup/encryption_plugin.cc index 8f1978e967a..a3242078293 100644 --- a/extra/mariabackup/encryption_plugin.cc +++ b/extra/mariabackup/encryption_plugin.cc @@ -1,3 +1,19 @@ +/* Copyright (c) 2017, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ + +#include <my_global.h> #include <mysqld.h> #include <mysql.h> #include <xtrabackup.h> @@ -196,6 +212,7 @@ static void encryption_plugin_init(int argc, char **argv) { /* Patch optional and mandatory plugins, we only need to load the one in xb_plugin_load. */ mysql_optional_plugins[0] = mysql_mandatory_plugins[0] = 0; + plugin_maturity = MariaDB_PLUGIN_MATURITY_UNKNOWN; /* mariabackup accepts all plugins */ msg("Loading encryption plugin"); for (int i= 1; i < argc; i++) msg("\t Encryption plugin parameter : '%s'", argv[i]); diff --git a/extra/mariabackup/fil_cur.cc b/extra/mariabackup/fil_cur.cc index dce0f9ba6f2..5e64e262166 100644 --- a/extra/mariabackup/fil_cur.cc +++ b/extra/mariabackup/fil_cur.cc @@ -22,8 +22,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA /* Source file cursor implementation */ +#include <my_global.h> #include <my_base.h> - #include <fil0fil.h> #include <fsp0fsp.h> #include <srv0start.h> @@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA #include "common.h" #include "read_filt.h" #include "xtrabackup.h" -#include "xb0xb.h" /* Size of read buffer in pages (640 pages = 10M for 16K sized pages) */ #define XB_FIL_CUR_PAGES 640 @@ -91,7 +90,7 @@ xb_fil_node_close_file( { ibool ret; - mutex_enter(&fil_system->mutex); + mutex_enter(&fil_system.mutex); ut_ad(node); ut_a(node->n_pending == 0); @@ -100,7 +99,7 @@ xb_fil_node_close_file( if (!node->is_open()) { - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); return; } @@ -110,19 +109,19 @@ xb_fil_node_close_file( node->handle = OS_FILE_CLOSED; - ut_a(fil_system->n_open > 0); - fil_system->n_open--; + ut_a(fil_system.n_open > 0); + fil_system.n_open--; if (node->space->purpose == FIL_TYPE_TABLESPACE && fil_is_user_tablespace_id(node->space->id)) { - ut_a(UT_LIST_GET_LEN(fil_system->LRU) > 0); + ut_a(UT_LIST_GET_LEN(fil_system.LRU) > 0); /* The node is in the LRU list, remove it */ - UT_LIST_REMOVE(fil_system->LRU, node); + UT_LIST_REMOVE(fil_system.LRU, node); } - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); } /************************************************************************ @@ -181,18 +180,18 @@ xb_fil_cur_open( return(XB_FIL_CUR_SKIP); } - mutex_enter(&fil_system->mutex); + mutex_enter(&fil_system.mutex); - fil_system->n_open++; + fil_system.n_open++; if (node->space->purpose == FIL_TYPE_TABLESPACE && fil_is_user_tablespace_id(node->space->id)) { /* Put the node to the LRU list */ - UT_LIST_ADD_FIRST(fil_system->LRU, node); + UT_LIST_ADD_FIRST(fil_system.LRU, node); } - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); } ut_ad(node->is_open()); @@ -240,9 +239,9 @@ xb_fil_cur_open( /* Allocate read buffer */ cursor->buf_size = XB_FIL_CUR_PAGES * page_size.physical(); cursor->orig_buf = static_cast<byte *> - (malloc(cursor->buf_size + UNIV_PAGE_SIZE)); + (malloc(cursor->buf_size + srv_page_size)); cursor->buf = static_cast<byte *> - (ut_align(cursor->orig_buf, UNIV_PAGE_SIZE)); + (ut_align(cursor->orig_buf, srv_page_size)); cursor->buf_read = 0; cursor->buf_npages = 0; @@ -254,13 +253,13 @@ xb_fil_cur_open( && os_file_read(IORequestRead, node->handle, cursor->buf, 0, page_size.physical()) == DB_SUCCESS) { - mutex_enter(&fil_system->mutex); + mutex_enter(&fil_system.mutex); if (!node->space->crypt_data) { node->space->crypt_data = fil_space_read_crypt_data(page_size, cursor->buf); } - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); } cursor->space_size = (ulint)(cursor->statinfo.st_size @@ -393,7 +392,7 @@ xb_fil_cur_read( ib_int64_t offset; ib_int64_t to_read; const ulint page_size = cursor->page_size.physical(); - xb_ad(!cursor->is_system() || page_size == UNIV_PAGE_SIZE); + xb_ad(!cursor->is_system() || page_size == srv_page_size); cursor->read_filter->get_next_batch(&cursor->read_filter_ctxt, &offset, &to_read); @@ -477,7 +476,7 @@ read_retry: posix_fadvise(cursor->file, offset, to_read, POSIX_FADV_DONTNEED); func_exit: - fil_space_release_for_io(space); + space->release_for_io(); return(ret); } diff --git a/extra/mariabackup/fil_cur.h b/extra/mariabackup/fil_cur.h index d4a7c0d5b39..0f2d620ff7b 100644 --- a/extra/mariabackup/fil_cur.h +++ b/extra/mariabackup/fil_cur.h @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA #include <my_dir.h> #include "read_filt.h" #include "srv0start.h" +#include "srv0srv.h" struct xb_fil_cur_t { pfs_os_file_t file; /*!< source file handle */ diff --git a/extra/mariabackup/write_filt.cc b/extra/mariabackup/write_filt.cc index d72c11978a9..75ddf9fa99e 100644 --- a/extra/mariabackup/write_filt.cc +++ b/extra/mariabackup/write_filt.cc @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA /* Page write filters implementation */ +#include <my_global.h> #include <my_base.h> #include "common.h" #include "write_filt.h" diff --git a/extra/mariabackup/wsrep.cc b/extra/mariabackup/wsrep.cc index ce702096a32..1b93e9ed10e 100644 --- a/extra/mariabackup/wsrep.cc +++ b/extra/mariabackup/wsrep.cc @@ -40,123 +40,20 @@ permission notice: *******************************************************/ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include <handler.h> -#include <trx0sys.h> +#include <trx0rseg.h> +#include <mysql/service_wsrep.h> #include "common.h" #ifdef WITH_WSREP -#define WSREP_XID_PREFIX "WSREPXid" -#define WSREP_XID_PREFIX_LEN MYSQL_XID_PREFIX_LEN -#define WSREP_XID_UUID_OFFSET 8 -#define WSREP_XID_SEQNO_OFFSET (WSREP_XID_UUID_OFFSET + sizeof(wsrep_uuid_t)) -#define WSREP_XID_GTRID_LEN (WSREP_XID_SEQNO_OFFSET + sizeof(wsrep_seqno_t)) -/*! undefined seqno */ -#define WSREP_SEQNO_UNDEFINED (-1) +#include <wsrep_api.h> /*! Name of file where Galera info is stored on recovery */ #define XB_GALERA_INFO_FILENAME "xtrabackup_galera_info" -/* Galera UUID type - for all unique IDs */ -typedef struct wsrep_uuid { - unsigned char data[16]; -} wsrep_uuid_t; - -/* sequence number of a writeset, etc. */ -typedef long long wsrep_seqno_t; - -/* Undefined UUID */ -static const wsrep_uuid_t WSREP_UUID_UNDEFINED = {{0,}}; - -/***********************************************************************//** -Check if a given WSREP XID is valid. - -@return true if valid. -*/ -static -bool -wsrep_is_wsrep_xid( -/*===============*/ - const void* xid_ptr) -{ - const XID* xid = reinterpret_cast<const XID*>(xid_ptr); - - return((xid->formatID == 1 && - xid->gtrid_length == WSREP_XID_GTRID_LEN && - xid->bqual_length == 0 && - !memcmp(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN))); -} - -/***********************************************************************//** -Retrieve binary WSREP UUID from XID. - -@return binary WSREP UUID represenataion, if UUID is valid, or - WSREP_UUID_UNDEFINED otherwise. -*/ -static -const wsrep_uuid_t* -wsrep_xid_uuid( -/*===========*/ - const XID* xid) -{ - if (wsrep_is_wsrep_xid(xid)) { - return(reinterpret_cast<const wsrep_uuid_t*> - (xid->data + WSREP_XID_UUID_OFFSET)); - } else { - return(&WSREP_UUID_UNDEFINED); - } -} - -/***********************************************************************//** -Retrieve WSREP seqno from XID. - -@return WSREP seqno, if it is valid, or WSREP_SEQNO_UNDEFINED otherwise. -*/ -wsrep_seqno_t wsrep_xid_seqno( -/*==========================*/ - const XID* xid) -{ - if (wsrep_is_wsrep_xid(xid)) { - wsrep_seqno_t seqno; - memcpy(&seqno, xid->data + WSREP_XID_SEQNO_OFFSET, - sizeof(wsrep_seqno_t)); - - return(seqno); - } else { - return(WSREP_SEQNO_UNDEFINED); - } -} - -/***********************************************************************//** -Write UUID to string. - -@return length of UUID string representation or -EMSGSIZE if string is too -short. -*/ -static -int -wsrep_uuid_print( -/*=============*/ - const wsrep_uuid_t* uuid, - char* str, - size_t str_len) -{ - if (str_len > 36) { - const unsigned char* u = uuid->data; - return snprintf(str, str_len, - "%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x-%02x%02x%02x%02x%02x%02x", - u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], - u[ 7], u[ 8], u[ 9], u[10], u[11], u[12], u[13], - u[14], u[15]); - } - else { - return -EMSGSIZE; - } -} - /*********************************************************************** Store Galera checkpoint info in the 'xtrabackup_galera_info' file, if that information is present in the trx system header. Otherwise, do nothing. */ @@ -167,7 +64,7 @@ xb_write_galera_info(bool incremental_prepare) FILE* fp; XID xid; char uuid_str[40]; - wsrep_seqno_t seqno; + long long seqno; MY_STAT statinfo; /* Do not overwrite existing an existing file to be compatible with @@ -180,12 +77,14 @@ xb_write_galera_info(bool incremental_prepare) xid.null(); - if (!trx_sys_read_wsrep_checkpoint(&xid)) { + if (!trx_rseg_read_wsrep_checkpoint(xid)) { return; } - if (wsrep_uuid_print(wsrep_xid_uuid(&xid), uuid_str, + wsrep_uuid_t uuid; + memcpy(uuid.data, wsrep_xid_uuid(&xid), sizeof(uuid.data)); + if (wsrep_uuid_print(&uuid, uuid_str, sizeof(uuid_str)) < 0) { return; } diff --git a/extra/mariabackup/xb0xb.h b/extra/mariabackup/xb0xb.h deleted file mode 100644 index b82fd2ba27b..00000000000 --- a/extra/mariabackup/xb0xb.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************** -Copyright (c) 2012 Percona LLC and/or its affiliates. - -Declarations of XtraBackup functions called by InnoDB code. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*******************************************************/ - -#ifndef xb0xb_h -#define xb0xb_h - -extern const char *innodb_checksum_algorithm_names[]; -extern TYPELIB innodb_checksum_algorithm_typelib; - -#endif diff --git a/extra/mariabackup/xbstream.cc b/extra/mariabackup/xbstream.cc index 5d33f27cbb3..1655b69235c 100644 --- a/extra/mariabackup/xbstream.cc +++ b/extra/mariabackup/xbstream.cc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include <my_getopt.h> #include <hash.h> diff --git a/extra/mariabackup/xbstream_read.cc b/extra/mariabackup/xbstream_read.cc index 74f2f888ef7..ff13800fd94 100644 --- a/extra/mariabackup/xbstream_read.cc +++ b/extra/mariabackup/xbstream_read.cc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include <zlib.h> #include "common.h" diff --git a/extra/mariabackup/xbstream_write.cc b/extra/mariabackup/xbstream_write.cc index abaf89f8a6a..fcf92f40acd 100644 --- a/extra/mariabackup/xbstream_write.cc +++ b/extra/mariabackup/xbstream_write.cc @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *******************************************************/ -#include <mysql_version.h> +#include <my_global.h> #include <my_base.h> #include <zlib.h> #include "common.h" diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 46b67705700..c14de6a3104 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -43,6 +43,7 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA //#define XTRABACKUP_TARGET_IS_PLUGIN +#include <my_global.h> #include <my_config.h> #include <unireg.h> #include <mysql_version.h> @@ -96,7 +97,6 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include "backup_mysql.h" #include "backup_copy.h" #include "backup_mysql.h" -#include "xb0xb.h" #include "encryption_plugin.h" #include <sql_plugin.h> #include <srv0srv.h> @@ -228,8 +228,6 @@ long innobase_buffer_pool_awe_mem_mb = 0; long innobase_file_io_threads = 4; long innobase_read_io_threads = 4; long innobase_write_io_threads = 4; -long innobase_log_buffer_size = 1024*1024L; -long innobase_open_files = 300L; longlong innobase_page_size = (1LL << 14); /* 16KB */ char* innobase_buffer_pool_filename = NULL; @@ -240,9 +238,6 @@ are determined in innobase_init below: */ static char* innobase_ignored_opt; char* innobase_data_home_dir; char* innobase_data_file_path; -/* The following has a misleading name: starting from 4.0.5, this also -affects Windows: */ -char* innobase_unix_file_flush_method; my_bool innobase_use_doublewrite; my_bool innobase_file_per_table; @@ -258,8 +253,9 @@ it every INNOBASE_WAKE_INTERVAL'th step. */ #define INNOBASE_WAKE_INTERVAL 32 ulong innobase_active_counter = 0; - +#ifndef _WIN32 static char *xtrabackup_debug_sync = NULL; +#endif my_bool xtrabackup_incremental_force_scan = FALSE; @@ -304,6 +300,11 @@ my_bool opt_remove_original; my_bool opt_lock_ddl_per_table = FALSE; static my_bool opt_check_privileges; +extern const char *innodb_checksum_algorithm_names[]; +extern TYPELIB innodb_checksum_algorithm_typelib; +extern const char *innodb_flush_method_names[]; +extern TYPELIB innodb_flush_method_typelib; + static const char *binlog_info_values[] = {"off", "lockless", "on", "auto", NullS}; static TYPELIB binlog_info_typelib = {array_elements(binlog_info_values)-1, "", @@ -379,7 +380,6 @@ static dberr_t enumerate_ibd_files(process_single_tablespace_func_t callback); /* ======== Datafiles iterator ======== */ struct datafiles_iter_t { - fil_system_t *system; fil_space_t *space; fil_node_t *node; ibool started; @@ -389,14 +389,13 @@ struct datafiles_iter_t { /* ======== Datafiles iterator ======== */ static datafiles_iter_t * -datafiles_iter_new(fil_system_t *f_system) +datafiles_iter_new() { datafiles_iter_t *it; it = static_cast<datafiles_iter_t *>(malloc(sizeof(datafiles_iter_t))); pthread_mutex_init(&it->mutex, NULL); - it->system = f_system; it->space = NULL; it->node = NULL; it->started = FALSE; @@ -423,7 +422,7 @@ datafiles_iter_next(datafiles_iter_t *it) } it->space = (it->space == NULL) ? - UT_LIST_GET_FIRST(it->system->space_list) : + UT_LIST_GET_FIRST(fil_system.space_list) : UT_LIST_GET_NEXT(space_list, it->space); while (it->space != NULL && @@ -540,7 +539,7 @@ os_event_t dbug_alter_thread_done; void mdl_lock_all() { mdl_lock_init(); - datafiles_iter_t *it = datafiles_iter_new(fil_system); + datafiles_iter_t *it = datafiles_iter_new(); if (!it) return; @@ -766,13 +765,10 @@ enum options_xtrabackup OPT_INNODB_ADAPTIVE_HASH_INDEX, OPT_INNODB_DOUBLEWRITE, OPT_INNODB_FILE_PER_TABLE, - OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT, OPT_INNODB_FLUSH_METHOD, - OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG, OPT_INNODB_LOG_GROUP_HOME_DIR, OPT_INNODB_MAX_DIRTY_PAGES_PCT, OPT_INNODB_MAX_PURGE_LAG, - OPT_INNODB_ROLLBACK_ON_TIMEOUT, OPT_INNODB_STATUS_FILE, OPT_INNODB_AUTOEXTEND_INCREMENT, OPT_INNODB_BUFFER_POOL_SIZE, @@ -1287,14 +1283,15 @@ struct my_option xb_server_options[] = FALSE, 0, 0, 0, 0, 0}, {"innodb_flush_method", OPT_INNODB_FLUSH_METHOD, - "With which method to flush data.", (G_PTR*) &innobase_unix_file_flush_method, - (G_PTR*) &innobase_unix_file_flush_method, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, - 0, 0, 0}, + "With which method to flush data.", + &srv_file_flush_method, &srv_file_flush_method, + &innodb_flush_method_typelib, GET_ENUM, REQUIRED_ARG, + IF_WIN(SRV_ALL_O_DIRECT_FSYNC, SRV_FSYNC), 0, 0, 0, 0, 0}, {"innodb_log_buffer_size", OPT_INNODB_LOG_BUFFER_SIZE, "The size of the buffer which InnoDB uses to write log to the log files on disk.", - (G_PTR*) &innobase_log_buffer_size, (G_PTR*) &innobase_log_buffer_size, 0, - GET_LONG, REQUIRED_ARG, 1024*1024L, 256*1024L, LONG_MAX, 0, 1024, 0}, + (G_PTR*) &srv_log_buffer_size, (G_PTR*) &srv_log_buffer_size, 0, + GET_ULONG, REQUIRED_ARG, 1024*1024L, 256*1024L, LONG_MAX, 0, 1024, 0}, {"innodb_log_file_size", OPT_INNODB_LOG_FILE_SIZE, "Ignored for mysqld option compatibility", (G_PTR*) &srv_log_file_size, (G_PTR*) &srv_log_file_size, 0, @@ -1310,10 +1307,6 @@ struct my_option xb_server_options[] = {"innodb_max_dirty_pages_pct", OPT_INNODB_MAX_DIRTY_PAGES_PCT, "Percentage of dirty pages allowed in bufferpool.", (G_PTR*) &srv_max_buf_pool_modified_pct, (G_PTR*) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0}, - {"innodb_open_files", OPT_INNODB_OPEN_FILES, - "How many files at the maximum InnoDB keeps open at the same time.", - (G_PTR*) &innobase_open_files, (G_PTR*) &innobase_open_files, 0, - GET_LONG, REQUIRED_ARG, 300L, 10L, LONG_MAX, 0, 1L, 0}, {"innodb_use_native_aio", OPT_INNODB_USE_NATIVE_AIO, "Use native AIO if supported on this platform.", (G_PTR*) &srv_use_native_aio, @@ -1675,8 +1668,9 @@ xb_get_one_option(int optid, break; case OPT_INNODB_FLUSH_METHOD: - - ADD_PRINT_PARAM_OPT(innobase_unix_file_flush_method); + ut_a(srv_file_flush_method + <= IF_WIN(SRV_ALL_O_DIRECT_FSYNC, SRV_O_DIRECT_NO_FSYNC)); + ADD_PRINT_PARAM_OPT(innodb_flush_method_names[srv_file_flush_method]); break; case OPT_INNODB_PAGE_SIZE: @@ -1788,37 +1782,42 @@ xb_get_one_option(int optid, return 0; } -static my_bool -innodb_init_param(void) +static bool innodb_init_param() { srv_is_being_started = TRUE; /* === some variables from mysqld === */ memset((G_PTR) &mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list)); - if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) - die("init_tmpdir() failed"); + if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) { + msg("init_tmpdir() failed"); + return true; + } xtrabackup_tmpdir = my_tmpdir(&mysql_tmpdir_list); /* dummy for initialize all_charsets[] */ get_charset_name(0); srv_page_size = 0; srv_page_size_shift = 0; +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_parts = 1; +#endif /* BTR_CUR_HASH_ADAPT */ if (innobase_page_size != (1LL << 14)) { - int n_shift = (int)get_bit_shift((ulint) innobase_page_size); + size_t n_shift = get_bit_shift(size_t(innobase_page_size)); if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) { - srv_page_size_shift = n_shift; - srv_page_size = 1 << n_shift; - msg("InnoDB: The page size of the " + srv_page_size_shift = ulong(n_shift); + srv_page_size = 1U << n_shift; + msg("InnoDB: The universal page size of the " "database is set to %lu.", srv_page_size); } else { - die("invalid value of " + msg("invalid value of " "innobase_page_size: %lld", innobase_page_size); + goto error; } } else { srv_page_size_shift = 14; - srv_page_size = (1 << srv_page_size_shift); + srv_page_size = 1U << 14; } /* Check that values don't overflow on 32-bit systems. */ @@ -1874,6 +1873,9 @@ innodb_init_param(void) goto error; } + srv_sys_space.normalize_size(); + srv_lock_table_size = 5 * (srv_buf_pool_size >> srv_page_size_shift); + /* -------------- Log files ---------------------------*/ /* The default dir for log files is the datadir of MySQL */ @@ -1895,20 +1897,14 @@ innodb_init_param(void) } srv_adaptive_flushing = FALSE; - srv_file_format = 1; /* Barracuda */ - srv_max_file_format_at_startup = UNIV_FORMAT_MIN; /* on */ - /* --------------------------------------------------*/ - - srv_file_flush_method_str = innobase_unix_file_flush_method; - - srv_log_buffer_size = (ulint) innobase_log_buffer_size; /* We set srv_pool_size here in units of 1 kB. InnoDB internally changes the value so that it becomes the number of database pages. */ srv_buf_pool_size = (ulint) xtrabackup_use_memory; - srv_buf_pool_chunk_unit = srv_buf_pool_size; + srv_buf_pool_chunk_unit = (ulong)srv_buf_pool_size; srv_buf_pool_instances = 1; + srv_n_page_cleaners = 1; srv_n_file_io_threads = (ulint) innobase_file_io_threads; srv_n_read_io_threads = (ulint) innobase_read_io_threads; @@ -1922,7 +1918,7 @@ innodb_init_param(void) srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog; - srv_max_n_open_files = (ulint) innobase_open_files; + srv_max_n_open_files = ULINT_UNDEFINED - 5; srv_innodb_status = (ibool) innobase_create_status_file; srv_print_verbose_log = verbose ? 2 : 1; @@ -1933,20 +1929,7 @@ innodb_init_param(void) /* We cannot treat characterset here for now!! */ data_mysql_default_charset_coll = (ulint)default_charset_info->number; - ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number); - - //innobase_commit_concurrency_init_default(); - - /* Since we in this module access directly the fields of a trx - struct, and due to different headers and flags it might happen that - mutex_t has a different size in this module and in InnoDB - modules, we check at run time that the size is the same in - these compilation modules. */ - - /* On 5.5+ srv_use_native_aio is TRUE by default. It is later reset - if it is not supported by the platform in - innobase_start_or_create_for_mysql(). As we don't call it in xtrabackup, - we have to duplicate checks from that function here. */ + ut_ad(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number); #ifdef _WIN32 srv_use_native_aio = TRUE; @@ -1978,16 +1961,26 @@ innodb_init_param(void) ? log_block_calc_checksum_crc32 : log_block_calc_checksum_none; - return(FALSE); +#ifdef _WIN32 + srv_use_native_aio = TRUE; +#endif + return false; error: - msg("innodb_init_param(): Error occured."); - return(TRUE); + msg("mariabackup: innodb_init_param(): Error occured.\n"); + return true; } static bool innodb_init() { - dberr_t err = innobase_start_or_create_for_mysql(); + bool create_new_db = false; + /* Check if the data files exist or not. */ + dberr_t err = srv_sys_space.check_file_spec(&create_new_db, 5U << 20); + + if (err == DB_SUCCESS) { + err = srv_start(create_new_db); + } + if (err != DB_SUCCESS) { die("mariabackup: innodb_init() returned %d (%s).", err, ut_strerr(err)); @@ -2525,7 +2518,11 @@ xtrabackup_copy_datafile(fil_node_t* node, uint thread_n, const char *dest_name= was_dropped = (ddl_tracker.drops.find(node->space->id) != ddl_tracker.drops.end()); pthread_mutex_unlock(&backup_mutex); if (was_dropped) { - fil_space_close(node->space->name); + if (node->is_open()) { + mutex_enter(&fil_system.mutex); + node->close(); + mutex_exit(&fil_system.mutex); + } goto skip; } @@ -2640,7 +2637,7 @@ skip: static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last) { lsn_t scanned_lsn = start_lsn; - const byte* log_block = log_sys->buf; + const byte* log_block = log_sys.buf; bool more_data = false; for (ulint scanned_checkpoint = 0; @@ -2692,7 +2689,7 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last) recv_sys_justify_left_parsing_buf(); - log_sys->log.scanned_lsn = scanned_lsn; + log_sys.log.scanned_lsn = scanned_lsn; end_lsn = last ? ut_uint64_align_up(scanned_lsn, OS_FILE_LOG_BLOCK_SIZE) @@ -2700,11 +2697,11 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last) if (ulint write_size = ulint(end_lsn - start_lsn)) { if (srv_encrypt_log) { - log_crypt(log_sys->buf, start_lsn, write_size); + log_crypt(log_sys.buf, start_lsn, write_size); } - if (ds_write(dst_log_file, log_sys->buf, write_size)) { - msg("Error: write to logfile failed\n"); + if (ds_write(dst_log_file, log_sys.buf, write_size)) { + msg("Error: write to logfile failed"); return(0); } } @@ -2736,8 +2733,7 @@ static bool xtrabackup_copy_logfile(bool last = false) log_mutex_enter(); lsn_t lsn= start_lsn; for (int retries= 0; retries < 100; retries++) { - if (log_group_read_log_seg(log_sys->buf, &log_sys->log, - &lsn, end_lsn) + if (log_sys.log.read_log_seg(&lsn, end_lsn) || lsn != start_lsn) { break; } @@ -2763,7 +2759,7 @@ static bool xtrabackup_copy_logfile(bool last = false) } } while (start_lsn == end_lsn); - ut_ad(start_lsn == log_sys->log.scanned_lsn); + ut_ad(start_lsn == log_sys.log.scanned_lsn); msg(">> log scanned up to (" LSN_PF ")", start_lsn); @@ -2792,7 +2788,7 @@ void backup_wait_for_lsn(lsn_t lsn) { extern lsn_t server_lsn_after_lock; -static os_thread_ret_t log_copying_thread(void*) +static os_thread_ret_t DECLARE_THREAD(log_copying_thread)(void*) { /* Initialize mysys thread-specific memory so we can @@ -2826,7 +2822,7 @@ static os_thread_ret_t log_copying_thread(void*) } /* io throttle watching (rough) */ -static os_thread_ret_t io_watching_thread(void*) +static os_thread_ret_t DECLARE_THREAD(io_watching_thread)(void*) { /* currently, for --backup only */ ut_a(xtrabackup_backup); @@ -2889,7 +2885,7 @@ static void dbug_mariabackup_event(const char *event,const char *key) Datafiles copying thread.*/ static os_thread_ret_t -data_copy_thread_func( +DECLARE_THREAD(data_copy_thread_func)( /*==================*/ void *arg) /* thread context */ { @@ -3024,8 +3020,7 @@ static void xb_fil_io_init() { - fil_init(srv_file_per_table ? 50000 : 5000, LONG_MAX); - fsp_init(); + fil_system.create(srv_file_per_table ? 50000 : 5000); } static @@ -3118,11 +3113,11 @@ xb_load_single_table_tablespace( false, false); /* by opening the tablespace we forcing node and space objects in the cache to be populated with fields from space header */ - fil_space_open(space->name); + space->open(); if (srv_operation == SRV_OPERATION_RESTORE_DELTA || xb_close_files) { - fil_space_close(space->name); + space->close(); } } @@ -3298,12 +3293,13 @@ static dberr_t xb_assign_undo_space_start() return DB_ERROR; } - buf = static_cast<byte*>(ut_malloc_nokey(2 * UNIV_PAGE_SIZE)); - page = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE)); + buf = static_cast<byte*>(ut_malloc_nokey(2U << srv_page_size_shift)); + page = static_cast<byte*>(ut_align(buf, srv_page_size)); retry: - if (os_file_read(IORequestRead, file, page, TRX_SYS_PAGE_NO * UNIV_PAGE_SIZE, - UNIV_PAGE_SIZE) != DB_SUCCESS) { + if (os_file_read(IORequestRead, file, page, + TRX_SYS_PAGE_NO << srv_page_size_shift, + srv_page_size) != DB_SUCCESS) { msg("Reading TRX_SYS page failed."); error = DB_ERROR; goto func_exit; @@ -3821,19 +3817,6 @@ open_or_create_log_file( false, false); } -/*********************************************************************//** -Normalizes init parameter values to use units we use inside InnoDB. -@return DB_SUCCESS or error code */ -static -void -xb_normalize_init_values(void) -/*==========================*/ -{ - srv_sys_space.normalize(); - srv_log_buffer_size /= UNIV_PAGE_SIZE; - srv_lock_table_size = 5 * (srv_buf_pool_size / UNIV_PAGE_SIZE); -} - /*********************************************************************** Set the open files limit. Based on set_max_open_files(). @@ -3928,14 +3911,13 @@ static bool xtrabackup_backup_low() log_mutex_enter(); if (recv_find_max_checkpoint(&max_cp_field) == DB_SUCCESS - && log_sys->log.format != 0) { + && log_sys.log.format != 0) { if (max_cp_field == LOG_CHECKPOINT_1) { - log_group_header_read(&log_sys->log, - max_cp_field); + log_header_read(max_cp_field); } metadata_to_lsn = mach_read_from_8( - log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN); - msg("The latest check point" + log_sys.checkpoint_buf + LOG_CHECKPOINT_LSN); + msg("mariabackup: The latest check point" " (for incremental): '" LSN_PF "'", metadata_to_lsn); } else { @@ -4044,47 +4026,12 @@ fail: ds_close(dst_log_file); dst_log_file = NULL; } - if (fil_system) { + if (fil_system.is_initialised()) { innodb_shutdown(); } return(false); } - xb_normalize_init_values(); - - if (srv_file_flush_method_str == NULL) { - /* These are the default options */ - srv_file_flush_method = SRV_FSYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) { - srv_file_flush_method = SRV_FSYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) { - srv_file_flush_method = SRV_O_DSYNC; - - } else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DIRECT")) { - srv_file_flush_method = SRV_O_DIRECT; - msg("using O_DIRECT"); - } else if (0 == ut_strcmp(srv_file_flush_method_str, "littlesync")) { - srv_file_flush_method = SRV_LITTLESYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) { - srv_file_flush_method = SRV_NOSYNC; - } else if (0 == ut_strcmp(srv_file_flush_method_str, "ALL_O_DIRECT")) { - srv_file_flush_method = SRV_ALL_O_DIRECT_FSYNC; - msg("using ALL_O_DIRECT"); - } else if (0 == ut_strcmp(srv_file_flush_method_str, - "O_DIRECT_NO_FSYNC")) { - srv_file_flush_method = SRV_O_DIRECT_NO_FSYNC; - msg("using O_DIRECT_NO_FSYNC"); - } else { - msg("Unrecognized value %s for " - "innodb_flush_method", srv_file_flush_method_str); - goto fail; - } - -#ifdef _WIN32 - srv_file_flush_method = SRV_ALL_O_DIRECT_FSYNC; - srv_use_native_aio = TRUE; -#endif - if (srv_buf_pool_size >= 1000 * 1024 * 1024) { /* Here we still have srv_pool_size counted in kilobytes (in 4.0 this was in bytes) @@ -4125,14 +4072,12 @@ fail: os_aio_init(srv_n_read_io_threads, srv_n_write_io_threads, SRV_MAX_N_PENDING_SYNC_IOS); - log_sys_init(); - log_init(srv_n_log_files); + log_sys.create(); + log_sys.log.create(srv_n_log_files); fil_space_t* space = fil_space_create( "innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0, FIL_TYPE_LOG, NULL); - lock_sys_create(srv_lock_table_size); - for (ulint i = 0; i < srv_n_log_files; i++) { open_or_create_log_file(space, i); } @@ -4175,22 +4120,23 @@ reread_log_header: goto fail; } - if (log_sys->log.format == 0) { + if (log_sys.log.format == 0) { msg("Error: cannot process redo log before MariaDB 10.2.2"); log_mutex_exit(); goto fail; } - const byte* buf = log_sys->checkpoint_buf; - checkpoint_lsn_start = log_sys->log.lsn; - checkpoint_no_start = log_sys->next_checkpoint_no; + const byte* buf = log_sys.checkpoint_buf; + checkpoint_lsn_start = log_sys.log.get_lsn(); + checkpoint_no_start = log_sys.next_checkpoint_no; - log_group_header_read(&log_sys->log, max_cp_field); + log_header_read(max_cp_field); if (checkpoint_no_start != mach_read_from_8(buf + LOG_CHECKPOINT_NO) - || checkpoint_lsn_start != mach_read_from_8(buf + LOG_CHECKPOINT_LSN) - || log_sys->log.lsn_offset - != mach_read_from_8(buf + LOG_CHECKPOINT_OFFSET)) + || checkpoint_lsn_start + != mach_read_from_8(buf + LOG_CHECKPOINT_LSN) + || log_sys.log.get_lsn_offset() + != mach_read_from_8(buf + LOG_CHECKPOINT_OFFSET)) goto reread_log_header; log_mutex_exit(); @@ -4215,8 +4161,8 @@ reread_log_header: memset(log_hdr_buf, 0, sizeof log_hdr_buf); byte *log_hdr_field = log_hdr_buf; - mach_write_to_4(LOG_HEADER_FORMAT + log_hdr_field, log_sys->log.format); - mach_write_to_4(LOG_HEADER_SUBFORMAT + log_hdr_field, log_sys->log.subformat); + mach_write_to_4(LOG_HEADER_FORMAT + log_hdr_field, log_sys.log.format); + mach_write_to_4(LOG_HEADER_SUBFORMAT + log_hdr_field, log_sys.log.subformat); mach_write_to_8(LOG_HEADER_START_LSN + log_hdr_field, checkpoint_lsn_start); strcpy(reinterpret_cast<char*>(LOG_HEADER_CREATOR + log_hdr_field), "Backup " MYSQL_SERVER_VERSION); @@ -4225,15 +4171,15 @@ reread_log_header: /* copied from log_group_checkpoint() */ log_hdr_field += - (log_sys->next_checkpoint_no & 1) ? LOG_CHECKPOINT_2 : LOG_CHECKPOINT_1; + (log_sys.next_checkpoint_no & 1) ? LOG_CHECKPOINT_2 : LOG_CHECKPOINT_1; /* The least significant bits of LOG_CHECKPOINT_OFFSET must be stored correctly in the copy of the ib_logfile. The most significant bits, which identify the start offset of the log block in the file, we did choose freely, as LOG_FILE_HDR_SIZE. */ - ut_ad(!((log_sys->log.lsn ^ checkpoint_lsn_start) + ut_ad(!((log_sys.log.get_lsn() ^ checkpoint_lsn_start) & (OS_FILE_LOG_BLOCK_SIZE - 1))); /* Adjust the checkpoint page. */ - memcpy(log_hdr_field, log_sys->checkpoint_buf, OS_FILE_LOG_BLOCK_SIZE); + memcpy(log_hdr_field, log_sys.checkpoint_buf, OS_FILE_LOG_BLOCK_SIZE); mach_write_to_8(log_hdr_field + LOG_CHECKPOINT_OFFSET, (checkpoint_lsn_start & (OS_FILE_LOG_BLOCK_SIZE - 1)) | LOG_FILE_HDR_SIZE); @@ -4304,7 +4250,7 @@ fail_before_log_copying_thread_start: "Waiting for table metadata lock", 1, ER_QUERY_INTERRUPTED);); } - datafiles_iter_t *it = datafiles_iter_new(fil_system); + datafiles_iter_t *it = datafiles_iter_new(); if (it == NULL) { msg("mariabackup: Error: datafiles_iter_new() failed."); goto fail; @@ -4500,7 +4446,7 @@ void backup_fix_ddl(void) // Load and copy new tables. // Close all datanodes first, reload only new tables. std::vector<fil_node_t *> all_nodes; - datafiles_iter_t *it = datafiles_iter_new(fil_system); + datafiles_iter_t *it = datafiles_iter_new(); if (!it) return; while (fil_node_t *node = datafiles_iter_next(it)) { @@ -4510,7 +4456,11 @@ void backup_fix_ddl(void) fil_node_t *n = all_nodes[i]; if (n->space->id == 0) continue; - fil_space_close(n->space->name); + if (n->is_open()) { + mutex_enter(&fil_system.mutex); + n->close(); + mutex_exit(&fil_system.mutex); + } fil_space_free(n->space->id, false); } datafiles_iter_free(it); @@ -4539,7 +4489,7 @@ void backup_fix_ddl(void) xb_load_single_table_tablespace(dbname, tablename, is_remote); } - it = datafiles_iter_new(fil_system); + it = datafiles_iter_new(); if (!it) return; @@ -4608,7 +4558,8 @@ xb_space_create_file( } ret = os_file_set_size(path, *file, - FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE); + FIL_IBD_FILE_INITIAL_SIZE + << srv_page_size_shift); if (!ret) { msg("mariabackup: cannot set size for file %s", path); os_file_close(*file); @@ -4616,11 +4567,11 @@ xb_space_create_file( return ret; } - buf = static_cast<byte *>(malloc(3 * UNIV_PAGE_SIZE)); + buf = static_cast<byte *>(malloc(3U << srv_page_size_shift)); /* Align the memory for file i/o if we might have O_DIRECT set */ - page = static_cast<byte *>(ut_align(buf, UNIV_PAGE_SIZE)); + page = static_cast<byte *>(ut_align(buf, srv_page_size)); - memset(page, '\0', UNIV_PAGE_SIZE); + memset(page, '\0', srv_page_size); fsp_header_init_fields(page, space_id, flags); mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id); @@ -4631,12 +4582,12 @@ xb_space_create_file( buf_flush_init_for_writing(NULL, page, NULL, 0); ret = os_file_write(IORequestWrite, path, *file, page, 0, - UNIV_PAGE_SIZE); + srv_page_size); } else { page_zip_des_t page_zip; ulint zip_size = page_size.physical(); page_zip_set_size(&page_zip, zip_size); - page_zip.data = page + UNIV_PAGE_SIZE; + page_zip.data = page + srv_page_size; fprintf(stderr, "zip_size = " ULINTPF "\n", zip_size); #ifdef UNIV_DEBUG @@ -4664,6 +4615,16 @@ xb_space_create_file( return TRUE; } +static fil_space_t* fil_space_get_by_name(const char* name) +{ + ut_ad(mutex_own(&fil_system.mutex)); + for (fil_space_t* space = UT_LIST_GET_FIRST(fil_system.space_list); + space != NULL; + space = UT_LIST_GET_NEXT(space_list, space)) + if (!strcmp(space->name, name)) return space; + return NULL; +} + /*********************************************************************** Searches for matching tablespace file for given .delta file and space_id in given directory. When matching tablespace found, renames it to match the @@ -4746,9 +4707,9 @@ exit: HASH_INSERT(xb_filter_entry_t, name_hash, inc_dir_tables_hash, ut_fold_string(table->name), table); - mutex_enter(&fil_system->mutex); + mutex_enter(&fil_system.mutex); fil_space = fil_space_get_by_name(dest_space_name); - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); if (fil_space != NULL) { if (fil_space->id == info.space_id @@ -4765,11 +4726,8 @@ exit: msg("mariabackup: Renaming %s to %s.ibd", fil_space->name, tmpname); - if (!fil_rename_tablespace( - fil_space->id, - fil_space->chain.start->name, - tmpname, NULL)) - { + if (fil_space->rename(tmpname, NULL, false) + != DB_SUCCESS) { msg("mariabackup: Cannot rename %s to %s", fil_space->name, tmpname); goto exit; @@ -4782,9 +4740,9 @@ exit: die("Can't handle DDL operation on tablespace " "%s\n", dest_space_name); } - mutex_enter(&fil_system->mutex); + mutex_enter(&fil_system.mutex); fil_space = fil_space_get_by_id(info.space_id); - mutex_exit(&fil_system->mutex); + mutex_exit(&fil_system.mutex); if (fil_space != NULL) { char tmpname[FN_REFLEN]; @@ -4793,10 +4751,7 @@ exit: msg("mariabackup: Renaming %s to %s", fil_space->name, dest_space_name); - if (!fil_rename_tablespace(fil_space->id, - fil_space->chain.start->name, - tmpname, - NULL)) + if (fil_space->rename(tmpname, NULL, false) != DB_SUCCESS) { msg("mariabackup: Cannot rename %s to %s", fil_space->name, dest_space_name); @@ -5009,7 +4964,7 @@ xtrabackup_apply_delta( n_pages * page_size)) goto error; } else if (fil_space_t* space - = fil_space_acquire(0)) { + = fil_system.sys_space) { /* The system tablespace can consist of multiple files. The first one has full tablespace @@ -5020,7 +4975,6 @@ xtrabackup_apply_delta( bool fail = !strcmp(n->name, dst_path) && !fil_space_extend( space, (ulint)n_pages); - fil_space_release(space); if (fail) goto error; } } @@ -5170,7 +5124,7 @@ xb_process_datadir( handle_datadir_entry_func_t func) /*!<in: callback */ { ulint ret; - char dbpath[OS_FILE_MAX_PATH]; + char dbpath[OS_FILE_MAX_PATH+1]; os_file_dir_t dir; os_file_dir_t dbdir; os_file_stat_t dbinfo; @@ -5502,12 +5456,11 @@ static bool xtrabackup_prepare_func(char** argv) goto error_cleanup; } - xb_normalize_init_values(); sync_check_init(); ut_d(sync_check_enable()); ut_crc32_init(); recv_sys_init(); - log_sys_init(); + log_sys.create(); recv_recovery_on = true; #ifdef WITH_INNODB_DISALLOW_WRITES @@ -5536,12 +5489,12 @@ static bool xtrabackup_prepare_func(char** argv) xb_filter_hash_free(inc_dir_tables_hash); - fil_close(); + fil_system.close(); #ifdef WITH_INNODB_DISALLOW_WRITES os_event_destroy(srv_allow_writes_event); #endif innodb_free_param(); - log_shutdown(); + log_sys.close(); sync_check_close(); if (!ok) goto error_cleanup; } @@ -5575,25 +5528,9 @@ static bool xtrabackup_prepare_func(char** argv) } if (ok) { - mtr_t mtr; - mtr.start(); - const trx_sysf_t* sys_header = trx_sysf_get(&mtr); - - if (mach_read_from_4(TRX_SYS_MYSQL_LOG_INFO - + TRX_SYS_MYSQL_LOG_MAGIC_N_FLD - + sys_header) - == TRX_SYS_MYSQL_LOG_MAGIC_N) { - ulonglong pos = mach_read_from_8( - TRX_SYS_MYSQL_LOG_INFO - + TRX_SYS_MYSQL_LOG_OFFSET - + sys_header); - const char* name = reinterpret_cast<const char*>( - TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME - + sys_header); - msg("Last binlog file %s, position %llu", name, pos); - } - - mtr.commit(); + msg("Last binlog file %s, position %lld", + trx_sys.recovered_binlog_filename, + longlong(trx_sys.recovered_binlog_offset)); } /* Check whether the log is applied enough or not. */ @@ -6427,7 +6364,7 @@ static int main_low(char** argv) static int get_exepath(char *buf, size_t size, const char *argv0) { #ifdef _WIN32 - DWORD ret = GetModuleFileNameA(NULL, buf, size); + DWORD ret = GetModuleFileNameA(NULL, buf, (DWORD)size); if (ret > 0) return 0; #elif defined(__linux__) |