Skip to content

Commit

Permalink
fix: taosdump code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sangshuduo committed Mar 4, 2023
1 parent 7876113 commit d69348c
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 368 deletions.
11 changes: 4 additions & 7 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
#define RESP_BUF_LEN 4096
#define SHORT_1K_SQL_BUFF_LEN 1024
#define URL_BUFF_LEN 1024
#define TTL_BUFF_LEN 20

#define STR_INSERT_INTO "INSERT INTO "

Expand Down Expand Up @@ -129,10 +128,9 @@

#define MAX_JSON_BUFF 6400000

#define INPUT_BUF_LEN 256
#define EXTRA_SQL_LEN 256
#define SMALL_BUFF_LEN 8
#define DATATYPE_BUFF_LEN (SMALL_BUFF_LEN * 3)
#define INPUT_BUF_LEN 256
#define EXTRA_SQL_LEN 256
#define DATATYPE_BUFF_LEN (TINY_BUFF_LEN * 3)
#define SML_MAX_BATCH 65536 * 32
#define DEFAULT_NTHREADS 8

Expand All @@ -155,7 +153,6 @@
#define BARRAY_MIN_SIZE 8
#define SML_LINE_SQL_SYNTAX_OFFSET 7

#define TEMP_BUFF_LEN 64
// tdengine define macro
#define TSDB_DEFAULT_DURATION_PER_FILE (10 * 1440)

Expand Down Expand Up @@ -690,7 +687,7 @@ typedef struct SSTREAM_S {
char stream_stb[TSDB_TABLE_NAME_LEN];
char trigger_mode[BIGINT_BUFF_LEN];
char watermark[BIGINT_BUFF_LEN];
char source_sql[TSDB_MAX_SQL_LEN];
char source_sql[TSDB_DEFAULT_PKT_SIZE];
bool drop;
} SSTREAM;

Expand Down
51 changes: 26 additions & 25 deletions inc/toolsdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
#include <stdbool.h>
#include <time.h>

#define TINY_BUFF_LEN 8
#define SMALL_BUFF_LEN 20
#define MIDDLE_BUFF_LEN 64
#define LARGE_BUFF_LEN 512
// max file name length on Linux is 255
#define MAX_FILE_NAME_LEN 256 // max file name length on linux is 255.
#define MAX_FILE_NAME_LEN 256 // max file name length on linux is 255.

// max path length on Linux is 4095
#define MAX_PATH_LEN 4096
#define MAX_PATH_LEN 4096

// max hostname length on Linux is 253
#define MAX_HOSTNAME_LEN 254
#define MAX_HOSTNAME_LEN 254

#define TSDB_CODE_SUCCESS 0
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
#define TSDB_CODE_SUCCESS 0
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error

// NULL definition
#define TSDB_DATA_BOOL_NULL 0x02
Expand Down Expand Up @@ -69,40 +73,37 @@
#define TSDB_PASS_LEN 129
#define SHELL_MAX_PASSWORD_LEN TSDB_PASS_LEN

#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1
#define TSDB_TIME_PRECISION_NANO 2
#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1
#define TSDB_TIME_PRECISION_NANO 2

#define TSDB_MAX_COLUMNS 4096
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
#define TSDB_MAX_COLUMNS 4096
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns

#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string

#define TSDB_DB_NAME_LEN 65
#define TSDB_DB_NAME_LEN 65

#define TSDB_COL_NAME_LEN 65
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb
#define TSDB_COL_NAME_LEN 65
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb

#define TSDB_MAX_BYTES_PER_ROW 65531
#define TSDB_MAX_TAGS 128
#define TSDB_MAX_BYTES_PER_ROW 65531
#define TSDB_MAX_TAGS 128

#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE

#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE

#ifdef TSKEY32
#define TSKEY int32_t;
#else
#define TSKEY int64_t
#endif

#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_MAX_FIELD_LEN 65519
#define TSDB_MAX_BINARY_LEN TSDB_MAX_FIELD_LEN
#define TSDB_FILENAME_LEN 128
#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_MAX_FIELD_LEN 65519
#define TSDB_MAX_BINARY_LEN TSDB_MAX_FIELD_LEN
#define TSDB_FILENAME_LEN 128

#define TSDB_PORT_HTTP 11
#define TSDB_PORT_HTTP 11

#if _MSC_VER <= 1900
#define __func__ __FUNCTION__
Expand Down
13 changes: 8 additions & 5 deletions src/benchCommandOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

#include <bench.h>
#include <toolsdef.h>

