Repository navigation
Persistence: DynamoDB (atomic) sort the children index by entity id - #6006
Conversation
flyrain
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the fix, @ZephyrYWZhou !
vigneshio
left a comment
There was a problem hiding this comment.
Thanks @ZephyrYWZhou. Left a note on the padding format.
| * relational-jdbc} does). Entity ids are non-negative. | ||
| */ | ||
| public static String childrenGsiSk(long id) { | ||
| return String.format("%019d", id); |
There was a problem hiding this comment.
Since this is a DynamoDB key, String.format without Locale.ROOT picks up the JVM's default digits. On a non-Latin locale it would store a different gsi1sk than the one the listing query looks for. Let's use Locale.ROOT, same as the other padded ids in the tree.
There was a problem hiding this comment.
Ahhh Good catch, thanks @vigneshio. Switched to String.format(Locale.ROOT, "%019d", id) - same as the padded version numbers in LocalIcebergCatalog.
orca-review-bot
left a comment
There was a problem hiding this comment.
Looks good. This is a small, focused change that lines gsi1 up with id-based paging so the listing PR can reuse EntityIdToken. The rename is complete. The table and GSI definitions don't change because gsi1sk stays a string. Realm isolation is unchanged since the realm stays in gsi1pk. The IT picks ids 30/200 so that name order, id order, and unpadded order all differ, which is a nice touch. One optional nit inline about negative ids. No CHANGELOG needed since the backend isn't selectable yet.
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| * numeric order. This lists children in id order, the order Polaris pages by (as {@code | ||
| * relational-jdbc} does). Entity ids are non-negative. | ||
| */ | ||
| public static String childrenGsiSk(long id) { |
There was a problem hiding this comment.
A negative id would sort wrong here. %019d turns -42 into "-000000000000000042", which lands before every positive id, so gsi1sk > pad(lastId) paging would quietly skip or repeat rows. That can't happen today because JDBC's IdGenerator masks ids to non-negative. But this module hasn't settled its id source yet, and the javadoc's "ids are non-negative" isn't enforced. Can we throw IllegalArgumentException for id < 0 so a bad id fails loudly instead?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
|
Thanks for the review and approval @flyrain @vigneshio! Could @flyrain help with the merge of this fixing PR please? Thanks! |
Summary
The DynamoDB (atomic) backend keeps a children index,
gsi1, for listing a parent's children. Its sort key was the entity name. Polaris pages listings by entity id instead:JdbcBasePersistenceImplorders children by id, and the sharedEntityIdTokenresumes after the last id returned. With a name sort key,gsi1could not resume from anEntityIdTokenwithout reading every child and sorting in memory.This PR makes
gsi1skthe entity id, zero-padded to 19 digits so that string order matches numeric order. The upcoming listing PR can then page with oneQuery(gsi1sk > pad(lastId), limited to the page size) and reuseEntityIdTokenas is.Nothing reads
gsi1yet and the backend cannot be selected, so no stored data is affected.Changes
DynamoDbLayout: addchildrenGsiSk(long id)for the padded id. RenamebyNameGsiPktochildrenGsiPk, and update the comments that calledgsi1a by-name index. By-name lookups go through the name sentinel, notgsi1.EntityItem: writechildrenGsiSk(id)intogsi1skinstead of the name.DynamoDbSchema: comment and helper-name updates only.gsi1skstays a string attribute, so the table and index definitions do not change.Testing
DynamoDbLayoutTest: padding (0, 42,Long.MAX_VALUE) and numeric sort order.EntityItemTest: expects the padded id ingsi1sk.DynamoDbSchemaIT: siblings whose name order and id order differ come back fromgsi1in id order. Ids 30 and 200 also check the padding../gradlew :polaris-persistence-dynamodb-atomic:spotlessCheck checkstyleMain checkstyleTest checkstyleIntTest compileIntTestJava test javadocpasses locally.DynamoDbSchemaITneeds Docker and runs in CI.Checklist