// vim: ts=8 sw=2 smarttab
#include "include/types.h"
-#include "include/utime.h"
+
+#include "common/ceph_time.h"
+
#include "objclass/objclass.h"
#include "cls_log_types.h"
using std::string;
using ceph::bufferlist;
+using namespace std::literals;
CLS_VER(1,0)
CLS_NAME(log)
return 0;
}
-static void get_index_time_prefix(utime_t& ts, string& index)
+static void get_index_time_prefix(ceph::real_time ts, string& index)
{
+ auto tv = ceph::real_clock::to_timeval(ts);
char buf[32];
- snprintf(buf, sizeof(buf), "%010ld.%06ld_", (long)ts.sec(), (long)ts.usec());
+ snprintf(buf, sizeof(buf), "%010ld.%06ld_", (long)tv.tv_sec, (long)tv.tv_usec);
index = log_index_prefix + buf;
}
return 0;
}
-static void get_index(cls_method_context_t hctx, utime_t& ts, string& index)
+static void get_index(cls_method_context_t hctx, ceph::real_time ts, string& index)
{
get_index_time_prefix(ts, index);
string index;
- utime_t timestamp = entry.timestamp;
+ auto timestamp = entry.timestamp;
if (op.monotonic_inc && timestamp < header.max_time)
timestamp = header.max_time;
else if (timestamp > header.max_time)
} else {
from_index = op.marker;
}
- bool use_time_boundary = (!op.from_time.is_zero() && (op.to_time >= op.from_time));
+ bool use_time_boundary = (!ceph::real_clock::is_zero(op.from_time) && (op.to_time >= op.from_time));
if (use_time_boundary)
get_index_time_prefix(op.to_time, to_index);
-#define MAX_ENTRIES 1000
+ static constexpr auto MAX_ENTRIES = 1000u;
size_t max_entries = op.max_entries;
if (!max_entries || max_entries > MAX_ENTRIES)
max_entries = MAX_ENTRIES;
// cls_cxx_map_remove_range() expects one-past-end
if (op.to_marker.empty()) {
auto t = op.to_time;
- t.nsec_ref() += 1000; // equivalent to usec() += 1
- t.normalize();
+ t += 1000us; // equivalent to usec() += 1
get_index_time_prefix(t, to_index);
} else {
to_index = op.to_marker;
op.exec("log", "add", in);
}
-void cls_log_add_prepare_entry(cls_log_entry& entry, const utime_t& timestamp,
- const string& section, const string& name, bufferlist& bl)
+void cls_log_add_prepare_entry(cls_log_entry& entry, ceph::real_time timestamp,
+ const string& section, const string& name, bufferlist& bl)
{
entry.timestamp = timestamp;
entry.section = section;
entry.data = bl;
}
-void cls_log_add(librados::ObjectWriteOperation& op, const utime_t& timestamp,
+void cls_log_add(librados::ObjectWriteOperation& op, ceph::real_time timestamp,
const string& section, const string& name, bufferlist& bl)
{
cls_log_entry entry;
cls_log_add(op, entry);
}
-void cls_log_trim(librados::ObjectWriteOperation& op, const utime_t& from_time, const utime_t& to_time,
- const string& from_marker, const string& to_marker)
+void cls_log_trim(librados::ObjectWriteOperation& op, ceph::real_time from_time,
+ ceph::real_time to_time, const string& from_marker, const string& to_marker)
{
bufferlist in;
cls_log_trim_op call;
op.exec("log", "trim", in);
}
-int cls_log_trim(librados::IoCtx& io_ctx, const string& oid, const utime_t& from_time, const utime_t& to_time,
+int cls_log_trim(librados::IoCtx& io_ctx, const string& oid,
+ ceph::real_time from_time, ceph::real_time to_time,
const string& from_marker, const string& to_marker)
{
bool done = false;
}
};
-void cls_log_list(librados::ObjectReadOperation& op, const utime_t& from,
- const utime_t& to, const string& in_marker, int max_entries,
+void cls_log_list(librados::ObjectReadOperation& op, ceph::real_time from,
+ ceph::real_time to, const string& in_marker, int max_entries,
vector<cls_log_entry>& entries,
string *out_marker, bool *truncated)
{
* log objclass
*/
-void cls_log_add_prepare_entry(cls_log_entry& entry, const utime_t& timestamp,
- const std::string& section, const std::string& name, ceph::buffer::list& bl);
+void cls_log_add_prepare_entry(cls_log_entry& entry, ceph::real_time timestamp,
+ const std::string& section,
+ const std::string& name, ceph::buffer::list& bl);
void cls_log_add(librados::ObjectWriteOperation& op, std::vector<cls_log_entry>& entries, bool monotonic_inc);
void cls_log_add(librados::ObjectWriteOperation& op, cls_log_entry& entry);
-void cls_log_add(librados::ObjectWriteOperation& op, const utime_t& timestamp,
+void cls_log_add(librados::ObjectWriteOperation& op, ceph::real_time timestamp,
const std::string& section, const std::string& name, ceph::buffer::list& bl);
-void cls_log_list(librados::ObjectReadOperation& op, const utime_t& from,
- const utime_t& to, const std::string& in_marker,
+void cls_log_list(librados::ObjectReadOperation& op, ceph::real_time from,
+ ceph::real_time to, const std::string& in_marker,
int max_entries, std::vector<cls_log_entry>& entries,
std::string *out_marker, bool *truncated);
-void cls_log_trim(librados::ObjectWriteOperation& op, const utime_t& from_time, const utime_t& to_time,
- const std::string& from_marker, const std::string& to_marker);
+void cls_log_trim(librados::ObjectWriteOperation& op, ceph::real_time from_time,
+ ceph::real_time to_time, const std::string& from_marker,
+ const std::string& to_marker);
// these overloads which call io_ctx.operate() should not be called in the rgw.
// rgw_rados_operate() should be called after the overloads w/o calls to io_ctx.operate()
#ifndef CLS_CLIENT_HIDE_IOCTX
-int cls_log_trim(librados::IoCtx& io_ctx, const std::string& oid, const utime_t& from_time, const utime_t& to_time,
+int cls_log_trim(librados::IoCtx& io_ctx, const std::string& oid,
+ ceph::real_time from_time, ceph::real_time to_time,
const std::string& from_marker, const std::string& to_marker);
#endif
}
static void generate_test_instances(std::list<cls_log_add_op *>& l) {
+ using namespace std::literals;
l.push_back(new cls_log_add_op);
l.push_back(new cls_log_add_op);
l.back()->entries.push_back(cls_log_entry());
l.back()->entries.push_back(cls_log_entry());
l.back()->entries.back().section = "section";
l.back()->entries.back().name = "name";
- l.back()->entries.back().timestamp = utime_t(1, 2);
+ l.back()->entries.back().timestamp = ceph::real_time{1s + 2ns};
l.back()->entries.back().data.append("data");
l.back()->entries.back().id = "id";
}
WRITE_CLASS_ENCODER(cls_log_add_op)
struct cls_log_list_op {
- utime_t from_time;
+ ceph::real_time from_time;
std::string marker; /* if not empty, overrides from_time */
- utime_t to_time; /* not inclusive */
+ ceph::real_time to_time; /* not inclusive */
int max_entries; /* upperbound to returned num of entries
might return less than that and still be truncated */
* -ENODATA when done, so caller needs to repeat sending request until that.
*/
struct cls_log_trim_op {
- utime_t from_time;
- utime_t to_time; /* inclusive */
+ ceph::real_time from_time;
+ ceph::real_time to_time; /* inclusive */
std::string from_marker;
std::string to_marker;
#include "include/buffer.h"
#include "include/encoding.h"
#include "include/types.h"
-#include "include/utime.h"
#include "common/ceph_json.h"
#include "common/Formatter.h"
+#include "common/ceph_time.h"
+
class JSONObj;
class JSONDecoder;
std::string id;
std::string section;
std::string name;
- utime_t timestamp;
+ ceph::real_time timestamp;
ceph::buffer::list data;
cls_log_entry() = default;
cls_log_entry(ceph::real_time timestamp, std::string section,
std::string name, ceph::buffer::list&& data)
: section(std::move(section)), name(std::move(name)),
- timestamp(utime_t(timestamp)), data(std::move(data)) {}
-
- cls_log_entry(utime_t timestamp, std::string section,
- std::string name, ceph::buffer::list&& data)
- : section(std::move(section)), name(std::move(name)), timestamp(timestamp),
- data(std::move(data)) {}
+ timestamp(timestamp), data(std::move(data)) {}
void encode(ceph::buffer::list& bl) const {
ENCODE_START(2, 1, bl);
l.back()->id = "test_id";
l.back()->section = "test_section";
l.back()->name = "test_name";
- l.back()->timestamp = utime_t();
+ l.back()->timestamp = ceph::real_time{};
ceph::buffer::list bl;
ceph::encode(std::string("Test"), bl, 0);
l.back()->data = bl;
struct cls_log_header {
std::string max_marker;
- utime_t max_time;
+ ceph::real_time max_time;
void encode(ceph::buffer::list& bl) const {
ENCODE_START(1, 1, bl);
}
cls_log_entry e;
- cls_log_add_prepare_entry(e, utime_t(ut), {}, key, entry);
+ cls_log_add_prepare_entry(e, ut, {}, key, entry);
std::get<centries>(out).push_back(std::move(e));
}
int push(const DoutPrefixProvider *dpp, int index, entries&& items, optional_yield y) override {
const std::string& key, ceph::buffer::list&& bl,
optional_yield y) override {
lr::ObjectWriteOperation op;
- cls_log_add(op, utime_t(now), {}, key, bl);
+ cls_log_add(op, now, {}, key, bl);
auto r = rgw_rados_operate(dpp, ioctx, oids[index], &op, y);
if (r < 0) {
ldpp_dout(dpp, -1) << __PRETTY_FUNCTION__
for (auto iter = log_entries.begin(); iter != log_entries.end(); ++iter) {
rgw_data_change_log_entry log_entry;
log_entry.log_id = iter->id;
- auto rt = iter->timestamp.to_real_time();
+ auto rt = iter->timestamp;
log_entry.log_timestamp = rt;
auto liter = iter->data.cbegin();
try {
<< cpp_strerror(-r) << dendl;
} else {
info->marker = header.max_marker;
- info->last_update = header.max_time.to_real_time();
+ info->last_update = header.max_time;
}
return r;
}
return ret;
info->marker = header.max_marker;
- info->last_update = header.max_time.to_real_time();
+ info->last_update = header.max_time;
return 0;
}
continue;
}
tn->log(20, SSTR("log_entry: " << log_iter->id << ":" << log_iter->section << ":" << log_iter->name << ":" << log_iter->timestamp));
- if (!marker_tracker->start(log_iter->id, 0, log_iter->timestamp.to_real_time())) {
+ if (!marker_tracker->start(log_iter->id, 0, log_iter->timestamp)) {
ldpp_dout(sync_env->dpp, 0) << "ERROR: cannot start syncing " << log_iter->id << ". Duplicate entry?" << dendl;
} else {
raw_key = log_iter->section + ":" + log_iter->name;
}
} else {
shard_info.marker = header.max_marker;
- shard_info.last_update = header.max_time.to_real_time();
+ shard_info.last_update = header.max_time;
}
// wake up parent stack
io_complete();
dest_entry.id = entry.id;
dest_entry.section = entry.section;
dest_entry.name = entry.name;
- dest_entry.timestamp = utime_t(entry.timestamp);
+ dest_entry.timestamp = entry.timestamp;
encode(entry.log_data, dest_entry.data);
id = le.id;
section = le.section;
name = le.name;
- timestamp = le.timestamp.to_real_time();
+ timestamp = le.timestamp;
try {
auto iter = le.data.cbegin();
decode(log_data, iter);
f->dump_string("id", entry.id);
f->dump_string("section", entry.section);
f->dump_string("name", entry.name);
- entry.timestamp.gmtime_nsec(f->dump_stream("timestamp"));
+ utime_t ts(entry.timestamp);
+ ts.gmtime_nsec(f->dump_stream("timestamp"));
try {
RGWMetadataLogData log_data;
const string& key,
bufferlist& bl)
{
- cls_log_add_prepare_entry(entry, utime_t(ut), section, key, bl);
+ cls_log_add_prepare_entry(entry, ut, section, key, bl);
}
int RGWSI_Cls::TimeLog::init_obj(const DoutPrefixProvider *dpp, const string& oid, RGWSI_RADOS::Obj& obj)
}
librados::ObjectWriteOperation op;
- utime_t t(ut);
- cls_log_add(op, t, section, key, bl);
+ cls_log_add(op, ut, section, key, bl);
return obj.operate(dpp, &op, y);
}
librados::ObjectReadOperation op;
- utime_t st(start_time);
- utime_t et(end_time);
-
- cls_log_list(op, st, et, marker, max_entries, entries,
+ cls_log_list(op, start_time, end_time, marker, max_entries, entries,
out_marker, truncated);
bufferlist obl;
return r;
}
- utime_t st(start_time);
- utime_t et(end_time);
-
librados::ObjectWriteOperation op;
- cls_log_trim(op, st, et, from_marker, to_marker);
+ cls_log_trim(op, start_time, end_time, from_marker, to_marker);
if (!completion) {
r = obj.operate(dpp, &op, y);
#include "cls/log/cls_log_types.h"
#include "cls/log/cls_log_client.h"
-#include "include/utime.h"
-#include "common/Clock.h"
+#include "common/ceph_time.h"
#include "global/global_context.h"
#include "gtest/gtest.h"
#include <vector>
using namespace std;
+using namespace std::literals;
+
+using ceph::real_time;
+using ceph::real_clock;
/// creates a temporary pool and initializes an IoCtx for each test
class cls_log : public ::testing::Test {
return 0;
}
-void add_log(librados::ObjectWriteOperation *op, utime_t& timestamp, string& section, string&name, int i)
+void add_log(librados::ObjectWriteOperation *op, real_time timestamp, string& section, string&name, int i)
{
bufferlist bl;
encode(i, bl);
return name_prefix + buf;
}
-void generate_log(librados::IoCtx& ioctx, string& oid, int max, utime_t& start_time, bool modify_time)
+void generate_log(librados::IoCtx& ioctx, string& oid, int max, real_time start_time, bool modify_time)
{
string section = "global";
int i;
for (i = 0; i < max; i++) {
- uint32_t secs = start_time.sec();
+ auto ts = start_time;
if (modify_time)
- secs += i;
+ ts += i * 1s;
- utime_t ts(secs, start_time.nsec());
string name = get_name(i);
add_log(&op, ts, section, name, i);
ASSERT_EQ(0, ioctx.operate(oid, &op));
}
-utime_t get_time(utime_t& start_time, int i, bool modify_time)
+real_time get_time(real_time start_time, int i, bool modify_time)
{
- uint32_t secs = start_time.sec();
- if (modify_time)
- secs += i;
- return utime_t(secs, start_time.nsec());
+ return modify_time ? start_time + (i * 1s) : start_time;
}
-void check_entry(cls_log_entry& entry, utime_t& start_time, int i, bool modified_time)
+void check_entry(cls_log_entry& entry, real_time start_time, int i, bool modified_time)
{
string section = "global";
string name = get_name(i);
- utime_t ts = get_time(start_time, i, modified_time);
+ auto ts = get_time(start_time, i, modified_time);
ASSERT_EQ(section, entry.section);
ASSERT_EQ(name, entry.name);
}
static int log_list(librados::IoCtx& ioctx, const std::string& oid,
- utime_t& from, utime_t& to,
+ real_time from, real_time to,
const string& in_marker, int max_entries,
vector<cls_log_entry>& entries,
string *out_marker, bool *truncated)
}
static int log_list(librados::IoCtx& ioctx, const std::string& oid,
- utime_t& from, utime_t& to, int max_entries,
+ real_time from, real_time to, int max_entries,
vector<cls_log_entry>& entries, bool *truncated)
{
std::string marker;
static int log_list(librados::IoCtx& ioctx, const std::string& oid,
vector<cls_log_entry>& entries)
{
- utime_t from, to;
+ real_time from, to;
bool truncated{false};
return log_list(ioctx, oid, from, to, 0, entries, &truncated);
}
ASSERT_EQ(0, ioctx.create(oid, true));
/* generate log */
- utime_t start_time = ceph_clock_now();
- utime_t to_time = get_time(start_time, 1, true);
+ auto start_time = real_clock::now();
+ auto to_time = get_time(start_time, 1, true);
generate_log(ioctx, oid, 10, start_time, false);
vector<cls_log_entry> entries;
ASSERT_EQ(0, ioctx.create(oid, true));
/* generate log */
- utime_t start_time = ceph_clock_now();
+ auto start_time = real_clock::now();
generate_log(ioctx, oid, 10, start_time, true);
vector<cls_log_entry> entries;
bool truncated;
- utime_t to_time = utime_t(start_time.sec() + 10, start_time.nsec());
+ auto to_time = start_time + (10 * 1s);
{
/* check list */
/* check list again with shifted time */
{
- utime_t next_time = get_time(start_time, 1, true);
+ auto next_time = get_time(start_time, 1, true);
ASSERT_EQ(0, log_list(ioctx, oid, next_time, to_time, 0,
entries, &truncated));
ASSERT_EQ(9u, entries.size());
}
int do_log_trim(librados::IoCtx& ioctx, const std::string& oid,
- const utime_t& from_time, const utime_t& to_time)
+ real_time from_time, real_time to_time)
{
librados::ObjectWriteOperation op;
cls_log_trim(op, from_time, to_time, "", "");
ASSERT_EQ(0, ioctx.create(oid, true));
/* generate log */
- utime_t start_time = ceph_clock_now();
+ auto start_time = real_clock::now();
generate_log(ioctx, oid, 10, start_time, true);
vector<cls_log_entry> entries;
/* check list */
/* trim */
- utime_t to_time = get_time(start_time, 10, true);
+ auto to_time = get_time(start_time, 10, true);
for (int i = 0; i < 10; i++) {
- utime_t trim_time = get_time(start_time, i, true);
+ auto trim_time = get_time(start_time, i, true);
- utime_t zero_time;
+ real_time zero_time;
ASSERT_EQ(0, do_log_trim(ioctx, oid, zero_time, trim_time));
ASSERT_EQ(-ENODATA, do_log_trim(ioctx, oid, zero_time, trim_time));
string oid = "obj";
ASSERT_EQ(0, ioctx.create(oid, true));
- utime_t start_time = ceph_clock_now();
+ auto start_time = real_clock::now();
generate_log(ioctx, oid, 10, start_time, true);
- utime_t zero_time;
std::vector<cls_log_entry> log1;
{
vector<cls_log_entry> entries;
lr::ObjectWriteOperation op;
cb::list bl;
encode(i, bl);
- cls_log_add(op, ceph_clock_now(), {}, "meow", bl);
+ cls_log_add(op, ceph::real_clock::now(), {}, "meow", bl);
auto r = rgw_rados_operate(&dp, ioctx, get_oid(0, i), &op, null_yield);
ASSERT_GE(r, 0);
}
lr::ObjectWriteOperation op;
cb::list bl;
encode(i, bl);
- cls_log_add(op, ceph_clock_now(), {}, "meow", bl);
+ cls_log_add(op, ceph::real_clock::now(), {}, "meow", bl);
auto r = rgw_rados_operate(&dp, ioctx, get_oid(0, i), &op, null_yield);
ASSERT_GE(r, 0);
}