X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f4ca9ad94a6bb006d1f3c7ba207837f1736d1247..3c88abd3cb33cbe80bb81a7cca779fe668036c9e:/services/keepstore/keepstore.go diff --git a/services/keepstore/keepstore.go b/services/keepstore/keepstore.go index 3850e993fc..b17cc79e17 100644 --- a/services/keepstore/keepstore.go +++ b/services/keepstore/keepstore.go @@ -57,8 +57,14 @@ var neverDelete = true // trashLifetime is the time duration after a block is trashed // during which it can be recovered using an /untrash request +// Use 10s or 10m or 10h to set as 10 seconds or minutes or hours respectively. var trashLifetime time.Duration +// trashCheckInterval is the time duration at which the emptyTrash goroutine +// will check and delete expired trashed blocks. Default is one day. +// Use 10s or 10m or 10h to set as 10 seconds or minutes or hours respectively. +var trashCheckInterval time.Duration + var maxBuffers = 128 var bufs *bufferPool @@ -183,7 +189,7 @@ func main() { &permissionTTLSec, "blob-signature-ttl", int(time.Duration(2*7*24*time.Hour).Seconds()), - "Lifetime of blob permission signatures. "+ + "Lifetime of blob permission signatures. Modifying the ttl will invalidate all existing signatures. "+ "See services/api/config/application.default.yml.") flag.BoolVar( &flagSerializeIO, @@ -209,7 +215,12 @@ func main() { &trashLifetime, "trash-lifetime", 0*time.Second, - "Interval after a block is trashed during which it can be recovered using an /untrash request") + "Time duration after a block is trashed during which it can be recovered using an /untrash request") + flag.DurationVar( + &trashCheckInterval, + "trash-check-interval", + 24*time.Hour, + "Time duration at which the emptyTrash goroutine will check and delete expired trashed blocks. Default is one day.") flag.Parse() @@ -321,12 +332,17 @@ func main() { trashq = NewWorkQueue() go RunTrashWorker(trashq) + // Start emptyTrash goroutine + doneEmptyingTrash := make(chan bool) + go emptyTrash(doneEmptyingTrash, trashCheckInterval) + // Shut down the server gracefully (by closing the listener) // if SIGTERM is received. term := make(chan os.Signal, 1) go func(sig <-chan os.Signal) { s := <-sig log.Println("caught signal:", s) + doneEmptyingTrash <- true listener.Close() }(term) signal.Notify(term, syscall.SIGTERM) @@ -336,3 +352,22 @@ func main() { srv := &http.Server{Addr: listen} srv.Serve(listener) } + +// At every trashCheckInterval tick, invoke EmptyTrash on all volumes. +func emptyTrash(doneEmptyingTrash chan bool, trashCheckInterval time.Duration) { + ticker := time.NewTicker(trashCheckInterval) + + for { + select { + case <-ticker.C: + for _, v := range volumes { + if v.Writable() { + v.EmptyTrash() + } + } + case <-doneEmptyingTrash: + ticker.Stop() + return + } + } +}