Skip to content

Commit

Permalink
Merge pull request #133312 from RaduBerinde/radu/pebble-release-24.3-…
Browse files Browse the repository at this point in the history
…8bf23da79c5c

release-24.3: go.mod: bump Pebble to 8bf23da79c5c
  • Loading branch information
RaduBerinde authored Oct 24, 2024
2 parents 183bed7 + 6a00122 commit 7d4e4b4
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 58 deletions.
6 changes: 3 additions & 3 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1818,10 +1818,10 @@ def go_deps():
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
],
sha256 = "8c165990dc3d4d67618b19e45e2c79f5f48ab9df4e19f881ee1cfa82cdd009df",
strip_prefix = "github.com/cockroachdb/[email protected]20241017195839-1d2e9e829b92",
sha256 = "a72c365ccf143d2bdb7c9619bab0a577568bb205b5d298711f32297098747b7c",
strip_prefix = "github.com/cockroachdb/[email protected]20241023221932-8bf23da79c5c",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20241017195839-1d2e9e829b92.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20241023221932-8bf23da79c5c.zip",
],
)
go_repository(
Expand Down
2 changes: 1 addition & 1 deletion build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20230118201751-21c54148d20b.zip": "ca7776f47e5fecb4c495490a679036bfc29d95bd7625290cfdb9abb0baf97476",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20241017195839-1d2e9e829b92.zip": "8c165990dc3d4d67618b19e45e2c79f5f48ab9df4e19f881ee1cfa82cdd009df",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20241023221932-8bf23da79c5c.zip": "a72c365ccf143d2bdb7c9619bab0a577568bb205b5d298711f32297098747b7c",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.5.zip": "11b30528eb0dafc8bc1a5ba39d81277c257cbe6946a7564402f588357c164560",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ require (
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
github.com/cockroachdb/gostdlib v1.19.0
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b
github.com/cockroachdb/pebble v0.0.0-20241017195839-1d2e9e829b92
github.com/cockroachdb/pebble v0.0.0-20241023221932-8bf23da79c5c
github.com/cockroachdb/redact v1.1.5
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZe
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
github.com/cockroachdb/pebble v0.0.0-20241017195839-1d2e9e829b92 h1:AEWpYdO8k0gpPWZtpP8CyTr901vv7yxKVrzkXz5Vte8=
github.com/cockroachdb/pebble v0.0.0-20241017195839-1d2e9e829b92/go.mod h1:XmS8uVDd9YFw/1R7J0J/CmTUANwT7iGnBRxH9AyDA90=
github.com/cockroachdb/pebble v0.0.0-20241023221932-8bf23da79c5c h1:KxaJAPo1rdkJdghI6y4GhHUDNIBMsvTz8fW6nThzWLg=
github.com/cockroachdb/pebble v0.0.0-20241023221932-8bf23da79c5c/go.mod h1:XmS8uVDd9YFw/1R7J0J/CmTUANwT7iGnBRxH9AyDA90=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
Expand Down
16 changes: 9 additions & 7 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ func ShouldUseEFOS(settings *settings.Values) bool {
return UseEFOS.Get(settings) || UseExciseForSnapshots.Get(settings)
}

// EngineSuffixCompare implements pebble.Comparer.CompareSuffixes. It compares
// EngineRangeSuffixCompare implements pebble.Comparer.CompareSuffixes. It compares
// cockroach suffixes (which are composed of the version and a trailing sentinel
// byte); the version can be an MVCC timestamp or a lock key.
func EngineSuffixCompare(a, b []byte) int {
func EngineRangeSuffixCompare(a, b []byte) int {
if len(a) == 0 || len(b) == 0 {
// Empty suffixes sort before non-empty suffixes.
return cmp.Compare(len(a), len(b))
Expand Down Expand Up @@ -617,10 +617,12 @@ func normalizeEngineSuffixForCompare(a []byte) []byte {
// EngineComparer is a pebble.Comparer object that implements MVCC-specific
// comparator settings for use with Pebble.
var EngineComparer = &pebble.Comparer{
Split: EngineKeySplit,
CompareSuffixes: EngineSuffixCompare,
Compare: EngineKeyCompare,
Equal: EngineKeyEqual,
Split: EngineKeySplit,
CompareRangeSuffixes: EngineRangeSuffixCompare,
ComparePointSuffixes: EnginePointSuffixCompare,

Compare: EngineKeyCompare,
Equal: EngineKeyEqual,

AbbreviatedKey: func(k []byte) uint64 {
key, ok := GetKeyPartFromEngineKey(k)
Expand Down Expand Up @@ -840,7 +842,7 @@ func DefaultPebbleOptions() *pebble.Options {
Comparer: EngineComparer,
FS: vfs.Default,
KeySchema: keySchema.Name,
KeySchemas: sstable.MakeKeySchemas(keySchema),
KeySchemas: sstable.MakeKeySchemas(&keySchema),
// A value of 2 triggers a compaction when there is 1 sub-level.
L0CompactionThreshold: 2,
L0StopWritesThreshold: 1000,
Expand Down
42 changes: 21 additions & 21 deletions pkg/storage/pebble_key_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/binary"
"fmt"
"io"
"sync"
"unsafe"

"github.com/cockroachdb/cockroach/pkg/util/buildutil"
Expand Down Expand Up @@ -47,15 +46,14 @@ var keySchema = colblk.KeySchema{
cockroachColUntypedVersion: colblk.DataTypeBytes,
},
NewKeyWriter: func() colblk.KeyWriter {
kw := &cockroachKeyWriter{}
kw.roachKeys.Init(16)
kw.wallTimes.Init()
kw.logicalTimes.InitWithDefault()
kw.untypedVersions.Init()
return kw
return makeCockroachKeyWriter()
},
NewKeySeeker: func() colblk.KeySeeker {
return &cockroachKeySeeker{}
InitKeySeekerMetadata: func(meta *colblk.KeySeekerMetadata, d *colblk.DataBlockDecoder) {
ks := (*cockroachKeySeeker)(unsafe.Pointer(meta))
ks.init(d)
},
KeySeeker: func(meta *colblk.KeySeekerMetadata) colblk.KeySeeker {
return (*cockroachKeySeeker)(unsafe.Pointer(meta))
},
}

Expand All @@ -70,6 +68,15 @@ type cockroachKeyWriter struct {
// Assert *cockroachKeyWriter implements colblk.KeyWriter.
var _ colblk.KeyWriter = (*cockroachKeyWriter)(nil)

func makeCockroachKeyWriter() *cockroachKeyWriter {
kw := &cockroachKeyWriter{}
kw.roachKeys.Init(16)
kw.wallTimes.Init()
kw.logicalTimes.InitWithDefault()
kw.untypedVersions.Init()
return kw
}

func (kw *cockroachKeyWriter) ComparePrev(key []byte) colblk.KeyComparison {
var cmpv colblk.KeyComparison
cmpv.PrefixLen = int32(EngineKeySplit(key)) // TODO(jackson): Inline
Expand Down Expand Up @@ -223,9 +230,7 @@ func (kw *cockroachKeyWriter) Finish(
}
}

var cockroachKeySeekerPool = sync.Pool{
New: func() interface{} { return &cockroachKeySeeker{} },
}
func (kw *cockroachKeyWriter) FinishHeader(buf []byte) {}

type cockroachKeySeeker struct {
roachKeys colblk.PrefixBytes
Expand All @@ -235,17 +240,18 @@ type cockroachKeySeeker struct {
untypedVersions colblk.RawBytes
}

// Assert that the cockroachKeySeeker fits inside KeySeekerMetadata.
var _ uint = colblk.KeySeekerMetadataSize - uint(unsafe.Sizeof(cockroachKeySeeker{}))

var _ colblk.KeySeeker = (*cockroachKeySeeker)(nil)

// Init is part of the KeySeeker interface.
func (ks *cockroachKeySeeker) Init(d *colblk.DataBlockDecoder) error {
func (ks *cockroachKeySeeker) init(d *colblk.DataBlockDecoder) {
bd := d.BlockDecoder()
ks.roachKeys = bd.PrefixBytes(cockroachColRoachKey)
ks.roachKeyChanged = d.PrefixChanged()
ks.mvccWallTimes = bd.Uints(cockroachColMVCCWallTime)
ks.mvccLogical = bd.Uints(cockroachColMVCCLogical)
ks.untypedVersions = bd.RawBytes(cockroachColUntypedVersion)
return nil
}

// IsLowerBound compares the provided key to the first user key
Expand Down Expand Up @@ -460,11 +466,5 @@ func (ks *cockroachKeySeeker) MaterializeUserKeyWithSyntheticSuffix(
return res
}

// Release is part of the KeySeeker interface.
func (ks *cockroachKeySeeker) Release() {
*ks = cockroachKeySeeker{}
cockroachKeySeekerPool.Put(ks)
}

//go:linkname memmove runtime.memmove
func memmove(to, from unsafe.Pointer, n uintptr)
17 changes: 6 additions & 11 deletions pkg/storage/pebble_key_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strconv"
"strings"
"testing"
"unsafe"

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
Expand Down Expand Up @@ -121,18 +122,12 @@ func TestKeySchema_KeySeeker(t *testing.T) {
var dec colblk.DataBlockDecoder
var ks colblk.KeySeeker
var maxKeyLen int
enc.Init(keySchema)
enc.Init(&keySchema)

initKeySeeker := func() {
if ks == nil || rand.Intn(2) == 1 {
if ks != nil {
ks.Release()
}
ks = keySchema.NewKeySeeker()
}
if err := ks.Init(&dec); err != nil {
t.Fatal(err)
}
ksPointer := &cockroachKeySeeker{}
keySchema.InitKeySeekerMetadata((*colblk.KeySeekerMetadata)(unsafe.Pointer(ksPointer)), &dec)
ks = keySchema.KeySeeker((*colblk.KeySeekerMetadata)(unsafe.Pointer(ksPointer)))
}

datadriven.RunTest(t, datapathutils.TestDataPath(t, "key_schema_key_seeker"), func(t *testing.T, td *datadriven.TestData) string {
Expand All @@ -158,7 +153,7 @@ func TestKeySchema_KeySeeker(t *testing.T) {
rows++
}
blk, _ := enc.Finish(rows, enc.Size())
dec.Init(keySchema, blk)
dec.Init(&keySchema, blk)
return buf.String()
case "is-lower-bound":
initKeySeeker()
Expand Down
52 changes: 40 additions & 12 deletions pkg/storage/pebble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,33 @@ func TestEngineComparer(t *testing.T) {
ts3a := appendBytesToTimestamp(ts3, zeroLogical[:])
ts3b := appendBytesToTimestamp(ts3, slices.Concat(zeroLogical[:], syntheticBit))

// We group versions by equality and in the expected ordering.
orderedVersions := []any{
// We group versions by equality and in the expected point key ordering.
orderedVersions := [][]any{
{ts1}, // Empty version sorts first.
{ts2a, ts2},
{ts3b, ts3a, ts3},
{ts4},
{ts5},
}

// Compare range suffixes.
for i := range orderedVersions {
for j := range orderedVersions {
for _, v1 := range orderedVersions[i] {
for _, v2 := range orderedVersions[j] {
result := EngineComparer.ComparePointSuffixes(encodeVersion(v1), encodeVersion(v2))
if expected := cmp.Compare(i, j); result != expected {
t.Fatalf("CompareSuffixes(%x, %x) = %d, expected %d", v1, v2, result, expected)
}
}
}
}
}

// CompareRangeSuffixes has a more strict ordering.
rangeOrderedVersions := []any{
ts1, // Empty version sorts first.
ts2a, // Synthetic bit is not ignored when comparing suffixes.
ts2a, // Synthetic bit is not ignored when comparing range suffixes.
ts2,
ts3b, // Higher timestamps sort before lower timestamps.
ts3a,
Expand All @@ -104,10 +127,10 @@ func TestEngineComparer(t *testing.T) {
ts5,
}

// Compare suffixes.
for i, v1 := range orderedVersions {
for j, v2 := range orderedVersions {
result := EngineComparer.CompareSuffixes(encodeVersion(v1), encodeVersion(v2))
// Compare range suffixes.
for i, v1 := range rangeOrderedVersions {
for j, v2 := range rangeOrderedVersions {
result := EngineComparer.CompareRangeSuffixes(encodeVersion(v1), encodeVersion(v2))
if expected := cmp.Compare(i, j); result != expected {
t.Fatalf("CompareSuffixes(%x, %x) = %d, expected %d", v1, v2, result, expected)
}
Expand All @@ -116,10 +139,15 @@ func TestEngineComparer(t *testing.T) {

lock1 := bytes.Repeat([]byte{1}, engineKeyVersionLockTableLen)
lock2 := bytes.Repeat([]byte{2}, engineKeyVersionLockTableLen)
require.Equal(t, 0, EngineComparer.CompareSuffixes(encodeVersion(lock1), encodeVersion(lock1)))
require.Equal(t, 0, EngineComparer.CompareSuffixes(encodeVersion(lock2), encodeVersion(lock2)))
require.Equal(t, +1, EngineComparer.CompareSuffixes(encodeVersion(lock1), encodeVersion(lock2)))
require.Equal(t, -1, EngineComparer.CompareSuffixes(encodeVersion(lock2), encodeVersion(lock1)))
require.Equal(t, 0, EngineComparer.CompareRangeSuffixes(encodeVersion(lock1), encodeVersion(lock1)))
require.Equal(t, 0, EngineComparer.CompareRangeSuffixes(encodeVersion(lock2), encodeVersion(lock2)))
require.Equal(t, +1, EngineComparer.CompareRangeSuffixes(encodeVersion(lock1), encodeVersion(lock2)))
require.Equal(t, -1, EngineComparer.CompareRangeSuffixes(encodeVersion(lock2), encodeVersion(lock1)))

require.Equal(t, 0, EngineComparer.ComparePointSuffixes(encodeVersion(lock1), encodeVersion(lock1)))
require.Equal(t, 0, EngineComparer.ComparePointSuffixes(encodeVersion(lock2), encodeVersion(lock2)))
require.Equal(t, +1, EngineComparer.ComparePointSuffixes(encodeVersion(lock1), encodeVersion(lock2)))
require.Equal(t, -1, EngineComparer.ComparePointSuffixes(encodeVersion(lock2), encodeVersion(lock1)))

keys := []roachpb.Key{
roachpb.Key(""),
Expand All @@ -128,7 +156,7 @@ func TestEngineComparer(t *testing.T) {
roachpb.Key("fg"),
}

// We group keys by equality and in the expected ordering.
// We group keys by equality and the groups are in the expected order.
var orderedKeys [][][]byte
for _, k := range keys {
orderedKeys = append(orderedKeys,
Expand Down

0 comments on commit 7d4e4b4

Please sign in to comment.