Fix ffiwrapper unseal

This commit is contained in:
Łukasz Magiera 2020-05-08 00:22:58 +02:00
parent 10f7750d80
commit 1bbfb7cffd
2 changed files with 41 additions and 26 deletions

View File

@ -108,33 +108,48 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector abi.SectorID, existingPie
}, werr() }, werr()
} }
type closerFunc func() error
func (cf closerFunc) Close() error {
return cf()
}
func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.SectorID, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealedCID cid.Cid) (io.ReadCloser, error) { func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.SectorID, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealedCID cid.Cid) (io.ReadCloser, error) {
path, doneUnsealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed, stores.FTUnsealed, false) {
if err != nil { path, doneUnsealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed, stores.FTNone, false)
return nil, xerrors.Errorf("acquire unsealed sector path: %w", err) if err != nil {
} return nil, xerrors.Errorf("acquire unsealed sector path: %w", err)
defer doneUnsealed()
f, err := os.OpenFile(path.Unsealed, os.O_RDONLY, 0644)
if err == nil {
if _, err := f.Seek(int64(offset), io.SeekStart); err != nil {
return nil, xerrors.Errorf("seek: %w", err)
} }
lr := io.LimitReader(f, int64(size)) f, err := os.OpenFile(path.Unsealed, os.O_RDONLY, 0644)
if err == nil {
if _, err := f.Seek(int64(offset), io.SeekStart); err != nil {
doneUnsealed()
return nil, xerrors.Errorf("seek: %w", err)
}
return &struct { lr := io.LimitReader(f, int64(size))
io.Reader
io.Closer return &struct {
}{ io.Reader
Reader: lr, io.Closer
Closer: f, }{
}, nil Reader: lr,
} Closer: closerFunc(func() error {
if !os.IsNotExist(err) { doneUnsealed()
return nil, err return f.Close()
}),
}, nil
}
doneUnsealed()
if !os.IsNotExist(err) {
return nil, err
}
} }
sealed, doneSealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTUnsealed|stores.FTCache, 0, false) paths, doneSealed, err := sb.sectors.AcquireSector(ctx, sector, stores.FTSealed|stores.FTCache, stores.FTUnsealed, false)
if err != nil { if err != nil {
return nil, xerrors.Errorf("acquire sealed/cache sector path: %w", err) return nil, xerrors.Errorf("acquire sealed/cache sector path: %w", err)
} }
@ -145,9 +160,9 @@ func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.Sect
// remove last used one (or use whatever other cache policy makes sense)) // remove last used one (or use whatever other cache policy makes sense))
err = ffi.Unseal( err = ffi.Unseal(
sb.sealProofType, sb.sealProofType,
sealed.Cache, paths.Cache,
sealed.Sealed, paths.Sealed,
path.Unsealed, paths.Unsealed,
sector.Number, sector.Number,
sector.Miner, sector.Miner,
ticket, ticket,
@ -157,7 +172,7 @@ func (sb *Sealer) ReadPieceFromSealedSector(ctx context.Context, sector abi.Sect
return nil, xerrors.Errorf("unseal failed: %w", err) return nil, xerrors.Errorf("unseal failed: %w", err)
} }
f, err = os.OpenFile(string(path.Unsealed), os.O_RDONLY, 0644) f, err := os.OpenFile(paths.Unsealed, os.O_RDONLY, 0644)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -110,7 +110,7 @@ var ResourceTable = map[sealtasks.TaskType]map[abi.RegisteredProof]Resources{
MinMemory: 32 << 30, MinMemory: 32 << 30,
Threads: -1, Threads: -1,
CanGPU: true, CanGPU: true,
BaseMinMemory: 30 << 30, BaseMinMemory: 30 << 30,
}, },