Skip to content

Commit 8859026

Browse files
committed
db: disable writing to value blocks if DisableSeparationBySuffix is true
Make sure this field, which has been moved from SpanPolicy to ValueStoragePolicy, is read for the DisableValueBlocks option in the sst writer.
1 parent 6d69292 commit 8859026

File tree

7 files changed

+201
-54
lines changed

7 files changed

+201
-54
lines changed

compaction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,11 +3480,11 @@ func (d *DB) compactAndWrite(
34803480
}
34813481
vSep := valueSeparation
34823482
switch spanPolicy.ValueStoragePolicy.PolicyAdjustment {
3483-
case UseDefaultValueStorage:
3483+
case UseDefaultValueSeparation:
34843484
// No change to value separation.
3485-
case NoValueSeparation:
3485+
case NoBlobHandles:
34863486
vSep = valsep.NeverSeparateValues{}
3487-
case OverrideValueStorage:
3487+
case OverrideValueSeparation:
34883488
// This span of keyspace is more tolerant of latency, so set a more
34893489
// aggressive value separation policy for this output.
34903490
vSep.SetNextOutputConfig(valsep.ValueSeparationOutputConfig{

compaction_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,24 +1530,23 @@ func runCompactionTest(
15301530
if len(parts) != 1 {
15311531
td.Fatalf(t, "expected disable-separation-by-suffix with no value, got: %s", arg)
15321532
}
1533-
if policy.ValueStoragePolicy.PolicyAdjustment == NoValueSeparation {
1534-
td.Fatalf(t, "conflicting value storage policies for span: %s", line)
1533+
if policy.ValueStoragePolicy.PolicyAdjustment == UseDefaultValueSeparation {
1534+
policy.ValueStoragePolicy.PolicyAdjustment = OverrideValueSeparation
15351535
}
1536-
policy.ValueStoragePolicy.PolicyAdjustment = OverrideValueStorage
15371536
policy.ValueStoragePolicy.DisableSeparationBySuffix = true
15381537
case "val-sep-minimum-size":
15391538
if len(parts) != 2 {
15401539
td.Fatalf(t, "expected val-sep-minimum-size=<size>, got: %s", arg)
15411540
}
15421541
size, err := strconv.ParseUint(parts[1], 10, 64)
15431542
if err != nil {
1544-
td.Fatalf(t, "parsing value-minimum-size: %s", err)
1543+
td.Fatalf(t, "parsing val-sep-minimum-size: %s", err)
15451544
}
15461545
policy.ValueStoragePolicy.MinimumSize = int(size)
15471546
if size == 0 {
1548-
policy.ValueStoragePolicy.PolicyAdjustment = NoValueSeparation
1547+
policy.ValueStoragePolicy.PolicyAdjustment = NoBlobHandles
15491548
} else if int(size) != d.opts.Experimental.ValueSeparationPolicy().MinimumSize {
1550-
policy.ValueStoragePolicy.PolicyAdjustment = OverrideValueStorage
1549+
policy.ValueStoragePolicy.PolicyAdjustment = OverrideValueSeparation
15511550
}
15521551
default:
15531552
td.Fatalf(t, "unknown span policy arg: %s", arg)

compaction_value_separation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ func shouldWriteBlobFiles(
138138
return true, 0
139139
}
140140
switch spanPolicy.ValueStoragePolicy.PolicyAdjustment {
141-
case UseDefaultValueStorage:
141+
case UseDefaultValueSeparation:
142142
// Use the global policy.
143-
case OverrideValueStorage:
143+
case OverrideValueSeparation:
144144
expectedMinSize = spanPolicy.ValueStoragePolicy.MinimumSize
145145
if expectedMinSize == 0 {
146146
// A 0 minimum value size on the span policy indicates the field
@@ -149,7 +149,7 @@ func shouldWriteBlobFiles(
149149
expectedMinSize = policy.MinimumSize
150150
}
151151
expectedValSepBySuffixDisabled = spanPolicy.ValueStoragePolicy.DisableSeparationBySuffix
152-
case NoValueSeparation:
152+
case NoBlobHandles:
153153
expectedMinSize = 0
154154
}
155155
}

options.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,23 +1298,18 @@ func (p SpanPolicy) String() string {
12981298
sb.WriteString("disable-value-separation-by-suffix,")
12991299
}
13001300
switch p.ValueStoragePolicy.PolicyAdjustment {
1301-
case NoValueSeparation:
1302-
sb.WriteString("no-value-separation,")
1303-
case OverrideValueStorage:
1304-
sb.WriteString("override,")
1301+
case NoBlobHandles:
1302+
sb.WriteString("no-blob-value-separation,")
1303+
case OverrideValueSeparation:
1304+
sb.WriteString("override-value-separation,")
13051305
}
13061306
return strings.TrimSuffix(sb.String(), ",")
13071307
}
13081308

13091309
// ValueStoragePolicyAdjustment is used to determine where to store the values for
1310-
// KVs. If the PolicyAdjustment specified is OverrideValueStorage, the remaining fields
1311-
// are used to override the global configuration for value separation.
1310+
// KVs, overriding global policies. Values can be configured to be stored in-place,
1311+
// in value blocks, or in blob files.
13121312
type ValueStoragePolicyAdjustment struct {
1313-
// PolicyAdjustment specifies the policy adjustment to apply.
1314-
PolicyAdjustment ValueStoragePolicyAdjustmentType
1315-
1316-
// Remaining fields are ignored, unless the PolicyAdjustment is OverrideValueStorage.
1317-
13181313
// DisableSeparationBySuffix disables discriminating KVs depending on
13191314
// suffix.
13201315
//
@@ -1323,6 +1318,13 @@ type ValueStoragePolicyAdjustment struct {
13231318
// keys (where the smallest suffix is the latest version), but should be
13241319
// disabled for keys where the suffix does not correspond to a version.
13251320
DisableSeparationBySuffix bool
1321+
1322+
// PolicyAdjustment specifies the policy adjustment to apply for value separation
1323+
// into blob files.
1324+
PolicyAdjustment ValueStoragePolicyAdjustmentType
1325+
1326+
// Remaining fields are ignored, unless the PolicyAdjustment is OverrideValueSeparation.
1327+
13261328
// MinimumSize is the minimum size of the value.
13271329
MinimumSize int
13281330
}
@@ -1332,35 +1334,36 @@ type ValueStoragePolicyAdjustment struct {
13321334
type ValueStoragePolicyAdjustmentType uint8
13331335

13341336
const (
1335-
// UseDefaultValueStorage is the default value; Pebble will respect global
1336-
// configuration for value separation.
1337-
UseDefaultValueStorage ValueStoragePolicyAdjustmentType = iota
1337+
// UseDefaultValueSeparation is the default value; Pebble will respect global
1338+
// configuration for value separation into blob files.
1339+
UseDefaultValueSeparation ValueStoragePolicyAdjustmentType = iota
13381340

1339-
// NoValueSeparation indicates Pebble should prefer storing values
1340-
// in-place.
1341-
NoValueSeparation
1341+
// NoBlobHandles indicates Pebble should prefer storing values in
1342+
// the same sstable (either in-place or in a value block).
1343+
NoBlobHandles
13421344

1343-
// OverrideValueStorage indicates that value separation thresholds (see
1345+
// OverrideValueSeparation indicates that value separation thresholds (see
13441346
// valsep.ValueSeparationOutputConfig) for this key range are being
13451347
// overridden from a SpanPolicy. If the global Options enable value
1346-
// separation, Pebble will separate values under the OverrideValueStorage
1348+
// separation, Pebble will separate values under the OverrideValueSeparation
13471349
// policy even if they do not meet the minimum size threshold of the
13481350
// global Options' ValueSeparationPolicy.
1349-
OverrideValueStorage
1351+
OverrideValueSeparation
13501352
)
13511353

13521354
// ValueStorageLatencyTolerant is the suggested ValueStoragePolicyAdjustment
13531355
// to use for key ranges that can tolerate higher value retrieval
13541356
// latency.
13551357
var ValueStorageLatencyTolerant = ValueStoragePolicyAdjustment{
1356-
PolicyAdjustment: OverrideValueStorage,
1358+
PolicyAdjustment: OverrideValueSeparation,
13571359
MinimumSize: 10,
13581360
}
13591361

13601362
// ValueStorageLowReadLatency is the suggested ValueStoragePolicyAdjustment
13611363
// to use for key ranges that require low value retrieval latency.
13621364
var ValueStorageLowReadLatency = ValueStoragePolicyAdjustment{
1363-
PolicyAdjustment: NoValueSeparation,
1365+
PolicyAdjustment: NoBlobHandles,
1366+
DisableSeparationBySuffix: true,
13641367
}
13651368

13661369
// SpanPolicyFunc is used to determine the SpanPolicy for a key region.

sstable/properties.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ type Properties struct {
125125
// The minimum size a value must be to be separated into a blob file during writing.
126126
ValueSeparationMinSize uint64 `prop:"pebble.value-separation.min-size"`
127127
// ValueSeparationBySuffixDisabled indicates if special value separation rules were
128-
// applied based on the KV suffix when writing. Pebble attempts to optimize writing of
129-
// MVCC garbage values into blob files, which are recognized by the key suffix.
128+
// applied based on the KV suffix when writing blob files. Pebble attempts to optimize
129+
// separating MVCC garbage, which are recognized by the key suffix. Note that this
130+
// value corresponds only for blob file writing and not value blocks.
130131
ValueSeparationBySuffixDisabled bool `prop:"pebble.value-separation.by-suffix.disabled"`
131132
// User collected properties. Currently, we only use them to store block
132133
// properties aggregated at the table level.

testdata/compaction/mvcc_garbage_blob

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ flush-log
6767

6868
# Another test with the same value separation config, but this time we set a span
6969
# policy for the span y-zz that disables value separation by suffix. This should
70-
# prevent MVCC garbage from being written to blob files.
70+
# prevent MVCC garbage from being separeted (both into blob files and value blocks).
7171

7272
define value-separation=(enabled, min-size=5, max-ref-depth=3, garbage-ratios=1.0:1.0)
7373
----
@@ -127,3 +127,147 @@ pebble.compression_stats: None:234
127127
pebble.value-separation.min-size: 5
128128
pebble.value-separation.by-suffix.disabled: true
129129
obsolete-key: hex:00
130+
131+
define value-separation=(enabled, min-size=5, max-ref-depth=3, garbage-ratios=1.0:1.0)
132+
----
133+
134+
135+
set-span-policies
136+
a,c val-sep-minimum-size=0 disable-separation-by-suffix
137+
----
138+
139+
140+
batch
141+
set a@2 a2
142+
set b@5 b5
143+
del b@4
144+
set b@3 bat3
145+
set b@2 bat2
146+
del b@1
147+
set b@1 bat1
148+
set b@0 bat0
149+
----
150+
151+
flush
152+
----
153+
L0.0:
154+
000005:[a@2#10,SET-b@0#17,SET] seqnums:[10-17] points:[a@2#10,SET-b@0#17,SET] size:770
155+
156+
sstable-properties file=000005
157+
----
158+
rocksdb.num.entries: 7
159+
rocksdb.raw.key.size: 77
160+
rocksdb.raw.value.size: 20
161+
pebble.raw.point-tombstone.key.size: 3
162+
rocksdb.deleted.keys: 1
163+
rocksdb.num.range-deletions: 0
164+
rocksdb.num.data.blocks: 1
165+
rocksdb.comparator: pebble.internal.testkeys
166+
rocksdb.data.size: 157
167+
rocksdb.filter.size: 0
168+
rocksdb.index.size: 36
169+
rocksdb.block.based.table.index.type: 0
170+
pebble.colblk.schema: DefaultKeySchema(pebble.internal.testkeys,16)
171+
rocksdb.merge.operator: pebble.concatenate
172+
rocksdb.merge.operands: 0
173+
rocksdb.property.collectors: [obsolete-key]
174+
rocksdb.compression: Snappy
175+
pebble.compression_stats: None:188
176+
obsolete-key: hex:00
177+
178+
179+
define value-separation=(enabled, min-size=5, max-ref-depth=3, garbage-ratios=1.0:1.0)
180+
----
181+
182+
set-span-policies
183+
a,c val-sep-minimum-size=0
184+
----
185+
186+
187+
batch
188+
set a@2 a2
189+
set b@5 b5
190+
del b@4
191+
set b@3 bat3
192+
set b@2 bat2
193+
del b@1
194+
set b@1 bat1
195+
set b@0 bat0
196+
----
197+
198+
# Although we've disabled value separation into blob files, writing to
199+
# value blocks should still be enabled.
200+
flush
201+
----
202+
L0.0:
203+
000005:[a@2#10,SET-b@0#17,SET] seqnums:[10-17] points:[a@2#10,SET-b@0#17,SET] size:880
204+
205+
sstable-properties file=000005
206+
----
207+
rocksdb.num.entries: 7
208+
rocksdb.raw.key.size: 77
209+
rocksdb.raw.value.size: 20
210+
pebble.raw.point-tombstone.key.size: 3
211+
rocksdb.deleted.keys: 1
212+
rocksdb.num.range-deletions: 0
213+
pebble.value-blocks.size: 25
214+
rocksdb.num.data.blocks: 1
215+
rocksdb.comparator: pebble.internal.testkeys
216+
rocksdb.data.size: 175
217+
rocksdb.filter.size: 0
218+
rocksdb.index.size: 36
219+
rocksdb.block.based.table.index.type: 0
220+
pebble.colblk.schema: DefaultKeySchema(pebble.internal.testkeys,16)
221+
rocksdb.merge.operator: pebble.concatenate
222+
rocksdb.merge.operands: 0
223+
pebble.num.value-blocks: 1
224+
pebble.num.values.in.value-blocks: 3
225+
rocksdb.property.collectors: [obsolete-key]
226+
rocksdb.compression: Snappy
227+
pebble.compression_stats: None:221
228+
obsolete-key: hex:00
229+
230+
batch
231+
set a@2 a2
232+
set b@5 b5
233+
del b@4
234+
set b@3 bat3
235+
set b@2 bat2
236+
del b@1
237+
set b@1 bat1
238+
set b@0 bat0
239+
----
240+
241+
# Disabling value separation by suffix should also disable writing to value blocks.
242+
set-span-policies
243+
a,c val-sep-minimum-size=0 disable-separation-by-suffix
244+
----
245+
246+
flush
247+
----
248+
L0.1:
249+
000007:[a@2#18,SET-b@0#25,SET] seqnums:[18-25] points:[a@2#18,SET-b@0#25,SET] size:770
250+
L0.0:
251+
000005:[a@2#10,SET-b@0#17,SET] seqnums:[10-17] points:[a@2#10,SET-b@0#17,SET] size:880
252+
253+
sstable-properties file=000007
254+
----
255+
rocksdb.num.entries: 7
256+
rocksdb.raw.key.size: 77
257+
rocksdb.raw.value.size: 20
258+
pebble.raw.point-tombstone.key.size: 3
259+
rocksdb.deleted.keys: 1
260+
rocksdb.num.range-deletions: 0
261+
rocksdb.num.data.blocks: 1
262+
rocksdb.comparator: pebble.internal.testkeys
263+
rocksdb.data.size: 157
264+
rocksdb.filter.size: 0
265+
rocksdb.index.size: 36
266+
rocksdb.block.based.table.index.type: 0
267+
pebble.colblk.schema: DefaultKeySchema(pebble.internal.testkeys,16)
268+
rocksdb.merge.operator: pebble.concatenate
269+
rocksdb.merge.operands: 0
270+
rocksdb.property.collectors: [obsolete-key]
271+
rocksdb.compression: Snappy
272+
pebble.compression_stats: None:188
273+
obsolete-key: hex:00

testdata/static_span_policy_func

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ a b c d e f g
66
a -> until d
77
b -> until d
88
c -> until d
9-
d -> no-value-separation until f
10-
e -> no-value-separation until f
9+
d -> disable-value-separation-by-suffix,no-blob-value-separation until f
10+
e -> disable-value-separation-by-suffix,no-blob-value-separation until f
1111
f -> none
1212
g -> none
1313

@@ -17,11 +17,11 @@ g -> none
1717
test a-z:lowlatency
1818
a b c d e z
1919
----
20-
a -> no-value-separation until z
21-
b -> no-value-separation until z
22-
c -> no-value-separation until z
23-
d -> no-value-separation until z
24-
e -> no-value-separation until z
20+
a -> disable-value-separation-by-suffix,no-blob-value-separation until z
21+
b -> disable-value-separation-by-suffix,no-blob-value-separation until z
22+
c -> disable-value-separation-by-suffix,no-blob-value-separation until z
23+
d -> disable-value-separation-by-suffix,no-blob-value-separation until z
24+
e -> disable-value-separation-by-suffix,no-blob-value-separation until z
2525
z -> none
2626

2727
# Abutting policies.
@@ -30,12 +30,12 @@ test b-d:lowlatency d-f:latencytolerant f-h:lowlatency
3030
a b c d e f g h i z
3131
----
3232
a -> until b
33-
b -> no-value-separation until d
34-
c -> no-value-separation until d
35-
d -> override until f
36-
e -> override until f
37-
f -> no-value-separation until h
38-
g -> no-value-separation until h
33+
b -> disable-value-separation-by-suffix,no-blob-value-separation until d
34+
c -> disable-value-separation-by-suffix,no-blob-value-separation until d
35+
d -> override-value-separation until f
36+
e -> override-value-separation until f
37+
f -> disable-value-separation-by-suffix,no-blob-value-separation until h
38+
g -> disable-value-separation-by-suffix,no-blob-value-separation until h
3939
h -> none
4040
i -> none
4141
z -> none
@@ -46,14 +46,14 @@ test b-d:lowlatency h-j:latencytolerant
4646
a b c d e f g h i j k l
4747
----
4848
a -> until b
49-
b -> no-value-separation until d
50-
c -> no-value-separation until d
49+
b -> disable-value-separation-by-suffix,no-blob-value-separation until d
50+
c -> disable-value-separation-by-suffix,no-blob-value-separation until d
5151
d -> until h
5252
e -> until h
5353
f -> until h
5454
g -> until h
55-
h -> override until j
56-
i -> override until j
55+
h -> override-value-separation until j
56+
i -> override-value-separation until j
5757
j -> none
5858
k -> none
5959
l -> none

0 commit comments

Comments
 (0)