Skip to content

feat(storage): carry ConsistentRead to the data engine as ReadOptions - #559

Open
LeeroyHannigan wants to merge 18 commits into
mainfrom
feat/read-options
Open

LeeroyHannigan wants to merge 18 commits into
mainfrom
feat/read-options

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

The engine passes extenddb_storage::ReadOptions { consistent_read } as the last parameter of DataEngine::get_item, query and scan. Before this change the engine read the client's ConsistentRead for capacity accounting and dropped it. No backend could see it.

The engine passes the client's value on GetItem, Query and Scan (false when the member is absent), and each table's own KeysAndAttributes.ConsistentRead on BatchGetItem. The client's value also goes on the base-table read under a PartiQL SELECT from a local secondary index that does not project a selected attribute. The engine passes true on the export scan, because an export reflects every write acknowledged before the export time. It also passes true on the two PartiQL reads that evaluate a write against its stored item. One evaluates an UPDATE whose value nests past the item limit. The other sizes a failed batch write's charge. A read through a global secondary index reaches storage with false. The engine refuses ConsistentRead: true on a GSI before any storage call, on Query and on Scan, as the service does. A local secondary index read carries the client's value. This change leaves transact_get_items as it was. The service has no consistency flag there, and the reads reflect every acknowledged write.

The struct is #[non_exhaustive] with Default and const fn new(bool). It follows the VectorSearch parameter-struct precedent. A later per-read option becomes a field, and the three signatures do not change again. A Copy field that owns its data breaks no backend outside the workspace. The doc comment states the contract by what the read returns. With true the read reflects every write acknowledged before it started. With false it may miss recently acknowledged writes. A backend that serves every read from the copy that took the write meets both by ignoring the value. A backend with followers can serve false from a follower. A quorum backend needs read and write levels that intersect for true.

The SQLite, PostgreSQL, MongoDB and Cassandra backends accept the value and do not route on it. Each get_item carries a doc comment stating what that backend does with the flag today and what a routing change would need. SQLite holds one copy. PostgreSQL serves item reads and writes from the same data_pool. MongoDB refuses a non-primary read preference in a replica-set connection string, so those reads go to the primary. A directConnection=true string pins one member, which the driver reads with primaryPreferred. Cassandra reads and writes at LOCAL_QUORUM (#945), levels that intersect, so with the node and host clocks in sync both values are met the same way.

Why

Some backends run on a database with more than one copy of the data. Examples are a MongoDB replica set, PostgreSQL with a streaming replica, and a Cassandra keyspace. Such a backend can serve ConsistentRead: false from a copy that lags. It must serve ConsistentRead: true from a copy that does not lag. Without the flag at the storage layer, the backend cannot tell the two reads apart. An application that depends on ConsistentRead: true then cannot see the difference when it runs against ExtendDB. ADR-0024 records the decision and the options considered.

Stacking

This branch is on main and does not depend on the other open changes. It touches batch_get_item.rs, which #536 also edits. The PR that lands second merges the other, and the overlap is the call that passes the per-table value.

Testing done

Eleven engine tests run the handlers over the backup tests' Fake, which records every read with the options it received:

  • GetItem with true, false and the member absent.
  • Query and Scan with the three shapes on the table and on a local secondary index.
  • BatchGetItem with one table that asks for a consistent read, and another that sends false in one round and nothing in the other.
  • A GSI Query and a GSI Scan that reach storage eventually consistent. The engine refuses each before storage with the service's message when the client asks for true.
  • The export handler, into a temp root that a Drop guard removes. It scans both pages that the double answers, consistent.

Three more tests cover the reads that the PartiQL layer makes on its own. The base-table read under an LSI SELECT that reaches back carries the client's value with the three shapes. The read that evaluates an UPDATE past the item limit is consistent with false and with the member absent. So is the read that sizes a failed batch write's charge.

Negative controls ran on a clean committed tree, and I restored each one after:

  • Each of these fails the one test named for it:
    • the batch handler treating a present false as consistent
    • every index Query reaching storage eventually consistent
    • the GSI Scan refusal disabled
    • the export passing the default
  • Each of these fails its test too: the default on GetItem, Query or Scan, true for every batch table, and the double dropping the index name.
  • With the three PartiQL sites set to the default, their three tests fail and the other 11 pass.
  • With the base-table join set to true, its test fails alone.

The four backends' integration test call sites pass ReadOptions::default(). The reads main added since the merge base that assert they see rows the test wrote pass ReadOptions::new(true). Five PostgreSQL test binaries (90 tests) passed against a local PostgreSQL 16. CI runs cargo test --release -p extenddb-storage-postgres --tests: on the 17 November run of 6e96426, 36 targets and 452 tests passed. The MongoDB and Cassandra suites run in CI. Their changes are the added parameter at each call site and compile under clippy with all targets.

cargo +1.97.0 fmt --all -- --check
cargo +1.97.0 clippy --all-targets -- -D warnings
cargo +1.97.0 test -p extenddb-storage -p extenddb-engine -p extenddb-storage-sqlite -p extenddb-server -p extenddb-app   # 685 passed
EXTENDDB_TEST_PG_CONNECTION_STRING=... cargo +1.97.0 test -p extenddb-storage-postgres --test vector_control_plane --test put_create_race --test twi_conflict --test stream_shard_retention --test backup_restore   # 90 passed

Changes since the 24 November review

  • b1e7f8d merges main at 3534c9e. The consistent-read export scan moved to crates/engine/src/import_export/files.rs, where feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 put the export.
  • ca3dc07 passes ReadOptions at the four read calls main added since the merge base, each with the value its read needs.
  • 5c047fc rebuilds the recording double on the backup tests' Fake: read_options_tests/recording.rs goes from 848 lines to 39.
  • f5899fe adds tests for the three PartiQL reads, behind the partiql feature. edaa9c3 also checks the index read of the PartiQL SELECT.
  • 4371e2d makes the export test's double answer two pages.
  • f7744ce describes Cassandra at LOCAL_QUORUM, lists every read that passes true in the ReadOptions doc, and corrects the MongoDB comment for a direct connection.
  • 20da26a merges main at 9e457a3. docs: describe the PostgreSQL read replica mode as a proposal #584 marked the PostgreSQL read replica section of the storage design as a proposal, as this PR did, so the merge keeps main's text there. It adds this PR's sentence that the flag reaches the backend as ReadOptions::consistent_read.
  • These checks pass at 20da26a:
    • cargo +1.97.0 fmt in check mode on the workspace
    • cargo +1.97.0 check of the workspace with all targets
    • the 14 engine read_options tests
    • clippy with all targets on the engine, storage, Cassandra, MongoDB, PostgreSQL and SQLite crates
    • the WebAssembly adapter tests
    • cargo +1.97.0 check of the engine library with the default feature set off
    • cargo +1.91.1 check of the engine, storage, Cassandra and MongoDB crates

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace --lib; the integration suites run in CI)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy --all-targets -- -D warnings)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: ADR-0024, read consistency reaches storage as a ReadOptions parameter. RFC-0002 records that the team maintains all backends and that Storage trait changes land across all of them at once, which this change does. The storage design (04-component-storage.md) describes the type under DataEngine. The high availability design (11-high-availability.md) gains status notes on section 8 and Stage 1, which this change completes in a different shape. The storage extension manual gains a Read options bullet under DataEngine.

Breaking changes

DataEngine::get_item, query and scan gain a required last parameter, opts: ReadOptions. A backend outside this workspace stops compiling until it adds the parameter; a backend that holds one copy of the data adds it and ignores it. No wire body, status, header or capacity number changes for any client.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

Add `ReadOptions { consistent_read }` to extenddb-storage beside
`VectorSearch` and pass it as the last parameter of `DataEngine::get_item`,
`query` and `scan`. The struct is `#[non_exhaustive]` with `new` and
`Default`, so a `Copy` field that owns its data, added later, widens no
signature and breaks no caller.

