Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: taosbenchmark check remain vnodes #542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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 @@ -133,7 +133,7 @@ jobs:
apt install -y cmake build-essential git libjansson-dev libsnappy-dev liblzma-dev libz-dev zlib1g pkg-config libssl-dev > /dev/null

echo "clone TDengine 3.0 on ${{ steps.setup.outputs.uname }}"
git clone --branch feat/sangshuduo/TD-16450-taosdump-for-windows --depth 1 https://github.com/taosdata/TDengine > /dev/null || exit 1
git clone --branch fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes --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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- 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: 'feat/sangshuduo/TD-16450-taosdump-for-windows'
ref: 'fix/sangshuduo/TS-2389-taosbenchmark-check-remain-vnodes'

- name: create debug directory
if: |
Expand Down
6 changes: 3 additions & 3 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <winsock2.h>
#endif

#include <limits.h>
#include <regex.h>
#include <stdio.h>
#include <assert.h>
Expand All @@ -68,9 +69,6 @@
#include <time.h>
#include <stdarg.h>

// temporary flag for 3.0 development TODO need to remove in future
#define ALLOW_FORBID_FUNC

#include "taos.h"
#include "toolsdef.h"
#include "taoserror.h"
Expand Down Expand Up @@ -838,6 +836,8 @@ void destroySockFd(int sockfd);
void printVersion();
int32_t benchParseSingleOpt(int32_t key, char* arg);

void printErrCmdCodeStr(char *cmd, int32_t code, TAOS_RES *res);

