incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1352702 - /incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py
Date Thu, 21 Jun 2012 21:39:35 GMT
Author: stroucki
Date: Thu Jun 21 21:39:35 2012
New Revision: 1352702

URL: http://svn.apache.org/viewvc?rev=1352702&view=rev
Log:
pickled: add lock around database saves

Modified:
    incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py

Modified: incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py?rev=1352702&r1=1352701&r2=1352702&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py (original)
+++ incubator/tashi/trunk/src/tashi/clustermanager/data/pickled.py Thu Jun 21 21:39:35 2012
@@ -37,6 +37,7 @@ class Pickled(FromConfig):
 		self.hostLock = threading.Lock()
 		self.hostLocks = {}
 		self.idLock = threading.Lock()
+		self.dbLock = threading.Lock()
 		self.load()
 	
 	def cleanInstances(self):
@@ -54,21 +55,22 @@ class Pickled(FromConfig):
 		return ch
 	
 	def save(self):
-		# XXXstroucki lock here to serialize saves
 		filename = self.file
 		# XXXstroucki could be better
 		tempfile = "%s.new" % filename
 
-		filehandle = open(tempfile, "w")
-		cPickle.dump((self.cleanHosts(), self.cleanInstances(), self.networks, self.users), filehandle)
-		filehandle.close()
+		self.dbLock.acquire()
 		try:
+			filehandle = open(tempfile, "w")
+			cPickle.dump((self.cleanHosts(), self.cleanInstances(), self.networks, self.users), filehandle)
+			filehandle.close()
 			os.rename(tempfile, filename)
+
 		except OSError:
-			# XXXstroucki: regular save will take place
-			# soon enough, ignore this until locking is
-			# in place.
-			pass
+			self.log.exception("Error saving database")
+
+		finally:
+			self.dbLock.release()
 
 	def load(self):
 		if (os.access(self.file, os.F_OK)):



Mime
View raw message