2021-02-01 12:27:20 +00:00
|
|
|
package splitstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
|
2021-02-10 17:21:42 +00:00
|
|
|
"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()
|
2021-02-10 17:21:42 +00:00
|
|
|
if err != nil && lmdb.IsErrno(err, lmdb.ReadersFull) {
|
2021-02-13 14:54:19 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:21:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("error performing lmdb operation: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-02-01 12:27:20 +00:00
|
|
|
}
|