Commit 09eda84f authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com
Browse files

LOAD DATA INFILE is now replicated properly, except for cleanup on

Stop event and bugs the test suite could not catch
Did some big restructuring of binlog event classes - most important
change is that now each event class has exec_event method and one does
not need to modify slave core code to add a new event. Slave code is
now much smaller and easier to read
parent d4d22f21
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -281,6 +281,8 @@ typedef struct st_io_cache /* Used when cacheing files */
  /* callbacks when the actual read I/O happens */
  IO_CACHE_CALLBACK pre_read;
  IO_CACHE_CALLBACK post_read;
  IO_CACHE_CALLBACK pre_close;
  void* arg; /* for use by pre/post_read */
  char *file_name;			/* if used with 'open_cached_file' */
  char *dir,*prefix;
  File file;
+15 −11
Original line number Diff line number Diff line
@@ -5,8 +5,9 @@ master-bin.001 172 Intvar 1 3 INSERT_ID=1
master-bin.001	200	Query	1	4	use test; insert into t1 values (NULL)
master-bin.001	263	Query	1	5	use test; drop table t1
master-bin.001	311	Query	1	6	use test; create table t1 (word char(20) not null)
master-bin.001	386	Load	1	7	use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\\t' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n' (word)
master-bin.001	468	Query	1	8	use test; drop table t1
master-bin.001	386	Create_file	1	7	db=test;table=t1;file_id=11;block_len=81
master-bin.001	554	Exec_load	1	8	;file_id=11
master-bin.001	577	Query	1	9	use test; drop table t1
Log_name	Pos	Event_type	Server_id	Log_seq	Info
master-bin.001	79	Query	1	2	use test; create table t1(n int not null auto_increment primary key)
Log_name	Pos	Event_type	Server_id	Log_seq	Info
@@ -21,10 +22,11 @@ master-bin.001 172 Intvar 1 3 INSERT_ID=1
master-bin.001	200	Query	1	4	use test; insert into t1 values (NULL)
master-bin.001	263	Query	1	5	use test; drop table t1
master-bin.001	311	Query	1	6	use test; create table t1 (word char(20) not null)
master-bin.001	386	Load	1	7	use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\\t' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n' (word)
master-bin.001	468	Query	1	8	use test; drop table t1
master-bin.001	516	Rotate	1	9	master-bin.002;pos=4
master-bin.001	557	Stop	1	10	
master-bin.001	386	Create_file	1	7	db=test;table=t1;file_id=11;block_len=81
master-bin.001	554	Exec_load	1	8	;file_id=11
master-bin.001	577	Query	1	9	use test; drop table t1
master-bin.001	625	Rotate	1	10	master-bin.002;pos=4
master-bin.001	666	Stop	1	11	
Log_name	Pos	Event_type	Server_id	Log_seq	Info
master-bin.002	4	Start	1	1	Server ver: $VERSION, Binlog ver: 2
master-bin.002	79	Query	1	2	use test; create table t1 (n int)
@@ -38,18 +40,20 @@ slave-bin.001
slave-bin.002
Log_name	Pos	Event_type	Server_id	Log_seq	Info
slave-bin.001	4	Start	2	1	Server ver: $VERSION, Binlog ver: 2
slave-bin.001	79	Slave	2	2	host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.001,pos=4
slave-bin.001	79	Slave	2	3	host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.001,pos=4
slave-bin.001	132	Query	1	2	use test; create table t1(n int not null auto_increment primary key)
slave-bin.001	225	Intvar	1	3	INSERT_ID=1
slave-bin.001	253	Query	1	4	use test; insert into t1 values (NULL)
slave-bin.001	316	Query	1	5	use test; drop table t1
slave-bin.001	364	Query	1	6	use test; create table t1 (word char(20) not null)
slave-bin.001	439	Query	1	8	use test; drop table t1
slave-bin.001	487	Rotate	2	3	slave-bin.002;pos=4; forced by master
slave-bin.001	527	Stop	2	4	
slave-bin.001	439	Create_file	1	7	db=test;table=t1;file_id=11;block_len=81
slave-bin.001	647	Exec_load	1	8	;file_id=11
slave-bin.001	670	Query	1	9	use test; drop table t1
slave-bin.001	718	Rotate	1	4	slave-bin.002;pos=4; forced by master
slave-bin.001	758	Stop	2	5	
Log_name	Pos	Event_type	Server_id	Log_seq	Info
slave-bin.002	4	Start	2	1	Server ver: $VERSION, Binlog ver: 2
slave-bin.002	79	Slave	2	2	host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.002,pos=4
slave-bin.002	79	Slave	2	10	host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.002,pos=4
slave-bin.002	132	Query	1	2	use test; create table t1 (n int)
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
+6 −1
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
  DBUG_PRINT("enter",("type: %d  pos: %ld",(int) type, (ulong) seek_offset));

  info->file=file;
  info->pre_read = info->post_read = 0;
  info->pre_close = info->pre_read = info->post_read = 0;
  info->arg = 0;
  if (!cachesize)
    if (! (cachesize= my_default_record_cache_size))
      DBUG_RETURN(1);				/* No cache requested */
