X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7faa4aa742a7562c75e2fc2cabc7bf2ea8e856a8..8a2c490a3905dc85a438ea92aa5b020a87d7b8b0:/services/keepstore/trash_worker.go diff --git a/services/keepstore/trash_worker.go b/services/keepstore/trash_worker.go index 62f63d57c8..8a9fedfb70 100644 --- a/services/keepstore/trash_worker.go +++ b/services/keepstore/trash_worker.go @@ -1,9 +1,14 @@ +// 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" ) // RunTrashWorker is used by Keepstore to initiate trash worker channel goroutine. @@ -22,38 +27,48 @@ func RunTrashWorker(trashq *WorkQueue) { // TrashItem deletes the indicated block from every writable volume. func TrashItem(trashRequest TrashRequest) { - reqMtime := time.Unix(trashRequest.BlockMtime, 0) - if time.Since(reqMtime) < blobSignatureTTL { + reqMtime := time.Unix(0, trashRequest.BlockMtime) + 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) + log.Printf("%v Trash(%v): %v", volume, trashRequest.Locator, err) continue } - if trashRequest.BlockMtime != mtime.Unix() { - log.Printf("%v Delete(%v): mtime on volume is %v does not match trash list value %v", volume, trashRequest.Locator, mtime.Unix(), trashRequest.BlockMtime) + if trashRequest.BlockMtime != mtime.UnixNano() { + log.Printf("%v Trash(%v): stored mtime %v does not match trash list value %v", volume, trashRequest.Locator, mtime.UnixNano(), trashRequest.BlockMtime) continue } - if neverDelete { - err = errors.New("did not delete block because neverDelete is true") + if !theConfig.EnableDelete { + err = errors.New("skipping because EnableDelete is false") } else { err = volume.Trash(trashRequest.Locator) } if err != nil { - log.Printf("%v Delete(%v): %v", volume, trashRequest.Locator, err) + log.Printf("%v Trash(%v): %v", volume, trashRequest.Locator, err) } else { - log.Printf("%v Delete(%v) OK", volume, trashRequest.Locator) + log.Printf("%v Trash(%v) OK", volume, trashRequest.Locator) } } }