add reification limit

This commit is contained in:
vyzo 2022-02-18 12:19:09 +02:00
parent cf7a0415c1
commit cbd23c2b1b

View File

@ -1,6 +1,7 @@
package splitstore package splitstore
import ( import (
"errors"
"runtime" "runtime"
"sync/atomic" "sync/atomic"
@ -10,13 +11,12 @@ import (
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
) )
var EnableReification = false var (
errReifyLimit = errors.New("reification limit reached")
ReifyLimit = 16384
)
func (s *SplitStore) reifyColdObject(c cid.Cid) { func (s *SplitStore) reifyColdObject(c cid.Cid) {
if !EnableReification {
return
}
if !s.isWarm() { if !s.isWarm() {
return return
} }
@ -104,12 +104,18 @@ func (s *SplitStore) doReify(c cid.Cid) {
s.txnLk.RLock() s.txnLk.RLock()
defer s.txnLk.RUnlock() defer s.txnLk.RUnlock()
count := 0
err := s.walkObjectIncomplete(c, newTmpVisitor(), err := s.walkObjectIncomplete(c, newTmpVisitor(),
func(c cid.Cid) error { func(c cid.Cid) error {
if isUnitaryObject(c) { if isUnitaryObject(c) {
return errStopWalk return errStopWalk
} }
count++
if count > ReifyLimit {
return errReifyLimit
}
s.reifyMx.Lock() s.reifyMx.Lock()
_, inProgress := s.reifyInProgress[c] _, inProgress := s.reifyInProgress[c]
if !inProgress { if !inProgress {
@ -150,6 +156,11 @@ func (s *SplitStore) doReify(c cid.Cid) {
}) })
if err != nil { if err != nil {
if xerrors.Is(err, errReifyLimit) {
log.Debug("reification aborted; reify limit reached")
return
}
log.Warnf("error walking cold object for reification (cid: %s): %s", c, err) log.Warnf("error walking cold object for reification (cid: %s): %s", c, err)
return return
} }