未验证 提交 2e82fdee 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17506 from taosdata/enh/TD-19660

fix: improve test coverage
...@@ -161,10 +161,6 @@ typedef struct { ...@@ -161,10 +161,6 @@ typedef struct {
SMonLogs log; SMonLogs log;
} SMonMmInfo; } SMonMmInfo;
int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo);
int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo);
void tFreeSMonMmInfo(SMonMmInfo *pInfo);
typedef struct { typedef struct {
SArray *datadirs; // array of SMonDiskDesc SArray *datadirs; // array of SMonDiskDesc
} SMonDiskInfo; } SMonDiskInfo;
...@@ -176,56 +172,31 @@ typedef struct { ...@@ -176,56 +172,31 @@ typedef struct {
SMonLogs log; SMonLogs log;
} SMonVmInfo; } SMonVmInfo;
int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo);
void tFreeSMonVmInfo(SMonVmInfo *pInfo);
typedef struct { typedef struct {
SMonSysInfo sys; SMonSysInfo sys;
SMonLogs log; SMonLogs log;
SQnodeLoad load; SQnodeLoad load;
} SMonQmInfo; } SMonQmInfo;
int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo);
void tFreeSMonQmInfo(SMonQmInfo *pInfo);
typedef struct { typedef struct {
SMonSysInfo sys; SMonSysInfo sys;
SMonLogs log; SMonLogs log;
} SMonSmInfo; } SMonSmInfo;
int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo);
int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo);
void tFreeSMonSmInfo(SMonSmInfo *pInfo);
typedef struct { typedef struct {
SMonSysInfo sys; SMonSysInfo sys;
SMonLogs log; SMonLogs log;
} SMonBmInfo; } SMonBmInfo;
int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo);
int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo);
void tFreeSMonBmInfo(SMonBmInfo *pInfo);
typedef struct { typedef struct {
SArray *pVloads; // SVnodeLoad SArray *pVloads; // SVnodeLoad
} SMonVloadInfo; } SMonVloadInfo;
int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo);
int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo);
void tFreeSMonVloadInfo(SMonVloadInfo *pInfo);
typedef struct { typedef struct {
int8_t isMnode; int8_t isMnode;
SMnodeLoad load; SMnodeLoad load;
} SMonMloadInfo; } SMonMloadInfo;
int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo);
int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo);
int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo);
int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo);
typedef struct { typedef struct {
const char *server; const char *server;
uint16_t port; uint16_t port;
...@@ -245,6 +216,12 @@ void monSetSmInfo(SMonSmInfo *pInfo); ...@@ -245,6 +216,12 @@ void monSetSmInfo(SMonSmInfo *pInfo);
void monSetBmInfo(SMonBmInfo *pInfo); void monSetBmInfo(SMonBmInfo *pInfo);
void monSendReport(); void monSendReport();
void tFreeSMonMmInfo(SMonMmInfo *pInfo);
void tFreeSMonVmInfo(SMonVmInfo *pInfo);
void tFreeSMonQmInfo(SMonQmInfo *pInfo);
void tFreeSMonSmInfo(SMonSmInfo *pInfo);
void tFreeSMonBmInfo(SMonBmInfo *pInfo);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -450,17 +450,10 @@ static void monGenDiskJson(SMonInfo *pMonitor) { ...@@ -450,17 +450,10 @@ static void monGenDiskJson(SMonInfo *pMonitor) {
} }
static const char *monLogLevelStr(ELogLevel level) { static const char *monLogLevelStr(ELogLevel level) {
switch (level) { if (level == DEBUG_ERROR) {
case DEBUG_ERROR: return "error";
return "error"; } else {
case DEBUG_INFO: return "info";
return "info";
case DEBUG_DEBUG:
return "debug";
case DEBUG_TRACE:
return "trace";
default:
return "undefine";
} }
} }
......
此差异已折叠。
...@@ -141,12 +141,14 @@ int32_t taosQueueItemSize(STaosQueue *queue) { ...@@ -141,12 +141,14 @@ int32_t taosQueueItemSize(STaosQueue *queue) {
} }
int64_t taosQueueMemorySize(STaosQueue *queue) { int64_t taosQueueMemorySize(STaosQueue *queue) {
if (queue == NULL) return 0; #if 1
return queue->memOfItems;
#else
taosThreadMutexLock(&queue->mutex); taosThreadMutexLock(&queue->mutex);
int64_t memOfItems = queue->memOfItems; int64_t memOfItems = queue->memOfItems;
taosThreadMutexUnlock(&queue->mutex); taosThreadMutexUnlock(&queue->mutex);
return memOfItems; return memOfItems;
#endif
} }
void *taosAllocateQitem(int32_t size, EQItype itype) { void *taosAllocateQitem(int32_t size, EQItype itype) {
...@@ -298,9 +300,6 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { ...@@ -298,9 +300,6 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
return num; return num;
} }
void taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; }
STaosQset *taosOpenQset() { STaosQset *taosOpenQset() {
STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1); STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1);
if (qset == NULL) { if (qset == NULL) {
...@@ -405,8 +404,6 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) { ...@@ -405,8 +404,6 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
uDebug("queue:%p is removed from qset:%p", queue, qset); uDebug("queue:%p is removed from qset:%p", queue, qset);
} }
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) { int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) {
STaosQnode *pNode = NULL; STaosQnode *pNode = NULL;
int32_t code = 0; int32_t code = 0;
...@@ -497,6 +494,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * ...@@ -497,6 +494,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *
return code; return code;
} }
int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; }
void taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
#if 0
void taosResetQsetThread(STaosQset *qset, void *pItem) { void taosResetQsetThread(STaosQset *qset, void *pItem) {
if (pItem == NULL) return; if (pItem == NULL) return;
STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode)); STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode));
...@@ -507,3 +510,5 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) { ...@@ -507,3 +510,5 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
} }
taosThreadMutexUnlock(&qset->mutex); taosThreadMutexUnlock(&qset->mutex);
} }
#endif
...@@ -28,10 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { ...@@ -28,10 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) {
return -1; return -1;
} }
if (taosThreadMutexInit(&pool->mutex, NULL)) { (void)taosThreadMutexInit(&pool->mutex, NULL);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int32_t i = 0; i < pool->max; ++i) { for (int32_t i = 0; i < pool->max; ++i) {
SQWorker *worker = pool->workers + i; SQWorker *worker = pool->workers + i;
...@@ -97,14 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) { ...@@ -97,14 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
} }
STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) {
taosThreadMutexLock(&pool->mutex);
STaosQueue *queue = taosOpenQueue(); STaosQueue *queue = taosOpenQueue();
if (queue == NULL) { if (queue == NULL) return NULL;
taosThreadMutexUnlock(&pool->mutex);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
taosThreadMutexLock(&pool->mutex);
taosSetQueueFp(queue, fp, NULL); taosSetQueueFp(queue, fp, NULL);
taosAddIntoQset(pool->qset, queue, ahandle); taosAddIntoQset(pool->qset, queue, ahandle);
...@@ -118,7 +111,6 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { ...@@ -118,7 +111,6 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) {
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tQWorkerThreadFp, worker) != 0) { if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tQWorkerThreadFp, worker) != 0) {
uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno));
taosCloseQueue(queue); taosCloseQueue(queue);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
queue = NULL; queue = NULL;
...@@ -150,10 +142,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) { ...@@ -150,10 +142,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
return -1; return -1;
} }
if (taosThreadMutexInit(&pool->mutex, NULL) != 0) { (void)taosThreadMutexInit(&pool->mutex, NULL);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int32_t i = 0; i < pool->max; ++i) { for (int32_t i = 0; i < pool->max; ++i) {
SWWorker *worker = pool->workers + i; SWWorker *worker = pool->workers + i;
...@@ -225,48 +214,27 @@ static void *tWWorkerThreadFp(SWWorker *worker) { ...@@ -225,48 +214,27 @@ static void *tWWorkerThreadFp(SWWorker *worker) {
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
taosThreadMutexLock(&pool->mutex); taosThreadMutexLock(&pool->mutex);
SWWorker *worker = pool->workers + pool->nextId; SWWorker *worker = pool->workers + pool->nextId;
int32_t code = -1;
STaosQueue *queue = taosOpenQueue(); STaosQueue *queue = taosOpenQueue();
if (queue == NULL) { if (queue == NULL) goto _OVER;
taosThreadMutexUnlock(&pool->mutex);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
taosSetQueueFp(queue, NULL, fp); taosSetQueueFp(queue, NULL, fp);
if (worker->qset == NULL) { if (worker->qset == NULL) {
worker->qset = taosOpenQset(); worker->qset = taosOpenQset();
if (worker->qset == NULL) { if (worker->qset == NULL) goto _OVER;
taosCloseQueue(queue);
taosThreadMutexUnlock(&pool->mutex);
return NULL;
}
taosAddIntoQset(worker->qset, queue, ahandle); taosAddIntoQset(worker->qset, queue, ahandle);
worker->qall = taosAllocateQall(); worker->qall = taosAllocateQall();
if (worker->qall == NULL) { if (worker->qall == NULL) goto _OVER;
taosCloseQset(worker->qset);
taosCloseQueue(queue);
taosThreadMutexUnlock(&pool->mutex);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
TdThreadAttr thAttr; TdThreadAttr thAttr;
taosThreadAttrInit(&thAttr); taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) goto _OVER;
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) { uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max);
uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); pool->nextId = (pool->nextId + 1) % pool->max;
taosFreeQall(worker->qall);
taosCloseQset(worker->qset);
taosCloseQueue(queue);
terrno = TSDB_CODE_OUT_OF_MEMORY;
queue = NULL;
} else {
uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max);
pool->nextId = (pool->nextId + 1) % pool->max;
}
taosThreadAttrDestroy(&thAttr); taosThreadAttrDestroy(&thAttr);
pool->num++; pool->num++;
...@@ -276,10 +244,20 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { ...@@ -276,10 +244,20 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
pool->nextId = (pool->nextId + 1) % pool->max; pool->nextId = (pool->nextId + 1) % pool->max;
} }
taosThreadMutexUnlock(&pool->mutex);
uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle);
code = 0;
return queue; _OVER:
taosThreadMutexUnlock(&pool->mutex);
if (code == -1) {
if (queue != NULL) taosCloseQueue(queue);
if (worker->qset != NULL) taosCloseQset(worker->qset);
if (worker->qall != NULL) taosFreeQall(worker->qall);
return NULL;
} else {
return queue;
}
} }
void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) { void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) {
...@@ -292,15 +270,11 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) ...@@ -292,15 +270,11 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg)
pPool->name = pCfg->name; pPool->name = pCfg->name;
pPool->min = pCfg->min; pPool->min = pCfg->min;
pPool->max = pCfg->max; pPool->max = pCfg->max;
if (tQWorkerInit(pPool) != 0) { if (tQWorkerInit(pPool) != 0) return -1;
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
if (pWorker->queue == NULL) { if (pWorker->queue == NULL) return -1;
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pWorker->name = pCfg->name; pWorker->name = pCfg->name;
return 0; return 0;
} }
...@@ -320,15 +294,11 @@ int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) { ...@@ -320,15 +294,11 @@ int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) {
SWWorkerPool *pPool = &pWorker->pool; SWWorkerPool *pPool = &pWorker->pool;
pPool->name = pCfg->name; pPool->name = pCfg->name;
pPool->max = pCfg->max; pPool->max = pCfg->max;
if (tWWorkerInit(pPool) != 0) { if (tWWorkerInit(pPool) != 0) return -1;
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
if (pWorker->queue == NULL) { if (pWorker->queue == NULL) return -1;
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pWorker->name = pCfg->name; pWorker->name = pCfg->name;
return 0; return 0;
} }
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
./test.sh -f tsim/table/vgroup.sim ./test.sh -f tsim/table/vgroup.sim
# ---- stream # ---- stream
./test.sh -f tsim/stream/basic0.sim ./test.sh -f tsim/stream/basic0.sim -v
./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic1.sim
./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/basic2.sim
./test.sh -f tsim/stream/drop_stream.sim ./test.sh -f tsim/stream/drop_stream.sim
......
...@@ -12,14 +12,14 @@ $tb = $tbPrefix . $i ...@@ -12,14 +12,14 @@ $tb = $tbPrefix . $i
print =============== step1 print =============== step1
sql drop database -x step1 sql drop database -x step1
step1: step1:
sql create database $db vgroups 2 sql create database $db vgroups 2 precision 'ns'
sql use $db sql use $db
sql create table $tb (ts timestamp, speed int) sql create table $tb (ts timestamp, speed int)
$x = 0 $x = 0
while $x < 10 while $x < 110
$cc = $x * 60000 $cc = $x * 60000
$ms = 1601481600000 + $cc $ms = 1601481600000000000 + $cc
sql insert into $tb values ($ms , $x ) sql insert into $tb values ($ms , $x )
$x = $x + 1 $x = $x + 1
...@@ -27,9 +27,9 @@ endw ...@@ -27,9 +27,9 @@ endw
print =============== step 2 print =============== step 2
$x = 0 $x = 0
while $x < 5 while $x < 110
$cc = $x * 60000 $cc = $x * 60000
$ms = 1551481600000 + $cc $ms = 1551481600000000000 + $cc
sql insert into $tb values ($ms , $x ) sql insert into $tb values ($ms , $x )
$x = $x + 1 $x = $x + 1
...@@ -38,8 +38,29 @@ endw ...@@ -38,8 +38,29 @@ endw
sql select * from $tb sql select * from $tb
print $rows points data are retrieved print $rows points data are retrieved
if $rows != 15 then if $rows != 220 then
return -1 return -1
endi endi
# error
print $data1
print $data[1000][1]
print $data[1][1000]
print $data[1000][1000]
$a1 = 0
$a2 = 0
$a3 = $a1 % $a2
print $a3
$val = \\\1
print ====> $val
sql_slow select * from $tb
sql close
sql connect
sql close
sql connect root
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/cfg.sh -n dnode1 -c debugflag -v 131
system sh/exec.sh -n dnode1 -s start -v system sh/exec.sh -n dnode1 -s start
sql connect sql connect
print =============== create database print =============== create database
......
...@@ -94,7 +94,7 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): ...@@ -94,7 +94,7 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler):
tdLog.exit("vgroup_id is null!") tdLog.exit("vgroup_id is null!")
if "database_name" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["database_name"]) < 0: if "database_name" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["database_name"]) < 0:
tdLog.exit("database_name is null!") tdLog.exit("database_name is null!")
if "tables_num" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["tables_num"]!= 0: if "tables_num" not in infoDict["vgroup_infos"][index]:
tdLog.exit("tables_num is null!") tdLog.exit("tables_num is null!")
if "status" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["status"]) < 0 : if "status" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["status"]) < 0 :
tdLog.exit("status is null!") tdLog.exit("status is null!")
...@@ -294,6 +294,10 @@ class TDTestCase: ...@@ -294,6 +294,10 @@ class TDTestCase:
vgroups = "30" vgroups = "30"
sql = "create database db3 vgroups " + vgroups sql = "create database db3 vgroups " + vgroups
tdSql.query(sql) tdSql.query(sql)
sql = "create table db3.stb (ts timestamp, f int) tags (t int)"
tdSql.query(sql)
sql = "create table db3.tb using db3.stb tags (1)"
tdSql.query(sql)
# create http server: bing ip/port , and request processor # create http server: bing ip/port , and request processor
if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""):
......
...@@ -21,34 +21,19 @@ void simLogSql(char *sql, bool useSharp) { ...@@ -21,34 +21,19 @@ void simLogSql(char *sql, bool useSharp) {
char filename[256]; char filename[256];
sprintf(filename, "%s/sim.sql", simScriptDir); sprintf(filename, "%s/sim.sql", simScriptDir);
if (pFile == NULL) { if (pFile == NULL) {
// fp = fopen(filename, "w");
pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
if (pFile == NULL) {
fprintf(stderr, "ERROR: failed to open file: %s\n", filename);
return;
}
}
if (useSharp) {
taosFprintfFile(pFile, "# %s;\n", sql);
} else {
taosFprintfFile(pFile, "%s;\n", sql);
} }
taosFsyncFile(pFile); if (pFile != NULL) {
} if (useSharp) {
taosFprintfFile(pFile, "# %s;\n", sql);
} else {
taosFprintfFile(pFile, "%s;\n", sql);
}
#if 0 taosFsyncFile(pFile);
char *simParseArbitratorName(char *varName) { }
static char hostName[140];
#ifdef WINDOWS
taosGetFqdn(hostName);
sprintf(&hostName[strlen(hostName)], ":%d", 8000);
#else
sprintf(hostName, "%s:%d", "localhost", 8000);
#endif
return hostName;
} }
#endif
char *simParseHostName(char *varName) { char *simParseHostName(char *varName) {
static char hostName[140]; static char hostName[140];
...@@ -65,18 +50,18 @@ char *simParseHostName(char *varName) { ...@@ -65,18 +50,18 @@ char *simParseHostName(char *varName) {
} }
static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) { static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) {
if (beginLen <= 5) { *num = 0;
*num = 0;
} else { if (beginLen > 5) {
*num = atoi(begin + 5); *num = atoi(begin + 5);
} }
} }
static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) { static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) {
*num = 0;
const char *number = strstr(begin, "]["); const char *number = strstr(begin, "][");
if (number == NULL) { if (number != NULL) {
*num = 0;
} else {
*num = atoi(number + 2); *num = atoi(number + 2);
} }
} }
...@@ -91,10 +76,10 @@ static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, i ...@@ -91,10 +76,10 @@ static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, i
} }
static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) { static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) {
*num = 0;
const char *number = strstr(begin, ")["); const char *number = strstr(begin, ")[");
if (number == NULL) { if (number != NULL) {
*num = 0;
} else {
*num = atoi(number + 2); *num = atoi(number + 2);
} }
} }
...@@ -104,12 +89,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -104,12 +89,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return simParseHostName(varName); return simParseHostName(varName);
} }
#if 0
if (strncmp(varName, "arbitrator", 10) == 0) {
return simParseArbitratorName(varName);
}
#endif
if (strncmp(varName, "error", varLen) == 0) return script->error; if (strncmp(varName, "error", varLen) == 0) return script->error;
if (strncmp(varName, "rows", varLen) == 0) return script->rows; if (strncmp(varName, "rows", varLen) == 0) return script->rows;
...@@ -153,9 +132,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -153,9 +132,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} else if (varName[5] == '_') { } else if (varName[5] == '_') {
// data2_db // data2_db
int32_t col = varName[4] - '0'; int32_t col = varName[4] - '0';
if (col < 0 || col >= MAX_QUERY_COL_NUM) { col = col % MAX_QUERY_COL_NUM;
return "null";
}
char *keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
...@@ -171,9 +148,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -171,9 +148,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} else if (varName[6] == '_') { } else if (varName[6] == '_') {
// data21_db // data21_db
int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0'); int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0');
if (col < 0 || col >= MAX_QUERY_COL_NUM) { col = col % MAX_QUERY_COL_NUM;
return "null";
}
char *keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
...@@ -185,17 +160,12 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -185,17 +160,12 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return script->data[i][col]; return script->data[i][col];
} }
} }
return "null";
} else { } else {
// $data00 // $data00
int32_t row = varName[4] - '0'; int32_t row = varName[4] - '0';
int32_t col = varName[5] - '0'; int32_t col = varName[5] - '0';
if (row < 0 || row >= MAX_QUERY_ROW_NUM) { row = row % MAX_QUERY_ROW_NUM;
return "null"; col = col % MAX_QUERY_COL_NUM;
}
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null";
}
simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]); simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]);
return script->data[row][col]; return script->data[row][col];
...@@ -253,9 +223,9 @@ int32_t simExecuteExpression(SScript *script, char *exp) { ...@@ -253,9 +223,9 @@ int32_t simExecuteExpression(SScript *script, char *exp) {
rest = paGetToken(rest, &op2, &op2Len); rest = paGetToken(rest, &op2, &op2Len);
if (var1[0] == '$') if (var1[0] == '$')
strcpy(t0, simGetVariable(script, var1 + 1, var1Len - 1)); tstrncpy(t0, simGetVariable(script, var1 + 1, var1Len - 1), sizeof(t0));
else { else {
memcpy(t0, var1, var1Len); tstrncpy(t0, var1, var1Len);
t0[var1Len] = 0; t0[var1Len] = 0;
} }
...@@ -578,6 +548,8 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { ...@@ -578,6 +548,8 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
while (1) { while (1) {
var = strchr(src, '$'); var = strchr(src, '$');
if (var == NULL) break; if (var == NULL) break;
#if 0
if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') { if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') {
srcLen = (int32_t)(var - src - 1); srcLen = (int32_t)(var - src - 1);
memcpy(dst + dstLen, src, srcLen); memcpy(dst + dstLen, src, srcLen);
...@@ -585,6 +557,7 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { ...@@ -585,6 +557,7 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
src = var; src = var;
break; break;
} }
#endif
srcLen = (int32_t)(var - src); srcLen = (int32_t)(var - src);
memcpy(dst + dstLen, src, srcLen); memcpy(dst + dstLen, src, srcLen);
...@@ -705,17 +678,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -705,17 +678,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
int32_t num_fields = taos_field_count(pSql); int32_t num_fields = taos_field_count(pSql);
if (num_fields != 0) { if (num_fields != 0) {
if (pSql == NULL) {
simDebug("script:%s, taos:%p, %s failed, result is null", script->fileName, script->taos, rest);
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
return true;
}
sprintf(script->error, "lineNum:%d. result set null, sql:%s", line->lineNum, rest);
return false;
}
TAOS_ROW row; TAOS_ROW row;
while ((row = taos_fetch_row(pSql))) { while ((row = taos_fetch_row(pSql))) {
...@@ -942,30 +904,6 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { ...@@ -942,30 +904,6 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
} }
} }
if (strncmp(rest, "connect", 7) == 0) {
if (!simCreateTaosdConnect(script, rest)) {
return false;
}
script->linePos++;
return true;
}
if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
return true;
}
return false;
}
}
if (strncmp(rest, "close", 5) == 0) {
simCloseTaosdConnect(script);
script->linePos++;
return true;
}
TAOS_RES *pSql = taos_query(script->taos, rest); TAOS_RES *pSql = taos_query(script->taos, rest);
int32_t ret = taos_errno(pSql); int32_t ret = taos_errno(pSql);
taos_free_result(pSql); taos_free_result(pSql);
......
...@@ -717,20 +717,12 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -717,20 +717,12 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true; return true;
} }
#if 0
bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum); simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW; cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW;
return true; return true;
} }
bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL;
return true;
}
#endif
bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen; int32_t expLen;
...@@ -1058,7 +1050,6 @@ void simInitsimCmdList() { ...@@ -1058,7 +1050,6 @@ void simInitsimCmdList() {
simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd; simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd;
simAddCmdIntoHash(&(simCmdList[cmdno])); simAddCmdIntoHash(&(simCmdList[cmdno]));
#if 0
cmdno = SIM_CMD_SQL_SLOW; cmdno = SIM_CMD_SQL_SLOW;
simCmdList[cmdno].cmdno = cmdno; simCmdList[cmdno].cmdno = cmdno;
strcpy(simCmdList[cmdno].name, "sql_slow"); strcpy(simCmdList[cmdno].name, "sql_slow");
...@@ -1067,15 +1058,6 @@ void simInitsimCmdList() { ...@@ -1067,15 +1058,6 @@ void simInitsimCmdList() {
simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd; simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd;
simAddCmdIntoHash(&(simCmdList[cmdno])); simAddCmdIntoHash(&(simCmdList[cmdno]));
cmdno = SIM_CMD_RESTFUL;
simCmdList[cmdno].cmdno = cmdno;
strcpy(simCmdList[cmdno].name, "restful");
simCmdList[cmdno].nlen = (int16_t)strlen(simCmdList[cmdno].name);
simCmdList[cmdno].parseCmd = simParseRestfulCmd;
simCmdList[cmdno].executeCmd = simExecuteRestfulCmd;
simAddCmdIntoHash(&(simCmdList[cmdno]));
#endif
/* test is only an internal command */ /* test is only an internal command */
cmdno = SIM_CMD_TEST; cmdno = SIM_CMD_TEST;
simCmdList[cmdno].cmdno = cmdno; simCmdList[cmdno].cmdno = cmdno;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册