diff options
author | Sage Weil <sage@newdream.net> | 2017-03-07 15:41:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 15:41:08 +0100 |
commit | 3f5269d8b5ddfe4694af452103f0a811fcf76bb4 (patch) | |
tree | 047e47098e86b3c31f23da32beb113ffefecada1 /src/librados | |
parent | Merge pull request #13262 from batrick/multimds-thrasher (diff) | |
parent | test/librados: extend pool list test to include cursor (diff) | |
download | ceph-3f5269d8b5ddfe4694af452103f0a811fcf76bb4.tar.xz ceph-3f5269d8b5ddfe4694af452103f0a811fcf76bb4.zip |
Merge pull request #13323 from yehudasa/wip-18079-2
librados: use cursor for nobjects listing
Reviewed-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src/librados')
-rw-r--r-- | src/librados/IoCtxImpl.cc | 15 | ||||
-rw-r--r-- | src/librados/IoCtxImpl.h | 2 | ||||
-rw-r--r-- | src/librados/ListObjectImpl.h | 6 | ||||
-rw-r--r-- | src/librados/librados.cc | 127 |
4 files changed, 144 insertions, 6 deletions
diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index 16662ca9e88..835711030bd 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -595,6 +595,21 @@ uint32_t librados::IoCtxImpl::nlist_seek(Objecter::NListContext *context, return objecter->list_nobjects_seek(context, pos); } +uint32_t librados::IoCtxImpl::nlist_seek(Objecter::NListContext *context, + const rados_object_list_cursor& cursor) +{ + context->list.clear(); + return objecter->list_nobjects_seek(context, *(const hobject_t *)cursor); +} + +rados_object_list_cursor librados::IoCtxImpl::nlist_get_cursor(Objecter::NListContext *context) +{ + hobject_t *c = new hobject_t; + + objecter->list_nobjects_get_cursor(context, c); + return (rados_object_list_cursor)c; +} + int librados::IoCtxImpl::create(const object_t& oid, bool exclusive) { ::ObjectOperation op; diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index 3db028398a5..873a9fcad43 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -110,6 +110,8 @@ struct librados::IoCtxImpl { // io int nlist(Objecter::NListContext *context, int max_entries); uint32_t nlist_seek(Objecter::NListContext *context, uint32_t pos); + uint32_t nlist_seek(Objecter::NListContext *context, const rados_object_list_cursor& cursor); + rados_object_list_cursor nlist_get_cursor(Objecter::NListContext *context); void object_list_slice( const hobject_t start, const hobject_t finish, diff --git a/src/librados/ListObjectImpl.h b/src/librados/ListObjectImpl.h index bda275f7f5c..7e605254652 100644 --- a/src/librados/ListObjectImpl.h +++ b/src/librados/ListObjectImpl.h @@ -67,6 +67,12 @@ class NObjectIteratorImpl { /// move the iterator to a given hash position. this may (will!) be rounded to the nearest pg. uint32_t seek(uint32_t pos); + /// move the iterator to a given cursor position + uint32_t seek(const librados::ObjectCursor& cursor); + + /// get current cursor position + librados::ObjectCursor get_cursor(); + void set_filter(const bufferlist &bl); private: diff --git a/src/librados/librados.cc b/src/librados/librados.cc index d2f7b280bd4..5b5639287b6 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -737,6 +737,21 @@ uint32_t librados::NObjectIteratorImpl::seek(uint32_t pos) return r; } +uint32_t librados::NObjectIteratorImpl::seek(const ObjectCursor& cursor) +{ + uint32_t r = rados_nobjects_list_seek_cursor(ctx.get(), (rados_object_list_cursor)cursor.c_cursor); + get_next(); + return r; +} + +librados::ObjectCursor librados::NObjectIteratorImpl::get_cursor() +{ + librados::ObjListCtx *lh = (librados::ObjListCtx *)ctx.get(); + librados::ObjectCursor oc; + oc.set(lh->ctx->nlist_get_cursor(lh->nlc)); + return oc; +} + void librados::NObjectIteratorImpl::set_filter(const bufferlist &bl) { assert(ctx); @@ -848,6 +863,18 @@ uint32_t librados::NObjectIterator::seek(uint32_t pos) return impl->seek(pos); } +uint32_t librados::NObjectIterator::seek(const ObjectCursor& cursor) +{ + assert(impl); + return impl->seek(cursor); +} + +librados::ObjectCursor librados::NObjectIterator::get_cursor() +{ + assert(impl); + return impl->get_cursor(); +} + void librados::NObjectIterator::set_filter(const bufferlist &bl) { impl->set_filter(bl); @@ -1702,6 +1729,25 @@ librados::NObjectIterator librados::IoCtx::nobjects_begin( return iter; } +librados::NObjectIterator librados::IoCtx::nobjects_begin(const ObjectCursor& cursor) +{ + bufferlist bl; + return nobjects_begin(cursor, bl); +} + +librados::NObjectIterator librados::IoCtx::nobjects_begin( + const ObjectCursor& cursor, const bufferlist &filter) +{ + rados_list_ctx_t listh; + rados_nobjects_list_open(io_ctx_impl, &listh); + NObjectIterator iter((ObjListCtx*)listh); + if (filter.length() > 0) { + iter.set_filter(filter); + } + iter.seek(cursor); + return iter; +} + const librados::NObjectIterator& librados::IoCtx::nobjects_end() const { return NObjectIterator::__EndObjectIterator; @@ -4163,6 +4209,28 @@ extern "C" uint32_t rados_nobjects_list_seek(rados_list_ctx_t listctx, return r; } +extern "C" uint32_t rados_nobjects_list_seek_cursor(rados_list_ctx_t listctx, + rados_object_list_cursor cursor) +{ + librados::ObjListCtx *lh = (librados::ObjListCtx *)listctx; + + tracepoint(librados, rados_nobjects_list_seek_cursor_enter, listctx); + uint32_t r = lh->ctx->nlist_seek(lh->nlc, cursor); + tracepoint(librados, rados_nobjects_list_seek_cursor_exit, r); + return r; +} + +extern "C" int rados_nobjects_list_get_cursor(rados_list_ctx_t listctx, + rados_object_list_cursor *cursor) +{ + librados::ObjListCtx *lh = (librados::ObjListCtx *)listctx; + + tracepoint(librados, rados_nobjects_list_get_cursor_enter, listctx); + *cursor = lh->ctx->nlist_get_cursor(lh->nlc); + tracepoint(librados, rados_nobjects_list_get_cursor_exit, 0); + return 0; +} + extern "C" uint32_t rados_nobjects_list_get_pg_hash_position( rados_list_ctx_t listctx) { @@ -5839,7 +5907,7 @@ CEPH_RADOS_API void rados_object_list_slice( librados::ObjectCursor::ObjectCursor() { - c_cursor = new hobject_t(); + c_cursor = (rados_object_list_cursor)new hobject_t(); } librados::ObjectCursor::~ObjectCursor() @@ -5848,14 +5916,16 @@ librados::ObjectCursor::~ObjectCursor() delete h; } -bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs) +librados::ObjectCursor::ObjectCursor(rados_object_list_cursor c) { - const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); - const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); - return lhs_hobj < rhs_hobj; + if (!c) { + c_cursor = nullptr; + } else { + c_cursor = (rados_object_list_cursor)new hobject_t(*(hobject_t *)c); + } } -librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) +librados::ObjectCursor& librados::ObjectCursor::operator=(const librados::ObjectCursor& rhs) { if (rhs.c_cursor != nullptr) { hobject_t *h = (hobject_t*)rhs.c_cursor; @@ -5863,6 +5933,25 @@ librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) } else { c_cursor = nullptr; } + return *this; +} + +bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs) const +{ + const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); + const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); + return lhs_hobj < rhs_hobj; +} + +bool librados::ObjectCursor::operator==(const librados::ObjectCursor &rhs) const +{ + const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); + const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); + return cmp(lhs_hobj, rhs_hobj) == 0; +} +librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) +{ + *this = rhs; } librados::ObjectCursor librados::IoCtx::object_list_begin() @@ -5889,6 +5978,32 @@ void librados::ObjectCursor::set(rados_object_list_cursor c) c_cursor = c; } +string librados::ObjectCursor::to_str() const +{ + stringstream ss; + ss << *(hobject_t *)c_cursor; + return ss.str(); +} + +bool librados::ObjectCursor::from_str(const string& s) +{ + if (s.empty()) { + *(hobject_t *)c_cursor = hobject_t(); + return true; + } + return ((hobject_t *)c_cursor)->parse(s); +} + +CEPH_RADOS_API std::ostream& librados::operator<<(std::ostream& os, const librados::ObjectCursor& oc) +{ + if (oc.c_cursor) { + os << *(hobject_t *)oc.c_cursor; + } else { + os << hobject_t(); + } + return os; +} + bool librados::IoCtx::object_list_is_end(const ObjectCursor &oc) { hobject_t *h = (hobject_t *)oc.c_cursor; |