mvcc: Obtain txLock once in readTx#UnsafeRange

Signed-off-by: Ted Yu <yuzhihong@gmail.com>
This commit is contained in:
Ted Yu 2020-05-09 16:28:47 -07:00
parent c9377195d5
commit 2dbbe6ce85

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()