Skip to content

Commit 44d4e6e

Browse files
committed
Named pins, storing pins in Datastore
* Change pin structure to a tree stored in KV store * Adjust pin-related commands accordingly * Make pinning routines use meaningful default prefixes License: MIT Signed-off-by: Iaroslav Gridin <[email protected]>
1 parent b95e00c commit 44d4e6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+660
-1258
lines changed

assets/assets.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,9 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
8080
return cid.Cid{}, err
8181
}
8282

83-
if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
83+
if err := nd.Pinning.Pin(nd.Context(), "assets", dir, true); err != nil {
8484
return cid.Cid{}, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
8585
}
8686

87-
if err := nd.Pinning.Flush(); err != nil {
88-
return cid.Cid{}, fmt.Errorf("assets: Pinning flush failed: %s", err)
89-
}
90-
9187
return dir.Cid(), nil
9288
}

core/builder.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,7 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
268268
n.Blocks = bserv.New(n.Blockstore, n.Exchange)
269269
n.DAG = dag.NewDAGService(n.Blocks)
270270

271-
internalDag := dag.NewDAGService(bserv.New(n.Blockstore, offline.Exchange(n.Blockstore)))
272-
n.Pinning, err = pin.LoadPinner(n.Repo.Datastore(), n.DAG, internalDag)
273-
if err != nil {
274-
// TODO: we should move towards only running 'NewPinner' explicitly on
275-
// node init instead of implicitly here as a result of the pinner keys
276-
// not being found in the datastore.
277-
// this is kinda sketchy and could cause data loss
278-
n.Pinning = pin.NewPinner(n.Repo.Datastore(), n.DAG, internalDag)
279-
}
271+
n.Pinning = pin.NewPinner(n.DAG, n.Repo.Datastore())
280272
n.Resolver = resolver.NewBasicResolver(n.DAG)
281273

282274
if cfg.Online {

core/commands/add.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
onlyHashOptionName = "only-hash"
4040
chunkerOptionName = "chunker"
4141
pinOptionName = "pin"
42+
pinPathOptionName = "pinpath"
4243
rawLeavesOptionName = "raw-leaves"
4344
noCopyOptionName = "nocopy"
4445
fstoreCacheOptionName = "fscache"
@@ -119,6 +120,7 @@ You can now check what blocks have been created by:
119120
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
120121
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
121122
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
123+
cmdkit.StringOption(pinPathOptionName, "P", "Pin object under this path.").WithDefault("added/"),
122124
cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
123125
cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
124126
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
@@ -160,6 +162,7 @@ You can now check what blocks have been created by:
160162
silent, _ := req.Options[silentOptionName].(bool)
161163
chunker, _ := req.Options[chunkerOptionName].(string)
162164
dopin, _ := req.Options[pinOptionName].(bool)
165+
pinPath, _ := req.Options[pinPathOptionName].(string)
163166
rawblks, rbset := req.Options[rawLeavesOptionName].(bool)
164167
nocopy, _ := req.Options[noCopyOptionName].(bool)
165168
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
@@ -185,6 +188,7 @@ You can now check what blocks have been created by:
185188
options.Unixfs.Chunker(chunker),
186189

187190
options.Unixfs.Pin(dopin),
191+
options.Unixfs.PinPath(pinPath),
188192
options.Unixfs.HashOnly(hash),
189193
options.Unixfs.FsCache(fscache),
190194
options.Unixfs.Nocopy(nocopy),

core/commands/dag/dag.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
99
"github.com/ipfs/go-ipfs/core/coredag"
10-
"github.com/ipfs/go-ipfs/pin"
1110

1211
path "gx/ipfs/QmNYPETsdAu2uQ1k9q9S1jYEGURaLHV6cbYRSVFVRftpF8/go-path"
1312
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
@@ -60,7 +59,7 @@ into an object of the specified format.
6059
Options: []cmdkit.Option{
6160
cmdkit.StringOption("format", "f", "Format that the object will be added as.").WithDefault("cbor"),
6261
cmdkit.StringOption("input-enc", "Format that the input object will be.").WithDefault("json"),
63-
cmdkit.BoolOption("pin", "Pin this object when adding."),
62+
cmdkit.StringOption("pin", "Pin this object when adding.").WithDefault(""),
6463
cmdkit.StringOption("hash", "Hash function to use").WithDefault(""),
6564
},
6665
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
@@ -72,7 +71,7 @@ into an object of the specified format.
7271
ienc, _ := req.Options["input-enc"].(string)
7372
format, _ := req.Options["format"].(string)
7473
hash, _ := req.Options["hash"].(string)
75-
dopin, _ := req.Options["pin"].(bool)
74+
pinpath, _ := req.Options["pin"].(string)
7675

7776
// mhType tells inputParser which hash should be used. MaxUint64 means 'use
7877
// default hash' (sha256 for cbor, sha1 for git..)
@@ -89,10 +88,6 @@ into an object of the specified format.
8988
cids := cid.NewSet()
9089
b := ipld.NewBatch(req.Context, nd.DAG)
9190

92-
if dopin {
93-
defer nd.Blockstore.PinLock().Unlock()
94-
}
95-
9691
it := req.Files.Entries()
9792
for it.Next() {
9893
file := files.FileFromEntry(it)
@@ -128,13 +123,11 @@ into an object of the specified format.
128123
return err
129124
}
130125

131-
if dopin {
132-
cids.ForEach(func(c cid.Cid) error {
133-
nd.Pinning.PinWithMode(c, pin.Recursive)
134-
return nil
126+
if pinpath != "" {
127+
err := cids.ForEach(func(c cid.Cid) error {
128+
return nd.Pinning.AddPin(pinpath, c, true)
135129
})
136130

137-
err := nd.Pinning.Flush()
138131
if err != nil {
139132
return err
140133
}

core/commands/object/object.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ And then run:
383383
cmdkit.StringOption("inputenc", "Encoding type of input data. One of: {\"protobuf\", \"json\"}.").WithDefault("json"),
384384
cmdkit.StringOption("datafieldenc", "Encoding type of the data field, either \"text\" or \"base64\".").WithDefault("text"),
385385
cmdkit.BoolOption("pin", "Pin this object when adding."),
386+
cmdkit.StringOption("pinpath", "Pin under this path").WithDefault("added/"),
386387
cmdkit.BoolOption("quiet", "q", "Write minimal output."),
387388
},
388389
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
@@ -406,15 +407,21 @@ And then run:
406407
return err
407408
}
408409

409-
dopin, _ := req.Options["pin"].(bool)
410+
pinpath, _ := req.Options["pinpath"].(string)
411+
if err != nil {
412+
return err
413+
}
414+
415+
pin, _ := req.Options["pin"].(bool)
410416
if err != nil {
411417
return err
412418
}
413419

414420
p, err := api.Object().Put(req.Context, file,
415421
options.Object.DataType(datafieldenc),
416422
options.Object.InputEnc(inputenc),
417-
options.Object.Pin(dopin))
423+
options.Object.Pin(pin),
424+
options.Object.PinPath(pinpath))
418425
if err != nil {
419426
return err
420427
}

0 commit comments

Comments
 (0)