Skip to content

Commit

Permalink
Merge pull request #727 from taosdata/feat/TD-28024-MAIN
Browse files Browse the repository at this point in the history
feat: support timestamp_start fill with now-7d
  • Loading branch information
DuanKuanJun authored Dec 25, 2023
2 parents 067ef43 + 729f557 commit 0e0a63f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ typedef struct SSuperTable_S {
bool tcpTransfer;
bool non_stop;
bool autoFillback; // "start_fillback_time" item set "auto"
char *calcNow; // need calculate now timestamp expression
char *comment;
int delay;
int file_factor;
Expand Down
50 changes: 48 additions & 2 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ static int64_t fillChildTblName(SDataBase *database, SSuperTable *stbInfo) {
return ntables;
}

// last ts fill to filllBackTime
static bool fillSTableLastTs(SDataBase *database, SSuperTable *stbInfo) {
SBenchConn* conn = initBenchConn();
if (NULL == conn) {
Expand All @@ -2863,7 +2864,6 @@ static bool fillSTableLastTs(SDataBase *database, SSuperTable *stbInfo) {
return false;
}

bool ret = false;
char lastTs[128];
memset(lastTs, 0, sizeof(lastTs));

Expand All @@ -2874,9 +2874,46 @@ static bool fillSTableLastTs(SDataBase *database, SSuperTable *stbInfo) {
taos_free_result(res);
closeBenchConn(conn);

return ret;
return true;
}

// calcNow expression fill to timestamp_start
static bool calcExprFromServer(SDataBase *database, SSuperTable *stbInfo) {
SBenchConn* conn = initBenchConn();
if (NULL == conn) {
return false;
}
char cmd[SHORT_1K_SQL_BUFF_LEN] = "\0";
snprintf(cmd, SHORT_1K_SQL_BUFF_LEN, "select %s", stbInfo->calcNow);

infoPrint("calcExprFromServer: %s\n", cmd);
TAOS_RES *res = taos_query(conn->taos, cmd);
int32_t code = taos_errno(res);
if (code) {
printErrCmdCodeStr(cmd, code, res);
closeBenchConn(conn);
return false;
}

TAOS_ROW row = taos_fetch_row(res);
if(row == NULL) {
taos_free_result(res);
closeBenchConn(conn);
return false;
}

char ts[128];
memset(ts, 0, sizeof(ts));

stbInfo->startTimestamp = *(int64_t*)row[0];
toolsFormatTimestamp(ts, stbInfo->startTimestamp, database->precision);
infoPrint("calcExprFromServer: get ok. %s = %s \n", stbInfo->calcNow, ts);

taos_free_result(res);
closeBenchConn(conn);

return true;
}

static int startMultiThreadInsertData(SDataBase* database,
SSuperTable* stbInfo) {
Expand Down Expand Up @@ -3559,6 +3596,7 @@ int insertTestProcess() {
prompt(0);

encodeAuthBase64();
//loop create database
for (int i = 0; i < g_arguments->databases->size; i++) {
if (REST_IFACE == g_arguments->iface) {
if (0 != convertServAddr(g_arguments->iface,
Expand Down Expand Up @@ -3588,6 +3626,8 @@ int insertTestProcess() {
succPrint("created database (%s)\n", database->dbName);
}
}

// fill table and prepareSampleData
for (int i = 0; i < g_arguments->databases->size; i++) {
SDataBase * database = benchArrayGet(g_arguments->databases, i);
if (database->superTbls) {
Expand All @@ -3612,6 +3652,11 @@ int insertTestProcess() {
fillSTableLastTs(database, stbInfo);
}

// calc now
if(stbInfo->calcNow) {
calcExprFromServer(database, stbInfo);
}

// check fill child table count valid
if(fillChildTblName(database, stbInfo) <= 0) {
infoPrint(" warning fill childs table count is zero, please check parameters in json is correct. database:%s stb: %s \n", database->dbName, stbInfo->stbName);
Expand All @@ -3623,6 +3668,7 @@ int insertTestProcess() {
}
}

// create threads
if (g_arguments->taosc_version == 3) {
for (int i = 0; i < g_arguments->databases->size; i++) {
SDataBase* database = benchArrayGet(g_arguments->databases, i);
Expand Down
3 changes: 3 additions & 0 deletions src/benchJsonOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,9 @@ static int getStableInfo(tools_cJSON *dbinfos, int index) {
superTable->useNow = true;
// fill time with now conflict with check_sql
g_arguments->check_sql = false;
} else if (0 == strncasecmp(ts->valuestring, "now", 3)) {
// like now - 7d expression
superTable->calcNow = ts->valuestring;
} else {
if (toolsParseTime(ts->valuestring,
&(superTable->startTimestamp),
Expand Down

0 comments on commit 0e0a63f

Please sign in to comment.