From 5901eab20ba3c1345107fb9cc15682bf14cf7245 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann <adin.schmahmann@gmail.com> Date: Thu, 5 Dec 2019 12:15:45 -0500 Subject: [PATCH] add support for asynchronous datastores --- go.sum | 3 +-- pin.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index f06d01b..c6a12e4 100644 --- a/go.sum +++ b/go.sum @@ -76,8 +76,7 @@ github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAK github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= github.com/ipfs/go-datastore v0.1.0 h1:TOxI04l8CmO4zGtesENhzm4PwkFwJXY3rKiYaaMf9fI= github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= -github.com/ipfs/go-datastore v0.1.1 h1:F4k0TkTAZGLFzBOrVKDAvch6JZtuN4NHkfdcEZL50aI= -github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= +github.com/ipfs/go-datastore v0.3.0 h1:9au0tYi/+n7xeUnGHG6davnS8x9hWbOzP/388Vx3CMs= github.com/ipfs/go-datastore v0.3.0/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= diff --git a/pin.go b/pin.go index fa17a6b..7a3cabd 100644 --- a/pin.go +++ b/pin.go @@ -192,6 +192,11 @@ type pinner struct { dstore ds.Datastore } +type syncDAGService interface { + ipld.DAGService + Sync() error +} + // NewPinner creates a new pinner using the given datastore as a backend func NewPinner(dstore ds.Datastore, serv, internal ipld.DAGService) Pinner { @@ -576,6 +581,19 @@ func (p *pinner) Flush(ctx context.Context) error { k := root.Cid() internalset.Add(k) + + if syncDServ, ok := p.dserv.(syncDAGService); ok { + if err := syncDServ.Sync(); err != nil { + return fmt.Errorf("cannot sync pinned data: %v", err) + } + } + + if syncInternal, ok := p.internal.(syncDAGService); ok { + if err := syncInternal.Sync(); err != nil { + return fmt.Errorf("cannot sync pinning data: %v", err) + } + } + if err := p.dstore.Put(pinDatastoreKey, k.Bytes()); err != nil { return fmt.Errorf("cannot store pin state: %v", err) } -- GitLab