5562: Use static method. Fixes "TypeError: _socket_open() takes exactly 5 arguments...
[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.AllWritable() {
33                 mtime, err := volume.Mtime(trashRequest.Locator)
34                 if err != nil || trashRequest.BlockMtime != mtime.Unix() {
35                         continue
36                 }
37                 currentTime := time.Now().Unix()
38                 if time.Duration(currentTime-trashRequest.BlockMtime)*time.Second >= permission_ttl {
39                         err = volume.Delete(trashRequest.Locator)
40                 }
41         }
42         return
43 }