From b3709f262eac8b421f527ae52d1895d907ffe6b7 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 21 May 2024 17:47:13 -0700 Subject: [PATCH] panic when a column family would be created twice `create_cf` already fails when the column family already exists, but this gives us a much better error message; namely, it tells us what column family name is at fault. --- src/database/abstraction/rocksdb.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index da797d65..176e56ea 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -2,7 +2,7 @@ use std::{ collections::HashSet, future::Future, pin::Pin, - sync::{Arc, RwLock}, + sync::{Arc, Mutex, RwLock}, }; use rocksdb::{ @@ -22,6 +22,7 @@ pub(crate) struct Engine { max_open_files: i32, cache: Cache, old_cfs: HashSet, + new_cfs: Mutex>, } pub(crate) struct RocksDbEngineTree<'a> { @@ -104,10 +105,21 @@ impl KeyValueDatabaseEngine for Arc { max_open_files: config.rocksdb_max_open_files, cache: rocksdb_cache, old_cfs: cfs, + new_cfs: Mutex::default(), })) } fn open_tree(&self, name: &'static str) -> Result> { + let mut new_cfs = + self.new_cfs.lock().expect("lock should not be poisoned"); + + let created_already = !new_cfs.insert(name); + + assert!( + !created_already, + "detected attempt to alias column family: {name}", + ); + if !self.old_cfs.contains(&name.to_owned()) { // Create if it didn't exist self.rocks