Preparing the ground in the IndexReader.

This commit is contained in:
Paul Masurel
2019-12-31 09:44:58 +09:00
parent 97d808ef50
commit c0ec7ebf38
2 changed files with 18 additions and 9 deletions

View File

@@ -90,7 +90,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

@@ -121,15 +121,24 @@ struct InnerIndexReader {
}
impl InnerIndexReader {
fn load_segment_readers(&self) -> 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::<Result<_>>()
}
fn reload(&self) -> 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::<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()))