Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemory transaction fixes. #91

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

tachyonics
Copy link
Contributor

@tachyonics tachyonics commented Mar 8, 2023

Issue #, if available: #89

Description of changes: Fixes to InMemoryDynamoDBCompositePrimaryKeyTable for transactions

  1. Perform all updates for the transaction atomically
  2. If the transaction fails, revert the store to its state before the transaction
  3. Throw the DuplicateItem error reason correctly if a row exists prior to the transaction
  4. Throw the transactionConditionalCheckFailed correctly if a constraint fails.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment on lines +320 to +321
// restore the state prior to the transaction
self.store = store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for concurrent transactions? Is this possible?

  1. Transaction A takes a store snapshot
  2. Transaction B takes a store + A snapshot
  3. Transaction B succeeds
  4. Transaction A fails and restores store snapshot without B.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't happen as we are executing everything on a serial DispatchQueue. Only one transaction will be executing on the dispatch queue so Transaction A will complete (either successfully or restoring the state) before Transaction B can be run.

https://github.com/amzn/smoke-dynamodb/blob/in_memory_transaction_fixes/Sources/SmokeDynamoDB/InMemoryDynamoDBCompositePrimaryKeyTableStore.swift#L74
https://developer.apple.com/documentation/dispatch/dispatchqueue/2300059-init

This effectively uses a global lock for the table which would be significantly less efficient than DynamoDB in the real world but should ensure correctness.

@tachyonics tachyonics merged commit 38634b5 into smoke-dynamodb-3.x Apr 12, 2023
@tachyonics tachyonics deleted the in_memory_transaction_fixes branch October 5, 2023 21:20
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