Skip to content

fix(engine): classify a lexical rebuild by the data it discards, so that one of a field that is not stored is a Reindex when it keeps every document's data (#1889) - #1903

Merged
mosuka merged 1 commit into
mainfrom
fix/unstored-lossless-rebuild-classification
Dec 5, 2026

Conversation

@mosuka

@mosuka mosuka commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Summary

Engine::update_field now classifies a change between two lexical options by the data its rebuild discards, whether the field is stored or not: Destructive when it discards a live document's data, a Reindex otherwise. Before, classify_change called every rebuild of a field that is not stored Destructive from the options alone, and update_field could only raise a Reindex from the data (#1872), never lower a Destructive. A dry run now also reads the documents written since the last commit, which the rebuild commits first.

Closes #1889

The bug

The investigation reproduced it on de2f1797, with a dry run, the applied call and a commit:

  • turning doc_values on for an Integer field never stored keeps all 4 documents found, and was Destructive and recorded in pending_reindex;
  • an analyzer change of a Text field not stored and holding no document was Destructive and recorded.

Since #1890 such a record stays until every document written before the change is deleted or put again.

The rule

  • Destructive when the rebuild discards the data of a live document: a document with the field's data and no stored value of it, whose data the new option does not index as the old one did (FieldOption::keeps_index_data_under). A document without a stored value has no doc values or stored tokens for highlighting to lose, since the writer builds both from stored values only.
  • One exception, decided in the plan: turning indexed on for a field that is not stored stays Destructive, though it discards nothing. A document written while the field was neither indexed nor stored kept nothing of its value, and the index cannot tell it from a document without the field.
  • Reindex otherwise: every document has a stored value to rebuild from, keeps its data, or has none to lose. A new option that does not index the field drops every document's terms and points and counts none, as turning indexed off does (fix(lexical/index): the whole reader's BKD queries skip the segments that hold a field without its tree, which per-segment views scan #1868): a document put under it would hold none either.

