[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Maint branch: change Filestore to raise an exception on...
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv27233/lib/mixminion
Modified Files:
Tag: mixminion-v0-0-5-patches
ClientMain.py Filestore.py
Log Message:
Maint branch: change Filestore to raise an exception on failed cPickle.load.
Change users of Filestore to respond appropriately.
Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.112.2.1
retrieving revision 1.112.2.2
diff -u -d -r1.112.2.1 -r1.112.2.2
--- ClientMain.py 12 Sep 2003 15:35:47 -0000 1.112.2.1
+++ ClientMain.py 28 Sep 2003 03:57:32 -0000 1.112.2.2
@@ -1349,7 +1349,8 @@
def getPacket(self, handle):
"""Given a handle, return a 3-tuple of the corresponding
32K packet, IPV4Info, and time of first queueing. (The time
- is rounded down to the closest midnight GMT.)"""
+ is rounded down to the closest midnight GMT.) May raise
+ CorruptedFile."""
obj = self.store.getObject(handle)
try:
magic, message, routing, when = obj
@@ -1381,7 +1382,10 @@
return
timesByServer = {}
for h in handles:
- _, routing, when = self.getPacket(h)
+ try:
+ _, routing, when = self.getPacket(h)
+ except mixminion.Filestore.CorruptedFile:
+ continue
timesByServer.setdefault(routing, []).append(when)
for s in timesByServer.keys():
count = len(timesByServer[s])
@@ -1400,7 +1404,10 @@
cutoff = now - maxAge
remove = []
for h in self.getHandles():
- when = self.getPacket(h)[2]
+ try:
+ when = self.getPacket(h)[2]
+ except mixminion.Filestore.CorruptedFile:
+ continue
if when < cutoff:
remove.append(h)
LOG.info("Removing %s old messages from queue", len(remove))
@@ -1657,7 +1664,10 @@
LOG.info("Flushing %s", len(handles))
messagesByServer = {}
for h in handles:
- message, routing, _ = self.queue.getPacket(h)
+ try:
+ message, routing, _ = self.queue.getPacket(h)
+ except mixminion.Filestore.CorruptedFile:
+ continue
messagesByServer.setdefault(routing, []).append((message, h))
finally:
clientUnlock()
Index: Filestore.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Filestore.py,v
retrieving revision 1.9.2.2
retrieving revision 1.9.2.3
diff -u -d -r1.9.2.2 -r1.9.2.3
--- Filestore.py 26 Sep 2003 02:16:22 -0000 1.9.2.2
+++ Filestore.py 28 Sep 2003 03:57:32 -0000 1.9.2.3
@@ -23,16 +23,20 @@
import threading
import time
-from mixminion.Common import MixFatalError, secureDelete, LOG, \
+from mixminion.Common import MixError, MixFatalError, secureDelete, LOG, \
createPrivateDir, readFile, tryUnlink
from mixminion.Crypto import getCommonPRNG
__all__ = [ "StringStore", "StringMetadataStore",
"ObjectStore", "ObjectMetadataStore",
"MixedStore", "MixedMetadataStore",
- "DBBase", "JournaledDBBase", "BooleanJournaledDBBase"
+ "DBBase", "JournaledDBBase", "BooleanJournaledDBBase",
+ "CorruptedFile",
]
+class CorruptedFile(MixError):
+ """Raised when a pickled object cannot be properly decoded."""
+ pass
# ======================================================================
# Filestores.
@@ -309,21 +313,22 @@
"""
def __init__(self): pass
def getObject(self, handle):
- """Given a message handle, read and unpickle the contents of the
- corresponding message. In rare error cases, defaults to 'None'.
+ """Given a message handle, read and unpickle the contents of
+ the corresponding message. In rare error cases, raises
+ CorruptedFile.
"""
try:
self._lock.acquire()
f = open(os.path.join(self.dir, "msg_"+handle), 'rb')
try:
res = cPickle.load(f)
+ f.close()
+ return res
except cPickle.UnpicklingError, e:
LOG.error("Found damaged object %s in filestore %s: %s",
handle, self.dir, str(e))
self.removeMessage(handle)
- res = None
- f.close()
- return res
+ raise CorruptedFile()
finally:
self._lock.release()
@@ -389,11 +394,15 @@
except KeyError:
LOG.warn("Missing metadata for file %s",h)
self.setMetadata(h, newDataFn(h))
+ except CorruptedFile:
+ LOG.warn("Repairing metadata for file %s",h)
+ self.setMetadata(h, newDataFn(h))
finally:
self._lock.release()
def getMetadata(self, handle):
- """Return the metadata associated with a given handle."""
+ """Return the metadata associated with a given handle. If the
+ metadata is damaged, may raise CorruptedFile."""
fname = os.path.join(self.dir, "meta_"+handle)
if not os.path.exists(fname):
raise KeyError(handle)
@@ -410,7 +419,7 @@
LOG.error("Found damaged metadata for %s in filestore %s: %s",
handle, self.dir, str(e))
self.removeMessage(handle)
- return None
+ raise CorruptedFile()
f.close()
self._metadata_cache[handle] = res
return res