ensure kv semaphore has at least 1 count (#641)

This commit is contained in:
hexoscott 2022-09-15 21:14:10 +01:00 committed by GitHub
parent ef693175fe
commit 547ac03eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -281,7 +281,11 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) {
}
if opts.roTxsLimiter == nil {
opts.roTxsLimiter = semaphore.NewWeighted(int64(runtime.GOMAXPROCS(-1)) - 1) // 1 less than max to allow unlocking to happen
targetSemCount := int64(runtime.GOMAXPROCS(-1)) - 1
if targetSemCount <= 1 {
targetSemCount = 2
}
opts.roTxsLimiter = semaphore.NewWeighted(targetSemCount) // 1 less than max to allow unlocking to happen
}
db := &MdbxKV{
opts: opts,

View File

@ -69,12 +69,17 @@ func (opts remoteOpts) WithBucketsConfig(f mdbx.TableCfgFunc) remoteOpts {
}
func (opts remoteOpts) Open() (*RemoteKV, error) {
targetSemCount := int64(runtime.GOMAXPROCS(-1)) - 1
if targetSemCount <= 1 {
targetSemCount = 2
}
db := &RemoteKV{
opts: opts,
remoteKV: opts.remoteKV,
log: log.New("remote_db", opts.DialAddress),
buckets: kv.TableCfg{},
roTxsLimiter: semaphore.NewWeighted(int64(runtime.GOMAXPROCS(-1)) - 1), // 1 less than max to allow unlocking
roTxsLimiter: semaphore.NewWeighted(targetSemCount), // 1 less than max to allow unlocking
}
customBuckets := opts.bucketsCfg(kv.ChaindataTablesCfg)
for name, cfg := range customBuckets { // copy map to avoid changing global variable