]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: RESTful api for shards info
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 2 Jul 2013 23:15:42 +0000 (16:15 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 2 Jul 2013 23:15:42 +0000 (16:15 -0700)
For both mdlog, datalog

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_json_enc.cc
src/rgw/rgw_metadata.cc
src/rgw/rgw_metadata.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_log.cc
src/rgw/rgw_rest_log.h

index 2e94423be859b3c7a9681c8a952e484ac9565acc..f7efd266047fb271a4b30d9216671c891fe373b6 100644 (file)
@@ -1219,11 +1219,33 @@ int RGWDataChangesLog::list_entries(utime_t& start_time, utime_t& end_time, int
   return 0;
 }
 
+int RGWDataChangesLog::get_info(int shard_id, RGWDataChangesLogInfo *info)
+{
+  if (shard_id > num_shards)
+    return -EINVAL;
+
+  string oid = oids[shard_id];
+
+  cls_log_header header;
+
+  int ret = store->time_log_info(oid, &header);
+  if ((ret < 0) && (ret != -ENOENT))
+    return ret;
+
+  info->marker = header.max_marker;
+  info->last_update = header.max_time;
+
+  return 0;
+}
+
 int RGWDataChangesLog::trim_entries(int shard_id, const utime_t& start_time, const utime_t& end_time,
                                     const string& start_marker, const string& end_marker)
 {
   int ret;
 
+  if (shard_id > num_shards)
+    return -EINVAL;
+
   ret = store->time_log_trim(oids[shard_id], start_time, end_time, start_marker, end_marker);
 
   if (ret == -ENOENT)
index 50d51444eb0ecbb43f4fcfaf0148ff3cf51a506f..d5f023f7bd9fa7a04a832b96ec8cd965a066ac39 100644 (file)
@@ -263,6 +263,14 @@ struct rgw_data_change {
 };
 WRITE_CLASS_ENCODER(rgw_data_change)
 
+struct RGWDataChangesLogInfo {
+  string marker;
+  utime_t last_update;
+
+  void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+
 class RGWDataChangesLog {
   CephContext *cct;
   RGWRados *store;
@@ -349,6 +357,7 @@ public:
                    const string& start_marker, const string& end_marker);
   int trim_entries(const utime_t& start_time, const utime_t& end_time,
                    const string& start_marker, const string& end_marker);
+  int get_info(int shard_id, RGWDataChangesLogInfo *info);
   int lock_exclusive(int shard_id, utime_t& duration, string& zone_id, string& owner_id) {
     return store->lock_exclusive(store->zone.log_pool, oids[shard_id], duration, zone_id, owner_id);
   }
index c3d1e7baba8fe87b101fc6c825e3896f477f7c1e..face8534eb581956efee4ae00f0d72b37edab3f2 100644 (file)
@@ -5,6 +5,7 @@
 #include "rgw_acl.h"
 #include "rgw_acl_s3.h"
 #include "rgw_cache.h"
+#include "rgw_bucket.h"
 
 #include "common/ceph_json.h"
 #include "common/Formatter.h"
@@ -652,3 +653,27 @@ void RGWRegionMap::decode_json(JSONObj *obj)
   JSONDecoder::decode_json("master_region", master_region, obj);
 }
 
+void RGWMetadataLogInfo::dump(Formatter *f) const
+{
+  encode_json("marker", marker, f);
+  encode_json("last_update", last_update, f);
+}
+
+void RGWMetadataLogInfo::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("marker", marker, obj);
+  JSONDecoder::decode_json("last_update", last_update, obj);
+}
+
+void RGWDataChangesLogInfo::dump(Formatter *f) const
+{
+  encode_json("marker", marker, f);
+  encode_json("last_update", last_update, f);
+}
+
+void RGWDataChangesLogInfo::decode_json(JSONObj *obj)
+{
+  JSONDecoder::decode_json("marker", marker, obj);
+  JSONDecoder::decode_json("last_update", last_update, obj);
+}
+
index 5735396e33cfd09bb41339ec3fbe4049235b0322..c370addc293f65cbc18b5d72f2baf5262689786b 100644 (file)
@@ -130,6 +130,23 @@ int RGWMetadataLog::list_entries(void *handle,
   return 0;
 }
 
+int RGWMetadataLog::get_info(int shard_id, RGWMetadataLogInfo *info)
+{
+  string oid;
+  get_shard_oid(shard_id, oid);
+
+  cls_log_header header;
+
+  int ret = store->time_log_info(oid, &header);
+  if ((ret < 0) && (ret != -ENOENT))
+    return ret;
+
+  info->marker = header.max_marker;
+  info->last_update = header.max_time;
+
+  return 0;
+}
+
 int RGWMetadataLog::trim(int shard_id, const utime_t& from_time, const utime_t& end_time,
                          const string& start_marker, const string& end_marker)
 {
index ff0e35f94386e0dcc7e46cb77afd862dd3cc1665..2cc9110191aab2dc1d461e5b15fde0e0816edb10 100644 (file)
@@ -66,6 +66,14 @@ public:
 
 #define META_LOG_OBJ_PREFIX "meta.log."
 
+struct RGWMetadataLogInfo {
+  string marker;
+  utime_t last_update;
+
+  void dump(Formatter *f) const;
+  void decode_json(JSONObj *obj);
+};
+
 class RGWMetadataLog {
   CephContext *cct;
   RGWRados *store;
@@ -104,6 +112,7 @@ public:
                    list<cls_log_entry>& entries, bool *truncated);
 
   int trim(int shard_id, const utime_t& from_time, const utime_t& end_time, const string& start_marker, const string& end_marker);
+  int get_info(int shard_id, RGWMetadataLogInfo *info);
   int lock_exclusive(int shard_id, utime_t& duration, string&zone_id, string& owner_id);
   int unlock(int shard_id, string& zone_id, string& owner_id);
 };
index be75db65fe7e00ccb2d45015324540b400dffb4e..40867432fe43bbb2f75879b1066fdcdc43f385bc 100644 (file)
@@ -1524,6 +1524,27 @@ int RGWRados::time_log_list(const string& oid, utime_t& start_time, utime_t& end
   return 0;
 }
 
+int RGWRados::time_log_info(const string& oid, cls_log_header *header)
+{
+  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_info(op, header);
+
+  bufferlist obl;
+
+  int ret = io_ctx.operate(oid, &op, &obl);
+  if (ret < 0)
+    return ret;
+
+  return 0;
+}
+
 int RGWRados::time_log_trim(const string& oid, const utime_t& start_time, const utime_t& end_time,
                            const string& from_marker, const string& to_marker)
 {
index c8d031557d7271c44c263450f5a0a3723ab5a784..3c91153db773f3eea2d7cce28824d6809d5ade47 100644 (file)
@@ -1340,6 +1340,7 @@ public:
   int time_log_add(const string& oid, const utime_t& ut, const string& section, const 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_info(const string& oid, cls_log_header *header);
   int time_log_trim(const string& oid, const utime_t& start_time, const utime_t& end_time,
                     const string& from_marker, const string& to_marker);
   int lock_exclusive(rgw_bucket& pool, const string& oid, utime_t& duration, string& zone_id, string& owner_id);
index 2dc6071321bd317f3aec41f48ee10ee78224c310..1c54710f5beb7248a3aa93fa6082b14043e41637 100644 (file)
@@ -109,12 +109,12 @@ void RGWOp_MDLog_List::send_response() {
   flusher.flush();
 }
 
-void RGWOp_MDLog_GetShardsInfo::execute() {
+void RGWOp_MDLog_Info::execute() {
   num_objects = s->cct->_conf->rgw_md_log_max_shards;
   http_ret = 0;
 }
 
-void RGWOp_MDLog_GetShardsInfo::send_response() {
+void RGWOp_MDLog_Info::send_response() {
   set_req_state_err(s, http_ret);
   dump_errno(s);
   end_header(s);
@@ -125,6 +125,31 @@ void RGWOp_MDLog_GetShardsInfo::send_response() {
   flusher.flush();
 }
 
+void RGWOp_MDLog_ShardInfo::execute() {
+  string shard = s->info.args.get("id");
+  string err;
+
+  unsigned shard_id = (unsigned)strict_strtol(shard.c_str(), 10, &err);
+  if (!err.empty()) {
+    dout(5) << "Error parsing shard_id " << shard << dendl;
+    http_ret = -EINVAL;
+    return;
+  }
+
+  RGWMetadataLog *meta_log = store->meta_mgr->get_log();
+
+  http_ret = meta_log->get_info(shard_id, &info);
+}
+
+void RGWOp_MDLog_ShardInfo::send_response() {
+  set_req_state_err(s, http_ret);
+  dump_errno(s);
+  end_header(s);
+
+  encode_json("info", info, s->formatter);
+  flusher.flush();
+}
+
 void RGWOp_MDLog_Delete::execute() {
   string   st = s->info.args.get("start-time"),
            et = s->info.args.get("end-time"),
@@ -425,12 +450,12 @@ void RGWOp_DATALog_List::send_response() {
 }
 
 
-void RGWOp_DATALog_GetShardsInfo::execute() {
+void RGWOp_DATALog_Info::execute() {
   num_objects = s->cct->_conf->rgw_data_log_num_shards;
   http_ret = 0;
 }
 
-void RGWOp_DATALog_GetShardsInfo::send_response() {
+void RGWOp_DATALog_Info::send_response() {
   set_req_state_err(s, http_ret);
   dump_errno(s);
   end_header(s);
@@ -441,6 +466,29 @@ void RGWOp_DATALog_GetShardsInfo::send_response() {
   flusher.flush();
 }
 
+void RGWOp_DATALog_ShardInfo::execute() {
+  string shard = s->info.args.get("id");
+  string err;
+
+  unsigned shard_id = (unsigned)strict_strtol(shard.c_str(), 10, &err);
+  if (!err.empty()) {
+    dout(5) << "Error parsing shard_id " << shard << dendl;
+    http_ret = -EINVAL;
+    return;
+  }
+
+  http_ret = store->data_log->get_info(shard_id, &info);
+}
+
+void RGWOp_DATALog_ShardInfo::send_response() {
+  set_req_state_err(s, http_ret);
+  dump_errno(s);
+  end_header(s);
+
+  encode_json("info", info, s->formatter);
+  flusher.flush();
+}
+
 void RGWOp_DATALog_Lock::execute() {
   string shard_id_str, duration_str, locker_id, zone_id;
   unsigned shard_id;
@@ -558,7 +606,7 @@ RGWOp *RGWHandler_Log::op_get() {
     if (s->info.args.exists("id")) {
       return new RGWOp_MDLog_List;
     } else {
-      return new RGWOp_MDLog_GetShardsInfo;
+      return new RGWOp_MDLog_Info;
     }
   } else if (type.compare("bucket-index") == 0) {
     return new RGWOp_BILog_List;
@@ -566,7 +614,7 @@ RGWOp *RGWHandler_Log::op_get() {
     if (s->info.args.exists("id")) {
       return new RGWOp_DATALog_List;
     } else {
-      return new RGWOp_DATALog_GetShardsInfo;
+      return new RGWOp_DATALog_Info;
     }
   }
   return NULL;
index 58207c59c32ae6d416874f00252f11b6bb5fd89f..ec340d66482af96aad66c92bc50a52d9e928c7d5 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef CEPH_RGW_REST_LOG_H
 #define CEPH_RGW_REST_LOG_H
 
+#include "rgw_metadata.h"
+
 class RGWOp_BILog_List : public RGWRESTOp {
   int http_ret;
   bool sent_header;
@@ -70,12 +72,31 @@ public:
   }
 };
 
-class RGWOp_MDLog_GetShardsInfo : public RGWRESTOp {
+class RGWOp_MDLog_Info : public RGWRESTOp {
   unsigned num_objects;
   int http_ret;
 public:
-  RGWOp_MDLog_GetShardsInfo() : num_objects(0), http_ret(0) {}
-  ~RGWOp_MDLog_GetShardsInfo() {}
+  RGWOp_MDLog_Info() : num_objects(0), http_ret(0) {}
+  ~RGWOp_MDLog_Info() {}
+
+  int check_caps(RGWUserCaps& caps) {
+    return caps.check_cap("mdlog", RGW_CAP_READ);
+  }
+  int verify_permission() {
+    return check_caps(s->user.caps);
+  }
+  void execute();
+  virtual void send_response();
+  virtual const char *name() {
+    return "get_metadata_log_info";
+  }
+};
+
+class RGWOp_MDLog_ShardInfo : public RGWRESTOp {
+  RGWMetadataLogInfo info;
+public:
+  RGWOp_MDLog_ShardInfo() {}
+  ~RGWOp_MDLog_ShardInfo() {}
 
   int check_caps(RGWUserCaps& caps) {
     return caps.check_cap("mdlog", RGW_CAP_READ);
@@ -86,7 +107,7 @@ public:
   void execute();
   virtual void send_response();
   virtual const char *name() {
-    return "get_metadata_log_shards_info";
+    return "get_metadata_log_shard_info";
   }
 };
 
@@ -152,12 +173,31 @@ public:
   }
 };
 
-class RGWOp_DATALog_GetShardsInfo : public RGWRESTOp {
+class RGWOp_DATALog_Info : public RGWRESTOp {
   unsigned num_objects;
   int http_ret;
 public:
-  RGWOp_DATALog_GetShardsInfo() : num_objects(0), http_ret(0) {}
-  ~RGWOp_DATALog_GetShardsInfo() {}
+  RGWOp_DATALog_Info() : num_objects(0), http_ret(0) {}
+  ~RGWOp_DATALog_Info() {}
+
+  int check_caps(RGWUserCaps& caps) {
+    return caps.check_cap("datalog", RGW_CAP_READ);
+  }
+  int verify_permission() {
+    return check_caps(s->user.caps);
+  }
+  void execute();
+  virtual void send_response();
+  virtual const char *name() {
+    return "get_data_changes_log_info";
+  }
+};
+
+class RGWOp_DATALog_ShardInfo : public RGWRESTOp {
+  RGWDataChangesLogInfo info;
+public:
+  RGWOp_DATALog_ShardInfo() {}
+  ~RGWOp_DATALog_ShardInfo() {}
 
   int check_caps(RGWUserCaps& caps) {
     return caps.check_cap("datalog", RGW_CAP_READ);
@@ -168,7 +208,7 @@ public:
   void execute();
   virtual void send_response();
   virtual const char *name() {
-    return "get_data_changes_log_shards_info";
+    return "get_data_changes_log_shard_info";
   }
 };