TDengine/test/cases/70-Cluster/test_4dnode1mnode_basic_replica3_insertdatas.py

169 lines
6.4 KiB
Python
Raw Normal View History

2022-07-22 08:29:22 +00:00
# author : wenzhouwww
2025-07-09 03:38:11 +00:00
from new_test_framework.utils import tdLog, tdSql
2022-07-22 08:29:22 +00:00
import sys
2022-07-30 03:33:39 +00:00
import os
2022-07-22 08:29:22 +00:00
sys.path.append(os.path.dirname(__file__))
2025-07-09 03:38:11 +00:00
class Test4dnode1mnodeBasicReplica3Insertdatas:
def setup_class(cls):
2022-07-22 08:29:22 +00:00
tdLog.debug(f"start to excute {__file__}")
2025-07-09 03:38:11 +00:00
cls.mnode_list = {}
cls.dnode_list = {}
cls.ts = 1483200000000
cls.db_name ='testdb'
cls.replica = 3
cls.vgroups = 2
cls.tb_nums = 10
cls.row_nums = 100
2022-07-22 08:29:22 +00:00
def check_setup_cluster_status(self):
2022-08-11 13:21:59 +00:00
tdSql.query("select * from information_schema.ins_mnodes")
2022-07-22 08:29:22 +00:00
for mnode in tdSql.queryResult:
name = mnode[1]
info = mnode
self.mnode_list[name] = info
2022-08-11 13:55:20 +00:00
tdSql.query("select * from information_schema.ins_dnodes")
2022-07-22 08:29:22 +00:00
for dnode in tdSql.queryResult:
name = dnode[1]
info = dnode
self.dnode_list[name] = info
count = 0
is_leader = False
mnode_name = ''
for k,v in self.mnode_list.items():
count +=1
# only for 1 mnode
mnode_name = k
if v[2] =='leader':
is_leader=True
if count==1 and is_leader:
2022-07-25 10:06:46 +00:00
tdLog.notice("===== depoly cluster success with 1 mnode as leader =====")
2022-07-22 08:29:22 +00:00
else:
2022-11-24 03:43:54 +00:00
tdLog.notice("===== depoly cluster fail with 1 mnode as leader =====")
2022-07-22 08:29:22 +00:00
for k ,v in self.dnode_list.items():
if k == mnode_name:
if v[3]==0:
2022-07-25 10:06:46 +00:00
tdLog.notice("===== depoly cluster mnode only success at {} , support_vnodes is {} ".format(mnode_name,v[3]))
2022-07-22 08:29:22 +00:00
else:
2022-11-24 03:43:54 +00:00
tdLog.notice("===== depoly cluster mnode only fail at {} , support_vnodes is {} ".format(mnode_name,v[3]))
2022-07-22 08:29:22 +00:00
else:
continue
def create_db_check_vgroups(self):
tdSql.execute("drop database if exists test")
2024-10-24 01:16:24 +00:00
tdSql.execute("create database if not exists test replica 1 duration 100")
2022-07-22 08:29:22 +00:00
tdSql.execute("use test")
tdSql.execute(
'''create table stb1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
tags (t1 int)
'''
)
tdSql.execute(
'''
create table t1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
'''
)
2022-07-30 03:33:39 +00:00
2022-07-22 08:29:22 +00:00
for i in range(5):
tdSql.execute("create table sub_tb_{} using stb1 tags({})".format(i,i))
tdSql.query("show stables")
tdSql.checkRows(1)
tdSql.query("show tables")
tdSql.checkRows(6)
tdSql.query("show test.vgroups;")
vgroups_infos = {} # key is id: value is info list
for vgroup_info in tdSql.queryResult:
vgroup_id = vgroup_info[0]
tmp_list = []
for role in vgroup_info[3:-4]:
2022-12-01 05:48:51 +00:00
if role in ['leader', 'leader*', 'leader**', 'follower']:
2022-07-22 08:29:22 +00:00
tmp_list.append(role)
vgroups_infos[vgroup_id]=tmp_list
for k , v in vgroups_infos.items():
2022-12-01 05:48:51 +00:00
if len(v) == 1 and v[0] in ['leader', 'leader*', 'leader**']:
2022-07-25 10:06:46 +00:00
tdLog.notice(" === create database replica only 1 role leader check success of vgroup_id {} ======".format(k))
2022-07-22 08:29:22 +00:00
else:
2022-11-24 03:43:54 +00:00
tdLog.notice(" === create database replica only 1 role leader check fail of vgroup_id {} ======".format(k))
2022-07-22 08:29:22 +00:00
def create_db_replica_3_insertdatas(self, dbname, replica_num ,vgroup_nums ,tb_nums , row_nums ):
drop_db_sql = "drop database if exists {}".format(dbname)
create_db_sql = "create database {} replica {} vgroups {}".format(dbname,replica_num,vgroup_nums)
2022-07-25 10:06:46 +00:00
tdLog.notice(" ==== create database {} and insert rows begin =====".format(dbname))
2022-07-22 08:29:22 +00:00
tdSql.execute(drop_db_sql)
tdSql.execute(create_db_sql)
tdSql.execute("use {}".format(dbname))
tdSql.execute(
'''create table stb1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp)
tags (t1 int)
'''
)
tdSql.execute(
'''
create table t1
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp)
'''
)
2022-07-30 03:33:39 +00:00
2022-07-22 08:29:22 +00:00
for i in range(tb_nums):
sub_tbname = "sub_tb_{}".format(i)
tdSql.execute("create table {} using stb1 tags({})".format(sub_tbname,i))
# insert datas about new database
for row_num in range(row_nums):
ts = self.ts + 1000*row_num
tdSql.execute(f"insert into {sub_tbname} values ({ts}, {row_num} ,{row_num}, 10 ,1 ,{row_num} ,{row_num},true,'bin_{row_num}','nchar_{row_num}',now) ")
2022-07-25 10:06:46 +00:00
tdLog.notice(" ==== create database {} and insert rows execute end =====".format(dbname))
2022-07-22 08:29:22 +00:00
def check_insert_status(self, dbname, tb_nums , row_nums):
tdSql.execute("use {}".format(dbname))
tdSql.query("select count(*) from {}.{}".format(dbname,'stb1'))
tdSql.checkData(0 , 0 , tb_nums*row_nums)
tdSql.query("select distinct tbname from {}.{}".format(dbname,'stb1'))
tdSql.checkRows(tb_nums)
2025-07-09 03:38:11 +00:00
def test_4dnode1mnode_basic_replica3_insertdatas(self):
"""Cluster 4 dnodes 1 mnode replica 3 insert
1. Create 4 node and 1 mnode cluster
2. Ensure above cluster setup success
3. Check mnode is leader and only 1 mnode
4. Create database with replica 3
5. Create 1 super table and 1 normal table
6. Create 5 subtables using super table
7. Ensure above tables created success
8. Insert each subtable 100 rows data
9. Check vgroups info , ensure each vgroup only has 1 leader role
2025-07-09 03:38:11 +00:00
Since: v3.0.0.0
2025-07-09 03:38:11 +00:00
Labels: common,ci
2025-07-09 03:38:11 +00:00
Jira: None
2025-07-09 05:39:20 +00:00
2025-07-09 03:38:11 +00:00
History:
- 2025-11-01 Alex Duan Migrated from uncatalog/system-test/6-cluster/test_4dnode1mnode_basic_replica3_insertdatas.py
2025-07-09 03:38:11 +00:00
"""
2022-07-22 08:29:22 +00:00
self.check_setup_cluster_status()
self.create_db_check_vgroups()
self.create_db_replica_3_insertdatas(self.db_name , self.replica , self.vgroups , self.tb_nums , self.row_nums)
self.check_insert_status(self.db_name , self.tb_nums , self.row_nums)
tdLog.success(f"{__file__} successfully executed")