List:Internals« Previous MessageNext Message »
From:sasha Date:May 6 2002 10:16pm
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, 2002-05-06 16:16:21-06:00, sasha@stripped
  merged

  sql/slave.cc
    1.170 02/05/06 16:16:20 sasha@stripped +1 -7
    murged

  sql/slave.h
    1.40 02/05/06 16:16:20 sasha@stripped +0 -3
    merged

  sql/sql_parse.cc
    1.223 02/05/06 14:31:54 sasha@stripped +0 -0
    Auto merged

  sql/sql_yacc.yy
    1.156 02/05/06 14:31:54 sasha@stripped +0 -0
    Auto merged

  sql/log.cc
    1.82 02/05/06 14:31:53 sasha@stripped +0 -0
    Auto merged

# 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:	/reiser-data/mysql-multi-master/RESYNC

--- 1.81/sql/log.cc	Sun Apr 28 15:22:36 2002
+++ 1.82/sql/log.cc	Mon May  6 14:31:53 2002
@@ -173,6 +173,7 @@
   File file= -1;
   bool do_magic;
   int open_flags = O_CREAT | O_APPEND | O_BINARY;
+  DBUG_ENTER("MYSQL_LOG::open");
   if (!inited && log_type_arg == LOG_BIN && *fn_ext(log_name))
       no_rotate = 1;
   init(log_type_arg,io_cache_type_arg,no_auto_events_arg);
@@ -255,14 +256,19 @@
     error=(my_write(index_file, (byte*) log_file_name, strlen(log_file_name),
 		    MYF(MY_NABP | MY_WME)) ||
 	   my_write(index_file, (byte*) "\n", 1, MYF(MY_NABP | MY_WME)));
+    DBUG_PRINT("info",("added %s to index file",log_file_name));
     pthread_mutex_unlock(&LOCK_index);
     if (error)
     {
+      DBUG_PRINT("info",("write error appending %s to log index %s",
+			 log_file_name,index_file_name));
+      sql_print_error("Write error appending %s to log index %s",
+		      log_file_name,index_file_name);
       close_index();
       goto err;
     }
   }
-  return;
+  DBUG_VOID_RETURN;
 
 err:
   sql_print_error("Could not use %s for logging (error %d)", log_name,errno);
@@ -271,7 +277,7 @@
   end_io_cache(&log_file);
   x_free(name); name=0;
   log_type=LOG_CLOSED;
-  return;
+  DBUG_VOID_RETURN;
 }
 
 int MYSQL_LOG::get_current_log(LOG_INFO* linfo)
@@ -375,6 +381,7 @@
   int error=0;
   const char* save_name;
   enum_log_type save_log_type;
+  DBUG_ENTER("MYSQL_LOG::reset_logs");
   pthread_mutex_lock(&LOCK_log);
   if (find_first_log(&linfo,""))
   {
@@ -399,7 +406,7 @@
   my_free((gptr)save_name,MYF(0));
 err:  
   pthread_mutex_unlock(&LOCK_log);
-  return error;
+  DBUG_RETURN(error);
 }
 
 

--- 1.169/sql/slave.cc	Tue Apr 30 07:40:44 2002
+++ 1.170/sql/slave.cc	Mon May  6 16:16:20 2002
@@ -28,6 +28,7 @@
 
 bool use_slave_mask = 0;
 MY_BITMAP slave_error_mask;
+DYNAMIC_ARRAY master_list;
 
 typedef bool (*CHECK_KILLED_FUNC)(THD*,void*);
 
@@ -116,6 +117,11 @@
 
 int init_slave()
 {
+  if (init_dynamic_array(&master_list,sizeof(MASTER_INFO*),50,100))
+  {
+    sql_print_error("Could not initialize master list");
+    return 1;
+  }
   // TODO (multi-master): replace this with list initialization
   active_mi = &main_mi;
 
@@ -132,12 +138,13 @@
     MY_STAT stat_area;
     fn_format(fname, master_info_file, mysql_data_home, "", 4+16+32);
     if (my_stat(fname, &stat_area, MYF(0)) &&
-	!init_master_info(active_mi,master_info_file,relay_log_info_file))
+	!init_master_info(active_mi,master_info_file,relay_log_info_file,0))
       master_host = active_mi->host;
   }
   // slave thread
   if (master_host)
   {
+    // TODO: multi-master re-write
     if (!opt_skip_slave_start && start_slave_threads(1 /* need mutex */,
 						     0 /* no wait for start*/,
 						     active_mi,
@@ -147,7 +154,8 @@
 						     ))
       sql_print_error("Warning: Can't create threads to handle slave");
     else if (opt_skip_slave_start)
-      if (init_master_info(active_mi, master_info_file, relay_log_info_file))
+      if (init_master_info(active_mi, master_info_file,
+			   relay_log_info_file,0))
 	sql_print_error("Warning: failed to initialized master info");
   }
   return 0;
