Commits

Adam Lindsay  committed 31c8b79

Debugging my changes in hash_ring, handover on server exit

  • Participants
  • Parent commits 9b863c9

Comments (0)

Files changed (3)

File hash_ring.py

 """
 
 # Pretty radically changed by atl on 2009.04.28:
-# added append/extend/remove methods
+# added append/extend/remove methods (bugfix 2009.05.18)
 # made nodes a set to accommodate that more easily/naturally
 #
 # __getindex__() to support dict-like access::
 
     def remove(self, item):
         self.nodes.discard(item)
+        self._sorted_keys = []
+        self.ring = dict()
         self._generate_circle()
     
     def __getitem__(self, item):
     def cleanup(self):
         self.ring.remove(self.here)
         for node in select_peers(self.ring.nodes):
-            remote_call(str2loc(node), 'remove', self.location, [self.location])
+            try:
+                remote_call(str2loc(node), 'remove', self.location, [self.location])
+            except NodeNotFound, tx:
+                pass
     
     def local_join(self):
         if self.peer:

File storeserver.py

         Parameters:
          - key
         """
+        print self.ring.nodes
         dest = self.get_node(key)
+        print dest
         if location.loc2str(dest) == self.here:
             if key in self.store:
                 print 'found %s' % key
         a += "self.store:\n%r\n" % self.store
         print a
     
+    def cleanup(self):
+        self.ring.remove(self.here)
+        for dest in location.select_peers(self.ring.nodes):
+            try:
+                remote_call(location.str2loc(dest), 'remove', self.location, [self.location])
+            except location.NodeNotFound, tx:
+                self.ring.remove(loc2str(tx.location))            
+        for key, value in ((a, b) for (a, b) in self.store.items() if b):
+            dest = self.get_node(key)
+            try:
+                remote_call(dest, 'put', key, value)
+            except location.NodeNotFound, tx:
+                pass
+    
 
 #
 def main(inputargs):
     if 'port' not in inputargs:
         loc = location.ping_until_not_found(Location('localhost', DEFAULTPORT), 25)
         inputargs['port'] = loc.port
-    if 'peer' not in inputargs and inputargs['port'] != DEFAULTPORT:
+    if 'peer' not in inputargs:
         try:
             loc = location.ping_until_found(Location('localhost', DEFAULTPORT))
             inputargs['peer'] = loc