fix: centralize DB open/create logic, fix force-reindex on missing DB#54
Merged
Conversation
Replace `index_quiet()` background task (which opens its own LMDB handle) with inline `SharedStores::new()` + background `force_reindex_with_stores()`. This prevents the race where `get_or_open_stores()` tries to open a second LMDB handle on the same path while `index_quiet` holds the first one. Key changes: - Open SharedStores inline (fast, just LMDB+Tantivy handle creation) - Store as RepoState::Write immediately (prevents double-open from other handlers) - Spawn force_reindex_with_stores + vector build + restart_fsw in background - Add active_reindexes guard for concurrency protection - Clean up config entry on failure
In serve mode, with_vector_store_read_for() no longer falls back to opening a standalone VectorStore when shared_stores read fails. This prevents "environment already opened" errors from LMDB.
… fix force-reindex on missing DB
- stop_fsw now returns None for Readonly repos instead of passing readonly stores into the force-reindex path. Callers fall through to try_open_stores(create_if_missing=true) which fails clearly when the write lock is held. - touch_access doc: warmup_repo now calls touch_access after successful warmup; update doc to reflect current callers.
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.
Summary
Centralize all LMDB database open/create logic into a single
try_open_storeshelper onServeState, eliminating 4 duplicate code paths. Fix the bug wherePOST /repos/{alias}/reindex?force=truereturned HTTP 500 when the.codesearch.dbdirectory had been externally deleted.Changes
New:
try_open_storeshelper (src/serve/mod.rs:1319)create_if_missing=false: fails fast if DB missing; tries write -> readonly -> Conflicted fallbackcreate_if_missing=true: creates fresh DB if absent; no readonly fallbackOpenedStores::Write(caller registers) orOpenedStores::Readonly(already registered)Bug fix: force-reindex on deleted DB
reindex_handlerforce branch now callstry_open_stores(.., true)when FSW is not runningget_or_open_storeswhich blocked on missing DB -> HTTP 5004 call sites unified
warmup_reposlow path: create_if_missing=falseget_or_open_storesslow path: create_if_missing=falsereindex_handlerforce branch: create_if_missing=true (bug fix)add_repo_handler: create_if_missing=trueBonus fixes
stop_fswreturns None for Readonly repos (prevents force-reindex against readonly-locked stores)add_repo_handlerconcurrent guard cancels token + removes repos entry on 409touch_accessdoc updated (warmup_repo now calls it)TrackedEnvruntime guard prevents LMDB double-open from MCP fallback pathsTesting