GetItem, Query and Scan pass the request's ConsistentRead (false when
absent); BatchGetItem passes each table's KeysAndAttributes.ConsistentRead
on its per-key get_item calls; the export scan passes true, because an
export reflects every write acknowledged before the export time. A global
secondary index read reaches storage with consistent_read false because the
handler refuses ConsistentRead true on a GSI before storage is called, on
Query and on Scan; a local secondary index read carries the client's value.

The SQLite, PostgreSQL, MongoDB and Cassandra backends accept the value and
do not route on it; each parameter's doc comment states what that backend
does with the flag today and what a routing change would need. Integration
test call sites pass ReadOptions::default().

Engine tests with a recording storage double pin the flag on GetItem, Query,
Scan and BatchGetItem (per table, with false and absent told apart), the
LSI read carrying the client's value on Query and Scan, the GSI read as
eventually consistent on Query and Scan, the GSI refusal before any storage
call on both, and the export's consistent scan.
…d the backend author manual

ADR-0024 records the decision: a non_exhaustive ReadOptions struct in
place of the bare bool and the ConsistencyLevel enum the high availability
design proposed, the export scan read consistent, the GSI and LSI rules,
and the breaking change for a backend outside the workspace. The storage
design describes the type under DataEngine and marks the PostgreSQL read
replica routing in its section 5.3 as a proposal rather than code. The high
availability design gains a status note on section 8 and Stage 1. The
storage extension manual gains a Read options bullet under DataEngine.
…that does not

The storage design and the backend author manual said every in-tree backend
serves both ConsistentRead values from the copy that took the write. The
Cassandra backend reads at ONE against a keyspace whose replication factor
defaults to 3, which ADR-0024 records under Consequences and issue #560
tracks. Both sentences now name the three backends the statement holds for
and state what the Cassandra backend does.
…test

#401 added crates/storage-postgres/tests/gsi_online_build.rs on main. Its one
DataEngine::get_item call passes two arguments, and this branch gives
get_item a third parameter, ReadOptions, so the test did not compile once
main was merged in (E0061). The call now passes ReadOptions::default(). The
PostgreSQL backend ignores ReadOptions, so the test reads as it did before.
The Deciders line named @lhnng, which is not a GitHub account. ADR-0004, ADR-0005 and ADR-0023 name the same author as @LeeroyHannigan.
crates/storage-cassandra/tests/direct/backup_engine.rs: main removed
the catalog V005 tests (assert_catalog_lacks_v005 and the test that ran
table and item operations on a catalog without V005) when the Cassandra
catalog moved to the migration runner. This branch had added the
ReadOptions argument to the get_item calls inside that block. The merged
file keeps main's removal; the ReadOptions argument stays on every
remaining get_item, query and scan call in the file.

crates/storage-cassandra/tests/direct/index.rs: main added setup_engine
to the helpers import. This branch added the ReadOptions import. The
merged file has both.

docs/adr/README.md: main added rows for ADR-0023, ADR-0026 and ADR-0027.
This branch added the row for ADR-0024. The merged table lists all four
in number order.

Call sites main added since the branch point take the new parameter:
get_item in crates/storage-sqlite/src/data/update_item_tests.rs (five
calls), in crates/storage-postgres/tests/table_snapshot.rs (one call),
and in the Cassandra direct tests
transact_write_rollback_after_commit.rs,
transact_write_stream_records.rs, transact_write_stream_size_sweep.rs
and transaction_ledger.rs; scan in transact_write_stream_tables.rs (two
calls). Each passes ReadOptions::default().

crates/engine/src/read_options_tests/recording.rs: the storage double
follows the trait changes main made. StreamEngine::get_stream_records
takes the stream ARN, BackupEngine no longer has the continuous backups
methods, and StorageEngine requires SnapshotEngine, so the double gains
an open_table_snapshot that is not reached by the handlers under test.
crates/storage-cassandra/tests/direct/backup_engine.rs: main replaced
the `BackupEngine` import with `BackupCatalog`, `JobPermit` and
`LegacyBackupReader` and rewrote the backup tests for the catalog
index. This branch added `ReadOptions` to the same import and passed
`ReadOptions::default()` at the six `get_item`, `query` and `scan`
call sites. The result keeps main's import list and tests with
`ReadOptions` added to the list and the six call sites carrying the
parameter.

