def test_5_transfer_pgs_to_another_machine(self): util.print_frame() self.load_gen_list = {} # get gateway info ip, port = util.get_rand_gateway(self.cluster) gw = gateway_mgmt.Gateway(self.cluster['servers'][0]['id']) ret = gw.connect(ip, port) self.assertEqual(ret, 0, 'failed to connect to gateway, %s:%d' % (ip, port)) # incrase master generation number util.log('failover in order to increase master generation number.') max = 0 for i in range(5): key_base = 'key' for i in range(max, max + 10000): cmd = 'set %s%d %d\r\n' % (key_base, i, i) gw.write(cmd) res = gw.read_until('\r\n') self.assertEquals(res, '+OK\r\n') max = max + 10000 m = util.get_server_by_role(self.cluster['servers'], 'master') util.log('failover pgs%d' % m['id']) ret = util.failover(m, self.leader_cm) self.assertTrue(ret, 'failed to failover pgs%d' % m['id']) # start load generator util.log("start load_generator") for i in range(self.max_load_generator): ip, port = util.get_rand_gateway(self.cluster) self.load_gen_list[i] = load_generator.LoadGenerator(i, ip, port) self.load_gen_list[i].start() time.sleep(5) # generate load for 5 sec util.log("started load_generator") m, s1, s2 = util.get_mss(self.cluster) servers = [m, s1, s2] # bgsave for s in servers: ret = util.bgsave(s) self.assertTrue(ret, 'failed to bgsave. pgs%d' % s['id']) new_servers = [config.server4, config.server5] # add new slaves for s in new_servers: util.log('delete pgs%d`s check point.' % s['id']) util.del_dumprdb(s['id']) ret = util.cluster_util_getdump(s['id'], m['ip'], m['redis_port'], 'dump.rdb', 0, 8191) self.assertEqual( True, ret, 'failed : util.cluster_util_getdump returns false, src=%s:%d dest_pgsid=%d' % (m['ip'], m['redis_port'], s['id'])) ret = util.install_pgs(self.cluster, s, self.leader_cm, 0, rm_ckpt=False) self.assertEqual( True, ret, 'failed : util.pgs_add returns false, pgsid=%d' % s['id']) util.log('succeeeded : add a new slave, pgsid=%d' % s['id']) # check consistency ok = True for j in range(self.max_load_generator): if self.load_gen_list[j].isConsistent() == False: ok = False break if not ok: break for server_to_del in servers: for s in servers: util.pingpong(s['ip'], s['smr_mgmt_port']) for s in new_servers: util.pingpong(s['ip'], s['smr_mgmt_port']) self.__del_server(server_to_del) util.log('succeeded : delete pgs%d' % server_to_del['id']) new_m = util.get_server_by_role(new_servers, 'master') new_s = util.get_server_by_role(new_servers, 'slave') self.assertNotEqual(new_m, None, 'master is None.') self.assertNotEqual(new_s, None, 'slave is None.') for s in new_servers: util.pingpong(s['ip'], s['smr_mgmt_port']) time.sleep(5) # generate load for 5 sec # check consistency of load_generator for i in range(self.max_load_generator): self.load_gen_list[i].quit() for i in range(self.max_load_generator): self.load_gen_list[i].join() self.assertTrue(self.load_gen_list[i].isConsistent(), 'Inconsistent after migration') self.load_gen_list.pop(i, None) # Go back to initial configuration # recover pgs for s in servers: self.assertTrue( util.install_pgs(self.cluster, s, self.leader_cm, rm_ckpt=False), 'failed to recover pgs. (install_pgs)') # cleanup new slaves for s in new_servers: self.assertTrue( util.uninstall_pgs(self.cluster, s, self.leader_cm), 'failed to cleanup pgs. (uninstall_pgs)')
def test_restart_recovery_with_remote_checkpoint_and_remote_log(self): util.print_frame() key_base = 'key' target = util.get_server_by_role(self.cluster['servers'], 'slave') master = util.get_server_by_role(self.cluster['servers'], 'master') ip, port = util.get_rand_gateway(self.cluster) gw = gateway_mgmt.Gateway(master['id']) ret = gw.connect(ip, port) self.assertEqual(ret, 0, 'failed to connect to gateway') # set initial data in order to make an elapsed time for bgsave longer self.put_some_data() # generate some data for i in range(0, 100): key = '%s%d' % (key_base, i) cmd = 'set %s %d\r\n' % (key, i) gw.write(cmd) res = gw.read_until('\r\n') self.assertEquals(res, '+OK\r\n') gw.disconnect() # delete a local checkpoint util.log('delete pgs%d`s check point.' % target['id']) util.del_dumprdb(target['id']) # generate a remote check point bgsave_ret = util.bgsave(master) self.assertTrue(bgsave_ret, 'failed to bgsave. pgs%d' % master['id']) # shutdown util.log('shutdown target') ret = testbase.request_to_shutdown_smr(target) self.assertEqual(ret, 0, 'failed to shutdown smr') time.sleep(10) # generate some data ret = gw.connect(ip, port) self.assertEqual(ret, 0, 'failed to connect to gateway') for i in range(100, 200): key = '%s%d' % (key_base, i) cmd = 'set %s %d\r\n' % (key, i) gw.write(cmd) res = gw.read_until('\r\n') self.assertEquals(res, '+OK\r\n') gw.disconnect() # recovery util.log('recovery target') ret = testbase.request_to_start_smr(target) self.assertEqual(ret, 0, 'failed to start smr') ret = testbase.request_to_start_redis(target) self.assertEqual(ret, 0, 'failed to start redis') time.sleep(5) ret = testbase.wait_until_finished_to_set_up_role(target) self.assertEquals(ret, 0, 'failed to role change. smr_id:%d' % (target['id'])) # check value recovered_redis = redis_mgmt.Redis(target['id']) ret = recovered_redis.connect(target['ip'], target['redis_port']) self.assertEquals(ret, 0, 'failed to connect to redis') for i in range(0, 200): key = '%s%d' % (key_base, i) cmd = 'get %s\r\n' % (key) recovered_redis.write(cmd) recovered_redis.read_until('\r\n') response = recovered_redis.read_until('\r\n') self.assertEqual(response, '%d\r\n' % i, 'inconsistent %s, %d' % (response, i))
def test_5_transfer_pgs_to_another_machine(self): util.print_frame() self.load_gen_list = {} # get gateway info ip, port = util.get_rand_gateway( self.cluster ) gw = gateway_mgmt.Gateway( self.cluster['servers'][0]['id'] ) ret = gw.connect( ip, port ) self.assertEqual( ret, 0, 'failed to connect to gateway, %s:%d' % (ip, port) ) # incrase master generation number util.log('failover in order to increase master generation number.') max = 0 for i in range(5): key_base = 'key' for i in range(max, max+10000): cmd = 'set %s%d %d\r\n' % (key_base, i, i) gw.write( cmd ) res = gw.read_until( '\r\n' ) self.assertEquals( res, '+OK\r\n' ) max = max + 10000 m = util.get_server_by_role(self.cluster['servers'], 'master') util.log('failover pgs%d' % m['id']) ret = util.failover(m, self.leader_cm) self.assertTrue(ret, 'failed to failover pgs%d' % m['id']) # start load generator util.log("start load_generator") for i in range(self.max_load_generator): ip, port = util.get_rand_gateway(self.cluster) self.load_gen_list[i] = load_generator.LoadGenerator(i, ip, port) self.load_gen_list[i].start() time.sleep(5) # generate load for 5 sec util.log("started load_generator") m, s1, s2 = util.get_mss(self.cluster) servers = [m, s1, s2] # bgsave for s in servers: ret = util.bgsave(s) self.assertTrue(ret, 'failed to bgsave. pgs%d' % s['id']) new_servers = [config.server4, config.server5] # add new slaves for s in new_servers: util.log('delete pgs%d`s check point.' % s['id']) util.del_dumprdb(s['id']) ret = util.cluster_util_getdump(s['id'], m['ip'], m['redis_port'], 'dump.rdb', 0, 8191) self.assertEqual(True, ret, 'failed : util.cluster_util_getdump returns false, src=%s:%d dest_pgsid=%d' % ( m['ip'], m['redis_port'], s['id'])) ret = util.pgs_add(self.cluster, s, self.leader_cm, 0, rm_ckpt=False) self.assertEqual(True, ret, 'failed : util.pgs_add returns false, pgsid=%d' % s['id']) util.log('succeeeded : add a new slave, pgsid=%d' % s['id']) # check consistency ok = True for j in range(self.max_load_generator): if self.load_gen_list[j].isConsistent() == False: ok = False break if not ok: break; for server_to_del in servers: for s in servers: util.pingpong( s['ip'], s['smr_mgmt_port'] ) for s in new_servers: util.pingpong( s['ip'], s['smr_mgmt_port'] ) self.__del_server(server_to_del) util.log('succeeded : delete pgs%d' % server_to_del['id']) new_m = util.get_server_by_role(new_servers, 'master') new_s = util.get_server_by_role(new_servers, 'slave') self.assertNotEqual( new_m, None, 'master is None.' ) self.assertNotEqual( new_s, None, 'slave is None.' ) for s in new_servers: util.pingpong( s['ip'], s['smr_mgmt_port'] ) time.sleep(5) # generate load for 5 sec # check consistency of load_generator for i in range(self.max_load_generator): self.load_gen_list[i].quit() for i in range(self.max_load_generator): self.load_gen_list[i].join() self.assertTrue(self.load_gen_list[i].isConsistent(), 'Inconsistent after migration') self.load_gen_list.pop(i, None)
def test_restart_recovery_with_remote_checkpoint_and_remote_log( self ): util.print_frame() key_base = 'key' target = util.get_server_by_role( self.cluster['servers'], 'slave' ) master = util.get_server_by_role( self.cluster['servers'], 'master' ) ip, port = util.get_rand_gateway( self.cluster ) gw = gateway_mgmt.Gateway( master['id'] ) ret = gw.connect( ip, port ) self.assertEqual( ret, 0, 'failed to connect to gateway' ) # set initial data in order to make an elapsed time for bgsave longer self.put_some_data() # generate some data for i in range( 0, 100 ): key = '%s%d' % (key_base, i) cmd = 'set %s %d\r\n' % (key, i) gw.write( cmd ) res = gw.read_until( '\r\n' ) self.assertEquals( res, '+OK\r\n' ) gw.disconnect() # delete a local checkpoint util.log('delete pgs%d`s check point.' % target['id']) util.del_dumprdb( target['id'] ) # generate a remote check point bgsave_ret = util.bgsave( master ) self.assertTrue( bgsave_ret, 'failed to bgsave. pgs%d' % master['id'] ) # shutdown util.log('shutdown target') ret = testbase.request_to_shutdown_smr( target ) self.assertEqual( ret, 0, 'failed to shutdown smr' ) time.sleep( 10 ) # generate some data ret = gw.connect( ip, port ) self.assertEqual( ret, 0, 'failed to connect to gateway' ) for i in range( 100, 200 ): key = '%s%d' % (key_base, i) cmd = 'set %s %d\r\n' % (key, i) gw.write( cmd ) res = gw.read_until( '\r\n' ) self.assertEquals( res, '+OK\r\n' ) gw.disconnect() # recovery util.log('recovery target') ret = testbase.request_to_start_smr( target ) self.assertEqual( ret, 0, 'failed to start smr' ) ret = testbase.request_to_start_redis( target ) self.assertEqual( ret, 0, 'failed to start redis' ) time.sleep( 5 ) ret = testbase.wait_until_finished_to_set_up_role( target) self.assertEquals( ret, 0, 'failed to role change. smr_id:%d' % (target['id']) ) # check value recovered_redis = redis_mgmt.Redis( target['id'] ) ret = recovered_redis .connect( target['ip'], target['redis_port'] ) self.assertEquals( ret, 0, 'failed to connect to redis' ) for i in range (0, 200): key = '%s%d' % (key_base, i) cmd = 'get %s\r\n' % (key) recovered_redis .write( cmd ) recovered_redis.read_until( '\r\n' ) response = recovered_redis.read_until( '\r\n' ) self.assertEqual( response, '%d\r\n' % i, 'inconsistent %s, %d' % (response, i) )