-
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
rocksdb: add Env related API #103
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ use comparator::{self, ComparatorCallback, compare_callback}; | |
use crocksdb_ffi::{self, DBOptions, DBWriteOptions, DBBlockBasedTableOptions, DBReadOptions, | ||
DBRestoreOptions, DBCompressionType, DBRecoveryMode, DBSnapshot, DBInstance, | ||
DBFlushOptions, DBStatisticsTickerType, DBStatisticsHistogramType, | ||
DBRateLimiter, DBInfoLogLevel, DBCompactOptions}; | ||
DBRateLimiter, DBInfoLogLevel, DBCompactOptions, Priority}; | ||
use event_listener::{EventListener, new_event_listener}; | ||
use libc::{self, c_int, size_t, c_void}; | ||
use merge_operator::{self, MergeOperatorCallback, full_merge_callback, partial_merge_callback}; | ||
|
@@ -294,6 +294,31 @@ impl Drop for CompactOptions { | |
} | ||
} | ||
|
||
pub struct Env { | ||
pub inner: *mut crocksdb_ffi::Env, | ||
} | ||
|
||
impl Env { | ||
pub fn new() -> Env { | ||
unsafe { Env { inner: crocksdb_ffi::crocksdb_create_default_env() } } | ||
} | ||
|
||
pub fn set_background_threads(&mut self, n: Priority) { | ||
unsafe { | ||
crocksdb_ffi::crocksdb_env_set_background_threads(self.inner, n); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Miss number parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also use |
||
} | ||
} | ||
} | ||
|
||
impl Drop for Env { | ||
fn drop(&mut self) { | ||
unsafe { | ||
crocksdb_ffi::crocksdb_env_join_all_threads(self.inner); | ||
crocksdb_ffi::crocksdb_env_destroy(self.inner) | ||
} | ||
} | ||
} | ||
|
||
pub struct Options { | ||
pub inner: *mut DBOptions, | ||
filter: Option<CompactionFilterHandle>, | ||
|
@@ -949,6 +974,10 @@ impl Options { | |
crocksdb_ffi::crocksdb_options_set_allow_concurrent_memtable_write(self.inner, v); | ||
} | ||
} | ||
|
||
pub fn set_env(&mut self, env: &Env) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should keep the Env in the Options. Otherwise, the Env may be destroyed quickly when dropping Env. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to share Env among two or more db instances, but Options cannot be shared. We should keep Env's lifetime as the same to databases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is bad to let the users manage the lifetime of Env. We should use DB outside only. |
||
unsafe { crocksdb_ffi::crocksdb_options_set_env(self.inner, env.inner) } | ||
} | ||
} | ||
|
||
pub struct FlushOptions { | ||
|
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.
ThreadPoolPriority