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.
This commit is contained in:
Aaron Son
2025-11-14 14:37:39 -08:00
parent 483b9cd064
commit 6cf689f359

View File

@@ -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