fix(search): contain faults while copying results - #1126
Conversation
keegancsmith
left a comment
There was a problem hiding this comment.
I've never seen this happen in practice. Are you seeing it cause of NFS? I wonder if there is a more fundamental change we can make such that we can treat the shards as proper immutable blobs that we can do a bit of validation on when we load it up.
I have a feeling for a normal FS if we successfully find a match, this part of the code should continue to work.
|
|
||
| logShardCrash("copy", shard, q, recovered, stack) | ||
| ss.shardRepairs.schedule(shard) | ||
| return |
There was a problem hiding this comment.
a repo can be in multiple shards.
There was a problem hiding this comment.
Right. I removed repository-based attribution. Each shard result now records one range covering its mmap-backed match pointers; the final copy resolves the exact searched shard after aggregation. Overlapping ranges are treated as ambiguous and do not repair either shard. There is a regression with the same repository present in two shards.
| sr.Stats.Crashes++ | ||
| metricSearchCrashesTotal.Inc() | ||
| if onFault != nil { | ||
| onFault(file, recovered, stack) | ||
| } | ||
| continue |
There was a problem hiding this comment.
definition of Stats.Crashes is the number of shards that crashed, this will increment per file that failed.
There was a problem hiding this comment.
Agreed. Crash deduplication now lives in the request-scoped provenance tracker, so multiple bad matches and multiple StreamSearch repository events from one shard contribute exactly one crash and one metric increment. Both cases are covered.
95b2a54 to
6b4b6c4
Compare
|
On the broader question: yes, the observed failure is AWS EFS over NFSv4.1; #1109 has the production sequence and the two-client control. I agree immutable generation paths are the root fix. Load-time validation alone cannot catch this case because the shard loads successfully and its backing object is invalidated later. This PR is the narrow containment for the remaining copy window while that publication-lifetime issue is separate. |
Summary
FileMatchcopy, where mmap-backed slices are accessed after the per-shard search guard has returnedThis is stacked on #1125 and addresses the remaining late-copy fault window described in #1106. Until #1125 merges, GitHub's comparison against upstream
mainincludes both commits; afterward this PR reduces to the result-copy commit.Behavior
Zoekt intentionally delays copying mmap-backed match data until after aggregation and result limiting. The guard remains at that boundary, so candidates discarded by global limits are not copied.
Each match is copied under a narrowly scoped
debug.SetPanicOnFaultguard. If an mmap read faults, the unsafe match is dropped and healthy matches remain.Stats.Crashesand the crash metric increment once per faulted shard for the whole request, includingStreamSearchresults split across multiple repository events.Repository identity is not used for attribution because one repository can span shards. Before aggregation, each shard result records the address range of its mmap-backed match data. Aggregation and tail truncation preserve those slice pointers, allowing the final copy to resolve the exact searched shard. Overlapping or missing provenance is reported but never used to guess a repair target.
A concurrent watcher replacement unregisters the old shard instance, so a late copy fault from the old snapshot cannot reopen the new generation.
Controlled before/after
The Linux control supplies the final copy function with
FileMatchvalues backed by a truncatedMAP_SHAREDmapping.SIGBUSwithfatal error: faultCoverage includes
Search,StreamSearch, display limiting, a repository split across shards, multiple repository events from one shard, and deliberately ambiguous provenance.The limited-result benchmark remains near the parent branch (
~225-258µsversus~221-251µsover five 30-iteration samples on darwin/arm64). This is containment for the EFS/NFS failure documented in #1109; immutable shard generations remain the root publication-lifetime fix.Test plan
go test ./...go test -race ./searchgo vet ./...go test ./searchBenchmarkShardedSearchManyChunks/max-docs-8