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

ReadWrite: add an alternative FinalizeReadOnly+Close flow #376

Merged
merged 2 commits into from
Mar 7, 2023

Conversation

MichaelMure
Copy link
Contributor

@MichaelMure MichaelMure commented Feb 16, 2023

The goal being to be able to keep reading blocks and the index after safely finalizing the file on disk. Typically for indexing purpose.

More tests are likely required, but PR for early feedback.

fix #375

Copy link
Member

@willscott willscott left a comment

Choose a reason for hiding this comment

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

this looks fine to me in terms of structure.

A test would probably not hurt to make sure we don't break the functionality in the future

Comment on lines 296 to 299
if !b.finalized {
return fmt.Errorf("called Close without FinalizeReadOnly first")
}
Copy link
Member

Choose a reason for hiding this comment

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

should we finalize in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm maybe? TBH, if I had to write that code from zero I would just panic(), as that's a clear developer problem.
Up to you, I can add it.

Copy link
Member

Choose a reason for hiding this comment

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

If we make this also finalise then we could eventually deprecate Finalize() so that Close() is always what you call at the end of use of a readwrite, you just have the option of also making it readonly before you do that. So I think my vote would be to add a finalisation phase in here if it's not already done, then we could update docs to make it clear you can do either.

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 is a bit odd to me. When working on a file, there is two outcomes: Finalize() and Discard(). Here you want, in the odd case that the caller didn't choose one, arbitrary choose Finalize()?

With the current PR, you get three clear paths:

  • Discard()
  • Finalize()
  • FinalizeReadOnly() + Close()

If Close() also finalize, we get:

  • Discard()
  • Finalize()
  • Close()
  • FinalizeReadOnly() + Close()

I get that you might want this (although the current PR version look more obvious to me):

  • Discard()
  • Close()
  • FinalizeReadOnly() + Close()

In that case, I'd suggest to go there in one go, and skip the confusing in-between.

@MichaelMure MichaelMure force-pushed the finalizeReadOnly branch 3 times, most recently from c99362e to ad281c5 Compare February 20, 2023 13:17
@MichaelMure
Copy link
Contributor Author

I added a test. It should be good to go, depending on what you want with #376 (comment).

v2/blockstore/readwrite.go Outdated Show resolved Hide resolved
The goal being to be able to keep reading blocks and the index after safely finalizing
the file on disk. Typically for indexing purpose.
v2/blockstore/readwrite.go Outdated Show resolved Hide resolved
…error

Co-authored-by: Rod Vagg <rod@vagg.org>
@rvagg rvagg merged commit 34f4b63 into ipld:master Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Development

Successfully merging this pull request may close these issues.

Blockstore: Finalize but still readable
3 participants