diff options
| author | cotton | 1998-10-22 11:21:16 +0000 |
|---|---|---|
| committer | cotton | 1998-10-22 11:21:16 +0000 |
| commit | 4e72daaa69e254fd40394416b0115956c6fe8ac3 (patch) | |
| tree | d3b521521650f2c58f74eba29a28bbcfffb36489 /Mailman/HyperDatabase.py | |
| parent | fa4ed3fca6fb7205c132cd3debde7362304ff9bb (diff) | |
| download | mailman-4e72daaa69e254fd40394416b0115956c6fe8ac3.tar.gz mailman-4e72daaa69e254fd40394416b0115956c6fe8ac3.tar.zst mailman-4e72daaa69e254fd40394416b0115956c6fe8ac3.zip | |
bug fix: Archiving mechansim
the native python bsddb replacement wasn't protected in all
cases from HyperArch.Archive's locking. added a single global
lock uses the flock module to HyperDatabase.DumbBTree so that
only one process may access it at a time.
specifics:
1) removed previously added locking around the
pipermail.T.__init__ line in HyperArch.Archive.__init__, as
the database locking should take care of this
2) added lock and unlock methods to HyperDatabase.DumbBTree
making multple calls to unlock, and therefore multple calls
to HyperDatabase.DumbBTree.close() ok, as the comments from
pipermail indicate this might happen.
scott
Diffstat (limited to 'Mailman/HyperDatabase.py')
| -rw-r--r-- | Mailman/HyperDatabase.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Mailman/HyperDatabase.py b/Mailman/HyperDatabase.py index e10e7329d..a0700773e 100644 --- a/Mailman/HyperDatabase.py +++ b/Mailman/HyperDatabase.py @@ -14,11 +14,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# site modules +# import os import marshal import string +# +# package/project modules +# import pipermail +import flock + CACHESIZE = pipermail.CACHESIZE try: @@ -32,18 +40,32 @@ except ImportError: # we're using a python dict in place of # of bsddb.btree database. only defining # the parts of the interface used by class HyperDatabase +# only one thing can access this at a time. # class DumbBTree: def __init__(self, path): + self.current_index = 0 + self.path = path + self.lockfile = flock.FileLock(self.path + ".lock") + self.lock() if os.path.exists(path): self.dict = marshal.load(open(path)) else: self.dict = {} self.sorted = self.dict.keys() self.sorted.sort() - self.current_index = 0 - self.path = path + + def lock(self): + self.lockfile.lock() + + + def unlock(self): + try: + self.lockfile.unlock() + except flock.NotLockedError: + pass + def __delitem__(self, item): try: @@ -119,11 +141,15 @@ class DumbBTree: def __len__(self): return len(self.sorted) + def close(self): fp = open(self.path, "w") fp.write(marshal.dumps(self.dict)) fp.close() - + self.unlock() + + + @@ -205,7 +231,6 @@ class HyperDatabase(pipermail.Database): def __closeIndices(self): if self.__currentOpenArchive!=None: pass -# print 'closing indices for [%s]' % (repr(self.__currentOpenArchive),) for i in ['date', 'author', 'subject', 'thread', 'article']: attr=i+'Index' if hasattr(self, attr): |
