@@ -467,9 +467,11 @@ get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
467
467
468
468
/*
469
469
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.
471
471
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.
473
475
474
476
Wait a maximum of 30 seconds.
475
477
*/
@@ -478,31 +480,47 @@ static void ndbcluster_binlog_wait(THD *thd)
478
480
if (ndb_binlog_running)
479
481
{
480
482
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);
488
484
489
485
/*
490
486
Binlog Injector should not wait for itself
491
487
*/
492
- if (thd &&
493
- thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
488
+ if (thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
494
489
DBUG_VOID_RETURN;
495
490
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 "
500
503
" reach current position" ;
504
+
501
505
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
+
502
520
pthread_mutex_lock (&injector_mutex);
503
- while (!( thd && thd ->killed ) && count && ndb_binlog_running &&
521
+ while (!thd->killed && count && ndb_binlog_running &&
504
522
(ndb_latest_handled_binlog_epoch == 0 ||
505
- ndb_latest_handled_binlog_epoch < wait_epoch ))
523
+ ndb_latest_handled_binlog_epoch < session_last_committed_epoch ))
506
524
{
507
525
count--;
508
526
struct timespec abstime;
@@ -516,16 +534,15 @@ static void ndbcluster_binlog_wait(THD *thd)
516
534
sql_print_warning (" NDB: Thread id %llu timed out (30s) waiting for epoch %u/%u "
517
535
" to be handled. Progress : %u/%u -> %u/%u." ,
518
536
(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 ),
521
539
Uint32 ((start_handled_epoch >> 32 ) & 0xffffffff ),
522
540
Uint32 (start_handled_epoch & 0xffffffff ),
523
541
Uint32 ((ndb_latest_handled_binlog_epoch >> 32 ) & 0xffffffff ),
524
542
Uint32 (ndb_latest_handled_binlog_epoch & 0xffffffff ));
525
543
}
526
544
527
- if (thd)
528
- thd->proc_info = save_info;
545
+ thd->proc_info = save_info;
529
546
DBUG_VOID_RETURN;
530
547
}
531
548
}
@@ -860,8 +877,9 @@ static void ndbcluster_reset_slave(THD *thd)
860
877
861
878
/* *
862
879
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.
865
883
*/
866
884
static bool ndbcluster_flush_logs (handlerton *hton)
867
885
{
0 commit comments