Skip to content

Commit

Permalink
fix: taosbenchmark benchinsert coverity scan (#588)
Browse files Browse the repository at this point in the history
* fix: taosbenchmark coverity scan issues

* fix: taosbenchmark coverity scan issues

* fix: compile warning

* fix: benchinsert coverity scan issue

* fix: remove werror from src/CMakeLists.txt for alpine

* fix: for alpine compile

* fix: change test branch

* fix: more coverity scan issues
  • Loading branch information
sangshuduo committed Feb 23, 2023
1 parent 61cbfd2 commit 1fe8e6f
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/3.0-alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
|| github.event_name == 'push'
shell: alpine.sh --root {0}
run: |
git clone --branch 3.0 --depth 1 https://github.com/taosdata/TDengine > /dev/null || exit 1
git clone --branch fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan --depth 1 https://github.com/taosdata/TDengine > /dev/null || exit 1
cd TDengine && mkdir debug && cd debug && cmake .. -DBUILD_TOOLS=true -DTOOLS_BUILD_TYPE=${{env.TOOLS_BUILD_TYPE}} -DBUILD_HTTP=false && make -j8 && make install
if [[ ! -f /usr/local/taos/bin/taosd ]] || [[ ! -f /usr/local/taos/bin/taos ]]
then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-macos-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-non-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
echo "clone TDengine 3.0 on ${{ steps.setup.outputs.uname }}"
git clone --branch chore/sangshuduo/TD-22652-stringop-overflow --depth 1 https://github.com/taosdata/TDengine > /dev/null || exit 1
git clone --branch fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan --depth 1 https://github.com/taosdata/TDengine > /dev/null || exit 1
echo "build TDengine 3.0 on ${{ steps.setup.outputs.uname }}"
cd TDengine || exit 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-taosBenchmark-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-taosBenchmark-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-taosdump-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-taosdump-release-ws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-taosdump-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: Change time zone
if:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/3.0-windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
with:
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'chore/sangshuduo/TD-22652-stringop-overflow'
ref: 'fix/sangshuduo/TD-11856-taosbenchmark-coverity-scan'

- name: create debug directory
if: |
Expand Down
21 changes: 20 additions & 1 deletion inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,25 @@
} \
} while (0)

#define debugPrintWithLen(fmt, len, ...) \
do { \
if (g_arguments->debug_print) { \
struct tm Tm, *ptm; \
struct timeval timeSecs; \
time_t curTime; \
toolsGetTimeOfDay(&timeSecs); \
curTime = timeSecs.tv_sec; \
ptm = toolsLocalTime(&curTime, &Tm); \
fnprintf(stdout, len, "[%02d/%02d %02d:%02d:%02d.%06d] ", \
ptm->tm_mon + 1, \
ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, \
(int32_t)timeSecs.tv_usec); \
fprintf(stdout, "DEBG: "); \
fprintf(stdout, "%s(%d) ", __FILE__, __LINE__); \
fprintf(stdout, "" fmt, __VA_ARGS__); \
} \
} while (0)

