From ca81048ffa0b3cd62dc5e44c158f640f26264eec Mon Sep 17 00:00:00 2001 From: Kishan Mohanbhai Sagathiya Date: Wed, 18 Sep 2019 13:21:04 +0530 Subject: [PATCH] Allocate in the beginning for local as well --- adder/single/dag_service.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/adder/single/dag_service.go b/adder/single/dag_service.go index a14cde5a..d629e843 100644 --- a/adder/single/dag_service.go +++ b/adder/single/dag_service.go @@ -48,17 +48,18 @@ func New(rpc *rpc.Client, opts api.PinOptions, local bool) *DAGService { // Add puts the given node in the destination peers. 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 { dests, err := adder.BlockAllocate(ctx, dgs.rpcClient, dgs.pinOpts) if err != nil { return err } 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) @@ -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) { // Cluster pin the result rootPin := api.PinWithOpts(root, dgs.pinOpts) - if dgs.local { - return root, adder.Pin(ctx, dgs.rpcClient, rootPin) - } - rootPin.Allocations = dgs.dests dgs.dests = nil