summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorLuis Soares <luis.soares@oracle.com>2011-11-24 17:15:58 +0000
committerLuis Soares <luis.soares@oracle.com>2011-11-24 17:15:58 +0000
commit67791697e4303355260fa97f5e4493b20e55c49b (patch)
treecb27960c54625082046a6586e57fccdf377a60b8 /sql
parent2dd10f632b3ec1fa9c4e46785a7cb9a26b2c13b8 (diff)
downloadmariadb-git-67791697e4303355260fa97f5e4493b20e55c49b.tar.gz
BUG#11745230: 12133: MASTER.INDEX FILE KEEPS MYSQLD FROM STARTING IF
BIN LOG HAS BEEN MOVED When moving the binary/relay log files from one location to another and restarting the server with a different log-bin or relay-log paths, would cause the startup process to abort. The root cause was that the server would not be able to find the log files because it would consider old paths for entries in the index file instead of the new location. What's even worse, the relative paths would not be considered relative to the path provided in log-bin and relay-log, but to mysql_data_dir. We fix the cases where the server contains relative paths. When the server is reading from the index file, it checks whether the entry contains relative paths. If it does, we replace it with the absolute path set in log-bin/relay-log option. Absolute paths remain unchanged and the index must be manually edited to consider the new log-bin and/or relay-log path (this should be documented). This is a fix for a GA version, that does not break behavior (that much). For development versions, we should go with Zhenxing's approach that removes paths altogether from index files.
Diffstat (limited to 'sql')
-rw-r--r--sql/log.cc56
-rw-r--r--sql/log.h62
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/mysqld.h3
4 files changed, 111 insertions, 13 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 77ba7aa6283..ec4c01003e0 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -3242,10 +3242,11 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
bool need_lock)
{
int error= 0;
- char *fname= linfo->log_file_name;
- uint log_name_len= log_name ? (uint) strlen(log_name) : 0;
+ char *full_fname= linfo->log_file_name;
+ char full_log_name[FN_REFLEN], fname[FN_REFLEN];
+ uint log_name_len= 0, fname_len= 0;
DBUG_ENTER("find_log_pos");
- DBUG_PRINT("enter",("log_name: %s", log_name ? log_name : "NULL"));
+ full_log_name[0]= full_fname[0]= 0;
/*
Mutex needed because we need to make sure the file pointer does not
@@ -3255,6 +3256,20 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
mysql_mutex_lock(&LOCK_index);
mysql_mutex_assert_owner(&LOCK_index);
+ // extend relative paths for log_name to be searched
+ if (log_name)
+ {
+ if(normalize_binlog_name(full_log_name, log_name, is_relay_log))
+ {
+ error= LOG_INFO_EOF;
+ goto end;
+ }
+ }
+
+ log_name_len= log_name ? (uint) strlen(full_log_name) : 0;
+ DBUG_PRINT("enter", ("log_name: %s, full_log_name: %s",
+ log_name ? log_name : "NULL", full_log_name));
+
/* As the file is flushed, we can't get an error here */
(void) reinit_io_cache(&index_file, READ_CACHE, (my_off_t) 0, 0, 0);
@@ -3273,19 +3288,28 @@ int MYSQL_BIN_LOG::find_log_pos(LOG_INFO *linfo, const char *log_name,
break;
}
+ // extend relative paths and match against full path
+ if (normalize_binlog_name(full_fname, fname, is_relay_log))
+ {
+ error= LOG_INFO_EOF;
+ break;
+ }
+ fname_len= (uint) strlen(full_fname);
+
// if the log entry matches, null string matching anything
if (!log_name ||
- (log_name_len == length-1 && fname[log_name_len] == '\n' &&
- !memcmp(fname, log_name, log_name_len)))
+ (log_name_len == fname_len-1 && full_fname[log_name_len] == '\n' &&
+ !memcmp(full_fname, full_log_name, log_name_len)))
{
- DBUG_PRINT("info",("Found log file entry"));
- fname[length-1]=0; // remove last \n
+ DBUG_PRINT("info", ("Found log file entry"));
+ full_fname[fname_len-1]= 0; // remove last \n
linfo->index_file_start_offset= offset;
linfo->index_file_offset = my_b_tell(&index_file);
break;
}
}
+end:
if (need_lock)
mysql_mutex_unlock(&LOCK_index);
DBUG_RETURN(error);
@@ -3320,7 +3344,8 @@ int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
{
int error= 0;
uint length;
- char *fname= linfo->log_file_name;
+ char fname[FN_REFLEN];
+ char *full_fname= linfo->log_file_name;
if (need_lock)
mysql_mutex_lock(&LOCK_index);
@@ -3336,8 +3361,19 @@ int MYSQL_BIN_LOG::find_next_log(LOG_INFO* linfo, bool need_lock)
error = !index_file.error ? LOG_INFO_EOF : LOG_INFO_IO;
goto err;
}
- fname[length-1]=0; // kill \n
- linfo->index_file_offset = my_b_tell(&index_file);
+
+ if (fname[0] != 0)
+ {
+ if(normalize_binlog_name(full_fname, fname, is_relay_log))
+ {
+ error= LOG_INFO_EOF;
+ goto err;
+ }
+ length= strlen(full_fname);
+ }
+
+ full_fname[length-1]= 0; // kill \n
+ linfo->index_file_offset= my_b_tell(&index_file);
err:
if (need_lock)
diff --git a/sql/log.h b/sql/log.h
index 481bd545960..2e9d308e5e5 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -715,4 +715,66 @@ char *make_log_name(char *buff, const char *name, const char* log_ext);
extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
extern LOGGER logger;
+
+/**
+ Turns a relative log binary log path into a full path, based on the
+ opt_bin_logname or opt_relay_logname.
+
+ @param from The log name we want to make into an absolute path.
+ @param to The buffer where to put the results of the
+ normalization.
+ @param is_relay_log Switch that makes is used inside to choose which
+ option (opt_bin_logname or opt_relay_logname) to
+ use when calculating the base path.
+
+ @returns true if a problem occurs, false otherwise.
+ */
+
+inline bool normalize_binlog_name(char *to, const char *from, bool is_relay_log)
+{
+ DBUG_ENTER("normalize_binlog_name");
+ bool error= false;
+ char buff[FN_REFLEN];
+ char *ptr= (char*) from;
+ char *opt_name= is_relay_log ? opt_relay_logname : opt_bin_logname;
+
+ DBUG_ASSERT(from);
+
+ /* opt_name is not null and not empty and from is a relative path */
+ if (opt_name && opt_name[0] && from && !test_if_hard_path(from))
+ {
+ // take the path from opt_name
+ // take the filename from from
+ char log_dirpart[FN_REFLEN], log_dirname[FN_REFLEN];
+ size_t log_dirpart_len, log_dirname_len;
+ dirname_part(log_dirpart, opt_name, &log_dirpart_len);
+ dirname_part(log_dirname, from, &log_dirname_len);
+
+ /* log may be empty => relay-log or log-bin did not
+ hold paths, just filename pattern */
+ if (log_dirpart_len > 0)
+ {
+ /* create the new path name */
+ if(fn_format(buff, from+log_dirname_len, log_dirpart, "",
+ MYF(MY_UNPACK_FILENAME | MY_SAFE_PATH)) == NULL)
+ {
+ error= true;
+ goto end;
+ }
+
+ ptr= buff;
+ }
+ }
+
+ DBUG_ASSERT(ptr);
+
+ if (ptr)
+ strmake(to, ptr, strlen(ptr));
+
+end:
+ DBUG_RETURN(error);
+}
+
+
+
#endif /* LOG_H */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 0f5087c6ccf..285b10154ce 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -652,7 +652,7 @@ ulong master_retry_count=0;
char *master_info_file;
char *relay_log_info_file, *report_user, *report_password, *report_host;
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
-char *opt_logname, *opt_slow_logname;
+char *opt_logname, *opt_slow_logname, *opt_bin_logname;
/* Static variables */
@@ -677,7 +677,6 @@ static char **defaults_argv;
static int remaining_argc;
/** Remaining command line arguments (arguments), filtered by handle_options().*/
static char **remaining_argv;
-static char *opt_bin_logname;
int orig_argc;
char **orig_argv;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index fc9182ed02e..70089f56e4e 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -139,7 +139,8 @@ extern my_bool relay_log_recovery;
extern uint test_flags,select_errors,ha_open_options;
extern uint protocol_version, mysqld_port, dropping_tables;
extern ulong delay_key_write_options;
-extern char *opt_logname, *opt_slow_logname;
+extern char *opt_logname, *opt_slow_logname, *opt_bin_logname,
+ *opt_relay_logname;
extern char *opt_backup_history_logname, *opt_backup_progress_logname,
*opt_backup_settings_name;
extern const char *log_output_str;