Skip to content

Commit

Permalink
Merge pull request #8108 from yehudasa/wip-rgw-highres-3
Browse files Browse the repository at this point in the history
Wip rgw highres 3
  • Loading branch information
mattbenjamin committed Mar 15, 2016
2 parents 8d10fdf + 1c5e225 commit cd45105
Show file tree
Hide file tree
Showing 56 changed files with 963 additions and 712 deletions.
62 changes: 37 additions & 25 deletions src/cls/rgw/cls_rgw.cc
Expand Up @@ -9,7 +9,7 @@
#include <stdlib.h>
#include <errno.h>

#include "include/utime.h"
#include "common/ceph_time.h"
#include "objclass/objclass.h"
#include "cls/rgw/cls_rgw_ops.h"
#include "common/Clock.h"
Expand Down Expand Up @@ -114,10 +114,11 @@ static bool bi_entry_gt(const string& first, const string& second)
return first > second;
}

static void get_time_key(utime_t& ut, string *key)
static void get_time_key(real_time& ut, string *key)
{
char buf[32];
snprintf(buf, 32, "%011llu.%09u", (unsigned long long)ut.sec(), ut.nsec());
ceph_timespec ts = ceph::real_clock::to_ceph_timespec(ut);
snprintf(buf, 32, "%011llu.%09u", (unsigned long long)ts.tv_sec, (unsigned int)ts.tv_nsec);
*key = buf;
}

Expand All @@ -140,7 +141,7 @@ static void bi_log_index_key(cls_method_context_t hctx, string& key, string& id,
}

