]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/stats.py
If a stats.pickle file cannot be read, print a better error message.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / stats.py
index fc9ca9e7b0f1aa9961f374a3f2aa7591767c0dd9..ea0a7f85d850dacd74584ecdfa3dd2e5e08d8155 100644 (file)
@@ -9,12 +9,10 @@ from twisted.internet import reactor
 from twisted.application import service
 from twisted.application.internet import TimerService
 from zope.interface import implements
-import foolscap
-from foolscap.eventual import eventually
-from twisted.internet.error import ConnectionDone, ConnectionLost
-from foolscap import DeadReferenceError
+from foolscap.api import eventually, DeadReferenceError, Referenceable, Tub
 
 from allmydata.util import log
+from allmydata.util.encodingutil import quote_output
 from allmydata.interfaces import RIStatsProvider, RIStatsGatherer, IStatsProducer
 
 class LoadMonitor(service.MultiService):
@@ -124,7 +122,7 @@ class CPUUsageMonitor(service.MultiService):
         return s
 
 
-class StatsProvider(foolscap.Referenceable, service.MultiService):
+class StatsProvider(Referenceable, service.MultiService):
     implements(RIStatsProvider)
 
     def __init__(self, node, gatherer_furl):
@@ -180,7 +178,7 @@ class StatsProvider(foolscap.Referenceable, service.MultiService):
         gatherer.callRemoteOnly('provide', self, nickname or '')
 
 
-class StatsGatherer(foolscap.Referenceable, service.MultiService):
+class StatsGatherer(Referenceable, service.MultiService):
     implements(RIStatsGatherer)
 
     poll_interval = 60
@@ -196,7 +194,7 @@ class StatsGatherer(foolscap.Referenceable, service.MultiService):
         self.timer.setServiceParent(self)
 
     def get_tubid(self, rref):
-        return foolscap.SturdyRef(rref.tracker.getURL()).getTubRef().getTubID()
+        return rref.getRemoteTubID()
 
     def remote_provide(self, provider, nickname):
         tubid = self.get_tubid(provider)
@@ -220,7 +218,7 @@ class StatsGatherer(foolscap.Referenceable, service.MultiService):
         # this is called lazily, when a get_stats request fails
         del self.clients[tubid]
         del self.nicknames[tubid]
-        f.trap(DeadReferenceError, ConnectionDone, ConnectionLost)
+        f.trap(DeadReferenceError)
 
     def log_client_error(self, f, tubid):
         log.msg("StatsGatherer: error in get_stats(), peerid=%s" % tubid,
@@ -255,7 +253,12 @@ class PickleStatsGatherer(StdOutStatsGatherer):
 
         if os.path.exists(self.picklefile):
             f = open(self.picklefile, 'rb')
-            self.gathered_stats = pickle.load(f)
+            try:
+                self.gathered_stats = pickle.load(f)
+            except Exception:
+                print ("Error while attempting to load pickle file %s.\nYou may need to delete this file.\n" %
+                       quote_output(os.path.abspath(self.picklefile)))
+                raise
             f.close()
         else:
             self.gathered_stats = {}
@@ -282,11 +285,12 @@ class StatsGathererService(service.MultiService):
     def __init__(self, basedir=".", verbose=False):
         service.MultiService.__init__(self)
         self.basedir = basedir
-        self.tub = foolscap.Tub(certFile=os.path.join(self.basedir,
-                                                      "stats_gatherer.pem"))
+        self.tub = Tub(certFile=os.path.join(self.basedir,
+                                             "stats_gatherer.pem"))
         self.tub.setServiceParent(self)
         self.tub.setOption("logLocalFailures", True)
         self.tub.setOption("logRemoteFailures", True)
+        self.tub.setOption("expose-remote-exception-types", False)
 
         self.stats_gatherer = PickleStatsGatherer(self.basedir, verbose)
         self.stats_gatherer.setServiceParent(self)