From 24aa42d85d10ca858ba0f8ea0e54ec6151cf3fb4 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 30 Nov 2016 17:45:17 -0500 Subject: [PATCH 1/2] blockstore.AllKeyChan: avoid channels by using the new NextSync method License: MIT Signed-off-by: Kevin Atkinson --- blocks/blockstore/blockstore.go | 39 ++++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index 9e5d8ca809b..d5a77ab2319 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -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.Debug("blockstore.AllKeysChan got err:", e.Error) + continue + } + + // 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 } From aaaab9508c64a4560664daa5d3ed985c8d85e0c2 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 30 Nov 2016 18:21:24 -0500 Subject: [PATCH 2/2] blockstore.AllKeyChan: fix/cleanup error handling License: MIT Signed-off-by: Kevin Atkinson --- blocks/blockstore/blockstore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index d5a77ab2319..6313cfffe48 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -194,8 +194,8 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) return } if e.Error != nil { - log.Debug("blockstore.AllKeysChan got err:", e.Error) - continue + log.Errorf("blockstore.AllKeysChan got err:", e.Error) + return } // need to convert to key.Key using key.KeyFromDsKey.