|
|
|
@ -13,14 +13,14 @@ |
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
use std::ffi::CString; |
|
|
|
|
use std::path::{Path}; |
|
|
|
|
|
|
|
|
|
use libc::{uint32_t}; |
|
|
|
|
|
|
|
|
|
use {DB, Error}; |
|
|
|
|
use ffi; |
|
|
|
|
|
|
|
|
|
use libc::{c_int, uint32_t}; |
|
|
|
|
use std::ffi::CString; |
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
pub struct BackupEngine { |
|
|
|
|
inner: *mut ffi::rocksdb_backup_engine_t, |
|
|
|
|
} |
|
|
|
@ -29,9 +29,15 @@ pub struct BackupEngineOptions { |
|
|
|
|
inner: *mut ffi::rocksdb_options_t, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct RestoreOptions { |
|
|
|
|
inner: *mut ffi::rocksdb_restore_options_t, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl BackupEngine { |
|
|
|
|
/// Open a backup engine with the specified options.
|
|
|
|
|
pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions, path: P) -> Result<BackupEngine, Error> { |
|
|
|
|
pub fn open<P: AsRef<Path>>(opts: &BackupEngineOptions, |
|
|
|
|
path: P) |
|
|
|
|
-> Result<BackupEngine, Error> { |
|
|
|
|
let path = path.as_ref(); |
|
|
|
|
let cpath = match CString::new(path.to_string_lossy().as_bytes()) { |
|
|
|
|
Ok(c) => c, |
|
|
|
@ -43,17 +49,13 @@ impl BackupEngine { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let be: *mut ffi::rocksdb_backup_engine_t; |
|
|
|
|
unsafe { |
|
|
|
|
be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr())) |
|
|
|
|
} |
|
|
|
|
unsafe { be = ffi_try!(ffi::rocksdb_backup_engine_open(opts.inner, cpath.as_ptr())) } |
|
|
|
|
|
|
|
|
|
if be.is_null() { |
|
|
|
|
return Err(Error::new("Could not initialize backup engine.".to_owned())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(BackupEngine { |
|
|
|
|
inner: be, |
|
|
|
|
}) |
|
|
|
|
Ok(BackupEngine { inner: be }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_new_backup(&mut self, db: &DB) -> Result<(), Error> { |
|
|
|
@ -65,24 +67,49 @@ impl BackupEngine { |
|
|
|
|
|
|
|
|
|
fn purge_old_backups(&mut self, num_backups_to_keep: usize) -> Result<(), Error> { |
|
|
|
|
unsafe { |
|
|
|
|
ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups(self.inner, num_backups_to_keep as uint32_t)); |
|
|
|
|
ffi_try!(ffi::rocksdb_backup_engine_purge_old_backups(self.inner, |
|
|
|
|
num_backups_to_keep as uint32_t)); |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl BackupEngineOptions { |
|
|
|
|
//
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl RestoreOptions { |
|
|
|
|
pub fn set_keep_log_files(&mut self, keep_log_files: bool) { |
|
|
|
|
unsafe { |
|
|
|
|
ffi::rocksdb_restore_options_set_keep_log_files(self.inner, keep_log_files as c_int); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for BackupEngineOptions { |
|
|
|
|
fn default() -> BackupEngineOptions { |
|
|
|
|
unsafe { |
|
|
|
|
let opts = ffi::rocksdb_options_create(); |
|
|
|
|
if opts.is_null() { |
|
|
|
|
panic!("Could not create backup options".to_owned()); |
|
|
|
|
panic!("Could not create RocksDB backup options".to_owned()); |
|
|
|
|
} |
|
|
|
|
BackupEngineOptions { inner: opts } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for RestoreOptions { |
|
|
|
|
fn default() -> RestoreOptions { |
|
|
|
|
unsafe { |
|
|
|
|
let opts = ffi::rocksdb_restore_options_create(); |
|
|
|
|
if opts.is_null() { |
|
|
|
|
panic!("Could not create RocksDB restore options".to_owned()); |
|
|
|
|
} |
|
|
|
|
RestoreOptions { inner: opts } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Drop for BackupEngine { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { |
|
|
|
@ -98,3 +125,11 @@ impl Drop for BackupEngineOptions { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Drop for RestoreOptions { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { |
|
|
|
|
ffi::rocksdb_restore_options_destroy(self.inner); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|