2021-03-02 00:47:21 +00:00
|
|
|
package splitstore
|
|
|
|
|
|
|
|
import (
|
2021-07-08 07:18:43 +00:00
|
|
|
"errors"
|
|
|
|
|
2021-03-02 00:47:21 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
2021-07-08 07:18:43 +00:00
|
|
|
var errMarkSetClosed = errors.New("markset closed")
|
|
|
|
|
2021-03-02 00:47:21 +00:00
|
|
|
// MarkSet is a utility to keep track of seen CID, and later query for them.
|
|
|
|
//
|
|
|
|
// * If the expected dataset is large, it can be backed by a datastore (e.g. bbolt).
|
2021-07-06 11:44:40 +00:00
|
|
|
// * If a probabilistic result is acceptable, it can be backed by a bloom filter
|
2021-03-02 00:47:21 +00:00
|
|
|
type MarkSet interface {
|
|
|
|
Mark(cid.Cid) error
|
|
|
|
Has(cid.Cid) (bool, error)
|
|
|
|
Close() error
|
2021-07-09 01:26:36 +00:00
|
|
|
SetConcurrent()
|
2021-03-02 00:47:21 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 06:42:20 +00:00
|
|
|
type MarkSetVisitor interface {
|
2021-08-03 07:37:08 +00:00
|
|
|
MarkSet
|
2021-07-30 06:42:20 +00:00
|
|
|
ObjectVisitor
|
|
|
|
}
|
|
|
|
|
2021-03-02 00:47:21 +00:00
|
|
|
type MarkSetEnv interface {
|
2021-08-03 07:37:08 +00:00
|
|
|
// Create creates a new markset within the environment.
|
|
|
|
// name is a unique name for this markset, mapped to the filesystem in disk-backed environments
|
|
|
|
// sizeHint is a hint about the expected size of the markset
|
2021-03-02 00:47:21 +00:00
|
|
|
Create(name string, sizeHint int64) (MarkSet, error)
|
2021-08-03 07:37:08 +00:00
|
|
|
// 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).
|
2021-07-30 06:42:20 +00:00
|
|
|
CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error)
|
2021-08-10 07:27:32 +00:00
|
|
|
// SupportsVisitor returns true if the marksets created by this environment support the visitor interface.
|
|
|
|
SupportsVisitor() bool
|
2021-03-02 00:47:21 +00:00
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenMarkSetEnv(path string, mtype string) (MarkSetEnv, error) {
|
|
|
|
switch mtype {
|
2021-06-25 16:41:31 +00:00
|
|
|
case "map":
|
2021-07-09 01:26:36 +00:00
|
|
|
return NewMapMarkSetEnv()
|
2021-07-22 09:11:49 +00:00
|
|
|
case "badger":
|
|
|
|
return NewBadgerMarkSetEnv(path)
|
2021-03-02 00:47:21 +00:00
|
|
|
default:
|
|
|
|
return nil, xerrors.Errorf("unknown mark set type %s", mtype)
|
|
|
|
}
|
|
|
|
}
|