-
Notifications
You must be signed in to change notification settings - Fork 155
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
open database for read only #130
Conversation
src/rocksdb.rs
Outdated
Self::open_cf_for_read_only(opts, path, vec![], error_if_log_file_exist) | ||
} | ||
|
||
pub fn open_cf_for_read_only( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seem we can use most of the same codes for open and open read-only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reply.
You mean "need more cleanup" ?
I'll try it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RFC:
I think open_cf
arguments should be
pub fn open_cf(
opts: DBOptions,
path: &str,
cfs: Vec<(&str, ColumnFamilyOptions)>,
) -> Result<DB, String> {
// ...
}
not
pub fn open_cf(
opts: DBOptions,
path: &str,
cfs: Vec<&str>,
cf_opts: Vec<ColumnFamilyOptions>,
) -> Result<DB, String> {
// ...
}
The later is error prone, so I want to fix this.
Do you have any objections to this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not using tuple but a ColumnFamilyDescriptor like RocksDB. But this change may break the compatibility but can make the open function more elegant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
pub fn open_cf<T: Into<ColumnFamilyDescriptor>>(
opts: DBOptions,
path: &str,
cfds: Vec<T>,
) -> Result<DB, String> {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer &[T]
:-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we just add a read_only
parameter for open_cf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've add a method open_cf_internal
,
every other open
method invoke this.
fn open_cf_internal<'a, T>(
opts: DBOptions,
path: &str,
cfds: Vec<T>,
// if none, open for read write mode.
// otherwise, open for read only.
error_if_log_file_exist: Option<bool>,
) -> Result<DB, String>
where
T: Into<ColumnFamilyDescriptor<'a>>,
{
// ...
}
I'm trying to change Vec<T>
to &[T]
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siddontang @zhangjinpeng1987
Changing Vec<T>
to &[T]
may need to change type of DB
because of ColumnFamilyOptions
's implementation of Clone
and lifetime.
I think Vec<T>
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
This change breaks API, but makes code more clean and readable too.
I found that test added in 1742f18 ( any idea? |
Cool @feb29 But I think you should split this PR into two PRs, first is to refactor open function, the other is to support read only. |
What is the failure output? |
About splitting into two PRs, I got it. Test fails at this assertion . Running test on master branch by output:
macOS Sierra (10.12.6) |
We should figure out why this value is 0. |
No description provided.