/
storagemanager.go
136 lines (115 loc) · 6.12 KB
/
storagemanager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package modules
import (
"go.sia.tech/siad/crypto"
)
const (
// ContractManagerDir is the standard name used for the directory that
// contains all files directly related to the contract manager.
ContractManagerDir = "contractmanager"
// StorageManagerDir is standard name used for the directory that contains
// all of the storage manager files.
StorageManagerDir = "storagemanager"
)
type (
// StorageFolderMetadata contains metadata about a storage folder that is
// tracked by the storage folder manager.
StorageFolderMetadata struct {
Capacity uint64 `json:"capacity"` // bytes
CapacityRemaining uint64 `json:"capacityremaining"` // bytes
Index uint16 `json:"index"`
Path string `json:"path"`
// Below are statistics about the filesystem. FailedReads and
// FailedWrites are only incremented if the filesystem is returning
// errors when operations are being performed. A large number of
// FailedWrites can indicate that more space has been allocated on a
// drive than is physically available. A high number of failures can
// also indicate disk trouble.
FailedReads uint64 `json:"failedreads"`
FailedWrites uint64 `json:"failedwrites"`
SuccessfulReads uint64 `json:"successfulreads"`
SuccessfulWrites uint64 `json:"successfulwrites"`
// Certain operations on a storage folder can take a long time (Add,
// Remove, and Resize). The fields below indicate the progress of any
// long running operations that might be under way in the storage
// folder. Progress is always reported in bytes.
ProgressNumerator uint64
ProgressDenominator uint64
}
// A StorageManager is responsible for managing storage folders and
// sectors. Sectors are the base unit of storage that gets moved between
// renters and hosts, and primarily is stored on the hosts.
StorageManager interface {
Alerter
// AddSector will add a sector to the storage manager. If the sector
// already exists, a virtual sector will be added, meaning that the
// 'sectorData' will be ignored and no new disk space will be consumed.
// The expiry height is used to track what height the sector can be
// safely deleted at, though typically the host will manually delete
// the sector before the expiry height. The same sector can be added
// multiple times at different expiry heights, and the storage manager
// is expected to only store the data once.
AddSector(sectorRoot crypto.Hash, sectorData []byte) error
// HasSector indicates whether the contract manager stores a sector with
// a given root or not.
HasSector(crypto.Hash) bool
// AddSectorBatch is a performance optimization over AddSector when
// adding a bunch of virtual sectors. It is necessary because otherwise
// potentially thousands or even tens-of-thousands of fsync calls would
// need to be made in serial, which would prevent renters from ever
// successfully renewing.
AddSectorBatch(sectorRoots []crypto.Hash) error
// AddStorageFolder adds a storage folder to the manager. The manager
// may not check that there is enough space available on-disk to
// support as much storage as requested, though the manager should
// gracefully handle running out of storage unexpectedly.
AddStorageFolder(path string, size uint64) error
// The storage manager needs to be able to shut down.
Close() error
// DeleteSector deletes a sector, meaning that the manager will be
// unable to upload that sector and be unable to provide a storage
// proof on that sector. DeleteSector is for removing the data
// entirely, and will remove instances of the sector appearing at all
// heights. The primary purpose of DeleteSector is to comply with legal
// requests to remove data.
DeleteSector(sectorRoot crypto.Hash) error
// ReadSector will read a sector from the storage manager, returning the
// bytes that match the input sector root.
ReadSector(sectorRoot crypto.Hash) ([]byte, error)
// ReadPartialSector will read a sector from the storage manager,
// returning the bytes that match the input sector root.
ReadPartialSector(sectorRoot crypto.Hash, offset, length uint64) ([]byte, error)
// RemoveSector will remove a sector from the storage manager. The
// height at which the sector expires should be provided, so that the
// auto-expiry information for that sector can be properly updated.
RemoveSector(sectorRoot crypto.Hash) error
// MarkSectorsForRemoval is a non-ACID performance optimization to
// remove a ton of sectors from the host. Works around lockups in the
// WAL by batching sectors to be removed over a period of time instead
// of all at once.
MarkSectorsForRemoval(sectorRoots []crypto.Hash) error
// RemoveStorageFolder will remove a storage folder from the manager.
// All storage on the folder will be moved to other storage folders,
// meaning that no data will be lost. If the manager is unable to save
// data, an error will be returned and the operation will be stopped. If
// the force flag is set to true, errors will be ignored and the remove
// operation will be completed, meaning that data will be lost.
RemoveStorageFolder(index uint16, force bool) error
// ResetStorageFolderHealth will reset the health statistics on a
// storage folder.
ResetStorageFolderHealth(index uint16) error
// ResizeStorageFolder will grow or shrink a storage folder in the
// manager. The manager may not check that there is enough space
// on-disk to support growing the storage folder, but should gracefully
// handle running out of space unexpectedly. When shrinking a storage
// folder, any data in the folder that needs to be moved will be placed
// into other storage folders, meaning that no data will be lost. If
// the manager is unable to migrate the data, an error will be returned
// and the operation will be stopped. If the force flag is set to true,
// errors will be ignored and the resize operation completed, meaning
// that data will be lost.
ResizeStorageFolder(index uint16, newSize uint64, force bool) error
// StorageFolders will return a list of storage folders tracked by the
// manager.
StorageFolders() []StorageFolderMetadata
}
)