lotus/chain/store/splitstore/lmdb_util.go

28 lines
520 B
Go
Raw Normal View History

2021-02-01 12:27:20 +00:00
package splitstore
import (
"math/rand"
"time"
"golang.org/x/xerrors"
2021-02-01 12:27:20 +00:00
"github.com/ledgerwatch/lmdb-go/lmdb"
)
func withMaxReadersRetry(f func() error) error {
retry:
err := f()
if err != nil && lmdb.IsErrno(err, lmdb.ReadersFull) {
dt := time.Microsecond + time.Duration(rand.Intn(int(10*time.Microsecond)))
2021-02-01 12:31:31 +00:00
log.Debugf("MDB_READERS_FULL; retrying operation in %s", dt)
2021-02-01 12:27:20 +00:00
time.Sleep(dt)
goto retry
}
if err != nil {
return xerrors.Errorf("error performing lmdb operation: %w", err)
}
return nil
2021-02-01 12:27:20 +00:00
}