Converting SoliDB from Arc<RwLock<DB>> to lock-free Arc<DB> with selective locking for column family operations.
- Issues: Drop impl error, CF operations need mutability, type mismatches
- Changes Made:
- Fixed Drop impl to use direct DB access
- Added unsafe blocks with cf_lock for create_cf/drop_cf operations
- Uses
Arc<DB>withcf_lock: Arc<RwLock<()>>pattern
- Issues: Uses
Arc<RwLock<DB>>throughout - Changes Made:
- Changed struct to use
Arc<DB>withcf_lock: Arc<RwLock<()>> - Updated
new()to acceptArc<DB> - Fixed
create_collection()with cf_lock + unsafe block - Fixed
delete_collection()with cf_lock + unsafe block - Removed locks from
list_collections()(lock-free) - Removed locks from
get_collection()(lock-free) - Updated
db_arc()to returnArc<DB> - Fixed
list_columnar()(lock-free)
- Changed struct to use
- Changes Needed:
- Change
db: Arc<RwLock<DB>>todb: Arc<DB> - Remove cf_lock (not needed for collections, only for CF ops)
- Change
- Changes Needed:
- Update
new()to acceptArc<DB> - Replace
db.read().unwrap()with direct&self.dbaccess - Replace
db.write().unwrap()with direct&self.dbaccess (RocksDB is thread-safe for writes)
- Update
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db - Writes using WriteBatch remain the same (already lock-free)
- Replace all
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db - All index operations use WriteBatch or direct reads (both lock-free)
- Replace all
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace
self.db.read().unwrap()with&self.db
- Replace
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace all
self.db.read/write().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace all
self.db.read().unwrap()with&self.db
- Replace all
- Changes Needed:
- Replace
self.db.read().unwrap()with&self.db
- Replace
- Changes Needed:
- Change
db: Arc<RwLock<DB>>todb: Arc<DB> - Update all methods that use db.read()/db.write()
- Change
For read operations:
// OLD:
let db = self.db.read().unwrap();
let cf = db.cf_handle(&self.name).unwrap();
let result = db.get_cf(cf, key)?;
// NEW:
let cf = self.db.cf_handle(&self.name).unwrap();
let result = self.db.get_cf(cf, key)?;For write operations (using WriteBatch):
// OLD:
let db = self.db.read().unwrap();
let cf = db.cf_handle(&self.name).unwrap();
let mut batch = WriteBatch::default();
batch.put_cf(cf, key, value);
db.write(batch)?;
// NEW:
let cf = self.db.cf_handle(&self.name).unwrap();
let mut batch = WriteBatch::default();
batch.put_cf(cf, key, value);
self.db.write(batch)?;For column family operations (rare, needs lock):
// In StorageEngine or Database (which have cf_lock):
let _cf_guard = self.cf_lock.write().unwrap();
let db_ptr = Arc::as_ptr(&self.db) as *mut DB;
unsafe {
(*db_ptr).create_cf(name, opts)?;
}- Files to modify: 15
- Lock occurrences to remove: 91
- Pattern: Simple replacement of
db.read().unwrap()with direct access - Safety: RocksDB is thread-safe for concurrent reads and writes (via WriteBatch)
- Only CF operations need locks: create_cf, drop_cf
Continue with collection/mod.rs and all collection/*.rs files using the search-and-replace pattern.