Skip to content

next-plaid: drop the cached metadata reader when recreating a deleted index - #198

Open
jipeng6036-del wants to merge 1 commit into
lightonai:mainfrom
jipeng6036-del:fix/197-stale-metadata-reader
Open

jipeng6036-del wants to merge 1 commit into
lightonai:mainfrom
jipeng6036-del:fix/197-stale-metadata-reader

Conversation

@jipeng6036-del

@jipeng6036-del jipeng6036-del commented Oct 10, 2026 •

Copy link
Copy Markdown

Fixes #197.

Problem

filtering::create() and create_with_fixed_columns() only drop the cached read-only SQLite connection (DB_READ_CONNECTIONS) inside if db_path.exists(). When an index is deleted with DELETE /indices/{name}, the whole directory is removed, so on recreation metadata.db no longer exists and the cached reader is never invalidated. It still points at the old, unlinked database, so count() and metadata reads on the recreated index return the old generation's rows. This matches the "index still has 50 documents but DB has 580 records" sync-repair error in the issue.

Change

Call invalidate_read_connection(&db_path) unconditionally before recreating the database in both create paths. Removing a key that isn't in the cache is a no-op, so the existing behavior when the file exists stays the same.

Verification

  • Added test_create_after_directory_removal_drops_cached_reader. It creates 5 rows, warms the reader with count(), runs fs::remove_dir_all, then recreates the index with 2 rows. On main it fails with left: 5, right: 2. With the fix it passes.
  • cargo test -p next-plaid (no BLAS features): all pass (159 lib tests plus the integration tests).
  • cargo clippy -p next-plaid --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • Run with rustc 1.99.0 on Linux.

Not run: the openblas/accelerate feature builds, the next-plaid-api end-to-end delete/recreate flow from the issue, the ONNX and colgrep crates.

This change was prepared with an AI coding assistant. The reproduction and the checks listed above were actually run.

… index

create() and create_with_fixed_columns() only invalidated the cached
read-only SQLite connection when metadata.db still existed. When the
index directory had been removed first (DELETE /indices/{name}), the
cached connection kept reading the old, unlinked database, so count()
and metadata reads on a recreated index of the same name returned the
old rows.

Invalidate the cached reader unconditionally before recreating the
database, and add a regression test that warms the reader, removes the
directory and recreates the index.

Fixes lightonai#197

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Same-name index recreation can retain a stale SQLite metadata reader

1 participant