static int log_index_operation(cls_method_context_t hctx, cls_rgw_obj_key& obj_key, RGWModifyOp op,
string& tag, utime_t& timestamp,
string& tag, real_time& timestamp,
rgw_bucket_entry_ver& ver, RGWPendingState state, uint64_t index_ver,
string& max_marker, uint16_t bilog_flags, string *owner, string *owner_display_name)
{
Expand Down Expand Up @@ -678,7 +679,7 @@ int rgw_bucket_prepare_op(cls_method_context_t hctx, bufferlist *in, bufferlist

// fill in proper state
struct rgw_bucket_pending_info info;
info.timestamp = ceph_clock_now(g_ceph_context);
info.timestamp = real_clock::now();
info.state = CLS_RGW_STATE_PENDING_MODIFY;
info.op = op.op;
entry.pending_map.insert(pair<string, rgw_bucket_pending_info>(op.tag, info));
Expand Down Expand Up @@ -1183,7 +1184,7 @@ class BIVerObjEntry {
return 0;
}

time_t mtime() {
real_time mtime() {
return instance_entry.meta.mtime;
}
};
Expand Down Expand Up @@ -1389,8 +1390,14 @@ static int rgw_bucket_link_olh(cls_method_context_t hctx, bufferlist *in, buffer
return ret;
}

if (existed && op.unmod_since > 0) {
if (obj.mtime() >= op.unmod_since) {
if (existed && !real_clock::is_zero(op.unmod_since)) {
struct timespec mtime = ceph::real_clock::to_timespec(obj.mtime);
struct timespec unmod = ceph::real_clock::to_timespec(op.unmod_since);
if (!op.high_precision_time) {
mtime.tv_nsec = 0;
unmod.tv_nsec = 0;
}
if (mtime >= unmod) {
return 0; /* no need to set error, we just return 0 and avoid writing to the bi log */
}
}
Expand Down Expand Up @@ -1654,7 +1661,7 @@ static int rgw_bucket_unlink_instance(cls_method_context_t hctx, bufferlist *in,
rgw_bucket_entry_ver ver;
ver.epoch = (op.olh_epoch ? op.olh_epoch : olh.get_epoch());

utime_t mtime = ceph_clock_now(g_ceph_context); /* mtime has no real meaning in instance removal context */
real_time mtime = real_clock::now(); /* mtime has no real meaning in instance removal context */
ret = log_index_operation(hctx, op.key, CLS_RGW_OP_UNLINK_INSTANCE, op.op_tag,
mtime, ver,
CLS_RGW_STATE_COMPLETE, header.ver, header.max_marker,
Expand Down Expand Up @@ -1842,15 +1849,14 @@ int rgw_dir_suggest_changes(cls_method_context_t hctx, bufferlist *in, bufferlis
bufferlist header_bl;
struct rgw_bucket_dir_header header;
bool header_changed = false;
uint64_t tag_timeout;

int rc = read_bucket_header(hctx, &header);
if (rc < 0) {
CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to read header\n");
return rc;
}

tag_timeout = (header.tag_timeout ? header.tag_timeout : CEPH_RGW_TAG_TIMEOUT);
timespan tag_timeout(header.tag_timeout ? header.tag_timeout : CEPH_RGW_TAG_TIMEOUT);

bufferlist::iterator in_iter = in->begin();

Expand Down Expand Up @@ -1882,7 +1888,7 @@ int rgw_dir_suggest_changes(cls_method_context_t hctx, bufferlist *in, bufferlis
return -EINVAL;
}

utime_t cur_time = ceph_clock_now(g_ceph_context);
real_time cur_time = real_clock::now();
map<string, struct rgw_bucket_pending_info>::iterator iter =
cur_disk.pending_map.begin();
while(iter != cur_disk.pending_map.end()) {
Expand Down Expand Up @@ -2091,8 +2097,8 @@ static int rgw_obj_check_mtime(cls_method_context_t hctx, bufferlist *in, buffer
return -EINVAL;
}

time_t mtime;
int ret = cls_cxx_stat(hctx, NULL, &mtime);
real_time obj_ut;
int ret = cls_cxx_stat2(hctx, NULL, &obj_ut);
if (ret < 0 && ret != -ENOENT) {
CLS_LOG(0, "ERROR: %s(): cls_cxx_stat() returned %d", __func__, ret);
return ret;
Expand All @@ -2101,29 +2107,35 @@ static int rgw_obj_check_mtime(cls_method_context_t hctx, bufferlist *in, buffer
CLS_LOG(10, "object does not exist, skipping check");
}

utime_t obj_ut(mtime, 0);
ceph_timespec obj_ts = ceph::real_clock::to_ceph_timespec(obj_ut);
ceph_timespec op_ts = ceph::real_clock::to_ceph_timespec(op.mtime);

if (!op.high_precision_time) {
obj_ts.tv_nsec = 0;
op_ts.tv_nsec = 0;
}

CLS_LOG(10, "%s: obj_ut=%lld.%06lld op.mtime=%lld.%06lld", __func__,
(long long)obj_ut.sec(), (long long)obj_ut.nsec(),
(long long)op.mtime.sec(), (long long)op.mtime.nsec());
(long long)obj_ts.tv_sec, (long long)obj_ts.tv_nsec,
(long long)op_ts.tv_sec, (long long)op_ts.tv_nsec);

bool check;

switch (op.type) {
case CLS_RGW_CHECK_TIME_MTIME_EQ:
check = (obj_ut == op.mtime);
check = (obj_ts == op_ts);
break;
case CLS_RGW_CHECK_TIME_MTIME_LT:
check = (obj_ut < op.mtime);
check = (obj_ts < op_ts);
break;
case CLS_RGW_CHECK_TIME_MTIME_LE:
check = (obj_ut <= op.mtime);
check = (obj_ts <= op_ts);
break;
case CLS_RGW_CHECK_TIME_MTIME_GT:
check = (obj_ut > op.mtime);
check = (obj_ts > op_ts);
break;
case CLS_RGW_CHECK_TIME_MTIME_GE:
check = (obj_ut >= op.mtime);
check = (obj_ts >= op_ts);
break;
default:
return -EINVAL;
Expand Down Expand Up @@ -2931,8 +2943,8 @@ static int gc_update_entry(cls_method_context_t hctx, uint32_t expiration_secs,
return ret;
}
}
info.time = ceph_clock_now(g_ceph_context);
info.time += expiration_secs;
info.time = ceph::real_clock::now();
info.time += timespan(expiration_secs);
ret = gc_omap_set(hctx, GC_OBJ_NAME_INDEX, info.tag, &info);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -3027,7 +3039,7 @@ static int gc_iterate_entries(cls_method_context_t hctx, const string& marker, b
}

if (expired_only) {
utime_t now = ceph_clock_now(g_ceph_context);
real_time now = ceph::real_clock::now();
string now_str;
get_time_key(now, &now_str);
prepend_index_prefix(now_str, GC_OBJ_TIME_INDEX, &end_key);
Expand Down
6 changes: 4 additions & 2 deletions src/cls/rgw/cls_rgw_client.cc
Expand Up @@ -227,11 +227,12 @@ void cls_rgw_obj_check_attrs_prefix(librados::ObjectOperation& o, const string&
o.exec("rgw", "obj_check_attrs_prefix", in);
}

void cls_rgw_obj_check_mtime(librados::ObjectOperation& o, const utime_t& mtime, RGWCheckMTimeType type)
void cls_rgw_obj_check_mtime(librados::ObjectOperation& o, const real_time& mtime, bool high_precision_time, RGWCheckMTimeType type)
{
bufferlist in;
struct rgw_cls_obj_check_mtime call;
call.mtime = mtime;
call.high_precision_time = high_precision_time;
call.type = type;
::encode(call, in);
o.exec("rgw", "obj_check_mtime", in);
Expand Down Expand Up @@ -306,7 +307,7 @@ int cls_rgw_bi_list(librados::IoCtx& io_ctx, const string oid,

int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_obj_key& key, bufferlist& olh_tag,
bool delete_marker, const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
uint64_t olh_epoch, time_t unmod_since, bool log_op)
uint64_t olh_epoch, ceph::real_time unmod_since, bool high_precision_time, bool log_op)
{
bufferlist in, out;
struct rgw_cls_link_olh_op call;
Expand All @@ -320,6 +321,7 @@ int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cl
call.olh_epoch = olh_epoch;
call.log_op = log_op;
call.unmod_since = unmod_since;
call.high_precision_time = high_precision_time;
::encode(call, in);
int r = io_ctx.exec(oid, "rgw", "bucket_link_olh", in, out);
if (r < 0)
Expand Down
5 changes: 3 additions & 2 deletions src/cls/rgw/cls_rgw_client.h
Expand Up @@ -8,6 +8,7 @@
#include "cls_rgw_ops.h"
#include "common/RefCountedObj.h"
#include "include/compat.h"
#include "common/ceph_time.h"

// Forward declaration
class BucketIndexAioManager;
Expand Down Expand Up @@ -317,7 +318,7 @@ void cls_rgw_bucket_complete_op(librados::ObjectWriteOperation& o, RGWModifyOp o
void cls_rgw_remove_obj(librados::ObjectWriteOperation& o, list<string>& keep_attr_prefixes);
void cls_rgw_obj_store_pg_ver(librados::ObjectWriteOperation& o, const string& attr);
void cls_rgw_obj_check_attrs_prefix(librados::ObjectOperation& o, const string& prefix, bool fail_if_exist);
void cls_rgw_obj_check_mtime(librados::ObjectOperation& o, const utime_t& mtime, RGWCheckMTimeType type);
void cls_rgw_obj_check_mtime(librados::ObjectOperation& o, const ceph::real_time& mtime, bool high_precision_time, RGWCheckMTimeType type);

int cls_rgw_bi_get(librados::IoCtx& io_ctx, const string oid,
BIIndexType index_type, cls_rgw_obj_key& key,
Expand All @@ -330,7 +331,7 @@ int cls_rgw_bi_list(librados::IoCtx& io_ctx, const string oid,

int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_obj_key& key, bufferlist& olh_tag,
bool delete_marker, const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
uint64_t olh_epoch, time_t unmod_since, bool log_op);
uint64_t olh_epoch, ceph::real_time unmod_since, bool high_precision_time, bool log_op);
int cls_rgw_bucket_unlink_instance(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_obj_key& key, const string& op_tag,
uint64_t olh_epoch, bool log_op);
int cls_rgw_get_olh_log(librados::IoCtx& io_ctx, string& oid, librados::ObjectReadOperation& op, const cls_rgw_obj_key& olh, uint64_t ver_marker,
Expand Down
5 changes: 4 additions & 1 deletion src/cls/rgw/cls_rgw_ops.cc
Expand Up @@ -3,6 +3,7 @@

#include "common/Formatter.h"
#include "common/ceph_json.h"
#include "include/utime.h"

void rgw_cls_tag_timeout_op::dump(Formatter *f) const
{
Expand Down Expand Up @@ -175,7 +176,9 @@ void rgw_cls_link_olh_op::dump(Formatter *f) const
::encode_json("olh_epoch", olh_epoch, f);
::encode_json("log_op", log_op, f);
::encode_json("bilog_flags", (uint32_t)bilog_flags, f);
::encode_json("unmod_since", unmod_since, f);
utime_t ut(unmod_since);
::encode_json("unmod_since", ut, f);
::encode_json("high_precision_time", high_precision_time, f);
}

void rgw_cls_unlink_instance_op::generate_test_instances(list<rgw_cls_unlink_instance_op*>& o)
Expand Down
36 changes: 27 additions & 9 deletions src/cls/rgw/cls_rgw_ops.h
Expand Up @@ -4,6 +4,7 @@
#include <map>

#include "include/types.h"
#include "common/ceph_time.h"
#include "cls/rgw/cls_rgw_types.h"

struct rgw_cls_tag_timeout_op
Expand Down Expand Up @@ -164,12 +165,13 @@ struct rgw_cls_link_olh_op {
uint64_t olh_epoch;
bool log_op;
uint16_t bilog_flags;
uint64_t unmod_since; /* only create delete marker if newer then this */
real_time unmod_since; /* only create delete marker if newer then this */
bool high_precision_time;

rgw_cls_link_olh_op() : delete_marker(false), olh_epoch(0), log_op(false), bilog_flags(0) {}
rgw_cls_link_olh_op() : delete_marker(false), olh_epoch(0), log_op(false), bilog_flags(0), high_precision_time(false) {}

void encode(bufferlist& bl) const {
ENCODE_START(2, 1, bl);
ENCODE_START(4, 1, bl);
::encode(key, bl);
::encode(olh_tag, bl);
::encode(delete_marker, bl);
Expand All @@ -178,12 +180,15 @@ struct rgw_cls_link_olh_op {
::encode(olh_epoch, bl);
::encode(log_op, bl);
::encode(bilog_flags, bl);
time_t t = ceph::real_clock::to_time_t(unmod_since);
::encode(t, bl);
::encode(unmod_since, bl);
::encode(high_precision_time, bl);
ENCODE_FINISH(bl);
}

void decode(bufferlist::iterator& bl) {
DECODE_START(2, bl);
DECODE_START(4, bl);
::decode(key, bl);
::decode(olh_tag, bl);
::decode(delete_marker, bl);
Expand All @@ -192,9 +197,17 @@ struct rgw_cls_link_olh_op {
::decode(olh_epoch, bl);
::decode(log_op, bl);
::decode(bilog_flags, bl);
if (struct_v >= 2) {
if (struct_v == 2) {
time_t t;
::decode(t, bl);
unmod_since = ceph::real_clock::from_time_t(t);
}
if (struct_v >= 3) {
::decode(unmod_since, bl);
}
if (struct_v >= 4) {
::decode(high_precision_time, bl);
}
DECODE_FINISH(bl);
}

Expand Down Expand Up @@ -482,24 +495,29 @@ struct rgw_cls_obj_check_attrs_prefix {
WRITE_CLASS_ENCODER(rgw_cls_obj_check_attrs_prefix)

struct rgw_cls_obj_check_mtime {
utime_t mtime;
ceph::real_time mtime;
RGWCheckMTimeType type;
bool high_precision_time;

rgw_cls_obj_check_mtime() : type(CLS_RGW_CHECK_TIME_MTIME_EQ) {}
rgw_cls_obj_check_mtime() : type(CLS_RGW_CHECK_TIME_MTIME_EQ), high_precision_time(false) {}

void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
ENCODE_START(2, 1, bl);
::encode(mtime, bl);
::encode((uint8_t)type, bl);
::encode(high_precision_time, bl);
ENCODE_FINISH(bl);
}

void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
DECODE_START(2, bl);
::decode(mtime, bl);
uint8_t c;
::decode(c, bl);
type = (RGWCheckMTimeType)c;
if (struct_v >= 2) {
::decode(high_precision_time, bl);
}
DECODE_FINISH(bl);
}
};
Expand Down

0 comments on commit cd45105

Please sign in to comment.