Skip to content

Commit e26ec98

Browse files
committed
sstable/blob: track MVCCGarbageBytes in FileWriterStats
We now track the amount of uncompressed, likely MVCC garbage bytes in our `FileWriterStats`.
1 parent ef31c6c commit e26ec98

File tree

9 files changed

+24
-18
lines changed

9 files changed

+24
-18
lines changed

blob_rewrite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func TestBlobRewriteRandomized(t *testing.T) {
270270
if rng.IntN(20) == 0 {
271271
blobWriter.FlushForTesting()
272272
}
273-
handles[i] = blobWriter.AddValue(values[i])
273+
handles[i] = blobWriter.AddValue(values[i], false /* isLikelyMVCCGarbage */)
274274
}
275275
stats, err := blobWriter.Close()
276276
require.NoError(t, err)

file_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (t *fileCacheTest) newTestHandle() (*fileCacheHandle, *fileCacheTestFS) {
239239
t.Fatal(err)
240240
}
241241
bw := blob.NewFileWriter(fn, w, blob.FileWriterOptions{})
242-
_ = bw.AddValue(xxx[:fn])
242+
_ = bw.AddValue(xxx[:fn], false /* isLikelyMVCCGarbage */)
243243
if _, err := bw.Close(); err != nil {
244244
t.Fatal(err)
245245
}

internal/blobtest/handles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ func (bv *Values) WriteFiles(
261261
BlockID: handle.BlockID,
262262
ValueID: blob.BlockValueID(prevID),
263263
ValueLen: 12,
264-
}))
264+
}), false /* isLikelyMVCCGarbage */)
265265
prevID++
266266
}
267267

268268
if value, ok := bv.trackedHandles[handle]; ok {
269-
writer.AddValue([]byte(value))
269+
writer.AddValue([]byte(value), false /* isLikelyMVCCGarbage */)
270270
} else {
271-
writer.AddValue(deriveValueFromHandle(handle))
271+
writer.AddValue(deriveValueFromHandle(handle), false /* isLikelyMVCCGarbage */)
272272
}
273273
}
274274
fileStats, err := writer.Close()

sstable/blob/blob.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"sync"
1313

14+
"github.com/cockroachdb/crlib/crhumanize"
1415
"github.com/cockroachdb/errors"
1516
"github.com/cockroachdb/pebble/internal/base"
1617
"github.com/cockroachdb/pebble/internal/crc"
@@ -125,13 +126,14 @@ type FileWriterStats struct {
125126
UncompressedValueBytes uint64
126127
FileLen uint64
127128
Properties FileProperties
129+
MVCCGarbageBytes uint64
128130
}
129131

130132
// String implements the fmt.Stringer interface.
131133
func (s FileWriterStats) String() string {
132134
var buf bytes.Buffer
133-
fmt.Fprintf(&buf, "{BlockCount: %d, ValueCount: %d, UncompressedValueBytes: %d, FileLen: %d}",
134-
s.BlockCount, s.ValueCount, s.UncompressedValueBytes, s.FileLen)
135+
fmt.Fprintf(&buf, "{BlockCount: %d, ValueCount: %d, UncompressedValueBytes: %d (%s MVCCGarbage), FileLen: %d}",
136+
s.BlockCount, s.ValueCount, s.UncompressedValueBytes, crhumanize.Percent(s.MVCCGarbageBytes, s.UncompressedValueBytes), s.FileLen)
135137
return buf.String()
136138
}
137139

