From: Date: February 6 2007 10:06pm Subject: bk commit into 5.1 tree (msvensson:1.2425) BUG#26015 List-Archive: http://lists.mysql.com/commits/19448 X-Bug: 26015 Message-Id: <200702062106.l16L6IWb023189@pilot> Below is the list of changes that have just been committed into a local 5.1 repository of msvensson. When msvensson does a push these changes will be propagated 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://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-02-06 22:06:13+01:00, msvensson@stripped +1 -0 Bug#26015 valgrind warning PollGuard::unlock_and_signal()/NdbCondition_Destroy - Add variable "ndbcluster_binlog_terminating" and use that to signal the cluster binlog thread it's time to shutdown. This allows exact control of when the thread shutdown, previous implementation would start shutdown of the thread as soon as the mysqld started shutdown. Now we will shutdown cluster binlog thread in 'ndbcluster_binlog_end' sql/ha_ndbcluster_binlog.cc@stripped, 2007-02-06 22:06:11+01:00, msvensson@stripped +23 -60 Make binlog thread shutdown controllable by using a separet variable to communicate the order to shutdown # 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: msvensson # Host: pilot.mysql.com # Root: /home/msvensson/mysql/my51-ndb_poll_guard --- 1.101/sql/ha_ndbcluster_binlog.cc 2007-02-06 06:42:08 +01:00 +++ 1.102/sql/ha_ndbcluster_binlog.cc 2007-02-06 22:06:11 +01:00 @@ -81,6 +81,7 @@ static Ndb *schema_ndb= 0; static int ndbcluster_binlog_inited= 0; +static int ndbcluster_binlog_terminating= 0; /* Mutex and condition used for interacting between client sql thread @@ -582,61 +583,18 @@ #ifdef HAVE_NDB_BINLOG /* wait for injector thread to finish */ + ndbcluster_binlog_terminating= 1; + pthread_cond_signal(&injector_cond); pthread_mutex_lock(&injector_mutex); - if (ndb_binlog_thread_running > 0) - { - pthread_cond_signal(&injector_cond); - pthread_mutex_unlock(&injector_mutex); - - pthread_mutex_lock(&injector_mutex); - while (ndb_binlog_thread_running > 0) - { - struct timespec abstime; - set_timespec(abstime, 1); - pthread_cond_timedwait(&injector_cond, &injector_mutex, &abstime); - } - } + while (ndb_binlog_thread_running > 0) + pthread_cond_wait(&injector_cond, &injector_mutex); pthread_mutex_unlock(&injector_mutex); - - /* remove all shares */ - { - pthread_mutex_lock(&ndbcluster_mutex); - for (uint i= 0; i < ndbcluster_open_tables.records; i++) - { - NDB_SHARE *share= - (NDB_SHARE*) hash_element(&ndbcluster_open_tables, i); - if (share->table) - DBUG_PRINT("share", - ("table->s->db.table_name: %s.%s", - share->table->s->db.str, share->table->s->table_name.str)); - /* ndb_share reference create free */ - if (share->state != NSS_DROPPED) - { - DBUG_PRINT("NDB_SHARE", ("%s create free use_count: %u", - share->key, share->use_count)); - --share->use_count; - } - if (share->use_count == 0) - ndbcluster_real_free_share(&share); - else - { - DBUG_PRINT("share", - ("[%d] 0x%lx key: %s key_length: %d", - i, (long) share, share->key, share->key_length)); - DBUG_PRINT("share", - ("db.tablename: %s.%s use_count: %d commit_count: %lu", - share->db, share->table_name, - share->use_count, (long) share->commit_count)); - } - } - pthread_mutex_unlock(&ndbcluster_mutex); - } - pthread_mutex_destroy(&injector_mutex); pthread_cond_destroy(&injector_cond); pthread_mutex_destroy(&ndb_schema_share_mutex); #endif + DBUG_RETURN(0); } @@ -2385,7 +2343,6 @@ if (ndb_binlog_thread_running < 0) DBUG_RETURN(-1); - DBUG_RETURN(0); } @@ -3562,6 +3519,9 @@ s_ndb->init()) { sql_print_error("NDB Binlog: Getting Schema Ndb object failed"); + ndb_binlog_thread_running= -1; + pthread_mutex_unlock(&injector_mutex); + pthread_cond_signal(&injector_cond); goto err; } @@ -3592,7 +3552,7 @@ p_latest_trans_gci= injector_ndb->get_ndb_cluster_connection().get_latest_trans_gci(); schema_ndb= s_ndb; - ndb_binlog_thread_running= 1; + if (opt_bin_log) { if (global_system_variables.binlog_format == BINLOG_FORMAT_ROW || @@ -3605,10 +3565,9 @@ sql_print_error("NDB: only row based binary logging is supported"); } } - /* - We signal the thread that started us that we've finished - starting up. - */ + + /* Thread start up completed */ + ndb_binlog_thread_running= 1; pthread_mutex_unlock(&injector_mutex); pthread_cond_signal(&injector_cond); @@ -3627,7 +3586,7 @@ struct timespec abstime; set_timespec(abstime, 1); pthread_cond_timedwait(&injector_cond, &injector_mutex, &abstime); - if (abort_loop) + if (ndbcluster_binlog_terminating) { pthread_mutex_unlock(&injector_mutex); goto err; @@ -3652,13 +3611,15 @@ { // wait for the first event thd->proc_info= "Waiting for first event from ndbcluster"; - DBUG_PRINT("info", ("Waiting for the first event")); int schema_res, res; Uint64 schema_gci; do { - if (abort_loop) + DBUG_PRINT("info", ("Waiting for the first event")); + + if (ndbcluster_binlog_terminating) goto err; + schema_res= s_ndb->pollEvents(100, &schema_gci); } while (schema_gci == 0 || ndb_latest_received_binlog_epoch == schema_gci); if (ndb_binlog_running) @@ -3666,7 +3627,7 @@ Uint64 gci= i_ndb->getLatestGCI(); while (gci < schema_gci || gci == ndb_latest_received_binlog_epoch) { - if (abort_loop) + if (ndbcluster_binlog_terminating) goto err; res= i_ndb->pollEvents(10, &gci); } @@ -3713,7 +3674,8 @@ thd->db= db; } do_ndbcluster_binlog_close_connection= BCCC_running; - for ( ; !((abort_loop || do_ndbcluster_binlog_close_connection) && + for ( ; !((ndbcluster_binlog_terminating || + do_ndbcluster_binlog_close_connection) && ndb_latest_handled_binlog_epoch >= *p_latest_trans_gci) && do_ndbcluster_binlog_close_connection != BCCC_restart; ) { @@ -3760,7 +3722,8 @@ schema_res= s_ndb->pollEvents(10, &schema_gci); } - if ((abort_loop || do_ndbcluster_binlog_close_connection) && + if ((ndbcluster_binlog_terminating || + do_ndbcluster_binlog_close_connection) && (ndb_latest_handled_binlog_epoch >= *p_latest_trans_gci || !ndb_binlog_running)) break; /* Shutting down server */