Repository navigation
fix(core): truncate and clamp a capacity figure, then bound it - #1167
LeeroyHannigan wants to merge 12 commits into
Conversation
CreateTable and UpdateTable answered SerializationException for a ReadCapacityUnits or WriteCapacityUnits figure past 9223372036854775807 or with a fraction. DynamoDB reads a figure past 9223372036854775807 as 9223372036854775807, and one below -9223372036854775808 as -9223372036854775808, then checks it. It truncates a fraction toward zero: CreateTable with a figure of 5.5 creates the table at 5. ExtendDB now reads the two figures the same way. Two refusals follow the answers DynamoDB gives: - On CreateTable and UpdateTable, a table figure above 1000000000000 gets ValidationException "Given value <n> for <unit> is out of bounds". The check comes after the minimum of 1 and names read units first. RestoreTableFromBackup runs it after it finds the backup. For a missing backup DynamoDB answers BackupNotFoundException. - On CreateTable, an index figure above the per-table maximum gets LimitExceededException. Its text starts "The requested <unit> for index <name>, <n>, is above the per index maximum". The check comes after the account and per-table maxima. DynamoDB refuses an index at 1000000000001 beside a table at 5 for the account limit. It refuses an index at 9223372036854775807 with the per-index text. So the sum of the request's units now wraps past 9223372036854775807, and such an index passes the account limit. Measured in us-east-1 on 14, 16 and 18 November 2026. Each refused request went out twice and got the same answer both times. Fixes #1029.
crates/core/src/validation/provisioned_limits.rs keeps CapacityUnits::of_description from the base and CapacityUnits::wrapping_add from this branch.
On 25 Nov 2026 at 08:04 UTC, DynamoDB answered an UpdateTable with both figures past the 64-bit range with the out-of-bounds text for ReadCapacityUnits. The row is now in CAPACITY_FIGURES and in the ROWS of tests/test_capacity_figure_bounds.py. A mutant of check_table_capacity_bounds that checks the write units first passed every core test before this row. It now fails on the row.
…t by equality The two rows that hold a figure below 1 matched any text that contains "greater than or equal to 1". The core test now compares ExtendDB's full minimum text. The wire file also runs against DynamoDB. So it accepts ExtendDB's full text, or the full text that DynamoDB gave for that row on 18 Nov 2026. The account row of the wire file now takes its limit from AccountMaxWriteCapacityUnits of DescribeLimits. The units that the account holds stay a pattern, because other tables of the account hold them. The comment of capacity_checks says that it repeats the order of enforce_create_table, and that the wire file pins that order.
deserialize_capacity_units reads a figure with a fraction as a 64-bit float first. Above 2^53 the figure takes the nearest float before the truncation, so 9007199254740993.5 reads as 9007199254740994. The doc comment now says so, and that the service was not measured there. The cast in the reader carries the allow for clippy::cast_possible_truncation that saturated_int32 carries for the same cast.
navareamol
left a comment
There was a problem hiding this comment.
The branch does not merge with current main (222d80a). A trial merge conflicts in four files: crates/engine/src/update_table.rs, crates/engine/src/partiql/test_context.rs, crates/server/src/authz_cache.rs and the upgrade manual. The same four conflict when #831's branch (b2b4dc7) merges main, so they come from the base and from main moving, not from these commits. With those resolved by hand, the merged tree builds, clippy with warnings denied is clean on core, engine and server, the core and engine lib tests pass (1252 and 979), and tests/test_capacity_figure_bounds.py passes 13 of 13 on SQLite. CI on this PR ran against the base branch, so it has not seen main. I think #831 needs main merged first, then this branch.
-
UpdateTable on a table that already holds more than 1000000000000 is now refused even when the request keeps that figure. I built a SQLite catalog with the main build holding a table at read 5 and write 1000000000005, then served it with this PR. UpdateTable with read 6 and write 1000000000005 answers
Given value 1000000000005 for WriteCapacityUnits is out of bounds. On #831's branch the per table check refuses only a figure the request raises, so this refusal is new. The Breaking changes section names only RestoreTableFromBackup. Your measured row on a missing table shows the bound comes before the table is read, so I think the code is right and the section should also say that UpdateTable on such a table has to bring the figure to 1000000000000 or less in the same request. -
The wrapping sum rests on two rows: an index at 1000000000001 gets the account text and an index at 9223372036854775807 gets the per index text. I think other rules give the same two answers, for example a per index check that runs ahead of the account check once a figure passes some size. With wrapping, ExtendDB now changes its answer at the exact point where the sum passes 9223372036854775807. Beside a table at write 5, an index at 9223372036854775802 gets the account text with
Requested: 9223372036854775807, and an index at 9223372036854775803 gets the per index text. One index at 4611686018427387904 gets the account text, and two indexes at that figure get the per index text. Has anyone sent DynamoDB the 9223372036854775802 and 9223372036854775803 rows? If it answers the account text and then the per index text, that pins the wrap and both rows belong inCAPACITY_FIGURES. If it does not, the saturating sum from #831 may be the closer rule. -
The description and the doc comment of
deserialize_capacity_unitssay a figure outside the 64 bit range is saturated. A figure past the float range still gets SerializationException: WriteCapacityUnits 1e400, or a 1 followed by 400 zeros, answersnumber out of range. Was DynamoDB sent such a figure? If not, I think the sentence should say the reader saturates up to the float range and that larger figures were not measured.
Optional, not a merge condition: the bound check now runs before the GSI count, duplicate index name and StreamSpecification checks in validate_create_table. A table at write 1000000000001 with 21 indexes, with two indexes of the same name, or with StreamEnabled and no view type answers the out of bounds text each time. Has DynamoDB's order for those pairs been measured?
I will approve once this branch merges cleanly with main through #831, the Breaking changes section names the UpdateTable case, and point 2 has a live measurement or the sum goes back to saturating.
The doc ended with "which #1167 changes". A statement about another open PR in a code comment goes out of date when that PR merges. The doc now ends at the refusal of the parse.
#831's branch merged main and now checks a CreateTable's table and each index against the per-table maximum on their own, with the per-index sentence. crates/core/src/validation/provisioned_limits.rs takes that check from #831, so check_create_table_indexes of this branch goes. It keeps check_table_capacity_bounds and MAX_TABLE_CAPACITY_UNITS from this branch. crates/engine/src/table_limits.rs makes the one call of #831. The test helper capacity_checks of this branch passes the request to check_create_table_capacity, as #831's signature takes it.
The sum of the units of a CreateTable wrapped past 9223372036854775807. An index at 9223372036854775807 beside a table at 5 then got the per-index sentence, which is DynamoDB's answer. Other rules give that answer too. The rows that would tell them apart are CreateTable requests, and no one has sent them to DynamoDB. The sum now saturates at 9223372036854775807 again, as on #831's branch. The measured row of an index at 9223372036854775808 leaves CAPACITY_FIGURES and tests/test_capacity_figure_bounds.py. ExtendDB now answers it with the account sentence and Requested: 9223372036854775807, where DynamoDB answers the per-index sentence. the_units_of_a_create_table_are_summed_up_to_i64_max holds that row with the four figures of the review of 30 Nov 2026. With a sum that wraps, the index at 9223372036854775803 and the two indexes at 4611686018427387904 get the per-index sentence instead, as the first row does.
The doc comment of deserialize_capacity_units said that a figure outside the 64-bit range is saturated. That holds only up to the largest 64-bit float, the largest number serde_json reads. A larger figure, such as 1e400 or a 1 followed by 400 zeros, gets SerializationException with number out of range. DynamoDB reads both of those figures as 9223372036854775807. UpdateTable on a table that does not exist answered "Given value 9223372036854775807 for WriteCapacityUnits is out of bounds" for each, twice, on 3 Dec 2026. The doc comment now says both.
#831's branch inlines check_table_max into check_create_table_capacity and adds gix() to the engine limits test. The merge takes both with no conflict. check_table_capacity_bounds and MAX_TABLE_CAPACITY_UNITS of this branch stay as they were.
the_units_of_a_create_table_are_summed_up_to_i64_max wrote a CreateTable body by hand. It now builds them with provisioned_table, from #831's branch, and passes them to check_create_table_capacity like the file's other CreateTable tests. The first row names the index figure as 9223372036854775807. That is what the reader makes of 9223372036854775808, so the rows and their answers stay the same.
The Breaking changes section of this PR lists two answers that a table from an earlier release can get. RestoreTableFromBackup refuses a backup of a table with a figure above 1000000000000. UpdateTable has to bring such a figure into the bound. The upgrade manual had no entry for them. The new v1.2.0 entry follows the entry of #831. It also names the reading of a fraction and of a figure outside the 64-bit range, which 1.1.0 refused with SerializationException.
|
#831's branch merged main at c057660 in 3c583fb, and this branch merged #831's branch in 8e14b84, e3ba981 and 23c834b. The four conflicts you found came from #831's branch, and 3c583fb resolves them.
The optional order: not measured. Each pair is a CreateTable, and this round sends none. The bound check stays where it is, and the body lists the three orders as not measured. |
navareamol
left a comment
There was a problem hiding this comment.
The branch merges with current main without a conflict (main at c057660), and all 70 checks pass at 39702c1.
-
The Breaking changes section now names the UpdateTable case. I built a SQLite catalog with the main build holding a table at read 5 and write 1000000000005, then served it with this head. UpdateTable with read 6 and write 1000000000005 answers
Given value 1000000000005 for WriteCapacityUnits is out of bounds. Write 1000000000001 gets the same text, and write 1000000000000 succeeds and leaves the table at 1000000000000. So "bring the figure to 1000000000000 or less in the same request" is exact. Restore of that table's backup without an override is refused, and with an override of 5 and 5 it restores. -
The sum of a CreateTable saturates again. An index at 9223372036854775802, an index at 9223372036854775803 and two indexes at 4611686018427387904 all get the account sentence with
Requested: 9223372036854775807, so the answer no longer changes where the sum passes that figure. I replaced the fold withwrapping_add, andthe_units_of_a_create_table_are_summed_up_to_i64_maxfails at provisioned_limits_tests.rs:593 while the 1271 other core tests pass. I did not send the CreateTable pairs to DynamoDB, and I did not repeat your measurement of the index at 9223372036854775808. #1563 holds that row. -
The doc comment, the What section and the manual entry now say the reader saturates only up to the largest 64 bit float. On the head, 1e19 and 2^64 read as 9223372036854775807, and 1e400, -1e400 and a 401 digit integer get
SerializationExceptionwithnumber out of range. Your statement that DynamoDB reads 1e400 as 9223372036854775807 is your measurement, and I did not repeat it. #1564 holds the difference.
The order of the bound check against the index count, a duplicate index name and a stream without a view type stays unmeasured, as the body says. That was optional and stays optional.
One optional fix: the body says production +61 -3 and tests +333 against #831. git diff --numstat against #831 at bd27313 gives production +64 -3 and tests +330 for me.
Core gives 1272 passed and engine 985 passed, as the body says. The wire file passes 12 on SQLite, and removing the UpdateTable call fails 3 of its rows. This PR still has to wait for #831 to land first.
All points are resolved. I approve.
Changes since the last review
The branch is at 39702c1. These commits sit on 5c9281c, the head that the review of 30 Nov 2026 read:
crates/core/src/validation/provisioned_limits.rs, fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831's check of the table and each index against the per-table maximum replacescheck_create_table_indexesof this branch.check_table_capacity_boundsandMAX_TABLE_CAPACITY_UNITSstay.crates/engine/src/table_limits.rsmakes the one call of fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831. The test helpercapacity_checkspasses the request tocheck_create_table_capacity, as fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831's signature takes it.CreateTableup to 9223372036854775807 again, as fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831 does. The sum wrapped past that figure before.deserialize_capacity_unitsthat the reader saturates a figure only up to the largest 64-bit float.provisioned_tableof fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831.docs/manuals/07-upgrade-manual.md, after the entry of fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831. It names the two answers of Breaking changes and the reading of a fraction and of a figure outside the 64-bit range. The tree differs from fcc8e33 in that file only.The body now names the
UpdateTablecase in Breaking changes, and it adds the rows measured on 3 Dec 2026. It says which measured row ExtendDB no longer matches with the saturating sum.What
CreateTable and UpdateTable now read a
ReadCapacityUnitsorWriteCapacityUnitsfigure as DynamoDB does, and then check it. The reader truncates a fraction toward zero and saturates a figure outside the 64-bit range. So5.5reads as 5, and9223372036854775808reads as9223372036854775807. Before this change, ExtendDB answered such a figure withSerializationException.The saturation goes only as far as the largest 64-bit float, the largest number that
serde_jsonreads. A larger figure, such as1e400, still getsSerializationExceptionwithnumber out of range. DynamoDB reads it as 9223372036854775807 (measured 3 Dec 2026). #1564 tracks the difference.On CreateTable and UpdateTable, a table figure above 1000000000000 gets
ValidationExceptionGiven value <n> for <unit> is out of bounds, as on DynamoDB. The check comes after the minimum of 1 and names the read units first. RestoreTableFromBackup runs it only after it finds the backup.An index figure past the 64-bit range now reaches #831's checks. The sum of the units of a CreateTable saturates at 9223372036854775807, as on #831's branch. So an index at 9223372036854775808 beside a table at 5 gets the account sentence with
Requested: 9223372036854775807, where DynamoDB answers the per-index sentence. A sum that wraps past 9223372036854775807 gives DynamoDB's answer, and so do other rules. The rows that would tell them apart are CreateTable requests, and no one has sent them to DynamoDB. #1563 tracks the row.The code:
deserialize_capacity_unitsincrates/core/src/serde_helpers.rsreads the two figures ofProvisionedThroughput.check_table_capacity_boundsincrates/core/src/validation/provisioned_limits.rswrites the out-of-bounds refusal.validate_create_tableandhandle_update_tablecall it.This PR builds on #831, which adds the per-table, per-index and per-account maxima.
Why
These are DynamoDB's answers, measured in us-east-1 on 14, 16, 18 and 25 November and 3 December 2026. Each refused request went out twice and got the same answer both times.
WriteCapacityUnits9223372036854775808, table at 5 and 7ValidationException:Given value 9223372036854775807 for WriteCapacityUnits is out of bounds. The table stays at 5 and 7.WriteCapacityUnits9223372036854775808WriteCapacityUnits9223372036854775808LimitExceededException:The requested WriteCapacityUnits for index by-label, 9223372036854775807, is above the per index maximum for the account in us-east-1. Per table maximum: 200000.and the limits guide sentenceReadCapacityUnits9223372036854775808 or 1000000000001ReadCapacityUnits, with 9223372036854775807 or 1000000000001ReadCapacityUnits9223372036854775808 andWriteCapacityUnits0writeCapacityUnitsWriteCapacityUnits-9223372036854775809Value '-9223372036854775808'WriteCapacityUnits1000000000001LimitExceededExceptionwith the account textWriteCapacityUnits5.5BackupNotFoundExceptionReadCapacityUnits, with 9223372036854775807ReadCapacityUnits0.5, on a table that does not exist (25 Nov)readCapacityUnitswithValue '0'ReadCapacityUnits1000000000000.9, on a table that does not exist (25 Nov)ResourceNotFoundException, so the figure reads as 1000000000000 and not 1000000000001WriteCapacityUnits1.7976931348623157e308,1e400, or a 1 followed by 400 zeros, on a table that does not exist (3 Dec)ValidationException:Given value 9223372036854775807 for WriteCapacityUnits is out of boundsEvery figure DynamoDB accepted was at most 10, and the script deleted the test table at once. The rows of 25 Nov and 3 Dec name a table that does not exist.
ExtendDB now gives each of these answers, with these exceptions:
1000000000000.9row it leaves the table name out of theResourceNotFoundExceptiontext (DescribeTable, DeleteTable, UpdateTable and DescribeTimeToLive of a missing table leave the table name out of the ResourceNotFoundException text #1055).1e400and the 1 followed by 400 zeros getSerializationException, as What says.Closes #1029
The base of this PR is #831's branch, so GitHub does not close #1029 when this PR merges. #1029 closes when #831's squash lands on main. The squash takes the messages of the branch's commits. Commit 6ab9bb5 ends with the line
Fixes #1029., so the squash closes the issue. After this PR, ExtendDB does not match one row of #1029, the index at 9223372036854775808. What names the issue that tracks it.Other open PRs
crates/core/src/validation/mod.rs, as it does with main. It movesvalidate_provisioned_throughputandvalidate_gsi_throughput_minimumintovalidate_create_table_constraints. The bound check of this PR moves with them, right aftervalidate_gsi_throughput_minimum. That keeps the measured order: the index minimum, then the out-of-bounds text.crates/core/src/validation/mod.rs. It has no call ofvalidate_gsi_throughput_minimuminvalidate_create_table, and this PR calls the bound check right after that call. Whichever of the two merges second keeps the bound check after the index minimum. fix(core): name the capacity member and value when it is below 1 #1442 also rewrites the minimum refusals. The two minimum rows of both new tests match those by their full text, so the second to merge updates the rows.saturated_int32to main. It reads an int32 member the same way, and fix(scan): report every Limit, Segment and TotalSegments range fault in the service's two forms #850 uses it too. This PR reads an int64 figure, so it does not use that function.Testing done
At fcc8e33, with toolchain 1.97.0 unless a line names another (39702c1 adds the manual entry alone, and
cargo test -p extenddb-storage-postgres --test doc_version_literalspasses 3 of 3 there):cargo fmt --all -- --check: clean..github/workflows/clippy.ymlwith-D warnings: clean. The first ran onextenddb-core,extenddb-auth,extenddb-engineandextenddb-server, and the second onextenddb-engine, whose feature it turns on.cargo clippy --all-targets -- -W clippy::pedanticon the same four crates: no warning on a line that this PR adds.cargo +1.94.0 check --all-targetson the four crates: clean..github/workflows/wasm.ymlforwasm32-unknown-unknown: clean. This host has no clang, so the run used a stand-in C compiler and archiver. Clippy does not link.cargo test -p extenddb-wasm-adapter: 3 passed, and theparitycorpus test passed.cargo test --lib:extenddb-core1272 passed and 1 ignored,extenddb-auth540 passed,extenddb-engine985 passed.extenddb-serverhas 528 tests, and 523 passed. Fivebackup_storetests fail on this host only, because/local/homebelongs to uid 65534 and the spool checks refuse a directory under it. storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414 describes the same cause for twoextenddb-storage-sqlitetests. This PR does not change that file.cargo test --release --no-fail-fast -p extenddb-storage-postgres --tests, as the PostgreSQL storage job of CI runs it, againstpgvector/pgvector:pg16on 127.0.0.1: 500 passed, 2 ignored and 5 failed, in 46 test binaries. The failures are threestore_identitytests ofbackup_restore.rsand two tests ofcatalog_nul_backup_jobs.rs. Each getsPermissionDeniedfor its backup root, because/local/homeon this host belongs to uid 65534.doc_version_literalspassed 3 of 3.python3 -m pytest --collect-only -qoftests/(7317 tests) and oftests/python(820): no error.devtools/run-testsmakes:tests/test_capacity_figure_bounds.py: 12 passed on each. It sends the rows above end to end, except the index at 9223372036854775808, the0.5and1000000000000.9rows and the rows of 3 Dec. It also sends two more UpdateTable rows: 1000000000000 gets fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831's per-table text, and 1000000000001 the out-of-bounds text.tests/test_misc_operations.py,tests/test_table_operations.py,tests/test_table_throughput_mode.pyandtests/test_update_table_billing_validation.py: 60 passed on each.tests/test_import_export.pyandtests/test_backup_restore_fidelity.py, with[import]and[export]paths andEXTENDDB_TEST_BACKUP_STORE=noneasdevtools/run-testssets them: 72 passed on each.tests/python/test_control_plane.py: 15 passed on each.tests/test_policy_size_limit_sqlite.py, on a SQLite deployment of its own: 1 passed.a_capacity_figure_is_read_and_bounded_as_measuredholds the rows of the wire file, except the restore row. On the first form of the commit, with the change reverted, it failed on the issue's CreateTable row withinvalid value: integer 9223372036854775808, expected i64. With the write units checked first incheck_table_capacity_bounds, it fails on the row of 25 Nov.the_units_of_a_create_table_are_summed_up_to_i64_maxholds the four rows of the review of 30 Nov 2026 and an index at 9223372036854775807. Each gets the account sentence with the sum, saturated where it passes 9223372036854775807. The test fails with the wrapping sum put back, on the index at 9223372036854775807 with the per-index sentence.Line counts against #831: production +61 -3, tests +333. The commits since the last review: production +7 -12, tests +88 -59.
Not in this PR, each in an open issue or for a measurement:
Updateaction. DynamoDB gives the per-index text for an indexUpdatewithWriteCapacityUnits9223372036854775808.LimitExceededException.CreateatWriteCapacityUnits9223372036854775808 now gets the account text withRequested: 9223372036854775807, where it gotSerializationException. DynamoDB's answer to it was not measured.9007199254740993.5reads as 9007199254740994. A restore of a backup that exists, with an override above the bound, is not measured. A figure that is not a number still getsSerializationException, and its text now endsexpected a JSON numberin place ofexpected i64.InternalFailure, with no message, to CreateTable with an index atReadCapacityUnits9223372036854775808 andWriteCapacityUnits5 beside a table at 5 and 5. It answered the same on 25 Nov 2026. ExtendDB answers the account text forReadCapacityUnits.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
Earlier releases put no upper bound on a table figure, so a table can hold a figure above 1000000000000. On such a table:
validate_create_tableon the stored definition, andvalidate_create_tablenow runs the bound check.ProvisionedThroughputnow refuses a request that keeps the figure above 1000000000000. The request has to bring that figure to 1000000000000 or less in the same request. The bound comes before the table is read, as DynamoDB orders it on a table that does not exist.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.