Allocate in the beginning for local as well
This commit is contained in:
parent
6543c0c79b
commit
ca81048ffa
|
@ -48,17 +48,18 @@ func New(rpc *rpc.Client, opts api.PinOptions, local bool) *DAGService {
|
||||||
|
|
||||||
// Add puts the given node in the destination peers.
|
// Add puts the given node in the destination peers.
|
||||||
func (dgs *DAGService) Add(ctx context.Context, node ipld.Node) error {
|
func (dgs *DAGService) Add(ctx context.Context, node ipld.Node) error {
|
||||||
if dgs.local {
|
|
||||||
return adder.NewBlockAdder(dgs.rpcClient, []peer.ID{""}).Add(ctx, node)
|
|
||||||
}
|
|
||||||
|
|
||||||
if dgs.dests == nil {
|
if dgs.dests == nil {
|
||||||
dests, err := adder.BlockAllocate(ctx, dgs.rpcClient, dgs.pinOpts)
|
dests, err := adder.BlockAllocate(ctx, dgs.rpcClient, dgs.pinOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dgs.dests = dests
|
dgs.dests = dests
|
||||||
dgs.ba = adder.NewBlockAdder(dgs.rpcClient, dests)
|
|
||||||
|
if dgs.local {
|
||||||
|
dgs.ba = adder.NewBlockAdder(dgs.rpcClient, []peer.ID{""})
|
||||||
|
} else {
|
||||||
|
dgs.ba = adder.NewBlockAdder(dgs.rpcClient, dests)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dgs.ba.Add(ctx, node)
|
return dgs.ba.Add(ctx, node)
|
||||||
|
@ -68,10 +69,6 @@ func (dgs *DAGService) Add(ctx context.Context, node ipld.Node) error {
|
||||||
func (dgs *DAGService) Finalize(ctx context.Context, root cid.Cid) (cid.Cid, error) {
|
func (dgs *DAGService) Finalize(ctx context.Context, root cid.Cid) (cid.Cid, error) {
|
||||||
// Cluster pin the result
|
// Cluster pin the result
|
||||||
rootPin := api.PinWithOpts(root, dgs.pinOpts)
|
rootPin := api.PinWithOpts(root, dgs.pinOpts)
|
||||||
if dgs.local {
|
|
||||||
return root, adder.Pin(ctx, dgs.rpcClient, rootPin)
|
|
||||||
}
|
|
||||||
|
|
||||||
rootPin.Allocations = dgs.dests
|
rootPin.Allocations = dgs.dests
|
||||||
dgs.dests = nil
|
dgs.dests = nil
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user