Skip to content

Commit

Permalink
colblk: misc index block tweaks
Browse files Browse the repository at this point in the history
Add block properties column to IndexReader. Remove the numColumns field from
IndexBlockWriter as index blocks now always have a static number of columns.
  • Loading branch information
jbowens committed Aug 30, 2024
1 parent 5294f89 commit d6b21ae
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions sstable/colblk/index_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type IndexBlockWriter struct {
offsets UintBuilder
lengths UintBuilder
blockProperties RawBytesBuilder
numColumns int
rows int
enc blockEncoder
}
Expand All @@ -56,7 +55,6 @@ func (w *IndexBlockWriter) Init(blockProperties ...ColumnWriter) {
w.separators.Init()
w.offsets.Init()
w.lengths.InitWithDefault()
w.numColumns = indexBlockColumnCount
w.blockProperties.Init()
w.rows = 0
}
Expand All @@ -72,8 +70,7 @@ func (w *IndexBlockWriter) Reset() {
}

// AddBlockHandle adds a new separator and end offset of a data block to the
// index block. Add returns the index of the row. The caller should add rows to
// the block properties columns too if necessary.
// index block. Add returns the index of the row.
//
// AddBlockHandle should only be used for first-level index blocks.
func (w *IndexBlockWriter) AddBlockHandle(
Expand All @@ -90,7 +87,7 @@ func (w *IndexBlockWriter) AddBlockHandle(

// Size returns the size of the pending index block.
func (w *IndexBlockWriter) Size() int {
off := blockHeaderSize(w.numColumns, indexBlockCustomHeaderSize)
off := blockHeaderSize(indexBlockColumnCount, indexBlockCustomHeaderSize)
off = w.separators.Size(w.rows, off)
off = w.offsets.Size(w.rows, off)
off = w.lengths.Size(w.rows, off)
Expand All @@ -103,7 +100,7 @@ func (w *IndexBlockWriter) Size() int {
func (w *IndexBlockWriter) Finish() []byte {
w.enc.init(w.Size(), Header{
Version: Version1,
Columns: uint16(w.numColumns),
Columns: indexBlockColumnCount,
Rows: uint32(w.rows),
}, indexBlockCustomHeaderSize)
w.enc.encode(w.rows, &w.separators)
Expand All @@ -118,6 +115,7 @@ type IndexReader struct {
separators RawBytes
offsets UnsafeUints
lengths UnsafeUints // only used for second-level index blocks
blockProps RawBytes
br BlockReader
}

Expand All @@ -127,6 +125,7 @@ func (r *IndexReader) Init(data []byte) {
r.separators = r.br.RawBytes(indexBlockColumnSeparator)
r.offsets = r.br.Uints(indexBlockColumnOffsets)
r.lengths = r.br.Uints(indexBlockColumnLengths)
r.blockProps = r.br.RawBytes(indexBlockColumnBlockProperties)
}

// DebugString prints a human-readable explanation of the keyspan block's binary
Expand Down Expand Up @@ -232,7 +231,7 @@ func (i *IndexIter) BlockHandleWithProperties() (block.HandleWithProperties, err
Offset: i.r.offsets.At(i.row),
Length: i.r.lengths.At(i.row),
},
Props: i.r.br.RawBytes(indexBlockColumnBlockProperties).At(i.row),
Props: i.r.blockProps.At(i.row),
}, nil
}

Expand Down

0 comments on commit d6b21ae

Please sign in to comment.