From 31dd24f902d081e50f16a19d5fb3d7b0fdfae5b5 Mon Sep 17 00:00:00 2001 From: lidezhu <47731263+lidezhu@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:14:01 +0800 Subject: [PATCH] barrier(ticdc): fix wrong barrier ts under frequent ddl scenario (#10669) close pingcap/tiflow#10668 --- cdc/owner/ddl_manager.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cdc/owner/ddl_manager.go b/cdc/owner/ddl_manager.go index a603469436c..c2cecc367b4 100644 --- a/cdc/owner/ddl_manager.go +++ b/cdc/owner/ddl_manager.go @@ -456,7 +456,20 @@ func (m *ddlManager) barrier() *schedulepb.BarrierWithMinTs { // barrier related physical tables ids := getRelatedPhysicalTableIDs(ddl) for _, id := range ids { - tableBarrierMap[id] = ddl.CommitTs + // The same physical table may have multiple related ddl events when calculating barrier. + // Example cases: + // 1. The logical id of the same partition table may change after change partition. + // So the related ddls may be considered for different tables. + // And they may be returned by `getAllTableNextDDL` at the same time. + // 2. The result of `getAllTableNextDDL` may influence the same physical tables as `ddlManager.justSentDDL`. + // So we always choose the min commitTs of all ddls related to the same physical table as the barrierTs. + if ts, ok := tableBarrierMap[id]; ok { + if ddl.CommitTs < ts { + tableBarrierMap[id] = ddl.CommitTs + } + } else { + tableBarrierMap[id] = ddl.CommitTs + } } } }