Commit bb9da602 authored by unknown's avatar unknown

SHOW NEW MASTER FOR SLAVE WITH ...


include/mysqld_error.h:
  new error message
mysql-test/r/rpl_log.result:
  updated results
mysql-test/t/rpl_log.test:
  test show new master for slave
sql/lex.h:
  show new master for slave
sql/share/czech/errmsg.txt:
  new error
sql/share/danish/errmsg.txt:
  new error
sql/share/dutch/errmsg.txt:
  new error
sql/share/english/errmsg.txt:
  new error
sql/share/estonian/errmsg.txt:
  new error
sql/share/french/errmsg.txt:
  new error
sql/share/german/errmsg.txt:
  new error
sql/share/greek/errmsg.txt:
  new error
sql/share/hungarian/errmsg.txt:
  new error
sql/share/italian/errmsg.txt:
  new error
sql/share/japanese/errmsg.txt:
  new error
sql/share/korean/errmsg.txt:
  new error
sql/share/norwegian-ny/errmsg.txt:
  new error
sql/share/norwegian/errmsg.txt:
  new error
sql/share/polish/errmsg.txt:
  new error
sql/share/portuguese/errmsg.txt:
  new error
sql/share/romanian/errmsg.txt:
  new error
sql/share/russian/errmsg.txt:
  new error
sql/share/slovak/errmsg.txt:
  new error
sql/share/spanish/errmsg.txt:
  new error
sql/share/swedish/errmsg.txt:
  new error
sql/sql_lex.h:
  show new master for slave
sql/sql_parse.cc:
  show new master for slave
sql/sql_repl.cc:
  show new master for slave
sql/sql_repl.h:
  show new master for slave
sql/sql_yacc.yy:
  show new master for slave
