Skip to content

Latest commit

 

History

History
134 lines (108 loc) · 4.44 KB

File metadata and controls

134 lines (108 loc) · 4.44 KB

Lock-Free Architecture Implementation Report

Summary

Converting SoliDB from Arc<RwLock<DB>> to lock-free Arc<DB> with selective locking for column family operations.

Changes Required by File

1. engine.rs - ✅ FIXED

  • 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> with cf_lock: Arc<RwLock<()>> pattern

2. database.rs - ✅ FIXED

  • Issues: Uses Arc<RwLock<DB>> throughout
  • Changes Made:
    • Changed struct to use Arc<DB> with cf_lock: Arc<RwLock<()>>
    • Updated new() to accept Arc<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 return Arc<DB>
    • Fixed list_columnar() (lock-free)

3. collection/mod.rs - PENDING

  • Changes Needed:
    • Change db: Arc<RwLock<DB>> to db: Arc<DB>
    • Remove cf_lock (not needed for collections, only for CF ops)

4. collection/core.rs - PENDING (9 occurrences)

  • Changes Needed:
    • Update new() to accept Arc<DB>
    • Replace db.read().unwrap() with direct &self.db access
    • Replace db.write().unwrap() with direct &self.db access (RocksDB is thread-safe for writes)

5. collection/crud.rs - PENDING (9 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db
    • Writes using WriteBatch remain the same (already lock-free)

6. collection/indexes.rs - PENDING (21 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db
    • All index operations use WriteBatch or direct reads (both lock-free)

7. collection/ttl.rs - PENDING (7 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db

8. collection/txn.rs - PENDING (1 occurrence)

  • Changes Needed:
    • Replace self.db.read().unwrap() with &self.db

9. collection/fulltext.rs - PENDING (8 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db

10. collection/vector.rs - PENDING (6 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db

11. collection/schema.rs - PENDING (3 occurrences)

  • Changes Needed:
    • Replace all self.db.read/write().unwrap() with &self.db

12. collection/geo.rs - PENDING (8 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db

13. collection/blobs.rs - PENDING (3 occurrences)

  • Changes Needed:
    • Replace all self.db.read().unwrap() with &self.db

14. collection/indexes_patch_ref.rs - PENDING (1 occurrence)

  • Changes Needed:
    • Replace self.db.read().unwrap() with &self.db

15. columnar.rs - PENDING

  • Changes Needed:
    • Change db: Arc<RwLock<DB>> to db: Arc<DB>
    • Update all methods that use db.read()/db.write()

Pattern for Changes

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)?;
}

Total Statistics

  • 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

Next Steps

Continue with collection/mod.rs and all collection/*.rs files using the search-and-replace pattern.