Skip to content

Commit a2a8803

Browse files
committed
db: avoid provider lookup when pacing file deletions
When deciding whether to pace a file deletion, avoid looking up the object in the objstorage provider. We now have an isLocal field readily available on the obsoleteFile.
1 parent 12c215c commit a2a8803

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

obsolete_files.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ type obsoleteFile struct {
6666
isLocal bool
6767
}
6868

69+
func (of *obsoleteFile) needsPacing() bool {
70+
// We only need to pace local objects--sstables and blob files.
71+
return of.isLocal && (of.fileType == base.FileTypeTable || of.fileType == base.FileTypeBlob)
72+
}
73+
6974
type cleanupJob struct {
7075
jobID JobID
7176
obsoleteFiles []obsoleteFile
@@ -126,7 +131,7 @@ func (cm *cleanupManager) EnqueueJob(jobID JobID, obsoleteFiles []obsoleteFile)
126131
// subject to the throttling rate which defeats the purpose.
127132
var pacingBytes uint64
128133
for _, of := range obsoleteFiles {
129-
if cm.needsPacing(of.fileType, of.fileNum) {
134+
if of.needsPacing() {
130135
pacingBytes += of.fileSize
131136
}
132137
}
@@ -168,11 +173,11 @@ func (cm *cleanupManager) mainLoop() {
168173
for _, of := range job.obsoleteFiles {
169174
switch of.fileType {
170175
case base.FileTypeTable:
171-
cm.maybePace(&tb, of.fileType, of.fileNum, of.fileSize)
176+
cm.maybePace(&tb, &of)
172177
cm.onTableDeleteFn(of.fileSize, of.isLocal)
173178
cm.deleteObsoleteObject(of.fileType, job.jobID, of.fileNum)
174179
case base.FileTypeBlob:
175-
cm.maybePace(&tb, of.fileType, of.fileNum, of.fileSize)
180+
cm.maybePace(&tb, &of)
176181
cm.deleteObsoleteObject(of.fileType, job.jobID, of.fileNum)
177182
default:
178183
cm.deleteObsoleteFile(of.fs, of.fileType, job.jobID, of.path, of.fileNum)
@@ -186,31 +191,14 @@ func (cm *cleanupManager) mainLoop() {
186191
}
187192
}
188193

189-
// fileNumIfSST is read iff fileType is fileTypeTable.
190-
func (cm *cleanupManager) needsPacing(fileType base.FileType, fileNumIfSST base.DiskFileNum) bool {
191-
if fileType != base.FileTypeTable && fileType != base.FileTypeBlob {
192-
return false
193-
}
194-
meta, err := cm.objProvider.Lookup(fileType, fileNumIfSST)
195-
if err != nil {
196-
// The object was already removed from the provider; we won't actually
197-
// delete anything, so we don't need to pace.
198-
return false
199-
}
200-
// Don't throttle deletion of remote objects.
201-
return !meta.IsRemote()
202-
}
203-
204194
// maybePace sleeps before deleting an object if appropriate. It is always
205195
// called from the background goroutine.
206-
func (cm *cleanupManager) maybePace(
207-
tb *tokenbucket.TokenBucket, fileType base.FileType, fileNum base.DiskFileNum, fileSize uint64,
208-
) {
209-
if !cm.needsPacing(fileType, fileNum) {
196+
func (cm *cleanupManager) maybePace(tb *tokenbucket.TokenBucket, of *obsoleteFile) {
197+
if !of.needsPacing() {
210198
return
211199
}
212200

213-
tokens := cm.deletePacer.PacingDelay(crtime.NowMono(), fileSize)
201+
tokens := cm.deletePacer.PacingDelay(crtime.NowMono(), of.fileSize)
214202
if tokens == 0.0 {
215203
// The token bucket might be in debt; it could make us wait even for 0
216204
// tokens. We don't want that if the pacer decided throttling should be
@@ -338,8 +326,8 @@ func (d *DB) onObsoleteTableDelete(fileSize uint64, isLocal bool) {
338326
d.mu.versions.metrics.Table.ObsoleteCount--
339327
d.mu.versions.metrics.Table.ObsoleteSize -= fileSize
340328
if isLocal {
341-
d.mu.versions.metrics.Table.Local.ObsoleteSize -= fileSize
342329
d.mu.versions.metrics.Table.Local.ObsoleteCount--
330+
d.mu.versions.metrics.Table.Local.ObsoleteSize -= fileSize
343331
}
344332
d.mu.Unlock()
345333
}

0 commit comments

Comments
 (0)