]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/lc: adjust timing if the configured end work-time is less than the start-time
authorOguzhan Ozmen <oozmen@bloomberg.net>
Wed, 22 Nov 2023 20:37:00 +0000 (15:37 -0500)
committerMykola Golub <mgolub@suse.com>
Mon, 11 Dec 2023 16:59:12 +0000 (18:59 +0200)
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 <oozmen@bloomberg.net>
(cherry picked from commit 48e189fe0ec6c0ace23ddaed09ef3f936e8c2a6f)

src/rgw/rgw_lc.cc
src/test/rgw/test_rgw_lc.cc

index d7d72c87bdaba16e3e3a2097f62997cd55c12795..b9003c2b94227ab5e63f16e27da578f56c079b01 100644 (file)
@@ -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;
index 2943094c6d0165867b1870202649edc4dabedffe..d10b482cbfcec96f7426c4aa8ad08a661f967a9b 100644 (file)
@@ -235,13 +235,13 @@ TEST_F(LCWorkTimeTests, ShouldWorkCustomWorkTimeEndTimeInTheNextDay)
    std::unordered_map<std::string, bool> 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<std::string, bool> 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<std::string, bool> 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},