mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 11:35:05 +08:00
get rids of the horrendous spinlock in favor of synchronoise
This commit is contained in:
parent
7b6673dc1d
commit
366a344474
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1791,6 +1791,7 @@ dependencies = [
|
|||||||
"nelson",
|
"nelson",
|
||||||
"roaring 0.9.0",
|
"roaring 0.9.0",
|
||||||
"serde",
|
"serde",
|
||||||
|
"synchronoise",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
|
@ -19,6 +19,7 @@ tempfile = "3.3.0"
|
|||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] }
|
time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] }
|
||||||
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
||||||
|
synchronoise = "1.0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
nelson = { git = "https://github.com/meilisearch/nelson.git", rev = "675f13885548fb415ead8fbb447e9e6d9314000a"}
|
nelson = { git = "https://github.com/meilisearch/nelson.git", rev = "675f13885548fb415ead8fbb447e9e6d9314000a"}
|
||||||
|
@ -10,6 +10,7 @@ pub use error::Error;
|
|||||||
use file_store::FileStore;
|
use file_store::FileStore;
|
||||||
use index::Index;
|
use index::Index;
|
||||||
use index_mapper::IndexMapper;
|
use index_mapper::IndexMapper;
|
||||||
|
use synchronoise::SignalEvent;
|
||||||
pub use task::Task;
|
pub use task::Task;
|
||||||
use task::{Kind, KindWithContent, Status};
|
use task::{Kind, KindWithContent, Status};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
@ -73,10 +74,16 @@ pub struct IndexScheduler {
|
|||||||
index_mapper: IndexMapper,
|
index_mapper: IndexMapper,
|
||||||
|
|
||||||
// set to true when there is work to do.
|
// set to true when there is work to do.
|
||||||
wake_up: Arc<AtomicBool>,
|
wake_up: Arc<SignalEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexScheduler {
|
impl IndexScheduler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
// we want to start the loop right away in case meilisearch was ctrl+Ced while processing things
|
||||||
|
let wake_up = SignalEvent::auto(true);
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the index corresponding to the name. If it wasn't opened before
|
/// Return the index corresponding to the name. If it wasn't opened before
|
||||||
/// it'll be opened. But if it doesn't exist on disk it'll throw an
|
/// it'll be opened. But if it doesn't exist on disk it'll throw an
|
||||||
/// `IndexNotFound` error.
|
/// `IndexNotFound` error.
|
||||||
@ -166,8 +173,7 @@ impl IndexScheduler {
|
|||||||
/// This worker function must be run in a different thread and must be run only once.
|
/// This worker function must be run in a different thread and must be run only once.
|
||||||
fn run(&self) {
|
fn run(&self) {
|
||||||
loop {
|
loop {
|
||||||
// TODO: TAMO: remove this horrible spinlock in favor of a sleep / channel / we’ll see
|
self.wake_up.wait();
|
||||||
while !self.wake_up.swap(false, Ordering::Relaxed) {}
|
|
||||||
|
|
||||||
let mut wtxn = match self.env.write_txn() {
|
let mut wtxn = match self.env.write_txn() {
|
||||||
Ok(wtxn) => wtxn,
|
Ok(wtxn) => wtxn,
|
||||||
@ -370,7 +376,6 @@ impl IndexScheduler {
|
|||||||
|
|
||||||
/// Notify the scheduler there is or may be work to do.
|
/// Notify the scheduler there is or may be work to do.
|
||||||
pub fn notify(&self) {
|
pub fn notify(&self) {
|
||||||
self.wake_up
|
self.wake_up.signal()
|
||||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user