Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: call Sync after deletion threshold #3122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type DeleteCleaner = base.DeleteCleaner
type ArchiveCleaner = base.ArchiveCleaner

type cleanupManager struct {
opts *Options
objProvider objstorage.Provider
onTableDeleteFn func(fileSize uint64)
deletePacer *deletionPacer
opts *Options
objProvider objstorage.Provider
onTableDeleteFn func(fileSize uint64)
deletePacer *deletionPacer
deletedFileSizePendingSync uint64

// jobsCh is used as the cleanup job queue.
jobsCh chan *cleanupJob
Expand Down Expand Up @@ -160,7 +161,7 @@ func (cm *cleanupManager) mainLoop() {
} else {
cm.maybePace(&tb, of.fileType, of.fileNum, of.fileSize)
cm.onTableDeleteFn(of.fileSize)
cm.deleteObsoleteObject(fileTypeTable, job.jobID, of.fileNum)
cm.deleteObsoleteObjectAndSyncIfRequired(job.jobID, of.fileNum, of.fileSize)
}
}
cm.mu.Lock()
Expand All @@ -171,6 +172,24 @@ func (cm *cleanupManager) mainLoop() {
}
}

func (cm *cleanupManager) deleteObsoleteObjectAndSyncIfRequired(jobID int, fileNum base.DiskFileNum, fileSize uint64) {
var deleteThresholdForSync uint64 = 64 * 1024 * 1024 // 64 MB

deleted := cm.deleteObsoleteObject(fileTypeTable, jobID, fileNum)
if !deleted {
return
}

cm.deletedFileSizePendingSync += fileSize
if cm.deletedFileSizePendingSync < deleteThresholdForSync {
return
}

if err := cm.objProvider.Sync(); err == nil {
cm.deletedFileSizePendingSync = 0
}
}

func (cm *cleanupManager) needsPacing(fileType base.FileType, fileNum base.DiskFileNum) bool {
if fileType != fileTypeTable {
return false
Expand Down Expand Up @@ -245,7 +264,7 @@ func (cm *cleanupManager) deleteObsoleteFile(

func (cm *cleanupManager) deleteObsoleteObject(
fileType fileType, jobID int, fileNum base.DiskFileNum,
) {
) bool {
if fileType != fileTypeTable {
panic("not an object")
}
Expand All @@ -258,8 +277,9 @@ func (cm *cleanupManager) deleteObsoleteObject(
path = cm.objProvider.Path(meta)
err = cm.objProvider.Remove(fileType, fileNum)
}

if cm.objProvider.IsNotExistError(err) {
return
return false
}

switch fileType {
Expand All @@ -271,6 +291,7 @@ func (cm *cleanupManager) deleteObsoleteObject(
Err: err,
})
}
return true
}

// maybeLogLocked issues a log if the job queue gets 75% full and issues a log
Expand Down
16 changes: 13 additions & 3 deletions cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package pebble
import (
"fmt"
"sort"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -119,12 +120,21 @@ func TestCleaner(t *testing.T) {
return memLog.String()

case "create-bogus-file":
if len(td.CmdArgs) != 1 {
return "create-bogus-file <db/file>"
if len(td.CmdArgs) < 1 {
return "create-bogus-file <db/file> [size]"
}
dst, err := fs.Create(td.CmdArgs[0].String())
require.NoError(t, err)
_, err = dst.Write([]byte("bogus data"))
var byteStream []byte
if len(td.CmdArgs) == 2 {
num, err := strconv.Atoi(td.CmdArgs[1].String())
require.NoError(t, err)
byteStream = make([]byte, num)
} else {
byteStream = []byte("bogus data")
}

_, err = dst.Write(byteStream)
require.NoError(t, err)
require.NoError(t, dst.Sync())
require.NoError(t, dst.Close())
Expand Down
3 changes: 2 additions & 1 deletion testdata/cleaner
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ create: db1/000123.sst
sync: db1/000123.sst
close: db1/000123.sst

create-bogus-file db1/000456.sst
create-bogus-file db1/000456.sst 100000000
----
create: db1/000456.sst
sync: db1/000456.sst
Expand Down Expand Up @@ -231,6 +231,7 @@ remove: db1_wal/000002.log
remove: db1_wal/000004.log
remove: db1/000123.sst
remove: db1/000456.sst
sync: db1
remove: db1/OPTIONS-000003

list db1
Expand Down
Loading