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

[WIP] remove UnixfsNode from trickledag(part2) #54

Merged

Conversation

bjzhang
Copy link
Contributor

@bjzhang bjzhang commented Dec 25, 2018

This pull request try to fix ipfs/kubo#5135 and it is based on #10.

Currently, go test ./... successful. The test log:

$ go test ./...
ok      github.com/ipfs/go-unixfs       (cached)
?       github.com/ipfs/go-unixfs/archive       [no test files]
?       github.com/ipfs/go-unixfs/archive/tar   [no test files]
ok      github.com/ipfs/go-unixfs/hamt  (cached)
ok      github.com/ipfs/go-unixfs/importer      (cached)
ok      github.com/ipfs/go-unixfs/importer/balanced     (cached)
?       github.com/ipfs/go-unixfs/importer/helpers      [no test files]
ok      github.com/ipfs/go-unixfs/importer/trickle      (cached)
ok      github.com/ipfs/go-unixfs/io    (cached)
ok      github.com/ipfs/go-unixfs/mod   (cached)
?       github.com/ipfs/go-unixfs/pb    [no test files]
?       github.com/ipfs/go-unixfs/test  [no test files]

@bjzhang bjzhang force-pushed the fix/dag/WIP-remove-unixfs-node-from-trickledag branch from af4360a to 959f06a Compare December 25, 2018 09:20
Copy link
Contributor

@schomatis schomatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, this is great @bjzhang! Thanks for putting in all this work, the ./t0250-files-api.sh test is passing and starting now from a working PR everything is made much easier.

I left a couple of minor comments for now, give me some time to review this thoroughly, especially the modifications in FSNodeOverDag which I understand come from the Append logic in the trickle builder that wasn't present in the balanced one, I want to be sure we need those new methods or if there's something we can refactor on the trickle logic to avoid adding more complexity.


// while we have room AND we're not done
for node.NumChildren() < db.maxlinks && !db.Done() {
//TODO size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this TODO be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -251,6 +246,26 @@ func (db *DagBuilderHelper) FillNodeLayer(node *UnixfsNode) error {
return nil
}

// FillFSNodeLayer do the same thing as FillNodeLayer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the comments from the original UnixfsNode functions like FillNodeLayer here? Also, we can now just remove everything related to UnixfsNode right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Test passed after remove everything of UnixfsNode.

@@ -388,6 +403,24 @@ func (db *DagBuilderHelper) NewFSNodeOverDag(fsNodeType pb.Data_DataType) *FSNod
return node
}

