18870: Need to declare NODES as array
[arvados.git] / services / keepstore / keepstore.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package keepstore
6
7 import (
8         "time"
9 )
10
11 // BlockSize for a Keep "block" is 64MB.
12 const BlockSize = 64 * 1024 * 1024
13
14 // MinFreeKilobytes is the amount of space a Keep volume must have available
15 // in order to permit writes.
16 const MinFreeKilobytes = BlockSize / 1024
17
18 var bufs *bufferPool
19
20 // KeepError types.
21 //
22 type KeepError struct {
23         HTTPCode int
24         ErrMsg   string
25 }
26
27 var (
28         BadRequestError     = &KeepError{400, "Bad Request"}
29         UnauthorizedError   = &KeepError{401, "Unauthorized"}
30         CollisionError      = &KeepError{500, "Collision"}
31         RequestHashError    = &KeepError{422, "Hash mismatch in request"}
32         PermissionError     = &KeepError{403, "Forbidden"}
33         DiskHashError       = &KeepError{500, "Hash mismatch in stored data"}
34         ExpiredError        = &KeepError{401, "Expired permission signature"}
35         NotFoundError       = &KeepError{404, "Not Found"}
36         VolumeBusyError     = &KeepError{503, "Volume backend busy"}
37         GenericError        = &KeepError{500, "Fail"}
38         FullError           = &KeepError{503, "Full"}
39         SizeRequiredError   = &KeepError{411, "Missing Content-Length"}
40         TooLongError        = &KeepError{413, "Block is too large"}
41         MethodDisabledError = &KeepError{405, "Method disabled"}
42         ErrNotImplemented   = &KeepError{500, "Unsupported configuration"}
43         ErrClientDisconnect = &KeepError{503, "Client disconnected"}
44 )
45
46 func (e *KeepError) Error() string {
47         return e.ErrMsg
48 }
49
50 // Periodically (once per interval) invoke EmptyTrash on all volumes.
51 func emptyTrash(mounts []*VolumeMount, interval time.Duration) {
52         for range time.NewTicker(interval).C {
53                 for _, v := range mounts {
54                         v.EmptyTrash()
55                 }
56         }
57 }