Skip to content

Commit

Permalink
Remove lifetime from ReadTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Feb 3, 2024
1 parent 207a9e9 commit 46e31c2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a> RedbBenchDatabase<'a> {

impl<'a> BenchDatabase for RedbBenchDatabase<'a> {
type W<'db> = RedbBenchWriteTransaction where Self: 'db;
type R<'db> = RedbBenchReadTransaction<'db> where Self: 'db;
type R<'db> = RedbBenchReadTransaction where Self: 'db;

fn db_type_name() -> &'static str {
"redb"
Expand All @@ -103,11 +103,11 @@ impl<'a> BenchDatabase for RedbBenchDatabase<'a> {
}
}

pub struct RedbBenchReadTransaction<'db> {
txn: redb::ReadTransaction<'db>,
pub struct RedbBenchReadTransaction {
txn: redb::ReadTransaction,
}

impl<'db> BenchReadTransaction for RedbBenchReadTransaction<'db> {
impl BenchReadTransaction for RedbBenchReadTransaction {
type T<'txn> = RedbBenchReader<'txn> where Self: 'txn;

fn get_reader(&self) -> Self::T<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ impl Database {
///
/// Returns a [`ReadTransaction`] which may be used to read from the database. Read transactions
/// may exist concurrently with writes
pub fn begin_read(&self) -> Result<ReadTransaction<'static>, TransactionError> {
pub fn begin_read(&self) -> Result<ReadTransaction, TransactionError> {
let guard = self.allocate_read_transaction()?;
#[cfg(feature = "logging")]
info!("Beginning read transaction id={:?}", guard.id());
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub enum TransactionError {
/// Error from underlying storage
Storage(StorageError),
/// The transaction is still referenced by a table or other object
ReadTransactionStillInUse(ReadTransaction<'static>),
ReadTransactionStillInUse(ReadTransaction),
}

impl TransactionError {
Expand Down Expand Up @@ -463,7 +463,7 @@ pub enum Error {
Io(io::Error),
LockPoisoned(&'static panic::Location<'static>),
/// The transaction is still referenced by a table or other object
ReadTransactionStillInUse(ReadTransaction<'static>),
ReadTransactionStillInUse(ReadTransaction),
}

impl<T> From<PoisonError<T>> for Error {
Expand Down
10 changes: 3 additions & 7 deletions src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,14 +1180,13 @@ impl Drop for WriteTransaction {
/// A read-only transaction
///
/// Read-only transactions may exist concurrently with writes
pub struct ReadTransaction<'a> {
pub struct ReadTransaction {
mem: Arc<TransactionalMemory>,
tree: TableTree,
transaction_guard: Arc<TransactionGuard>,
_lifetime: PhantomData<&'a ()>,
}

impl<'a> ReadTransaction<'a> {
impl ReadTransaction {
pub(crate) fn new(
mem: Arc<TransactionalMemory>,
guard: TransactionGuard,
Expand All @@ -1199,7 +1198,6 @@ impl<'a> ReadTransaction<'a> {
tree: TableTree::new(root_page, PageHint::Clean, guard.clone(), mem)
.map_err(TransactionError::Storage)?,
transaction_guard: guard,
_lifetime: Default::default(),
})
}

Expand Down Expand Up @@ -1289,9 +1287,7 @@ impl<'a> ReadTransaction<'a> {
.list_tables(TableType::Multimap)
.map(|x| x.into_iter().map(UntypedMultimapTableHandle::new))
}
}

impl ReadTransaction<'static> {
/// Close the transaction
///
/// Transactions are automatically closed when they and all objects referencing them have been dropped.
Expand All @@ -1307,7 +1303,7 @@ impl ReadTransaction<'static> {
}
}

impl Debug for ReadTransaction<'static> {
impl Debug for ReadTransaction {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("ReadTransaction")
}
Expand Down

0 comments on commit 46e31c2

Please sign in to comment.