2021-03-02 00:47:21 +00:00
|
|
|
package splitstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
type MarkSetEnv interface {
|
|
|
|
Create(name string, sizeHint int64) (MarkSet, error)
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenMarkSetEnv(path string, mtype string) (MarkSetEnv, error) {
|
|
|
|
switch mtype {
|
2021-07-06 11:44:40 +00:00
|
|
|
case "bloom":
|
2021-06-25 07:07:45 +00:00
|
|
|
return NewBloomMarkSetEnv(false)
|
2021-07-07 13:39:37 +00:00
|
|
|
case "bloomts": // thread-safe
|
2021-06-25 07:07:45 +00:00
|
|
|
return NewBloomMarkSetEnv(true)
|
2021-06-25 16:41:31 +00:00
|
|
|
case "map":
|
|
|
|
return NewMapMarkSetEnv(false)
|
2021-07-07 13:39:37 +00:00
|
|
|
case "mapts": // thread-safe
|
2021-06-25 16:41:31 +00:00
|
|
|
return NewMapMarkSetEnv(true)
|
2021-03-02 00:47:21 +00:00
|
|
|
default:
|
|
|
|
return nil, xerrors.Errorf("unknown mark set type %s", mtype)
|
|
|
|
}
|
|
|
|
}
|