From 6cf689f359540a41b3f8b013d442d08bc2ca2cdf Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Fri, 14 Nov 2025 14:37:39 -0800 Subject: [PATCH] go: sqle/dsess: autoincrement_tracker.go: Fix race condition in initialization. When initializing the autoincrement_tracker, we look at the current value of the autoincrement sequence on the table across every branch. We do this concurrently, and take the highest value we find as the initial value to use across the `dolt` run. This fixes a race condition which would cause us to calculate the wrong highest value across all branches. --- .../doltcore/sqle/dsess/autoincrement_tracker.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go b/go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go index c6091da6cc..20b403e477 100644 --- a/go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go +++ b/go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go @@ -550,8 +550,13 @@ func (a *AutoIncrementTracker) initWithRoots(ctx context.Context, roots ...doltd } tableNameStr := tableName.ToLower().Name - if oldValue, loaded := a.sequences.LoadOrStore(tableNameStr, seq); loaded && seq > oldValue.(uint64) { - a.sequences.Store(tableNameStr, seq) + if oldValue, loaded := a.sequences.LoadOrStore(tableNameStr, seq); loaded { + old := oldValue.(uint64) + for seq > old && !a.sequences.CompareAndSwap(tableNameStr, old, seq) { + oldValue, _ = a.sequences.Load(tableNameStr) + old = oldValue.(uint64) + + } } return false, nil