Skip to content

Make interrupted tar builds resumable - #43

Open
wshlavacek wants to merge 34 commits into
mainfrom
fix/resumable-producer-batches
Open

wshlavacek wants to merge 34 commits into
mainfrom
fix/resumable-producer-batches

Conversation

@wshlavacek

Copy link
Copy Markdown
Collaborator

PR #41 fixed pending-file discovery (#4), tar-boundary checkpoints (#3), and the ten-shard merge limit (#1). This PR closes the remaining restart gap documented in #41. A normal incremental rerun now recovers both paper and passage vectors after a mid-tar failure.

What changed

  • Tar ingestion commits one batch at a time. Each article has a savepoint, so a malformed member can be skipped. An embedding or index-save failure rolls back the batch and its file records, allowing a retry to pick it up (Each article is committed separately, and batch rollback doesn't undo it #13).
  • Producers record staged segments in SQLite and publish both paper and passage segments before advancing the checkpoint. A restart can finish an interrupted publication. Consumers, rebuild checks and cluster scripts ignore unfinished files (Producer checkpoint can cover segments that are later deleted #3, Consumer picks up unfinished *_pending.npz segments #4).
  • Node-local jobs copy a consistent SQLite snapshot, its checkpoint and its segments before publishing the completion marker. A stale retry cannot replace a newer shard or restore a completion marker after consumption. Cluster resubmission preserves populated indexes. Hosts without Python's SQLite backup API fall back to shared storage.
  • The consumer records the completed checkpoint as part of each shard merge and preserves claimed segments until the saved vectors and SQLite marks are durable. Backfill advances through missing rows during throttled saves and marks them indexed after their vectors are durable (Backfill re-adds the same batch while FAISS saves are throttled #6).
  • Incremental producers verify that papers and their passages have vectors before skipping previously registered files. Revisions update the text, citation IDs and vectors together and retire obsolete passage IDs. When independent producers first encounter the same PMID or PMCID in different archives, the merge retains both file paths and resolves their segments to one paper. Delayed segments cannot replace newer embedding inputs. IVF-PQ replacement preserves the surviving passages' search IDs and scores.

Verification

  • Compared SQLite rows and the IDs and contents of saved FAISS vectors after interrupted and uninterrupted builds. Exercised abrupt exits before SQLite commit, before the first public rename and between renames, plus stale and interrupted node-local transfers.
  • Compared the latest titles, passages, numeric IDs and saved vectors across 270 merges in 90 workspaces.
  • Merged 64 shards under a 32-file-descriptor limit. Covered all three Python 3.12 SQLite transaction modes, retained and detached shards, revised articles and throttled backfill.
  • The default pytest suite passed (487 passed, 1 platform skip, 8 expected failures on Builds give a paper a second vector when it reappears #7 and Databases created before doc_id can't be opened #10, 11 deselected). The offline installed-CLI CPU build-and-search test also passed. Ran the repository validator on a local two-producer workspace. Cluster scripts were exercised locally without a live Slurm allocation.

Recovery notes

  • If a shard from an older release has missing vectors, overlapping identifiers without verifiable checkpoints, or ambiguous embedding history, rebuild from the original archives in a fresh workspace. For a historical segment that lacks an embedding-text digest for a revised article, the consumer preserves the original file with an .unverified suffix and applies the verifiable rows.
  • Before a destructive rebuild, finish consuming retained shards that depend on the existing indexes, or use a fresh workspace. Direct Python callers must reopen previously populated FAISS handles after a failed writer save. The CLI reopens its indexes on restart.
  • When an archive links a PMID and PMCID already assigned to two indexed papers, LitKit reports the conflict and preserves both records. Automatic consolidation is tracked in Consolidate separate paper records when a later archive links their PMID and PMCID #42.

Closes #13
Closes #6

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
… starts

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ter scripts

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…vector

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…nting

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…hard handoff

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ous revisions

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ckpoints

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…er resume

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
… paths

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…a batch

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…t copies

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…node recovery

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…tions

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ation

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…s and rebuilds

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…and vectors together

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…t passages

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…ision

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…m main

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
…dent shards

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
… converge

Signed-off-by: Bill Hlavacek <hlavacek@lanl.gov>
Keep this branch's batch publication in ingest_loop.py and port what #44
added on top of per-member commits:
- Writers turn off cache_spill while a batch is open, so readers are not
  locked out while the batch is embedded.
- When SQLite has rolled back the whole batch (disk full, I/O error), the
  member's error handler re-raises instead of skipping the member.

#44's tests now check this branch's publication: a writer killed after
its commit, before or after the index files move into place, finishes
that batch on restart; other connections see papers only after their
batch commits. The two #13 CHANGELOG entries are now one.

Also sort the local imports ruff flags and run black on the test files
that were clean on main.
make_id_selector() now builds an IDSelectorBatch (#14) and still keeps
the IDs as _litkit_ids. The IVF removal path reads them back; given only
the selector it would call is_member() from Python for every stored ID,
about 0.11 s per dedup at 1M vectors even when nothing is removed. A test
now fails if the IDs are missing.
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.

Backfill re-adds the same batch while FAISS saves are throttled Each article is committed separately, and batch rollback doesn't undo it

1 participant