mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
161 lines
4.9 KiB
Python
161 lines
4.9 KiB
Python
import time
|
|
from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck, clusterComCheck
|
|
|
|
|
|
class TestStableDnode:
|
|
|
|
def setup_class(cls):
|
|
tdLog.debug(f"start to execute {__file__}")
|
|
|
|
def test_stable_dnode(self):
|
|
"""Query: after restart
|
|
|
|
1. Start a 2-node cluster
|
|
2. Create a 1-replica database with 3 vgroups
|
|
3. Create one super table and 10 child tables; insert 20 rows into each
|
|
4. Stop dnode2 → expect queries to fail
|
|
5. Restart dnode2 → queries succeed and all data are present
|
|
|
|
Catalog:
|
|
- DataBase:Sync
|
|
|
|
Since: v3.0.0.0
|
|
|
|
Labels: common,ci
|
|
|
|
Jira: None
|
|
|
|
History:
|
|
- 2025-5-5 Simon Guan Migrated from tsim/vnode/stable_dnode2_stop.sim
|
|
- 2025-5-5 Simon Guan Migrated from tsim/vnode/stable_dnode2.sim
|
|
|
|
"""
|
|
|
|
clusterComCheck.checkDnodes(2)
|
|
tdSql.execute(f"alter dnode 1 'supportVnodes' '4'")
|
|
tdSql.execute(f"alter dnode 2 'supportVnodes' '4'")
|
|
|
|
clusterComCheck.checkDnodeSupportVnodes(1, 4)
|
|
clusterComCheck.checkDnodeSupportVnodes(2, 4)
|
|
|
|
clusterComCheck.checkDnodes(2)
|
|
|
|
tdLog.info(f"======================== dnode1 start")
|
|
|
|
dbPrefix = "d2_db"
|
|
tbPrefix = "d2_tb"
|
|
mtPrefix = "d2_mt"
|
|
tbNum = 10
|
|
rowNum = 20
|
|
totalNum = 200
|
|
|
|
tdLog.info(f"=============== step1")
|
|
i = 0
|
|
db = dbPrefix + str(i)
|
|
mt = mtPrefix + str(i)
|
|
|
|
tdSql.execute(f"create database {db} vgroups 3")
|
|
tdSql.execute(f"use {db}")
|
|
tdSql.execute(f"create table {mt} (ts timestamp, tbcol int) TAGS(tgcol int)")
|
|
|
|
i = 0
|
|
while i < tbNum:
|
|
tb = tbPrefix + str(i)
|
|
tdSql.execute(f"create table {tb} using {mt} tags( {i} )")
|
|
|
|
x = 0
|
|
while x < rowNum:
|
|
val = x * 60000
|
|
ms = 1519833600000 + val
|
|
tdSql.execute(f"insert into {tb} values ({ms} , {x} )")
|
|
x = x + 1
|
|
|
|
i = i + 1
|
|
|
|
tdSql.query(f"show vgroups")
|
|
tdLog.info(f"vgroups ==> {tdSql.getRows()})")
|
|
tdSql.checkRows(3)
|
|
|
|
sc.dnodeStop(2)
|
|
clusterComCheck.checkDnodes(1)
|
|
|
|
tdLog.info(f"=============== step2")
|
|
tdSql.error(f"select count(*) from {mt}")
|
|
tdSql.error(f"select count(tbcol) from {mt}")
|
|
|
|
sc.dnodeStart(2)
|
|
clusterComCheck.checkDnodes(2)
|
|
|
|
tdSql.query(f"select * from information_schema.ins_dnodes")
|
|
tdSql.checkRows(2)
|
|
tdSql.checkKeyData(1, 4, "ready")
|
|
tdSql.checkKeyData(2, 4, "ready")
|
|
|
|
i = 1
|
|
tb = tbPrefix + str(i)
|
|
|
|
tdSql.query(f"select count(*) from {tb}")
|
|
tdSql.checkData(0, 0, rowNum)
|
|
|
|
tdSql.query(f"select count(tbcol) from {tb}")
|
|
tdSql.checkData(0, 0, rowNum)
|
|
|
|
tdLog.info(f"=============== step3")
|
|
tdSql.query(f"select count(tbcol) from {tb} where ts <= 1519833840000")
|
|
tdSql.checkData(0, 0, 5)
|
|
|
|
tdLog.info(f"=============== step4")
|
|
tdSql.query(f"select count(tbcol) as b from {tb}")
|
|
tdSql.checkData(0, 0, rowNum)
|
|
|
|
tdLog.info(f"=============== step5")
|
|
tdSql.query(f"select _wstart, count(tbcol) as b from {tb} interval(1m)")
|
|
tdSql.checkData(0, 1, 1)
|
|
|
|
tdSql.query(f"select _wstart, count(tbcol) as b from {tb} interval(1d)")
|
|
tdSql.checkData(0, 1, rowNum)
|
|
|
|
tdLog.info(f"=============== step6")
|
|
tdSql.query(
|
|
f"select _wstart, count(tbcol) as b from {tb} where ts <= 1519833840000 interval(1m)"
|
|
)
|
|
|
|
tdSql.checkData(0, 1, 1)
|
|
|
|
tdSql.checkRows(5)
|
|
|
|
tdLog.info(f"=============== step7")
|
|
tdSql.query(f"select count(*) from {mt}")
|
|
tdSql.checkData(0, 0, totalNum)
|
|
|
|
tdSql.query(f"select count(tbcol) from {mt}")
|
|
tdSql.checkData(0, 0, totalNum)
|
|
|
|
tdLog.info(f"=============== step8")
|
|
tdSql.query(f"select count(tbcol) as c from {mt} where ts <= 1519833840000")
|
|
tdSql.checkData(0, 0, 50)
|
|
|
|
tdSql.query(f"select count(tbcol) as c from {mt} where tgcol < 5")
|
|
tdSql.checkData(0, 0, 100)
|
|
|
|
tdSql.query(
|
|
f"select count(tbcol) as c from {mt} where tgcol < 5 and ts <= 1519833840000"
|
|
)
|
|
tdSql.checkData(0, 0, 25)
|
|
|
|
tdLog.info(f"=============== step9")
|
|
tdSql.query(f"select _wstart, count(tbcol) as b from {mt} interval(1m)")
|
|
tdSql.checkData(0, 1, 10)
|
|
|
|
tdSql.query(f"select _wstart, count(tbcol) as b from {mt} interval(1d)")
|
|
tdSql.checkData(0, 1, 200)
|
|
|
|
tdLog.info(f"=============== step10")
|
|
tdSql.query(f"select count(tbcol) as b from {mt} group by tgcol")
|
|
tdSql.checkData(0, 0, rowNum)
|
|
tdSql.checkRows(tbNum)
|
|
|
|
tdLog.info(f"=============== clear")
|
|
tdSql.execute(f"drop database {db}")
|
|
tdSql.query(f"select * from information_schema.ins_databases")
|
|
tdSql.checkRows(2)
|