Commit e0bf4c12 authored by Jeromy's avatar Jeromy

pin: use separate dagservice for storing pinsets

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent eb2035cb
...@@ -110,15 +110,14 @@ type pinner struct { ...@@ -110,15 +110,14 @@ type pinner struct {
// not delete them. // not delete them.
internalPin map[key.Key]struct{} internalPin map[key.Key]struct{}
dserv mdag.DAGService dserv mdag.DAGService
internal mdag.DAGService // dagservice used to store internal objects
dstore ds.Datastore dstore ds.Datastore
} }
// NewPinner creates a new pinner using the given datastore as a backend // NewPinner creates a new pinner using the given datastore as a backend
func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner { func NewPinner(dstore ds.Datastore, serv, internal mdag.DAGService) Pinner {
// Load set from given datastore...
rcset := set.NewSimpleBlockSet() rcset := set.NewSimpleBlockSet()
dirset := set.NewSimpleBlockSet() dirset := set.NewSimpleBlockSet()
return &pinner{ return &pinner{
...@@ -126,6 +125,7 @@ func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner { ...@@ -126,6 +125,7 @@ func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner {
directPin: dirset, directPin: dirset,
dserv: serv, dserv: serv,
dstore: dstore, dstore: dstore,
internal: internal,
} }
} }
...@@ -344,7 +344,7 @@ func (p *pinner) RemovePinWithMode(key key.Key, mode PinMode) { ...@@ -344,7 +344,7 @@ func (p *pinner) RemovePinWithMode(key key.Key, mode PinMode) {
} }
// LoadPinner loads a pinner and its keysets from the given datastore // LoadPinner loads a pinner and its keysets from the given datastore
func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) { func LoadPinner(d ds.Datastore, dserv, internal mdag.DAGService) (Pinner, error) {
p := new(pinner) p := new(pinner)
rootKeyI, err := d.Get(pinDatastoreKey) rootKeyI, err := d.Get(pinDatastoreKey)
...@@ -361,7 +361,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) { ...@@ -361,7 +361,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5) ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5)
defer cancel() defer cancel()
root, err := dserv.Get(ctx, rootKey) root, err := internal.Get(ctx, rootKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot find pinning root object: %v", err) return nil, fmt.Errorf("cannot find pinning root object: %v", err)
} }
...@@ -374,7 +374,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) { ...@@ -374,7 +374,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
} }
{ // load recursive set { // load recursive set
recurseKeys, err := loadSet(ctx, dserv, root, linkRecursive, recordInternal) recurseKeys, err := loadSet(ctx, internal, root, linkRecursive, recordInternal)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot load recursive pins: %v", err) return nil, fmt.Errorf("cannot load recursive pins: %v", err)
} }
...@@ -382,7 +382,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) { ...@@ -382,7 +382,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
} }
{ // load direct set { // load direct set
directKeys, err := loadSet(ctx, dserv, root, linkDirect, recordInternal) directKeys, err := loadSet(ctx, internal, root, linkDirect, recordInternal)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot load direct pins: %v", err) return nil, fmt.Errorf("cannot load direct pins: %v", err)
} }
...@@ -394,6 +394,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) { ...@@ -394,6 +394,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
// assign services // assign services
p.dserv = dserv p.dserv = dserv
p.dstore = d p.dstore = d
p.internal = internal
return p, nil return p, nil
} }
...@@ -422,7 +423,7 @@ func (p *pinner) Flush() error { ...@@ -422,7 +423,7 @@ func (p *pinner) Flush() error {
root := &mdag.Node{} root := &mdag.Node{}
{ {
n, err := storeSet(ctx, p.dserv, p.directPin.GetKeys(), recordInternal) n, err := storeSet(ctx, p.internal, p.directPin.GetKeys(), recordInternal)
if err != nil { if err != nil {
return err return err
} }
...@@ -432,7 +433,7 @@ func (p *pinner) Flush() error { ...@@ -432,7 +433,7 @@ func (p *pinner) Flush() error {
} }
{ {
n, err := storeSet(ctx, p.dserv, p.recursePin.GetKeys(), recordInternal) n, err := storeSet(ctx, p.internal, p.recursePin.GetKeys(), recordInternal)
if err != nil { if err != nil {
return err return err
} }
...@@ -442,12 +443,12 @@ func (p *pinner) Flush() error { ...@@ -442,12 +443,12 @@ func (p *pinner) Flush() error {
} }
// add the empty node, its referenced by the pin sets but never created // add the empty node, its referenced by the pin sets but never created
_, err := p.dserv.Add(new(mdag.Node)) _, err := p.internal.Add(new(mdag.Node))
if err != nil { if err != nil {
return err return err
} }
k, err := p.dserv.Add(root) k, err := p.internal.Add(root)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -45,7 +45,7 @@ func TestPinnerBasic(t *testing.T) { ...@@ -45,7 +45,7 @@ func TestPinnerBasic(t *testing.T) {
dserv := mdag.NewDAGService(bserv) dserv := mdag.NewDAGService(bserv)
// TODO does pinner need to share datastore with blockservice? // TODO does pinner need to share datastore with blockservice?
p := NewPinner(dstore, dserv) p := NewPinner(dstore, dserv, dserv)
a, ak := randNode() a, ak := randNode()
_, err := dserv.Add(a) _, err := dserv.Add(a)
...@@ -133,7 +133,7 @@ func TestPinnerBasic(t *testing.T) { ...@@ -133,7 +133,7 @@ func TestPinnerBasic(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
np, err := LoadPinner(dstore, dserv) np, err := LoadPinner(dstore, dserv, dserv)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -154,7 +154,7 @@ func TestDuplicateSemantics(t *testing.T) { ...@@ -154,7 +154,7 @@ func TestDuplicateSemantics(t *testing.T) {
dserv := mdag.NewDAGService(bserv) dserv := mdag.NewDAGService(bserv)
// TODO does pinner need to share datastore with blockservice? // TODO does pinner need to share datastore with blockservice?
p := NewPinner(dstore, dserv) p := NewPinner(dstore, dserv, dserv)
a, _ := randNode() a, _ := randNode()
_, err := dserv.Add(a) _, err := dserv.Add(a)
...@@ -187,7 +187,7 @@ func TestFlush(t *testing.T) { ...@@ -187,7 +187,7 @@ func TestFlush(t *testing.T) {
bserv := bs.New(bstore, offline.Exchange(bstore)) bserv := bs.New(bstore, offline.Exchange(bstore))
dserv := mdag.NewDAGService(bserv) dserv := mdag.NewDAGService(bserv)
p := NewPinner(dstore, dserv) p := NewPinner(dstore, dserv, dserv)
_, k := randNode() _, k := randNode()
p.PinWithMode(k, Recursive) p.PinWithMode(k, Recursive)
...@@ -204,7 +204,7 @@ func TestPinRecursiveFail(t *testing.T) { ...@@ -204,7 +204,7 @@ func TestPinRecursiveFail(t *testing.T) {
bserv := bs.New(bstore, offline.Exchange(bstore)) bserv := bs.New(bstore, offline.Exchange(bstore))
dserv := mdag.NewDAGService(bserv) dserv := mdag.NewDAGService(bserv)
p := NewPinner(dstore, dserv) p := NewPinner(dstore, dserv, dserv)
a, _ := randNode() a, _ := randNode()
b, _ := randNode() b, _ := randNode()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment