r5405 - in trunk: cumin/bin mint/python/mint

tmckay at fedoraproject.org tmckay at fedoraproject.org
Wed Jun 6 19:18:53 UTC 2012


Author: tmckay
Date: 2012-06-06 19:18:53 +0000 (Wed, 06 Jun 2012)
New Revision: 5405

Modified:
   trunk/cumin/bin/cumin-data
   trunk/mint/python/mint/main.py
   trunk/mint/python/mint/util.py
   trunk/mint/python/mint/vacuum.py
Log:
Additional tweaks to shutdown.  Let an ongoing vacuum operation finish.


Modified: trunk/cumin/bin/cumin-data
===================================================================
--- trunk/cumin/bin/cumin-data	2012-06-06 17:33:56 UTC (rev 5404)
+++ trunk/cumin/bin/cumin-data	2012-06-06 19:18:53 UTC (rev 5405)
@@ -294,12 +294,11 @@
 
     def shutdown():
         if mint:
-            mint.stop()
-        log.info("about to call logging shutdown")
-        logging.shutdown()
+            # Don't stop vacuum here.  If a vacuum is happening,
+            # we want to let it complete.  Stop it below.
+            mint.stop(skip_vacuum=True)
 
     # Run shutdown with a timeout in the main thread.
-    # This guarantees exit.
     t = ShutdownThread(shutdown)
     t.start()
 
@@ -311,6 +310,14 @@
     t.join(tm)
     if pipeThread:
         pipeThread.stop(immediate=True)
+
+    # Vacuum is not interruptable and could take a while.
+    # This call to stop will wait for vacuum to exit
+    mint.vacuum_thread.stop()
+
+    log.info("about to call logging shutdown")
+    logging.shutdown()
+
     return adjust_return(passed_init, return_code)
 
 def make_ctrl_c(sig, frame):

Modified: trunk/mint/python/mint/main.py
===================================================================
--- trunk/mint/python/mint/main.py	2012-06-06 17:33:56 UTC (rev 5404)
+++ trunk/mint/python/mint/main.py	2012-06-06 19:18:53 UTC (rev 5405)
@@ -85,21 +85,17 @@
         if self.vacuum_enabled:
             self.vacuum_thread.start()
 
-    def stop(self):
+    def stop(self, skip_vacuum=False):
         log.info("Stopping %s", self)
 
         self.update_thread.stop()
-        log.info("Update thread stopped")
 
         if self.expire_enabled:
             self.expire_thread.stop()
-            log.info("Expire thread stopped")
-
-        if self.vacuum_enabled:
+        
+        if self.vacuum_enabled and not skip_vacuum:
             self.vacuum_thread.stop()
-            log.info("Vacuum thread stopped")
 
-
         self.session.stop()
         log.info("Session stopped")
 

Modified: trunk/mint/python/mint/util.py
===================================================================
--- trunk/mint/python/mint/util.py	2012-06-06 17:33:56 UTC (rev 5404)
+++ trunk/mint/python/mint/util.py	2012-06-06 19:18:53 UTC (rev 5405)
@@ -42,6 +42,7 @@
         self.stop_requested = True
         if self.isAlive():
             self.join(timeout)
+            log.info("%s stopped" % self.getName())
 
 class MintBlockingDaemonThread(MintDaemonThread):
     def __init__(self, app):
@@ -53,14 +54,14 @@
     def stop(self, timeout=5):
         try:
             self._condition.acquire()
-            if self.stop_requested:
-                return
             self.stop_requested = True
             self._condition.notify()
         finally:
             self._condition.release()
+
         if self.isAlive():
             self.join(timeout)
+            log.info("%s stopped" % self.getName())
 
 class MintPeriodicProcessThread(MintBlockingDaemonThread):
     def __init__(self, app, interval):

Modified: trunk/mint/python/mint/vacuum.py
===================================================================
--- trunk/mint/python/mint/vacuum.py	2012-06-06 17:33:56 UTC (rev 5404)
+++ trunk/mint/python/mint/vacuum.py	2012-06-06 19:18:53 UTC (rev 5405)
@@ -11,6 +11,7 @@
         super(VacuumThread, self).init()
 
         log.debug("Vacuum interval is %i seconds", self.interval)
+        self.processing_vacuum = False
 
     def run(self):
         if self.interval >= 60 * 60:
@@ -23,23 +24,49 @@
             if not self.stop_requested:
                 self._condition.wait(interval)
             if self.stop_requested:
-                log.debug("Periodic process %s exited" % self.getName())
                 return
         finally:
             self._condition.release()
 
         super(VacuumThread, self).run()
 
+    def stop(self, timeout=5):
+        try:
+            self._condition.acquire()
+            self.stop_requested = True
+            self._condition.notify()
+            if self.processing_vacuum:
+                timeout = None # forever
+                log.info("Waiting for vacuum to finish")
+        finally:
+            self._condition.release()
+        if self.isAlive():
+            self.join(timeout)
+        log.info("%s stopped" % self.getName())
+
     def process(self):
+        self._condition.acquire()
+        if self.stop_requested:
+            self._condition.release()
+            return
+
+        # Flag this so the main thread can
+        # know what we're doing
+        self.processing_vacuum = True
+        self._condition.release()
+
         log.info("Starting vacuum")
 
         conn = self.app.database.get_connection()
         conn.set_isolation_level(0)
-
         try:
             cursor = conn.cursor()
             cursor.execute("vacuum analyze")
         finally:
             conn.close()
 
+        self._condition.acquire()
+        self.processing_vacuum = False
+        self._condition.release()
+
         log.info("Finished vacuum")



More information about the cumin-developers mailing list