Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Calling non-Close() methods on closed or written batches panic #71
Calling non-Close() methods on closed or written batches panic #71
Changes from 14 commits
f461790
a52e1a4
d2cd3a9
de5a944
5e27f01
06ff802
50dce04
509e3a6
2ba5dce
adde9ca
f579de8
50bea15
1b5ff54
518db80
131b3e7
ebf819f
76d78b6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
do we even need a separate Close method? if we execute Close in Write/WriteSync
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, because the caller may e.g. return an error while they are building the batch, in which case they need to close it without calling
Write
.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 can easily envision cases where Close will be called twice... maybe it's okay, but I'd prefer to remove Close calls from Write/WriteSync. You're mixing responsibilities
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.
Calling
Close()
twice is fine, it is idempotent. It is a normal Go pattern to usedefer c.Close()
for error handling and then also do an explicitc.Close()
as early as possible to free up resources before the function exits.If we don't call
Close()
inWrite()
, then what should happen when a caller callsWrite()
twice?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.
Didn't know about such.
you can't prevent people from shooting themselves into the leg. I'd assume correct usage in most cases.
New -> Set/Delete -> Write(Sync) -> Close (via defer)
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.
Of course, we just have to specify what should happen, as unspecified behavior is the root of all evil. Either
Write()
also callsClose()
, in which case a secondWrite()
call errors, otherwise the secondWrite()
call should write the same batch again.I think erroring is safer, and easier to implement across all backends. The typical and recommended usage would still be the same flow that you outline.
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.
Agree.
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.
Ok, I think this should be good to go then.