]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: metadata log trim
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 17:52:26 +0000 (10:52 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 19:18:17 +0000 (12:18 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/log/cls_log_client.cc
src/cls/log/cls_log_client.h
src/rgw/rgw_admin.cc
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index c551f40735876c74569878d663c2d645c1d35292..00e37bb43aa2d9554a96a121930213dfc3569970 100644 (file)
@@ -55,7 +55,7 @@ void cls_log_trim(librados::ObjectWriteOperation& op, utime_t& from, utime_t& to
   op.exec("log", "trim", in);
 }
 
-int cls_log_trim(librados::IoCtx& io_ctx, string& oid, utime_t& from, utime_t& to)
+int cls_log_trim(librados::IoCtx& io_ctx, const string& oid, utime_t& from, utime_t& to)
 {
   bool done = false;
 
index 4171adbda113f311091f4a65055f0ec4edbbfb69..a035e58bde1801857dc46f55deb01cde3c3abf0d 100644 (file)
@@ -22,6 +22,6 @@ void cls_log_list(librados::ObjectReadOperation& op, utime_t& from, utime_t& to,
                   string *out_marker, bool *truncated);
 
 void cls_log_trim(librados::ObjectWriteOperation& op, utime_t& from, utime_t& to);
-int cls_log_trim(librados::IoCtx& io_ctx, string& oid, utime_t& from, utime_t& to);
+int cls_log_trim(librados::IoCtx& io_ctx, const string& oid, utime_t& from, utime_t& to);
 
 #endif
index bb6f69ed638216f116429b91a0d86c7cf2a25750..7766e5196e5c1057e8e9904631303cdbef2eb3ac 100644 (file)
@@ -89,6 +89,7 @@ void _usage()
   cerr << "  metadata rm                remove metadata info\n";
   cerr << "  metadata list              list metadata info\n";
   cerr << "  mdlog list                 list metadata log\n";
+  cerr << "  mdlog trim                 trim metadata log\n";
   cerr << "  bilog list                 list bucket index log\n";
   cerr << "  datalog list               list data log\n";
   cerr << "options:\n";
@@ -198,6 +199,7 @@ enum {
   OPT_METADATA_RM,
   OPT_METADATA_LIST,
   OPT_MDLOG_LIST,
+  OPT_MDLOG_TRIM,
   OPT_BILOG_LIST,
   OPT_DATALOG_LIST,
 };
@@ -366,6 +368,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
   } else if (strcmp(prev_cmd, "mdlog") == 0) {
     if (strcmp(cmd, "list") == 0)
       return OPT_MDLOG_LIST;
+    if (strcmp(cmd, "trim") == 0)
+      return OPT_MDLOG_TRIM;
   } else if (strcmp(prev_cmd, "bilog") == 0) {
     if (strcmp(cmd, "list") == 0)
       return OPT_BILOG_LIST;
@@ -1765,6 +1769,26 @@ next:
     formatter->flush(cout);
   }
 
+  if (opt_cmd == OPT_MDLOG_TRIM) {
+    utime_t start_time, end_time;
+
+    int ret = parse_date_str(start_date, start_time);
+    if (ret < 0)
+      return -ret;
+
+    ret = parse_date_str(end_date, end_time);
+    if (ret < 0)
+      return -ret;
+
+    RGWMetadataLog *meta_log = store->meta_mgr->get_log();
+
+    ret = meta_log->trim(store, start_time, end_time);
+    if (ret < 0) {
+      cerr << "ERROR: meta_log->trim(): " << cpp_strerror(-ret) << std::endl;
+      return -ret;
+    }
+  }
+  
   if (opt_cmd == OPT_BILOG_LIST) {
     if (bucket_name.empty()) {
       cerr << "ERROR: bucket not specified" << std::endl;
index 695372c639938203a773bb2c5b7be39ef18e7660..423d96bde4fa249a11722447e0c37e61251f61a2 100644 (file)
@@ -130,7 +130,7 @@ int RGWMetadataLog::list_entries(void *handle,
 
     if (!is_truncated) {
       ++ctx->cur_shard;
-      if (ctx->cur_shard <cct->_conf->rgw_md_log_max_shards) {
+      if (ctx->cur_shard < cct->_conf->rgw_md_log_max_shards) {
         get_shard_oid(ctx->cur_shard, ctx->cur_oid);
         ctx->marker.clear();
       } else {
@@ -145,6 +145,26 @@ int RGWMetadataLog::list_entries(void *handle,
   return 0;
 }
 
+int RGWMetadataLog::trim(RGWRados *store, utime_t& from_time, utime_t& end_time)
+{
+  string oid;
+  for (int shard = 0; shard < cct->_conf->rgw_md_log_max_shards; shard++) {
+    get_shard_oid(shard, oid);
+
+    int ret;
+
+    ret = store->time_log_trim(oid, from_time, end_time);
+
+    if (ret == -ENOENT)
+      ret = 0;
+
+    if (ret < 0)
+      return ret;
+  }
+
+  return 0;
+}
+
 obj_version& RGWMetadataObject::get_version()
 {
   return objv;
index 686e41ca116c79a9b7ba82766620f284d1f645b6..266769e2e9cc54b972d3e57a7304631a72bbd127 100644 (file)
@@ -88,6 +88,8 @@ public:
                    int max_entries,
                    list<cls_log_entry>& entries,
                    bool *truncated);
+
+  int trim(RGWRados *store, utime_t& from_time, utime_t& end_time);
 };
 
 class RGWMetadataManager {
index 0b818cacd5c1bbc7a2b3c5b7c9c93c7a3d6ea9b4..6d6b6324331a29696032a9a758534d1a0935aae1 100644 (file)
@@ -1173,6 +1173,18 @@ int RGWRados::time_log_list(const string& oid, utime_t& start_time, utime_t& end
   return 0;
 }
 
+int RGWRados::time_log_trim(const string& oid, utime_t& start_time, utime_t& end_time)
+{
+  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;
+
+  return cls_log_trim(io_ctx, oid, start_time, end_time);
+}
+
 int RGWRados::decode_policy(bufferlist& bl, ACLOwner *owner)
 {
   bufferlist::iterator i = bl.begin();
index 5d59f9a2a7b65ea4a84a66d3ea3cdce7bfcfe9a1..231026e1f0da37f27a90d9ad83f87dd636de3f9d 100644 (file)
@@ -992,6 +992,7 @@ public:
   int time_log_add(const string& oid, const utime_t& ut, string& section, string& key, bufferlist& bl);
   int time_log_list(const string& oid, utime_t& start_time, utime_t& end_time,
                     int max_entries, list<cls_log_entry>& entries, string& marker, bool *truncated);
+  int time_log_trim(const string& oid, utime_t& start_time, utime_t& end_time);
 
   /// clean up/process any temporary objects older than given date[/time]
   int remove_temp_objects(string date, string time);