Skip to content

fix(engine): end a failed ImportTable as DynamoDB does - #1370

Open
LeeroyHannigan wants to merge 12 commits into
fix/1258-unpadded-base64from
fix/1357-import-failure-model
Open

LeeroyHannigan wants to merge 12 commits into
fix/1258-unpadded-base64from
fix/1357-import-failure-model

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

An ImportTable of DYNAMODB_JSON now ends as DynamoDB does when it cannot read a line of a file. Before, the request answered ValidationException with Invalid DynamoDB item at line N or Invalid JSON at line N. It imported nothing, and the new table stayed empty.

With this PR, a line that the import cannot read is one error and ends the reading of its file. The items before it stay imported. The lines after it are not imported or counted. Such a line is not JSON, has no Item member, or holds a B value that is not padded base64. A line whose Item the item reader refuses, such as an unknown type descriptor, ends the file too. Before, ExtendDB read a line without Item as a bare item.

An item that fails a check (no key, a key of another type) is one error, and the import reads the next line. The import then ends FAILED with FailureCode ItemValidationError and keeps the imported items. This part is already on main, from #620. The issue says that such an import ends COMPLETED, which was the behaviour before #620.

The changes:

  • crates/engine/src/import_export_io.rs: read_items and read_dynamodb_json return the items and the first line they cannot read, with its number and its fault. read_line gives the item or the fault for one line.
  • crates/engine/src/import_export/files.rs: import_table, the body of the ImportTable handler, counts the unread line as one processed row and one error, after the items before it. It writes the line number and the fault to the server log and stops. An item with an N value that is not a number still ends the import of its file, as on main (fix(engine): validate numbers on every key and item path #620).
  • docs/troubleshooting.md: the entry Invalid JSON at line N becomes An import ends FAILED with ItemValidationError. The module comment of crates/core/src/backup_format/data_file.rs changes to match.
  • docs/manuals/07-upgrade-manual.md: a v1.2.0 entry gives the two changes of the Breaking changes section. The last sentence of the entry of fix(core): send DynamoDB's text for a B value that does not decode #1260 changes to match. An ImportTable line with a B value that does not decode got Invalid DynamoDB item at line N in 1.1.0, and now it ends the reading of its file.

The ION format uses the same reader, so it gets the same rules. CSV does not change. The FailureMessage keeps ExtendDB's text, which names the server log. DynamoDB's text names CloudWatch. #620 set that text, and docs/differences-from-dynamodb.md lists the difference in the row Imported rows holding a number the service cannot store.

The base of this PR is #1313.

Why

Fixes #1357

These are DynamoDB's answers, measured in us-east-1 on 22 November 2026. The same eight files went into two S3 prefixes. One ImportTable per prefix (DYNAMODB_JSON, no compression, a new table keyed on pk of type S) gave the same answers both times. The counts are (ProcessedItemCount, ImportedItemCount, ErrorCount).

File Lines DynamoDB imported ExtendDB before ExtendDB with this PR
a A1, A2 with {"B": "YQ"}, A3 A1 HTTP 400, Invalid DynamoDB item at line 2, no items FAILED (2, 1, 1), A1
c C1, a line that is not JSON, C3 C1 HTTP 400, Invalid JSON at line 2, no items FAILED (2, 1, 1), C1
d an item with no pk, D2 D2 FAILED (2, 1, 1), D2 the same
e an item with a pk of type N, E2 E2 FAILED (2, 1, 1), E2 the same
f F1, F2 F1, F2 COMPLETED (2, 2, 0) the same
g G1 with {"B": "YQ"}, G2 none HTTP 400, Invalid DynamoDB item at line 1, no items FAILED (1, 0, 1), none
i I1, an empty line, I3 I1, I3 COMPLETED (2, 2, 0) the same
j {"pk": {"S": "J1"}} with no Item, J2 none COMPLETED (2, 2, 0), J1 and J2 FAILED (1, 0, 1), none

DynamoDB read the eight files in one import. It ended FAILED with ItemValidationError and the counts (14, 8, 6). ExtendDB reads one file per import, and its eight imports add up to (14, 8, 6). For a line it cannot read, DynamoDB writes the fault and Remainder of the file will not be processed. to CloudWatch. ExtendDB's server log gives the line number and the fault. For a line that is not JSON, has no Item member or holds a B value that is not padded, the fault is DynamoDB's text.

Not measured on DynamoDB: a line whose Item the item reader refuses, such as an unknown type descriptor. ExtendDB ends the file there. The ION and CSV formats and a compressed file are not measured either. No measured file started with a UTF-8 byte order mark. The reader does not take the mark as JSON, so the reading of such a file ends at line 1, and the import ends FAILED. A measurement needs an ImportTable, which creates a table.

Not in this PR

Conflicts

git merge-tree shows no conflict of dfff876 with main at b6c8595. fd1c1e1 resolved the conflict with main in crates/engine/src/import_export.rs, and the body of import_table in crates/engine/src/import_export/files.rs holds the handler change of this PR. This PR adds a conflict with one open PR:

#831, and #1167 on the branch of #831, conflict with the base in docs/manuals/07-upgrade-manual.md. The v1.2.0 entry of this PR sits below the entry of #1260, above the v1.1.0 entries, where other open PRs add their entries too. Whichever PR merges second keeps both entries.

The base #1313 has conflicts of its own.

Testing done

The runs below are on 5854827, before the merges of #1313's new heads, unless a line names another tree. "Changes since the last review" gives the runs on the commits since the last review.

  • cargo test -p extenddb-core -p extenddb-engine --lib --no-fail-fast: 1147 core unit tests passed and 1 ignored, and 931 engine unit tests passed.
  • cargo +1.97.0 fmt --all -- --check is clean. cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings, the same with --features extenddb-engine/backup-test-hooks, and cargo +1.91.1 check -p extenddb-core -p extenddb-engine --all-targets are clean.
  • The module test a_line_the_import_cannot_read_ends_the_file in crates/engine/src/import_export_io.rs has one data table of six measured files. LINE_FILES in tests/test_import_export.py has six measured files and one row that puts a skipped item before a line that ends the file. The measurement on DynamoDB has those two rules in separate files.
  • Against a SQLite build of 5854827 with one import and export root, as devtools/run-tests sets it, tests/test_import_export.py passed 42 tests.
  • A server with the reader and the handler of the base fails 5 rows of test_a_line_the_import_cannot_read_ends_the_import_of_its_file: unpadded-base64-ends-the-file, not-json-ends-the-file, first-line-ends-the-file, no-item-member-ends-the-file and skipped-item-then-unread-line. A mutant that does not count the unread line as an error fails the same 5 rows. These ran on the merge with fix(core): read a B value with its padding left out or cut short #1313's head, whose Rust files are the same as at 5854827.
  • A scratch merge with main (891f30ccf) checks the resolution of the conflict with main. Its two handler files differ from main only by this PR's change. The engine unit tests of import_export passed on it, and tests/test_import_export.py passed 42 tests against a SQLite build of it. In one earlier run of that build, TestExportTable::test_export_dynamodb_json read 4 lines from an export whose description counted 5 items. This PR does not change the export. The WebAssembly clippy step of devtools/run-wasm-step clippy is clean on the scratch merge. 5854827 lacks devtools/wasm-clippy, which feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 added on main.
  • python3 -m pytest --collect-only -q collects 7027 tests in tests/ and 672 in tests/python, with no error.

At a3ef625 against #1313's head 6825c8e, the Rust code is +90 -49, with the module comment of data_file.rs. The Markdown docs are +21 -4, and the tests are +160 -6.

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

  • A DYNAMODB_JSON or ION line without an Item member, such as {"pk": {"S": "J1"}}, is no longer read as a bare item. A file of such lines imported every line before. Now the import ends at the first such line, imports nothing from the file, and ends FAILED with ItemValidationError. The troubleshooting entry on main gives the bare form as valid.
  • A request whose file holds a line that the import cannot read answered HTTP 400 ValidationException with Invalid JSON at line N or Invalid DynamoDB item at line N, and left the new table empty. It now answers HTTP 200. Its ImportTableDescription has ImportStatus FAILED and FailureCode ItemValidationError, and the items before the line stay in the table.

The v1.2.0 entry of docs/manuals/07-upgrade-manual.md gives both changes.


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.

A DYNAMODB_JSON line the import could not read answered the request with
ValidationException and "Invalid DynamoDB item at line N". Nothing was
imported, and the table created before the read stayed empty.

Measured on DynamoDB in us-east-1 on 22 November 2026, twice with the same
answers. A line the import cannot read is one error and ends the reading
of its file. Such a line is not JSON, has no "Item" member, or has a B
value that is not padded base64. The items before it stay imported. The
lines after it are neither imported nor counted. An item that fails a
check (no key, a key of another type) is one error, and the import reads
the next line. The import skips an empty line. ProcessedItemCount is the
imported items plus the errors. The import ends FAILED with
ItemValidationError, and the table keeps the imported items. For the
eight measured files: ProcessedItemCount 14, ImportedItemCount 8,
ErrorCount 6.

The reader now returns the items before the first line it cannot read,
with the number and the fault of that line. The handler counts the line
as one error after those items. The check of an item, the FAILED status
and the message that names the server log are the ones already there.
Before, the reader took a line without an "Item" member as a bare item.
The service refuses such a line. The ION format shares the reader. CSV is
unchanged. The request's own errors (the source path, the item count
limit, I/O) are unchanged.

Fixes #1357.
The base merges #1260's branch twice, which brings #544's newer commits,
and adds a doc comment to its import test. The merge has no conflict.
Of the files this branch changes, git merged two with changes from the
base. In crates/engine/src/import_export_io.rs the base extends the doc
comment of import_reads_a_binary_only_in_the_canonical_form. In
docs/troubleshooting.md the base changes the catalog-check entry, which
is not the import entry that this branch changes.
…t end a file

The troubleshooting entry for an import that ends FAILED named three
kinds of line that end the import of a file. A line whose Item the item
reader refuses, such as {"Item": {"pk": {"Q": "x"}}}, ends the file too:
read_line answers "Invalid DynamoDB item" for it. The entry now gives
the lines and the item that end a file as a list, with this line added.
This branch changes two ImportTable answers that an existing client can
see. A file of lines without an Item member imported its lines, and now
it imports nothing. A file with a line the import cannot read answered
HTTP 400 and left the new table empty. Now the request answers HTTP 200
with ImportStatus FAILED, and the items before the line stay imported.

The upgrade manual gets a v1.1.0 entry for both changes, as the earlier
ImportTable change of #620 has an entry.
The base merges main at 14ade59. That brings #544 as a squash and
ten other commits: #1280, #1009, #596, #1173, #398, #428, #567, #584,
#588 and #864.

One file conflicted: crates/engine/src/import_export.rs. #1009 moves
the body of handle_import_table to import_table in the new file
crates/engine/src/import_export/files.rs. The wasm32 build replaces
that file with a stand-in that refuses the operation.
handle_import_table keeps the enabled check and calls
files::import_table.

This branch changes the body that #1009 moves. When read_items finds a
line that it cannot read, the import keeps the items before that line.
It counts the line as one error and reads no more of the file.

The merge keeps the code of main in import_export.rs, with the doc
comment of this branch on handle_import_table. It makes the three
changes of this branch to the body in files.rs:

- The variable read holds the result of read_items: the items and the
  line that the reader cannot read.
- The loop takes the items, then that line. At that line it logs the
  line number and the fault, counts one error and ends the import.
- The comment over the FAILED status adds the date 2026-11-22, for the
  lines that the import cannot read.

The body of import_table in files.rs is now the same as the body of
handle_import_table at the head of this branch.

Git merged docs/manuals/07-upgrade-manual.md with no conflict. #398
adds its v1.1.0 entry at the top of "Behavior Changes by Release".
This branch adds its v1.1.0 entry at the end of that section.

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

fd1c1e1 no longer merges with main. Main at 92155f3 moved the v1.1.0 entries of docs/manuals/07-upgrade-manual.md in #1514, and a three way merge of this head with it conflicts in that file. No code file conflicts. The description says the merge with main at 5252eda has no conflict, which still holds for 5252eda. #1514 is tagged v1.1.0, so the new entry "v1.1.0: an ImportTable line that cannot be read ends its file, and each line needs an Item member" now names a release that shipped without this change. Could you merge main and move the entry under the next release? I merged it here keeping main's side plus this entry: fmt, a workspace check of all targets, clippy on core and engine, the core lib (1243) and engine lib (981) tests, and tests/test_import_export.py with four other wire files on SQLite (265) pass. The wasm check on this head fails with E0308 at crates/core/src/metrics/collector.rs:60, the error main had before #1482, so CI on the merged branch would also clear that.

A file that starts with a UTF 8 byte order mark (EF BB BF) followed by two good {"Item": ...} lines now answers 200 with ImportStatus FAILED, counts (1, 0, 1) and an empty table. #1313's head and main answer 400 Invalid JSON at line 1. trim() keeps U+FEFF, so line 1 is not JSON and ends the file. Was such a file among the ones measured on the service? If the service reads it, I think the reader should drop a leading U+FEFF on line 1.

I will approve once the branch is merged with main, the upgrade manual entry names the next release, and CI is green on that tree.

The base merges main at 01556cf, 27 commits past 14ade59, through
#1260. That brings #1514, which released v1.1.0 and moved the v1.1.0
entries of docs/manuals/07-upgrade-manual.md to the top of "Behavior
Changes by Release". The base also checks only the items and keys of
BatchWriteItem for padding, and check_binaries now takes one attribute
value.

Two files conflicted:

- docs/manuals/07-upgrade-manual.md: this branch added its v1.1.0
  entry at the end of "Behavior Changes by Release". The conflict hunk
  also holds the earlier copy of the ClientRequestToken entry, which
  main moved and rewrote. The merge keeps the side of main. The entry of this branch is now a
  v1.2.0 entry at the top, after the v1.2.0 entry of #1260, since
  v1.1.0 shipped without this change.
- crates/engine/src/import_export_io.rs: this branch moved the line
  check to read_line, and the base changed the call of check_binaries
  there. The merge keeps read_line and calls check_binaries on each
  value of the item.

Git merged docs/troubleshooting.md with no conflict. Main changes the
entries at lines 330 to 470, and this branch changes the import entry
at line 1029.
The base merges main at e8b5f10 through #1260, which brings #481,
#1137 and #1403. #1403 adds a v1.2.0 entry for #606 at the top of
"Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md,
above the entry of #1260. Git merged the file with no conflict, so the
order is #606, #1260, then the entry of this branch.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

The branch merges main through #1313 and #1260: d23563c for main at 01556cf, then da4d5c9 for main at e8b5f10. The conflict in docs/manuals/07-upgrade-manual.md resolves to the side of main. The entry of this PR moves to the top of "Behavior Changes by Release", after the v1.2.0 entries of #606 and #1260. Its heading is now "v1.2.0: an ImportTable line that cannot be read ends its file, and each line needs an Item member". Its text names 1.1.0 as the release before the change. The merge also calls check_binaries on each value of the item in read_line, the change that #1313 made to that function.

The byte order mark: no measured file started with one. A measurement needs an ImportTable, which creates a table, and this round creates no resource on the service. Without the answer of the service, the reader keeps its rule. Line 1 with U+FEFF is not JSON, so it ends the file, as line 2 of file c does.

The base brings main at c8e66fb through #1260, with #1465, #1515 and
#1411, and adds the v1.2.0 entry of #1313 to
docs/manuals/07-upgrade-manual.md. Git merged the manual with no
conflict. The order of the v1.2.0 entries is #1313, #1411, #606, #1260,
then the entry of this branch. No other file has changes on both sides.
@navareamol

Copy link
Copy Markdown
Collaborator

The merge with main and the upgrade note are fixed. git merge-tree of da4d5c9 with main at e8b5f10 reports no conflict, main is 1.1.0 and untagged after that, and the manual lists the #606, #1260 and #1370 entries in that order under v1.2.0. The heading and the sentences about 1.1.0 and the rollback to 1.1.0 are right.

The v1.2.0 entry of #1260 now disagrees with yours. It ends with "An ImportTable line with such a value keeps its 1.1.0 answer, Invalid DynamoDB item at line N." Your entry, two paragraphs below, says such a line now ends the file and the request answers 200. Both are v1.2.0 entries, so a reader of the manual gets two answers. Could you change that sentence in this branch, or tell me which PR will?

I checked the call of check_binaries in read_line. Before the merge it was called on the whole item. Since #1313 it checks only the value it is given, and the item map itself is not an attribute value, so the per value call is needed. I rebuilt da4d5c9 on SQLite and sent the same ImportTable files as before the merge: padded and unpadded B, BS, nested M and L, and the byte order mark file. 53 of 54 answers are the same as at fd1c1e1, and the other one differs only in a random table name. Nine more files give the answers I expect: a padded B and BS deep in L, M and L stay imported, one unpadded member makes the line unread, and a BS with a number member or an unknown type around an unpadded B also ends the file with the items before it kept. If I put the old whole item call back, two of your unit tests fail, so they cover this.

On the byte order mark, I take it that no measured file had one and that you cannot measure it without creating a table, so the rule stays. I agree that stripping U+FEFF would be a guess too. The description names it under "Changes since the last review". The upgrade entry does not, so a user whose tool writes a byte order mark would learn from the manual only that bad lines end the file. One sentence there that a file starting with a byte order mark ends FAILED at line 1 would help, but I do not need it for approval.

The head has since moved to c76a612, another merge of main. The #1260 sentence is unchanged there. Checks on it are still running: 38 passed and 29 pending when I looked, none failed.

I will approve once the #1260 sentence matches your entry and the checks on the branch are green.

The base brings a new BatchWriteItem check. It reads a fault ahead of a
B in request order, also inside a value. The base also adds a sentence
to its v1.2.0 entry. The merge has no conflict. Git merged the upgrade
manual, where both sides changed other lines. The base adds the new
sentence to the entry of #1313. This branch has its entry below the
entry of #1260. No other file has changes on both sides.
The v1.2.0 entry of #1260 ended with "An ImportTable line with such a
value keeps its 1.1.0 answer, Invalid DynamoDB item at line N". The
entry of this branch says that such a line now ends the reading of its
file. The sentence in the entry of #1260 now gives the 1.1.0 answer and
the new one. The request answers HTTP 200, and the import ends FAILED.

The entry of this branch now also says what a file that starts with a
UTF-8 byte order mark gets. The reader does not take U+FEFF as JSON, so
the reading ends at line 1 and the import ends FAILED. No measured file
started with a byte order mark.
The base changes one sentence of its v1.2.0 entry. It now says that
1.1.0 answered such a BatchWriteItem request with the text of the other
fault. The merge has no conflict.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

a3ef625 changes the sentence in this branch. The v1.2.0 entry of #1260 now ends with "An ImportTable line with such a value got Invalid DynamoDB item at line N in 1.1.0. Now it ends the reading of its file, as the entry for #1370 gives. The request answers HTTP 200, and the import ends FAILED." So once this PR merges, the manual gives one answer.

The same commit adds the byte order mark to the entry of this PR. The reader does not take a UTF-8 byte order mark at the start of a file as JSON. So the reading of such a file ends at line 1, and the import ends FAILED. The entry also says that no measured file started with one.

c6813fe merges #1313's new head 6825c8e, which changes the BatchWriteItem check inside a value. The merge has no conflict, and read_line does not change. babe801 merges #1313's head 835b5ae, which changes one sentence of the entry of #1313. The new head is babe801.

@navareamol

Copy link
Copy Markdown
Collaborator

The #1260 sentence now reads "An ImportTable line with such a value got Invalid DynamoDB item at line N in 1.1.0. Now it ends the reading of its file, as the entry for #1370 gives. The request answers HTTP 200, and the import ends FAILED." That matches your entry, so the manual gives one answer.

The byte order mark sentence matches the reader: crates/engine/src/import_export_io.rs trims each line with trim(), which keeps U+FEFF, so line 1 of such a file is not JSON and the file ends there. On da4d5c9 I measured 200 with FAILED, counts (1, 0, 1) and an empty table on SQLite. That no measured file started with a byte order mark is your statement, and I have not measured the service.

Main has moved to c057660 (#1446) and a merge of it into this head conflicts in docs/manuals/07-upgrade-manual.md, where main added six lines. No code file conflicts, and the head of #1313 conflicts in the same way. On babe801, 4 checks had passed and 36 were queued or running when I looked.

I will approve once main is merged and the checks on that head are green.

The base brings main at b6c8595 through #1260, with #1446, #1531 and
#1466, and the 15 new rows of #1260 in tests/test_binary_base64.py.
The merge has no conflict. Git merged the upgrade manual, where both
sides changed other lines. The base adds the two entries of main above
the entry of #1313, and this branch has its entry below the entry of
#1260. No other file has changes on both sides.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol dfff876 merges the new head of #1313, which brings main at b6c8595 through #1260. Git merged the upgrade manual with no conflict. The two entries of main are at the top, and the entry of this PR stays below the entry of #1260. No code file has changes on both sides. The checks run again on this head.

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

Main has moved again, to 5826e1b (#1087). A merge of it into dfff876 conflicts in docs/manuals/07-upgrade-manual.md, where #1087 added the entry "SQLite parallel Scan segments follow the partition key". No code file conflicts, and the head of #1368 conflicts in the same way, so this comes from main moving under the stack. On dfff876, 39 checks had passed, 1 was cancelled (conventional) and 28 were running or queued when I looked.

The byte order mark sentence holds on this head. On a SQLite build of dfff876, an ImportTable file that starts with U+FEFF answers HTTP 200 and the import ends FAILED with counts (1, 0, 1) and an empty table, whether the mark sits on its own line or before the first item. A mark at the start of line 2 keeps the item of line 1 and ends the file there. A UTF-16 mark fails the request with HTTP 400 and the I/O error text, as the entry says for a line that is not UTF-8. When I strip U+FEFF before the line is read, the same files import and end COMPLETED, so the sentence depends on the reader as it is. That no measured file started with a byte order mark is your statement, and I have not measured the service.

The sentence in the entry of #1260 matches this entry, so the manual gives one answer. The head differs from the one I read before only by merges of main and of #1313, and read_line is unchanged.

All 70 checks pass on dfff876, so I approve. The manual conflict with main sits in the whole stack, and the stack can fix it when it lands.

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