Skip to content

Commit

Permalink
colblk: expose block reader Describe methods
Browse files Browse the repository at this point in the history
Expose Describe methods from the IndexBlockReader, DataBlockReader and
KeyspanReader types allowing a caller to write a description of the binary
representation of the block to a binfmt.Formatter.

Additionally, ensure we format the trailing 0x00 block padding byte.
  • Loading branch information
jbowens committed Sep 9, 2024
1 parent 376d455 commit 934a223
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sstable/colblk/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,16 @@ func (r *DataBlockReader) Init(schema KeySchema, data []byte) {
r.maximumKeyLength = binary.LittleEndian.Uint32(data[:dataBlockCustomHeaderSize])
}

func (r *DataBlockReader) toFormatter(f *binfmt.Formatter) {
// Describe descirbes the binary format of the data block, assuming f.Offset()
// is positioned at the beginning of the same data block described by r.
func (r *DataBlockReader) Describe(f *binfmt.Formatter) {
f.CommentLine("data block header")
f.HexBytesln(4, "maximum key length: %d", r.maximumKeyLength)
r.r.headerToBinFormatter(f)
for i := 0; i < int(r.r.header.Columns); i++ {
r.r.columnToBinFormatter(f, i, int(r.r.header.Rows))
}
f.HexBytesln(1, "block padding byte")
}

// DataBlockIter iterates over a columnar data block.
Expand Down
2 changes: 1 addition & 1 deletion sstable/colblk/data_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestDataBlock(t *testing.T) {
block := w.Finish()
r.Init(testKeysSchema, block)
f := binfmt.New(r.r.data).LineWidth(20)
r.toFormatter(f)
r.Describe(f)

return f.String()
case "iter":
Expand Down
9 changes: 8 additions & 1 deletion sstable/colblk/index_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,19 @@ func (r *IndexReader) Init(data []byte) {
// representation.
func (r *IndexReader) DebugString() string {
f := binfmt.New(r.br.data).LineWidth(20)
r.Describe(f)
return f.String()
}

// Describe describes the binary format of the index block, assuming f.Offset()
// is positioned at the beginning of the same index block described by r.
func (r *IndexReader) Describe(f *binfmt.Formatter) {
f.CommentLine("index block header")
r.br.headerToBinFormatter(f)
for i := 0; i < indexBlockColumnCount; i++ {
r.br.columnToBinFormatter(f, i, int(r.br.header.Rows))
}
return f.String()
f.HexBytesln(1, "block padding byte")
}

// IndexIter is an iterator over the block entries in an index block.
Expand Down
10 changes: 9 additions & 1 deletion sstable/colblk/keyspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ func (r *KeyspanReader) Init(data []byte) {
// representation.
func (r *KeyspanReader) DebugString() string {
f := binfmt.New(r.blockReader.data).LineWidth(20)
r.Describe(f)
return f.String()
}

// Describe describes the binary format of the keyspan block, assuming
// f.Offset() is positioned at the beginning of the same keyspan block described
// by r.
func (r *KeyspanReader) Describe(f *binfmt.Formatter) {
f.CommentLine("keyspan block header")
f.HexBytesln(4, "user key count: %d", r.boundaryKeysCount)
r.blockReader.headerToBinFormatter(f)
Expand All @@ -246,7 +254,7 @@ func (r *KeyspanReader) DebugString() string {
}
r.blockReader.columnToBinFormatter(f, i, rows)
}
return f.String()
f.HexBytesln(1, "block padding byte")
}

// searchBoundaryKeys returns the index of the first boundary key greater than
Expand Down
1 change: 1 addition & 0 deletions sstable/colblk/testdata/data_block/bundle_search
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ finish
717-718: x 76 # data[65]: v
# data for column 5
718-719: x 01 # bitmap encoding
719-720: x 00 # block padding byte

iter
seek-ge backache
Expand Down
1 change: 1 addition & 0 deletions sstable/colblk/testdata/data_block/external_value
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ finish
623-624: x 00 # bitmap encoding
624-632: b 1100111011111011000001110000000000000000000000000000000000000000 # bitmap word 0
632-640: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63
640-641: x 00 # block padding byte

# Scan across the block using next.
iter
Expand Down
1 change: 1 addition & 0 deletions sstable/colblk/testdata/data_block/next_prefix
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ finish
406-406: x # data[19]:
# data for column 5
406-407: x 01 # bitmap encoding
407-408: x 00 # block padding byte

# Scan across the block using next prefix.

Expand Down
2 changes: 2 additions & 0 deletions sstable/colblk/testdata/data_block/simple
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ finish
167-167: x # data[6]:
# data for column 5
167-168: x 01 # bitmap encoding
168-169: x 00 # block padding byte

iter
first
Expand Down Expand Up @@ -484,6 +485,7 @@ finish
331-332: x 61 # data[16]: a
# data for column 5
332-333: x 01 # bitmap encoding
333-334: x 00 # block padding byte

iter
seek-ge aaa
Expand Down
2 changes: 2 additions & 0 deletions sstable/colblk/testdata/index_block
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ UnsafeSeparator(Rows()-1) = "bonifide"
121-121: x # data[3]:
121-124: x 627035 # data[4]: bp5
124-127: x 627036 # data[5]: bp6
127-128: x 00 # block padding byte

iter
seek-ge zoo
Expand Down Expand Up @@ -193,6 +194,7 @@ UnsafeSeparator(Rows()-1) = "coat"
114-114: x # data[2]:
114-117: x 627034 # data[3]: bp4
117-117: x # data[4]:
117-118: x 00 # block padding byte

iter
first
Expand Down
3 changes: 3 additions & 0 deletions sstable/colblk/testdata/keyspan_block
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Boundaries: a#0,RANGEDEL — e#inf,RANGEDEL
72-72: x # data[4]:
72-72: x # data[5]:
72-72: x # data[6]:
72-73: x 00 # block padding byte

# Test iterating over the block's spans.

Expand Down Expand Up @@ -277,6 +278,7 @@ Boundaries: b#4,RANGEKEYSET — d#inf,RANGEKEYSET
61-62: x 07 # data[1] = 7 [69 overall]
# data
62-69: x 636f636f6e7574 # data[0]: coconut
69-70: x 00 # block padding byte

iter
seek-ge a
Expand Down Expand Up @@ -374,6 +376,7 @@ Boundaries: b#4,RANGEKEYSET — g#inf,RANGEKEYSET
# data
68-75: x 636f636f6e7574 # data[0]: coconut
75-79: x 74726565 # data[1]: tree
79-80: x 00 # block padding byte

iter
seek-ge dog
Expand Down

0 comments on commit 934a223

Please sign in to comment.