45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package splitstore
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"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).
|
|
// * If a probabilistic result is acceptable, it can be backed by a bloom filter
|
|
type MarkSet interface {
|
|
Mark(cid.Cid) error
|
|
Has(cid.Cid) (bool, error)
|
|
Close() error
|
|
}
|
|
|
|
// markBytes is deliberately a non-nil empty byte slice for serialization.
|
|
var markBytes = []byte{}
|
|
|
|
type MarkSetEnv interface {
|
|
Create(name string, sizeHint int64) (MarkSet, error)
|
|
Close() error
|
|
}
|
|
|
|
func OpenMarkSetEnv(path string, mtype string) (MarkSetEnv, error) {
|
|
switch mtype {
|
|
case "bloom":
|
|
return NewBloomMarkSetEnv(false)
|
|
case "bloomts":
|
|
return NewBloomMarkSetEnv(true)
|
|
case "map":
|
|
return NewMapMarkSetEnv(false)
|
|
case "mapts":
|
|
return NewMapMarkSetEnv(true)
|
|
case "bolt":
|
|
return NewBoltMarkSetEnv(filepath.Join(path, "markset.bolt"))
|
|
default:
|
|
return nil, xerrors.Errorf("unknown mark set type %s", mtype)
|
|
}
|
|
}
|