Update registry DB delete to be atomic
Updates the `RegistryInsertNodeOperation::delete_node` operation for the
Diesel-backed registry store to be fully atomic. This requires wrapping
the contents of the method in a Diesel transaction to ensure the fetch
and removal happen in the same DB transaction.
@@ -30,13 +30,18 @@ where
String: diesel::deserialize::FromSql<diesel::sql_types::Text, C::Backend>,
{
fn delete_node(&self, identity: &str) -> Result<Option<Node>, RegistryError> {
+ self.conn.transaction(|| {
self.fetch_node(identity).and_then(|node| {
delete(splinter_nodes::table.find(identity))
.execute(self.conn)
.map_err(|err| {
- RegistryError::general_error_with_source("Failed to delete node", Box::new(err))
+ RegistryError::general_error_with_source(
+ "Failed to delete node",
+ Box::new(err),
+ )
})?;
Ok(node)
})
+ })
}
}
