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

Add example blockstore examples #180

Merged
merged 2 commits into from
Jul 16, 2021
Merged

Add example blockstore examples #180

merged 2 commits into from
Jul 16, 2021

Conversation

masih
Copy link
Member

@masih masih commented Jul 16, 2021

Implement examples that show how to open a read-only blockstore, and a
read-write blockstore along with resumption from the same file.

Fixes:

@masih masih force-pushed the blockstore-example branch 2 times, most recently from 1798caf to d9aa434 Compare July 16, 2021 15:23
@masih masih marked this pull request as ready for review July 16, 2021 15:25
fmt.Println("List of first 5 CIDs and their raw data size:")
var i int
for k := range keysChan {
if i > 4 {
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want to print 5, I think it's then easier to do i >= 5, to use the same number everywhere. you might as well make that a const/var and use it in the print above


// Finalize the blockstore to flush out the index and make a complete CARv2.
// Note, Finalize must be called on an open ReadWrite blockstore to flush out a complete CARv2.
if err = resumedRwbos.Finalize(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be :=; it helps keep the code simpler to follow as you're not modifying the var in the parent scope. this can be done for any other place where you only assign an error.

masih and others added 2 commits July 16, 2021 17:54
Implement examples that show how to open a read-only blockstore, and a
read-write blockstore along with resumption from the same file.

The example surfaced a race condition where if the `AllKeysChan` is
partially consumed and file is closed then the gorutie started by chan
population causes the race condition. Locking on Close will make the
closure hang. Better solution is needed but choices are limited due to
`AllKeysChan` signature.

Fixes:
- #124
@masih masih merged commit c06b4f2 into wip-v2 Jul 16, 2021
@masih masih deleted the blockstore-example branch July 16, 2021 16:59
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