From ce07e3bc743aa6092df8ce9427aafd047a407aa3 Mon Sep 17 00:00:00 2001 From: Naitik Shah Date: Sat, 9 Apr 2016 19:56:51 -0700 Subject: [PATCH] C rocksdb_create_iterators to expose NewIterators --- db/c.cc | 25 +++++++++++++++++++++++++ db/c_test.c | 24 ++++++++++++++++++++++++ include/rocksdb/c.h | 5 +++++ 3 files changed, 54 insertions(+) diff --git a/db/c.cc b/db/c.cc index 9f49aba2312..5c2162c5be5 100644 --- a/db/c.cc +++ b/db/c.cc @@ -825,6 +825,31 @@ rocksdb_iterator_t* rocksdb_create_iterator_cf( return result; } +void rocksdb_create_iterators( + rocksdb_t *db, + rocksdb_readoptions_t* opts, + rocksdb_column_family_handle_t** column_families, + rocksdb_iterator_t** iterators, + size_t size, + char** errptr) { + std::vector column_families_vec; + for (size_t i = 0; i < size; i++) { + column_families_vec.push_back(column_families[i]->rep); + } + + std::vector res; + Status status = db->rep->NewIterators(opts->rep, column_families_vec, &res); + assert(res.size() == size); + if (SaveError(errptr, status)) { + return; + } + + for (size_t i = 0; i < size; i++) { + iterators[i] = new rocksdb_iterator_t; + iterators[i]->rep = res[i]; + } +} + const rocksdb_snapshot_t* rocksdb_create_snapshot( rocksdb_t* db) { rocksdb_snapshot_t* result = new rocksdb_snapshot_t; diff --git a/db/c_test.c b/db/c_test.c index 554362711bc..fcc7cc4ba50 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -768,6 +768,30 @@ int main(int argc, char** argv) { CheckNoError(err); rocksdb_iter_destroy(iter); + rocksdb_column_family_handle_t* iters_cf_handles[2] = { handles[0], handles[1] }; + rocksdb_iterator_t* iters_handles[2]; + rocksdb_create_iterators(db, roptions, iters_cf_handles, iters_handles, 2, &err); + CheckNoError(err); + + iter = iters_handles[0]; + CheckCondition(!rocksdb_iter_valid(iter)); + rocksdb_iter_seek_to_first(iter); + CheckCondition(!rocksdb_iter_valid(iter)); + rocksdb_iter_destroy(iter); + + iter = iters_handles[1]; + CheckCondition(!rocksdb_iter_valid(iter)); + rocksdb_iter_seek_to_first(iter); + CheckCondition(rocksdb_iter_valid(iter)); + + for (i = 0; rocksdb_iter_valid(iter) != 0; rocksdb_iter_next(iter)) { + i++; + } + CheckCondition(i == 1); + rocksdb_iter_get_error(iter, &err); + CheckNoError(err); + rocksdb_iter_destroy(iter); + rocksdb_drop_column_family(db, handles[1], &err); CheckNoError(err); for (i = 0; i < 2; i++) { diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 6e52d20afe1..5bc30f68079 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -266,6 +266,11 @@ extern ROCKSDB_LIBRARY_API rocksdb_iterator_t* rocksdb_create_iterator_cf( rocksdb_t* db, const rocksdb_readoptions_t* options, rocksdb_column_family_handle_t* column_family); +extern ROCKSDB_LIBRARY_API void rocksdb_create_iterators( + rocksdb_t *db, rocksdb_readoptions_t* opts, + rocksdb_column_family_handle_t** column_families, + rocksdb_iterator_t** iterators, size_t size, char** errptr); + extern ROCKSDB_LIBRARY_API const rocksdb_snapshot_t* rocksdb_create_snapshot( rocksdb_t* db);