]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: show metadata log through radosgw-admin
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 20 Mar 2013 22:47:14 +0000 (15:47 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 17:57:45 +0000 (10:57 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_rados.cc

index eb1b3b92c63b793905fc04bc0499941c6971c271..bcf16afd8f7d948fe9eaa5750da2c87f782f2c7a 100644 (file)
@@ -87,6 +87,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";
@@ -191,6 +192,7 @@ enum {
   OPT_METADATA_GET,
   OPT_METADATA_PUT,
   OPT_METADATA_LIST,
+  OPT_MDLOG_SHOW,
 };
 
 static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
@@ -215,9 +217,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;
   }
@@ -348,6 +349,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;
@@ -1533,5 +1537,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;
 }
index 5ee7444c0ad11430f35833edf35ae900f3b21591..d22f5d63597177ed52a9259343a761245e395627 100644 (file)
@@ -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()
 {
index f50ab84e1ad6e64a7f12fa7b94fa596a380e2e03..bee940779f5269ed8ec154a79e9fb3d27e18ae07 100644 (file)
@@ -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
index 5d45f99c4ea573ea9d4426a3984aa8e652162388..86cf5a86e7b5a186e7ee2804a9201adcf0e526cb 100644 (file)
@@ -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);