diff --git a/blockstore/splitstore/markset.go b/blockstore/splitstore/markset.go index 34a12de38..218681e13 100644 --- a/blockstore/splitstore/markset.go +++ b/blockstore/splitstore/markset.go @@ -41,8 +41,6 @@ type MarkSetEnv interface { func OpenMarkSetEnv(path string, mtype string) (MarkSetEnv, error) { switch mtype { - case "bloom": - return NewBloomMarkSetEnv() case "map": return NewMapMarkSetEnv() case "badger": diff --git a/blockstore/splitstore/markset_bloom.go b/blockstore/splitstore/markset_bloom.go deleted file mode 100644 index 26c6b06f6..000000000 --- a/blockstore/splitstore/markset_bloom.go +++ /dev/null @@ -1,113 +0,0 @@ -package splitstore - -import ( - "crypto/rand" - "crypto/sha256" - "sync" - - "golang.org/x/xerrors" - - bbloom "github.com/ipfs/bbloom" - cid "github.com/ipfs/go-cid" -) - -const ( - BloomFilterMinSize = 10_000_000 - BloomFilterProbability = 0.01 -) - -type BloomMarkSetEnv struct{} - -var _ MarkSetEnv = (*BloomMarkSetEnv)(nil) - -type BloomMarkSet struct { - salt []byte - mx sync.RWMutex - bf *bbloom.Bloom - ts bool -} - -var _ MarkSet = (*BloomMarkSet)(nil) - -func NewBloomMarkSetEnv() (*BloomMarkSetEnv, error) { - return &BloomMarkSetEnv{}, nil -} - -func (e *BloomMarkSetEnv) Create(name string, sizeHint int64) (MarkSet, error) { - size := int64(BloomFilterMinSize) - for size < sizeHint { - size += BloomFilterMinSize - } - - salt := make([]byte, 4) - _, err := rand.Read(salt) - if err != nil { - return nil, xerrors.Errorf("error reading salt: %w", err) - } - - bf, err := bbloom.New(float64(size), BloomFilterProbability) - if err != nil { - return nil, xerrors.Errorf("error creating bloom filter: %w", err) - } - - return &BloomMarkSet{salt: salt, bf: bf}, nil -} - -func (e *BloomMarkSetEnv) CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error) { - return nil, xerrors.Errorf("bloom mark set does not support visitors due to false positives") -} - -func (e *BloomMarkSetEnv) SupportsVisitor() bool { return false } - -func (e *BloomMarkSetEnv) Close() error { - return nil -} - -func (s *BloomMarkSet) saltedKey(cid cid.Cid) []byte { - hash := cid.Hash() - key := make([]byte, len(s.salt)+len(hash)) - n := copy(key, s.salt) - copy(key[n:], hash) - rehash := sha256.Sum256(key) - return rehash[:] -} - -func (s *BloomMarkSet) Mark(cid cid.Cid) error { - if s.ts { - s.mx.Lock() - defer s.mx.Unlock() - } - - if s.bf == nil { - return errMarkSetClosed - } - - s.bf.Add(s.saltedKey(cid)) - return nil -} - -func (s *BloomMarkSet) Has(cid cid.Cid) (bool, error) { - if s.ts { - s.mx.RLock() - defer s.mx.RUnlock() - } - - if s.bf == nil { - return false, errMarkSetClosed - } - - return s.bf.Has(s.saltedKey(cid)), nil -} - -func (s *BloomMarkSet) Close() error { - if s.ts { - s.mx.Lock() - defer s.mx.Unlock() - } - s.bf = nil - return nil -} - -func (s *BloomMarkSet) SetConcurrent() { - s.ts = true -} diff --git a/blockstore/splitstore/markset_test.go b/blockstore/splitstore/markset_test.go index 93490c4c1..a4a42e860 100644 --- a/blockstore/splitstore/markset_test.go +++ b/blockstore/splitstore/markset_test.go @@ -14,10 +14,6 @@ func TestMapMarkSet(t *testing.T) { testMarkSetVisitor(t, "map") } -func TestBloomMarkSet(t *testing.T) { - testMarkSet(t, "bloom") -} - func TestBadgerMarkSet(t *testing.T) { bs := badgerMarkSetBatchSize badgerMarkSetBatchSize = 1