From 4dc6b334400e8add2b435932013d3c070b832851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 7 Oct 2025 14:30:48 +0200 Subject: [PATCH] Introduce a function to effectively close an index --- crates/index-scheduler/src/index_mapper/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/index-scheduler/src/index_mapper/mod.rs b/crates/index-scheduler/src/index_mapper/mod.rs index 7e2d3b5e2..7cb11e80e 100644 --- a/crates/index-scheduler/src/index_mapper/mod.rs +++ b/crates/index-scheduler/src/index_mapper/mod.rs @@ -341,6 +341,24 @@ impl IndexMapper { Ok(()) } + /// Closes the specified index. + /// + /// This operation involves closing the underlying environment and so can take a long time to complete. + /// + /// # Panics + /// + /// - If the Index corresponding to the passed name is concurrently being deleted/resized or cannot be found in the + /// in memory hash map. + pub fn close_index(&self, rtxn: &RoTxn, name: &str) -> Result> { + let uuid = self + .index_mapping + .get(rtxn, name)? + .ok_or_else(|| Error::IndexNotFound(name.to_string()))?; + + // We remove the index from the in-memory index map. + Ok(self.index_map.write().unwrap().close_for_resize(&uuid, self.enable_mdb_writemap, 0)) + } + /// Return an index, may open it if it wasn't already opened. pub fn index(&self, rtxn: &RoTxn, name: &str) -> Result { if let Some((current_name, current_index)) =