Skip to content

Commit 1c94e31

Browse files
author
Maitrayi Sabaratnam
committed
Merge 7.3 -> 7.4
2 parents 6278b25 + 9012c63 commit 1c94e31

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
@@ -467,9 +467,11 @@ get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
467467

468468
/*
469469
called in mysql_show_binlog_events and reset_logs to make sure we wait for
470-
all events originating from this mysql server to arrive in the binlog
470+
all events originating from the 'thd' to arrive in the binlog.
471471
472-
Wait for the last epoch in which the last transaction is a part of.
472+
'thd' is expected to be non-NULL.
473+
474+
Wait for the epoch in which the last transaction of the 'thd' is a part of.
473475
474476
Wait a maximum of 30 seconds.
475477
*/
@@ -478,31 +480,47 @@ static void ndbcluster_binlog_wait(THD *thd)
478480
if (ndb_binlog_running)
479481
{
480482
DBUG_ENTER("ndbcluster_binlog_wait");
481-
ulonglong wait_epoch= ndb_get_latest_trans_gci();
482-
/*
483-
cluster not connected or no transactions done
484-
so nothing to wait for
485-
*/
486-
if (!wait_epoch)
487-
DBUG_VOID_RETURN;
483+
DBUG_ASSERT(thd);
488484

489485
/*
490486
Binlog Injector should not wait for itself
491487
*/
492-
if (thd &&
493-
thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
488+
if (thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
494489
DBUG_VOID_RETURN;
495490

496-
const char *save_info= thd ? thd->proc_info : 0;
497-
int count= 30;
498-
if (thd)
499-
thd->proc_info= "Waiting for ndbcluster binlog update to "
491+
Thd_ndb *thd_ndb = get_thd_ndb(thd);
492+
if (!thd_ndb)
493+
{
494+
/*
495+
thd has not interfaced with ndb before
496+
so there is no need for waiting
497+
*/
498+
DBUG_VOID_RETURN;
499+
}
500+
501+
const char *save_info = thd->proc_info;
502+
thd->proc_info = "Waiting for ndbcluster binlog update to "
500503
"reach current position";
504+
501505
const Uint64 start_handled_epoch = ndb_latest_handled_binlog_epoch;
506+
/*
507+
Highest epoch that a transaction against Ndb has received
508+
as part of commit processing *in this thread*. This is a
509+
per-session 'most recent change' indicator.
510+
*/
511+
const Uint64 session_last_committed_epoch =
512+
thd_ndb->m_last_commit_epoch_session;
513+
514+
/*
515+
* Wait until the last committed epoch from the session enters Binlog.
516+
* Break any possible deadlock after 30s.
517+
*/
518+
int count = 30;
519+
502520
pthread_mutex_lock(&injector_mutex);
503-
while (!(thd && thd->killed) && count && ndb_binlog_running &&
521+
while (!thd->killed && count && ndb_binlog_running &&
504522
(ndb_latest_handled_binlog_epoch == 0 ||
505-
ndb_latest_handled_binlog_epoch < wait_epoch))
523+
ndb_latest_handled_binlog_epoch < session_last_committed_epoch))
506524
{
507525
count--;
508526
struct timespec abstime;
@@ -516,16 +534,15 @@ static void ndbcluster_binlog_wait(THD *thd)
516534
sql_print_warning("NDB: Thread id %llu timed out (30s) waiting for epoch %u/%u "
517535
"to be handled. Progress : %u/%u -> %u/%u.",
518536
(ulonglong) thd->thread_id,
519-
Uint32((wait_epoch >> 32) & 0xffffffff),
520-
Uint32(wait_epoch & 0xffffffff),
537+
Uint32((session_last_committed_epoch >> 32) & 0xffffffff),
538+
Uint32(session_last_committed_epoch & 0xffffffff),
521539
Uint32((start_handled_epoch >> 32) & 0xffffffff),
522540
Uint32(start_handled_epoch & 0xffffffff),
523541
Uint32((ndb_latest_handled_binlog_epoch >> 32) & 0xffffffff),
524542
Uint32(ndb_latest_handled_binlog_epoch & 0xffffffff));
525543
}
526544

527-
if (thd)
528-
thd->proc_info= save_info;
545+
thd->proc_info= save_info;
529546
DBUG_VOID_RETURN;
530547
}
531548
}
@@ -860,8 +877,9 @@ static void ndbcluster_reset_slave(THD *thd)
860877

861878
/**
862879
Upon the sql command flush logs, we need to ensure that all outstanding
863-
ndb data to be logged has made it to the binary log to get a deterministic
864-
behavior on the rotation of the log.
880+
changes made to ndb by the current thread have entered the binary log
881+
in order to get a deterministic behavior on the rotation of the log.
882+
'current_thd' should not be NULL.
865883
*/
866884
static bool ndbcluster_flush_logs(handlerton *hton)
867885
{

0 commit comments

Comments
 (0)