implement the index swap in the index mapper

This commit is contained in:
Tamo 2022-09-14 12:58:48 +02:00 committed by Clément Renault
parent 03aca2e452
commit 7b6673dc1d
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -88,4 +88,21 @@ impl IndexMapper {
Ok(index) 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(())
}
} }