Skip to content

Commit 72a6384

Browse files
committed
spanset: recursively disable spanset assertions
This commit changes the way we disable spanset assertionsby doing it recursively. This is because the SpansetBatch follows the decorator design pattern, and allows for multiple wrappers on top of each other. Note that the same recursive disabling was already happening in: DisableReadWriterAssertions and DisableReaderAssertions functions. Also, this commit adds DisableWriterAssertions so that we have the functions for reader, writer, and readwriter.
1 parent 62fe51a commit 72a6384

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pkg/kv/kvserver/spanset/batch.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,19 @@ func DisableReaderAssertions(reader storage.Reader) storage.Reader {
975975
}
976976
}
977977

978+
// DisableWriterAssertions unwraps any storage.Writer implementations that may
979+
// assert access against a given SpanSet.
980+
func DisableWriterAssertions(writer storage.Writer) storage.Writer {
981+
switch v := writer.(type) {
982+
case spanSetWriter:
983+
return DisableWriterAssertions(v.w)
984+
case *spanSetBatch:
985+
return DisableWriterAssertions(v.spanSetWriter.w)
986+
default:
987+
return writer
988+
}
989+
}
990+
978991
// DisableReadWriterAssertions unwraps any storage.ReadWriter implementations
979992
// that may assert access against a given SpanSet.
980993
func DisableReadWriterAssertions(rw storage.ReadWriter) storage.ReadWriter {
@@ -994,10 +1007,24 @@ func DisableReadWriterAssertions(rw storage.ReadWriter) storage.ReadWriter {
9941007
// wrapper with the latch assertion disabled.
9951008
func DisableUndeclaredSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
9961009
switch v := rw.(type) {
1010+
case *storage.OpLoggerBatch:
1011+
// OpLoggerBatch embeds a storage.Batch.
1012+
result := DisableUndeclaredSpanAssertions(v.Batch)
1013+
return result
1014+
9971015
case *spanSetBatch:
9981016
newSnapSetBatch := v.shallowCopy()
9991017
newSnapSetBatch.spans.DisableUndeclaredAccessAssertions()
1018+
1019+
// Recursively disable on the underlying batch in case there are
1020+
// nested spanSetBatches.
1021+
newSnapSetBatch.b = DisableUndeclaredSpanAssertions(v.b).(storage.Batch)
1022+
// Update the reader and writer to point to the recursively processed batch.
1023+
newSnapSetBatch.spanSetReader.r = newSnapSetBatch.b
1024+
newSnapSetBatch.spanSetWriteBatch.spanSetWriter.w = newSnapSetBatch.b
1025+
newSnapSetBatch.spanSetWriteBatch.wb = newSnapSetBatch.b
10001026
return newSnapSetBatch
1027+
10011028
default:
10021029
return rw
10031030
}
@@ -1011,10 +1038,24 @@ func DisableUndeclaredSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
10111038
// function.
10121039
func DisableForbiddenSpanAssertions(rw storage.ReadWriter) storage.ReadWriter {
10131040
switch v := rw.(type) {
1041+
case *storage.OpLoggerBatch:
1042+
// OpLoggerBatch embeds a storage.Batch.
1043+
result := DisableForbiddenSpanAssertions(v.Batch)
1044+
return result
1045+
10141046
case *spanSetBatch:
10151047
newSnapSetBatch := v.shallowCopy()
10161048
newSnapSetBatch.spans.DisableForbiddenSpansAssertions()
1049+
1050+
// Recursively disable on the underlying batch in case there are
1051+
// nested spanSetBatches.
1052+
newSnapSetBatch.b = DisableForbiddenSpanAssertions(v.b).(storage.Batch)
1053+
// Update the reader and writer to point to the recursively processed batch.
1054+
newSnapSetBatch.spanSetReader.r = newSnapSetBatch.b
1055+
newSnapSetBatch.spanSetWriteBatch.spanSetWriter.w = newSnapSetBatch.b
1056+
newSnapSetBatch.spanSetWriteBatch.wb = newSnapSetBatch.b
10171057
return newSnapSetBatch
1058+
10181059
default:
10191060
return rw
10201061
}

0 commit comments

Comments
 (0)