Skip to content

Commit 4ca4296

Browse files
committed
Remove reward from PostCommitWork
It's not needed, we can do it safely without embedding T in there.
1 parent b9a432e commit 4ca4296

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

src/handle.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl Handle {
302302
// Maybe it's okay just to commit anyway, since we have a deferred transaction and sqlite
303303
// might know nothing has changed.
304304
if deleted.is_some() {
305-
tx.commit(())?.complete();
305+
tx.commit()?.complete();
306306
}
307307
Ok(deleted)
308308
}
@@ -319,7 +319,8 @@ impl Handle {
319319
pub fn rename_item(&mut self, from: &[u8], to: &[u8]) -> PubResult<Timestamp> {
320320
let mut tx = self.start_immediate_transaction()?;
321321
let last_used = tx.rename_item(from, to)?;
322-
Ok(tx.commit(last_used)?.complete())
322+
tx.commit()?.complete();
323+
Ok(last_used)
323324
}
324325

325326
/// Walks the underlying files in the possum directory.
@@ -451,7 +452,7 @@ impl Handle {
451452
to_vec.extend_from_slice(item.key.strip_prefix(from).unwrap());
452453
tx.rename_item(&item.key, &to_vec)?;
453454
}
454-
tx.commit(())?.complete();
455+
tx.commit()?.complete();
455456
Ok(())
456457
}
457458

@@ -460,7 +461,7 @@ impl Handle {
460461
for item in tx.list_items(prefix)? {
461462
tx.delete_key(&item.key)?;
462463
}
463-
tx.commit(())?.complete();
464+
tx.commit()?.complete();
464465
Ok(())
465466
}
466467
}

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,11 @@ impl<'handle> BatchWriter<'handle> {
344344
transaction.rename_value(&vr.value, vr.new_key)?;
345345
}
346346
// TODO: On error here, rewind the exclusive to undo any writes that just occurred.
347-
let work = transaction
348-
.commit(write_commit_res)
349-
.context("commit transaction")?;
347+
let work = transaction.commit().context("commit transaction")?;
350348

351349
self.flush_exclusive_files();
352-
Ok(work.complete())
350+
work.complete();
351+
Ok(write_commit_res)
353352
}
354353

355354
/// Flush Writer's exclusive files and return them to the Handle pool.

src/ownedtx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl DerefMut for OwnedTx<'_> {
3131

3232
impl<'a> OwnedTx<'a> {
3333
// Except for this move dependent dance it shouldn't be necessary to wrap the OwnedCell.
34-
pub fn commit<T>(self, reward: T) -> Result<PostCommitWork<'a, T>> {
35-
self.cell.move_dependent(|tx| tx.commit(reward))
34+
pub fn commit(self) -> Result<PostCommitWork<'a>> {
35+
self.cell.move_dependent(|tx| tx.commit())
3636
}
3737
}
3838

src/reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> Reader<'a> {
3737
pub fn begin(self) -> Result<Snapshot> {
3838
let file_clones = self.clone_files().context("cloning files")?;
3939
self.owned_tx
40-
.commit(())
40+
.commit()
4141
.context("committing transaction")?
4242
.complete();
4343
Ok(Snapshot { file_clones })

src/tx.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use super::*;
22

33
/// This is more work to be done after the Handle conn mutex is released.
44
#[must_use]
5-
pub(crate) struct PostCommitWork<'h, T> {
5+
pub(crate) struct PostCommitWork<'h> {
66
handle: &'h Handle,
77
deleted_values: Vec<NonzeroValueLocation>,
88
altered_files: HashSet<FileId>,
9-
reward: T,
109
}
1110

1211
/// Exposes a rusqlite Transaction to implement ReadTransaction.
@@ -146,8 +145,8 @@ fn list_items_inner(
146145
.map_err(Into::into)
147146
}
148147

149-
impl<'h, T> PostCommitWork<'h, T> {
150-
pub fn complete(self) -> T {
148+
impl<'h> PostCommitWork<'h> {
149+
pub fn complete(self) {
151150
// This has to happen after exclusive files are flushed or there's a tendency for hole
152151
// punches to not persist. It doesn't fix the problem, but it significantly reduces it.
153152
if !self.handle.instance_limits.disable_hole_punching {
@@ -157,7 +156,6 @@ impl<'h, T> PostCommitWork<'h, T> {
157156
for file_id in self.altered_files {
158157
self.handle.clones.lock().unwrap().remove(&file_id);
159158
}
160-
self.reward
161159
}
162160
}
163161

@@ -190,14 +188,13 @@ impl<'h> Transaction<'h> {
190188
}
191189
}
192190

193-
pub(crate) fn commit<T>(mut self, reward: T) -> Result<PostCommitWork<'h, T>> {
191+
pub(crate) fn commit(mut self) -> Result<PostCommitWork<'h>> {
194192
self.apply_limits()?;
195193
self.tx.commit()?;
196194
Ok(PostCommitWork {
197195
handle: self.handle,
198196
deleted_values: self.deleted_values,
199197
altered_files: self.altered_files,
200-
reward,
201198
})
202199
}
203200

0 commit comments

Comments
 (0)