Repository navigation
fix(engine): answer an invalid table Scan start key as DynamoDB does - #1218
LeeroyHannigan wants to merge 6 commits into
Conversation
A table Scan refused an ExclusiveStartKey that does not fit the key schema with a longer text. That text was "The provided starting key is invalid: The provided key element does not match the schema". Amazon DynamoDB answers "The provided starting key is invalid" for each of these start keys. They hold another attribute name, an extra attribute or a key of another type, or they leave a key out. A Query already answers this text for the same start keys. Measured in us-east-1 on 19 and 20 Nov 2026, each request twice. The tables were keyed on a partition key, and on a partition key and a sort key. A table Scan now answers each of these start keys with this text. The longer text and the function that chose between the two texts are removed. Fixes #1174.
The five Scan tests that expect "The provided starting key is invalid" compared only the error code and the message. They now call assert_validation with the INVALID_START_KEY constant of the module. assert_validation also checks that the HTTP status is 400.
The doc comment of validate_scan_exclusive_start_key keeps the dates of the measurements and names no issue.
navareamol
left a comment
There was a problem hiding this comment.
CI has not run the wire tests on this head. The Test, Integration Tests, Cassandra Integration Tests and MongoDB Integration Tests runs for 4b7486e (45695123506, 45695122959, 45695123427 and 45695123014) were cancelled before a runner picked them up, and WebAssembly failed with E0308. WebAssembly passes on main since #1482 landed, and this branch is 14 commits behind main. I merged current main (222d80a) into the head locally: no conflict, it builds, and on SQLite the six tests/python files from the description pass (249), as do tests/test_read_paging.py, tests/test_query_scan.py and tests/test_attribute_value_validation.py (294). So PostgreSQL, Cassandra and MongoDB have no result for this change yet. Could you update the branch with main once #1179 lands and let these workflows finish?
The five changed tests cover 5 of the 11 refused start keys in the description table. These rows have no test: table A with {"pk": {"N": "42"}}, and table B with {"pk": {"S": "a"}, "sk": {"SS": ["a"]}}, with {"pk": {"S": "P"}}, with {}, and the two Segment 0 of 2 rows. The Segment rows also pass through the segment membership check in crates/engine/src/scan.rs, which runs after the shape check, and nothing pins that order for a table Scan. There is no engine unit test for a table Scan start key either: with the start_key.rs change reverted, the engine library unit tests still pass, 979 of 979. I ran all 11 rows as wire tests on SQLite. They pass on this head merged with main and fail on main and on the revert, so I think the code is right and only the tests are short. Could you add the six missing rows to test_scan_edge_cases.py, for example as one parametrized table like INDEX_START_KEY_ROWS, and a table case (no index) to start_key_tests.rs?
I will approve once CI has run to the end on a branch updated with main and the six missing rows have tests.
DynamoDB refuses 11 start keys of a table Scan with `The provided starting key is invalid` in the table of #1174, and five tests covered 5 of them. TABLE_START_KEY_ROWS adds the other six to one parametrized test. Table "a" is keyed on pk, and table "b" on pk and sk: - "a" with {"pk": {"N": "42"}} - "b" with {"pk": {"S": "a"}, "sk": {"SS": ["a"]}}, with {"pk": {"S": "P"}} and with {} - "b" with Segment 0 of 2, with {"pk": {"N": "42"}, "sk": {"S": "S"}} and with {"pk": {"S": "P"}} Each row is the answer that DynamoDB gave in us-east-1 on 19 or 20 November 2026, on a table that held one item. The answer was HTTP 400, ValidationException and the short text. The test stores the same item before the Scan.
The engine tests checked the start key text of an index Scan and an index Query, but not of a table Scan. table_scan_start_key_faults_answer_as_dynamodb_does sends the measured start keys of a table Scan, without Segment, to validate_scan_exclusive_start_key with no index. It expects `The provided starting key is invalid` for the nine start keys that DynamoDB refuses and no error for the one that it serves.
|
|
The wire suites now run on this head and pass on SQLite, PostgreSQL, Cassandra and MongoDB (run-integration, run-integration-sqlite, cassandra-pytest and mongodb-pytest all pass at 12e4194). Six checks are red: wasm, run-tests (stable and 1.91.1), test, mongodb-rust and mongodb-integration. I read the job logs. wasm fails with E0308 at crates/core/src/metrics/collector.rs:60,
I will approve once the checks are green on a branch that has #1179 updated with main. |
Changes since the last review
TABLE_START_KEY_ROWStotests/python/test_scan_edge_cases.py. It holds the six refused start keys of the table in Why that had no test, and one parametrized test,test_table_start_keys, sends them. Each row asserts the answer that DynamoDB gave. The test stores one item before the Scan, as the measured tables held one item.table_scan_start_key_faults_answer_as_dynamodb_doestocrates/engine/src/start_key_tests.rs. It sends the nine refused start keys of the table withoutSegment, and the served one, tovalidate_scan_exclusive_start_keywith no index.What
A Scan of a table refused an
ExclusiveStartKeythat does not fit the key schema withThe provided starting key is invalid: The provided key element does not match the schema. DynamoDB answersThe provided starting key is invalid. A Query gives that text for the same start keys. A Scan of an index gives it for a key left out, an extra attribute or an empty map. A table Scan now answers each of these start keys with that text.The change is in
crates/engine/src/start_key.rs. It removes the long text, a second copy of the short text, the function that chose between them, and the parameter that carried the choice. The Query constant becomesINVALID_START_KEY_MSGand serves both reads. Five tests intests/python/test_scan_edge_cases.pynow expect the short text. They pass the module'sINVALID_START_KEYtoassert_validation, which also checks HTTP status 400.TABLE_START_KEY_ROWSin the same file holds the other six refused start keys of the table in Why.table_scan_start_key_faults_answer_as_dynamodb_doesincrates/engine/src/start_key_tests.rschecks the table Scan start keys in the engine.Two storage copies of the long text stay, in
scan_implofcrates/storage-sqlite/src/data/query_scan.rsand inscan_implofcrates/storage-postgres/src/data/query_scan.rs. The engine refuses these start keys first, so no request reaches them. The code after each copy relies on the condition that guards it (SQLite reads the partition key withunwrap()), so both stay.The base of this PR is #1179, which changes the same file.
Why
DynamoDB's answers, measured in us-east-1 on 19 and 20 November 2026 for a Scan with an
ExclusiveStartKey. Each request was sent twice and got the same answer both times. The key of table A ispk(S). The key of table B ispkandsk(S).ExclusiveStartKey{"bad": {"S": "p"}}The provided starting key is invalid{}{"pk": {"S": "P"}, "sk": {"S": "S"}}{"pk": {"N": "42"}}{"pk": {"S": "P"}, "sk": {"S": "S"}, "extra": {"S": "junk"}}{"pk": {"N": "42"}, "sk": {"S": "S"}}{"pk": {"S": "a"}, "sk": {"SS": ["a"]}}{"pk": {"S": "P"}}{}Segment0 of 2{"pk": {"N": "42"}, "sk": {"S": "S"}}Segment0 of 2{"pk": {"S": "P"}}{"pk": {"S": "P"}, "sk": {"S": "S"}}Each refusal is HTTP 400
ValidationException. With this change, ExtendDB answers each row as DynamoDB does. The answers of a Query and of an index Scan with these start keys do not change.The wire tests of these rows are in
tests/python/test_scan_edge_cases.py:test_scan_malformed_exclusive_start_key,test_scan_empty_exclusive_start_keyandtest_scan_simple_table_extra_attribute_in_exclusive_start_key.test_scan_extra_attribute_in_exclusive_start_keyandtest_scan_wrong_scalar_type_in_exclusive_start_key.Segmentrows included:TABLE_START_KEY_ROWS.test_scan_full_composite_exclusive_start_key_is_accepted.The two
Segmentrows give DynamoDB's answer. The record does not show the order of DynamoDB's checks, because it does not show which segment DynamoDB gives these keys.handle_scanincrates/engine/src/scan.rsruns the start key shape check before the segment check. On SQLite and on PostgreSQL,{"pk": {"S": "P"}}is outside segment 0 of 2 in the test's table, so its row fails when the segment check runs first.Fixes #1174
Testing done
At 12e4194, with
--lockedon each cargo build, check, clippy and test:cargo +1.97.0 test -p extenddb-engine --lib: 935 passed..github/workflows/clippy.yml, withcargo +1.97.0, are clean:cargo clippy --all-targets --features extenddb-storage-cassandra/test-hooks,extenddb-storage-mongodb/test-hooks -- -D warningsandcargo clippy --all-targets --features extenddb-engine/backup-test-hooks -- -D warnings.cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -W clippy::pedanticgives no warning on a line this PR adds.cargo +1.94.0 check -p extenddb-engine --all-targets,cargo +1.91.1 check -p extenddb-engine --all-targetsandcargo +1.97.0 fmt --all -- --checkare clean too.--no-default-features --features sqlite) and on PostgreSQL 16 (the default build):tests/pythonpassed 255 tests on each backend:test_scan_edge_cases.py,test_query_start_key_index.py,test_query_start_key_partition.py,test_query_start_key_range.py,test_query_scan.pyandtest_composite_keys.py.tests/passed 590 tests on each backend:test_attribute_value_validation.py,test_query_scan.py,test_read_paging.py,test_gsi_multi_range_query.py,test_query_key_value_types.pyandtest_query_begins_with_max_character.py. On each backend, one test skipped, because it runs only on a backend that filters the first RANGE attribute alone.pytest --collect-onlyoftestsand oftests/pythoncollects 7102 and 703 tests with no error.crates/engine/src/start_key.rsof fix(engine): name the start key of the wrong type in an index Scan #1179's head 74fe005, each of the six rows ofTABLE_START_KEY_ROWSfails on SQLite and on PostgreSQL with the long text.table_scan_start_key_faults_answer_as_dynamodb_doesfails, and the other 934 engine lib tests pass.handle_scan, theSegmentrow with{"pk": {"S": "P"}}fails on SQLite and on PostgreSQL with the segment text. TheSegmentrow with{"pk": {"N": "42"}, "sk": {"S": "S"}}passes.start_keytests of the engine pass, and the 56 tests oftest_scan_edge_cases.pypass on SQLite and on PostgreSQL. This merge is not in the branch.extenddb-wasm-adapter.Line counts against #1179: production +8 -33, tests +70 -27.
This PR adds no conflict with an open PR.
Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
Breaking changes
A Scan of a table with an
ExclusiveStartKeythat does not fit the key schema getsThe provided starting key is invalidin place of the longer text. A client that matches the longer text sees the short one. A start key that fits, a Query and a Scan of an index get the same answers as before.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.