-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that flush on the mfs root flushes its directory #4509
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,36 @@ func (kr *Root) Flush() error { | |
return nil | ||
} | ||
|
||
// FlushMemFree flushes the root directory and then uncaches all of its links. | ||
// This has the effect of clearing out potentially stale references and allows | ||
// them to be garbage collected. | ||
// CAUTION: Take care not to ever call this while holding a reference to any | ||
// child directories. Those directories will be bad references and using them | ||
// may have unintended racy side effects. | ||
// A better implemented mfs system (one that does smarter internal caching and | ||
// refcounting) shouldnt need this method. | ||
func (kr *Root) FlushMemFree(ctx context.Context) error { | ||
dir, ok := kr.GetValue().(*Directory) | ||
if !ok { | ||
return fmt.Errorf("invalid mfs structure, root should be a directory") | ||
} | ||
|
||
if err := dir.Flush(); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we concurrently modify this directory? Can we end up uncaching non-flushed entries? Is that an issue? Should we have a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats basically the purpose of this method. In my comment i make it explicit that you shouldnt use this method concurrently with any other operations since there are deeper issues that could potentially happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I'm working on improving this situation, FYI. |
||
return err | ||
} | ||
|
||
dir.lock.Lock() | ||
defer dir.lock.Unlock() | ||
for name := range dir.files { | ||
delete(dir.files, name) | ||
} | ||
for name := range dir.childDirs { | ||
delete(dir.childDirs, name) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// closeChild implements the childCloser interface, and signals to the publisher that | ||
// there are changes ready to be published | ||
func (kr *Root) closeChild(name string, nd node.Node, sync bool) 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.
What exactly do you mean here? How will removing these from the map lead to race conditions?I think what's throwing me is the term "cache". Is it a write cache? A read cache?Answered offline. Basically, we could have open file descriptors and we'll lose updates to these files if we remove the references to them from the cache.