def _recover_instance(node): logging.info('Recover node %d(%s:%d)', node.id, node.host, node.port) try: comm.fix_migrating(node.host, node.port) except (StandardError, SocketError), e: logging.exception(e) logging.error('Fail to recover %s:%d', node.host, node.port)
def test_fix(self): def migrate_one_slot(nodes, _): if nodes[0].port == 7100: source, target = nodes else: target, source = nodes return [(source, target, 1)] comm.create([('127.0.0.1', 7100)]) rc = StrictRedisCluster(startup_nodes=[{ 'host': '127.0.0.1', 'port': 7100 }], decode_responses=True) comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101, balance_plan=migrate_one_slot) rc.set('h-893', 'I am in slot 0') comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) t7100 = Connection('127.0.0.1', 7100) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] t7100.execute('cluster', 'setslot', 0, 'importing', n7101.node_id) comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] self.assertEqual(16384, len(n7100.assigned_slots)) self.assertEqual(0, len(n7101.assigned_slots)) t7101 = Connection('127.0.0.1', 7101) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] self.assertEqual(16384, len(n7100.assigned_slots)) self.assertEqual(0, len(n7101.assigned_slots)) t7100.execute('cluster', 'setslot', 0, 'migrating', n7101.node_id) comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) comm.quit_cluster('127.0.0.1', 7101) rc.delete('h-893') comm.shutdown_cluster('127.0.0.1', 7100) t7100.close() t7101.close()
def test_fix(self): def migrate_one_slot(nodes, _): if nodes[0].port == 7100: source, target = nodes else: target, source = nodes return [(source, target, 1)] comm.start_cluster('127.0.0.1', 7100) rc = RedisCluster([{'host': '127.0.0.1', 'port': 7100}]) comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101, balance_plan=migrate_one_slot) rc.set('h-893', 'I am in slot 0') comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) t7100 = Talker('127.0.0.1', 7100) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] t7100.talk('cluster', 'setslot', 0, 'importing', n7101.node_id) comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] self.assertEqual(16384, len(n7100.assigned_slots)) self.assertEqual(0, len(n7101.assigned_slots)) t7101 = Talker('127.0.0.1', 7101) nodes = base.list_nodes('127.0.0.1', 7100) self.assertEqual(2, len(nodes)) n7100 = nodes[('127.0.0.1', 7100)] n7101 = nodes[('127.0.0.1', 7101)] self.assertEqual(16384, len(n7100.assigned_slots)) self.assertEqual(0, len(n7101.assigned_slots)) t7100.talk('cluster', 'setslot', 0, 'migrating', n7101.node_id) comm.fix_migrating('127.0.0.1', 7100) self.assertEqual('I am in slot 0', rc.get('h-893')) comm.quit_cluster('127.0.0.1', 7101) rc.delete('h-893') comm.shutdown_cluster('127.0.0.1', 7100) t7100.close() t7101.close()