List:Internals« Previous MessageNext Message »
From:sasha Date:July 4 2001 11:14pm
Subject:bk commit into 4.0 tree
View as plain text  
Below is the list of changes that have just been committed into a
4.0 repository of sasha. When sasha does a push, they will be propogated to 
the main repository and within 24 hours after the push to the public repository. 
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet@stripped, 2001-07-04 17:14:31-06:00, sasha@stripped
  SHOW NEW MASTER FOR SLAVE WITH ...

  mysql-test/fix-result
    1.1 01/07/04 17:14:29 sasha@stripped +22 -0

  mysql-test/fix-result
    1.0 01/07/04 17:14:29 sasha@stripped +0 -0
    BitKeeper file /home/sasha/src/bk/mysql-4.0/mysql-test/fix-result

  sql/share/norwegian-ny/errmsg.txt
    1.26 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/norwegian/errmsg.txt
    1.26 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/polish/errmsg.txt
    1.26 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/portuguese/errmsg.txt
    1.28 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/romanian/errmsg.txt
    1.25 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/russian/errmsg.txt
    1.27 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/slovak/errmsg.txt
    1.27 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/spanish/errmsg.txt
    1.27 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/share/swedish/errmsg.txt
    1.27 01/07/04 17:14:29 sasha@stripped +1 -0
    new error

  sql/sql_lex.h
    1.42 01/07/04 17:14:29 sasha@stripped +3 -1
    show new master for slave

  sql/sql_parse.cc
    1.143 01/07/04 17:14:29 sasha@stripped +7 -0
    show new master for slave

  sql/sql_repl.cc
    1.48 01/07/04 17:14:29 sasha@stripped +271 -1
    show new master for slave

  sql/sql_repl.h
    1.11 01/07/04 17:14:29 sasha@stripped +4 -0
    show new master for slave

  sql/sql_yacc.yy
    1.99 01/07/04 17:14:29 sasha@stripped +14 -0
    show new master for slave

  include/mysqld_error.h
    1.28 01/07/04 17:14:28 sasha@stripped +2 -1
    new error message

  mysql-test/r/rpl_log.result
    1.8 01/07/04 17:14:28 sasha@stripped +10 -0
    updated results

  mysql-test/t/rpl_log.test
    1.5 01/07/04 17:14:28 sasha@stripped +10 -0
    test show new master for slave

  sql/lex.h
    1.50 01/07/04 17:14:28 sasha@stripped +3 -0
    show new master for slave

  sql/share/czech/errmsg.txt
    1.27 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/danish/errmsg.txt
    1.26 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/dutch/errmsg.txt
    1.27 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/english/errmsg.txt
    1.31 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/estonian/errmsg.txt
    1.28 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/french/errmsg.txt
    1.26 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/german/errmsg.txt
    1.28 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/greek/errmsg.txt
    1.27 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/hungarian/errmsg.txt
    1.28 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/italian/errmsg.txt
    1.32 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/japanese/errmsg.txt
    1.26 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

  sql/share/korean/errmsg.txt
    1.26 01/07/04 17:14:28 sasha@stripped +1 -0
    new error

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	sasha
# Host:	mysql.sashanet.com
# Root:	/home/sasha/src/bk/mysql-4.0

--- 1.27/include/mysqld_error.h	Fri Jun 22 08:35:16 2001
+++ 1.28/include/mysqld_error.h	Wed Jul  4 17:14:28 2001
@@ -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

--- 1.49/sql/lex.h	Thu Jun 28 01:49:15 2001
+++ 1.50/sql/lex.h	Wed Jul  4 17:14:28 2001
@@ -215,8 +215,10 @@
   { "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 @@
   { "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},

--- 1.26/sql/share/czech/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/czech/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.25/sql/share/danish/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/danish/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.26/sql/share/dutch/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/dutch/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.30/sql/share/english/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.31/sql/share/english/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.27/sql/share/estonian/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.28/sql/share/estonian/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.25/sql/share/french/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/french/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.27/sql/share/german/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.28/sql/share/german/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.26/sql/share/greek/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/greek/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.27/sql/share/hungarian/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.28/sql/share/hungarian/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.31/sql/share/italian/errmsg.txt	Thu Jun 28 06:36:56 2001
+++ 1.32/sql/share/italian/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.25/sql/share/japanese/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/japanese/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.25/sql/share/korean/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/korean/errmsg.txt	Wed Jul  4 17:14:28 2001
@@ -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",

--- 1.25/sql/share/norwegian-ny/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/norwegian-ny/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.25/sql/share/norwegian/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/norwegian/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.25/sql/share/polish/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.26/sql/share/polish/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.27/sql/share/portuguese/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.28/sql/share/portuguese/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.24/sql/share/romanian/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.25/sql/share/romanian/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.26/sql/share/russian/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/russian/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.26/sql/share/slovak/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/slovak/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.26/sql/share/spanish/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/spanish/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.26/sql/share/swedish/errmsg.txt	Fri Jun 22 08:35:17 2001
+++ 1.27/sql/share/swedish/errmsg.txt	Wed Jul  4 17:14:29 2001
@@ -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",

--- 1.41/sql/sql_lex.h	Thu Jun 28 01:49:15 2001
+++ 1.42/sql/sql_lex.h	Wed Jul  4 17:14:29 2001
@@ -56,7 +56,7 @@
   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 @@
 {
   char* host, *user, *password,*log_file_name;
   uint port, connect_retry;
+  ulong last_log_seq;
   ulonglong pos;
+  ulong server_id;
 } LEX_MASTER_INFO;
 
 

--- 1.142/sql/sql_parse.cc	Thu Jun 21 13:20:21 2001
+++ 1.143/sql/sql_parse.cc	Wed Jul  4 17:14:29 2001
@@ -1173,6 +1173,13 @@
       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))

--- 1.98/sql/sql_yacc.yy	Thu Jun 28 01:49:15 2001
+++ 1.99/sql/sql_yacc.yy	Wed Jul  4 17:14:29 2001
@@ -223,9 +223,11 @@
 %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 @@
 %token	MYISAM_SYM
 %token	NATIONAL_SYM
 %token	NATURAL
+%token  NEW_SYM
 %token	NCHAR_SYM
 %token	NOT
 %token	NO_SYM
@@ -2402,6 +2405,17 @@
 	    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;
--- New file ---
+++ mysql-test/fix-result	01/07/04 17:14:29
#! /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




--- 1.7/mysql-test/r/rpl_log.result	Sat Jun 30 14:38:46 2001
+++ 1.8/mysql-test/r/rpl_log.result	Wed Jul  4 17:14:28 2001
@@ -55,3 +55,13 @@
 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

--- 1.4/mysql-test/t/rpl_log.test	Sat Jun 30 13:08:33 2001
+++ 1.5/mysql-test/t/rpl_log.test	Wed Jul  4 17:14:28 2001
@@ -36,3 +36,13 @@
 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;

--- 1.47/sql/sql_repl.cc	Fri Jun 29 09:55:20 2001
+++ 1.48/sql/sql_repl.cc	Wed Jul  4 17:14:29 2001
@@ -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 @@
 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 @@
 
 }
 
+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 @@
     }
 
     pthread_mutex_lock(mysql_bin_log.get_log_lock());
- 
     my_b_seek(&log, pos);
 
     for (event_count = 0;

--- 1.10/sql/sql_repl.h	Thu Jun 28 19:32:07 2001
+++ 1.11/sql/sql_repl.h	Wed Jul  4 17:14:29 2001
@@ -33,8 +33,12 @@
 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();
Thread
bk commit into 4.0 treesasha5 Jul