1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.arvados.org/arvados.git/sdk/go/arvados"
12 "github.com/sirupsen/logrus"
15 // RunTrashWorker processes the trash request queue.
16 func RunTrashWorker(volmgr *RRVolumeManager, logger logrus.FieldLogger, cluster *arvados.Cluster, trashq *WorkQueue) {
17 for item := range trashq.NextItem {
18 trashRequest := item.(TrashRequest)
19 TrashItem(volmgr, logger, cluster, trashRequest)
20 trashq.DoneItem <- struct{}{}
24 // TrashItem deletes the indicated block from every writable volume.
25 func TrashItem(volmgr *RRVolumeManager, logger logrus.FieldLogger, cluster *arvados.Cluster, trashRequest TrashRequest) {
26 reqMtime := time.Unix(0, trashRequest.BlockMtime)
27 if time.Since(reqMtime) < cluster.Collections.BlobSigningTTL.Duration() {
28 logger.Warnf("client asked to delete a %v old block %v (BlockMtime %d = %v), but my blobSignatureTTL is %v! Skipping.",
29 arvados.Duration(time.Since(reqMtime)),
31 trashRequest.BlockMtime,
33 cluster.Collections.BlobSigningTTL)
37 var volumes []*VolumeMount
38 if uuid := trashRequest.MountUUID; uuid == "" {
39 volumes = volmgr.Mounts()
40 } else if mnt := volmgr.Lookup(uuid, false); mnt == nil {
41 logger.Warnf("trash request for nonexistent mount: %v", trashRequest)
43 } else if !mnt.KeepMount.AllowTrash {
44 logger.Warnf("trash request for mount with ReadOnly=true, AllowTrashWhenReadOnly=false: %v", trashRequest)
46 volumes = []*VolumeMount{mnt}
49 for _, volume := range volumes {
50 mtime, err := volume.Mtime(trashRequest.Locator)
52 logger.WithError(err).Errorf("%v Trash(%v)", volume, trashRequest.Locator)
55 if trashRequest.BlockMtime != mtime.UnixNano() {
56 logger.Infof("%v Trash(%v): stored mtime %v does not match trash list value %v; skipping", volume, trashRequest.Locator, mtime.UnixNano(), trashRequest.BlockMtime)
60 if !cluster.Collections.BlobTrash {
61 err = errors.New("skipping because Collections.BlobTrash is false")
63 err = volume.Trash(trashRequest.Locator)
67 logger.WithError(err).Errorf("%v Trash(%v)", volume, trashRequest.Locator)
69 logger.Infof("%v Trash(%v) OK", volume, trashRequest.Locator)