Skip to content
Snippets Groups Projects
Commit 177ed5df authored by Denis Smirnov's avatar Denis Smirnov
Browse files

fix: LRU inconsistency on eviction failure

parent 213d358f
No related branches found
No related tags found
1 merge request!495Resolve "Prepared statement with id XXX does not exist"
......@@ -180,6 +180,7 @@ where
};
let map = &mut self.map;
let mut evict_result = None;
if let Some(evict_fn) = &self.evict_fn {
let head_prev = map.get_mut(&head_prev_id).ok_or_else(|| {
SbroadError::NotFound(
......@@ -187,7 +188,8 @@ where
format_smolstr!("(mutable LRU) with key {:?}", &head_prev_id),
)
})?;
evict_fn(key, &mut head_prev.value)?;
// If eviction function failed, we still need to remove the node.
evict_result = Some(evict_fn(key, &mut head_prev.value));
}
self.unlink_node(&head_prev_id)?;
......@@ -195,6 +197,9 @@ where
self.map.remove(&Some(last_key.clone()));
self.size -= 1;
}
if let Some(evict_result) = evict_result {
evict_result?;
}
Ok(())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment