Skip to content

Commit

Permalink
db: rename fileBackings to virtualBackings
Browse files Browse the repository at this point in the history
Rename to clarify that this includes only backings for virtual
sstables.
  • Loading branch information
RaduBerinde committed Mar 6, 2024
1 parent 1e4eca5 commit b50ef87
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (d *DB) Checkpoint(
optionsFileNum := d.optionsFileNum

virtualBackingFiles := make(map[base.DiskFileNum]struct{})
d.mu.versions.fileBackings.ForEach(func(backing *fileBacking) {
d.mu.versions.virtualBackings.ForEach(func(backing *fileBacking) {
virtualBackingFiles[backing.DiskFileNum] = struct{}{}
})

Expand Down
2 changes: 1 addition & 1 deletion checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestCheckpoint(t *testing.T) {
d := dbs[td.CmdArgs[0].String()]
d.mu.Lock()
d.mu.versions.logLock()
fileNums := d.mu.versions.fileBackings.DiskFileNums()
fileNums := d.mu.versions.virtualBackings.DiskFileNums()
d.mu.versions.logUnlock()
d.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ func (d *DB) Metrics() *Metrics {

d.mu.versions.logLock()
metrics.private.manifestFileSize = uint64(d.mu.versions.manifest.Size())
backingCount, backingTotalSize := d.mu.versions.fileBackings.Stats()
backingCount, backingTotalSize := d.mu.versions.virtualBackings.Stats()
metrics.Table.BackingTableCount = uint64(backingCount)
metrics.Table.BackingTableSize = backingTotalSize
d.mu.versions.logUnlock()
Expand Down
27 changes: 13 additions & 14 deletions version_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ type versionSet struct {
// still referenced by an inuse iterator.
zombieTables map[base.DiskFileNum]uint64 // filenum -> size

// fileBackings contains the FileBackings with support virtual sstables in the
// latest version, sstables in the latest version. Once the file backing is
// backing no virtual sstables in the latest version, it is removed from this
// map and the corresponding state is added to the zombieTables map. Note that
// we don't keep track of file backings which support a virtual sstable which
// is not in the latest version.
// virtualBackings contains the FileBackings which support virtual sstables in
// the latest version. Once the file backing is backing no virtual sstables in
// the latest version, it is removed from this map and the corresponding state
// is added to the zombieTables map. Note that we don't keep track of file
// backings which support a virtual sstable which is not in the latest
// version.
//
// fileBackings is protected by the versionSet.logLock. It's populated
// during Open in versionSet.load, but it's not used concurrently during
// load.
fileBackings manifest.FileBackings
// virtualBackings is protected by the versionSet.logLock. It's populated
// during Open in versionSet.load, but it's not used concurrently during load.
virtualBackings manifest.FileBackings

// minUnflushedLogNum is the smallest WAL log file number corresponding to
// mutations that have not been flushed to an sstable.
Expand Down Expand Up @@ -135,7 +134,7 @@ func (vs *versionSet) init(
vs.versions.Init(mu)
vs.obsoleteFn = vs.addObsoleteLocked
vs.zombieTables = make(map[base.DiskFileNum]uint64)
vs.fileBackings = manifest.FileBackings{}
vs.virtualBackings = manifest.FileBackings{}
vs.nextFileNum = 1
vs.manifestMarker = marker
vs.getFormatMajorVersion = getFMV
Expand Down Expand Up @@ -287,11 +286,11 @@ func (vs *versionSet) load(
// Populate the fileBackingMap and the FileBacking for virtual sstables since
// we have finished version edit accumulation.
for _, s := range bve.AddedFileBacking {
vs.fileBackings.Add(s)
vs.virtualBackings.Add(s)
}

for _, diskFileNum := range bve.RemovedFileBacking {
vs.fileBackings.Remove(diskFileNum)
vs.virtualBackings.Remove(diskFileNum)
}

newVersion, err := bve.Apply(nil, opts.Comparer, opts.FlushSplitBytes,
Expand Down Expand Up @@ -485,7 +484,7 @@ func (vs *versionSet) logAndApply(
newVersion, zombies, err = manifest.AccumulateIncompleteAndApplySingleVE(
ve, currentVersion, vs.cmp,
vs.opts.FlushSplitBytes, vs.opts.Experimental.ReadCompactionRate,
&vs.fileBackings,
&vs.virtualBackings,
)
if err != nil {
return errors.Wrap(err, "MANIFEST apply failed")
Expand Down
18 changes: 9 additions & 9 deletions version_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func writeAndIngest(t *testing.T, mem vfs.FS, d *DB, k InternalKey, v []byte, fi
// d.mu should be help. logLock should not be held.
func checkBackingSize(t *testing.T, d *DB) {
d.mu.versions.logLock()
d.mu.versions.fileBackings.Check()
d.mu.versions.virtualBackings.Check()
d.mu.versions.logUnlock()
}

Expand Down Expand Up @@ -156,7 +156,7 @@ func TestLatestRefCounting(t *testing.T) {
// to the physical sstable.
require.Equal(t, 2, int(m1.LatestRefs()))
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, f.Size, m2.FileBacking.VirtualizedSize.Load())
checkBackingSize(t, d)

Expand All @@ -176,7 +176,7 @@ func TestLatestRefCounting(t *testing.T) {
require.Equal(t, 1, int(m2.LatestRefs()))
require.Equal(t, 0, len(d.mu.versions.zombieTables))
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, m2.Size, m2.FileBacking.VirtualizedSize.Load())
checkBackingSize(t, d)

Expand All @@ -193,7 +193,7 @@ func TestLatestRefCounting(t *testing.T) {
require.Equal(t, 1, int(m2.LatestRefs()))
require.Equal(t, 0, len(d.mu.versions.zombieTables))
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, m2.Size, m2.FileBacking.VirtualizedSize.Load())

// Delete m2 from L6.
Expand All @@ -208,7 +208,7 @@ func TestLatestRefCounting(t *testing.T) {
require.Equal(t, 0, int(m2.LatestRefs()))
require.Equal(t, 1, len(d.mu.versions.zombieTables))
require.Equal(t, f.Size, d.mu.versions.zombieTables[f.FileBacking.DiskFileNum])
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, 0, int(m2.FileBacking.VirtualizedSize.Load()))
checkBackingSize(t, d)
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestVirtualSSTableManifestReplay(t *testing.T) {

require.Equal(t, 2, int(m1.LatestRefs()))
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, f.Size, m2.FileBacking.VirtualizedSize.Load())

// Snapshot version edit will be written to a new manifest due to the flush.
Expand All @@ -356,7 +356,7 @@ func TestVirtualSSTableManifestReplay(t *testing.T) {

require.Equal(t, 2, int(virtualFile.LatestRefs()))
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{f.FileBacking.DiskFileNum}, d.mu.versions.virtualBackings.DiskFileNums())
require.Equal(t, f.Size, virtualFile.FileBacking.VirtualizedSize.Load())
checkBackingSize(t, d)
d.mu.Unlock()
Expand All @@ -376,7 +376,7 @@ func TestVirtualSSTableManifestReplay(t *testing.T) {
}
require.Nil(t, virtualFile)
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.virtualBackings.DiskFileNums())
checkBackingSize(t, d)
d.mu.Unlock()

Expand All @@ -397,7 +397,7 @@ func TestVirtualSSTableManifestReplay(t *testing.T) {
}
require.Nil(t, virtualFile)
require.Equal(t, 0, len(d.mu.versions.obsoleteTables))
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.fileBackings.DiskFileNums())
require.Equal(t, []base.DiskFileNum{}, d.mu.versions.virtualBackings.DiskFileNums())
checkBackingSize(t, d)
d.mu.Unlock()
require.NoError(t, d.Close())
Expand Down

0 comments on commit b50ef87

Please sign in to comment.