2020-05-19 16:11:56 +00:00
|
|
|
package ffiwrapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-08-16 10:40:35 +00:00
|
|
|
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-05-26 08:25:17 +00:00
|
|
|
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/partialfile"
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2020-05-19 16:11:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// merge gaps between ranges which are close to each other
|
|
|
|
// TODO: more benchmarking to come up with more optimal number
|
|
|
|
const mergeGaps = 32 << 20
|
|
|
|
|
|
|
|
// TODO const expandRuns = 16 << 20 // unseal more than requested for future requests
|
|
|
|
|
2020-05-26 08:25:17 +00:00
|
|
|
func computeUnsealRanges(unsealed rlepluslazy.RunIterator, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (rlepluslazy.RunIterator, error) {
|
2021-06-07 09:51:25 +00:00
|
|
|
todo := partialfile.PieceRun(offset.Padded(), size.Padded())
|
2020-05-19 16:11:56 +00:00
|
|
|
todo, err := rlepluslazy.Subtract(todo, unsealed)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("compute todo-unsealed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return rlepluslazy.JoinClose(todo, mergeGaps)
|
|
|
|
}
|