#define debugPrintJsonNoTime(json) \
do { \
if (g_arguments->debug_print) { \
Expand Down Expand Up @@ -718,7 +737,7 @@ typedef struct SuperQueryInfo_S {
uint64_t subscribeTimes; // ms
bool subscribeRestart;
int subscribeKeepProgress;
uint64_t childTblCount;
int64_t childTblCount;
int sqlCount;
char sql[MAX_QUERY_SQL_COUNT][TSDB_MAX_ALLOWED_SQL_LEN + 1];
char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN];
Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin
IF (CMAKE_C_COMPILER_ID MATCHES "GNU")
MESSAGE("Compiler is: ${CMAKE_C_COMPILER_ID}, version: ${CMAKE_C_COMPILER_VERSION}")
IF (CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.8.5)
SET(CMAKE_C_FLAGS "-Wall -Wshadow -std=c99 -std=gnu11 -O3 -DRELEASE -Werror -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation ${GCC_COVERAGE_COMPILE_FLAGS} ${TOOLS_SANITIZE_FLAG}")
IF (${OS_ID} MATCHES "alpine")
SET(CMAKE_C_FLAGS "-Wall -Wshadow -std=c99 -std=gnu11 -O3 -DRELEASE -Wformat=2 -Wno-stringop-truncation -Wno-format-nonliteral -Wno-format-truncation ${GCC_COVERAGE_COMPILE_FLAGS} ${TOOLS_SANITIZE_FLAG}")
ELSE ()
SET(CMAKE_C_FLAGS "-Wall -Wshadow -std=c99 -std=gnu11 -O3 -DRELEASE -Werror -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation ${GCC_COVERAGE_COMPILE_FLAGS} ${TOOLS_SANITIZE_FLAG}")
ENDIF ()
ELSE ()
SET(CMAKE_C_FLAGS "-Wall -Wshadow -std=c99 -std=gnu11 -O3 -DRELEASE ${GCC_COVERAGE_COMPILE_FLAGS}")
ENDIF ()
Expand Down
3 changes: 2 additions & 1 deletion src/benchCommandOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ static void *queryStableAggrFunc(void *sarg) {
static void *queryNtableAggrFunc(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg;
TAOS * taos = NULL;
if (pThreadInfo && pThreadInfo->conn) {
if (pThreadInfo->conn) {
taos = pThreadInfo->conn->taos;
}
#ifdef LINUX
Expand Down Expand Up @@ -1082,6 +1082,7 @@ void queryAggrFunc() {
} else {
pThreadInfo->sockfd = createSockFd();
if (pThreadInfo->sockfd < 0) {
free(pThreadInfo);
return;
}
}
Expand Down
110 changes: 58 additions & 52 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,21 +1269,23 @@ static int smartContinueIfFail(threadInfo *pThreadInfo,
}

static void cleanupAndPrint(threadInfo *pThreadInfo, char *mode) {
if (pThreadInfo && pThreadInfo->json_array) {
tools_cJSON_Delete(pThreadInfo->json_array);
pThreadInfo->json_array = NULL;
}
if ((pThreadInfo) && (0 == pThreadInfo->totalDelay)) {
pThreadInfo->totalDelay = 1;
}
succPrint(
if (pThreadInfo) {
if (pThreadInfo->json_array) {
tools_cJSON_Delete(pThreadInfo->json_array);
pThreadInfo->json_array = NULL;
}
if (0 == pThreadInfo->totalDelay) {
pThreadInfo->totalDelay = 1;
}
succPrint(
"thread[%d] %s mode, completed total inserted rows: %" PRIu64
", %.2f records/second\n",
pThreadInfo->threadID,
mode,
pThreadInfo->totalInsertRows,
(double)(pThreadInfo->totalInsertRows /
((double)pThreadInfo->totalDelay / 1E6)));
}
}

static void *syncWriteInterlace(void *sarg) {
Expand Down Expand Up @@ -1526,9 +1528,7 @@ static void *syncWriteInterlace(void *sarg) {
}
endTs = toolsGetTimestampUs();

if (pThreadInfo) {
pThreadInfo->totalInsertRows += tmp_total_insert_rows;
}
pThreadInfo->totalInsertRows += tmp_total_insert_rows;

if (g_arguments->terminate) {
goto free_of_interlace;
Expand Down Expand Up @@ -2551,6 +2551,45 @@ static void preProcessArgument(SSuperTable *stbInfo) {
}
}

static int printTotalDelay(SDataBase *database,
int64_t totalDelay,
BArray *total_delay_list,
int threads,
int64_t totalInsertRows,
int64_t start, int64_t end) {
succPrint("Spent %.6f seconds to insert rows: %" PRIu64
" with %d thread(s) into %s %.2f records/second\n",
(end - start)/1E6, totalInsertRows, threads,
database->dbName,
(double)(totalInsertRows / ((end - start)/1E6)));
if (!total_delay_list->size) {
return -1;
}

succPrint("insert delay, "
"min: %.4fms, "
"avg: %.4fms, "
"p90: %.4fms, "
"p95: %.4fms, "
"p99: %.4fms, "
"max: %.4fms\n",
*(int64_t *)(benchArrayGet(total_delay_list, 0))/1E3,
(double)totalDelay/total_delay_list->size/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.9)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.95)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.99)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
- 1)))/1E3);
return 0;
}

static int startMultiThreadInsertData(SDataBase* database,
SSuperTable* stbInfo) {
if ((stbInfo->iface == SML_IFACE || stbInfo->iface == SML_REST_IFACE)
Expand All @@ -2562,7 +2601,7 @@ static int startMultiThreadInsertData(SDataBase* database,
preProcessArgument(stbInfo);

uint64_t tableFrom = 0;
uint64_t ntables = stbInfo->childTblCount;
int64_t ntables = stbInfo->childTblCount;
stbInfo->childTblName = benchCalloc(stbInfo->childTblCount,
sizeof(char *), true);
for (int64_t i = 0; i < stbInfo->childTblCount; ++i) {
Expand Down Expand Up @@ -3064,40 +3103,11 @@ static int startMultiThreadInsertData(SDataBase* database,
free(pids);
free(infos);

succPrint("Spent %.6f seconds to insert rows: %" PRIu64
" with %d thread(s) into %s %.2f records/second\n",
(end - start)/1E6, totalInsertRows, threads,
database->dbName,
(double)(totalInsertRows / ((end - start)/1E6)));
if (!total_delay_list->size) {
benchArrayDestroy(total_delay_list);
return -1;
}

succPrint("insert delay, "
"min: %.4fms, "
"avg: %.4fms, "
"p90: %.4fms, "
"p95: %.4fms, "
"p99: %.4fms, "
"max: %.4fms\n",
*(int64_t *)(benchArrayGet(total_delay_list, 0))/1E3,
(double)totalDelay/total_delay_list->size/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.9)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.95)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
* 0.99)))/1E3,
*(int64_t *)(benchArrayGet(total_delay_list,
(int32_t)(total_delay_list->size
- 1)))/1E3);

int ret = printTotalDelay(database, totalDelay,
total_delay_list, threads,
totalInsertRows, start, end);
benchArrayDestroy(total_delay_list);
if (g_fail) {
if (g_fail || ret) {
return -1;
}
return 0;
Expand Down Expand Up @@ -3181,7 +3191,7 @@ static int32_t createStream(SSTREAM* stream) {
infoPrint("%s\n", command);
SBenchConn* conn = initBenchConn();
if (NULL == conn) {
goto END;
goto END_STREAM;
}

code = queryDbExecCall(conn, command);
Expand All @@ -3198,7 +3208,7 @@ static int32_t createStream(SSTREAM* stream) {

if (code) {
closeBenchConn(conn);
goto END;
goto END_STREAM;
}

memset(command, 0, TSDB_MAX_ALLOWED_SQL_LEN);
Expand Down Expand Up @@ -3229,12 +3239,8 @@ static int32_t createStream(SSTREAM* stream) {
}
}

if (code) {
closeBenchConn(conn);
goto END;
}
closeBenchConn(conn);
END:
END_STREAM:
tmfree(command);
return code;
}
Expand Down
7 changes: 6 additions & 1 deletion src/benchQuery.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ static void *specifiedTableQuery(void *sarg) {
- (et - st))); // ms
}
if (g_queryInfo.reset_query_cache) {
queryDbExecCall(pThreadInfo->conn, "reset query cache");
if (queryDbExecCall(pThreadInfo->conn,
"RESET QUERY CACHE")) {
errorPrint("%s() LN%d, reset query cache failed\n",
__func__, __LINE__);
return NULL;
}
}

st = toolsGetTimestampUs();
Expand Down
1 change: 1 addition & 0 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ int postProceSqlImpl(char *sqlstr, char* dbName, int precision, int iface,
do {
bytes = recv(sockfd, responseBuf + received,
resp_len - received, 0);
responseBuf[resp_len] = 0;
debugPrint("response buffer: %s\n", responseBuf);
if (NULL != strstr(responseBuf, resEncodingChunk)) {
chunked = true;
Expand Down
1 change: 1 addition & 0 deletions src/taosdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -7001,6 +7001,7 @@ static int64_t dumpInAvroDataImpl(
"reason: %s, timestamp: %"PRId64"\n",
__func__, __LINE__, taos_stmt_errstr(stmt), ts_debug);
failed -= stmt_count;
tfree(tbName);
break;
} else {
success++;
Expand Down

0 comments on commit 1fe8e6f

Please sign in to comment.