Skip to content

Commit 7011721

Browse files
committed
Handle empty mutable txs wrt the offset returned on commit
1 parent 0437aad commit 7011721

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/datastore/src/locking_tx_datastore/mut_tx.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,19 @@ impl MutTxId {
12041204
);
12051205
let reducer = self.ctx.into_reducer_name();
12061206

1207+
// If the transaction didn't consume an offset (i.e. it was empty),
1208+
// report the previous offset.
1209+
//
1210+
// Note that technically the tx could have run against an empty database,
1211+
// in which case we'd wrongly return zero (a non-existent transaction).
1212+
// This doesn not happen in practice, however, as [RelationalDB::set_initialized]
1213+
// creates a transaction.
1214+
let tx_offset = if tx_offset == self.committed_state_write_lock.next_tx_offset {
1215+
tx_offset.saturating_sub(1)
1216+
} else {
1217+
tx_offset
1218+
};
1219+
12071220
(tx_offset, tx_data, tx_metrics, reducer)
12081221
}
12091222

crates/datastore/src/locking_tx_datastore/tx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl TxId {
9696
pub(super) fn release(self) -> (TxOffset, TxMetrics, String) {
9797
// A read tx doesn't consume `next_tx_offset`, so subtract one to obtain
9898
// the offset that was visible to the transaction.
99+
//
99100
// Note that technically the tx could have run against an empty database,
100101
// in which case we'd wrongly return zero (a non-existent transaction).
101102
// This doesn not happen in practice, however, as [RelationalDB::set_initialized]

0 commit comments

Comments
 (0)