// NewFSNFromDag reconstructs a FSNodeOverDag node from a given dag node
func (db *DagBuilderHelper) NewFSNFromDag(nd *dag.ProtoNode) (*FSNodeOverDag, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we expand all the newFSN to newFSNode names to be consistent with the current terminology?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewFSNFromDag should be NewFSNodeOverDagFromDag. It is too long for me, and I simply truncate it at that time. Is there some better name in your mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, drop the OverDag, I was thinking of expanding just the FSN to FSNode part: NewFSNodeFromDag.

@schomatis
Copy link
Contributor

Note to self: the obscure portion in the trickle logic is the recursive loop appendFillLastChild -> appendRec -> appendFillLastChild.

@bjzhang bjzhang force-pushed the fix/dag/WIP-remove-unixfs-node-from-trickledag branch from 959f06a to 9402e69 Compare December 26, 2018 09:16
@bjzhang
Copy link
Contributor Author

bjzhang commented Dec 26, 2018

Hi @schomatis I just push latest version of my patches which address above comments, here is not some notes when I remove everything relative to the UnixfsNode

  • NewLeafNode will return the FSNodeOverDag with the given fsNodeType. While the old NewLeaf: if data is nil the type field will be TRaw (for backwards compatibility), if data is defined (but possibly empty) the type field will be TRaw.. Not sure if I should follow this. And because of this, I keep the NewLeafNode and NewLeafDataNode, not rename them to NewLeaf and GetNextDataNode.

  • There is no functions in importer/helpers/helpers.go. I am thinking if I should move the FSNodeOverDag part of importer/helpers/dagbuilder.go into importer/helpers/helpers.go.

  • GetDagNode return FilestoreNode for RawNode. But I do not understand how it is used in the DagBuilderHelper.AddChild. And FileSize do not calculate the size of RawNode because there is no flag of Raw in FSNodeOverDag.

@bjzhang bjzhang force-pushed the fix/dag/WIP-remove-unixfs-node-from-trickledag branch from 9402e69 to 7c129ff Compare December 26, 2018 09:27
@schomatis
Copy link
Contributor

here is not some notes when I remove everything relative to the UnixfsNode

Great, I'll take a closer look and get back to you.

@ghost ghost assigned schomatis Jan 15, 2019
@ghost ghost added the status/in-progress In progress label Jan 15, 2019
@schomatis schomatis force-pushed the fix/dag/WIP-remove-unixfs-node-from-trickledag branch 2 times, most recently from 0c485c2 to 29ce207 Compare January 15, 2019 20:31
Bamvor Zhang and others added 12 commits January 16, 2019 12:23
NewLeafNode and NewLeafDataNode is introduced in commit 474b77a2bdb1c
("importer: remove `UnixfsNode` from the balanced builder"). It is
intended to return ipfs.Node instead of UnixfsNode. But it only
support creating the TFile leaf node for merkledag.

This commit add fsNodeType to above two functions and update the code
in dagbuild.go. Further patches of trickledag will make use of them
and pass TRaw to create leaf node.

License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
After fsNodeType in NewLeafNode is supported by commit 85897b3
("dag: add fsNodeType in NewLeafNode and NewLeafDataNode"). Move
comments in NewLeafNode to importer/balanced/builder.go to clarify
why TFile is used by balanced builder as leaves.

License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
This patch is the part of trickledag work which is similar to the
merkledag work in commit 474b77a2bdb1c ("importer: remove `UnixfsNode`
from the balanced builder"). Two helper functions(fillTrickleRecFSNode
and FillFSNodeLayer) is introduced temporarily for modifing the Layout
functions. These two funtions will be removed when all the code of
UnixfsNode is removed in trickledag.go.

Test ipfs add and get commands to check whether get the same hash of
file after the code changes.

License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
Notes of removing UnixfsNode:
- `NewLeafNode` will return the `FSNodeOverDag` with the given
  `fsNodeType`. While the old `NewLeaf`: `if data is nil the type
  field will be TRaw (for backwards compatibility), if data is
  defined (but possibly empty) the type field will be TRaw.`. Not
  sure if I should follow this. And because of this, I keep the
  `NewLeafNode` and `NewLeafDataNode`, not rename them to
  `NewLeaf` and `GetNextDataNode`.
- There is no functions in importer/helpers/helpers.go. I am
  thinking if I should move the `FSNodeOverDag` part of
  importer/helpers/dagbuilder.go into importer/helpers/helpers.go.
- `GetDagNode` return FilestoreNode for RawNode. But I do not
  understand how it is used in the `DagBuilderHelper.AddChild`. And
  `FileSize` do not calculate the size of RawNode because there is
  no flag of Raw in `FSNodeOverDag`.

License: MIT
Signed-off-by: Bamvor Zhang <jian.zhang@ipfsbit.com>
@schomatis schomatis force-pushed the fix/dag/WIP-remove-unixfs-node-from-trickledag branch from 2bc1e15 to 002f54f Compare January 16, 2019 15:36
Copy link
Contributor

@schomatis schomatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in the review. Added some documentation and renamed a couple of variables in the append functions, there's definitely something strange in the relationship between appendFillLastChild and appendRec (without mentioning the fact that we are repeating the same for loop in all 3 append functions) but that's not something that needs to be fixed in this PR.

Great job @bjzhang!! I can't believe it but we have finally slain the UnixfsNode monster ⚔️ (it still shocks me to see the diff), when I started reading the UnixFS code last year this structure was really intimidating, but now new users won't have to go through the same as we did thanks to you. I recognize that delving into this code hasn't been easy (that's why it was abandoned for such a long time) so I really value your dedication here, I expected nothing less from a kernel hacker ❤️

@schomatis schomatis merged commit 2ea1b47 into ipfs:master Jan 16, 2019
@ghost ghost removed the status/in-progress In progress label Jan 16, 2019
@bjzhang bjzhang deleted the fix/dag/WIP-remove-unixfs-node-from-trickledag branch January 19, 2019 10:33
@bjzhang
Copy link
Contributor Author

bjzhang commented Jan 19, 2019

Hi, @schomatis . Thanks for your guiding, suggestion and help. I hope I could do more for go-ipfs. Is there something else I could do?

@schomatis
Copy link
Contributor

Glad you asked :)

ipfs/go-ipld-format#50

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[community contribution] Remove UnixfsNode from the trickle builder
2 participants