Merge branch '3.0' of https://github.com/taosdata/TDengine into feature/3.0_mhli

This commit is contained in:
Minghao Li 2022-03-10 16:18:32 +08:00
commit 901b5976cc
65 changed files with 1052 additions and 758 deletions

3
.gitmodules vendored
View File

@ -13,3 +13,6 @@
[submodule "examples/rust"] [submodule "examples/rust"]
path = examples/rust path = examples/rust
url = https://github.com/songtianyi/tdengine-rust-bindings.git url = https://github.com/songtianyi/tdengine-rust-bindings.git
[submodule "tools/taos-tools"]
path = tools/taos-tools
url = https://github.com/taosdata/taos-tools

View File

@ -6,6 +6,32 @@ project(
DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)" DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)"
) )
IF ("${BUILD_TOOLS}" STREQUAL "")
IF (TD_LINUX)
IF (TD_ARM_32)
SET(BUILD_TOOLS "false")
ELSEIF (TD_ARM_64)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ELSEIF (TD_DARWIN)
SET(BUILD_TOOLS "false")
ELSE ()
SET(BUILD_TOOLS "false")
ENDIF ()
ENDIF ()
IF ("${BUILD_TOOLS}" MATCHES "false")
MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
SET(TD_TAOS_TOOLS FALSE)
ELSE ()
MESSAGE("")
MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
MESSAGE("")
SET(TD_TAOS_TOOLS TRUE)
ENDIF ()
set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib") set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib")
include(${CMAKE_SUPPORT_DIR}/cmake.options) include(${CMAKE_SUPPORT_DIR}/cmake.options)

View File

@ -377,7 +377,7 @@ void printConf(SRaftServerConfig *pConf) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
int32_t ret; int32_t ret;
exe_name = argv[0]; exe_name = argv[0];

View File

@ -132,7 +132,7 @@ static void proposeValue(struct raft *r) {
buf.base = raft_malloc(buf.len); buf.base = raft_malloc(buf.len);
// mock ts value // mock ts value
int vid = rand() % VNODE_COUNT; int vid = taosRand() % VNODE_COUNT;
snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL)); snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL));
printf("propose value: %s \n", (char*)buf.base); printf("propose value: %s \n", (char*)buf.base);
@ -174,7 +174,7 @@ void usage() {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
exe_name = argv[0]; exe_name = argv[0];
if (argc < 2) { if (argc < 2) {

View File

@ -19,7 +19,7 @@ void shuffle(char**lines, size_t n)
size_t i; size_t i;
for (i = 0; i < n - 1; i++) for (i = 0; i < n - 1; i++)
{ {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1); size_t j = i + taosRand() / (RAND_MAX / (n - i) + 1);
char* t = lines[j]; char* t = lines[j];
lines[j] = lines[i]; lines[j] = lines[i];
lines[i] = t; lines[i] = t;

View File

@ -256,6 +256,10 @@ DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_co
void tmqShowMsg(tmq_message_t *tmq_message); void tmqShowMsg(tmq_message_t *tmq_message);
int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code);
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT* stmt);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -63,6 +63,8 @@ typedef enum {
extern char *qtypeStr[]; extern char *qtypeStr[];
#define TSDB_PORT_HTTP 11
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1856,19 +1856,27 @@ typedef enum {
TD_TIME_UNIT_MICROSEC = 9, TD_TIME_UNIT_MICROSEC = 9,
TD_TIME_UNIT_NANOSEC = 10 TD_TIME_UNIT_NANOSEC = 10
} ETDTimeUnit; } ETDTimeUnit;
typedef struct { typedef struct {
uint8_t version; // for compatibility uint16_t funcId;
uint8_t intervalUnit; uint16_t nColIds;
uint8_t slidingUnit; col_id_t* colIds; // sorted colIds
char indexName[TSDB_INDEX_NAME_LEN + 1]; } SFuncColIds;
col_id_t numOfColIds;
uint16_t numOfFuncIds; typedef struct {
uint64_t tableUid; // super/common table uid uint8_t version; // for compatibility
int64_t interval; uint8_t intervalUnit;
int64_t sliding; uint8_t slidingUnit;
col_id_t* colIds; // sorted column ids char indexName[TSDB_INDEX_NAME_LEN];
uint16_t* funcIds; // sorted sma function ids char timezone[TD_TIMEZONE_LEN];
} STSma; // Time-range-wise SMA uint16_t nFuncColIds;
uint16_t tagsFilterLen;
tb_uid_t tableUid; // super/common table uid
int64_t interval;
int64_t sliding;
SFuncColIds* funcColIds; // sorted funcIds
char* tagsFilter;
} STSma; // Time-range-wise SMA
typedef struct { typedef struct {
int64_t ver; // use a general definition int64_t ver; // use a general definition
@ -1877,13 +1885,13 @@ typedef struct {
typedef struct { typedef struct {
int8_t type; // 0 status report, 1 update data int8_t type; // 0 status report, 1 update data
char indexName[TSDB_INDEX_NAME_LEN + 1]; // char indexName[TSDB_INDEX_NAME_LEN]; //
STimeWindow windows; STimeWindow windows;
} STSmaMsg; } STSmaMsg;
typedef struct { typedef struct {
int64_t ver; // use a general definition int64_t ver; // use a general definition
char indexName[TSDB_INDEX_NAME_LEN + 1]; char indexName[TSDB_INDEX_NAME_LEN];
} SVDropTSmaReq; } SVDropTSmaReq;
typedef struct { typedef struct {
} SVCreateTSmaRsp, SVDropTSmaRsp; } SVCreateTSmaRsp, SVDropTSmaRsp;
@ -1934,8 +1942,14 @@ typedef struct {
static FORCE_INLINE void tdDestroyTSma(STSma* pSma) { static FORCE_INLINE void tdDestroyTSma(STSma* pSma) {
if (pSma) { if (pSma) {
tfree(pSma->colIds); if (pSma->funcColIds != NULL) {
tfree(pSma->funcIds); for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
tfree((pSma->funcColIds + i)->colIds);
}
tfree(pSma->funcColIds);
}
tfree(pSma->tagsFilter);
} }
} }
@ -1957,18 +1971,24 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
tlen += taosEncodeFixedU8(buf, pSma->intervalUnit); tlen += taosEncodeFixedU8(buf, pSma->intervalUnit);
tlen += taosEncodeFixedU8(buf, pSma->slidingUnit); tlen += taosEncodeFixedU8(buf, pSma->slidingUnit);
tlen += taosEncodeString(buf, pSma->indexName); tlen += taosEncodeString(buf, pSma->indexName);
tlen += taosEncodeFixedU16(buf, pSma->numOfColIds); tlen += taosEncodeString(buf, pSma->timezone);
tlen += taosEncodeFixedU16(buf, pSma->numOfFuncIds); tlen += taosEncodeFixedU16(buf, pSma->nFuncColIds);
tlen += taosEncodeFixedU64(buf, pSma->tableUid); tlen += taosEncodeFixedU16(buf, pSma->tagsFilterLen);
tlen += taosEncodeFixedI64(buf, pSma->tableUid);
tlen += taosEncodeFixedI64(buf, pSma->interval); tlen += taosEncodeFixedI64(buf, pSma->interval);
tlen += taosEncodeFixedI64(buf, pSma->sliding); tlen += taosEncodeFixedI64(buf, pSma->sliding);
for (col_id_t i = 0; i < pSma->numOfColIds; ++i) { for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
tlen += taosEncodeFixedU16(buf, *(pSma->colIds + i)); SFuncColIds* funcColIds = pSma->funcColIds + i;
tlen += taosEncodeFixedU16(buf, funcColIds->funcId);
tlen += taosEncodeFixedU16(buf, funcColIds->nColIds);
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
tlen += taosEncodeFixedU16(buf, *(funcColIds->colIds + j));
}
} }
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) { if (pSma->tagsFilterLen > 0) {
tlen += taosEncodeFixedU16(buf, *(pSma->funcIds + i)); tlen += taosEncodeString(buf, pSma->tagsFilter);
} }
return tlen; return tlen;
@ -1989,34 +2009,52 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
buf = taosDecodeFixedU8(buf, &pSma->intervalUnit); buf = taosDecodeFixedU8(buf, &pSma->intervalUnit);
buf = taosDecodeFixedU8(buf, &pSma->slidingUnit); buf = taosDecodeFixedU8(buf, &pSma->slidingUnit);
buf = taosDecodeStringTo(buf, pSma->indexName); buf = taosDecodeStringTo(buf, pSma->indexName);
buf = taosDecodeFixedU16(buf, &pSma->numOfColIds); buf = taosDecodeStringTo(buf, pSma->timezone);
buf = taosDecodeFixedU16(buf, &pSma->numOfFuncIds); buf = taosDecodeFixedU16(buf, &pSma->nFuncColIds);
buf = taosDecodeFixedU64(buf, &pSma->tableUid); buf = taosDecodeFixedU16(buf, &pSma->tagsFilterLen);
buf = taosDecodeFixedI64(buf, &pSma->tableUid);
buf = taosDecodeFixedI64(buf, &pSma->interval); buf = taosDecodeFixedI64(buf, &pSma->interval);
buf = taosDecodeFixedI64(buf, &pSma->sliding); buf = taosDecodeFixedI64(buf, &pSma->sliding);
if (pSma->numOfColIds > 0) { if (pSma->nFuncColIds > 0) {
pSma->colIds = (col_id_t*)calloc(pSma->numOfColIds, sizeof(STSma)); pSma->funcColIds = (SFuncColIds*)calloc(pSma->nFuncColIds, sizeof(SFuncColIds));
if (pSma->colIds == NULL) { if (pSma->funcColIds == NULL) {
tdDestroyTSma(pSma);
return NULL; return NULL;
} }
for (uint16_t i = 0; i < pSma->numOfColIds; ++i) { for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
buf = taosDecodeFixedU16(buf, pSma->colIds + i); SFuncColIds* funcColIds = pSma->funcColIds + i;
buf = taosDecodeFixedU16(buf, &funcColIds->funcId);
buf = taosDecodeFixedU16(buf, &funcColIds->nColIds);
if (funcColIds->nColIds > 0) {
funcColIds->colIds = (col_id_t*)calloc(funcColIds->nColIds, sizeof(col_id_t));
if (funcColIds->colIds != NULL) {
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
buf = taosDecodeFixedU16(buf, funcColIds->colIds + j);
}
} else {
tdDestroyTSma(pSma);
return NULL;
}
} else {
funcColIds->colIds = NULL;
}
} }
} else { } else {
pSma->colIds = NULL; pSma->funcColIds = NULL;
} }
if (pSma->numOfFuncIds > 0) { if (pSma->tagsFilterLen > 0) {
pSma->funcIds = (uint16_t*)calloc(pSma->numOfFuncIds, sizeof(STSma)); pSma->tagsFilter = (char*)calloc(pSma->tagsFilterLen, 1);
if (pSma->funcIds == NULL) { if (pSma->tagsFilter != NULL) {
buf = taosDecodeStringTo(buf, pSma->tagsFilter);
} else {
tdDestroyTSma(pSma);
return NULL; return NULL;
} }
for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) {
buf = taosDecodeFixedU16(buf, pSma->funcIds + i);
}
} else { } else {
pSma->funcIds = NULL; pSma->tagsFilter = NULL;
} }
return buf; return buf;

