Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
`ReadOnlyMultimapTable::range()`, whose `'static` iterators do not keep the transaction alive,
are removed under the flag; use the `ReadableTable` and `ReadableMultimapTable` methods, or the
`range_owned()` variants when the iterator must outlive the table.
* The inherent `ReadOnlyTable::get()` and `ReadOnlyMultimapTable::get()`, whose `'static` guards
and iterators likewise do not keep the transaction alive, are also removed under the
`experimental-api-5` flag; use the `ReadableTable` and `ReadableMultimapTable` methods, or the
`get_owned()` variants when the guard must outlive the table.

## 4.2.0 - 2026-XX-XX
* Fix a panic when opening a database containing a corrupted persistent savepoint record;
Expand Down
2 changes: 2 additions & 0 deletions crates/redb-derive/tests/crate_attr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ use new::NewValue;
use old::OldValue;
use old3::{Old3Inner, Old3Value};
use redb::ReadableDatabase;
#[allow(unused_imports)]
use redb::ReadableTable;
use redb3_0::ReadableDatabase as _;

fn create_tempfile() -> tempfile::NamedTempFile {
Expand Down
2 changes: 2 additions & 0 deletions crates/redb-derive/tests/derive_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[allow(unused_imports)]
use redb::ReadableTable;
use redb::{Database, Key, ReadableDatabase, TableDefinition, TableError, TypeName, Value};
use redb_derive::{Key, Value};
use std::fmt::Debug;
Expand Down
10 changes: 9 additions & 1 deletion src/multimap_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,15 @@ impl<K: Key + 'static, V: Key + 'static> ReadOnlyMultimapTable<K, V> {

/// This method is like [`ReadableMultimapTable::get()`], but the iterator is reference counted and keeps the transaction
/// alive until it is dropped.
#[cfg(not(feature = "experimental-api-5"))]
pub fn get<'a>(&self, key: impl Borrow<K::SelfType<'a>>) -> Result<MultimapValue<'static, V>> {
self.get_inner(key)
}

fn get_inner<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<MultimapValue<'static, V>> {
let iter = if let Some(collection) = self.tree.get(key.borrow())? {
MultimapValue::from_collection(
collection,
Expand Down Expand Up @@ -1164,7 +1172,7 @@ impl<K: Key + 'static, V: Key + 'static> ReadOnlyMultimapTable<K, V> {
key: impl Borrow<K::SelfType<'a>>,
) -> Result<OwnedMultimapValue<V>> {
Ok(OwnedMultimapValue::new(
self.get(key)?,
self.get_inner(key)?,
self.transaction_guard.clone(),
))
}
Expand Down
4 changes: 3 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ impl<K: Key + 'static, V: Value + 'static> ReadOnlyTable<K, V> {

/// This method is like [`ReadableTable::get()`], but the [`AccessGuard`] is reference counted
/// and keeps the transaction alive until it is dropped.
#[cfg(not(feature = "experimental-api-5"))]
pub fn get<'a>(
&self,
key: impl Borrow<K::SelfType<'a>>,
Expand All @@ -893,7 +894,8 @@ impl<K: Key + 'static, V: Value + 'static> ReadOnlyTable<K, V> {
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<OwnedAccessGuard<V>>> {
Ok(self
.get(key)?
.tree
.get(key.borrow())?
.map(|x| OwnedAccessGuard::new(x, self.transaction_guard.clone())))
}

Expand Down
2 changes: 2 additions & 0 deletions src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,8 @@ impl Debug for ReadTransaction {

#[cfg(test)]
mod test {
#[cfg(feature = "experimental-api-5")]
use crate::ReadableTable;
use crate::{Database, ReadableDatabase, StorageError, TableDefinition, TransactionError};

const X: TableDefinition<&str, &str> = TableDefinition::new("x");
Expand Down
2 changes: 2 additions & 0 deletions src/tree_store/page_store/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ impl TransactionHeader {

#[cfg(test)]
mod test {
#[cfg(feature = "experimental-api-5")]
use crate::ReadableTable;
use crate::backends::FileBackend;
use crate::db::TableDefinition;
use crate::tree_store::page_store::base::MAX_REGIONS;
Expand Down
2 changes: 2 additions & 0 deletions tests/backward_compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(feature = "experimental-api-5")]
use redb::ReadableTable;
use redb::{ReadableDatabase, ReadableTableMetadata};

const ELEMENTS: usize = 3;
Expand Down
2 changes: 2 additions & 0 deletions tests/check_integrity_nondurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! the live state from disk; it refuses to promote when the backing file was externally truncated
//! or extended, falling back to repairing the durable state instead.

#[cfg(feature = "experimental-api-5")]
use redb::ReadableTable;
use redb::{
Database, Durability, ReadableDatabase, ReadableTableMetadata, StorageBackend, TableDefinition,
};
Expand Down
2 changes: 2 additions & 0 deletions tests/crash_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! `Corrupted("File truncated below stored layout")` -- permanent data loss -- even though the
//! previous durable state was intact. The fix makes the file extension durable as the file grows.

#[cfg(feature = "experimental-api-5")]
use redb::ReadableTable;
use redb::backends::InMemoryBackend;
use redb::{Database, ReadableDatabase, StorageBackend, TableDefinition};
use std::io::ErrorKind;
Expand Down
8 changes: 7 additions & 1 deletion tests/multimap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ fn get_arc_lifetime() {
let read_txn = db.begin_read().unwrap();
let table = read_txn.open_multimap_table(definition).unwrap();
let start = "hello".to_string();
table.get(start.as_str()).unwrap()
// The 'static get() does not keep the transaction alive, so experimental-api-5 drops it
// in favour of get_owned()
#[cfg(feature = "experimental-api-5")]
let iter = table.get_owned(start.as_str()).unwrap();
#[cfg(not(feature = "experimental-api-5"))]
let iter = table.get(start.as_str()).unwrap();
iter
};
assert_eq!(iter.next().unwrap().unwrap().value(), "world");
assert!(iter.next().is_none());
Expand Down
Loading