-
Notifications
You must be signed in to change notification settings - Fork 53
[WIP] remove UnixfsNode
from trickledag(part2)
#54
[WIP] remove UnixfsNode
from trickledag(part2)
#54
Conversation
af4360a
to
959f06a
Compare
There was a problem hiding this 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.
importer/helpers/dagbuilder.go
Outdated
|
||
// while we have room AND we're not done | ||
for node.NumChildren() < db.maxlinks && !db.Done() { | ||
//TODO size |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
importer/helpers/dagbuilder.go
Outdated
@@ -251,6 +246,26 @@ func (db *DagBuilderHelper) FillNodeLayer(node *UnixfsNode) error { | |||
return nil | |||
} | |||
|
|||
// FillFSNodeLayer do the same thing as FillNodeLayer. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
Note to self: the obscure portion in the trickle logic is the recursive loop |
959f06a
to
9402e69
Compare
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
|
9402e69
to
7c129ff
Compare
Great, I'll take a closer look and get back to you. |
0c485c2
to
29ce207
Compare
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>
2bc1e15
to
002f54f
Compare
There was a problem hiding this 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 ❤️
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? |
Glad you asked :) |
This pull request try to fix ipfs/kubo#5135 and it is based on #10.
Currently, go test ./... successful. The test log: