Skip to content

index file I/O: a logical file layer and disk cache over index chunk tables - #31050

Merged
XuPeng-SH merged 27 commits into
matrixorigin:mainfrom
cpegeric:index_io
Oct 27, 2026
Merged

XuPeng-SH merged 27 commits into
matrixorigin:mainfrom
cpegeric:index_io

Conversation

@cpegeric

@cpegeric cpegeric commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #31051

What this PR does / why we need it:

A logical index file layer over the existing index chunk tables (index_id, chunk_id, data, tag) shared by HNSW, CAGRA, IVF-PQ and FULLTEXT2, plus a CN-local disk cache for whole index files. Physical storage does not change: chunks stay rows of the hidden tables. No index uses the layer yet; each algorithm adopts it in its own PR (FULLTEXT2 next).

Design and decisions: docs/design/20261024-index-file-io.md.

Why

Today every index load streams all chunks through SQL into a temp file, and every write builds INSERT statements with each 64 KiB chunk as a bound parameter or hex literal. Nothing is reused between loads, and the writing CN reads its own file back through SQL.

Changes

  • fileservice.IndexFileCache (pkg/fileservice/index_cache.go): its own DiskCache instance whose entries are directories (file + manifest). An entry is published by one rename, opened through one directory handle (os.OpenRoot), and evicted or deleted as a unit. Capacity, eviction, disk-full handling, per-path coordination and restart reuse are the existing DiskCache mechanisms; the directory-entry handling is enabled only on this instance, so table-data caches are unchanged.
  • Config ([fileservice.cache]): index-file-disk-share (default 0, so this PR changes nothing until configured), index-file-disk-path (default <disk-path>-index-file; must not overlap disk-path), index-file-rebuild-cache (read | none | read-write). Only a CN's SHARED file service gets the cache. The share splits disk-capacity and a runtime cache resize.
  • pkg/vectorindex/indexfile, generic for all chunk-table indexes:
    • Open: a cache hit is checked against its manifest (full CRC32-C on the first open in the process, then the length). A miss takes a per-file lock (concurrent misses rebuild once), streams only the file's chunk range through the relation readers of the caller's transaction (snapshot-aware, same workspace visibility as a SQL SELECT in that position), requires every chunk exactly once with its exact length, verifies the metadata checksum, and moves the file into the cache. Cache errors fall back to a rebuild.
    • Write: keeps the file as one local file and writes the rows with internal INSERT INTO <chunk table> SELECT ... FROM index_file_chunks('<token>', start, count) statements of at most 1000 chunks each, so the insert pipeline keeps its primary-key locks, duplicate check and composite key. The local file then moves into the cache without a second copy.
    • File.FDPath() gives path-taking libraries (usearch View, the cuvs tar unpacker) a path to the open descriptor, valid even if the cache evicts the file.
  • index_file_chunks: an internal table function (rejected for non-internal SQL at plan time). It takes a random token bound to the writing transaction, never a path, and runs as a single local scope.

Compatibility

  • No schema, catalog, wire or on-disk change. Rows written through the layer are ordinary chunk rows readable by the existing SQL loaders, and the reverse.
  • No MORPC version: index_file_chunks is only planned and executed on the CN that holds the file (childless function scan → compileSingleTableFunction; it fails closed if given an input), and it is never persisted in a view or plan another CN would run.
  • With the default share of 0, no index-file cache is created and the table-data disk cache keeps its full capacity.

Tests

  • pkg/fileservice/index_cache_test.go: put/open/delete; invalid names; source errors and cancellation leave nothing; never visible before publication; evicted-while-open stays readable; restart reuse and temp/trash cleanup; two instances sharing a directory; concurrent put/open/delete/evict; one generation per open; incomplete entry repaired; move-in of a temp file; config split, default 0, resize split, path overlap rejected, invalid settings rejected; table-data cache ignores directory entries.
  • pkg/vectorindex/indexfile: chunk assembly rules; manifest and names; per-file lock; rebuild then hit; tail-frame range with a caller verifier; missing, duplicate and corrupted chunks; corrupted cache entry rebuilt; no cache; concurrent misses rebuild once (fails without the lock); FDPath after eviction; Write naming, cleanup on failure and empty files; bounded verified set.
  • pkg/sql/colexec/table_function, pkg/sql/plan: round trip through the real operator, lifecycle (Prepare/Call/Reset/Call/Free), argument and range checks, other transaction, expired token, internal-only planning.
  • pkg/vm/engine/test/indexfile_test.go, against the real engine and SQL executor: write through INSERT ... SELECT index_file_chunks; read back by SQL, by the writing transaction before commit, and by another cache after a flush with neighbouring rows the key-range filter must exclude; snapshot read after delete; duplicate key on rewrite; rows written by plain INSERT.
  • cmd/mo-service: only a CN's SHARED file service gets the cache; default share creates none.
  • Race: the concurrency tests repeated under -race, and the touched packages once under -race.

