Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions test/cases/02-Databases/01-Create/test_db_basic1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def test_database_basic1(self):
1. Create database with vgroup option
2. Show vgroups
3. Show vnodes

Catalog:
- Databases:Create
4. Create same name db and drop loop 100 times(TD-25762)

Since: v3.0.0.0

Expand All @@ -25,6 +23,7 @@ def test_database_basic1(self):

History:
- 2025-5-12 Simon Guan Migrated from tsim/db/basic1.sim
- 2025-11-04 Alex Duan Migrated from uncatalog/system-test/0-others/test_create_same_name_db.py

"""

Expand Down Expand Up @@ -144,3 +143,15 @@ def test_database_basic1(self):

tdSql.query(f"show d5.vgroups")
tdSql.checkRows(5)

# test_create_same_name_db.py
self.do_create_same_name_db()

def do_create_same_name_db(self):
try:
# create same name database multiple times
for i in range(100):
tdSql.execute(f"create database db")
tdSql.execute(f"drop database db")
except Exception as ex:
tdLog.exit(str(ex))
604 changes: 604 additions & 0 deletions test/cases/02-Databases/01-Create/test_db_cachemode.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import threading
import platform

class TestDbCompact:

class TestCompactAuto:
def setup_class(cls):
tdLog.debug("start to execute %s" % __file__)
cls.default_compact_options = [ "0d", "0d,0d", "0h"]
cls.compact_options = [["db00", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"],
["db01", "0m", "-2d,-1", "0", "0d", "-2d,-1d", "0h"],
Expand All @@ -20,6 +19,78 @@ def setup_class(cls):
["db05", "2", "-61,-1440h", "23h", "2d", "-61d,-60d", "23h"],
]

#
# ------------------- test_compact.py ----------------
#
def do_compact(self):
tdSql.query("CREATE DATABASE power KEEP 365 DURATION 10 BUFFER 16 WAL_LEVEL 1 vgroups 1 replica 1;")

tdSql.query("CREATE DATABASE power1 KEEP 365 DURATION 10 BUFFER 16 WAL_LEVEL 1 vgroups 1 replica 1;")

#first
tdSql.query("compact database power;")

tdLog.info("compact id:%d"%tdSql.queryResult[0][1])

tdSql.query("show compact %d;"%tdSql.queryResult[0][1])

tdLog.info("detail:%d"%tdSql.queryRows)

#second
tdSql.query("compact database power1;")

tdLog.info("compact id:%d"%tdSql.queryResult[0][1])

tdSql.query("show compact %d;"%tdSql.queryResult[0][1])

tdLog.info("detail:%d"%tdSql.queryRows)


#kill
tdSql.query("show compacts;")
number1 = tdSql.queryResult[0][0]
number2 = tdSql.queryResult[1][0]

#first
tdLog.info("kill compact %d;"%number1)
tdSql.query("kill compact %d;"%number1)

#second
tdLog.info("kill compact %d;"%number2)
tdSql.query("kill compact %d;"%number2)


#show
count = 0
tdLog.info("query progress")
while count < 50:
tdSql.query("show compact %d;"%number1)

row1 = tdSql.queryRows

tdSql.query("show compact %d;"%number2)

row2 = tdSql.queryRows

tdLog.info("compact%d:detail count:%d"%(number1, row1))
tdLog.info("compact%d:detail count:%d"%(number2, row2))

if row1 == 0 and row2 == 0 :
break

time.sleep(1)

count +=1
#tdLog.info("loop%d"%count)

if row1 != 0 or row2 != 0:
tdLog.exit("compact failed")

print("\ndo compact ............................ [passed]")

#
# ------------------- test_compact_auto.py ----------------
#
def create_db_compact(self):
tdLog.info("create db compact options")
for item in self.compact_options:
Expand Down Expand Up @@ -150,28 +221,216 @@ def compact_error(self):
tdSql.error(f"alter database db {item[0]}", expectErrInfo=item[1], fullMatched=False)
tdSql.execute('drop database db')

def test_compact_auto(self):
"""summary: xxx
def do_compact_auto(self):
self.create_db_compact()
self.alter_db_compact()
self.compact_error()

description: xxx
print("do compact auto ....................... [passed]")

Since: xxx
#
# ------------------- test_compact_vgroups.py ----------------
#
# Test cases ======================
def run_compact_vgroups_error(self):
# invalid sql
sql = "compact vgroups;"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

Labels: xxx
# invalid sql
sql = "compact vgroups in"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

Jira: xxx
# invalid sql
sql = "compact vgroups in ()"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

Catalog:
- xxx:xxx
# error without using database
sql = "compact vgroups in (2)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

