def on_peer_response_append(self, peer, msg):
"""Handle peer response to append_entries.
If successful RPC, try to commit new entries.
If RPC unsuccessful, backtrack."""
if msg['success']:
self.matchIndex[peer] = msg['matchIndex']
self.nextIndex[peer] = msg['matchIndex'] + 1
self.matchIndex[self.volatile['address']] = self.log.index
self.nextIndex[self.volatile['address']] = self.log.index + 1
index = statistics.median_low(self.matchIndex.values())
self.log.commit(index)
self.send_client_append_response()
else:
self.nextIndex[peer] = max(0, self.nextIndex[peer] - 1)
评论列表
文章目录