MB-21029: Don't return ep_access_scanner_task_time until it has been scheduled 43/67943/7
authorDave Rigby <daver@couchbase.com>
Fri, 23 Sep 2016 10:23:11 +0000 (11:23 +0100)
committerDave Rigby <daver@couchbase.com>
Tue, 27 Sep 2016 16:32:15 +0000 (16:32 +0000)
Fix a latent race condition in ep_access_scanner_task_time stat
(exposed by intermittent failure in access_scanner_settings test),
whereby we can return a value for ep_access_scanner_task_time of the
Unix epoch (1970-01-01 00:00:00) if the AccessScanner has been enabled
but not yet scheduled.

Solution is to not return a value (and instead 'NOT SCHEDULED') until
scheduling has occurred.

Change-Id: Id85a602b3424c30c8795884207a1b0d31cb3c75a
Reviewed-on: http://review.couchbase.org/67943
Reviewed-by: Manu Dhundi <manu@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/ep_engine.cc
tests/ep_testsuite.cc

index 393010a..14b30d0 100644 (file)
@@ -3555,7 +3555,7 @@ ENGINE_ERROR_CODE EventuallyPersistentEngine::doEngineStats(const void *cookie,
     add_casted_stat("ep_access_scanner_num_items", epstats.alogNumItems,
                     add_stat, cookie);
 
-    if (epstore->isAccessScannerEnabled()) {
+    if (epstore->isAccessScannerEnabled() && epstats.alogTime.load() != 0) {
         char timestr[20];
         struct tm alogTim;
         hrtime_t alogTime = epstats.alogTime.load();
index 9533efd..d5d3ff8 100644 (file)
@@ -2696,10 +2696,15 @@ static enum test_result test_access_scanner_settings(ENGINE_HANDLE *h,
 
     std::string err_msg;
     // Check access scanner is enabled and alog_task_time is at default
-    cb_assert(get_bool_stat(h, h1, "ep_access_scanner_enabled"));
+    checkeq(true, get_bool_stat(h, h1, "ep_access_scanner_enabled"),
+            "Expected access scanner to be enabled");
     cb_assert(get_int_stat(h, h1, "ep_alog_task_time") == 2);
 
-    // Ensure access_scanner_task_time is what its expected to be
+    // Ensure access_scanner_task_time is what its expected to be.
+    // Need to wait until the AccessScanner task has been setup.
+    wait_for_stat_change(h, h1, "ep_access_scanner_task_time",
+                         std::string{"NOT_SCHEDULED"});
+
     std::string str = get_str_stat(h, h1, "ep_access_scanner_task_time");
     std::string expected_time = "02:00";
     err_msg.assign("Initial time incorrect, expect: " +