diff --git a/pkg/storage/batcheval/cmd_range_lookup.go b/pkg/storage/batcheval/cmd_range_lookup.go index 3e74ec208319..71c2104e02ac 100644 --- a/pkg/storage/batcheval/cmd_range_lookup.go +++ b/pkg/storage/batcheval/cmd_range_lookup.go @@ -50,18 +50,20 @@ func declareKeysDeprecatedRangeLookup( // Both forward and reverse RangeLookupRequests scan forward initially. We are // unable to bound this initial scan any further than from the lookup key to // the end of the current descriptor. - scanBounds, err := rangeLookupScanBounds(&desc, key, false /* reverse */) - if err != nil { - // Errors will be caught during evaluation. - return + if !lookupReq.Reverse || key.Less(roachpb.RKey(keys.Meta2KeyMax)) { + scanBounds, err := rangeLookupScanBounds(&desc, key, false /* reverse */) + if err != nil { + // Errors will be caught during evaluation. + return + } + spans.Add(spanset.SpanReadOnly, roachpb.Span{ + Key: scanBounds.Key.AsRawKey(), + EndKey: scanBounds.EndKey.AsRawKey(), + }) } - spans.Add(spanset.SpanReadOnly, roachpb.Span{ - Key: scanBounds.Key.AsRawKey(), - EndKey: scanBounds.EndKey.AsRawKey(), - }) + // A reverse RangeLookupRequest also scans backwards. if lookupReq.Reverse { - // A reverse RangeLookupRequest also scans backwards. revScanBounds, err := rangeLookupScanBounds(&desc, key, true /* reverse */) if err != nil { // Errors will be caught during evaluation. diff --git a/pkg/storage/replica.go b/pkg/storage/replica.go index d764b0cf57e4..3c541e06d964 100644 --- a/pkg/storage/replica.go +++ b/pkg/storage/replica.go @@ -2544,6 +2544,9 @@ func (r *Replica) executeReadOnlyBatch( var result result.Result rec := NewReplicaEvalContext(r, spans) readOnly := r.store.Engine().NewReadOnly() + if util.RaceEnabled { + readOnly = spanset.NewReadWriter(readOnly, spans) + } defer readOnly.Close() br, result, pErr = evaluateBatch(ctx, storagebase.CmdIDKey(""), readOnly, rec, nil, ba) @@ -5272,7 +5275,7 @@ func (r *Replica) evaluateWriteBatchWithLocalRetries( batch.Close() } batch = r.store.Engine().NewBatch() - if util.RaceEnabled && spans != nil { + if util.RaceEnabled { batch = spanset.NewBatch(batch, spans) } br, res, pErr = evaluateBatch(ctx, idKey, batch, rec, ms, ba) diff --git a/pkg/storage/spanset/batch.go b/pkg/storage/spanset/batch.go index 990c39489c59..4737ba35dd8f 100644 --- a/pkg/storage/spanset/batch.go +++ b/pkg/storage/spanset/batch.go @@ -307,6 +307,12 @@ func makeSpanSetReadWriter(rw engine.ReadWriter, spans *SpanSet) spanSetReadWrit } } +// NewReadWriter returns an engine.ReadWriter that asserts access of the +// underlying ReadWriter against the given SpanSet. +func NewReadWriter(rw engine.ReadWriter, spans *SpanSet) engine.ReadWriter { + return makeSpanSetReadWriter(rw, spans) +} + type spanSetBatch struct { spanSetReadWriter b engine.Batch diff --git a/pkg/storage/spanset/spanset.go b/pkg/storage/spanset/spanset.go index c888f4e632f0..d19d2469d915 100644 --- a/pkg/storage/spanset/spanset.go +++ b/pkg/storage/spanset/spanset.go @@ -114,9 +114,6 @@ func (ss *SpanSet) CheckAllowed(access SpanAccess, span roachpb.Span) error { } for ac := access; ac < NumSpanAccess; ac++ { for _, s := range ss.spans[ac][scope] { - if s.Key.Equal(keys.LocalMax) && s.EndKey.Equal(roachpb.KeyMax) { - continue - } if s.Contains(span) { return nil }