Skip to content

Commit

Permalink
Fixing flush control
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Feb 8, 2024
1 parent 1838d0c commit 1c999ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/core/index/writer/flush_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use core::index::writer::{
};
use core::util::external::Volatile;
use error::Result;
use std::cell::UnsafeCell;

use core::store::directory::Directory;
use std::collections::{HashMap, VecDeque};
Expand Down Expand Up @@ -101,14 +102,24 @@ impl<D: Directory + Send + Sync + 'static, C: Codec, MS: MergeScheduler, MP: Mer
unsafe { &*self.per_thread_pool }
}

unsafe fn get_self(
ptr: &UnsafeCell<DocumentsWriterFlushControl<D, C, MS, MP>>,
) -> &mut DocumentsWriterFlushControl<D, C, MS, MP> {
unsafe { &mut *ptr.get() }
}

#[allow(clippy::mut_from_ref)]
unsafe fn flush_control_mut(
&self,
_l: &MutexGuard<FlushControlLock>,
) -> &mut DocumentsWriterFlushControl<D, C, MS, MP> {
let control = self as *const DocumentsWriterFlushControl<D, C, MS, MP>
as *mut DocumentsWriterFlushControl<D, C, MS, MP>;
&mut *control
as *mut DocumentsWriterFlushControl<D, C, MS, MP>
as *const UnsafeCell<DocumentsWriterFlushControl<D, C, MS, MP>>;
unsafe {
let s = DocumentsWriterFlushControl::get_self(control.as_ref().unwrap());
&mut *s
}
}

pub fn do_after_document(
Expand Down
14 changes: 12 additions & 2 deletions src/core/index/writer/index_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use core::util::to_base36;
use core::util::{BitsRef, DerefWrapper, DocId, VERSION_LATEST};

use core::index::ErrorKind::MergeAborted;
use std::cell::UnsafeCell;
use error::ErrorKind::{AlreadyClosed, IllegalArgument, IllegalState, Index, RuntimeError};
use error::{Error, Result};

Expand Down Expand Up @@ -1061,11 +1062,20 @@ where
})
}

unsafe fn get_self(
ptr: &UnsafeCell<IndexWriterInner<D, C, MS, MP>>,
) -> &mut IndexWriterInner<D, C, MS, MP> {
unsafe { &mut *ptr.get() }
}

#[allow(clippy::mut_from_ref)]
unsafe fn writer_mut(&self, _l: &MutexGuard<()>) -> &mut IndexWriterInner<D, C, MS, MP> {
let writer =
self as *const IndexWriterInner<D, C, MS, MP> as *mut IndexWriterInner<D, C, MS, MP>;
&mut *writer
self as *const IndexWriterInner<D, C, MS, MP> as *mut IndexWriterInner<D, C, MS, MP> as *const UnsafeCell<IndexWriterInner<D, C, MS, MP>>;
unsafe {
let s = IndexWriterInner::get_self(writer.as_ref().unwrap());
&mut *s
}
}

fn get_reader(
Expand Down

0 comments on commit 1c999ec

Please sign in to comment.