diff --git a/pkg/keys/keys.go b/pkg/keys/keys.go index 794c3bebc713..56e00cff1f19 100644 --- a/pkg/keys/keys.go +++ b/pkg/keys/keys.go @@ -804,12 +804,11 @@ func EnsureSafeSplitKey(key roachpb.Key) (roachpb.Key, error) { return key[:idx], nil } -// Range returns a key range encompassing the key ranges of all requests in the -// Batch. -func Range(ba roachpb.BatchRequest) (roachpb.RSpan, error) { +// Range returns a key range encompassing the key ranges of all requests. +func Range(reqs []roachpb.RequestUnion) (roachpb.RSpan, error) { from := roachpb.RKeyMax to := roachpb.RKeyMin - for _, arg := range ba.Requests { + for _, arg := range reqs { req := arg.GetInner() h := req.Header() if !roachpb.IsRange(req) && len(h.EndKey) != 0 { diff --git a/pkg/keys/keys_test.go b/pkg/keys/keys_test.go index 6f73ea483f54..c3f6cb94deaf 100644 --- a/pkg/keys/keys_test.go +++ b/pkg/keys/keys_test.go @@ -474,7 +474,7 @@ func TestBatchRange(t *testing.T) { Key: roachpb.Key(pair[0]), EndKey: roachpb.Key(pair[1]), }}) } - if rs, err := Range(ba); err != nil { + if rs, err := Range(ba.Requests); err != nil { t.Errorf("%d: %v", i, err) } else if actPair := [2]string{string(rs.Key), string(rs.EndKey)}; !reflect.DeepEqual(actPair, c.exp) { t.Errorf("%d: expected [%q,%q), got [%q,%q)", i, c.exp[0], c.exp[1], actPair[0], actPair[1]) @@ -503,7 +503,7 @@ func TestBatchError(t *testing.T) { ba.Add(&roachpb.ScanRequest{RequestHeader: roachpb.RequestHeader{ Key: roachpb.Key(c.req[0]), EndKey: roachpb.Key(c.req[1]), }}) - if _, err := Range(ba); !testutils.IsError(err, c.errMsg) { + if _, err := Range(ba.Requests); !testutils.IsError(err, c.errMsg) { t.Errorf("%d: unexpected error %v", i, err) } } @@ -513,7 +513,7 @@ func TestBatchError(t *testing.T) { ba.Add(&roachpb.GetRequest{RequestHeader: roachpb.RequestHeader{ Key: roachpb.Key("a"), EndKey: roachpb.Key("b"), }}) - if _, err := Range(ba); !testutils.IsError(err, "end key specified for non-range operation") { + if _, err := Range(ba.Requests); !testutils.IsError(err, "end key specified for non-range operation") { t.Errorf("unexpected error %v", err) } } diff --git a/pkg/kv/dist_sender.go b/pkg/kv/dist_sender.go index b86ea8a9c6dc..a537093dbd89 100644 --- a/pkg/kv/dist_sender.go +++ b/pkg/kv/dist_sender.go @@ -703,7 +703,7 @@ func (ds *DistSender) Send( // Local addressing has already been resolved. // TODO(tschottdorf): consider rudimentary validation of the batch here // (for example, non-range requests with EndKey, or empty key ranges). - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { return nil, roachpb.NewError(err) } @@ -840,7 +840,7 @@ func (ds *DistSender) divideAndSendParallelCommit( // over multiple ranges, so call into divideAndSendBatchToRanges. qiBa := ba qiBa.Requests = swappedReqs[swapIdx+1:] - qiRS, err := keys.Range(qiBa) + qiRS, err := keys.Range(qiBa.Requests) if err != nil { return br, roachpb.NewError(err) } @@ -882,7 +882,7 @@ func (ds *DistSender) divideAndSendParallelCommit( // QueryIntent requests. Make sure to determine the request's // new key span. ba.Requests = swappedReqs[:swapIdx+1] - rs, err = keys.Range(ba) + rs, err = keys.Range(ba.Requests) if err != nil { return nil, roachpb.NewError(err) } diff --git a/pkg/kv/dist_sender_test.go b/pkg/kv/dist_sender_test.go index 1dc215b0d4c4..40bb729c85a3 100644 --- a/pkg/kv/dist_sender_test.go +++ b/pkg/kv/dist_sender_test.go @@ -1114,7 +1114,7 @@ func TestRetryOnWrongReplicaError(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { t.Fatal(err) } @@ -1211,7 +1211,7 @@ func TestRetryOnWrongReplicaErrorWithSuggestion(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { t.Fatal(err) } @@ -1652,7 +1652,7 @@ func TestMultiRangeMergeStaleDescriptor(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { t.Fatal(err) } @@ -1867,7 +1867,7 @@ func TestTruncateWithSpanAndDescriptor(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { t.Fatal(err) } @@ -3264,7 +3264,7 @@ func TestEvictMetaRange(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { t.Fatal(err) } @@ -3431,7 +3431,7 @@ func TestEvictionTokenCoalesce(t *testing.T) { _ ReplicaSlice, ba roachpb.BatchRequest, ) (*roachpb.BatchResponse, error) { - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) br := ba.CreateReply() if err != nil { br.Error = roachpb.NewError(err) diff --git a/pkg/storage/replica.go b/pkg/storage/replica.go index 819ed140c617..0f4480c6a8aa 100644 --- a/pkg/storage/replica.go +++ b/pkg/storage/replica.go @@ -1220,7 +1220,7 @@ func (r *Replica) executeAdminBatch( return nil, roachpb.NewErrorf("only single-element admin batches allowed") } - rSpan, err := keys.Range(ba) + rSpan, err := keys.Range(ba.Requests) if err != nil { return nil, roachpb.NewError(err) } diff --git a/pkg/storage/replica_raft.go b/pkg/storage/replica_raft.go index a563c0acc0f1..90e2a219e6f0 100644 --- a/pkg/storage/replica_raft.go +++ b/pkg/storage/replica_raft.go @@ -84,7 +84,7 @@ func (r *Replica) evalAndPropose( } r.mu.RUnlock() - rSpan, err := keys.Range(ba) + rSpan, err := keys.Range(ba.Requests) if err != nil { return nil, nil, 0, roachpb.NewError(err) } diff --git a/pkg/storage/replica_read.go b/pkg/storage/replica_read.go index 321546466304..47e82005a115 100644 --- a/pkg/storage/replica_read.go +++ b/pkg/storage/replica_read.go @@ -72,7 +72,7 @@ func (r *Replica) executeReadOnlyBatch( return nil, roachpb.NewError(err) } - rSpan, err := keys.Range(ba) + rSpan, err := keys.Range(ba.Requests) if err != nil { return nil, roachpb.NewError(err) } diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index db1b74245b47..9782ef687fe6 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -72,7 +72,7 @@ func (s *Store) TestSender() client.Sender { // If the client hasn't set ba.Range, we do it a favor and figure out the // range to which the request needs to go. // - // NOTE: We don't use keys.Range(ba) here because that does some + // NOTE: We don't use keys.Range(ba.Requests) here because that does some // validation on the batch, and some tests using this sender don't like // that. key, err := keys.Addr(ba.Requests[0].GetInner().Header().Key) @@ -150,7 +150,7 @@ func (db *testSender) Send( return nil, roachpb.NewErrorf("%s method not supported", et.Method()) } // Lookup range and direct request. - rs, err := keys.Range(ba) + rs, err := keys.Range(ba.Requests) if err != nil { return nil, roachpb.NewError(err) }