Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panics opening system tables from multiple threads #685

Merged
merged 2 commits into from
Sep 17, 2023
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
1 change: 0 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@ impl Builder {
}
}

// This just makes it easier to throw `dbg` etc statements on `Result<Database>`
impl std::fmt::Debug for Database {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Database").finish()
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
//!
//! const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");
//!
//! #[cfg(not(target_os = "wasi"))]
//! fn main() -> Result<(), Error> {
//! let db = Database::create("my_db.redb")?;
//! let file = tempfile::NamedTempFile::new().unwrap();
//! let db = Database::create(file.path())?;
//! let write_txn = db.begin_write()?;
//! {
//! let mut table = write_txn.open_table(TABLE)?;
Expand Down
6 changes: 1 addition & 5 deletions src/multimap_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> DoubleEndedIterator
/// [Multimap tables](https://en.wikipedia.org/wiki/Multimap) may have multiple values associated with each key
pub struct MultimapTable<'db, 'txn, K: RedbKey + 'static, V: RedbKey + 'static> {
name: String,
system: bool,
transaction: &'txn WriteTransaction<'db>,
freed_pages: Arc<Mutex<Vec<PageNumber>>>,
tree: BtreeMut<'txn, K, &'static DynamicCollection<V>>,
Expand All @@ -724,15 +723,13 @@ pub struct MultimapTable<'db, 'txn, K: RedbKey + 'static, V: RedbKey + 'static>
impl<'db, 'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'db, 'txn, K, V> {
pub(crate) fn new(
name: &str,
system: bool,
table_root: Option<(PageNumber, Checksum)>,
freed_pages: Arc<Mutex<Vec<PageNumber>>>,
mem: &'db TransactionalMemory,
transaction: &'txn WriteTransaction<'db>,
) -> MultimapTable<'db, 'txn, K, V> {
MultimapTable {
name: name.to_string(),
system,
transaction,
freed_pages: freed_pages.clone(),
tree: BtreeMut::new(table_root, mem, freed_pages),
Expand Down Expand Up @@ -1129,8 +1126,7 @@ impl<'db, 'txn, K: RedbKey + 'static, V: RedbKey + 'static> Drop
for MultimapTable<'db, 'txn, K, V>
{
fn drop(&mut self) {
self.transaction
.close_table(&self.name, self.system, &self.tree);
self.transaction.close_table(&self.name, &self.tree);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,20 @@ impl TableStats {
/// A table containing key-value mappings
pub struct Table<'db, 'txn, K: RedbKey + 'static, V: RedbValue + 'static> {
name: String,
system: bool,
transaction: &'txn WriteTransaction<'db>,
tree: BtreeMut<'txn, K, V>,
}

impl<'db, 'txn, K: RedbKey + 'static, V: RedbValue + 'static> Table<'db, 'txn, K, V> {
pub(crate) fn new(
name: &str,
system: bool,
table_root: Option<(PageNumber, Checksum)>,
freed_pages: Arc<Mutex<Vec<PageNumber>>>,
mem: &'db TransactionalMemory,
transaction: &'txn WriteTransaction<'db>,
) -> Table<'db, 'txn, K, V> {
Table {
name: name.to_string(),
system,
transaction,
tree: BtreeMut::new(table_root, mem, freed_pages),
}
Expand Down Expand Up @@ -248,8 +245,7 @@ impl<K: RedbKey, V: RedbValue> Sealed for Table<'_, '_, K, V> {}

impl<'db, 'txn, K: RedbKey + 'static, V: RedbValue + 'static> Drop for Table<'db, 'txn, K, V> {
fn drop(&mut self) {
self.transaction
.close_table(&self.name, self.system, &self.tree);
self.transaction.close_table(&self.name, &self.tree);
}
}

Expand Down Expand Up @@ -470,7 +466,7 @@ pub struct Range<'a, K: RedbKey + 'static, V: RedbValue + 'static> {
}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Range<'a, K, V> {
fn new(inner: BtreeRangeIter<'a, K, V>) -> Self {
pub(super) fn new(inner: BtreeRangeIter<'a, K, V>) -> Self {
Self { inner }
}
}
Expand Down
Loading
Loading