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

more predicatable slave behaviour with wait_for_slave_stop in mysqltest

fixed a couple of bugs with SEQ_READ_APPEND cache
rpl000016 still has non-deterministic result, but I am going to commit and
push since what I have is now better than what is in the main repository
parent 90a77b4f
Loading
Loading
Loading
Loading
+51 −6
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/* mysqltest test tool
 * See man page for more information.
 * See the manual for more information
 * TODO: document better how mysqltest works
 *
 * Written by:
 *   Sasha Pachev <sasha@mysql.com>
@@ -26,9 +27,6 @@
/**********************************************************************
  TODO:

- Print also the queries that returns a result to the log file;  This makes
  it much easier to find out what's wrong.

- Do comparison line by line, instead of doing a full comparison of
  the text file.  This will save space as we don't need to keep many
  results in memory.  It will also make it possible to do simple
@@ -43,7 +41,7 @@

**********************************************************************/

#define MTEST_VERSION "1.13"
#define MTEST_VERSION "1.14"

#include <my_global.h>
#include <mysql_embed.h>
@@ -88,6 +86,12 @@
#define CON_RETRY_SLEEP 2
#define MAX_CON_TRIES   5

#ifndef OS2
#define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */
#else
#defile SLAVE_POLL_INTERVAL 0.3
#endif

enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
      OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT};

@@ -187,6 +191,7 @@ Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER,
Q_WAIT_FOR_SLAVE_TO_STOP,
Q_UNKNOWN,                             /* Unknown command.   */
Q_COMMENT,                             /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND
@@ -222,7 +227,7 @@ const char *command_names[] = {
  "enable_query_log", "disable_query_log",
  "enable_result_log", "disable_result_log",
  "server_start", "server_stop",
  "require_manager",
  "require_manager", "wait_for_slave_to_stop",
  0
};

@@ -653,6 +658,45 @@ int open_file(const char* name)
  return 0;
}

/* ugly long name, but we are following the convention */
int do_wait_for_slave_to_stop(struct st_query* __attribute__((unused)) q)
{
  MYSQL* mysql = &cur_con->mysql;
#ifndef OS2 
  struct timeval t;
#endif
  for (;;)
  {
    MYSQL_RES* res;
    MYSQL_ROW row;
    int done;
    LINT_INIT(res);
    
    if (mysql_query(mysql,"show status like 'Slave_running'")
	|| !(res=mysql_store_result(mysql)))
      die("Query failed while probing slave for stop: %s",
	  mysql_error(mysql));
    if (!(row=mysql_fetch_row(res)) || !row[1])
    {
      mysql_free_result(res);
      die("Strange result from query while probing slave for stop");
    }
    done = !strcmp(row[1],"OFF");
    mysql_free_result(res);
    if (done)
      break;
#ifndef OS2  
    t.tv_sec=0;
    t.tv_usec=SLAVE_POLL_INTERVAL;
    select(0,0,0,0,&t); /* sleep */
#else
    DosSleep(OS2_SLAVE_POLL_INTERVAL);
#endif
  }
  
  return 0;
}

int do_require_manager(struct st_query* __attribute__((unused)) q)
{
  if (!manager)
@@ -2335,6 +2379,7 @@ int main(int argc, char** argv)
      case Q_DISABLE_RESULT_LOG: disable_result_log=1; break;
      case Q_SOURCE: do_source(q); break;
      case Q_SLEEP: do_sleep(q); break;
      case Q_WAIT_FOR_SLAVE_TO_STOP: do_wait_for_slave_to_stop(q); break;
      case Q_REQUIRE_MANAGER: do_require_manager(q); break;
#ifndef EMBEDDED_LIBRARY	
      case Q_SERVER_START: do_server_start(q); break;
+4 −1
Original line number Diff line number Diff line
@@ -643,7 +643,10 @@ extern int _my_b_write(IO_CACHE *info,const byte *Buffer,uint Count);
extern int my_b_append(IO_CACHE *info,const byte *Buffer,uint Count);
extern int my_block_write(IO_CACHE *info, const byte *Buffer,
			  uint Count, my_off_t pos);
extern int flush_io_cache(IO_CACHE *info);
extern int _flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);

