From 0eee733220fc766ff0d193d61d9124aa06493986 Mon Sep 17 00:00:00 2001 From: mlmhl Date: Fri, 20 Mar 2020 12:01:36 +0800 Subject: [PATCH] mvcc: no need to hold tx lock when converting kvs to watch events (#11701) Method `kvsToEvents` can take a long time if a large number of events need to be synchronized. However, this method does not access any shared resources, so it no need to hold the tx lock when executing. So we can move it outside to reduce lock holding time. --- mvcc/watchable_store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvcc/watchable_store.go b/mvcc/watchable_store.go index 0529993c658..4d709d6440f 100644 --- a/mvcc/watchable_store.go +++ b/mvcc/watchable_store.go @@ -358,9 +358,9 @@ func (s *watchableStore) syncWatchers() int { tx := s.store.b.ReadTx() tx.RLock() revs, vs := tx.UnsafeRange(keyBucketName, minBytes, maxBytes, 0) + tx.RUnlock() var evs []mvccpb.Event evs = kvsToEvents(s.store.lg, wg, revs, vs) - tx.RUnlock() var victims watcherBatch wb := newWatcherBatch(wg, evs)