@@ -284,8 +292,11 @@
 int purge_relay_logs(RELAY_LOG_INFO* rli, bool just_reset, const char** errmsg)
 {
   DBUG_ENTER("purge_relay_logs");
+  DBUG_PRINT("info",("rli->inited=%d",rli->inited));
   if (!rli->inited)
-    DBUG_RETURN(0); /* successfully do nothing */
+  {
+    DBUG_RETURN(0);
+  }
   DBUG_ASSERT(rli->slave_running == 0);
   DBUG_ASSERT(rli->mi->slave_running == 0);
   int error=0;
@@ -492,7 +503,7 @@
     lock_cond_io = &mi->run_lock;
     lock_cond_sql = &mi->rli.run_lock;
   }
-  if (init_master_info(mi,master_info_fname,slave_info_fname))
+  if (init_master_info(mi,master_info_fname,slave_info_fname,0))
     return ER_MASTER_INFO;
 
   if ((thread_mask & SLAVE_IO) &&
@@ -518,7 +529,7 @@
 
 void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited)
 {
-  my_init_dynamic_array(a, sizeof(TABLE_RULE_ENT*), TABLE_RULE_ARR_SIZE,
+  init_dynamic_array(a, sizeof(TABLE_RULE_ENT*), TABLE_RULE_ARR_SIZE,
 		     TABLE_RULE_ARR_SIZE);
   *a_inited = 1;
 }
@@ -629,11 +640,18 @@
 
 void end_slave()
 {
-  // TODO: replace the line below with
-  // list_walk(&master_list, (list_walk_action)end_slave_on_walk,0);
-  // once multi-master code is ready
   terminate_slave_threads(active_mi,SLAVE_FORCE_ALL);
-  end_master_info(active_mi);
+  end_master_info(&main_mi);
+  uint i;
+  for (i=0;i<master_list.elements;i++)
+  {
+    MASTER_INFO* mi;
+    get_dynamic(&master_list,(gptr)&mi,i);
+    terminate_slave_threads(mi,SLAVE_FORCE_ALL);
+    end_master_info(mi);
+    delete mi;
+  }
+  
   if (do_table_inited)
     hash_free(&replicate_do_table);
   if (ignore_table_inited)
@@ -977,7 +995,8 @@
   mi->inited = 0;
 }
 
-int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
+int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname,
+			const char* master_ident)
 {
   DBUG_ENTER("init_relay_log_info");
   if (rli->inited)
@@ -987,6 +1006,8 @@
   int info_fd;
   const char* msg = 0;
   int error = 0;
+  const char* relay_log_base = opt_relay_logname,
+    *relay_log_index = opt_relaylog_index_name;
   fn_format(fname, info_fname,
 	    mysql_data_home, "", 4+32);
   pthread_mutex_lock(&rli->data_lock);
@@ -999,19 +1020,51 @@
   rli->skip_log_purge=0;
   rli->log_space_limit = relay_log_space_limit;
   rli->log_space_total = 0;
+  rli->last_slave_error[0]=0;
+  rli->last_slave_errno=0;
+
   // TODO: make this work with multi-master
-  if (!opt_relay_logname)
+  char tmp[FN_REFLEN],tmp1[FN_REFLEN];
+  int master_ident_len=0;
+  if (master_ident)
+    master_ident_len=strlen(master_ident)+1;
+
+  // TODO: see if the code below can be put into a function
+  if (!relay_log_base || master_ident_len)
+  {
+    char* p = tmp;
+    p = strmake(p,glob_hostname,FN_REFLEN-10);
+    if (p-tmp > FN_REFLEN-10-master_ident_len)
+    {
+      sql_print_error("relay log name too long");
+      return 1;
+    }
+    if (master_ident_len)
+    {
+      *p++ = '-';
+      p=strmov(p,master_ident);
+    }
+    
+    strmov(p,"-relay-bin");
+    relay_log_base=tmp;
+  }
+  
+  if (!relay_log_index || master_ident_len)
   {
-    char tmp[FN_REFLEN];
-    /* TODO: The following should be using fn_format();  We just need to
-       first change fn_format() to cut the file name if it's too long.
-    */
-    strmake(tmp,glob_hostname,FN_REFLEN-5);
-    strmov(strcend(tmp,'.'),"-relay-bin");
-    opt_relay_logname=my_strdup(tmp,MYF(MY_WME));
+    char* p = tmp;
+    p=strmake(p,"relay-log",FN_REFLEN-6);
+    if (master_ident_len)
+    {
+      *p++ = '-';
+      p=strmov(p,master_ident);
+    }
+    
+    strmov(p,".index");
+    relay_log_index=tmp;
   }
-  rli->relay_log.set_index_file_name(opt_relaylog_index_name);
-  open_log(&rli->relay_log, glob_hostname, opt_relay_logname, "-relay-bin",
+  
+  rli->relay_log.set_index_file_name(relay_log_index);
+  open_log(&rli->relay_log, glob_hostname, relay_log_base, "-relay-bin",
 	   LOG_BIN, 1 /* read_append cache */,
 	   1 /* no auto events*/);
   
@@ -1158,11 +1211,12 @@
 }
 
 int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
-		     const char* slave_info_fname)
+		     const char* slave_info_fname,
+		     const char* master_ident)
 {
   if (mi->inited)
     return 0;
-  if (init_relay_log_info(&mi->rli, slave_info_fname))
+  if (init_relay_log_info(&mi->rli, slave_info_fname, master_ident))
     return 1;
   mi->rli.mi = mi;
   mi->mysql=0;
@@ -1307,37 +1361,9 @@
   return 0;
 }
 
