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)
};
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;
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);
}
#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"
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);
+}
+
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)
{
#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;
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);
};
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)
{
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);
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);
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"),
}
-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);
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;
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;
if (s->info.args.exists("id")) {
return new RGWOp_DATALog_List;
} else {
- return new RGWOp_DATALog_GetShardsInfo;
+ return new RGWOp_DATALog_Info;
}
}
return NULL;
#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;
}
};
-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);
void execute();
virtual void send_response();
virtual const char *name() {
- return "get_metadata_log_shards_info";
+ return "get_metadata_log_shard_info";
}
};
}
};
-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);
void execute();
virtual void send_response();
virtual const char *name() {
- return "get_data_changes_log_shards_info";
+ return "get_data_changes_log_shard_info";
}
};