X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fbackends%2Fback_bsddb.py;h=6e14a6e5ee24882b50ddcc7effee56f6e0354ad9;hb=4b49a95cf5001a573043ec7c463dea45274b62c2;hp=b30dacb00c407169ae8362b360c3658189f22b9d;hpb=496eef016c85be643f0816af03844ad9175a67ab;p=roundup.git diff --git a/roundup/backends/back_bsddb.py b/roundup/backends/back_bsddb.py index b30dacb..6e14a6e 100644 --- a/roundup/backends/back_bsddb.py +++ b/roundup/backends/back_bsddb.py @@ -15,21 +15,21 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb.py,v 1.15 2002-02-16 09:15:33 richard Exp $ +#$Id: back_bsddb.py,v 1.20 2002-07-19 03:36:34 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in BSDDB. ''' import bsddb, os, marshal -from roundup import hyperdb, date, password +from roundup import hyperdb, date # these classes are so similar, we just use the anydbm methods -import back_anydbm +from back_anydbm import Database, Class, FileClass, IssueClass # # Now the database # -class Database(back_anydbm.Database): +class Database(Database): """A database for storing records containing flexible data types.""" # # Class DBs @@ -51,22 +51,22 @@ class Database(back_anydbm.Database): else: return bsddb.btopen(path, 'n') - def _opendb(self, name, mode): + def opendb(self, name, mode): '''Low-level database opener that gets around anydbm/dbm eccentricities. ''' - if hyperdb.DEBUG: - print self, '_opendb', (self, name, mode) + if __debug__: + print >>hyperdb.DEBUG, self, 'opendb', (self, name, mode) # determine which DB wrote the class file path = os.path.join(os.getcwd(), self.dir, name) if not os.path.exists(path): - if hyperdb.DEBUG: - print "_opendb bsddb.open(%r, 'n')"%path + if __debug__: + print >>hyperdb.DEBUG, "opendb bsddb.open(%r, 'n')"%path return bsddb.btopen(path, 'n') # open the database with the correct module - if hyperdb.DEBUG: - print "_opendb bsddb.open(%r, %r)"%(path, mode) + if __debug__: + print >>hyperdb.DEBUG, "opendb bsddb.open(%r, %r)"%(path, mode) return bsddb.btopen(path, mode) # @@ -82,9 +82,10 @@ class Database(back_anydbm.Database): 'r') except bsddb.error, error: if error.args[0] != 2: raise - return [] - # mor handling of bad journals - if not db.has_key(nodeid): return [] + raise IndexError, 'no such %s %s'%(classname, nodeid) + # more handling of bad journals + if not db.has_key(nodeid): + raise IndexError, 'no such %s %s'%(classname, nodeid) journal = marshal.loads(db[nodeid]) res = [] for entry in journal: @@ -94,21 +95,67 @@ class Database(back_anydbm.Database): db.close() return res - def _doSaveJournal(self, classname, nodeid, action, params): + def getCachedJournalDB(self, classname): + ''' get the journal db, looking in our cache of databases for commit + ''' + # get the database handle + db_name = 'journals.%s'%classname + if self.databases.has_key(db_name): + return self.databases[db_name] + else: + db = bsddb.btopen(os.path.join(self.dir, db_name), 'c') + self.databases[db_name] = db + return db + + def doSaveJournal(self, classname, nodeid, action, params): + # serialise first + if action in ('set', 'create'): + params = self.serialise(classname, params) + entry = (nodeid, date.Date().get_tuple(), self.journaltag, action, params) - db = bsddb.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'c') + + if __debug__: + print >>hyperdb.DEBUG, 'doSaveJournal', entry + + db = self.getCachedJournalDB(classname) + if db.has_key(nodeid): s = db[nodeid] - l = marshal.loads(db[nodeid]) + l = marshal.loads(s) l.append(entry) else: l = [entry] + db[nodeid] = marshal.dumps(l) - db.close() # #$Log: not supported by cvs2svn $ +#Revision 1.19 2002/07/14 02:05:53 richard +#. all storage-specific code (ie. backend) is now implemented by the backends +# +#Revision 1.18 2002/05/15 06:21:21 richard +# . node caching now works, and gives a small boost in performance +# +#As a part of this, I cleaned up the DEBUG output and implemented TRACE +#output (HYPERDBTRACE='file to trace to') with checkpoints at the start of +#CGI requests. Run roundup with python -O to skip all the DEBUG/TRACE stuff +#(using if __debug__ which is compiled out with -O) +# +#Revision 1.17 2002/04/03 05:54:31 richard +#Fixed serialisation problem by moving the serialisation step out of the +#hyperdb.Class (get, set) into the hyperdb.Database. +# +#Also fixed htmltemplate after the showid changes I made yesterday. +# +#Unit tests for all of the above written. +# +#Revision 1.16 2002/02/27 03:40:59 richard +#Ran it through pychecker, made fixes +# +#Revision 1.15 2002/02/16 09:15:33 richard +#forgot to patch bsddb backend too +# #Revision 1.14 2002/01/22 07:21:13 richard #. fixed back_bsddb so it passed the journal tests #