#ifndef LINUX
int32_t benchParseArgsNoArgp(int argc, char* argv[]);
#endif
Expand Down
23 changes: 10 additions & 13 deletions src/benchCommandOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,19 +890,18 @@ static void *queryStableAggrFunc(void *sarg) {
0, g_arguments->port, 0,
pThreadInfo->sockfd, NULL);
} else {
TAOS_RES *pSql = taos_query(taos, command);
code = taos_errno(pSql);
TAOS_RES *res = taos_query(taos, command);
code = taos_errno(res);
if (code != 0) {
errorPrint("Failed to query:%s\n", taos_errstr(pSql));
taos_free_result(pSql);
printErrCmdCodeStr(command, code, res);
free(command);
return NULL;
}
int count = 0;
while (taos_fetch_row(pSql) != NULL) {
while (taos_fetch_row(res) != NULL) {
count++;
}
taos_free_result(pSql);
taos_free_result(res);
}
t = toolsGetTimestampUs() - t;
if (fp) {
Expand Down Expand Up @@ -970,19 +969,17 @@ static void *queryNtableAggrFunc(void *sarg) {
0, g_arguments->port, 0,
pThreadInfo->sockfd, NULL);
} else {
TAOS_RES *pSql = taos_query(taos, command);
code = taos_errno(pSql);
TAOS_RES *res = taos_query(taos, command);
code = taos_errno(res);
if (code != 0) {
errorPrint("Failed to query <%s>, reason:%s\n", command,
taos_errstr(pSql));
taos_free_result(pSql);
printErrCmdCodeStr(command, code, res);
free(command);
return NULL;
}
while (taos_fetch_row(pSql) != NULL) {
while (taos_fetch_row(res) != NULL) {
count++;
}
taos_free_result(pSql);
taos_free_result(res);
}

t = toolsGetTimestampUs() - t;
Expand Down
87 changes: 56 additions & 31 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ static int getSuperTableFromServerTaosc(
res = taos_query(conn->taos, command);
int32_t code = taos_errno(res);
if (code != 0) {
debugPrint("failed to run command %s, reason: %s\n", command,
taos_errstr(res));
printErrCmdCodeStr(command, code, res);
infoPrint("stable %s does not exist, will create one\n",
stbInfo->stbName);
taos_free_result(res);
close_bench_conn(conn);
return -1;
}
Expand Down Expand Up @@ -310,19 +308,15 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) {
res = taos_query(conn->taos, cmd);
code = taos_errno(res);
if (code) {
errorPrint("failed to execute: %s. code: 0x%08x reason: %s\n",
cmd, code, taos_errstr(res));
taos_free_result(res);
printErrCmdCodeStr(cmd, code, res);
return -1;
}

sprintf(cmd, "SHOW vgroups");
res = taos_query(conn->taos, cmd);
code = taos_errno(res);
if (code) {
errorPrint("failed to execute: %s. code: 0x%08x reason: %s\n",
cmd, code, taos_errstr(res));
taos_free_result(res);
printErrCmdCodeStr(cmd, code, res);
return -1;
}

Expand All @@ -343,9 +337,7 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) {
res = taos_query(conn->taos, cmd);
code = taos_errno(res);
if (code) {
errorPrint("failed to execute: %s. code: 0x%08x reason: %s\n",
cmd, code, taos_errstr(res));
taos_free_result(res);
printErrCmdCodeStr(cmd, code, res);
return -1;
}

Expand All @@ -361,15 +353,18 @@ int32_t getVgroupsOfDb(SBenchConn *conn, SDataBase *database) {
}
#endif // TD_VER_COMPATIBLE_3_0_0_0

int geneDbCreateCmd(SDataBase *database, char *command) {
int geneDbCreateCmd(SDataBase *database, char *command, int remainVnodes) {
int dataLen = 0;
#ifdef TD_VER_COMPATIBLE_3_0_0_0
if (g_arguments->nthreads_auto) {
dataLen += snprintf(command + dataLen, SQL_BUFF_LEN - dataLen,
"CREATE DATABASE IF NOT EXISTS %s VGROUPS %d", database->dbName, toolsGetNumberOfCores());
"CREATE DATABASE IF NOT EXISTS %s VGROUPS %d",
database->dbName,
min(remainVnodes, toolsGetNumberOfCores()));
} else {
dataLen += snprintf(command + dataLen, SQL_BUFF_LEN - dataLen,
"CREATE DATABASE IF NOT EXISTS %s", database->dbName);
"CREATE DATABASE IF NOT EXISTS %s",
database->dbName);
}
#else
dataLen += snprintf(command + dataLen, SQL_BUFF_LEN - dataLen,
Expand Down Expand Up @@ -429,7 +424,8 @@ int createDatabaseRest(SDataBase* database) {
if (code != 0) {
errorPrint("Failed to drop database %s\n", database->dbName);
} else {
geneDbCreateCmd(database, command);
int remainVnodes = INT_MAX;
geneDbCreateCmd(database, command, remainVnodes);
code = postProceSql(command,
database->dbName,
database->precision,
Expand All @@ -444,8 +440,29 @@ int createDatabaseRest(SDataBase* database) {
return code;
}

int32_t getRemainVnodes(SBenchConn *conn) {
int remainVnodes = 0;
char command[SQL_BUFF_LEN] = "SHOW DNODES";

TAOS_RES *res = taos_query(conn->taos, command);
int32_t code = taos_errno(res);
if (code) {
printErrCmdCodeStr(command, code, res);
close_bench_conn(conn);
return -1;
}
TAOS_ROW row = NULL;
while ((row = taos_fetch_row(res)) != NULL) {
remainVnodes += (*(int16_t*)(row[3]) - *(int16_t*)(row[2]));
}
debugPrint("%s() LN%d, remainVnodes: %d\n",
__func__, __LINE__, remainVnodes);
taos_free_result(res);
return remainVnodes;
}

int createDatabaseTaosc(SDataBase* database) {
char command[SQL_BUFF_LEN] = "\0";
char command[SQL_BUFF_LEN] = "\0";
SBenchConn* conn = init_bench_conn();
if (NULL == conn) {
return -1;
Expand All @@ -471,13 +488,25 @@ int createDatabaseTaosc(SDataBase* database) {
return -1;
}

geneDbCreateCmd(database, command);
int remainVnodes = INT_MAX;
#ifdef TD_VER_COMPATIBLE_3_0_0_0
if (g_arguments->nthreads_auto) {
remainVnodes = getRemainVnodes(conn);
if (0 >= remainVnodes) {
errorPrint("Remain vnodes %d, failed to create database\n",
remainVnodes);
return -1;
}
}
#endif
geneDbCreateCmd(database, command, remainVnodes);

int32_t code = queryDbExec(conn, command);
int32_t trying = g_arguments->keep_trying;
while (code && trying) {
infoPrint("will sleep %"PRIu32" milliseconds then re-create database %s\n",
g_arguments->trying_interval, database->dbName);
infoPrint("will sleep %"PRIu32" milliseconds then "
"re-create database %s\n",
g_arguments->trying_interval, database->dbName);
toolsMsleep(g_arguments->trying_interval);
code = queryDbExec(conn, command);
if (trying != -1) {
Expand Down Expand Up @@ -1898,9 +1927,7 @@ static int startMultiThreadInsertData(SDataBase* database,
int32_t code = taos_errno(res);
int64_t count = 0;
if (code) {
errorPrint("failed to get child table name: %s. reason: %s",
cmd, taos_errstr(res));
taos_free_result(res);
printErrCmdCodeStr(cmd, code, res);
close_bench_conn(conn);
return -1;
}
Expand Down Expand Up @@ -2348,16 +2375,14 @@ static int startMultiThreadInsertData(SDataBase* database,
return 0;
}

static int get_stb_inserted_rows(char* dbName, char* stbName, TAOS* taos) {
static int getStbInsertedRows(char* dbName, char* stbName, TAOS* taos) {
int rows = 0;
char command[SQL_BUFF_LEN];
sprintf(command, "select count(*) from %s.%s", dbName, stbName);
sprintf(command, "SELECT COUNT(*) FROM %s.%s", dbName, stbName);
TAOS_RES* res = taos_query(taos, command);
int code = taos_errno(res);
if (code != 0) {
errorPrint("Failed to execute <%s>, reason: %s\n",
command, taos_errstr(res));
taos_free_result(res);
printErrCmdCodeStr(command, code, res);
return -1;
}
TAOS_ROW row = taos_fetch_row(res);
Expand All @@ -2373,8 +2398,8 @@ static int get_stb_inserted_rows(char* dbName, char* stbName, TAOS* taos) {
static void create_tsma(TSMA* tsma, SBenchConn* conn, char* stbName) {
char command[SQL_BUFF_LEN];
int len = snprintf(command, SQL_BUFF_LEN,
"create sma index %s on %s function(%s) "
"interval (%s) sliding (%s)",
"CREATE sma INDEX %s ON %s function(%s) "
"INTERVAL (%s) SLIDING (%s)",
tsma->name, stbName, tsma->func,
tsma->interval, tsma->sliding);
if (tsma->custom) {
Expand All @@ -2400,7 +2425,7 @@ static void* create_tsmas(void* args) {
return NULL;
}
while(finished < pThreadInfo->tsmas->size && inserted_rows >= 0) {
inserted_rows = (int)get_stb_inserted_rows(
inserted_rows = (int)getStbInsertedRows(
pThreadInfo->dbName, pThreadInfo->stbName, conn->taos);
for (int i = 0; i < pThreadInfo->tsmas->size; i++) {
TSMA* tsma = benchArrayGet(pThreadInfo->tsmas, i);
Expand Down
22 changes: 7 additions & 15 deletions src/benchQuery.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,8 @@ void *queryKiller(void *arg) {
"SELECT kill_id,exec_usec,sql FROM performance_schema.perf_queries";
TAOS_RES *res = taos_query(taos, command);
int32_t code = taos_errno(res);
if (code != 0) {
errorPrint("%s execution failed. Reason: %s\n",
command, taos_errstr(res));
taos_free_result(res);
if (code) {
printErrCmdCodeStr(command, code, res);
}

TAOS_ROW row = NULL;
Expand All @@ -621,14 +619,12 @@ void *queryKiller(void *arg) {
snprintf(killCommand, KILLID_LEN + 15, "KILL QUERY '%s'", killId);
TAOS_RES *resKill = taos_query(taos, killCommand);
int32_t codeKill = taos_errno(resKill);
if (codeKill != 0) {
errorPrint("%s execution failed. Reason: %s\n",
killCommand, taos_errstr(resKill));
if (codeKill) {
printErrCmdCodeStr(killCommand, codeKill, resKill);
} else {
infoPrint("%s succeed, sql: %s\n", killCommand, sql);
infoPrint("%s succeed, sql: %s killed!\n", killCommand, sql);
taos_free_result(resKill);
}

taos_free_result(resKill);
}
}
}
Expand Down Expand Up @@ -682,11 +678,7 @@ int queryTestProcess() {
TAOS_RES *res = taos_query(conn->taos, cmd);
int32_t code = taos_errno(res);
if (code) {
errorPrint(
"failed to count child table name: %s. reason: %s\n",
cmd, taos_errstr(res));
taos_free_result(res);

printErrCmdCodeStr(cmd, code, res);
return -1;
}
TAOS_ROW row = NULL;
Expand Down