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

Use NextSync method in Datastore #3386

Merged
merged 2 commits into from
Dec 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions blocks/blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,44 +181,27 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
return nil, err
}

// this function is here to compartmentalize
get := func() (*cid.Cid, bool) {
select {
case <-ctx.Done():
return nil, false
case e, more := <-res.Next():
if !more {
return nil, false
}
if e.Error != nil {
log.Debug("blockstore.AllKeysChan got err:", e.Error)
return nil, false
}

// need to convert to key.Key using key.KeyFromDsKey.
c, err := dshelp.DsKeyToCid(ds.RawKey(e.Key))
if err != nil {
log.Warningf("error parsing key from DsKey: ", err)
return nil, true
}

return c, true
}
}

output := make(chan *cid.Cid, dsq.KeysOnlyBufSize)
go func() {
defer func() {
res.Process().Close() // ensure exit (signals early exit, too)
res.Close() // ensure exit (signals early exit, too)
close(output)
}()

for {
k, ok := get()
e, ok := res.NextSync()
if !ok {
return
}
if k == nil {
if e.Error != nil {
log.Errorf("blockstore.AllKeysChan got err:", e.Error)
return
}

// need to convert to key.Key using key.KeyFromDsKey.
k, err := dshelp.DsKeyToCid(ds.RawKey(e.Key))
if err != nil {
log.Warningf("error parsing key from DsKey: ", err)
continue
}

Expand Down