Hi Zhenxing,
On Mon, 2011-01-17 at 11:22 +0800, He Zhenxing wrote:
> Hi Daogang,
>
> I think it's better to only add the sync points in the code and define
> the synchronization policy in the test code, so that we can reuse the
> sync points in other tests and also we can change the synchronization
> logic without changing the code. And also we do not need the
> DBUG_EXECUTE_IF().
>
> I think you can setup three sync points in the code:
>
> bool mysql_insert(...)
> {
> ...
> DEBUG_SYNC(thd, "before_write_delayed");
> error= write_delayed(...);
> DEBUG_SYNC(thd, "after_write_delayed");
debug_sync is a session variable, so we cannot control
handler thread's debug_sync variable in test file.
> ...
> }
>
> bool Delayed_insert::handle_inserts(void)
> {
> ...
> mysql_mutex_lock(&mutex);
> DEBUG_SYNC(thd, "handler_inserts_exist");
> DBUG_RETURN(0);
> }
>
> And then in the test file:
> # this is used to clear the has_inserted flag if it has been signaled to replace
> the 'RESET'
> set DEBUG_SYNC= 'before_write_delayed SIGNAL before_insert';
I agree to this idea.
> set DEBUG_SYNC= 'after_write_delayed WAIT_FOR has_inserted';
> set DEBUG_SYNC= 'handler_inserts_exist SIGNAL has_inserted';
>
>
> daogang.qu@stripped wrote:
> > #At file:///home/daogang/bzrwork/bug58784/mysql-trunk/ based on
> revid:marc.alff@stripped
> >
> > 3454 daogang.qu@stripped 2011-01-14
> > Bug #58784 rpl_row_ignorable_event fails on PB2
> >
> > In RBR, The rows are inserted to a queue by the thread executing
> > the 'INSERT DELAYED' statement, and are taken out from the queue
> > by the handler thread to do the real insertion. Because these two
> > threads are running in parallel, there is a possibility that they
> > are run in an interleaved manner, and result in different number
> > of table_map and rows events.
> >
> > Added 'wait' and 'signal' mechanism for the test to make the
> > binlog of multi 'INSERT DELAYED ...' stmt stable by forcing
> > every value is executed into one execution series, and then
> > each value will be binlogged into a separate rows event with
> > its table map event.
> > @ mysql-test/suite/rpl/r/rpl_row_ignorable_event.result
> > Updated for the patch of bug#58784.
> > @ mysql-test/suite/rpl/t/rpl_row_ignorable_event.test
> > Added debug option for making the binlog of
> > multi 'INSERT DELAYED ...' stmt stable.
> > @ sql/sql_insert.cc
> > Added 'wait' and 'signal' mechanism to make 'INSERT DELAYED'
> > thread wait to insert data into the queue until the signal
> > is sent from 'HANDLER' thread, after the last row from the
> > queue is taken out and executed.
> >
> > modified:
> > mysql-test/suite/rpl/r/rpl_row_ignorable_event.result
> > mysql-test/suite/rpl/t/rpl_row_ignorable_event.test
> > sql/sql_insert.cc
> > === modified file 'mysql-test/suite/rpl/r/rpl_row_ignorable_event.result'
> > --- a/mysql-test/suite/rpl/r/rpl_row_ignorable_event.result 2010-12-19 17:22:30
> +0000
> > +++ b/mysql-test/suite/rpl/r/rpl_row_ignorable_event.result 2011-01-14 02:21:46
> +0000
> > @@ -1,7 +1,5 @@
> > include/master-slave.inc
> > [connection master]
> > -SET @old_debug= @@global.debug;
> > -SET GLOBAL debug="+d,waiting_for_delayed_insert_queue_is_empty";
> > # Test non-transaction
> > create table t1(a int, b int) engine= myisam;
> > insert into t1(a,b) values(1,1),(2,1);
> > @@ -38,6 +36,9 @@ insert into t5(a, b) values(3,1);
> > # Test the Rows_query log event will be filtered out if slave filters
> > # out all its related tables by replication filtering rules
> > update t4,t5 set t4.a=4, t5.a=5 where t4.b=t5.b;
> > +SET @old_debug= @@global.debug;
> > +SET GLOBAL debug="+d,after_handle_inserts";
> > +SET debug="+d,after_write_delayed";
> > # Test insert delayed ...
> > insert delayed into t3(a,b) values(1,5),(1,6),(1,7);
> > SET @@global.debug= @old_debug;
> >
> > === modified file 'mysql-test/suite/rpl/t/rpl_row_ignorable_event.test'
> > --- a/mysql-test/suite/rpl/t/rpl_row_ignorable_event.test 2010-12-19 17:22:30
> +0000
> > +++ b/mysql-test/suite/rpl/t/rpl_row_ignorable_event.test 2011-01-14 02:21:46
> +0000
> > @@ -13,8 +13,6 @@ source include/have_binlog_rows_query.in
> > source include/have_innodb.inc;
> > source include/have_debug.inc;
> >
> > -SET @old_debug= @@global.debug;
> > -SET GLOBAL debug="+d,waiting_for_delayed_insert_queue_is_empty";
> > --echo # Test non-transaction
> > let $binlog_start= query_get_value("SHOW MASTER STATUS", Position, 1);
> > let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
> > @@ -60,6 +58,9 @@ insert into t5(a, b) values(3,1);
> > --echo # out all its related tables by replication filtering rules
> > update t4,t5 set t4.a=4, t5.a=5 where t4.b=t5.b;
> >
> > +SET @old_debug= @@global.debug;
> > +SET GLOBAL debug="+d,after_handle_inserts";
> > +SET debug="+d,after_write_delayed";
> > --echo # Test insert delayed ...
> > let $table=t3;
> > insert delayed into t3(a,b) values(1,5),(1,6),(1,7);
> >
> > === modified file 'sql/sql_insert.cc'
> > --- a/sql/sql_insert.cc 2010-12-22 13:23:59 +0000
> > +++ b/sql/sql_insert.cc 2011-01-14 02:21:46 +0000
> > @@ -75,6 +75,7 @@
> > #include "rpl_mi.h"
> > #include "transaction.h"
> > #include "sql_audit.h"
> > +#include "debug_sync.h"
> >
> > #ifndef EMBEDDED_LIBRARY
> > static bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,
> > @@ -2345,8 +2346,6 @@ int write_delayed(THD *thd, TABLE *table
> > (ulong) query.length));
> >
> > thd_proc_info(thd, "waiting for handler insert");
> > - DBUG_EXECUTE_IF("waiting_for_delayed_insert_queue_is_empty",
> > - while(di->stacked_inserts) sleep(1););
> > mysql_mutex_lock(&di->mutex);
> > while (di->stacked_inserts >= delayed_queue_size &&
> !thd->killed)
> > mysql_cond_wait(&di->cond_client, &di->mutex);
> > @@ -2438,6 +2437,23 @@ int write_delayed(THD *thd, TABLE *table
> >
> > thread_safe_increment(delayed_rows_in_use,&LOCK_delayed_status);
> > mysql_mutex_unlock(&di->mutex);
> > + DBUG_EXECUTE_IF("after_write_delayed",
> > + {
> > + const char act[]=
> > + "now "
> > + "wait_for has_inserted";
> > + DBUG_ASSERT(opt_debug_sync_timeout > 0);
> > + DBUG_ASSERT(!debug_sync_set_action(current_thd,
> > + STRING_WITH_LEN(act)));
> > + };);
> > + DBUG_EXECUTE_IF("after_write_delayed",
> > + {
> > + const char act[]=
> > + "reset";
> > + DBUG_ASSERT(opt_debug_sync_timeout > 0);
> > + DBUG_ASSERT(!debug_sync_set_action(current_thd,
> > + STRING_WITH_LEN(act)));
> > + };);
> > DBUG_RETURN(0);
> >
> > err:
> > @@ -3104,6 +3120,15 @@ bool Delayed_insert::handle_inserts(void
> > }
> > query_cache_invalidate3(&thd, table, 1);
> > mysql_mutex_lock(&mutex);
> > + DBUG_EXECUTE_IF("after_handle_inserts",
> > + {
> > + const char act[]=
> > + "now "
> > + "signal has_inserted";
> > + DBUG_ASSERT(opt_debug_sync_timeout > 0);
> > + DBUG_ASSERT(!debug_sync_set_action(current_thd,
> > + STRING_WITH_LEN(act)));
> > + };);
> > DBUG_RETURN(0);
> >
> > err:
>
>
>
--
Your Sincerely,
Libing Song
==================================
MySQL Replication Team
Software Engineer
Email : Anders.Song@stripped
Skype : libing.song
MSN : slb_database@stripped
Phone : +86 010-6505-4020 ext. 319
Mobile: +86 138-1144-2038
==================================