Adam Lindsay avatar Adam Lindsay committed 8aedcaf

some more diststore cleanup, especially with cleanup() ordering.

Comments (0)

Files changed (1)

         'Make it quiet for the example'
         pass
     
-    # def join(self, location):
-    #     """
-    #     Parameters:
-    #      - location
-    #     """
-    #     store = self.add(location, [self.location])
-    #     return StarterPackage(self.get_all(), store)
-    
     def add(self, loc, authorities):
         """
         Parameters:
                 self.remove(tx.location, map(location.str2loc, self.ring.nodes))
         locstr = location.loc2str(loc)
         self.ring.append(locstr)
-        #location.ping_until_return(loc)
         sleep(WAITPERIOD)
         for key, value in self.store.items():
             if location.loc2str(self.get_node(key)) == locstr:
         a += "self.store:\n%r\n" % self.store
         print a
     
-    # def local_join(self):
-    #         if self.peer:
-    #             remote_call(self.peer, 'join', self.location)
-    #             print 'Joining the network...'
-    #         else:
-    #             self.ring.append(self.here)
-    #             print 'Initiating the network...'
-    
     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])
-                break
-            except location.NodeNotFound, tx:
-                self.ring.remove(location.loc2str(tx.location))            
-        for key, value in ((a, b) for (a, b) in self.store.items() if b):
-            dest = self.get_node(key)
-            try:
-                #location.ping_until_return(dest, 3)
-                remote_call(dest, 'remove', self.location, [self.location])
-                sleep(WAITPERIOD)
-                remote_call(dest, 'put', key, value)
-            except location.NodeNotFound, tx:
-                print "not found"
-                pass
-    
+        informed = set()
+        if self.ring.nodes:
+            for key, value in ((a, b) for (a, b) in self.store.items() if b):
+                dest = self.get_node(key)
+                try:
+                    if location.loc2str(dest) not in informed:
+                        remote_call(dest, 'remove', self.location, [self.location])
+                    remote_call(dest, 'ping')
+                    informed.add(location.loc2str(dest))
+                    remote_call(dest, 'put', key, value)
+                except location.NodeNotFound, tx:
+                    print "not found"
+                    pass
+            if not informed:
+                for dest in location.select_peers(self.ring.nodes):
+                    try:
+                        remote_call(location.str2loc(dest), 'remove', self.location, [self.location])
+                        informed.add(dest)
+                        break
+                    except location.NodeNotFound, tx:
+                        self.ring.remove(location.loc2str(tx.location))            
+        
 
 def main(inputargs):
     handler = StoreHandler(**inputargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.