-int show_master_info(THD* thd, MASTER_INFO* mi)
+static int show_master_info_row(THD* thd, MASTER_INFO* mi)
 {
-  // TODO: fix this for multi-master
-  DBUG_ENTER("show_master_info");
-  List<Item> field_list;
-  field_list.push_back(new Item_empty_string("Master_Host",
-						     sizeof(mi->host)));
-  field_list.push_back(new Item_empty_string("Master_User",
-						     sizeof(mi->user)));
-  field_list.push_back(new Item_empty_string("Master_Port", 6));
-  field_list.push_back(new Item_empty_string("Connect_retry", 6));
-  field_list.push_back(new Item_empty_string("Master_Log_File",
-						     FN_REFLEN));
-  field_list.push_back(new Item_empty_string("Read_Master_Log_Pos", 12));
-  field_list.push_back(new Item_empty_string("Relay_Log_File",
-						     FN_REFLEN));
-  field_list.push_back(new Item_empty_string("Relay_Log_Pos", 12));
-  field_list.push_back(new Item_empty_string("Relay_Master_Log_File",
-						     FN_REFLEN));
-  field_list.push_back(new Item_empty_string("Slave_IO_Running", 3));
-  field_list.push_back(new Item_empty_string("Slave_SQL_Running", 3));
-  field_list.push_back(new Item_empty_string("Replicate_do_db", 20));
-  field_list.push_back(new Item_empty_string("Replicate_ignore_db", 20));
-  field_list.push_back(new Item_empty_string("Last_errno", 4));
-  field_list.push_back(new Item_empty_string("Last_error", 20));
-  field_list.push_back(new Item_empty_string("Skip_counter", 12));
-  field_list.push_back(new Item_empty_string("Exec_master_log_pos", 12));
-  field_list.push_back(new Item_empty_string("Relay_log_space", 12));
-  if(send_fields(thd, field_list, 1))
-    DBUG_RETURN(-1);
-
+  DBUG_ENTER("show_master_info_row");
   String* packet = &thd->packet;
   packet->length(0);
   
@@ -1367,7 +1393,54 @@
   
   if (my_net_write(&thd->net, (char*)thd->packet.ptr(), packet->length()))
     DBUG_RETURN(-1);
+  
+  DBUG_RETURN(0);
+}
 
