Documentation ¶
Index ¶
- Constants
- Variables
- func CmpRepairPriority(h1, h2 uint32) int
- type CachedHealthMetadata
- type DxFile
- func (df *DxFile) AddSector(address enode.ID, merkleRoot common.Hash, segmentIndex, sectorIndex int) error
- func (df *DxFile) ApplyCachedHealthMetadata(metadata CachedHealthMetadata) error
- func (df *DxFile) CipherKey() (crypto.CipherKey, error)
- func (df *DxFile) Delete() error
- func (df *DxFile) Deleted() bool
- func (df *DxFile) DxPath() storage.DxPath
- func (df *DxFile) ErasureCode() (erasurecode.ErasureCoder, error)
- func (df *DxFile) FileMode() os.FileMode
- func (df *DxFile) FilePath() string
- func (df *DxFile) FileSize() uint64
- func (df *DxFile) GetHealth() uint32
- func (df *DxFile) GetNumStuckSegments() uint32
- func (df *DxFile) GetRedundancy() uint32
- func (df *DxFile) GetStuckByIndex(index int) bool
- func (df *DxFile) GetStuckHealth() uint32
- func (df *DxFile) Health(table storage.HostHealthInfoTable) (uint32, uint32, uint32)
- func (df *DxFile) HostIDs() []enode.ID
- func (df *DxFile) LastTimeRecentRepair() time.Time
- func (df *DxFile) LocalPath() storage.SysPath
- func (df *DxFile) MarkAllHealthySegmentsAsUnstuck(table storage.HostHealthInfoTable) error
- func (df *DxFile) MarkAllUnhealthySegmentsAsStuck(table storage.HostHealthInfoTable) error
- func (df *DxFile) NumSegments() int
- func (df *DxFile) NumStuckSegments() int
- func (df *DxFile) Redundancy(table storage.HostHealthInfoTable) uint32
- func (df *DxFile) Rename(newDxFile storage.DxPath, newDxFilename storage.SysPath) error
- func (df *DxFile) SectorSize() uint64
- func (df *DxFile) Sectors(segmentIndex int) ([][]*Sector, error)
- func (df *DxFile) SectorsOfSegmentIndex(index int) ([][]*Sector, error)
- func (df *DxFile) SegmentHealth(segmentIndex int, table storage.HostHealthInfoTable) uint32
- func (df *DxFile) SegmentSize() uint64
- func (df *DxFile) SetFileMode(mode os.FileMode) error
- func (df *DxFile) SetLocalPath(path storage.SysPath) error
- func (df *DxFile) SetStuckByIndex(index int, stuck bool) (err error)
- func (df *DxFile) SetTimeAccess(t time.Time) error
- func (df *DxFile) SetTimeLastHealthCheck(t time.Time) error
- func (df *DxFile) SetTimeRecentRepair(t time.Time) error
- func (df *DxFile) Snapshot() (*Snapshot, error)
- func (df *DxFile) SnapshotReader() (*SnapshotReader, error)
- func (df *DxFile) TimeAccess() time.Time
- func (df *DxFile) TimeCreate() time.Time
- func (df *DxFile) TimeLastHealthCheck() time.Time
- func (df *DxFile) TimeModify() time.Time
- func (df *DxFile) TimeRecentRepair() time.Time
- func (df *DxFile) TimeUpdate() time.Time
- func (df *DxFile) UID() FileID
- func (df *DxFile) UpdateUsedHosts(used []enode.ID) error
- func (df *DxFile) UploadProgress() float64
- func (df *DxFile) UploadedBytes() uint64
- type FileID
- type FileSet
- func (fs *FileSet) Delete(dxPath storage.DxPath) error
- func (fs *FileSet) Exists(dxPath storage.DxPath) bool
- func (fs *FileSet) NewDxFile(dxPath storage.DxPath, sourcePath storage.SysPath, force bool, ...) (*FileSetEntryWithID, error)
- func (fs *FileSet) NewRandomDxFile(dxPath storage.DxPath, minSectors, numSectors uint32, ecCode uint8, ...) (*FileSetEntryWithID, error)
- func (fs *FileSet) Open(dxPath storage.DxPath) (*FileSetEntryWithID, error)
- func (fs *FileSet) Rename(dxPath, newDxPath storage.DxPath) error
- type FileSetEntryWithID
- type Metadata
- type Sector
- type Segment
- type Snapshot
- func (s *Snapshot) CipherKey() crypto.CipherKey
- func (s *Snapshot) DxPath() storage.DxPath
- func (s *Snapshot) ErasureCode() erasurecode.ErasureCoder
- func (s *Snapshot) FileMode() os.FileMode
- func (s *Snapshot) FileSize() uint64
- func (s *Snapshot) NumSegments() uint64
- func (s *Snapshot) SectorSize() uint64
- func (s *Snapshot) Sectors(segmentIndex uint64) ([][]*Sector, error)
- func (s *Snapshot) SegmentIndexByOffset(offset uint64) (uint64, uint64)
- func (s *Snapshot) SegmentSize() uint64
- type SnapshotReader
- type UpdateMetaData
Constants ¶
const ( // SectorSize is the size of a Sector, which is 4MiB SectorSize = uint64(1 << 22) // Version is the version of dxfile Version = "1.0.0" )
const ( // RepairHealthThreshold is the threshold that file with smaller health is marked as Stuck and // to be repaired RepairHealthThreshold = 175 // StuckThreshold is the threshold that defines the threshold between the stuck and unstuck segments StuckThreshold = 100 // CompleteHealthThreshold is that segment upload all sectors CompleteHealthThreshold = 200 )
const (
// PageSize is the page size of persist Data
PageSize = 4096
)
Variables ¶
var ( // ErrUnknownFile is the error for opening a file that not exists on disk ErrUnknownFile = errors.New("file not known") // ErrFileExist is the error for creating a new file while there already exist a file // with the same name ErrFileExist = errors.New("file already exist") )
Functions ¶
func CmpRepairPriority ¶
CmpRepairPriority compare two health. The compare result returns the priority the health related Segment should be fixed The priority is determined by the follows: When the file is not recoverable from contract (health 0~99), it has the highest property to recover from disk When the file is recoverable (health 100~199), it is then prioritized. When the file is totally health, there is no need to recover. Thus the priority of recovery is as follows: 175 == RepairHealthThreshold (175 ~ 200) < (0 ~ 99) < 174 < 100 In the following expression p(h) means the priority of the health If p(h1) == p(h2), return 0 If p(h1) < p(h2), return -1 If p(h1) > p(h2), return 1
Types ¶
type CachedHealthMetadata ¶
CachedHealthMetadata is a helper struct that contains the dxfile health metadata fields that are cached
type DxFile ¶
type DxFile struct { ID FileID // contains filtered or unexported fields }
DxFile is the type of user uploaded DxFile
func New ¶
func New(filePath storage.SysPath, dxPath storage.DxPath, sourcePath storage.SysPath, wal *writeaheadlog.Wal, erasureCode erasurecode.ErasureCoder, cipherKey crypto.CipherKey, fileSize uint64, fileMode os.FileMode) (*DxFile, error)
New creates a new dxfile. filePath is the file where DxFile locates, dxPath is the user input dxPath. sourcePath is the file of the original data. wal is the writeaheadlog. erasureCode is the erasure coder for encoding. cipherKey is the key for encryption. fileSize is the size of the original data file. fileMode is the file privilege mode (e.g. 0777)
func (*DxFile) AddSector ¶
func (df *DxFile) AddSector(address enode.ID, merkleRoot common.Hash, segmentIndex, sectorIndex int) error
AddSector add a Sector to DxFile to the location specified by segmentIndex and sectorIndex. The sector content is filled by address and merkleRoot.
func (*DxFile) ApplyCachedHealthMetadata ¶
func (df *DxFile) ApplyCachedHealthMetadata(metadata CachedHealthMetadata) error
ApplyCachedHealthMetadata apply the cachedHealthMetadata to the DxFile
func (*DxFile) Delete ¶
Delete delete the DxFile. The function delete the DxFile on disk, and also mark df.deleted as true
func (*DxFile) ErasureCode ¶
func (df *DxFile) ErasureCode() (erasurecode.ErasureCoder, error)
ErasureCode return the erasure code
func (*DxFile) GetNumStuckSegments ¶
GetNumStuckSegments return NumStuckSegments in the metadata
func (*DxFile) GetRedundancy ¶
GetRedundancy return the last redundancy in the metadata
func (*DxFile) GetStuckByIndex ¶
GetStuckByIndex get the Stuck status of the indexed Segment
func (*DxFile) GetStuckHealth ¶
GetStuckHealth return the stuck health in the metadata
func (*DxFile) Health ¶
Health return check for dxFile's segments and return the health, stuckHealth, and numStuckSegments Health 0~100: unrecoverable from contracts Health 100~200: recoverable Health 200: No fix needed
func (*DxFile) LastTimeRecentRepair ¶
LastTimeRecentRepair return df.metadata.LastTimeRecentRepair
func (*DxFile) MarkAllHealthySegmentsAsUnstuck ¶
func (df *DxFile) MarkAllHealthySegmentsAsUnstuck(table storage.HostHealthInfoTable) error
MarkAllHealthySegmentsAsUnstuck mark all health > 100 segments as unstuck
func (*DxFile) MarkAllUnhealthySegmentsAsStuck ¶
func (df *DxFile) MarkAllUnhealthySegmentsAsStuck(table storage.HostHealthInfoTable) error
MarkAllUnhealthySegmentsAsStuck mark all unhealthy segments (health smaller than RepairHealthThreshold) as Stuck
func (*DxFile) NumSegments ¶
NumSegments return the number of segments
func (*DxFile) NumStuckSegments ¶
NumStuckChunks returns the Number of Stuck Chunks recorded in the file's metadata
func (*DxFile) Redundancy ¶
func (df *DxFile) Redundancy(table storage.HostHealthInfoTable) uint32
Redundancy return the redundancy of a dxfile. The redundancy is goodSectors * 100 / minSectors.
func (*DxFile) SectorSize ¶
SectorSize return the Sector size of a dxfile
func (*DxFile) SectorsOfSegmentIndex ¶
SectorsOfSegmentIndex returns Sectors of a specific Segment with Index. Notice the returned sector is the deep copy of the sectors specified by index
func (*DxFile) SegmentHealth ¶
func (df *DxFile) SegmentHealth(segmentIndex int, table storage.HostHealthInfoTable) uint32
SegmentHealth return the health of a Segment based on information provided Health 0~100: unrecoverable from contracts Health 100~200: recoverable Health 200: No fix needed
func (*DxFile) SegmentSize ¶
SegmentSize return the size of a Segment for a DxFile.
func (*DxFile) SetFileMode ¶
SetFileMode change the value of df.metadata.FileMode and save it to file
func (*DxFile) SetLocalPath ¶
SetLocalPath change the value of local path and save to disk
func (*DxFile) SetStuckByIndex ¶
SetStuckByIndex set a Segment of Index to the value of Stuck.
func (*DxFile) SetTimeAccess ¶
SetTimeAccess set df.metadata.TimeAccess
func (*DxFile) SetTimeLastHealthCheck ¶
SetTimeLastHealthCheck set and save df.metadata.TimeLastHealthCheck
func (*DxFile) SetTimeRecentRepair ¶
SetTimeRecentRepair set and save df.metadata.TimeRecentRepair
func (*DxFile) SnapshotReader ¶
func (df *DxFile) SnapshotReader() (*SnapshotReader, error)
SnapshotReader creates a reader that could be used to read DxFile content
func (*DxFile) TimeAccess ¶
TimeAccess return the last access time of a DxFile
func (*DxFile) TimeCreate ¶
TimeCreate returns the TimeCreate of a DxFile
func (*DxFile) TimeLastHealthCheck ¶
TimeLastHealthCheck return TimeHealthCheck
func (*DxFile) TimeModify ¶
TimeModify return the TimeModify of a DxFile
func (*DxFile) TimeRecentRepair ¶
func (*DxFile) TimeUpdate ¶
TimeUpdate return the last update time of a DxFile
func (*DxFile) UpdateUsedHosts ¶
UpdateUsedHosts update host table of the dxfile. hosts in df.hostTable exist in used slice are marked as used, rest are marked as unused
func (*DxFile) UploadProgress ¶
UploadProgress return the upload process of a dxfile. The upload progress is calculated based on uploadedByte divided by total bytes to upload
func (*DxFile) UploadedBytes ¶
UploadedBytes return the uploaded bytes. The uploaded bytes is calculated by number of sectors in df.segments
type FileSet ¶
type FileSet struct {
// contains filtered or unexported fields
}
FileSet is the set of DxFile
func NewFileSet ¶
func NewFileSet(rootDir storage.SysPath, wal *writeaheadlog.Wal) *FileSet
NewFileSet create a new DxFileSet with provided rootDir and wal.
func (*FileSet) Delete ¶
Delete delete a file with dxPath from the file set. Also the DxFile specified by dxPath on disk is also deleted
func (*FileSet) Exists ¶
Exists is the public function that returns whether the dxPath exists (cached then on disk)
func (*FileSet) NewDxFile ¶
func (fs *FileSet) NewDxFile(dxPath storage.DxPath, sourcePath storage.SysPath, force bool, erasureCode erasurecode.ErasureCoder, cipherKey crypto.CipherKey, fileSize uint64, fileMode os.FileMode) (*FileSetEntryWithID, error)
NewDxFile create a DxFile based on the params given. Return a FileSetEntryWithID that has been registered with threadID in FileSetEntry
func (*FileSet) NewRandomDxFile ¶
func (fs *FileSet) NewRandomDxFile(dxPath storage.DxPath, minSectors, numSectors uint32, ecCode uint8, ck crypto.CipherKey, fileSize uint64, missRate float32) (*FileSetEntryWithID, error)
NewRandomDxFile creates a new random DxFile with random segments data. missRate is the params indicate the possibility that a sector of a segment is missed. If not set, all sectors will be available.
type FileSetEntryWithID ¶
type FileSetEntryWithID struct {
// contains filtered or unexported fields
}
FileSetEntryWithID is a fileSetEntry with the threadID. FileSetEntryWithID extends DxFile
func (*FileSetEntryWithID) Close ¶
func (entry *FileSetEntryWithID) Close() error
Close close a FileSetEntryWithID
func (*FileSetEntryWithID) CopyEntry ¶
func (entry *FileSetEntryWithID) CopyEntry() *FileSetEntryWithID
CopyEntry copy the FileSetEntry. A new thread is created and registered in entry.threadMap
type Metadata ¶
type Metadata struct { ID FileID // storage related HostTableOffset uint64 SegmentOffset uint64 // size related FileSize uint64 SectorSize uint64 // ShardSize is the size for one shard, which is by default 4MiB // path related LocalPath storage.SysPath // Local path is the on-disk location for uploaded files DxPath storage.DxPath // DxPath is the user specified dxpath // Encryption CipherKeyCode uint8 // cipher key code defined in cipher package CipherKey []byte // Key used to encrypt pieces // Time fields. most of unix timestamp TimeModify uint64 // time of last content modification TimeUpdate uint64 // time of last Metadata update TimeAccess uint64 // time of last access TimeCreate uint64 // time of file creation // Repair loop fields Health uint32 // Worst health of the file's unstuck segment StuckHealth uint32 // Worst health of the file's Stuck segment TimeLastHealthCheck uint64 // Time of last health check happenning NumStuckSegments uint32 // Number of Stuck segments TimeRecentRepair uint64 // Timestamp of last segment repair LastRedundancy uint32 // File redundancy from last check // File related FileMode os.FileMode // unix file mode // Erasure code field ErasureCodeType uint8 // the code for the specific erasure code MinSectors uint32 // params for erasure coding. The number of slice raw Data split into. NumSectors uint32 // params for erasure coding. The number of total Sectors ECExtra []byte // extra parameters for erasure code // Version control for fork Version string }
Metadata is the Metadata of a user uploaded file.
type Sector ¶
Sector is the Data for a single Sector, which has Data of merkle root and related host address
type Segment ¶
type Segment struct { Sectors [][]*Sector Index uint64 Stuck bool // contains filtered or unexported fields }
Segment is the Data for a Segment, which is composed of several Sectors
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is the snapshot of a DxFile which contains necessary info for a DxFile. The data of Snapshot is deep copy of the Original DxFile and will not affect the Original DxFile
func (*Snapshot) ErasureCode ¶
func (s *Snapshot) ErasureCode() erasurecode.ErasureCoder
ErasureCode return the erasure code
func (*Snapshot) NumSegments ¶
NumSegments return the number of segments for DxFile
func (*Snapshot) SectorSize ¶
SectorSize return the sectorSize
func (*Snapshot) SegmentIndexByOffset ¶
SegmentIndexByOffset return the segment index and offset with the give offset of a file
func (*Snapshot) SegmentSize ¶
SegmentSize return the size of a single segment
type SnapshotReader ¶
type SnapshotReader struct {
// contains filtered or unexported fields
}
SnapshotReader is the structure that allow reading the raw DxFile content
func (*SnapshotReader) Close ¶
func (sr *SnapshotReader) Close() error
Close close the DxFile data file, and also release the lock of the DxFile