def test_delreplica_pid_group(self, pid_group, exp_msg): """ 一次删除好几个副本 :return: """ name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata('"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-7"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-7"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.delreplica(self.ns_leader, name, pid_group, 'ns_client', self.slave1) self.assertIn(exp_msg, rs2) if 'DelReplica ok' in rs2: time.sleep(15) rs3 = self.showtable(self.ns_leader, name) self.tid = int(rs3.keys()[0][1]) self.assertIn((name, str(self.tid), '6', self.slave1), rs3) self.assertNotIn((name, str(self.tid), '0', self.slave1), rs3) if pid_group == '0-3': self.assertNotIn((name, str(self.tid), '1', self.slave1), rs3) self.assertNotIn((name, str(self.tid), '2', self.slave1), rs3) self.assertNotIn((name, str(self.tid), '3', self.slave1), rs3) elif pid_group == '0,2,3': self.assertNotIn((name, str(self.tid), '2', self.slave1), rs3) self.assertNotIn((name, str(self.tid), '3', self.slave1), rs3) self.ns_drop(self.ns_leader, name)
def test_count_schema(self): """ schema表统计pk下的条数 :return: """ name = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(name), '"kAbsoluteTime"', 0, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'true'), ('column_desc', '"k3"', '"uint16"', 'false'), ) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) rs1 = self.ns_put_multi(self.ns_leader, name, 11, ['card0', 'mcc0', '15']) self.assertIn('Put ok', rs1) rs2 = self.ns_put_multi(self.ns_leader, name, 22, ['card0', 'mcc1', '16']) self.assertIn('Put ok', rs2) rs3 = self.ns_put_multi(self.ns_leader, name, 33, ['card1', 'mcc2', '20']) self.assertIn('Put ok', rs3) rs4 = self.ns_count(self.ns_leader, name, 'card0', 'k1') self.assertIn('count: 2', rs4) rs5 = self.ns_count(self.ns_leader, name, 'mcc1', 'k2') self.assertIn('count: 1', rs5) rs6 = self.ns_count(self.ns_leader, name, 'mcc1', 'k1') self.assertIn('count: 0', rs6) rs7 = self.ns_count(self.ns_leader, name, 'mcc1', 'card') self.assertIn('idx name not found', rs7)
def test_addreplica_pid_group(self, pid_group, exp_msg): """ 添加副本一次执行多个分片 :return: """ name = 't{}'.format(time.time()) infoLogger.info(name) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-5"', 'true')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.ns_addreplica(self.ns_leader, name, pid_group, self.slave1) self.assertIn(exp_msg, rs2) if 'AddReplica ok' in rs2: time.sleep(20) rs3 = self.showtable(self.ns_leader, name) self.tid = int(rs3.keys()[0][1]) self.assertIn((name, str(self.tid), '0', self.slave1), rs3) if pid_group == "0-3": self.assertIn((name, str(self.tid), '1', self.slave1), rs3) self.assertIn((name, str(self.tid), '2', self.slave1), rs3) self.assertIn((name, str(self.tid), '3', self.slave1), rs3) elif pid_group == '0,2,3': self.assertIn((name, str(self.tid), '2', self.slave1), rs3) self.assertIn((name, str(self.tid), '3', self.slave1), rs3) self.ns_drop(self.ns_leader, name)
def test_recoverendpoint_offline_master_failed(self): """ 主节点挂掉未启动,不可以手工recoverendpoint成功 :return: """ self.start_client(self.leader) metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} self.stop_client(self.leader) time.sleep(10) rs = self.recoverendpoint(self.ns_leader, self.leader) self.assertIn('failed', rs) self.ns_drop(self.ns_leader, name)
def test_makesnapshot_pid_notexist(self): """ pid不存在时,makesnapshot失败 :return: """ name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 8, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-3"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-3"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'true')) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) table_info = self.showtable(self.ns_leader, name) tid = table_info.keys()[0][1] pid = table_info.keys()[0][2] self.put(self.leader, tid, pid, 'testkey0', self.now(), 'testvalue0') rs3 = self.makesnapshot(self.ns_leader, name, 4, 'ns_client') self.assertIn('Fail to makesnapshot', rs3) self.ns_drop(self.ns_leader, name)
def test_ns_drop_table(self): """ 通过ns建的表,可以通过ns全部drop掉,drop后gettablestatus为空 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-7"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-7"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-7"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] rs3 = self.get_table_status(self.leader, tid, 0) infoLogger.info(rs3) self.assertNotEqual(rs3, None) self.ns_drop(self.ns_leader, name) time.sleep(2) rs2 = self.showtable(self.ns_leader, name) rs3 = self.get_table_status(self.leader, tid, 0) self.assertEqual(len(rs1), 24) self.assertEqual(rs2, {}) self.assertEqual(rs3, None)
def test_delreplica_drop_table(self): """ delreplica后droptable :return: """ name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata('"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-2"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-2"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.get_table_status(self.slave1) rs3 = self.showtable(self.ns_leader, name) tid = tid = int(rs3.keys()[0][1]) rs4 = self.delreplica(self.ns_leader, name, 0, 'ns_client', self.slave1) time.sleep(10) rs5 = self.showtable(self.ns_leader, name) rs6 = self.get_table_status(self.slave1) self.assertIn((name, str(tid), str(0), self.slave1), rs3) self.assertNotIn((name, str(tid), str(0), self.slave1), rs5) self.assertIn((tid, 0), rs2.keys()) self.assertNotIn((tid, 0), rs6.keys()) self.ns_drop(self.ns_leader, name)
def test_delreplica_not_alive(self): # RTIDB-201 """ 建表时带副本,然后删掉副本,showtable时不会再出现删掉的副本 :return: """ self.start_client(self.slave1) name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata('"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"merchant"', '"string"', 'true'), ('column_desc', '"amt"', '"double"', 'false'), ('column_desc', '"card"', '"string"', 'true'),) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.showtable(self.ns_leader, name) tid = rs2.keys()[0][1] self.stop_client(self.slave1) self.updatetablealive(self.ns_leader, name, '*', self.slave1, 'no') time.sleep(10) self.showtable(self.ns_leader, name) rs3 = self.delreplica(self.ns_leader, name, 0, 'ns_client', self.slave1) time.sleep(5) rs4 = self.showtable(self.ns_leader, name) self.start_client(self.slave1) time.sleep(10) self.assertIn('Fail to delreplica', rs3) self.assertEqual(rs4[(name, tid, '1', self.slave1)], ['follower', '100', 'no', 'kNoCompress']) self.ns_drop(self.ns_leader, name)
def test_create_name_too_many_field(self): """ 4000个字段 创建成功 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = '"large_table"' m = utils.gen_table_metadata( name, None, 144000, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"k1000"', '"string"', 'true'), ('column_desc', '"k1001"', '"double"', 'false'), ('column_desc', '"k1002"', '"int32"', 'true'), ) for num in range(1003, 4000): name = 'k' + str(num) m.append(('column_desc', [('name', '"' + name + '"'), ('type', '"int32"'), ('add_ts_idx', 'false')])) print(m[-1]) #self.assertTrue(False) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.run_client(self.ns_leader, 'create ' + metadata_path, 'ns_client') self.assertIn('Create table ok', rs1) self.ns_drop(self.ns_leader, name)
def test_no_replica_bug(self, *steps): # RTIDB-221 """ 没有副本的分片,挂掉后再恢复,会恢复为主节点 :param steps: :return: """ self.tname = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(self.tname), '"kAbsoluteTime"', 144000, 8, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"2-3"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"2-3"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) table_info = self.showtable(self.ns_leader, self.tname) self.tid = int(table_info.keys()[0][1]) self.pid = 1 for _ in range(10): self.put(self.leader, self.tid, self.pid, 'testkey0', self.now() + 90000, 'testvalue0') steps_dict = self.get_steps_dict() for i in steps: eval(steps_dict[i]) rs = self.showtable(self.ns_leader, self.tname) self.assertEqual( rs[(self.tname, str(self.tid), str(self.pid), self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.ns_drop(self.ns_leader, self.tname)
def test_create_partition_column_order(self, exp_msg, *eles): """ table_partition和column_desc的前后顺序测试,无论顺序如何,都会拼成完整的schema :param exp_msg: :param eles: :return: """ tname = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata('"' + tname + '"', '"kAbsoluteTime"', 144000, 8, *eles) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) infoLogger.info(rs) self.assertIn(exp_msg, rs) rs1 = self.showtable(self.ns_leader, tname) tid = rs1.keys()[0][1] infoLogger.info(rs1) self.assertEqual(rs1[(tname, tid, '0', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(tname, tid, '0', self.slave1)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(tname, tid, '2', self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) (schema, column_key) = self.showschema(self.slave1, tid, 0) self.assertEqual(len(schema), 3) self.assertEqual(len(column_key), 0) self.assertEqual(schema[0], ['0', 'k1', 'string', 'yes']) self.assertEqual(schema[1], ['1', 'k2', 'double', 'no']) self.assertEqual(schema[2], ['2', 'k3', 'int32', 'yes']) self.ns_drop(self.ns_leader, tname)
def test_addreplica_args_invalid(self, tname, pid, endpoint, exp_msg): # RTIDB-201 """ 建表时带副本,然后添加新副本时,参数异常检查 :return: """ name = 't{}'.format(time.time()) infoLogger.info(name) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) table_name = name if tname is None else tname tpid = 1 if pid is None else pid tendpoint = self.slave2 if endpoint is None else endpoint rs2 = self.addreplica(self.ns_leader, table_name, tpid, 'ns_client', tendpoint) self.assertIn(exp_msg, rs2) self.ns_drop(self.ns_leader, name)
def createtable_put(self): self.tname = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(self.tname), '"kAbsoluteTime"', 144000, 8, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-3"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"2-3"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertTrue('Create table ok', rs) self.multidimension_vk = { 'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue1'), 'k3': ('string', 1.1) } self.multidimension_scan_vk = {'k1': 'testvalue0'} table_info = self.showtable(self.ns_leader, self.tname) self.tid = int(table_info.keys()[0][1]) self.pid = 3 for _ in range(10): self.put(self.leader, self.tid, self.pid, 'testkey0', self.now() + 90000, 'testvalue0')
def test_addreplica_offline(self): """ 添加一个offline的副本,添加失败 :return: """ self.start_client(self.slave1) metadata_path = '{}/metadata.txt'.format(self.testpath) name = '"tname{}"'.format(time.time()) infoLogger.info(name) m = utils.gen_table_metadata( name, None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) self.stop_client(self.slave1) time.sleep(10) infoLogger.info(self.showtablet(self.ns_leader)) rs2 = self.addreplica(self.ns_leader, name, 1, 'ns_client', self.slave1) self.assertIn('Fail to addreplica', rs2) self.start_client(self.slave1) self.ns_drop(self.ns_leader, name)
def test_addreplica_no_snapshot(self): """ 没有snapshot,添加副本成功,数据追加成功 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) infoLogger.info(name) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.showtable(self.ns_leader, name) tid = rs2.keys()[0][1] rs3 = self.put(self.leader, tid, 1, 'testkey0', self.now() + 9999, 'testvalue0') self.assertIn('Put ok', rs3) rs4 = self.addreplica(self.ns_leader, name, 1, 'ns_client', self.slave1) self.assertIn('AddReplica ok', rs4) time.sleep(5) rs5 = self.showtable(self.ns_leader, name) self.assertIn((name, tid, '1', self.leader), rs5.keys()) self.assertIn((name, tid, '1', self.slave1), rs5.keys()) self.assertIn( 'testvalue0', self.scan(self.slave1, tid, 1, 'testkey0', self.now() + 9999, 1)) self.ns_drop(self.ns_leader, name)
def test_auto_failover_slave_exception(self, failover_reason): """ auto_failover=true:从节点挂掉或断网后,showtable中从节点is_alive为no auto_failover=true:从节点挂掉或断网后,showtablet中从节点为offline状态 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) rs1 = self.showtable(self.ns_leader) tid = rs1.keys()[0][1] self.confset(self.ns_leader, 'auto_failover', 'true') if failover_reason == 'killed': self.stop_client(self.slave1) elif failover_reason == 'network_failure': self.disconnectzk(self.slave1) time.sleep(5) rs2 = self.showtablet(self.ns_leader) rs3 = self.showtable(self.ns_leader) if failover_reason == 'killed': self.start_client(self.slave1) elif failover_reason == 'network_failure': self.connectzk(self.slave1) time.sleep(5) self.assertIn('kTabletOffline', rs2[self.slave1]) self.confset(self.ns_leader, 'auto_failover', 'false') self.assertEqual(rs3[(name, tid, '0', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '1', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '2', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '0', self.slave1)], ['follower', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '1', self.slave1)], ['follower', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '1', self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '2', self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) self.get_new_ns_leader() self.ns_drop(self.ns_leader, name)
def test_changeleader_master_killed(self): """ changeleader功能正常,主节点挂掉后,可以手工故障切换,切换成功后从节点可以同步数据 原主节点启动后可以手工recoversnapshot成功 :return: """ self.start_client(self.leader) metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] self.stop_client(self.leader) self.updatetablealive(self.ns_leader, name, '*', self.leader, 'no') time.sleep(5) self.changeleader(self.ns_leader, name, 0) time.sleep(5) rs2 = self.showtable(self.ns_leader) self.start_client(self.leader) time.sleep(1) self.assertEqual(rs2[(name, tid, '0', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '1', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) act1 = rs2[(name, tid, '0', self.slave1)] act2 = rs2[(name, tid, '0', self.slave2)] roles = [x[0] for x in [act1, act2]] self.assertEqual(roles.count('leader'), 1) self.assertEqual(roles.count('follower'), 1) leader_new = self.slave1 if 'leader' in act1 else self.slave2 follower = self.slave1 if 'follower' in act1 else self.slave2 rs2 = self.put(self.leader, tid, 1, 'testkey0', self.now(), 'testvalue0') rs3 = self.put(self.slave1, tid, 1, 'testkey0', self.now(), 'testvalue0') rs4 = self.put(leader_new, tid, 0, 'testkey0', self.now(), 'testvalue0') self.assertFalse('Put ok' in rs2) self.assertFalse('Put ok' in rs3) self.assertIn('Put ok', rs4) time.sleep(1) self.assertIn('testvalue0', self.scan(follower, tid, 0, 'testkey0', self.now(), 1)) self.ns_drop(self.ns_leader, name)
def test_recoverendpoint_need_restore(self): """ recoverendpoint恢复最初的表结构 :return: """ self.start_client(self.leader) metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-3"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"3"', 'true'), ('table_partition', '"{}"'.format(self.leader), '"3"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] rs = self.put(self.leader, tid, 0, '', self.now(), 'pk1' ,'v1', 'w1') self.assertIn('Put ok', rs) rs = self.put(self.leader, tid, 1, '', self.now(), 'pk2' ,'v2', 'w2') self.assertIn('Put ok', rs) time.sleep(1) self.stop_client(self.leader) time.sleep(10) self.offlineendpoint(self.ns_leader, self.leader) self.start_client(self.leader) time.sleep(3) self.recoverendpoint(self.ns_leader, self.leader, 'true') time.sleep(10) rs5 = self.showtable(self.ns_leader, name) self.assertEqual(rs5[(name, tid, '0', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs5[(name, tid, '1', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs5[(name, tid, '3', self.leader)], ['follower', '144000min', 'yes', 'kNoCompress']) rs = self.put(self.leader, tid, 0, '', self.now(), 'pk3' ,'v3', 'w5') self.assertIn('Put ok', rs) rs = self.put(self.leader, tid, 1, '', self.now(), 'pk4' ,'v4', 'w4') self.assertIn('Put ok', rs) time.sleep(1) self.assertIn('v1', self.scan(self.slave1, tid, 0, {'k1': 'pk1'}, self.now(), 1)) self.assertIn('v4', self.scan(self.slave1, tid, 1, {'k1': 'pk4'}, self.now(), 1)) self.ns_drop(self.ns_leader, name)
def test_offlineendpoint_alive(self): """ offlineendpoint传入alive状态节点, 执行成功 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"1-2"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"2-3"', 'false'), ('table_partition', '"{}"'.format(self.leader), '"4-6"', 'false'), ('table_partition', '"{}"'.format(self.slave1), '"4-6"', 'true'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs = self.showtable(self.ns_leader, name) tid = rs.keys()[0][1] rs = self.put(self.leader, tid, 1, '', self.now(), 'pk1', 'v2', 'v3') self.assertIn('Put ok', rs) rs = self.put(self.leader, tid, 2, '', self.now(), 'pk2', 'v5', 'v6') self.assertIn('Put ok', rs) time.sleep(1) rs2 = self.offlineendpoint(self.ns_leader, self.leader) self.assertIn("offline endpoint ok", rs2) time.sleep(10) rs3 = self.showtable(self.ns_leader, name) self.assertEqual(rs3[(name, tid, '0', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '1', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '2', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '3', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '1', self.slave1)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '3', self.slave2)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs3[(name, tid, '4', self.leader)], ['follower', '144000min', 'no', 'kNoCompress']) self.assertIn( 'v2', self.scan(self.slave1, tid, 1, {'k1': 'pk1'}, self.now(), 1)) self.assertIn( 'v5', self.scan(self.slave1, tid, 2, {'k1': 'pk2'}, self.now(), 1)) self.ns_drop(self.ns_leader, name)
def test_changeleader_and_makesnapshot(self): """ changeleader后,可以makesnapshot,未changeleader的无法makesnapshot :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-2"', 'false'), ('column_desc', '"merchant"', '"string"', 'true'), ('column_desc', '"amt"', '"double"', 'false'), ('column_desc', '"card"', '"string"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] self.put(self.leader, tid, 0, 'testkey0', self.now(), 'testvalue0') self.stop_client(self.leader) self.updatetablealive(self.ns_leader, name, '*', self.leader, 'no') time.sleep(10) self.changeleader(self.ns_leader, name, 0) time.sleep(2) rs2 = self.showtable(self.ns_leader, name) rs3 = self.makesnapshot(self.ns_leader, name, 0, 'ns_client') rs4 = self.makesnapshot(self.ns_leader, name, 1, 'ns_client') self.start_client(self.leader) time.sleep(10) self.assertEqual(rs2[(name, tid, '0', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '1', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.leader)], ['leader', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '0', self.slave1)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '1', self.slave1)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.slave1)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertIn('MakeSnapshot ok', rs3) self.assertIn('Fail to makesnapshot', rs4) mf = self.get_manifest(self.slave1path, tid, 0) self.assertEqual(mf['offset'], '1') self.assertTrue(mf['name']) self.assertEqual(mf['count'], '1') self.ns_drop(self.ns_leader, name)
def test_preview_schema(self): """ 预览schema表 :return: """ name = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(name), '"kAbsoluteTime"', 0, 8, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'true'), ('column_desc', '"k3"', '"uint16"', 'false'), ) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) rs1 = self.ns_put_multi(self.ns_leader, name, 11, ['card0', 'mcc0', '15']) self.assertIn('Put ok', rs1) rs2 = self.ns_put_multi(self.ns_leader, name, 22, ['card0', 'mcc1', '16']) self.assertIn('Put ok', rs2) rs3 = self.ns_put_multi(self.ns_leader, name, 33, ['card1', 'mcc2', '20']) self.assertIn('Put ok', rs3) rs4 = self.ns_preview(self.ns_leader, name, 2) self.assertEqual(2, len(rs4)) self.assertEqual(rs4[0]['k1'], 'card1') self.assertEqual(rs4[0]['k2'], 'mcc2') self.assertEqual(rs4[0]['k3'], '20') self.assertEqual(rs4[1]['k1'], 'card0') self.assertEqual(rs4[1]['k2'], 'mcc1') rs5 = self.ns_preview(self.ns_leader, name) self.assertEqual(3, len(rs5)) self.assertEqual(rs5[0]['k1'], 'card1') self.assertEqual(rs5[0]['k2'], 'mcc2') self.assertEqual(rs5[0]['k3'], '20') self.assertEqual(rs5[1]['k1'], 'card0') self.assertEqual(rs5[1]['k2'], 'mcc1') self.assertEqual(rs5[2]['k1'], 'card0') self.assertEqual(rs5[2]['k2'], 'mcc0')
def test_create_name_ttltype_ttl_seg(self, name, ttl_type, ttl, seg_cnt, exp_msg): """ name,ttp type,ttl和seg的参数检查 :param ttl_type: :param name: :param seg_cnt: :param ttl: :param exp_msg: :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( name, ttl_type, ttl, seg_cnt, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"1-2"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"double"', 'false'), ('column_desc', '"k3"', '"int32"', 'true'), ) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn(exp_msg, rs) d = { 'k1': ('string:index', 'testvalue0'), 'k2': ('double', 1.111), 'k3': ('int32:index', -20) } self.multidimension_vk = collections.OrderedDict( sorted(d.items(), key=lambda t: t[0])) self.multidimension_scan_vk = {'k1': 'testvalue0'} if exp_msg == 'Create table ok': table_info = self.showtable(self.ns_leader, name) tid = table_info.keys()[0][1] pid = 1 self.put(self.leader, tid, pid, 'testkey0', self.now() + 100, 'testvalue0') time.sleep(0.5) self.assertIn( 'testvalue0', self.scan(self.slave1, tid, pid, 'testkey0', self.now(), 1)) self.ns_drop(self.ns_leader, name)
def createtable_nofollower_put(self, data_count): self.tname = 'tname{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata( '"{}"'.format(self.tname), '"kAbsoluteTime"', 144000, 8, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) table_info = self.showtable(self.ns_leader, self.tname) self.tid = int(table_info.keys()[0][1]) self.pid = 3 self.put_large_datas(data_count, 7)
def test_delreplica_pid_group_error(self, exp_msg, pid_group, endpoint): """ 删除失败 :return: """ name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) m = utils.gen_table_metadata('"{}"'.format(name), '"kLatestTime"', 100, 8, ('table_partition', '"{}"'.format(self.leader), '"0-7"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-5"', 'false')) utils.gen_table_metadata_file(m, metadata_path) rs1 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs1) rs2 = self.delreplica(self.ns_leader, name, pid_group, 'ns_client', endpoint) self.assertIn(exp_msg, rs2)
def test_offlineendpoint_slave_killed(self): """ offlineendpoint功能正常,从节点挂掉后,副本可以被删掉 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) infoLogger.info(name) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-3"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"1-2"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"2-3"', 'false'), ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] self.stop_client(self.slave1) time.sleep(5) self.offlineendpoint(self.ns_leader, self.slave1) time.sleep(10) rs2 = self.showtable(self.ns_leader, name) # showtable ok self.assertEqual(rs2[(name, tid, '1', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '3', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '1', self.slave1)], ['follower', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.slave1)], ['follower', '144000min', 'no', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '2', self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs2[(name, tid, '3', self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) self.ns_drop(self.ns_leader, name)
def test_create_pid_group(self, pid_group1, pid_group2, exp_msg): """ pid_group参数测试 :param pid_group1: :param pid_group2: :param exp_msg: :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = '"tname{}"'.format(time.time()) infoLogger.info(name) table_partition1 = ('table_partition', '"{}"'.format(self.leader), pid_group1[0], pid_group1[1]) table_partition2 = ('table_partition', '"{}"'.format(self.slave1), pid_group2[0], pid_group2[1]) m = utils.gen_table_metadata(name, None, 144000, 2, table_partition1, table_partition2) utils.gen_table_metadata_file(m, metadata_path) rs = self.run_client(self.ns_leader, 'create ' + metadata_path, 'ns_client') infoLogger.info(rs) self.assertIn(exp_msg, rs) self.showtable(self.ns_leader, name) if exp_msg == 'Create table ok': for x in [(self.leader, pid_group1), (self.slave1, pid_group2)]: table_status = self.get_table_status(x[0]) tids = list(set(tpid[0] for tpid in table_status.keys())) tids.sort() pids = [ tpid[1] for tpid in table_status.keys() if tpid[0] == tids[-1] ] pid_group_start = int( x[1][0].split('-')[0][1:]) if '-' in x[1][0] else int( x[1][0][1:-1]) pid_group_end = int( x[1][0].split('-')[1][:-1]) if '-' in x[1][0] else int( x[1][0][1:-1]) infoLogger.info("*" * 88) infoLogger.info(tids) infoLogger.info(table_status.keys()) infoLogger.info(pids) for pid in range(pid_group_start, pid_group_end): self.assertIn(pid, pids) time.sleep(1) rs1 = self.ns_drop(self.ns_leader, name) self.assertIn('drop ok', rs1)
def test_changeleader_with_many_times(self, pid, switch, switch1, rsp_msg): """ 不当机更新leader,多次changeleader。有follower情况,change成功,无follow情况,change失败 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} rs1 = self.showtable(self.ns_leader) tid = rs1.keys()[0][1] self.assertEqual(rs1[(name, tid, str(pid), self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(name, tid, str(pid), self.slave1)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(name, tid, str(pid), self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) rs_change1 = self.changeleader(self.ns_leader, name, pid, switch) time.sleep(1) self.assertTrue('change leader ok' in rs_change1) rs_change2 = self.changeleader(self.ns_leader, name, pid, switch1) time.sleep(1) self.assertTrue('change leader ok' in rs_change2) rs_change3 = self.changeleader(self.ns_leader, name, pid, 'auto') self.assertTrue('failed to change leader. error msg: no alive follower' in rs_change3) rs_change4 = self.changeleader(self.ns_leader, name, pid, 'auto') self.assertTrue('failed to change leader. error msg: no alive follower' in rs_change4) rs_change5 = self.changeleader(self.ns_leader, name, pid, switch) self.assertTrue('failed to change leader. error msg: no alive follower' in rs_change5) rs_change6 = self.changeleader(self.ns_leader, name, pid, self.leader) self.assertTrue('failed to change leader. error msg: no alive follower' in rs_change6) self.ns_drop(self.ns_leader, name)
def test_makesnapshot_expired(self): """ 数据全部过期后, termid正常 makesnapshot功能正常,op是kMakeSnapshotOP :return: """ self.clear_ns_table(self.ns_leader) old_last_op_id = max(self.showopstatus(self.ns_leader).keys()) if self.showopstatus(self.ns_leader) != {} else 1 name = 't{}'.format(time.time()) metadata_path = '{}/metadata.txt'.format(self.testpath) pid_group = '"0"' m = utils.gen_table_metadata( '"{}"'.format(name), None, 1, 8, ('table_partition', '"{}"'.format(self.leader), pid_group, 'true'), ('table_partition', '"{}"'.format(self.slave1), pid_group, 'false'), ('table_partition', '"{}"'.format(self.slave2), pid_group, 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'true')) utils.gen_table_metadata_file(m, metadata_path) rs = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs) table_info = self.showtable(self.ns_leader, name) tid = table_info.keys()[0][1] pid = '0' self.put(self.leader, tid, pid, 'testkey0', self.now() - 120000, 'testvalue0') self.assertFalse("0" == "1") rs3 = self.makesnapshot(self.ns_leader, name, pid, 'ns_client') self.assertIn('MakeSnapshot ok', rs3) time.sleep(2) mf = self.get_manifest(self.leaderpath, tid, pid) self.assertEqual(mf['offset'], '1') self.assertTrue(mf['name']) self.assertEqual(mf['count'], '0') self.assertFalse(mf['term'] == '0') last_op_id = max(self.showopstatus(self.ns_leader).keys()) self.assertFalse(old_last_op_id == last_op_id) last_opstatus = self.showopstatus(self.ns_leader)[last_op_id] self.assertIn('kMakeSnapshotOP', last_opstatus) self.ns_drop(self.ns_leader, name)
def test_changeleader_auto_without_offline(self, pid, switch,rsp_msg): """ 不当机更新leader, auto模式(1 leader 2 follower)。在三个副本的情况下,进行changeleader 参数是auto,测试自动切换是否成功 :return: """ metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} rs1 = self.showtable(self.ns_leader) tid = rs1.keys()[0][1] self.assertEqual(rs1[(name, tid, str(pid), self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(name, tid, str(pid), self.slave1)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs1[(name, tid, str(pid), self.slave2)], ['follower', '144000min', 'yes', 'kNoCompress']) self.changeleader(self.ns_leader, name, pid, switch) time.sleep(1) rs2 = self.showtable(self.ns_leader) self.assertEqual(rs2[(name, tid, str(pid), self.leader)], ['leader', '144000min', rsp_msg, 'kNoCompress']) flag = 'false' if (rs2[(name, tid, str(pid), self.slave1)] == ['leader', '144000min', 'yes', 'kNoCompress'] and rs2[(name, tid, str(pid), self.slave2)] == ['follower', '144000min', 'yes', 'kNoCompress']): flag = 'true' if (rs2[(name, tid, str(pid), self.slave1)] == ['follower', '144000min', 'yes', 'kNoCompress'] and rs2[(name, tid, str(pid), self.slave2)] == ['leader', '144000min', 'yes', 'kNoCompress']): flag = 'true' self.assertEqual(flag, 'true') self.ns_drop(self.ns_leader, name)
def test_recoversnapshot_offline_master_after_changeleader(self): """ 主节点挂掉,手动故障切换成功后启动, 做了故障切换的分片,可以手工recovertable为follower 无副本的分片,手工recovertablet为leader :return: """ self.start_client(self.leader) metadata_path = '{}/metadata.txt'.format(self.testpath) name = 'tname{}'.format(time.time()) m = utils.gen_table_metadata( '"{}"'.format(name), None, 144000, 2, ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'), ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'), ('table_partition', '"{}"'.format(self.slave2), '"0-1"', 'false'), ('column_desc', '"k1"', '"string"', 'true'), ('column_desc', '"k2"', '"string"', 'false'), ('column_desc', '"k3"', '"string"', 'false') ) utils.gen_table_metadata_file(m, metadata_path) rs0 = self.ns_create(self.ns_leader, metadata_path) self.assertIn('Create table ok', rs0) self.multidimension_vk = {'k1': ('string:index', 'testvalue0'), 'k2': ('string', 'testvalue0'), 'k3': ('string', 'testvalue0')} self.multidimension_scan_vk = {'k1': 'testvalue0'} rs1 = self.showtable(self.ns_leader, name) tid = rs1.keys()[0][1] self.stop_client(self.leader) self.updatetablealive(self.ns_leader, name, '*', self.leader, 'no') time.sleep(5) self.changeleader(self.ns_leader, name, 0) self.changeleader(self.ns_leader, name, 1) self.start_client(self.leader) time.sleep(5) self.recoverendpoint(self.ns_leader, self.leader) time.sleep(10) rs5 = self.showtable(self.ns_leader, name) self.assertEqual(rs5[(name, tid, '0', self.leader)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs5[(name, tid, '1', self.leader)], ['follower', '144000min', 'yes', 'kNoCompress']) self.assertEqual(rs5[(name, tid, '2', self.leader)], ['leader', '144000min', 'yes', 'kNoCompress']) self.ns_drop(self.ns_leader, name)