Repository navigation
feat(hnsw): read and write HNSW models through the index-file cache - #32251
Conversation
…atrixorigin#31109) Searches, CREATE/REINDEX and the ISCP sync now read and write HNSW model files through the index-file layer, so a model is served from the CN's index-file cache instead of being streamed from its chunk rows through SQL on every load. Files are named by the MD5 HNSW records, as a sync rewrites a model under its id. The layer accepts a SqlProcess with only a SqlContext, as a background job has: it reads in the SqlContext's transaction and account, and a rebuild builds its readers on a process of its own. A cache hold can be released as superseded, without counting as a use, which an HNSW search does when a newer generation replaced it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
A rebuild from chunk rows in a job without a query process, such as an
HNSW CDC sync, opened the storage relation with a typed nil process. The
storage engine bound the relation to no process, and Ranges dereferenced
it: the CN crashed on the first cache miss of a sync (compose BVT,
vector_filtered_search_hnsw.sql), and the restart rebound its lock tables
("lock table bind changed").
scanChunks reopens the relation on the process it builds for such a read,
and openRelation passes no process as an untyped nil, so the engine falls
back to the transaction's process. The test relation opened without a
process now fails Ranges, as the engine does.
Adds HNSW index-file BVT cases like FULLTEXT2's: CLONE, the clone's first
background sync rebuilding its models from rows, REINDEX, DROP and
snapshot RESTORE; and CDC syncs rewriting models, with a named snapshot
reading the replaced version.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # pkg/fileservice/index_cache_test.go
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: a41d9c6c91d5feb44b0678c039d81666d06397c8
Assessment: approve
HNSW coherently reuses the existing transactional index-file cache. The hold and background-process changes preserve ownership without a parallel mechanism. Earlier generation-reuse, invalidation-race and CN-service findings are resolved; no actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 33 changed paths, affected owners and consumers, all 15 discussion records and linked issue 31109.
-
Final static audit passed 19 checks, including clean frozen source, complete discussion coverage and formatting/parsing of all 28 changed Go files. Receipt: checks/1794046368001079128-3.json; log: review-audit.log.
-
Isolation preflight passed. Receipt: checks/1794046013563159541-3.json; log: preflight.log.
-
Reused supplied current-head successful build, UT, SCA, coverage and PROXY/PESSIMISTIC BVT summaries. Check receipts and retained logs are correlated in validation-evidence.json.
Limitations:
-
Focused local tests stopped before compilation because libmo.so is missing and native artifact reuse was rejected. No fresh native, GPU or live-SQL pass is claimed; receipt checks/1794046042041086388-3.json matches focused-tests.log.
-
Raw CI and author execution logs were unavailable. Single-CN SIFT 500k performance figures remain author measurements; the original 5M-vector outlier and multi-CN performance were not independently reproduced.
The engine test harness sends transactions to the TN through a test sender, which skips the RPC header that advances the CN's clock to the TN's. The TN had its own HLC, so after the wall clock stepped back both clocks advanced only their logical parts, independently, and a transaction begun right after a commit could get an earlier snapshot: a create table right after create database failed with "Unknown database", and TestIndexFileWriteOpenThroughEngine read rows deleted before its snapshot. The test TN now uses the CN runtime's clock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: a0d1b3130fce645eb57d77524fcab96e4dd62a84
Assessment: approve
HNSW coherently reuses the approved transactional index-file cache. Holds and private background reader processes preserve ownership and CN service binding. The earlier generation-reuse, invalidation-race and prefetch findings are resolved. No actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all 34 changed paths, affected owners, all 17 discussion records and linked issue 31109.
-
Isolation preflight and 12 static audit checks passed, including clean frozen source, parsing/formatting of 29 Go files and both SQL/result statement pairs.
-
Frozen evidence reports successful build, UT, static analysis, coverage and proxy/pessimistic BVT checks.
-
Focused real-engine prefetch tests stopped before compilation because libmo.so is absent and native artifact reuse was rejected. Receipts and logs are reconciled in validation-evidence.json.
Limitations:
-
No fresh local native, race, GPU or live-SQL execution; raw CI and author execution logs were unavailable.
-
Performance figures remain author measurements on one CN with 500k vectors; the original 5M-vector outlier was not independently reproduced.
|
@aunjgr please review again. thanks |
|
mo-bot review · Commit: New discussion was assessed; the previous review remains unchanged. |
aunjgr
left a comment
There was a problem hiding this comment.
Independent re-review at a0d1b31. The HNSW adoption follows the approved index-file design: transaction/account/snapshot visibility stays with the existing chunk tables, full-MD5 file identities distinguish rewritten models, and native model destruction precedes release of the file hold.
My earlier generation-reuse blocker is resolved. Destroy clears the generation marker, and every wrapper teardown consumes the invalidation once, so a losing eviction claimant cannot mark a reused algorithm after teardown. The deterministic failed-load/invalidation tests cover that ordering. Background cold readers now retain the CN service binding, with a real four-block prefetch regression rather than only mock-reader coverage. I found no remaining actionable correctness or lifecycle issue in the current change map.
Evidence reused: current-head successful build, UT, SCA, coverage and both active BVT lanes, plus scoped author regression/race reports. No fresh local native, race or SQL run is claimed. The performance measurements remain one-CN/500k-vector author measurements, not independent verification of the original 5M-vector outlier.
✅ Merged into
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #31109
What this PR does / why we need it:
Every HNSW model load streams the model's chunk rows through SQL into a temp file and MD5s it, so the first query after a restart or a change pays for the whole model (#31109: 85.7 s at 5M x 1536D). This moves HNSW onto the index-file layer and cache that FULLTEXT2 already uses (design:
docs/design/20261024-index-file-io.md).SqlProcesswith only aSqlContext, reading in its transaction and account with the engine and cache it is given; a rebuild builds its readers on a process of its own. The ISCP sync uses it, so it reads the version the previous sync wrote from the cache.IndexFileHold.ReleaseSuperseded). An HNSW search evicted because a newer generation replaced it (stale sweep, or the sync's own eviction, now with reasongeneration_changed) releases its models that way, so the replaced version is evicted first.Results (SIFT 500k x 128, one CN, local disk, same data for both binaries):
Validation: unit tests in
fileservice,indexfile,vectorindex/cache,hnsw,fulltext2,iscp,table_function, including a CREATE -> CDC sync -> search lifecycle test on a real cache that fails on any rebuild from rows or SQL read; new tests under-race -count=100; all HNSW BVT suites and the FULLTEXT2 index-file suites pass.Limits: measured at 500k on one CN only; a model written on another CN is rebuilt once per version on each CN; searches map the cached file through
/dev/fd/N, run on macOS locally and on Linux first in CI.🤖 Generated with Claude Code