@@ -23,8 +23,8 @@ import (
2323// MVCCIterator wraps an storage.MVCCIterator and ensures that it can
2424// only be used to access spans in a SpanSet.
2525type MVCCIterator struct {
26- i storage.MVCCIterator
27- spans * SpanSet
26+ i storage.MVCCIterator
27+ checker * SpanChecker
2828
2929 // spansOnly controls whether or not timestamps associated with the
3030 // spans are considered when ensuring access. If set to true,
@@ -48,13 +48,13 @@ var _ storage.MVCCIterator = &MVCCIterator{}
4848// iterator against the given SpanSet. Timestamps associated with the spans
4949// in the spanset are not considered, only the span boundaries are checked.
5050func NewIterator (iter storage.MVCCIterator , spans * SpanSet ) * MVCCIterator {
51- return & MVCCIterator {i : iter , spans : spans , spansOnly : true }
51+ return & MVCCIterator {i : iter , checker : NewSpanChecker ( spans ) , spansOnly : true }
5252}
5353
5454// NewIteratorAt constructs an iterator that verifies access of the underlying
5555// iterator against the given SpanSet at the given timestamp.
5656func NewIteratorAt (iter storage.MVCCIterator , spans * SpanSet , ts hlc.Timestamp ) * MVCCIterator {
57- return & MVCCIterator {i : iter , spans : spans , ts : ts }
57+ return & MVCCIterator {i : iter , checker : NewSpanChecker ( spans ) , ts : ts }
5858}
5959
6060// Close is part of the storage.MVCCIterator interface.
@@ -137,9 +137,9 @@ func (i *MVCCIterator) checkAllowed(span roachpb.Span, errIfDisallowed bool) {
137137func (i * MVCCIterator ) checkAllowedValidPos (span roachpb.Span , errIfDisallowed bool ) {
138138 var err error
139139 if i .spansOnly {
140- err = i .spans .CheckAllowed (SpanReadOnly , span )
140+ err = i .checker .CheckAllowed (SpanReadOnly , span )
141141 } else {
142- err = i .spans .CheckAllowedAt (SpanReadOnly , span , i .ts )
142+ err = i .checker .CheckAllowedAt (SpanReadOnly , span , i .ts )
143143 }
144144 if errIfDisallowed {
145145 i .err = err
@@ -213,11 +213,11 @@ func (i *MVCCIterator) FindSplitKey(
213213 start , end , minSplitKey roachpb.Key , targetSize int64 ,
214214) (storage.MVCCKey , error ) {
215215 if i .spansOnly {
216- if err := i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }); err != nil {
216+ if err := i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }); err != nil {
217217 return storage.MVCCKey {}, err
218218 }
219219 } else {
220- if err := i .spans .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }, i .ts ); err != nil {
220+ if err := i .checker .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }, i .ts ); err != nil {
221221 return storage.MVCCKey {}, err
222222 }
223223 }
@@ -242,8 +242,9 @@ func (i *MVCCIterator) UnsafeLazyValue() pebble.LazyValue {
242242// EngineIterator wraps a storage.EngineIterator and ensures that it can
243243// only be used to access spans in a SpanSet.
244244type EngineIterator struct {
245- i storage.EngineIterator
246- spans * SpanSet
245+ i storage.EngineIterator
246+ //spans *SpanSet
247+ checker * SpanChecker
247248 spansOnly bool
248249 ts hlc.Timestamp
249250}
@@ -261,10 +262,10 @@ func (i *EngineIterator) SeekEngineKeyGE(key storage.EngineKey) (valid bool, err
261262 }
262263 if key .IsMVCCKey () && ! i .spansOnly {
263264 mvccKey , _ := key .ToMVCCKey ()
264- if err := i .spans .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
265+ if err := i .checker .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
265266 return false , err
266267 }
267- } else if err = i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
268+ } else if err = i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
268269 return false , err
269270 }
270271 return valid , err
@@ -278,10 +279,10 @@ func (i *EngineIterator) SeekEngineKeyLT(key storage.EngineKey) (valid bool, err
278279 }
279280 if key .IsMVCCKey () && ! i .spansOnly {
280281 mvccKey , _ := key .ToMVCCKey ()
281- if err := i .spans .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
282+ if err := i .checker .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
282283 return false , err
283284 }
284- } else if err = i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {EndKey : key .Key }); err != nil {
285+ } else if err = i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {EndKey : key .Key }); err != nil {
285286 return false , err
286287 }
287288 return valid , err
@@ -313,7 +314,7 @@ func (i *EngineIterator) SeekEngineKeyGEWithLimit(
313314 if state != pebble .IterValid {
314315 return state , err
315316 }
316- if err = i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
317+ if err = i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
317318 return pebble .IterExhausted , err
318319 }
319320 return state , err
@@ -327,7 +328,7 @@ func (i *EngineIterator) SeekEngineKeyLTWithLimit(
327328 if state != pebble .IterValid {
328329 return state , err
329330 }
330- if err = i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {EndKey : key .Key }); err != nil {
331+ if err = i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {EndKey : key .Key }); err != nil {
331332 return pebble .IterExhausted , err
332333 }
333334 return state , err
@@ -354,11 +355,11 @@ func (i *EngineIterator) checkKeyAllowed() (valid bool, err error) {
354355 }
355356 if key .IsMVCCKey () && ! i .spansOnly {
356357 mvccKey , _ := key .ToMVCCKey ()
357- if err := i .spans .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
358+ if err := i .checker .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : mvccKey .Key }, i .ts ); err != nil {
358359 // Invalid, but no error.
359360 return false , nil // nolint:returnerrcheck
360361 }
361- } else if err = i .spans .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
362+ } else if err = i .checker .CheckAllowed (SpanReadOnly , roachpb.Span {Key : key .Key }); err != nil {
362363 // Invalid, but no error.
363364 return false , nil // nolint:returnerrcheck
364365 }
@@ -431,8 +432,8 @@ func (i *EngineIterator) Stats() storage.IteratorStats {
431432}
432433
433434type spanSetReader struct {
434- r storage.Reader
435- spans * SpanSet
435+ r storage.Reader
436+ checker * SpanChecker
436437
437438 spansOnly bool
438439 ts hlc.Timestamp
@@ -469,11 +470,11 @@ func (s spanSetReader) MVCCIterate(
469470 f func (storage.MVCCKeyValue , storage.MVCCRangeKeyStack ) error ,
470471) error {
471472 if s .spansOnly {
472- if err := s .spans .CheckAllowed (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }); err != nil {
473+ if err := s .checker .CheckAllowed (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }); err != nil {
473474 return err
474475 }
475476 } else {
476- if err := s .spans .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }, s .ts ); err != nil {
477+ if err := s .checker .CheckAllowedAt (SpanReadOnly , roachpb.Span {Key : start , EndKey : end }, s .ts ); err != nil {
477478 return err
478479 }
479480 }
@@ -488,9 +489,9 @@ func (s spanSetReader) NewMVCCIterator(
488489 return nil , err
489490 }
490491 if s .spansOnly {
491- return NewIterator (mvccIter , s .spans ), nil
492+ return NewIterator (mvccIter , s .checker . spans ), nil
492493 }
493- return NewIteratorAt (mvccIter , s .spans , s .ts ), nil
494+ return NewIteratorAt (mvccIter , s .checker . spans , s .ts ), nil
494495}
495496
496497func (s spanSetReader ) NewEngineIterator (
@@ -501,8 +502,9 @@ func (s spanSetReader) NewEngineIterator(
501502 return nil , err
502503 }
503504 return & EngineIterator {
504- i : engineIter ,
505- spans : s .spans ,
505+ i : engineIter ,
506+ //spans: s.checker.spans,
507+ checker : s .checker ,
506508 spansOnly : s .spansOnly ,
507509 ts : s .ts ,
508510 }, nil
@@ -519,8 +521,8 @@ func (s spanSetReader) PinEngineStateForIterators(readCategory fs.ReadCategory)
519521}
520522
521523type spanSetWriter struct {
522- w storage.Writer
523- spans * SpanSet
524+ w storage.Writer
525+ checker * SpanChecker
524526
525527 spansOnly bool
526528 ts hlc.Timestamp
@@ -535,11 +537,11 @@ func (s spanSetWriter) ApplyBatchRepr(repr []byte, sync bool) error {
535537
536538func (s spanSetWriter ) checkAllowed (key roachpb.Key ) error {
537539 if s .spansOnly {
538- if err := s .spans .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key }); err != nil {
540+ if err := s .checker .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key }); err != nil {
539541 return err
540542 }
541543 } else {
542- if err := s .spans .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : key }, s .ts ); err != nil {
544+ if err := s .checker .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : key }, s .ts ); err != nil {
543545 return err
544546 }
545547 }
@@ -561,7 +563,7 @@ func (s spanSetWriter) ClearUnversioned(key roachpb.Key, opts storage.ClearOptio
561563}
562564
563565func (s spanSetWriter ) ClearEngineKey (key storage.EngineKey , opts storage.ClearOptions ) error {
564- if err := s .spans .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
566+ if err := s .checker .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
565567 return err
566568 }
567569 return s .w .ClearEngineKey (key , opts )
@@ -575,11 +577,11 @@ func (s spanSetWriter) SingleClearEngineKey(key storage.EngineKey) error {
575577
576578func (s spanSetWriter ) checkAllowedRange (start , end roachpb.Key ) error {
577579 if s .spansOnly {
578- if err := s .spans .CheckAllowed (SpanReadWrite , roachpb.Span {Key : start , EndKey : end }); err != nil {
580+ if err := s .checker .CheckAllowed (SpanReadWrite , roachpb.Span {Key : start , EndKey : end }); err != nil {
579581 return err
580582 }
581583 } else {
582- if err := s .spans .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : start , EndKey : end }, s .ts ); err != nil {
584+ if err := s .checker .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : start , EndKey : end }, s .ts ); err != nil {
583585 return err
584586 }
585587 }
@@ -661,11 +663,11 @@ func (s spanSetWriter) ClearMVCCRangeKey(rangeKey storage.MVCCRangeKey) error {
661663
662664func (s spanSetWriter ) Merge (key storage.MVCCKey , value []byte ) error {
663665 if s .spansOnly {
664- if err := s .spans .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
666+ if err := s .checker .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
665667 return err
666668 }
667669 } else {
668- if err := s .spans .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : key .Key }, s .ts ); err != nil {
670+ if err := s .checker .CheckAllowedAt (SpanReadWrite , roachpb.Span {Key : key .Key }, s .ts ); err != nil {
669671 return err
670672 }
671673 }
@@ -697,7 +699,7 @@ func (s spanSetWriter) PutEngineKey(key storage.EngineKey, value []byte) error {
697699 if ! s .spansOnly {
698700 panic ("cannot do timestamp checking for putting EngineKey" )
699701 }
700- if err := s .spans .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
702+ if err := s .checker .CheckAllowed (SpanReadWrite , roachpb.Span {Key : key .Key }); err != nil {
701703 return err
702704 }
703705 return s .w .PutEngineKey (key , value )
@@ -731,17 +733,19 @@ var _ storage.ReadWriter = ReadWriter{}
731733
732734func makeSpanSetReadWriter (rw storage.ReadWriter , spans * SpanSet ) ReadWriter {
733735 spans = addLockTableSpans (spans )
736+ checker := NewSpanChecker (spans )
734737 return ReadWriter {
735- spanSetReader : spanSetReader {r : rw , spans : spans , spansOnly : true },
736- spanSetWriter : spanSetWriter {w : rw , spans : spans , spansOnly : true },
738+ spanSetReader : spanSetReader {r : rw , checker : checker , spansOnly : true },
739+ spanSetWriter : spanSetWriter {w : rw , checker : checker , spansOnly : true },
737740 }
738741}
739742
740743func makeSpanSetReadWriterAt (rw storage.ReadWriter , spans * SpanSet , ts hlc.Timestamp ) ReadWriter {
741744 spans = addLockTableSpans (spans )
745+ checker := NewSpanChecker (spans )
742746 return ReadWriter {
743- spanSetReader : spanSetReader {r : rw , spans : spans , ts : ts },
744- spanSetWriter : spanSetWriter {w : rw , spans : spans , ts : ts },
747+ spanSetReader : spanSetReader {r : rw , checker : checker , ts : ts },
748+ spanSetWriter : spanSetWriter {w : rw , checker : checker , ts : ts },
745749 }
746750}
747751
@@ -752,7 +756,7 @@ func makeSpanSetReadWriterAt(rw storage.ReadWriter, spans *SpanSet, ts hlc.Times
752756// NewReader clones and does not retain the provided span set.
753757func NewReader (r storage.Reader , spans * SpanSet , ts hlc.Timestamp ) storage.Reader {
754758 spans = addLockTableSpans (spans )
755- return spanSetReader {r : r , spans : spans , ts : ts }
759+ return spanSetReader {r : r , checker : NewSpanChecker ( spans ) , ts : ts }
756760}
757761
758762// NewReadWriterAt returns a storage.ReadWriter that asserts access of the
0 commit comments