Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 85852b5

Browse files
committedJan 11, 2016
flush pinning improvements
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 404b180 commit 85852b5

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed
 

‎core/core.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,11 @@ func (n *IpfsNode) loadFilesRoot() error {
483483
return err
484484
}
485485

486-
err = n.Pinning.Pin(n.Context(), nnd, true)
487-
if err != nil {
486+
if err := n.Pinning.Pin(n.Context(), nnd, true); err != nil {
487+
return err
488+
}
489+
490+
if err := n.Pinning.Flush(); err != nil {
488491
return err
489492
}
490493

‎mfs/ops.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ func DirLookup(d *Directory, pth string) (FSNode, error) {
197197

198198
func FlushPath(r *Root, pth string) error {
199199
parts := path.SplitList(strings.Trim(pth, "/"))
200+
if len(parts) == 1 && parts[0] == "" {
201+
parts = nil
202+
}
200203

201204
d, ok := r.GetValue().(*Directory)
202205
if !ok {
@@ -214,12 +217,24 @@ func FlushPath(r *Root, pth string) error {
214217
}
215218

216219
r.repub.Update(k)
220+
r.repub.WaitPub()
221+
217222
return nil
218223
}
219224

220225
func flushPathRec(d *Directory, parts []string) (*dag.Node, error) {
221226
if len(parts) == 0 {
222-
return d.GetNode()
227+
nd, err := d.GetNode()
228+
if err != nil {
229+
return nil, err
230+
}
231+
232+
_, err = d.dserv.Add(nd)
233+
if err != nil {
234+
return nil, err
235+
}
236+
237+
return nd, nil
223238
}
224239

225240
d.Lock()
@@ -243,6 +258,11 @@ func flushPathRec(d *Directory, parts []string) (*dag.Node, error) {
243258
return nil, err
244259
}
245260

261+
_, err = d.dserv.Add(newnode)
262+
if err != nil {
263+
return nil, err
264+
}
265+
246266
d.node = newnode
247267
return newnode, nil
248268
case *File:

‎mfs/system.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ type Republisher struct {
165165
TimeoutShort time.Duration
166166
Publish chan struct{}
167167
pubfunc PubFunc
168-
pubnowch chan struct{}
168+
pubnowch chan chan struct{}
169169

170170
ctx context.Context
171171
cancel func()
@@ -190,7 +190,7 @@ func NewRepublisher(ctx context.Context, pf PubFunc, tshort, tlong time.Duration
190190
TimeoutLong: tlong,
191191
Publish: make(chan struct{}, 1),
192192
pubfunc: pf,
193-
pubnowch: make(chan struct{}),
193+
pubnowch: make(chan chan struct{}),
194194
ctx: ctx,
195195
cancel: cancel,
196196
}
@@ -204,11 +204,17 @@ func (p *Republisher) setVal(k key.Key) {
204204

205205
func (p *Republisher) pubNow() {
206206
select {
207-
case p.pubnowch <- struct{}{}:
207+
case p.pubnowch <- nil:
208208
default:
209209
}
210210
}
211211

212+
func (p *Republisher) WaitPub() {
213+
wait := make(chan struct{})
214+
p.pubnowch <- wait
215+
<-wait
216+
}
217+
212218
func (p *Republisher) Close() error {
213219
err := p.publish(p.ctx)
214220
p.cancel()
@@ -235,6 +241,8 @@ func (np *Republisher) Run() {
235241
longer := time.After(np.TimeoutLong)
236242

237243
wait:
244+
var pubnowresp chan struct{}
245+
238246
select {
239247
case <-np.ctx.Done():
240248
return
@@ -243,10 +251,13 @@ func (np *Republisher) Run() {
243251
goto wait
244252
case <-quick:
245253
case <-longer:
246-
case <-np.pubnowch:
254+
case pubnowresp = <-np.pubnowch:
247255
}
248256

249257
err := np.publish(np.ctx)
258+
if pubnowresp != nil {
259+
pubnowresp <- struct{}{}
260+
}
250261
if err != nil {
251262
log.Error("republishRoot error: %s", err)
252263
}

‎test/sharness/t0250-files-api.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,13 @@ test_files_api() {
336336
test_cmp root_hash_exp root_hash
337337
'
338338

339-
test_expect_success "root hash is pinned" '
340-
ipfs pin ls
341-
return 1
339+
test_expect_success "flush root succeeds" '
340+
ipfs files flush /
341+
'
342+
343+
test_expect_success "root hash is pinned after flush" '
344+
ipfs pin ls > pins &&
345+
grep $EXP_ROOT_HASH pins || (cat pins && exit 1)
342346
'
343347

344348
# test mv

0 commit comments

Comments
 (0)
Please sign in to comment.