parent 2752103d
......@@ -213,4 +213,5 @@
#define ER_CONNECT_TO_MASTER 1210
#define ER_QUERY_ON_MASTER 1211
#define ER_SHOW_BINLOG_EVENTS 1212
#define ER_ERROR_MESSAGES 213
#define ER_SHOW_NEW_MASTER 1213
#define ER_ERROR_MESSAGES 214
#! /bin/sh
# Sasha's hack to fix results generated with mysql-test-run --record
# to be version and test port independent. In some cases, further minor
# manual edititing may be required, but most of the time it should not
# happen
#It is assumed we are running the script in mysql-test directory
VERSION=4.0.0-debug-log
TEST_CASE=$1
if [ -z "$TEST_CASE" ] ;
then
echo "usage: $0 test_case_name"
exit 1
fi
../extra/replace $VERSION '$VERSION' 9306 '$MASTER_MYPORT' 9307 \
'$SLAVE_MYPORT' \\ \\\\ -- r/$TEST_CASE.result
......@@ -55,3 +55,13 @@ slave-bin.002 190 Query 1 3 use test; insert into t1 values (1)
slave-bin.002 250 Query 1 4 use test; drop table t1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root $MASTER_MYPORT 1 master-bin.002 245 Yes 0 0 4
Log_name Log_pos
slave-bin.001 132
Log_name Log_pos
slave-bin.001 225
Log_name Log_pos
slave-bin.001 439
Log_name Log_pos
slave-bin.002 132
Log_name Log_pos
slave-bin.002 250
......@@ -36,3 +36,13 @@ show master logs;
show binlog events in 'slave-bin.001' from 4;
show binlog events in 'slave-bin.002' from 4;
show slave status;
show new master for slave with master_log_file='master-bin.001' and
master_log_pos=4 and master_log_seq=1 and master_server_id=1;
show new master for slave with master_log_file='master-bin.001' and
master_log_pos=79 and master_log_seq=2 and master_server_id=1;
show new master for slave with master_log_file='master-bin.001' and
master_log_pos=311 and master_log_seq=6 and master_server_id=1;
show new master for slave with master_log_file='master-bin.002' and
master_log_pos=4 and master_log_seq=1 and master_server_id=1;
show new master for slave with master_log_file='master-bin.002' and
master_log_pos=137 and master_log_seq=3 and master_server_id=1;
......@@ -215,8 +215,10 @@ static SYMBOL symbols[] = {
{ "MASTER_HOST", SYM(MASTER_HOST_SYM),0,0},
{ "MASTER_LOG_FILE", SYM(MASTER_LOG_FILE_SYM),0,0},
{ "MASTER_LOG_POS", SYM(MASTER_LOG_POS_SYM),0,0},
{ "MASTER_LOG_SEQ", SYM(MASTER_LOG_SEQ_SYM),0,0},
{ "MASTER_PASSWORD", SYM(MASTER_PASSWORD_SYM),0,0},
{ "MASTER_PORT", SYM(MASTER_PORT_SYM),0,0},
{ "MASTER_SERVER_ID", SYM(MASTER_SERVER_ID_SYM),0,0},
{ "MASTER_USER", SYM(MASTER_USER_SYM),0,0},
{ "MAX_ROWS", SYM(MAX_ROWS),0,0},
{ "MATCH", SYM(MATCH),0,0},
......@@ -237,6 +239,7 @@ static SYMBOL symbols[] = {
{ "NATURAL", SYM(NATURAL),0,0},
{ "NATIONAL", SYM(NATIONAL_SYM),0,0},
{ "NEXT", SYM(NEXT_SYM),0,0},
{ "NEW", SYM(NEW_SYM),0,0},
{ "NCHAR", SYM(NCHAR_SYM),0,0},
{ "NO", SYM(NO_SYM),0,0},
{ "NOT", SYM(NOT),0,0},
......
......@@ -223,3 +223,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -217,3 +217,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -218,3 +218,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -217,3 +217,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -216,3 +216,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -216,3 +216,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -216,3 +216,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -216,3 +216,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -218,3 +218,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -218,3 +218,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -217,3 +217,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -222,3 +222,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -215,3 +215,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -214,3 +214,4 @@
"Error connecting to master: %-.128s",
"Error running query on master: %-.128s",
"Error in SHOW BINLOG EVENTS: %-.128s",
"Error in SHOW NEW MASTER: %-.128s",
......@@ -56,7 +56,7 @@ enum enum_sql_command {
SQLCOM_SHOW_OPEN_TABLES, SQLCOM_LOAD_MASTER_DATA,
SQLCOM_HA_OPEN, SQLCOM_HA_CLOSE, SQLCOM_HA_READ,
SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_MULTI_DELETE, SQLCOM_UNION_SELECT,
SQLCOM_SHOW_BINLOG_EVENTS
SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER
};
enum lex_states { STATE_START, STATE_CHAR, STATE_IDENT,
......@@ -93,7 +93,9 @@ typedef struct st_lex_master_info
{
char* host, *user, *password,*log_file_name;
uint port, connect_retry;
ulong last_log_seq;
ulonglong pos;
ulong server_id;
} LEX_MASTER_INFO;
......
......@@ -1173,6 +1173,13 @@ mysql_execute_command(void)
res = purge_master_logs(thd, lex->to_log);
break;
}
case SQLCOM_SHOW_NEW_MASTER:
{
if(check_access(thd, FILE_ACL, any_db))
goto error;
res = show_new_master(thd);
break;
}
case SQLCOM_SHOW_SLAVE_HOSTS:
{
if(check_access(thd, FILE_ACL, any_db))
......
......@@ -26,6 +26,7 @@
#include <my_dir.h>
#define SLAVE_LIST_CHUNK 128
#define SLAVE_ERRMSG_SIZE (FN_REFLEN+64)
extern const char* any_db;
extern pthread_handler_decl(handle_slave,arg);
......@@ -38,6 +39,10 @@ bool opt_sporadic_binlog_dump_fail = 0;
static int binlog_dump_count = 0;
#endif
static Slave_log_event* find_slave_event(IO_CACHE* log,
const char* log_file_name,
char* errmsg);
static uint32* slave_list_key(SLAVE_INFO* si, uint* len,
my_bool not_used __attribute__((unused)))
{
......@@ -863,6 +868,272 @@ void reset_master()
}
int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
const char* log_file_name2, ulonglong log_pos2)
{
int res;
if ((res = strcmp(log_file_name1, log_file_name2)))
return res;
if (log_pos1 > log_pos2)
return 1;
else if (log_pos1 == log_pos2)
return 0;
return -1;
}
static inline int cmp_master_pos(Slave_log_event* sev, LEX_MASTER_INFO* mi)
{
return cmp_master_pos(sev->master_log, sev->master_pos, mi->log_file_name,
mi->pos);
}
static int find_target_pos(LEX_MASTER_INFO* mi, IO_CACHE* log, char* errmsg)
{
uint32 log_seq = mi->last_log_seq;
uint32 target_server_id = mi->server_id;
for (;;)
{
Log_event* ev;
if (!(ev = Log_event::read_log_event(log, 0)))
{
if (log->error > 0)
strmov(errmsg, "Binary log truncated in the middle of event");
else if(log->error < 0)
strmov(errmsg, "I/O error reading binary log");
else
strmov(errmsg, "Could not find target event in the binary log");
return 1;
}
if (ev->log_seq == log_seq && ev->server_id == target_server_id)
{
delete ev;
mi->pos = my_b_tell(log);
return 0;
}
delete ev;
}
}
static void copy_base_name(char* dest, char* src)
{
char* p;
p = strrchr(src, FN_LIBCHAR);
if (p)
p++;
else
p = src;
strmov(dest, p);
}
int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg)
{
LOG_INFO linfo;
char search_file_name[FN_REFLEN],last_log_name[FN_REFLEN];
IO_CACHE log, last_log;
File file = -1, last_file = -1;
pthread_mutex_t *log_lock;
const char* errmsg_p;
Slave_log_event* sev = 0;
my_off_t last_pos = 0;
int error = 1;
int cmp_res;
LINT_INIT(cmp_res);
if (!mysql_bin_log.is_open())
{
strmov(errmsg,"Binary log is not open");
return 1;
}
if (!server_id_supplied)
{
strmov(errmsg, "Misconfigured master - server id was not set");
return 1;
}
linfo.index_file_offset = 0;
thd->current_linfo = &linfo;
search_file_name[0] = 0;
if (mysql_bin_log.find_first_log(&linfo, search_file_name))
{
strmov(errmsg,"Could not find first log");
return 1;
}
bzero((char*) &log,sizeof(log));
log_lock = mysql_bin_log.get_log_lock();
pthread_mutex_lock(log_lock);
for (;;)
{
if ((file=open_binlog(&log, linfo.log_file_name, &errmsg_p)) < 0)
{
pthread_mutex_unlock(log_lock);
strmov(errmsg, errmsg_p);
goto err;
}
if (!(sev = find_slave_event(&log, linfo.log_file_name, errmsg)))
{
pthread_mutex_unlock(log_lock);
goto err;
}
cmp_res = cmp_master_pos(sev, mi);
delete sev;
if(!cmp_res)
{
pthread_mutex_unlock(log_lock);
copy_base_name(mi->log_file_name, linfo.log_file_name);
mi->pos = my_b_tell(&log);
goto mi_inited;
}
if (!last_pos && cmp_res > 0)
{
pthread_mutex_unlock(log_lock);
strmov(errmsg, "Slave event in first log points past the \
target position");
goto err;
}
if (last_pos && cmp_res > 0)
{
end_io_cache(&log);
(void) my_close(file, MYF(MY_WME));
if (init_io_cache(&log, (file = last_file), IO_SIZE, READ_CACHE, 0, 0,
MYF(MY_WME)))
{
errmsg[0] = 0;
goto err;
}
goto found_log;
}
strmov(last_log_name, linfo.log_file_name);
last_pos = my_b_tell(&log);
switch (mysql_bin_log.find_next_log(&linfo))
{
case LOG_INFO_EOF:
if (last_file >= 0)
(void)my_close(last_file, MYF(MY_WME));
last_file = -1;
goto found_log;
case 0:
break;
default:
pthread_mutex_unlock(log_lock);
strmov(errmsg, "Error reading log index");
goto err;
}
end_io_cache(&log);
if (last_file >= 0)
(void) my_close(last_file, MYF(MY_WME));
last_file = file;
}
found_log:
my_b_seek(&log, last_pos);
if (find_target_pos(mi,&log,errmsg))
{
pthread_mutex_unlock(log_lock);
goto err;
}
pthread_mutex_unlock(log_lock);
copy_base_name(mi->log_file_name, last_log_name);
mi_inited:
error = 0;
err:
end_io_cache(&log);
pthread_mutex_lock(&LOCK_thread_count);
thd->current_linfo = 0;
pthread_mutex_unlock(&LOCK_thread_count);
if (file >= 0)
(void) my_close(file, MYF(MY_WME));
if (last_file >= 0 && last_file != file)
(void) my_close(last_file, MYF(MY_WME));
return error;
}
// caller must delete result when done
static Slave_log_event* find_slave_event(IO_CACHE* log,
const char* log_file_name,
char* errmsg)
{
Log_event* ev;
if (!(ev = Log_event::read_log_event(log, 0)))
{
my_vsnprintf(errmsg, SLAVE_ERRMSG_SIZE,
"Error reading start event in log '%s'",
(char*)log_file_name);
return 0;
}
delete ev;
if (!(ev = Log_event::read_log_event(log, 0)))
{
my_vsnprintf(errmsg, SLAVE_ERRMSG_SIZE,
"Error reading slave event in log '%s'",
(char*)log_file_name);
return 0;
}
if (ev->get_type_code() != SLAVE_EVENT)
{
my_vsnprintf(errmsg, SLAVE_ERRMSG_SIZE,
"Second event in log '%s' is not slave event",
(char*)log_file_name);
delete ev;
return 0;
}
return (Slave_log_event*)ev;
}
int show_new_master(THD* thd)
{
DBUG_ENTER("show_new_master");
List<Item> field_list;
char errmsg[SLAVE_ERRMSG_SIZE];
LEX_MASTER_INFO* lex_mi = &thd->lex.mi;
if (translate_master(thd, lex_mi, errmsg))
{
if (errmsg[0])
net_printf(&thd->net, ER_SHOW_NEW_MASTER, errmsg);
else
send_error(&thd->net, 0);
DBUG_RETURN(1);
}
else
{
String* packet = &thd->packet;
field_list.push_back(new Item_empty_string("Log_name", 20));
field_list.push_back(new Item_empty_string("Log_pos", 20));
if (send_fields(thd, field_list, 1))
DBUG_RETURN(-1);
packet->length(0);
net_store_data(packet, lex_mi->log_file_name);
net_store_data(packet, (longlong)lex_mi->pos);
if (my_net_write(&thd->net, packet->ptr(), packet->length()))
DBUG_RETURN(-1);
send_eof(&thd->net);
DBUG_RETURN(0);
}
}
int show_binlog_events(THD* thd)
{
......@@ -913,7 +1184,6 @@ int show_binlog_events(THD* thd)
}
pthread_mutex_lock(mysql_bin_log.get_log_lock());
my_b_seek(&log, pos);
for (event_count = 0;
......
......@@ -33,8 +33,12 @@ int stop_slave(THD* thd = 0, bool net_report = 1);
int load_master_data(THD* thd);
int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi);
int change_master(THD* thd);
int show_new_master(THD* thd);
int show_slave_hosts(THD* thd);
int show_binlog_events(THD* thd);
int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg);
int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
const char* log_file_name2, ulonglong log_pos2);
void reset_slave();
void reset_master();
void init_slave_list();
......
......@@ -223,9 +223,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token MASTER_USER_SYM
%token MASTER_LOG_FILE_SYM
%token MASTER_LOG_POS_SYM
%token MASTER_LOG_SEQ_SYM
%token MASTER_PASSWORD_SYM
%token MASTER_PORT_SYM
%token MASTER_CONNECT_RETRY_SYM
%token MASTER_SERVER_ID_SYM
%token MATCH
%token MAX_ROWS
%token MEDIUM_SYM
......@@ -234,6 +236,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token MYISAM_SYM
%token NATIONAL_SYM
%token NATURAL
%token NEW_SYM
%token NCHAR_SYM
%token NOT
%token NO_SYM
......@@ -2402,6 +2405,17 @@ show_param:
if (!add_table_to_list($4,NULL,0))
YYABORT;
}
| NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
TEXT_STRING AND MASTER_LOG_POS_SYM EQ ULONGLONG_NUM AND
MASTER_LOG_SEQ_SYM EQ ULONG_NUM AND MASTER_SERVER_ID_SYM EQ
ULONG_NUM
{
Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
Lex->mi.log_file_name = $8.str;
Lex->mi.pos = $12;
Lex->mi.last_log_seq = $16;
Lex->mi.server_id = $20;
}
| MASTER_SYM LOGS_SYM
{
Lex->sql_command = SQLCOM_SHOW_BINLOGS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment