Skip to content

fix(storage-postgres): send table creation times to the millisecond - #1212

Open
LeeroyHannigan wants to merge 3 commits into
mainfrom
fix/1036-postgres-creation-millis
Open

LeeroyHannigan wants to merge 3 commits into
mainfrom
fix/1036-postgres-creation-millis

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

On PostgreSQL, CreateTable, DescribeTable, UpdateTable and DeleteTable sent CreationDateTime as epoch seconds with microseconds, for example 1794835907.194914. DescribeTable sent the same value as BillingModeSummary.LastUpdateToPayPerRequestDateTime. DynamoDB sends these members with three decimal places. They now carry milliseconds: 1794835907.194.

The catalog column keeps microseconds. Each read of it truncates the value in SQL with date_trunc('milliseconds', creation_date_time): the CreateTable RETURNING, build_table_description_on in table_helpers.rs, and the DeleteTable query. So a table created before this change answers the same way.

DescribeBackup and DeleteBackup of an in-catalog backup read the source table's creation time in backup_engine.rs. Those two queries truncate it too, so SourceTableDetails.TableCreationDateTime equals the table's CreationDateTime, as on DynamoDB.

The truncation is the same SQL expression in three reads. pg_timestamp_to_epoch keeps the sub-millisecond digits, so these reads do not use it. A shared constant would need format! queries, which open PR #1166 wraps in sqlx::AssertSqlSafe, so the three copies stay.

Why

DynamoDB's answers, measured in us-east-1:

Member DynamoDB ExtendDB on PostgreSQL before this change
CreationDateTime of CreateTable, DescribeTable and UpdateTable (14 and 16 November 2026) three decimals, such as 1.794674022596E9 six decimals, such as 1794835907.194914
BillingModeSummary.LastUpdateToPayPerRequestDateTime of DescribeTable equal to CreationDateTime equal to CreationDateTime, six decimals
SourceTableDetails.TableCreationDateTime of DescribeBackup and DeleteBackup (20 November 2026, twice) equal to CreationDateTime, three decimals equal to CreationDateTime, six decimals

The other backends already send at most three decimals: SQLite and MongoDB send whole seconds, and Cassandra sends milliseconds.

Fixes #1036

Testing done

  • cargo test -p extenddb-storage-postgres against a PostgreSQL 16 container on 127.0.0.1: 454 passed. On this host 5 tests fail on every branch at the filesystem backup store's ownership check, because uid 65534 owns /local/home.
  • date_members_carry_at_most_milliseconds in crates/storage-postgres/tests/backup_restore.rs stores a creation time of .194914. It reads the time back as 1794835907.194 from DescribeTable CreationDateTime, LastUpdateToPayPerRequestDateTime, DeleteTable and DescribeBackup TableCreationDateTime. With the two backup queries reverted, the DescribeBackup check fails with 1794835907.194914.
  • cargo test -p extenddb-core --lib: 1146 passed. cargo test -p extenddb-engine --lib: 870 passed.
  • cargo +1.97.0 clippy -p extenddb-storage-postgres --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • Against ExtendDB on PostgreSQL, tests/test_table_operations.py, tests/test_backup_restore_fidelity.py and tests/python/test_tables.py passed 86 tests. The new rows of tests/test_table_operations.py check three decimals or fewer in CreateTable, DescribeTable, CreateBackup and UpdateTable.
  • The same server answered CreateTable, DescribeTable, CreateBackup, DescribeBackup, ListBackups, RestoreTableFromBackup, DeleteBackup and DeleteTable with at most three decimals in every date member.

Line counts: production +11 -5, tests +145.

Not in this PR, each in an open issue:

This PR adds no conflict with an open PR.

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


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.

On PostgreSQL, CreateTable, DescribeTable and UpdateTable sent
CreationDateTime as epoch seconds with microseconds, for example
1794835907.194914. DescribeTable sent the same value as
BillingModeSummary.LastUpdateToPayPerRequestDateTime. Amazon DynamoDB
sent each of these members with three decimal places, for example
1.794674022596E9, when measured in us-east-1 on 2026-11-14 and
2026-11-16.

The catalog column keeps microseconds. The reads of CreateTable,
DescribeTable, UpdateTable and DeleteTable now truncate it to the
millisecond. The backup's source creation time is truncated too, so
DescribeBackup and DeleteBackup send
SourceTableDetails.TableCreationDateTime equal to CreationDateTime, as
DynamoDB did on 2026-11-20. A table created before this change answers
the same way, because the value is truncated when it is read.

Fixes #1036.

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

I think backups taken before this change still report six decimals. On a catalog built on main (222d80a) with a filesystem backup store, I created an on demand table and a backup, then started a build of this branch merged with main on the same catalog. DescribeTable answered CreationDateTime 1796027244.587, while DescribeBackup and DeleteBackup of the old backup answered SourceTableDetails.TableCreationDateTime 1796027244.587888. On main the two were equal. The description says a table created before the change answers the same way and that TableCreationDateTime equals CreationDateTime. For a store backed backup that time comes from the catalog row written at CreateBackup (snapshot.rs line 429, read by BackupRow::description), which none of the changed queries read. The same holds for a legacy backup that an earlier build moved with extenddb backup migrate-legacy: 1796029160.425746 against 1796029160.425. Could the time be cut to the millisecond where DescribeBackup reads the row, with a test that stores a row with a microsecond remainder? If you would rather leave old rows as they are, could the description say so?

The change to the restore_source query in backup_engine.rs has no test. With only that change reverted, date_members_carry_at_most_milliseconds and the new wire rows still pass. That query is what backup migrate-legacy copies into the catalog row: a backup migrated by this branch reports 1796029141.976, one migrated by main reports 1796029160.425746. The description names the two queries as the DescribeBackup and DeleteBackup reads. Could it name the migration, and could a test migrate a legacy backup whose table time has a microsecond remainder and check TableCreationDateTime?

Small: the description says #1166 is open. It merged on 26 November and main's backup_engine.rs already uses sqlx::AssertSqlSafe, so the reason given for keeping three copies of the expression no longer reads true. Either choice is fine with me; I think the sentence should match main.

Small: in tests/test_table_operations.py, class TestListTables: now follows the new test with no blank line between them.

I will approve once old store backed and migrated backups report the same TableCreationDateTime as their table (or the description says they keep six decimals), and the restore_source change has a test.

Main made TableDescription::creation_date_time an Option<f64> in #1411.
The value is None only for a DELETING table. The test
date_members_carry_at_most_milliseconds formats the field in three
places: after CreateTable, after DescribeTable and after the PostgreSQL
DeleteTable. After the merge of main, the test did not compile.

Each place now takes the time out of the Option with expect before it
formats it. The PostgreSQL DeleteTable result still holds the time. The
engine removes it later, when it prepares the DELETING answer.

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.

PostgreSQL: CreationDateTime and LastUpdateToPayPerRequestDateTime carry microseconds, where DynamoDB sends milliseconds

2 participants