@@ -964,6 +964,9 @@ func NewBatchAt(b storage.Batch, spans *SpanSet, ts hlc.Timestamp) storage.Batch
964964
965965// DisableReaderAssertions unwraps any storage.Reader implementations that may
966966// assert access against a given SpanSet.
967+ // TODO(ibrahim): Eventually we want to eliminate all the users of these generic
968+ // disable functions, and use the specific disable functions
969+ // (DisableUndeclaredSpanAssertions or DisableForbiddenSpanAssertions).
967970func DisableReaderAssertions (reader storage.Reader ) storage.Reader {
968971 switch v := reader .(type ) {
969972 case ReadWriter :
@@ -975,10 +978,32 @@ func DisableReaderAssertions(reader storage.Reader) storage.Reader {
975978 }
976979}
977980
981+ // DisableWriterAssertions unwraps any storage.Writer implementations that may
982+ // assert access against a given SpanSet.
983+ // TODO(ibrahim): Eventually we want to eliminate all the users of these generic
984+ // disable functions, and use the specific disable functions
985+ // (DisableUndeclaredSpanAssertions or DisableForbiddenSpanAssertions).
986+ func DisableWriterAssertions (writer storage.Writer ) storage.Writer {
987+ switch v := writer .(type ) {
988+ case spanSetWriter :
989+ return DisableWriterAssertions (v .w )
990+ case * spanSetWriteBatch :
991+ return DisableWriterAssertions (v .spanSetWriter .w )
992+ case * spanSetBatch :
993+ return DisableWriterAssertions (v .spanSetWriter .w )
994+ default :
995+ return writer
996+ }
997+ }
998+
978999// DisableReadWriterAssertions unwraps any storage.ReadWriter implementations
9791000// that may assert access against a given SpanSet.
1001+ // TODO(ibrahim): Eventually we want to eliminate all the users of these generic
1002+ // disable functions, and use the specific disable functions
1003+ // (DisableUndeclaredSpanAssertions or DisableForbiddenSpanAssertions).
9801004func DisableReadWriterAssertions (rw storage.ReadWriter ) storage.ReadWriter {
9811005 switch v := rw .(type ) {
1006+ // TODO(ibrahim): fix the case where one case is a pointer and the other is not.
9821007 case ReadWriter :
9831008 return DisableReadWriterAssertions (v .spanSetWriter .w .(storage.ReadWriter ))
9841009 case * spanSetBatch :
@@ -995,9 +1020,18 @@ func DisableReadWriterAssertions(rw storage.ReadWriter) storage.ReadWriter {
9951020func DisableUndeclaredSpanAssertions (rw storage.ReadWriter ) storage.ReadWriter {
9961021 switch v := rw .(type ) {
9971022 case * spanSetBatch :
998- newSnapSetBatch := v .shallowCopy ()
999- newSnapSetBatch .spans .DisableUndeclaredAccessAssertions ()
1000- return newSnapSetBatch
1023+ newSpanSetBatch := v .shallowCopy ()
1024+ newSpanSetBatch .spans .DisableUndeclaredAccessAssertions ()
1025+
1026+ // Recursively disable on the underlying batch in case there are
1027+ // nested spanSetBatches.
1028+ newSpanSetBatch .b = DisableUndeclaredSpanAssertions (v .b ).(storage.Batch )
1029+ // Update the reader and writer to point to the recursively processed batch.
1030+ newSpanSetBatch .spanSetReader .r = newSpanSetBatch .b
1031+ newSpanSetBatch .spanSetWriteBatch .spanSetWriter .w = newSpanSetBatch .b
1032+ newSpanSetBatch .spanSetWriteBatch .wb = newSpanSetBatch .b
1033+ return newSpanSetBatch
1034+
10011035 default :
10021036 return rw
10031037 }
@@ -1011,10 +1045,27 @@ func DisableUndeclaredSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
10111045// function.
10121046func DisableForbiddenSpanAssertions (rw storage.ReadWriter ) storage.ReadWriter {
10131047 switch v := rw .(type ) {
1048+ // TODO(ibrahim): We eventually want to remove OpLoggerBatch from this switch
1049+ // case.
1050+ case * storage.OpLoggerBatch :
1051+ // OpLoggerBatch embeds a storage.Batch. Recursively process the inner
1052+ // batch and wrap it back in an OpLoggerBatch to preserve the chain.
1053+ innerBatch := DisableForbiddenSpanAssertions (v .Batch ).(storage.Batch )
1054+ return v .ShallowCopyWithBatch (innerBatch )
1055+
10141056 case * spanSetBatch :
1015- newSnapSetBatch := v .shallowCopy ()
1016- newSnapSetBatch .spans .DisableForbiddenSpansAssertions ()
1017- return newSnapSetBatch
1057+ newSpanSetBatch := v .shallowCopy ()
1058+ newSpanSetBatch .spans .DisableForbiddenSpansAssertions ()
1059+
1060+ // Recursively disable on the underlying batch in case there are
1061+ // nested spanSetBatches.
1062+ newSpanSetBatch .b = DisableForbiddenSpanAssertions (v .b ).(storage.Batch )
1063+ // Update the reader and writer to point to the recursively processed batch.
1064+ newSpanSetBatch .spanSetReader .r = newSpanSetBatch .b
1065+ newSpanSetBatch .spanSetWriteBatch .spanSetWriter .w = newSpanSetBatch .b
1066+ newSpanSetBatch .spanSetWriteBatch .wb = newSpanSetBatch .b
1067+ return newSpanSetBatch
1068+
10181069 default :
10191070 return rw
10201071 }
0 commit comments