@@ -187,14 +189,17 @@ var writerPool = sync.Pool{
187189

188190
// AddValue adds the provided value to the blob file, returning a Handle
189191
// identifying the location of the value.
190-
func (w *FileWriter) AddValue(v []byte) Handle {
192+
func (w *FileWriter) AddValue(v []byte, isLikelyMVCCGarbage bool) Handle {
191193
// Determine if we should first flush the block.
192194
if sz := w.valuesEncoder.size(); w.flushGov.ShouldFlush(sz, sz+len(v)) {
193195
w.flush()
194196
}
195197
valuesInBlock := w.valuesEncoder.Count()
196198
w.stats.ValueCount++
197199
w.stats.UncompressedValueBytes += uint64(len(v))
200+
if isLikelyMVCCGarbage {
201+
w.stats.MVCCGarbageBytes += uint64(len(v))
202+
}
198203
w.valuesEncoder.AddValue(v)
199204
return Handle{
200205
BlobFileID: base.BlobFileID(w.fileNum),

sstable/blob/blob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestBlobWriter(t *testing.T) {
3232
obj = &objstorage.MemObj{}
3333
w := NewFileWriter(000001, obj, opts)
3434
for _, l := range crstrings.Lines(td.Input) {
35-
h := w.AddValue([]byte(l))
35+
h := w.AddValue([]byte(l), false /* isLikelyMVCCGarbage */)
3636
fmt.Fprintf(&buf, "%-25s: %q\n", h, l)
3737
}
3838
stats, err := w.Close()
@@ -55,7 +55,7 @@ func TestBlobWriter(t *testing.T) {
5555
w.beginNewVirtualBlock(BlockID(vBlockID))
5656
vBlockID++
5757
default:
58-
h := w.AddValue([]byte(l))
58+
h := w.AddValue([]byte(l), false /* isLikelyMVCCGarbage */)
5959
fmt.Fprintf(&buf, "%-25s: %q\n", h, l)
6060
}
6161
}

sstable/blob/fetcher_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestValueFetcher(t *testing.T) {
9999
obj := &objstorage.MemObj{}
100100
w := NewFileWriter(base.DiskFileNum(fileNum), obj, opts)
101101
for _, l := range crstrings.Lines(td.Input) {
102-
h := w.AddValue([]byte(l))
102+
h := w.AddValue([]byte(l), false /* isLikelyMVCCGarbage */)
103103
fmt.Fprintf(&buf, "%-25s: %q\n", h, l)
104104
}
105105
stats, err := w.Close()
@@ -191,7 +191,7 @@ func TestValueFetcherRetrieveRandomized(t *testing.T) {
191191
for v := 4 << 20; v > 0; {
192192
n := testutils.RandIntInRange(rng, 1, 4096)
193193
val := testutils.RandBytes(rng, n)
194-
h := w.AddValue(val)
194+
h := w.AddValue(val, false /* isLikelyMVCCGarbage */)
195195
handles = append(handles, h)
196196
values = append(values, val)
197197
v -= n
@@ -269,7 +269,7 @@ func benchmarkValueFetcherRetrieve(b *testing.B, valueSize int, cacheSize int64)
269269
var handles []Handle
270270
for v := valueSize; v > 0; {
271271
n := testutils.RandIntInRange(rng, 1, 4096)
272-
h := w.AddValue(testutils.RandBytes(rng, n))
272+
h := w.AddValue(testutils.RandBytes(rng, n), false /* isLikelyMVCCGarbage */)
273273
handles = append(handles, h)
274274
v -= n
275275
}

testdata/blob_rewrite

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ close-output
2424
# sync-data: 000002.blob
2525
# close: 000002.blob
2626
Blob file created: 000002 size:[105 (105B)] vals:[15 (15B)]
27-
{BlockCount: 1, ValueCount: 2, UncompressedValueBytes: 15, FileLen: 105}
27+
{BlockCount: 1, ValueCount: 2, UncompressedValueBytes: 15 (0% MVCCGarbage), FileLen: 105}
2828
blobrefs:[
2929
0: B000002 15
3030
]
@@ -76,4 +76,4 @@ rewrite-blob 000002 000001 000003
7676
Successfully rewrote blob file 000002 to 000004
7777
Input SSTables: [000001 000003]
7878
SSTables with blob references: 2
79-
{BlockCount: 1, ValueCount: 2, UncompressedValueBytes: 15, FileLen: 106}
79+
{BlockCount: 1, ValueCount: 2, UncompressedValueBytes: 15 (0% MVCCGarbage), FileLen: 106}

testdata/value_separation_policy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ close-output
4848
# sync-data: 000002.blob
4949
# close: 000002.blob
5050
Blob file created: 000002 size:[120 (120B)] vals:[29 (29B)]
51-
{BlockCount: 1, ValueCount: 3, UncompressedValueBytes: 29, FileLen: 120}
51+
{BlockCount: 1, ValueCount: 3, UncompressedValueBytes: 29 (0% MVCCGarbage), FileLen: 120}
5252
blobrefs:[
5353
0: B000002 29
5454
]

value_separation.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (vs *writeNewBlobFiles) Add(
296296
}
297297

298298
// Append the value to the blob file.
299-
handle := vs.writer.AddValue(v)
299+
handle := vs.writer.AddValue(v, isLikelyMVCCGarbage)
300300

301301
// Write the key and the handle to the sstable. We need to map the
302302
// blob.Handle into a blob.InlineHandle. Everything is copied verbatim,
@@ -341,7 +341,8 @@ func (vs *writeNewBlobFiles) FinishOutput() (compact.ValueSeparationMetadata, er
341341

342342
return compact.ValueSeparationMetadata{
343343
BlobReferences: manifest.BlobReferences{
344-
manifest.MakeBlobReference(base.BlobFileID(vs.objMeta.DiskFileNum), stats.UncompressedValueBytes, stats.UncompressedValueBytes, meta),
344+
manifest.MakeBlobReference(base.BlobFileID(vs.objMeta.DiskFileNum),
345+
stats.UncompressedValueBytes, stats.UncompressedValueBytes, meta),
345346
},
346347
BlobReferenceSize: stats.UncompressedValueBytes,
347348
BlobReferenceDepth: 1,

0 commit comments

Comments
 (0)