refactor: Rearrange reading of db rules and locking
@@ -991,17 +991,21 @@ impl Db {
/// Given a `SequencedEntry`, if the mutable buffer is configured, the `SequencedEntry` is then
/// written into the mutable buffer.
pub fn store_sequenced_entry(&self, sequenced_entry: Arc<SequencedEntry>) -> Result<()> {
+ // Get all needed database rule values, then release the lock
let rules = self.rules.read();
let mutable_size_threshold = rules.lifecycle_rules.mutable_size_threshold;
- if rules.lifecycle_rules.immutable {
+ let immutable = rules.lifecycle_rules.immutable;
+ let buffer_size_hard = rules.lifecycle_rules.buffer_size_hard;
+ std::mem::drop(rules);
+
+ if immutable {
return DatabaseNotWriteable {}.fail();
}
- if let Some(hard_limit) = rules.lifecycle_rules.buffer_size_hard {
+ if let Some(hard_limit) = buffer_size_hard {
if self.preserved_catalog.state().metrics().memory().total() > hard_limit.get() {
return HardLimitReached {}.fail();
}
}
- std::mem::drop(rules);
// TODO: Direct writes to closing chunks
