Skip to content

Commit 88410ab

Browse files
committed
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
1 parent 6d9a6a2 commit 88410ab

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pkg/storage/pebble.go

Lines changed: 25 additions & 11 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"
@@ -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

0 commit comments

Comments
 (0)