-
Notifications
You must be signed in to change notification settings - Fork 44
/
array.go
48 lines (37 loc) · 1.25 KB
/
array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package diff
import (
"context"
"os"
"runtime"
"strconv"
"go.opentelemetry.io/otel"
"github.com/filecoin-project/go-amt-ipld/v4"
adt2 "github.com/filecoin-project/lily/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/adt"
)
var AmtParallelWorkerLimit int64
const AmtParallelWorkerEnv = "LILY_AMT_PARALLEL_WORKER_LIMIT"
func init() {
AmtParallelWorkerLimit = int64(runtime.NumCPU())
workerStr := os.Getenv(AmtParallelWorkerEnv)
if workerStr != "" {
AmtParallelWorkerLimit, err := strconv.ParseInt(workerStr, 10, 64)
if err != nil {
log.Warnf("failed to parse env %s defaulting to %d (runtime.NumCPU()) : %s", AmtParallelWorkerEnv, AmtParallelWorkerLimit, err)
}
}
}
// Amt returns a set of changes that transform `preArr` into `curArr`. opts are applied to both `preArr` and `curArr`.
func Amt(ctx context.Context, preArr, curArr adt2.Array, preStore, curStore adt.Store, amtOpts ...amt.Option) ([]*amt.Change, error) {
ctx, span := otel.Tracer("").Start(ctx, "Amt.Diff")
defer span.End()
preRoot, err := preArr.Root()
if err != nil {
return nil, err
}
curRoot, err := curArr.Root()
if err != nil {
return nil, err
}
return amt.ParallelDiff(ctx, preStore, curStore, preRoot, curRoot, AmtParallelWorkerLimit, amtOpts...)
}