History:
- xxx
- xxx
"""
self.create_db_compact()
self.alter_db_compact()
self.compact_error()
# error with duplicate vgroup
sql = "compact db1.vgroups in (2, 2)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

# error with invalid vgroup id
sql = "compact db1.vgroups in (0, -1)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

tdLog.success(f"{__file__} successfully executed")
# error to compact vgroups not in the same dat
sql = "compact db1.vgroups in (7, 8)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

# error to compact vgroups not in the same database
sql = "compact db1.vgroups in (2, 5, 8)"
tdLog.info(f"expect error SQL: {sql}")
tdSql.error(sql)

def waitCompactFinish(self):
while True:
sql = 'show compacts'
rows = tdSql.query(sql)
if rows == 0:
break
time.sleep(1)

def run_compact_vgroups_sql(self):
# make sure there is no compacts
sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 0)

# use db1 and compact with db name should be ok
sql = 'use db1'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)

sql = 'compact vgroups in (2)'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)

# check there should be one row in compacts
sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)

compactId = tdSql.getData(0, 0)

# query the compact status
sql = f'show compact {compactId}'
tdLog.info(f'expect success SQL: {sql}')
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)
tdSql.checkEqual(tdSql.getData(0, 0), compactId) # compact_id
tdSql.checkEqual(tdSql.getData(0, 1), 2) # vgroup_id

# wait for compact finish
self.waitCompactFinish()

# start a new compact
sql = 'compact db2.vgroups in (7, 10)'
tdLog.info(f'expect success SQL: {sql}')
tdSql.execute(sql)

sql = 'show compacts'
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 1)

compactId = tdSql.getData(0, 0)
sql = f'show compact {compactId}'
tdLog.info(f'expect success SQL: {sql}')
rows = tdSql.query(sql)
tdSql.checkEqual(rows, 2)
tdSql.checkEqual(tdSql.getData(0, 1) in (7, 10), True)
tdSql.checkEqual(tdSql.getData(1, 1) in (7, 10), True)
tdSql.checkEqual(tdSql.getData(0, 1) != tdSql.getData(1, 1), True)

# wait for compact finish
self.waitCompactFinish()

def do_compact_vgroups(self):
# create database db1
sql = "create database db1 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)

# create database db2
sql = "create database db2 vgroups 5"
tdLog.info(sql)
tdSql.execute(sql)

# error test
self.run_compact_vgroups_error()

# success to compact vgroups
self.run_compact_vgroups_sql()
print("do compact vgroups .................... [passed]")

#
# ------------------- main ----------------
#
def do_compact_col(self):
tdSql.execute("drop database if exists tbname_vgroup")
tdSql.execute("create database if not exists tbname_vgroup")
tdSql.execute('use tbname_vgroup')
tdSql.execute('drop database if exists dbvg')
tdSql.execute('create database dbvg vgroups 8;')

tdSql.execute('use dbvg;')

tdSql.execute('create table st(ts timestamp, f int) tags (t int);')

tables = []
tables.append("ct1 using st tags(1) values('2021-04-19 00:00:01', 1)")
tables.append("ct2 using st tags(2) values('2021-04-19 00:00:02', 2)")
tables.append("ct3 using st tags(3) values('2021-04-19 00:00:03', 3)")
tables.append("ct4 using st tags(4) values('2021-04-19 00:00:04', 4)")

sql = "insert into " + " ".join(tables)
tdSql.execute(sql)

tdSql.execute('create table st2(ts timestamp, f int) tags (t int);')

tables = []
tables.append("ct21 using st2 tags(1) values('2021-04-19 00:00:01', 1)")
tables.append("ct22 using st2 tags(2) values('2021-04-19 00:00:02', 2)")
tables.append("ct23 using st2 tags(3) values('2021-04-19 00:00:03', 3)")
tables.append("ct24 using st2 tags(4) values('2021-04-19 00:00:04', 4)")

sql = "insert into " + " ".join(tables)
tdSql.execute(sql)

col_names = tdSql.getColNameList("compact database tbname_vgroup")
if col_names[0] != "result":
raise Exception("first column name of compact result shall be result")

col_names = tdSql.getColNameList("show variables")
if col_names[0] != "name":
raise Exception("first column name of compact result shall be name")

tdSql.execute('drop database tbname_vgroup')

print("do compact cols ....................... [passed]")

#
# ------------------- main ----------------
#
def test_db_compact(self):
"""Database compact

1. Compact a empty database and verify no error occurs
2. Show compacts and get compact id
3. Show compact with the compact id and verify the result
4. Kill the compact operation and verify it is killed successfully
5. Create databases with different compact options
6. Verify the compact options are set correctly
7. Alter the compact options and verify the options are changed correctly
8. Verify error handling for invalid compact options
9. Create databases with vgroups
10. Compact specific vgroups and verify the operation is successful
11. Verify "compact database" command can return column names correctly

Since: v3.0.0.0

Labels: common,ci

Jira: None

History:
- 2025-11-03 Alex Duan Migrated from uncatalog/system-test/0-others/test_compact.py
- 2025-11-03 Alex Duan Migrated from uncatalog/system-test/0-others/test_compact_auto.py
- 2025-11-03 Alex Duan Migrated from uncatalog/system-test/0-others/test_compact_vgroups.py
- 2025-11-04 Alex Duan Migrated from uncatalog/system-test/2-query/test_compact_col.py

"""
self.do_compact_vgroups()
self.do_compact()
self.do_compact_auto()
self.do_compact_col()
Loading
Loading