From 7d189da4df651e00a42398ee53ca4d1a2dbc5a82 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Tue, 22 Oct 2024 16:49:43 -0700 Subject: [PATCH] colblk: don't require the header size for KeySchemaHeader `KeySchemaHeader` returns the header that was written instead of relying on the caller to provide the correct size. This makes things less error-prone and also allows for extending the header while allowing backward compatibility. --- internal/crdbtest/crdb.go | 6 +++++- sstable/colblk/data_block.go | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/crdbtest/crdb.go b/internal/crdbtest/crdb.go index 2f594fe7b5..4c0511550a 100644 --- a/internal/crdbtest/crdb.go +++ b/internal/crdbtest/crdb.go @@ -633,7 +633,11 @@ func (ks *cockroachKeySeeker) init(d *colblk.DataBlockDecoder) { ks.mvccWallTimes = bd.Uints(cockroachColMVCCWallTime) ks.mvccLogical = bd.Uints(cockroachColMVCCLogical) ks.untypedVersions = bd.RawBytes(cockroachColUntypedVersion) - ks.suffixTypes = suffixTypes(d.KeySchemaHeader(1)[0]) + header := d.KeySchemaHeader() + if len(header) != 1 { + panic(errors.AssertionFailedf("invalid key schema-specific header %x", header)) + } + ks.suffixTypes = suffixTypes(header[0]) } // IsLowerBound is part of the KeySeeker interface. diff --git a/sstable/colblk/data_block.go b/sstable/colblk/data_block.go index 550e600cae..c6a245ddf1 100644 --- a/sstable/colblk/data_block.go +++ b/sstable/colblk/data_block.go @@ -874,9 +874,9 @@ func (d *DataBlockDecoder) PrefixChanged() Bitmap { return d.prefixChanged } -// KeySchemaHeader returns the KeySchema-specific header of fixed size. -func (d *DataBlockDecoder) KeySchemaHeader(schemaHeaderSize uint32) []byte { - return d.d.data[:schemaHeaderSize] +// KeySchemaHeader returns the KeySchema-specific header. +func (d *DataBlockDecoder) KeySchemaHeader() []byte { + return d.d.data[:d.d.customHeaderSize-dataBlockCustomHeaderSize] } // Init initializes the data block reader with the given serialized data block.