add SupportsVisitor in the markset env interface

This commit is contained in:
vyzo 2021-08-10 10:27:32 +03:00
parent 79f348a01c
commit 742c85bf81
5 changed files with 12 additions and 0 deletions

View File

@ -34,6 +34,8 @@ type MarkSetEnv interface {
// CreateVisitor is like Create, but returns a wider interface that supports atomic visits. // CreateVisitor is like Create, but returns a wider interface that supports atomic visits.
// It may not be supported by some markset types (e.g. bloom). // It may not be supported by some markset types (e.g. bloom).
CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error) CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error)
// SupportsVisitor returns true if the marksets created by this environment support the visitor interface.
SupportsVisitor() bool
Close() error Close() error
} }

View File

@ -76,6 +76,8 @@ func (e *BadgerMarkSetEnv) CreateVisitor(name string, sizeHint int64) (MarkSetVi
return e.create(name, sizeHint) return e.create(name, sizeHint)
} }
func (e *BadgerMarkSetEnv) SupportsVisitor() bool { return true }
func (e *BadgerMarkSetEnv) Close() error { func (e *BadgerMarkSetEnv) Close() error {
return os.RemoveAll(e.path) return os.RemoveAll(e.path)
} }

View File

@ -57,6 +57,8 @@ func (e *BloomMarkSetEnv) CreateVisitor(name string, sizeHint int64) (MarkSetVis
return nil, xerrors.Errorf("bloom mark set does not support visitors due to false positives") 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 { func (e *BloomMarkSetEnv) Close() error {
return nil return nil
} }

View File

@ -38,6 +38,8 @@ func (e *MapMarkSetEnv) CreateVisitor(name string, sizeHint int64) (MarkSetVisit
return e.create(name, sizeHint) return e.create(name, sizeHint)
} }
func (e *MapMarkSetEnv) SupportsVisitor() bool { return true }
func (e *MapMarkSetEnv) Close() error { func (e *MapMarkSetEnv) Close() error {
return nil return nil
} }

View File

@ -173,6 +173,10 @@ func Open(path string, ds dstore.Datastore, hot, cold bstore.Blockstore, cfg *Co
return nil, err return nil, err
} }
if !markSetEnv.SupportsVisitor() {
return nil, xerrors.Errorf("markset type does not support atomic visitors")
}
// and now we can make a SplitStore // and now we can make a SplitStore
ss := &SplitStore{ ss := &SplitStore{
cfg: cfg, cfg: cfg,