5414: Do not blow up if local config file is empty.
[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         nextItem := trashq.NextItem
18         for item := range nextItem {
19                 trashRequest := item.(TrashRequest)
20                 err := TrashItem(trashRequest)
21                 if err != nil {
22                         log.Printf("Trash request error for %s: %s", trashRequest, err)
23                 }
24         }
25 }
26
27 /*
28         Delete the block indicated by the Locator in TrashRequest.
29 */
30 func TrashItem(trashRequest TrashRequest) (err error) {
31         // Verify if the block is to be deleted based on its Mtime
32         for _, volume := range KeepVM.Volumes() {
33                 mtime, err := volume.Mtime(trashRequest.Locator)
34                 if err == nil {
35                         if trashRequest.BlockMtime == mtime.Unix() {
36                                 currentTime := time.Now().Unix()
37                                 if time.Duration(currentTime-trashRequest.BlockMtime)*time.Second >= permission_ttl {
38                                         err = volume.Delete(trashRequest.Locator)
39                                 }
40                         }
41                 }
42         }
43         return
44 }