use a map for txn protection mark set
This commit is contained in:
parent
65ccc99e79
commit
6af3a23dd4
@ -2,6 +2,7 @@ package splitstore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -32,9 +33,67 @@ func OpenMarkSetEnv(path string, mtype string) (MarkSetEnv, error) {
|
|||||||
return NewBloomMarkSetEnv(false)
|
return NewBloomMarkSetEnv(false)
|
||||||
case "bloomts":
|
case "bloomts":
|
||||||
return NewBloomMarkSetEnv(true)
|
return NewBloomMarkSetEnv(true)
|
||||||
|
case "map":
|
||||||
|
return NewMapMarkSetEnv(false)
|
||||||
|
case "mapts":
|
||||||
|
return NewMapMarkSetEnv(true)
|
||||||
case "bolt":
|
case "bolt":
|
||||||
return NewBoltMarkSetEnv(filepath.Join(path, "markset.bolt"))
|
return NewBoltMarkSetEnv(filepath.Join(path, "markset.bolt"))
|
||||||
default:
|
default:
|
||||||
return nil, xerrors.Errorf("unknown mark set type %s", mtype)
|
return nil, xerrors.Errorf("unknown mark set type %s", mtype)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MapMarkSetEnv struct {
|
||||||
|
ts bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ MarkSetEnv = (*MapMarkSetEnv)(nil)
|
||||||
|
|
||||||
|
type MapMarkSet struct {
|
||||||
|
mx sync.Mutex
|
||||||
|
cids map[cid.Cid]struct{}
|
||||||
|
|
||||||
|
ts bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ MarkSet = (*MapMarkSet)(nil)
|
||||||
|
|
||||||
|
func NewMapMarkSetEnv(ts bool) (*MapMarkSetEnv, error) {
|
||||||
|
return &MapMarkSetEnv{ts: ts}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MapMarkSetEnv) Create(name string, sizeHint int64) (MarkSet, error) {
|
||||||
|
return &MapMarkSet{
|
||||||
|
cids: make(map[cid.Cid]struct{}),
|
||||||
|
ts: e.ts,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MapMarkSetEnv) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapMarkSet) Mark(cid cid.Cid) error {
|
||||||
|
if s.ts {
|
||||||
|
s.mx.Lock()
|
||||||
|
defer s.mx.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
s.cids[cid] = struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapMarkSet) Has(cid cid.Cid) (bool, error) {
|
||||||
|
if s.ts {
|
||||||
|
s.mx.Lock()
|
||||||
|
defer s.mx.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok := s.cids[cid]
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapMarkSet) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -168,7 +168,7 @@ func Open(path string, ds dstore.Datastore, hot, cold bstore.Blockstore, cfg *Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the txn markset env
|
// the txn markset env
|
||||||
txnEnv, err := OpenMarkSetEnv(path, "bloomts")
|
txnEnv, err := OpenMarkSetEnv(path, "mapts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = tracker.Close()
|
_ = tracker.Close()
|
||||||
_ = env.Close()
|
_ = env.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user