Merge branch '8784-dir-listings'
[arvados.git] / services / keepstore / trash_worker.go
index d11bc05192246a75e8ba4c95bd544b0712279ff6..51fbb947917328e30db244ca841441a983d8bec5 100644 (file)
@@ -1,9 +1,15 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
        "errors"
-       "log"
        "time"
+
+       "git.curoverse.com/arvados.git/sdk/go/arvados"
+       log "github.com/Sirupsen/logrus"
 )
 
 // RunTrashWorker is used by Keepstore to initiate trash worker channel goroutine.
@@ -23,17 +29,27 @@ func RunTrashWorker(trashq *WorkQueue) {
 // TrashItem deletes the indicated block from every writable volume.
 func TrashItem(trashRequest TrashRequest) {
        reqMtime := time.Unix(0, trashRequest.BlockMtime)
-       if time.Since(reqMtime) < blobSignatureTTL {
+       if time.Since(reqMtime) < theConfig.BlobSignatureTTL.Duration() {
                log.Printf("WARNING: data manager asked to delete a %v old block %v (BlockMtime %d = %v), but my blobSignatureTTL is %v! Skipping.",
-                       time.Since(reqMtime),
+                       arvados.Duration(time.Since(reqMtime)),
                        trashRequest.Locator,
                        trashRequest.BlockMtime,
                        reqMtime,
-                       blobSignatureTTL)
+                       theConfig.BlobSignatureTTL)
+               return
+       }
+
+       var volumes []Volume
+       if uuid := trashRequest.MountUUID; uuid == "" {
+               volumes = KeepVM.AllWritable()
+       } else if v := KeepVM.Lookup(uuid, true); v == nil {
+               log.Printf("warning: trash request for nonexistent mount: %v", trashRequest)
                return
+       } else {
+               volumes = []Volume{v}
        }
 
-       for _, volume := range KeepVM.AllWritable() {
+       for _, volume := range volumes {
                mtime, err := volume.Mtime(trashRequest.Locator)
                if err != nil {
                        log.Printf("%v Delete(%v): %v", volume, trashRequest.Locator, err)
@@ -44,8 +60,8 @@ func TrashItem(trashRequest TrashRequest) {
                        continue
                }
 
-               if neverDelete {
-                       err = errors.New("did not delete block because neverDelete is true")
+               if !theConfig.EnableDelete {
+                       err = errors.New("did not delete block because EnableDelete is false")
                } else {
                        err = volume.Trash(trashRequest.Locator)
                }