From 2a4f5190a636a91f3142dd81bee79df490740b8f Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 8 Mar 2022 15:08:45 +0000 Subject: [PATCH] kv/bulk: ensure initial splits are safe split keys Release note: none. Release justification: bug fix in new functionality. --- pkg/kv/bulk/buffering_adder.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/kv/bulk/buffering_adder.go b/pkg/kv/bulk/buffering_adder.go index c84695a96c89..28f2f4a52e9b 100644 --- a/pkg/kv/bulk/buffering_adder.go +++ b/pkg/kv/bulk/buffering_adder.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangecache" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" @@ -392,7 +393,11 @@ func (b *BufferingAdder) createInitialSplits(ctx context.Context) error { } predicateAt = next } - splitKey := b.curBuf.Key(splitAt) + splitKey, err := keys.EnsureSafeSplitKey(b.curBuf.Key(splitAt)) + if err != nil { + log.Warningf(ctx, "failed to generate pre-split key for key %s", b.curBuf.Key(splitAt)) + continue + } predicateKey := b.curBuf.Key(predicateAt) log.VEventf(ctx, 1, "pre-splitting span %d of %d at %s", i, b.initialSplits, splitKey) resp, err := b.sink.db.SplitAndScatter(ctx, splitKey, expire, predicateKey)