Francesco Romani has uploaded a new change for review.

Change subject: lib: executor: make possible to name work tasks
......................................................................

lib: executor: make possible to name work tasks

To improve the debuggability of the executor, we
add the possibility to add a name to work items
submitted to it, so we can know what exactly was
stuck inside a worker when the latter is discarded.

Change-Id: I40584ee9a99839a4cb56d2f4d908d274f3a46638
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M lib/vdsm/executor.py
1 file changed, 14 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/48191/1

diff --git a/lib/vdsm/executor.py b/lib/vdsm/executor.py
index cee1e9a..767eca3 100644
--- a/lib/vdsm/executor.py
+++ b/lib/vdsm/executor.py
@@ -80,12 +80,12 @@
             self._running = False
             self._tasks.clear()
             for _ in xrange(self._workers_count):
-                self._tasks.put((_STOP, None))
+                self._tasks.put((_STOP, None, None))
             workers = tuple(self._workers) if wait else ()
         for worker in workers:
             worker.join()
 
-    def dispatch(self, callable, timeout=None):
+    def dispatch(self, callable, timeout=None, workid=None):
         """
         dispatches a new task to the executor.
 
@@ -95,10 +95,14 @@
 
         The timeout is measured from the time the callable
         is called.
+
+        The workid is an opaque string passed through for
+        debug purposes.
         """
         if not self._running:
             raise NotRunning()
-        self._tasks.put((callable, timeout))
+        work_id = 'N/A' if workid is None else workid
+        self._tasks.put((callable, timeout, work_id))
 
     # Serving workers
 
@@ -123,10 +127,10 @@
         Called from worker thread to get the next task from the taks queue.
         Raises NotRunning exception if executor was stopped.
         """
-        task, timeout = self._tasks.get()
+        task, timeout, work_id = self._tasks.get()
         if task is _STOP:
             raise NotRunning()
-        return task, timeout
+        return task, timeout, work_id
 
     # Private
 
@@ -156,6 +160,7 @@
         self._thread.daemon = True
         self._log.debug('Starting worker %s' % name)
         self._thread.start()
+        self._work_id = "N/A"
 
     @property
     def name(self):
@@ -180,7 +185,8 @@
             self._executor._worker_stopped(self)
 
     def _execute_task(self):
-        callable, timeout = self._executor._next_task()
+        callable, timeout, work_id = self._executor._next_task()
+        self._work_id = work_id
         discard = self._discard_after(timeout)
         try:
             callable()
@@ -206,7 +212,8 @@
         if self._discarded:
             raise AssertionError("Attempt to discard worker twice")
         self._discarded = True
-        self._log.debug("Worker %s discarded", self.name)
+        self._log.debug("Worker %s discarded while doing '%s'",
+                        self.name, self._work_id)
         self._executor._worker_discarded(self)
 
 


-- 
To view, visit https://gerrit.ovirt.org/48191
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I40584ee9a99839a4cb56d2f4d908d274f3a46638
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to