Mercurial > p > roundup > code
diff roundup/backends/back_anydbm.py @ 1333:80d27b7d6db5
implemented whole-database locking
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 12 Dec 2002 09:31:04 +0000 |
| parents | 7af3f0df307b |
| children | d1bfb479e527 |
line wrap: on
line diff
--- a/roundup/backends/back_anydbm.py Wed Dec 11 11:37:07 2002 +0000 +++ b/roundup/backends/back_anydbm.py Thu Dec 12 09:31:04 2002 +0000 @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.94 2002-12-11 01:03:38 richard Exp $ +#$Id: back_anydbm.py,v 1.95 2002-12-12 09:31:04 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -28,7 +28,7 @@ from blobfiles import FileStorage from sessions import Sessions from roundup.indexer import Indexer -from locking import acquire_lock, release_lock +from roundup.backends import locking from roundup.hyperdb import String, Password, Date, Interval, Link, \ Multilink, DatabaseError, Boolean, Number @@ -72,6 +72,12 @@ # ensure files are group readable and writable os.umask(0002) + # lock it + lockfilenm = os.path.join(self.dir, 'lock') + self.lockfile = locking.acquire_lock(lockfilenm) + self.lockfile.write(str(os.getpid())) + self.lockfile.flush() + def post_init(self): ''' Called once the schema initialisation has finished. ''' @@ -203,12 +209,6 @@ mode) return dbm.open(path, mode) - def lockdb(self, name): - ''' Lock a database file - ''' - path = os.path.join(os.getcwd(), self.dir, '%s.lock'%name) - return acquire_lock(path) - # # Node IDs # @@ -216,7 +216,6 @@ ''' Generate a new id for the given class ''' # open the ids DB - create if if doesn't exist - lock = self.lockdb('_ids') db = self.opendb('_ids', 'c') if db.has_key(classname): newid = db[classname] = str(int(db[classname]) + 1) @@ -225,18 +224,15 @@ newid = str(self.getclass(classname).count()+1) db[classname] = newid db.close() - release_lock(lock) return newid def setid(self, classname, setid): ''' Set the id counter: used during import of database ''' # open the ids DB - create if if doesn't exist - lock = self.lockdb('_ids') db = self.opendb('_ids', 'c') db[classname] = str(setid) db.close() - release_lock(lock) # # Nodes @@ -696,7 +692,11 @@ def close(self): ''' Nothing to do ''' - pass + if self.lockfile is not None: + locking.release_lock(self.lockfile) + if self.lockfile is not None: + self.lockfile.close() + self.lockfile = None _marker = [] class Class(hyperdb.Class): @@ -1326,7 +1326,7 @@ def destroy(self, nodeid): '''Destroy a node. - + WARNING: this method should never be used except in extremely rare situations where there could never be links to the node being deleted @@ -1906,13 +1906,12 @@ def get(self, nodeid, propname, default=_marker, cache=1): ''' trap the content propname and get it from the file ''' - - poss_msg = 'Possibly a access right configuration problem.' + poss_msg = 'Possibly an access right configuration problem.' if propname == 'content': try: return self.db.getfile(self.classname, nodeid, None) except IOError, (strerror): - # BUG: by catching this we donot see an error in the log. + # XXX by catching this we donot see an error in the log. return 'ERROR reading file: %s%s\n%s\n%s'%( self.classname, nodeid, poss_msg, strerror) if default is not _marker:
