Skip to content

fix(engine): a lossless Reindex removes a field from pending_reindex though the documents that lost its data remain #1890

Done

Description

@mosuka

Background

Found while fixing #1872. Line numbers are at 5a0420e8. Read from the code; not reproduced.

Schema::pending_reindex records the fields whose data a Destructive change discarded, so that GetSchema and laurus get schema show it (#1079). Engine::update_field removes a field from it after any Reindex (laurus/src/engine.rs:3376).

A Reindex does not bring back what an earlier Destructive change discarded. For example:

  1. A field is stored: false, and a change of its type is Destructive: the documents written before it lose the field's data, and the field is recorded.
  2. stored is turned on, and documents are written with it.
  3. An analyzer change is a lossless Reindex, since no live document has the field's data without a stored value any more.

After step 3 the field is no longer in pending_reindex, though the documents of step 1 still have no data of it. They have no norms either, so the data does not tell them apart from documents written without the field.

Goal

pending_reindex keeps a field while documents that lost its data remain, or the docs say what removing it means.

Acceptance criteria

  • The plan decides when a field leaves pending_reindex: for example, only when the documents written before the loss are gone, or when the user clears it.
  • A test of the sequence above shows the field removed on the current code (T1 and T2 in laurus/tests/engine_pending_reindex_test.rs, the investigation's lexical and vector sequences, fail with the old removal put back; the lexical one turns indexed off as the lossless Reindex, since an Integer field has no analyzer).
  • The docs of Schema::pending_reindex and docs/src/concepts/schema_and_fields.md (en/ja) say when a field leaves it.

References

Tasks

Activity

  1. added
    bug
    on Dec 4, 2026
  2. mosuka commented on Dec 4, 2026

    @mosuka
    OwnerAuthor

    Investigation

    At main ce5f3baf, on evo-x2 (Linux).

    Reproduction

    The Issue read this from the code; an integration test (not committed) runs it through Engine, for a lexical field and for a vector field. update_field was called with reindex: true at each step.

    Lexical field v:

    Step Classification pending_reindex A range on v finds
    Integer, stored: false; put a1–a4 {} 4
    1. Float, stored: false Destructive {"v"} 0
    2. stored: true; put b1–b4 MetadataOnly {"v"}
    3. indexed: false Reindex {} 4 of 8 (b1–b4)

    Vector field v, HNSW:

    Step Classification pending_reindex
    dimension 2; put a1–a4 {}
    1. dimension 3 Destructive {"v"}
    2. put b1–b4; then m 16 to 8 Reindex {}

    A destructive vector change recreates the field empty (#1535), so a1–a4 have no vector after step 1. I did not check that with a search.

    So the bug is the Issue's, and a vector field has it too.

    Why

    • Where the field is removed: update_field records the field after a change that discarded data, and removes it after any other rebuild: if purge { insert } else { remove } (engine.rs:3453-3457). The branch is shared by the lexical and the vector rebuild.
    • Why a rebuild cannot restore the data: a rebuild re-derives the field from each document's stored value (lexical) or raw vector (vector). A document that lost its data at a destructive change has neither: that is why it lost it. So no later rebuild brings the data back.
    • What a removal after a lossless rebuild says: only that this change discarded nothing.

    Which documents may have lost the data

    • Every put gets a new internal id: it draws from a counter that only grows (DocumentLog::append_put, store/log.rs:773), and putting an id again deletes its old copy.
    • So the documents that may have lost the data are the live ones whose internal id is below DocumentLog::next_doc_id() at the time of the change. Once none of them is live (deleted, or put again), no document that lost the data remains.
    • Some of them lost nothing: documents without the field, and, for a lexical field, documents written while it was stored. Without norms the data does not tell them apart.
    • The check is cheap: LexicalLiveness::live_upper_bound (perf(store): merge the document store's segments and drop deleted documents #1798, lexical/index/inverted/liveness.rs:111) bounds the live ids of a range without listing them. It overcounts, never under: a segment of unknown membership counts its whole range.

    How others do it

    Read from the official docs by a subagent; I have not read them myself.

    • Vespa: a schema change that needs it triggers reindexing, which re-feeds every document of the type through the indexing chain (reindexing). The cluster reports, per document type, "the state (pending, running, successful, or failed)" until it is done (reindexing in Vespa Cloud).
    • Elasticsearch: "In most cases, you can't change mappings for fields that are already mapped", and "These changes require reindexing" into a new index (mapping). There is no per-field pending state.
    • Solr: "When you change Solr's schema, the Lucene index is not modified in any way", and the user verifies what is left (reindexing).

    Options

    1. A rebuild never removes the field. Only delete_field does.
      • Simple.
      • The field stays pending even after every document has been put again.
    2. The field leaves pending_reindex once no document that may have lost its data is live.
      • The change that records the field also records the next internal id with it.
      • update_field and each commit remove the field once no live document is below that id.
      • This is Vespa's model, pending until every document from before the change is processed, except that laurus re-feeds only when the user puts the documents again.
      • The id needs to be persisted: a new key of the schema, with a serde default, so that an existing schema.toml still reads. A field pending in such a file gets the next id at open, which keeps it pending longer, never shorter.
      • An older laurus cannot read a schema that has the key (deny_unknown_fields, fix(schema): an analyzer component's unknown key is ignored #1700), and Schema gains a public field, so the title would carry !.
    3. Documentation only. Removing the field after a lossless rebuild would be documented as "this change discarded nothing", not as "the field's data is complete".

    Summary

    • The bug: after any lossless rebuild, pending_reindex forgets a field whose data an earlier destructive change discarded. This holds for both lexical and vector fields.
    • The data to fix it exists: internal ids only grow, so "no live document from before the loss" is a precise, cheap condition.
    • The option I propose for the plan: option 2.

    The plan follows in a separate comment.

  3. mosuka commented on Dec 4, 2026

    @mosuka
    OwnerAuthor

    Plan

    This follows the investigation and takes its option 2: a field stays in pending_reindex while a document that may have lost its data is live. One PR.

    Shape

    • Who records and releases: Engine, which already records a field in update_field.
    • The condition: "no live document below the internal id the change recorded".

    Changes

    • laurus/src/engine/schema.rs:
      • Schema gains pending_reindex_below: BTreeMap<String, u64>: for each field in pending_reindex, the next internal id at the change that recorded it. It is #[serde(default, skip_serializing_if = "BTreeMap::is_empty")], so an existing schema.toml still reads.
      • The doc comments of both fields say when a field is recorded and when it leaves.
    • laurus/src/lexical/index/inverted/liveness.rs: LexicalLiveness::may_hold_live_below(id) -> bool, built on live_upper_bound.
    • laurus/src/engine.rs:
      • Recording: both places that record a field, a destructive change and a change between a lexical and a vector option, also record self.log.next_doc_id(). If the field already has an id, the larger one stays.
      • A lossless rebuild no longer removes the field.
      • release_pending_reindex: a new method that removes every field with no live document below its id, from both records.
        • It runs at the end of update_field, after Engine::commit, and at the end of EngineBuilder::build.
        • It saves the schema when it removed a field. If the save after a commit fails, the removal is undone with a warning, and the commit still succeeds.
        • CommitPolicy::Interval's background commits do not touch the schema, so the field leaves at the next of these instead; the docs say so.
      • Opening: a field in pending_reindex without an id, written before this change, gets the next_doc_id() after recovery. That covers every document there is.
      • delete_field removes the field from both records.
      • A dry run changes nothing, as today.
    • laurus-server/src/convert/schema.rs and laurus-cli/src/commands/create.rs: their struct literals get the new field, empty. The proto and the HTTP gateway keep listing names only.
    • Docs: the pending_reindex paragraphs of schema_and_fields.md and laurus-cli/commands.md (en/ja) say when a field leaves.
      • Once every document written before the change has been deleted or put again, and committed.
      • Or once the field is deleted.
      • And when this is checked.
    • !:
      • Schema gains a public field.
      • An older laurus cannot read a schema.toml that holds the new key, while a field is pending (deny_unknown_fields, fix(schema): an analyzer component's unknown key is ignored #1700).
      • Title: fix(engine)!: keep a field in pending_reindex while a document that may have lost its data is live, instead of removing it after any lossless rebuild (#1890)

    Tests

    All but T6 are in laurus/tests/engine_pending_reindex_test.rs.

    • T1: the investigation's lexical sequence. The field stays after the Reindex of step 3.
    • T2: the investigation's vector sequence. The field stays after the m change.
    • T3: when the field leaves, for both kinds.
      • It stays while one of a1-a4 is put again.
      • It leaves once all of them are put again and committed.
      • It also leaves once they are deleted and committed.
    • T4: the record survives a reopen, and the field does not leave while a document from before the loss is live.
    • T5: a schema.toml written before this change: pending_reindex holds the field and there is no id.
      • Opening records the next id.
      • The field stays while an old document is live, and leaves once all are put again and committed.
    • T6 (liveness.rs): may_hold_live_below agrees with live_upper_bound over ranges, memberships and deletions.
    • Existing tests: the ones that check pending_reindex (such as engine.rs:7922) and fix(engine): a lexical Reindex drops the terms and points of the documents written while the field was not stored #1872's run. Any whose meaning changes is updated, and the PR says which.
    • RED: each must fail when one of these is put in:
      • a lossless rebuild removes the field again (T1, T2);
      • the check after a commit is skipped (T3);
      • opening records no id, or 0 (T5);
      • may_hold_live_below ignores deletions (T3 or T6).

    Measurements

    The check runs only while a field is pending, once per explicit commit, and takes one liveness snapshot. Its time on T3's index goes in the PR; no benchmark is planned.

    Checks before the PR

    On CPUs 8-15:

    • cargo fmt --check;
    • Clippy on the workspace, all targets, with embeddings-all, and on wasm32;
    • rustdoc;
    • the CI filter, timeout and snippet checks;
    • the tests of laurus, laurus-server, laurus-mcp and laurus-cli.

    The bindings are left to CI, after checking that their jobs start.

    Out of scope

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions