summaryrefslogtreecommitdiff
path: root/storage/xtradb/fil/fil0fil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/xtradb/fil/fil0fil.cc')
-rw-r--r--storage/xtradb/fil/fil0fil.cc158
1 files changed, 85 insertions, 73 deletions
diff --git a/storage/xtradb/fil/fil0fil.cc b/storage/xtradb/fil/fil0fil.cc
index 2da234ad094..b0695e2f260 100644
--- a/storage/xtradb/fil/fil0fil.cc
+++ b/storage/xtradb/fil/fil0fil.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
-Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2013, 2015, MariaDB Corporation. All Rights Reserved.
+Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2013, 2016, MariaDB Corporation. All Rights Reserved.
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
@@ -719,16 +719,23 @@ fil_node_open_file(
}
if (UNIV_UNLIKELY(space->flags != flags)) {
- fprintf(stderr,
- "InnoDB: Error: table flags are 0x%lx"
- " in the data dictionary\n"
- "InnoDB: but the flags in file %s are 0x%lx!\n",
- space->flags, node->name, flags);
+ ulint sflags = (space->flags & ~FSP_FLAGS_MASK_DATA_DIR);
+ ulint fflags = (flags & ~FSP_FLAGS_MASK_DATA_DIR_ORACLE);
- ut_error;
- }
+ /* DATA_DIR option is on different place on MariaDB
+ compared to MySQL. If this is the difference. Fix
+ it. */
+
+ if (sflags == fflags) {
+ fprintf(stderr,
+ "InnoDB: Warning: Table flags 0x%lx"
+ " in the data dictionary but in file %s are 0x%lx!\n"
+ " Temporally corrected because DATA_DIR option to 0x%lx.\n",
+ space->flags, node->name, flags, space->flags);
+
+ flags = space->flags;
+ }
- if (UNIV_UNLIKELY(space->flags != flags)) {
if (!dict_tf_verify_flags(space->flags, flags)) {
fprintf(stderr,
"InnoDB: Error: table flags are 0x%lx"
@@ -3218,8 +3225,6 @@ fil_create_link_file(
const char* tablename, /*!< in: tablename */
const char* filepath) /*!< in: pathname of tablespace */
{
- os_file_t file;
- ibool success;
dberr_t err = DB_SUCCESS;
char* link_filepath;
char* prev_filepath = fil_read_link_file(tablename);
@@ -3238,16 +3243,24 @@ fil_create_link_file(
link_filepath = fil_make_isl_name(tablename);
- /* Note that OS_FILE_READ_WRITE_CACHED used here to avoid
- unnecessary errors on O_DIRECT, link files are not really
- a data files. */
- file = os_file_create_simple_no_error_handling(
- innodb_file_data_key, link_filepath,
- OS_FILE_CREATE, OS_FILE_READ_WRITE_CACHED, &success, 0);
+ /** Check if the file already exists. */
+ FILE* file = NULL;
+ ibool exists;
+ os_file_type_t ftype;
- if (!success) {
- /* The following call will print an error message */
- ulint error = os_file_get_last_error(true);
+ bool success = os_file_status(link_filepath, &exists, &ftype);
+
+ ulint error = 0;
+ if (success && !exists) {
+ file = fopen(link_filepath, "w");
+ if (file == NULL) {
+ /* This call will print its own error message */
+ error = os_file_get_last_error(true);
+ }
+ } else {
+ error = OS_FILE_ALREADY_EXISTS;
+ }
+ if (error != 0) {
ut_print_timestamp(stderr);
fputs(" InnoDB: Cannot create file ", stderr);
@@ -3259,10 +3272,8 @@ fil_create_link_file(
ut_print_filename(stderr, filepath);
fputs(" already exists.\n", stderr);
err = DB_TABLESPACE_EXISTS;
-
} else if (error == OS_FILE_DISK_FULL) {
err = DB_OUT_OF_FILE_SPACE;
-
} else if (error == OS_FILE_OPERATION_NOT_SUPPORTED) {
err = DB_UNSUPPORTED;
} else {
@@ -3274,13 +3285,17 @@ fil_create_link_file(
return(err);
}
- if (!os_file_write(link_filepath, file, filepath, 0,
- strlen(filepath))) {
+ ulint rbytes = fwrite(filepath, 1, strlen(filepath), file);
+ if (rbytes != strlen(filepath)) {
+ os_file_get_last_error(true);
+ ib_logf(IB_LOG_LEVEL_ERROR,
+ "cannot write link file "
+ "%s",filepath);
err = DB_ERROR;
}
/* Close the file, we only need it at startup */
- os_file_close(file);
+ fclose(file);
mem_free(link_filepath);
@@ -3829,8 +3844,18 @@ fil_open_single_table_tablespace(
/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
tablespace was relocated. */
+
+ ulint newf = def.flags;
+ if (newf != mod_flags) {
+ if (FSP_FLAGS_HAS_DATA_DIR(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR);
+ } else if(FSP_FLAGS_HAS_DATA_DIR_ORACLE(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR_ORACLE);
+ }
+ }
+
if (def.valid && def.id == id
- && (def.flags & ~FSP_FLAGS_MASK_DATA_DIR) == mod_flags) {
+ && newf == mod_flags) {
valid_tablespaces_found++;
} else {
def.valid = false;
@@ -3855,8 +3880,17 @@ fil_open_single_table_tablespace(
/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
tablespace was relocated. */
+ ulint newf = remote.flags;
+ if (newf != mod_flags) {
+ if (FSP_FLAGS_HAS_DATA_DIR(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR);
+ } else if(FSP_FLAGS_HAS_DATA_DIR_ORACLE(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR_ORACLE);
+ }
+ }
+
if (remote.valid && remote.id == id
- && (remote.flags & ~FSP_FLAGS_MASK_DATA_DIR) == mod_flags) {
+ && newf == mod_flags) {
valid_tablespaces_found++;
} else {
remote.valid = false;
@@ -3882,8 +3916,17 @@ fil_open_single_table_tablespace(
/* Validate this single-table-tablespace with SYS_TABLES,
but do not compare the DATA_DIR flag, in case the
tablespace was relocated. */
+ ulint newf = dict.flags;
+ if (newf != mod_flags) {
+ if (FSP_FLAGS_HAS_DATA_DIR(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR);
+ } else if(FSP_FLAGS_HAS_DATA_DIR_ORACLE(newf)) {
+ newf = (newf & ~FSP_FLAGS_MASK_DATA_DIR_ORACLE);
+ }
+ }
+
if (dict.valid && dict.id == id
- && (dict.flags & ~FSP_FLAGS_MASK_DATA_DIR) == mod_flags) {
+ && newf == mod_flags) {
valid_tablespaces_found++;
} else {
dict.valid = false;
@@ -5249,7 +5292,7 @@ retry:
if (posix_fallocate(node->handle, start_offset, len) == -1) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
"space for file \'%s\' failed. Current size "
- INT64PF ", desired size " INT64PF "\n",
+ INT64PF ", desired size " INT64PF,
node->name, start_offset, len+start_offset);
os_file_handle_error_no_exit(node->name, "posix_fallocate", FALSE, __FILE__, __LINE__);
success = FALSE;
@@ -5293,12 +5336,15 @@ retry:
os_offset_t offset
= ((os_offset_t) (start_page_no - file_start_page_no))
* page_size;
+
+ const char* name = node->name == NULL ? space->name : node->name;
+
#ifdef UNIV_HOTBACKUP
- success = os_file_write(node->name, node->handle, buf,
+ success = os_file_write(name, node->handle, buf,
offset, page_size * n_pages);
#else
success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC,
- node->name, node->handle, buf,
+ name, node->handle, buf,
offset, page_size * n_pages, page_size,
node, NULL, space_id, NULL, 0);
#endif /* UNIV_HOTBACKUP */
@@ -5962,22 +6008,12 @@ _fil_io(
}
}
+ const char* name = node->name == NULL ? space->name : node->name;
+
/* Queue the aio request */
- ret = os_aio(
- type,
- is_log,
- mode | wake_later,
- node->name,
- node->handle,
- buf,
- offset,
- len,
- zip_size ? zip_size : UNIV_PAGE_SIZE,
- node,
- message,
- space_id,
- trx,
- write_size);
+ ret = os_aio(type, is_log, mode | wake_later, name, node->handle, buf,
+ offset, len, zip_size ? zip_size : UNIV_PAGE_SIZE, node,
+ message, space_id, trx, write_size);
#else
/* In mysqlbackup do normal i/o, not aio */
@@ -5985,7 +6021,7 @@ _fil_io(
ret = os_file_read(node->handle, buf, offset, len);
} else {
ut_ad(!srv_read_only_mode);
- ret = os_file_write(node->name, node->handle, buf,
+ ret = os_file_write(name, node->handle, buf,
offset, len);
}
#endif /* !UNIV_HOTBACKUP */
@@ -6418,10 +6454,7 @@ fil_close(void)
{
fil_space_crypt_cleanup();
-#ifndef UNIV_HOTBACKUP
- /* The mutex should already have been freed. */
- ut_ad(fil_system->mutex.magic_n == 0);
-#endif /* !UNIV_HOTBACKUP */
+ mutex_free(&fil_system->mutex);
hash_table_free(fil_system->spaces);
@@ -7070,27 +7103,6 @@ fil_mtr_rename_log(
/*************************************************************************
functions to access is_corrupt flag of fil_space_t*/
-ibool
-fil_space_is_corrupt(
-/*=================*/
- ulint space_id)
-{
- fil_space_t* space;
- ibool ret = FALSE;
-
- mutex_enter(&fil_system->mutex);
-
- space = fil_space_get_by_id(space_id);
-
- if (UNIV_UNLIKELY(space && space->is_corrupt)) {
- ret = TRUE;
- }
-
- mutex_exit(&fil_system->mutex);
-
- return(ret);
-}
-
void
fil_space_set_corrupt(
/*==================*/