Merge pull request #769 from filecoin-project/feat/seed-cache-trim
seed: Trim cache
This commit is contained in:
commit
476fba3af1
@ -84,6 +84,10 @@ func PreSeal(maddr address.Address, ssize uint64, sectors int, sbroot string, pr
|
||||
return nil, xerrors.Errorf("commit: %w", err)
|
||||
}
|
||||
|
||||
if err := sb.TrimCache(sid); err != nil {
|
||||
return nil, xerrors.Errorf("trim cache: %w", err)
|
||||
}
|
||||
|
||||
log.Warn("PreCommitOutput: ", sid, pco)
|
||||
sealedSectors = append(sealedSectors, &genesis.PreSeal{
|
||||
CommR: pco.CommR,
|
||||
|
@ -3,8 +3,10 @@ package sectorbuilder
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
@ -61,6 +63,33 @@ func (sb *SectorBuilder) GetPath(typ string, sectorName string) (string, error)
|
||||
}
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) TrimCache(sectorID uint64) error {
|
||||
dir, err := sb.sectorCacheDir(sectorID)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting cache dir: %w", err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("readdir: %w", err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if !strings.HasSuffix(file.Name(), ".dat") { // _aux probably
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(file.Name(), "-data-tree-r-last.dat") { // Want to keep
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.Remove(filepath.Join(dir, file.Name())); err != nil {
|
||||
return xerrors.Errorf("rm %s: %w", file.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func toReadableFile(r io.Reader, n int64) (*os.File, func() error, error) {
|
||||
f, ok := r.(*os.File)
|
||||
if ok {
|
||||
|
@ -240,6 +240,10 @@ func TestSealPoStNoCommit(t *testing.T) {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
|
||||
if err := sb.TrimCache(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
genCandidiates := post(t, sb, s)
|
||||
|
||||
epost := time.Now()
|
||||
|
Loading…
Reference in New Issue
Block a user