Skip to content

Commit a7c678d

Browse files
committed
db: avoid use of internal type in ValueSeparationPolicy
Avoid use of the internal/manifest.BlobReferenceDepth type in the external ValueSeparationPolicy type. Users are expected to construct a ValueSeparationPolicy and must be able to construct a MaxBlobReferenceDepth value.
1 parent 3056964 commit a7c678d

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

data_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,12 +1675,10 @@ func parseDBOptionsArgs(opts *Options, args []datadriven.CmdArg) error {
16751675
if err != nil {
16761676
return err
16771677
}
1678-
var maxDepth int
1679-
maxDepth, err = strconv.Atoi(cmdArg.Vals[2])
1678+
policy.MaxBlobReferenceDepth, err = strconv.Atoi(cmdArg.Vals[2])
16801679
if err != nil {
16811680
return err
16821681
}
1683-
policy.MaxBlobReferenceDepth = manifest.BlobReferenceDepth(maxDepth)
16841682
opts.Experimental.ValueSeparationPolicy = func() ValueSeparationPolicy {
16851683
return policy
16861684
}

options.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ type ValueSeparationPolicy struct {
11401140
// compaction may produce an output sstable referencing more than this many
11411141
// overlapping blob files, the compaction will instead rewrite referenced
11421142
// values into new blob files.
1143-
MaxBlobReferenceDepth manifest.BlobReferenceDepth
1143+
MaxBlobReferenceDepth int
11441144
}
11451145

11461146
// WALFailoverOptions configures the WAL failover mechanics to use during
@@ -1928,9 +1928,7 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
19281928
minimumSize, err = strconv.Atoi(value)
19291929
valSepPolicy.MinimumSize = minimumSize
19301930
case "max_blob_reference_depth":
1931-
var maxBlobReferenceDepth int
1932-
maxBlobReferenceDepth, err = strconv.Atoi(value)
1933-
valSepPolicy.MaxBlobReferenceDepth = manifest.BlobReferenceDepth(maxBlobReferenceDepth)
1931+
valSepPolicy.MaxBlobReferenceDepth, err = strconv.Atoi(value)
19341932
default:
19351933
if hooks != nil && hooks.SkipUnknown != nil && hooks.SkipUnknown(section+"."+key, value) {
19361934
return nil

value_separation.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,29 @@ func (d *DB) determineCompactionValueSeparation(
6565
}
6666

6767
// shouldWriteBlobFiles returns true if the compaction should write new blob
68-
// files. It also returns the maximum blob reference depth to assign to output
69-
// sstables (the actual value may be lower iff the output table references fewer
70-
// distinct blob files).
68+
// files. If it returns false, the referenceDepth return value contains the
69+
// maximum blob reference depth to assign to output sstables (the actual value
70+
// may be lower iff the output table references fewer distinct blob files).
7171
func shouldWriteBlobFiles(
7272
c *compaction, policy ValueSeparationPolicy,
7373
) (writeBlobs bool, referenceDepth manifest.BlobReferenceDepth) {
7474
// Flushes will have no existing references to blob files and should write
7575
// their values to new blob files.
7676
if c.kind == compactionKindFlush {
77-
return true, 1
77+
return true, 0
7878
}
7979
inputReferenceDepth := compactionBlobReferenceDepth(c.inputs)
8080
if inputReferenceDepth == 0 {
8181
// None of the input sstables reference blob files. It may be the case
8282
// that these sstables were created before value separation was enabled.
8383
// We should try to write to new blob files.
84-
return true, 1
84+
return true, 0
8585
}
8686
// If the compaction's output blob reference depth would be greater than the
8787
// configured max, we should rewrite the values into new blob files to
8888
// restore locality.
89-
if inputReferenceDepth > policy.MaxBlobReferenceDepth {
90-
return true, 1
89+
if inputReferenceDepth > manifest.BlobReferenceDepth(policy.MaxBlobReferenceDepth) {
90+
return true, 0
9191
}
9292
// Otherwise, we won't write any new blob files but will carry forward
9393
// existing references.

0 commit comments

Comments
 (0)