@@ -765,9 +765,16 @@ func NewReader(r storage.Reader, spans *SpanSet, ts hlc.Timestamp) storage.Reade
765765 return spanSetReader {r : r , spans : spans , ts : ts }
766766}
767767
768+ // NewReadWriter returns a storage.ReadWriter that asserts access of the
769+ // underlying ReadWriter against the given SpanSet.
770+ //
771+ // NewReadWriter clones and does not retain the provided span set.
772+ func NewReadWriter (rw storage.ReadWriter , spans * SpanSet ) storage.ReadWriter {
773+ return makeSpanSetReadWriter (rw , spans )
774+ }
775+
768776// NewReadWriterAt returns a storage.ReadWriter that asserts access of the
769777// underlying ReadWriter against the given SpanSet at a given timestamp.
770- // If zero timestamp is provided, accesses are considered non-MVCC.
771778//
772779// NewReadWriterAt clones and does not retain the provided span set.
773780func NewReadWriterAt (rw storage.ReadWriter , spans * SpanSet , ts hlc.Timestamp ) storage.ReadWriter {
@@ -877,7 +884,8 @@ func (s spanSetWriteBatch) CommitStats() storage.BatchCommitStats {
877884}
878885
879886type spanSetBatch struct {
880- ReadWriter
887+ spanSetReader
888+ spanSetWriteBatch
881889 b storage.Batch
882890 // TODO(ibrahim): The fields spans, spansOnly, and ts don't seem to be used.
883891 // Consider removing or marking them as intended.
@@ -889,6 +897,12 @@ type spanSetBatch struct {
889897
890898var _ storage.Batch = spanSetBatch {}
891899
900+ // Close implements storage.Batch (resolves ambiguity between Reader.Close
901+ // and WriteBatch.Close).
902+ func (s spanSetBatch ) Close () {
903+ s .wb .Close ()
904+ }
905+
892906func (s spanSetBatch ) NewBatchOnlyMVCCIterator (
893907 ctx context.Context , opts storage.IterOptions ,
894908) (storage.MVCCIterator , error ) {
@@ -902,83 +916,49 @@ func (s spanSetBatch) NewBatchOnlyMVCCIterator(
902916 return NewIteratorAt (mvccIter , s .spans , s .ts ), nil
903917}
904918
905- func (s spanSetBatch ) Commit (sync bool ) error {
906- return s .b .Commit (sync )
907- }
908-
909- func (s spanSetBatch ) CommitNoSyncWait () error {
910- return s .b .CommitNoSyncWait ()
911- }
912-
913- func (s spanSetBatch ) SyncWait () error {
914- return s .b .SyncWait ()
915- }
916-
917- func (s spanSetBatch ) Empty () bool {
918- return s .b .Empty ()
919- }
920-
921- func (s spanSetBatch ) Count () uint32 {
922- return s .b .Count ()
923- }
924-
925- func (s spanSetBatch ) Len () int {
926- return s .b .Len ()
927- }
928-
929- func (s spanSetBatch ) Repr () []byte {
930- return s .b .Repr ()
931- }
932-
933- func (s spanSetBatch ) CommitStats () storage.BatchCommitStats {
934- return s .b .CommitStats ()
935- }
936-
937- func (s spanSetBatch ) PutInternalRangeKey (start , end []byte , key rangekey.Key ) error {
938- return s .b .PutInternalRangeKey (start , end , key )
939- }
940-
941- func (s spanSetBatch ) PutInternalPointKey (key * pebble.InternalKey , value []byte ) error {
942- return s .b .PutInternalPointKey (key , value )
943- }
944-
945- func (s spanSetBatch ) ClearRawEncodedRange (start , end []byte ) error {
946- return s .b .ClearRawEncodedRange (start , end )
947- }
948-
949919// shallowCopy returns a shallow copy of the spanSetBatch. The returned batch
950920// shares the same underlying storage.Batch but has its own spanSetBatch wrapper
951921// with a new copy of the SpanSet that uses a shallow copy of the underlying
952922// spans.
953923func (s spanSetBatch ) shallowCopy () * spanSetBatch {
954924 b := s
955- b .spanSetReader .spans = b .spanSetReader .spans .ShallowCopy ()
956- b .spanSetWriter .spans = b .spanSetWriter .spans .ShallowCopy ()
957925 b .spans = b .spans .ShallowCopy ()
926+ b .spanSetReader .spans = b .spans
927+ b .spanSetWriter .spans = b .spans
958928 return & b
959929}
960930
961931// NewBatch returns a storage.Batch that asserts access of the underlying
962932// Batch against the given SpanSet. We only consider span boundaries, associated
963933// timestamps are not considered.
964934func NewBatch (b storage.Batch , spans * SpanSet ) storage.Batch {
935+ spans = addLockTableSpans (spans )
965936 return & spanSetBatch {
966- ReadWriter : makeSpanSetReadWriter (b , spans ),
967- b : b ,
968- spans : spans ,
969- spansOnly : true ,
937+ spanSetReader : spanSetReader {r : b , spans : spans , spansOnly : true },
938+ spanSetWriteBatch : spanSetWriteBatch {
939+ spanSetWriter : spanSetWriter {w : b , spans : spans , spansOnly : true },
940+ wb : b ,
941+ },
942+ b : b ,
943+ spans : spans ,
944+ spansOnly : true ,
970945 }
971946}
972947
973948// NewBatchAt returns an storage.Batch that asserts access of the underlying
974949// Batch against the given SpanSet at the given timestamp.
975950// If the zero timestamp is used, all accesses are considered non-MVCC.
976951func NewBatchAt (b storage.Batch , spans * SpanSet , ts hlc.Timestamp ) storage.Batch {
952+ spans = addLockTableSpans (spans )
977953 return & spanSetBatch {
978- ReadWriter : makeSpanSetReadWriterAt (b , spans , ts ),
979- b : b ,
980- spans : spans ,
981- ts : ts ,
954+ spanSetReader : spanSetReader {r : b , spans : spans , ts : ts },
955+ spanSetWriteBatch : spanSetWriteBatch {
956+ spanSetWriter : spanSetWriter {w : b , spans : spans , ts : ts },
957+ wb : b ,
958+ },
959+ b : b ,
960+ spans : spans ,
961+ ts : ts ,
982962 }
983963}
984964
@@ -987,9 +967,9 @@ func NewBatchAt(b storage.Batch, spans *SpanSet, ts hlc.Timestamp) storage.Batch
987967func DisableReaderAssertions (reader storage.Reader ) storage.Reader {
988968 switch v := reader .(type ) {
989969 case ReadWriter :
990- return DisableReaderAssertions (v .r )
970+ return DisableReaderAssertions (v .spanSetReader . r )
991971 case * spanSetBatch :
992- return DisableReaderAssertions (v .r )
972+ return DisableReaderAssertions (v .spanSetReader . r )
993973 default :
994974 return reader
995975 }
@@ -1000,9 +980,9 @@ func DisableReaderAssertions(reader storage.Reader) storage.Reader {
1000980func DisableReadWriterAssertions (rw storage.ReadWriter ) storage.ReadWriter {
1001981 switch v := rw .(type ) {
1002982 case ReadWriter :
1003- return DisableReadWriterAssertions (v .w .(storage.ReadWriter ))
983+ return DisableReadWriterAssertions (v .spanSetWriter . w .(storage.ReadWriter ))
1004984 case * spanSetBatch :
1005- return DisableReadWriterAssertions (v .w .(storage.ReadWriter ))
985+ return DisableReadWriterAssertions (v .spanSetWriteBatch . spanSetWriter . w .(storage.ReadWriter ))
1006986 default :
1007987 return rw
1008988 }
@@ -1016,10 +996,8 @@ func DisableUndeclaredSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
1016996 switch v := rw .(type ) {
1017997 case * spanSetBatch :
1018998 newSnapSetBatch := v .shallowCopy ()
1019- newSnapSetBatch .spanSetReader .spans .DisableUndeclaredAccessAssertions ()
1020- newSnapSetBatch .spanSetWriter .spans .DisableUndeclaredAccessAssertions ()
999+ newSnapSetBatch .spans .DisableUndeclaredAccessAssertions ()
10211000 return newSnapSetBatch
1022-
10231001 default :
10241002 return rw
10251003 }
@@ -1035,10 +1013,8 @@ func DisableForbiddenSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
10351013 switch v := rw .(type ) {
10361014 case * spanSetBatch :
10371015 newSnapSetBatch := v .shallowCopy ()
1038- newSnapSetBatch .spanSetReader .spans .DisableForbiddenSpansAssertions ()
1039- newSnapSetBatch .spanSetWriter .spans .DisableForbiddenSpansAssertions ()
1016+ newSnapSetBatch .spans .DisableForbiddenSpansAssertions ()
10401017 return newSnapSetBatch
1041-
10421018 default :
10431019 return rw
10441020 }
0 commit comments