当前位置: 首页>>代码示例>>Python>>正文


Python Framework.setDynamo方法代码示例

本文整理汇总了Python中framework.Framework.setDynamo方法的典型用法代码示例。如果您正苦于以下问题:Python Framework.setDynamo方法的具体用法?Python Framework.setDynamo怎么用?Python Framework.setDynamo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在framework.Framework的用法示例。


在下文中一共展示了Framework.setDynamo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DynamoNode

# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import setDynamo [as 别名]
class DynamoNode(Node):
    timer_priority = 20
    T = 10  # Number of repeats for nodes in consistent hash table
    N = 2  # Number of nodes to replicate at
    W = 1  # Number of nodes that need to reply to a write operation
    R = 1  # Number of nodes that need to reply to a read operation
    nodelist = []
    chash = ConsistentHashTable(nodelist, T)

    def __init__(self, addr, config_file='server_config'):
        super(DynamoNode, self).__init__()
        self.framework = Framework()
        self.m_addr = "127.0.0.1:29009"
        self.local_store = MerkleTree()  # key => (value, metadata)
        self.pending_put_rsp = {}  # seqno => set of nodes that have stored
        self.pending_put_msg = {}  # seqno => original client message
        self.pending_get_rsp = {}  # seqno => set of (node, value, metadata) tuples
        self.pending_get_msg = {}  # seqno => original client message
        # seqno => set of requests sent to other nodes, for each message class
        self.pending_req = {PutReq: {}, GetReq: {}}
        self.failed_nodes = []
        self.pending_handoffs = {}
        self.result = {}
        self.reduceResult = {}
        self.MapReduceDB = leveldb.LevelDB('./' + addr + '_mrdb')
        self.mapDict = {}
        # Rebuild the consistent hash table
        self.addr = addr
        self.servers = []
        self.db = leveldb.LevelDB('./' + addr + '_db')
        c = zerorpc.Client(timeout=3)
        c.connect('tcp://' + self.m_addr)
        try:
            
            c.add_node(self.addr)
            c.close()
        except:
            pass

        self.pool = gevent.pool.Group()
        self.pool.spawn(self.retry_failed_node)
        self.framework.setDynamo(self)

    def getNodeList(self, servers):
        print servers
        for i, server in enumerate(list(servers)):
            DynamoNode.nodelist.append(server)
        DynamoNode.chash = ConsistentHashTable(DynamoNode.nodelist, DynamoNode.T)
        
# PART reset
    @classmethod
    def reset(cls):
        cls.nodelist = []
        cls.chash = ConsistentHashTable(cls.nodelist, cls.T)

# PART storage
    def store(self, key, value, metadata):
        self.db.Put(key,pickle.dumps((value,metadata)))

    def retrieve(self, key):
        try:
            return pickle.loads(self.db.Get(key))
        except:
            return (None, None)
    
    def are_you_there(self):
        return
# PART retry_failed_node
    def retry_failed_node(self):  # Permanently repeating timer       
        while True:
            if self.failed_nodes:
                for node in self.failed_nodes:
                    c = zerorpc.Client(timeout=1)
                    c.connect('tcp://' + str(node))
                    try:
                        c.are_you_there()
                        c.close()
                        self.recovery(node)
                    except:
                        continue
            time.sleep(1)
        
    def recovery(self, node):
        # Remove all instances of recovered node from failed node list
        recovered_node = node
        while recovered_node in self.failed_nodes:
            self.failed_nodes.remove(recovered_node)
        if recovered_node in self.pending_handoffs:
            for key in self.pending_handoffs[recovered_node]:
                # Send our latest value for this key
                (value, metadata) = self.retrieve(key)
                putmsg = PutReq(self.addr, recovered_node, key, value, metadata)
                self.framework.send_message(putmsg)
                self.framework.schedule()
            del self.pending_handoffs[recovered_node]


    def retry_request(self, reqmsg):
        self.failed_nodes.append(reqmsg.to_node)
        if not isinstance(reqmsg, DynamoRequestMessage):
#.........这里部分代码省略.........
开发者ID:TaoZong,项目名称:Python,代码行数:103,代码来源:dynamo.py


注:本文中的framework.Framework.setDynamo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。