21217: Strip leading/trailing space chars from incoming tokens.
[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 type KeepError struct {
21         HTTPCode int
22         ErrMsg   string
23 }
24
25 var (
26         BadRequestError     = &KeepError{400, "Bad Request"}
27         UnauthorizedError   = &KeepError{401, "Unauthorized"}
28         CollisionError      = &KeepError{500, "Collision"}
29         RequestHashError    = &KeepError{422, "Hash mismatch in request"}
30         PermissionError     = &KeepError{403, "Forbidden"}
31         DiskHashError       = &KeepError{500, "Hash mismatch in stored data"}
32         ExpiredError        = &KeepError{401, "Expired permission signature"}
33         NotFoundError       = &KeepError{404, "Not Found"}
34         VolumeBusyError     = &KeepError{503, "Volume backend busy"}
35         GenericError        = &KeepError{500, "Fail"}
36         FullError           = &KeepError{503, "Full"}
37         SizeRequiredError   = &KeepError{411, "Missing Content-Length"}
38         TooLongError        = &KeepError{413, "Block is too large"}
39         MethodDisabledError = &KeepError{405, "Method disabled"}
40         ErrNotImplemented   = &KeepError{500, "Unsupported configuration"}
41         ErrClientDisconnect = &KeepError{503, "Client disconnected"}
42 )
43
44 func (e *KeepError) Error() string {
45         return e.ErrMsg
46 }
47
48 // Periodically (once per interval) invoke EmptyTrash on all volumes.
49 func emptyTrash(mounts []*VolumeMount, interval time.Duration) {
50         for range time.NewTicker(interval).C {
51                 for _, v := range mounts {
52                         if v.KeepMount.AllowTrash {
53                                 v.EmptyTrash()
54                         }
55                 }
56         }
57 }