Skip to content

fix(core): truncate and clamp a capacity figure, then bound it - #1167

Open
LeeroyHannigan wants to merge 12 commits into
fix/538-enforce-limits-keysfrom
fix/1029-capacity-past-i64
Open

LeeroyHannigan wants to merge 12 commits into
fix/538-enforce-limits-keysfrom
fix/1029-capacity-past-i64

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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:

The body now names the UpdateTable case 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 ReadCapacityUnits or WriteCapacityUnits figure as DynamoDB does, and then check it. The reader truncates a fraction toward zero and saturates a figure outside the 64-bit range. So 5.5 reads as 5, and 9223372036854775808 reads as 9223372036854775807. Before this change, ExtendDB answered such a figure with SerializationException.

The saturation goes only as far as the largest 64-bit float, the largest number that serde_json reads. A larger figure, such as 1e400, still gets SerializationException with number 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 ValidationException Given 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_units in crates/core/src/serde_helpers.rs reads the two figures of ProvisionedThroughput.
  • check_table_capacity_bounds in crates/core/src/validation/provisioned_limits.rs writes the out-of-bounds refusal. validate_create_table and handle_update_table call 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.

Request DynamoDB
UpdateTable with WriteCapacityUnits 9223372036854775808, table at 5 and 7 ValidationException: Given value 9223372036854775807 for WriteCapacityUnits is out of bounds. The table stays at 5 and 7.
CreateTable with WriteCapacityUnits 9223372036854775808 the same text
CreateTable with an index at WriteCapacityUnits 9223372036854775808 LimitExceededException: 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 sentence
CreateTable with ReadCapacityUnits 9223372036854775808 or 1000000000001 the out-of-bounds text for ReadCapacityUnits, with 9223372036854775807 or 1000000000001
CreateTable with ReadCapacityUnits 9223372036854775808 and WriteCapacityUnits 0 the minimum refusal for writeCapacityUnits
CreateTable with WriteCapacityUnits -9223372036854775809 the minimum refusal with Value '-9223372036854775808'
CreateTable with an index at WriteCapacityUnits 1000000000001 LimitExceededException with the account text
CreateTable with WriteCapacityUnits 5.5 the table, created at 5 and 5
RestoreTableFromBackup of a backup that does not exist, override 1000000000001 and 5 BackupNotFoundException
UpdateTable with both figures at 9223372036854775808, on a table that does not exist (25 Nov) the out-of-bounds text for ReadCapacityUnits, with 9223372036854775807
UpdateTable with ReadCapacityUnits 0.5, on a table that does not exist (25 Nov) the minimum refusal for readCapacityUnits with Value '0'
UpdateTable with ReadCapacityUnits 1000000000000.9, on a table that does not exist (25 Nov) ResourceNotFoundException, so the figure reads as 1000000000000 and not 1000000000001
UpdateTable with WriteCapacityUnits 1.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 bounds

Every 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:

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

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_literals passes 3 of 3 there):

  • cargo fmt --all -- --check: clean.
  • The two clippy commands of .github/workflows/clippy.yml with -D warnings: clean. The first ran on extenddb-core, extenddb-auth, extenddb-engine and extenddb-server, and the second on extenddb-engine, whose feature it turns on.
  • cargo clippy --all-targets -- -W clippy::pedantic on the same four crates: no warning on a line that this PR adds.
  • cargo +1.94.0 check --all-targets on the four crates: clean.
  • The clippy step of .github/workflows/wasm.yml for wasm32-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 the parity corpus test passed.
  • cargo test --lib: extenddb-core 1272 passed and 1 ignored, extenddb-auth 540 passed, extenddb-engine 985 passed. extenddb-server has 528 tests, and 523 passed. Five backup_store tests fail on this host only, because /local/home belongs 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 two extenddb-storage-sqlite tests. 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, against pgvector/pgvector:pg16 on 127.0.0.1: 500 passed, 2 ignored and 5 failed, in 46 test binaries. The failures are three store_identity tests of backup_restore.rs and two tests of catalog_nul_backup_jobs.rs. Each gets PermissionDenied for its backup root, because /local/home on this host belongs to uid 65534. doc_version_literals passed 3 of 3.
  • python3 -m pytest --collect-only -q of tests/ (7317 tests) and of tests/python (820): no error.
  • Against SQLite and PostgreSQL builds of fcc8e33 on 127.0.0.1, with the four settings that devtools/run-tests makes:
    • tests/test_capacity_figure_bounds.py: 12 passed on each. It sends the rows above end to end, except the index at 9223372036854775808, the 0.5 and 1000000000000.9 rows 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.py and tests/test_update_table_billing_validation.py: 60 passed on each.
    • tests/test_import_export.py and tests/test_backup_restore_fidelity.py, with [import] and [export] paths and EXTENDDB_TEST_BACKUP_STORE=none as devtools/run-tests sets 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.
  • The core test a_capacity_figure_is_read_and_bounded_as_measured holds 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 with invalid value: integer 9223372036854775808, expected i64. With the write units checked first in check_table_capacity_bounds, it fails on the row of 25 Nov.
  • the_units_of_a_create_table_are_summed_up_to_i64_max holds 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:

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • 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: 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:

  • RestoreTableFromBackup now refuses, without an override, a backup of the table. Both restore paths run validate_create_table on the stored definition, and validate_create_table now runs the bound check.
  • UpdateTable with a ProvisionedThroughput now 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.

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 navareamol 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 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.

  1. 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.

  2. 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 in CAPACITY_FIGURES. If it does not, the saturating sum from #831 may be the closer rule.

  3. The description and the doc comment of deserialize_capacity_units say 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, answers number 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.

LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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 adds one commit that formats three test files with cargo fmt.
The merge takes it with no conflict.
provisioned_limits_tests.rs merged on its own, and the other two files take #831's text.
#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.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

#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. git merge-tree of this head with main finds no conflict.

  1. The Breaking changes section now names the case. UpdateTable on a table that already holds a figure above 1000000000000 has to bring that figure to 1000000000000 or less in the same request.

  2. No one has sent DynamoDB the 9223372036854775802 and 9223372036854775803 rows. Each is a CreateTable, and this round sends none. So the sum saturates again, as on fix: enforce the table quota, the provisioned-capacity maxima and max_policy_document_bytes #831's branch (a5ae957). the_units_of_a_create_table_are_summed_up_to_i64_max holds your four rows and an index at 9223372036854775807 (fcc8e33). Each gets the account sentence with the sum, saturated where it passes 9223372036854775807. The test fails with the wrapping sum put back. The measured row with an index at 9223372036854775808 leaves CAPACITY_FIGURES and tests/test_capacity_figure_bounds.py. DynamoDB answers it with the per-index sentence, and ExtendDB now answers the account sentence. CreateTable answers the account sentence for an index figure that takes the request's units past 9223372036854775807, where DynamoDB answers the per-index sentence #1563 tracks that row with your four.

  3. Yes, on 3 Dec. UpdateTable on a table that does not exist answered Given value 9223372036854775807 for WriteCapacityUnits is out of bounds for WriteCapacityUnits 1e400 and for a 1 followed by 400 zeros, twice each. The largest 64-bit float got the same answer. So DynamoDB saturates these figures too. ExtendDB saturates only up to the largest 64-bit float, and a larger figure still gets SerializationException with number out of range. c5bb0c6 says so in the doc comment of deserialize_capacity_units, and the body says it too. CreateTable and UpdateTable refuse a capacity figure past the float range with SerializationException, where DynamoDB reads it as 9223372036854775807 #1564 tracks the difference.

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 navareamol 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 branch merges with current main without a conflict (main at c057660), and all 70 checks pass at 39702c1.

  1. 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.

  2. 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 with wrapping_add, and the_units_of_a_create_table_are_summed_up_to_i64_max fails 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.

  3. 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 SerializationException with number 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.

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