Merge branch 'master' into 3198-writable-fuse
[arvados.git] / services / keepstore / trash_worker.go
1 package main
2
3 import (
4         "log"
5         "time"
6 )
7
8 /*
9         Keepstore initiates trash worker channel goroutine.
10         The channel will process trash list.
11                 For each (next) trash request:
12       Delete the block indicated by the trash request Locator
13                 Repeat
14 */
15
16 func RunTrashWorker(trashq *WorkQueue) {
17         for item := range trashq.NextItem {
18                 trashRequest := item.(TrashRequest)
19                 TrashItem(trashRequest)
20         }
21 }
22
23 // TrashItem deletes the indicated block from every writable volume.
24 func TrashItem(trashRequest TrashRequest) {
25         reqMtime := time.Unix(trashRequest.BlockMtime, 0)
26         if time.Since(reqMtime) < blob_signature_ttl {
27                 log.Printf("WARNING: data manager asked to delete a %v old block %v (BlockMtime %d = %v), but my blob_signature_ttl is %v! Skipping.",
28                         time.Since(reqMtime),
29                         trashRequest.Locator,
30                         trashRequest.BlockMtime,
31                         reqMtime,
32                         blob_signature_ttl)
33                 return
34         }
35         for _, volume := range KeepVM.AllWritable() {
36                 mtime, err := volume.Mtime(trashRequest.Locator)
37                 if err != nil || trashRequest.BlockMtime != mtime.Unix() {
38                         continue
39                 }
40                 err = volume.Delete(trashRequest.Locator)
41                 if err != nil {
42                         log.Printf("%v Delete(%v): %v", volume, trashRequest.Locator, err)
43                         continue
44                 }
45                 log.Printf("%v Delete(%v) OK", volume, trashRequest.Locator)
46         }
47 }