Skip to content

Commit

Permalink
Merge pull request #840 from taosdata/fix/TS-5889-3.0
Browse files Browse the repository at this point in the history
taosBenchmark no retry for default and  add check write correct case
  • Loading branch information
zitsen authored Jan 18, 2025
2 parents 79495b0 + bc8b3c9 commit cde537a
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 14 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/3.0-coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,11 @@ jobs:
gcov -abcfu ${topdir}/taos-tools/src/benchData.c -o src/CMakeFiles/taosBenchmark.dir/benchData.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchInsert.c -o src/CMakeFiles/taosBenchmark.dir/benchInsert.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchJsonOpt.c -o src/CMakeFiles/taosBenchmark.dir/benchJsonOpt.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchOutput.c -o src/CMakeFiles/taosBenchmark.dir/benchOutput.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchQuery.c -o src/CMakeFiles/taosBenchmark.dir/benchQuery.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchTmq.c -o src/CMakeFiles/taosBenchmark.dir/benchTmq.c.gcno
gcov -abcfu ${topdir}/taos-tools/src/benchUtil.c -o src/CMakeFiles/taosBenchmark.dir/benchUtil.c.gcno
mkdir ${topdir}/coverage || :
lcov -c -d . -o ${topdir}/coverage/lcov-with-deps.info
lcov -r ${topdir}/coverage/lcov-with-deps.info "*/deps/*" -o ${topdir}/coverage/lcov.info
lcov -r ${topdir}/coverage/lcov-with-deps.info "*/src/tools*" -o ${topdir}/coverage/lcov.info
lcov --ignore-errors negative,unused -c -d . -o ${topdir}/coverage/lcov.info
- name: Publish to coveralls.io
if:
Expand Down
2 changes: 1 addition & 1 deletion src/benchCommandOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void initArgument() {
g_arguments->startTimestamp = DEFAULT_START_TIME;
g_arguments->partialColNum = 0;

g_arguments->keep_trying = 3;
g_arguments->keep_trying = 0;
g_arguments->trying_interval = 0;
g_arguments->iface = TAOSC_IFACE;
g_arguments->rest_server_ver_major = -1;
Expand Down
9 changes: 6 additions & 3 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,12 +1834,15 @@ int32_t submitStmt2(threadInfo * pThreadInfo, TAOS_STMT2_BINDV *bindv, int64_t *
break;
} else {
// failed to try
if (loop == 0) {
if (--loop == 0) {
// failed finally
errorPrint("finally faild execute submitStmt2() after retry %d \n", i);
char tip[64] = "";
if (i > 0) {
snprintf(tip, sizeof(tip), " after retry %d", i);
}
errorPrint("finally faild execute submitStmt2()%s\n", tip);
return -1;
}
loop --;

// wait a memont for trying
toolsMsleep(stbInfo->trying_interval);
Expand Down
14 changes: 8 additions & 6 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,20 @@ int postProceSqlImpl(char *sqlstr, char* dbName, int precision, int iface,
do {
bytes = recv(sockfd, responseBuf + received,
resp_len - received, 0);
if (bytes <= 0) {
errorPrint("%s", "reading no response from socket\n");
goto free_of_postImpl;
}
responseBuf[resp_len] = 0;
debugPrint("response buffer: %s\n", responseBuf);
debugPrint("response buffer: %s bytes=%d\n", responseBuf, bytes);
if (NULL != strstr(responseBuf, resEncodingChunk)) {
chunked = true;
}
int64_t index = strlen(responseBuf) - 1;
while (responseBuf[index] == '\n' || responseBuf[index] == '\r') {
if (index == 0) {
break;
}
index--;
}
debugPrint("index: %" PRId64 "\n", index);
Expand All @@ -555,11 +562,6 @@ int postProceSqlImpl(char *sqlstr, char* dbName, int precision, int iface,
break;
}

if (bytes <= 0) {
errorPrint("%s", "reading no response from socket\n");
goto free_of_postImpl;
}

received += bytes;

if (g_arguments->test_mode == INSERT_TEST) {
Expand Down
235 changes: 235 additions & 0 deletions tests/cases/insertReliability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-
import os
import json
import sys
import os
import time
import datetime
import platform
import subprocess

from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
from util.dnodes import tdDnodes


# reomve single and double quotation
def removeQuotation(origin):
value = ""
for c in origin:
if c != '\'' and c != '"':
value += c

return value

class TDTestCase:
def caseDescription(self):
"""
[TD-11510] taosBenchmark test cases
"""

def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)

def getPath(self, tool="taosBenchmark"):
selfPath = os.path.dirname(os.path.realpath(__file__))

if "community" in selfPath:
projPath = selfPath[: selfPath.find("community")]
elif "src" in selfPath:
projPath = selfPath[: selfPath.find("src")]
elif "/tools/" in selfPath:
projPath = selfPath[: selfPath.find("/tools/")]
else:
projPath = selfPath[: selfPath.find("tests")]

paths = []
for root, dummy, files in os.walk(projPath):
if (tool) in files:
rootRealPath = os.path.dirname(os.path.realpath(root))
if "packaging" not in rootRealPath:
paths.append(os.path.join(root, tool))
break
if len(paths) == 0:
tdLog.exit("taosBenchmark not found!")
return
else:
tdLog.info("taosBenchmark found in %s" % paths[0])
return paths[0]



def runSeconds(self, command, seconds, timeout = 180):

tdLog.info(f"run with {command} after seconds:{seconds} ...")
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(seconds)

# check have dbRows
for i in range(60):
# maybe db can not create , so need try
try:
rows = self.getDbRows(4)
except:
time.sleep(1)
continue

# check break condition
if rows > 0:
tdLog.info(f" runSecond loop = {i} wait db have record ok, records={rows}, break wait ...")
break

index = 1
tdLog.info(f"stop taosd index={index} ...")
tdDnodes.forcestop(index)

tdLog.info(f"wait taosbenchmark end ...")
process.wait(timeout)

tdLog.info(f"start taosd index={index} ...")
tdDnodes.startWithoutSleep(index)
tdLog.info(f"start taosd index={index} ok")

# get output
output = process.stdout.read().decode(encoding="gbk")
error = process.stderr.read().decode(encoding="gbk")
return output, error

def getKeyValue(self, content, key, end):
# find key
s = content.find(key)
if s == -1:
return False,""

# find end
s += len(key)
e = content.find(end, s)
if e == -1:
value = content[s : ]
else:
value = content[s : e]

return True, value

def getDbRows(self, times):
sql = f"select count(*) from {self.db}.meters"
tdSql.waitedQuery(sql, 1, times)
dbRows = tdSql.getData(0, 0)
return dbRows


def checkAfterRestart(self, command):
# taosc
output, error = self.runSeconds(command, 10)

#
# check succRows <= dbRows
#

# find value
key = "seconds to insert rows: "
result, value = self.getKeyValue(error, key, " ")
if result == False:
tdLog.exit(f"not found key:{key} value, content={error}")

succRows = int(value)
if succRows == 0:
tdLog.exit(f"key:{key} value:{value} is zero, content={error}")

# compare with database rows
dbRows = self.getDbRows(100)
if dbRows < succRows:
tdLog.exit(f"db rows less than insert success rows. {dbRows} < {succRows}")

# succ
tdLog.info(f"check write ok. succRows: {succRows} <= dbRows:{dbRows} command={command}")

#
# check no retry information
#
msgs = [
"milliseconds then re-insert",
"stmt2 start retry submit"
]

for msg in msgs:
pos = output.find(msg)
if pos != -1:
tdLog.exit(f"default not retry, buf found retry msg: {msg} pos={pos} content={output}")


def writeSuccCheck(self):
benchmark = self.getPath()
self.db = "relia"

#
# rest
#

# batch
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I rest -r 100 -y"
self.checkAfterRestart(command)
# interlace
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I rest -r 100 -B 1 -y"
self.checkAfterRestart(command)

#
# taosc
#

# batch
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I taosc -r 100 -y"
self.checkAfterRestart(command)
# interlace
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I taosc -r 100 -B 1 -y"
self.checkAfterRestart(command)

#
# stmt2
#

# batch
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I stmt2 -r 100 -y"
self.checkAfterRestart(command)
# interlace
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -I stmt2 -r 100 -B 1 -y"
self.checkAfterRestart(command)

#
# websocket
#

# batch
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -r 100 --cloud_dsn=http://localhost:6041 -y"
self.checkAfterRestart(command)
# interlace
command = f"{benchmark} -d {self.db} -t 100 -n 1000000 -r 100 -B 1 --cloud_dsn=http://localhost:6041 -y"
self.checkAfterRestart(command)


def run(self):
# restart taosd test
self.writeSuccCheck()


def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
18 changes: 18 additions & 0 deletions tests/pytest/util/dnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def startWithoutSleep(self):
)
if os.system(taosadapterCmd) != 0:
tdLog.exit(taosadapterCmd)
tdLog.debug(f"taosadapter run: {taosadapterCmd}")

if os.system(cmd) != 0:
tdLog.exit(cmd)
Expand Down Expand Up @@ -507,6 +508,23 @@ def stop(self):
tdLog.debug("dnode:%d is stopped by kill -INT" % (self.index))

def forcestop(self):
taosadapterToBeKilled = "taosadapter"

taosadapterPsCmd = (
"ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % taosadapterToBeKilled
)
taosadapterProcessID = subprocess.check_output(
taosadapterPsCmd, shell=True
).decode("utf-8")

while taosadapterProcessID:
taosadapterKillCmd = "kill -KILL %s > /dev/null 2>&1" % taosadapterProcessID
os.system(taosadapterKillCmd)
time.sleep(1)
taosadapterProcessID = subprocess.check_output(
taosadapterPsCmd, shell=True
).decode("utf-8")

if self.valgrind == 0:
toBeKilled = "taosd"
else:
Expand Down

0 comments on commit cde537a

Please sign in to comment.