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
import (
"errors"
"runtime"
"sync/atomic"
@ -10,13 +11,12 @@ import (
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) {
if !EnableReification {
return
}
if !s.isWarm() {
return
}
@ -104,12 +104,18 @@ func (s *SplitStore) doReify(c cid.Cid) {
s.txnLk.RLock()
defer s.txnLk.RUnlock()
count := 0
err := s.walkObjectIncomplete(c, newTmpVisitor(),
func(c cid.Cid) error {
if isUnitaryObject(c) {
return errStopWalk
}
count++
if count > ReifyLimit {
return errReifyLimit
}
s.reifyMx.Lock()
_, inProgress := s.reifyInProgress[c]
if !inProgress {
@ -150,6 +156,11 @@ func (s *SplitStore) doReify(c cid.Cid) {
})
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)
return
}