Unverified Commit 035db162 authored by Xintao's avatar Xintao Committed by GitHub

Add delete_file interface (#670)

Signed-off-by: 's avatarXintao <hunterlxt@live.com>
parent 4dd1d667
......@@ -1335,8 +1335,8 @@ void crocksdb_approximate_memtable_stats_cf(
db->rep->GetApproximateMemTableStats(cf->rep, range, count, size);
}
void crocksdb_delete_file(crocksdb_t* db, const char* name) {
db->rep->DeleteFile(name);
void crocksdb_delete_file(crocksdb_t* db, const char* name, char** errptr) {
SaveError(errptr, db->rep->DeleteFile(name));
}
const crocksdb_livefiles_t* crocksdb_livefiles(crocksdb_t* db) {
......
......@@ -509,7 +509,8 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_compact_range_cf_opt(
const char* limit_key, size_t limit_key_len);
extern C_ROCKSDB_LIBRARY_API void crocksdb_delete_file(crocksdb_t* db,
const char* name);
const char* name,
char** errptr);
extern C_ROCKSDB_LIBRARY_API const crocksdb_livefiles_t* crocksdb_livefiles(
crocksdb_t* db);
......@@ -1884,8 +1885,8 @@ crocksdb_fifo_compaction_options_set_allow_compaction(
extern C_ROCKSDB_LIBRARY_API void crocksdb_fifo_compaction_options_destroy(
crocksdb_fifo_compaction_options_t* fifo_opts);
extern C_ROCKSDB_LIBRARY_API size_t crocksdb_livefiles_count(
const crocksdb_livefiles_t*);
extern C_ROCKSDB_LIBRARY_API size_t
crocksdb_livefiles_count(const crocksdb_livefiles_t*);
extern C_ROCKSDB_LIBRARY_API const char* crocksdb_livefiles_name(
const crocksdb_livefiles_t*, int index);
extern C_ROCKSDB_LIBRARY_API int crocksdb_livefiles_level(
......
......@@ -1493,6 +1493,7 @@ extern "C" {
limit_key: *const u8,
limit_key_len: size_t,
);
pub fn crocksdb_delete_file(db: *mut DBInstance, name: *const c_char, err: *mut *mut c_char);
pub fn crocksdb_delete_files_in_range(
db: *mut DBInstance,
range_start_key: *const u8,
......
......@@ -1364,6 +1364,14 @@ impl DB {
}
}
pub fn delete_file(&self, path: &str) -> Result<(), String> {
unsafe {
let file_path = CString::new(path).unwrap();
ffi_try!(crocksdb_delete_file(self.inner, file_path.as_ptr()));
Ok(())
}
}
pub fn delete_files_in_range(
&self,
start_key: &[u8],
......
......@@ -257,6 +257,11 @@ fn test_event_listener_ingestion() {
assert_eq!(db.get(b"k1").unwrap().unwrap(), b"v1");
assert_eq!(db.get(b"k2").unwrap().unwrap(), b"v2");
assert_ne!(counter.ingestion.load(Ordering::SeqCst), 0);
let files = db.get_live_files();
assert!(test_sstfile.exists());
assert!(db.delete_file(&files.get_name(0)).is_ok());
assert!(db.get(b"k1").unwrap().is_none());
assert!(db.get(b"k2").unwrap().is_none());
}
#[test]
......
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