Skip to content

Sparse typed-JSON segments fail boolean queries with required-component DataLoss #259

Description

@zcourts

Summary

Keldra 0.14.0 returns DataLoss / Unrecoverable data loss or corruption when a typed JSON boolean query references optional indexed fields that are absent from every document in one format-v4 segment.

This reproduces on a newly created Docker volume, so it is not an upgrade or stale-index problem.

Version

  • Release/tag: 0.14.0, commit 4352bbd2
  • Image: ghcr.io/keldra-store/keldra:0.14.0
  • Single-node, local durability, fresh volume

Index shape

Create a typed JSON index over a broad REST-style prefix with:

  • exact keyword object_kind
  • exact keyword status
  • exact signed integer engine_task_id
  • range signed integer next_eval_at_unix_ms
  • range signed integer lease_expires_at_unix_ms

Documents under the prefix legitimately have different kinds. Some documents contain object_kind but omit the optional scheduling fields entirely.

Query shape

The failing predicate is equivalent to:

all(
  equal(object_kind, "task"),
  in(status, ["ready", "deferred", "waiting", "running"]),
  any(
    not(exists(next_eval_at_unix_ms)),
    less_than_or_equal(next_eval_at_unix_ms, now)
  ),
  any(
    not(exists(lease_expires_at_unix_ms)),
    less_than_or_equal(lease_expires_at_unix_ms, now)
  )
)

Once the index contains a segment built from JSON documents that do not have one of those optional range fields, QueryIndex repeatedly fails with:

code: Unrecoverable data loss or corruption
message: invalid index format: format-v4 segment lacks a required component stream

The error originates from the missing-component assumptions in crates/keldra-index/src/v4/executor/posting.rs / segment_reader.rs.

Expected behavior

A missing optional field component in an otherwise valid sparse segment is not corruption:

  • exists(field) should evaluate false for documents/segments without that field.
  • not(exists(field)) should therefore include those documents, subject to the rest of the predicate.
  • comparisons against an absent field should produce no matches for that branch.
  • the query should return an ordinary empty or populated result, not DataLoss.

Operational impact

A scheduler using the new 0.14 boolean predicates cannot query eligible records when its index covers heterogeneous JSON documents with optional due/lease fields. The failure occurs continuously on a fresh deployment and prevents work acquisition.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions