Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyUpdates(updates ...writeaheadlog.Update) error
- func HealthPercentage(health float64) float64
- func IsSiaDirUpdate(update writeaheadlog.Update) bool
- type DeleteDirFunc
- type DirReader
- type Metadata
- type RenameDirFunc
- type SiaDir
- type SiaDirSet
- func (sds *SiaDirSet) Delete(siaPath modules.SiaPath) error
- func (sds *SiaDirSet) DirInfo(siaPath modules.SiaPath) (modules.DirectoryInfo, error)
- func (sds *SiaDirSet) DirList(siaPath modules.SiaPath) ([]modules.DirectoryInfo, error)
- func (sds *SiaDirSet) Exists(siaPath modules.SiaPath) (bool, error)
- func (sds *SiaDirSet) InitRootDir() error
- func (sds *SiaDirSet) NewSiaDir(siaPath modules.SiaPath) (*SiaDirSetEntry, error)
- func (sds *SiaDirSet) Open(siaPath modules.SiaPath) (*SiaDirSetEntry, error)
- func (sds *SiaDirSet) Rename(oldPath, newPath modules.SiaPath) error
- func (sds *SiaDirSet) UpdateMetadata(siaPath modules.SiaPath, metadata Metadata) error
- type SiaDirSetEntry
Constants ¶
const ( // SiaDirExtension is the name of the metadata file for the sia directory SiaDirExtension = ".siadir" // DefaultDirHealth is the default health for the directory and the fall // back value when there is an error. This is to protect against falsely // trying to repair directories that had a read error DefaultDirHealth = float64(0) )
Variables ¶
var ( // ErrPathOverload is an error when a siadir already exists at that location ErrPathOverload = errors.New("a siadir already exists at that location") // ErrUnknownPath is an error when a siadir cannot be found with the given path ErrUnknownPath = errors.New("no siadir known with that path") // ErrUnknownThread is an error when a siadir is trying to be closed by a // thread that is not in the threadMap ErrUnknownThread = errors.New("thread should not be calling Close(), does not have control of the siadir") )
Functions ¶
func ApplyUpdates ¶
func ApplyUpdates(updates ...writeaheadlog.Update) error
ApplyUpdates applies a number of writeaheadlog updates to the corresponding SiaDir. This method can apply updates from different SiaDirs and should only be run before the SiaDirs are loaded from disk right after the startup of siad. Otherwise we might run into concurrency issues.
func HealthPercentage ¶ added in v1.4.1
HealthPercentage returns the health in a more human understandable format out of 100%
The percentage is out of 1.25, this is to account for the RepairThreshold of 0.25 and assumes that the worst health is 1.5. Since we do not repair until the health is worse than the RepairThreshold, a health of 0 - 0.25 is full health. Likewise, a health that is greater than 1.25 is essentially 0 health.
func IsSiaDirUpdate ¶
func IsSiaDirUpdate(update writeaheadlog.Update) bool
IsSiaDirUpdate is a helper method that makes sure that a wal update belongs to the SiaDir package.
Types ¶
type DeleteDirFunc ¶ added in v1.4.1
A DeleteDirFunc is a function that can be used to delete a SiaDir. It's passed to the SiaFileSet to delete the direcory after already loaded SiaFiles are locked. A DeleteDirFunc is assumed to lock the SiaDirSet and can therefore not be called from a locked SiaDirSet.
type DirReader ¶ added in v1.4.1
type DirReader struct {
// contains filtered or unexported fields
}
DirReader is a helper type that allows reading a raw .siadir from disk while keeping the file in memory locked.
type Metadata ¶
type Metadata struct { // The following fields are aggregate values of the siadir. These values are // the totals of the siadir and any sub siadirs, or are calculated based on // all the values in the subtree AggregateHealth float64 `json:"aggregatehealth"` AggregateLastHealthCheckTime time.Time `json:"aggregatelasthealthchecktime"` AggregateMinRedundancy float64 `json:"aggregateminredundancy"` AggregateModTime time.Time `json:"aggregatemodtime"` AggregateNumFiles uint64 `json:"aggregatenumfiles"` AggregateNumStuckChunks uint64 `json:"aggregatenumstuckchunks"` AggregateNumSubDirs uint64 `json:"aggregatenumsubdirs"` AggregateSize uint64 `json:"aggregatesize"` AggregateStuckHealth float64 `json:"aggregatestuckhealth"` // The following fields are information specific to the siadir that is not // an aggregate of the entire sub directory tree Health float64 `json:"health"` LastHealthCheckTime time.Time `json:"lasthealthchecktime"` MinRedundancy float64 `json:"minredundancy"` ModTime time.Time `json:"modtime"` NumFiles uint64 `json:"numfiles"` NumStuckChunks uint64 `json:"numstuckchunks"` NumSubDirs uint64 `json:"numsubdirs"` Size uint64 `json:"size"` StuckHealth float64 `json:"stuckhealth"` }
Metadata is the metadata that is saved to disk as a .siadir file
type RenameDirFunc ¶ added in v1.4.1
A RenameDirFunc is a function that can be used to rename a SiaDir. It's passed to the SiaFileSet to rename the direcory after already loaded SiaFiles are locked. A RenameDirFunc is assumed to lock the SiaDirSet and can therefore not be called from a locked SiaDirSet.
type SiaDir ¶
type SiaDir struct {
// contains filtered or unexported fields
}
SiaDir contains the metadata information about a renter directory
func LoadSiaDir ¶
func LoadSiaDir(rootDir string, siaPath modules.SiaPath, deps modules.Dependencies, wal *writeaheadlog.WAL) (sd *SiaDir, err error)
LoadSiaDir loads the directory metadata from disk
func New ¶
New creates a new directory in the renter directory and makes sure there is a metadata file in the directory and creates one as needed. This method will also make sure that all the parent directories are created and have metadata files as well and will return the SiaDir containing the information for the directory that matches the siaPath provided
func (*SiaDir) Delete ¶
Delete removes the directory from disk and marks it as deleted. Once the directory is deleted, attempting to access the directory will return an error.
func (*SiaDir) DirReader ¶ added in v1.4.1
DirReader creates a io.ReadCloser that can be used to read the raw SiaDir from disk.
func (*SiaDir) UpdateMetadata ¶
UpdateMetadata updates the SiaDir metadata on disk
type SiaDirSet ¶
type SiaDirSet struct {
// contains filtered or unexported fields
}
SiaDirSet handles the thread management for the SiaDirs on disk and in memory
func NewSiaDirSet ¶
func NewSiaDirSet(rootDir string, wal *writeaheadlog.WAL) *SiaDirSet
NewSiaDirSet initializes and returns a SiaDirSet
func (*SiaDirSet) DirList ¶ added in v1.4.1
DirList returns directories stored in the siadir as well as the DirectoryInfo of the siadir
func (*SiaDirSet) Exists ¶
Exists checks to see if a file with the provided siaPath already exists in the renter
func (*SiaDirSet) InitRootDir ¶
InitRootDir initializes the root directory SiaDir on disk. The root directory is not added in memory or returned.
func (*SiaDirSet) NewSiaDir ¶
func (sds *SiaDirSet) NewSiaDir(siaPath modules.SiaPath) (*SiaDirSetEntry, error)
NewSiaDir creates a new SiaDir and returns a SiaDirSetEntry
func (*SiaDirSet) Open ¶
func (sds *SiaDirSet) Open(siaPath modules.SiaPath) (*SiaDirSetEntry, error)
Open returns the siadir from the SiaDirSet for the corresponding key and adds the thread to the entry's threadMap. If the siadir is not in memory it will load it from disk
type SiaDirSetEntry ¶
type SiaDirSetEntry struct {
// contains filtered or unexported fields
}
SiaDirSetEntry is the exported struct that is returned to the thread accessing the SiaDir and the Entry
func (*SiaDirSetEntry) Close ¶
func (entry *SiaDirSetEntry) Close() error
Close will close the set entry, removing the entry from memory if there are no other entries using the siadir.
Note that 'Close' grabs a lock on the SiaDirSet, do not call this function while holding a lock on the SiaDirSet - standard concurrency conventions though dictate that you should not be calling exported / capitalized functions while holding a lock anyway, but this function is particularly sensitive to that.