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")
|
|
|
|
|
2022-01-25 14:31:45 +00:00
|
|
|
// MarkSet is an interface for tracking CIDs during chain and object walks
|
2021-03-02 00:47:21 +00:00
|
|
|
type MarkSet interface {
|
2022-01-25 14:31:45 +00:00
|
|
|
ObjectVisitor
|
2021-03-02 00:47:21 +00:00
|
|
|
Mark(cid.Cid) error
|
|
|
|
Has(cid.Cid) (bool, error)
|
|
|
|
Close() error
|
2022-01-28 13:41:33 +00:00
|
|
|
|
|
|
|
// BeginCriticalSection ensures that the markset is persisted to disk for recovery in case
|
|
|
|
// of abnormal termination during the critical section span.
|
|
|
|
BeginCriticalSection() error
|
|
|
|
// EndCriticalSection ends the critical section span.
|
|
|
|
EndCriticalSection()
|
2021-07-30 06:42:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 00:47:21 +00:00
|
|
|
type MarkSetEnv interface {
|
2022-01-28 13:41:33 +00:00
|
|
|
// New creates a new markset within the environment.
|
|
|
|
// name is a unique name for this markset, mapped to the filesystem for on-disk persistence.
|
2021-08-03 07:37:08 +00:00
|
|
|
// sizeHint is a hint about the expected size of the markset
|
2022-01-28 13:41:33 +00:00
|
|
|
New(name string, sizeHint int64) (MarkSet, error)
|
|
|
|
// Recover recovers an existing markset persisted on-disk.
|
|
|
|
Recover(name string) (MarkSet, error)
|
2022-01-25 14:31:45 +00:00
|
|
|
// Close closes the markset
|
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":
|
2022-01-28 13:41:33 +00:00
|
|
|
return NewMapMarkSetEnv(path)
|
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)
|
|
|
|
}
|
|
|
|
}
|