Skip to content

Commit

Permalink
colblk: don't require the header size for KeySchemaHeader
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
RaduBerinde committed Oct 23, 2024
1 parent 6cca117 commit 8e36a20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion internal/crdbtest/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions sstable/colblk/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8e36a20

Please sign in to comment.