Merge pull request #63 from filecoin-project/feat/keep-unsealed
Unsealed copy changes
This commit is contained in:
commit
ce8ec242f9
@ -12,6 +12,7 @@ import (
|
|||||||
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/sector-storage/fsutil"
|
||||||
"github.com/filecoin-project/sector-storage/storiface"
|
"github.com/filecoin-project/sector-storage/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -218,6 +219,28 @@ func (pf *partialFile) MarkAllocated(offset storiface.PaddedByteIndex, size abi.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pf *partialFile) Free(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) error {
|
||||||
|
have, err := pf.allocated.RunIterator()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fsutil.Deallocate(pf.file, int64(offset), int64(size)); err != nil {
|
||||||
|
return xerrors.Errorf("deallocating: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := rlepluslazy.Subtract(have, pieceRun(offset, size))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := writeTrailer(int64(pf.maxPiece), pf.file, s); err != nil {
|
||||||
|
return xerrors.Errorf("writing trailer: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (pf *partialFile) Reader(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) (*os.File, error) {
|
func (pf *partialFile) Reader(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) (*os.File, error) {
|
||||||
if _, err := pf.file.Seek(int64(offset), io.SeekStart); err != nil {
|
if _, err := pf.file.Seek(int64(offset), io.SeekStart); err != nil {
|
||||||
return nil, xerrors.Errorf("seek piece start: %w", err)
|
return nil, xerrors.Errorf("seek piece start: %w", err)
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||||
|
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
||||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-storage/storage"
|
"github.com/filecoin-project/specs-storage/storage"
|
||||||
@ -502,7 +503,60 @@ func (sb *Sealer) SealCommit2(ctx context.Context, sector abi.SectorID, phase1Ou
|
|||||||
|
|
||||||
func (sb *Sealer) FinalizeSector(ctx context.Context, sector abi.SectorID, keepUnsealed []storage.Range) error {
|
func (sb *Sealer) FinalizeSector(ctx context.Context, sector abi.SectorID, keepUnsealed []storage.Range) error {
|
||||||
if len(keepUnsealed) > 0 {
|
if len(keepUnsealed) > 0 {
|
||||||
return xerrors.Errorf("keepUnsealed unsupported") // TODO: impl for fastretrieval copies
|
maxPieceSize := abi.PaddedPieceSize(sb.ssize)
|
||||||
|
|
||||||
|
sr := pieceRun(0, maxPieceSize)
|
||||||
|
|
||||||
|
for _, s := range keepUnsealed {
|
||||||
|
si := &rlepluslazy.RunSliceIterator{}
|
||||||
|
if s.Offset != 0 {
|
||||||
|
si.Runs = append(si.Runs, rlepluslazy.Run{Val: false, Len: uint64(s.Offset)})
|
||||||
|
}
|
||||||
|
si.Runs = append(si.Runs, rlepluslazy.Run{Val: true, Len: uint64(s.Size)})
|
||||||
|
|
||||||
|
var err error
|
||||||
|
sr, err = rlepluslazy.Subtract(sr, si)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
paths, done, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed, 0, false)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("acquiring sector cache path: %w", err)
|
||||||
|
}
|
||||||
|
defer done()
|
||||||
|
|
||||||
|
pf, err := openPartialFile(maxPieceSize, paths.Unsealed)
|
||||||
|
if xerrors.Is(err, os.ErrNotExist) {
|
||||||
|
return xerrors.Errorf("opening partial file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var at uint64
|
||||||
|
for sr.HasNext() {
|
||||||
|
r, err := sr.NextRun()
|
||||||
|
if err != nil {
|
||||||
|
_ = pf.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
offset := at
|
||||||
|
at += r.Len
|
||||||
|
if !r.Val {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pf.Free(storiface.PaddedByteIndex(abi.UnpaddedPieceSize(offset).Padded()), abi.UnpaddedPieceSize(r.Len).Padded())
|
||||||
|
if err != nil {
|
||||||
|
_ = pf.Close()
|
||||||
|
return xerrors.Errorf("free partial file range: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := pf.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, done, err := sb.sectors.AcquireSector(ctx, sector, stores.FTCache, 0, false)
|
paths, done, err := sb.sectors.AcquireSector(ctx, sector, stores.FTCache, 0, false)
|
||||||
|
28
fsutil/dealloc_linux.go
Normal file
28
fsutil/dealloc_linux.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package fsutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("fsutil")
|
||||||
|
|
||||||
|
const FallocFlPunchHole = 0x02 // linux/falloc.h
|
||||||
|
|
||||||
|
func Deallocate(file *os.File, offset int64, length int64) error {
|
||||||
|
if length == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := syscall.Fallocate(int(file.Fd()), FallocFlPunchHole, offset, length)
|
||||||
|
if errno, ok := err.(syscall.Errno); ok {
|
||||||
|
if errno == syscall.EOPNOTSUPP || errno == syscall.ENOSYS {
|
||||||
|
log.Warnf("could not deallocate space, ignoring: %v", errno)
|
||||||
|
err = nil // log and ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
18
fsutil/dealloc_other.go
Normal file
18
fsutil/dealloc_other.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// +build !linux
|
||||||
|
|
||||||
|
package fsutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("fsutil")
|
||||||
|
|
||||||
|
|
||||||
|
func Deallocate(file *os.File, offset int64, length int64) error {
|
||||||
|
log.Warnf("deallocating space not supported")
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
|
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
|
||||||
github.com/elastic/go-sysinfo v1.3.0
|
github.com/elastic/go-sysinfo v1.3.0
|
||||||
github.com/filecoin-project/filecoin-ffi v0.0.0-20200326153646-e899cc1dd072
|
github.com/filecoin-project/filecoin-ffi v0.0.0-20200326153646-e899cc1dd072
|
||||||
github.com/filecoin-project/go-bitfield v0.0.2-0.20200518150651-562fdb554b6e
|
github.com/filecoin-project/go-bitfield v0.0.4-0.20200703174658-f4a5758051a1
|
||||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
|
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
|
||||||
github.com/filecoin-project/go-paramfetch v0.0.1
|
github.com/filecoin-project/go-paramfetch v0.0.1
|
||||||
github.com/filecoin-project/specs-actors v0.6.1
|
github.com/filecoin-project/specs-actors v0.6.1
|
||||||
|
4
go.sum
4
go.sum
@ -34,8 +34,8 @@ github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200424220931-6263827e49f2/
|
|||||||
github.com/filecoin-project/go-bitfield v0.0.0-20200416002808-b3ee67ec9060/go.mod h1:iodsLxOFZnqKtjj2zkgqzoGNrv6vUqj69AT/J8DKXEw=
|
github.com/filecoin-project/go-bitfield v0.0.0-20200416002808-b3ee67ec9060/go.mod h1:iodsLxOFZnqKtjj2zkgqzoGNrv6vUqj69AT/J8DKXEw=
|
||||||
github.com/filecoin-project/go-bitfield v0.0.1 h1:Xg/JnrqqE77aJVKdbEyR04n9FZQWhwrN+buDgQCVpZU=
|
github.com/filecoin-project/go-bitfield v0.0.1 h1:Xg/JnrqqE77aJVKdbEyR04n9FZQWhwrN+buDgQCVpZU=
|
||||||
github.com/filecoin-project/go-bitfield v0.0.1/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY=
|
github.com/filecoin-project/go-bitfield v0.0.1/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY=
|
||||||
github.com/filecoin-project/go-bitfield v0.0.2-0.20200518150651-562fdb554b6e h1:gkG/7G+iKy4He+IiQNeQn+nndFznb/vCoOR8iRQsm60=
|
github.com/filecoin-project/go-bitfield v0.0.4-0.20200703174658-f4a5758051a1 h1:xuHlrdznafh7ul5t4xEncnA4qgpQvJZEw+mr98eqHXw=
|
||||||
github.com/filecoin-project/go-bitfield v0.0.2-0.20200518150651-562fdb554b6e/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY=
|
github.com/filecoin-project/go-bitfield v0.0.4-0.20200703174658-f4a5758051a1/go.mod h1:Ry9/iUlWSyjPUzlAvdnfy4Gtvrq4kWmWDztCU1yEgJY=
|
||||||
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus=
|
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus=
|
||||||
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
|
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
|
||||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo=
|
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo=
|
||||||
|
@ -171,9 +171,11 @@ func (l *LocalWorker) FinalizeSector(ctx context.Context, sector abi.SectorID, k
|
|||||||
return xerrors.Errorf("finalizing sector: %w", err)
|
return xerrors.Errorf("finalizing sector: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(keepUnsealed) == 0 {
|
||||||
if err := l.storage.Remove(ctx, sector, stores.FTUnsealed, true); err != nil {
|
if err := l.storage.Remove(ctx, sector, stores.FTUnsealed, true); err != nil {
|
||||||
return xerrors.Errorf("removing unsealed data: %w", err)
|
return xerrors.Errorf("removing unsealed data: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -441,7 +441,8 @@ func (m *Manager) FinalizeSector(ctx context.Context, sector abi.SectorID, keepU
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) ReleaseUnsealed(ctx context.Context, sector abi.SectorID, safeToFree []storage.Range) error {
|
func (m *Manager) ReleaseUnsealed(ctx context.Context, sector abi.SectorID, safeToFree []storage.Range) error {
|
||||||
return xerrors.Errorf("implement me")
|
log.Warnw("ReleaseUnsealed todo")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Remove(ctx context.Context, sector abi.SectorID) error {
|
func (m *Manager) Remove(ctx context.Context, sector abi.SectorID) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user