-
Notifications
You must be signed in to change notification settings - Fork 65
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
db: add txn discard to api #437
Conversation
Signed-off-by: Sander Pick <sanderpick@gmail.com>
t.Fatalf("failed to write txn discard: %v", err) | ||
} | ||
|
||
err = txn.Save(existingPerson) |
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.
To be clear, this method discards the changes, but it doesn't abort the transaction itself, correct? To abort the transaction, it looks like we need to close the context, is that right?
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.
I ask because from a remote client perspective, this doesn't appear to be possible?
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.
Yep, exactly, it's still "alive" but will error when it's committed using End
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.
Perfect!
t.Fatalf("failed to start write txn: %v", err) | ||
} | ||
defer func() { | ||
err = end() |
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.
@carsonfarmer this is calling the func returned by the Go client that actually just sends a CloseSend
to the server, which makes it release the transaction... that means it will be committed, but will error if it has been marked as "discarded"
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.
You can see how the Go client "ends" the transaction here: https://github.com/textileio/go-threads/blob/master/api/client/write.go#L233 (note the extra error catch...)
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.
Yeh this is exactly what I needed. Perfect. One thing I noticed though, in the js client, we're not properly getting the final response as in here: https://github.com/textileio/go-threads/blob/master/api/client/write.go#L237 which we need to ensure the transaction was successful or not.
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.
So this has been a useful thread/discussion. Cheers!
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.
Yeah totally, I ran into that yesterday: #436 (comment)
Signed-off-by: Sander Pick sanderpick@gmail.com