fix/TS-5251-add-conflic-check-fix-case

This commit is contained in:
dmchen 2024-11-11 09:54:56 +08:00
parent 3598b3b917
commit b1d5dc9e05
1 changed files with 59 additions and 52 deletions

View File

@ -19,63 +19,68 @@ import threading
class TDTestCase(TBase): class TDTestCase(TBase):
def init(self, conn, logSql, replicaVar=1): def init(self, conn, logSql, replicaVar=1):
tdLog.debug(f"start to init {__file__}") tdLog.debug(f"start to init {__file__}")
self.replicaVar = int(replicaVar) self.replicaVar = int(replicaVar)
tdSql.init(conn.cursor(), logSql) # output sql.txt file tdSql.init(conn.cursor(), logSql) # output sql.txt file
self.configJsonFile('splitVgroupByLearner.json', 'db', 4, 1, 'splitVgroupByLearner.json', 100000) self.configJsonFile('splitVgroupByLearner.json', 'db', 4, 1, 'compactDBConflict.json', 100000)
def configJsonFile(self, fileName, dbName, vgroups, replica, newFileName='', insert_rows=100000, def configJsonFile(self, fileName, dbName, vgroups, replica, newFileName='', insert_rows=100000,
timestamp_step=10000): timestamp_step=10000):
tdLog.debug(f"configJsonFile {fileName}") tdLog.debug(f"configJsonFile {fileName}")
filePath = etool.curFile(__file__, fileName) filePath = etool.curFile(__file__, fileName)
with open(filePath, 'r') as f: with open(filePath, 'r') as f:
data = json.load(f) data = json.load(f)
if len(newFileName) == 0: if len(newFileName) == 0:
newFileName = fileName newFileName = fileName
data['databases'][0]['dbinfo']['name'] = dbName data['databases'][0]['dbinfo']['name'] = dbName
data['databases'][0]['dbinfo']['vgroups'] = vgroups data['databases'][0]['dbinfo']['vgroups'] = vgroups
data['databases'][0]['dbinfo']['replica'] = replica data['databases'][0]['dbinfo']['replica'] = replica
data['databases'][0]['super_tables'][0]['insert_rows'] = insert_rows data['databases'][0]['super_tables'][0]['insert_rows'] = insert_rows
data['databases'][0]['super_tables'][0]['timestamp_step'] = timestamp_step data['databases'][0]['super_tables'][0]['timestamp_step'] = timestamp_step
json_data = json.dumps(data) json_data = json.dumps(data)
filePath = etool.curFile(__file__, newFileName) filePath = etool.curFile(__file__, newFileName)
with open(filePath, "w") as file: with open(filePath, "w") as file:
file.write(json_data) file.write(json_data)
tdLog.debug(f"configJsonFile {json_data}") tdLog.debug(f"configJsonFile {json_data}")
def insertData(self, configFile): def insertData(self, configFile):
tdLog.info(f"insert data.") tdLog.info(f"insert data.")
# taosBenchmark run # taosBenchmark run
jfile = etool.curFile(__file__, configFile) jfile = etool.curFile(__file__, configFile)
etool.benchMark(json=jfile) etool.benchMark(json=jfile)
def run(self): def run(self):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
self.insertData('splitVgroupByLearner.json') self.insertData('splitVgroupByLearner.json')
tdSql.execute('use db') tdSql.execute('use db')
t0 = threading.Thread(target=self.compactDBThread) event0 = threading.Event()
t0 = threading.Thread(target=self.compactDBThread, args=(event0))
t0.start() t0.start()
tdLog.debug("threading started!!!!!") tdLog.debug("threading started!!!!!")
event0.wait()
tdSql.error('ALTER DATABASE db REPLICA 3;', expectErrInfo="Transaction not completed due to conflict with compact") tdSql.error('ALTER DATABASE db REPLICA 3;', expectErrInfo="Transaction not completed due to conflict with compact")
t0.join() t0.join()
t1 = threading.Thread(target=self.compactDBThread) event1 = threading.Event()
t1 = threading.Thread(target=self.compactDBThread, args=(event1))
t1.start() t1.start()
tdLog.debug("threading started!!!!!") tdLog.debug("threading started!!!!!")
time.sleep(1) event1.wait()
tdSql.error('REDISTRIBUTE VGROUP 5 DNODE 1;', expectErrInfo="Transaction not completed due to conflict with compact") tdSql.error('REDISTRIBUTE VGROUP 5 DNODE 1;', expectErrInfo="Transaction not completed due to conflict with compact")
t1.join() t1.join()
t2 = threading.Thread(target=self.compactDBThread) event2 = threading.Event()
t2 = threading.Thread(target=self.compactDBThread, args=(event2))
t2.start() t2.start()
tdLog.debug("threading started!!!!!") tdLog.debug("threading started!!!!!")
event2.wait()
rowLen = tdSql.query('show vgroups') rowLen = tdSql.query('show vgroups')
if rowLen > 0: if rowLen > 0:
vgroupId = tdSql.getData(0, 0) vgroupId = tdSql.getData(0, 0)
@ -83,10 +88,11 @@ class TDTestCase(TBase):
tdSql.error('REDISTRIBUTE VGROUP 5 DNODE 1;', expectErrInfo="Transaction not completed due to conflict with compact") tdSql.error('REDISTRIBUTE VGROUP 5 DNODE 1;', expectErrInfo="Transaction not completed due to conflict with compact")
t2.join() t2.join()
t3 = threading.Thread(target=self.compactDBThread) event3 = threading.Event()
t3 = threading.Thread(target=self.compactDBThread, args=(event3))
t3.start() t3.start()
tdLog.debug("threading started!!!!!") tdLog.debug("threading started!!!!!")
time.sleep(1) event3.wait()
tdSql.error('BALANCE VGROUP;', expectErrInfo="Transaction not completed due to conflict with compact") tdSql.error('BALANCE VGROUP;', expectErrInfo="Transaction not completed due to conflict with compact")
t3.join() t3.join()
@ -119,31 +125,32 @@ class TDTestCase(TBase):
t7.join() t7.join()
def compactDBThread(self): def compactDBThread(self, event):
tdLog.info("compact db start") tdLog.info("compact db start")
tdSql.execute('compact DATABASE db') tdSql.execute('compact DATABASE db')
if self.waitCompactsZero() is False: event.set()
tdLog.info(f"compact not finished") if self.waitCompactsZero() is False:
tdLog.info(f"compact not finished")
def alterDBThread(self): def alterDBThread(self):
tdLog.info("alter db start") tdLog.info("alter db start")
tdSql.execute('ALTER DATABASE db REPLICA 3') tdSql.execute('ALTER DATABASE db REPLICA 3')
if self.waitTransactionZero() is False: if self.waitTransactionZero() is False:
tdLog.info(f"transaction not finished") tdLog.info(f"transaction not finished")
def balanceVGROUPThread(self): def balanceVGROUPThread(self):
tdLog.info("balance VGROUP start") tdLog.info("balance VGROUP start")
tdSql.execute('BALANCE VGROUP') tdSql.execute('BALANCE VGROUP')
if self.waitTransactionZero() is False: if self.waitTransactionZero() is False:
tdLog.info(f"transaction not finished") tdLog.info(f"transaction not finished")
def RedistributeVGroups(self): def RedistributeVGroups(self):
sql = f"REDISTRIBUTE VGROUP 5 DNODE 1" sql = f"REDISTRIBUTE VGROUP 5 DNODE 1"
tdSql.execute(sql, show=True) tdSql.execute(sql, show=True)
if self.waitTransactionZero() is False: if self.waitTransactionZero() is False:
tdLog.exit(f"{sql} transaction not finished") tdLog.exit(f"{sql} transaction not finished")
return False return False
sql = f"REDISTRIBUTE VGROUP 4 DNODE 1" sql = f"REDISTRIBUTE VGROUP 4 DNODE 1"
tdSql.execute(sql, show=True) tdSql.execute(sql, show=True)
if self.waitTransactionZero() is False: if self.waitTransactionZero() is False:
@ -158,7 +165,7 @@ class TDTestCase(TBase):
return True return True
def splitVgroupThread(self): def splitVgroupThread(self):
rowLen = tdSql.query('show vgroups') rowLen = tdSql.query('show vgroups')
if rowLen > 0: if rowLen > 0:
vgroupId = tdSql.getData(0, 0) vgroupId = tdSql.getData(0, 0)
@ -169,9 +176,9 @@ class TDTestCase(TBase):
if self.waitTransactionZero() is False: if self.waitTransactionZero() is False:
tdLog.info(f"transaction not finished") tdLog.info(f"transaction not finished")
def stop(self): def stop(self):
tdSql.close() tdSql.close()
tdLog.success(f"{__file__} successfully executed") tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())