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

sql/log.cc

    Added magic number to binlog
sql/log_event.cc
    distinquish bogus data from truncated logs
sql/log_event.h
    added magic number
    added LOG_READ_TRUNC error
sql/mysqlbinlog.cc
    fixed to handle magic number
    added O_BINARY to my_fopen
sql/mysqld.cc
    added code for replicate-rewrite-db
sql/slave.cc
    replicate-rewrite-db
    O_BINARY
    handle magic
sql/sql_class.h
    added i_string_pair class
sql/sql_repl.cc
    added magic
    better error messages
support-files/magic
    added magic for binlog

Added test case for replication of queries with error
parent a434c8d2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
source ../include/master-slave.inc;
connection master;
drop table if exists x;
create table x(n int primary key);
!insert into x values (1),(2),(2);
insert into x values (3);
connection slave;
sleep 3;
@x.master select * from x;
 
+4 −0
Original line number Diff line number Diff line
n	
1	
2	
3	
+16 −3
Original line number Diff line number Diff line
@@ -149,6 +149,10 @@ void MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
    fn_format(index_file_name, name, mysql_data_home, ".index", 6);
  
  db[0]=0;
  MY_STAT tmp_stat;
  bool do_magic = ((log_type == LOG_BIN) && !my_stat(log_file_name,
						     &tmp_stat, MYF(0)));
  
  file=my_fopen(log_file_name,O_APPEND | O_WRONLY | O_BINARY,
		MYF(MY_WME | ME_WAITTANG));
  if (!file)
@@ -187,10 +191,18 @@ void MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
  }
  else if (log_type == LOG_BIN)
  {
    Start_log_event s;
    if(!index_file && 

    // Explanation of the boolean black magic:
    //
    // if we are supposed to write magic number try write
    // clean up if failed
    // then if index_file has not been previously opened, try to open it
    // clean up if failed
    if((do_magic && my_fwrite(file, (byte*)BINLOG_MAGIC, 4,
			     MYF(MY_NABP|MY_WME)) ||
	(!index_file && 
       !(index_file = my_fopen(index_file_name,O_APPEND | O_BINARY | O_RDWR,
			       MYF(MY_WME))))
			       MYF(MY_WME))))))
    {
      my_fclose(file,MYF(MY_WME));
      my_free(name,MYF(0));    
@@ -199,6 +211,7 @@ void MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
      log_type=LOG_CLOSED;
      return;
    }
    Start_log_event s;
    s.write(file);
    pthread_mutex_lock(&LOCK_index);
    my_fseek(index_file, 0L, MY_SEEK_END, MYF(MY_WME));
+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ int Log_event::read_log_event(FILE* file, String* packet,
    {
      if(log_lock)
	pthread_mutex_unlock(log_lock);
      return feof(file) ? LOG_READ_BOGUS: LOG_READ_IO;
      return feof(file) ? LOG_READ_TRUNC: LOG_READ_IO;
    }

  if(log_lock) pthread_mutex_unlock(log_lock);
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#define LOG_READ_BOGUS  -2
#define LOG_READ_IO     -3
#define LOG_READ_MEM    -5
#define LOG_READ_TRUNC  -6

#define LOG_EVENT_OFFSET 4
#define BINLOG_VERSION    1
@@ -42,6 +43,7 @@
#define ROTATE_EVENT_OVERHEAD LOG_EVENT_HEADER_LEN
#define LOAD_EVENT_OVERHEAD   (LOG_EVENT_HEADER_LEN+LOAD_HEADER_LEN+sizeof(sql_ex_info))

#define BINLOG_MAGIC        "\xfe\x62\x69\x6e"

enum Log_event_type { START_EVENT = 1, QUERY_EVENT =2,
		      STOP_EVENT=3, ROTATE_EVENT = 4, INTVAR_EVENT=5,
Loading