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
Implementation of fsnotify based scan watcher #232
Conversation
thanks Brian!! this looks nice . hoping to have a closer look tomorrow |
doScan := event.Op&(fsnotify.Create|fsnotify.Write) != 0 | ||
if doScan && s.StartScanning() { | ||
var dirName string | ||
c := &Context{ |
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.
might be nice to extract this as a "newScanContext" or something, IIRC we do the same thing above
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.
Not sure I follow since I'm doing the same with the local context creation as in ScanAndClean()
} else { | ||
dirName = filepath.Dir(event.Name) | ||
} |
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 case is this handing? do we support watching normal files?
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.
If memory serves this is handling the sym link case.
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.
lookin good. and left some questions above.
i'm also wondering about limits that the kernal has on inotify watchers per user. apparently it's 8192 on ubuntu. my personal library is approaching 8k dirs. what would happen if someone with a bigger library starts the watcher?
also wondering how it affects memory consumption
cheers! sorry for the very late responses here btw
also interestingly, the likes of jellyfin and plex do filewatching too. i wonder do they have some trick up their sleeve to avoid the limits |
Re: watch limits -- if someone with more directories starts the watcher they should see errors in the log but it will watch what it can. Then if they have root access they can increase the system limit. |
just ran again locally and seems to work quite nice 👍 i have some questions also
what do you think? IIRC syncthing for example does some debounce stuff |
another QQ, could s.watchMap be replaced by s.watcher.WatchList() ? also regarding the debounce, if you think it's a good idea, hugo do something similar here (found from fsnotify/fsnotify#401 ) |
Re: initial scan -- yes, that was deliberate to make sure the library was up to date as we set the watches, but I'm fine with omitting it if that's what you want. |
yeah personally i think it would be good to not scan on startup, if that doesn't break anything
👍
thanks, yes this is just testing on my laptop with just a few dirs
👍 |
ah now it has started working for the whole tree copy. though it produces a lot of event. i think if we debounce/batch (maybe something like the hugo example?) it help a lot. any maybe make sure we don't miss any files for example: ("watching" message turned off) 20220913_202500.mp4 |
We could go a couple of routes on the batching:
I prefer 3 because of sloth :D but I'd be willing to take a stab at 2. |
personally like 2 not only seems like a good thing but I think solves the problem I initially had when I first tested (whole tree copied, notified only about first event, no children to add watchers to yet, meaning no children found (though I could be way off on this)) wdyt? very happy to help out on this if your time is limited |
Let me see if I can get to it this week. |
…10 second timer and then process in bulk.
Ok check it out. |
* First cut at fsnotify support. Tested on Linux. * Fixed bug in logging. * Fixed lint issues. * Added new scan watcher option to README.md * Inverted conditional and dedented following code as per PR discussion. * Changed command line switch and error return on ExecuteWatch() as per GH comments. * Scan watcher: Removed scan at first start. Modified watcher to set a 10 second timer and then process in bulk. Co-authored-by: Brian Doherty <brian@hplaptop.dohertyfamily.me>
thanks brian! did some testing and seem to work very well. i just make scanList a map (seems like we can just incase we get duplicate events, then we don't try process them twice. does this make sense?) and removed the "watching folder" log message, since it's a lot with a big library is this ok? |
* First cut at fsnotify support. Tested on Linux. * Fixed bug in logging. * Fixed lint issues. * Added new scan watcher option to README.md * Inverted conditional and dedented following code as per PR discussion. * Changed command line switch and error return on ExecuteWatch() as per GH comments. * Scan watcher: Removed scan at first start. Modified watcher to set a 10 second timer and then process in bulk. Co-authored-by: Brian Doherty <brian@hplaptop.dohertyfamily.me>
OK by me. Thanks! |
Tested on Linux.