Skip to content

Commit 61b17c1

Browse files
craig[bot]RaduBerinde
andcommitted
Merge #148692
148692: storage: bump Pebble, fix up code, prefer fast compression for local keys r=RaduBerinde a=RaduBerinde #### go.mod: bump Pebble to cca0dfd291bc Changes: * [`cca0dfd2`](cockroachdb/pebble@cca0dfd2) db: move TargetFileSize out of LevelOptions * [`9ba5661c`](cockroachdb/pebble@9ba5661c) db: introduce DBCompressionSettings * [`a4a43492`](cockroachdb/pebble@a4a43492) db: move compression profile reexports to sstable * [`e1f48f9e`](cockroachdb/pebble@e1f48f9e) db: consolidate compaction fields related to iteration state * [`14b15449`](cockroachdb/pebble@14b15449) db: remove compaction.allowedZeroSeqNum * [`520d3f31`](cockroachdb/pebble@520d3f31) db: consolidate compaction metrics in a struct * [`ee64cc61`](cockroachdb/pebble@ee64cc61) db: organize compaction kind-specific fields * [`6cbf981c`](cockroachdb/pebble@6cbf981c) db: remove redundant Comparer fields from compaction * [`1643b8d5`](cockroachdb/pebble@1643b8d5) db: represent compaction bounds as UserKeyBounds * [`bb173d20`](cockroachdb/pebble@bb173d20) db: remove pickedCompaction.cmp * [`a50aabcf`](cockroachdb/pebble@a50aabcf) db: simplify L0 picked compaction input construction * [`27c75484`](cockroachdb/pebble@27c75484) db: fix 32-bit overflow * [`72bfd418`](cockroachdb/pebble@72bfd418) db: add SpanPolicy flag to prefer faster compression * [`430ae82b`](cockroachdb/pebble@430ae82b) tool: analyze-data: support remote storage * [`bc68d6c7`](cockroachdb/pebble@bc68d6c7) tool: analyze-data: separate vfs-specific code behind interface * [`e24d2aa7`](cockroachdb/pebble@e24d2aa7) tool: improvements to analyze-data * [`23da05ed`](cockroachdb/pebble@23da05ed) manifest: add blob file rewrite heuristic * [`18051c53`](cockroachdb/pebble@18051c53) manifest: allow specifying blob file creation time * [`2b4a96ed`](cockroachdb/pebble@2b4a96ed) crossversion: don't parallelize calls to the meta test * [`7dc8e559`](cockroachdb/pebble@7dc8e559) db: move latest version state into a shared struct * [`28e2c9df`](cockroachdb/pebble@28e2c9df) db: fix Options.Clone() Release note: none. Epic: none. #### storage: update pebble configuration code Update Pebble configuration code to use compression definitions from `sstable` and to use the separated `TargetFileSizes`. Epic: none Release note: None #### storage: prefer fast compression for all local keys Improve the span policy function to set the `PreferFastCompression` flag for all local keys. Better compression for these keys won't save a significant amount of space, but might affect performance (e.g. raft logs, lock keys). Epic: none Release note: None #### cli: pebble: enable remote storage for analyze-data Set up a `tool.WithDBRemoteStorageFn` callback to allow the debug tool to use remote storage for `analyze-data`. Epic: none Release note: None Co-authored-by: Radu Berinde <[email protected]>
2 parents 3cc3a22 + 3070a87 commit 61b17c1

File tree

8 files changed

+69
-39
lines changed

8 files changed

+69
-39
lines changed