crates/storage-postgres/tests/backup_restore.rs: the same change on
the PostgreSQL side. The result keeps main's import list and tests
with `ReadOptions` added and the one `get_item` call site carrying
`ReadOptions::default()`.

crates/engine/src/read_options_tests/recording.rs: the recording
storage double implemented `BackupEngine`, which main removed from the
`StorageEngine` supertraits in favour of `BackupCatalog` and
`LegacyBackupReader`. The double now implements those two traits, with
every method unimplemented as the old one was, since no read handler
reaches them.

crates/engine/src/read_options_tests.rs: `OperationContext` gained a
`backup: Arc<BackupRuntime>` field on main. The test context fills it
with a one-slot runtime and no configured store.
crates/storage-cassandra/tests/direct/backup_engine.rs keeps the BulkLoadFile, Finished and RestoreEngine imports from main and the ReadOptions import from this branch.
Main added PartiQL point reads, two DataEngine test doubles and two Cassandra
integration tests that call DataEngine::get_item and query with the old
signatures. This commit adds the ReadOptions parameter at each one.

The PartiQL index read in base_join.rs passes the client's ConsistentRead,
as the Query and Scan handlers do. Two reads sit inside write paths: the
condition check in item_depth.rs and the failed write charge in batch.rs.
Both pass a consistent read. The engine evaluates a write condition against
the item that holds every acknowledged write, and sizes the charge from that
item. The test doubles in backup/tests.rs and
batch_write_item/scripted.rs take the parameter and ignore it. The two
Cassandra integration tests pass the default.
@demohan demohan self-assigned this Nov 24, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each storage read gets the right value: GetItem, Query and Scan carry the client's ConsistentRead, BatchGetItem carries each table's own, and export and the two PartiQL internal reads pass true. A GSI with true is refused before storage, and an LSI carries the client's value. On release builds of this head and the merge-base for SQLite, PostgreSQL, MongoDB and Cassandra, 578 read requests and 22 PartiQL write failures, sent twice each, give identical answers, and capacity and the GSI refusals match the service. With 8 writers and 8 readers for 30 s, no backend returned a stale consistent read, and server CPU per 1,000 reads is unchanged within run-to-run noise. The PR's 10 negative controls fail as named, and 5,171 tests pass.

This branch is behind main, and the merge below blocks it. I will approve once it is rebased and the items below are done.

crates/engine/src/read_options_tests/recording.rs

Optional. The file is 848 lines, about 700 of them unimplemented! stubs that repeat the Fake and Scripted doubles.

Other optional notes

  • No backend test passes true: 103 ReadOptions::default() calls in crates/storage-* and none with new(true), including tests that assert read after write, such as storage-sqlite/src/data/update_item_tests.rs:113.
  • The PR body says CI runs five PostgreSQL test binaries, 90 tests. CI runs --tests: 36 targets, 452 passed, including gsi_online_build and table_snapshot, which this PR edits.
  • The export test says it checks every page, and its double returns one page.

}
}

impl StreamEngine for RecordingStorage {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test targets do not compile on a merge with current main: cargo check --workspace --all-targets gives 5 errors in 4 targets. first_sequence_number_at_or_after, which #468 added to the trait, is missing here, and the new query and get_item calls on main pass one argument too few at storage-postgres/tests/lsi_query_plan.rs:300, lsi_query_plan/multi_range_gsi.rs:274 and catalog_check/support.rs:462. The release binary still builds, and the green CI ran on an older merge. This comes from main moving.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged main at 3534c9e in b1e7f8d. The one text conflict was crates/engine/src/import_export.rs. I took main's file and moved the consistent-read scan to crates/engine/src/import_export/files.rs, where #1009 moved the export.

With the merge alone, cargo check --workspace --all-targets gave 6 errors in 5 targets: your five, plus storage-sqlite/tests/wasm_shim.rs:1324, which #1009 added after your review. ca3dc07 fixes them. Each new call passes the value its read needs. The GetItem in catalog_check/support.rs, the LSI Query page in lsi_query_plan.rs and the Scan in wasm_shim.rs assert they see rows the test wrote, so they pass ReadOptions::new(true). The GSI Query in multi_range_gsi.rs passes the default, the only value the engine sends for a GSI read. The recording double gained first_sequence_number_at_or_after here and went away in 5c047fc. The check now finishes with 0 errors.

})
}

