siadir

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 15 Imported by: 0

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 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 Metadata

type Metadata struct {
	// AggregateNumFiles is the total number of files in a directory and any
	// sub directory
	AggregateNumFiles uint64 `json:"aggregatenumfiles"`

	// AggregateSize is the total amount of data in the files and sub
	// directories
	AggregateSize uint64 `json:"aggregatesize"`

	// Health is the health of the most in need file in the directory or any
	// of the sub directories that are not stuck
	Health float64 `json:"health"`

	// LastHealthCheckTime is the oldest LastHealthCheckTime of any of the
	// siafiles in the siadir or any of the sub directories
	LastHealthCheckTime time.Time `json:"lasthealthchecktime"`

	// MinRedundancy is the minimum redundancy of any of the files or sub
	// directories
	MinRedundancy float64 `json:"minredundancy"`

	// ModTime is the last time any of the files or sub directories
	// was updated
	ModTime time.Time `json:"modtime"`

	// NumFiles is the number of files in a directory
	NumFiles uint64 `json:"numfiles"`

	// NumStuckChunks is the sum of all the Stuck Chunks of any of the
	// siafiles in the siadir or any of the sub directories
	NumStuckChunks uint64 `json:"numstuckchunks"`

	// NumSubDirs is the number of subdirectories in a directory
	NumSubDirs uint64 `json:"numsubdirs"`

	// RootDir is the path to the root directory on disk
	RootDir string `json:"rootdir"`

	// SiaPath is the path to the siadir on the sia network
	SiaPath modules.SiaPath `json:"siapath"`

	// StuckHealth is the health of the most in need file in the directory
	// or any of the sub directories, stuck or not stuck
	StuckHealth float64 `json:"stuckhealth"`
}

Metadata is the metadata that is saved to disk as a .siadir file

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) (*SiaDir, 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) 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) 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) 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