Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sstable,colblk: minor bug fixes #3962

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sstable/colblk/cockroach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ type cockroachKeyWriter struct {
}

func (kw *cockroachKeyWriter) ComparePrev(key []byte) KeyComparison {
lp := kw.prefixes.UnsafeGet(kw.prefixes.Rows() - 1)
var cmpv KeyComparison
cmpv.PrefixLen = int32(crdbtest.Split(key)) // TODO(jackson): Inline
if kw.prefixes.Rows() == 0 {
cmpv.UserKeyComparison = 1
return cmpv
}
lp := kw.prefixes.UnsafeGet(kw.prefixes.Rows() - 1)
cmpv.CommonPrefixLen = int32(crbytes.CommonPrefix(lp, key[:cmpv.PrefixLen]))
if cmpv.CommonPrefixLen == cmpv.PrefixLen {
cmpv.UserKeyComparison = int32(crdbtest.CompareSuffixes(key[cmpv.PrefixLen:], kw.prevSuffix))
Expand Down
11 changes: 7 additions & 4 deletions sstable/colblk/data_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type KeyWriter interface {
// key. The returned KeyComparison's UserKeyComparison field is equivalent
// to Compare(key, prevKey) where prevKey is the last key passed to
// WriteKey.
//
// If no key has been written yet, ComparePrev returns a KeyComparison with
// PrefixLen set and UserKeyComparison=1.
ComparePrev(key []byte) KeyComparison
// WriteKey writes a user key into the KeyWriter's columns. The
// keyPrefixLenSharedWithPrev parameter takes the number of bytes prefixing
Expand Down Expand Up @@ -169,15 +172,15 @@ type defaultKeyWriter struct {
}

func (w *defaultKeyWriter) ComparePrev(key []byte) KeyComparison {
lp := w.prefixes.UnsafeGet(w.prefixes.nKeys - 1)

var cmpv KeyComparison
cmpv.PrefixLen = int32(w.comparer.Split(key))
cmpv.CommonPrefixLen = int32(crbytes.CommonPrefix(lp, key[:cmpv.PrefixLen]))
if len(lp) == 0 {
if w.prefixes.nKeys == 0 {
// The first key has no previous key to compare to.
cmpv.UserKeyComparison = 1
return cmpv
}
lp := w.prefixes.UnsafeGet(w.prefixes.nKeys - 1)
cmpv.CommonPrefixLen = int32(crbytes.CommonPrefix(lp, key[:cmpv.PrefixLen]))

if invariants.Enabled && bytes.Compare(lp, key[:cmpv.PrefixLen]) > 0 {
panic(errors.AssertionFailedf("keys are not in order: %q > %q", lp, key[:cmpv.PrefixLen]))
Expand Down
1 change: 1 addition & 0 deletions sstable/colblk_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ func (w *RawColumnWriter) flushBufferedIndexBlocks() (rootIndex block.Handle, er
// writing a large file or the index separators happen to be excessively
// long, we may have several index blocks and need to construct a
// "two-level" index structure.
w.props.IndexPartitions = uint64(len(w.indexBuffering.partitions))
switch len(w.indexBuffering.partitions) {
case 0:
// This is impossible because we'll flush the index block immediately
Expand Down
13 changes: 13 additions & 0 deletions sstable/suffix_rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,16 @@ func BenchmarkRewriteSST(b *testing.B) {
})
}
}

var test4bSuffixComparer = func() *base.Comparer {
c := new(base.Comparer)
*c = *base.DefaultComparer
c.Split = func(key []byte) int {
if len(key) > 4 {
return len(key) - 4
}
return len(key)
}
c.Name = "comparer-split-4b-suffix"
return c
}()
Loading
Loading