/// `_opts.consistent_read` is accepted and not acted on. Reads run at the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this head Cassandra reads items at ONE for both values, as this comment says. On a merge with main the same reads run at LOCAL_QUORUM, from #945, which closed #560. This comment, ADR-0024 (lines 102 to 110), the storage design doc and 12-extending-extenddb-storage.md:101 would then describe ONE and an open #560.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f7744ce. After the merge the item reads run at LOCAL_QUORUM through cassandra_util::Stmt::Read, the plain writes at LOCAL_QUORUM, and the lightweight transactions run Paxos at LOCAL_SERIAL and commit at LOCAL_QUORUM (#945). The comment now says that and gives the clock condition that the high availability design states. It also says that a routing change would read false at LOCAL_ONE and keep true at LOCAL_QUORUM. ADR-0024 (Consequences), docs/design/04-component-storage.md and docs/manuals/12-extending-extenddb-storage.md now describe the merged levels. The ADR names #560 as closed by #945, and the other two drop the #560 reference. The PR body paragraph on the Cassandra gap goes the same way.

let stored = ctx
.storage
.get_item(key_info, key)
.get_item(key_info, key, ReadOptions::new(true))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test covers the three PartiQL reads this PR changes: this one and partiql/batch.rs:529 (both pass true), and partiql/base_join.rs:132 (passes the client's value). With each changed to ReadOptions::default(), and base_join also to true, all 881 engine tests pass. The recording double used for the other reads would hold them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in f5899fe, crates/engine/src/read_options_tests/partiql.rs, on the recording double. lsi_read_that_reaches_back_carries_the_clients_consistent_read runs SELECT payload FROM "Events"."ByCreated" WHERE pk = 'device-1' with true, false and the member absent. The LSI fixture now projects the keys only, so the read reaches back, and the two base-table GetItems carry the client's value. an_update_past_the_item_limit_reads_its_item_consistent runs an UPDATE with a 32-level parameter. a_failed_batch_write_sizes_its_charge_from_a_consistent_read runs a batch UPDATE whose storage write fails its condition, with ReturnConsumedCapacity: TOTAL. Both check one GetItem with consistent_read: true, with the member absent and with false. In edaa9c3 the first test also checks the ReadOptions of the SELECT's own index read.

With your three changes applied together, the three tests fail and the other 11 pass. With base_join set to true alone, the first test fails. The module sits behind the partiql feature, like the layer it tests.

Comment thread crates/storage/src/lib.rs Outdated
/// the read reflects every write acknowledged before it started. `false`: the
/// read may miss recently acknowledged writes. A backend that serves every
/// read from the copy that took the write meets both by ignoring the value;
/// every in-tree backend does that today. A backend with followers can serve

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"every in-tree backend" serves reads from the copy that took the write. The Cassandra comment in this PR, ADR-0024, the manual and the design doc say Cassandra does not. 0f2aa19 fixed the manual and the design doc and left this line. The get_item doc at line 352 says the flag carries the request's ConsistentRead, and export and the two PartiQL reads pass true without one; the ADR, the manual, the design doc and the PR body list GetItem, Query, Scan, BatchGetItem and export only.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f7744ce. The ReadOptions doc now says that SQLite and PostgreSQL, and MongoDB on a replica-set connection, serve every read from the copy that took the write. For Cassandra it says that the read and write levels intersect, at LOCAL_QUORUM for both values after the merge, with the clocks in sync. It also lists what the engine passes. The client's value goes on GetItem, Query and Scan, and per table on BatchGetItem. It also goes on the base-table read under a PartiQL SELECT from an LSI that does not project a selected attribute. A read through a GSI gets false. true goes on the export scan and on two PartiQL reads. One evaluates an UPDATE whose value nests past the item limit. The other sizes a failed batch write's charge. The ADR's Decision has the same list. The get_item doc, the two design docs and the manual point at the ReadOptions doc instead of keeping a copy, and the scan doc names the export scan. The field and constructor docs of ReadOptions no longer say that the value is the client's.

})
}

