未验证 提交 51490bdb 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #9182 from taosdata/feature/dnode3

make script/sh available
...@@ -26,8 +26,9 @@ if(${BUILD_TEST}) ...@@ -26,8 +26,9 @@ if(${BUILD_TEST})
endif(${BUILD_TEST}) endif(${BUILD_TEST})
add_subdirectory(source) add_subdirectory(source)
add_subdirectory(tools) add_subdirectory(tools)
add_subdirectory(tests)
# docs # docs
add_subdirectory(docs) add_subdirectory(docs)
# tests (TODO) # tests (TODO)
\ No newline at end of file
...@@ -235,6 +235,7 @@ do { \ ...@@ -235,6 +235,7 @@ do { \
#define TSDB_MAX_VNODES 512 #define TSDB_MAX_VNODES 512
#define TSDB_MIN_VNODES_PER_DB 1 #define TSDB_MIN_VNODES_PER_DB 1
#define TSDB_MAX_VNODES_PER_DB 4096 #define TSDB_MAX_VNODES_PER_DB 4096
#define TSDB_DEFAULT_VN_PER_DB 2
#define TSDB_DNODE_ROLE_ANY 0 #define TSDB_DNODE_ROLE_ANY 0
#define TSDB_DNODE_ROLE_MGMT 1 #define TSDB_DNODE_ROLE_MGMT 1
......
...@@ -92,6 +92,7 @@ void dmnPrintVersion() { ...@@ -92,6 +92,7 @@ void dmnPrintVersion() {
} }
int dmnReadConfig(const char *path) { int dmnReadConfig(const char *path) {
tstrncpy(configDir, global.configDir, PATH_MAX);
taosInitGlobalCfg(); taosInitGlobalCfg();
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
......
...@@ -182,6 +182,7 @@ typedef struct { ...@@ -182,6 +182,7 @@ typedef struct {
} SUserObj; } SUserObj;
typedef struct { typedef struct {
int32_t numOfVgroups;
int32_t cacheBlockSize; int32_t cacheBlockSize;
int32_t totalBlocks; int32_t totalBlocks;
int32_t daysPerFile; int32_t daysPerFile;
...@@ -209,7 +210,6 @@ typedef struct { ...@@ -209,7 +210,6 @@ typedef struct {
int64_t uid; int64_t uid;
int32_t cfgVersion; int32_t cfgVersion;
int32_t vgVersion; int32_t vgVersion;
int32_t numOfVgroups;
int8_t hashMethod; // default is 1 int8_t hashMethod; // default is 1
SDbCfg cfg; SDbCfg cfg;
} SDbObj; } SDbObj;
......
...@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { ...@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT64(pRaw, dataPos, pDb->uid) SDB_SET_INT64(pRaw, dataPos, pDb->uid)
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion) SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion)
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion) SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion)
SDB_SET_INT32(pRaw, dataPos, pDb->numOfVgroups)
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod) SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile)
...@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { ...@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid) SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->numOfVgroups)
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod) SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile)
...@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) { ...@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
pOldDb->updateTime = pNewDb->createdTime; pOldDb->updateTime = pNewDb->createdTime;
pOldDb->cfgVersion = pNewDb->cfgVersion; pOldDb->cfgVersion = pNewDb->cfgVersion;
pOldDb->vgVersion = pNewDb->vgVersion; pOldDb->vgVersion = pNewDb->vgVersion;
pOldDb->numOfVgroups = pNewDb->numOfVgroups;
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg)); memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
return 0; return 0;
} }
...@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) { ...@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
} }
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1; if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1;
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1; if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1;
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1; if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
...@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { ...@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
} }
static void mndSetDefaultDbCfg(SDbCfg *pCfg) { static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->numOfVgroups < 0) pCfg->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE; if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS; if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
...@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb ...@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING); sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING); sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING);
...@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb ...@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED); sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED); sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED);
...@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg ...@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg
if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_READY); sdbSetRawStatus(pDbRaw, SDB_STATUS_READY);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
...@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat ...@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
dbObj.createdTime = taosGetTimestampMs(); dbObj.createdTime = taosGetTimestampMs();
dbObj.updateTime = dbObj.createdTime; dbObj.updateTime = dbObj.createdTime;
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN); dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
dbObj.numOfVgroups = pCreate->numOfVgroups;
dbObj.hashMethod = 1; dbObj.hashMethod = 1;
dbObj.cfgVersion = 1; dbObj.cfgVersion = 1;
dbObj.vgVersion = 1; dbObj.vgVersion = 1;
dbObj.cfg = (SDbCfg){.cacheBlockSize = pCreate->cacheBlockSize, dbObj.cfg = (SDbCfg){.numOfVgroups = pCreate->numOfVgroups,
.cacheBlockSize = pCreate->cacheBlockSize,
.totalBlocks = pCreate->totalBlocks, .totalBlocks = pCreate->totalBlocks,
.daysPerFile = pCreate->daysPerFile, .daysPerFile = pCreate->daysPerFile,
.daysToKeep0 = pCreate->daysToKeep0, .daysToKeep0 = pCreate->daysToKeep0,
...@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { ...@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
return -1; return -1;
} }
int32_t contLen = sizeof(SUseDbRsp) + pDb->numOfVgroups * sizeof(SVgroupInfo); int32_t contLen = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
SUseDbRsp *pRsp = rpcMallocCont(contLen); SUseDbRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { ...@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
if (pUse->vgVersion < pDb->vgVersion) { if (pUse->vgVersion < pDb->vgVersion) {
void *pIter = NULL; void *pIter = NULL;
while (vindex < pDb->numOfVgroups) { while (vindex < pDb->cfg.numOfVgroups) {
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break; if (pIter == NULL) break;
...@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 ...@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *)pWrite = pDb->numOfVgroups; *(int16_t *)pWrite = pDb->cfg.numOfVgroups;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
......
...@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) { ...@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
sdbRelease(pSdb, pVgroup); sdbRelease(pSdb, pVgroup);
} }
static int32_t mndGetDefaultVgroupSize(SMnode *pMnode) {
// todo
return 2;
}
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) { static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t allocedVnodes = 0; int32_t allocedVnodes = 0;
...@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) { ...@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
} }
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
if (pDb->numOfVgroups != -1 && SVgObj *pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj));
(pDb->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pDb->numOfVgroups > TSDB_MAX_VNODES_PER_DB)) {
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
return -1;
}
if (pDb->numOfVgroups == -1) {
pDb->numOfVgroups = mndGetDefaultVgroupSize(pMnode);
if (pDb->numOfVgroups < 0) {
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
return -1;
}
}
SVgObj *pVgroups = calloc(pDb->numOfVgroups, sizeof(SVgObj));
if (pVgroups == NULL) { if (pVgroups == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
...@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { ...@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
uint32_t hashMin = 0; uint32_t hashMin = 0;
uint32_t hashMax = UINT32_MAX; uint32_t hashMax = UINT32_MAX;
uint32_t hashInterval = (hashMax - hashMin) / pDb->numOfVgroups; uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
for (uint32_t v = 0; v < pDb->numOfVgroups; v++) { for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
SVgObj *pVgroup = &pVgroups[v]; SVgObj *pVgroup = &pVgroups[v];
pVgroup->vgId = maxVgId++; pVgroup->vgId = maxVgId++;
pVgroup->createdTime = taosGetTimestampMs(); pVgroup->createdTime = taosGetTimestampMs();
...@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { ...@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup->version = 1; pVgroup->version = 1;
pVgroup->dbUid = pDb->uid; pVgroup->dbUid = pDb->uid;
pVgroup->hashBegin = hashMin + hashInterval * v; pVgroup->hashBegin = hashMin + hashInterval * v;
if (v == pDb->numOfVgroups - 1) { if (v == pDb->cfg.numOfVgroups - 1) {
pVgroup->hashEnd = hashMax; pVgroup->hashEnd = hashMax;
} else { } else {
pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1; pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1;
......
# generate debug version: #ADD_SUBDIRECTORY(examples/c)
# mkdir debug; cd debug; cmake -DCMAKE_BUILD_TYPE=Debug ..
# generate release version:
# mkdir release; cd release; cmake -DCMAKE_BUILD_TYPE=Release ..
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(TDengine)
SET(CMAKE_C_STANDARD 11)
SET(CMAKE_VERBOSE_MAKEFILE ON)
ADD_SUBDIRECTORY(examples/c)
ADD_SUBDIRECTORY(tsim) ADD_SUBDIRECTORY(tsim)
ADD_SUBDIRECTORY(test/c) #ADD_SUBDIRECTORY(test/c)
ADD_SUBDIRECTORY(comparisonTest/tdengine) #ADD_SUBDIRECTORY(comparisonTest/tdengine)
...@@ -5,7 +5,7 @@ sql connect ...@@ -5,7 +5,7 @@ sql connect
print =============== show users print =============== show users
sql show users sql show users
if $rows != 3 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -21,7 +21,7 @@ sql_error drop account root ...@@ -21,7 +21,7 @@ sql_error drop account root
print =============== create user1 print =============== create user1
sql create user user1 PASS 'user1' sql create user user1 PASS 'user1'
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -33,7 +33,7 @@ print $data30 $data31 $data32 ...@@ -33,7 +33,7 @@ print $data30 $data31 $data32
print =============== create user2 print =============== create user2
sql create user user2 PASS 'user2' sql create user user2 PASS 'user2'
sql show users sql show users
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
...@@ -46,7 +46,7 @@ print $data40 $data41 $data42 ...@@ -46,7 +46,7 @@ print $data40 $data41 $data42
print =============== drop user1 print =============== drop user1
sql drop user user1 sql drop user user1
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start ...@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start
print =============== show users print =============== show users
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
......
#!/bin/bash #!/bin/bash
set +e
#set -x
echo "Executing deploy.sh" echo "Executing deploy.sh"
if [ $# != 4 ]; then if [ $# != 4 ]; then
...@@ -50,12 +53,12 @@ else ...@@ -50,12 +53,12 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim SIM_DIR=$TAOS_DIR/sim
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
# exit 1 # exit 1
# fi # fi
set +e
#set -x
UNAME_BIN=`which uname` UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN` OS_TYPE=`$UNAME_BIN`
...@@ -62,16 +65,16 @@ else ...@@ -62,16 +65,16 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim SIM_DIR=$TAOS_DIR/sim
NODE_DIR=$SIM_DIR/$NODE_NAME NODE_DIR=$SIM_DIR/$NODE_NAME
EXE_DIR=$BUILD_DIR/bin EXE_DIR=$BUILD_DIR/source/dnode/mgmt/daemon
CFG_DIR=$NODE_DIR/cfg CFG_DIR=$NODE_DIR/cfg
LOG_DIR=$NODE_DIR/log LOG_DIR=$NODE_DIR/log
DATA_DIR=$NODE_DIR/data DATA_DIR=$NODE_DIR/data
......
...@@ -22,9 +22,6 @@ do ...@@ -22,9 +22,6 @@ do
f) f)
FILE_NAME=$OPTARG FILE_NAME=$OPTARG
;; ;;
a)
ASYNC=1
;;
v) v)
VALGRIND=1 VALGRIND=1
;; ;;
...@@ -60,32 +57,22 @@ else ...@@ -60,32 +57,22 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TOP_DIR/$BIN_DIR/build BUILD_DIR=$TOP_DIR/$BIN_DIR
SIM_DIR=$TOP_DIR/sim SIM_DIR=$TOP_DIR/sim
if [ $ASYNC -eq 0 ]; then PROGRAM=$BUILD_DIR/tests/tsim/tsim
PROGRAM=$BUILD_DIR/bin/tsim
else
PROGRAM="$BUILD_DIR/bin/tsim -a"
fi
PRG_DIR=$SIM_DIR/tsim PRG_DIR=$SIM_DIR/tsim
CFG_DIR=$PRG_DIR/cfg CFG_DIR=$PRG_DIR/cfg
LOG_DIR=$PRG_DIR/log LOG_DIR=$PRG_DIR/log
DATA_DIR=$PRG_DIR/data DATA_DIR=$PRG_DIR/data
ARBITRATOR_PRG_DIR=$SIM_DIR/arbitrator
ARBITRATOR_LOG_DIR=$ARBITRATOR_PRG_DIR/log
chmod -R 777 $PRG_DIR chmod -R 777 $PRG_DIR
echo "------------------------------------------------------------------------" echo "------------------------------------------------------------------------"
echo "Start TDengine Testing Case ..." echo "Start TDengine Testing Case ..."
...@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR" ...@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR"
rm -rf $LOG_DIR rm -rf $LOG_DIR
rm -rf $CFG_DIR rm -rf $CFG_DIR
rm -rf $ARBITRATOR_LOG_DIR
mkdir -p $PRG_DIR mkdir -p $PRG_DIR
mkdir -p $LOG_DIR mkdir -p $LOG_DIR
mkdir -p $CFG_DIR mkdir -p $CFG_DIR
mkdir -p $ARBITRATOR_LOG_DIR
TAOS_CFG=$PRG_DIR/cfg/taos.cfg TAOS_CFG=$PRG_DIR/cfg/taos.cfg
touch -f $TAOS_CFG touch -f $TAOS_CFG
...@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG ...@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
echo "serverPort 7100" >> $TAOS_CFG echo "serverPort 7100" >> $TAOS_CFG
echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG
echo "logDir $LOG_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG
echo "scriptDir ${CODE_DIR}/../script" >> $TAOS_CFG echo "scriptDir ${CODE_DIR}" >> $TAOS_CFG
echo "numOfLogLines 100000000" >> $TAOS_CFG echo "numOfLogLines 100000000" >> $TAOS_CFG
echo "rpcDebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG
echo "tmrDebugFlag 131" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG
...@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then ...@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then
else else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME
$PROGRAM -c $CFG_DIR -f $FILE_NAME $PROGRAM -c $CFG_DIR -f $FILE_NAME
# valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME
fi fi
else else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim
......
PROJECT(TDengine) aux_source_directory(src TSIM_SRC)
add_executable(tsim ${TSIM_SRC})
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) target_link_libraries(
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) tsim
INCLUDE_DIRECTORIES(inc) PUBLIC taos
PUBLIC util
AUX_SOURCE_DIRECTORY(src SRC) PUBLIC common
ADD_EXECUTABLE(tsim ${SRC}) PUBLIC os
TARGET_LINK_LIBRARIES(tsim taos_static trpc tutil pthread cJson) PUBLIC cjson
)
target_include_directories(
tsim
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SIM_H__ #ifndef _TD_SIM_H_
#define __SIM_H__ #define _TD_SIM_H_
#include <semaphore.h> #include <semaphore.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -102,18 +102,18 @@ typedef struct _cmd_t { ...@@ -102,18 +102,18 @@ typedef struct _cmd_t {
int16_t cmdno; int16_t cmdno;
int16_t nlen; int16_t nlen;
char name[MAX_SIM_CMD_NAME_LEN]; char name[MAX_SIM_CMD_NAME_LEN];
bool (*parseCmd)(char *, struct _cmd_t *, int32_t); bool (*parseCmd)(char *, struct _cmd_t *, int32_t);
bool (*executeCmd)(struct _script_t *script, char *option); bool (*executeCmd)(struct _script_t *script, char *option);
struct _cmd_t *next; struct _cmd_t *next;
} SCommand; } SCommand;
typedef struct { typedef struct {
int16_t cmdno; int16_t cmdno;
int16_t jump; // jump position int16_t jump; // jump position
int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */ // will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t lineNum; // correspodning line number in original file int16_t lineNum; // correspodning line number in original file
int32_t optionOffset;// relative option offset int32_t optionOffset; // relative option offset
} SCmdLine; } SCmdLine;
typedef struct _var_t { typedef struct _var_t {
...@@ -123,24 +123,24 @@ typedef struct _var_t { ...@@ -123,24 +123,24 @@ typedef struct _var_t {
} SVariable; } SVariable;
typedef struct _script_t { typedef struct _script_t {
int32_t type; int32_t type;
bool killed; bool killed;
void * taos; void *taos;
char rows[12]; // number of rows data retrieved char rows[12]; // number of rows data retrieved
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
char system_exit_code[12]; char system_exit_code[12];
char system_ret_content[MAX_SYSTEM_RESULT_LEN]; char system_ret_content[MAX_SYSTEM_RESULT_LEN];
int32_t varLen; int32_t varLen;
int32_t linePos; // current cmd position int32_t linePos; // current cmd position
int32_t numOfLines; // number of lines in the script int32_t numOfLines; // number of lines in the script
int32_t bgScriptLen; int32_t bgScriptLen;
char fileName[MAX_FILE_NAME_LEN]; // script file name char fileName[MAX_FILE_NAME_LEN]; // script file name
char error[MAX_ERROR_LEN]; char error[MAX_ERROR_LEN];
char * optionBuffer; char *optionBuffer;
SCmdLine *lines; // command list SCmdLine *lines; // command list
SVariable variables[MAX_VAR_LEN]; SVariable variables[MAX_VAR_LEN];
pthread_t bgPid; pthread_t bgPid;
char auth[128]; char auth[128];
struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM]; struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM];
} SScript; } SScript;
...@@ -150,16 +150,15 @@ extern int32_t simScriptPos; ...@@ -150,16 +150,15 @@ extern int32_t simScriptPos;
extern int32_t simScriptSucced; extern int32_t simScriptSucced;
extern int32_t simDebugFlag; extern int32_t simDebugFlag;
extern char tsScriptDir[]; extern char tsScriptDir[];
extern bool simAsyncQuery;
extern bool abortExecution; extern bool abortExecution;
SScript *simParseScript(char *fileName); SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script); SScript *simProcessCallOver(SScript *script);
void * simExecuteScript(void *script); void *simExecuteScript(void *script);
void simInitsimCmdList(); void simInitsimCmdList();
bool simSystemInit(); bool simSystemInit();
void simSystemCleanUp(); void simSystemCleanUp();
char * simGetVariable(SScript *script, char *varName, int32_t varLen); char *simGetVariable(SScript *script, char *varName, int32_t varLen);
bool simExecuteExpCmd(SScript *script, char *option); bool simExecuteExpCmd(SScript *script, char *option);
bool simExecuteTestCmd(SScript *script, char *option); bool simExecuteTestCmd(SScript *script, char *option);
bool simExecuteGotoCmd(SScript *script, char *option); bool simExecuteGotoCmd(SScript *script, char *option);
...@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option); ...@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option);
bool simExecuteLineInsertErrorCmd(SScript *script, char *option); bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
void simVisuallizeOption(SScript *script, char *src, char *dst); void simVisuallizeOption(SScript *script, char *src, char *dst);
#endif #endif /*_TD_SIM_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SIM_PARSE_H__ #ifndef _TD_SIM_PARSE_H_
#define __SIM_PARSE_H__ #define _TD_SIM_PARSE_H_
#define MAX_NUM_CMD 64 #define MAX_NUM_CMD 64
#define MAX_NUM_LABLES 100 #define MAX_NUM_LABLES 100
...@@ -40,10 +40,10 @@ typedef struct { ...@@ -40,10 +40,10 @@ typedef struct {
/* block definition */ /* block definition */
typedef struct { typedef struct {
char top; /* the number of blocks stacked */ char top; /* the number of blocks stacked */
char type[MAX_NUM_BLOCK]; /* the block type */ char type[MAX_NUM_BLOCK]; /* the block type */
int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */ int16_t *pos[MAX_NUM_BLOCK]; /* position of the jump for if/elif/case */
int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */ int16_t back[MAX_NUM_BLOCK]; /* go back, endw and continue */
char numJump[MAX_NUM_BLOCK]; char numJump[MAX_NUM_BLOCK];
int16_t *jump[MAX_NUM_BLOCK][MAX_NUM_JUMP]; /* break or elif */ int16_t *jump[MAX_NUM_BLOCK][MAX_NUM_JUMP]; /* break or elif */
char sexp[MAX_NUM_BLOCK][40]; /*switch expression */ char sexp[MAX_NUM_BLOCK][40]; /*switch expression */
...@@ -52,4 +52,4 @@ typedef struct { ...@@ -52,4 +52,4 @@ typedef struct {
bool simParseExpression(char *token, int32_t lineNum); bool simParseExpression(char *token, int32_t lineNum);
#endif #endif /*_TD_SIM_PARSE_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -14,18 +14,18 @@ ...@@ -14,18 +14,18 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "cJSON.h" #include "cJSON.h"
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "taos.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "ttypes.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK
void simLogSql(char *sql, bool useSharp) { void simLogSql(char *sql, bool useSharp) {
static FILE *fp = NULL; static FILE *fp = NULL;
char filename[256]; char filename[256];
sprintf(filename, "%s/sim.sql", tsScriptDir); sprintf(filename, "%s/sim.sql", tsScriptDir);
if (fp == NULL) { if (fp == NULL) {
fp = fopen(filename, "w"); fp = fopen(filename, "w");
...@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null"; return "null";
} }
char * keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
paGetToken(varName + 6, &keyName, &keyLen); paGetToken(varName + 6, &keyName, &keyLen);
...@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null"; return "null";
} }
char * keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
paGetToken(varName + 7, &keyName, &keyLen); paGetToken(varName + 7, &keyName, &keyLen);
...@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} }
int32_t simExecuteExpression(SScript *script, char *exp) { int32_t simExecuteExpression(SScript *script, char *exp) {
char * op1, *op2, *var1, *var2, *var3, *rest; char *op1, *op2, *var1, *var2, *var3, *rest;
int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1; int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
char t0[1024], t1[1024], t2[1024], t3[2048]; char t0[1024], t1[1024], t2[1024], t3[2048];
int32_t result; int32_t result;
...@@ -302,10 +302,10 @@ bool simExecuteRunBackCmd(SScript *script, char *option) { ...@@ -302,10 +302,10 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
} }
void simReplaceShToBat(char *dst) { void simReplaceShToBat(char *dst) {
char* sh = strstr(dst, ".sh"); char *sh = strstr(dst, ".sh");
if (sh != NULL) { if (sh != NULL) {
int32_t dstLen = (int32_t)strlen(dst); int32_t dstLen = (int32_t)strlen(dst);
char *end = dst + dstLen; char *end = dst + dstLen;
*(end + 1) = 0; *(end + 1) = 0;
for (char *p = end; p >= sh; p--) { for (char *p = end; p >= sh; p--) {
...@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) { ...@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
} }
void simVisuallizeOption(SScript *script, char *src, char *dst) { void simVisuallizeOption(SScript *script, char *src, char *dst) {
char * var, *token, *value; char *var, *token, *value;
int32_t dstLen, srcLen, tokenLen; int32_t dstLen, srcLen, tokenLen;
dst[0] = 0, dstLen = 0; dst[0] = 0, dstLen = 0;
...@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { ...@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
strcpy(dst + dstLen, src); strcpy(dst + dstLen, src);
} }
void simCloseRestFulConnect(SScript *script) {
memset(script->auth, 0, sizeof(script->auth));
}
void simCloseNativeConnect(SScript *script) { void simCloseNativeConnect(SScript *script) {
if (script->taos == NULL) return; if (script->taos == NULL) return;
...@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) { ...@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) {
script->taos = NULL; script->taos = NULL;
} }
void simCloseTaosdConnect(SScript *script) { void simCloseTaosdConnect(SScript *script) { simCloseNativeConnect(script); }
if (simAsyncQuery) {
simCloseRestFulConnect(script);
} else {
simCloseNativeConnect(script);
}
}
// {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}
// {"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}
// {"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}
int32_t simParseHttpCommandResult(SScript *script, char *command) {
cJSON* root = cJSON_Parse(command);
if (root == NULL) {
simError("script:%s, failed to parse json, response:%s", script->fileName, command);
return -1;
}
cJSON *status = cJSON_GetObjectItem(root, "status");
if (status == NULL) {
simError("script:%s, failed to parse json, status is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
if (status->valuestring == NULL || strlen(status->valuestring) == 0) {
simError("script:%s, failed to parse json, status value is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
if (strcmp(status->valuestring, "succ") != 0) {
cJSON *code = cJSON_GetObjectItem(root, "code");
if (code == NULL) {
simError("script:%s, failed to parse json, code is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
int32_t retcode = (int32_t)code->valueint;
if (retcode != 1017) {
simError("script:%s, json:status:%s not equal to succ, response:%s", script->fileName, status->valuestring,
command);
cJSON_Delete(root);
return retcode;
} else {
simDebug("script:%s, json:status:%s not equal to succ, but code is %d, response:%s", script->fileName,
status->valuestring, retcode, command);
cJSON_Delete(root);
return 0;
}
}
cJSON *desc = cJSON_GetObjectItem(root, "desc");
if (desc != NULL) {
if (desc->valuestring == NULL || strlen(desc->valuestring) == 0) {
simError("script:%s, failed to parse json, desc value is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
strcpy(script->auth, desc->valuestring);
cJSON_Delete(root);
return 0;
}
cJSON *data = cJSON_GetObjectItem(root, "data");
if (data == NULL) {
simError("script:%s, failed to parse json, data is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
int32_t rowsize = cJSON_GetArraySize(data);
if (rowsize < 0) {
simError("script:%s, failed to parse json:data, data size %d, response:%s", script->fileName, rowsize, command);
cJSON_Delete(root);
return -1;
}
int32_t rowIndex = 0;
sprintf(script->rows, "%d", rowsize);
for (int32_t r = 0; r < rowsize; ++r) {
cJSON *row = cJSON_GetArrayItem(data, r);
if (row == NULL) continue;
if (rowIndex++ >= 10) break;
int32_t colsize = cJSON_GetArraySize(row);
if (colsize < 0) {
break;
}
colsize = MIN(10, colsize);
for (int32_t c = 0; c < colsize; ++c) {
cJSON *col = cJSON_GetArrayItem(row, c);
if (col->valuestring != NULL) {
strcpy(script->data[r][c], col->valuestring);
} else {
if (col->numberstring[0] == 0) {
strcpy(script->data[r][c], "null");
} else {
strcpy(script->data[r][c], col->numberstring);
}
}
}
}
return 0;
}
int32_t simExecuteRestFulCommand(SScript *script, char *command) {
char buf[5000] = {0};
sprintf(buf, "%s 2>/dev/null", command);
FILE *fp = popen(buf, "r");
if (fp == NULL) {
simError("failed to execute %s", buf);
return -1;
}
int32_t mallocSize = 2000;
int32_t alreadyReadSize = 0;
char * content = malloc(mallocSize);
while (!feof(fp)) {
int32_t availSize = mallocSize - alreadyReadSize;
int32_t len = (int32_t)fread(content + alreadyReadSize, 1, availSize, fp);
if (len >= availSize) {
alreadyReadSize += len;
mallocSize *= 2;
content = realloc(content, mallocSize);
}
}
pclose(fp);
return simParseHttpCommandResult(script, content);
}
bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
char command[4096];
sprintf(command, "curl 127.0.0.1:6041/rest/login/%s/%s", user, pass);
bool success = false;
for (int32_t attempt = 0; attempt < 10; ++attempt) {
success = simExecuteRestFulCommand(script, command) == 0;
if (!success) {
simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
attempt);
taosMsleep(1000);
} else {
simDebug("script:%s, user:%s connect taosd successed, attempt:%d", script->fileName, user, attempt);
break;
}
}
if (!success) {
sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum,
taos_errstr(NULL));
return false;
}
simDebug("script:%s, connect taosd successed, auth:%p", script->fileName, script->auth);
return true;
}
bool simCreateNativeConnect(SScript *script, char *user, char *pass) { bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect(script); simCloseTaosdConnect(script);
...@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) { ...@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
return false; return false;
} }
taos = taos_connect(NULL, user, pass, NULL, tsDnodeShellPort); taos = taos_connect(NULL, user, pass, NULL, 0);
if (taos == NULL) { if (taos == NULL) {
simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL), simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
attempt); attempt);
...@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) { ...@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
} }
bool simCreateTaosdConnect(SScript *script, char *rest) { bool simCreateTaosdConnect(SScript *script, char *rest) {
char * user = TSDB_DEFAULT_USER; char *user = TSDB_DEFAULT_USER;
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) { ...@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
user = token; user = token;
} }
if (simAsyncQuery) { return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS);
return simCreateRestFulConnect(script, user, TSDB_DEFAULT_PASS);
} else {
return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS);
}
} }
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
char timeStr[30] = {0}; char timeStr[30] = {0};
time_t tt; time_t tt;
struct tm *tp; struct tm *tp;
SCmdLine * line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
int32_t ret = -1; int32_t ret = -1;
TAOS_RES *pSql = NULL; TAOS_RES *pSql = NULL;
...@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
pSql = taos_query(script->taos, rest); pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql); ret = taos_errno(pSql);
if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { if (ret == TSDB_CODE_MND_STB_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF, simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
tstrerror(ret)); tstrerror(ret));
ret = 0; ret = 0;
...@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
while ((row = taos_fetch_row(pSql))) { while ((row = taos_fetch_row(pSql))) {
if (numOfRows < MAX_QUERY_ROW_NUM) { if (numOfRows < MAX_QUERY_ROW_NUM) {
TAOS_FIELD *fields = taos_fetch_fields(pSql); TAOS_FIELD *fields = taos_fetch_fields(pSql);
int32_t * length = taos_fetch_lengths(pSql); int32_t *length = taos_fetch_lengths(pSql);
for (int32_t i = 0; i < num_fields; i++) { for (int32_t i = 0; i < num_fields; i++) {
char *value = NULL; char *value = NULL;
...@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
sprintf(value, "%d", *((int8_t *)row[i])); sprintf(value, "%d", *((int8_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
sprintf(value, "%u", *((uint8_t*)row[i])); sprintf(value, "%u", *((uint8_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
sprintf(value, "%d", *((int16_t *)row[i])); sprintf(value, "%d", *((int16_t *)row[i]));
...@@ -846,7 +677,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -846,7 +677,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
} else if (precision == TSDB_TIME_PRECISION_MICRO) { } else if (precision == TSDB_TIME_PRECISION_MICRO) {
sprintf(value, "%s.%06d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000)); sprintf(value, "%s.%06d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000));
} else { } else {
sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000)); sprintf(value, "%s.%09d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000000000));
} }
break; break;
...@@ -877,43 +708,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -877,43 +708,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
bool simExecuteRestFulSqlCommand(SScript *script, char *rest) {
SCmdLine *line = &script->lines[script->linePos];
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d \"%s\" 127.0.0.1:6041/rest/sql", script->auth, rest);
int32_t ret = -1;
for (int32_t attempt = 0; attempt < 10; ++attempt) {
ret = simExecuteRestFulCommand(script, command);
if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
tstrerror(ret));
ret = 0;
break;
} else if (ret != 0) {
simDebug("script:%s, taos:%p, %s failed, ret:%d", script->fileName, script->taos, rest, ret);
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
return true;
}
taosMsleep(1000);
} else {
break;
}
}
if (ret) {
sprintf(script->error, "lineNum:%d. sql:%s failed, ret:%d", line->lineNum, rest, ret);
return false;
}
script->linePos++;
return true;
}
bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
char buf[3000]; char buf[3000];
SCmdLine *line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf); simVisuallizeOption(script, rest, buf);
...@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { ...@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) { if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) { if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) { if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump; script->linePos = line->jump;
...@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { ...@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
if (simAsyncQuery) { return simExecuteNativeSqlCommand(script, rest, isSlow);
return simExecuteRestFulSqlCommand(script, rest);
} else {
return simExecuteNativeSqlCommand(script, rest, isSlow);
}
} }
bool simExecuteSqlCmd(SScript *script, char *rest) { bool simExecuteSqlCmd(SScript *script, char *rest) {
...@@ -1010,7 +802,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) { ...@@ -1010,7 +802,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) {
} }
bool simExecuteSqlErrorCmd(SScript *script, char *rest) { bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
char buf[3000]; char buf[3000];
SCmdLine *line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
simVisuallizeOption(script, rest, buf); simVisuallizeOption(script, rest, buf);
...@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { ...@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true; return true;
} }
if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) { if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) { if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) { if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump; script->linePos = line->jump;
...@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { ...@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true; return true;
} }
int32_t ret; TAOS_RES *pSql = pSql = taos_query(script->taos, rest);
TAOS_RES *pSql = NULL; int32_t ret = taos_errno(pSql);
if (simAsyncQuery) { taos_free_result(pSql);
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d '%s' 127.0.0.1:6041/rest/sql", script->auth, rest);
ret = simExecuteRestFulCommand(script, command);
} else {
pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql);
taos_free_result(pSql);
}
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos, simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos,
...@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) { ...@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest); simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true); simLogSql(buf, true);
char * lines[] = {rest}; char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1); int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t ret = 0;
#endif
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s executed. success.", script->fileName, script->taos, rest); simDebug("script:%s, taos:%p, %s executed. success.", script->fileName, script->taos, rest);
script->linePos++; script->linePos++;
return true; return true;
} else { } else {
sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF,
ret & 0XFFFF, tstrerror(ret)); tstrerror(ret));
return false; return false;
} }
} }
...@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) { ...@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest); simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true); simLogSql(buf, true);
char * lines[] = {rest}; char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1); int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t ret = 0;
#endif
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName, script->taos, rest); sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName,
script->taos, rest);
script->linePos++; script->linePos++;
return false; return false;
} else { } else {
simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, ret & 0XFFFF,
ret & 0XFFFF, tstrerror(ret)); tstrerror(ret));
return true; return true;
} }
} }
...@@ -15,19 +15,17 @@ ...@@ -15,19 +15,17 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "sim.h" #include "sim.h"
#undef TAOS_MEM_CHECK #include "tglobal.h"
bool simAsyncQuery = false;
bool simExecSuccess = false; bool simExecSuccess = false;
bool abortExecution = false; bool abortExecution = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) { void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp(); simSystemCleanUp();
abortExecution = true; abortExecution = true;
// runningScript->killed = true; // runningScript->killed = true;
// exit(1); // exit(1);
} }
int32_t main(int32_t argc, char *argv[]) { int32_t main(int32_t argc, char *argv[]) {
...@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) { ...@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) {
tstrncpy(configDir, argv[++i], 128); tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
strcpy(scriptFile, argv[++i]); strcpy(scriptFile, argv[++i]);
} else if (strcmp(argv[i], "-a") == 0) {
simAsyncQuery = true;
} else { } else {
printf("usage: %s [options] \n", argv[0]); printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", configDir); printf(" [-c config]: config directory, default is: %s\n", configDir);
......
...@@ -60,9 +60,9 @@ ...@@ -60,9 +60,9 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "simParse.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK
#include "simParse.h"
static SCommand *cmdHashList[MAX_NUM_CMD]; static SCommand *cmdHashList[MAX_NUM_CMD];
static SCmdLine cmdLine[MAX_CMD_LINES]; static SCmdLine cmdLine[MAX_CMD_LINES];
...@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) { ...@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
} }
SScript *simParseScript(char *fileName) { SScript *simParseScript(char *fileName) {
FILE * fd; FILE *fd;
int32_t tokenLen, lineNum = 0; int32_t tokenLen, lineNum = 0;
char buffer[MAX_LINE_LEN], name[128], *token, *rest; char buffer[MAX_LINE_LEN], name[128], *token, *rest;
SCommand *pCmd; SCommand *pCmd;
SScript * script; SScript *script;
if ((fileName[0] == '.') || (fileName[0] == '/')) { if ((fileName[0] == '.') || (fileName[0] == '/')) {
strcpy(name, fileName); strcpy(name, fileName);
...@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) { ...@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) {
} }
int32_t simCheckExpression(char *exp) { int32_t simCheckExpression(char *exp) {
char * op1, *op2, *op, *rest; char *op1, *op2, *op, *rest;
int32_t op1Len, op2Len, opLen; int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len); rest = paGetToken(exp, &op1, &op1Len);
...@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) { ...@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) {
} }
bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * ret; char *ret;
int32_t expLen; int32_t expLen;
expLen = simCheckExpression(rest); expLen = simCheckExpression(rest);
...@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
void simCheckSqlOption(char *rest) { void simCheckSqlOption(char *rest) {
int32_t valueLen; int32_t valueLen;
char * value, *xpos; char *value, *xpos;
xpos = strstr(rest, " -x"); // need a blank xpos = strstr(rest, " -x"); // need a blank
if (xpos) { if (xpos) {
...@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP; cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
...@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN; cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
...@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true; return true;
} }
bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) { bool simParseLineInsertCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen; int32_t expLen;
rest++; rest++;
...@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) { ...@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
return true; return true;
} }
bool simParseLineInsertErrorCmd(char* rest, SCommand* pCmd, int32_t lineNum) { bool simParseLineInsertErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen; int32_t expLen;
rest++; rest++;
......
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "taos.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "tsocket.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK #include "tglobal.h"
#include "tconfig.h"
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
SCommand simCmdList[SIM_CMD_END]; SCommand simCmdList[SIM_CMD_END];
...@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) { ...@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) {
} }
bool simSystemInit() { bool simSystemInit() {
if (taos_init()) {
return false;
}
taosGetFqdn(simHostName); taosGetFqdn(simHostName);
taosInitGlobalCfg();
taosReadCfgFromFile();
simInitsimCmdList(); simInitsimCmdList();
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM); memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
return true; return true;
...@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) { ...@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) {
} }
} else { } else {
SCmdLine *line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
char * option = script->optionBuffer + line->optionOffset; char *option = script->optionBuffer + line->optionOffset;
simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option); simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
SCommand *cmd = &simCmdList[line->cmdno]; SCommand *cmd = &simCmdList[line->cmdno];
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __COMMAND_STRUCT__ #ifndef _TD_SHELL_COMMAND_H_
#define __COMMAND_STRUCT__ #define _TD_SHELL_COMMAND_H_
#include "shell.h" #include "shell.h"
......
...@@ -219,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -219,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse(&argp, argc, argv, 0, 0, arguments); argp_parse(&argp, argc, argv, 0, 0, arguments);
if (arguments->abort) { if (arguments->abort) {
#ifndef _ALPINE #ifndef _ALPINE
#if 0
error(10, 0, "ABORTED"); error(10, 0, "ABORTED");
#endif
#else #else
abort(); abort();
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册