mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-09 00:39:54 -06:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user