siadir

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 17 Imported by: 0

README

SiaDir

Coming Soon...

Documentation

Index

Constants

View Source
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

View Source
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

func HealthPercentage(health float64) float64

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

type DeleteDirFunc func(siaPath modules.SiaPath) error

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.

func (*DirReader) Close added in v1.4.1

func (sdr *DirReader) Close() error

Close closes the underlying file.

func (*DirReader) Read added in v1.4.1

func (sdr *DirReader) Read(b []byte) (int, error)

Read calls Read on the underlying file.

func (*DirReader) Stat added in v1.4.1

func (sdr *DirReader) Stat() (os.FileInfo, error)

Stat returns the FileInfo of the underlying file.

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

type RenameDirFunc func(oldPath, newPath modules.SiaPath) error

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

func New(siaPath modules.SiaPath, rootDir string, wal *writeaheadlog.WAL) (*SiaDir, error)

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

func (sd *SiaDir) Delete() error

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) Deleted

func (sd *SiaDir) Deleted() bool

Deleted returns the deleted field of the siaDir

func (*SiaDir) DirReader added in v1.4.1

func (sd *SiaDir) DirReader() (*DirReader, error)

DirReader creates a io.ReadCloser that can be used to read the raw SiaDir from disk.

func (*SiaDir) Metadata

func (sd *SiaDir) Metadata() Metadata

Metadata returns the metadata of the SiaDir

func (*SiaDir) SiaPath

func (sd *SiaDir) SiaPath() modules.SiaPath

SiaPath returns the SiaPath of the SiaDir

func (*SiaDir) UpdateMetadata

func (sd *SiaDir) UpdateMetadata(metadata Metadata) error

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) Delete

func (sds *SiaDirSet) Delete(siaPath modules.SiaPath) error

Delete deletes the SiaDir that belongs to the siaPath

func (*SiaDirSet) DirInfo added in v1.4.1

func (sds *SiaDirSet) DirInfo(siaPath modules.SiaPath) (modules.DirectoryInfo, error)

DirInfo returns the Directory Information of the siadir

func (*SiaDirSet) DirList added in v1.4.1

func (sds *SiaDirSet) DirList(siaPath modules.SiaPath) ([]modules.DirectoryInfo, error)

DirList returns directories stored in the siadir as well as the DirectoryInfo of the siadir

func (*SiaDirSet) Exists

func (sds *SiaDirSet) Exists(siaPath modules.SiaPath) (bool, error)

Exists checks to see if a file with the provided siaPath already exists in the renter

func (*SiaDirSet) InitRootDir

func (sds *SiaDirSet) InitRootDir() error

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

func (*SiaDirSet) Rename added in v1.4.1

func (sds *SiaDirSet) Rename(oldPath, newPath modules.SiaPath) error

Rename renames a SiaDir on disk atomically by locking all the already loaded, affected dirs and renaming the root. NOTE: This shouldn't be called directly but instead be passed to siafileset.RenameDir as an argument.

func (*SiaDirSet) UpdateMetadata

func (sds *SiaDirSet) UpdateMetadata(siaPath modules.SiaPath, metadata Metadata) error

UpdateMetadata will update the metadata of the SiaDir in memory and on 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL