Skip to content

Commit

Permalink
/go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Jan 16, 2025
1 parent abfafcb commit 341d8e0
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions go/libraries/doltcore/sqle/dsess/autoincrement_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type AutoIncrementTracker struct {
sequences *sync.Map // map[string]uint64
mm *mutexmap.MutexMap
lockMode LockMode
wg *sync.WaitGroup
init chan struct{}
initErr error
}

Expand All @@ -65,7 +65,7 @@ func NewAutoIncrementTracker(ctx context.Context, dbName string, roots ...doltdb
dbName: dbName,
sequences: &sync.Map{},
mm: mutexmap.NewMutexMap(),
wg: &sync.WaitGroup{},
init: make(chan struct{}),
}
ait.runInitWithRootsAsync(ctx, roots...)
return &ait, nil
Expand Down Expand Up @@ -438,25 +438,17 @@ func (a *AutoIncrementTracker) AcquireTableLock(ctx *sql.Context, tableName stri
}

func (a *AutoIncrementTracker) waitForInit() error {
done := make(chan struct{})

go func() {
defer close(done)
a.wg.Wait()
}()

select {
case <-done:
case <-a.init:
return a.initErr
case <-time.After(5 * time.Minute):
return errors.New("failed to initialize autoincrement tracker")
}
}

func (a *AutoIncrementTracker) runInitWithRootsAsync(ctx context.Context, roots ...doltdb.Rootish) {
a.wg.Add(1)
go func() {
defer a.wg.Done()
defer close(a.init)
a.initErr = a.initWithRoots(ctx, roots...)
}()
}
Expand Down

0 comments on commit 341d8e0

Please sign in to comment.