diff --git a/build/version.go b/build/version.go index a5980a922..095ce8d0c 100644 --- a/build/version.go +++ b/build/version.go @@ -3,7 +3,7 @@ package build var CurrentCommit string // Version is the local build version, set by build system -const Version = "0.1.1" +const Version = "0.1.2" var UserVersion = Version + CurrentCommit @@ -16,7 +16,7 @@ var UserVersion = Version + CurrentCommit // R R H // |\vv/| // vv vv -const APIVersion = 0x000101 +const APIVersion = 0x000102 const ( MajorMask = 0xff0000 diff --git a/cmd/lotus-seal-worker/transfer.go b/cmd/lotus-seal-worker/transfer.go index e091edadf..af4681a1f 100644 --- a/cmd/lotus-seal-worker/transfer.go +++ b/cmd/lotus-seal-worker/transfer.go @@ -132,7 +132,7 @@ func (w *worker) fetchSector(sectorID uint64, typ sectorbuilder.WorkerTaskType) var err error switch typ { case sectorbuilder.WorkerPreCommit: - err = w.fetch("staged", sectorID) + err = w.fetch("staging", sectorID) case sectorbuilder.WorkerCommit: err = w.fetch("sealed", sectorID) if err != nil { diff --git a/lib/sectorbuilder/files.go b/lib/sectorbuilder/files.go index 0e2cee0d2..88dbec988 100644 --- a/lib/sectorbuilder/files.go +++ b/lib/sectorbuilder/files.go @@ -17,11 +17,11 @@ func (sb *SectorBuilder) SectorName(sectorID uint64) string { } func (sb *SectorBuilder) StagedSectorPath(sectorID uint64) string { - return filepath.Join(sb.filesystem.staging(), sb.SectorName(sectorID)) + return filepath.Join(sb.filesystem.pathFor(dataStaging), sb.SectorName(sectorID)) } func (sb *SectorBuilder) unsealedSectorPath(sectorID uint64) string { - return filepath.Join(sb.filesystem.unsealed(), sb.SectorName(sectorID)) + return filepath.Join(sb.filesystem.pathFor(dataUnsealed), sb.SectorName(sectorID)) } func (sb *SectorBuilder) stagedSectorFile(sectorID uint64) (*os.File, error) { @@ -29,13 +29,13 @@ func (sb *SectorBuilder) stagedSectorFile(sectorID uint64) (*os.File, error) { } func (sb *SectorBuilder) SealedSectorPath(sectorID uint64) (string, error) { - path := filepath.Join(sb.filesystem.sealed(), sb.SectorName(sectorID)) + path := filepath.Join(sb.filesystem.pathFor(dataSealed), sb.SectorName(sectorID)) return path, nil } func (sb *SectorBuilder) sectorCacheDir(sectorID uint64) (string, error) { - dir := filepath.Join(sb.filesystem.cache(), sb.SectorName(sectorID)) + dir := filepath.Join(sb.filesystem.pathFor(dataCache), sb.SectorName(sectorID)) err := os.Mkdir(dir, 0755) if os.IsExist(err) { @@ -46,16 +46,12 @@ func (sb *SectorBuilder) sectorCacheDir(sectorID uint64) (string, error) { } func (sb *SectorBuilder) GetPath(typ string, sectorName string) (string, error) { - switch typ { - case "staged": - return filepath.Join(sb.filesystem.staging(), sectorName), nil - case "sealed": - return filepath.Join(sb.filesystem.sealed(), sectorName), nil - case "cache": - return filepath.Join(sb.filesystem.cache(), sectorName), nil - default: - return "", xerrors.Errorf("unknown sector type for write: %s", typ) + _, found := overheadMul[dataType(typ)] + if !found { + return "", xerrors.Errorf("unknown sector type: %s", typ) } + + return sb.filesystem.pathFor(dataType(typ)), nil } func (sb *SectorBuilder) TrimCache(sectorID uint64) error { diff --git a/lib/sectorbuilder/fs.go b/lib/sectorbuilder/fs.go index adc2a621f..ac8de3a4d 100644 --- a/lib/sectorbuilder/fs.go +++ b/lib/sectorbuilder/fs.go @@ -9,18 +9,16 @@ import ( "syscall" ) -type dataType int +type dataType string const ( - dataCache dataType = iota - dataStaging - dataSealed - dataUnsealed - - nDataTypes + dataCache dataType = "cache" + dataStaging dataType = "staging" + dataSealed dataType = "sealed" + dataUnsealed dataType = "unsealed" ) -var overheadMul = []uint64{ // * sectorSize +var overheadMul = map[dataType]uint64{ // * sectorSize dataCache: 11, // TODO: check if true for 32G sectors dataStaging: 1, dataSealed: 1, @@ -32,19 +30,24 @@ type fs struct { // in progress actions - reserved [nDataTypes]uint64 + reserved map[dataType]uint64 lk sync.Mutex } func openFs(dir string) *fs { return &fs{ - path: dir, + path: dir, + reserved: map[dataType]uint64{}, } } func (f *fs) init() error { - for _, dir := range []string{f.path, f.cache(), f.staging(), f.sealed(), f.unsealed()} { + for _, dir := range []string{f.path, + f.pathFor(dataCache), + f.pathFor(dataStaging), + f.pathFor(dataSealed), + f.pathFor(dataUnsealed)} { if err := os.Mkdir(dir, 0755); err != nil { if os.IsExist(err) { continue @@ -56,20 +59,13 @@ func (f *fs) init() error { return nil } -func (f *fs) cache() string { - return filepath.Join(f.path, "cache") -} +func (f *fs) pathFor(typ dataType) string { + _, found := overheadMul[typ] + if !found { + panic("unknown data path requested") + } -func (f *fs) staging() string { - return filepath.Join(f.path, "staging") -} - -func (f *fs) sealed() string { - return filepath.Join(f.path, "sealed") -} - -func (f *fs) unsealed() string { - return filepath.Join(f.path, "unsealed") + return filepath.Join(f.path, string(typ)) } func (f *fs) reservedBytes() int64 { @@ -86,7 +82,7 @@ func (f *fs) reserve(typ dataType, size uint64) error { var fsstat syscall.Statfs_t - if err := syscall.Statfs(f.path, &fsstat); err != nil { + if err := syscall.Statfs(f.pathFor(typ), &fsstat); err != nil { return err } diff --git a/lib/sectorbuilder/sectorbuilder.go b/lib/sectorbuilder/sectorbuilder.go index 013a5eda6..59f8bd176 100644 --- a/lib/sectorbuilder/sectorbuilder.go +++ b/lib/sectorbuilder/sectorbuilder.go @@ -699,15 +699,15 @@ func fallbackPostChallengeCount(sectors uint64) uint64 { } func (sb *SectorBuilder) ImportFrom(osb *SectorBuilder, symlink bool) error { - if err := migrate(osb.filesystem.cache(), sb.filesystem.cache(), symlink); err != nil { + if err := migrate(osb.filesystem.pathFor(dataCache), sb.filesystem.pathFor(dataCache), symlink); err != nil { return err } - if err := migrate(osb.filesystem.sealed(), sb.filesystem.sealed(), symlink); err != nil { + if err := migrate(osb.filesystem.pathFor(dataStaging), sb.filesystem.pathFor(dataStaging), symlink); err != nil { return err } - if err := migrate(osb.filesystem.staging(), sb.filesystem.staging(), symlink); err != nil { + if err := migrate(osb.filesystem.pathFor(dataSealed), sb.filesystem.pathFor(dataSealed), symlink); err != nil { return err }