DEPS.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,10 +1835,10 @@ def go_deps():
18351835
patches = [
18361836
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
18371837
],
1838-
sha256 = "a7619dca2877f739868a0e62ec02537172589edafbbeeeb396e2b63aa04d2845",
1839-
strip_prefix = "github.com/cockroachdb/[email protected]20250620225651-4a0664421082",
1838+
sha256 = "07377eda591e261e925d3eb04c500ba429f0cf3bb76784127d1ac920ed8db6f4",
1839+
strip_prefix = "github.com/cockroachdb/[email protected]20250623151700-cca0dfd291bc",
18401840
urls = [
1841-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250620225651-4a0664421082.zip",
1841+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250623151700-cca0dfd291bc.zip",
18421842
],
18431843
)
18441844
go_repository(

build/bazelutil/distdir_files.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ DISTDIR_FILES = {
357357
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
358358
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241215232642-bb51bb14a506.zip": "920068af09e3846d9ebb4e4a7787ff1dd10f3989c5f940ad861b0f6a9f824f6e",
359359
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
360-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250620225651-4a0664421082.zip": "a7619dca2877f739868a0e62ec02537172589edafbbeeeb396e2b63aa04d2845",
360+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250623151700-cca0dfd291bc.zip": "07377eda591e261e925d3eb04c500ba429f0cf3bb76784127d1ac920ed8db6f4",
361361
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.6.zip": "018eccb5fb9ca52d43ec9eaf213539d01c1f2b94e0e822406ebfb2e9321ef6cf",
362362
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
363363
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ require (
139139
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
140140
github.com/cockroachdb/gostdlib v1.19.0
141141
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506
142-
github.com/cockroachdb/pebble v0.0.0-20250620225651-4a0664421082
142+
github.com/cockroachdb/pebble v0.0.0-20250623151700-cca0dfd291bc
143143
github.com/cockroachdb/redact v1.1.6
144144
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
145145
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILM
580580
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
581581
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
582582
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
583-
github.com/cockroachdb/pebble v0.0.0-20250620225651-4a0664421082 h1:oHPlpmKCv9MQ0mYNWCBdmvDH3dlHbxOh5xgaKFwSlvg=
584-
github.com/cockroachdb/pebble v0.0.0-20250620225651-4a0664421082/go.mod h1:cnPe7/4+ZaEoSSlr4P3QT2CBbd6fdnP+JQ6On5PEpoE=
583+
github.com/cockroachdb/pebble v0.0.0-20250623151700-cca0dfd291bc h1:T3ta04LDb7HSfo9PBaBl/hqh3+uHZKPhxyYuMZwtVP4=
584+
github.com/cockroachdb/pebble v0.0.0-20250623151700-cca0dfd291bc/go.mod h1:cnPe7/4+ZaEoSSlr4P3QT2CBbd6fdnP+JQ6On5PEpoE=
585585
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
586586
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
587587
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=

pkg/cli/debug.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,7 @@ func init() {
14481448
}),
14491449
tool.OpenOptions(pebbleOpenOptionLockDir{pebbleToolFS}),
14501450
tool.WithDBExciseSpanFn(pebbleExciseSpanFn),
1451+
tool.WithDBRemoteStorageFn(pebbleRemoteStorageFn),
14511452
)
14521453
debugPebbleCmd.AddCommand(pebbleTool.Commands...)
14531454
f := debugPebbleCmd.PersistentFlags()
@@ -1715,6 +1716,25 @@ func pebbleExciseSpanFn() (pebble.KeyRange, error) {
17151716
}, nil
17161717
}
17171718