🤖 Generated with Claude Code

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

cpegeric and others added 9 commits October 25, 2026 05:15
…ables

Proposed contract for reading and writing index files without SQL while the
chunks stay rows of the existing hidden tables: identity and versions,
engine-level reads with range reads, a fileservice chunk cache keyed by
content, engine-level writes with write-through, and compatibility.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… disk cache

Record the decisions: the unit is the whole named file, written as chunk rows
and into the disk cache only (no memory cache); reads by name rebuild from the
rows on a miss; integrity reuses the base-file checksum and the CDC frame
footer; FULLTEXT2 adopts first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Snapshot reads are handled by the caller's transaction and the
content-addressed name; record the decision and a snapshot-after-merge
validation case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A cached file carries a trailing integrity record (format version, length,
one checksum); chunk rows keep today's bytes, so no format gate. Rebuilds
verify against the metadata checksum by kind; the tail is one file per frame
with the shared frame encoding moved out of the GPU package (proposed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cached index file is exactly the payload (a tarball stays a tarball);
integrity lives in a separate manifest beside it, so path-based consumers
read unchanged bytes and chunk rows keep today's format.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Index files live in the shared fileservice disk cache under a reserved
namespace, rebuilt from chunk rows on a miss. A new whole-file API pins an
open file: pinned files are never evicted and stay counted, deletes wait for
the last release, and eviction terminates when only pinned files remain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…isting capacity

A separate directory and cache instance holds index files, sized as a
configured share of the existing disk-cache capacity; pinning applies to it
only, so table-data eviction is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uild cache use is configurable

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ld per file, removal and sharing rules

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cpegeric

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH fixed in 1614070 (the cache-key alias in pkg/vectorindex/indexfile/ref.go).

  • pathSafe now maps checksums to a path component one-to-one: a checksum is kept only when it is digits and lowercase letters and does not start with x; anything else is x + hex. Kept names never start with x and encoded ones always do, so "!" and "x21" no longer share an entry.
  • The old scheme also aliased case-only differences ("Ab" / "aB") on a case-insensitive file system (e.g. default macOS); excluding uppercase from the kept set closes that too.
  • Hex MD5 checksums keep their names, so existing entries stay valid.

Tests (both fail on the previous code):

  • TestManifestAndNames: distinct checksums never share a name, compared case-insensitively, including !/x21, X21/x21, Ab/aB.
  • TestOpenDistinguishesCustomChecksums: two versions with the same table/index/tag/first chunk/size and custom checksums ! and x21, through the cached Open: the second version is rebuilt and returns its own bytes.

Also merged main (b525cd7).

@XuPeng-SH

XuPeng-SH commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: b525cd7bef02f20716be985108a95cddb9a24cf6

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: b525cd7bef02f20716be985108a95cddb9a24cf6

Assessment: approve

Reviewed the complete 24-file delta, linked issue, and discussion. The checksum-name alias is fixed and verified through cached Open. Earlier staging, prefetch, directory-retention, and design concerns are resolved. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Isolation preflight and native provenance verification passed with matching current native inputs.

  • Focused identity, cache lifecycle, staging fallback, configuration, internal table-function, and engine transaction/snapshot/prefetch tests passed.

  • Full indexfile and fileservice packages passed under -race. Bounded concurrency stress checks also passed.

  • All 24 discussion keys are reconciled in discussion-assessment.json. Commands, source fingerprints, terminal receipts, and retained logs were verified; the audit is recorded under /home/xupeng/.local/state/mo-bot/jobs/36856002e88b2699a9fd754b/attempt-1/evidence-audit.json and final-validation-receipt.json.

Limitations:

  • Raw CI logs were unavailable; validation claims above rely on audited local execution.

  • No full-cluster or algorithm-adoption run was performed. This PR introduces the reusable layer without adopting it in an index algorithm.

@mergify mergify Bot added the queued label Oct 27, 2026
@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · checks failed

1 h 56 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 27 Oct, 15:53 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 17:50 · bf9f10b

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, comment @mergifyio queue to queue it again as it is.
Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Requeued — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

3 h 11 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 27 Oct, 19:04 · rule main · triggered by @cpegeric with the merge queue checkbox
  • 🚫 Left the queue 22:15 · bf9f10b

Reason

Pull request #31050 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added queued and removed dequeued labels Oct 27, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants