From: Oguzhan Ozmen Date: Wed, 22 Nov 2023 20:37:00 +0000 (-0500) Subject: rgw/lc: adjust timing if the configured end work-time is less than the start-time X-Git-Tag: v18.2.4~211^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0dda6d05df5f631cd2cdbb78363afa7b010d7779;p=ceph.git rgw/lc: adjust timing if the configured end work-time is less than the start-time LC work time is given in the form of "HH:MM-HH:MM"; the first part represents the "start_time" and the next "end_time". "should_work" function decides, given the current time, whether the LC worker can resume. It essentially checks whether the current time is within start and end times. Since there's no "date" (month/day/year) notion taken into account, a work time whose end_time (i.e., hour field) is less than start_time is not properly handled by "should_work". For example, "14:00-13:59" would normally mean to start LC processing at 2PM local time and allowing it to run for 24 hours. So, given such a work time range, "should_work" must return true for any given current_time. However, without this adjustment, it always returns false. The fix simply adds a "next day" adjustment if the end_time is configured to be less than the configured start_time. Fixes https://tracker.ceph.com/issues/63613 Signed-off-by: Oguzhan Ozmen (cherry picked from commit 48e189fe0ec6c0ace23ddaed09ef3f936e8c2a6f) --- diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index d7d72c87bdaba..b9003c2b94227 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -2347,6 +2347,12 @@ bool RGWLC::LCWorker::should_work(utime_t& now) time_t tt = now.sec(); localtime_r(&tt, &bdt); + // next-day adjustment if the configured end_hour is less than start_hour + if (end_hour < start_hour) { + bdt.tm_hour = bdt.tm_hour > end_hour ? bdt.tm_hour : bdt.tm_hour + hours_in_a_day; + end_hour += hours_in_a_day; + } + if (cct->_conf->rgw_lc_debug_interval > 0) { /* We're debugging, so say we can run */ return true; diff --git a/src/test/rgw/test_rgw_lc.cc b/src/test/rgw/test_rgw_lc.cc index 2943094c6d016..d10b482cbfcec 100644 --- a/src/test/rgw/test_rgw_lc.cc +++ b/src/test/rgw/test_rgw_lc.cc @@ -235,13 +235,13 @@ TEST_F(LCWorkTimeTests, ShouldWorkCustomWorkTimeEndTimeInTheNextDay) std::unordered_map test_values_to_expectations = { {"01/01/23 13:59:00", false}, {"01/01/23 13:59:59", false}, - {"01/01/24 14:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 17:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 23:59:59", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 00:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 00:59:59", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 01:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 01:00:59", false}, // should have been true, expected to fail due to tracker issue #63613 + {"01/01/24 14:00:00", true}, // used-to-fail + {"01/01/24 17:00:00", true}, // used-to-fail + {"01/01/24 23:59:59", true}, // used-to-fail + {"01/01/23 00:00:00", true}, // used-to-fail + {"01/01/23 00:59:59", true}, // used-to-fail + {"01/01/23 01:00:00", true}, // used-to-fail + {"01/01/23 01:00:59", true}, // used-to-fail {"01/01/23 01:01:00", false}, {"01/01/23 05:00:00", false}, {"01/01/23 12:00:00", false}, @@ -255,21 +255,22 @@ TEST_F(LCWorkTimeTests, ShouldWorkCustomWorkTimeEndTimeInTheNextDay24Hours) { cct->_conf->rgw_lifecycle_work_time = "14:00-13:59"; + // all of the below cases used-to-fail std::unordered_map test_values_to_expectations = { - {"01/01/23 00:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 00:00:01", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 00:01:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 01:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 12:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 13:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 13:59:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 13:59:59", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 14:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 14:00:01", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 14:01:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 16:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 23:59:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 23:59:59", false}, // should have been true, expected to fail due to tracker issue #63613 + {"01/01/23 00:00:00", true}, + {"01/01/23 00:00:01", true}, + {"01/01/23 00:01:00", true}, + {"01/01/24 01:00:00", true}, + {"01/01/24 12:00:00", true}, + {"01/01/24 13:00:00", true}, + {"01/01/24 13:59:00", true}, + {"01/01/24 13:59:59", true}, + {"01/01/23 14:00:00", true}, + {"01/01/23 14:00:01", true}, + {"01/01/23 14:01:00", true}, + {"01/01/23 16:00:00", true}, + {"01/01/23 23:59:00", true}, + {"01/01/23 23:59:59", true}, }; run_should_work_test(test_values_to_expectations); @@ -281,12 +282,12 @@ TEST_F(LCWorkTimeTests, ShouldWorkCustomWorkTimeEndTimeInTheNextDayIrregularMins std::unordered_map test_values_to_expectations = { {"01/01/23 22:14:59", false}, - {"01/01/23 22:15:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 00:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 01:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/24 02:00:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 03:33:00", false}, // should have been true, expected to fail due to tracker issue #63613 - {"01/01/23 03:33:59", false}, // should have been true, expected to fail due to tracker issue #63613 + {"01/01/23 22:15:00", true}, // used-to-fail + {"01/01/24 00:00:00", true}, // used-to-fail + {"01/01/24 01:00:00", true}, // used-to-fail + {"01/01/24 02:00:00", true}, // used-to-fail + {"01/01/23 03:33:00", true}, // used-to-fail + {"01/01/23 03:33:59", true}, // used-to-fail {"01/01/23 03:34:00", false}, {"01/01/23 04:00:00", false}, {"01/01/23 12:00:00", false},