Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
remove the fullSync option from updateChildEntry
Browse files Browse the repository at this point in the history
Make `updateChildEntry` always propagate the update all the way up to the root,
the equivalent of calling it always with `fullSync` set.

The case of calling it without setting `fullSync` (a kind of "half-update")
where only the parent's directory UnixFS node was updated (but nothing else,
leaving the root outdated) seemed of little used. This helps to simplify the
logic around the update mechanism in MFS.
  • Loading branch information
schomatis committed Dec 21, 2018
1 parent e5a375d commit 1bbc52d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
30 changes: 9 additions & 21 deletions dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ func (d *Directory) SetCidBuilder(b cid.Builder) {
}

// This method implements the `parent` interface. It first updates
// the child entry in the underlying UnixFS directory and then, if `fullSync`
// is set, it:
// the child entry in the underlying UnixFS directory and then it:
// 1. DAG: saves the newly created directory node with the updated entry.
// 2. MFS: propagates the update upwards (through this same interface)
// repeating the whole process in the parent.
func (d *Directory) updateChildEntry(c child, fullSync bool) error {
func (d *Directory) updateChildEntry(c child) error {

// There's a local flush (`closeChildUpdate`) and a propagated flush (`updateChildEntry`).

newDirNode, err := d.closeChildUpdate(c, fullSync)
newDirNode, err := d.closeChildUpdate(c)
if err != nil {
return err
}
Expand All @@ -98,23 +97,15 @@ func (d *Directory) updateChildEntry(c child, fullSync bool) error {
// be merged with this one (the use of the `lock` is stopping this at the
// moment, re-evaluate when its purpose has been better understood).

if fullSync {
return d.parent.updateChildEntry(child{d.name, newDirNode}, true)
// Setting `fullSync` to true here means, if the original child that
// initiated the update process wanted to propagate it upwards then
// continue to do so all the way up to the root, that is, the only
// time `fullSync` can be false is in the first call (which will be
// the *only* call), we either update the first parent entry or *all*
// the parent's.
}

return nil
// Continue to propagate the update process upwards
// (all the way up to the root).
return d.parent.updateChildEntry(child{d.name, newDirNode})
}

// This method implements the part of `updateChildEntry` that needs
// to be locked around: in charge of updating the UnixFS layer and
// generating the new node reflecting the update.
func (d *Directory) closeChildUpdate(c child, fullSync bool) (*dag.ProtoNode, error) {
func (d *Directory) closeChildUpdate(c child) (*dag.ProtoNode, error) {
d.lock.Lock()
defer d.lock.Unlock()

Expand All @@ -125,10 +116,7 @@ func (d *Directory) closeChildUpdate(c child, fullSync bool) (*dag.ProtoNode, er
// TODO: Clearly define how are we propagating changes to lower layers
// like UnixFS.

if fullSync {
return d.flushCurrentNode()
}
return nil, nil
return d.flushCurrentNode()
}

// Recreate the underlying UnixFS directory node and save it in the DAG layer.
Expand Down Expand Up @@ -374,7 +362,7 @@ func (d *Directory) Flush() error {
return err
}

return d.parent.updateChildEntry(child{d.name, nd}, true)
return d.parent.updateChildEntry(child{d.name, nd})
}

// AddChild adds the node 'nd' under this directory giving it the name 'name'
Expand Down
11 changes: 7 additions & 4 deletions fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ func (fi *fileDescriptor) Flush() error {

// flushUp syncs the file and adds it to the dagservice
// it *must* be called with the File's lock taken
// TODO: What is `fullsync`? Propagate the changes upward
// to the root flushing every node in the path (the "up"
// part of `flushUp`).
// If `fullSync` is set the changes are propagated upwards
// (the `Up` part of `flushUp`).
func (fi *fileDescriptor) flushUp(fullSync bool) error {
nd, err := fi.mod.GetNode()
if err != nil {
Expand All @@ -151,7 +150,11 @@ func (fi *fileDescriptor) flushUp(fullSync bool) error {
fi.inode.nodeLock.Unlock()
// TODO: Maybe all this logic should happen in `File`.

return parent.updateChildEntry(child{name, nd}, fullSync)
if fullSync {
return parent.updateChildEntry(child{name, nd})
}

return nil
}

// Seek implements io.Seeker
Expand Down
15 changes: 7 additions & 8 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ type child struct {
// the entry/link of the directory that pointed to the modified node).
type parent interface {
// Method called by a child to its parent to signal to update the content
// pointed to in the entry by that child's name. The child sends as
// arguments its own information (under the `child` structure) and a flag
// (`fullsync`) indicating whether or not to propagate the update upwards:
// modifying a directory entry entails modifying its contents which means
// that its parent (the parent's parent) will also need to be updated (and
// so on).
updateChildEntry(c child, fullSync bool) error
// pointed to in the entry by that child's name. The child sends its own
// information in the `child` structure. As modifying a directory entry
// entails modifying its contents the parent will also call *its* parent's
// `updateChildEntry` to update the entry pointing to the new directory,
// this mechanism is in turn repeated until reaching the `Root`.
updateChildEntry(c child) error
}

type NodeType int
Expand Down Expand Up @@ -189,7 +188,7 @@ func (kr *Root) FlushMemFree(ctx context.Context) error {
// TODO: The `sync` argument isn't used here (we've already reached
// the top), document it and maybe make it an anonymous variable (if
// that's possible).
func (kr *Root) updateChildEntry(c child, fullSync bool) error {
func (kr *Root) updateChildEntry(c child) error {
err := kr.GetDirectory().dagService.Add(context.TODO(), c.Node)
if err != nil {
return err
Expand Down

0 comments on commit 1bbc52d

Please sign in to comment.