Skip to content

Commit a80a801

Browse files
committed
sstable: clean up and document maximum handle lengths
This commit removes the +1 from valblk.HandleMaxLen. The code treats the handle as the data after the valuePrefix byte, noninclusive of the byte. The assertion that blockHandleLikelyMaxLen is large enough now incorporates the +1 of the valuePrefix byte explicitly. This was the only usage the depended on HandleMaxLen being inclusive of the valuePrefix byte. Additionally, this commit documents blockHandleMaxLenWithoutProperties and adds an assertion that blockHandleLikelyMaxLen is larger than the length of an inline blob value handle (blob.MaxInlineHandleLength) plus the valuePrefix byte.
1 parent 4e2b8b2 commit a80a801

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

sstable/internal.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package sstable
77
import (
88
"github.com/cockroachdb/pebble/internal/base"
99
"github.com/cockroachdb/pebble/internal/keyspan"
10+
"github.com/cockroachdb/pebble/sstable/blob"
1011
"github.com/cockroachdb/pebble/sstable/valblk"
1112
)
1213

@@ -35,5 +36,14 @@ const valueBlocksIndexHandleMaxLen = blockHandleMaxLenWithoutProperties + 3
3536
// Assert blockHandleLikelyMaxLen >= valueBlocksIndexHandleMaxLen.
3637
const _ = uint(blockHandleLikelyMaxLen - valueBlocksIndexHandleMaxLen)
3738

38-
// Assert blockHandleLikelyMaxLen >= valblk.HandleMaxLen.
39-
const _ = uint(blockHandleLikelyMaxLen - valblk.HandleMaxLen)
39+
// Assert blockHandleLikelyMaxLen >= (valblk.HandleMaxLen+1).
40+
//
41+
// The additional 1 is for the 'valuePrefix' byte which prefaces values in
42+
// recent SSTable versions.
43+
const _ = uint(blockHandleLikelyMaxLen - valblk.HandleMaxLen - 1)
44+
45+
// Assert blockHandleLikelyMaxLen >= (blob.MaxInlineHandleLength+1).
46+
//
47+
// The additional 1 is for the 'valuePrefix' byte which prefaces values in recent
48+
// SSTable versions.
49+
const _ = uint(blockHandleLikelyMaxLen - blob.MaxInlineHandleLength - 1)

sstable/table.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ Data blocks have some additional features:
186186
*/
187187

188188
const (
189-
blockHandleMaxLenWithoutProperties = 10 + 10
189+
// blockHandleMaxLenWithoutProperties is the maximum length of a block
190+
// handle that does not encode any block properties. It consists of just
191+
// the offset and length, each of which is a varint-encoded uint64.
192+
blockHandleMaxLenWithoutProperties = 2 * binary.MaxVarintLen64
190193
// blockHandleLikelyMaxLen can be used for pre-allocating buffers to
191194
// reduce memory copies. It is not guaranteed that a block handle will not
192195
// exceed this length.

sstable/valblk/valblk.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,10 @@ type Handle struct {
186186

187187
// HandleMaxLen is the maximum length of a variable-width encoded Handle.
188188
//
189-
// Handle fields are varint encoded, so maximum 5 bytes each, plus 1 byte for
190-
// the valuePrefix. This could alternatively be group varint encoded, but
191-
// experiments were inconclusive
189+
// Handle fields are varint encoded, so maximum 5 bytes each. This could
190+
// alternatively be group varint encoded, but experiments were inconclusive
192191
// (https://github.com/cockroachdb/pebble/pull/1443#issuecomment-1270298802).
193-
const HandleMaxLen = 5*3 + 1
192+
const HandleMaxLen = 3 * binary.MaxVarintLen32
194193

195194
// EncodeHandle encodes the Handle into dst in a variable-width encoding and
196195
// returns the number of bytes encoded.

0 commit comments

Comments
 (0)