Skip to content

Commit

Permalink
badger: log instead of panicing
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Nov 20, 2023
1 parent 0cf890b commit fc14aa4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion persist/badger/cids.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dgraph-io/badger/v4"
"github.com/ipfs/go-cid"
"go.sia.tech/fsd/sia"
"go.uber.org/zap"
)

// HasBlock returns true if the CID is in the store
Expand Down Expand Up @@ -62,15 +63,22 @@ func (s *Store) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
ch := make(chan cid.Cid)

go func() {
log := s.log.Named("allKeysChan")
_ = s.db.View(func(txn *badger.Txn) error {
it := txn.NewIterator(badger.IteratorOptions{})
defer it.Close()

for it.Rewind(); it.Valid(); it.Next() {
key := string(it.Item().Key())
cid, err := cid.Parse(key)
if err != nil {
log.Error("failed to parse cid", zap.String("key", key))
continue
}
select {
case <-ctx.Done():
return ctx.Err()
case ch <- cid.MustParse(string(it.Item().Key())):
case ch <- cid:
}
}
return nil
Expand Down

0 comments on commit fc14aa4

Please sign in to comment.