Commit 4838a968 authored by zhangjinpeng1987's avatar zhangjinpeng1987 Committed by Huachao Huang

sync wal before close (#189)

parent f57f6731
...@@ -82,6 +82,7 @@ pub struct DB { ...@@ -82,6 +82,7 @@ pub struct DB {
path: String, path: String,
opts: DBOptions, opts: DBOptions,
_cf_opts: Vec<ColumnFamilyOptions>, _cf_opts: Vec<ColumnFamilyOptions>,
readonly: bool,
} }
impl Debug for DB { impl Debug for DB {
...@@ -433,6 +434,11 @@ impl DB { ...@@ -433,6 +434,11 @@ impl DB {
.map(|x| x.inner as *const crocksdb_ffi::Options) .map(|x| x.inner as *const crocksdb_ffi::Options)
.collect(); .collect();
let readonly = if error_if_log_file_exist.is_some() {
true
} else {
false
};
let db = { let db = {
let db_options = opts.inner; let db_options = opts.inner;
let db_path = cpath.as_ptr(); let db_path = cpath.as_ptr();
...@@ -484,6 +490,7 @@ impl DB { ...@@ -484,6 +490,7 @@ impl DB {
path: path.to_owned(), path: path.to_owned(),
opts: opts, opts: opts,
_cf_opts: options, _cf_opts: options,
readonly: readonly,
}) })
} }
...@@ -1518,6 +1525,10 @@ impl Drop for WriteBatch { ...@@ -1518,6 +1525,10 @@ impl Drop for WriteBatch {
impl Drop for DB { impl Drop for DB {
fn drop(&mut self) { fn drop(&mut self) {
// SyncWAL before call close.
if !self.readonly {
self.sync_wal().unwrap();
}
unsafe { unsafe {
self.cfs.clear(); self.cfs.clear();
crocksdb_ffi::crocksdb_close(self.inner); crocksdb_ffi::crocksdb_close(self.inner);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment