-
Notifications
You must be signed in to change notification settings - Fork 703
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
Make cf_handle
lock-free
#279
Comments
like this? use std::collections::HashMap;
#[derive(Debug)]
struct ColumnFamily(i32);
struct DB {
cfs:HashMap<i32,ColumnFamily>,
}
impl DB {
fn new()->DB{
let mut cfs = HashMap::new();
cfs.insert(1,ColumnFamily(1));
cfs.insert(2,ColumnFamily(2));
DB{
cfs
}
}
fn get(&self,key:i32)->&ColumnFamily{
self.cfs.get(&key).unwrap()
}
fn drop_key(&mut self,key:i32){
self.cfs.remove(&key);
}
}
fn main() {
let mut f = DB::new();
let a = f.get(1);
println!("{:?}",a);
f.drop_key(1);
let c = f.get(2);
println!("{:?}",c);
} |
FWIW, in paritech's fork |
@hjiayz Yes, very similar to that. |
When I tried making this change (i.e. take
The error happen when making a method call on db that takes
I can't think of a very elegant way around this, but one option is to not return a
Would changing |
ref. rust-rocksdb#279 Essentially reverts rust-rocksdb#197 and makes `create_cf`/`drop_cf` take `&mut self` to ensure nothing else can update the column family map. The biggest breaking change here is that `create_cf` does not return a `ColumnFamily`. See [this comment](rust-rocksdb#279 (comment)) on the original ticket for details.
@dvdplm Adding lifetimes to |
Agree with @iSynaptic. Obviously returning a reference to |
Maybe #298 can be merged then? |
Is it resolved by #314? Any plans to release if so? |
Yes, it is. We plan to release it in near future. |
@aleksuss what is the status of releasing it? :) |
@bkchr I think we will do it next week. |
The
cf_handle
function is often called very frequently and it's implementation requires acquiring a read-lock to an underlying map. If this is called in a hot-path, it can have performance implications. We should investigate switching this to an approach that doesn't require a lock. For example, we could makecreate_cf
anddrop_cf
and any other function that mutates the internal map require a mutable reference toDB
and make the caller responsible for acquiring any locks in order to mutate theDB
.The text was updated successfully, but these errors were encountered: