github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/storagemanager.go (about)

     1  package modules
     2  
     3  import (
     4  	"github.com/NebulousLabs/Sia/crypto"
     5  	"github.com/NebulousLabs/Sia/types"
     6  )
     7  
     8  const (
     9  	// StorageManagerDir is standard name used for the directory that contains
    10  	// all of the storage manager files.
    11  	StorageManagerDir = "storagemanager"
    12  )
    13  
    14  type (
    15  	// StorageFolderMetadata contains metadata about a storage folder that is
    16  	// tracked by the storage folder manager.
    17  	StorageFolderMetadata struct {
    18  		Capacity          uint64 `json:"capacity"`
    19  		CapacityRemaining uint64 `json:"capacityremaining"`
    20  		Path              string `json:"path"`
    21  
    22  		// Below are statistics about the filesystem. FailedReads and
    23  		// FailedWrites are only incremented if the filesystem is returning
    24  		// errors when operations are being performed. A large number of
    25  		// FailedWrites can indicate that more space has been allocated on a
    26  		// drive than is physically available. A high number of failures can
    27  		// also indicaate disk trouble.
    28  		FailedReads      uint64 `json:"failedreads"`
    29  		FailedWrites     uint64 `json:"failedwrites"`
    30  		SuccessfulReads  uint64 `json:"successfulreads"`
    31  		SuccessfulWrites uint64 `json:"successfulwrites"`
    32  	}
    33  
    34  	// A StorageManager is responsible for managing storage folders and
    35  	// sectors. Sectors are the base unit of storage that gets moved between
    36  	// renters and hosts, and primarily is stored on the hosts.
    37  	StorageManager interface {
    38  		// AddSector will add a sector to the storage manager. If the sector
    39  		// already exists, a virtual sector will be added, meaning that the
    40  		// 'sectorData' will be ignored and no new disk space will be consumed.
    41  		// The expiry height is used to track what height the sector can be
    42  		// safely deleted at, though typically the host will manually delete
    43  		// the sector before the expiry height. The same sector can be added
    44  		// multiple times at different expiry heights, and the storage manager
    45  		// is expected to only store the data once.
    46  		AddSector(sectorRoot crypto.Hash, expiryHeight types.BlockHeight, sectorData []byte) error
    47  
    48  		// AddStorageFolder adds a storage folder to the manager. The manager
    49  		// may not check that there is enough space available on-disk to
    50  		// support as much storage as requested, though the manager should
    51  		// gracefully handle running out of storage unexpectedly.
    52  		AddStorageFolder(path string, size uint64) error
    53  
    54  		// The storage manager needs to be able to shut down.
    55  		Close() error
    56  
    57  		// DeleteSector deletes a sector, meaning that the manager will be
    58  		// unable to upload that sector and be unable to provide a storage
    59  		// proof on that sector. DeleteSector is for removing the data
    60  		// entirely, and will remove instances of the sector appearing at all
    61  		// heights. The primary purpose of DeleteSector is to comply with legal
    62  		// requests to remove data.
    63  		DeleteSector(sectorRoot crypto.Hash) error
    64  
    65  		// ReadSector will read a sector from the storage manager, returning the
    66  		// bytes that match the input sector root.
    67  		ReadSector(sectorRoot crypto.Hash) ([]byte, error)
    68  
    69  		// RemoveSector will remove a sector from the storage manager. The
    70  		// height at which the sector expires should be provided, so that the
    71  		// auto-expiry information for that sector can be properly updated.
    72  		RemoveSector(sectorRoot crypto.Hash, expiryHeight types.BlockHeight) error
    73  
    74  		// RemoveStorageFolder will remove a storage folder from the manager.
    75  		// All storage on the folder will be moved to other storage folders,
    76  		// meaning that no data will be lost. If the manager is unable to save
    77  		// data, an error will be returned and the operation will be stopped.
    78  		RemoveStorageFolder(index int, force bool) error
    79  
    80  		// ResetStorageFolderHealth will reset the health statistics on a
    81  		// storage folder.
    82  		ResetStorageFolderHealth(index int) error
    83  
    84  		// ResizeStorageFolder will grow or shrink a storage folder in the
    85  		// manager. The manager may not check that there is enough space
    86  		// on-disk to support growing the storage folder, but should gracefully
    87  		// handle running out of space unexpectedly. When shrinking a storage
    88  		// folder, any data in the folder that needs to be moved will be placed
    89  		// into other storage folders, meaning that no data will be lost. If
    90  		// the manager is unable to migrate the data, an error will be returned
    91  		// and the operation will be stopped.
    92  		ResizeStorageFolder(index int, newSize uint64) error
    93  
    94  		// StorageFolders will return a list of storage folders tracked by the
    95  		// manager.
    96  		StorageFolders() []StorageFolderMetadata
    97  	}
    98  )