+int show_master_info(THD* thd)
+{
+  // TODO: fix this for multi-master
+  DBUG_ENTER("show_master_info");
+  List<Item> field_list;
+  field_list.push_back(new Item_empty_string("Master_Host",
+						     sizeof(main_mi.host)));
+  field_list.push_back(new Item_empty_string("Master_User",
+						     sizeof(main_mi.user)));
+  field_list.push_back(new Item_empty_string("Master_Port", 6));
+  field_list.push_back(new Item_empty_string("Connect_retry", 6));
+  field_list.push_back(new Item_empty_string("Master_Log_File",
+						     FN_REFLEN));
+  field_list.push_back(new Item_empty_string("Read_Master_Log_Pos", 12));
+  field_list.push_back(new Item_empty_string("Relay_Log_File",
+						     FN_REFLEN));
+  field_list.push_back(new Item_empty_string("Relay_Log_Pos", 12));
+  field_list.push_back(new Item_empty_string("Relay_Master_Log_File",
+						     FN_REFLEN));
+  field_list.push_back(new Item_empty_string("Slave_IO_Running", 3));
+  field_list.push_back(new Item_empty_string("Slave_SQL_Running", 3));
+  field_list.push_back(new Item_empty_string("Replicate_do_db", 20));
+  field_list.push_back(new Item_empty_string("Replicate_ignore_db", 20));
+  field_list.push_back(new Item_empty_string("Last_errno", 4));
+  field_list.push_back(new Item_empty_string("Last_error", 20));
+  field_list.push_back(new Item_empty_string("Skip_counter", 12));
+  field_list.push_back(new Item_empty_string("Exec_master_log_pos", 12));
+  field_list.push_back(new Item_empty_string("Relay_log_space", 12));
+  if(send_fields(thd, field_list, 1))
+    DBUG_RETURN(-1);
+
+  
+  if (show_master_info_row(thd,&main_mi))
+    DBUG_RETURN(-1);
+
+  uint i;
+  for (i=0;i<master_list.elements;i++)
+  {
+    MASTER_INFO *mi;
+    get_dynamic(&master_list, (gptr)&mi, i);
+    if (show_master_info_row(thd,mi))
+      DBUG_RETURN(-1);
+  }
+  
   send_eof(&thd->net);
   DBUG_RETURN(0);
 }
@@ -1571,7 +1644,7 @@
 
 static ulong read_event(MYSQL* mysql, MASTER_INFO *mi)
 {
-  ulong len = packet_error;
+  ulong len;
 
   // my_real_read() will time us out
   // we check if we were told to die, and if not, try reading again
@@ -1581,12 +1654,11 @@
 #endif
   
   len = mc_net_safe_read(mysql);
-
   if (len == packet_error || (long) len < 1)
   {
     sql_print_error("Error reading packet from server: %s (\
 server_errno=%d)",
-		    mc_mysql_error(mysql), mc_mysql_errno(mysql));
+		    mc_mysql_error(mysql),mc_mysql_errno(mysql));
     return packet_error;
   }
 
@@ -2636,7 +2708,6 @@
   sql_print_error("Error reading relay log event: %s", errmsg);
   return 0;
 }
-
 
 #ifdef __GNUC__
 template class I_List_iterator<i_string>;

--- 1.222/sql/sql_parse.cc	Wed Apr 24 16:16:39 2002
+++ 1.223/sql/sql_parse.cc	Mon May  6 14:31:54 2002
@@ -1317,6 +1317,13 @@
       delete result;
     break;
   }
+  case SQLCOM_NEW_MASTER:
+  {
+    if (check_process_priv(thd))
+      goto error;
+    res = add_new_master(thd, &lex->mi);
+    break;
+  }
   case SQLCOM_DO:
     res=mysql_do(thd, *lex->insert_list);
     break;
@@ -1385,9 +1392,7 @@
   {
     if (check_process_priv(thd))
       goto error;
-    LOCK_ACTIVE_MI;
-    res = show_master_info(thd,active_mi);
-    UNLOCK_ACTIVE_MI;
+    res = show_master_info(thd);
     break;
   }
   case SQLCOM_SHOW_MASTER_STAT:

--- 1.155/sql/sql_yacc.yy	Mon Apr 29 03:24:11 2002
+++ 1.156/sql/sql_yacc.yy	Mon May  6 14:31:54 2002
@@ -589,7 +589,7 @@
 	table_to_table_list table_to_table opt_table_list opt_as
 	handler_rkey_function handler_read_or_scan
 	single_multi table_wild_list table_wild_one opt_wild union union_list
-	precision union_option
+	precision union_option new
 END_OF_INPUT
 
 %type <NONE>
@@ -634,6 +634,7 @@
 	| load
 	| lock
 	| kill
+	| new
 	| optimize
 	| purge  
 	| rename
@@ -774,6 +775,15 @@
 	    lex->udf.returns=(Item_result) $7;
 	    lex->udf.dl=$9.str;
 	  };
+new:
+         NEW_SYM MASTER_SYM
+          {
+	    LEX *lex = Lex;
+	    lex->sql_command = SQLCOM_NEW_MASTER;
+	    memset(&lex->mi, 0, sizeof(lex->mi));
+          } 
+          master_defs;   
+
 
 create2:
 	'(' field_list ')' opt_create_table_options create3 {}

--- 1.39/sql/slave.h	Tue Apr 30 07:40:44 2002
+++ 1.40/sql/slave.h	Mon May  6 16:16:20 2002
@@ -159,8 +159,7 @@
   pthread_cond_t log_space_cond;
   
   st_relay_log_info():info_fd(-1),cur_log_fd(-1),inited(0),
-		      cur_log_init_count(0),
-		      abort_slave(0),slave_running(0),
+		      cur_log_init_count(0),abort_slave(0),slave_running(0),
 		      log_pos_current(0),abort_pos_wait(0),
 		      skip_log_purge(0)
     {
@@ -279,10 +278,19 @@
   bool old_format;			// master binlog is in 3.23 format
   volatile bool abort_slave, slave_running;
   bool ignore_stop_event;
+
+  static void* operator new(size_t size)
+    {
+      return (void*)my_malloc((uint)size, MYF(MY_WME|MY_FAE));
+    }
+
+  static void operator delete(void* ptr, size_t size)
+    {
+      my_free((gptr)ptr,MYF(MY_WME));
+    }
   
-  
-  st_master_info():fd(-1), io_thd(0), inited(0), old_format(0),abort_slave(0),
-		   slave_running(0)
+  st_master_info():fd(-1), io_thd(0), inited(0), old_format(0),
+		   abort_slave(0),slave_running(0)
   {
     host[0] = 0; user[0] = 0; password[0] = 0;
     bzero(&file,sizeof(file));
@@ -366,7 +374,7 @@
 int fetch_master_table(THD* thd, const char* db_name, const char* table_name,
 		       MASTER_INFO* mi, MYSQL* mysql);
 
-int show_master_info(THD* thd, MASTER_INFO* mi);
+int show_master_info(THD* thd);
 int show_binlog_info(THD* thd);
 
 // See if the query uses any tables that should not be replicated
@@ -390,9 +398,11 @@
 
 void end_slave(); // clean up
 int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
-		     const char* slave_info_fname);
+		     const char* slave_info_fname,
+		     const char* master_ident);
 void end_master_info(MASTER_INFO* mi);
-int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname);
+int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname,
+			const char* master_ident);
 void end_relay_log_info(RELAY_LOG_INFO* rli);
 void lock_slave_threads(MASTER_INFO* mi);
 void unlock_slave_threads(MASTER_INFO* mi);
@@ -408,7 +418,7 @@
 extern bool volatile abort_loop;
 extern MASTER_INFO main_mi, *active_mi; // active_mi for multi-master
 extern volatile int active_mi_in_use;
-extern LIST master_list;
+extern DYNAMIC_ARRAY master_list;
 extern HASH replicate_do_table, replicate_ignore_table;
 extern DYNAMIC_ARRAY  replicate_wild_do_table, replicate_wild_ignore_table;
 extern bool do_table_inited, ignore_table_inited,
Thread
bk commit into 4.0 treesasha7 May