Commit 984db4c0 authored by Matthieu Dorier's avatar Matthieu Dorier

fixed tests and fixed leveldb datastore

parent 6f745819
......@@ -20,17 +20,17 @@ LevelDBDataStore::LevelDBDataStore(Duplicates duplicates, bool eraseOnGet, bool
_dbm = NULL;
};
std::string LevelDBDataStore::toString(const ds_bulk_t &bulk_val) const {
std::string LevelDBDataStore::toString(const ds_bulk_t &bulk_val) {
std::string str_val(bulk_val.begin(), bulk_val.end());
return str_val;
};
std::string LevelDBDataStore::toString(const char* buf, size_t buf_size) const {
std::string LevelDBDataStore::toString(const char* buf, size_t buf_size) {
std::string str_val(buf, buf_size);
return str_val;
};
ds_bulk_t LevelDBDataStore::fromString(const std::string &str_val) const {
ds_bulk_t LevelDBDataStore::fromString(const std::string &str_val) {
ds_bulk_t bulk_val(str_val.begin(), str_val.end());
return bulk_val;
};
......@@ -87,8 +87,8 @@ bool LevelDBDataStore::put(const void* key, size_t ksize, const void* value, siz
// redundant put simply overwrites previous value which is fine when key/value is the same.
if (_duplicates == Duplicates::IGNORE) {
status = _dbm->Put(leveldb::WriteOptions(),
leveldb::Slice(key, ksize),
leveldb::Slice(value, vsize);
leveldb::Slice((const char*)key, ksize),
leveldb::Slice((const char*)value, vsize));
if (status.ok()) {
success = true;
}
......@@ -108,14 +108,6 @@ bool LevelDBDataStore::put(const void* key, size_t ksize, const void* value, siz
return success;
};
bool LevelDBDataStore::put(ds_bulk_t&& key, ds_bulk_t&& value) {
return put(key.data(), key.size(), value.data(), value.size());
}
bool LevelDBDataStore::put(const ds_bulk_t& key, const ds_bulk_t& value) {
return put(key.data(), key.size(), value.data(), value.size());
}
bool LevelDBDataStore::erase(const ds_bulk_t &key) {
leveldb::Status status;
status = _dbm->Delete(leveldb::WriteOptions(), toString(key));
......@@ -125,7 +117,7 @@ bool LevelDBDataStore::erase(const ds_bulk_t &key) {
bool LevelDBDataStore::exists(const void* key, size_t ksize) const {
leveldb::Status status;
std::string value;
status = _dbm->Get(leveldb::ReadOptions(), leveldb::Slice(key, ksize), &value);
status = _dbm->Get(leveldb::ReadOptions(), leveldb::Slice((const char*)key, ksize), &value);
return status.ok();
}
......
......@@ -46,7 +46,7 @@ class LevelDBDataStore : public AbstractDataStore {
virtual bool put(const ds_bulk_t &key, const ds_bulk_t &data) override;
virtual bool put(ds_bulk_t &&key, ds_bulk_t &&data) override;
*/
virtual bool put(const void* key, size_t ksize, const void* kdata, size_t kdata) override;
virtual bool put(const void* key, size_t ksize, const void* kdata, size_t dsize) override;
virtual bool get(const ds_bulk_t &key, ds_bulk_t &data) override;
virtual bool get(const ds_bulk_t &key, std::vector<ds_bulk_t> &data) override;
virtual bool exists(const void* key, size_t ksize) const override;
......@@ -71,9 +71,9 @@ class LevelDBDataStore : public AbstractDataStore {
const ds_bulk_t &lower_bound, const ds_bulk_t& upper_bound, size_t max_keys) const override;
leveldb::DB *_dbm = NULL;
private:
static std::string toString(const ds_bulk_t &key) const;
static std::string toString(const char* bug, size_t buf_size) const;
static ds_bulk_t fromString(const std::string &keystr) const;
static std::string toString(const ds_bulk_t &key);
static std::string toString(const char* bug, size_t buf_size);
static ds_bulk_t fromString(const std::string &keystr);
AbstractDataStore::comparator_fn _less;
LevelDBDataStoreComparator _keycmp;
};
......
......@@ -179,10 +179,18 @@ int main(int argc, char **argv)
return(-1);
}
char* path = opts.db_names[i];
char* x = strrchr(path, '/');
char* db_name = path;
if(x != NULL) {
db_name = x+1;
*x = '\0';
}
sdskv_database_id_t db_id;
sdskv_config_t db_config = {
.db_name = opts.db_names[i],
.db_path = "",
.db_name = db_name,
.db_path = (x == NULL ? "" : path),
.db_type = opts.db_types[i],
.db_comp_fn_name = SDSKV_COMPARE_DEFAULT,
.db_no_overwrite = 0
......@@ -216,9 +224,16 @@ int main(int argc, char **argv)
for(i=0; i < opts.num_db; i++) {
sdskv_database_id_t db_id;
char* path = opts.db_names[i];
char* x = strrchr(path, '/');
char* db_name = path;
if(x != NULL) {
db_name = x+1;
*x = '\0';
}
sdskv_config_t db_config = {
.db_name = opts.db_names[i],
.db_path = "",
.db_name = db_name,
.db_path = (x == NULL ? "" : path),
.db_type = opts.db_types[i],
.db_comp_fn_name = SDSKV_COMPARE_DEFAULT,
.db_no_overwrite = 0
......
......@@ -195,10 +195,18 @@ int main(int argc, char **argv)
return(-1);
}
char* path = opts.db_names[i];
char* x = strrchr(path, '/');
char* db_name = path;
if(x != NULL) {
db_name = x+1;
*x = '\0';
}
sdskv_database_id_t db_id;
sdskv_config_t db_config = {
.db_name = opts.db_names[i],
.db_path = "",
.db_name = db_name,
.db_path = (x == NULL ? "" : path),
.db_type = opts.db_types[i],
.db_comp_fn_name = "my_custom_comp_function",
.db_no_overwrite = 0
......@@ -241,9 +249,16 @@ int main(int argc, char **argv)
for(i=0; i < opts.num_db; i++) {
sdskv_database_id_t db_id;
char* path = opts.db_names[i];
char* x = strrchr(path, '/');
char* db_name = path;
if(x != NULL) {
db_name = x+1;
*x = '\0';
}
sdskv_config_t db_config = {
.db_name = opts.db_names[i],
.db_path = "",
.db_name = db_name,
.db_path = (x == NULL ? "" : path),
.db_type = opts.db_types[i],
.db_comp_fn_name = "my_custom_comp_function",
.db_no_overwrite = 0
......
......@@ -56,7 +56,7 @@ function test_start_custom_server ()
function find_db_name ()
{
test_db_name=$TMPBASE/${SDSKV_TEST_DB_NAME:-"sdskv-test-db"}
test_db_name=${SDSKV_TEST_DB_NAME:-"sdskv-test-db"}
test_db_type=${SDSKV_TEST_DB_TYPE:-"map"}
test_db_full="${test_db_name}:${test_db_type}"
test_db_full="${TMPBASE}/${test_db_name}:${test_db_type}"
}
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