aboutsummaryrefslogtreecommitdiffstats
path: root/log_db/src/engine.rs
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-01-18 09:48:55 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-01-18 09:48:55 +0200
commitbe9caff6b158a762418815ff2cbaf521b6727029 (patch)
treef7c63a549bc4331b0fe6598417e687e58abf0d41 /log_db/src/engine.rs
parent46942daf0292d2cce4cf5b46b0831ef4ffed0526 (diff)
Make lock manager stricter
Diffstat (limited to 'log_db/src/engine.rs')
-rw-r--r--log_db/src/engine.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/log_db/src/engine.rs b/log_db/src/engine.rs
index 8ad4590..c682704 100644
--- a/log_db/src/engine.rs
+++ b/log_db/src/engine.rs
@@ -61,8 +61,6 @@ impl<R: Recordable> Engine<R> {
fs::File::create(data_dir_path.join(INITIALIZED_FILENAME))?;
}
- lock_manager.unlock()?;
-
// Calculate the index of the primary value in a record
let primary_key_index = config
.fields
@@ -125,6 +123,7 @@ impl<R: Recordable> Engine<R> {
info!("Database ready.");
+ engine.lock_manager.unlock()?;
Ok(engine)
}
@@ -506,7 +505,7 @@ impl<R: Recordable> Engine<R> {
let correct = is_file_same_as_path(&self.active_metadata_file, &active_metadata_path)?;
if !correct {
debug!("Metadata file has been rotated. Reopening...");
- let mut metadata_file = APPEND_MODE.open(&active_metadata_path)?;
+ let metadata_file = APPEND_MODE.open(&active_metadata_path)?;
let metadata_header = read_metadata_header(&mut self.active_metadata_file)?;
@@ -715,20 +714,22 @@ impl<R: Recordable> Engine<R> {
.map(|(_, t)| t)
}
+ #[inline]
pub fn with_exclusive_lock<T>(
&mut self,
f: impl FnOnce(&mut Self) -> DBResult<T>,
) -> DBResult<T> {
self.lock_manager.lock_exclusive()?;
- let result = f(self)?;
+ let result = f(self);
self.lock_manager.unlock()?;
- Ok(result)
+ result
}
+ #[inline]
pub fn with_shared_lock<T>(&mut self, f: impl FnOnce(&mut Self) -> DBResult<T>) -> DBResult<T> {
self.lock_manager.lock_shared()?;
- let result = f(self)?;
+ let result = f(self);
self.lock_manager.unlock()?;
- Ok(result)
+ result
}
}