From fe330e1be96a3bf8c861751917e7fc2a9baa208d Mon Sep 17 00:00:00 2001 From: Irevoire Date: Wed, 7 Sep 2022 11:21:53 +0200 Subject: [PATCH] add a little bit of documentation --- index-scheduler/src/lib.rs | 16 ++++------------ index-scheduler/src/utils.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index debee8d59..f650dd448 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -70,6 +70,9 @@ pub struct IndexScheduler { } impl IndexScheduler { + /// 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 + /// `IndexNotFound` error. pub fn index(&self, name: &str) -> Result { let rtxn = self.env.read_txn()?; let uuid = self @@ -105,18 +108,6 @@ impl IndexScheduler { Ok(index) } - fn last_task_id(&self, rtxn: &RoTxn) -> Result> { - Ok(self - .all_tasks - .remap_data_type::() - .last(rtxn)? - .map(|(k, _)| k.get() + 1)) - } - - fn next_task_id(&self, rtxn: &RoTxn) -> Result { - Ok(self.last_task_id(rtxn)?.unwrap_or_default()) - } - /// Returns the tasks corresponding to the query. pub fn get_tasks(&self, query: Query) -> Result> { let rtxn = self.env.read_txn()?; @@ -200,6 +191,7 @@ impl IndexScheduler { Ok(()) } + /// Notify the scheduler there is or may be work to do. pub fn notify(&self) { self.wake_up .store(true, std::sync::atomic::Ordering::Relaxed); diff --git a/index-scheduler/src/utils.rs b/index-scheduler/src/utils.rs index c3c4c7350..dbebbae2a 100644 --- a/index-scheduler/src/utils.rs +++ b/index-scheduler/src/utils.rs @@ -1,7 +1,7 @@ //! Utility functions on the DBs. Mainly getter and setters. use milli::{ - heed::{RoTxn, RwTxn}, + heed::{types::DecodeIgnore, RoTxn, RwTxn}, BEU32, }; use roaring::RoaringBitmap; @@ -12,6 +12,18 @@ use crate::{ }; impl IndexScheduler { + pub(crate) fn last_task_id(&self, rtxn: &RoTxn) -> Result> { + Ok(self + .all_tasks + .remap_data_type::() + .last(rtxn)? + .map(|(k, _)| k.get() + 1)) + } + + pub(crate) fn next_task_id(&self, rtxn: &RoTxn) -> Result { + Ok(self.last_task_id(rtxn)?.unwrap_or_default()) + } + pub(crate) fn get_task(&self, rtxn: &RoTxn, task_id: TaskId) -> Result> { Ok(self.all_tasks.get(rtxn, &BEU32::new(task_id))?) }