feat: Allow SecretDB to open unknown column families#2065
Conversation
Code ReviewCritical Issue: Potential panic scenario (low risk but worth documenting)Location: The fn cf_handle(&self, cf: DBCol) -> rocksdb::ColumnFamilyRef {
self.db.cf_handle(cf.as_str()).unwrap() // Could panic
}Analysis:
Recommendation: fn cf_handle(&self, cf: DBCol) -> rocksdb::ColumnFamilyRef {
// SAFETY: All DBCol variants are guaranteed to exist in the database
// because we open with known_cfs.union(on_disk_cfs). Unknown CFs
// opened for forward compatibility are never accessed through DBCol.
self.db.cf_handle(cf.as_str()).unwrap()
}Code Quality: Minor optimization opportunityLocation: The union operation creates unnecessary allocations. Consider using let mut all_cfs: Vec<String> = DBCol::all()
.iter()
.map(|col| col.as_str().to_string())
.collect();
all_cfs.extend(
rocksdb::DB::list_cf(&options, path)
.unwrap_or_default()
.into_iter()
.filter(|cf| \!all_cfs.contains(cf))
);
let all_cfs_refs: Vec<&str> = all_cfs.iter().map(|s| s.as_str()).collect();
let db = rocksdb::DB::open_cf(&options, path, &all_cfs_refs)?;This avoids the intermediate Test Coverage: ✅ GoodThe test properly validates the forward compatibility scenario with an unknown Overall Assessment: The implementation correctly solves the forward compatibility issue. The potential panic in |
f8cbbd2 to
c03d33e
Compare
closes #2064