def add(self, loc, authorities): """ Parameters: - location - authorities """ key = location.loc2str(loc) authorities.append(self.location) destinations = location.select_peers(self.ring.nodes.difference(map(location.loc2str,authorities))) for destination in destinations: try: remote_call('add', location.str2loc(destination), loc, authorities) break except location.NodeNotFound, tx: self.remove(tx.location, map(location.str2loc, self.ring.nodes))
def cleanup(self): self.ring.remove(self.here) 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('remove', dest, self.location, [self.location]) remote_call('ping', dest) informed.add(location.loc2str(dest)) remote_call('put', dest, 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('remove', location.str2loc(dest), self.location, [self.location]) informed.add(dest) break except location.NodeNotFound, tx: self.ring.remove(location.loc2str(tx.location))
""" import sys sys.path.append('gen-py') from locator.ttypes import Location from storeserver import remote_call, parser, DEFAULTPORT, SERVICENAME from location import find_matching_service, str2loc usage = ''' python %prog [options] <key> <value> Looks for a storage node at PEER, either as specified, or auto-discovered on the localhost starting from the default port. Sends the remote command there, which gets forwarded to the actual node that has it.''' parser.set_usage(usage) parser.remove_option('--port') if __name__ == '__main__': (options, args) = parser.parse_args() if len(args) != 2: parser.error("incorrect number of arguments") (key, value) = args if options.peer: loc = str2loc(options.peer) else: loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit() remote_call('put', loc, key, value)
self.ring.remove(location.loc2str(tx.location)) def main(inputargs): handler = StoreHandler(**inputargs) processor = Store.Processor(handler) transport = TSocket.TServerSocket(handler.port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) handler.local_join() print 'Starting the server at %s...' % (handler.here) try: server.serve() finally: handler.cleanup() print 'done.' if __name__ == '__main__': (options, args) = parser.parse_args() if not options.port: loc = location.ping_until_not_found(Location('localhost', DEFAULTPORT), 25) options.port = loc.port if options.peer: options.peer = location.str2loc(options.peer) else: options.peer = location.find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) main(options.__dict__)