Repository navigation
fix(server): read request members in the client's order on every build - #781
LeeroyHannigan wants to merge 6 commits into
Conversation
demohan
left a comment
There was a problem hiding this comment.
On the MongoDB build, and on the workspace-root builds that CI runs pytest against (PostgreSQL, Cassandra and MongoDB), the merge-base read request members in the order the client wrote them. DynamoDB uses that order to choose among serialization faults, so those builds gave DynamoDB's answer on the bodies in the inline comments. With the sort they give the name-order answer. I measured each body in us-east-1 on 10 November 2026, two sends each, with the same answer both times.
Merged onto main, the sort also changes PartiQL answers that main gets right. That one comes from main moving under the branch, not from this change, but the merged result answers it wrongly. Keeping the client's order fixes both.
The description also needs four corrections:
- The new file also runs in the Cassandra pytest job, which has
preserve_order, and in the SQLite job, which does not and so cannot fail it. - The published PostgreSQL image is built with
-p extenddband has nopreserve_order, unlike CI's PostgreSQL server. - The "695 tests" selection collects 700 with the run-tests ignore list. The result it reports holds.
- If the sort stays,
serde_json = "1"inCargo.tomlneeds to be at least1.0.129, the first release withsort_all_objects.
| // order. DynamoDB answered each two-fault Query and Scan body measured on | ||
| // 2026-11-03 alike in both orders. Sorting gives every build the sorted | ||
| // order; without `preserve_order` the call does nothing. | ||
| input.sort_all_objects(); |
There was a problem hiding this comment.
On the MongoDB build this changes answers the merge-base gave correctly. Query {..., "Limit": "0", "ConsistentRead": "x"}: DynamoDB answers SerializationException: STRING_VALUE cannot be converted to Integer (Limit). The merge-base MongoDB build names Limit; this change names ConsistentRead. With ConsistentRead written first DynamoDB answers Unexpected token received from parser.
PutItem "Item": {"pk": {"S": "k"}, "b": {}, "a": {"X": "1"}}: DynamoDB answers ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes. The merge-base MongoDB build gives the same. This change gives SerializationException: ... unknown AttributeValue type descriptor: X.
The same holds for UpdateItem with ":b": {} before ":a": {"X": "1"}, for TransactItems[].Put with TableName: 5 before Item: "x", and for this file's own Scan body with :b first. Keeping the client's member order on every build gives DynamoDB's member on all of these. The fingerprint in transact_write_helpers.rs can hash a sorted copy, because DynamoDB accepts a retry with reordered members as a replay.
There was a problem hiding this comment.
The sort is gone. The server crate now enables preserve_order, so every build reads the members in the order the client wrote them. compute_fingerprint hashes a copy with the members sorted by name. On the service, a retry whose Put lists its members in another order replays (16 November, two runs). A different item under the same token answers IdempotentParameterMismatchException.
Your Query and TransactWriteItems pairs and this file's Scan body are rows of the new test, in both orders. On ExtendDB a type-fault row checks serde_json's text, which names the member written first (#1012).
With b or :b written first, the PutItem and UpdateItem bodies now get the service's empty-value answer on every build. With {"X": "1"} written first, ExtendDB still answers the descriptor fault, where the service answers the empty-value text in both orders (#629).
| // order. DynamoDB answered each two-fault Query and Scan body measured on | ||
| // 2026-11-03 alike in both orders. Sorting gives every build the sorted | ||
| // order; without `preserve_order` the call does nothing. | ||
| input.sort_all_objects(); |
There was a problem hiding this comment.
Merged onto main, this also changes PartiQL answers on the MongoDB build. ExecuteStatement with the parameter {"M": {"d": <40 nested M levels>, "bad": {"N": "abc"}}}: DynamoDB and main answer Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit. Main with this change answers The parameter cannot be converted to a numeric value: abc.
The BatchExecuteStatement echo of a parameter map {"BB": ..., "Aa": ...} prints BB first on DynamoDB and on main, and Aa first with this change. test_the_first_problem_in_map_member_order_is_reported moves from XPASS to XFAIL, and the comments in params.rs, partiql/mod.rs, echo.rs and table_name_gate.rs that say these builds keep request order stop being true.
There was a problem hiding this comment.
With the sort gone, every build keeps the written order. The ExecuteStatement parameter with d first answers the nesting fault again. On a SQLite server built from this branch, the BatchExecuteStatement echo prints BB first, as the service does.
test_the_first_problem_in_map_member_order_is_reported passes on every build now, so this branch removes its xfail. The comments in params.rs, partiql/mod.rs, echo.rs and table_name_gate.rs say that every build with the server keeps the request's order.
| // client wrote its members in; other builds sort them by name. The typed | ||
| // input deserializers stop at the first member that fails, so on such a | ||
| // build a body with two faults got an error chosen by the client's member | ||
| // order. DynamoDB answered each two-fault Query and Scan body measured on |
There was a problem hiding this comment.
DynamoDB does not answer every two-fault body alike in both orders. Query with Select: 7 and Limit: "0" answers NUMBER_VALUE cannot be converted to String with Select first and STRING_VALUE cannot be converted to Integer with Limit first. The bodies measured on 3 November pair a type fault with a validation fault, and those do answer alike.
There was a problem hiding this comment.
The measurements agree. Two type faults answer the member written first in Query and TransactWriteItems (12 November) and in GetItem, PutItem and UpdateItem (16 November). A sort cannot give that in both orders, so this revision keeps the client's order instead. The test has one row per order for each of those pairs.
| # Copyright 2026 ExtendDB contributors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """The order of a request body's members does not change the error it gets. |
There was a problem hiding this comment.
This does not hold for two type faults (see the comment on handler.rs). It holds for the pairs this file sends.
There was a problem hiding this comment.
The docstring now gives three cases. Two type faults answer the member written first. A type fault beside a validation fault answers the type fault in both orders. Two validation faults get one answer in both orders.
| {**head, "ExpressionAttributeValues": values, "Limit": limit}, | ||
| ) | ||
| assert limit_first[0] == 400, limit_first | ||
| assert values_first == limit_first |
There was a problem hiding this comment.
This passes while the change answers DynamoDB's SerializationException: STRING_VALUE cannot be converted to Integer body with ValidationException: ExpressionAttributeValues contains invalid value: ... for key :a. It also passes when the sort runs only for Query and Scan, and when it sorts in descending order. Pinning each body's status, type and message from DynamoDB (xfail on #778 where ExtendDB differs), adding PutItem, UpdateItem and GetItem bodies, and adding a Rust unit test that runs under cargo test --workspace would catch these.
There was a problem hiding this comment.
Each row now pins the service's status, error type and message for one body in one member order. The rows cover Query, Scan, TransactWriteItems, GetItem, PutItem and UpdateItem. On ExtendDB a type-fault row checks serde_json's text instead, which names the member written first (#1012). A row that ExtendDB answers otherwise is a strict xfail on #720, #778 or #629.
The two rows of each pair with two type faults expect different members. A server that reads the members in any fixed order fails one row of each such pair. That covers a descending sort, and a sort for Query and Scan only. With the sort restored after the parse in handle_request, 8 rows fail.
two_type_faults_answer_the_member_written_first, in crates/server/src/handler_member_order_tests.rs, runs under cargo test --workspace. It fails when the server crate loses preserve_order.
| resp = requests.post( | ||
| url, data=payload, headers=dict(request.headers), verify=endpoint_url is None, timeout=30 | ||
| ) | ||
| doc = resp.json() |
There was a problem hiding this comment.
A non-JSON answer raises JSONDecodeError here and the status is lost. tests/raw_signed_request.py has signed_post for raw signed bodies, which would also avoid reading client._request_signer._credentials on line 51.
There was a problem hiding this comment.
The rows now post through signed_post, with the credentials of the boto3 session, so the test no longer reads the client's signer. answer in tests/raw_signed_request.py reads the status, the error type and the message. For an answer that is not JSON it keeps the status and returns the text.
1ddf02d to
f685853
Compare
demohan
left a comment
There was a problem hiding this comment.
The sort is gone, every build keeps the written order, and the fingerprint hashes a sorted copy. Each body from the earlier review now gets DynamoDB's member on all four backends, the PartiQL answers on main match DynamoDB again, and the rows pin DynamoDB's status, type and message. I measured each body in us-east-1 on 19 November 2026, two sends per order.
Three items remain.
- On the SQLite, PostgreSQL and Cassandra builds this changes two answers that main gives correctly. Both come from a walk over one map. The earlier review asked for the written order without these maps in view. UpdateItem with
"ExpressionAttributeValues": {":c": {}, ":b": {}}: DynamoDB and main name:b, and this branch names:c. ExecuteStatement with the parameter{"M": {"e": <40 nested M levels>, "bad": {"N": "abc"}}}: DynamoDB and main answerThe parameter cannot be converted to a numeric value: abc, and this branch answersNesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit. The same holds withnfore. These are rows of #1013. The empty-value check indeserialize_expression_valuesand the parameter walk inparams.rscan visit the members in the bucket order thatprint_orderinecho.rsmodels, or keep name order as main does. tests/test_request_member_order.py:9and the message of f685853 say that two validation faults get one answer in both orders. Inside one map that does not hold: UpdateItem and Scan with:aand:eboth{}answer the key written first. This branch gives the same answers. The PR body words it correctly.two_type_faults_answer_the_member_written_firstpasses undercargo test --locked --workspace --exclude extenddb-backup-storewithpreserve_orderremoved fromcrates/server/Cargo.toml.bsonturns the feature on in any workspace build. It fails undercargo test -p extenddb-server. The pytest rows catch the same loss on the SQLite build.
| # faults with the fault of the member written first. Without this feature a | ||
| # parsed object is sorted by name, except in a build that also compiles | ||
| # `bson`, which turns the feature on. | ||
| serde_json = { workspace = true, features = ["preserve_order"] } |
There was a problem hiding this comment.
With this line the empty-value check in deserialize_expression_values walks ExpressionAttributeValues in the written order on every build. UpdateItem with {":c": {}, ":b": {}} written in that order: DynamoDB answers ExpressionAttributeValues contains invalid value: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes for key :b in both orders, and main on SQLite gives the same. This branch on SQLite answers for key :c. The PartiQL parameter walk changes the same way: {"e": <40 nested M levels>, "bad": {"N": "abc"}} answers The parameter cannot be converted to a numeric value: abc on DynamoDB and on main, and the nesting fault on this branch. Measured 19 November 2026, two sends per order.
There was a problem hiding this comment.
Fixed in 7c3d5d6. The checks of one ExpressionAttributeValues, ExpressionAttributeNames or PartiQL parameter map now visit the members in the order that print_order modelled, on every build. The model moved to extenddb_core::map_order, and the echo uses it there. Both of your bodies get the service's answer, and the n body is a row of the parameter test in params.rs.
I measured more bodies on 19 November, two sends per order. The service checks one placeholder map in steps. A value of the wrong JSON type comes first, the first one written. Then ExpressionAttributeValues checks its keys ahead of its values, and ExpressionAttributeNames its empty names ahead of its keys. The bucket order alone would answer the empty :b for {":b": {}, ":a": {"S": 5}} in both orders, where the service and main answer the type fault. So the two placeholder maps now check the JSON types first, with the check that check_parameter_types runs. The bodies are rows of tests/test_request_member_order.py. Each of its 44 rows got the pinned answer from the service twice, and a server built from main fails 22 of them.
| Amazon DynamoDB answers a body with two type faults (members it cannot | ||
| convert to their type) with the fault of the member written first, and a | ||
| type fault beside a validation fault with the type fault in either order. | ||
| Two validation faults get one answer in both orders. |
There was a problem hiding this comment.
Inside one map this does not hold. UpdateItem with "ExpressionAttributeValues": {":a": {}, ":e": {}} answers for key :a, and with :e written first answers for key :e. Scan gives the same. This branch matches both, so only the sentence needs to change. The f685853 commit message has the same sentence.
There was a problem hiding this comment.
Fixed in 4774b89. The docstring now says that inside one map the order written decides only between two members in one bucket, such as :a and :e. The :a and :e bodies are rows of the file in both orders, with and without a third member. The commit message says the same.
| /// parses the body itself and so checks the feature, not `handle_request`: | ||
| /// `tests/test_request_member_order.py` sends the bodies through the handler. | ||
| #[tokio::test] | ||
| async fn two_type_faults_answer_the_member_written_first() { |
There was a problem hiding this comment.
With preserve_order removed from crates/server/Cargo.toml, this test passes under cargo test --locked --workspace --exclude extenddb-backup-store, the command in test.yml. bson from extenddb-storage-mongodb turns the feature on in any workspace build. Under cargo test -p extenddb-server it fails at line 67. A CI step that runs it with -p extenddb-server would let it fail.
There was a problem hiding this comment.
In the workspace run it cannot fail. Besides bson, the engine's dev-dependency on serde_json turns the feature on there too. I left CI as it is. CI's Python job tests a SQLite server built with -p extenddb --no-default-features --features sqlite, which has neither. Without the feature, that server parses in name order. A name sort after the parse gives that order, and it fails 11 tests there (the first mutant in the description). They are 10 rows of tests/test_request_member_order.py and the map order test of tests/test_partiql_numbers.py. A step with -p extenddb-server would compile the server crate's tree a second time in each test run, for a second check of the same feature. The test's comment and the description now say what it checks in each build. I can add the step if you want it.
compute_fingerprint hashed the TransactItems JSON in the order the parsed request held it. A build with serde_json's preserve_order feature, such as the MongoDB build, holds the client's order. There, a retry that wrote the same members in another order got IdempotentParameterMismatchException. The service replays such a retry. Measured in us-east-1: on 2026-11-10 for an item's attributes, and on 2026-11-16 for a Put's members. A different item under the same token is still a mismatch. The hash now covers a copy with the members of every object sorted by name. A build without preserve_order hashed those bytes before, so its stored tokens still match. A token that a preserve_order build stored for members out of name order answers a mismatch to a retry after the upgrade. compute_fingerprint sorts the copy with Value::sort_all_objects. serde_json added it in 1.0.129, so the workspace now requires that version. The engine's tests turn on preserve_order. Their rows can then hold members out of name order, and the fingerprint test fails without the sort.
The server crate now turns on serde_json's preserve_order feature, so a parsed request keeps the order the client wrote its members in. Before, only a build that compiled the MongoDB backend did, through bson. Other builds read every object in name order. The typed input deserializers stop at the first member that fails, so the builds answered a body with two type faults differently. The service answers such a body with the fault of the member written first. Measured in us-east-1 in both member orders: Query and TransactWriteItems on 2026-11-12, GetItem, PutItem and UpdateItem on 2026-11-16. A sort in every build would make the builds agree, but it cannot match the service in both orders of one body. A unit test sends two type faults in both orders through dispatch. The comments about member order now say that every build with the server keeps the request's order. Inside one map the service walks Java HashMap order (#1013), so for two faults in different buckets ExtendDB can still answer the other member. The PartiQL parameter map test no longer needs its build-dependent xfail. Every build now writes /health with "status" first. The admin guide and the backup manual showed its keys in name order, or said that the order depends on the build. Their examples now show "status" first. Fixes #723
The service checks the members of one ExpressionAttributeValues map in
the order that a Java HashMap of the map yields them. It checks one
PartiQL parameter map the same way. Two members in one bucket come in
the order written. The previous commit made every build walk these maps
in the order written. Main walks them in name order on the builds
without the MongoDB backend. Neither order is the service's, so the
previous commit changed answers that main gave correctly. For :c and :b
both {}, the service and main name :b, and the order written names :c.
The bucket model of the PartiQL echo moves from the engine to
extenddb_core::map_order. The echo, the PartiQL parameter checks and the
checks of ExpressionAttributeValues and ExpressionAttributeNames use it.
For two empty names, the service named either member in each order, so
any fixed order gives one of its answers.
The two placeholder maps also take the service's steps in its order.
The service refuses a value of the wrong JSON type first, the first one
written. It finds such a value while it reads the request. A JSON null
is not such a value. Then ExpressionAttributeValues checks its keys, and
then its values. ExpressionAttributeNames checks its empty names ahead
of its keys. The refusal of each fault keeps its text.
ExpressionAttributeValues uses check_types, the check that
check_parameter_types runs on each PartiQL parameter. A build without the
partiql feature has no PartiQL module, so both functions move from that
module to serde_helpers. PR #1103 makes the same move.
Measured in us-east-1 on 2026-11-12 and 2026-11-19, in both member
orders, on maps of two, three and four members (#1013).
…ders Each row of test_request_member_order.py sends one body with its members in the order written. It pins the status, error type and message the service gave in us-east-1. Two type faults in a Query, a TransactWriteItems Put, GetItem, PutItem or UpdateItem answer the member written first. A type fault beside a validation fault answers the type fault in both orders. A Limit of 0.0 beside an empty value answers the Limit fault in both orders. Other rows hold two faults in one ExpressionAttributeValues, ExpressionAttributeNames or PartiQL parameter map. The service answers a value of the wrong JSON type first, and of two such values the one written first. A malformed key of ExpressionAttributeValues comes ahead of an empty value. Among the other faults, the service names the member that a Java HashMap of the map yields first. The order written decides only between two members in one bucket, such as :a and :e. A server that walks such a map in name order or in the order written fails a row. The service named either member from one send to the next for two malformed keys in ExpressionAttributeValues, and for two empty names. No row pins those. ExtendDB words a type fault with serde_json's text or with its own (#1012), and on ExtendDB a type-fault row checks that text. For two type faults it names the member written first, so a server that reads the members in another order fails the row. A row that ExtendDB answers otherwise is a strict xfail: - a fractional Limit (#720) - a Limit fault after a value fault (#778) The rows post through signed_post, and a new helper beside it in raw_signed_request.py, answer, reads the status, error type and message of a response. An answer that is not JSON keeps its status.
f685853 to
4774b89
Compare
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier reviews are resolved at 4774b89. Each body was sent twice to the service and to this head on SQLite, PostgreSQL, MongoDB and Cassandra.
- UpdateItem with
{":c": {}, ":b": {}}answers the empty value errorfor key :bin both written orders, as the service does. Scan, Query, DeleteItem and TransactWriteItems answer the same. - ExecuteStatement with a 40-level parameter
eornbeside"bad": {"N": "abc"}answersThe parameter cannot be converted to a numeric value: abcin both orders. PartiQL pairsm/randk/u, and placeholder maps of 7 and 13 members, also match the service in both orders. - Of 104 bodies, 24 that answered differently at f685853 now match the service, and none that matched answers differently here. 200 placeholder pairs and a 100-member PartiQL map keep each value with its key.
- With
preserve_orderremoved, 2 core unit tests and 7 wire rows fail, and the SQLite pytest build CI uses fails 11 tests. CI is green on 64 of 64 checks.
crates/server/tests/handler_member_order_tests.rs
Optional. Under CI's cargo test --workspace, preserve_order is on, so this test cannot fail there. It fails under cargo test -p extenddb-server. A CI step running that crate alone would let it fail where it is meant to.
crates/core/src/params.rs:41 and serde_helpers.rs:458
Optional. These comments say the crate's own tests run in name order. Under cargo test --workspace they run in written order, because preserve_order is on.
…mber order test Main's #526 added two parameters to compute_fingerprint: the request's ReturnConsumedCapacity and ReturnItemCollectionMetrics. The merge of main into this branch (9dbeb7d) left this branch's test fingerprint_hashes_the_members_sorted_by_name with a call of two arguments. So the engine's lib tests did not compile. The test now calls the module's fp helper, which passes NONE for both. With NONE, the hash covers the same bytes as before #526, so each expected fingerprint is unchanged.
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier review are resolved at 4ef91ea. Each body was sent twice to the service in us-east-1 and to SQLite, PostgreSQL, MongoDB and Cassandra servers built from this head.
- UpdateItem with
{":b":{},":c":{}}answers... for key :bin both written orders, and so do the Query, DeleteItem, TransactWriteItems and Scan forms. ExecuteStatement with a 40-leveleornbeside"bad":{"N":"abc"}answersThe parameter cannot be converted to a numeric value: abcin both orders, as do the m/r and k/u pairs and the 7- and 13-member maps. - The 104 bodies from the earlier round answer at this head as at 4774b89, the four backends answer alike on 113 of 113, and this head matches the service on 100 of 113 against 72 on main, with none regressed; the other 13 differ on main and at 4774b89 too (#1160, #1104, #778, #720). 200 placeholder pairs and a 100-member PartiQL map store every value under its own key.
- 4ef91ea makes the engine tests compile after the merge of main without changing the four expected fingerprints, and removing the sort in
compute_fingerprintfailstransact_write_helpers.rs:407. With main's #526, a reordered retry with the same token replays with 200 on the service and on all four backends, and addingReturnConsumedCapacityorReturnItemCollectionMetrics, or changing the item, answersIdempotentParameterMismatchException. - With
preserve_orderremoved, the Rust test fails under-p extenddb-serverand 11 SQLite wire tests fail; with both map walks in parsed order, 2 core tests and 7 wire rows fail. fmt, both clippy commands, the 1.91.1 check and core with and without the feature are clean, and CI is green on 64 of 64 checks.
crates/core/src/params.rs:41
Optional. Under cargo test --workspace this crate's tests do not run in name order, so this comment and serde_helpers.rs:458 describe the -p extenddb-server run only.
Changes since the last review
demohan approved 4774b89 on 24 November. Since then the branch has two new commits:
mainat 018715e, through GitHub's update of the branch.ReturnConsumedCapacityandReturnItemCollectionMetricstocompute_fingerprint. The testfingerprint_hashes_the_members_sorted_by_namenow calls the module'sfphelper, which passes NONE for both. With NONE the hash covers the same bytes as before fix(engine): compare the Return fields on a TransactWriteItems token replay #526, so each expected fingerprint is unchanged.CI at 4ef91ea passed all 64 checks, and code scanning reports no open alert.
What
The server crate enables
serde_json'spreserve_orderfeature. Every build of theextenddbbinary now parses a request with its members in the order the client wrote them. That covers the four Dockerfiles and the npm binaries. Before, only a build that compiled the MongoDB backend kept that order, becausebson2.15.0 enables the feature. The other builds read every object in name order.Inside one map the service uses another order. It checks the members of one
ExpressionAttributeValuesmap or one PartiQL parameter map in the order that a JavaHashMapof the map yields them. This change walks those maps andExpressionAttributeNamesin that order on every build.The changes:
crates/server/Cargo.tomlenables the feature, with a comment that gives the reason.compute_fingerprinthashes a copy ofTransactItemswith the members of every object sorted by name. It callsValue::sort_all_objects, whichserde_jsonadded in 1.0.129. The workspace requirement moves from"1"to"1.0.129".Cargo.lockdoes not change, because it holds 1.0.150.crates/engine/Cargo.tomlenables the feature for the engine's tests.crates/core/src/map_order.rsholds the bucket model thatprint_orderin the PartiQL echo held, and its tests. The echo, the PartiQL parameter checks and the two placeholder maps use it.deserialize_placeholder_mapinserde_helpers.rsruns its checks in the service's order. A value of the wrong JSON type comes first, the first one written. A JSON null is not such a value. ThenExpressionAttributeValueschecks its keys and then its values, andExpressionAttributeNameschecks its empty names and then its keys. Each fault keeps its text.check_parameter_typesand its check of one value move frompartiql/params.rstoserde_helpers.rs, because a build without thepartiqlfeature has no PartiQL module.params.rsre-exports it. fix(core): answer JSON null members as DynamoDB does #1103 makes the same move, so the two branches conflict in five hunks of the two files. A merge that keeps one copy passes the core tests.table_name_gate.rs,partiql/mod.rs,partiql/common.rs,core/src/partiql/params.rs,backup_format/data_file.rsanddata_file_nested_decode_memory.rs./healthwithstatusfirst, the order that every build now writes.crates/server/src/handler_member_order_tests.rs, the dual-target filetests/test_request_member_order.py, a table of two-fault maps inserde_helpers.rsand the map rows ofparams.rs.tests/raw_signed_request.pygetsanswer, which reads the status, error type and message of a response.tests/test_partiql_numbers.pydrops the xfail that depended on the build.Measured on Amazon DynamoDB
us-east-1, raw signed bodies with the members in the order written. Two type faults in two members of the body get the fault of the member written first. Every answer is HTTP 400
SerializationException."Limit": "0","ConsistentRead": "x""Select": 7,"Limit": "0""TableName": 5,"Item": "x""ConsistentRead": "x","ProjectionExpression": 5"ReturnValues": 5,"Expected": "x""ReturnValues": 5,"ExpressionAttributeNames": "x"A type fault beside a validation fault answers the type fault in both orders. A
Limitof 0.0 beside an empty value answers theLimitfault in both orders.Two faults in one map. In a table of 4 buckets,
:bis in bucket 0,:cin 1, and:aand:ein 3.badandxare in bucket 0, andaandein 1. A map of four members takes 8 buckets, whereais in bucket 1 andbadin 4.ExpressionAttributeValues:cand:bboth{}:b:aand:cboth{}:c:aand:eboth{}, with and without a valid:p:c={"S": 5}and:b={"BOOL": "x"}:b={}and:a={"S": 5}SerializationExceptionfor:abwith a valid value, and:c={}bExpressionAttributeValues, with a valid:p:b={}and:a={"X": "1"}:bExpressionAttributeNames#c=""and#b=5SerializationExceptionfor#b#c=""and#b= null#ce40 maps deep andbad={"N": "abc"}badanda40 maps deep, with and without a validxbadanda40 maps deep, with a validxandyThe 44 rows of
tests/test_request_member_order.pypin these answers. On 19 November a script posted each row body twice, as the test posts it. All 88 answers equal the pinned status, error type and message. The:aand:crows, the:cand:brows, theerow and the Scan row date from 12 November (#1013). The other one-map rows date from 19 November, with 2 sends per order and the same answer each time.For two malformed keys in
ExpressionAttributeValuesand for two empty names, the service named either member from one send to the next. No fixed order matches it every time. For a malformed key beside an empty name it named the empty name in both orders. Its text there has a1 validation error detected:prefix that ExtendDB does not send (#1160), so the Rust table pins that row and the Python file does not.Other effects on the PostgreSQL, SQLite and Cassandra builds
The MongoDB build already behaved this way, except in the three maps above, which change on every build.
KeyorItemas written. Before, it used the first by name. Neither reads the key schema (Per-partition throttling takes the first attribute of Key or Item as the partition key #779).-p extenddbbuild sorts maps by name. That stops being true with this change. The two branches merge without a conflict.json!, such as/health, write their keys in the order of the code. A JSON client sees no difference.NextTokenlists its members in written order. A token from an earlier build still decodes.Typed items and
Mvalues areBTreeMaps. So stream records, backup data files, exports and the duplicate item checks keep name order.compute_fingerprintmakes one more copy of theTransactItemstree while it hashes. It runs only for a TransactWriteItems with aClientRequestToken. A standalone benchmark of three 4 MB request shapes measured 1.4 to 38 ms and 6 to 109 MB for the copy and the sort.Not in this change
serde_json's text or ExtendDB's own, which differs from the service's (A request member of the wrong JSON type gets serde_json's error text, where the service sends its own #1012).Minside an attribute value is one. For:v={"M": {"b": {}, "e": {"NULL": false}}}the service refuses theNULLofein both orders, and ExtendDB refuses the emptybwhen the request writesbfirst (19 November). Items and keys are others. I did not measure the service's order for the legacy condition maps andRequestItems.ExpressionAttributeValuesahead of a number it cannot read in another member, because it checks the numbers later (Two faults in one request map: ExtendDB can report another member than the service #1013).ExpressionAttributeValuesgets aValidationExceptiontext, where the service answersSerializationException(19 November). PutItem answers ValidationException for a set member or list element of the wrong JSON type, where DynamoDB answers SerializationException #1104 has the same reader for items.ExpressionAttributeValuesgetsSerializationException, where the service answersValidationException(A JSON null in a key, an ExpressionAttributeValues entry, an AttributesToGet element or a batch or transaction item answers SerializationException, where DynamoDB answers ValidationException #1102).NULLof false otherwise than the service (UpdateItem words an empty expression attribute name and a NULL of false otherwise than DynamoDB #1160).Limit(Query: an empty AttributesToGet, a fractional Limit, a value nested 32 levels deep and a malformed number in ExclusiveStartKey answer differently from the service #720) and aLimitfault after a value fault (Query and Scan: a Limit fault beside an ExpressionAttributeValues fault answers the value fault; DynamoDB answers the Limit fault #778). Their rows are strict xfails on ExtendDB.Why
The builds answered a body with two type faults differently. The typed input deserializers visit the members in the map's order and stop at the first one that fails. The MongoDB build visited the written order and answered as the service does. The other builds visited name order. They answered the other fault when the member first by name was not the one written first.
Inside one map, main's name order gives another member than the service for some maps, and the written order for others. Walking those maps in the service's order gives the service's member on every build.
Closes #723
Testing done
At 4774b89, on main c2e9a32.
A SQLite server,
cargo build --locked -p extenddb --no-default-features --features sqlite, on 127.0.0.1:tests/test_request_member_order.pyandtests/test_partiql_numbers.py: 147 passed, 3 xfailed.test_the_first_problem_in_map_member_order_is_reported.test_query_scan.py: 3876 passed, 3 skipped, 10 xfailed. CI runs the whole suite on the SQLite integration server.Mutants:
handle_request, which gives the order of a build without the feature: 11 rows fail.preserve_orderremoved fromcrates/server/Cargo.toml: the Rust test fails undercargo test -p extenddb-server, and passes at the head.serde_helpers.rs, in both feature modes. They drop the type check, check the values ofExpressionAttributeValuesahead of its keys, or check the keys ofExpressionAttributeNamesahead of its empty names.compute_fingerprint:cargo test --locked -p extenddb-engine --lib fingerprintfails.In a build of the whole workspace,
bsonand the engine's dev-dependency also turn the feature on. There the Rust testhandler_member_order_tests.rschecksdispatchalone. It checks the feature undercargo test -p extenddb-server, as the second mutant shows. In CI the Python rows check it on the SQLite server, which has neither.Builds and checks:
cargo +1.97.0 fmt --all -- --check: pass.clippy.yml, on 1.97.0 with--lockedand-D warnings: pass.cargo +1.91.1 check --locked --workspace --all-targets: pass.cargo +1.97.0 test --locked --lib, with-pfor each crate:extenddb-engine867 passed,extenddb-core1151 passed and 1 ignored, and the same forextenddb-corewith--features serde_json/preserve_order.extenddb-servergives 514 passed and 5 failed. The 5 arebackup_storetests that need a temporary directory whose ancestors belong to root or to the test user. This host has no such directory.cargo +1.97.0 check --locked -p extenddb-core --no-default-features --all-targets: pass.cargo tree -i serde_json -e featuresshowspreserve_orderfor the feature setspostgres,mongodb,cassandra,sqlite,dev-modeandsqlite.licenses.yml: pass.Cargo.lockis the same as on main.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
On the PostgreSQL, SQLite and Cassandra builds, a body with two type faults can get another answer than before. It is the fault of the member written first, as the service answers. On every build, two faults in one
ExpressionAttributeValues,ExpressionAttributeNamesor PartiQL parameter map can get another answer than before, in the service's order above. On the PostgreSQL, SQLite and Cassandra builds, the JSON that the server writes lists its keys in another order.A build with
preserve_orderhashed a transaction request in the client's order: the MongoDB build, and a build of the whole workspace. After the upgrade, a retry with the sameClientRequestTokengetsIdempotentParameterMismatchExceptionwhen the first request's members were not in name order. That holds while the store keeps the first request's token, at most 10 minutes on the MongoDB store. Builds without the feature hashed name order before, so their stored tokens still match.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.