fix(code-intel): serve code tools from the last committed index during a reindex - #27
Merged
Merged
Conversation
…g a reindex A held index-write lock made every code tool refuse to answer for the length of every reindex. A reindex commits in one transaction and the databases run in WAL mode, so readers see the last committed index whole until it commits. Answer from it and append a note that results may lag the newest edits; a first build with nothing committed still refuses. Co-Authored-By: lemoncrow <302591943+lemoncrow-agent[bot]@users.noreply.github.com> LemonCrow-Session: s1
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.
Problem
Every code tool refused to answer while any reindex held the index-write lock.
index_statemapped "lock held" torebuilding, socode_search,relationsandcode_queryfailed for the whole length of every reindex. On a large repo that was most of the time.Why reading is safe
A reindex writes in one transaction, a full rebuild included, and the databases run in WAL mode. Until the writer commits, a reader in another process sees the last committed index, whole.
test_reads_during_reindex.pyproves this with the real engine. It pauses an indexer in a subprocess after its deletes and before its inserts, for both a full rebuild and an incremental run. The reader still sees every symbol and line of the previous index, then sees the new content once the writer commits.Change
readywithrefreshing=True. It staysrebuildingonly where there is nothing committed to read: a first build with no files yet. The torn-index checks are unchanged (missing tables, symbols without files).take_refreshing()reports whether this thread read a refreshing index since it was last called.index_state: "refreshing"and appends a note to the response text, the same way the repeat-call note is added: "note: the code index is refreshing; results come from the last completed index and may not reflect the newest edits".Trade-off
During a reindex, answers may be missing the edits that reindex is picking up.
WAL commits each attached database separately, so one read that spans the commit could see
code_contextandftsout of step for a few milliseconds.Tests
The real-engine premise test above, plus:
code_search(engine-cache path) andcode_query(require_readypath) with the lock held. Each answers, carries the note, and the note does not leak into the next call.The tests fail on three separate breakages:
Related
One of three independent fixes for code search failing on symphony-alpha:
fix/code-engine-autosync-leak,fix/incremental-reindex-batched-deletes,fix/search-reads-during-reindex. Each is based onmain, and all three merge cleanly in any order (checked withgit merge-tree, and their new tests pass together on an octopus merge).