summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-03-20 15:47:14 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-03-22 11:29:49 -0700
commitec8073f9c7d59ef094f9338c0f07c7ee4423150f (patch)
tree2550b421d4855aa1c9dcda772a81bc9996c1e874
parent6909041e4c9e1cf6ddaec2c74f7f91af000525be (diff)
downloadceph-ec8073f9c7d59ef094f9338c0f07c7ee4423150f.tar.gz
rgw: show metadata log through radosgw-admin
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_admin.cc43
-rw-r--r--src/rgw/rgw_metadata.cc89
-rw-r--r--src/rgw/rgw_metadata.h45
-rw-r--r--src/rgw/rgw_rados.cc5
4 files changed, 154 insertions, 28 deletions
diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc
index 246d0d528b6..781206cbb69 100644
--- a/src/rgw/rgw_admin.cc
+++ b/src/rgw/rgw_admin.cc
@@ -86,6 +86,7 @@ void _usage()
cerr << " metadata get get metadata info\n";
cerr << " metadata put put metadata info\n";
cerr << " metadata list list metadata info\n";
+ cerr << " mdlog show show metadata log\n";
cerr << "options:\n";
cerr << " --uid=<id> user id\n";
cerr << " --subuser=<name> subuser name\n";
@@ -190,6 +191,7 @@ enum {
OPT_METADATA_GET,
OPT_METADATA_PUT,
OPT_METADATA_LIST,
+ OPT_MDLOG_SHOW,
};
static uint32_t str_to_perm(const char *str)
@@ -229,9 +231,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
strcmp(cmd, "regionmap") == 0 ||
strcmp(cmd, "zone") == 0 ||
strcmp(cmd, "temp") == 0 ||
- strcmp(cmd, "usage") == 0 ||
- strcmp(cmd, "user") == 0 ||
- strcmp(cmd, "metadata") == 0) {
+ strcmp(cmd, "metadata") == 0 ||
+ strcmp(cmd, "mdlog") == 0) {
*need_more = true;
return 0;
}
@@ -362,6 +363,9 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
return OPT_METADATA_PUT;
if (strcmp(cmd, "list") == 0)
return OPT_METADATA_LIST;
+ } else if (strcmp(prev_cmd, "mdlog") == 0) {
+ if (strcmp(cmd, "show") == 0)
+ return OPT_MDLOG_SHOW;
}
return -EINVAL;
@@ -2221,5 +2225,38 @@ next:
store->meta_mgr->list_keys_complete(handle);
}
+ if (opt_cmd == OPT_MDLOG_SHOW) {
+ void *handle;
+ list<cls_log_entry> entries;
+
+ RGWMetadataLog *meta_log = store->meta_mgr->get_log();
+
+ utime_t from_time;
+ utime_t end_time;
+ meta_log->init_list_entries(store, from_time, end_time, &handle);
+
+ bool truncated;
+
+ formatter->open_array_section("entries");
+ do {
+ int ret = meta_log->list_entries(handle, 1000, entries, &truncated);
+ if (ret < 0) {
+ cerr << "ERROR: meta_log->list_entries(): " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+
+ for (list<cls_log_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) {
+ cls_log_entry& entry = *iter;
+ formatter->open_object_section("entry");
+ formatter->dump_string("name", entry.name);
+ formatter->close_section();
+ }
+ formatter->flush(cout);
+ } while (truncated);
+
+ formatter->close_section();
+ formatter->flush(cout);
+ }
+
return 0;
}
diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc
index 5ee7444c0ad..d22f5d63597 100644
--- a/src/rgw/rgw_metadata.cc
+++ b/src/rgw/rgw_metadata.cc
@@ -6,35 +6,76 @@
#include "rgw_rados.h"
-#define META_LOG_OBJ_PREFIX "meta.log."
+int RGWMetadataLog::add_entry(RGWRados *store, string& section, string& key, bufferlist& bl) {
+ string oid;
-class RGWMetadataLog {
- CephContext *cct;
- RGWRados *store;
- string prefix;
+ store->shard_name(prefix, cct->_conf->rgw_md_log_max_shards, section, key, oid);
+ utime_t now = ceph_clock_now(cct);
+ return store->time_log_add(oid, now, section, key, bl);
+}
-public:
- RGWMetadataLog(CephContext *_cct, RGWRados *_store) : cct(_cct), store(_store) {
- prefix = META_LOG_OBJ_PREFIX;
- }
+void RGWMetadataLog::init_list_entries(RGWRados *store, utime_t& from_time, utime_t& end_time, void **handle)
+{
+ LogListCtx *ctx = new LogListCtx(store);
- int add_entry(RGWRados *store, string& section, string& key, bufferlist& bl) {
- string oid;
+ ctx->from_time = from_time;
+ ctx->end_time = end_time;
- store->shard_name(prefix, cct->_conf->rgw_md_log_max_shards, section, key, oid);
- utime_t now = ceph_clock_now(cct);
- return store->time_log_add(oid, now, section, key, bl);
- }
- int list_entries(RGWRados *store, string& section, string& key,
- utime_t& from_time, utime_t& end_time,
- list<cls_log_entry>& entries,
- string& marker, bool *truncated) {
- string oid;
-
- store->shard_name(prefix, cct->_conf->rgw_md_log_max_shards, section, key, oid);
- return store->time_log_list(oid, from_time, end_time, 0, entries, marker, truncated);
+ get_shard_oid(0, ctx->cur_oid);
+
+ *handle = (void *)ctx;
+}
+
+void RGWMetadataLog::complete_list_entries(void *handle) {
+ LogListCtx *ctx = (LogListCtx *)handle;
+ delete ctx;
+}
+
+int RGWMetadataLog::list_entries(void *handle,
+ int max_entries,
+ list<cls_log_entry>& entries,
+ bool *truncated) {
+ LogListCtx *ctx = (LogListCtx *)handle;
+
+ if (ctx->done || !max_entries) {
+ *truncated = false;
+ return 0;
}
-};
+
+ entries.clear();
+
+ do {
+ list<cls_log_entry> ents;
+ bool is_truncated;
+ int ret = store->time_log_list(ctx->cur_oid, ctx->from_time, ctx->end_time,
+ max_entries - entries.size(), ents, ctx->marker, &is_truncated);
+ if (ret = -ENOENT) {
+ is_truncated = false;
+ ret = 0;
+ }
+ if (ret < 0)
+ return ret;
+
+ if (ents.size()) {
+ entries.splice(entries.end(), ents);
+ }
+
+ if (!is_truncated) {
+ ++ctx->cur_shard;
+ if (ctx->cur_shard <cct->_conf->rgw_md_log_max_shards) {
+ get_shard_oid(ctx->cur_shard, ctx->cur_oid);
+ ctx->marker.clear();
+ } else {
+ ctx->done = true;
+ break;
+ }
+ }
+ } while (entries.size() < (size_t)max_entries);
+
+ *truncated = !ctx->done;
+
+ return 0;
+}
obj_version& RGWMetadataObject::get_version()
{
diff --git a/src/rgw/rgw_metadata.h b/src/rgw/rgw_metadata.h
index f50ab84e1ad..bee940779f5 100644
--- a/src/rgw/rgw_metadata.h
+++ b/src/rgw/rgw_metadata.h
@@ -6,6 +6,7 @@
#include "include/types.h"
#include "rgw_common.h"
#include "cls/version/cls_version_types.h"
+#include "cls/log/cls_log_types.h"
class RGWRados;
@@ -47,7 +48,47 @@ public:
virtual void list_keys_complete(void *handle) = 0;
};
-class RGWMetadataLog;
+#define META_LOG_OBJ_PREFIX "meta.log."
+
+class RGWMetadataLog {
+ CephContext *cct;
+ RGWRados *store;
+ string prefix;
+
+ void get_shard_oid(int id, string& oid) {
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%d", id);
+ oid = prefix + buf;
+ }
+
+public:
+ RGWMetadataLog(CephContext *_cct, RGWRados *_store) : cct(_cct), store(_store) {
+ prefix = META_LOG_OBJ_PREFIX;
+ }
+
+ int add_entry(RGWRados *store, string& section, string& key, bufferlist& bl);
+
+ struct LogListCtx {
+ RGWRados *store;
+ int cur_shard;
+ string marker;
+ utime_t from_time;
+ utime_t end_time;
+
+ string cur_oid;
+
+ bool done;
+
+ LogListCtx(RGWRados *_store) : store(_store), cur_shard(0), done(false) {}
+ };
+
+ void init_list_entries(RGWRados *store, utime_t& from_time, utime_t& end_time, void **handle);
+ void complete_list_entries(void *handle);
+ int list_entries(void *handle,
+ int max_entries,
+ list<cls_log_entry>& entries,
+ bool *truncated);
+};
class RGWMetadataManager {
map<string, RGWMetadataHandler *> handlers;
@@ -76,6 +117,8 @@ public:
void list_keys_complete(void *handle);
void get_sections(list<string>& sections);
+
+ RGWMetadataLog *get_log() { return md_log; }
};
#endif
diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc
index a8ac4acd436..c1ad786a063 100644
--- a/src/rgw/rgw_rados.cc
+++ b/src/rgw/rgw_rados.cc
@@ -1106,6 +1106,11 @@ int RGWRados::time_log_list(const string& oid, utime_t& start_time, utime_t& end
{
librados::IoCtx io_ctx;
+ const char *log_pool = zone.log_pool.name.c_str();
+ int r = rados->ioctx_create(log_pool, io_ctx);
+ if (r < 0)
+ return r;
+
librados::ObjectReadOperation op;
cls_log_list(op, start_time, end_time, marker, max_entries, entries, &marker, truncated);