From 7b6673dc1d8d9ef6461748b2540c846c62e77793 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 14 Sep 2022 12:58:48 +0200 Subject: [PATCH] implement the index swap in the index mapper --- index-scheduler/src/index_mapper.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index-scheduler/src/index_mapper.rs b/index-scheduler/src/index_mapper.rs index b314ee861..43d72b51d 100644 --- a/index-scheduler/src/index_mapper.rs +++ b/index-scheduler/src/index_mapper.rs @@ -88,4 +88,21 @@ impl IndexMapper { Ok(index) } + + /// Swap two index name. + pub fn swap(&self, wtxn: &mut RwTxn, lhs: &str, rhs: &str) -> Result<()> { + let lhs_uuid = self + .index_mapping + .get(wtxn, lhs)? + .ok_or(Error::IndexNotFound(lhs.to_string()))?; + let rhs_uuid = self + .index_mapping + .get(wtxn, rhs)? + .ok_or(Error::IndexNotFound(rhs.to_string()))?; + + self.index_mapping.put(wtxn, lhs, &rhs_uuid)?; + self.index_mapping.put(wtxn, rhs, &lhs_uuid)?; + + Ok(()) + } }