#ifdef LINUX
#include <argp.h>
Expand Down Expand Up @@ -912,21 +913,23 @@ static void *queryStableAggrFunc(void *sarg) {
}
for (int j = 0; j < n; j++) {
char condition[COND_BUF_LEN] = "\0";
char tempS[TEMP_BUFF_LEN] = "\0";
char tempS[LARGE_BUFF_LEN] = "\0";
int64_t m = 10 < stbInfo->childTblCount ? 10 : stbInfo->childTblCount;
for (int64_t i = 1; i <= m; i++) {
if (i == 1) {
if (g_arguments->demo_mode) {
snprintf(tempS, TEMP_BUFF_LEN, "groupid = %" PRId64 "", i);
snprintf(tempS, LARGE_BUFF_LEN,
"groupid = %" PRId64 "", i);
} else {
snprintf(tempS, TEMP_BUFF_LEN, "t0 = %" PRId64 "", i);
snprintf(tempS, LARGE_BUFF_LEN,
"t0 = %" PRId64 "", i);
}
} else {
if (g_arguments->demo_mode) {
snprintf(tempS, TEMP_BUFF_LEN,
snprintf(tempS, LARGE_BUFF_LEN,
" or groupid = %" PRId64 " ", i);
} else {
snprintf(tempS, TEMP_BUFF_LEN,
snprintf(tempS, LARGE_BUFF_LEN,
" or t0 = %" PRId64 " ", i);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/benchData.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ int prepareStmt(SSuperTable *stbInfo, TAOS_STMT *stmt, uint64_t tableSeq) {
char *prepare = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true);
int n;
if (stbInfo->autoCreateTable) {
char ttl[TTL_BUFF_LEN] = "";
char ttl[SMALL_BUFF_LEN] = "";
if (stbInfo->ttl != 0) {
snprintf(ttl, TTL_BUFF_LEN, "TTL %d", stbInfo->ttl);
snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
}
n = snprintf(prepare + len,
TSDB_MAX_ALLOWED_SQL_LEN - len,
Expand Down Expand Up @@ -256,14 +256,14 @@ static int getAndSetRowsFromCsvFile(char *sampleFile, uint64_t *insertRows) {
int line_count = 0;
char * buf = NULL;

buf = benchCalloc(1, TSDB_MAX_SQL_LEN, false);
buf = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, false);
if (NULL == buf) {
errorPrint("%s() failed to allocate memory!\n", __func__);
fclose(fp);
return -1;
}

while (fgets(buf, TSDB_MAX_SQL_LEN, fp)) {
while (fgets(buf, TSDB_MAX_ALLOWED_SQL_LEN, fp)) {
line_count++;
}
*insertRows = line_count;
Expand Down
12 changes: 6 additions & 6 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,9 @@ static void *createTable(void *sarg) {
pThreadInfo->threadID, pThreadInfo->start_table_from,
pThreadInfo->end_table_to);

char ttl[TTL_BUFF_LEN] = "";
char ttl[SMALL_BUFF_LEN] = "";
if (stbInfo->ttl != 0) {
snprintf(ttl, TTL_BUFF_LEN, "TTL %d", stbInfo->ttl);
snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
}

for (uint64_t i = pThreadInfo->start_table_from;
Expand Down Expand Up @@ -1349,9 +1349,9 @@ static void *syncWriteInterlace(void *sarg) {
char *sampleDataBuf = childTbl->useOwnSample?
childTbl->sampleDataBuf:
stbInfo->sampleDataBuf;
char ttl[TTL_BUFF_LEN] = "";
char ttl[SMALL_BUFF_LEN] = "";
if (stbInfo->ttl != 0) {
snprintf(ttl, TTL_BUFF_LEN, "TTL %d", stbInfo->ttl);
snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
}
switch (stbInfo->iface) {
case REST_IFACE:
Expand Down Expand Up @@ -2113,9 +2113,9 @@ void *syncWriteProgressive(void *sarg) {
}
}

char ttl[TTL_BUFF_LEN] = "";
char ttl[SMALL_BUFF_LEN] = "";
if (stbInfo->ttl != 0) {
snprintf(ttl, TTL_BUFF_LEN, "TTL %d", stbInfo->ttl);
snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl);
}
for (uint64_t i = 0; i < stbInfo->insertRows;) {
if (g_arguments->terminate) {
Expand Down
2 changes: 1 addition & 1 deletion src/benchJsonOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ static int getStreamInfo(tools_cJSON* json) {
tstrncpy(stream->stream_stb, stream_stb->valuestring,
TSDB_TABLE_NAME_LEN);
tstrncpy(stream->source_sql, source_sql->valuestring,
TSDB_MAX_SQL_LEN);
TSDB_DEFAULT_PKT_SIZE);

tools_cJSON* trigger_mode =
tools_cJSON_GetObjectItem(streamObj, "trigger_mode");
Expand Down
Loading

0 comments on commit d69348c

Please sign in to comment.