View File

@ -20,7 +20,16 @@
extern "C" { extern "C" {
#endif #endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define rand RAND_FUNC_TAOS_FORBID
#define srand SRAND_FUNC_TAOS_FORBID
#define rand_r RANDR_FUNC_TAOS_FORBID
#endif
void taosSeedRand(uint32_t seed);
uint32_t taosRand(void); uint32_t taosRand(void);
uint32_t taosRandR(uint32_t *pSeed);
void taosRandStr(char* str, int32_t size); void taosRandStr(char* str, int32_t size);
uint32_t taosSafeRand(void); uint32_t taosSafeRand(void);

View File

@ -20,7 +20,17 @@
extern "C" { extern "C" {
#endif #endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define Sleep SLEEP_FUNC_TAOS_FORBID
#define sleep SLEEP_FUNC_TAOS_FORBID
#define usleep USLEEP_FUNC_TAOS_FORBID
#define nanosleep NANOSLEEP_FUNC_TAOS_FORBID
#endif
void taosSsleep(int32_t s);
void taosMsleep(int32_t ms); void taosMsleep(int32_t ms);
void taosUsleep(int32_t us);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -207,7 +207,7 @@ typedef enum ELogicConditionType {
#define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_FUNC_TYPE_AGGREGATE 2
#define TSDB_FUNC_MAX_RETRIEVE 1024 #define TSDB_FUNC_MAX_RETRIEVE 1024
#define TSDB_INDEX_NAME_LEN 32 #define TSDB_INDEX_NAME_LEN 33 // 32 + 1 '\0'
#define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TYPE_STR_MAX_LEN 32
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN #define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN

View File

@ -208,7 +208,7 @@ void taos_init_imp(void) {
atexit(taos_cleanup); atexit(taos_cleanup);
errno = TSDB_CODE_SUCCESS; errno = TSDB_CODE_SUCCESS;
srand(taosGetTimestampSec()); taosSeedRand(taosGetTimestampSec());
deltaToUtcInitOnce(); deltaToUtcInitOnce();

View File

@ -449,7 +449,7 @@ static void hbStopThread() {
} }
while (2 != atomic_load_8(&clientHbMgr.threadStop)) { while (2 != atomic_load_8(&clientHbMgr.threadStop)) {
usleep(10); taosUsleep(10);
} }
tscDebug("hb thread stopped"); tscDebug("hb thread stopped");

View File

@ -343,3 +343,77 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param
void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
// TODO // TODO
} }
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) {
// TODO
return NULL;
}
TAOS_RES *taos_consume(TAOS_SUB *tsub) {
// TODO
return NULL;
}
void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
// TODO
}
TAOS_STMT* taos_stmt_init(TAOS* taos) {
// TODO
return NULL;
}
int taos_stmt_close(TAOS_STMT* stmt) {
// TODO
return -1;
}
int taos_stmt_execute(TAOS_STMT* stmt) {
// TODO
return -1;
}
char *taos_stmt_errstr(TAOS_STMT *stmt) {
// TODO
return NULL;
}
int taos_stmt_affected_rows(TAOS_STMT* stmt) {
// TODO
return -1;
}
TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) {
// TODO
return NULL;
}
int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
// TODO
return -1;
}
int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
// TODO
return -1;
}
int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) {
// TODO
return -1;
}
int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
// TODO
return -1;
}
int taos_stmt_add_batch(TAOS_STMT* stmt) {
// TODO
return -1;
}
int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
// TODO
return -1;
}

View File

@ -1146,13 +1146,13 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
if (taosArrayGetSize(tmq->clientTopics) == 0) { if (taosArrayGetSize(tmq->clientTopics) == 0) {
tscDebug("consumer:%ld poll but not assigned", tmq->consumerId); tscDebug("consumer:%ld poll but not assigned", tmq->consumerId);
/*printf("over1\n");*/ /*printf("over1\n");*/
usleep(blocking_time * 1000); taosMsleep(blocking_time);
return NULL; return NULL;
} }
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, tmq->nextTopicIdx); SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, tmq->nextTopicIdx);
if (taosArrayGetSize(pTopic->vgs) == 0) { if (taosArrayGetSize(pTopic->vgs) == 0) {
/*printf("over2\n");*/ /*printf("over2\n");*/
usleep(blocking_time * 1000); taosMsleep(blocking_time);
return NULL; return NULL;
} }
@ -1165,14 +1165,14 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blocking_time, pTopic, pVg); SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blocking_time, pTopic, pVg);
if (pReq == NULL) { if (pReq == NULL) {
ASSERT(false); ASSERT(false);
usleep(blocking_time * 1000); taosMsleep(blocking_time);
return NULL; return NULL;
} }
SMqPollCbParam* param = malloc(sizeof(SMqPollCbParam)); SMqPollCbParam* param = malloc(sizeof(SMqPollCbParam));
if (param == NULL) { if (param == NULL) {
ASSERT(false); ASSERT(false);
usleep(blocking_time * 1000); taosMsleep(blocking_time);
return NULL; return NULL;
} }
param->tmq = tmq; param->tmq = tmq;
@ -1204,7 +1204,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
if (tmq_message == NULL) { if (tmq_message == NULL) {
if (beginVgIdx == pTopic->nextVgIdx) { if (beginVgIdx == pTopic->nextVgIdx) {
usleep(blocking_time * 1000); taosMsleep(blocking_time);
} else { } else {
continue; continue;
} }

View File

@ -43,12 +43,30 @@ typedef struct {
STsdbFSMeta meta; // FS meta STsdbFSMeta meta; // FS meta
SArray * df; // data file array SArray * df; // data file array
// SArray * v2f100.tsma.index_name // SArray * v2t100.index_name
SArray * smaf; // sma data file array v2f1900.tsma.index_name SArray * smaf; // sma data file array v2t1900.index_name
} SFSStatus; } SFSStatus;
typedef struct { /**
* @brief Directory structure of .tsma data files.
*
* root@cary /vnode2/tsdb $ tree .tsma/
* .tsma/
* v2t100.index_name_1
* v2t101.index_name_1
* v2t102.index_name_1
* v2t1900.index_name_3
* v2t1901.index_name_3
* v2t1902.index_name_3
* v2t200.index_name_2
* v2t201.index_name_2
* v2t202.index_name_2
*
* 0 directories, 9 files
*/
typedef struct {
pthread_rwlock_t lock; pthread_rwlock_t lock;
SFSStatus *cstatus; // current status SFSStatus *cstatus; // current status

View File

@ -56,10 +56,11 @@ typedef enum {
TSDB_FILE_SMAL, // .smal(Block-wise SMA) TSDB_FILE_SMAL, // .smal(Block-wise SMA)
TSDB_FILE_MAX, // TSDB_FILE_MAX, //
TSDB_FILE_META, // meta TSDB_FILE_META, // meta
TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA TSDB_FILE_TSMA, // v2t100.${sma_index_name}, Time-range-wise SMA
TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA TSDB_FILE_RSMA, // v2r100.${sma_index_name}, Time-range-wise Rollup SMA
} TSDB_FILE_T; } E_TSDB_FILE_T;
typedef int32_t TSDB_FILE_T;
typedef enum { typedef enum {
TSDB_FS_VER_0 = 0, TSDB_FS_VER_0 = 0,
TSDB_FS_VER_MAX, TSDB_FS_VER_MAX,

View File

@ -31,7 +31,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg); int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg);
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat); int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
// internal func // internal func

View File

@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"smal", // TSDB_FILE_SMAL "smal", // TSDB_FILE_SMAL
"", // TSDB_FILE_MAX "", // TSDB_FILE_MAX
"meta", // TSDB_FILE_META "meta", // TSDB_FILE_META
"tsma", // TSDB_FILE_TSMA "sma", // TSDB_FILE_TSMA(directory name)
"rsma", // TSDB_FILE_RSMA "sma", // TSDB_FILE_RSMA(directory name)
}; };
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname); static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);

