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