diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index 80e4127c0..b75267927 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -5,13 +5,14 @@ use std::sync::{Arc, RwLock}; use std::{fs, thread}; use log::error; -use meilisearch_types::heed::types::{SerdeBincode, Str}; +use meilisearch_types::heed::types::Str; use meilisearch_types::heed::{Database, Env, EnvOpenOptions, RoTxn, RwTxn}; use meilisearch_types::milli::update::IndexerConfig; use meilisearch_types::milli::Index; use uuid::Uuid; use self::IndexStatus::{Available, BeingDeleted}; +use crate::uuid_codec::UuidCodec; use crate::{Error, Result}; const INDEX_MAPPING: &str = "index-mapping"; @@ -28,9 +29,8 @@ pub struct IndexMapper { /// Keep track of the opened indexes. Used mainly by the index resolver. index_map: Arc>>, - // TODO create a UUID Codec that uses the 16 bytes representation /// Map an index name with an index uuid currently available on disk. - pub(crate) index_mapping: Database>, + pub(crate) index_mapping: Database, /// Path to the folder where the LMDB environments of each index are. base_path: PathBuf, diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index a25f74a69..1807bdb40 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -25,6 +25,7 @@ mod index_mapper; #[cfg(test)] mod insta_snapshot; mod utils; +mod uuid_codec; pub type Result = std::result::Result; pub type TaskId = u32; diff --git a/index-scheduler/src/uuid_codec.rs b/index-scheduler/src/uuid_codec.rs new file mode 100644 index 000000000..70a92ca94 --- /dev/null +++ b/index-scheduler/src/uuid_codec.rs @@ -0,0 +1,24 @@ +use std::borrow::Cow; +use std::convert::TryInto; + +use meilisearch_types::heed::{BytesDecode, BytesEncode}; +use uuid::Uuid; + +/// A heed codec for value of struct Uuid. +pub struct UuidCodec; + +impl<'a> BytesDecode<'a> for UuidCodec { + type DItem = Uuid; + + fn bytes_decode(bytes: &'a [u8]) -> Option { + bytes.try_into().ok().map(Uuid::from_bytes) + } +} + +impl BytesEncode<'_> for UuidCodec { + type EItem = Uuid; + + fn bytes_encode(item: &Self::EItem) -> Option> { + Some(Cow::Borrowed(item.as_bytes())) + } +}