Skip to content

Commit

Permalink
rgw/lc: [non-functional change] use const expr to represent seconds i…
Browse files Browse the repository at this point in the history
…n a day

Signed-off-by: Oguzhan Ozmen <oozmen@bloomberg.net>
  • Loading branch information
BBoozmen committed Nov 23, 2023
1 parent 2446c01 commit b3afae9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/rgw/rgw_lc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw

constexpr int32_t hours_in_a_day = 24;
constexpr int32_t secs_in_a_day = hours_in_a_day * 60 * 60;

using namespace std;

const char* LC_STATUS[] = {
Expand Down Expand Up @@ -289,7 +292,7 @@ static bool obj_has_expired(const DoutPrefixProvider *dpp, CephContext *cct, cep
utime_t base_time;
if (cct->_conf->rgw_lc_debug_interval <= 0) {
/* Normal case, run properly */
cmp = double(days)*24*60*60;
cmp = double(days) * secs_in_a_day;
base_time = ceph_clock_now().round_to_day();
} else {
/* We're in debug mode; Treat each rgw_lc_debug_interval seconds as a day */
Expand Down Expand Up @@ -1944,8 +1947,7 @@ bool RGWLC::expired_session(time_t started)
}

time_t interval = (cct->_conf->rgw_lc_debug_interval > 0)
? cct->_conf->rgw_lc_debug_interval
: 24*60*60;
? cct->_conf->rgw_lc_debug_interval : secs_in_a_day;

auto now = time(nullptr);

Expand All @@ -1961,8 +1963,7 @@ bool RGWLC::expired_session(time_t started)
time_t RGWLC::thread_stop_at()
{
uint64_t interval = (cct->_conf->rgw_lc_debug_interval > 0)
? cct->_conf->rgw_lc_debug_interval
: 24*60*60;
? cct->_conf->rgw_lc_debug_interval : secs_in_a_day;

return time(nullptr) + interval;
}
Expand Down Expand Up @@ -2053,7 +2054,7 @@ static inline bool allow_shard_rollover(CephContext* cct, time_t now, time_t sha
* - the current shard has not rolled over in the last 24 hours
*/
if (((shard_rollover_date < now) &&
(now - shard_rollover_date > 24*60*60)) ||
(now - shard_rollover_date > secs_in_a_day)) ||
(! shard_rollover_date /* no rollover date stored */) ||
(cct->_conf->rgw_lc_debug_interval > 0 /* defaults to -1 == disabled */)) {
return true;
Expand All @@ -2079,7 +2080,7 @@ static inline bool already_run_today(CephContext* cct, time_t start_date)
bdt.tm_min = 0;
bdt.tm_sec = 0;
begin_of_day = mktime(&bdt);
if (now - begin_of_day < 24*60*60)
if (now - begin_of_day < secs_in_a_day)
return true;
else
return false;
Expand Down Expand Up @@ -2465,7 +2466,7 @@ int RGWLC::LCWorker::schedule_next_start_time(utime_t &start, utime_t& now)
nt = mktime(&bdt);
secs = nt - tt;

return secs>0 ? secs : secs+24*60*60;
return secs > 0 ? secs : secs + secs_in_a_day;
}

RGWLC::LCWorker::~LCWorker()
Expand Down Expand Up @@ -2756,7 +2757,7 @@ std::string s3_expiration_header(
if (rule_expiration.has_days()) {
rule_expiration_date =
boost::optional<ceph::real_time>(
mtime + make_timespan(double(rule_expiration.get_days())*24*60*60 - ceph::real_clock::to_time_t(mtime)%(24*60*60) + 24*60*60));
mtime + make_timespan(double(rule_expiration.get_days()) * secs_in_a_day - ceph::real_clock::to_time_t(mtime)%(secs_in_a_day) + secs_in_a_day));
}
}

Expand Down Expand Up @@ -2835,7 +2836,7 @@ bool s3_multipart_abort_header(
std::optional<ceph::real_time> rule_abort_date;
if (mp_expiration.has_days()) {
rule_abort_date = std::optional<ceph::real_time>(
mtime + make_timespan(mp_expiration.get_days()*24*60*60 - ceph::real_clock::to_time_t(mtime)%(24*60*60) + 24*60*60));
mtime + make_timespan(mp_expiration.get_days() * secs_in_a_day - ceph::real_clock::to_time_t(mtime)%(secs_in_a_day) + secs_in_a_day));
}

// update earliest abort date
Expand Down

0 comments on commit b3afae9

Please sign in to comment.