Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions db/state/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,17 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {

g, ctx := errgroup.WithContext(ctx)
g.SetLimit(a.collateAndBuildWorkers)
for _, d := range a.d {

// Use agg.BeginFilesRo() to safely snapshot visible files under visibleFilesLock,
// instead of calling individual domain/ii BeginFilesRo() without synchronization.
ac := a.BeginFilesRo()
for id, d := range a.d {
if d.Disable {
continue
}

d := d
dc := d.BeginFilesRo()
firstStepNotInFiles := dc.FirstStepNotInFiles()
dc.Close()
firstStepNotInFiles := ac.d[id].FirstStepNotInFiles()
if step < firstStepNotInFiles {
continue
}
Expand Down Expand Up @@ -739,9 +741,7 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
}

ii := ii
dc := ii.BeginFilesRo()
firstStepNotInFiles := dc.FirstStepNotInFiles()
dc.Close()
firstStepNotInFiles := ac.iis[iikey].FirstStepNotInFiles()
if step < firstStepNotInFiles {
continue
}
Expand All @@ -768,6 +768,7 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
return nil
})
}
ac.Close()
if err := g.Wait(); err != nil {
static.CleanupOnError()
return fmt.Errorf("domain collate-build: %w", err)
Expand Down
Loading