diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index 80e4127c0..52b269b06 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -1,12 +1,16 @@ +use std::borrow::Cow; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::convert::TryInto; use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; use std::{fs, thread}; use log::error; -use meilisearch_types::heed::types::{SerdeBincode, Str}; -use meilisearch_types::heed::{Database, Env, EnvOpenOptions, RoTxn, RwTxn}; +use meilisearch_types::heed::types::Str; +use meilisearch_types::heed::{ + BytesDecode, BytesEncode, Database, Env, EnvOpenOptions, RoTxn, RwTxn, +}; use meilisearch_types::milli::update::IndexerConfig; use meilisearch_types::milli::Index; use uuid::Uuid; @@ -28,9 +32,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, @@ -228,3 +231,22 @@ impl IndexMapper { &self.indexer_config } } + +/// 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())) + } +}