Skip to content

Commit 9012c63

Browse files
author
Maitrayi Sabaratnam
committed
bug#19793475 - NO WAIT FOR EPOCHS THAT HAVE NO DB CHANGES MADE BY THIS NDB THD TO BE IN BINLOG
Ensure the most recent data changes made by the current thread to Ndb (session_last_committed_epoch) instead of those made by all threads (server_last_committed_epoch) to be flushed to Binlog.
1 parent 6c3b9f2 commit 9012c63

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

mysql-test/suite/ndb_binlog/t/ndb_binlog_discover.test

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ select * from t1;
4343
--source include/show_binlog_events2.inc
4444
PURGE MASTER LOGS TO 'mysqld-bin.000002';
4545

46+
--source include/wait_for_ndb_committed_to_binlog.inc
4647
--source include/show_binlog_events2.inc
4748
drop table t1;

mysql-test/suite/ndb_rpl/r/ndb_rpl_circular.result

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ insert into t1 values (1,1);
102102
select server_id, log_name from mysql.ndb_apply_status order by server_id;
103103
server_id log_name
104104
1 master-bin.000001
105-
show binlog events;
106105
'Slave' has following ndb_binlog_index entries
107106
select inserts, updates, deletes, schemaops, orig_server_id from mysql.ndb_binlog_index order by position;
108107
inserts updates deletes schemaops orig_server_id

mysql-test/suite/ndb_rpl/t/ndb_rpl_circular.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ insert into t1 values (1,1);
105105
select server_id, log_name from mysql.ndb_apply_status order by server_id;
106106

107107
--disable_result_log
108-
show binlog events;
108+
--source include/wait_for_ndb_committed_to_binlog.inc
109109
--enable_result_log
110110
--echo 'Slave' has following ndb_binlog_index entries
111111
select inserts, updates, deletes, schemaops, orig_server_id from mysql.ndb_binlog_index order by position;

sql/ha_ndbcluster_binlog.cc

+41-23
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,11 @@ get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
483483

484484
/*
485485
called in mysql_show_binlog_events and reset_logs to make sure we wait for
486-
all events originating from this mysql server to arrive in the binlog
486+
all events originating from the 'thd' to arrive in the binlog.
487487
488-
Wait for the last epoch in which the last transaction is a part of.
488+
'thd' is expected to be non-NULL.
489+
490+
Wait for the epoch in which the last transaction of the 'thd' is a part of.
489491
490492
Wait a maximum of 30 seconds.
491493
*/
@@ -494,31 +496,47 @@ static void ndbcluster_binlog_wait(THD *thd)
494496
if (ndb_binlog_running)
495497
{
496498
DBUG_ENTER("ndbcluster_binlog_wait");
497-
ulonglong wait_epoch= ndb_get_latest_trans_gci();
498-
/*
499-
cluster not connected or no transactions done
500-
so nothing to wait for
501-
*/
502-
if (!wait_epoch)
503-
DBUG_VOID_RETURN;
499+
DBUG_ASSERT(thd);
504500

505501
/*
506502
Binlog Injector should not wait for itself
507503
*/
508-
if (thd &&
509-
thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
504+
if (thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
510505
DBUG_VOID_RETURN;
511506

512-
const char *save_info= thd ? thd->proc_info : 0;
513-
int count= 30;
514-
if (thd)
515-
thd->proc_info= "Waiting for ndbcluster binlog update to "
507+
Thd_ndb *thd_ndb = get_thd_ndb(thd);
508+
if (!thd_ndb)
509+
{
510+
/*
511+
thd has not interfaced with ndb before
512+
so there is no need for waiting
513+
*/
514+
DBUG_VOID_RETURN;
515+
}
516+
517+
const char *save_info = thd->proc_info;
518+
thd->proc_info = "Waiting for ndbcluster binlog update to "
516519
"reach current position";
520+
517521
const Uint64 start_handled_epoch = ndb_latest_handled_binlog_epoch;
522+
/*
523+
Highest epoch that a transaction against Ndb has received
524+
as part of commit processing *in this thread*. This is a
525+
per-session 'most recent change' indicator.
526+
*/
527+
const Uint64 session_last_committed_epoch =
528+
thd_ndb->m_last_commit_epoch_session;
529+
530+
/*
531+
* Wait until the last committed epoch from the session enters Binlog.
532+
* Break any possible deadlock after 30s.
533+
*/
534+
int count = 30;
535+
518536
pthread_mutex_lock(&injector_mutex);
519-
while (!(thd && thd->killed) && count && ndb_binlog_running &&
537+
while (!thd->killed && count && ndb_binlog_running &&
520538
(ndb_latest_handled_binlog_epoch == 0 ||
521-
ndb_latest_handled_binlog_epoch < wait_epoch))
539+
ndb_latest_handled_binlog_epoch < session_last_committed_epoch))
522540
{
523541
count--;
524542
struct timespec abstime;
@@ -532,16 +550,15 @@ static void ndbcluster_binlog_wait(THD *thd)
532550
sql_print_warning("NDB: Thread id %llu timed out (30s) waiting for epoch %u/%u "
533551
"to be handled. Progress : %u/%u -> %u/%u.",
534552
(ulonglong) thd->thread_id,
535-
Uint32((wait_epoch >> 32) & 0xffffffff),
536-
Uint32(wait_epoch & 0xffffffff),
553+
Uint32((session_last_committed_epoch >> 32) & 0xffffffff),
554+
Uint32(session_last_committed_epoch & 0xffffffff),
537555
Uint32((start_handled_epoch >> 32) & 0xffffffff),
538556
Uint32(start_handled_epoch & 0xffffffff),
539557
Uint32((ndb_latest_handled_binlog_epoch >> 32) & 0xffffffff),
540558
Uint32(ndb_latest_handled_binlog_epoch & 0xffffffff));
541559
}
542560

543-
if (thd)
544-
thd->proc_info= save_info;
561+
thd->proc_info= save_info;
545562
DBUG_VOID_RETURN;
546563
}
547564
}
@@ -913,8 +930,9 @@ static void ndbcluster_reset_slave(THD *thd)
913930

914931
/**
915932
Upon the sql command flush logs, we need to ensure that all outstanding
916-
ndb data to be logged has made it to the binary log to get a deterministic
917-
behavior on the rotation of the log.
933+
changes made to ndb by the current thread have entered the binary log
934+
in order to get a deterministic behavior on the rotation of the log.
935+
'current_thd' should not be NULL.
918936
*/
919937
static bool ndbcluster_flush_logs(handlerton *hton)
920938
{

0 commit comments

Comments
 (0)