summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-10-03 12:38:40 -0700
committerSage Weil <sage@inktank.com>2013-10-10 11:51:38 -0700
commit3c7af76b8fb65843a04603a80b706041f45d91fa (patch)
treed6a019fab878fa1492fa57a52777dc7ab0434606
parentf496e5714ddee2af291f0903d5d041fd02f8ef21 (diff)
downloadceph-3c7af76b8fb65843a04603a80b706041f45d91fa.tar.gz
librados: add get_pg_hash_position to determine pg while listing objects
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r--src/include/rados/librados.h8
-rw-r--r--src/include/rados/librados.hpp4
-rw-r--r--src/librados/librados.cc12
-rw-r--r--src/osdc/Objecter.h4
-rw-r--r--src/test/librados/list.cc37
5 files changed, 65 insertions, 0 deletions
diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h
index 515663c2335..449aeebe41a 100644
--- a/src/include/rados/librados.h
+++ b/src/include/rados/librados.h
@@ -685,6 +685,14 @@ void rados_ioctx_set_namespace(rados_ioctx_t io, const char *nspace);
int rados_objects_list_open(rados_ioctx_t io, rados_list_ctx_t *ctx);
/**
+ * Return hash position of iterator, rounded to the current PG
+ *
+ * @param ctx iterator marking where you are in the listing
+ * @returns current hash position, rounded to the current pg
+ */
+uint32_t rados_objects_list_get_pg_hash_position(rados_list_ctx_t ctx);
+
+/**
* Get the next object name and locator in the pool
*
* *entry and *key are valid until next call to rados_objects_list_*
diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp
index 3f6d025ff41..46cedd578c5 100644
--- a/src/include/rados/librados.hpp
+++ b/src/include/rados/librados.hpp
@@ -71,6 +71,10 @@ namespace librados
ObjectIterator &operator++(); // Preincrement
ObjectIterator operator++(int); // Postincrement
friend class IoCtx;
+
+ /// get current hash position of the iterator, rounded to the current pg
+ uint32_t get_pg_hash_position() const;
+
private:
void get_next();
std::tr1::shared_ptr < ObjListCtx > ctx;
diff --git a/src/librados/librados.cc b/src/librados/librados.cc
index 217a0a7bfb2..a916abcff26 100644
--- a/src/librados/librados.cc
+++ b/src/librados/librados.cc
@@ -506,6 +506,11 @@ void librados::ObjectIterator::get_next()
cur_obj = make_pair(entry, key ? key : string());
}
+uint32_t librados::ObjectIterator::get_pg_hash_position() const
+{
+ return ctx->lc->get_pg_hash_position();
+}
+
const librados::ObjectIterator librados::ObjectIterator::__EndObjectIterator(NULL);
///////////////////////////// PoolAsyncCompletion //////////////////////////////
@@ -2529,6 +2534,13 @@ extern "C" void rados_objects_list_close(rados_list_ctx_t h)
delete lh;
}
+extern "C" uint32_t rados_objects_list_get_pg_hash_position(
+ rados_list_ctx_t listctx)
+{
+ librados::ObjListCtx *lh = (librados::ObjListCtx *)listctx;
+ return lh->lc->get_pg_hash_position();
+}
+
extern "C" int rados_objects_list_next(rados_list_ctx_t listctx, const char **entry, const char **key)
{
librados::ObjListCtx *lh = (librados::ObjListCtx *)listctx;
diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h
index b42a211b754..ca67aff3660 100644
--- a/src/osdc/Objecter.h
+++ b/src/osdc/Objecter.h
@@ -1031,6 +1031,10 @@ public:
ListContext() : current_pg(0), current_pg_epoch(0), starting_pg_num(0),
at_end(false), pool_id(0),
pool_snap_seq(0), max_entries(0) {}
+
+ uint32_t get_pg_hash_position() const {
+ return current_pg;
+ }
};
struct C_List : public Context {
diff --git a/src/test/librados/list.cc b/src/test/librados/list.cc
index 1ea56c295a4..fca0ad40395 100644
--- a/src/test/librados/list.cc
+++ b/src/test/librados/list.cc
@@ -1,5 +1,6 @@
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
+#include "include/stringify.h"
#include "test/librados/test.h"
#include "gtest/gtest.h"
@@ -177,3 +178,39 @@ TEST(LibRadosList, ListObjectsPPNS) {
ioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
+
+TEST(LibRadosList, ListObjectsManyPP) {
+ std::string pool_name = get_temp_pool_name();
+ Rados cluster;
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ char buf[128];
+ memset(buf, 0xcc, sizeof(buf));
+ bufferlist bl;
+ bl.append(buf, sizeof(buf));
+
+ for (int i=0; i<256; ++i) {
+ ASSERT_EQ((int)sizeof(buf), ioctx.write(stringify(i), bl, bl.length(), 0));
+ }
+
+ librados::ObjectIterator it = ioctx.objects_begin();
+ std::set<std::string> saw_obj;
+ std::set<int> saw_pg;
+ for (; it != ioctx.objects_end(); ++it) {
+ std::cout << it->first
+ << " " << it.get_pg_hash_position() << std::endl;
+ saw_obj.insert(it->first);
+ saw_pg.insert(it.get_pg_hash_position());
+ }
+ std::cout << "saw " << saw_pg.size() << " pgs " << std::endl;
+
+ // make sure they are 0..n
+ for (unsigned i = 0; i < saw_pg.size(); ++i)
+ ASSERT_TRUE(saw_pg.count(i));
+
+ ioctx.close();
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+