Introduce testing exception for rescheduled dead tasks 51/76551/7
authorJames Harrison <00jamesh@gmail.com>
Fri, 7 Apr 2017 14:21:32 +0000 (15:21 +0100)
committerDave Rigby <daver@couchbase.com>
Tue, 11 Apr 2017 11:06:24 +0000 (11:06 +0000)
In http://review.couchbase.org/#/c/76394/ the ability to reschedule a
cancelled (and now in state TASK_DEAD) GlobalTask was fixed.

it does not appear that any tasks other than the ItemPager for ephemeral
buckets are rescheduled once dead, but to avoid changing existing
behaviour this introduces an exception if any task other than the
ItemPager is rescheduled, to bring them to our attention.

NB: This patch will be reverted to remove this exception for Spock.
(MB-23797)

Change-Id: If44b7cf8a71c3dc4d85fba98d65c4f608d449460
Reviewed-on: http://review.couchbase.org/76551
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
src/globaltask.h
src/taskqueue.cc

index 917885a..44b8244 100644 (file)
@@ -136,8 +136,8 @@ public:
         return state.load();
     }
 
-    void setState(task_state_t tstate, task_state_t expected) {
-        state.compare_exchange_strong(expected, tstate);
+    bool setState(task_state_t tstate, task_state_t expected) {
+        return state.compare_exchange_strong(expected, tstate);
     }
 
     Taskable& getTaskable() const {
index 8b94799..8ef6239 100644 (file)
@@ -212,7 +212,22 @@ void TaskQueue::_schedule(ExTask &task) {
 
         // If we are rescheduling a previously cancelled task, we should reset
         // the task state to the initial value of running.
-        task->setState(TASK_RUNNING, TASK_DEAD);
+        bool changed_state = task->setState(TASK_RUNNING, TASK_DEAD);
+
+        /* This test is to confirm that we are not changing existing
+         * behaviour by resetting dead tasks to running when rescheduling an
+         * existing task. Will be removed (MB-23797).
+         */
+        if (changed_state) {
+            if (task->getTypeId() != TaskId::ItemPager) {
+                throw std::logic_error(
+                        "Unexpected task was scheduled while DEAD "
+                        "queue:{" + name + "} "
+                        "taskId:{" + std::to_string(task->getId()) + "} "
+                        "taskName:{" +
+                        GlobalTask::getTaskName(task->getTypeId()) + "}");
+            }
+        }
 
         futureQueue.push(task);