From a9403b42f024b2d1d656d4ad1c08d810ee712b5a Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 3 Aug 2021 11:41:49 +0300 Subject: [PATCH] deduplicate put code --- blockstore/splitstore/markset_badger.go | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/blockstore/splitstore/markset_badger.go b/blockstore/splitstore/markset_badger.go index 53aea25c9..d46b5cf6b 100644 --- a/blockstore/splitstore/markset_badger.go +++ b/blockstore/splitstore/markset_badger.go @@ -87,14 +87,7 @@ func (s *BadgerMarkSet) Mark(c cid.Cid) error { return errMarkSetClosed } - s.pend[string(c.Hash())] = struct{}{} - - if len(s.pend) < badgerMarkSetBatchSize { - s.mx.Unlock() - return nil - } - - return s.putPending() + return s.put(string(c.Hash())) } func (s *BadgerMarkSet) Has(c cid.Cid) (bool, error) { @@ -153,13 +146,7 @@ func (s *BadgerMarkSet) Visit(c cid.Cid) (bool, error) { } } - s.pend[pendKey] = struct{}{} - if len(s.pend) < badgerMarkSetBatchSize { - s.mx.Unlock() - return true, nil - } - - if err := s.putPending(); err != nil { + if err := s.put(pendKey); err != nil { return false, err } @@ -203,8 +190,14 @@ func (s *BadgerMarkSet) tryDB(key []byte) (has bool, err error) { } } -// writer holds the exclusive lock; putPending releases it -func (s *BadgerMarkSet) putPending() error { +// writer holds the exclusive lock; put releases it +func (s *BadgerMarkSet) put(key string) error { + s.pend[key] = struct{}{} + if len(s.pend) < badgerMarkSetBatchSize { + s.mx.Unlock() + return nil + } + pend := s.pend seqno := s.seqno s.seqno++