From 612ecd884d8b028c2b0d8055c58488ec14b360db 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 d3da4031c3f..a99fec7eead 100644 --- a/cdc/owner/ddl_manager.go +++ b/cdc/owner/ddl_manager.go @@ -484,7 +484,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 + } } } }