-
Notifications
You must be signed in to change notification settings - Fork 242
Idempotent apis #1096
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
Idempotent apis #1096
Conversation
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
0618bc2 to
56d727a
Compare
Codecov Report
@@ Coverage Diff @@
## main #1096 +/- ##
=======================================
Coverage 99.98% 99.98%
=======================================
Files 308 309 +1
Lines 20467 20553 +86
=======================================
+ Hits 20463 20549 +86
Misses 4 4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
| } | ||
|
|
||
| txid, err := mm.txHelper.SubmitNewTransaction(ctx, core.TransactionTypeNetworkAction) | ||
| txid, err := mm.txHelper.SubmitNewTransaction(ctx, core.TransactionTypeNetworkAction, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idempotency on this one?
| fb := database.MessageQueryFactory.NewFilter(ctx) | ||
| existing, _, err := mw.database.GetMessages(ctx, m.Header.Namespace, fb.Eq("idempotencykey", (string)(m.IdempotencyKey))) | ||
| if err != nil { | ||
| // Don't overwrite the original error for this - return -1 to the caller, who will return the previous error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1?
| } | ||
| batch = nil | ||
| delete(batch.listeners, *m.Header.ID) | ||
| // Remove all the data associated with this message from the batch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an edge case where two messages in the same batch could reference the same piece of data, and only one gets removed?
awrichar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good. One edge case noted for consideration.
This feature allows API requests to FireFly Core to be made idempotent.
That is that the caller of the API can specify its own unique identifier (an arbitrary string up to 256 characters) that uniquely identifies the request. So if there is a network connectivity failure, or an abrupt termination of either runtime, the application can safely attempt to resubmit the REST API call and be returned a
409 ConflictHTTP code.Examples of how an app might construct such an idempotencyKey include:
FireFly already uses an idempotent interface downstream to key plugins:
Tasks
idempotencyKeyfield to messagesMessageobjectpersistBatchwhen received remotelyidempotencyKeytoinvokeof blockchain smart contractsTransactionobjectidempotencyKeytodeployof blockchain smart contractsTransactionobjectidempotencyKeytotransfer(/mint/burn/approval) of tokensTransactionobjectidempotencyKeytopublishAPIs