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

[WIP] Invalidate Unlinked FSNodes from the cache #52

Closed
wants to merge 3 commits into from

Conversation

schomatis
Copy link
Contributor

Inspired by #48 (comment).

Provisional (informal) description:

  1. The only place that should modify the internal bookkeeping of issued FSNodes (e.g., when calling Child), alias the "cache", to remove entries should be Unlink.

  2. If you need to lower the memory usage because you requested too many nodes (a.k.a. listed the entire MFS) remove the entire MFS reference (I'm not sure this is a perfect guarantee, we don't know when all the FSNodes are reclaimed by GC).

  3. When removed from our internal bookkeeping, nullify the FSNode structure issued, this is implemented here by setting the parent reference to nil to make sure it doesn't have access to upper layers to propagate its changes. (This is just a proposed solution, we could add an explicit unlinked field or similar).

@ghost ghost assigned schomatis Jan 6, 2019
@ghost ghost added the status/in-progress In progress label Jan 6, 2019
@schomatis
Copy link
Contributor Author

This now passes the TestEditUnlinkedFile test.

@schomatis
Copy link
Contributor Author

(Ignoring Uncache for now until #48 is resolved.)

@schomatis schomatis requested a review from Stebalien January 6, 2019 21:45
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

This is better than what we currently have but I'd consider reviewing the entire interface. As-is, we also have issues around renames etc.

// TODO: This could actually transform the directory into a
// new root, but it wouldn't work with a `File`.
func (d *Directory) RemoveParent() {
d.inode.parent = nil
Copy link
Member

Choose a reason for hiding this comment

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

This isn't going to be thread-safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm not even sure if we should even be manipulating the internal inode.

@@ -69,6 +69,7 @@ type FSNode interface {
GetNode() (ipld.Node, error)
Flush() error
Type() NodeType
RemoveParent()
Copy link
Member

Choose a reason for hiding this comment

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

Exposing RemoveParent on a public interface probably isn't a good idea (it's an internal function only meant to be called by Unlink. We could either:

  1. Define a private interface.
  2. Call it Unlink() and have files unlink themselves (the child would need access to the parent somehow).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Define a private interface.

Yes, that sounds good, I'm abusing the FSNode interface here (because in my mental model FSNode just means child of a directory -either another dir or a file- but I'm thinking in OOP terms and I don't think I can have a public interface with private methods).

@schomatis
Copy link
Contributor Author

As-is, we also have issues around renames etc.

Yes, this is more of a PoC to test an idea that would help clean up this internal "cache".

@Stebalien
Copy link
Member

Yes, this is more of a PoC to test an idea that would help clean up this internal "cache".

Actually, we can probably handle renames in the same way (just make sure to update cache/parent on rename). I think we really are going to need a lock around the "parent" (or are going to need to use an atomic value) regardless of what we do.

As for cleaning up the cache, I really think the only solution is a Close function on files (it really isn't a cache, unfortunately).

@schomatis
Copy link
Contributor Author

Ok, if this solution makes sense (since I probably won't have time to implement it) I'm going to assign it to @nitishm who I think we'll be interested in.

I'm going to close this now as it was a fast PoC to test an idea but we shouldn't cherry-pick these commits into the final PR I think, just use them as a starting point.

@nitishm This is just a heads-up, don't bother doing anything here until I create a well documented issue describing the problem and the potential solution coded here, I won't be very active in MFS from now on but @Stebalien will be able to guide you through it.

@schomatis schomatis closed this Jan 8, 2019
@ghost ghost removed the status/in-progress In progress label Jan 8, 2019
@Stebalien
Copy link
Member

@Stebalien will be able to guide you through it.

I can try. Really, my only knowledge of MFS comes from hacking on ipfs/kubo#4514. I'm mostly just groping blindly and reading code.

@schomatis
Copy link
Contributor Author

I'm mostly just groping blindly and reading code.

So do the rest of us.. but you tend to have better judgement 😄

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.

2 participants