View File

@ -89,7 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg,
static void tsdbFree(STsdb *pTsdb) { static void tsdbFree(STsdb *pTsdb) {
if (pTsdb) { if (pTsdb) {
tsdbFreeFS(pTsdb->fs); tsdbFreeFS(pTsdb->fs);
tsdbFreeSmaState(pTsdb->pSmaStat); tsdbDestroySmaState(pTsdb->pSmaStat);
tfree(pTsdb->path); tfree(pTsdb->path);
free(pTsdb); free(pTsdb);
} }

View File

@ -128,7 +128,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
return pItem; return pItem;
} }
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat) { int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
if (pSmaStat) { if (pSmaStat) {
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL); SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
@ -203,6 +203,23 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, const char *indexName, void *timeWindow) {
SSmaStatItem *pItem = NULL;
if (pTsdb->pSmaStat && pTsdb->pSmaStat->smaStatItems) {
pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName));
}
if (pItem != NULL) {
// TODO: reset time windows for the sma data blocks
while (true) {
TSKEY thisWindow = 0;
taosHashRemove(pItem->expiredWindows, &thisWindow, sizeof(thisWindow));
}
}
return TSDB_CODE_SUCCESS;
}
/** /**
* @brief Judge the tSma storage level * @brief Judge the tSma storage level
* *
@ -387,7 +404,7 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, i
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
} }
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel, static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel,
@ -495,6 +512,9 @@ int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData) {
return terrno; return terrno;
} }
// reset the SSmaStat
tsdbResetExpiredWindow(pTsdb, param->indexName, &pData->tsWindow);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -542,6 +562,10 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
TASSERT(0); TASSERT(0);
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
// reset the SSmaStat
tsdbResetExpiredWindow(pTsdb, param->tsma.indexName, &pData->tsWindow);
// Step 4: finish // Step 4: finish
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -558,7 +582,7 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
pSmaH->pTsdb = pTsdb; pSmaH->pTsdb = pTsdb;
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
} }
/** /**

View File

@ -168,10 +168,10 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
} }
TEST_F(TqMetaUpdateAppendTest, multiplePage) { TEST_F(TqMetaUpdateAppendTest, multiplePage) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
@ -202,10 +202,10 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) {
} }
TEST_F(TqMetaUpdateAppendTest, multipleRewrite) { TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
@ -213,14 +213,14 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
tqHandleCommit(pMeta, i); tqHandleCommit(pMeta, i);
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
} }
for (int i = 500; i < 1000; i++) { for (int i = 500; i < 1000; i++) {
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
@ -235,7 +235,7 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
ASSERT(pMeta); ASSERT(pMeta);
for (int i = 500; i < 1000; i++) { for (int i = 500; i < 1000; i++) {
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
@ -250,10 +250,10 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
} }
TEST_F(TqMetaUpdateAppendTest, dupCommit) { TEST_F(TqMetaUpdateAppendTest, dupCommit) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));

View File

@ -20,6 +20,7 @@
#include <metaDef.h> #include <metaDef.h>
#include <tmsg.h> #include <tmsg.h>
#include <tsdbDef.h>
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
@ -41,17 +42,20 @@ TEST(testCase, tSmaEncodeDecodeTest) {
tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.slidingUnit = TD_TIME_UNIT_HOUR;
tSma.sliding = 0; tSma.sliding = 0;
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN);
tSma.tableUid = 1234567890; tSma.tableUid = 1234567890;
tSma.numOfColIds = 2; tSma.nFuncColIds = 5;
tSma.numOfFuncIds = 5; // sum/min/max/avg/last tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); ASSERT(tSma.funcColIds != NULL);
tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
SFuncColIds *funcColIds = tSma.funcColIds + n;
for (int32_t i = 0; i < tSma.numOfColIds; ++i) { funcColIds->funcId = n;
*(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); funcColIds->nColIds = 10;
} funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { ASSERT(funcColIds->colIds != NULL);
*(tSma.funcIds + i) = (i + 2); for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
}
} }
STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma}; STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma};
@ -80,16 +84,21 @@ TEST(testCase, tSmaEncodeDecodeTest) {
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit); EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit); EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName); EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
EXPECT_EQ(pSma->numOfColIds, qSma->numOfColIds); EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone);
EXPECT_EQ(pSma->numOfFuncIds, qSma->numOfFuncIds); EXPECT_EQ(pSma->nFuncColIds, qSma->nFuncColIds);
EXPECT_EQ(pSma->tableUid, qSma->tableUid); EXPECT_EQ(pSma->tableUid, qSma->tableUid);
EXPECT_EQ(pSma->interval, qSma->interval); EXPECT_EQ(pSma->interval, qSma->interval);
EXPECT_EQ(pSma->sliding, qSma->sliding); EXPECT_EQ(pSma->sliding, qSma->sliding);
for (uint32_t j = 0; j < pSma->numOfColIds; ++j) { EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
EXPECT_EQ(*(col_id_t *)(pSma->colIds + j), *(col_id_t *)(qSma->colIds + j)); EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
} for (uint32_t j = 0; j < pSma->nFuncColIds; ++j) {
for (uint32_t j = 0; j < pSma->numOfFuncIds; ++j) { SFuncColIds *pFuncColIds = pSma->funcColIds + j;
EXPECT_EQ(*(uint16_t *)(pSma->funcIds + j), *(uint16_t *)(qSma->funcIds + j)); SFuncColIds *qFuncColIds = qSma->funcColIds + j;
EXPECT_EQ(pFuncColIds->funcId, qFuncColIds->funcId);
EXPECT_EQ(pFuncColIds->nColIds, qFuncColIds->nColIds);
for (uint32_t k = 0; k < pFuncColIds->nColIds; ++k) {
EXPECT_EQ(*(pFuncColIds->colIds + k), *(qFuncColIds->colIds + k));
}
} }
} }
@ -99,9 +108,11 @@ TEST(testCase, tSmaEncodeDecodeTest) {
} }
TEST(testCase, tSma_DB_Put_Get_Del_Test) { TEST(testCase, tSma_DB_Put_Get_Del_Test) {
const char *smaIndexName1 = "sma_index_test_1"; const char * smaIndexName1 = "sma_index_test_1";
const char *smaIndexName2 = "sma_index_test_2"; const char * smaIndexName2 = "sma_index_test_2";
const char *smaTestDir = "./smaTest"; const char * timeZone = "Asia/Shanghai";
const char * tagsFilter = "I'm tags filter";
const char * smaTestDir = "./smaTest";
const uint64_t tbUid = 1234567890; const uint64_t tbUid = 1234567890;
const uint32_t nCntTSma = 2; const uint32_t nCntTSma = 2;
// encode // encode
@ -112,21 +123,27 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.slidingUnit = TD_TIME_UNIT_HOUR;
tSma.sliding = 0; tSma.sliding = 0;
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
tstrncpy(tSma.timezone, timeZone, TD_TIMEZONE_LEN);
tSma.tableUid = tbUid; tSma.tableUid = tbUid;
tSma.numOfColIds = 2; tSma.nFuncColIds = 5;
tSma.numOfFuncIds = 5; // sum/min/max/avg/last tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); ASSERT(tSma.funcColIds != NULL);
tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
SFuncColIds *funcColIds = tSma.funcColIds + n;
for (int32_t i = 0; i < tSma.numOfColIds; ++i) { funcColIds->funcId = n;
*(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); funcColIds->nColIds = 10;
} funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { ASSERT(funcColIds->colIds != NULL);
*(tSma.funcIds + i) = (i + 2); for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
}
} }
tSma.tagsFilterLen = strlen(tagsFilter);
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
SMeta * pMeta = NULL; SMeta * pMeta = NULL;
STSma * pSmaCfg = &tSma; STSma * pSmaCfg = &tSma;
const SMetaCfg *pMetaCfg = &defaultMetaOptions; const SMetaCfg *pMetaCfg = &defaultMetaOptions;
taosRemoveDir(smaTestDir); taosRemoveDir(smaTestDir);
@ -151,6 +168,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1); qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1);
assert(qSmaCfg != NULL); assert(qSmaCfg != NULL);
printf("name1 = %s\n", qSmaCfg->indexName); printf("name1 = %s\n", qSmaCfg->indexName);
printf("timezone1 = %s\n", qSmaCfg->timezone);
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid); EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
@ -159,6 +178,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2); qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2);
assert(qSmaCfg != NULL); assert(qSmaCfg != NULL);
printf("name2 = %s\n", qSmaCfg->indexName); printf("name2 = %s\n", qSmaCfg->indexName);
printf("timezone2 = %s\n", qSmaCfg->timezone);
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
EXPECT_EQ(qSmaCfg->interval, tSma.interval); EXPECT_EQ(qSmaCfg->interval, tSma.interval);
tdDestroyTSma(qSmaCfg); tdDestroyTSma(qSmaCfg);
@ -169,7 +190,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert(pSmaCur != NULL); assert(pSmaCur != NULL);
uint32_t indexCnt = 0; uint32_t indexCnt = 0;
while (1) { while (1) {
const char* indexName = metaSmaCursorNext(pSmaCur); const char *indexName = metaSmaCursorNext(pSmaCur);
if (indexName == NULL) { if (indexName == NULL) {
break; break;
} }
@ -184,10 +205,14 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
assert(pSW != NULL); assert(pSW != NULL);
EXPECT_EQ(pSW->number, nCntTSma); EXPECT_EQ(pSW->number, nCntTSma);
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
EXPECT_STRCASEEQ(pSW->tSma->timezone, timeZone);
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid); EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid);
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timeZone);
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid); EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid);
tdDestroyTSmaWrapper(pSW); tdDestroyTSmaWrapper(pSW);
tfree(pSW); tfree(pSW);
@ -211,9 +236,9 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
#if 0 #if 0
TEST(testCase, tSmaInsertTest) { TEST(testCase, tSmaInsertTest) {
STSma tSma = {0}; STSma tSma = {0};
STSmaData* pSmaData = NULL; STSmaData *pSmaData = NULL;
STsdb tsdb = {0}; STsdb tsdb = {0};
// init // init
tSma.intervalUnit = TD_TIME_UNIT_DAY; tSma.intervalUnit = TD_TIME_UNIT_DAY;
@ -226,7 +251,7 @@ TEST(testCase, tSmaInsertTest) {
int32_t dataLen = numOfColIds * numOfBlocks * blockSize; int32_t dataLen = numOfColIds * numOfBlocks * blockSize;
pSmaData = (STSmaData*)malloc(sizeof(STSmaData) + dataLen); pSmaData = (STSmaData *)malloc(sizeof(STSmaData) + dataLen);
ASSERT_EQ(pSmaData != NULL, true); ASSERT_EQ(pSmaData != NULL, true);
pSmaData->tableUid = 3232329230; pSmaData->tableUid = 3232329230;
pSmaData->numOfColIds = numOfColIds; pSmaData->numOfColIds = numOfColIds;
@ -234,7 +259,7 @@ TEST(testCase, tSmaInsertTest) {
pSmaData->dataLen = dataLen; pSmaData->dataLen = dataLen;
pSmaData->tsWindow.skey = 1640000000; pSmaData->tsWindow.skey = 1640000000;
pSmaData->tsWindow.ekey = 1645788649; pSmaData->tsWindow.ekey = 1645788649;
pSmaData->colIds = (col_id_t*)malloc(sizeof(col_id_t) * numOfColIds); pSmaData->colIds = (col_id_t *)malloc(sizeof(col_id_t) * numOfColIds);
ASSERT_EQ(pSmaData->colIds != NULL, true); ASSERT_EQ(pSmaData->colIds != NULL, true);
for (int32_t i = 0; i < numOfColIds; ++i) { for (int32_t i = 0; i < numOfColIds; ++i) {

View File

@ -2635,7 +2635,7 @@ void catalogDestroy(void) {
tsem_post(&gCtgMgmt.sem); tsem_post(&gCtgMgmt.sem);
while (CTG_IS_LOCKED(&gCtgMgmt.lock)) { while (CTG_IS_LOCKED(&gCtgMgmt.lock)) {
usleep(1); taosUsleep(1);
} }
CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock); CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock);

View File

@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); taosUsleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Get:%d\n", n); printf("Get:%d\n", n);
@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); taosUsleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); taosUsleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
tfree(tbMeta); tfree(tbMeta);
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); taosUsleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); taosUsleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
@ -880,7 +880,7 @@ TEST(tableMeta, normalTable) {
ASSERT_EQ(vgInfo.epSet.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
usleep(50000); taosMsleep(50);
} }
ctgTestSetRspTableMeta(); ctgTestSetRspTableMeta();
@ -901,7 +901,7 @@ TEST(tableMeta, normalTable) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) { if (0 == n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -949,7 +949,7 @@ TEST(tableMeta, normalTable) {
allDbNum += dbNum; allDbNum += dbNum;
allStbNum += stbNum; allStbNum += stbNum;
sleep(2); taosSsleep(2);
} }
ASSERT_EQ(allDbNum, 1); ASSERT_EQ(allDbNum, 1);
@ -996,7 +996,7 @@ TEST(tableMeta, childTableCase) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) { if (0 == n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1058,7 +1058,7 @@ TEST(tableMeta, childTableCase) {
allDbNum += dbNum; allDbNum += dbNum;
allStbNum += stbNum; allStbNum += stbNum;
sleep(2); taosSsleep(2);
} }
ASSERT_EQ(allDbNum, 1); ASSERT_EQ(allDbNum, 1);
@ -1105,7 +1105,7 @@ TEST(tableMeta, superTableCase) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) { if (0 == n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1132,7 +1132,7 @@ TEST(tableMeta, superTableCase) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (2 != n) { if (2 != n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1181,7 +1181,7 @@ TEST(tableMeta, superTableCase) {
allDbNum += dbNum; allDbNum += dbNum;
allStbNum += stbNum; allStbNum += stbNum;
sleep(2); taosSsleep(2);
} }
ASSERT_EQ(allDbNum, 1); ASSERT_EQ(allDbNum, 1);
@ -1230,7 +1230,7 @@ TEST(tableMeta, rmStbMeta) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) { if (0 == n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1244,7 +1244,7 @@ TEST(tableMeta, rmStbMeta) {
int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM); int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
if (n || m) { if (n || m) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1300,7 +1300,7 @@ TEST(tableMeta, updateStbMeta) {
while (true) { while (true) {
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
if (0 == n) { if (0 == n) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1320,7 +1320,7 @@ TEST(tableMeta, updateStbMeta) {
uint64_t n = 0; uint64_t n = 0;
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
if (n != 3) { if (n != 3) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -1392,7 +1392,7 @@ TEST(refreshGetMeta, normal2normal) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1410,7 +1410,7 @@ TEST(refreshGetMeta, normal2normal) {
tfree(tableMeta); tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@ -1471,7 +1471,7 @@ TEST(refreshGetMeta, normal2notexist) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1489,7 +1489,7 @@ TEST(refreshGetMeta, normal2notexist) {
tfree(tableMeta); tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@ -1545,7 +1545,7 @@ TEST(refreshGetMeta, normal2child) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1563,7 +1563,7 @@ TEST(refreshGetMeta, normal2child) {
tfree(tableMeta); tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@ -1629,7 +1629,7 @@ TEST(refreshGetMeta, stable2child) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1648,7 +1648,7 @@ TEST(refreshGetMeta, stable2child) {
tfree(tableMeta); tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
ctgTestCurrentSTableName = ctgTestSTablename; ctgTestCurrentSTableName = ctgTestSTablename;
@ -1714,7 +1714,7 @@ TEST(refreshGetMeta, stable2stable) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1733,7 +1733,7 @@ TEST(refreshGetMeta, stable2stable) {
tfree(tableMeta); tfree(tableMeta);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
@ -1802,7 +1802,7 @@ TEST(refreshGetMeta, child2stable) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
STableMeta *tableMeta = NULL; STableMeta *tableMeta = NULL;
@ -1819,7 +1819,7 @@ TEST(refreshGetMeta, child2stable) {
tfree(tableMeta); tfree(tableMeta);
while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
usleep(50000); taosMsleep(50);
} }
ctgTestCurrentSTableName = ctgTestTablename; ctgTestCurrentSTableName = ctgTestTablename;
@ -2019,7 +2019,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
if (n > 0) { if (n > 0) {
break; break;
} }
usleep(50000); taosMsleep(50);
} }
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
@ -2043,7 +2043,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
uint64_t n = 0; uint64_t n = 0;
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
if (n != 3) { if (n != 3) {
usleep(50000); taosMsleep(50);
} else { } else {
break; break;
} }
@ -2100,20 +2100,20 @@ TEST(multiThread, getSetRmSameDbVgroup) {
pthread_t thread1, thread2; pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg); pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
sleep(1); taosSsleep(1);
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg); pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
while (true) { while (true) {
if (ctgTestDeadLoop) { if (ctgTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(ctgTestMTRunSec); taosSsleep(ctgTestMTRunSec);
break; break;
} }
} }
ctgTestStop = true; ctgTestStop = true;
sleep(1); taosSsleep(1);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@ -2152,20 +2152,20 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
pthread_t thread1, thread2; pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg); pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
sleep(1); taosSsleep(1);
pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg); pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
while (true) { while (true) {
if (ctgTestDeadLoop) { if (ctgTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(ctgTestMTRunSec); taosSsleep(ctgTestMTRunSec);
break; break;
} }
} }
ctgTestStop = true; ctgTestStop = true;
sleep(1); taosSsleep(1);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@ -2203,20 +2203,20 @@ TEST(multiThread, ctableMeta) {
pthread_t thread1, thread2; pthread_t thread1, thread2;
pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg); pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
sleep(1); taosSsleep(1);
pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg); pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
while (true) { while (true) {
if (ctgTestDeadLoop) { if (ctgTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(ctgTestMTRunSec); taosSsleep(ctgTestMTRunSec);
break; break;
} }
} }
ctgTestStop = true; ctgTestStop = true;
sleep(2); taosSsleep(2);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
@ -2267,7 +2267,7 @@ TEST(rentTest, allRent) {
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) { while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
usleep(50000); taosMsleep(50);
} }
code = catalogGetExpiredDBs(pCtg, &dbs, &num); code = catalogGetExpiredDBs(pCtg, &dbs, &num);
@ -2292,7 +2292,7 @@ TEST(rentTest, allRent) {
} }
printf("*************************************************\n"); printf("*************************************************\n");
sleep(2); taosSsleep(2);
} }
catalogDestroy(); catalogDestroy();

View File

@ -61,7 +61,7 @@ typedef enum SResultTsInterpType {
#if 0 #if 0
static UNUSED_FUNC void *u_malloc (size_t __size) { static UNUSED_FUNC void *u_malloc (size_t __size) {
uint32_t v = rand(); uint32_t v = taosRand();
if (v % 1000 <= 0) { if (v % 1000 <= 0) {
return NULL; return NULL;
@ -71,7 +71,7 @@ static UNUSED_FUNC void *u_malloc (size_t __size) {
} }
static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) { static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
uint32_t v = rand(); uint32_t v = taosRand();
if (v % 1000 <= 0) { if (v % 1000 <= 0) {
return NULL; return NULL;
} else { } else {
@ -80,7 +80,7 @@ static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
} }
static UNUSED_FUNC void* u_realloc(void* p, size_t __size) { static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
uint32_t v = rand(); uint32_t v = taosRand();
if (v % 5 <= 1) { if (v % 5 <= 1) {
return NULL; return NULL;
} else { } else {

View File

@ -869,7 +869,7 @@ TEST(testCase, external_sort_Test) {
#if 0 #if 0
su* v = static_cast<su*>(calloc(1000000, sizeof(su))); su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
for(int32_t i = 0; i < 1000000; ++i) { for(int32_t i = 0; i < 1000000; ++i) {
v[i].v = rand(); v[i].v = taosRand();
v[i].c = static_cast<char*>(malloc(4)); v[i].c = static_cast<char*>(malloc(4));
*(int32_t*) v[i].c = i; *(int32_t*) v[i].c = i;
} }
@ -882,7 +882,7 @@ TEST(testCase, external_sort_Test) {
return; return;
#endif #endif
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
@ -943,7 +943,7 @@ TEST(testCase, external_sort_Test) {
} }
TEST(testCase, sorted_merge_Test) { TEST(testCase, sorted_merge_Test) {
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
@ -1015,7 +1015,7 @@ TEST(testCase, sorted_merge_Test) {
} }
TEST(testCase, time_interval_Operator_Test) { TEST(testCase, time_interval_Operator_Test) {
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};

View File

@ -25,7 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
TEST(testCase, linear_hash_Tests) { TEST(testCase, linear_hash_Tests) {
srand(time(NULL)); taosSeedRand(time(NULL));
_hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); _hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
#if 0 #if 0

View File

@ -699,7 +699,7 @@ class IndexObj {
for (int i = 0; i < numOfTable; i++) { for (int i = 0; i < numOfTable; i++) {
for (int k = 0; k < 10 && k < colVal.size(); k++) { for (int k = 0; k < 10 && k < colVal.size(); k++) {
// opt // opt
tColVal[rand() % colValSize] = 'a' + k % 26; tColVal[taosRand() % colValSize] = 'a' + k % 26;
} }
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
tColVal.c_str(), tColVal.size()); tColVal.c_str(), tColVal.size());

View File

@ -63,7 +63,7 @@ int main(int argc, char** argv) {
TEST(testCase, async_task_test) { TEST(testCase, async_task_test) {
SParam* p = (SParam*)calloc(1, sizeof(SParam)); SParam* p = (SParam*)calloc(1, sizeof(SParam));
taosAsyncExec(testPrint, p, NULL); taosAsyncExec(testPrint, p, NULL);
usleep(5000); taosMsleep(5);
} }
TEST(testCase, many_async_task_test) { TEST(testCase, many_async_task_test) {
@ -73,14 +73,14 @@ TEST(testCase, many_async_task_test) {
taosAsyncExec(testPrint, p, NULL); taosAsyncExec(testPrint, p, NULL);
} }
usleep(10000); taosMsleep(10);
} }
TEST(testCase, error_in_async_test) { TEST(testCase, error_in_async_test) {
int32_t code = 0; int32_t code = 0;
SParam* p = (SParam*) calloc(1, sizeof(SParam)); SParam* p = (SParam*) calloc(1, sizeof(SParam));
taosAsyncExec(testPrintError, p, &code); taosAsyncExec(testPrintError, p, &code);
usleep(1000); taosMsleep(1);
printf("Error code:%d after asynchronously exec function\n", code); printf("Error code:%d after asynchronously exec function\n", code);
} }

View File

@ -266,7 +266,7 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, struct SSubplan* pPlan, qTas
int32_t idx = abs((++qwtTestCaseIdx) % qwtTestCaseNum); int32_t idx = abs((++qwtTestCaseIdx) % qwtTestCaseNum);
qwtTestSinkBlockNum = 0; qwtTestSinkBlockNum = 0;
qwtTestSinkMaxBlockNum = rand() % 100 + 1; qwtTestSinkMaxBlockNum = taosRand() % 100 + 1;
qwtTestSinkQueryEnd = false; qwtTestSinkQueryEnd = false;
if (0 == idx) { if (0 == idx) {
@ -295,29 +295,29 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
} else { } else {
if (qwtTestSinkQueryEnd) { if (qwtTestSinkQueryEnd) {
*pRes = NULL; *pRes = NULL;
*useconds = rand() % 10; *useconds = taosRand() % 10;
return 0; return 0;
} }
endExec = rand() % 5; endExec = taosRand() % 5;
int32_t runTime = 0; int32_t runTime = 0;
if (qwtTestEnableSleep && qwtTestMaxExecTaskUsec > 0) { if (qwtTestEnableSleep && qwtTestMaxExecTaskUsec > 0) {
runTime = rand() % qwtTestMaxExecTaskUsec; runTime = taosRand() % qwtTestMaxExecTaskUsec;
} }
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
if (runTime) { if (runTime) {
usleep(runTime); taosUsleep(runTime);
} }
} }
if (endExec) { if (endExec) {
*pRes = (SSDataBlock*)calloc(1, sizeof(SSDataBlock)); *pRes = (SSDataBlock*)calloc(1, sizeof(SSDataBlock));
(*pRes)->info.rows = rand() % 1000; (*pRes)->info.rows = taosRand() % 1000;
} else { } else {
*pRes = NULL; *pRes = NULL;
*useconds = rand() % 10; *useconds = taosRand() % 10;
} }
} }
@ -376,7 +376,7 @@ void qwtGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd) {
taosWLockLatch(&qwtTestSinkLock); taosWLockLatch(&qwtTestSinkLock);
if (qwtTestSinkBlockNum > 0) { if (qwtTestSinkBlockNum > 0) {
*pLen = rand() % 100 + 1; *pLen = taosRand() % 100 + 1;
qwtTestSinkBlockNum--; qwtTestSinkBlockNum--;
} else { } else {
*pLen = 0; *pLen = 0;
@ -392,7 +392,7 @@ void qwtGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd) {
int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
taosWLockLatch(&qwtTestSinkLock); taosWLockLatch(&qwtTestSinkLock);
if (qwtTestSinkLastLen > 0) { if (qwtTestSinkLastLen > 0) {
pOutput->numOfRows = rand() % 10 + 1; pOutput->numOfRows = taosRand() % 10 + 1;
pOutput->compressed = 1; pOutput->compressed = 1;
pOutput->queryEnd = qwtTestSinkQueryEnd; pOutput->queryEnd = qwtTestSinkQueryEnd;
if (qwtTestSinkBlockNum == 0) { if (qwtTestSinkBlockNum == 0) {
@ -402,7 +402,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
} else { } else {
pOutput->bufStatus = DS_BUF_FULL; pOutput->bufStatus = DS_BUF_FULL;
} }
pOutput->useconds = rand() % 10 + 1; pOutput->useconds = taosRand() % 10 + 1;
pOutput->precision = 1; pOutput->precision = 1;
} else if (qwtTestSinkLastLen == 0) { } else if (qwtTestSinkLastLen == 0) {
pOutput->numOfRows = 0; pOutput->numOfRows = 0;
@ -416,7 +416,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
} else { } else {
pOutput->bufStatus = DS_BUF_FULL; pOutput->bufStatus = DS_BUF_FULL;
} }
pOutput->useconds = rand() % 10 + 1; pOutput->useconds = taosRand() % 10 + 1;
pOutput->precision = 1; pOutput->precision = 1;
} else { } else {
assert(0); assert(0);
@ -590,7 +590,7 @@ void *queryThread(void *param) {
qwtBuildQueryReqMsg(&queryRpc); qwtBuildQueryReqMsg(&queryRpc);
qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(rand()%5); taosUsleep(taosRand()%5);
} }
if (++n % qwtTestPrintNum == 0) { if (++n % qwtTestPrintNum == 0) {
printf("query:%d\n", n); printf("query:%d\n", n);
@ -612,7 +612,7 @@ void *readyThread(void *param) {
qwtBuildReadyReqMsg(&readyMsg, &readyRpc); qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(rand()%5); taosUsleep(taosRand()%5);
} }
if (++n % qwtTestPrintNum == 0) { if (++n % qwtTestPrintNum == 0) {
printf("ready:%d\n", n); printf("ready:%d\n", n);
@ -634,7 +634,7 @@ void *fetchThread(void *param) {
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(rand()%5); taosUsleep(taosRand()%5);
} }
if (++n % qwtTestPrintNum == 0) { if (++n % qwtTestPrintNum == 0) {
printf("fetch:%d\n", n); printf("fetch:%d\n", n);
@ -656,7 +656,7 @@ void *dropThread(void *param) {
qwtBuildDropReqMsg(&dropMsg, &dropRpc); qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(rand()%5); taosUsleep(taosRand()%5);
} }
if (++n % qwtTestPrintNum == 0) { if (++n % qwtTestPrintNum == 0) {
printf("drop:%d\n", n); printf("drop:%d\n", n);
@ -678,7 +678,7 @@ void *statusThread(void *param) {
qwtBuildStatusReqMsg(&statusMsg, &statusRpc); qwtBuildStatusReqMsg(&statusMsg, &statusRpc);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(rand()%5); taosUsleep(taosRand()%5);
} }
if (++n % qwtTestPrintNum == 0) { if (++n % qwtTestPrintNum == 0) {
printf("status:%d\n", n); printf("status:%d\n", n);
@ -696,7 +696,7 @@ void *qwtclientThread(void *param) {
void *mockPointer = (void *)0x1; void *mockPointer = (void *)0x1;
SRpcMsg queryRpc = {0}; SRpcMsg queryRpc = {0};
sleep(1); taosSsleep(1);
while (!qwtTestStop) { while (!qwtTestStop) {
qwtTestCaseFinished = false; qwtTestCaseFinished = false;
@ -705,7 +705,7 @@ void *qwtclientThread(void *param) {
qwtPutReqToQueue((void *)0x1, &queryRpc); qwtPutReqToQueue((void *)0x1, &queryRpc);
while (!qwtTestCaseFinished) { while (!qwtTestCaseFinished) {
usleep(1); taosUsleep(1);
} }
@ -748,10 +748,10 @@ void *queryQueueThread(void *param) {
if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) { if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) {
int32_t delay = rand() % qwtTestReqMaxDelayUsec; int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) { if (delay) {
usleep(delay); taosUsleep(delay);
} }
} }
@ -804,10 +804,10 @@ void *fetchQueueThread(void *param) {
taosWUnLockLatch(&qwtTestFetchQueueLock); taosWUnLockLatch(&qwtTestFetchQueueLock);
if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) { if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) {
int32_t delay = rand() % qwtTestReqMaxDelayUsec; int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) { if (delay) {
usleep(delay); taosUsleep(delay);
} }
} }
@ -963,7 +963,7 @@ TEST(seqTest, randCase) {
stubSetRpcSendResponse(); stubSetRpcSendResponse();
stubSetCreateExecTask(); stubSetCreateExecTask();
srand(time(NULL)); taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -971,7 +971,7 @@ TEST(seqTest, randCase) {
int32_t t = 0; int32_t t = 0;
int32_t maxr = 10001; int32_t maxr = 10001;
while (true) { while (true) {
int32_t r = rand() % maxr; int32_t r = taosRand() % maxr;
if (r >= 0 && r < maxr/5) { if (r >= 0 && r < maxr/5) {
printf("Query,%d\n", t++); printf("Query,%d\n", t++);
@ -982,21 +982,21 @@ TEST(seqTest, randCase) {
qwtBuildReadyReqMsg(&readyMsg, &readyRpc); qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(1); taosUsleep(1);
} }
} else if (r >= maxr * 2/5 && r < maxr* 3/5) { } else if (r >= maxr * 2/5 && r < maxr* 3/5) {
printf("Fetch,%d\n", t++); printf("Fetch,%d\n", t++);
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(1); taosUsleep(1);
} }
} else if (r >= maxr * 3/5 && r < maxr * 4/5) { } else if (r >= maxr * 3/5 && r < maxr * 4/5) {
printf("Drop,%d\n", t++); printf("Drop,%d\n", t++);
qwtBuildDropReqMsg(&dropMsg, &dropRpc); qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(1); taosUsleep(1);
} }
} else if (r >= maxr * 4/5 && r < maxr-1) { } else if (r >= maxr * 4/5 && r < maxr-1) {
printf("Status,%d\n", t++); printf("Status,%d\n", t++);
@ -1004,7 +1004,7 @@ TEST(seqTest, randCase) {
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
if (qwtTestEnableSleep) { if (qwtTestEnableSleep) {
usleep(1); taosUsleep(1);
} }
} else { } else {
printf("QUIT RAND NOW"); printf("QUIT RAND NOW");
@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) {
stubSetStringToPlan(); stubSetStringToPlan();
stubSetRpcSendResponse(); stubSetRpcSendResponse();
srand(time(NULL)); taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1042,15 +1042,15 @@ TEST(seqTest, multithreadRand) {
while (true) { while (true) {
if (qwtTestDeadLoop) { if (qwtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(qwtTestMTRunSec); taosSsleep(qwtTestMTRunSec);
break; break;
} }
} }
qwtTestStop = true; qwtTestStop = true;
sleep(3); taosSsleep(3);
qWorkerDestroy(&mgmt); qWorkerDestroy(&mgmt);
} }
@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
srand(time(NULL)); taosSeedRand(time(NULL));
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
@ -1099,9 +1099,9 @@ TEST(rcTest, shortExecshortDelay) {
while (true) { while (true) {
if (qwtTestDeadLoop) { if (qwtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(qwtTestMTRunSec); taosSsleep(qwtTestMTRunSec);
break; break;
} }
} }
@ -1113,14 +1113,14 @@ TEST(rcTest, shortExecshortDelay) {
break; break;
} }
sleep(1); taosSsleep(1);
if (qwtTestCaseFinished) { if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) { if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem); tsem_post(&qwtTestFetchSem);
usleep(10); taosUsleep(10);
} }
} }
@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
srand(time(NULL)); taosSeedRand(time(NULL));
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
@ -1180,9 +1180,9 @@ TEST(rcTest, longExecshortDelay) {
while (true) { while (true) {
if (qwtTestDeadLoop) { if (qwtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(qwtTestMTRunSec); taosSsleep(qwtTestMTRunSec);
break; break;
} }
} }
@ -1195,14 +1195,14 @@ TEST(rcTest, longExecshortDelay) {
break; break;
} }
sleep(1); taosSsleep(1);
if (qwtTestCaseFinished) { if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) { if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem); tsem_post(&qwtTestFetchSem);
usleep(10); taosUsleep(10);
} }
} }
@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
srand(time(NULL)); taosSeedRand(time(NULL));
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
@ -1263,9 +1263,9 @@ TEST(rcTest, shortExeclongDelay) {
while (true) { while (true) {
if (qwtTestDeadLoop) { if (qwtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(qwtTestMTRunSec); taosSsleep(qwtTestMTRunSec);
break; break;
} }
} }
@ -1278,14 +1278,14 @@ TEST(rcTest, shortExeclongDelay) {
break; break;
} }
sleep(1); taosSsleep(1);
if (qwtTestCaseFinished) { if (qwtTestCaseFinished) {
if (qwtTestQuitThreadNum < 3) { if (qwtTestQuitThreadNum < 3) {
tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestQuerySem);
tsem_post(&qwtTestFetchSem); tsem_post(&qwtTestFetchSem);
usleep(10); taosUsleep(10);
} }
} }
@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
srand(time(NULL)); taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -1342,15 +1342,15 @@ TEST(rcTest, dropTest) {
while (true) { while (true) {
if (qwtTestDeadLoop) { if (qwtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(qwtTestMTRunSec); taosSsleep(qwtTestMTRunSec);
break; break;
} }
} }
qwtTestStop = true; qwtTestStop = true;
sleep(3); taosSsleep(3);
qWorkerDestroy(&mgmt); qWorkerDestroy(&mgmt);
} }
@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -1427,7 +1427,7 @@ TEST(columnTest, greater_and_lower) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -278,7 +278,7 @@ void *schtSendRsp(void *param) {
break; break;
} }
usleep(1000); taosMsleep(1);
} }
pJob = schAcquireJob(job); pJob = schAcquireJob(job);
@ -303,7 +303,7 @@ void *schtCreateFetchRspThread(void *param) {
int64_t job = *(int64_t *)param; int64_t job = *(int64_t *)param;
SSchJob* pJob = schAcquireJob(job); SSchJob* pJob = schAcquireJob(job);
sleep(1); taosSsleep(1);
int32_t code = 0; int32_t code = 0;
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp)); SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp));
@ -327,7 +327,7 @@ void *schtFetchRspThread(void *aa) {
continue; continue;
} }
usleep(1); taosUsleep(1);
param = (SSchCallbackParam *)calloc(1, sizeof(*param)); param = (SSchCallbackParam *)calloc(1, sizeof(*param));
@ -532,7 +532,7 @@ void* schtRunJobThread(void *aa) {
void* schtFreeJobThread(void *aa) { void* schtFreeJobThread(void *aa) {
while (!schtTestStop) { while (!schtTestStop) {
usleep(rand() % 100); taosUsleep(taosRand() % 100);
schtFreeQueryJob(1); schtFreeQueryJob(1);
} }
} }
@ -701,19 +701,19 @@ TEST(multiThread, forceFree) {
while (true) { while (true) {
if (schtTestDeadLoop) { if (schtTestDeadLoop) {
sleep(1); taosSsleep(1);
} else { } else {
sleep(schtTestMTRunSec); taosSsleep(schtTestMTRunSec);
break; break;
} }
} }
schtTestStop = true; schtTestStop = true;
sleep(3); taosSsleep(3);
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer);
int32_t syncEnvStart() { int32_t syncEnvStart() {
int32_t ret; int32_t ret;
srand(time(NULL)); taosSeedRand(time(NULL));
gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv)); gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
assert(gSyncEnv != NULL); assert(gSyncEnv != NULL);
ret = doSyncEnvStart(gSyncEnv); ret = doSyncEnvStart(gSyncEnv);

View File

@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) {
gSyncIO = syncIOCreate(host, port); gSyncIO = syncIOCreate(host, port);
assert(gSyncIO != NULL); assert(gSyncIO != NULL);
srand(time(NULL)); taosSeedRand(time(NULL));
int32_t ret = syncIOStartInternal(gSyncIO); int32_t ret = syncIOStartInternal(gSyncIO);
assert(ret == 0); assert(ret == 0);

View File

@ -95,7 +95,7 @@ void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
// ---- misc ---- // ---- misc ----
int32_t syncUtilRand(int32_t max) { return rand() % max; } int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
int32_t syncUtilElectRandomMS() { return ELECT_TIMER_MS_MIN + syncUtilRand(ELECT_TIMER_MS_RANGE); } int32_t syncUtilElectRandomMS() { return ELECT_TIMER_MS_MIN + syncUtilRand(ELECT_TIMER_MS_RANGE); }

View File

@ -39,11 +39,11 @@ int main() {
rpcMsg.msgType = 77; rpcMsg.msgType = 77;
syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg); syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg);
sleep(1); taosSsleep(1);
} }
while (1) { while (1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;

View File

@ -26,7 +26,7 @@ int main() {
assert(ret == 0); assert(ret == 0);
while (1) { while (1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;

View File

@ -39,11 +39,11 @@ int main() {
rpcMsg.msgType = 77; rpcMsg.msgType = 77;
syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg); syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg);
sleep(1); taosSsleep(1);
} }
while (1) { while (1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;

View File

@ -29,7 +29,7 @@ int main() {
assert(ret == 0); assert(ret == 0);
while (1) { while (1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;
} }

View File

@ -29,7 +29,7 @@ int main() {
assert(ret == 0); assert(ret == 0);
while (1) { while (1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;
} }

View File

@ -27,7 +27,7 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
((uint64_t *)fileid)[0] = stDev; ((uint64_t *)fileid)[0] = stDev;
((uint64_t *)fileid)[1] = stIno; ((uint64_t *)fileid)[1] = stIno;
if (unique) { if (unique) {
((uint64_t *)fileid)[2] = rand(); ((uint64_t *)fileid)[2] = taosRand();
} }
return 0; return 0;

View File

@ -749,7 +749,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
memcpy(pConn->user, pHead->user, tListLen(pConn->user)); memcpy(pConn->user, pHead->user, tListLen(pConn->user));
pConn->pRpc = pRpc; pConn->pRpc = pRpc;
pConn->sid = sid; pConn->sid = sid;
pConn->tranId = (uint16_t)(rand() & 0xFFFF); pConn->tranId = (uint16_t)(taosRand() & 0xFFFF);
pConn->ownId = htonl(pConn->sid); pConn->ownId = htonl(pConn->sid);
pConn->linkUid = pHead->linkUid; pConn->linkUid = pHead->linkUid;
if (pRpc->afp) { if (pRpc->afp) {

View File

@ -107,7 +107,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully"); tDebug("recv response succefully");
// usleep(100000000); // taosSsleep(100);
} }
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
} }
do { do {
usleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); gettimeofday(&systemTime, NULL);

View File

@ -77,7 +77,7 @@ void processShellMsg() {
taosFreeQitem(pRpcMsg); taosFreeQitem(pRpcMsg);
{ {
// sleep(1); // taosSsleep(1);
SRpcMsg nRpcMsg = {0}; SRpcMsg nRpcMsg = {0};
nRpcMsg.pCont = rpcMallocCont(msgSize); nRpcMsg.pCont = rpcMallocCont(msgSize);
nRpcMsg.contLen = msgSize; nRpcMsg.contLen = msgSize;
@ -176,7 +176,7 @@ int main(int argc, char *argv[]) {
tError("failed to start RPC server"); tError("failed to start RPC server");
return -1; return -1;
} }
// sleep(5); // taosSsleep(5);
tInfo("RPC server is running, ctrl-c to exit"); tInfo("RPC server is running, ctrl-c to exit");

View File

@ -84,7 +84,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully"); tDebug("recv response succefully");
// usleep(100000000); // taosSsleep(100);
} }
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@ -200,7 +200,7 @@ int main(int argc, char *argv[]) {
} }
do { do {
usleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); gettimeofday(&systemTime, NULL);

View File

@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
} }
do { do {
usleep(1); taosUsleep(1);
} while ( tcount < appThreads); } while ( tcount < appThreads);
gettimeofday(&systemTime, NULL); gettimeofday(&systemTime, NULL);

View File

@ -85,7 +85,7 @@ static void *sendRequest(void *param) {
tDebug("recv response succefully"); tDebug("recv response succefully");
// usleep(100000000); // taosSsleep(100);
} }
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
} }
do { do {
usleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); gettimeofday(&systemTime, NULL);

View File

@ -300,7 +300,7 @@ TEST_F(WalKeepEnv, readHandleRead) {
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
} }
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
int ver = rand() % 100; int ver = taosRand() % 100;
code = walReadWithHandle(pRead, ver); code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -352,7 +352,7 @@ TEST_F(WalRetentionEnv, repairMeta1) {
ASSERT(pRead != NULL); ASSERT(pRead != NULL);
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
int ver = rand() % 100; int ver = taosRand() % 100;
code = walReadWithHandle(pRead, ver); code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
@ -382,7 +382,7 @@ TEST_F(WalRetentionEnv, repairMeta1) {
} }
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
int ver = rand() % 200; int ver = taosRand() % 200;
code = walReadWithHandle(pRead, ver); code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);

View File

@ -38,7 +38,7 @@ float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0; int64_t tsTotalMemoryKB = 0;
void osInit() { void osInit() {
srand(taosSafeRand()); taosSeedRand(taosSafeRand());
taosGetSystemLocale(tsLocale, tsCharset); taosGetSystemLocale(tsLocale, tsCharset);
taosGetSystemTimezone(tsTimezone); taosGetSystemTimezone(tsTimezone);
taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
@ -21,8 +21,12 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t taosRand(void) { return rand(); } uint32_t taosRand(void) { return rand(); }
uint32_t taosRandR(uint32_t *pSeed) { return rand_r(pSeed); }
uint32_t taosSafeRand(void) { uint32_t taosSafeRand(void) {
TdFilePtr pFile; TdFilePtr pFile;
int seed; int seed;

View File

@ -13,47 +13,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
void taosMsleep(int32_t ms) { Sleep(ms); }
#else
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#include <unistd.h> #include <unistd.h>
#endif
/* void taosSsleep(int32_t s) {
to make taosMsleep work, #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
signal SIGALRM shall be blocked in the calling thread, Sleep(1000 * s);
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGALRM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
*/
void taosMsleep(int32_t mseconds) {
#if 1
usleep(mseconds * 1000);
#else #else
struct timeval timeout; sleep(s);
int32_t seconds, useconds;
seconds = mseconds / 1000;
useconds = (mseconds % 1000) * 1000;
timeout.tv_sec = seconds;
timeout.tv_usec = useconds;
/* sigset_t set; */
/* sigemptyset(&set); */
/* sigaddset(&set, SIGALRM); */
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
select(0, NULL, NULL, NULL, &timeout);
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
#endif #endif
} }
void taosMsleep(int32_t ms) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
Sleep(ms);
#else
usleep(ms * 1000);
#endif #endif
}
void taosUsleep(int32_t us) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
nanosleep(1000 * us);
#else
usleep(us);
#endif
}

View File

@ -291,11 +291,10 @@ int32_t twcslen(const wchar_t *wcs) {
return n; return n;
} }
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
for (int32_t i = 0; i < bytes; ++i) { for (int32_t i = 0; i < bytes; i += TSDB_NCHAR_SIZE) {
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i);
int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i);
if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) { if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) {
return f1 - f2; return f1 - f2;

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ void process_message(uint8_t* message_piece, uint8_t* processed_piece, key_set*
#if 0 #if 0
int64_t taosDesGenKey() { int64_t taosDesGenKey() {
uint32_t iseed = (uint32_t)time(NULL); uint32_t iseed = (uint32_t)time(NULL);
srand(iseed); taosSeedRand(iseed);
uint8_t key[8] = {0}; uint8_t key[8] = {0};
generate_key(key); generate_key(key);

View File

@ -51,7 +51,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
pSkipList->len = keyLen; pSkipList->len = keyLen;
pSkipList->flags = flags; pSkipList->flags = flags;
pSkipList->keyFn = fn; pSkipList->keyFn = fn;
pSkipList->seed = rand(); pSkipList->seed = taosRand();
#if 0 #if 0
// the function getkeycomparfunc is defined in common // the function getkeycomparfunc is defined in common
@ -82,7 +82,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
} }
} }
srand((uint32_t)time(NULL)); taosSeedRand((uint32_t)time(NULL));
#if SKIP_LIST_RECORD_PERFORMANCE #if SKIP_LIST_RECORD_PERFORMANCE
pSkipList->state.nTotalMemSize += sizeof(SSkipList); pSkipList->state.nTotalMemSize += sizeof(SSkipList);
@ -560,9 +560,9 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) {
int32_t n = 1; int32_t n = 1;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) {
#else #else
while ((rand_r(&(pSkipList->seed)) % factor) == 0 && n <= pSkipList->maxLevel) { while ((taosRandR(&(pSkipList->seed)) % factor) == 0 && n <= pSkipList->maxLevel) {
#endif #endif
n++; n++;
} }

View File

@ -14,7 +14,7 @@ TEST(cacheTest, client_cache_test) {
char data1[] = "test11"; char data1[] = "test11";
char* cachedObj = (char*) taosCachePut(tscMetaCache, key1, strlen(key1), data1, strlen(data1)+1, 1); char* cachedObj = (char*) taosCachePut(tscMetaCache, key1, strlen(key1), data1, strlen(data1)+1, 1);
sleep(REFRESH_TIME_IN_SEC+1); taosSsleep(REFRESH_TIME_IN_SEC+1);
printf("obj is still valid: %s\n", cachedObj); printf("obj is still valid: %s\n", cachedObj);
@ -37,7 +37,7 @@ TEST(cacheTest, client_cache_test) {
taosCacheRelease(tscMetaCache, (void**) &cachedObj2, false); taosCacheRelease(tscMetaCache, (void**) &cachedObj2, false);
sleep(3); taosSsleep(3);
char* d = (char*) taosCacheAcquireByKey(tscMetaCache, key3, strlen(key3)); char* d = (char*) taosCacheAcquireByKey(tscMetaCache, key3, strlen(key3));
assert(d == NULL); assert(d == NULL);

View File

@ -150,7 +150,7 @@ static bool test_variant_int64(int64_t value) {
} }
TEST(codingTest, fixed_encode_decode) { TEST(codingTest, fixed_encode_decode) {
srand(time(0)); taosSeedRand(time(0));
// uint16_t // uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) { for (uint16_t value = 0; value <= UINT16_MAX; value++) {
@ -204,7 +204,7 @@ TEST(codingTest, fixed_encode_decode) {
} }
TEST(codingTest, variant_encode_decode) { TEST(codingTest, variant_encode_decode) {
srand(time(0)); taosSeedRand(time(0));
// uint16_t // uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) { for (uint16_t value = 0; value <= UINT16_MAX; value++) {

View File

@ -161,7 +161,7 @@ void recyclePageTest() {
TEST(testCase, resultBufferTest) { TEST(testCase, resultBufferTest) {
srand(time(NULL)); taosSeedRand(time(NULL));
simpleTest(); simpleTest();
writeDownTest(); writeDownTest();
recyclePageTest(); recyclePageTest();

View File

@ -47,7 +47,7 @@ void doubleSkipListTest() {
SSkipListKey sk; SSkipListKey sk;
for (int32_t i = 0; i < 100; ++i) { for (int32_t i = 0; i < 100; ++i) {
sk.nType = TSDB_DATA_TYPE_DOUBLE; sk.nType = TSDB_DATA_TYPE_DOUBLE;
int32_t idx = abs((i * rand()) % 1000); int32_t idx = abs((i * taosRand()) % 1000);
sk.dKey = doubleVal[idx]; sk.dKey = doubleVal[idx];
@ -74,7 +74,7 @@ void randKeyTest() {
false, getkey); false, getkey);
int32_t size = 200000; int32_t size = 200000;
srand(time(NULL)); taosSeedRand(time(NULL));
printf("generated %d keys is: \n", size); printf("generated %d keys is: \n", size);
@ -87,7 +87,7 @@ void randKeyTest() {
d->level = level; d->level = level;
int32_t* key = (int32_t*)SL_GET_NODE_KEY(pSkipList, d); int32_t* key = (int32_t*)SL_GET_NODE_KEY(pSkipList, d);
key[0] = rand() % 1000000000; key[0] = taosRand() % 1000000000;
key[1] = key[0]; key[1] = key[0];
@ -337,7 +337,7 @@ void duplicatedKeyTest() {
TEST(testCase, skiplist_test) { TEST(testCase, skiplist_test) {
assert(sizeof(SSkipListKey) == 8); assert(sizeof(SSkipListKey) == 8);
srand(time(NULL)); taosSeedRand(time(NULL));
stringKeySkiplistTest(); stringKeySkiplistTest();
doubleSkipListTest(); doubleSkipListTest();

View File

@ -42,7 +42,7 @@ void *addRef(void *param) {
pSpace->p[id] = malloc(128); pSpace->p[id] = malloc(128);
pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]); pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]);
} }
usleep(100); taosUsleep(100);
} }
return NULL; return NULL;
@ -60,7 +60,7 @@ void *removeRef(void *param) {
if (code == 0) pSpace->rid[id] = 0; if (code == 0) pSpace->rid[id] = 0;
} }
usleep(100); taosUsleep(100);
} }
return NULL; return NULL;
@ -76,7 +76,7 @@ void *acquireRelease(void *param) {
id = random() % pSpace->refNum; id = random() % pSpace->refNum;
void *p = taosAcquireRef(pSpace->rsetId, (int64_t) pSpace->p[id]); void *p = taosAcquireRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
if (p) { if (p) {
usleep(id % 5 + 1); taosUsleep(id % 5 + 1);
taosReleaseRef(pSpace->rsetId, (int64_t) pSpace->p[id]); taosReleaseRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
} }
} }

View File

@ -5089,7 +5089,7 @@ int main(int argc, char *argv[])
//pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]); //pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while(1) { while(1) {
sleep(1); taosSsleep(1);
} }
return 0; return 0;
} }

View File

@ -1 +1,10 @@
add_subdirectory(shell) IF (TD_TAOS_TOOLS)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tools/taos_tools/deps/avro/lang/c/src)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/client)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/common)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/util)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/os)
ADD_SUBDIRECTORY(taos-tools)
ENDIF ()
add_subdirectory(shell)

1
tools/taos-tools Submodule

@ -0,0 +1 @@
Subproject commit f36b07f710d661dca88fdd70e73b5e3e16a960e0