make repo gc call CollectGarbage on datastore
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Feb 1, 2018 at 13:20 UTC
04e43b855b391afe6d06644e50a4e83eeee5c4c0
3 files changed
+17
-4
core/corerepo/gc.go
+2
-2
@@ -86,7 +86,7 @@ func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
86
if err != nil {
87
return err
88
}
89
- rmed := gc.GC(ctx, n.Blockstore, n.Pinning, roots)
89
+ rmed := gc.GC(ctx, n.Blockstore, n.Repo.Datastore(), n.Pinning, roots)
90
91
return CollectResult(ctx, rmed, nil)
92
}
@@ -154,7 +154,7 @@ func GarbageCollectAsync(n *core.IpfsNode, ctx context.Context) <-chan gc.Result
154
return out
155
}
156
157
- return gc.GC(ctx, n.Blockstore, n.Pinning, roots)
157
+ return gc.GC(ctx, n.Blockstore, n.Repo.Datastore(), n.Pinning, roots)
158
}
159
160
func PeriodicGC(ctx context.Context, node *core.IpfsNode) error {
core/coreunix/add_test.go
+1
-1
@@ -104,7 +104,7 @@ func TestAddGCLive(t *testing.T) {
104
gcstarted := make(chan struct{})
105
go func() {
106
defer close(gcstarted)
107
- gcout = gc.GC(context.Background(), node.Blockstore, node.Pinning, nil)
107
+ gcout = gc.GC(context.Background(), node.Blockstore, node.Repo.Datastore(), node.Pinning, nil)
108
}()
109
110
// gc shouldnt start until we let the add finish its current file.
pin/gc/gc.go
+14
-1
@@ -11,6 +11,7 @@ import (
11
dag "github.com/ipfs/go-ipfs/merkledag"
12
pin "github.com/ipfs/go-ipfs/pin"
13
14
+ dstore "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
15
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
16
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
17
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
@@ -35,7 +36,7 @@ type Result struct {
36
// The routine then iterates over every block in the blockstore and
37
// deletes any block that is not found in the marked set.
38
//
38
-func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
39
+func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
40
41
elock := log.EventBegin(ctx, "GC.lockWait")
42
unlocker := bs.GCLock()
@@ -107,6 +108,18 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner, bestEffortRo
108
if errors {
109
output <- Result{Error: ErrCannotDeleteSomeBlocks}
110
}
111
+
112
+ defer log.EventBegin(ctx, "GC.datastore").Done()
113
+ gds, ok := dstor.(dstore.GCDatastore)
114
+ if !ok {
115
+ return
116
+ }
117
+
118
+ err = gds.CollectGarbage()
119
+ if err != nil {
120
+ output <- Result{Error: err}
121
+ return
122
+ }
123
}()
124
125
return output