summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2019-10-01 09:44:56 +0900
committerPaul Masurel <paul.masurel@gmail.com>2019-10-01 09:44:56 +0900
commit2ea8e618f25037eef757ff21538d2b580b2280c1 (patch)
tree00c4743dce297944a4c7f2289dd104c1ba46602e
parent349e8aa348839bfc7909bf47325eefbfba90623a (diff)
parent94f27f990b862197e54438a71fb7cac24de88974 (diff)
Merge branch 'hotfix-656'
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/directory/mmap_directory.rs60
2 files changed, 30 insertions, 36 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57ba22d..a0df3a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,12 @@ Tantivy 0.11.0
- Regex are now compiled when the `RegexQuery` instance is built. As a result, it can now return
an error and handling the `Result` is required.
+
+Tantivy 0.10.2
+=====================
+
+- Closes #656. Solving memory leak.
+
Tantivy 0.10.1
=====================
diff --git a/src/directory/mmap_directory.rs b/src/directory/mmap_directory.rs
index fc3898c..2f8ebc5 100644
--- a/src/directory/mmap_directory.rs
+++ b/src/directory/mmap_directory.rs
@@ -142,42 +142,28 @@ impl MmapCache {
}
}
-struct InnerWatcherWrapper {
- _watcher: Mutex<notify::RecommendedWatcher>,
- watcher_router: WatchCallbackList,
-}
-
-impl InnerWatcherWrapper {
- pub fn new(path: &Path) -> Result<(Self, Receiver<notify::RawEvent>), notify::Error> {
- let (tx, watcher_recv): (Sender<RawEvent>, Receiver<RawEvent>) = channel();
- // We need to initialize the
- let mut watcher = notify::raw_watcher(tx)?;
- watcher.watch(path, RecursiveMode::Recursive)?;
- let inner = InnerWatcherWrapper {
- _watcher: Mutex::new(watcher),
- watcher_router: Default::default(),
- };
- Ok((inner, watcher_recv))
- }
-}
-
-#[derive(Clone)]
struct WatcherWrapper {
- inner: Arc<InnerWatcherWrapper>,
+ _watcher: Mutex<notify::RecommendedWatcher>,
+ watcher_router: Arc<WatchCallbackList>,
}
impl WatcherWrapper {
pub fn new(path: &Path) -> Result<Self, OpenDirectoryError> {
- let (inner, watcher_recv) = InnerWatcherWrapper::new(path).map_err(|err| match err {
- notify::Error::PathNotFound => OpenDirectoryError::DoesNotExist(path.to_owned()),
- _ => {
- panic!("Unknown error while starting watching directory {:?}", path);
- }
- })?;
- let watcher_wrapper = WatcherWrapper {
- inner: Arc::new(inner),
- };
- let watcher_wrapper_clone = watcher_wrapper.clone();
+ let (tx, watcher_recv): (Sender<RawEvent>, Receiver<RawEvent>) = channel();
+ // We need to initialize the
+ let watcher = notify::raw_watcher(tx)
+ .and_then(|mut watcher| {
+ watcher.watch(path, RecursiveMode::Recursive)?;
+ Ok(watcher)
+ })
+ .map_err(|err| match err {
+ notify::Error::PathNotFound => OpenDirectoryError::DoesNotExist(path.to_owned()),
+ _ => {
+ panic!("Unknown error while starting watching directory {:?}", path);
+ }
+ })?;
+ let watcher_router: Arc<WatchCallbackList> = Default::default();
+ let watcher_router_clone = watcher_router.clone();
thread::Builder::new()
.name("meta-file-watch-thread".to_string())
.spawn(move || {
@@ -188,7 +174,7 @@ impl WatcherWrapper {
// We might want to be more accurate than this at one point.
if let Some(filename) = changed_path.file_name() {
if filename == *META_FILEPATH {
- watcher_wrapper_clone.inner.watcher_router.broadcast();
+ watcher_router_clone.broadcast();
}
}
}
@@ -201,13 +187,15 @@ impl WatcherWrapper {
}
}
}
- })
- .expect("Failed to spawn thread to watch meta.json");
- Ok(watcher_wrapper)
+ })?;
+ Ok(WatcherWrapper {
+ _watcher: Mutex::new(watcher),
+ watcher_router,
+ })
}
pub fn watch(&mut self, watch_callback: WatchCallback) -> WatchHandle {
- self.inner.watcher_router.subscribe(watch_callback)
+ self.watcher_router.subscribe(watch_callback)
}
}