@@ -483,9 +483,11 @@ get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
483
483
484
484
/*
485
485
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.
487
487
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.
489
491
490
492
Wait a maximum of 30 seconds.
491
493
*/
@@ -494,31 +496,47 @@ static void ndbcluster_binlog_wait(THD *thd)
494
496
if (ndb_binlog_running)
495
497
{
496
498
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);
504
500
505
501
/*
506
502
Binlog Injector should not wait for itself
507
503
*/
508
- if (thd &&
509
- thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
504
+ if (thd->system_thread == SYSTEM_THREAD_NDBCLUSTER_BINLOG)
510
505
DBUG_VOID_RETURN;
511
506
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 "
516
519
" reach current position" ;
520
+
517
521
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
+
518
536
pthread_mutex_lock (&injector_mutex);
519
- while (!( thd && thd ->killed ) && count && ndb_binlog_running &&
537
+ while (!thd->killed && count && ndb_binlog_running &&
520
538
(ndb_latest_handled_binlog_epoch == 0 ||
521
- ndb_latest_handled_binlog_epoch < wait_epoch ))
539
+ ndb_latest_handled_binlog_epoch < session_last_committed_epoch ))
522
540
{
523
541
count--;
524
542
struct timespec abstime;
@@ -532,16 +550,15 @@ static void ndbcluster_binlog_wait(THD *thd)
532
550
sql_print_warning (" NDB: Thread id %llu timed out (30s) waiting for epoch %u/%u "
533
551
" to be handled. Progress : %u/%u -> %u/%u." ,
534
552
(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 ),
537
555
Uint32 ((start_handled_epoch >> 32 ) & 0xffffffff ),
538
556
Uint32 (start_handled_epoch & 0xffffffff ),
539
557
Uint32 ((ndb_latest_handled_binlog_epoch >> 32 ) & 0xffffffff ),
540
558
Uint32 (ndb_latest_handled_binlog_epoch & 0xffffffff ));
541
559
}
542
560
543
- if (thd)
544
- thd->proc_info = save_info;
561
+ thd->proc_info = save_info;
545
562
DBUG_VOID_RETURN;
546
563
}
547
564
}
@@ -913,8 +930,9 @@ static void ndbcluster_reset_slave(THD *thd)
913
930
914
931
/* *
915
932
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.
918
936
*/
919
937
static bool ndbcluster_flush_logs (handlerton *hton)
920
938
{
0 commit comments