Commit 25391594 authored by Little-Wallace's avatar Little-Wallace

add interface to support write multi batch

Signed-off-by: 's avatarLittle-Wallace <bupt2013211450@gmail.com>
parent 56d3bd75
......@@ -960,6 +960,19 @@ void crocksdb_write(
SaveError(errptr, db->rep->Write(options->rep, &batch->rep));
}
void crocksdb_write_multi_batch(
crocksdb_t* db,
const crocksdb_writeoptions_t* options,
crocksdb_writebatch_t** batches,
size_t batch_size,
char** errptr) {
std::vector<WriteBatch*> ws;
for (size_t i = 0; i < batch_size; i ++) {
ws.push_back(&batches[i]->rep);
}
SaveError(errptr, db->rep->MultiThreadWrite(options->rep, ws));
}
char* crocksdb_get(
crocksdb_t* db,
const crocksdb_readoptions_t* options,
......
......@@ -341,6 +341,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_merge_cf(
extern C_ROCKSDB_LIBRARY_API void crocksdb_write(
crocksdb_t* db, const crocksdb_writeoptions_t* options,
crocksdb_writebatch_t* batch, char** errptr);
extern C_ROCKSDB_LIBRARY_API void crocksdb_write_multi_batch(
crocksdb_t* db, const crocksdb_writeoptions_t* options,
crocksdb_writebatch_t** batches, size_t batch_size, char** errptr);
/* Returns NULL if not found. A malloc()ed array otherwise.
Stores the length of the array in *vallen. */
......
......@@ -912,6 +912,14 @@ extern "C" {
batch: *mut DBWriteBatch,
err: *mut *mut c_char,
);
pub fn crocksdb_write_multi_batch(
db: *mut DBInstance,
writeopts: *const DBWriteOptions,
batch: *const *mut DBWriteBatch,
batchlen: size_t,
err: *mut *mut c_char,
);
pub fn crocksdb_writebatch_create() -> *mut DBWriteBatch;
pub fn crocksdb_writebatch_create_with_capacity(cap: size_t) -> *mut DBWriteBatch;
pub fn crocksdb_writebatch_create_from(rep: *const u8, size: size_t) -> *mut DBWriteBatch;
......
......@@ -738,6 +738,18 @@ impl DB {
&self.path
}
pub fn multi_thread_write(&self, batches: &Vec<WriteBatch>, writeopts: &WriteOptions) -> Result<(), String> {
unsafe {
if batches.len() == 1 {
ffi_try!(crocksdb_write(self.inner, writeopts.inner, batches[0].inner));
} else {
let b : Vec<*mut DBWriteBatch> = batches.iter().map(|w| w.inner).collect();
ffi_try!(crocksdb_write_multi_batch(self.inner, writeopts.inner, b.as_ptr(), b.len()));
}
}
Ok(())
}
pub fn write_opt(&self, batch: &WriteBatch, writeopts: &WriteOptions) -> Result<(), String> {
unsafe {
ffi_try!(crocksdb_write(self.inner, writeopts.inner, batch.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