From: Jonas Oreland Date: February 9 2011 7:57am Subject: Re: bzr commit into mysql-5.5-telco-7.0 branch (magnus.blaudd:3195) List-Archive: http://lists.mysql.com/commits/130801 Message-Id: <4D5248D8.90902@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit super... On 02/09/11 08:58, Magnus Blćudd wrote: > #At file:///home/msvensson/mysql/5.5-telco-7.0-run-query/ based on revid:magnus.blaudd@stripped > > 3195 Magnus BlĂ„udd 2011-02-09 > ndb > - Straigthen up the interface of ndb_binlog allowing to hide its internals > -- Rename ndbcluster_setup_binlog_table_shares to ndb_binlog_setup and > make it return true or false for sucess/fail > -- Make "ndb_binlog_tables_inited" variable local to ha_ndbcluster_binlog > -- Add function ndb_binlog_is_read_only() which return false as long as the > binlog is not ready and we only allow to open tables in read only mode. > -- Make "ndb_binlog_is_ready" variable local to ha_ndbcluster_binlog > -- Remove the first call to ndb_binlog_setup, calling it once > every second until it succeeds and regularly thereafter should be enough. > > modified: > sql/ha_ndbcluster.cc > sql/ha_ndbcluster_binlog.cc > sql/ha_ndbcluster_binlog.h > === modified file 'sql/ha_ndbcluster.cc' > --- a/sql/ha_ndbcluster.cc 2011-02-09 07:28:54 +0000 > +++ b/sql/ha_ndbcluster.cc 2011-02-09 07:58:07 +0000 > @@ -9696,8 +9696,7 @@ int ha_ndbcluster::open(const char *name > local_close(thd, TRUE); > DBUG_RETURN(res); > } > - if (!ndb_binlog_tables_inited || > - (ndb_binlog_running && !ndb_binlog_is_ready)) > + if (ndb_binlog_is_read_only()) > { > table->db_stat|= HA_READ_ONLY; > sql_print_information("table '%s' opened read only", name); > @@ -13125,8 +13124,6 @@ pthread_handler_t ndb_util_thread_func(v > > if (opt_ndb_extra_logging && ndb_binlog_running) > sql_print_information("NDB Binlog: Ndb tables initially read only."); > - /* create tables needed by the replication */ > - ndbcluster_setup_binlog_table_shares(thd); > > set_timespec(abstime, 0); > for (;;) > @@ -13145,23 +13142,28 @@ pthread_handler_t ndb_util_thread_func(v > #endif > > /* > - Check that the ndb_apply_status_share and ndb_schema_share > - have been created. > - If not try to create it > + Check if the Ndb object in thd_ndb is still valid(it will be > + invalid if connection to cluster has been lost) and recycle > + it if necessary. > */ > if (!check_ndb_in_thd(thd, false)) > { > set_timespec(abstime, 1); > continue; > } > - if (!ndb_binlog_tables_inited) > + > + /* > + Regularly give the ndb_binlog component chance to set it self up > + i.e at first start it needs to create the ndb_* system tables > + and setup event operations on those. In case of lost connection > + to cluster, the ndb_* system tables are hopefully still there > + but the event operations need to be recreated. > + */ > + if (!ndb_binlog_setup(thd)) > { > - ndbcluster_setup_binlog_table_shares(thd); > - if (!ndb_binlog_tables_inited) > - { > - set_timespec(abstime, 1); > - continue; > - } > + /* Failed to setup binlog, try again in 1 second */ > + set_timespec(abstime, 1); > + continue; > } > > if (opt_ndb_cache_check_time == 0) > > === modified file 'sql/ha_ndbcluster_binlog.cc' > --- a/sql/ha_ndbcluster_binlog.cc 2011-02-08 10:11:09 +0000 > +++ b/sql/ha_ndbcluster_binlog.cc 2011-02-09 07:58:07 +0000 > @@ -74,8 +74,29 @@ static int ndb_binlog_thread_running= 0; > FALSE if not > */ > my_bool ndb_binlog_running= FALSE; > -my_bool ndb_binlog_tables_inited= FALSE; > -my_bool ndb_binlog_is_ready= FALSE; > +static my_bool ndb_binlog_tables_inited= FALSE; > +static my_bool ndb_binlog_is_ready= FALSE; > + > +bool > +ndb_binlog_is_read_only(void) > +{ > + if(!ndb_binlog_tables_inited) > + { > + /* the ndb_* system tables not setup yet */ > + return true; > + } > + > + if (ndb_binlog_running && !ndb_binlog_is_ready) > + { > + /* > + The binlog thread is supposed to write to binlog > + but not ready (still initializing or has lost connection) > + */ > + return true; > + } > + return false; > +} > + > /* > Global reference to the ndb injector thread THD oject > > @@ -1553,11 +1574,15 @@ static int ndbcluster_find_all_databases > } > } > > -int ndbcluster_setup_binlog_table_shares(THD *thd) > +bool > +ndb_binlog_setup(THD *thd) > { > + if (ndb_binlog_tables_inited) > + return true; // Already setup -> OK > + > Ndbcluster_global_schema_lock_guard global_schema_lock_guard(thd); > if (global_schema_lock_guard.lock()) > - return 1; > + return false; > if (!ndb_schema_share && > ndbcluster_check_ndb_schema_share() == 0) > { > @@ -1567,7 +1592,7 @@ int ndbcluster_setup_binlog_table_shares > ndbcluster_create_schema_table(thd); > // always make sure we create the 'schema' first > if (!ndb_schema_share) > - return 1; > + return false; > } > } > if (!ndb_apply_status_share && > @@ -1578,13 +1603,13 @@ int ndbcluster_setup_binlog_table_shares > { > ndbcluster_create_ndb_apply_status_table(thd); > if (!ndb_apply_status_share) > - return 1; > + return false; > } > } > > if (ndbcluster_find_all_databases(thd)) > { > - return 1; > + return false; > } > > if (!ndbcluster_find_all_files(thd)) > @@ -1605,8 +1630,10 @@ int ndbcluster_setup_binlog_table_shares > } > /* Signal injector thread that all is setup */ > pthread_cond_signal(&injector_cond); > + > + return true; // Setup completed -> OK > } > - return 0; > + return false; > } > > /* > > === modified file 'sql/ha_ndbcluster_binlog.h' > --- a/sql/ha_ndbcluster_binlog.h 2011-02-08 10:11:09 +0000 > +++ b/sql/ha_ndbcluster_binlog.h 2011-02-09 07:58:07 +0000 > @@ -249,13 +249,27 @@ int ndb_create_table_from_engine(THD *th > const char *table_name); > int ndbcluster_binlog_start(); > > -int ndbcluster_setup_binlog_table_shares(THD *thd); > + > +/* > + Setup function for the ndb binlog component. The function should be > + called on startup until it succeeds(to allow initial setup) and with > + regular intervals afterwards to reconnect after a lost cluster > + connection > +*/ > +bool ndb_binlog_setup(THD *thd); > + > +/* > + Will return true when the ndb binlog component is properly setup > + and ready to receive events from the cluster. As long as function > + returns false, all tables in this MySQL Server are opened in read only > + mode to avoid writes before the binlog is ready to record them. > + */ > +bool ndb_binlog_is_read_only(void); > + > extern NDB_SHARE *ndb_apply_status_share; > extern NDB_SHARE *ndb_schema_share; > > extern my_bool ndb_binlog_running; > -extern my_bool ndb_binlog_tables_inited; > -extern my_bool ndb_binlog_is_ready; > > bool > ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print, > > > > >