diff --git a/src/db.rs b/src/db.rs index 6ba46896..f308786d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -63,13 +63,13 @@ struct AtomicTransactionId { impl AtomicTransactionId { fn new(last_id: TransactionId) -> Self { Self { - inner: AtomicU64::new(last_id.0), + inner: AtomicU64::new(last_id.raw_id()), } } fn next(&self) -> TransactionId { let id = self.inner.fetch_add(1, Ordering::AcqRel); - TransactionId(id) + TransactionId::new(id) } } @@ -483,7 +483,7 @@ impl Database { mem, )?; let lookup_key = FreedTableKey { - transaction_id: oldest_unprocessed_free_transaction.0, + transaction_id: oldest_unprocessed_free_transaction.raw_id(), pagination_id: 0, }; for result in freed_table.range::(lookup_key..)? { @@ -609,7 +609,7 @@ impl Database { let freed_root = mem.get_freed_root(); // Allow processing of all transactions, since this is the main freed tree - Self::mark_freed_tree(freed_root, mem, TransactionId(0))?; + Self::mark_freed_tree(freed_root, mem, TransactionId::new(0))?; let freed_table: ReadOnlyTable> = ReadOnlyTable::new( "internal freed table".to_string(), freed_root, @@ -620,7 +620,7 @@ impl Database { // Make sure we don't reprocess those frees, as that would result in a double-free let oldest_unprocessed_transaction = if let Some(entry) = freed_table.range::(..)?.next() { - TransactionId(entry?.0.value().transaction_id) + TransactionId::new(entry?.0.value().transaction_id) } else { mem.get_last_committed_transaction_id()? }; diff --git a/src/transaction_tracker.rs b/src/transaction_tracker.rs index aeba7d27..79f05fbf 100644 --- a/src/transaction_tracker.rs +++ b/src/transaction_tracker.rs @@ -5,9 +5,17 @@ use std::collections::btree_set::BTreeSet; use std::mem::size_of; #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)] -pub(crate) struct TransactionId(pub u64); +pub(crate) struct TransactionId(u64); impl TransactionId { + pub(crate) fn new(value: u64) -> TransactionId { + Self(value) + } + + pub(crate) fn raw_id(&self) -> u64 { + self.0 + } + pub(crate) fn next(&self) -> TransactionId { TransactionId(self.0 + 1) } diff --git a/src/transactions.rs b/src/transactions.rs index a9eda881..c4bb9565 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -680,7 +680,7 @@ impl<'db> WriteTransaction<'db> { { entry?.key().transaction_id } else { - self.transaction_id.0 + self.transaction_id.raw_id() }; let mut freed_tree = BtreeMut::new( @@ -1018,7 +1018,7 @@ impl<'db> WriteTransaction<'db> { // We assume below that PageNumber is length 8 assert_eq!(PageNumber::serialized_size(), 8); let lookup_key = FreedTableKey { - transaction_id: oldest_live_read.0, + transaction_id: oldest_live_read.raw_id(), pagination_id: 0, }; @@ -1058,7 +1058,7 @@ impl<'db> WriteTransaction<'db> { let chunk_size = 100; let buffer_size = FreedPageList::required_bytes(chunk_size); let key = FreedTableKey { - transaction_id: self.transaction_id.0, + transaction_id: self.transaction_id.raw_id(), pagination_id: pagination_counter, }; let mut access_guard = diff --git a/src/tree_store/page_store/header.rs b/src/tree_store/page_store/header.rs index 15d53654..c0651a76 100644 --- a/src/tree_store/page_store/header.rs +++ b/src/tree_store/page_store/header.rs @@ -353,7 +353,7 @@ impl TransactionHeader { } else { None }; - let transaction_id = TransactionId(get_u64(&data[TRANSACTION_ID_OFFSET..])); + let transaction_id = TransactionId::new(get_u64(&data[TRANSACTION_ID_OFFSET..])); let result = Self { version, @@ -394,7 +394,7 @@ impl TransactionHeader { .copy_from_slice(&checksum.to_le_bytes()); } result[TRANSACTION_ID_OFFSET..(TRANSACTION_ID_OFFSET + size_of::())] - .copy_from_slice(&self.transaction_id.0.to_le_bytes()); + .copy_from_slice(&self.transaction_id.raw_id().to_le_bytes()); let checksum = xxh3_checksum(&result[..SLOT_CHECKSUM_OFFSET]); result[SLOT_CHECKSUM_OFFSET..(SLOT_CHECKSUM_OFFSET + size_of::())] .copy_from_slice(&checksum.to_le_bytes()); diff --git a/src/tree_store/page_store/page_manager.rs b/src/tree_store/page_store/page_manager.rs index 2254897e..de6eb12a 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -171,7 +171,7 @@ impl TransactionalMemory { PageNumber::new(0, page_number, required_order) }; - let mut header = DatabaseHeader::new(layout, TransactionId(0), tracker_page); + let mut header = DatabaseHeader::new(layout, TransactionId::new(0), tracker_page); header.recovery_required = false; storage diff --git a/src/tree_store/page_store/savepoint.rs b/src/tree_store/page_store/savepoint.rs index df4bee67..72061d2a 100644 --- a/src/tree_store/page_store/savepoint.rs +++ b/src/tree_store/page_store/savepoint.rs @@ -115,7 +115,7 @@ impl<'a> SerializedSavepoint<'a> { pub(crate) fn from_savepoint(savepoint: &Savepoint) -> Self { let mut result = vec![savepoint.version]; result.extend(savepoint.id.0.to_le_bytes()); - result.extend(savepoint.transaction_id.0.to_le_bytes()); + result.extend(savepoint.transaction_id.raw_id().to_le_bytes()); if let Some((root, checksum)) = savepoint.user_root { result.push(1); @@ -291,7 +291,7 @@ impl<'a> SerializedSavepoint<'a> { Savepoint { version, id: SavepointId(id), - transaction_id: TransactionId(transaction_id), + transaction_id: TransactionId::new(transaction_id), user_root, system_root, freed_root,