@@ -608,7 +609,10 @@ int flush_io_cache(IO_CACHE *info)
int end_io_cache(IO_CACHE *info)
{
  int error=0;
  IO_CACHE_CALLBACK pre_close;
  DBUG_ENTER("end_io_cache");
  if((pre_close=info->pre_close))
    (*pre_close)(info);
  if (info->buffer)
  {
    if (info->file != -1)			/* File doesn't exist */
@@ -618,3 +622,4 @@ int end_io_cache(IO_CACHE *info)
  }
  DBUG_RETURN(error);
} /* end_io_cache */
+12 −62
Original line number Diff line number Diff line
@@ -535,8 +535,8 @@ void MYSQL_LOG::new_file(bool inside_mutex)
	We log the whole file name for log file as the user may decide
	to change base names at some point.
      */
      Rotate_log_event r(new_name+dirname_length(new_name));
      THD* thd = current_thd;
      Rotate_log_event r(thd,new_name+dirname_length(new_name));
      r.set_log_seq(0, this);
      // this log rotation could have been initiated by a master of
      // the slave running with log-bin
@@ -638,24 +638,8 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command,
  return 0;
}

/* Write to binary log in a format to be used for replication */

bool MYSQL_LOG::write(Slave_log_event* event_info)
{
  bool error;
  if (!inited)					// Can't use mutex if not init
    return 0;
  VOID(pthread_mutex_lock(&LOCK_log));
  if(!event_info->log_seq)
    event_info->set_log_seq(current_thd, this);
  error = event_info->write(&log_file);
  flush_io_cache(&log_file);
  VOID(pthread_mutex_unlock(&LOCK_log));
  return error;
}


bool MYSQL_LOG::write(Query_log_event* event_info)
bool MYSQL_LOG::write(Log_event* event_info)
{
  /* In most cases this is only called if 'is_open()' is true */
  bool error=0;
@@ -667,40 +651,42 @@ bool MYSQL_LOG::write(Query_log_event* event_info)
  if (is_open())
  {
    THD *thd=event_info->thd;
    const char* db = event_info->get_db();
#ifdef USING_TRANSACTIONS    
    IO_CACHE *file = (event_info->cache_stmt ? &thd->transaction.trans_log :
    IO_CACHE *file = ((event_info->cache_stmt && thd) ?
		      &thd->transaction.trans_log :
		      &log_file);
#else
    IO_CACHE *file = &log_file;
#endif    
    if ((!(thd->options & OPTION_BIN_LOG) &&
    if ((thd && !(thd->options & OPTION_BIN_LOG) &&
	 (thd->master_access & PROCESS_ACL)) ||
	!db_ok(event_info->db, binlog_do_db, binlog_ignore_db))
	(db && !db_ok(db, binlog_do_db, binlog_ignore_db)))
    {
      VOID(pthread_mutex_unlock(&LOCK_log));
      return 0;
    }
    error=1;

    if (thd->last_insert_id_used)
    if (thd && thd->last_insert_id_used)
    {
      Intvar_log_event e((uchar)LAST_INSERT_ID_EVENT, thd->last_insert_id);
      Intvar_log_event e(thd,(uchar)LAST_INSERT_ID_EVENT,thd->last_insert_id);
      e.set_log_seq(thd, this);
      if (thd->server_id)
        e.server_id = thd->server_id;
      if (e.write(file))
	goto err;
    }
    if (thd->insert_id_used)
    if (thd && thd->insert_id_used)
    {
      Intvar_log_event e((uchar)INSERT_ID_EVENT, thd->last_insert_id);
      Intvar_log_event e(thd,(uchar)INSERT_ID_EVENT,thd->last_insert_id);
      e.set_log_seq(thd, this);
      if (thd->server_id)
        e.server_id = thd->server_id;
      if (e.write(file))
	goto err;
    }
    if (thd->convert_set)
    if (thd && thd->convert_set)
    {
      char buf[1024] = "SET CHARACTER SET ";
      char* p = strend(buf);
@@ -795,42 +781,6 @@ bool MYSQL_LOG::write(IO_CACHE *cache)
}


bool MYSQL_LOG::write(Load_log_event* event_info)
{
  bool error=0;
  bool should_rotate = 0;
  
  if (inited)
  {
    VOID(pthread_mutex_lock(&LOCK_log));
    if (is_open())
    {
      THD *thd=event_info->thd;
      if ((thd->options & OPTION_BIN_LOG) ||
	  !(thd->master_access & PROCESS_ACL))
      {
	event_info->set_log_seq(thd, this);
	if (event_info->write(&log_file) || flush_io_cache(&log_file))
	{
	  if (!write_error)
	    sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
	  error=write_error=1;
	}
	should_rotate = (my_b_tell(&log_file) >= max_binlog_size);
	VOID(pthread_cond_broadcast(&COND_binlog_update));
      }
    }
    
    if(should_rotate)
      new_file(1); // inside mutex
    
    VOID(pthread_mutex_unlock(&LOCK_log));
  }

  return error;
}


/* Write update log in a format suitable for incremental backup */

bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length,
+851 −115

File changed.

Preview size limit exceeded, changes collapsed.

Loading