From 298366deb4473370467e3f345dddadc2d5a87b71 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 9 Dec 2016 14:22:57 -0800 Subject: [PATCH] rgw: marker for raw pool listing We now have a marker (cursor) that can be used for raw pool listing. Signed-off-by: Yehuda Sadeh (cherry picked from commit a24b8aeb1e376ce9e5e50535d8ce1a287c99fa90) --- src/rgw/rgw_rados.cc | 66 ++++++++++++++++++++++++++++++++++++++------ src/rgw/rgw_rados.h | 22 +++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 7a1fce857151..f844869ac862 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -12203,6 +12203,31 @@ int RGWRados::pool_iterate_begin(const rgw_pool& pool, RGWPoolIterCtx& ctx) return 0; } +int RGWRados::pool_iterate_begin(const rgw_pool& pool, const string& cursor, RGWPoolIterCtx& ctx) +{ + librados::IoCtx& io_ctx = ctx.io_ctx; + librados::NObjectIterator& iter = ctx.iter; + + int r = open_pool_ctx(pool, io_ctx); + if (r < 0) + return r; + + librados::ObjectCursor oc; + if (!oc.from_str(cursor)) { + ldout(cct, 10) << "failed to parse cursor: " << cursor << dendl; + return -EINVAL; + } + + iter = io_ctx.nobjects_begin(oc); + + return 0; +} + +string RGWRados::pool_iterate_get_cursor(RGWPoolIterCtx& ctx) +{ + return ctx.iter.get_cursor().to_str(); +} + int RGWRados::pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vector& objs, bool *is_truncated, RGWAccessListFilter *filter) { @@ -12242,21 +12267,27 @@ struct RGWAccessListFilterPrefix : public RGWAccessListFilter { } }; -int RGWRados::list_raw_objects(const rgw_pool& pool, const string& prefix_filter, - int max, RGWListRawObjsCtx& ctx, list& oids, - bool *is_truncated) +int RGWRados::list_raw_objects_init(const rgw_pool& pool, const string& marker, RGWListRawObjsCtx *ctx) { - RGWAccessListFilterPrefix filter(prefix_filter); - - if (!ctx.initialized) { - int r = pool_iterate_begin(pool, ctx.iter_ctx); + if (!ctx->initialized) { + int r = pool_iterate_begin(pool, marker, ctx->iter_ctx); if (r < 0) { ldout(cct, 10) << "failed to list objects pool_iterate_begin() returned r=" << r << dendl; return r; } - ctx.initialized = true; + ctx->initialized = true; } + return 0; +} +int RGWRados::list_raw_objects_next(const string& prefix_filter, int max, + RGWListRawObjsCtx& ctx, list& oids, + bool *is_truncated) +{ + if (!ctx.initialized) { + return -EINVAL; + } + RGWAccessListFilterPrefix filter(prefix_filter); vector objs; int r = pool_iterate(ctx.iter_ctx, max, objs, is_truncated, &filter); if (r < 0) { @@ -12273,6 +12304,25 @@ int RGWRados::list_raw_objects(const rgw_pool& pool, const string& prefix_filter return oids.size(); } +int RGWRados::list_raw_objects(const rgw_pool& pool, const string& prefix_filter, + int max, RGWListRawObjsCtx& ctx, list& oids, + bool *is_truncated) +{ + if (!ctx.initialized) { + int r = list_raw_objects_init(pool, string(), &ctx); + if (r < 0) { + return r; + } + } + + return list_raw_objects_next(prefix_filter, max, ctx, oids, is_truncated); +} + +string RGWRados::list_raw_objs_get_cursor(RGWListRawObjsCtx& ctx) +{ + return pool_iterate_get_cursor(ctx.iter_ctx); +} + int RGWRados::list_bi_log_entries(RGWBucketInfo& bucket_info, int shard_id, string& marker, uint32_t max, std::list& result, bool *truncated) { diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 23caafd6314f..6963315061fb 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -2517,11 +2517,17 @@ public: return rgw_shards_max(); } + int get_raw_obj_ref(const rgw_raw_obj& obj, rgw_rados_ref *ref); + int list_raw_objects_init(const rgw_pool& pool, const string& marker, RGWListRawObjsCtx *ctx); + int list_raw_objects_next(const string& prefix_filter, int max, + RGWListRawObjsCtx& ctx, list& oids, + bool *is_truncated); int list_raw_objects(const rgw_pool& pool, const string& prefix_filter, int max, RGWListRawObjsCtx& ctx, list& oids, bool *is_truncated); + string list_raw_objs_get_cursor(RGWListRawObjsCtx& ctx); int list_raw_prefixed_objs(const rgw_pool& pool, const string& prefix, list& result); int list_zonegroups(list& zonegroups); @@ -3644,6 +3650,22 @@ public: */ int pool_iterate_begin(const rgw_pool& pool, RGWPoolIterCtx& ctx); + /** + * Init pool iteration + * pool: pool to use + * cursor: position to start iteration + * ctx: context object to use for the iteration + * Returns: 0 on success, -ERR# otherwise. + */ + int pool_iterate_begin(const rgw_pool& pool, const string& cursor, RGWPoolIterCtx& ctx); + + /** + * Get pool iteration position + * ctx: context object to use for the iteration + * Returns: string representation of position + */ + string pool_iterate_get_cursor(RGWPoolIterCtx& ctx); + /** * Iterate over pool return object names, use optional filter * ctx: iteration context, initialized with pool_iterate_begin() -- 2.47.3