Skip to content

Commit fc29b04

Browse files
committed
db: simplify shouldWriteBlobFiles
1 parent 785e7fb commit fc29b04

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

value_separation.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,30 @@ func (d *DB) determineCompactionValueSeparation(
4141
return compact.NeverSeparateValues{}
4242
}
4343
policy := d.opts.Experimental.ValueSeparationPolicy()
44-
if !policy.Enabled || valueStorage == ValueStorageLowReadLatency {
44+
if !policy.Enabled {
4545
return compact.NeverSeparateValues{}
4646
}
4747

4848
// We're allowed to write blob references. Determine whether we should carry
4949
// forward existing blob references, or write new ones.
50-
if writeBlobs, outputBlobReferenceDepth := shouldWriteBlobFiles(c, policy, valueStorage); !writeBlobs {
50+
minSize := uint64(policy.MinimumSize)
51+
switch valueStorage {
52+
case ValueStorageLowReadLatency:
53+
return compact.NeverSeparateValues{}
54+
case ValueStorageLatencyTolerant:
55+
minSize = latencyTolerantMinimumSize
56+
default:
57+
}
58+
if writeBlobs, outputBlobReferenceDepth := shouldWriteBlobFiles(c, policy, minSize); !writeBlobs {
5159
// This compaction should preserve existing blob references.
5260
kind := sstable.ValueSeparationDefault
53-
minSize := policy.MinimumSize
5461
if valueStorage != ValueStorageDefault {
5562
kind = sstable.ValueSeparationSpanPolicy
56-
minSize = latencyTolerantMinimumSize
5763
}
5864
return &preserveBlobReferences{
5965
inputBlobPhysicalFiles: uniqueInputBlobMetadatas(&c.version.BlobFiles, c.inputs),
6066
outputBlobReferenceDepth: outputBlobReferenceDepth,
61-
minimumValueSize: minSize,
67+
minimumValueSize: int(minSize),
6268
originalValueSeparationKind: kind,
6369
}
6470
}
@@ -92,7 +98,7 @@ func (d *DB) determineCompactionValueSeparation(
9298
// maximum blob reference depth to assign to output sstables (the actual value
9399
// may be lower iff the output table references fewer distinct blob files).
94100
func shouldWriteBlobFiles(
95-
c *tableCompaction, policy ValueSeparationPolicy, valueStorage ValueStoragePolicy,
101+
c *tableCompaction, policy ValueSeparationPolicy, minimumValueSizeForCompaction uint64,
96102
) (writeBlobs bool, referenceDepth manifest.BlobReferenceDepth) {
97103
// Flushes will have no existing references to blob files and should write
98104
// their values to new blob files.
@@ -131,19 +137,8 @@ func shouldWriteBlobFiles(
131137
if !backingPropsValid {
132138
continue
133139
}
134-
switch valueStorage {
135-
case ValueStorageLowReadLatency:
136-
// This case should be handled prior to calling this function,
137-
// but include it here for completeness.
138-
return false, inputReferenceDepth
139-
case ValueStorageLatencyTolerant:
140-
if backingProps.ValueSeparationMinSize != latencyTolerantMinimumSize {
141-
return true, 0
142-
}
143-
default:
144-
if int(backingProps.ValueSeparationMinSize) != policy.MinimumSize {
145-
return true, 0
146-
}
140+
if backingProps.ValueSeparationMinSize != minimumValueSizeForCompaction {
141+
return true, 0
147142
}
148143
}
149144
}

0 commit comments

Comments
 (0)