widen MarkSetVisitor interface and get rid of the casts
This commit is contained in:
parent
57c984cea1
commit
b83b5405c6
@ -22,13 +22,17 @@ type MarkSet interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MarkSetVisitor interface {
|
type MarkSetVisitor interface {
|
||||||
|
MarkSet
|
||||||
ObjectVisitor
|
ObjectVisitor
|
||||||
Close() error
|
|
||||||
SetConcurrent()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MarkSetEnv interface {
|
type MarkSetEnv interface {
|
||||||
|
// 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
|
||||||
Create(name string, sizeHint int64) (MarkSet, error)
|
Create(name string, sizeHint int64) (MarkSet, error)
|
||||||
|
// 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).
|
||||||
CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error)
|
CreateVisitor(name string, sizeHint int64) (MarkSetVisitor, error)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,6 @@ type SplitStore struct {
|
|||||||
txnViews int
|
txnViews int
|
||||||
txnViewsWaiting bool
|
txnViewsWaiting bool
|
||||||
txnActive bool
|
txnActive bool
|
||||||
txnProtect MarkSet
|
|
||||||
txnRefsMx sync.Mutex
|
txnRefsMx sync.Mutex
|
||||||
txnRefs map[cid.Cid]struct{}
|
txnRefs map[cid.Cid]struct{}
|
||||||
txnMissing map[cid.Cid]struct{}
|
txnMissing map[cid.Cid]struct{}
|
||||||
|
@ -211,7 +211,7 @@ func (s *SplitStore) trackTxnRefMany(cids []cid.Cid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// protect all pending transactional references
|
// protect all pending transactional references
|
||||||
func (s *SplitStore) protectTxnRefs(markSet MarkSet) error {
|
func (s *SplitStore) protectTxnRefs(markSet MarkSetVisitor) error {
|
||||||
for {
|
for {
|
||||||
var txnRefs map[cid.Cid]struct{}
|
var txnRefs map[cid.Cid]struct{}
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ func (s *SplitStore) protectTxnRefs(markSet MarkSet) error {
|
|||||||
|
|
||||||
// transactionally protect a reference by walking the object and marking.
|
// transactionally protect a reference by walking the object and marking.
|
||||||
// concurrent markings are short circuited by checking the markset.
|
// concurrent markings are short circuited by checking the markset.
|
||||||
func (s *SplitStore) doTxnProtect(root cid.Cid, markSet MarkSet) error {
|
func (s *SplitStore) doTxnProtect(root cid.Cid, markSet MarkSetVisitor) error {
|
||||||
if err := s.checkClosing(); err != nil {
|
if err := s.checkClosing(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -296,30 +296,13 @@ func (s *SplitStore) doTxnProtect(root cid.Cid, markSet MarkSet) error {
|
|||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor, ok := markSet.(MarkSetVisitor)
|
visit, err := markSet.Visit(c)
|
||||||
if ok {
|
if err != nil {
|
||||||
visit, err := visitor.Visit(c)
|
return xerrors.Errorf("error visiting object: %w", err)
|
||||||
if err != nil {
|
}
|
||||||
return xerrors.Errorf("error visiting object: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !visit {
|
if !visit {
|
||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mark, err := markSet.Has(c)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("error checking markset: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// it's marked, nothing to do
|
|
||||||
if mark {
|
|
||||||
return errStopWalk
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = markSet.Mark(c); err != nil {
|
|
||||||
return xerrors.Errorf("error marking object: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -398,7 +381,7 @@ func (s *SplitStore) doCompact(curTs *types.TipSet) error {
|
|||||||
|
|
||||||
log.Infow("running compaction", "currentEpoch", currentEpoch, "baseEpoch", s.baseEpoch, "boundaryEpoch", boundaryEpoch, "inclMsgsEpoch", inclMsgsEpoch, "compactionIndex", s.compactionIndex)
|
log.Infow("running compaction", "currentEpoch", currentEpoch, "baseEpoch", s.baseEpoch, "boundaryEpoch", boundaryEpoch, "inclMsgsEpoch", inclMsgsEpoch, "compactionIndex", s.compactionIndex)
|
||||||
|
|
||||||
markSet, err := s.markSetEnv.Create("live", s.markSetSize)
|
markSet, err := s.markSetEnv.CreateVisitor("live", s.markSetSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("error creating mark set: %w", err)
|
return xerrors.Errorf("error creating mark set: %w", err)
|
||||||
}
|
}
|
||||||
@ -432,28 +415,13 @@ func (s *SplitStore) doCompact(curTs *types.TipSet) error {
|
|||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
}
|
||||||
|
|
||||||
if visitor, ok := markSet.(MarkSetVisitor); ok {
|
visit, err := markSet.Visit(c)
|
||||||
visit, err := visitor.Visit(c)
|
if err != nil {
|
||||||
if err != nil {
|
return xerrors.Errorf("error visiting object: %w", err)
|
||||||
return xerrors.Errorf("error visiting object: %w", err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !visit {
|
if !visit {
|
||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
|
||||||
} else {
|
|
||||||
has, err := markSet.Has(c)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("error checking markset: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if has {
|
|
||||||
return errStopWalk
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = markSet.Mark(c); err != nil {
|
|
||||||
return xerrors.Errorf("error marking: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
@ -618,12 +586,8 @@ func (s *SplitStore) beginTxnProtect() {
|
|||||||
s.txnMissing = make(map[cid.Cid]struct{})
|
s.txnMissing = make(map[cid.Cid]struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SplitStore) beginTxnMarking(markSet MarkSet) {
|
func (s *SplitStore) beginTxnMarking(markSet MarkSetVisitor) {
|
||||||
markSet.SetConcurrent()
|
markSet.SetConcurrent()
|
||||||
|
|
||||||
s.txnLk.Lock()
|
|
||||||
s.txnProtect = markSet
|
|
||||||
s.txnLk.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SplitStore) endTxnProtect() {
|
func (s *SplitStore) endTxnProtect() {
|
||||||
@ -634,13 +598,7 @@ func (s *SplitStore) endTxnProtect() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// release markset memory
|
|
||||||
if s.txnProtect != nil {
|
|
||||||
_ = s.txnProtect.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
s.txnActive = false
|
s.txnActive = false
|
||||||
s.txnProtect = nil
|
|
||||||
s.txnRefs = nil
|
s.txnRefs = nil
|
||||||
s.txnMissing = nil
|
s.txnMissing = nil
|
||||||
}
|
}
|
||||||
@ -1037,7 +995,7 @@ func (s *SplitStore) purgeBatch(cids []cid.Cid, deleteBatch func([]cid.Cid) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SplitStore) purge(cids []cid.Cid, markSet MarkSet) error {
|
func (s *SplitStore) purge(cids []cid.Cid, markSet MarkSetVisitor) error {
|
||||||
deadCids := make([]cid.Cid, 0, batchSize)
|
deadCids := make([]cid.Cid, 0, batchSize)
|
||||||
var purgeCnt, liveCnt int
|
var purgeCnt, liveCnt int
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -1103,7 +1061,7 @@ func (s *SplitStore) purge(cids []cid.Cid, markSet MarkSet) error {
|
|||||||
// have this gem[TM].
|
// have this gem[TM].
|
||||||
// My best guess is that they are parent message receipts or yet to be computed state roots; magik
|
// My best guess is that they are parent message receipts or yet to be computed state roots; magik
|
||||||
// thinks the cause may be block validation.
|
// thinks the cause may be block validation.
|
||||||
func (s *SplitStore) waitForMissingRefs(markSet MarkSet) {
|
func (s *SplitStore) waitForMissingRefs(markSet MarkSetVisitor) {
|
||||||
s.txnLk.Lock()
|
s.txnLk.Lock()
|
||||||
missing := s.txnMissing
|
missing := s.txnMissing
|
||||||
s.txnMissing = nil
|
s.txnMissing = nil
|
||||||
@ -1142,29 +1100,13 @@ func (s *SplitStore) waitForMissingRefs(markSet MarkSet) {
|
|||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor, ok := markSet.(MarkSetVisitor)
|
visit, err := markSet.Visit(c)
|
||||||
if ok {
|
if err != nil {
|
||||||
visit, err := visitor.Visit(c)
|
return xerrors.Errorf("error visiting object: %w", err)
|
||||||
if err != nil {
|
}
|
||||||
return xerrors.Errorf("error visiting object: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !visit {
|
if !visit {
|
||||||
return errStopWalk
|
return errStopWalk
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mark, err := markSet.Has(c)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("error checking markset for %s: %w", c, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if mark {
|
|
||||||
return errStopWalk
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = markSet.Mark(c); err != nil {
|
|
||||||
return xerrors.Errorf("error marking object: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
|
Loading…
Reference in New Issue
Block a user