Skip to content

Commit 4140aa5

Browse files
committed
db: refactor obsolete, zombie file tracking
Add a zombieObjects type for tracking the lifecycle of zombie objects. Today this is used for zombie sstable objects. With the introduction of blob files (#112) we'll also need to track the lifecycle of zombie blob file objects. Additionally, refactor the lifecycle so that a file is considered either zombie or obsolete but not both. And avoid scanning the list of zombie objects on every call to Metrics, instead incrementally maintaining stats on the zombieObjects type.
1 parent 7682e17 commit 4140aa5

File tree

8 files changed

+218
-196
lines changed

8 files changed

+218
-196
lines changed

compaction.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ func (d *DB) cleanupVersionEdit(ve *versionEdit) {
24062406
// Add this file to zombie tables as well, as the versionSet
24072407
// asserts on whether every obsolete file was at one point
24082408
// marked zombie.
2409-
d.mu.versions.zombieTables[of.DiskFileNum] = objectInfo{
2409+
d.mu.versions.zombieTables.Add(objectInfo{
24102410
fileInfo: fileInfo{
24112411
FileNum: of.DiskFileNum,
24122412
FileSize: of.Size,
@@ -2417,7 +2417,7 @@ func (d *DB) cleanupVersionEdit(ve *versionEdit) {
24172417
// disaggregated storage; if this becomes the norm, we should do
24182418
// an objprovider lookup here.
24192419
isLocal: true,
2420-
}
2420+
})
24212421
}
24222422
d.mu.versions.addObsoleteLocked(obsoleteFiles)
24232423
}
@@ -3019,13 +3019,7 @@ func (d *DB) runCompaction(
30193019
// Add this file to zombie tables as well, as the versionSet
30203020
// asserts on whether every obsolete file was at one point
30213021
// marked zombie.
3022-
d.mu.versions.zombieTables[backing.DiskFileNum] = objectInfo{
3023-
fileInfo: fileInfo{
3024-
FileNum: backing.DiskFileNum,
3025-
FileSize: backing.Size,
3026-
},
3027-
isLocal: true,
3028-
}
3022+
d.mu.versions.zombieTables.AddMetadata(&result.Tables[i].ObjMeta, backing.Size)
30293023
}
30303024
d.mu.versions.addObsoleteLocked(obsoleteFiles)
30313025
d.mu.Unlock()

db.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ func (d *DB) Close() error {
16441644
if err := d.closed.Load(); err != nil {
16451645
panic(err)
16461646
}
1647+
d.compactionSchedulers.Wait()
16471648
// Compactions can be asynchronously started by the CompactionScheduler
16481649
// calling d.Schedule. When this Unregister returns, we know that the
16491650
// CompactionScheduler will never again call a method on the DB. Note that
@@ -1753,7 +1754,6 @@ func (d *DB) Close() error {
17531754
}
17541755

17551756
d.mu.Unlock()
1756-
d.compactionSchedulers.Wait()
17571757

17581758
// Wait for all cleaning jobs to finish.
17591759
d.cleanupManager.Close()
@@ -1771,7 +1771,7 @@ func (d *DB) Close() error {
17711771

17721772
// As a sanity check, ensure that there are no zombie tables. A non-zero count
17731773
// hints at a reference count leak.
1774-
if ztbls := len(d.mu.versions.zombieTables); ztbls > 0 {
1774+
if ztbls := d.mu.versions.zombieTables.Count(); ztbls > 0 {
17751775
err = firstError(err, errors.Errorf("non-zero zombie file count: %d", ztbls))
17761776
}
17771777

@@ -2041,13 +2041,9 @@ func (d *DB) Metrics() *Metrics {
20412041
metrics.Levels[level].Score = score
20422042
}
20432043
}
2044-
metrics.Table.ZombieCount = int64(len(d.mu.versions.zombieTables))
2045-
for _, info := range d.mu.versions.zombieTables {
2046-
metrics.Table.ZombieSize += info.FileSize
2047-
if info.isLocal {
2048-
metrics.Table.Local.ZombieSize += info.FileSize
2049-
}
2050-
}
2044+
metrics.Table.ZombieCount = int64(d.mu.versions.zombieTables.Count())
2045+
metrics.Table.ZombieSize = d.mu.versions.zombieTables.TotalSize()
2046+
metrics.Table.Local.ZombieSize = d.mu.versions.zombieTables.LocalSize()
20512047
metrics.private.optionsFileSize = d.optionsFileSize
20522048

20532049
// TODO(jackson): Consider making these metrics optional.

0 commit comments

Comments
 (0)