#define flush_io_cache(info) _flush_io_cache((info),1)

extern int end_io_cache(IO_CACHE *info);
extern uint my_b_fill(IO_CACHE *info);
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
+1 −2
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ master-bin.003
insert into t2 values(1234);
set insert_id=1234;
insert into t2 values(NULL);
slave stop;
set sql_slave_skip_counter=1;
slave start;
purge master logs to 'master-bin.003';
@@ -66,7 +65,7 @@ slave stop;
slave start;
show slave status;
Master_Host	Master_User	Master_Port	Connect_retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_do_db	Replicate_ignore_db	Last_errno	Last_error	Skip_counter	Exec_master_log_pos
127.0.0.1	root	MASTER_PORT	60	master-bin.006	445	mysql-relay-bin.004	1312	master-bin.006	Yes	Yes			0		0	445
127.0.0.1	root	MASTER_PORT	60	master-bin.006	445	mysql-relay-bin.004	1376	master-bin.006	Yes	Yes			0		0	445
lock tables t3 read;
select count(*) from t3 where n >= 4;
count(*)
+1 −3
Original line number Diff line number Diff line
@@ -51,9 +51,7 @@ insert into t2 values(NULL);
connection slave;
sync_with_master;

#the slave may have already stopped, so we ignore the error
--error 0,1199
!slave stop;
wait_for_slave_to_stop;

#restart slave skipping one event
set sql_slave_skip_counter=1;
+19 −3
Original line number Diff line number Diff line
@@ -808,13 +808,19 @@ int my_b_append(register IO_CACHE *info, const byte *Buffer, uint Count)
  Buffer+=rest_length;
  Count-=rest_length;
  info->write_pos+=rest_length;
  if (flush_io_cache(info))
  if (_flush_io_cache(info,0))
  {
    unlock_append_buffer(info);
    return 1;
  }
  if (Count >= IO_SIZE)
  {					/* Fill first intern buffer */
    length=Count & (uint) ~(IO_SIZE-1);
    if (my_write(info->file,Buffer,(uint) length,info->myflags | MY_NABP))
    {
      unlock_append_buffer(info);
      return info->error= -1;
    }
    Count-=length;
    Buffer+=length;
  }
@@ -883,14 +889,16 @@ int my_block_write(register IO_CACHE *info, const byte *Buffer, uint Count,

	/* Flush write cache */

int flush_io_cache(IO_CACHE *info)
int _flush_io_cache(IO_CACHE *info, int need_append_buffer_lock)
{
  uint length;
  my_bool append_cache;
  my_off_t pos_in_file;
  DBUG_ENTER("flush_io_cache");

  append_cache = (info->type == SEQ_READ_APPEND);
  if (!(append_cache = (info->type == SEQ_READ_APPEND)))
    need_append_buffer_lock=0;
  
  if (info->type == WRITE_CACHE || append_cache)
  {
    if (info->file == -1)
@@ -898,6 +906,8 @@ int flush_io_cache(IO_CACHE *info)
      if (real_open_cached_file(info))
	DBUG_RETURN((info->error= -1));
    }
    if (need_append_buffer_lock)
      lock_append_buffer(info);
    if ((length=(uint) (info->write_pos - info->write_buffer)))
    {
      pos_in_file=info->pos_in_file;
@@ -909,6 +919,8 @@ int flush_io_cache(IO_CACHE *info)
	if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) ==
	    MY_FILEPOS_ERROR)
	{
	  if (need_append_buffer_lock)
	    unlock_append_buffer(info);
	  DBUG_RETURN((info->error= -1));
	}
	if (!append_cache)
@@ -932,6 +944,8 @@ int flush_io_cache(IO_CACHE *info)
	info->end_of_file+=(info->write_pos-info->append_read_pos);
      
      info->append_read_pos=info->write_pos=info->write_buffer;
      if (need_append_buffer_lock)
        unlock_append_buffer(info);
      DBUG_RETURN(info->error);
    }
  }
@@ -942,6 +956,8 @@ int flush_io_cache(IO_CACHE *info)
    info->inited=0;
  }
#endif
  if (need_append_buffer_lock)
    unlock_append_buffer(info);
  DBUG_RETURN(0);
}

Loading