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