Preparing the ground in the IndexReader.

This commit is contained in:
Paul Masurel
2019-12-31 09:44:58 +09:00
parent 4c6bbca661
commit 444048d225
2 changed files with 18 additions and 9 deletions

View File

@@ -87,7 +87,7 @@ impl Segment {
///
/// That segment is entirely dissociated from the index directory.
/// It will be persisted by a background thread in charge of IO.
pub fn new_unpersisted(meta: SegmentMeta, schema: Schema) -> Segment {
pub fn new_volatile(meta: SegmentMeta, schema: Schema) -> Segment {
Segment {
schema,
meta,

View File

@@ -120,15 +120,24 @@ struct InnerIndexReader {
}
impl InnerIndexReader {
fn load_segment_readers(&self) -> crate::Result<Vec<SegmentReader>> {
// We keep the lock until we have effectively finished opening the
// the `SegmentReader` because it prevents a diffferent process
// to garbage collect these file while we open them.
//
// Once opened, on linux & mac, the mmap will remain valid after
// the file has been deleted
// On windows, the file deletion will fail.
let _meta_lock = self.index.directory().acquire_lock(&META_LOCK)?;
let searchable_segments = self.searchable_segments()?;
searchable_segments
.iter()
.map(SegmentReader::open)
.collect::<crate::Result<_>>()
}
fn reload(&self) -> crate::Result<()> {
let segment_readers: Vec<SegmentReader> = {
let _meta_lock = self.index.directory().acquire_lock(&META_LOCK)?;
let searchable_segments = self.searchable_segments()?;
searchable_segments
.iter()
.map(SegmentReader::open)
.collect::<crate::Result<_>>()?
};
let segment_readers: Vec<SegmentReader> = self.load_segment_readers()?;
let schema = self.index.schema();
let searchers = (0..self.num_searchers)
.map(|_| Searcher::new(schema.clone(), self.index.clone(), segment_readers.clone()))