1719+
func pebbleRemoteStorageFn(uri string) (remote.Storage, error) {
1720+
es, err := cloud.ExternalStorageFromURI(
1721+
context.Background(),
1722+
uri,
1723+
base.ExternalIODirConfig{},
1724+
cluster.MakeClusterSettings(),
1725+
nil, /* blobClientFactory: */
1726+
username.PublicRoleName(),
1727+
nil, /* db */
1728+
nil, /* limiters */
1729+
cloud.NilMetrics,
1730+
)
1731+
if err != nil {
1732+
return nil, err
1733+
}
1734+
wrapper := storage.MakeExternalStorageWrapper(context.Background(), es)
1735+
return wrapper, nil
1736+
}
1737+
17181738
func pebbleCryptoInitializer(ctx context.Context) {
17191739
var encryptedPaths []string
17201740
for _, spec := range encryptionSpecs.Specs {

pkg/storage/metamorphic/options.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,14 @@ func randomOptions() *pebble.Options {
110110
if opts.L0StopWritesThreshold < opts.L0CompactionThreshold {
111111
opts.L0StopWritesThreshold = opts.L0CompactionThreshold
112112
}
113-
for i := range opts.Levels {
114-
if i == 0 {
115-
opts.Levels[i].BlockRestartInterval = int(rngIntRange(rng, 1, 64))
116-
opts.Levels[i].BlockSize = 1 << rngIntRange(rng, 1, 20)
117-
opts.Levels[i].BlockSizeThreshold = int(rngIntRange(rng, 50, 100))
118-
opts.Levels[i].IndexBlockSize = opts.Levels[i].BlockSize
119-
opts.Levels[i].TargetFileSize = 1 << rngIntRange(rng, 1, 20)
120-
} else {
121-
opts.Levels[i] = opts.Levels[i-1]
122-
opts.Levels[i].TargetFileSize = opts.Levels[i-1].TargetFileSize * 2
123-
}
113+
opts.Levels[0].BlockRestartInterval = int(rngIntRange(rng, 1, 64))
114+
opts.Levels[0].BlockSize = 1 << rngIntRange(rng, 1, 20)
115+
opts.Levels[0].BlockSizeThreshold = int(rngIntRange(rng, 50, 100))
116+
opts.Levels[0].IndexBlockSize = opts.Levels[0].BlockSize
117+
opts.TargetFileSizes[0] = 1 << rngIntRange(rng, 1, 20)
118+
for i := 1; i < len(opts.Levels); i++ {
119+
opts.Levels[i] = opts.Levels[i-1]
120+
opts.TargetFileSizes[i] = opts.TargetFileSizes[i-1] * 2
124121
}
125122
opts.MaxManifestFileSize = 1 << rngIntRange(rng, 1, 28)
126123
opts.MaxOpenFiles = int(rngIntRange(rng, 20, 2000))

pkg/storage/open.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func BlockSize(size int) ConfigOption {
127127
// primarily for testing purposes.
128128
func TargetFileSize(size int64) ConfigOption {
129129
return func(cfg *engineConfig) error {
130-
for i := range cfg.opts.Levels {
131-
cfg.opts.Levels[i].TargetFileSize = size
130+
for i := range cfg.opts.TargetFileSizes {
131+
cfg.opts.TargetFileSizes[i] = size
132132
}
133133
return nil
134134
}

pkg/storage/pebble.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package storage
77

88
import (
9+
"bytes"
910
"context"
1011
"encoding/json"
1112
"fmt"
@@ -267,20 +268,20 @@ func getCompressionProfile(
267268
ctx context.Context,
268269
settings *cluster.Settings,
269270
setting *settings.EnumSetting[CompressionAlgorithm],
270-
) *pebble.CompressionProfile {
271+
) *sstable.CompressionProfile {
271272
switch setting.Get(&settings.SV) {
272273
case CompressionAlgorithmSnappy:
273-
return pebble.SnappyCompression
274+
return sstable.SnappyCompression
274275
case CompressionAlgorithmZstd:
275-
return pebble.ZstdCompression
276+
return sstable.ZstdCompression
276277
case CompressionAlgorithmNone:
277-
return pebble.NoCompression
278+
return sstable.NoCompression
278279
case CompressionAlgorithmMinLZ:
279-
return pebble.MinLZCompression
280+
return sstable.MinLZCompression
280281
case CompressionAlgorithmFastest:
281-
return pebble.FastestCompression
282+
return sstable.FastestCompression
282283
default:
283-
return pebble.DefaultCompression
284+
return sstable.DefaultCompression
284285
}
285286
}
286287

@@ -464,17 +465,30 @@ func DefaultPebbleOptions() *pebble.Options {
464465
// once.
465466
opts.TargetByteDeletionRate = 128 << 20 // 128 MB
466467
opts.Experimental.ShortAttributeExtractor = shortAttributeExtractorForValues
467-
opts.Experimental.SpanPolicyFunc = pebble.MakeStaticSpanPolicyFunc(
468-
cockroachkvs.Compare,
469-
pebble.KeyRange{
470-
Start: EncodeMVCCKey(MVCCKey{Key: keys.LocalRangeLockTablePrefix}),
471-
End: EncodeMVCCKey(MVCCKey{Key: keys.LocalRangeLockTablePrefix.PrefixEnd()}),
472-
},
473-
pebble.SpanPolicy{
474-
DisableValueSeparationBySuffix: true,
475-
ValueStoragePolicy: pebble.ValueStorageLowReadLatency,
476-
},
477-
)
468+
469+
lockTableStartKey := EncodeMVCCKey(MVCCKey{Key: keys.LocalRangeLockTablePrefix})
470+
lockTableEndKey := EncodeMVCCKey(MVCCKey{Key: keys.LocalRangeLockTablePrefix.PrefixEnd()})
471+
localEndKey := EncodeMVCCKey(MVCCKey{Key: keys.LocalPrefix.PrefixEnd()})
472+
opts.Experimental.SpanPolicyFunc = func(startKey []byte) (policy pebble.SpanPolicy, endKey []byte, _ error) {
473+
if !bytes.HasPrefix(startKey, keys.LocalPrefix) {
474+
return pebble.SpanPolicy{}, nil, nil
475+
}
476+
// Prefer fast compression for all local keys, since they shouldn't take up
477+
// a significant part of the space.
478+
policy.PreferFastCompression = true
479+
480+
// We also disable value separation for lock keys.
481+
if cockroachkvs.Compare(startKey, lockTableEndKey) >= 0 {
482+
return policy, localEndKey, nil
483+
}
484+
if cockroachkvs.Compare(startKey, lockTableStartKey) < 0 {
485+
return policy, lockTableStartKey, nil
486+
}
487+
policy.DisableValueSeparationBySuffix = true
488+
policy.ValueStoragePolicy = pebble.ValueStorageLowReadLatency
489+
return policy, lockTableEndKey, nil
490+
}
491+
478492
// Disable multi-level compaction heuristic for now. See #134423
479493
// for why this was disabled, and what needs to be changed to reenable it.
480494
// This issue tracks re-enablement: https://github.com/cockroachdb/pebble/issues/4139
@@ -494,7 +508,6 @@ func DefaultPebbleOptions() *pebble.Options {
494508
l.IndexBlockSize = 256 << 10 // 256 KB
495509
l.FilterPolicy = bloom.FilterPolicy(10)
496510
l.FilterType = pebble.TableFilter
497-
l.TargetFileSize = opts.Levels[i-1].TargetFileSize * 2
498511
l.EnsureL1PlusDefaults(&opts.Levels[i-1])
499512
}
500513

0 commit comments

Comments
 (0)