Documentation ¶
Index ¶
- Constants
- Variables
- type DirSet
- func (ds *DirSet) Delete(path storage.DxPath) error
- func (ds *DirSet) Exists(path storage.DxPath) bool
- func (ds *DirSet) NewDxDir(path storage.DxPath) (*DirSetEntryWithID, error)
- func (ds *DirSet) Open(path storage.DxPath) (*DirSetEntryWithID, error)
- func (ds *DirSet) UpdateMetadata(path storage.DxPath, metadata Metadata) error
- type DirSetEntryWithID
- type DxDir
- func (d *DxDir) DecodeRLP(st *rlp.Stream) error
- func (d *DxDir) Delete() error
- func (d *DxDir) Deleted() bool
- func (d *DxDir) DxPath() storage.DxPath
- func (d *DxDir) EncodeRLP(w io.Writer) error
- func (d *DxDir) FilePath() string
- func (d *DxDir) Metadata() Metadata
- func (d *DxDir) UpdateMetadata(metadata Metadata) error
- type Metadata
Examples ¶
Constants ¶
const ( DirFileName = ".dxdir" DefaultHealth = uint32(200) )
Variables ¶
var ( // ErrAlreadyDeleted is the error that happens when save or delete a DxDir // that is already deleted ErrAlreadyDeleted = errors.New("DxDir has already been deleted") // ErrUploadDirectory indicates that we can't upload directory ErrUploadDirectory = errors.New("cannot upload directory") // ErrPathOverload is an error when a file already exists at that location ErrPathOverload = errors.New("a file already exists at that location") // ErrUnknownPath is an error when a file cannot be found with the given path ErrUnknownPath = errors.New("no file known with that path") )
Functions ¶
This section is empty.
Types ¶
type DirSet ¶
type DirSet struct {
// contains filtered or unexported fields
}
DirSet is the manager of all DxDirs
Example ¶
ExampleDirSet shows an example usage of DirSet
package main import ( "fmt" "path/filepath" "reflect" "github.com/DxChainNetwork/godx/common/writeaheadlog" "github.com/DxChainNetwork/godx/storage" ) var exampleDirSetDir = tempDir("example") // ExampleDirSet shows an example usage of DirSet func main() { // initialize ds, err := NewDirSet(exampleDirSetDir, newExampleWal()) path := randomDxPath(2) entry, err := ds.NewDxDir(path) if err != nil { fmt.Println(err) } // create a random metadata and update newMeta := randomMetadata() // note the DxPath field is not updated newMeta.DxPath = path newMeta.RootPath = storage.SysPath(exampleDirSetDir) err = entry.UpdateMetadata(*newMeta) if err != nil { fmt.Println(err) } // Close the entry err = entry.Close() if err != nil { fmt.Println(err) } // Reopen the entry newEntry, err := ds.Open(path) if err != nil { fmt.Println(err) } newEntry.metadata.TimeModify = 0 newMeta.TimeModify = 0 if !reflect.DeepEqual(*newEntry.metadata, *newMeta) { fmt.Printf("After open, metadata not equal: \n\tExpect %+v\n\tGot %+v", newMeta, newEntry.metadata) } } // newExampleWal create a new wal for the example func newExampleWal() *writeaheadlog.Wal { wal, txns, err := writeaheadlog.New(filepath.Join(string(exampleDirSetDir), "example.wal")) if err != nil { fmt.Println(err) } for _, txn := range txns { err := txn.Release() if err != nil { panic(err) } } return wal }
Output:
func NewDirSet ¶
NewDirSet creates a New DirSet with the given parameters. If the root DxDir not exist, create a new DxDir
func (*DirSet) Exists ¶
Exists checks whether DxDir with path exists. If file not exist, return an os File Not Exist error
func (*DirSet) NewDxDir ¶
func (ds *DirSet) NewDxDir(path storage.DxPath) (*DirSetEntryWithID, error)
NewDxDir creates a DxDir. Return a DirSetEntryWithID that extends DxDir and the error
type DirSetEntryWithID ¶
type DirSetEntryWithID struct {
// contains filtered or unexported fields
}
DirSetEntryWithID is the entry with the threadID. It extends DxDir
func (*DirSetEntryWithID) Close ¶
func (entry *DirSetEntryWithID) Close() error
Close close the entry. If all threads with the entry is closed, remove the entry from the DirSet
type DxDir ¶
type DxDir struct {
// contains filtered or unexported fields
}
DxDir is the data structure for the directory for the meta info for a directory.
func New ¶
New create a DxDir with representing the dirPath metadata. Note that the only access method should be from dirSet
func (*DxDir) EncodeRLP ¶
EncodeRLP define the RLP rule for DxDir. Only the metadata is RLP encoded.
func (*DxDir) UpdateMetadata ¶
UpdateMetadata update the metadata with the given metadata. Not the DxPath field is not updated
type Metadata ¶
type Metadata struct { // Total number of files in directory and its subdirectories NumFiles uint64 // Total size of the directory and its subdirectories TotalSize uint64 // Health is the min Health all files and subdirectories Health uint32 // StuckHealth is the min StuckHealth for all files and subdirectories StuckHealth uint32 // MinRedundancy is the minimum redundancy MinRedundancy uint32 // TimeLastHealthCheck is the last health check time TimeLastHealthCheck uint64 // TimeModify is the last content modification time TimeModify uint64 // NumStuckSegments is the total number of segments that is stuck NumStuckSegments uint32 // DxPath is the DxPath which is the path related to the root directory DxPath storage.DxPath // RootPath is the root path of the file directory RootPath storage.SysPath }
Metadata is the necessary metadata to be saved in DxDir