Merge pull request #11860 from tedyu/range-tx-lock

mvcc: Obtain tx Lock once in readTx#UnsafeRange
This commit is contained in:
Gyuho Lee 2020-05-09 22:23:02 -07:00 committed by GitHub
commit 485e1409ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,18 +77,25 @@ func (rt *readTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]
rt.txMu.RLock()
bucket, ok := rt.buckets[bn]
rt.txMu.RUnlock()
lockHeld := false
if !ok {
rt.txMu.Lock()
lockHeld = true
bucket = rt.tx.Bucket(bucketName)
rt.buckets[bn] = bucket
rt.txMu.Unlock()
}
// ignore missing bucket since may have been created in this batch
if bucket == nil {
if lockHeld {
rt.txMu.Unlock()
}
return keys, vals
}
rt.txMu.Lock()
if !lockHeld {
rt.txMu.Lock()
lockHeld = true
}
c := bucket.Cursor()
rt.txMu.Unlock()