chore: tests reorg (#16638)
* chore: move few tests items out * fix: add taos as dep to tmq_demo * chore: remove tests/test and tests/tsim
This commit is contained in:
parent
c984fcaee0
commit
de09dadc82
|
@ -34,7 +34,6 @@ endif(${BUILD_TEST})
|
|||
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(tools)
|
||||
#add_subdirectory(tests)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(examples/c)
|
||||
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
add_executable(tmq_demo tmqDemo.c)
|
||||
add_dependencies(tmq_demo taos)
|
||||
add_executable(tmq_sim tmqSim.c)
|
||||
add_executable(create_table createTable.c)
|
||||
add_executable(tmq_taosx_ci tmq_taosx_ci.c)
|
||||
add_executable(sml_test sml_test.c)
|
||||
target_link_libraries(
|
||||
create_table
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
)
|
||||
target_link_libraries(
|
||||
tmq_demo
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
)
|
||||
target_link_libraries(
|
||||
tmq_sim
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
)
|
||||
target_link_libraries(
|
||||
tmq_taosx_ci
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
sml_test
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
)
|
||||
|
||||
add_executable(sdbDump sdbDump.c)
|
||||
target_link_libraries(
|
||||
sdbDump
|
||||
PUBLIC dnode
|
||||
PUBLIC mnode
|
||||
PUBLIC stream
|
||||
PUBLIC sdb
|
||||
PUBLIC os
|
||||
)
|
||||
target_include_directories(
|
||||
sdbDump
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mnode"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/dnode/mnode/impl/inc"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/dnode/mnode/sdb/inc"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/dnode/mgmt/node_mgmt/inc"
|
||||
)
|
|
@ -1,471 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#define GREEN "\033[1;32m"
|
||||
#define NC "\033[0m"
|
||||
|
||||
char dbName[32] = "db";
|
||||
char stbName[64] = "st";
|
||||
int32_t numOfThreads = 1;
|
||||
int64_t numOfTables = 200000;
|
||||
int64_t startOffset = 0;
|
||||
int32_t createTable = 1;
|
||||
int32_t insertData = 0;
|
||||
int32_t batchNumOfTbl = 100;
|
||||
int32_t batchNumOfRow = 1;
|
||||
int32_t totalRowsOfPerTbl = 1;
|
||||
int32_t numOfVgroups = 2;
|
||||
int32_t showTablesFlag = 0;
|
||||
int32_t queryFlag = 0;
|
||||
|
||||
int64_t startTimestamp = 1640966400000; // 2020-01-01 00:00:00.000
|
||||
|
||||
typedef struct {
|
||||
int64_t tableBeginIndex;
|
||||
int64_t tableEndIndex;
|
||||
int32_t threadIndex;
|
||||
char dbName[32];
|
||||
char stbName[64];
|
||||
float createTableSpeed;
|
||||
float insertDataSpeed;
|
||||
int64_t startMs;
|
||||
int64_t maxDelay;
|
||||
int64_t minDelay;
|
||||
TdThread thread;
|
||||
} SThreadInfo;
|
||||
|
||||
// void parseArgument(int32_t argc, char *argv[]);
|
||||
// void *threadFunc(void *param);
|
||||
// void createDbAndStb();
|
||||
|
||||
void createDbAndStb() {
|
||||
pPrint("start to create db and stable");
|
||||
char qstr[64000];
|
||||
|
||||
TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (con == NULL) {
|
||||
pError("failed to connect to DB, reason:%s", taos_errstr(NULL));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sprintf(qstr, "create database if not exists %s vgroups %d", dbName, numOfVgroups);
|
||||
TAOS_RES *pRes = taos_query(con, qstr);
|
||||
int32_t code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(pRes),
|
||||
taos_errstr(pRes));
|
||||
exit(0);
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
sprintf(qstr, "use %s", dbName);
|
||||
pRes = taos_query(con, qstr);
|
||||
code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to use db, code:%d reason:%s", taos_errno(pRes), taos_errstr(pRes));
|
||||
exit(0);
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
sprintf(qstr, "create table if not exists %s (ts timestamp, i int) tags (j bigint)", stbName);
|
||||
pRes = taos_query(con, qstr);
|
||||
code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to create stable, code:%d reason:%s", taos_errno(pRes), taos_errstr(pRes));
|
||||
exit(0);
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(con);
|
||||
}
|
||||
|
||||
void printCreateProgress(SThreadInfo *pInfo, int64_t t) {
|
||||
int64_t endMs = taosGetTimestampMs();
|
||||
int64_t totalTables = t - pInfo->tableBeginIndex;
|
||||
float seconds = (endMs - pInfo->startMs) / 1000.0;
|
||||
float speed = totalTables / seconds;
|
||||
pInfo->createTableSpeed = speed;
|
||||
pPrint("thread:%d, %" PRId64 " tables created, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex,
|
||||
totalTables, seconds, speed);
|
||||
}
|
||||
|
||||
void printInsertProgress(SThreadInfo *pInfo, int64_t insertTotalRows) {
|
||||
int64_t endMs = taosGetTimestampMs();
|
||||
//int64_t totalTables = t - pInfo->tableBeginIndex;
|
||||
float seconds = (endMs - pInfo->startMs) / 1000.0;
|
||||
float speed = insertTotalRows / seconds;
|
||||
pInfo->insertDataSpeed = speed;
|
||||
pPrint("thread:%d, %" PRId64 " rows inserted, time:%.2f sec, speed:%.1f rows/second, ", pInfo->threadIndex,
|
||||
insertTotalRows, seconds, speed);
|
||||
}
|
||||
|
||||
static int64_t getResult(TAOS_RES *tres) {
|
||||
TAOS_ROW row = taos_fetch_row(tres);
|
||||
if (row == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int num_fields = taos_num_fields(tres);
|
||||
TAOS_FIELD *fields = taos_fetch_fields(tres);
|
||||
int precision = taos_result_precision(tres);
|
||||
|
||||
int64_t numOfRows = 0;
|
||||
do {
|
||||
numOfRows++;
|
||||
row = taos_fetch_row(tres);
|
||||
} while (row != NULL);
|
||||
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
void showTables() {
|
||||
pPrint("start to show tables");
|
||||
char qstr[128];
|
||||
|
||||
TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (con == NULL) {
|
||||
pError("failed to connect to DB, reason:%s", taos_errstr(NULL));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
snprintf(qstr, 128, "use %s", dbName);
|
||||
TAOS_RES *pRes = taos_query(con, qstr);
|
||||
int code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to use db, code:%d reason:%s", taos_errno(pRes), taos_errstr(pRes));
|
||||
exit(1);
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
sprintf(qstr, "show tables");
|
||||
pRes = taos_query(con, qstr);
|
||||
code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to show tables, code:%d reason:%s", taos_errno(pRes), taos_errstr(pRes));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int64_t totalTableNum = getResult(pRes);
|
||||
taos_free_result(pRes);
|
||||
|
||||
pPrint("%s database: %s, total %" PRId64 " tables %s", GREEN, dbName, totalTableNum, NC);
|
||||
|
||||
taos_close(con);
|
||||
}
|
||||
|
||||
void *threadFunc(void *param) {
|
||||
SThreadInfo *pInfo = (SThreadInfo *)param;
|
||||
char *qstr = taosMemoryMalloc(batchNumOfTbl * batchNumOfRow * 128);
|
||||
int32_t code = 0;
|
||||
|
||||
TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (con == NULL) {
|
||||
pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(NULL));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//pPrint("====before thread:%d, table range: %" PRId64 " - %" PRId64 "\n", pInfo->threadIndex, pInfo->tableBeginIndex,
|
||||
// pInfo->tableEndIndex);
|
||||
|
||||
pInfo->tableBeginIndex += startOffset;
|
||||
pInfo->tableEndIndex += startOffset;
|
||||
|
||||
pPrint("====thread:%d, table range: %" PRId64 " - %" PRId64 "\n", pInfo->threadIndex, pInfo->tableBeginIndex, pInfo->tableEndIndex);
|
||||
|
||||
sprintf(qstr, "use %s", pInfo->dbName);
|
||||
TAOS_RES *pRes = taos_query(con, qstr);
|
||||
taos_free_result(pRes);
|
||||
|
||||
if (createTable) {
|
||||
int64_t curMs = 0;
|
||||
int64_t beginMs = taosGetTimestampMs();
|
||||
pInfo->startMs = beginMs;
|
||||
int64_t t = pInfo->tableBeginIndex;
|
||||
for (; t <= pInfo->tableEndIndex;) {
|
||||
// int64_t batch = (pInfo->tableEndIndex - t);
|
||||
// batch = MIN(batch, batchNum);
|
||||
|
||||
int32_t len = sprintf(qstr, "create table");
|
||||
for (int32_t i = 0; i < batchNumOfTbl;) {
|
||||
len += sprintf(qstr + len, " %s_t%" PRId64 " using %s tags(%" PRId64 ")", stbName, t, stbName, t);
|
||||
t++;
|
||||
i++;
|
||||
if (t > pInfo->tableEndIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
TAOS_RES *pRes = taos_query(con, qstr);
|
||||
code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to create table reason:%s, sql: %s", tstrerror(code), qstr);
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
int64_t endTs = taosGetTimestampUs();
|
||||
int64_t delay = endTs - startTs;
|
||||
// printf("==== %"PRId64" - %"PRId64", %"PRId64"\n", startTs, endTs, delay);
|
||||
if (delay > pInfo->maxDelay) pInfo->maxDelay = delay;
|
||||
if (delay < pInfo->minDelay) pInfo->minDelay = delay;
|
||||
|
||||
curMs = taosGetTimestampMs();
|
||||
if (curMs - beginMs > 10000) {
|
||||
beginMs = curMs;
|
||||
// printf("==== tableBeginIndex: %"PRId64", t: %"PRId64"\n", pInfo->tableBeginIndex, t);
|
||||
printCreateProgress(pInfo, t);
|
||||
}
|
||||
}
|
||||
printCreateProgress(pInfo, t);
|
||||
}
|
||||
|
||||
if (insertData) {
|
||||
int64_t insertTotalRows = 0;
|
||||
int64_t curMs = 0;
|
||||
int64_t beginMs = taosGetTimestampMs();
|
||||
pInfo->startMs = beginMs;
|
||||
int64_t t = pInfo->tableBeginIndex;
|
||||
for (; t <= pInfo->tableEndIndex; t++) {
|
||||
//printf("table name: %"PRId64"\n", t);
|
||||
int64_t ts = startTimestamp;
|
||||
for (int32_t i = 0; i < totalRowsOfPerTbl;) {
|
||||
int32_t len = sprintf(qstr, "insert into ");
|
||||
len += sprintf(qstr + len, "%s_t%" PRId64 " values ", stbName, t);
|
||||
for (int32_t j = 0; j < batchNumOfRow; j++) {
|
||||
len += sprintf(qstr + len, "(%" PRId64 ", 6666) ", ts++);
|
||||
i++;
|
||||
insertTotalRows++;
|
||||
if (i >= totalRowsOfPerTbl) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
TAOS_RES *pRes = taos_query(con, qstr);
|
||||
code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to insert %s_t%" PRId64 ", reason:%s", stbName, t, tstrerror(code));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
int64_t endTs = taosGetTimestampUs();
|
||||
int64_t delay = endTs - startTs;
|
||||
// printf("==== %"PRId64" - %"PRId64", %"PRId64"\n", startTs, endTs, delay);
|
||||
if (delay > pInfo->maxDelay) pInfo->maxDelay = delay;
|
||||
if (delay < pInfo->minDelay) pInfo->minDelay = delay;
|
||||
|
||||
curMs = taosGetTimestampMs();
|
||||
if (curMs - beginMs > 10000) {
|
||||
beginMs = curMs;
|
||||
// printf("==== tableBeginIndex: %"PRId64", t: %"PRId64"\n", pInfo->tableBeginIndex, t);
|
||||
printInsertProgress(pInfo, insertTotalRows);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
printInsertProgress(pInfo, insertTotalRows);
|
||||
}
|
||||
|
||||
taos_close(con);
|
||||
taosMemoryFree(qstr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printHelp() {
|
||||
char indent[10] = " ";
|
||||
printf("Used to test the performance while create table\n");
|
||||
|
||||
printf("%s%s\n", indent, "-c");
|
||||
printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir);
|
||||
printf("%s%s\n", indent, "-d");
|
||||
printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName);
|
||||
printf("%s%s\n", indent, "-s");
|
||||
printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stbName);
|
||||
printf("%s%s\n", indent, "-t");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", numOfThreads);
|
||||
printf("%s%s\n", indent, "-n");
|
||||
printf("%s%s%s%" PRId64 "\n", indent, indent, "numOfTables, default is ", numOfTables);
|
||||
printf("%s%s\n", indent, "-g");
|
||||
printf("%s%s%s%" PRId64 "\n", indent, indent, "startOffset, default is ", startOffset);
|
||||
printf("%s%s\n", indent, "-v");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfVgroups, default is ", numOfVgroups);
|
||||
printf("%s%s\n", indent, "-a");
|
||||
printf("%s%s%s%d\n", indent, indent, "createTable, default is ", createTable);
|
||||
printf("%s%s\n", indent, "-i");
|
||||
printf("%s%s%s%d\n", indent, indent, "insertData, default is ", insertData);
|
||||
printf("%s%s\n", indent, "-b");
|
||||
printf("%s%s%s%d\n", indent, indent, "batchNumOfTbl, default is ", batchNumOfTbl);
|
||||
printf("%s%s\n", indent, "-w");
|
||||
printf("%s%s%s%d\n", indent, indent, "showTablesFlag, default is ", showTablesFlag);
|
||||
printf("%s%s\n", indent, "-q");
|
||||
printf("%s%s%s%d\n", indent, indent, "queryFlag, default is ", queryFlag);
|
||||
printf("%s%s\n", indent, "-l");
|
||||
printf("%s%s%s%d\n", indent, indent, "batchNumOfRow, default is ", batchNumOfRow);
|
||||
printf("%s%s\n", indent, "-r");
|
||||
printf("%s%s%s%d\n", indent, indent, "totalRowsOfPerTbl, default is ", totalRowsOfPerTbl);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void parseArgument(int32_t argc, char *argv[]) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
printHelp();
|
||||
exit(0);
|
||||
} else if (strcmp(argv[i], "-d") == 0) {
|
||||
strcpy(dbName, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-c") == 0) {
|
||||
strcpy(configDir, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-s") == 0) {
|
||||
strcpy(stbName, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-t") == 0) {
|
||||
numOfThreads = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
numOfTables = atoll(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-g") == 0) {
|
||||
startOffset = atoll(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-v") == 0) {
|
||||
numOfVgroups = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
createTable = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-i") == 0) {
|
||||
insertData = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-b") == 0) {
|
||||
batchNumOfTbl = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-l") == 0) {
|
||||
batchNumOfRow = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-r") == 0) {
|
||||
totalRowsOfPerTbl = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-w") == 0) {
|
||||
showTablesFlag = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-q") == 0) {
|
||||
queryFlag = atoi(argv[++i]);
|
||||
} else {
|
||||
pPrint("%s unknow para: %s %s", GREEN, argv[++i], NC);
|
||||
}
|
||||
}
|
||||
|
||||
pPrint("%s dbName:%s %s", GREEN, dbName, NC);
|
||||
pPrint("%s stbName:%s %s", GREEN, stbName, NC);
|
||||
pPrint("%s configDir:%s %s", GREEN, configDir, NC);
|
||||
pPrint("%s numOfTables:%" PRId64 " %s", GREEN, numOfTables, NC);
|
||||
pPrint("%s startOffset:%" PRId64 " %s", GREEN, startOffset, NC);
|
||||
pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC);
|
||||
pPrint("%s numOfVgroups:%d %s", GREEN, numOfVgroups, NC);
|
||||
pPrint("%s createTable:%d %s", GREEN, createTable, NC);
|
||||
pPrint("%s insertData:%d %s", GREEN, insertData, NC);
|
||||
pPrint("%s batchNumOfTbl:%d %s", GREEN, batchNumOfTbl, NC);
|
||||
pPrint("%s batchNumOfRow:%d %s", GREEN, batchNumOfRow, NC);
|
||||
pPrint("%s totalRowsOfPerTbl:%d %s", GREEN, totalRowsOfPerTbl, NC);
|
||||
pPrint("%s showTablesFlag:%d %s", GREEN, showTablesFlag, NC);
|
||||
pPrint("%s queryFlag:%d %s", GREEN, queryFlag, NC);
|
||||
|
||||
pPrint("%s start create table performace test %s", GREEN, NC);
|
||||
}
|
||||
|
||||
int32_t main(int32_t argc, char *argv[]) {
|
||||
parseArgument(argc, argv);
|
||||
|
||||
if (showTablesFlag) {
|
||||
showTables();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (queryFlag) {
|
||||
// selectRowsFromTable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (createTable) {
|
||||
createDbAndStb();
|
||||
}
|
||||
|
||||
pPrint("%d threads are spawned to create %" PRId64 " tables, offset is %" PRId64 " ", numOfThreads, numOfTables,
|
||||
startOffset);
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
SThreadInfo *pInfo = (SThreadInfo *)taosMemoryCalloc(numOfThreads, sizeof(SThreadInfo));
|
||||
|
||||
// int64_t numOfTablesPerThread = numOfTables / numOfThreads;
|
||||
// numOfTables = numOfTablesPerThread * numOfThreads;
|
||||
|
||||
if (numOfThreads < 1) {
|
||||
numOfThreads = 1;
|
||||
}
|
||||
|
||||
int64_t a = numOfTables / numOfThreads;
|
||||
if (a < 1) {
|
||||
numOfThreads = numOfTables;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
int64_t b = 0;
|
||||
b = numOfTables % numOfThreads;
|
||||
|
||||
int64_t tableFrom = 0;
|
||||
for (int32_t i = 0; i < numOfThreads; ++i) {
|
||||
pInfo[i].tableBeginIndex = tableFrom;
|
||||
pInfo[i].tableEndIndex = (i < b ? tableFrom + a : tableFrom + a - 1);
|
||||
tableFrom = pInfo[i].tableEndIndex + 1;
|
||||
pInfo[i].threadIndex = i;
|
||||
pInfo[i].minDelay = INT64_MAX;
|
||||
strcpy(pInfo[i].dbName, dbName);
|
||||
strcpy(pInfo[i].stbName, stbName);
|
||||
taosThreadCreate(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i));
|
||||
}
|
||||
|
||||
taosMsleep(300);
|
||||
for (int32_t i = 0; i < numOfThreads; i++) {
|
||||
taosThreadJoin(pInfo[i].thread, NULL);
|
||||
taosThreadClear(&pInfo[i].thread);
|
||||
}
|
||||
|
||||
int64_t maxDelay = 0;
|
||||
int64_t minDelay = INT64_MAX;
|
||||
|
||||
float createTableSpeed = 0;
|
||||
for (int32_t i = 0; i < numOfThreads; ++i) {
|
||||
createTableSpeed += pInfo[i].createTableSpeed;
|
||||
|
||||
if (pInfo[i].maxDelay > maxDelay) maxDelay = pInfo[i].maxDelay;
|
||||
if (pInfo[i].minDelay < minDelay) minDelay = pInfo[i].minDelay;
|
||||
}
|
||||
|
||||
float insertDataSpeed = 0;
|
||||
for (int32_t i = 0; i < numOfThreads; ++i) {
|
||||
insertDataSpeed += pInfo[i].insertDataSpeed;
|
||||
}
|
||||
|
||||
if (createTable) {
|
||||
pPrint("%s total %" PRId64 " tables, %.1f tables/second, threads:%d, maxDelay: %" PRId64 "us, minDelay: %" PRId64
|
||||
"us %s",
|
||||
GREEN, numOfTables, createTableSpeed, numOfThreads, maxDelay, minDelay, NC);
|
||||
}
|
||||
|
||||
if (insertData) {
|
||||
pPrint("%s total %" PRId64 " tables, %.1f rows/second, threads:%d %s", GREEN, numOfTables, insertDataSpeed,
|
||||
numOfThreads, NC);
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thattr);
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
|
@ -1,475 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmMgmt.h"
|
||||
#include "mndInt.h"
|
||||
#include "sdb.h"
|
||||
#include "tconfig.h"
|
||||
#include "tjson.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-result"
|
||||
|
||||
#define TMP_DNODE_DIR TD_TMP_DIR_PATH "dumpsdb"
|
||||
#define TMP_MNODE_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode"
|
||||
#define TMP_SDB_DATA_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "data"
|
||||
#define TMP_SDB_SYNC_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync"
|
||||
#define TMP_SDB_MNODE_JSON TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "mnode.json"
|
||||
#define TMP_SDB_DATA_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "data" TD_DIRSEP "sdb.data"
|
||||
#define TMP_SDB_RAFT_CFG_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_config.json"
|
||||
#define TMP_SDB_RAFT_STORE_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_store.json"
|
||||
|
||||
void reportStartup(const char *name, const char *desc) {}
|
||||
|
||||
void sendRsp(SRpcMsg *pMsg) { rpcFreeCont(pMsg->pCont); }
|
||||
|
||||
int32_t sendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *i642str(int64_t val) {
|
||||
static char str[24] = {0};
|
||||
snprintf(str, sizeof(str), "%" PRId64, val);
|
||||
return str;
|
||||
}
|
||||
|
||||
void dumpFunc(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpDb(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "dbs", items);
|
||||
|
||||
while (1) {
|
||||
SDbObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "db", item);
|
||||
|
||||
tjsonAddStringToObject(item, "name", pObj->name);
|
||||
tjsonAddStringToObject(item, "acct", pObj->acct);
|
||||
tjsonAddStringToObject(item, "createUser", pObj->createUser);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddStringToObject(item, "uid", i642str(pObj->uid));
|
||||
tjsonAddIntegerToObject(item, "cfgVersion", pObj->cfgVersion);
|
||||
tjsonAddIntegerToObject(item, "vgVersion", pObj->vgVersion);
|
||||
tjsonAddIntegerToObject(item, "numOfVgroups", pObj->cfg.numOfVgroups);
|
||||
tjsonAddIntegerToObject(item, "numOfStables", pObj->cfg.numOfStables);
|
||||
tjsonAddIntegerToObject(item, "buffer", pObj->cfg.buffer);
|
||||
tjsonAddIntegerToObject(item, "pageSize", pObj->cfg.pageSize);
|
||||
tjsonAddIntegerToObject(item, "pages", pObj->cfg.pages);
|
||||
tjsonAddIntegerToObject(item, "cacheLastSize", pObj->cfg.cacheLastSize);
|
||||
tjsonAddIntegerToObject(item, "daysPerFile", pObj->cfg.daysPerFile);
|
||||
tjsonAddIntegerToObject(item, "daysToKeep0", pObj->cfg.daysToKeep0);
|
||||
tjsonAddIntegerToObject(item, "daysToKeep1", pObj->cfg.daysToKeep1);
|
||||
tjsonAddIntegerToObject(item, "daysToKeep2", pObj->cfg.daysToKeep2);
|
||||
tjsonAddIntegerToObject(item, "minRows", pObj->cfg.minRows);
|
||||
tjsonAddIntegerToObject(item, "maxRows", pObj->cfg.maxRows);
|
||||
tjsonAddIntegerToObject(item, "precision", pObj->cfg.precision);
|
||||
tjsonAddIntegerToObject(item, "compression", pObj->cfg.compression);
|
||||
tjsonAddIntegerToObject(item, "replications", pObj->cfg.replications);
|
||||
tjsonAddIntegerToObject(item, "strict", pObj->cfg.strict);
|
||||
tjsonAddIntegerToObject(item, "cacheLast", pObj->cfg.cacheLast);
|
||||
tjsonAddIntegerToObject(item, "hashMethod", pObj->cfg.hashMethod);
|
||||
tjsonAddIntegerToObject(item, "numOfRetensions", pObj->cfg.numOfRetensions);
|
||||
tjsonAddIntegerToObject(item, "schemaless", pObj->cfg.schemaless);
|
||||
tjsonAddIntegerToObject(item, "walLevel", pObj->cfg.walLevel);
|
||||
tjsonAddIntegerToObject(item, "walFsyncPeriod", pObj->cfg.walFsyncPeriod);
|
||||
tjsonAddIntegerToObject(item, "walRetentionPeriod", pObj->cfg.walRetentionPeriod);
|
||||
tjsonAddIntegerToObject(item, "walRetentionSize", pObj->cfg.walRetentionSize);
|
||||
tjsonAddIntegerToObject(item, "walRollPeriod", pObj->cfg.walRollPeriod);
|
||||
tjsonAddIntegerToObject(item, "walSegmentSize", pObj->cfg.walSegmentSize);
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpStb(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "stbs", items);
|
||||
|
||||
while (1) {
|
||||
SStbObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "stb", item);
|
||||
|
||||
tjsonAddStringToObject(item, "name", pObj->name);
|
||||
tjsonAddStringToObject(item, "db", pObj->db);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddStringToObject(item, "uid", i642str(pObj->uid));
|
||||
tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid));
|
||||
tjsonAddIntegerToObject(item, "tagVer", pObj->tagVer);
|
||||
tjsonAddIntegerToObject(item, "colVer", pObj->colVer);
|
||||
tjsonAddIntegerToObject(item, "nextColId", pObj->nextColId);
|
||||
tjsonAddIntegerToObject(item, "watermark1", pObj->watermark[0]);
|
||||
tjsonAddIntegerToObject(item, "watermark2", pObj->watermark[1]);
|
||||
tjsonAddIntegerToObject(item, "maxdelay1", pObj->maxdelay[0]);
|
||||
tjsonAddIntegerToObject(item, "maxdelay2", pObj->maxdelay[1]);
|
||||
tjsonAddIntegerToObject(item, "ttl", pObj->ttl);
|
||||
tjsonAddIntegerToObject(item, "numOfColumns", pObj->numOfColumns);
|
||||
tjsonAddIntegerToObject(item, "numOfTags", pObj->numOfTags);
|
||||
tjsonAddIntegerToObject(item, "commentLen", pObj->commentLen);
|
||||
tjsonAddIntegerToObject(item, "ast1Len", pObj->ast1Len);
|
||||
tjsonAddIntegerToObject(item, "ast2Len", pObj->ast2Len);
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpSma(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpVgroup(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpTopic(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpConsumber(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpSubscribe(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpOffset(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpStream(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpAcct(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "accts", items);
|
||||
|
||||
while (1) {
|
||||
SAcctObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_ACCT, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "acct", item);
|
||||
|
||||
tjsonAddStringToObject(item, "acct", pObj->acct);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddIntegerToObject(item, "acctId", pObj->acctId);
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpAuth(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpUser(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "users", items);
|
||||
|
||||
while (1) {
|
||||
SUserObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "user", item);
|
||||
|
||||
tjsonAddStringToObject(item, "name", pObj->user);
|
||||
tjsonAddStringToObject(item, "pass", pObj->pass);
|
||||
tjsonAddStringToObject(item, "acct", pObj->acct);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddIntegerToObject(item, "superUser", pObj->superUser);
|
||||
tjsonAddIntegerToObject(item, "authVersion", pObj->authVersion);
|
||||
tjsonAddIntegerToObject(item, "numOfReadDbs", taosHashGetSize(pObj->readDbs));
|
||||
tjsonAddIntegerToObject(item, "numOfWriteDbs", taosHashGetSize(pObj->writeDbs));
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpDnode(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "dnodes", items);
|
||||
|
||||
while (1) {
|
||||
SDnodeObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "dnode", item);
|
||||
|
||||
tjsonAddIntegerToObject(item, "id", pObj->id);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddIntegerToObject(item, "port", pObj->port);
|
||||
tjsonAddStringToObject(item, "fqdn", pObj->fqdn);
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpBnode(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpSnode(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpQnode(SSdb *pSdb, SJson *json) {}
|
||||
|
||||
void dumpMnode(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "mnodes", items);
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "mnode", item);
|
||||
|
||||
tjsonAddIntegerToObject(item, "id", pObj->id);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpCluster(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "clusters", items);
|
||||
|
||||
while (1) {
|
||||
SClusterObj *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "cluster", item);
|
||||
|
||||
tjsonAddStringToObject(item, "id", i642str(pObj->id));
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime));
|
||||
tjsonAddStringToObject(item, "name", pObj->name);
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpTrans(SSdb *pSdb, SJson *json) {
|
||||
void *pIter = NULL;
|
||||
SJson *items = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "transactions", items);
|
||||
|
||||
while (1) {
|
||||
STrans *pObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_TRANS, pIter, (void **)&pObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SJson *item = tjsonCreateObject();
|
||||
tjsonAddItemToObject(items, "trans", item);
|
||||
|
||||
tjsonAddIntegerToObject(item, "id", pObj->id);
|
||||
tjsonAddIntegerToObject(item, "stage", pObj->stage);
|
||||
tjsonAddIntegerToObject(item, "policy", pObj->policy);
|
||||
tjsonAddIntegerToObject(item, "conflict", pObj->conflict);
|
||||
tjsonAddIntegerToObject(item, "exec", pObj->exec);
|
||||
tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime));
|
||||
tjsonAddStringToObject(item, "dbname1", pObj->dbname1);
|
||||
tjsonAddStringToObject(item, "dbname2", pObj->dbname2);
|
||||
tjsonAddIntegerToObject(item, "commitLogNum", taosArrayGetSize(pObj->commitActions));
|
||||
tjsonAddIntegerToObject(item, "redoActionNum", taosArrayGetSize(pObj->redoActions));
|
||||
tjsonAddIntegerToObject(item, "undoActionNum", taosArrayGetSize(pObj->undoActions));
|
||||
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpHeader(SSdb *pSdb, SJson *json) {
|
||||
tjsonAddIntegerToObject(json, "sver", 1);
|
||||
tjsonAddStringToObject(json, "applyIndex", i642str(pSdb->applyIndex));
|
||||
tjsonAddStringToObject(json, "applyTerm", i642str(pSdb->applyTerm));
|
||||
tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig));
|
||||
|
||||
SJson *maxIdsJson = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "maxIds", maxIdsJson);
|
||||
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||
int64_t maxId = 0;
|
||||
if (i < SDB_MAX) {
|
||||
maxId = pSdb->maxId[i];
|
||||
}
|
||||
tjsonAddStringToObject(maxIdsJson, sdbTableName(i), i642str(maxId));
|
||||
}
|
||||
|
||||
SJson *tableVersJson = tjsonCreateObject();
|
||||
tjsonAddItemToObject(json, "tableVers", tableVersJson);
|
||||
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||
int64_t tableVer = 0;
|
||||
if (i < SDB_MAX) {
|
||||
tableVer = pSdb->tableVer[i];
|
||||
}
|
||||
tjsonAddStringToObject(tableVersJson, sdbTableName(i), i642str(tableVer));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dumpSdb() {
|
||||
wDebugFlag = 0;
|
||||
mDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
|
||||
SMsgCb msgCb = {0};
|
||||
msgCb.reportStartupFp = reportStartup;
|
||||
msgCb.sendReqFp = sendReq;
|
||||
msgCb.sendRspFp = sendRsp;
|
||||
msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack
|
||||
tmsgSetDefault(&msgCb);
|
||||
walInit();
|
||||
syncInit();
|
||||
|
||||
SMnodeOpt opt = {.msgCb = msgCb};
|
||||
SMnode *pMnode = mndOpen(TMP_MNODE_DIR, &opt);
|
||||
if (pMnode == NULL) return -1;
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SJson *json = tjsonCreateObject();
|
||||
dumpHeader(pSdb, json);
|
||||
dumpFunc(pSdb, json);
|
||||
dumpDb(pSdb, json);
|
||||
dumpStb(pSdb, json);
|
||||
dumpSma(pSdb, json);
|
||||
dumpVgroup(pSdb, json);
|
||||
dumpTopic(pSdb, json);
|
||||
dumpConsumber(pSdb, json);
|
||||
dumpSubscribe(pSdb, json);
|
||||
dumpOffset(pSdb, json);
|
||||
dumpStream(pSdb, json);
|
||||
dumpAcct(pSdb, json);
|
||||
dumpAuth(pSdb, json);
|
||||
dumpUser(pSdb, json);
|
||||
dumpDnode(pSdb, json);
|
||||
dumpBnode(pSdb, json);
|
||||
dumpSnode(pSdb, json);
|
||||
dumpQnode(pSdb, json);
|
||||
dumpMnode(pSdb, json);
|
||||
dumpCluster(pSdb, json);
|
||||
dumpTrans(pSdb, json);
|
||||
|
||||
char *pCont = tjsonToString(json);
|
||||
int32_t contLen = strlen(pCont);
|
||||
char file[] = "sdb.json";
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
taosWriteFile(pFile, pCont, contLen);
|
||||
taosWriteFile(pFile, "\n", 1);
|
||||
taosFsyncFile(pFile);
|
||||
taosCloseFile(&pFile);
|
||||
tjsonDelete(json);
|
||||
taosMemoryFree(pCont);
|
||||
taosRemoveDir(TMP_DNODE_DIR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t parseArgs(int32_t argc, char *argv[]) {
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
}
|
||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
printf("-c Configuration directory. \n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosCreateLog("dumplog", 1, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||
printf("failed to dump since init log error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||
printf("failed to dump since read config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char mnodeJson[PATH_MAX] = {0};
|
||||
char dataFile[PATH_MAX] = {0};
|
||||
char raftCfgFile[PATH_MAX] = {0};
|
||||
char raftStoreFile[PATH_MAX] = {0};
|
||||
snprintf(mnodeJson, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "mnode.json", tsDataDir);
|
||||
snprintf(dataFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "data" TD_DIRSEP "sdb.data", tsDataDir);
|
||||
snprintf(raftCfgFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_config.json", tsDataDir);
|
||||
snprintf(raftStoreFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_store.json", tsDataDir);
|
||||
|
||||
char cmd[PATH_MAX * 2] = {0};
|
||||
snprintf(cmd, sizeof(cmd), "rm -rf %s", TMP_DNODE_DIR);
|
||||
|
||||
system(cmd);
|
||||
#ifdef WINDOWS
|
||||
taosMulMkDir(TMP_SDB_DATA_DIR);
|
||||
taosMulMkDir(TMP_SDB_SYNC_DIR);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", mnodeJson, TMP_SDB_MNODE_JSON);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", dataFile, TMP_SDB_DATA_FILE);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", raftCfgFile, TMP_SDB_RAFT_CFG_FILE);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", raftStoreFile, TMP_SDB_RAFT_STORE_FILE);
|
||||
system(cmd);
|
||||
#else
|
||||
snprintf(cmd, sizeof(cmd), "mkdir -p %s", TMP_SDB_DATA_DIR);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "mkdir -p %s", TMP_SDB_SYNC_DIR);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", mnodeJson, TMP_SDB_MNODE_JSON);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", dataFile, TMP_SDB_DATA_FILE);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", raftCfgFile, TMP_SDB_RAFT_CFG_FILE);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", raftStoreFile, TMP_SDB_RAFT_STORE_FILE);
|
||||
system(cmd);
|
||||
#endif
|
||||
|
||||
strcpy(tsDataDir, TMP_DNODE_DIR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t main(int32_t argc, char *argv[]) {
|
||||
if (parseArgs(argc, argv) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dumpSdb();
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
File diff suppressed because it is too large
Load Diff
|
@ -1,705 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
// #include <unistd.h>
|
||||
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#define GREEN "\033[1;32m"
|
||||
#define NC "\033[0m"
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define MAX_SQL_STR_LEN (1024 * 1024)
|
||||
#define MAX_ROW_STR_LEN (16 * 1024)
|
||||
|
||||
enum _RUN_MODE {
|
||||
TMQ_RUN_INSERT_AND_CONSUME,
|
||||
TMQ_RUN_ONLY_INSERT,
|
||||
TMQ_RUN_ONLY_CONSUME,
|
||||
TMQ_RUN_MODE_BUTT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char dbName[32];
|
||||
char stbName[64];
|
||||
char resultFileName[256];
|
||||
char vnodeWalPath[256];
|
||||
int32_t numOfThreads;
|
||||
int32_t numOfTables;
|
||||
int32_t numOfVgroups;
|
||||
int32_t runMode;
|
||||
int32_t numOfColumn;
|
||||
double ratio;
|
||||
int32_t batchNumOfRow;
|
||||
int32_t totalRowsOfPerTbl;
|
||||
int64_t startTimestamp;
|
||||
int32_t showMsgFlag;
|
||||
int32_t simCase;
|
||||
|
||||
int32_t totalRowsOfT2;
|
||||
} SConfInfo;
|
||||
|
||||
static SConfInfo g_stConfInfo = {
|
||||
"tmqdb",
|
||||
"stb",
|
||||
"./tmqResult.txt", // output_file
|
||||
"", // /data2/dnode/data/vnode/vnode2/wal",
|
||||
1, // threads
|
||||
1, // tables
|
||||
1, // vgroups
|
||||
0, // run mode
|
||||
1, // columns
|
||||
1, // ratio
|
||||
1, // batch size
|
||||
10000, // total rows for per table
|
||||
0, // 2020-01-01 00:00:00.000
|
||||
0, // show consume msg switch
|
||||
0, // if run in sim case
|
||||
10000,
|
||||
};
|
||||
|
||||
char* g_pRowValue = NULL;
|
||||
TdFilePtr g_fp = NULL;
|
||||
|
||||
static void printHelp() {
|
||||
char indent[10] = " ";
|
||||
printf("Used to test the performance while create table\n");
|
||||
|
||||
printf("%s%s\n", indent, "-c");
|
||||
printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir);
|
||||
printf("%s%s\n", indent, "-d");
|
||||
printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", g_stConfInfo.dbName);
|
||||
printf("%s%s\n", indent, "-s");
|
||||
printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", g_stConfInfo.stbName);
|
||||
printf("%s%s\n", indent, "-f");
|
||||
printf("%s%s%s%s\n", indent, indent, "The file of result, default is ", g_stConfInfo.resultFileName);
|
||||
printf("%s%s\n", indent, "-w");
|
||||
printf("%s%s%s%s\n", indent, indent, "The path of vnode of wal, default is ", g_stConfInfo.vnodeWalPath);
|
||||
printf("%s%s\n", indent, "-t");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", g_stConfInfo.numOfThreads);
|
||||
printf("%s%s\n", indent, "-n");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfTables, default is ", g_stConfInfo.numOfTables);
|
||||
printf("%s%s\n", indent, "-v");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfVgroups, default is ", g_stConfInfo.numOfVgroups);
|
||||
printf("%s%s\n", indent, "-a");
|
||||
printf("%s%s%s%d\n", indent, indent, "runMode, default is ", g_stConfInfo.runMode);
|
||||
printf("%s%s\n", indent, "-l");
|
||||
printf("%s%s%s%d\n", indent, indent, "numOfColumn, default is ", g_stConfInfo.numOfColumn);
|
||||
printf("%s%s\n", indent, "-q");
|
||||
printf("%s%s%s%f\n", indent, indent, "ratio, default is ", g_stConfInfo.ratio);
|
||||
printf("%s%s\n", indent, "-b");
|
||||
printf("%s%s%s%d\n", indent, indent, "batchNumOfRow, default is ", g_stConfInfo.batchNumOfRow);
|
||||
printf("%s%s\n", indent, "-r");
|
||||
printf("%s%s%s%d\n", indent, indent, "totalRowsOfPerTbl, default is ", g_stConfInfo.totalRowsOfPerTbl);
|
||||
printf("%s%s\n", indent, "-m");
|
||||
printf("%s%s%s%" PRId64 "\n", indent, indent, "startTimestamp, default is ", g_stConfInfo.startTimestamp);
|
||||
printf("%s%s\n", indent, "-g");
|
||||
printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag);
|
||||
printf("%s%s\n", indent, "-sim");
|
||||
printf("%s%s%s%d\n", indent, indent, "simCase, default is ", g_stConfInfo.simCase);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void parseArgument(int32_t argc, char* argv[]) {
|
||||
g_stConfInfo.startTimestamp = 1640966400000; // 2020-01-01 00:00:00.000
|
||||
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
printHelp();
|
||||
exit(0);
|
||||
} else if (strcmp(argv[i], "-d") == 0) {
|
||||
strcpy(g_stConfInfo.dbName, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-c") == 0) {
|
||||
strcpy(configDir, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-s") == 0) {
|
||||
strcpy(g_stConfInfo.stbName, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-w") == 0) {
|
||||
strcpy(g_stConfInfo.vnodeWalPath, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-f") == 0) {
|
||||
strcpy(g_stConfInfo.resultFileName, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-t") == 0) {
|
||||
g_stConfInfo.numOfThreads = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
g_stConfInfo.numOfTables = atoll(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-v") == 0) {
|
||||
g_stConfInfo.numOfVgroups = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
g_stConfInfo.runMode = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-b") == 0) {
|
||||
g_stConfInfo.batchNumOfRow = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-r") == 0) {
|
||||
g_stConfInfo.totalRowsOfPerTbl = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-l") == 0) {
|
||||
g_stConfInfo.numOfColumn = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-q") == 0) {
|
||||
g_stConfInfo.ratio = atof(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-m") == 0) {
|
||||
g_stConfInfo.startTimestamp = atol(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-g") == 0) {
|
||||
g_stConfInfo.showMsgFlag = atol(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-sim") == 0) {
|
||||
g_stConfInfo.simCase = atol(argv[++i]);
|
||||
} else {
|
||||
printf("%s unknow para: %s %s", GREEN, argv[++i], NC);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
g_stConfInfo.totalRowsOfT2 = g_stConfInfo.totalRowsOfPerTbl * g_stConfInfo.ratio;
|
||||
|
||||
#if 0
|
||||
pPrint("%s configDir:%s %s", GREEN, configDir, NC);
|
||||
pPrint("%s dbName:%s %s", GREEN, g_stConfInfo.dbName, NC);
|
||||
pPrint("%s stbName:%s %s", GREEN, g_stConfInfo.stbName, NC);
|
||||
pPrint("%s resultFileName:%s %s", GREEN, g_stConfInfo.resultFileName, NC);
|
||||
pPrint("%s vnodeWalPath:%s %s", GREEN, g_stConfInfo.vnodeWalPath, NC);
|
||||
pPrint("%s numOfTables:%d %s", GREEN, g_stConfInfo.numOfTables, NC);
|
||||
pPrint("%s numOfThreads:%d %s", GREEN, g_stConfInfo.numOfThreads, NC);
|
||||
pPrint("%s numOfVgroups:%d %s", GREEN, g_stConfInfo.numOfVgroups, NC);
|
||||
pPrint("%s runMode:%d %s", GREEN, g_stConfInfo.runMode, NC);
|
||||
pPrint("%s ratio:%f %s", GREEN, g_stConfInfo.ratio, NC);
|
||||
pPrint("%s numOfColumn:%d %s", GREEN, g_stConfInfo.numOfColumn, NC);
|
||||
pPrint("%s batchNumOfRow:%d %s", GREEN, g_stConfInfo.batchNumOfRow, NC);
|
||||
pPrint("%s totalRowsOfPerTbl:%d %s", GREEN, g_stConfInfo.totalRowsOfPerTbl, NC);
|
||||
pPrint("%s totalRowsOfT2:%d %s", GREEN, g_stConfInfo.totalRowsOfT2, NC);
|
||||
pPrint("%s startTimestamp:%" PRId64" %s", GREEN, g_stConfInfo.startTimestamp, NC);
|
||||
pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int running = 1;
|
||||
/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/
|
||||
|
||||
// calc dir size (not include itself 4096Byte)
|
||||
int64_t getDirectorySize(char* dir) {
|
||||
TdDirPtr pDir;
|
||||
TdDirEntryPtr pDirEntry;
|
||||
int64_t totalSize = 0;
|
||||
|
||||
if ((pDir = taosOpenDir(dir)) == NULL) {
|
||||
fprintf(stderr, "Cannot open dir: %s\n", dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// lstat(dir, &statbuf);
|
||||
// totalSize+=statbuf.st_size;
|
||||
|
||||
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
|
||||
char subdir[1024];
|
||||
char* fileName = taosGetDirEntryName(pDirEntry);
|
||||
sprintf(subdir, "%s/%s", dir, fileName);
|
||||
|
||||
// printf("===d_name: %s\n", entry->d_name);
|
||||
if (taosIsDir(subdir)) {
|
||||
if (strcmp(".", fileName) == 0 || strcmp("..", fileName) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t subDirSize = getDirectorySize(subdir);
|
||||
totalSize += subDirSize;
|
||||
} else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file
|
||||
int64_t file_size = 0;
|
||||
taosStatFile(subdir, &file_size, NULL);
|
||||
totalSize += file_size;
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseDir(&pDir);
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
int queryDB(TAOS* taos, char* command) {
|
||||
TAOS_RES* pRes = taos_query(taos, command);
|
||||
int code = taos_errno(pRes);
|
||||
if (code != 0) {
|
||||
pError("failed to reason:%s, sql: %s", tstrerror(code), command);
|
||||
taos_free_result(pRes);
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t init_env() {
|
||||
char sqlStr[1024] = {0};
|
||||
|
||||
TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(sqlStr, "create database if not exists %s vgroups %d", g_stConfInfo.dbName, g_stConfInfo.numOfVgroups);
|
||||
TAOS_RES* pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
sprintf(sqlStr, "use %s", g_stConfInfo.dbName);
|
||||
pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
// create row value
|
||||
g_pRowValue = (char*)taosMemoryCalloc(1, g_stConfInfo.numOfColumn * 16 + 128);
|
||||
if (NULL == g_pRowValue) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t dataLen = 0;
|
||||
int32_t sqlLen = 0;
|
||||
sqlLen += sprintf(sqlStr + sqlLen, "create stable if not exists %s (ts timestamp, ", g_stConfInfo.stbName);
|
||||
for (int32_t i = 0; i < g_stConfInfo.numOfColumn; i++) {
|
||||
if (i == g_stConfInfo.numOfColumn - 1) {
|
||||
sqlLen += sprintf(sqlStr + sqlLen, "c%d int) ", i);
|
||||
memcpy(g_pRowValue + dataLen, "66778899", strlen("66778899"));
|
||||
dataLen += strlen("66778899");
|
||||
} else {
|
||||
sqlLen += sprintf(sqlStr + sqlLen, "c%d int, ", i);
|
||||
memcpy(g_pRowValue + dataLen, "66778899, ", strlen("66778899, "));
|
||||
dataLen += strlen("66778899, ");
|
||||
}
|
||||
}
|
||||
sqlLen += sprintf(sqlStr + sqlLen, "tags (t0 int)");
|
||||
|
||||
pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table %s, reason:%s\n", g_stConfInfo.stbName, taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
for (int32_t i = 0; i < g_stConfInfo.numOfTables; i++) {
|
||||
sprintf(sqlStr, "create table if not exists %s%d using %s tags(1)", g_stConfInfo.stbName, i, g_stConfInfo.stbName);
|
||||
pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table %s%d, reason:%s\n", g_stConfInfo.stbName, i, taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
// const char* sql = "select * from tu1";
|
||||
sprintf(sqlStr, "create topic test_stb_topic_1 as select ts,c0 from %s", g_stConfInfo.stbName);
|
||||
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sqlStr, strlen(sqlStr));*/
|
||||
pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmq_t* build_consumer() {
|
||||
#if 0
|
||||
char sqlStr[1024] = {0};
|
||||
|
||||
TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
sprintf(sqlStr, "use %s", g_stConfInfo.dbName);
|
||||
TAOS_RES* pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
#endif
|
||||
|
||||
tmq_conf_t* conf = tmq_conf_new();
|
||||
tmq_conf_set(conf, "group.id", "tg2");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName);
|
||||
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
||||
assert(tmq);
|
||||
tmq_conf_destroy(conf);
|
||||
return tmq;
|
||||
}
|
||||
|
||||
tmq_list_t* build_topic_list() {
|
||||
tmq_list_t* topic_list = tmq_list_new();
|
||||
tmq_list_append(topic_list, "test_stb_topic_1");
|
||||
return topic_list;
|
||||
}
|
||||
|
||||
void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
|
||||
static const int MIN_COMMIT_COUNT = 1000;
|
||||
|
||||
int msg_count = 0;
|
||||
int32_t err;
|
||||
|
||||
if ((err = tmq_subscribe(tmq, topics))) {
|
||||
fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err));
|
||||
return;
|
||||
}
|
||||
|
||||
while (running) {
|
||||
TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1);
|
||||
if (tmqmessage) {
|
||||
/*msg_process(tmqmessage);*/
|
||||
taos_free_result(tmqmessage);
|
||||
|
||||
if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit_sync(tmq, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
err = tmq_consumer_close(tmq);
|
||||
if (err)
|
||||
fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err));
|
||||
else
|
||||
fprintf(stderr, "%% Consumer closed\n");
|
||||
}
|
||||
|
||||
void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLogSize) {
|
||||
int32_t err;
|
||||
|
||||
if ((err = tmq_subscribe(tmq, topics))) {
|
||||
fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err));
|
||||
printf("subscribe err\n");
|
||||
return;
|
||||
}
|
||||
/*taosSsleep(3);*/
|
||||
int32_t batchCnt = 0;
|
||||
int64_t startTime = taosGetTimestampUs();
|
||||
while (running) {
|
||||
TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 3000);
|
||||
if (tmqmessage) {
|
||||
batchCnt++;
|
||||
if (0 != g_stConfInfo.showMsgFlag) {
|
||||
/*msg_process(tmqmessage);*/
|
||||
}
|
||||
taos_free_result(tmqmessage);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int64_t endTime = taosGetTimestampUs();
|
||||
double consumeTime = (double)(endTime - startTime) / 1000000;
|
||||
|
||||
if (batchCnt != totalMsgs) {
|
||||
printf("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC);
|
||||
/*exit(-1);*/
|
||||
}
|
||||
|
||||
if (0 == g_stConfInfo.simCase) {
|
||||
printf("consume result: msgs: %d, time used:%.3f second\n", batchCnt, consumeTime);
|
||||
} else {
|
||||
printf("{consume success: %d}", totalMsgs);
|
||||
}
|
||||
taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.2f| %10.2f |\n", batchCnt, consumeTime,
|
||||
(double)batchCnt / consumeTime, (double)walLogSize / (1024 * 1024.0) / consumeTime,
|
||||
(double)walLogSize / 1024.0 / batchCnt);
|
||||
|
||||
err = tmq_consumer_close(tmq);
|
||||
if (err) {
|
||||
fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// sync insertion
|
||||
int32_t syncWriteData() {
|
||||
TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char sqlStr[1024] = {0};
|
||||
sprintf(sqlStr, "use %s", g_stConfInfo.dbName);
|
||||
TAOS_RES* pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
char* buffer = NULL;
|
||||
buffer = (char*)taosMemoryMalloc(MAX_SQL_STR_LEN);
|
||||
if (NULL == buffer) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t totalMsgs = 0;
|
||||
|
||||
int64_t time_counter = g_stConfInfo.startTimestamp;
|
||||
for (int i = 0; i < g_stConfInfo.totalRowsOfPerTbl;) {
|
||||
for (int tID = 0; tID <= g_stConfInfo.numOfTables - 1; tID++) {
|
||||
int inserted = i;
|
||||
int64_t tmp_time = time_counter;
|
||||
|
||||
int32_t data_len = 0;
|
||||
data_len += sprintf(buffer + data_len, "insert into %s%d values", g_stConfInfo.stbName, tID);
|
||||
int k;
|
||||
for (k = 0; k < g_stConfInfo.batchNumOfRow;) {
|
||||
data_len += sprintf(buffer + data_len, "(%" PRId64 ", %s) ", tmp_time++, g_pRowValue);
|
||||
inserted++;
|
||||
k++;
|
||||
|
||||
if (inserted >= g_stConfInfo.totalRowsOfPerTbl) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int code = queryDB(pConn, buffer);
|
||||
if (0 != code) {
|
||||
fprintf(stderr, "insert data error!\n");
|
||||
taosMemoryFreeClear(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
totalMsgs++;
|
||||
|
||||
if (tID == g_stConfInfo.numOfTables - 1) {
|
||||
i = inserted;
|
||||
time_counter = tmp_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
taosMemoryFreeClear(buffer);
|
||||
return totalMsgs;
|
||||
}
|
||||
|
||||
// sync insertion
|
||||
int32_t syncWriteDataByRatio() {
|
||||
TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char sqlStr[1024] = {0};
|
||||
sprintf(sqlStr, "use %s", g_stConfInfo.dbName);
|
||||
TAOS_RES* pRes = taos_query(pConn, sqlStr);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
char* buffer = NULL;
|
||||
buffer = (char*)taosMemoryMalloc(MAX_SQL_STR_LEN);
|
||||
if (NULL == buffer) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t totalMsgs = 0;
|
||||
|
||||
int32_t insertedOfT1 = 0;
|
||||
int32_t insertedOfT2 = 0;
|
||||
|
||||
int64_t tsOfT1 = g_stConfInfo.startTimestamp;
|
||||
int64_t tsOfT2 = g_stConfInfo.startTimestamp;
|
||||
int64_t tmp_time;
|
||||
|
||||
for (;;) {
|
||||
if ((insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) && (insertedOfT2 >= g_stConfInfo.totalRowsOfT2)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (int tID = 0; tID <= g_stConfInfo.numOfTables - 1; tID++) {
|
||||
if (0 == tID) {
|
||||
tmp_time = tsOfT1;
|
||||
if (insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) {
|
||||
continue;
|
||||
}
|
||||
} else if (1 == tID) {
|
||||
tmp_time = tsOfT2;
|
||||
if (insertedOfT2 >= g_stConfInfo.totalRowsOfT2) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t data_len = 0;
|
||||
data_len += sprintf(buffer + data_len, "insert into %s%d values", g_stConfInfo.stbName, tID);
|
||||
int k;
|
||||
for (k = 0; k < g_stConfInfo.batchNumOfRow;) {
|
||||
data_len += sprintf(buffer + data_len, "(%" PRId64 ", %s) ", tmp_time++, g_pRowValue);
|
||||
k++;
|
||||
if (0 == tID) {
|
||||
insertedOfT1++;
|
||||
if (insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) {
|
||||
break;
|
||||
}
|
||||
} else if (1 == tID) {
|
||||
insertedOfT2++;
|
||||
if (insertedOfT2 >= g_stConfInfo.totalRowsOfT2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int code = queryDB(pConn, buffer);
|
||||
if (0 != code) {
|
||||
fprintf(stderr, "insert data error!\n");
|
||||
taosMemoryFreeClear(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == tID) {
|
||||
tsOfT1 = tmp_time;
|
||||
} else if (1 == tID) {
|
||||
tsOfT2 = tmp_time;
|
||||
}
|
||||
|
||||
totalMsgs++;
|
||||
}
|
||||
}
|
||||
pPrint("expect insert rows: T1[%d] T2[%d], actual insert rows: T1[%d] T2[%d]\n", g_stConfInfo.totalRowsOfPerTbl,
|
||||
g_stConfInfo.totalRowsOfT2, insertedOfT1, insertedOfT2);
|
||||
taosMemoryFreeClear(buffer);
|
||||
return totalMsgs;
|
||||
}
|
||||
|
||||
void printParaIntoFile() {
|
||||
// FILE *fp = fopen(g_stConfInfo.resultFileName, "a");
|
||||
TdFilePtr pFile =
|
||||
taosOpenFile(g_stConfInfo.resultFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_STREAM);
|
||||
if (NULL == pFile) {
|
||||
fprintf(stderr, "Failed to open %s for save result\n", g_stConfInfo.resultFileName);
|
||||
exit(-1);
|
||||
}
|
||||
g_fp = pFile;
|
||||
|
||||
time_t tTime = taosGetTimestampSec();
|
||||
struct tm tm;
|
||||
taosLocalTime(&tTime, &tm);
|
||||
|
||||
taosFprintfFile(pFile, "###################################################################\n");
|
||||
taosFprintfFile(pFile, "# configDir: %s\n", configDir);
|
||||
taosFprintfFile(pFile, "# dbName: %s\n", g_stConfInfo.dbName);
|
||||
taosFprintfFile(pFile, "# stbName: %s\n", g_stConfInfo.stbName);
|
||||
taosFprintfFile(pFile, "# vnodeWalPath: %s\n", g_stConfInfo.vnodeWalPath);
|
||||
taosFprintfFile(pFile, "# numOfTables: %d\n", g_stConfInfo.numOfTables);
|
||||
taosFprintfFile(pFile, "# numOfThreads: %d\n", g_stConfInfo.numOfThreads);
|
||||
taosFprintfFile(pFile, "# numOfVgroups: %d\n", g_stConfInfo.numOfVgroups);
|
||||
taosFprintfFile(pFile, "# runMode: %d\n", g_stConfInfo.runMode);
|
||||
taosFprintfFile(pFile, "# ratio: %f\n", g_stConfInfo.ratio);
|
||||
taosFprintfFile(pFile, "# numOfColumn: %d\n", g_stConfInfo.numOfColumn);
|
||||
taosFprintfFile(pFile, "# batchNumOfRow: %d\n", g_stConfInfo.batchNumOfRow);
|
||||
taosFprintfFile(pFile, "# totalRowsOfPerTbl: %d\n", g_stConfInfo.totalRowsOfPerTbl);
|
||||
taosFprintfFile(pFile, "# totalRowsOfT2: %d\n", g_stConfInfo.totalRowsOfT2);
|
||||
taosFprintfFile(pFile, "# Test time: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1,
|
||||
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
taosFprintfFile(pFile, "###################################################################\n");
|
||||
taosFprintfFile(pFile,
|
||||
"|-------------------------------insert "
|
||||
"info-----------------------------|--------------------------------consume "
|
||||
"info---------------------------------|\n");
|
||||
taosFprintfFile(pFile,
|
||||
"|batch size| insert msgs | insert time(s) | msgs/s | walLogSize(MB) | consume msgs | consume "
|
||||
"time(s) | msgs/s | MB/s | avg msg size(KB) |\n");
|
||||
taosFprintfFile(g_fp, "|%10d", g_stConfInfo.batchNumOfRow);
|
||||
}
|
||||
|
||||
int main(int32_t argc, char* argv[]) {
|
||||
parseArgument(argc, argv);
|
||||
printParaIntoFile();
|
||||
|
||||
int64_t walLogSize = 0;
|
||||
|
||||
int code;
|
||||
code = init_env();
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "%% init_env error!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t totalMsgs = 0;
|
||||
|
||||
if (g_stConfInfo.runMode != TMQ_RUN_ONLY_CONSUME) {
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
if (1 == g_stConfInfo.ratio) {
|
||||
totalMsgs = syncWriteData();
|
||||
} else {
|
||||
totalMsgs = syncWriteDataByRatio();
|
||||
}
|
||||
|
||||
if (totalMsgs <= 0) {
|
||||
pError("inset data error!\n");
|
||||
return -1;
|
||||
}
|
||||
int64_t endTs = taosGetTimestampUs();
|
||||
int64_t delay = endTs - startTs;
|
||||
|
||||
int32_t totalRows = 0;
|
||||
if (1 == g_stConfInfo.ratio) {
|
||||
totalRows = g_stConfInfo.totalRowsOfPerTbl * g_stConfInfo.numOfTables;
|
||||
} else {
|
||||
totalRows = g_stConfInfo.totalRowsOfPerTbl * (1 + g_stConfInfo.ratio);
|
||||
}
|
||||
|
||||
float seconds = delay / 1000000.0;
|
||||
float rowsSpeed = totalRows / seconds;
|
||||
float msgsSpeed = totalMsgs / seconds;
|
||||
|
||||
if ((0 == g_stConfInfo.simCase) && (strlen(g_stConfInfo.vnodeWalPath))) {
|
||||
walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath);
|
||||
if (walLogSize <= 0) {
|
||||
printf("%s size incorrect!", g_stConfInfo.vnodeWalPath);
|
||||
exit(-1);
|
||||
} else {
|
||||
pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize / (1024 * 1024.0));
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == g_stConfInfo.simCase) {
|
||||
pPrint("insert result: %d rows, %d msgs, time:%.3f sec, speed:%.1f rows/second, %.1f msgs/second\n", totalRows,
|
||||
totalMsgs, seconds, rowsSpeed, msgsSpeed);
|
||||
}
|
||||
taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.3f ", totalMsgs, seconds, msgsSpeed,
|
||||
(double)walLogSize / (1024 * 1024.0));
|
||||
}
|
||||
|
||||
if (g_stConfInfo.runMode == TMQ_RUN_ONLY_INSERT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmq_t* tmq = build_consumer();
|
||||
tmq_list_t* topic_list = build_topic_list();
|
||||
if ((NULL == tmq) || (NULL == topic_list)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
perf_loop(tmq, topic_list, totalMsgs, walLogSize);
|
||||
|
||||
taosMemoryFreeClear(g_pRowValue);
|
||||
taosFprintfFile(g_fp, "\n");
|
||||
taosCloseFile(&g_fp);
|
||||
return 0;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -1,623 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "taos.h"
|
||||
#include "types.h"
|
||||
|
||||
static int running = 1;
|
||||
TdFilePtr g_fp = NULL;
|
||||
typedef struct{
|
||||
bool snapShot;
|
||||
bool dropTable;
|
||||
bool subTable;
|
||||
int srcVgroups;
|
||||
int dstVgroups;
|
||||
char dir[64];
|
||||
}Config;
|
||||
|
||||
Config g_conf = {0};
|
||||
|
||||
static TAOS* use_db(){
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use db_taosx");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db_taosx, reason:%s\n", taos_errstr(pRes));
|
||||
return NULL;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
return pConn;
|
||||
}
|
||||
|
||||
static void msg_process(TAOS_RES* msg) {
|
||||
printf("-----------topic-------------: %s\n", tmq_get_topic_name(msg));
|
||||
printf("db: %s\n", tmq_get_db_name(msg));
|
||||
printf("vg: %d\n", tmq_get_vgroup_id(msg));
|
||||
TAOS *pConn = use_db();
|
||||
if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META) {
|
||||
char* result = tmq_get_json_meta(msg);
|
||||
if (result) {
|
||||
printf("meta result: %s\n", result);
|
||||
}
|
||||
if(g_fp){
|
||||
taosFprintfFile(g_fp, result);
|
||||
taosFprintfFile(g_fp, "\n");
|
||||
}
|
||||
|
||||
tmq_free_json_meta(result);
|
||||
}
|
||||
|
||||
tmq_raw_data raw = {0};
|
||||
tmq_get_raw(msg, &raw);
|
||||
int32_t ret = tmq_write_raw(pConn, raw);
|
||||
printf("write raw data: %s\n", tmq_err2str(ret));
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
int buildDatabase(TAOS* pConn, TAOS_RES* pRes){
|
||||
pRes = taos_query(pConn,
|
||||
"create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 "
|
||||
"nchar(8), t4 bool)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000, \"ttt\", true)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct0 values(1626006833400, 1, 2, 'a')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists ct1 using st1(t1) tags(2000)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists ct2 using st1(t1) tags(NULL)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table ct2, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct1 values(1626006833600, 3, 4, 'b')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists ct3 using st1(t1) tags(3000)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct3 values(1626006833600, 5, 6, 'c') ct1 values(1626006833601, 2, 3, 'sds') (1626006833602, 4, 5, 'ddd') ct0 values(1626006833603, 4, 3, 'hwj') ct1 values(now+5s, 23, 32, 's21ds')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table st1 add column c4 bigint");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table st1 modify column c3 binary(64)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct3 values(1626006833605, 53, 63, 'cffffffffffffffffffffffffffff', 8989898899999) (1626006833609, 51, 62, 'c333', 940)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into ct3 select * from ct1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table st1 add tag t2 binary(64)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table ct3 set tag t1=5000");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to slter child table ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "delete from abc1 .ct3 where ts < 1626006833606");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
if(g_conf.dropTable){
|
||||
pRes = taos_query(pConn, "drop table ct3 ct1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop child table ct3, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop table st1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
pRes = taos_query(pConn, "create table if not exists n1(ts timestamp, c1 int, c2 nchar(4))");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table n1 add column c3 bigint");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table n1 modify column c2 nchar(8)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table n1 rename column c3 cc3");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table n1 comment 'hello'");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "alter table n1 drop column c1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into n1 values(now, 'eeee', 8989898899999) (now+9s, 'c333', 940)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
if(g_conf.dropTable){
|
||||
pRes = taos_query(pConn, "drop table n1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop normal table n1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
pRes = taos_query(pConn, "create table jt(ts timestamp, i int) tags(t json)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table jt, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table jt1 using jt tags('{\"k1\":1, \"k2\":\"hello\"}')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table jt, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table jt2 using jt tags('')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table jt2, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into jt1 values(now, 1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table jt1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into jt2 values(now, 11)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table jt2, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
if(g_conf.dropTable){
|
||||
pRes = taos_query(pConn,
|
||||
"create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 "
|
||||
"nchar(8), t4 bool)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop table st1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int buildStable(TAOS* pConn, TAOS_RES* pRes){
|
||||
pRes = taos_query(pConn, "CREATE STABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` VARCHAR(16))");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table meters, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table d0 using meters tags(1, 'San Francisco')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table d0, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table d1 using meters tags(2, 'Beijing')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table d1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create stream meters_summary_s into meters_summary as select _wstart, max(current) as current, groupid, location from meters partition by groupid, location interval(10m)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table meters_summary, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into d0 (ts, current) values (now, 120)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into table d0, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t init_env() {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop database if exists db_taosx");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop db_taosx, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
char sql[128] = {0};
|
||||
snprintf(sql, 128, "create database if not exists db_taosx vgroups %d", g_conf.dstVgroups);
|
||||
pRes = taos_query(pConn, sql);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db_taosx, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop topic if exists topic_db");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop topic, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop topic if exists meters_summary_t1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop topic, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop database if exists abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
snprintf(sql, 128, "create database if not exists abc1 vgroups %d", g_conf.srcVgroups);
|
||||
pRes = taos_query(pConn, sql);
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
if(g_conf.subTable){
|
||||
buildStable(pConn, pRes);
|
||||
}else{
|
||||
buildDatabase(pConn, pRes);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t create_topic() {
|
||||
printf("create topic\n");
|
||||
TAOS_RES* pRes;
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
if(g_conf.subTable){
|
||||
pRes = taos_query(pConn, "create topic meters_summary_t1 with meta as stable meters_summary");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic meters_summary_t1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}else{
|
||||
pRes = taos_query(pConn, "create topic topic_db with meta as database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic topic_db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) {
|
||||
printf("commit %d tmq %p param %p\n", code, tmq, param);
|
||||
}
|
||||
|
||||
tmq_t* build_consumer() {
|
||||
tmq_conf_t* conf = tmq_conf_new();
|
||||
tmq_conf_set(conf, "group.id", "tg2");
|
||||
tmq_conf_set(conf, "client.id", "my app 1");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "msg.with.table.name", "true");
|
||||
tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||
tmq_conf_set(conf, "enable.heartbeat.background", "true");
|
||||
|
||||
if(g_conf.snapShot){
|
||||
tmq_conf_set(conf, "experimental.snapshot.enable", "true");
|
||||
}
|
||||
|
||||
tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL);
|
||||
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
||||
assert(tmq);
|
||||
tmq_conf_destroy(conf);
|
||||
return tmq;
|
||||
}
|
||||
|
||||
tmq_list_t* build_topic_list() {
|
||||
tmq_list_t* topic_list = tmq_list_new();
|
||||
if(g_conf.subTable){
|
||||
tmq_list_append(topic_list, "meters_summary_t1");
|
||||
}else{
|
||||
tmq_list_append(topic_list, "topic_db");
|
||||
}
|
||||
return topic_list;
|
||||
}
|
||||
|
||||
void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
|
||||
int32_t code;
|
||||
|
||||
if ((code = tmq_subscribe(tmq, topics))) {
|
||||
fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(code));
|
||||
printf("subscribe err\n");
|
||||
return;
|
||||
}
|
||||
int32_t cnt = 0;
|
||||
while (running) {
|
||||
TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000);
|
||||
if (tmqmessage) {
|
||||
cnt++;
|
||||
msg_process(tmqmessage);
|
||||
taos_free_result(tmqmessage);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
code = tmq_consumer_close(tmq);
|
||||
if (code)
|
||||
fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(code));
|
||||
else
|
||||
fprintf(stderr, "%% Consumer closed\n");
|
||||
}
|
||||
|
||||
void initLogFile() {
|
||||
char f1[256] = {0};
|
||||
char f2[256] = {0};
|
||||
|
||||
if(g_conf.snapShot){
|
||||
sprintf(f1, "%s/../log/tmq_taosx_tmp_snapshot.source", g_conf.dir);
|
||||
sprintf(f2, "%s/../log/tmq_taosx_tmp_snapshot.result", g_conf.dir);
|
||||
}else{
|
||||
sprintf(f1, "%s/../log/tmq_taosx_tmp.source", g_conf.dir);
|
||||
sprintf(f2, "%s/../log/tmq_taosx_tmp.result", g_conf.dir);
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(f1, TD_FILE_TEXT | TD_FILE_TRUNC | TD_FILE_STREAM);
|
||||
if (NULL == pFile) {
|
||||
fprintf(stderr, "Failed to open %s for save result\n", f1);
|
||||
exit(-1);
|
||||
}
|
||||
g_fp = pFile;
|
||||
|
||||
TdFilePtr pFile2 = taosOpenFile(f2, TD_FILE_TEXT | TD_FILE_TRUNC | TD_FILE_STREAM);
|
||||
if (NULL == pFile2) {
|
||||
fprintf(stderr, "Failed to open %s for save result\n", f2);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(g_conf.snapShot){
|
||||
char *result[] = {
|
||||
"{\"type\":\"create\",\"tableName\":\"st1\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":64},{\"name\":\"c4\",\"type\":5}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1},{\"name\":\"t2\",\"type\":8,\"length\":64}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct0\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct1\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct2\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":5000}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c2\",\"type\":10,\"length\":8},{\"name\":\"cc3\",\"type\":5}],\"tags\":[]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt1\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt2\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[]}",
|
||||
};
|
||||
|
||||
for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
|
||||
taosFprintfFile(pFile2, result[i]);
|
||||
taosFprintfFile(pFile2, "\n");
|
||||
}
|
||||
}else{
|
||||
char *result[] = {
|
||||
"{\"type\":\"create\",\"tableName\":\"st1\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct0\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct1\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct2\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":3000}]}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":5,\"colName\":\"c4\",\"colType\":5}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":7,\"colName\":\"c3\",\"colType\":8,\"colLength\":64}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":1,\"colName\":\"t2\",\"colType\":8,\"colLength\":64}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"alterType\":4,\"colName\":\"t1\",\"colValue\":\"5000\",\"colValueNull\":false}",
|
||||
"{\"type\":\"create\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":10,\"length\":4}],\"tags\":[]}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":5,\"colName\":\"c3\",\"colType\":5}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":7,\"colName\":\"c2\",\"colType\":10,\"colLength\":8}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":10,\"colName\":\"c3\",\"colNewName\":\"cc3\"}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":9}",
|
||||
"{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":6,\"colName\":\"c1\"}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt1\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}]}",
|
||||
"{\"type\":\"create\",\"tableName\":\"jt2\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[]}"
|
||||
};
|
||||
|
||||
for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
|
||||
taosFprintfFile(pFile2, result[i]);
|
||||
taosFprintfFile(pFile2, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile2);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "-c") == 0){
|
||||
strcpy(g_conf.dir, argv[++i]);
|
||||
}else if(strcmp(argv[i], "-s") == 0){
|
||||
g_conf.snapShot = true;
|
||||
}else if(strcmp(argv[i], "-d") == 0){
|
||||
g_conf.dropTable = true;
|
||||
}else if(strcmp(argv[i], "-sv") == 0){
|
||||
g_conf.srcVgroups = atol(argv[++i]);
|
||||
}else if(strcmp(argv[i], "-dv") == 0){
|
||||
g_conf.dstVgroups = atol(argv[++i]);
|
||||
}else if(strcmp(argv[i], "-t") == 0){
|
||||
g_conf.subTable = true;
|
||||
}
|
||||
}
|
||||
|
||||
printf("env init\n");
|
||||
if(strlen(g_conf.dir) != 0){
|
||||
initLogFile();
|
||||
}
|
||||
|
||||
if (init_env() < 0) {
|
||||
return -1;
|
||||
}
|
||||
create_topic();
|
||||
|
||||
tmq_t* tmq = build_consumer();
|
||||
tmq_list_t* topic_list = build_topic_list();
|
||||
basic_consume_loop(tmq, topic_list);
|
||||
taosCloseFile(&g_fp);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
aux_source_directory(src TSIM_SRC)
|
||||
add_executable(tsim ${TSIM_SRC})
|
||||
target_link_libraries(
|
||||
tsim
|
||||
PUBLIC taos_static
|
||||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC os
|
||||
PUBLIC cjson
|
||||
)
|
||||
target_include_directories(
|
||||
tsim
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -1,186 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_SIM_INT_H_
|
||||
#define _TD_SIM_INT_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "tconfig.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "tidpool.h"
|
||||
#include "tlog.h"
|
||||
#include "ttimer.h"
|
||||
#include "ttypes.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
#define MAX_MAIN_SCRIPT_NUM 10
|
||||
#define MAX_BACKGROUND_SCRIPT_NUM 10
|
||||
#define MAX_FILE_NAME_LEN 256
|
||||
#define MAX_ERROR_LEN 1024
|
||||
#define MAX_QUERY_VALUE_LEN 1024
|
||||
#define MAX_QUERY_COL_NUM 100
|
||||
#define MAX_QUERY_ROW_NUM 100
|
||||
#define MAX_SYSTEM_RESULT_LEN 2048
|
||||
#define MAX_VAR_LEN 100
|
||||
#define MAX_VAR_NAME_LEN 32
|
||||
#define MAX_VAR_VAL_LEN 80
|
||||
#define MAX_OPT_NAME_LEN 32
|
||||
#define MAX_SIM_CMD_NAME_LEN 40
|
||||
|
||||
#ifdef LINUX
|
||||
#define SUCCESS_PREFIX "\033[44;32;1m"
|
||||
#define SUCCESS_POSTFIX "\033[0m"
|
||||
#define FAILED_PREFIX "\033[44;31;1m"
|
||||
#define FAILED_POSTFIX "\033[0m"
|
||||
#else
|
||||
#define SUCCESS_PREFIX ""
|
||||
#define SUCCESS_POSTFIX ""
|
||||
#define FAILED_PREFIX ""
|
||||
#define FAILED_POSTFIX ""
|
||||
#endif
|
||||
|
||||
#define simFatal(...) { if (simDebugFlag & DEBUG_FATAL) { taosPrintLog("SIM FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||
#define simError(...) { if (simDebugFlag & DEBUG_ERROR) { taosPrintLog("SIM ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||
#define simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||
#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||
#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM ", DEBUG_DEBUG, simDebugFlag, __VA_ARGS__); }}
|
||||
#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM ", DEBUG_TRACE, simDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND };
|
||||
|
||||
enum {
|
||||
SIM_CMD_EXP,
|
||||
SIM_CMD_IF,
|
||||
SIM_CMD_ELIF,
|
||||
SIM_CMD_ELSE,
|
||||
SIM_CMD_ENDI,
|
||||
SIM_CMD_WHILE,
|
||||
SIM_CMD_ENDW,
|
||||
SIM_CMD_SWITCH,
|
||||
SIM_CMD_CASE,
|
||||
SIM_CMD_DEFAULT,
|
||||
SIM_CMD_CONTINUE,
|
||||
SIM_CMD_BREAK,
|
||||
SIM_CMD_ENDS,
|
||||
SIM_CMD_SLEEP,
|
||||
SIM_CMD_GOTO,
|
||||
SIM_CMD_RUN,
|
||||
SIM_CMD_RUN_BACK,
|
||||
SIM_CMD_PRINT,
|
||||
SIM_CMD_SYSTEM,
|
||||
SIM_CMD_SYSTEM_CONTENT,
|
||||
SIM_CMD_SQL,
|
||||
SIM_CMD_SQL_ERROR,
|
||||
SIM_CMD_SQL_SLOW,
|
||||
SIM_CMD_RESTFUL,
|
||||
SIM_CMD_TEST,
|
||||
SIM_CMD_RETURN,
|
||||
SIM_CMD_LINE_INSERT,
|
||||
SIM_CMD_LINE_INSERT_ERROR,
|
||||
SIM_CMD_END
|
||||
};
|
||||
|
||||
enum {
|
||||
SQL_JUMP_FALSE,
|
||||
SQL_JUMP_TRUE,
|
||||
};
|
||||
|
||||
struct _script_t;
|
||||
typedef struct _cmd_t {
|
||||
int16_t cmdno;
|
||||
int16_t nlen;
|
||||
char name[MAX_SIM_CMD_NAME_LEN];
|
||||
bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
|
||||
bool (*executeCmd)(struct _script_t *script, char *option);
|
||||
struct _cmd_t *next;
|
||||
} SCommand;
|
||||
|
||||
typedef struct {
|
||||
int16_t cmdno;
|
||||
int16_t jump; // jump position
|
||||
int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
|
||||
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
|
||||
int16_t lineNum; // correspodning line number in original file
|
||||
int32_t optionOffset; // relative option offset
|
||||
} SCmdLine;
|
||||
|
||||
typedef struct _var_t {
|
||||
char varName[MAX_VAR_NAME_LEN];
|
||||
char varValue[MAX_VAR_VAL_LEN];
|
||||
char varNameLen;
|
||||
} SVariable;
|
||||
|
||||
typedef struct _script_t {
|
||||
int32_t type;
|
||||
bool killed;
|
||||
void *taos;
|
||||
char rows[12]; // number of rows data retrieved
|
||||
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
|
||||
char system_exit_code[12];
|
||||
char system_ret_content[MAX_SYSTEM_RESULT_LEN];
|
||||
int32_t varLen;
|
||||
int32_t linePos; // current cmd position
|
||||
int32_t numOfLines; // number of lines in the script
|
||||
int32_t bgScriptLen;
|
||||
char fileName[MAX_FILE_NAME_LEN]; // script file name
|
||||
char error[MAX_ERROR_LEN];
|
||||
char *optionBuffer;
|
||||
SCmdLine *lines; // command list
|
||||
SVariable variables[MAX_VAR_LEN];
|
||||
TdThread bgPid;
|
||||
char auth[128];
|
||||
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
|
||||
} SScript;
|
||||
|
||||
extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
||||
extern SCommand simCmdList[];
|
||||
extern int32_t simScriptPos;
|
||||
extern int32_t simScriptSucced;
|
||||
extern int32_t simDebugFlag;
|
||||
extern char simScriptDir[];
|
||||
extern bool abortExecution;
|
||||
extern bool useMultiProcess;
|
||||
extern bool useValgrind;
|
||||
|
||||
SScript *simParseScript(char *fileName);
|
||||
SScript *simProcessCallOver(SScript *script);
|
||||
void *simExecuteScript(void *script);
|
||||
void simInitsimCmdList();
|
||||
bool simSystemInit();
|
||||
void simSystemCleanUp();
|
||||
char *simGetVariable(SScript *script, char *varName, int32_t varLen);
|
||||
bool simExecuteExpCmd(SScript *script, char *option);
|
||||
bool simExecuteTestCmd(SScript *script, char *option);
|
||||
bool simExecuteGotoCmd(SScript *script, char *option);
|
||||
bool simExecuteRunCmd(SScript *script, char *option);
|
||||
bool simExecuteRunBackCmd(SScript *script, char *option);
|
||||
bool simExecuteSystemCmd(SScript *script, char *option);
|
||||
bool simExecuteSystemContentCmd(SScript *script, char *option);
|
||||
bool simExecutePrintCmd(SScript *script, char *option);
|
||||
bool simExecuteSleepCmd(SScript *script, char *option);
|
||||
bool simExecuteReturnCmd(SScript *script, char *option);
|
||||
bool simExecuteSqlCmd(SScript *script, char *option);
|
||||
bool simExecuteSqlErrorCmd(SScript *script, char *rest);
|
||||
bool simExecuteSqlSlowCmd(SScript *script, char *option);
|
||||
bool simExecuteRestfulCmd(SScript *script, char *rest);
|
||||
bool simExecuteLineInsertCmd(SScript *script, char *option);
|
||||
bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
|
||||
void simVisuallizeOption(SScript *script, char *src, char *dst);
|
||||
|
||||
#endif /*_TD_SIM_INT_H_*/
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_SIM_PARSE_H_
|
||||
#define _TD_SIM_PARSE_H_
|
||||
|
||||
#include "simInt.h"
|
||||
|
||||
#define MAX_NUM_CMD 64
|
||||
#define MAX_NUM_LABLES 100
|
||||
#define MAX_LABEL_LEN 40
|
||||
#define MAX_NUM_BLOCK 100
|
||||
#define MAX_NUM_JUMP 100
|
||||
#define MAX_LINE_LEN 3000
|
||||
#define MAX_CMD_LINES 2048
|
||||
#define MAX_OPTION_BUFFER 64000
|
||||
|
||||
enum {
|
||||
BLOCK_IF,
|
||||
BLOCK_WHILE,
|
||||
BLOCK_SWITCH,
|
||||
};
|
||||
|
||||
/* label stack */
|
||||
typedef struct {
|
||||
int8_t top; /* number of labels */
|
||||
int16_t pos[MAX_NUM_LABLES]; /* the position of the label */
|
||||
char label[MAX_NUM_LABLES][MAX_LABEL_LEN]; /* name of the label */
|
||||
} SLabel;
|
||||
|
||||
/* block definition */
|
||||
typedef struct {
|
||||
int8_t top; /* the number of blocks stacked */
|
||||
char type[MAX_NUM_BLOCK]; /* the block type */
|
||||
int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
|
||||
int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
|
||||
char numJump[MAX_NUM_BLOCK];
|
||||
int16_t *jump[MAX_NUM_BLOCK][MAX_NUM_JUMP]; /* break or elif */
|
||||
char sexp[MAX_NUM_BLOCK][40]; /*switch expression */
|
||||
char sexpLen[MAX_NUM_BLOCK]; /*switch expression length */
|
||||
} SBlock;
|
||||
|
||||
bool simParseExpression(char *token, int32_t lineNum);
|
||||
|
||||
#endif /*_TD_SIM_PARSE_H_*/
|
File diff suppressed because it is too large
Load Diff
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "simInt.h"
|
||||
|
||||
bool simExecSuccess = false;
|
||||
bool abortExecution = false;
|
||||
bool useMultiProcess = false;
|
||||
bool useValgrind = false;
|
||||
|
||||
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
|
||||
simSystemCleanUp();
|
||||
abortExecution = true;
|
||||
}
|
||||
|
||||
int32_t main(int32_t argc, char *argv[]) {
|
||||
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
|
||||
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
|
||||
tstrncpy(configDir, argv[++i], 128);
|
||||
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
|
||||
strcpy(scriptFile, argv[++i]);
|
||||
} else if (strcmp(argv[i], "-m") == 0) {
|
||||
useMultiProcess = true;
|
||||
} else if (strcmp(argv[i], "-v") == 0) {
|
||||
useValgrind = true;
|
||||
} else {
|
||||
printf("usage: %s [options] \n", argv[0]);
|
||||
printf(" [-c config]: config directory, default is: %s\n", configDir);
|
||||
printf(" [-f script]: script filename\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!simSystemInit()) {
|
||||
simError("failed to initialize the system");
|
||||
simSystemCleanUp();
|
||||
return -1;
|
||||
}
|
||||
|
||||
simInfo("simulator is running ...");
|
||||
taosSetSignal(SIGINT, simHandleSignal);
|
||||
|
||||
SScript *script = simParseScript(scriptFile);
|
||||
if (script == NULL) {
|
||||
simError("parse script file:%s failed", scriptFile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (abortExecution) {
|
||||
simError("execute abort");
|
||||
return -1;
|
||||
}
|
||||
|
||||
simScriptList[++simScriptPos] = script;
|
||||
simExecuteScript(script);
|
||||
|
||||
int32_t ret = simExecSuccess ? 0 : -1;
|
||||
simInfo("execute result %d", ret);
|
||||
|
||||
return ret;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "simInt.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
||||
SCommand simCmdList[SIM_CMD_END];
|
||||
int32_t simScriptPos = -1;
|
||||
int32_t simScriptSucced = 0;
|
||||
int32_t simDebugFlag = 143;
|
||||
void simCloseTaosdConnect(SScript *script);
|
||||
char simScriptDir[PATH_MAX] = {0};
|
||||
|
||||
extern bool simExecSuccess;
|
||||
|
||||
int32_t simInitCfg() {
|
||||
taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1);
|
||||
taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1);
|
||||
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32;
|
||||
tstrncpy(simScriptDir, cfgGetItem(pCfg, "scriptDir")->str, PATH_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool simSystemInit() {
|
||||
simInitCfg();
|
||||
simInitsimCmdList();
|
||||
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
|
||||
return true;
|
||||
}
|
||||
|
||||
void simSystemCleanUp() {}
|
||||
|
||||
void simFreeScript(SScript *script) {
|
||||
if (script->type == SIM_SCRIPT_TYPE_MAIN) {
|
||||
simInfo("script:%s, background script num:%d, stop them", script->fileName, script->bgScriptLen);
|
||||
|
||||
for (int32_t i = 0; i < script->bgScriptLen; ++i) {
|
||||
SScript *bgScript = script->bgScripts[i];
|
||||
simDebug("script:%s, is background script, set stop flag", bgScript->fileName);
|
||||
bgScript->killed = true;
|
||||
if (taosCheckPthreadValid(bgScript->bgPid)) {
|
||||
taosThreadJoin(bgScript->bgPid, NULL);
|
||||
taosThreadClear(&bgScript->bgPid);
|
||||
}
|
||||
|
||||
simDebug("script:%s, background thread joined", bgScript->fileName);
|
||||
taos_close(bgScript->taos);
|
||||
taosMemoryFreeClear(bgScript->lines);
|
||||
taosMemoryFreeClear(bgScript->optionBuffer);
|
||||
taosMemoryFreeClear(bgScript);
|
||||
}
|
||||
|
||||
simDebug("script:%s, is cleaned", script->fileName);
|
||||
taos_close(script->taos);
|
||||
taosMemoryFreeClear(script->lines);
|
||||
taosMemoryFreeClear(script->optionBuffer);
|
||||
taosMemoryFreeClear(script);
|
||||
}
|
||||
}
|
||||
|
||||
SScript *simProcessCallOver(SScript *script) {
|
||||
if (script->type == SIM_SCRIPT_TYPE_MAIN) {
|
||||
simDebug("script:%s, is main script, set stop flag", script->fileName);
|
||||
if (script->killed) {
|
||||
simExecSuccess = false;
|
||||
simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s",
|
||||
script->fileName, script->error);
|
||||
} else {
|
||||
simExecSuccess = true;
|
||||
simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX,
|
||||
script->fileName);
|
||||
}
|
||||
|
||||
simCloseTaosdConnect(script);
|
||||
simScriptSucced++;
|
||||
simScriptPos--;
|
||||
simFreeScript(script);
|
||||
|
||||
if (simScriptPos == -1 && simExecSuccess) {
|
||||
simInfo("----------------------------------------------------------------------");
|
||||
simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (simScriptPos == -1) return NULL;
|
||||
if (!simExecSuccess) return NULL;
|
||||
|
||||
return simScriptList[simScriptPos];
|
||||
} else {
|
||||
simDebug("script:%s, is stopped", script->fileName);
|
||||
simFreeScript(script);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void *simExecuteScript(void *inputScript) {
|
||||
SScript *script = (SScript *)inputScript;
|
||||
|
||||
while (1) {
|
||||
if (script->type == SIM_SCRIPT_TYPE_MAIN) {
|
||||
script = simScriptList[simScriptPos];
|
||||
}
|
||||
|
||||
if (abortExecution) {
|
||||
script->killed = true;
|
||||
}
|
||||
|
||||
if (script->killed || script->linePos >= script->numOfLines) {
|
||||
script = simProcessCallOver(script);
|
||||
if (script == NULL) {
|
||||
simDebug("sim test abort now!");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SCmdLine *line = &script->lines[script->linePos];
|
||||
char *option = script->optionBuffer + line->optionOffset;
|
||||
simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
|
||||
|
||||
SCommand *cmd = &simCmdList[line->cmdno];
|
||||
int32_t ret = (*(cmd->executeCmd))(script, option);
|
||||
if (!ret) {
|
||||
script->killed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
simInfo("thread is stopped");
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in New Issue