Skip to content

Commit

Permalink
Closes #544. (#607)
Browse files Browse the repository at this point in the history
Prepare for release 0.10.1
  • Loading branch information
fulmicoton authored Jul 30, 2019
1 parent c91eb7f commit efd1af1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Tantivy 0.11.0

- Added f64 field. Internally reuse u64 code the same way i64 does (@fdb-hiroshima)

Tantivy 0.10.1
=====================

- Closes #544. A few users experienced problems with the directory watching system.
Avoid watching the mmap directory until someone effectively creates a reader that uses
this functionality.


Tantivy 0.10.0
=====================

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tantivy"
version = "0.10.0"
version = "0.10.1"
authors = ["Paul Masurel <[email protected]>"]
license = "MIT"
categories = ["database-implementations", "data-structures"]
Expand Down
2 changes: 1 addition & 1 deletion src/directory/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
/// Internally, tantivy only uses this API to detect new commits to implement the
/// `OnCommit` `ReloadPolicy`. Not implementing watch in a `Directory` only prevents the
/// `OnCommit` `ReloadPolicy` to work properly.
fn watch(&self, watch_callback: WatchCallback) -> WatchHandle;
fn watch(&self, watch_callback: WatchCallback) -> crate::Result<WatchHandle>;
}

/// DirectoryClone
Expand Down
2 changes: 1 addition & 1 deletion src/directory/managed_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Directory for ManagedDirectory {
self.directory.acquire_lock(lock)
}

fn watch(&self, watch_callback: WatchCallback) -> WatchHandle {
fn watch(&self, watch_callback: WatchCallback) -> crate::Result<WatchHandle> {
self.directory.watch(watch_callback)
}
}
Expand Down
33 changes: 25 additions & 8 deletions src/directory/mmap_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl InnerWatcherWrapper {
}

#[derive(Clone)]
pub(crate) struct WatcherWrapper {
struct WatcherWrapper {
inner: Arc<InnerWatcherWrapper>,
}

Expand Down Expand Up @@ -231,27 +231,44 @@ struct MmapDirectoryInner {
root_path: PathBuf,
mmap_cache: RwLock<MmapCache>,
_temp_directory: Option<TempDir>,
watcher: RwLock<WatcherWrapper>,
watcher: RwLock<Option<WatcherWrapper>>,
}

impl MmapDirectoryInner {
fn new(
root_path: PathBuf,
temp_directory: Option<TempDir>,
) -> Result<MmapDirectoryInner, OpenDirectoryError> {
let watch_wrapper = WatcherWrapper::new(&root_path)?;
let mmap_directory_inner = MmapDirectoryInner {
root_path,
mmap_cache: Default::default(),
_temp_directory: temp_directory,
watcher: RwLock::new(watch_wrapper),
watcher: RwLock::new(None),
};
Ok(mmap_directory_inner)
}

fn watch(&self, watch_callback: WatchCallback) -> WatchHandle {
let mut wlock = self.watcher.write().unwrap();
wlock.watch(watch_callback)
fn watch(&self, watch_callback: WatchCallback) -> crate::Result<WatchHandle> {
// a lot of juggling here, to ensure we don't do anything that panics
// while the rwlock is held. That way we ensure that the rwlock cannot
// be poisoned.
//
// The downside is that we might create a watch wrapper that is not useful.
let need_initialization = self.watcher.read().unwrap().is_none();
if need_initialization {
let watch_wrapper = WatcherWrapper::new(&self.root_path)?;
let mut watch_wlock = self.watcher.write().unwrap();
// the watcher could have been initialized when we released the lock, and
// we do not want to lose the watched files that were set.
if watch_wlock.is_none() {
*watch_wlock = Some(watch_wrapper);
}
}
if let Some(watch_wrapper) = self.watcher.write().unwrap().as_mut() {
return Ok(watch_wrapper.watch(watch_callback));
} else {
unreachable!("At this point, watch wrapper is supposed to be initialized");
}
}
}

Expand Down Expand Up @@ -514,7 +531,7 @@ impl Directory for MmapDirectory {
})))
}

fn watch(&self, watch_callback: WatchCallback) -> WatchHandle {
fn watch(&self, watch_callback: WatchCallback) -> crate::Result<WatchHandle> {
self.inner.watch(watch_callback)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/directory/ram_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl Directory for RAMDirectory {
Ok(())
}

fn watch(&self, watch_callback: WatchCallback) -> WatchHandle {
self.fs.write().unwrap().watch(watch_callback)
fn watch(&self, watch_callback: WatchCallback) -> crate::Result<WatchHandle> {
Ok(self.fs.write().unwrap().watch(watch_callback))
}
}
2 changes: 1 addition & 1 deletion src/directory/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn test_watch(directory: &mut dyn Directory) {
thread::sleep(Duration::new(0, 10_000));
assert_eq!(0, counter.load(Ordering::SeqCst));

let watch_handle = directory.watch(watch_callback);
let watch_handle = directory.watch(watch_callback).unwrap();
for i in 0..10 {
assert_eq!(i, counter.load(Ordering::SeqCst));
assert!(directory
Expand Down
5 changes: 4 additions & 1 deletion src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl IndexReaderBuilder {
);
}
};
let watch_handle = inner_reader_arc.index.directory().watch(Box::new(callback));
let watch_handle = inner_reader_arc
.index
.directory()
.watch(Box::new(callback))?;
watch_handle_opt = Some(watch_handle);
}
}
Expand Down

0 comments on commit efd1af1

Please sign in to comment.