unseal - comments

This commit is contained in:
Andrew Jackson (Ajax) 2023-09-01 17:15:56 -05:00
parent 7e6da3d76f
commit b73c016f6d
2 changed files with 12 additions and 10 deletions

View File

@ -404,16 +404,16 @@ func (sb *Sealer) pieceCid(spt abi.RegisteredSealProof, in []byte) (cid.Cid, err
return pieceCID, werr() return pieceCID, werr()
} }
func (sb *Sealer) maybeAcquireUpdatePath(ctx context.Context, sector storiface.SectorRef) (string, func(), error) { func (sb *Sealer) acquireUpdatePath(ctx context.Context, sector storiface.SectorRef) (string, func(), error) {
// copy so that the sector doesn't get removed from a long-term storage path // copy so that the sector doesn't get removed from a long-term storage path
replicaPath, done, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTUpdate, storiface.FTNone, storiface.PathSealing) replicaPath, releaseSector, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTUpdate, storiface.FTNone, storiface.PathSealing)
if xerrors.Is(err, storiface.ErrSectorNotFound) { if xerrors.Is(err, storiface.ErrSectorNotFound) {
return "", done, nil return "", releaseSector, nil
} else if err != nil { } else if err != nil {
return "", done, xerrors.Errorf("reading updated replica: %w", err) return "", releaseSector, xerrors.Errorf("reading updated replica: %w", err)
} }
return replicaPath.Update, done, nil return replicaPath.Update, releaseSector, nil
} }
func (sb *Sealer) decodeUpdatedReplica(ctx context.Context, sector storiface.SectorRef, commD cid.Cid, updatePath, unsealedPath string, randomness abi.SealRandomness) error { func (sb *Sealer) decodeUpdatedReplica(ctx context.Context, sector storiface.SectorRef, commD cid.Cid, updatePath, unsealedPath string, randomness abi.SealRandomness) error {
@ -478,11 +478,11 @@ func (sb *Sealer) acquireSectorKeyOrRegenerate(ctx context.Context, sector stori
} }
func (sb *Sealer) regenerateSectorKey(ctx context.Context, sector storiface.SectorRef, ticket abi.SealRandomness, keyDataCid cid.Cid) error { func (sb *Sealer) regenerateSectorKey(ctx context.Context, sector storiface.SectorRef, ticket abi.SealRandomness, keyDataCid cid.Cid) error {
paths, done, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTCache, storiface.FTSealed, storiface.PathSealing) paths, releaseSector, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTCache, storiface.FTSealed, storiface.PathSealing)
if err != nil { if err != nil {
return xerrors.Errorf("acquiring sector paths: %w", err) return xerrors.Errorf("acquiring sector paths: %w", err)
} }
defer done() defer releaseSector()
// stat paths.Sealed, make sure it doesn't exist // stat paths.Sealed, make sure it doesn't exist
_, err = os.Stat(paths.Sealed) _, err = os.Stat(paths.Sealed)
@ -570,6 +570,7 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storiface.SectorRef, o
return xerrors.Errorf("acquire unsealed sector path (allocate): %w", err) return xerrors.Errorf("acquire unsealed sector path (allocate): %w", err)
} }
case err == nil: case err == nil:
// no-op
default: default:
return xerrors.Errorf("acquire unsealed sector path (existing): %w", err) return xerrors.Errorf("acquire unsealed sector path (existing): %w", err)
} }
@ -608,7 +609,7 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storiface.SectorRef, o
// need to unseal // need to unseal
// If piece data stored in updated replica decode whole sector // If piece data stored in updated replica decode whole sector
upd, updDone, err := sb.maybeAcquireUpdatePath(ctx, sector) upd, updDone, err := sb.acquireUpdatePath(ctx, sector)
if err != nil { if err != nil {
return xerrors.Errorf("acquiring update path: %w", err) return xerrors.Errorf("acquiring update path: %w", err)
} }
@ -630,11 +631,11 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector storiface.SectorRef, o
// Piece data non-upgrade sealed in sector // Piece data non-upgrade sealed in sector
// (copy so that files stay in long-term storage) // (copy so that files stay in long-term storage)
srcPaths, srcDone, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTCache|storiface.FTSealed, storiface.FTNone, storiface.PathSealing) srcPaths, releaseSector, err := sb.sectors.AcquireSectorCopy(ctx, sector, storiface.FTCache|storiface.FTSealed, storiface.FTNone, storiface.PathSealing)
if err != nil { if err != nil {
return xerrors.Errorf("acquire sealed sector paths: %w", err) return xerrors.Errorf("acquire sealed sector paths: %w", err)
} }
defer srcDone() defer releaseSector()
sealed, err := os.OpenFile(srcPaths.Sealed, os.O_RDONLY, 0644) // nolint:gosec sealed, err := os.OpenFile(srcPaths.Sealed, os.O_RDONLY, 0644) // nolint:gosec
if err != nil { if err != nil {

View File

@ -11,6 +11,7 @@ type SectorProvider interface {
// * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist // * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist
// * returns an error when allocate is set, and existing isn't, and the sector exists // * returns an error when allocate is set, and existing isn't, and the sector exists
AcquireSector(ctx context.Context, id storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error) AcquireSector(ctx context.Context, id storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error)
// AcquireSector, but a copy to preseve its long-term storage location.
AcquireSectorCopy(ctx context.Context, id storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error) AcquireSectorCopy(ctx context.Context, id storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error)
} }