Awesome Reviewers

Reviewer · Database

Index storage consistency

When building operations that read, merge, or write index/metadata objects in the data store, explicitly design for idempotency, atomicity, and consistency rather than assuming them:

Instruction

When building operations that read, merge, or write index/metadata objects in the data store, explicitly design for idempotency, atomicity, and consistency rather than assuming them:

  • Make functions that apply updates to an index builder (e.g. deletes/additions before writing out index files) idempotent, and document this property, since the same build step is often invoked more than once (e.g. once for the unsharded index and again per shard). Prefer having the simpler path delegate to the general one (e.g. ToIndexFiles() calling ToShardedIndexFiles(1)) instead of duplicating logic.
  • When a merge/compaction step swaps in newly built artifacts, account for the case where the computed output is byte-identical to an existing path (e.g. same content hash). Planning is deterministic, so if the swap logic treats “path already exists” as a fatal error, the same failure recurs on every subsequent pass and wedges the pipeline. Either have the planner avoid producing a no-op task, or make the swap accept an unchanged path as success instead of just logging and retrying forever.
  • When validating a logical group of index entries (e.g. all parts of the same compaction run), require all-or-nothing consistency for derived properties: if only some entries in the group carry a property (such as a layout), treat that as corruption rather than silently falling back.
  • When reading mutable metadata objects from object storage (e.g. a Table of Contents that is rewritten in place), do not use range-prefetching helpers intended for immutable objects. A later GetRange call can land on a different version of the object, mixing data from two writes. Read such objects with one explicit, complete request instead.
  • When correctness depends on conditional writes (e.g. If-Match/ETag-based optimistic concurrency), ensure the payload has a determinable size so the client library doesn’t silently drop the condition (use objstore.NopCloserWithSize instead of io.NopCloser), and be aware that multipart uploads (triggered above a size threshold) can bypass conditional-write semantics entirely—bound payload size or use a different safety mechanism if this risk exists.

Example of an idempotency fix:

// ToIndexFiles builds the single, unsharded index file.
func (c *compactedIndex) ToIndexFiles() ([]shipperindex.Index, error) {
    return c.ToShardedIndexFiles(1) // delegate instead of duplicating applyUpdates()
}

Treat these storage-layer guarantees as part of the schema/index design itself: verify them with tests that call the operation more than once, and with tests that simulate concurrent writers or identical outputs.