classify_change does not change. It stays the classification from the options alone, and check_lexical_field_records (#1873) reads it only for MetadataOnly against the rest.

Changes

  • laurus/src/engine/schema.rs:
  • laurus/src/engine.rs (update_field): for a change between two lexical options that classify_change calls Reindex or Destructive:
    • a dry run, or a call refused for want of reindex, classifies with rebuild_would_discard, now for a Destructive too;
    • an applied call classifies from the rebuild's count;
    • purge, the record in pending_reindex and the warning follow the result. Before, a lexical Destructive was recorded, and the warning logged, with a count of 0. Turning indexed on for a field not stored logs its own warning.
    • A change between a lexical and a vector option (change_field_kind) is left as it is.
  • The dry run and the writer's documents:
    • LexicalStore::rebuild_would_discard asks the index about the published segments, then the cached writer about its documents since the last commit. It used to skip those as documents with a stored value, which holds for a stored field only.
    • LexicalIndexWriter::rebuild_would_discard_uncommitted is new, with a default that fails, as LexicalIndex::rebuild_would_discard's does. InvertedIndexWriter implements it with the rebuild's own test, over the buffered documents (with the field's length and no stored value) and the segments flushed and not yet published (MergeEngine::any_document_without_stored_value), skipping the documents deleted since the last commit. It reads nothing when the new option does not index the field or indexes it as the old one did.
  • Docs (concepts/schema_and_fields.md, en/ja):

Changes from the plan

  • Who asks the writer. The plan had InvertedIndex::rebuild_would_discard call a check handed to it by the store. LexicalIndex is a public trait, so its method keeps its signature: the store asks the index and then the writer. The test and the documents read are the plan's.
  • A change to an option that does not index the field is a Reindex. The independent review found it: a Text field not stored and holding data, changed to Bytes, or with indexed turned off together with an analyzer change, drops every document's terms and points, counts none, and is now a Reindex recorded nowhere. Under fix(engine): a lexical change with no stored value to rebuild from is classified Reindex and discards the field's data #1685 it was Destructive. It is kept, for the reason in "The rule"; turning indexed back on later is caught by the exception. The docs say so, and a test pins it.
  • Two more tests than planned: the Bytes field, and the change to an option that does not index the field.

What a user sees

  • A change of a stored: false lexical field is reported as a Reindex, and not recorded in pending_reindex, when no live document loses its data: one that indexes the field as before (doc_values, highlight_offsets, multi_valued or indexed turned on, term_vectors off), one of a field holding no document, one to an option that does not index the field, and turning multi_valued off on a Bytes field. It still needs reindex.
  • A dry run, and a call refused for want of reindex, of such a change reads the index (see the measurements).
  • No public API changes besides the new trait method, which has a default; hence no !.

Tests

  • laurus/tests/engine_unstored_documents_rebuild_test.rs (fix(engine): a lexical Reindex drops the terms and points of the documents written while the field was not stored #1872's file). Each case runs a dry run and then the applied call, and checks the record:
    • T1: turning doc_values on for a field never stored, for each of the 7 kinds, is a Reindex both ways, records nothing, and keeps the 4 documents found. It replaces a_field_never_stored_keeps_its_data_and_stays_destructive, which pinned the over-report.
    • T2: a field not stored and holding no document, in an index of documents without it: an analyzer change, and Integer to Float, are a Reindex.
    • T3: an analyzer change of a Text field never stored, with data, is Destructive, recorded, and finds nothing after.
    • T4: turning indexed on for a field not stored stays Destructive and recorded, for Integer and Text, and for a field holding no document.
    • T5: a document put and not committed makes an analyzer change Destructive as a dry run and applied; deleted before the commit, both are Reindex.
    • T6: a call refused for want of reindex names T1's change a Reindex.
    • Bytes: turning multi_valued off on a Bytes field never stored is a Reindex.
    • No index: Text to Bytes, indexed off with an analyzer change, and indexed off on an Integer with the documents not committed, are a Reindex.
  • lexical/index/inverted/writer.rs, T7: with max_buffered_docs: 2, the writer's check finds a document in a flushed, unpublished segment (the test checks that the segment is there and the buffer empty), not once it is deleted, and one in the buffer; a change that keeps the data finds none.
  • lexical/store.rs, T7: rebuild_would_discard agrees with the count rebuild_field returns, with the documents uncommitted (true, 3) and deleted (false, 0).
  • engine/schema.rs, T8: the table of classify_lexical_rebuild.

In the whole laurus suite, T1's predecessor was the only existing test whose expectation changed. #1685's and #1890's tests hold data in the field and stay Destructive.

RED

Each of these, put in alone, fails the tests named; the code was then restored and the same 18 tests passed again:

Put in Fails
an applied call does not lower a Destructive T1, T2, T5, Bytes, No index
a dry run does not lower it T1, T2, T5, T6, Bytes, No index
the buffered documents are not read T5, T7 (writer)
the unpublished segments are not read T7 (writer)
their pending deletes are not skipped T7 (writer, store)
the writer reads for an option that does not index the field No index
no exception for turning indexed on T4, T8

Measurements

A dry run that classifies a lexical rebuild reads the index. On evo-x2 (CPUs 8-15, release, FileStorage), on an index of 100,000 documents built by 10 commits of 10,000, the median of one dry run, 5 times (the 5 medians of each case lie within 1% of each other):

Case Classification Median
floor: a MetadataOnly change, which reads nothing MetadataOnly 0.2 µs
1. an analyzer change of a Text field not stored, with data (stops at the first document) Destructive 3.3 ms
2. the same of a field holding no document (each segment's norms list only) Reindex 40 µs
3. as 2, with 9,000 documents written and not committed Reindex 88 µs
4a. an analyzer change of a stored field (every document read; #1872's cost) Reindex 38.5 ms
4b. the same field after stored was turned off Reindex 38.4 ms

On main, cases 1-3 and 4b return at the floor, since classify_change calls them Destructive and the dry run reads nothing. So a dry run of such a change costs up to what a stored field's already does (4a). Case 1's 3.3 ms, though it stops at the first document, looks like the cost of opening a segment and reading its documents' list and stored documents; it was not broken down. An applied call costs the same as before: the rebuild reads every document anyway.

Checks

On evo-x2 (Linux x86_64), on the commit of this PR:

  • cargo fmt --all -- --check;
  • Clippy on the workspace, all targets, embeddings-all, -D warnings, and on laurus-wasm for wasm32-unknown-unknown;
  • scripts/check-rustdoc.py, check-ci-filters.py, check-job-timeouts.py (with their tests) and check-binding-snippets.py;
  • tests, all passed: laurus (embeddings-all,pq-fastscan) 4,298 passed and 28 ignored, laurus-server 334, laurus-mcp 53, laurus-cli 89.

The bindings, aarch64, Windows and the index interop are left to CI: a change under laurus/ starts all of them. The mdBook build runs only in Deploy Documentation after the merge; it was not run here, as mdbook is not installed.

Out of scope

…hat one of a field that is not stored is a Reindex when it keeps every document's data (#1889)

classify_change reads the options only and calls every lexical change
that rebuilds a field that is not stored Destructive. update_field raised
a Reindex to Destructive from the data its rebuild discards (#1872), but
never lowered a Destructive: turning doc_values on for a field never
stored, which keeps every document's terms and points, or an analyzer
change of a field that holds no document, was reported as Destructive and
recorded in pending_reindex, where it stayed until every document was put
again (#1890).

update_field now classifies a change between two lexical options by the
new classify_lexical_rebuild: Destructive when the rebuild discards a
live document's data, a Reindex otherwise, whether the field is stored or
not. Turning indexed on for a field that is not stored stays Destructive:
a document written while the field was neither indexed nor stored kept
nothing of its value, and nothing tells it from a document without the
field. An applied call classifies from the rebuild's count, a dry run and
a call refused for want of reindex from rebuild_would_discard.

A rebuild commits the cached writer first, so a dry run now also reads
the writer's documents since the last commit, with the rebuild's own
test: the buffered documents and the segments flushed and not yet
published, skipping the documents deleted since then. It used to skip
them as documents with a stored value, which holds for a stored field
only. LexicalIndexWriter gets rebuild_would_discard_uncommitted for it,
with a default that fails, and LexicalStore::rebuild_would_discard asks
the index and then the writer.

Closes #1889
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.

fix(engine): a rebuild that keeps every document's data is still reported as Destructive for a lexical field that is not stored

1 participant