diff --git a/CHANGELOG.md b/CHANGELOG.md index 812007614a..51e037d892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `StdFile::flush()` is now implemented using `std::File::flush()`. To synchronize all data and metadata, use `File::synchronize()` instead. +- `TransactionLog::current_transaction_id` has been removed, and + `TransactionLog::state` now returns a reference to the current state. This + function previously was returning `State::next_transaction_id()`, which made + the name a little weird. To preserve existing behavior, use + `log.state().next_transaction_id()`. ### Fixed diff --git a/nebari/src/transaction/log.rs b/nebari/src/transaction/log.rs index ecdf3e5732..8780be0041 100644 --- a/nebari/src/transaction/log.rs +++ b/nebari/src/transaction/log.rs @@ -150,11 +150,6 @@ impl TransactionLog { self.log.close() } - /// Returns the current transaction id. - pub fn current_transaction_id(&self) -> TransactionId { - self.state.next_transaction_id() - } - /// Begins a new transaction, exclusively locking `trees`. pub fn new_transaction< 'a, @@ -168,8 +163,8 @@ impl TransactionLog { } /// Returns the current state of the log. - pub fn state(&self) -> State { - self.state.clone() + pub fn state(&self) -> &State { + &self.state } } @@ -728,6 +723,7 @@ mod tests { log_file_tests("any_memory_log_file", AnyFileManager::memory(), None, None); } + #[allow(clippy::too_many_lines)] fn log_file_tests( file_name: &str, file_manager: Manager, @@ -756,7 +752,10 @@ mod tests { TransactionLog::::initialize_state(&state, &context).unwrap(); let mut transactions = TransactionLog::::open(&log_path, state, context.clone()).unwrap(); - assert_eq!(transactions.current_transaction_id(), TransactionId(id)); + assert_eq!( + transactions.state().next_transaction_id(), + TransactionId(id) + ); let mut tx = transactions.new_transaction([&b"hello"[..]]); tx.transaction.data = Some(ArcBytes::from(id.to_be_bytes())); @@ -870,7 +869,10 @@ mod tests { let mut valid_ids = HashSet::new(); for id in 1..=10_000 { - assert_eq!(transactions.current_transaction_id(), TransactionId(id)); + assert_eq!( + transactions.state().next_transaction_id(), + TransactionId(id) + ); let tx = transactions.new_transaction([&b"hello"[..]]); if rng.generate::() < 8 { // skip a few ids. diff --git a/nebari/src/transaction/manager.rs b/nebari/src/transaction/manager.rs index 797026eb35..7c46daabe6 100644 --- a/nebari/src/transaction/manager.rs +++ b/nebari/src/transaction/manager.rs @@ -207,7 +207,7 @@ impl ManagerThread { return; } }; - let transaction_id = log.current_transaction_id(); + let transaction_id = log.state().next_transaction_id(); drop(state_sender.send(Ok(state))); Self {