Skip to content

Commit e39a868

Browse files
committed
compact: remove allocation from closure
cockroachdb/cockroach#152355 (comment)
1 parent 36f982a commit e39a868

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

blob_rewrite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestBlobRewrite(t *testing.T) {
120120
} else {
121121
ikv.V = base.MakeInPlaceValue([]byte(parts[1]))
122122
}
123-
require.NoError(t, vs.Add(tw, &ikv, false /* forceObsolete */, func() bool { return false } /* isLikeyMVCCGarbage */))
123+
require.NoError(t, vs.Add(tw, &ikv, false /* forceObsolete */, false /* isLikeyMVCCGarbage */))
124124
}
125125
return buf.String()
126126
case "close-output":

internal/compact/run.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ type ValueSeparation interface {
133133
EstimatedReferenceSize() uint64
134134
// Add adds the provided key-value pair to the provided sstable writer,
135135
// possibly separating the value into a blob file.
136-
Add(tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, isLikelyMVCCGarbage func() bool) error
136+
Add(tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, isLikelyMVCCGarbage bool) error
137137
// FinishOutput is called when a compaction is finishing an output sstable.
138138
// It returns the table's blob references, which will be added to the
139139
// table's TableMetadata, and stats and metadata describing a newly
@@ -335,9 +335,7 @@ func (r *Runner) writeKeysToTable(
335335
}
336336

337337
valueLen := kv.V.Len()
338-
isLikelyMVCCGarbage := func() bool {
339-
return sstable.IsLikelyMVCCGarbage(kv.K.UserKey, prevKeyKind, kv.K.Kind(), valueLen, prefixEqual)
340-
}
338+
isLikelyMVCCGarbage := sstable.IsLikelyMVCCGarbage(kv.K.UserKey, prevKeyKind, kv.K.Kind(), valueLen, prefixEqual)
341339
// Add the value to the sstable, possibly separating its value into a
342340
// blob file. The ValueSeparation implementation is responsible for
343341
// writing the KV to the sstable.
@@ -508,7 +506,7 @@ func (NeverSeparateValues) EstimatedReferenceSize() uint64 { return 0 }
508506

509507
// Add implements the ValueSeparation interface.
510508
func (NeverSeparateValues) Add(
511-
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ func() bool,
509+
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ bool,
512510
) error {
513511
v, _, err := kv.Value(nil)
514512
if err != nil {

value_separation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (vs *writeNewBlobFiles) EstimatedReferenceSize() uint64 {
236236
// Add adds the provided key-value pair to the sstable, possibly separating the
237237
// value into a blob file.
238238
func (vs *writeNewBlobFiles) Add(
239-
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, isLikelyMVCCGarbage func() bool,
239+
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, isLikelyMVCCGarbage bool,
240240
) error {
241241
// We always fetch the value if we're rewriting blob files. We want to
242242
// replace any references to existing blob files with references to new blob
@@ -251,7 +251,7 @@ func (vs *writeNewBlobFiles) Add(
251251

252252
// Values that are too small are never separated; however, MVCC keys are
253253
// separated if they are a SET key kind, as long as the value is not empty.
254-
if len(v) < vs.minimumSize && !isLikelyMVCCGarbage() {
254+
if len(v) < vs.minimumSize && !isLikelyMVCCGarbage {
255255
return tw.Add(kv.K, v, forceObsolete)
256256
}
257257

@@ -410,7 +410,7 @@ func (vs *preserveBlobReferences) EstimatedReferenceSize() uint64 {
410410
// Add implements compact.ValueSeparation. This implementation will write
411411
// existing blob references to the output table.
412412
func (vs *preserveBlobReferences) Add(
413-
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ func() bool,
413+
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ bool,
414414
) error {
415415
if !kv.V.IsBlobValueHandle() {
416416
// If the value is not already a blob handle (either it's in-place or in

value_separation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestValueSeparationPolicy(t *testing.T) {
129129
} else {
130130
ikv.V = base.MakeInPlaceValue([]byte(parts[1]))
131131
}
132-
require.NoError(t, vs.Add(tw, &ikv, false /* forceObsolete */, func() bool { return false } /* isLikelyMVCCGarbage */))
132+
require.NoError(t, vs.Add(tw, &ikv, false /* forceObsolete */, false /* isLikelyMVCCGarbage */))
133133
}
134134
return buf.String()
135135
case "estimated-sizes":
@@ -225,7 +225,7 @@ func (vs *defineDBValueSeparator) EstimatedReferenceSize() uint64 {
225225
// Add adds the provided key-value pair to the sstable, possibly separating the
226226
// value into a blob file.
227227
func (vs *defineDBValueSeparator) Add(
228-
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ func() bool,
228+
tw sstable.RawWriter, kv *base.InternalKV, forceObsolete bool, _ bool,
229229
) error {
230230
// In datadriven tests, all defined values are in-place initially. See
231231
// runDBDefineCmdReuseFS.
@@ -261,7 +261,7 @@ func (vs *defineDBValueSeparator) Add(
261261
// Return a KV that uses the original key but our constructed blob reference.
262262
vs.kv.K = kv.K
263263
vs.kv.V = iv
264-
return vs.pbr.Add(tw, &vs.kv, forceObsolete, func() bool { return false } /* isLikelyMVCCGarbage */)
264+
return vs.pbr.Add(tw, &vs.kv, forceObsolete, false /* isLikelyMVCCGarbage */)
265265
}
266266

267267
// FinishOutput implements compact.ValueSeparation.

0 commit comments

Comments
 (0)