...
 
Commits (1)
......@@ -219,15 +219,25 @@ std::vector<ds_bulk_t> BerkeleyDBDataStore::list_keys(const ds_bulk_t &start, si
std::vector<ds_bulk_t> keys;
Dbc * cursorp;
Dbt key, data;
int ret;
_dbm->cursor(NULL, &cursorp, 0);
for (size_t i=0; i< count; i++) {
int ret = cursorp->get(&key, &data, DB_NEXT);
if (ret !=0 ) break;
ds_bulk_t k(key.get_size() );
memcpy(k.data(), key.get_data(), key.get_size() );
/* I hope this is a deep copy! */
keys.push_back(std::move(k));
if (start.size()) {
key.set_size(start.size());
key.set_data((void *)start.data());
ret = cursorp->get(&key, &data, DB_SET);
if (ret != 0) {
cursorp->close();
return keys;
}
}
while (keys.size() < count) {
ret = cursorp->get(&key, &data, DB_NEXT);
if (ret !=0 ) break;
ds_bulk_t k(key.get_size() );
memcpy(k.data(), key.get_data(), key.get_size() );
keys.push_back(std::move(k));
}
cursorp->close();
return keys;
......
......@@ -132,8 +132,16 @@ std::vector<ds_bulk_t> LevelDBDataStore::list_keys(const ds_bulk_t &start, size_
std::vector<ds_bulk_t> keys;
leveldb::Iterator *it = _dbm->NewIterator(leveldb::ReadOptions());
leveldb::Slice start_slice(start.data(), start.size());
size_t i=0;
for (it->SeekToFirst(); it->Valid(); it->Next() ) {
if (start.size() > 0) {
it->Seek(start_slice);
} else {
it->SeekToFirst();
}
/* note: iterator initialized above, not in for loop */
for (; it->Valid(); it->Next() ) {
ds_bulk_t k(it->key().size());
memcpy(k.data(), it->key().data(), it->key().size() );
keys.push_back(k);
......
......@@ -357,8 +357,9 @@ static hg_return_t list_handler(hg_handle_t handle)
list_in_t list_in;
list_out_t list_out;
std::vector<char> start{};
margo_get_input(handle, &list_in);
ds_bulk_t start(list_in.list_in.start_key,
list_in.list_in.start_key + list_in.list_in.start_ksize);
auto keys = datastore->list_keys(start, list_in.list_in.max_keys);
......