From 4ca4296295ebefc09e56eea323619bbf2421d274 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 11 Jul 2024 09:26:35 +1000 Subject: [PATCH] Remove reward from PostCommitWork It's not needed, we can do it safely without embedding T in there. --- src/handle.rs | 9 +++++---- src/lib.rs | 7 +++---- src/ownedtx.rs | 4 ++-- src/reader.rs | 2 +- src/tx.rs | 11 ++++------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/handle.rs b/src/handle.rs index ec18d9a..8c5d62b 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -302,7 +302,7 @@ impl Handle { // Maybe it's okay just to commit anyway, since we have a deferred transaction and sqlite // might know nothing has changed. if deleted.is_some() { - tx.commit(())?.complete(); + tx.commit()?.complete(); } Ok(deleted) } @@ -319,7 +319,8 @@ impl Handle { pub fn rename_item(&mut self, from: &[u8], to: &[u8]) -> PubResult { let mut tx = self.start_immediate_transaction()?; let last_used = tx.rename_item(from, to)?; - Ok(tx.commit(last_used)?.complete()) + tx.commit()?.complete(); + Ok(last_used) } /// Walks the underlying files in the possum directory. @@ -451,7 +452,7 @@ impl Handle { to_vec.extend_from_slice(item.key.strip_prefix(from).unwrap()); tx.rename_item(&item.key, &to_vec)?; } - tx.commit(())?.complete(); + tx.commit()?.complete(); Ok(()) } @@ -460,7 +461,7 @@ impl Handle { for item in tx.list_items(prefix)? { tx.delete_key(&item.key)?; } - tx.commit(())?.complete(); + tx.commit()?.complete(); Ok(()) } } diff --git a/src/lib.rs b/src/lib.rs index 07208af..dbb72b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -344,12 +344,11 @@ impl<'handle> BatchWriter<'handle> { transaction.rename_value(&vr.value, vr.new_key)?; } // TODO: On error here, rewind the exclusive to undo any writes that just occurred. - let work = transaction - .commit(write_commit_res) - .context("commit transaction")?; + let work = transaction.commit().context("commit transaction")?; self.flush_exclusive_files(); - Ok(work.complete()) + work.complete(); + Ok(write_commit_res) } /// Flush Writer's exclusive files and return them to the Handle pool. diff --git a/src/ownedtx.rs b/src/ownedtx.rs index 02caab8..2c35972 100644 --- a/src/ownedtx.rs +++ b/src/ownedtx.rs @@ -31,8 +31,8 @@ impl DerefMut for OwnedTx<'_> { impl<'a> OwnedTx<'a> { // Except for this move dependent dance it shouldn't be necessary to wrap the OwnedCell. - pub fn commit(self, reward: T) -> Result> { - self.cell.move_dependent(|tx| tx.commit(reward)) + pub fn commit(self) -> Result> { + self.cell.move_dependent(|tx| tx.commit()) } } diff --git a/src/reader.rs b/src/reader.rs index 1c6318d..5f7f48e 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -37,7 +37,7 @@ impl<'a> Reader<'a> { pub fn begin(self) -> Result { let file_clones = self.clone_files().context("cloning files")?; self.owned_tx - .commit(()) + .commit() .context("committing transaction")? .complete(); Ok(Snapshot { file_clones }) diff --git a/src/tx.rs b/src/tx.rs index aa84e4b..10f1a88 100644 --- a/src/tx.rs +++ b/src/tx.rs @@ -2,11 +2,10 @@ use super::*; /// This is more work to be done after the Handle conn mutex is released. #[must_use] -pub(crate) struct PostCommitWork<'h, T> { +pub(crate) struct PostCommitWork<'h> { handle: &'h Handle, deleted_values: Vec, altered_files: HashSet, - reward: T, } /// Exposes a rusqlite Transaction to implement ReadTransaction. @@ -146,8 +145,8 @@ fn list_items_inner( .map_err(Into::into) } -impl<'h, T> PostCommitWork<'h, T> { - pub fn complete(self) -> T { +impl<'h> PostCommitWork<'h> { + pub fn complete(self) { // This has to happen after exclusive files are flushed or there's a tendency for hole // punches to not persist. It doesn't fix the problem, but it significantly reduces it. if !self.handle.instance_limits.disable_hole_punching { @@ -157,7 +156,6 @@ impl<'h, T> PostCommitWork<'h, T> { for file_id in self.altered_files { self.handle.clones.lock().unwrap().remove(&file_id); } - self.reward } } @@ -190,14 +188,13 @@ impl<'h> Transaction<'h> { } } - pub(crate) fn commit(mut self, reward: T) -> Result> { + pub(crate) fn commit(mut self) -> Result> { self.apply_limits()?; self.tx.commit()?; Ok(PostCommitWork { handle: self.handle, deleted_values: self.deleted_values, altered_files: self.altered_files, - reward, }) }