From 64c7f5cfade04e6105059c82cce3e055df6beba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=BC=9F=E7=A7=91?= Date: Thu, 31 Oct 2019 14:39:25 +0800 Subject: [PATCH] Fix Panic Due To Decoding Unset EncDatum And Optimize Split Commit: It is found that the split and read-write are separated when the transaction is concurrent. For example, the data key is /Table/68/1/10. The endkey boundary of the range is exactly /Table/68/1/10/0. The previous range does not contain /Table/68/1/10/0, the next range is included. But the scan request sends startKey /Table/68/1/10, endKey /Table/68/1/10/0 in the previous range. The key of the put request is /Table/68/1/10/0. In the latter range, the read and write is separated, so it is optimized in the decider.go. In addition to optimizing the split, the test found that the panic of #41630 has not been triggered so far, so guessing that this modification may also fix the problem described by #39794 #36834 #36356. Fixes #39794 #36834 #36356 Release note (bug fix): Modified code in #42056 submission. --- pkg/storage/split/decider.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/storage/split/decider.go b/pkg/storage/split/decider.go index 91b13f928625..5ec2a0fe8879 100644 --- a/pkg/storage/split/decider.go +++ b/pkg/storage/split/decider.go @@ -15,6 +15,7 @@ package split import ( "time" + "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/syncutil" ) @@ -139,7 +140,12 @@ func (d *Decider) MaybeSplitKey(now time.Time) roachpb.Key { d.mu.Lock() d.recordLocked(now, 0, nil) if d.mu.splitFinder != nil && d.mu.splitFinder.Ready(now) { - key = d.mu.splitFinder.Key() + // For example, the data key is /Table/68/1/10. The endkey boundary of the range + // is exactly /Table/68/1/10/0. The previous range does not contain /Table/68/1/10/0, + // the latter one. Range contains. But the scan request sends startKey /Table/68/1/10, + // endKey /Table/68/1/10/0 in the previous range. The key of the put request is /Table/68/1/10/0. + // In the next range, the read and write is separated. + key, _ = keys.EnsureSafeSplitKey(d.mu.splitFinder.Key()) } d.mu.Unlock()