/// `_opts.consistent_read` is accepted and not acted on. Every read goes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. The comment says every read goes to the primary. With directConnection=true, which CI and the test scripts use, reads go out with $readPreference: primaryPreferred, and after a step-down the SECONDARY node answered GetItem ConsistentRead=true with 200 while PutItem failed (twice). The behaviour predates this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is from this PR, so I corrected it in f7744ce. On a replica-set connection the guard refuses a non-primary read preference and the reads go to the primary. With directConnection=true the driver pins one member and sends $readPreference: primaryPreferred on its reads. The server selection specification requires that for a direct connection to a replica-set member when the application preference is primary or unset. A member that stepped down therefore keeps answering reads while its writes fail. The comment now says both.

The step-down behaviour predates this PR, and I have not reproduced it here. I opened #1473 with your measurement and steps, for the backend to decide what a direct connection should do after a step-down.

Main moved the export scan from import_export.rs to import_export/files.rs
(#1009). The consistent read this branch asks for on that scan moves with it.
Main added four reads since this branch's merge base, each without the
ReadOptions parameter this branch adds: the PostgreSQL catalog check's GetItem
on the items it wrote, its LSI query plan page, its multi-range GSI page, and
the SQLite WebAssembly shim test's scan over the items it wrote. The reads
that assert items written before them ask for a consistent read; the GSI page
passes false, the only value the engine sends for a global secondary index
read.

#468 added first_sequence_number_at_or_after to StreamEngine; the recording
double of the read-options tests gets the method, unreached like its other
stubs.
read_options_tests/recording.rs held a third storage double, 856 lines, about
700 of them unimplemented stubs repeating the bodies the backup tests' Fake
and the batch write tests' Scripted already carry. The read-options tests now
run on Fake: it records every get_item, query and scan with the ReadOptions it
received, finds no item, answers query and scan pages from a script, and
answers table_key_info, index_info and describe_table from the maps a test
fills. Fake gains the two StorageEngine traits it did not implement
(StreamEngine and WorkerStore, unused like its other stubs), so it can stand
in for the whole engine. recording.rs keeps only the constructor that loads
the fixture tables and indexes: 39 lines.
The PartiQL layer makes three storage reads of its own, outside the
classic handlers, and no test covered their ReadOptions: the base-table
read under an LSI read that reaches back (partiql/base_join.rs) carries
the client's ConsistentRead, and the read that evaluates an UPDATE whose
value nests past the item limit (partiql/item_depth.rs) and the read that
sizes the charge of a batch write that failed at its item
(partiql/batch.rs) are consistent whatever the client sent. Each site
changed to ReadOptions::default(), and base_join also to
ReadOptions::new(true), left every engine test green.

read_options_tests/partiql.rs runs ExecuteStatement and
BatchExecuteStatement over the recording double and checks the recorded
read of each site, with the three client shapes for the join and with
false and absent for the two consistent reads. The module is behind the
partiql feature, like the layer it tests. The LSI fixture projects the
keys only, so a SELECT of another attribute reaches back; the recording
double answers the index read from a scripted page and fails an update
with a scripted error. The partiql test context's allowing authorizer is
crate-visible for these tests.
export_scan_asks_for_a_consistent_read says it checks every page of the
export scan, and the double answered one empty page, so the test saw one
read. The double now answers two pages, the first with a last key, and the
test asserts two consistent scans of the table.
… that passes true

Since #945 the Cassandra backend runs its item reads and base-row writes at
LOCAL_QUORUM, with Paxos at LOCAL_SERIAL for the lightweight transactions.
Issue #560 is closed. The Cassandra get_item comment, ADR-0024, the storage
design and the storage extension manual still described reads at ONE and an
open #560. They now describe the merged levels, with the clock condition the
high availability design states. The ReadOptions doc no longer says that
every in-tree backend serves reads from the copy that took the write.
Cassandra does not: its read and write levels intersect. MongoDB does on a
replica-set connection only.

The lists of the reads that carry the flag named GetItem, Query, Scan,
BatchGetItem and export. The ReadOptions doc and the ADR's Decision now list
every read, the three PartiQL reads and the global secondary index read
included. The base-table read under an LSI SELECT carries the client's
value. The read that evaluates an UPDATE past the item limit and the read
that sizes a failed batch write's charge pass true. The get_item doc, the
storage design, the high availability design and the manual point at the
ReadOptions doc. They keep no copy of the list.

The MongoDB get_item comment said every read goes to the primary. That holds
for a replica-set connection, whose non-primary read preferences the
connection guard refuses. With directConnection=true the driver sends reads
with $readPreference primaryPreferred, as the server selection specification
asks for a direct connection. So a member that stepped down keeps answering
reads. The comment now says so.
…e-read helper

The test of the base-table read under an LSI SELECT now also checks the
`ReadOptions` of the SELECT's own index read, which `request.rs` forwards
from the client. `only_read` returns the one storage read a test made, for
`single_read` and the two PartiQL write tests, which had a copy of it. The
recording double's module doc names `update_error`.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

Merged main at 3534c9e (b1e7f8d) and fixed the compile errors in ca3dc07: your five plus one from #1009, which landed after the review. cargo check --workspace --all-targets finishes with 0 errors. Details in the thread.

recording.rs: rebuilt on the backup tests' Fake in 5c047fc. Fake records every get_item, query and scan with its ReadOptions, answers query and scan from scripted pages, and gained the two traits it did not implement. recording.rs keeps the constructor that loads the fixtures. 848 lines at your head, 856 after the merge fix, 39 now. The 11 tests in read_options_tests.rs pass on it, and 5c047fc changes only their constructor call.

No backend test passes true: unchanged. No in-tree backend routes on the value, so a test that passes true on a read after a write asserts nothing the backend can fail today. The engine tests pin what each handler passes. A change that routes false to a replica can tell the two values apart, and its tests would pass each value.

The CI sentence: fixed in the body. CI runs cargo test --release -p extenddb-storage-postgres --tests. On the 17 November run of 6e96426 that is 36 targets and 452 tests passed, gsi_online_build and table_snapshot among them.

The export test: in 4371e2d the double answers two pages, the first with a last key, and the test asserts two consistent scans.

#584 marked the PostgreSQL read replica section of the storage design as a
proposal, as this branch did. The merge keeps main's text, which also says
that a read on a global secondary index can lag the base table. It adds this
branch's sentence that the flag reaches the backend as
ReadOptions::consistent_read. The proposal's read_pool helper keeps this
branch's call with opts.consistent_read.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items from the earlier review are resolved at edaa9c3.

  • Every target compiles at this head and with main a417b2f merged in, on 1.97.0 and on the 1.91.1 MSRV, with the Cassandra and MongoDB test-hooks features. The four new call sites pass ReadOptions::new(true) where the test reads back rows it wrote, and the GSI page passes the default, as the engine does for a GSI read.
  • The Cassandra comment, ADR-0024, the storage design doc and manual 12 say LOCAL_QUORUM with LOCAL_SERIAL for the Paxos round, which cassandra_util.rs:88 sets: a Cassandra build of this head ran all 12 traced GetItem, Query and Scan reads, ConsistentRead true and false, at LOCAL_QUORUM.
  • The three PartiQL reads have tests, and setting each call site to default(), or dropping the flag on a SELECT's own index read, fails the test named for it. The lib.rs list matches the 8 ReadOptions sites in the engine, the export scan passes ReadOptions::new(true) and its test pages twice, the MongoDB comment matches the driver's primaryPreferred on a direct connection, the test double is 39 lines on the backup Fake, and the body names the --tests command CI runs.
  • 578 read shapes, 22 PartiQL write failures and raw edge bodies, twice each, answer the same at this head as at 6e96426 on SQLite, PostgreSQL, MongoDB and Cassandra, and as at main on three of them; an export of 2500 items in 3 pages writes the file main writes. GetItem on a 9 KB item costs 3.0 and 1.5, a consistent read on a GSI is refused with the service's sentence on Query, Scan and ExecuteStatement, and TransactGetItems costs 8.0 and 4.0, as on the service in us-east-1. fmt and both clippy forms are clean, and CI is green on 59 of 59 checks.

rlunar pushed a commit to rlunar/extenddb that referenced this pull request Nov 25, 2026
…DB#584)

* docs: describe the PostgreSQL read replica mode as a proposal, not current behaviour

Four design documents stated a read replica mode in the present tense: a
storage.postgres.read_replica_url setting with read_replica_pool_size, a
read_pool field on PostgresEngine, a read_pool() helper, and
ConsistentRead=false reads routed to a streaming replica. None of it exists:
grep read_replica over crates/ returns nothing, PostgresConfig carries
deny_unknown_fields, and every item read and write runs on data_pool. An
operator who copied read_replica_url from the configuration reference got a
server that refused to start.

- 01-requirements: REQ-DATA-015 states what the backends do (the flag reaches
  storage as ReadOptions::consistent_read; every in-tree backend serves both
  values from the copy that took the write) and REQ-PG-008 is marked proposed
  with the startup refusal named.
- 02-high-level-design 4.7: the decision is strongly consistent reads today,
  the replica route a proposal; the rationale bullets are in the conditional.
- 04-component-storage 5.2: the pool sketch is labelled a proposal (5.3 is
  rewritten by ExtendDB#559).
- 08-component-config: the read_replica_url environment row and the two
  sample lines are removed, since the setting stops the server.
- technical-debt F-2 and the TODO index line say the same in the same tense.

Closes ExtendDB#561

* docs: label section 5.3 as the proposal and correct the read consistency claims

Review of 204827d found four statements in the new text that do not hold at
this head. It also found two keys in a sample that the server refuses.

- 04-component-storage 5.2 and 5.3: the 5.2 label pointed at 5.3 for what the
  backend does today. 5.3 still described the replica mode in the present
  tense. Both sections now read as the proposal. The backend serves every item
  read and write from data_pool. The read_pool helper and read_replica_url
  exist only in the sketch. The single-node paragraph carries the label
  "what the backend does today", the replica paragraph the label "proposed".
- 02-high-level-design 4.7: "its reads are strongly consistent whatever
  ConsistentRead says" holds for base table and local secondary index reads.
  Global secondary index rows go through the propagation queue
  (index_propagation_delay_ms, default 10 ms), so a read on a GSI can lag the
  base table. The decision says so. The last rationale bullet now reads the
  same before and after the trait carries the flag: the proposal depends on
  design document 11, Stage 1.
- 08-component-config: connection_timeout_secs and statement_timeout_secs are
  removed from the [storage.postgres] sample. PostgresStorageConfig refuses
  them with the same unknown field error as read_replica_url. A commented
  catalog_pool_size line lists the third key the struct has, as the admin
  guide does. The rest of the section 3 sample is ExtendDB#585.
- 01-requirements REQ-PG-008: the pointer names sections 5.2 and 5.3 of
  document 04, since the code sketch is in 5.2 and the prose in 5.3.

Corrections to the message of 204827d. The flag reaches the engine as
GetItemInput::consistent_read and does not reach storage. The SQLite,
PostgreSQL and MongoDB backends serve every read from the copy that took the
write. The Cassandra backend reads at LOCAL_QUORUM since ExtendDB#945. The struct
that refuses unknown fields is PostgresStorageConfig, not PostgresConfig.
docs/todo-index.md has no change in this PR, because its line already reads
in the future tense.

Refs ExtendDB#561

* docs: name the GSI lag in the single-node paragraph of section 5.3

Section 4.7 of the high-level design now says that base table and local
secondary index reads are strongly consistent. It also says that GSI rows go
through the propagation queue. The single-node paragraph of document 04, section 5.3, still said that all
reads are strongly consistent. This PR relabels that paragraph. It now says
the same as section 4.7 and points at section 6 for the queue.

Refs ExtendDB#561

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>

---------

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants