Repository navigation
fix(table): fix race condition in scanner - #445
Merged
Merged
Conversation
zeroshade
pushed a commit
that referenced
this pull request
Apr 29, 2026
) ## Problem Two evaluator types share a receiver across concurrent goroutine calls, causing data races detected by `-race`. **Race 1 — `exprEvaluator.Eval`** (`visitors.go`) `table.Scan.collectManifestEntries` fans out manifest opens via `errgroup` (`scanner.go`), and each goroutine calls the bound `*exprEvaluator.Eval` method value returned by `ExpressionEvaluator`. `Eval` writes the per-call `StructLike` to the receiver's shared `st` field (`e.st = st`). Because the `*exprEvaluator` is shared across the goroutine pool, parallel `Eval` calls race on `e.st`. **Race 2 — `manifestEvalVisitor.Eval`** (`table/evaluators.go`) `newManifestEvaluator` returns a closure that captures a shared `*manifestEvalVisitor`. When multiple goroutines call that closure concurrently (e.g. the `errgroup` in `classifyFilesForFilteredDeletions` and parallel manifest scans in `collectManifestEntries`), they race on the `partitionFields` write in `Eval` vs. the reads inside `VisitLess`/`VisitGreater`. ## Fix Both fixes mirror the approach used in #445 (closes #443) for `inclusiveMetricsEval`: instead of mutating the shared receiver, `Eval` builds a per-call stack-local copy of the visitor and passes `&ev` to `VisitExpr`. The captured receiver is read-only after construction; all per-call mutable state lives in the local copy. ```go // exprEvaluator func (e *exprEvaluator) Eval(st StructLike) (bool, error) { ev := exprEvaluator{bound: e.bound, st: st} return VisitExpr(ev.bound, &ev) } // manifestEvalVisitor func (m *manifestEvalVisitor) Eval(manifest iceberg.ManifestFile) (bool, error) { parts := manifest.Partitions() if len(parts) == 0 { return rowsMightMatch, nil } ev := manifestEvalVisitor{partitionFields: parts, partitionFilter: m.partitionFilter} return VisitExpr(ev.partitionFilter, &ev) } ``` No API changes. ## Testing - Adds `TestManifestEvalVisitorEvalRace` in `table/evaluator_race_test.go`: 256 goroutines share one cached evaluator closure and call it concurrently. Confirmed to trip `-race` before the fix and pass after. - Existing `TestKeyDefaultMapRaceCondition` (the only prior race test) still passes. - Full `go test -race ./table/ ./...` passes (pre-existing races in miniohq-specific tests are unrelated). ## Related - Sibling precedent: #445 (closes #443) — same pattern for `inclusiveMetricsEval`. --------- Co-authored-by: Varun Venkatesh <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #443
Eliminates potential race condition in scanning caused by the metrics evaluator used for manifest pruning.
Since the stats are only used for a given run of Eval, we don't need to modify the bound version of the
inclusiveMetricsEvalobject and can instead copy the type and expression (cheap) to populate for the call. This avoids the race condition without giving up performance (no locking needed).