Merge branch '3.0' of https://github.com/taosdata/TDengine into fix/TD-30967
This commit is contained in:
commit
29381075c5
|
@ -132,16 +132,16 @@
|
|||
#define TK_TABLE 114
|
||||
#define TK_NK_LP 115
|
||||
#define TK_NK_RP 116
|
||||
#define TK_STABLE 117
|
||||
#define TK_COLUMN 118
|
||||
#define TK_MODIFY 119
|
||||
#define TK_RENAME 120
|
||||
#define TK_TAG 121
|
||||
#define TK_SET 122
|
||||
#define TK_NK_EQ 123
|
||||
#define TK_USING 124
|
||||
#define TK_TAGS 125
|
||||
#define TK_FILE 126
|
||||
#define TK_USING 117
|
||||
#define TK_FILE 118
|
||||
#define TK_STABLE 119
|
||||
#define TK_COLUMN 120
|
||||
#define TK_MODIFY 121
|
||||
#define TK_RENAME 122
|
||||
#define TK_TAG 123
|
||||
#define TK_SET 124
|
||||
#define TK_NK_EQ 125
|
||||
#define TK_TAGS 126
|
||||
#define TK_BOOL 127
|
||||
#define TK_TINYINT 128
|
||||
#define TK_SMALLINT 129
|
||||
|
|
|
@ -152,7 +152,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
* @return
|
||||
*/
|
||||
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion,
|
||||
int32_t* tversion, int32_t idx);
|
||||
int32_t* tversion, int32_t idx, bool* tbGet);
|
||||
|
||||
/**
|
||||
* The main task execution function, including query on both table and multiple tables,
|
||||
|
|
|
@ -221,9 +221,6 @@ typedef struct SCreateSubTableFromFileClause {
|
|||
bool ignoreExists;
|
||||
SNodeList* pSpecificTags;
|
||||
char filePath[PATH_MAX];
|
||||
TdFilePtr fp;
|
||||
SArray* aCreateTbData;
|
||||
SArray* aTagIndexs;
|
||||
} SCreateSubTableFromFileClause;
|
||||
|
||||
typedef struct SCreateMultiTablesStmt {
|
||||
|
|
|
@ -233,7 +233,7 @@ typedef struct SViewNode {
|
|||
#define IS_WINDOW_JOIN(_stype) ((_stype) == JOIN_STYPE_WIN)
|
||||
#define IS_ASOF_JOIN(_stype) ((_stype) == JOIN_STYPE_ASOF)
|
||||
|
||||
typedef enum EJoinType {
|
||||
typedef enum EJoinType {
|
||||
JOIN_TYPE_INNER = 0,
|
||||
JOIN_TYPE_LEFT,
|
||||
JOIN_TYPE_RIGHT,
|
||||
|
@ -251,7 +251,7 @@ typedef enum EJoinSubType {
|
|||
JOIN_STYPE_MAX_VALUE
|
||||
} EJoinSubType;
|
||||
|
||||
typedef enum EJoinAlgorithm {
|
||||
typedef enum EJoinAlgorithm {
|
||||
JOIN_ALGO_UNKNOWN = 0,
|
||||
JOIN_ALGO_MERGE,
|
||||
JOIN_ALGO_HASH,
|
||||
|
@ -454,7 +454,7 @@ typedef struct SSetOperator {
|
|||
SNode* pLimit;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
ETimeLineMode timeLineResMode;
|
||||
ETimeLineMode timeLineResMode;
|
||||
bool timeLineFromOrderBy;
|
||||
bool joinContains;
|
||||
} SSetOperator;
|
||||
|
@ -504,6 +504,10 @@ typedef void (*FFreeTableBlockHash)(SHashObj*);
|
|||
typedef void (*FFreeVgourpBlockArray)(SArray*);
|
||||
struct SStbRowsDataContext;
|
||||
typedef void (*FFreeStbRowsDataContext)(struct SStbRowsDataContext*);
|
||||
struct SCreateTbInfo;
|
||||
struct SParseFileContext;
|
||||
typedef void (*FDestroyParseFileContext)(struct SParseFileContext**);
|
||||
|
||||
typedef struct SVnodeModifyOpStmt {
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
|
@ -524,7 +528,7 @@ typedef struct SVnodeModifyOpStmt {
|
|||
SHashObj* pTableNameHashObj; // set of table names for refreshing meta, sync mode
|
||||
SHashObj* pDbFNameHashObj; // set of db names for refreshing meta, sync mode
|
||||
SHashObj* pTableCxtHashObj; // temp SHashObj<tuid, STableDataCxt*> for single request
|
||||
SArray* pVgDataBlocks; // SArray<SVgroupDataCxt*>
|
||||
SArray* pVgDataBlocks; // SArray<SVgroupDataCxt*>
|
||||
SVCreateTbReq* pCreateTblReq;
|
||||
TdFilePtr fp;
|
||||
FFreeTableBlockHash freeHashFunc;
|
||||
|
@ -532,9 +536,13 @@ typedef struct SVnodeModifyOpStmt {
|
|||
bool usingTableProcessing;
|
||||
bool fileProcessing;
|
||||
|
||||
bool stbSyntax;
|
||||
struct SStbRowsDataContext* pStbRowsCxt;
|
||||
bool stbSyntax;
|
||||
struct SStbRowsDataContext* pStbRowsCxt;
|
||||
FFreeStbRowsDataContext freeStbRowsCxtFunc;
|
||||
|
||||
struct SCreateTbInfo* pCreateTbInfo;
|
||||
struct SParseFileContext* pParFileCxt;
|
||||
FDestroyParseFileContext destroyParseFileCxt;
|
||||
} SVnodeModifyOpStmt;
|
||||
|
||||
typedef struct SExplainOptions {
|
||||
|
@ -602,7 +610,7 @@ typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, C
|
|||
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
|
||||
SNodeList** pCols);
|
||||
int32_t nodesCollectColumnsExt(SSelectStmt* pSelect, ESqlClause clause, SSHashObj* pMultiTableAlias, ECollectColType type,
|
||||
SNodeList** pCols);
|
||||
SNodeList** pCols);
|
||||
int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols);
|
||||
|
||||
typedef bool (*FFuncClassifier)(int32_t funcId);
|
||||
|
@ -618,6 +626,7 @@ bool nodesIsArithmeticOp(const SOperatorNode* pOp);
|
|||
bool nodesIsComparisonOp(const SOperatorNode* pOp);
|
||||
bool nodesIsJsonOp(const SOperatorNode* pOp);
|
||||
bool nodesIsRegularOp(const SOperatorNode* pOp);
|
||||
bool nodesIsMatchRegularOp(const SOperatorNode* pOp);
|
||||
bool nodesIsBitwiseOp(const SOperatorNode* pOp);
|
||||
|
||||
bool nodesExprHasColumn(SNode* pNode);
|
||||
|
|
|
@ -28,6 +28,11 @@ typedef enum { HTTP_GZIP, HTTP_FLAT } EHttpCompFlag;
|
|||
int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag);
|
||||
|
||||
int64_t taosInitHttpChan();
|
||||
int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag, int64_t chanId);
|
||||
void taosDestroyHttpChan(int64_t chanId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -89,6 +89,7 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_RPC_MAX_SESSIONS TAOS_DEF_ERROR_CODE(0, 0x0022) //
|
||||
#define TSDB_CODE_RPC_NETWORK_ERROR TAOS_DEF_ERROR_CODE(0, 0x0023)
|
||||
#define TSDB_CODE_RPC_NETWORK_BUSY TAOS_DEF_ERROR_CODE(0, 0x0024)
|
||||
#define TSDB_CODE_HTTP_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0025)
|
||||
|
||||
|
||||
|
||||
|
@ -836,6 +837,7 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_PAR_TBNAME_DUPLICATED TAOS_DEF_ERROR_CODE(0, 0x267E)
|
||||
#define TSDB_CODE_PAR_TAG_NAME_DUPLICATED TAOS_DEF_ERROR_CODE(0, 0x267F)
|
||||
#define TSDB_CODE_PAR_NOT_ALLOWED_DIFFERENT_BY_ROW_FUNC TAOS_DEF_ERROR_CODE(0, 0x2680)
|
||||
#define TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2681)
|
||||
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF)
|
||||
|
||||
//planner
|
||||
|
|
|
@ -205,7 +205,7 @@ void taosArrayClearEx(SArray* pArray, void (*fp)(void*));
|
|||
|
||||
void taosArrayClearP(SArray* pArray, void (*fp)(void*));
|
||||
|
||||
void* taosArrayDestroy(SArray* pArray);
|
||||
void taosArrayDestroy(SArray* pArray);
|
||||
|
||||
void taosArrayDestroyP(SArray* pArray, FDelete fp);
|
||||
|
||||
|
|
|
@ -45,7 +45,10 @@ typedef struct SPatternCompareInfo {
|
|||
TdUcs4 umatchOne; // unicode version matchOne
|
||||
} SPatternCompareInfo;
|
||||
|
||||
int32_t InitRegexCache();
|
||||
void DestroyRegexCache();
|
||||
int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
int32_t checkRegexPattern(const char *pPattern);
|
||||
|
||||
int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
|
||||
|
@ -83,7 +86,6 @@ int32_t compareLenBinaryVal(const void *pLeft, const void *pRight);
|
|||
|
||||
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight);
|
||||
void DestoryThreadLocalRegComp();
|
||||
|
||||
int32_t comparewcsRegexMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparewcsRegexNMatch(const void *pLeft, const void *pRight);
|
||||
|
|
|
@ -57,7 +57,7 @@ void taosIpPort2String(uint32_t ip, uint16_t port, char *str);
|
|||
|
||||
void *tmemmem(const char *haystack, int hlen, const char *needle, int nlen);
|
||||
|
||||
int32_t parseCfgReal(const char* str, double* out);
|
||||
int32_t parseCfgReal(const char *str, double *out);
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
|
||||
T_MD5_CTX context;
|
||||
|
@ -85,9 +85,9 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
|
|||
static FORCE_INLINE int32_t taosCreateMD5Hash(char *pBuf, int32_t len) {
|
||||
T_MD5_CTX ctx;
|
||||
tMD5Init(&ctx);
|
||||
tMD5Update(&ctx, (uint8_t*)pBuf, len);
|
||||
tMD5Update(&ctx, (uint8_t *)pBuf, len);
|
||||
tMD5Final(&ctx);
|
||||
char* p = pBuf;
|
||||
char *p = pBuf;
|
||||
int32_t resLen = 0;
|
||||
for (uint8_t i = 0; i < tListLen(ctx.digest); ++i) {
|
||||
resLen += snprintf(p, 3, "%02x", ctx.digest[i]);
|
||||
|
@ -148,6 +148,30 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
|
||||
#define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
|
||||
|
||||
#define TAOS_RETURN(code) \
|
||||
do { \
|
||||
return (terrno = (code)); \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_RETURN(CMD) \
|
||||
do { \
|
||||
int32_t code = (CMD); \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
TAOS_RETURN(code); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_CHECK_GOTO(CMD, LINO, LABEL) \
|
||||
do { \
|
||||
code = (CMD); \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
if (LINO) { \
|
||||
*((int32_t *)(LINO)) = __LINE__; \
|
||||
} \
|
||||
goto LABEL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1398,7 +1398,8 @@ void hbMgrCleanUp() {
|
|||
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
appHbMgrCleanup();
|
||||
clientHbMgr.appHbMgrs = taosArrayDestroy(clientHbMgr.appHbMgrs);
|
||||
taosArrayDestroy(clientHbMgr.appHbMgrs);
|
||||
clientHbMgr.appHbMgrs = NULL;
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
}
|
||||
|
||||
|
|
|
@ -1512,7 +1512,9 @@ void blockDataFreeRes(SSDataBlock* pBlock) {
|
|||
colDataDestroy(pColInfoData);
|
||||
}
|
||||
|
||||
pBlock->pDataBlock = taosArrayDestroy(pBlock->pDataBlock);
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
pBlock->pDataBlock = NULL;
|
||||
|
||||
taosMemoryFreeClear(pBlock->pBlockAgg);
|
||||
memset(&pBlock->info, 0, sizeof(SDataBlockInfo));
|
||||
}
|
||||
|
|
|
@ -9505,7 +9505,8 @@ int32_t tDecodeMqDataRsp(SDecoder *pDecoder, void *pRsp) {
|
|||
|
||||
static void tDeleteMqDataRspCommon(void *rsp) {
|
||||
SMqDataRspCommon *pRsp = rsp;
|
||||
pRsp->blockDataLen = taosArrayDestroy(pRsp->blockDataLen);
|
||||
taosArrayDestroy(pRsp->blockDataLen);
|
||||
pRsp->blockDataLen = NULL;
|
||||
taosArrayDestroyP(pRsp->blockData, (FDelete)taosMemoryFree);
|
||||
pRsp->blockData = NULL;
|
||||
taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSchemaWrapper);
|
||||
|
@ -9558,7 +9559,8 @@ void tDeleteSTaosxRsp(void *rsp) {
|
|||
tDeleteMqDataRspCommon(rsp);
|
||||
|
||||
STaosxRsp *pRsp = (STaosxRsp *)rsp;
|
||||
pRsp->createTableLen = taosArrayDestroy(pRsp->createTableLen);
|
||||
taosArrayDestroy(pRsp->createTableLen);
|
||||
pRsp->createTableLen = NULL;
|
||||
taosArrayDestroyP(pRsp->createTableReq, (FDelete)taosMemoryFree);
|
||||
pRsp->createTableReq = NULL;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "audit.h"
|
||||
#include "libs/function/tudf.h"
|
||||
#include "tgrant.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#define DM_INIT_AUDIT() \
|
||||
do { \
|
||||
|
@ -163,6 +164,7 @@ int32_t dmInit() {
|
|||
if (dmInitMonitor() != 0) return -1;
|
||||
if (dmInitAudit() != 0) return -1;
|
||||
if (dmInitDnode(dmInstance()) != 0) return -1;
|
||||
if (InitRegexCache() != 0) return -1;
|
||||
#if defined(USE_S3)
|
||||
if (s3Begin() != 0) return -1;
|
||||
#endif
|
||||
|
@ -192,6 +194,7 @@ void dmCleanup() {
|
|||
udfStopUdfd();
|
||||
taosStopCacheRefreshWorker();
|
||||
dmDiskClose();
|
||||
DestroyRegexCache();
|
||||
|
||||
#if defined(USE_S3)
|
||||
s3End();
|
||||
|
|
|
@ -195,7 +195,9 @@ void *freeStreamTasks(SArray *pTaskLevel) {
|
|||
taosArrayDestroy(pLevel);
|
||||
}
|
||||
|
||||
return taosArrayDestroy(pTaskLevel);
|
||||
taosArrayDestroy(pTaskLevel);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tFreeStreamObj(SStreamObj *pStream) {
|
||||
|
|
|
@ -978,7 +978,8 @@ void mndAddConsensusTasks(SCheckpointConsensusInfo *pInfo, const SRestoreCheckpo
|
|||
}
|
||||
|
||||
void mndClearConsensusRspEntry(SCheckpointConsensusInfo* pInfo) {
|
||||
pInfo->pTaskList = taosArrayDestroy(pInfo->pTaskList);
|
||||
taosArrayDestroy(pInfo->pTaskList);
|
||||
pInfo->pTaskList = NULL;
|
||||
}
|
||||
|
||||
int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId) {
|
||||
|
|
|
@ -249,7 +249,8 @@ static int32_t doBuildAndSendCreateTableMsg(SVnode* pVnode, char* stbFullName, S
|
|||
}
|
||||
|
||||
tTagNew(tagArray, 1, false, (STag**)&pCreateTbReq->ctb.pTag);
|
||||
tagArray = taosArrayDestroy(tagArray);
|
||||
taosArrayDestroy(tagArray);
|
||||
tagArray = NULL;
|
||||
if (pCreateTbReq->ctb.pTag == NULL) {
|
||||
tdDestroySVCreateTbReq(pCreateTbReq);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -505,7 +506,8 @@ int32_t doConvertRows(SSubmitTbData* pTableData, const STSchema* pTSchema, SSDat
|
|||
pTableData->aRowP = taosArrayInit(numOfRows, sizeof(SRow*));
|
||||
|
||||
if (pTableData->aRowP == NULL || pVals == NULL) {
|
||||
pTableData->aRowP = taosArrayDestroy(pTableData->aRowP);
|
||||
taosArrayDestroy(pTableData->aRowP);
|
||||
pTableData->aRowP = NULL;
|
||||
taosArrayDestroy(pVals);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("s-task:%s failed to prepare write stream res blocks, code:%s", id, tstrerror(code));
|
||||
|
@ -530,7 +532,8 @@ int32_t doConvertRows(SSubmitTbData* pTableData, const STSchema* pTSchema, SSDat
|
|||
if (ts < earlyTs) {
|
||||
tqError("s-task:%s ts:%" PRId64 " of generated results out of valid time range %" PRId64 " , discarded", id,
|
||||
ts, earlyTs);
|
||||
pTableData->aRowP = taosArrayDestroy(pTableData->aRowP);
|
||||
taosArrayDestroy(pTableData->aRowP);
|
||||
pTableData->aRowP = NULL;
|
||||
taosArrayDestroy(pVals);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -54,19 +54,23 @@ static int32_t tqInitTaosxRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
|
|||
|
||||
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL || pRsp->blockTbName == NULL || pRsp->blockSchema == NULL) {
|
||||
if (pRsp->blockData != NULL) {
|
||||
pRsp->blockData = taosArrayDestroy(pRsp->blockData);
|
||||
taosArrayDestroy(pRsp->blockData);
|
||||
pRsp->blockData = NULL;
|
||||
}
|
||||
|
||||
if (pRsp->blockDataLen != NULL) {
|
||||
pRsp->blockDataLen = taosArrayDestroy(pRsp->blockDataLen);
|
||||
taosArrayDestroy(pRsp->blockDataLen);
|
||||
pRsp->blockDataLen = NULL;
|
||||
}
|
||||
|
||||
if (pRsp->blockTbName != NULL) {
|
||||
pRsp->blockTbName = taosArrayDestroy(pRsp->blockTbName);
|
||||
taosArrayDestroy(pRsp->blockTbName);
|
||||
pRsp->blockTbName = NULL;
|
||||
}
|
||||
|
||||
if (pRsp->blockSchema != NULL) {
|
||||
pRsp->blockSchema = taosArrayDestroy(pRsp->blockSchema);
|
||||
taosArrayDestroy(pRsp->blockSchema);
|
||||
pRsp->blockSchema = NULL;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -3187,7 +3187,8 @@ static void clearLastFileSet(SFSNextRowIter *state) {
|
|||
int32_t iter = 0;
|
||||
while ((pe = tSimpleHashIterate(state->pr->pTableMap, pe, &iter)) != NULL) {
|
||||
STableLoadInfo *pInfo = *(STableLoadInfo **)pe;
|
||||
pInfo->pTombData = taosArrayDestroy(pInfo->pTombData);
|
||||
taosArrayDestroy(pInfo->pTombData);
|
||||
pInfo->pTombData = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,7 +311,8 @@ void* tsdbCacherowsReaderClose(void* pReader) {
|
|||
int32_t iter = 0;
|
||||
while ((pe = tSimpleHashIterate(p->pTableMap, pe, &iter)) != NULL) {
|
||||
STableLoadInfo* pInfo = *(STableLoadInfo**)pe;
|
||||
pInfo->pTombData = taosArrayDestroy(pInfo->pTombData);
|
||||
taosArrayDestroy(pInfo->pTombData);
|
||||
pInfo->pTombData = NULL;
|
||||
}
|
||||
|
||||
tSimpleHashCleanup(p->pTableMap);
|
||||
|
|
|
@ -308,7 +308,8 @@ void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) {
|
|||
pInfo->iiter.iter = tsdbTbDataIterDestroy(pInfo->iiter.iter);
|
||||
}
|
||||
|
||||
pInfo->delSkyline = taosArrayDestroy(pInfo->delSkyline);
|
||||
taosArrayDestroy(pInfo->delSkyline);
|
||||
pInfo->delSkyline = NULL;
|
||||
pInfo->lastProcKey.ts = ts;
|
||||
// todo check the nextProcKey info
|
||||
pInfo->sttKeyInfo.nextProcKey.ts = ts + step;
|
||||
|
@ -329,11 +330,16 @@ void clearBlockScanInfo(STableBlockScanInfo* p) {
|
|||
p->iiter.iter = tsdbTbDataIterDestroy(p->iiter.iter);
|
||||
}
|
||||
|
||||
p->delSkyline = taosArrayDestroy(p->delSkyline);
|
||||
p->pBlockList = taosArrayDestroy(p->pBlockList);
|
||||
p->pBlockIdxList = taosArrayDestroy(p->pBlockIdxList);
|
||||
p->pMemDelData = taosArrayDestroy(p->pMemDelData);
|
||||
p->pFileDelData = taosArrayDestroy(p->pFileDelData);
|
||||
taosArrayDestroy(p->delSkyline);
|
||||
p->delSkyline = NULL;
|
||||
taosArrayDestroy(p->pBlockList);
|
||||
p->pBlockList = NULL;
|
||||
taosArrayDestroy(p->pBlockIdxList);
|
||||
p->pBlockIdxList = NULL;
|
||||
taosArrayDestroy(p->pMemDelData);
|
||||
p->pMemDelData = NULL;
|
||||
taosArrayDestroy(p->pFileDelData);
|
||||
p->pFileDelData = NULL;
|
||||
|
||||
clearRowKey(&p->lastProcKey);
|
||||
clearRowKey(&p->sttRange.skey);
|
||||
|
@ -579,7 +585,8 @@ int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int3
|
|||
}
|
||||
|
||||
taosArrayAddAll(pBlockIter->blockList, pTableScanInfo->pBlockList);
|
||||
pTableScanInfo->pBlockList = taosArrayDestroy(pTableScanInfo->pBlockList);
|
||||
taosArrayDestroy(pTableScanInfo->pBlockList);
|
||||
pTableScanInfo->pBlockList = NULL;
|
||||
|
||||
int64_t et = taosGetTimestampUs();
|
||||
tsdbDebug("%p create blocks info struct completed for one table, %d blocks not sorted, elapsed time:%.2f ms %s",
|
||||
|
@ -624,7 +631,8 @@ int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int3
|
|||
|
||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, i);
|
||||
pTableScanInfo->pBlockList = taosArrayDestroy(pTableScanInfo->pBlockList);
|
||||
taosArrayDestroy(pTableScanInfo->pBlockList);
|
||||
pTableScanInfo->pBlockList = NULL;
|
||||
}
|
||||
|
||||
int64_t et = taosGetTimestampUs();
|
||||
|
|
|
@ -96,7 +96,8 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) {
|
|||
pGroupResInfo->freeItem = false;
|
||||
pGroupResInfo->pRows = NULL;
|
||||
} else {
|
||||
pGroupResInfo->pRows = taosArrayDestroy(pGroupResInfo->pRows);
|
||||
taosArrayDestroy(pGroupResInfo->pRows);
|
||||
pGroupResInfo->pRows = NULL;
|
||||
}
|
||||
pGroupResInfo->index = 0;
|
||||
}
|
||||
|
@ -2102,7 +2103,8 @@ void* tableListDestroy(STableListInfo* pTableListInfo) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pTableListInfo->pTableList = taosArrayDestroy(pTableListInfo->pTableList);
|
||||
taosArrayDestroy(pTableListInfo->pTableList);
|
||||
pTableListInfo->pTableList = NULL;
|
||||
taosMemoryFreeClear(pTableListInfo->groupOffset);
|
||||
|
||||
taosHashCleanup(pTableListInfo->map);
|
||||
|
|
|
@ -479,12 +479,14 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI
|
|||
}
|
||||
|
||||
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion,
|
||||
int32_t* tversion, int32_t idx) {
|
||||
int32_t* tversion, int32_t idx, bool* tbGet) {
|
||||
*tbGet = false;
|
||||
|
||||
ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL);
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
|
||||
if (taosArrayGetSize(pTaskInfo->schemaInfos) <= idx) {
|
||||
return -1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSchemaInfo* pSchemaInfo = taosArrayGet(pTaskInfo->schemaInfos, idx);
|
||||
|
@ -502,6 +504,8 @@ int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* table
|
|||
tableName[0] = 0;
|
||||
}
|
||||
|
||||
*tbGet = true;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,8 @@ static void destroyStreamFillOperatorInfo(void* param) {
|
|||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
pInfo->pSrcBlock = blockDataDestroy(pInfo->pSrcBlock);
|
||||
pInfo->pDelRes = blockDataDestroy(pInfo->pDelRes);
|
||||
pInfo->matchInfo.pList = taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
pInfo->matchInfo.pList = NULL;
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -412,7 +412,8 @@ void clearGroupResInfo(SGroupResInfo* pGroupResInfo) {
|
|||
}
|
||||
pGroupResInfo->freeItem = false;
|
||||
}
|
||||
pGroupResInfo->pRows = taosArrayDestroy(pGroupResInfo->pRows);
|
||||
taosArrayDestroy(pGroupResInfo->pRows);
|
||||
pGroupResInfo->pRows = NULL;
|
||||
pGroupResInfo->index = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1136,7 +1136,8 @@ void destroyIntervalOperatorInfo(void* param) {
|
|||
|
||||
tdListFree(pInfo->binfo.resultRowInfo.openWindow);
|
||||
|
||||
pInfo->pInterpCols = taosArrayDestroy(pInfo->pInterpCols);
|
||||
taosArrayDestroy(pInfo->pInterpCols);
|
||||
pInfo->pInterpCols = NULL;
|
||||
taosArrayDestroyEx(pInfo->pPrevValues, freeItem);
|
||||
|
||||
pInfo->pPrevValues = NULL;
|
||||
|
|
|
@ -1441,6 +1441,9 @@ _stddev_over:
|
|||
}
|
||||
|
||||
static void stddevTransferInfo(SStddevRes* pInput, SStddevRes* pOutput) {
|
||||
if (IS_NULL_TYPE(pInput->type)) {
|
||||
return;
|
||||
}
|
||||
pOutput->type = pInput->type;
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pOutput->type)) {
|
||||
pOutput->quadraticISum += pInput->quadraticISum;
|
||||
|
|
|
@ -1061,6 +1061,13 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
pStmt->freeStbRowsCxtFunc(pStmt->pStbRowsCxt);
|
||||
}
|
||||
taosMemoryFreeClear(pStmt->pStbRowsCxt);
|
||||
|
||||
taosMemoryFreeClear(pStmt->pCreateTbInfo);
|
||||
|
||||
if (pStmt->destroyParseFileCxt) {
|
||||
pStmt->destroyParseFileCxt(&pStmt->pParFileCxt);
|
||||
}
|
||||
|
||||
taosCloseFile(&pStmt->fp);
|
||||
break;
|
||||
}
|
||||
|
@ -1093,15 +1100,6 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
}
|
||||
case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE: {
|
||||
SCreateSubTableFromFileClause* pStmt = (SCreateSubTableFromFileClause*)pNode;
|
||||
if (pStmt->aCreateTbData) {
|
||||
taosArrayDestroy(pStmt->aCreateTbData);
|
||||
}
|
||||
if (pStmt->aTagIndexs) {
|
||||
taosArrayDestroy(pStmt->aTagIndexs);
|
||||
}
|
||||
if (pStmt->fp) {
|
||||
taosCloseFile(&pStmt->fp);
|
||||
}
|
||||
nodesDestroyList(pStmt->pSpecificTags);
|
||||
break;
|
||||
}
|
||||
|
@ -2205,6 +2203,17 @@ bool nodesIsRegularOp(const SOperatorNode* pOp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool nodesIsMatchRegularOp(const SOperatorNode* pOp) {
|
||||
switch (pOp->opType) {
|
||||
case OP_TYPE_MATCH:
|
||||
case OP_TYPE_NMATCH:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool nodesIsBitwiseOp(const SOperatorNode* pOp) {
|
||||
switch (pOp->opType) {
|
||||
case OP_TYPE_BIT_AND:
|
||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
#define QUERY_SMA_OPTIMIZE_ENABLE 1
|
||||
|
||||
int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData);
|
||||
int32_t continueCreateTbFromFile(SParseContext* pCxt, SQuery** pQuery);
|
||||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||
int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache);
|
||||
int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache);
|
||||
|
|
|
@ -353,6 +353,8 @@ end_opt(A) ::= END WITH TIMESTAMP NK_STRING(B).
|
|||
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
|
||||
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
|
||||
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A); }
|
||||
cmd ::= CREATE TABLE not_exists_opt(B) USING full_table_name(C)
|
||||
NK_LP tag_list_opt(D) NK_RP FILE NK_STRING(E). { pCxt->pRootNode = createCreateSubTableFromFileClause(pCxt, B, C, D, &E); }
|
||||
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
|
||||
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
|
||||
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
|
||||
|
@ -385,15 +387,11 @@ alter_table_clause(A) ::=
|
|||
%destructor multi_create_clause { nodesDestroyList($$); }
|
||||
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
|
||||
multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). { A = addNodeToList(pCxt, B, C); }
|
||||
multi_create_clause(A) ::= create_from_file_clause(B). { A = createNodeList(pCxt, B); }
|
||||
|
||||
create_subtable_clause(A) ::=
|
||||
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
|
||||
specific_cols_opt(E) TAGS NK_LP tags_literal_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
|
||||
|
||||
create_from_file_clause(A) ::= not_exists_opt(B) USING full_table_name(C)
|
||||
NK_LP tag_list_opt(D) NK_RP FILE NK_STRING(E). { A = createCreateSubTableFromFileClause(pCxt, B, C, D, &E); }
|
||||
|
||||
%type multi_drop_clause { SNodeList* }
|
||||
%destructor multi_drop_clause { nodesDestroyList($$); }
|
||||
multi_drop_clause(A) ::= drop_table_clause(B). { A = createNodeList(pCxt, B); }
|
||||
|
|
|
@ -310,6 +310,24 @@ static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCre
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromCreateSubTableFromFile(SCollectMetaKeyCxt* pCxt,
|
||||
SCreateSubTableFromFileClause* pClause) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pNode = NULL;
|
||||
|
||||
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code =
|
||||
reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->useDbName, pClause->useTableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->useDbName, NULL,
|
||||
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pNode = NULL;
|
||||
|
@ -866,6 +884,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt);
|
||||
case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
|
||||
return collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
|
||||
case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE:
|
||||
return collectMetaKeyFromCreateSubTableFromFile(pCxt, (SCreateSubTableFromFileClause*)pStmt);
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
|
||||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
|
|
|
@ -11889,7 +11889,8 @@ static int32_t createOperatorNode(EOperatorType opType, const char* pColName, SN
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createParOperatorNode(EOperatorType opType, const char* pLeftCol, const char* pRightCol, SNode** ppResOp) {
|
||||
static int32_t createParOperatorNode(EOperatorType opType, const char* pLeftCol, const char* pRightCol,
|
||||
SNode** ppResOp) {
|
||||
SOperatorNode* pOper = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
CHECK_POINTER_OUT_OF_MEM(pOper);
|
||||
|
||||
|
@ -12694,7 +12695,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
|
||||
static int32_t buildTagIndexForBindTags(SMsgBuf* pMsgBuf, SCreateSubTableFromFileClause* pStmt,
|
||||
STableMeta* pSuperTableMeta) {
|
||||
STableMeta* pSuperTableMeta, SArray* aTagIndexs) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
||||
|
@ -12705,7 +12706,7 @@ static int32_t buildTagIndexForBindTags(SMsgBuf* pMsgBuf, SCreateSubTableFromFil
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
bool tbnameFound = false;
|
||||
bool tbnameFound = false;
|
||||
|
||||
SNode* pTagNode;
|
||||
FOREACH(pTagNode, pStmt->pSpecificTags) {
|
||||
|
@ -12757,14 +12758,14 @@ static int32_t buildTagIndexForBindTags(SMsgBuf* pMsgBuf, SCreateSubTableFromFil
|
|||
goto _OUT;
|
||||
}
|
||||
|
||||
if (NULL == taosArrayPush(pStmt->aTagIndexs, &idx)) {
|
||||
if (NULL == taosArrayPush(aTagIndexs, &idx)) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OUT;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && !tbnameFound) {
|
||||
code = generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_TBNAME_ERROR);
|
||||
code = generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_TBNAME_ERROR);
|
||||
}
|
||||
|
||||
_OUT:
|
||||
|
@ -12772,21 +12773,19 @@ _OUT:
|
|||
return code;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
// refer
|
||||
STableMeta* pSuperTableMeta;
|
||||
SArray* pTagIndexs;
|
||||
TdFilePtr fp;
|
||||
typedef struct SParseFileContext {
|
||||
SHashObj* pTbNameHash;
|
||||
SArray* aTagNames;
|
||||
bool tagNameFilled;
|
||||
STableMeta* pStbMeta;
|
||||
SArray* aTagIndexs;
|
||||
|
||||
// containers
|
||||
SHashObj* pTbNameHash;
|
||||
SArray* aTagNames;
|
||||
bool tagNameFilled;
|
||||
SArray* aTagVals;
|
||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW];
|
||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW];
|
||||
SArray* aCreateTbData;
|
||||
|
||||
// per line
|
||||
const char* pSql;
|
||||
SArray* aTagVals;
|
||||
STag* pTag;
|
||||
SName ctbName;
|
||||
SVgroupInfo vg;
|
||||
|
@ -12810,48 +12809,48 @@ static int32_t fillVgroupInfo(SParseContext* pParseCxt, const SName* pName, SVgr
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t parseOneStbRow(SMsgBuf* pMsgBuf, SParseFileContext* pParFileCtx) {
|
||||
static int32_t parseOneStbRow(SMsgBuf* pMsgBuf, SParseFileContext* pParFileCxt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int sz = taosArrayGetSize(pParFileCtx->pTagIndexs);
|
||||
int32_t numOfTags = getNumOfTags(pParFileCtx->pSuperTableMeta);
|
||||
uint8_t precision = getTableInfo(pParFileCtx->pSuperTableMeta).precision;
|
||||
SSchema* pSchemas = getTableTagSchema(pParFileCtx->pSuperTableMeta);
|
||||
int sz = taosArrayGetSize(pParFileCxt->aTagIndexs);
|
||||
int32_t numOfTags = getNumOfTags(pParFileCxt->pStbMeta);
|
||||
uint8_t precision = getTableInfo(pParFileCxt->pStbMeta).precision;
|
||||
SSchema* pSchemas = getTableTagSchema(pParFileCxt->pStbMeta);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
const char* pSql = pParFileCtx->pSql;
|
||||
const char* pSql = pParFileCxt->pSql;
|
||||
|
||||
int32_t pos = 0;
|
||||
SToken token = tStrGetToken(pSql, &pos, true, NULL);
|
||||
pParFileCtx->pSql += pos;
|
||||
pParFileCxt->pSql += pos;
|
||||
|
||||
if (TK_NK_RP == token.type) {
|
||||
code = generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
|
||||
break;
|
||||
}
|
||||
|
||||
int16_t index = *(int16_t*)taosArrayGet(pParFileCtx->pTagIndexs, i);
|
||||
int16_t index = *(int16_t*)taosArrayGet(pParFileCxt->aTagIndexs, i);
|
||||
if (index < numOfTags) {
|
||||
// parse tag
|
||||
const SSchema* pTagSchema = &pSchemas[index];
|
||||
|
||||
code = checkAndTrimValue(&token, pParFileCtx->tmpTokenBuf, pMsgBuf, pTagSchema->type);
|
||||
code = checkAndTrimValue(&token, pParFileCxt->tmpTokenBuf, pMsgBuf, pTagSchema->type);
|
||||
if (TSDB_CODE_SUCCESS == code && TK_NK_VARIABLE == token.type) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, "not expected row value");
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SArray* aTagNames = pParFileCtx->tagNameFilled ? NULL : pParFileCtx->aTagNames;
|
||||
code = parseTagValue(pMsgBuf, &pParFileCtx->pSql, precision, (SSchema*)pTagSchema, &token,
|
||||
aTagNames, pParFileCtx->aTagVals, &pParFileCtx->pTag);
|
||||
SArray* aTagNames = pParFileCxt->tagNameFilled ? NULL : pParFileCxt->aTagNames;
|
||||
code = parseTagValue(pMsgBuf, &pParFileCxt->pSql, precision, (SSchema*)pTagSchema, &token, aTagNames,
|
||||
pParFileCxt->aTagVals, &pParFileCxt->pTag);
|
||||
}
|
||||
} else {
|
||||
// parse tbname
|
||||
code = checkAndTrimValue(&token, pParFileCtx->tmpTokenBuf, pMsgBuf, TSDB_DATA_TYPE_BINARY);
|
||||
code = checkAndTrimValue(&token, pParFileCxt->tmpTokenBuf, pMsgBuf, TSDB_DATA_TYPE_BINARY);
|
||||
if (TK_NK_VARIABLE == token.type) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, "not expected tbname");
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
bool bFoundTbName = false;
|
||||
code = parseTbnameToken(pMsgBuf, pParFileCtx->ctbName.tname, &token, &bFoundTbName);
|
||||
code = parseTbnameToken(pMsgBuf, pParFileCxt->ctbName.tname, &token, &bFoundTbName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12859,8 +12858,8 @@ static int32_t parseOneStbRow(SMsgBuf* pMsgBuf, SParseFileContext* pParFileCtx)
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pParFileCtx->tagNameFilled = true;
|
||||
code = tTagNew(pParFileCtx->aTagVals, 1, false, &pParFileCtx->pTag);
|
||||
pParFileCxt->tagNameFilled = true;
|
||||
code = tTagNew(pParFileCxt->aTagVals, 1, false, &pParFileCxt->pTag);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -12873,171 +12872,262 @@ typedef struct {
|
|||
SVgroupInfo vg;
|
||||
} SCreateTableData;
|
||||
|
||||
static void clearTagValArrayFp(void *data) {
|
||||
static void clearTagValArrayFp(void* data) {
|
||||
STagVal* p = (STagVal*)data;
|
||||
if (IS_VAR_DATA_TYPE(p->type)) {
|
||||
taosMemoryFreeClear(p->pData);
|
||||
}
|
||||
}
|
||||
|
||||
static void clearCreateTbArrayFp(void *data) {
|
||||
static void clearCreateTbArrayFp(void* data) {
|
||||
SCreateTableData* p = (SCreateTableData*)data;
|
||||
taosMemoryFreeClear(p->pTag);
|
||||
}
|
||||
|
||||
static int32_t parseCsvFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SParseFileContext* pParseFileCtx,
|
||||
SArray* aCreateTbData) {
|
||||
static int32_t parseCsvFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SParseFileContext* pParFileCxt, TdFilePtr fp,
|
||||
int32_t maxLineCount) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
char* pLine = NULL;
|
||||
int64_t readLen = 0;
|
||||
while (TSDB_CODE_SUCCESS == code && (readLen = taosGetLineFile(pParseFileCtx->fp, &pLine)) != -1) {
|
||||
int32_t lineCount = 0;
|
||||
while (TSDB_CODE_SUCCESS == code && (readLen = taosGetLineFile(fp, &pLine)) != -1) {
|
||||
if (('\r' == pLine[readLen - 1]) || ('\n' == pLine[readLen - 1])) {
|
||||
pLine[--readLen] = '\0';
|
||||
}
|
||||
|
||||
if (readLen == 0) continue;
|
||||
|
||||
if (pLine[0] == '#') continue;
|
||||
if (pLine[0] == '#') continue; // ignore comment line begins with '#'
|
||||
|
||||
strtolower(pLine, pLine);
|
||||
pParseFileCtx->pSql = pLine;
|
||||
pParFileCxt->pSql = pLine;
|
||||
|
||||
code = parseOneStbRow(pMsgBuf, pParseFileCtx);
|
||||
code = parseOneStbRow(pMsgBuf, pParFileCxt);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (taosHashGet(pParseFileCtx->pTbNameHash, pParseFileCtx->ctbName.tname,
|
||||
strlen(pParseFileCtx->ctbName.tname) + 1) != NULL) {
|
||||
taosMemoryFreeClear(pParseFileCtx->pTag);
|
||||
code = generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_TBNAME_DUPLICATED, pParseFileCtx->ctbName.tname);
|
||||
if (taosHashGet(pParFileCxt->pTbNameHash, pParFileCxt->ctbName.tname, strlen(pParFileCxt->ctbName.tname) + 1) !=
|
||||
NULL) {
|
||||
taosMemoryFreeClear(pParFileCxt->pTag);
|
||||
code = generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_TBNAME_DUPLICATED, pParFileCxt->ctbName.tname);
|
||||
break;
|
||||
}
|
||||
|
||||
code = taosHashPut(pParseFileCtx->pTbNameHash, pParseFileCtx->ctbName.tname,
|
||||
strlen(pParseFileCtx->ctbName.tname) + 1, NULL, 0);
|
||||
code = taosHashPut(pParFileCxt->pTbNameHash, pParFileCxt->ctbName.tname, strlen(pParFileCxt->ctbName.tname) + 1,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = fillVgroupInfo(pParseCxt, &pParseFileCtx->ctbName, &pParseFileCtx->vg);
|
||||
code = fillVgroupInfo(pParseCxt, &pParFileCxt->ctbName, &pParFileCxt->vg);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SCreateTableData data = {.ctbName = pParseFileCtx->ctbName,
|
||||
.aTagNames = pParseFileCtx->aTagNames,
|
||||
.pTag = pParseFileCtx->pTag,
|
||||
.vg = pParseFileCtx->vg};
|
||||
SCreateTableData data = {.ctbName = pParFileCxt->ctbName,
|
||||
.aTagNames = pParFileCxt->aTagNames,
|
||||
.pTag = pParFileCxt->pTag,
|
||||
.vg = pParFileCxt->vg};
|
||||
|
||||
taosArrayPush(aCreateTbData, &data);
|
||||
taosArrayPush(pParFileCxt->aCreateTbData, &data);
|
||||
} else {
|
||||
taosMemoryFreeClear(pParseFileCtx->pTag);
|
||||
taosMemoryFreeClear(pParFileCxt->pTag);
|
||||
}
|
||||
|
||||
pParseFileCtx->pTag = NULL;
|
||||
taosArrayClearEx(pParseFileCtx->aTagVals, clearTagValArrayFp);
|
||||
pParFileCxt->pTag = NULL;
|
||||
taosArrayClearEx(pParFileCxt->aTagVals, clearTagValArrayFp);
|
||||
lineCount++;
|
||||
if (lineCount == maxLineCount) break;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosArrayClearEx(aCreateTbData, clearCreateTbArrayFp);
|
||||
taosArrayClearEx(pParFileCxt->aCreateTbData, clearCreateTbArrayFp);
|
||||
}
|
||||
|
||||
taosMemoryFree(pLine);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t prepareReadFromFile(SCreateSubTableFromFileClause* pStmt) {
|
||||
static void destructParseFileContext(SParseFileContext** ppParFileCxt) {
|
||||
if (NULL == ppParFileCxt || NULL == *ppParFileCxt) {
|
||||
return;
|
||||
}
|
||||
|
||||
SParseFileContext* pParFileCxt = *ppParFileCxt;
|
||||
|
||||
taosHashCleanup(pParFileCxt->pTbNameHash);
|
||||
taosArrayDestroy(pParFileCxt->aTagNames);
|
||||
taosMemoryFreeClear(pParFileCxt->pStbMeta);
|
||||
taosArrayDestroy(pParFileCxt->aTagIndexs);
|
||||
taosArrayDestroy(pParFileCxt->aCreateTbData);
|
||||
taosArrayDestroy(pParFileCxt->aTagVals);
|
||||
taosMemoryFree(pParFileCxt);
|
||||
|
||||
*ppParFileCxt = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t constructParseFileContext(SCreateSubTableFromFileClause* pStmt, STableMeta* pSuperTableMeta,
|
||||
int32_t acctId, SParseFileContext** ppParFileCxt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (NULL == pStmt->fp) {
|
||||
pStmt->fp = taosOpenFile(pStmt->filePath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (NULL == pStmt->fp) {
|
||||
|
||||
SParseFileContext* pParFileCxt = taosMemoryCalloc(1, sizeof(SParseFileContext));
|
||||
pParFileCxt->pStbMeta = pSuperTableMeta;
|
||||
pParFileCxt->tagNameFilled = false;
|
||||
pParFileCxt->pTag = NULL;
|
||||
pParFileCxt->ctbName.type = TSDB_TABLE_NAME_T;
|
||||
pParFileCxt->ctbName.acctId = acctId;
|
||||
strcpy(pParFileCxt->ctbName.dbname, pStmt->useDbName);
|
||||
|
||||
if (NULL == pParFileCxt->pTbNameHash) {
|
||||
pParFileCxt->pTbNameHash =
|
||||
taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
|
||||
if (!pParFileCxt->pTbNameHash) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pParFileCxt->aTagNames) {
|
||||
pParFileCxt->aTagNames = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||
if (NULL == pParFileCxt->aTagNames) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pParFileCxt->aCreateTbData) {
|
||||
pParFileCxt->aCreateTbData = taosArrayInit(16, sizeof(SCreateTableData));
|
||||
if (NULL == pParFileCxt->aCreateTbData) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pParFileCxt->aTagIndexs) {
|
||||
pParFileCxt->aTagIndexs = taosArrayInit(pStmt->pSpecificTags->length, sizeof(int16_t));
|
||||
if (!pParFileCxt->aTagIndexs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pParFileCxt->aTagVals) {
|
||||
pParFileCxt->aTagVals = taosArrayInit(8, sizeof(STagVal));
|
||||
if (!pParFileCxt->aTagVals) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
*ppParFileCxt = pParFileCxt;
|
||||
|
||||
return code;
|
||||
|
||||
_ERR:
|
||||
destructParseFileContext(&pParFileCxt);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
typedef struct SCreateTbInfo {
|
||||
bool ignoreExists;
|
||||
char useDbName[TSDB_DB_NAME_LEN];
|
||||
char useTableName[TSDB_TABLE_NAME_LEN];
|
||||
} SCreateTbInfo;
|
||||
|
||||
static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFileClause* pCreateStmt,
|
||||
SVnodeModifyOpStmt* pModifyStmt) {
|
||||
int32_t code = 0;
|
||||
|
||||
TdFilePtr fp = NULL;
|
||||
SCreateTbInfo* pCreateInfo = NULL;
|
||||
SParseFileContext* pParFileCxt = NULL;
|
||||
|
||||
if (NULL == pModifyStmt->fp) {
|
||||
fp = taosOpenFile(pCreateStmt->filePath, TD_FILE_READ | TD_FILE_STREAM);
|
||||
if (NULL == fp) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == pStmt->aCreateTbData) {
|
||||
pStmt->aCreateTbData = taosArrayInit(16, sizeof(SCreateTableData));
|
||||
if (NULL == pStmt->aCreateTbData) {
|
||||
{
|
||||
pCreateInfo = taosMemoryCalloc(1, sizeof(SCreateTbInfo));
|
||||
if (NULL == pCreateInfo) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
|
||||
pCreateInfo->ignoreExists = pCreateStmt->ignoreExists;
|
||||
strncpy(pCreateInfo->useDbName, pCreateStmt->useDbName, TSDB_DB_NAME_LEN);
|
||||
strncpy(pCreateInfo->useTableName, pCreateStmt->useTableName, TSDB_TABLE_NAME_LEN);
|
||||
}
|
||||
|
||||
if (NULL == pStmt->aTagIndexs) {
|
||||
pStmt->aTagIndexs = taosArrayInit(pStmt->pSpecificTags->length, sizeof(int16_t));
|
||||
if (!pStmt->aTagIndexs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERR;
|
||||
}
|
||||
{
|
||||
STableMeta* pSuperTableMeta = NULL;
|
||||
code = getTableMeta(pCxt, pCreateStmt->useDbName, pCreateStmt->useTableName, &pSuperTableMeta);
|
||||
if (TSDB_CODE_SUCCESS != code) goto _ERR;
|
||||
|
||||
code = constructParseFileContext(pCreateStmt, pSuperTableMeta, pCxt->pParseCxt->acctId, &pParFileCxt);
|
||||
if (TSDB_CODE_SUCCESS != code) goto _ERR;
|
||||
|
||||
code = buildTagIndexForBindTags(&pCxt->msgBuf, pCreateStmt, pParFileCxt->pStbMeta, pParFileCxt->aTagIndexs);
|
||||
if (TSDB_CODE_SUCCESS != code) goto _ERR;
|
||||
}
|
||||
|
||||
pModifyStmt->fp = fp;
|
||||
pModifyStmt->fileProcessing = false;
|
||||
pModifyStmt->pCreateTbInfo = pCreateInfo;
|
||||
pModifyStmt->pParFileCxt = pParFileCxt;
|
||||
|
||||
return code;
|
||||
|
||||
_ERR:
|
||||
taosCloseFile(&pStmt->fp);
|
||||
taosArrayDestroy(pStmt->aCreateTbData);
|
||||
taosArrayDestroy(pStmt->aTagIndexs);
|
||||
|
||||
taosCloseFile(&fp);
|
||||
taosMemoryFreeClear(pCreateInfo);
|
||||
destructParseFileContext(&pParFileCxt);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteCreateSubTableFromFile(STranslateContext* pCxt, SCreateSubTableFromFileClause* pStmt,
|
||||
SHashObj* pVgroupHashmap) {
|
||||
static int32_t resetParseFileContext(SParseFileContext* pParFileCxt) {
|
||||
taosArrayClear(pParFileCxt->aCreateTbData);
|
||||
taosArrayClearEx(pParFileCxt->aTagVals, clearTagValArrayFp);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createSubTableFromFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SVnodeModifyOpStmt* pModifyStmt) {
|
||||
int32_t code = 0;
|
||||
|
||||
STableMeta* pSuperTableMeta = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta);
|
||||
}
|
||||
SCreateTbInfo* pCreateInfo = pModifyStmt->pCreateTbInfo;
|
||||
SParseFileContext* pParFileCxt = pModifyStmt->pParFileCxt;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = prepareReadFromFile(pStmt);
|
||||
code = parseCsvFile(pMsgBuf, pParseCxt, pParFileCxt, pModifyStmt->fp, tsMaxInsertBatchRows);
|
||||
}
|
||||
|
||||
STableMeta* pSuperTableMeta = pParFileCxt->pStbMeta;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildTagIndexForBindTags(&pCxt->msgBuf, pStmt, pSuperTableMeta);
|
||||
}
|
||||
|
||||
SParseFileContext parseFileCtx = {
|
||||
.pSuperTableMeta = pSuperTableMeta, .fp = pStmt->fp, .pTagIndexs = pStmt->aTagIndexs};
|
||||
parseFileCtx.pTbNameHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK);
|
||||
parseFileCtx.aTagNames = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||
parseFileCtx.tagNameFilled = false;
|
||||
parseFileCtx.aTagVals = taosArrayInit(8, sizeof(STagVal));
|
||||
parseFileCtx.pTag = NULL;
|
||||
parseFileCtx.ctbName.type = TSDB_TABLE_NAME_T;
|
||||
parseFileCtx.ctbName.acctId = pCxt->pParseCxt->acctId;
|
||||
strcpy(parseFileCtx.ctbName.dbname, pStmt->useDbName);
|
||||
|
||||
if (NULL == parseFileCtx.aTagNames || NULL == parseFileCtx.aTagVals || NULL == parseFileCtx.pTbNameHash) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = parseCsvFile(&pCxt->msgBuf, pCxt->pParseCxt, &parseFileCtx, pStmt->aCreateTbData);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int sz = taosArrayGetSize(pStmt->aCreateTbData);
|
||||
int sz = taosArrayGetSize(pParFileCxt->aCreateTbData);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SCreateTableData* pData = taosArrayGet(pStmt->aCreateTbData, i);
|
||||
SCreateTableData* pData = taosArrayGet(pParFileCxt->aCreateTbData, i);
|
||||
|
||||
code = collectUseTable(&pData->ctbName, pCxt->pTargetTables);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFree(pData->pTag);
|
||||
}
|
||||
// code = collectUseTable(&pData->ctbName, pCxt->pTargetTables);
|
||||
// if (TSDB_CODE_SUCCESS != code) {
|
||||
// taosMemoryFree(pData->pTag);
|
||||
// }
|
||||
|
||||
code = addCreateTbReqIntoVgroup(pVgroupHashmap, pStmt->useDbName, pSuperTableMeta->uid, pStmt->useTableName,
|
||||
pData->ctbName.tname, pData->aTagNames, pSuperTableMeta->tableInfo.numOfTags,
|
||||
pData->pTag, TSDB_DEFAULT_TABLE_TTL, NULL, pStmt->ignoreExists, &pData->vg);
|
||||
code = addCreateTbReqIntoVgroup(pModifyStmt->pVgroupsHashObj, pCreateInfo->useDbName, pSuperTableMeta->uid,
|
||||
pCreateInfo->useTableName, pData->ctbName.tname, pData->aTagNames,
|
||||
pSuperTableMeta->tableInfo.numOfTags, pData->pTag, TSDB_DEFAULT_TABLE_TTL, NULL,
|
||||
pCreateInfo->ignoreExists, &pData->vg);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pModifyStmt->fileProcessing = (sz == tsMaxInsertBatchRows);
|
||||
}
|
||||
}
|
||||
|
||||
_OUT:
|
||||
taosMemoryFreeClear(pSuperTableMeta);
|
||||
taosHashCleanup(parseFileCtx.pTbNameHash);
|
||||
taosArrayDestroy(parseFileCtx.aTagNames);
|
||||
taosArrayDestroy(parseFileCtx.aTagVals);
|
||||
(void)resetParseFileContext(pModifyStmt->pParFileCxt);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -13074,13 +13164,8 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pStmt->pSubTables) {
|
||||
if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
|
||||
SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
|
||||
code = rewriteCreateSubTable(pCxt, pClause, pVgroupHashmap);
|
||||
} else {
|
||||
SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
|
||||
code = rewriteCreateSubTableFromFile(pCxt, pClause, pVgroupHashmap);
|
||||
}
|
||||
SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
|
||||
code = rewriteCreateSubTable(pCxt, pClause, pVgroupHashmap);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
return code;
|
||||
|
@ -13096,6 +13181,75 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
|
|||
return rewriteToVnodeModifyOpStmt(pQuery, pBufArray);
|
||||
}
|
||||
|
||||
static int32_t rewriteCreateTableFromFile(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
SVnodeModifyOpStmt* pModifyStmt = (SVnodeModifyOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||
if (pModifyStmt == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pModifyStmt->sqlNodeType = nodeType(pQuery->pRoot);
|
||||
pModifyStmt->fileProcessing = false;
|
||||
pModifyStmt->destroyParseFileCxt = destructParseFileContext;
|
||||
pModifyStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (NULL == pModifyStmt->pVgroupsHashObj) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
taosHashSetFreeFp(pModifyStmt->pVgroupsHashObj, destroyCreateTbReqBatch);
|
||||
|
||||
SCreateSubTableFromFileClause* pCreateStmt = (SCreateSubTableFromFileClause*)pQuery->pRoot;
|
||||
|
||||
int32_t code = prepareReadCsvFile(pCxt, pCreateStmt, pModifyStmt);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosHashCleanup(pModifyStmt->pVgroupsHashObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
code = createSubTableFromFile(&pCxt->msgBuf, pCxt->pParseCxt, pModifyStmt);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosHashCleanup(pModifyStmt->pVgroupsHashObj);
|
||||
return code;
|
||||
}
|
||||
|
||||
SArray* pBufArray = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj);
|
||||
taosHashClear(pModifyStmt->pVgroupsHashObj);
|
||||
if (NULL == pBufArray) {
|
||||
taosHashCleanup(pModifyStmt->pVgroupsHashObj);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pModifyStmt->pDataBlocks = pBufArray;
|
||||
nodesDestroyNode(pQuery->pRoot);
|
||||
pQuery->pRoot = (SNode*)pModifyStmt;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t continueCreateTbFromFile(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||
SVnodeModifyOpStmt* pModifyStmt = (SVnodeModifyOpStmt*)(*pQuery)->pRoot;
|
||||
|
||||
SMsgBuf tmpBuf = {0};
|
||||
tmpBuf.buf = taosMemoryMalloc(1024);
|
||||
int32_t code = createSubTableFromFile(&tmpBuf, pParseCxt, pModifyStmt);
|
||||
if (TSDB_CODE_SUCCESS != code) goto _OUT;
|
||||
|
||||
SArray* pBufArray = serializeVgroupsCreateTableBatch(pModifyStmt->pVgroupsHashObj);
|
||||
taosHashClear(pModifyStmt->pVgroupsHashObj);
|
||||
if (NULL == pBufArray) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
pModifyStmt->pDataBlocks = pBufArray;
|
||||
(*pQuery)->execStage = QUERY_EXEC_STAGE_SCHEDULE;
|
||||
if (!pModifyStmt->fileProcessing) {
|
||||
(*pQuery)->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||
}
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
|
||||
_OUT:
|
||||
taosMemoryFreeClear(tmpBuf.buf);
|
||||
return code;
|
||||
}
|
||||
|
||||
typedef struct SVgroupDropTableBatch {
|
||||
SVDropTbBatchReq req;
|
||||
SVgroupInfo info;
|
||||
|
@ -13798,7 +13952,8 @@ static int32_t createParWhenThenNode(SNode* pWhen, SNode* pThen, SNode** ppResWh
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createParCaseWhenNode(SNode* pCase, SNodeList* pWhenThenList, SNode* pElse, const char* pAias, SNode** ppResCaseWhen) {
|
||||
static int32_t createParCaseWhenNode(SNode* pCase, SNodeList* pWhenThenList, SNode* pElse, const char* pAias,
|
||||
SNode** ppResCaseWhen) {
|
||||
SCaseWhenNode* pCaseWhen = (SCaseWhenNode*)nodesMakeNode(QUERY_NODE_CASE_WHEN);
|
||||
CHECK_POINTER_OUT_OF_MEM(pCaseWhen);
|
||||
|
||||
|
@ -13813,7 +13968,8 @@ static int32_t createParCaseWhenNode(SNode* pCase, SNodeList* pWhenThenList, SNo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t createParFunctionNode(const char* pFunName, const char* pAias, SNodeList* pParameterList, SNode** ppResFunc) {
|
||||
static int32_t createParFunctionNode(const char* pFunName, const char* pAias, SNodeList* pParameterList,
|
||||
SNode** ppResFunc) {
|
||||
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_POINTER_OUT_OF_MEM(pFunc);
|
||||
strcpy(pFunc->functionName, pFunName);
|
||||
|
@ -13854,13 +14010,13 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
}
|
||||
|
||||
SValueNode* pValNode = nodesMakeValueNodeFromString("leader");
|
||||
SValueNode* pValNode = nodesMakeValueNodeFromString("leader");
|
||||
CHECK_POINTER_OUT_OF_MEM(pValNode);
|
||||
|
||||
SNode* pCond1 = NULL;
|
||||
SNode* pCond2 = NULL;
|
||||
SNode* pCond3 = NULL;
|
||||
SNode* pCond4 = NULL;
|
||||
SNode* pCond1 = NULL;
|
||||
SNode* pCond2 = NULL;
|
||||
SNode* pCond3 = NULL;
|
||||
SNode* pCond4 = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_EQUAL, "v1_status", (SNode*)pValNode, &pCond1));
|
||||
CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_EQUAL, "v2_status", (SNode*)pValNode, &pCond2));
|
||||
CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_EQUAL, "v3_status", (SNode*)pValNode, &pCond3));
|
||||
|
@ -13885,16 +14041,16 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
SNode* pElse = nodesMakeValueNodeFromInt32(0);
|
||||
CHECK_POINTER_OUT_OF_MEM(pElse);
|
||||
|
||||
// case when (v1_status = "leader" or v2_status = "lead er" or v3_status = "leader" or v4_status = "leader") then 1 else 0 end
|
||||
// case when (v1_status = "leader" or v2_status = "lead er" or v3_status = "leader" or v4_status = "leader") then 1
|
||||
// else 0 end
|
||||
SNode* pCaseWhen = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createParCaseWhenNode(NULL, pWhenThenlist, pElse, NULL, &pCaseWhen));
|
||||
|
||||
SNodeList* pParaList = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createParListNode(pCaseWhen, &pParaList));
|
||||
|
||||
|
||||
// sum( case when ... end) as leader_col
|
||||
SNode* pSumFun = NULL;
|
||||
SNode* pSumFun = NULL;
|
||||
const char* pSumColAlias = "leader_col";
|
||||
CHECK_RES_OUT_OF_MEM(createParFunctionNode("sum", pSumColAlias, pParaList, &pSumFun));
|
||||
|
||||
|
@ -13904,7 +14060,7 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
CHECK_RES_OUT_OF_MEM(createParListNode(pPara1, &pParaList));
|
||||
|
||||
// count(1) as count_col
|
||||
SNode* pCountFun = NULL;
|
||||
SNode* pCountFun = NULL;
|
||||
const char* pCountColAlias = "count_col";
|
||||
CHECK_RES_OUT_OF_MEM(createParFunctionNode("count", pCountColAlias, pParaList, &pCountFun));
|
||||
|
||||
|
@ -13914,11 +14070,13 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
|
||||
SSelectStmt* pSubSelect = NULL;
|
||||
// select sum( case when .... end) as leader_col, count(*) as count_col from information_schema.ins_vgroups
|
||||
CHECK_RES_OUT_OF_MEM(createSimpleSelectStmtFromProjList(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, pProjList, &pSubSelect));
|
||||
CHECK_RES_OUT_OF_MEM(
|
||||
createSimpleSelectStmtFromProjList(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, pProjList, &pSubSelect));
|
||||
|
||||
if (pDbName && pDbName[0] != 0) {
|
||||
// for show db.alive
|
||||
// select sum( case when .... end) as leader_col, count(*) as count_col from information_schema.ins_vgroups where db_name = "..."
|
||||
// select sum( case when .... end) as leader_col, count(*) as count_col from information_schema.ins_vgroups where
|
||||
// db_name = "..."
|
||||
SNode* pDbCond = NULL;
|
||||
pValNode = nodesMakeValueNodeFromString(pDbName);
|
||||
CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_EQUAL, "db_name", (SNode*)pValNode, &pDbCond));
|
||||
|
@ -13928,14 +14086,12 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
pSubSelect->pWhere = pDbCond;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pCond1 = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createParOperatorNode(OP_TYPE_EQUAL, pSumColAlias, pCountColAlias, &pCond1));
|
||||
pCond2 = NULL;
|
||||
SNode* pTempVal = nodesMakeValueNodeFromInt32(0);
|
||||
CHECK_RES_OUT_OF_MEM(createOperatorNode(OP_TYPE_GREATER_THAN, pSumColAlias, pTempVal, &pCond2));
|
||||
//leader_col = count_col and leader_col > 0
|
||||
// leader_col = count_col and leader_col > 0
|
||||
pTemp1 = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createLogicCondNode(pCond1, pCond2, &pTemp1, LOGIC_COND_TYPE_AND));
|
||||
|
||||
|
@ -13961,7 +14117,8 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
CHECK_RES_OUT_OF_MEM(createParWhenThenNode(pTemp2, pThen, &pWhenThen));
|
||||
CHECK_RES_OUT_OF_MEM(nodesListStrictAppend(pWhenThenlist, pWhenThen));
|
||||
|
||||
// case when leader_col = count_col and count_col > 0 then 1 when leader_col < count_col and count_col > 0 then 2 else 0 end as status
|
||||
// case when leader_col = count_col and count_col > 0 then 1 when leader_col < count_col and count_col > 0 then 2 else
|
||||
// 0 end as status
|
||||
pCaseWhen = NULL;
|
||||
pElse = nodesMakeValueNodeFromInt32(0);
|
||||
CHECK_POINTER_OUT_OF_MEM(pElse);
|
||||
|
@ -13973,7 +14130,6 @@ static int32_t rewriteShowAliveStmt(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
SNode* pTempTblNode = NULL;
|
||||
CHECK_RES_OUT_OF_MEM(createParTempTableNode(pSubSelect, &pTempTblNode));
|
||||
|
||||
|
||||
SSelectStmt* pStmt = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
||||
CHECK_POINTER_OUT_OF_MEM(pStmt);
|
||||
pStmt->pProjectionList = pProjList;
|
||||
|
@ -14047,6 +14203,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
|
||||
code = rewriteCreateMultiTable(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE:
|
||||
code = rewriteCreateTableFromFile(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
code = rewriteDropTable(pCxt, pQuery);
|
||||
break;
|
||||
|
|
|
@ -223,7 +223,9 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Tag name:%s duplicated";
|
||||
case TSDB_CODE_PAR_NOT_ALLOWED_DIFFERENT_BY_ROW_FUNC:
|
||||
return "Some functions cannot appear in the select list at the same time";
|
||||
default:
|
||||
case TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR:
|
||||
return "Syntax error in regular expression";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,33 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool qIsCreateTbFromFileSql(const char* pStr, size_t length) {
|
||||
if (NULL == pStr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* pSql = pStr;
|
||||
|
||||
int32_t index = 0;
|
||||
SToken t = tStrGetToken((char*)pStr, &index, false, NULL);
|
||||
if (TK_CREATE != t.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
pStr += index;
|
||||
index = 0;
|
||||
t = tStrGetToken((char*)pStr, &index, false, NULL);
|
||||
if (TK_FILE == t.type) {
|
||||
return true;
|
||||
}
|
||||
if (0 == t.type || 0 == t.n) {
|
||||
break;
|
||||
}
|
||||
} while (pStr - pSql < length);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
|
||||
(void) length;
|
||||
int32_t index = 0;
|
||||
|
@ -239,11 +266,19 @@ static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCa
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t parseCreateTbFromFileSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
|
||||
if (NULL == *pQuery) return parseQuerySyntax(pCxt, pQuery, pCatalogReq);
|
||||
|
||||
return continueCreateTbFromFile(pCxt, pQuery);
|
||||
}
|
||||
|
||||
int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
|
||||
int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
|
||||
code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
|
||||
} else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
|
||||
code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
|
||||
} else {
|
||||
code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
|
||||
}
|
||||
|
@ -322,7 +357,7 @@ void destoryCatalogReq(SCatalogReq *pCatalogReq) {
|
|||
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
|
||||
#ifdef TD_ENTERPRISE
|
||||
taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
|
||||
#endif
|
||||
#endif
|
||||
taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
|
||||
taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -539,7 +539,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
pJoin->pJLimit = nodesCloneNode(pJoinTable->pJLimit);
|
||||
pJoin->addPrimEqCond = nodesCloneNode(pJoinTable->addPrimCond);
|
||||
pJoin->node.pChildren = nodesMakeList();
|
||||
pJoin->seqWinGroup = (JOIN_STYPE_WIN == pJoinTable->subType) && (pSelect->hasAggFuncs || pSelect->hasIndefiniteRowsFunc);
|
||||
pJoin->seqWinGroup = (JOIN_STYPE_WIN == pJoinTable->subType) && (pSelect->hasAggFuncs || pSelect->hasIndefiniteRowsFunc);
|
||||
|
||||
if (NULL == pJoin->node.pChildren) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -619,7 +619,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
// set the output
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNodeList* pColList = NULL;
|
||||
|
@ -762,7 +762,7 @@ static int32_t addWinJoinPrimKeyToAggFuncs(SSelectStmt* pSelect, SNodeList** pLi
|
|||
pCol->hasIndex = (pColSchema != NULL && IS_IDX_ON(pColSchema));
|
||||
pCol->node.resType.type = pColSchema->type;
|
||||
pCol->node.resType.bytes = pColSchema->bytes;
|
||||
pCol->node.resType.precision = pProbeTable->pMeta->tableInfo.precision;
|
||||
pCol->node.resType.precision = pProbeTable->pMeta->tableInfo.precision;
|
||||
|
||||
SNode* pFunc = (SNode*)createGroupKeyAggFunc(pCol);
|
||||
|
||||
|
@ -841,7 +841,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
pAgg->isGroupTb = pAgg->pGroupKeys ? keysHasTbname(pAgg->pGroupKeys) : 0;
|
||||
pAgg->isPartTb = pSelect->pPartitionByList ? keysHasTbname(pSelect->pPartitionByList) : 0;
|
||||
pAgg->hasGroup = pAgg->pGroupKeys || pSelect->pPartitionByList;
|
||||
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pAgg;
|
||||
} else {
|
||||
|
@ -1708,6 +1708,7 @@ static int32_t getMsgType(ENodeType sqlType) {
|
|||
switch (sqlType) {
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
|
||||
case QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE:
|
||||
return TDMT_VND_CREATE_TABLE;
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
return TDMT_VND_DROP_TABLE;
|
||||
|
|
|
@ -391,7 +391,7 @@ void qwReleaseTaskCtx(SQWorker *mgmt, void *ctx);
|
|||
int32_t qwKillTaskHandle(SQWTaskCtx *ctx, int32_t rspCode);
|
||||
int32_t qwUpdateTaskStatus(QW_FPARAMS_DEF, int8_t status, bool dynamicTask);
|
||||
int32_t qwDropTask(QW_FPARAMS_DEF);
|
||||
void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx);
|
||||
int32_t qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx);
|
||||
int32_t qwOpenRef(void);
|
||||
void qwSetHbParam(int64_t refId, SQWHbParam **pParam);
|
||||
int32_t qwUpdateTimeInQueue(SQWorker *mgmt, int64_t ts, EQueueType type);
|
||||
|
|
|
@ -173,8 +173,21 @@ int32_t qwDbgBuildAndSendRedirectRsp(int32_t rspType, SRpcHandleInfo *pConn, int
|
|||
|
||||
if (pEpSet) {
|
||||
contLen = tSerializeSEpSet(NULL, 0, pEpSet);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSEpSet failed, code:%x", terrno);
|
||||
return terrno;
|
||||
}
|
||||
rsp = rpcMallocCont(contLen);
|
||||
tSerializeSEpSet(rsp, contLen, pEpSet);
|
||||
if (NULL == rsp) {
|
||||
qError("rpcMallocCont %d failed, code:%x", contLen, terrno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
contLen = tSerializeSEpSet(rsp, contLen, pEpSet);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSEpSet second failed, code:%x", terrno);
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -216,20 +229,20 @@ void qwDbgSimulateRedirect(SQWMsg *qwMsg, SQWTaskCtx *ctx, bool *rsped) {
|
|||
epSet.eps[2].port = 7300;
|
||||
|
||||
ctx->phase = QW_PHASE_POST_QUERY;
|
||||
qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, &epSet);
|
||||
(void)qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, &epSet); // ignore error
|
||||
*rsped = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TDMT_SCH_MERGE_QUERY == qwMsg->msgType && (0 == taosRand() % 3)) {
|
||||
QW_SET_PHASE(ctx, QW_PHASE_POST_QUERY);
|
||||
qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, NULL);
|
||||
(void)qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, NULL); // ignore error
|
||||
*rsped = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((TDMT_SCH_FETCH == qwMsg->msgType) && (0 == taosRand() % 9)) {
|
||||
qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, NULL);
|
||||
(void)qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_SYN_NOT_LEADER, NULL); // ignore error
|
||||
*rsped = true;
|
||||
return;
|
||||
}
|
||||
|
@ -260,8 +273,8 @@ void qwDbgSimulateDead(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *rsped) {
|
|||
|
||||
if (++ignoreTime > 10 && 0 == taosRand() % 9) {
|
||||
if (ctx->fetchMsgType == TDMT_SCH_FETCH) {
|
||||
qwBuildAndSendErrorRsp(TDMT_SCH_LINK_BROKEN, &ctx->ctrlConnInfo, TSDB_CODE_RPC_BROKEN_LINK);
|
||||
qwBuildAndSendErrorRsp(ctx->fetchMsgType + 1, &ctx->dataConnInfo, TSDB_CODE_QRY_TASK_CTX_NOT_EXIST);
|
||||
(void)qwBuildAndSendErrorRsp(TDMT_SCH_LINK_BROKEN, &ctx->ctrlConnInfo, TSDB_CODE_RPC_BROKEN_LINK); // ignore error
|
||||
(void)qwBuildAndSendErrorRsp(ctx->fetchMsgType + 1, &ctx->dataConnInfo, TSDB_CODE_QRY_TASK_CTX_NOT_EXIST); // ignore error
|
||||
*rsped = true;
|
||||
|
||||
taosSsleep(3);
|
||||
|
|
|
@ -105,8 +105,19 @@ int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray *pExecList) {
|
|||
SExplainRsp rsp = {.numOfPlans = taosArrayGetSize(pExecList), .subplanInfo = pInfo};
|
||||
|
||||
int32_t contLen = tSerializeSExplainRsp(NULL, 0, &rsp);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSExplainRsp failed, error: %x", terrno);
|
||||
QW_RET(terrno);
|
||||
}
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
tSerializeSExplainRsp(pRsp, contLen, &rsp);
|
||||
if (NULL == pRsp) {
|
||||
QW_RET(terrno);
|
||||
}
|
||||
contLen = tSerializeSExplainRsp(pRsp, contLen, &rsp);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSExplainRsp second failed, error: %x", terrno);
|
||||
QW_RET(terrno);
|
||||
}
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_SCH_EXPLAIN_RSP,
|
||||
|
@ -123,8 +134,20 @@ int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray *pExecList) {
|
|||
|
||||
int32_t qwBuildAndSendHbRsp(SRpcHandleInfo *pConn, SSchedulerHbRsp *pStatus, int32_t code) {
|
||||
int32_t contLen = tSerializeSSchedulerHbRsp(NULL, 0, pStatus);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSSchedulerHbRsp failed, error: %x", terrno);
|
||||
QW_RET(terrno);
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus);
|
||||
if (NULL == pRsp) {
|
||||
QW_RET(terrno);
|
||||
}
|
||||
contLen = tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus);
|
||||
if (contLen < 0) {
|
||||
qError("tSerializeSSchedulerHbRsp second failed, error: %x", terrno);
|
||||
QW_RET(terrno);
|
||||
}
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_SCH_QUERY_HEARTBEAT_RSP,
|
||||
|
@ -143,6 +166,9 @@ int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieve
|
|||
int32_t code) {
|
||||
if (NULL == pRsp) {
|
||||
pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp));
|
||||
if (NULL == pRsp) {
|
||||
QW_RET(terrno);
|
||||
}
|
||||
memset(pRsp, 0, sizeof(SRetrieveTableRsp));
|
||||
dataLength = 0;
|
||||
}
|
||||
|
@ -164,6 +190,9 @@ int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieve
|
|||
#if 0
|
||||
int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code) {
|
||||
STaskCancelRsp *pRsp = (STaskCancelRsp *)rpcMallocCont(sizeof(STaskCancelRsp));
|
||||
if (NULL == pRsp) {
|
||||
QW_RET(terrno);
|
||||
}
|
||||
pRsp->code = code;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -180,6 +209,9 @@ int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code) {
|
|||
|
||||
int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code) {
|
||||
STaskDropRsp *pRsp = (STaskDropRsp *)rpcMallocCont(sizeof(STaskDropRsp));
|
||||
if (NULL == pRsp) {
|
||||
QW_RET(terrno);
|
||||
}
|
||||
pRsp->code = code;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -405,6 +437,7 @@ int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SSubQueryMsg msg = {0};
|
||||
if (tDeserializeSSubQueryMsg(pMsg->pCont, pMsg->contLen, &msg) < 0) {
|
||||
|
@ -419,8 +452,8 @@ int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
int32_t eId = msg.execId;
|
||||
|
||||
QW_SCH_TASK_DLOG("Abort prerocessQuery start, handle:%p", pMsg->info.handle);
|
||||
qwAbortPrerocessQuery(QW_FPARAMS());
|
||||
QW_SCH_TASK_DLOG("Abort prerocessQuery end, handle:%p", pMsg->info.handle);
|
||||
code = qwAbortPrerocessQuery(QW_FPARAMS());
|
||||
QW_SCH_TASK_DLOG("Abort prerocessQuery end, handle:%p, code:%x", pMsg->info.handle, code);
|
||||
|
||||
tFreeSSubQueryMsg(&msg);
|
||||
|
||||
|
@ -435,7 +468,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
|
|||
int32_t code = 0;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.queryProcessed, 1);
|
||||
|
||||
SSubQueryMsg msg = {0};
|
||||
|
@ -477,7 +510,7 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in
|
|||
SQWTaskCtx *handles = NULL;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.cqueryProcessed, 1);
|
||||
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
|
@ -495,9 +528,9 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in
|
|||
|
||||
QW_SCH_TASK_DLOG("processCQuery start, node:%p, handle:%p", node, pMsg->info.handle);
|
||||
|
||||
QW_ERR_RET(qwProcessCQuery(QW_FPARAMS(), &qwMsg));
|
||||
code = qwProcessCQuery(QW_FPARAMS(), &qwMsg);
|
||||
|
||||
QW_SCH_TASK_DLOG("processCQuery end, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processCQuery end, node:%p, code:0x%x", node, code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -510,7 +543,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
|
|||
SResFetchReq req = {0};
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.fetchProcessed, 1);
|
||||
|
||||
if (tDeserializeSResFetchReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
|
@ -528,9 +561,9 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
|
|||
|
||||
QW_SCH_TASK_DLOG("processFetch start, node:%p, handle:%p", node, pMsg->info.handle);
|
||||
|
||||
QW_ERR_RET(qwProcessFetch(QW_FPARAMS(), &qwMsg));
|
||||
int32_t code = qwProcessFetch(QW_FPARAMS(), &qwMsg);
|
||||
|
||||
QW_SCH_TASK_DLOG("processFetch end, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processFetch end, node:%p, code:%x", node, code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -538,7 +571,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
|
|||
int32_t qWorkerProcessRspMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts) {
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
if (mgmt) {
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.rspProcessed, 1);
|
||||
}
|
||||
|
||||
|
@ -557,7 +590,7 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in
|
|||
int32_t code = 0;
|
||||
STaskCancelReq *msg = pMsg->pCont;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.cancelProcessed, 1);
|
||||
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
|
@ -598,7 +631,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6
|
|||
int32_t code = 0;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.dropProcessed, 1);
|
||||
|
||||
STaskDropReq msg = {0};
|
||||
|
@ -621,9 +654,9 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6
|
|||
|
||||
QW_SCH_TASK_DLOG("processDrop start, node:%p, handle:%p", node, pMsg->info.handle);
|
||||
|
||||
QW_ERR_RET(qwProcessDrop(QW_FPARAMS(), &qwMsg));
|
||||
code = qwProcessDrop(QW_FPARAMS(), &qwMsg);
|
||||
|
||||
QW_SCH_TASK_DLOG("processDrop end, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processDrop end, node:%p, code:%x", node, code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -636,7 +669,7 @@ int32_t qWorkerProcessNotifyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in
|
|||
int32_t code = 0;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.notifyProcessed, 1);
|
||||
|
||||
STaskNotifyReq msg = {0};
|
||||
|
@ -655,9 +688,9 @@ int32_t qWorkerProcessNotifyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in
|
|||
|
||||
QW_SCH_TASK_DLOG("processNotify start, node:%p, handle:%p", node, pMsg->info.handle);
|
||||
|
||||
QW_ERR_RET(qwProcessNotify(QW_FPARAMS(), &qwMsg));
|
||||
code = qwProcessNotify(QW_FPARAMS(), &qwMsg);
|
||||
|
||||
QW_SCH_TASK_DLOG("processNotify end, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processNotify end, node:%p, code:%x", node, code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -672,7 +705,7 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_
|
|||
SSchedulerHbReq req = {0};
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE);
|
||||
QW_ERR_RET(qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE));
|
||||
QW_STAT_INC(mgmt->stat.msgStat.hbProcessed, 1);
|
||||
|
||||
if (NULL == pMsg->pCont) {
|
||||
|
@ -694,9 +727,9 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_
|
|||
|
||||
QW_SCH_DLOG("processHb start, node:%p, handle:%p", node, pMsg->info.handle);
|
||||
|
||||
QW_ERR_RET(qwProcessHb(mgmt, &qwMsg, &req));
|
||||
code = qwProcessHb(mgmt, &qwMsg, &req);
|
||||
|
||||
QW_SCH_DLOG("processHb end, node:%p", node);
|
||||
QW_SCH_DLOG("processHb end, node:%p, code:%x", node, code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -712,7 +745,7 @@ int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SD
|
|||
|
||||
QW_STAT_INC(mgmt->stat.msgStat.deleteProcessed, 1);
|
||||
|
||||
tDeserializeSVDeleteReq(pMsg->pCont, pMsg->contLen, &req);
|
||||
QW_ERR_RET(tDeserializeSVDeleteReq(pMsg->pCont, pMsg->contLen, &req));
|
||||
|
||||
uint64_t sId = req.sId;
|
||||
uint64_t qId = req.queryId;
|
||||
|
|
|
@ -323,34 +323,52 @@ static void freeExplainExecItem(void *param) {
|
|||
|
||||
|
||||
int32_t qwSendExplainResponse(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
qTaskInfo_t taskHandle = ctx->taskHandle;
|
||||
|
||||
ctx->explainRsped = true;
|
||||
|
||||
SArray *execInfoList = taosArrayInit(4, sizeof(SExplainExecInfo));
|
||||
QW_ERR_RET(qGetExplainExecInfo(taskHandle, execInfoList));
|
||||
if (NULL == execInfoList) {
|
||||
QW_ERR_JRET(terrno);
|
||||
}
|
||||
|
||||
QW_ERR_JRET(qGetExplainExecInfo(taskHandle, execInfoList));
|
||||
|
||||
if (ctx->localExec) {
|
||||
SExplainLocalRsp localRsp = {0};
|
||||
localRsp.rsp.numOfPlans = taosArrayGetSize(execInfoList);
|
||||
SExplainExecInfo *pExec = taosMemoryCalloc(localRsp.rsp.numOfPlans, sizeof(SExplainExecInfo));
|
||||
if (NULL == pExec) {
|
||||
QW_ERR_JRET(terrno);
|
||||
}
|
||||
memcpy(pExec, taosArrayGet(execInfoList, 0), localRsp.rsp.numOfPlans * sizeof(SExplainExecInfo));
|
||||
localRsp.rsp.subplanInfo = pExec;
|
||||
localRsp.qId = qId;
|
||||
localRsp.tId = tId;
|
||||
localRsp.rId = rId;
|
||||
localRsp.eId = eId;
|
||||
taosArrayPush(ctx->explainRes, &localRsp);
|
||||
if (NULL == taosArrayPush(ctx->explainRes, &localRsp)) {
|
||||
QW_ERR_JRET(terrno);
|
||||
}
|
||||
|
||||
taosArrayDestroy(execInfoList);
|
||||
execInfoList = NULL;
|
||||
} else {
|
||||
SRpcHandleInfo connInfo = ctx->ctrlConnInfo;
|
||||
connInfo.ahandle = NULL;
|
||||
int32_t code = qwBuildAndSendExplainRsp(&connInfo, execInfoList);
|
||||
taosArrayDestroyEx(execInfoList, freeExplainExecItem);
|
||||
execInfoList = NULL;
|
||||
|
||||
QW_ERR_RET(code);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
|
||||
taosArrayDestroyEx(execInfoList, freeExplainExecItem);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
@ -503,14 +521,18 @@ void qwSetHbParam(int64_t refId, SQWHbParam **pParam) {
|
|||
*pParam = &gQwMgmt.param[paramIdx];
|
||||
}
|
||||
|
||||
void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) {
|
||||
int32_t qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
STbVerInfo tbInfo;
|
||||
int32_t i = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
bool tbGet = false;
|
||||
|
||||
while (true) {
|
||||
if (qGetQueryTableSchemaVersion(pTaskInfo, dbFName, tbName, &tbInfo.sversion, &tbInfo.tversion, i) < 0) {
|
||||
tbGet = false;
|
||||
code = qGetQueryTableSchemaVersion(pTaskInfo, dbFName, tbName, &tbInfo.sversion, &tbInfo.tversion, i, &tbGet);
|
||||
if (TSDB_CODE_SUCCESS != code || !tbGet) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -522,18 +544,25 @@ void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) {
|
|||
|
||||
if (NULL == ctx->tbInfo) {
|
||||
ctx->tbInfo = taosArrayInit(1, sizeof(tbInfo));
|
||||
if (NULL == ctx->tbInfo) {
|
||||
QW_ERR_RET(terrno);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayPush(ctx->tbInfo, &tbInfo);
|
||||
if (NULL == taosArrayPush(ctx->tbInfo, &tbInfo)) {
|
||||
QW_ERR_RET(terrno);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
QW_RET(code);
|
||||
}
|
||||
|
||||
void qwCloseRef(void) {
|
||||
taosWLockLatch(&gQwMgmt.lock);
|
||||
if (atomic_load_32(&gQwMgmt.qwNum) <= 0 && gQwMgmt.qwRef >= 0) {
|
||||
taosCloseRef(gQwMgmt.qwRef);
|
||||
(void)taosCloseRef(gQwMgmt.qwRef); // ignore error
|
||||
gQwMgmt.qwRef = -1;
|
||||
}
|
||||
taosWUnLockLatch(&gQwMgmt.lock);
|
||||
|
@ -550,7 +579,7 @@ void qwDestroyImpl(void *pMgmt) {
|
|||
int32_t schStatusCount = 0;
|
||||
qDebug("start to destroy qworker, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt);
|
||||
|
||||
taosTmrStop(mgmt->hbTimer);
|
||||
(void)taosTmrStop(mgmt->hbTimer); //ignore error
|
||||
mgmt->hbTimer = NULL;
|
||||
taosTmrCleanUp(mgmt->timer);
|
||||
|
||||
|
@ -641,24 +670,33 @@ int64_t qwGetTimeInQueue(SQWorker *mgmt, EQueueType type) {
|
|||
return pStat->num ? (pStat->total / pStat->num) : 0;
|
||||
default:
|
||||
qError("unsupported queue type %d", type);
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void qwClearExpiredSch(SQWorker *mgmt, SArray *pExpiredSch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t num = taosArrayGetSize(pExpiredSch);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
uint64_t *sId = taosArrayGet(pExpiredSch, i);
|
||||
SQWSchStatus *pSch = NULL;
|
||||
if (qwAcquireScheduler(mgmt, *sId, QW_WRITE, &pSch)) {
|
||||
if (NULL == sId) {
|
||||
qError("get the %dth sch failed, code:%x", i, terrno);
|
||||
break;
|
||||
}
|
||||
|
||||
code = qwAcquireScheduler(mgmt, *sId, QW_WRITE, &pSch);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
qError("acquire sch %" PRIx64 " failed, code:%x", *sId, code);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (taosHashGetSize(pSch->tasksHash) <= 0) {
|
||||
qwDestroySchStatus(pSch);
|
||||
taosHashRemove(mgmt->schHash, sId, sizeof(*sId));
|
||||
qDebug("sch %" PRIx64 " destroyed", *sId);
|
||||
code = taosHashRemove(mgmt->schHash, sId, sizeof(*sId));
|
||||
qDebug("sch %" PRIx64 " destroy result code:%x", *sId, code);
|
||||
}
|
||||
|
||||
qwReleaseScheduler(QW_WRITE, mgmt);
|
||||
|
|
|
@ -18,10 +18,11 @@ SQWorkerMgmt gQwMgmt = {
|
|||
.qwNum = 0,
|
||||
};
|
||||
|
||||
int32_t qwStopAllTasks(SQWorker *mgmt) {
|
||||
void qwStopAllTasks(SQWorker *mgmt) {
|
||||
uint64_t qId, tId, sId;
|
||||
int32_t eId;
|
||||
int64_t rId = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
void *pIter = taosHashIterate(mgmt->ctxHash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -44,22 +45,29 @@ int32_t qwStopAllTasks(SQWorker *mgmt) {
|
|||
}
|
||||
|
||||
if (QW_QUERY_RUNNING(ctx)) {
|
||||
qwKillTaskHandle(ctx, TSDB_CODE_VND_STOPPED);
|
||||
QW_TASK_DLOG_E("task running, async killed");
|
||||
code = qwKillTaskHandle(ctx, TSDB_CODE_VND_STOPPED);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("task running, async kill failed, error: %x", code);
|
||||
} else {
|
||||
QW_TASK_DLOG_E("task running, async killed");
|
||||
}
|
||||
} else if (QW_FETCH_RUNNING(ctx)) {
|
||||
QW_UPDATE_RSP_CODE(ctx, TSDB_CODE_VND_STOPPED);
|
||||
QW_SET_EVENT_RECEIVED(ctx, QW_EVENT_DROP);
|
||||
QW_TASK_DLOG_E("task fetching, update drop received");
|
||||
} else {
|
||||
qwDropTask(QW_FPARAMS());
|
||||
code = qwDropTask(QW_FPARAMS());
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("task drop failed, error: %x", code);
|
||||
} else {
|
||||
QW_TASK_DLOG_E("task dropped");
|
||||
}
|
||||
}
|
||||
|
||||
QW_UNLOCK(QW_WRITE, &ctx->lock);
|
||||
|
||||
pIter = taosHashIterate(mgmt->ctxHash, pIter);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwProcessHbLinkBroken(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) {
|
||||
|
@ -111,7 +119,7 @@ int32_t qwHandleTaskComplete(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
|||
int32_t qwSendQueryRsp(QW_FPARAMS_DEF, int32_t msgType, SQWTaskCtx *ctx, int32_t rspCode, bool quickRsp) {
|
||||
if ((!quickRsp) || QUERY_RSP_POLICY_QUICK == tsQueryRspPolicy) {
|
||||
if (!ctx->localExec) {
|
||||
qwBuildAndSendQueryRsp(msgType, &ctx->ctrlConnInfo, rspCode, ctx);
|
||||
QW_ERR_RET(qwBuildAndSendQueryRsp(msgType, &ctx->ctrlConnInfo, rspCode, ctx));
|
||||
QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", ctx->ctrlConnInfo.handle, rspCode, tstrerror(rspCode));
|
||||
}
|
||||
|
||||
|
@ -140,6 +148,10 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) {
|
|||
}
|
||||
|
||||
SArray *pResList = taosArrayInit(4, POINTER_BYTES);
|
||||
if (NULL == pResList) {
|
||||
QW_ERR_RET(terrno);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
QW_TASK_DLOG("start to execTask, loopIdx:%d", i++);
|
||||
|
||||
|
@ -165,6 +177,9 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) {
|
|||
size_t numOfResBlock = taosArrayGetSize(pResList);
|
||||
for (int32_t j = 0; j < numOfResBlock; ++j) {
|
||||
SSDataBlock *pRes = taosArrayGetP(pResList, j);
|
||||
if (NULL == pRes) {
|
||||
QW_ERR_JRET(TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SInputData inputData = {.pData = pRes};
|
||||
code = dsPutDataBlock(sinkHandle, &inputData, &qcontinue);
|
||||
|
@ -226,7 +241,9 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) {
|
|||
}
|
||||
|
||||
_return:
|
||||
|
||||
taosArrayDestroy(pResList);
|
||||
|
||||
QW_RET(code);
|
||||
}
|
||||
|
||||
|
@ -241,7 +258,8 @@ bool qwTaskNotInExec(SQWTaskCtx *ctx) {
|
|||
|
||||
int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) {
|
||||
int32_t taskNum = 0;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
hbInfo->connInfo = sch->hbConnInfo;
|
||||
hbInfo->rsp.epId = sch->hbEpId;
|
||||
|
||||
|
@ -272,7 +290,11 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo)
|
|||
status.status = taskStatus->status;
|
||||
status.refId = taskStatus->refId;
|
||||
|
||||
taosArrayPush(hbInfo->rsp.taskStatus, &status);
|
||||
if (NULL == taosArrayPush(hbInfo->rsp.taskStatus, &status)) {
|
||||
taosHashCancelIterate(sch->tasksHash, pIter);
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
|
||||
++i;
|
||||
pIter = taosHashIterate(sch->tasksHash, pIter);
|
||||
|
@ -280,7 +302,7 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo)
|
|||
|
||||
QW_UNLOCK(QW_READ, &sch->tasksLock);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, int32_t *pRawDataLen, void **rspMsg,
|
||||
|
@ -320,7 +342,7 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen,
|
|||
pOutput->numOfRows);
|
||||
|
||||
if (!ctx->dynamicTask) {
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask);
|
||||
QW_ERR_RET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask));
|
||||
}
|
||||
|
||||
if (NULL == pRsp) {
|
||||
|
@ -375,7 +397,7 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen,
|
|||
if (DS_BUF_EMPTY == pOutput->bufStatus && pOutput->queryEnd) {
|
||||
QW_TASK_DLOG("task all data fetched and done, fetched blocks %d rows %" PRId64, pOutput->numOfBlocks,
|
||||
pOutput->numOfRows);
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask);
|
||||
QW_ERR_RET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -464,7 +486,7 @@ int32_t qwQuickRspFetchReq(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SQWMsg *qwMsg, int32
|
|||
qwMsg->connInfo = ctx->dataConnInfo;
|
||||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
|
||||
|
||||
qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code);
|
||||
QW_ERR_RET(qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code));
|
||||
rsp = NULL;
|
||||
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
|
||||
|
@ -650,7 +672,7 @@ int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inp
|
|||
_return:
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && QW_PHASE_POST_QUERY == phase) {
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_PART_SUCC, ctx->dynamicTask);
|
||||
code = qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_PART_SUCC, ctx->dynamicTask);
|
||||
ctx->queryGotData = true;
|
||||
}
|
||||
|
||||
|
@ -660,7 +682,10 @@ _return:
|
|||
qwDbgSimulateRedirect(&qwMsg, ctx, &rsped);
|
||||
qwDbgSimulateDead(QW_FPARAMS(), ctx, &rsped);
|
||||
if (!rsped) {
|
||||
qwSendQueryRsp(QW_FPARAMS(), input->msgType + 1, ctx, code, false);
|
||||
int32_t newCode = qwSendQueryRsp(QW_FPARAMS(), input->msgType + 1, ctx, code, false);
|
||||
if (TSDB_CODE_SUCCESS != newCode && TSDB_CODE_SUCCESS == code) {
|
||||
code = newCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -672,7 +697,7 @@ _return:
|
|||
}
|
||||
|
||||
if (code) {
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask);
|
||||
(void)qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask); // already in error, ignore new error
|
||||
}
|
||||
|
||||
QW_UNLOCK(QW_WRITE, &ctx->lock);
|
||||
|
@ -687,11 +712,11 @@ _return:
|
|||
int32_t qwAbortPrerocessQuery(QW_FPARAMS_DEF) {
|
||||
QW_ERR_RET(qwDropTask(QW_FPARAMS()));
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
||||
int32_t code = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
|
||||
QW_ERR_JRET(qwRegisterQueryBrokenLinkArg(QW_FPARAMS(), &qwMsg->connInfo));
|
||||
|
@ -706,7 +731,7 @@ int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
|
||||
QW_ERR_JRET(qwAddTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_INIT));
|
||||
|
||||
qwSendQueryRsp(QW_FPARAMS(), qwMsg->msgType + 1, ctx, code, true);
|
||||
QW_ERR_JRET(qwSendQueryRsp(QW_FPARAMS(), qwMsg->msgType + 1, ctx, code, true));
|
||||
|
||||
_return:
|
||||
|
||||
|
@ -715,7 +740,7 @@ _return:
|
|||
qwReleaseTaskCtx(mgmt, ctx);
|
||||
}
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql) {
|
||||
|
@ -761,7 +786,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql) {
|
|||
atomic_store_ptr(&ctx->taskHandle, pTaskInfo);
|
||||
atomic_store_ptr(&ctx->sinkHandle, sinkHandle);
|
||||
|
||||
qwSaveTbVersionInfo(pTaskInfo, ctx);
|
||||
QW_ERR_JRET(qwSaveTbVersionInfo(pTaskInfo, ctx));
|
||||
|
||||
if (!ctx->dynamicTask) {
|
||||
QW_ERR_JRET(qwExecTask(QW_FPARAMS(), ctx, NULL));
|
||||
|
@ -778,7 +803,7 @@ _return:
|
|||
input.msgType = qwMsg->msgType;
|
||||
code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL);
|
||||
|
||||
qwQuickRspFetchReq(QW_FPARAMS(), ctx, qwMsg, code);
|
||||
QW_ERR_RET(qwQuickRspFetchReq(QW_FPARAMS(), ctx, qwMsg, code));
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
@ -829,7 +854,7 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
qwMsg->connInfo = ctx->dataConnInfo;
|
||||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
|
||||
|
||||
qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code);
|
||||
QW_ERR_JRET(qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code));
|
||||
rsp = NULL;
|
||||
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code,
|
||||
|
@ -851,9 +876,14 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
rsp = NULL;
|
||||
|
||||
qwMsg->connInfo = ctx->dataConnInfo;
|
||||
qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, NULL, 0, code);
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
|
||||
0);
|
||||
code = qwBuildAndSendFetchRsp(ctx->fetchMsgType + 1, &qwMsg->connInfo, NULL, 0, code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("fetch rsp send fail, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
|
||||
0);
|
||||
} else {
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
QW_LOCK(QW_WRITE, &ctx->lock);
|
||||
|
@ -869,7 +899,7 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
} while (true);
|
||||
|
||||
input.code = code;
|
||||
qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_CQUERY, &input, NULL);
|
||||
QW_ERR_RET(qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_CQUERY, &input, NULL));
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
@ -922,7 +952,7 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
} else if (QW_QUERY_RUNNING(ctx)) {
|
||||
atomic_store_8((int8_t *)&ctx->queryContinue, 1);
|
||||
} else if (0 == atomic_load_8((int8_t *)&ctx->queryInQueue)) {
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC, ctx->dynamicTask);
|
||||
QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC, ctx->dynamicTask));
|
||||
atomic_store_8((int8_t *)&ctx->queryInQueue, 1);
|
||||
|
||||
QW_ERR_JRET(qwBuildAndSendCQueryMsg(QW_FPARAMS(), &qwMsg->connInfo));
|
||||
|
@ -952,9 +982,14 @@ _return:
|
|||
}
|
||||
|
||||
if (!rsped) {
|
||||
qwBuildAndSendFetchRsp(qwMsg->msgType + 1, &qwMsg->connInfo, rsp, dataLen, code);
|
||||
QW_TASK_DLOG("fetch rsp send, msgType:%s, handle:%p, code:%x - %s, dataLen:%d", TMSG_INFO(qwMsg->msgType + 1),
|
||||
qwMsg->connInfo.handle, code, tstrerror(code), dataLen);
|
||||
code = qwBuildAndSendFetchRsp(qwMsg->msgType + 1, &qwMsg->connInfo, rsp, dataLen, code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("fetch rsp send fail, msgType:%s, handle:%p, code:%x - %s, dataLen:%d", TMSG_INFO(qwMsg->msgType + 1),
|
||||
qwMsg->connInfo.handle, code, tstrerror(code), dataLen);
|
||||
} else {
|
||||
QW_TASK_DLOG("fetch rsp send, msgType:%s, handle:%p, code:%x - %s, dataLen:%d", TMSG_INFO(qwMsg->msgType + 1),
|
||||
qwMsg->connInfo.handle, code, tstrerror(code), dataLen);
|
||||
}
|
||||
} else {
|
||||
qwFreeFetchRsp(rsp);
|
||||
rsp = NULL;
|
||||
|
@ -985,7 +1020,7 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
|
||||
if (QW_QUERY_RUNNING(ctx)) {
|
||||
QW_ERR_JRET(qwKillTaskHandle(ctx, TSDB_CODE_TSC_QUERY_CANCELLED));
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROP, ctx->dynamicTask);
|
||||
QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROP, ctx->dynamicTask));
|
||||
} else {
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
dropped = true;
|
||||
|
@ -1001,7 +1036,7 @@ _return:
|
|||
if (code) {
|
||||
if (ctx) {
|
||||
QW_UPDATE_RSP_CODE(ctx, code);
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask);
|
||||
(void)qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask); // task already failed, no more error handling
|
||||
} else {
|
||||
tmsgReleaseHandle(&qwMsg->connInfo, TAOS_CONN_SERVER);
|
||||
}
|
||||
|
@ -1035,7 +1070,7 @@ int32_t qwProcessNotify(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
|
||||
if (QW_QUERY_RUNNING(ctx)) {
|
||||
QW_ERR_JRET(qwKillTaskHandle(ctx, TSDB_CODE_TSC_QUERY_CANCELLED));
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask);
|
||||
QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCC, ctx->dynamicTask));
|
||||
}
|
||||
|
||||
switch (qwMsg->msgType) {
|
||||
|
@ -1055,7 +1090,7 @@ _return:
|
|||
if (code) {
|
||||
if (ctx) {
|
||||
QW_UPDATE_RSP_CODE(ctx, code);
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask);
|
||||
(void)qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_FAIL, ctx->dynamicTask); // task already failed, no more error handling
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1139,7 @@ int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) {
|
|||
_return:
|
||||
|
||||
memcpy(&rsp.epId, &req->epId, sizeof(req->epId));
|
||||
qwBuildAndSendHbRsp(&qwMsg->connInfo, &rsp, code);
|
||||
code = qwBuildAndSendHbRsp(&qwMsg->connInfo, &rsp, code);
|
||||
|
||||
if (code) {
|
||||
tmsgReleaseHandle(&qwMsg->connInfo, TAOS_CONN_SERVER);
|
||||
|
@ -1125,7 +1160,7 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
|||
int64_t refId = hbParam->refId;
|
||||
SQWorker *mgmt = qwAcquire(refId);
|
||||
if (NULL == mgmt) {
|
||||
QW_DLOG("qwAcquire %" PRIx64 "failed", refId);
|
||||
QW_DLOG("qwAcquire %" PRIx64 "failed, code:0x%x", refId, terrno);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1172,7 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
|||
qwDbgDumpMgmtInfo(mgmt);
|
||||
|
||||
if (gQWDebug.forceStop) {
|
||||
(void)qwStopAllTasks(mgmt);
|
||||
qwStopAllTasks(mgmt);
|
||||
}
|
||||
|
||||
QW_LOCK(QW_READ, &mgmt->schLock);
|
||||
|
@ -1145,8 +1180,8 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
|||
int32_t schNum = taosHashGetSize(mgmt->schHash);
|
||||
if (schNum <= 0) {
|
||||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer);
|
||||
qwRelease(refId);
|
||||
(void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error
|
||||
(void)qwRelease(refId); // ignore error
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1156,9 +1191,9 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
|||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
taosMemoryFree(rspList);
|
||||
taosArrayDestroy(pExpiredSch);
|
||||
QW_ELOG("calloc %d SQWHbInfo failed", schNum);
|
||||
taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer);
|
||||
qwRelease(refId);
|
||||
QW_ELOG("calloc %d SQWHbInfo failed, code:%x", schNum, terrno);
|
||||
(void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error
|
||||
(void)qwRelease(refId); // ignore error
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1174,7 +1209,11 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
|||
|
||||
if (sch1->hbBrokenTs > 0 && ((currentMs - sch1->hbBrokenTs) > QW_SCH_TIMEOUT_MSEC) &&
|
||||
taosHashGetSize(sch1->tasksHash) <= 0) {
|
||||
taosArrayPush(pExpiredSch, sId);
|
||||
if (NULL == taosArrayPush(pExpiredSch, sId)) {
|
||||
QW_ELOG("add sId 0x%" PRIx64 " to expiredSch failed, code:%x", *sId, terrno);
|
||||
taosHashCancelIterate(mgmt->schHash, pIter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(mgmt->schHash, pIter);
|
||||
|
@ -1196,7 +1235,7 @@ _return:
|
|||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
for (int32_t j = 0; j < i; ++j) {
|
||||
qwBuildAndSendHbRsp(&rspList[j].connInfo, &rspList[j].rsp, code);
|
||||
(void)qwBuildAndSendHbRsp(&rspList[j].connInfo, &rspList[j].rsp, code); // ignore error
|
||||
/*QW_DLOG("hb rsp send, handle:%p, code:%x - %s, taskNum:%d", rspList[j].connInfo.handle, code, tstrerror(code),*/
|
||||
/*(rspList[j].rsp.taskStatus ? (int32_t)taosArrayGetSize(rspList[j].rsp.taskStatus) : 0));*/
|
||||
tFreeSSchedulerHbRsp(&rspList[j].rsp);
|
||||
|
@ -1209,8 +1248,8 @@ _return:
|
|||
taosMemoryFreeClear(rspList);
|
||||
taosArrayDestroy(pExpiredSch);
|
||||
|
||||
taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer);
|
||||
qwRelease(refId);
|
||||
(void)taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); // ignore error
|
||||
(void)qwRelease(refId); // ignore error
|
||||
}
|
||||
|
||||
int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SDeleteRes *pRes) {
|
||||
|
@ -1333,7 +1372,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const S
|
|||
_return:
|
||||
|
||||
if (mgmt->refId >= 0) {
|
||||
qwRelease(mgmt->refId);
|
||||
(void)qwRelease(mgmt->refId); // ignore error
|
||||
} else {
|
||||
taosHashCleanup(mgmt->schHash);
|
||||
taosHashCleanup(mgmt->ctxHash);
|
||||
|
@ -1353,7 +1392,7 @@ void qWorkerStopAllTasks(void *qWorkerMgmt) {
|
|||
|
||||
atomic_store_8(&mgmt->nodeStopped, 1);
|
||||
|
||||
(void)qwStopAllTasks(mgmt);
|
||||
qwStopAllTasks(mgmt);
|
||||
}
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt) {
|
||||
|
@ -1383,7 +1422,7 @@ int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pSt
|
|||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SDataSinkStat sinkStat = {0};
|
||||
|
||||
dsDataSinkGetCacheSize(&sinkStat);
|
||||
QW_ERR_RET(dsDataSinkGetCacheSize(&sinkStat));
|
||||
pStat->cacheDataSize = sinkStat.cachedSize;
|
||||
|
||||
pStat->queryProcessed = QW_STAT_GET(mgmt->stat.msgStat.queryProcessed);
|
||||
|
@ -1427,6 +1466,10 @@ int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64
|
|||
ctx->explainRes = explainRes;
|
||||
|
||||
rHandle.pMsgCb = taosMemoryCalloc(1, sizeof(SMsgCb));
|
||||
if (NULL == rHandle.pMsgCb) {
|
||||
QW_ERR_JRET(terrno);
|
||||
}
|
||||
|
||||
rHandle.pMsgCb->clientRpc = qwMsg->connInfo.handle;
|
||||
|
||||
code = qCreateExecTask(&rHandle, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, 0, NULL, OPTR_EXEC_MODEL_BATCH);
|
||||
|
|
|
@ -130,30 +130,32 @@ void qwtBuildFetchReqMsg(SResFetchReq *fetchMsg, SRpcMsg *fetchRpc) {
|
|||
fetchRpc->contLen = sizeof(SResFetchReq);
|
||||
}
|
||||
|
||||
void qwtBuildDropReqMsg(STaskDropReq *dropMsg, SRpcMsg *dropRpc) {
|
||||
int qwtBuildDropReqMsg(STaskDropReq *dropMsg, SRpcMsg *dropRpc) {
|
||||
dropMsg->sId = 1;
|
||||
dropMsg->queryId = atomic_load_64(&qwtTestQueryId);
|
||||
dropMsg->taskId = 1;
|
||||
|
||||
int32_t msgSize = tSerializeSTaskDropReq(NULL, 0, dropMsg);
|
||||
if (msgSize < 0) {
|
||||
return;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char *msg = (char*)taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
return;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tSerializeSTaskDropReq(msg, msgSize, dropMsg) < 0) {
|
||||
taosMemoryFree(msg);
|
||||
return;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
||||
dropRpc->msgType = TDMT_SCH_DROP_TASK;
|
||||
dropRpc->pCont = msg;
|
||||
dropRpc->contLen = msgSize;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwtStringToPlan(const char *str, SSubplan **subplan) {
|
||||
|
@ -164,6 +166,10 @@ int32_t qwtStringToPlan(const char *str, SSubplan **subplan) {
|
|||
int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) {
|
||||
taosWLockLatch(&qwtTestFetchQueueLock);
|
||||
struct SRpcMsg *newMsg = (struct SRpcMsg *)taosMemoryCalloc(1, sizeof(struct SRpcMsg));
|
||||
if (NULL == newMsg) {
|
||||
printf("malloc failed");
|
||||
assert(0);
|
||||
}
|
||||
memcpy(newMsg, pMsg, sizeof(struct SRpcMsg));
|
||||
qwtTestFetchQueue[qwtTestFetchQueueWIdx++] = newMsg;
|
||||
if (qwtTestFetchQueueWIdx >= qwtTestFetchQueueSize) {
|
||||
|
@ -178,7 +184,10 @@ int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) {
|
|||
}
|
||||
taosWUnLockLatch(&qwtTestFetchQueueLock);
|
||||
|
||||
tsem_post(&qwtTestFetchSem);
|
||||
if (tsem_post(&qwtTestFetchSem) < 0) {
|
||||
printf("tsem_post failed, errno:%d", errno);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -186,6 +195,10 @@ int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) {
|
|||
int32_t qwtPutReqToQueue(void *node, EQueueType qtype, struct SRpcMsg *pMsg) {
|
||||
taosWLockLatch(&qwtTestQueryQueueLock);
|
||||
struct SRpcMsg *newMsg = (struct SRpcMsg *)taosMemoryCalloc(1, sizeof(struct SRpcMsg));
|
||||
if (NULL == newMsg) {
|
||||
printf("malloc failed");
|
||||
assert(0);
|
||||
}
|
||||
memcpy(newMsg, pMsg, sizeof(struct SRpcMsg));
|
||||
qwtTestQueryQueue[qwtTestQueryQueueWIdx++] = newMsg;
|
||||
if (qwtTestQueryQueueWIdx >= qwtTestQueryQueueSize) {
|
||||
|
@ -200,22 +213,34 @@ int32_t qwtPutReqToQueue(void *node, EQueueType qtype, struct SRpcMsg *pMsg) {
|
|||
}
|
||||
taosWUnLockLatch(&qwtTestQueryQueueLock);
|
||||
|
||||
tsem_post(&qwtTestQuerySem);
|
||||
if (tsem_post(&qwtTestQuerySem) < 0) {
|
||||
printf("tsem_post failed, errno:%d", errno);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qwtSendReqToDnode(void *pVnode, struct SEpSet *epSet, struct SRpcMsg *pReq) {}
|
||||
|
||||
void qwtRpcSendResponse(const SRpcMsg *pRsp) {
|
||||
int qwtRpcSendResponse(const SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
switch (pRsp->msgType) {
|
||||
case TDMT_SCH_QUERY_RSP:
|
||||
case TDMT_SCH_MERGE_QUERY_RSP: {
|
||||
SQueryTableRsp *rsp = (SQueryTableRsp *)pRsp->pCont;
|
||||
|
||||
if (pRsp->code) {
|
||||
qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc);
|
||||
qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc);
|
||||
code = qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc);
|
||||
if (code) {
|
||||
assert(0);
|
||||
return code;
|
||||
}
|
||||
code = qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc);
|
||||
if (code) {
|
||||
assert(0);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(rsp);
|
||||
|
@ -227,13 +252,25 @@ void qwtRpcSendResponse(const SRpcMsg *pRsp) {
|
|||
|
||||
if (0 == pRsp->code && 0 == rsp->completed) {
|
||||
qwtBuildFetchReqMsg(&qwtfetchMsg, &qwtfetchRpc);
|
||||
qwtPutReqToFetchQueue((void *)0x1, &qwtfetchRpc);
|
||||
code = qwtPutReqToFetchQueue((void *)0x1, &qwtfetchRpc);
|
||||
if (code) {
|
||||
assert(0);
|
||||
return code;
|
||||
}
|
||||
rpcFreeCont(rsp);
|
||||
return;
|
||||
return code;
|
||||
}
|
||||
|
||||
qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc);
|
||||
qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc);
|
||||
code = qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc);
|
||||
if (code) {
|
||||
assert(0);
|
||||
return code;
|
||||
}
|
||||
code = qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc);
|
||||
if (code) {
|
||||
assert(0);
|
||||
return code;
|
||||
}
|
||||
rpcFreeCont(rsp);
|
||||
|
||||
break;
|
||||
|
@ -245,9 +282,11 @@ void qwtRpcSendResponse(const SRpcMsg *pRsp) {
|
|||
qwtTestCaseFinished = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qwtCreateExecTask(void *tsdb, int32_t vgId, uint64_t taskId, struct SSubplan *pPlan, qTaskInfo_t *pTaskInfo,
|
||||
|
@ -292,6 +331,9 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock **pRes, uint64_t *useconds) {
|
|||
|
||||
if (endExec) {
|
||||
*pRes = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
if (NULL == *pRes) {
|
||||
return terrno;
|
||||
}
|
||||
(*pRes)->info.rows = taosRand() % 1000 + 1;
|
||||
} else {
|
||||
*pRes = NULL;
|
||||
|
@ -631,7 +673,7 @@ void *queryThread(void *param) {
|
|||
|
||||
while (!qwtTestStop) {
|
||||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0);
|
||||
(void)qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); // ignore error
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(taosRand() % 5);
|
||||
}
|
||||
|
@ -653,7 +695,7 @@ void *fetchThread(void *param) {
|
|||
|
||||
while (!qwtTestStop) {
|
||||
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
|
||||
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0);
|
||||
(void)qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0); // ignore error
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(taosRand() % 5);
|
||||
}
|
||||
|
@ -674,8 +716,11 @@ void *dropThread(void *param) {
|
|||
STaskDropReq dropMsg = {0};
|
||||
|
||||
while (!qwtTestStop) {
|
||||
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
|
||||
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0);
|
||||
if (0 != qwtBuildDropReqMsg(&dropMsg, &dropRpc)) {
|
||||
break;
|
||||
}
|
||||
(void)qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0); // ignore error
|
||||
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(taosRand() % 5);
|
||||
}
|
||||
|
@ -700,7 +745,7 @@ void *qwtclientThread(void *param) {
|
|||
qwtTestCaseFinished = false;
|
||||
|
||||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
qwtPutReqToQueue((void *)0x1, QUERY_QUEUE, &queryRpc);
|
||||
(void)qwtPutReqToQueue((void *)0x1, QUERY_QUEUE, &queryRpc); //ignore error
|
||||
|
||||
while (!qwtTestCaseFinished) {
|
||||
taosUsleep(1);
|
||||
|
@ -752,9 +797,9 @@ void *queryQueueThread(void *param) {
|
|||
}
|
||||
|
||||
if (TDMT_SCH_QUERY == queryRpc->msgType) {
|
||||
qWorkerProcessQueryMsg(mockPointer, mgmt, queryRpc, 0);
|
||||
(void)qWorkerProcessQueryMsg(mockPointer, mgmt, queryRpc, 0); //ignore error
|
||||
} else if (TDMT_SCH_QUERY_CONTINUE == queryRpc->msgType) {
|
||||
qWorkerProcessCQueryMsg(mockPointer, mgmt, queryRpc, 0);
|
||||
(void)qWorkerProcessCQueryMsg(mockPointer, mgmt, queryRpc, 0); //ignore error
|
||||
} else {
|
||||
printf("unknown msg in query queue, type:%d\n", queryRpc->msgType);
|
||||
assert(0);
|
||||
|
@ -810,16 +855,16 @@ void *fetchQueueThread(void *param) {
|
|||
switch (fetchRpc->msgType) {
|
||||
case TDMT_SCH_FETCH:
|
||||
case TDMT_SCH_MERGE_FETCH:
|
||||
qWorkerProcessFetchMsg(mockPointer, mgmt, fetchRpc, 0);
|
||||
(void)qWorkerProcessFetchMsg(mockPointer, mgmt, fetchRpc, 0); //ignore error
|
||||
break;
|
||||
case TDMT_SCH_CANCEL_TASK:
|
||||
//qWorkerProcessCancelMsg(mockPointer, mgmt, fetchRpc, 0);
|
||||
break;
|
||||
case TDMT_SCH_DROP_TASK:
|
||||
qWorkerProcessDropMsg(mockPointer, mgmt, fetchRpc, 0);
|
||||
(void)qWorkerProcessDropMsg(mockPointer, mgmt, fetchRpc, 0); //ignore error
|
||||
break;
|
||||
case TDMT_SCH_TASK_NOTIFY:
|
||||
qWorkerProcessNotifyMsg(mockPointer, mgmt, fetchRpc, 0);
|
||||
(void)qWorkerProcessNotifyMsg(mockPointer, mgmt, fetchRpc, 0); //ignore error
|
||||
break;
|
||||
default:
|
||||
printf("unknown msg type:%d in fetch queue", fetchRpc->msgType);
|
||||
|
@ -853,7 +898,7 @@ TEST(seqTest, normalCase) {
|
|||
|
||||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
qwtBuildFetchReqMsg(&qwtfetchMsg, &fetchRpc);
|
||||
qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc);
|
||||
(void)qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc); //ignore error
|
||||
|
||||
stubSetStringToPlan();
|
||||
stubSetRpcSendResponse();
|
||||
|
@ -898,7 +943,7 @@ TEST(seqTest, cancelFirst) {
|
|||
qwtInitLogFile();
|
||||
|
||||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc);
|
||||
(void)qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc); //ignore error
|
||||
|
||||
stubSetStringToPlan();
|
||||
stubSetRpcSendResponse();
|
||||
|
@ -954,7 +999,7 @@ TEST(seqTest, randCase) {
|
|||
if (r >= 0 && r < maxr / 5) {
|
||||
printf("Query,%d\n", t++);
|
||||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0);
|
||||
(void)qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); //ignore error
|
||||
} else if (r >= maxr / 5 && r < maxr * 2 / 5) {
|
||||
// printf("Ready,%d\n", t++);
|
||||
// qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
|
||||
|
@ -965,14 +1010,14 @@ TEST(seqTest, randCase) {
|
|||
} else if (r >= maxr * 2 / 5 && r < maxr * 3 / 5) {
|
||||
printf("Fetch,%d\n", t++);
|
||||
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
|
||||
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0);
|
||||
(void)qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0); //ignore error
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(1);
|
||||
}
|
||||
} else if (r >= maxr * 3 / 5 && r < maxr * 4 / 5) {
|
||||
printf("Drop,%d\n", t++);
|
||||
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
|
||||
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0);
|
||||
(void)qwtBuildDropReqMsg(&dropMsg, &dropRpc); //ignore error
|
||||
(void)qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0); //ignore error
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(1);
|
||||
}
|
||||
|
@ -1018,14 +1063,14 @@ TEST(seqTest, multithreadRand) {
|
|||
ASSERT_EQ(code, 0);
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
(void)taosThreadAttrInit(&thattr); //ignore error
|
||||
|
||||
TdThread t1, t2, t3, t4, t5, t6;
|
||||
taosThreadCreate(&(t1), &thattr, queryThread, mgmt);
|
||||
// taosThreadCreate(&(t2), &thattr, readyThread, NULL);
|
||||
taosThreadCreate(&(t3), &thattr, fetchThread, NULL);
|
||||
taosThreadCreate(&(t4), &thattr, dropThread, NULL);
|
||||
taosThreadCreate(&(t6), &thattr, fetchQueueThread, mgmt);
|
||||
(void)taosThreadCreate(&(t1), &thattr, queryThread, mgmt); //ignore error
|
||||
// (void)taosThreadCreate(&(t2), &thattr, readyThread, NULL); //ignore error
|
||||
(void)taosThreadCreate(&(t3), &thattr, fetchThread, NULL); //ignore error
|
||||
(void)taosThreadCreate(&(t4), &thattr, dropThread, NULL); //ignore error
|
||||
(void)taosThreadCreate(&(t6), &thattr, fetchQueueThread, mgmt); //ignore error
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1083,16 +1128,16 @@ TEST(rcTest, shortExecshortDelay) {
|
|||
qwtTestMaxExecTaskUsec = 0;
|
||||
qwtTestReqMaxDelayUsec = 0;
|
||||
|
||||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
(void)tsem_init(&qwtTestQuerySem, 0, 0); //ignore error
|
||||
(void)tsem_init(&qwtTestFetchSem, 0, 0); //ignore error
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
(void)taosThreadAttrInit(&thattr); //ignore error
|
||||
|
||||
TdThread t1, t2, t3, t4, t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
(void)taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); //ignore error
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1114,8 +1159,8 @@ TEST(rcTest, shortExecshortDelay) {
|
|||
|
||||
if (qwtTestCaseFinished) {
|
||||
if (qwtTestQuitThreadNum < 3) {
|
||||
tsem_post(&qwtTestQuerySem);
|
||||
tsem_post(&qwtTestFetchSem);
|
||||
(void)tsem_post(&qwtTestQuerySem); //ignore error
|
||||
(void)tsem_post(&qwtTestFetchSem); //ignore error
|
||||
|
||||
taosUsleep(10);
|
||||
}
|
||||
|
@ -1166,16 +1211,16 @@ TEST(rcTest, longExecshortDelay) {
|
|||
qwtTestMaxExecTaskUsec = 1000000;
|
||||
qwtTestReqMaxDelayUsec = 0;
|
||||
|
||||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
(void)tsem_init(&qwtTestQuerySem, 0, 0); //ignore error
|
||||
(void)tsem_init(&qwtTestFetchSem, 0, 0); //ignore error
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
(void)taosThreadAttrInit(&thattr); //ignore error
|
||||
|
||||
TdThread t1, t2, t3, t4, t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
(void)taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); //ignore error
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1197,8 +1242,8 @@ TEST(rcTest, longExecshortDelay) {
|
|||
|
||||
if (qwtTestCaseFinished) {
|
||||
if (qwtTestQuitThreadNum < 3) {
|
||||
tsem_post(&qwtTestQuerySem);
|
||||
tsem_post(&qwtTestFetchSem);
|
||||
(void)tsem_post(&qwtTestQuerySem); //ignore error
|
||||
(void)tsem_post(&qwtTestFetchSem); //ignore error
|
||||
|
||||
taosUsleep(10);
|
||||
}
|
||||
|
@ -1249,16 +1294,16 @@ TEST(rcTest, shortExeclongDelay) {
|
|||
qwtTestMaxExecTaskUsec = 0;
|
||||
qwtTestReqMaxDelayUsec = 1000000;
|
||||
|
||||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
(void)tsem_init(&qwtTestQuerySem, 0, 0); //ignore error
|
||||
(void)tsem_init(&qwtTestFetchSem, 0, 0); //ignore error
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
(void)taosThreadAttrInit(&thattr); //ignore error
|
||||
|
||||
TdThread t1, t2, t3, t4, t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
(void)taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); //ignore error
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
@ -1280,8 +1325,8 @@ TEST(rcTest, shortExeclongDelay) {
|
|||
|
||||
if (qwtTestCaseFinished) {
|
||||
if (qwtTestQuitThreadNum < 3) {
|
||||
tsem_post(&qwtTestQuerySem);
|
||||
tsem_post(&qwtTestFetchSem);
|
||||
(void)tsem_post(&qwtTestQuerySem); //ignore error
|
||||
(void)tsem_post(&qwtTestFetchSem); //ignore error
|
||||
|
||||
taosUsleep(10);
|
||||
}
|
||||
|
@ -1327,16 +1372,16 @@ TEST(rcTest, dropTest) {
|
|||
code = qWorkerInit(NODE_TYPE_VNODE, 1, &mgmt, &msgCb);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
tsem_init(&qwtTestQuerySem, 0, 0);
|
||||
tsem_init(&qwtTestFetchSem, 0, 0);
|
||||
(void)tsem_init(&qwtTestQuerySem, 0, 0); //ignore error
|
||||
(void)tsem_init(&qwtTestFetchSem, 0, 0); //ignore error
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
(void)taosThreadAttrInit(&thattr); //ignore error
|
||||
|
||||
TdThread t1, t2, t3, t4, t5;
|
||||
taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt);
|
||||
taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt);
|
||||
(void)taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); //ignore error
|
||||
(void)taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); //ignore error
|
||||
|
||||
while (true) {
|
||||
if (qwtTestDeadLoop) {
|
||||
|
|
|
@ -1654,6 +1654,12 @@ static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) {
|
|||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
if (nodesIsMatchRegularOp(pOp)) {
|
||||
SValueNode* node = (SValueNode*)(pOp->pRight);
|
||||
if(checkRegexPattern(node->literal) != TSDB_CODE_SUCCESS){
|
||||
return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||
|
|
|
@ -1675,10 +1675,8 @@ int32_t doVectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarPa
|
|||
pRes[i] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
char *pLeftData = colDataGetData(pLeft->columnData, leftIndex);
|
||||
char *pRightData = colDataGetData(pRight->columnData, rightIndex);
|
||||
|
||||
pRes[i] = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
if (pRes[i]) {
|
||||
++num;
|
||||
|
@ -1714,7 +1712,6 @@ int32_t doVectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarPa
|
|||
if (!pLeftData || !pRightData) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
colDataSetInt8(pOut->columnData, i, (int8_t *)&result);
|
||||
} else {
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "tvariant.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#define _DEBUG_PRINT_ 0
|
||||
|
||||
|
@ -52,6 +53,12 @@
|
|||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
class constantTest {
|
||||
public:
|
||||
constantTest() { InitRegexCache(); }
|
||||
~constantTest() { DestroyRegexCache(); }
|
||||
};
|
||||
static constantTest test;
|
||||
namespace {
|
||||
|
||||
SColumnInfo createColumnInfo(int32_t colId, int32_t type, int32_t bytes) {
|
||||
|
|
|
@ -308,7 +308,9 @@ int32_t streamTaskStopMonitorCheckRsp(STaskCheckInfo* pInfo, const char* id) {
|
|||
void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) {
|
||||
ASSERT(pInfo->inCheckProcess == 0);
|
||||
|
||||
pInfo->pList = taosArrayDestroy(pInfo->pList);
|
||||
taosArrayDestroy(pInfo->pList);
|
||||
pInfo->pList = NULL;
|
||||
|
||||
if (pInfo->checkRspTmr != NULL) {
|
||||
/*bool ret = */ taosTmrStop(pInfo->checkRspTmr);
|
||||
pInfo->checkRspTmr = NULL;
|
||||
|
|
|
@ -438,11 +438,13 @@ void tCleanupStreamHbMsg(SStreamHbMsg* pMsg) {
|
|||
}
|
||||
|
||||
if (pMsg->pUpdateNodes != NULL) {
|
||||
pMsg->pUpdateNodes = taosArrayDestroy(pMsg->pUpdateNodes);
|
||||
taosArrayDestroy(pMsg->pUpdateNodes);
|
||||
pMsg->pUpdateNodes = NULL;
|
||||
}
|
||||
|
||||
if (pMsg->pTaskStatus != NULL) {
|
||||
pMsg->pTaskStatus = taosArrayDestroy(pMsg->pTaskStatus);
|
||||
taosArrayDestroy(pMsg->pTaskStatus);
|
||||
pMsg->pTaskStatus = NULL;
|
||||
}
|
||||
|
||||
pMsg->msgId = -1;
|
||||
|
|
|
@ -280,10 +280,12 @@ void tFreeStreamTask(SStreamTask* pTask) {
|
|||
taosMemoryFree(pTask->outputInfo.pTokenBucket);
|
||||
taosThreadMutexDestroy(&pTask->lock);
|
||||
|
||||
pTask->msgInfo.pSendInfo = taosArrayDestroy(pTask->msgInfo.pSendInfo);
|
||||
taosArrayDestroy(pTask->msgInfo.pSendInfo);
|
||||
pTask->msgInfo.pSendInfo = NULL;
|
||||
taosThreadMutexDestroy(&pTask->msgInfo.lock);
|
||||
|
||||
pTask->outputInfo.pNodeEpsetUpdateList = taosArrayDestroy(pTask->outputInfo.pNodeEpsetUpdateList);
|
||||
taosArrayDestroy(pTask->outputInfo.pNodeEpsetUpdateList);
|
||||
pTask->outputInfo.pNodeEpsetUpdateList = NULL;
|
||||
|
||||
if ((pTask->status.removeBackendFiles) && (pTask->pMeta != NULL)) {
|
||||
char* path = taosMemoryCalloc(1, strlen(pTask->pMeta->path) + 128);
|
||||
|
@ -1055,9 +1057,12 @@ void streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo) {
|
|||
}
|
||||
|
||||
taosThreadMutexDestroy(&pInfo->lock);
|
||||
pInfo->pDispatchTriggerList = taosArrayDestroy(pInfo->pDispatchTriggerList);
|
||||
pInfo->pReadyMsgList = taosArrayDestroy(pInfo->pReadyMsgList);
|
||||
pInfo->pCheckpointReadyRecvList = taosArrayDestroy(pInfo->pCheckpointReadyRecvList);
|
||||
taosArrayDestroy(pInfo->pDispatchTriggerList);
|
||||
pInfo->pDispatchTriggerList = NULL;
|
||||
taosArrayDestroy(pInfo->pReadyMsgList);
|
||||
pInfo->pReadyMsgList = NULL;
|
||||
taosArrayDestroy(pInfo->pCheckpointReadyRecvList);
|
||||
pInfo->pCheckpointReadyRecvList = NULL;
|
||||
|
||||
if (pInfo->pChkptTriggerTmr != NULL) {
|
||||
taosTmrStop(pInfo->pChkptTriggerTmr);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "zlib.h"
|
||||
#include "thttp.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "transComm.h"
|
||||
|
||||
// clang-format on
|
||||
|
@ -27,14 +26,18 @@
|
|||
#define HTTP_RECV_BUF_SIZE 1024
|
||||
|
||||
static int32_t httpRefMgt = 0;
|
||||
static int64_t httpRef = -1;
|
||||
static int32_t FAST_FAILURE_LIMIT = 1;
|
||||
|
||||
static int64_t httpDefaultChanId = -1;
|
||||
|
||||
typedef struct SHttpModule {
|
||||
uv_loop_t* loop;
|
||||
SAsyncPool* asyncPool;
|
||||
TdThread thread;
|
||||
SHashObj* connStatusTable;
|
||||
SHashObj* connPool;
|
||||
int8_t quit;
|
||||
int16_t connNum;
|
||||
} SHttpModule;
|
||||
|
||||
typedef struct SHttpMsg {
|
||||
|
@ -46,7 +49,7 @@ typedef struct SHttpMsg {
|
|||
int32_t len;
|
||||
EHttpCompFlag flag;
|
||||
int8_t quit;
|
||||
|
||||
int64_t chanId;
|
||||
} SHttpMsg;
|
||||
|
||||
typedef struct SHttpClient {
|
||||
|
@ -58,50 +61,73 @@ typedef struct SHttpClient {
|
|||
char* addr;
|
||||
uint16_t port;
|
||||
struct sockaddr_in dest;
|
||||
int64_t chanId;
|
||||
} SHttpClient;
|
||||
|
||||
typedef struct SHttpConnList {
|
||||
queue q;
|
||||
|
||||
} SHttpConnList;
|
||||
|
||||
static TdThreadOnce transHttpInit = PTHREAD_ONCE_INIT;
|
||||
static void transHttpEnvInit();
|
||||
|
||||
static void httpHandleReq(SHttpMsg* msg);
|
||||
static void httpHandleQuit(SHttpMsg* msg);
|
||||
static int32_t httpSendQuit();
|
||||
static int32_t httpSendQuit(SHttpModule* http, int64_t chanId);
|
||||
|
||||
static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg);
|
||||
static void httpDestroyMsg(SHttpMsg* msg);
|
||||
|
||||
static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t port);
|
||||
static void httpFailFastMayUpdate(SHashObj* pTable, char* server, int16_t port, int8_t succ);
|
||||
static int32_t taosSendHttpReportImpl(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag);
|
||||
static void httpModuleDestroy(SHttpModule* http);
|
||||
|
||||
static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont,
|
||||
int32_t contLen, EHttpCompFlag flag, int64_t chanId);
|
||||
|
||||
static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t contLen, char* pHead, int32_t headLen,
|
||||
EHttpCompFlag flag) {
|
||||
|
||||
EHttpCompFlag flag) {
|
||||
int32_t code = 0;
|
||||
int32_t len = 0;
|
||||
if (flag == HTTP_FLAT) {
|
||||
return snprintf(pHead, headLen,
|
||||
len = snprintf(pHead, headLen,
|
||||
"POST %s HTTP/1.1\n"
|
||||
"Host: %s\n"
|
||||
"Content-Type: application/json\n"
|
||||
"Content-Length: %d\n\n",
|
||||
uri, server, contLen);
|
||||
if (len < 0 || len >= headLen) {
|
||||
code = TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
} else if (flag == HTTP_GZIP) {
|
||||
return snprintf(pHead, headLen,
|
||||
len = snprintf(pHead, headLen,
|
||||
"POST %s HTTP/1.1\n"
|
||||
"Host: %s\n"
|
||||
"Content-Type: application/json\n"
|
||||
"Content-Encoding: gzip\n"
|
||||
"Content-Length: %d\n\n",
|
||||
uri, server, contLen);
|
||||
if (len < 0 || len >= headLen) {
|
||||
code = TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
} else {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) {
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
int32_t destLen = srcLen;
|
||||
void* pDest = taosMemoryMalloc(destLen);
|
||||
|
||||
if (pDest == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code= TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -110,7 +136,7 @@ static int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) {
|
|||
gzipStream.zfree = (free_func)0;
|
||||
gzipStream.opaque = (voidpf)0;
|
||||
if (deflateInit2(&gzipStream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -121,13 +147,13 @@ static int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) {
|
|||
|
||||
while (gzipStream.avail_in != 0 && gzipStream.total_out < (uLong)(destLen)) {
|
||||
if (deflate(&gzipStream, Z_FULL_FLUSH) != Z_OK) {
|
||||
terrno = TSDB_CODE_COMPRESS_ERROR;
|
||||
code = TSDB_CODE_COMPRESS_ERROR;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (gzipStream.avail_in != 0) {
|
||||
terrno = TSDB_CODE_COMPRESS_ERROR;
|
||||
code = TSDB_CODE_COMPRESS_ERROR;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -137,18 +163,18 @@ static int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) {
|
|||
break;
|
||||
}
|
||||
if (err != Z_OK) {
|
||||
terrno = TSDB_CODE_COMPRESS_ERROR;
|
||||
code = TSDB_CODE_COMPRESS_ERROR;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (deflateEnd(&gzipStream) != Z_OK) {
|
||||
terrno = TSDB_CODE_COMPRESS_ERROR;
|
||||
code = TSDB_CODE_COMPRESS_ERROR;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (gzipStream.total_out >= srcLen) {
|
||||
terrno = TSDB_CODE_COMPRESS_ERROR;
|
||||
code = TSDB_CODE_COMPRESS_ERROR;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -158,8 +184,7 @@ _OVER:
|
|||
if (code == 0) {
|
||||
memcpy(pSrc, pDest, gzipStream.total_out);
|
||||
code = gzipStream.total_out;
|
||||
}
|
||||
|
||||
}
|
||||
taosMemoryFree(pDest);
|
||||
return code;
|
||||
}
|
||||
|
@ -168,11 +193,15 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port,
|
|||
uint32_t ip = taosGetIpv4FromFqdn(server);
|
||||
if (ip == 0xffffffff) {
|
||||
tError("http-report failed to resolving domain names: %s", server);
|
||||
return -1;
|
||||
return TSDB_CODE_RPC_FQDN_ERROR;
|
||||
}
|
||||
char buf[128] = {0};
|
||||
char buf[256] = {0};
|
||||
tinet_ntoa(buf, ip);
|
||||
uv_ip4_addr(buf, port, dest);
|
||||
int ret = uv_ip4_addr(buf, port, dest);
|
||||
if (ret != 0) {
|
||||
tError("http-report failed to get addr %s", uv_err_name(ret));
|
||||
return TSDB_CODE_THIRDPARTY_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -183,6 +212,44 @@ static void* httpThread(void* arg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag, int64_t chanId, SHttpMsg** httpMsg) {
|
||||
if (server == NULL || uri == NULL) {
|
||||
tError("http-report failed to report to invalid addr, chanId:%" PRId64 "", chanId);
|
||||
*httpMsg = NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
if (pCont == NULL || contLen == 0) {
|
||||
tError("http-report failed to report empty packet, chanId:%" PRId64 "", chanId);
|
||||
*httpMsg = NULL;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg));
|
||||
if (msg == NULL) {
|
||||
*httpMsg = NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
msg->port = port;
|
||||
msg->server = taosStrdup(server);
|
||||
msg->uri = taosStrdup(uri);
|
||||
msg->cont = taosMemoryMalloc(contLen);
|
||||
if (msg->server == NULL || msg->uri == NULL || msg->cont == NULL) {
|
||||
httpDestroyMsg(msg);
|
||||
*httpMsg = NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(msg->cont, pCont, contLen);
|
||||
msg->len = contLen;
|
||||
msg->flag = flag;
|
||||
msg->quit = 0;
|
||||
msg->chanId = chanId;
|
||||
*httpMsg = msg;
|
||||
return 0;
|
||||
}
|
||||
static void httpDestroyMsg(SHttpMsg* msg) {
|
||||
if (msg == NULL) return;
|
||||
|
||||
|
@ -191,15 +258,7 @@ static void httpDestroyMsg(SHttpMsg* msg) {
|
|||
taosMemoryFree(msg->cont);
|
||||
taosMemoryFree(msg);
|
||||
}
|
||||
static void httpDestroyMsgWrapper(void* cont, void* param) {
|
||||
httpDestroyMsg((SHttpMsg*)cont);
|
||||
// if (msg == NULL) return;
|
||||
|
||||
// taosMemoryFree(msg->server);
|
||||
// taosMemoryFree(msg->uri);
|
||||
// taosMemoryFree(msg->cont);
|
||||
// taosMemoryFree(msg);
|
||||
}
|
||||
static void httpDestroyMsgWrapper(void* cont, void* param) { httpDestroyMsg((SHttpMsg*)cont); }
|
||||
|
||||
static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) {
|
||||
SHttpMsg *msg = NULL, *quitMsg = NULL;
|
||||
|
@ -221,6 +280,7 @@ static void httpMayDiscardMsg(SHttpModule* http, SAsyncItem* item) {
|
|||
QUEUE_PUSH(&item->qmsg, &quitMsg->q);
|
||||
}
|
||||
}
|
||||
|
||||
static void httpAsyncCb(uv_async_t* handle) {
|
||||
SAsyncItem* item = handle->data;
|
||||
SHttpModule* http = item->pThrd;
|
||||
|
@ -266,6 +326,14 @@ static FORCE_INLINE void destroyHttpClient(SHttpClient* cli) {
|
|||
|
||||
static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) {
|
||||
SHttpClient* cli = handle->data;
|
||||
|
||||
int64_t chanId = cli->chanId;
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, cli->chanId);
|
||||
if (http != NULL) {
|
||||
http->connNum -= 1;
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
}
|
||||
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
|
||||
|
@ -278,7 +346,7 @@ static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested
|
|||
static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||
SHttpClient* cli = handle->data;
|
||||
if (nread < 0) {
|
||||
tError("http-report recv error:%s", uv_err_name(nread));
|
||||
tError("http-report recv error:%s", uv_strerror(nread));
|
||||
} else {
|
||||
tTrace("http-report succ to recv %d bytes", (int32_t)nread);
|
||||
}
|
||||
|
@ -289,92 +357,73 @@ static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const
|
|||
static void clientSentCb(uv_write_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
tError("http-report failed to send data, reason: %s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr,
|
||||
cli->port, cli->chanId);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
tTrace("http-report succ to send data");
|
||||
tTrace("http-report succ to send data, chanId:%" PRId64 "", cli->chanId);
|
||||
}
|
||||
status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb);
|
||||
if (status != 0) {
|
||||
tError("http-report failed to recv data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr,
|
||||
cli->port, cli->chanId);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void clientConnCb(uv_connect_t* req, int32_t status) {
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, httpRef);
|
||||
SHttpClient* cli = req->data;
|
||||
int64_t chanId = cli->chanId;
|
||||
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, chanId);
|
||||
if (status != 0) {
|
||||
httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0);
|
||||
|
||||
tError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
tError("http-report failed to conn to server, reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status),
|
||||
cli->addr, cli->port, chanId);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
http->connNum += 1;
|
||||
|
||||
httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 1);
|
||||
|
||||
status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb);
|
||||
if (0 != status) {
|
||||
tError("http-report failed to send data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
tError("http-report failed to send data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr,
|
||||
cli->port, chanId);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
}
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
}
|
||||
|
||||
int32_t httpSendQuit() {
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, httpRef);
|
||||
if (http == NULL) return 0;
|
||||
|
||||
int32_t httpSendQuit(SHttpModule* http, int64_t chanId) {
|
||||
SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg));
|
||||
if (msg == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
msg->quit = 1;
|
||||
msg->chanId = chanId;
|
||||
|
||||
int ret = transAsyncSend(http->asyncPool, &(msg->q));
|
||||
if (ret != 0) {
|
||||
taosMemoryFree(msg);
|
||||
return TSDB_CODE_THIRDPARTY_ERROR;
|
||||
}
|
||||
|
||||
transAsyncSend(http->asyncPool, &(msg->q));
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t taosSendHttpReportImpl(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag) {
|
||||
if (server == NULL || uri == NULL) {
|
||||
tError("http-report failed to report to invalid addr");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCont == NULL || contLen == 0) {
|
||||
tError("http-report failed to report empty packet");
|
||||
return -1;
|
||||
}
|
||||
SHttpModule* load = taosAcquireRef(httpRefMgt, httpRef);
|
||||
if (load == NULL) {
|
||||
tError("http-report already released");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg));
|
||||
|
||||
msg->server = taosStrdup(server);
|
||||
msg->uri = taosStrdup(uri);
|
||||
msg->port = port;
|
||||
msg->cont = taosMemoryMalloc(contLen);
|
||||
memcpy(msg->cont, pCont, contLen);
|
||||
msg->len = contLen;
|
||||
msg->flag = flag;
|
||||
msg->quit = 0;
|
||||
|
||||
int ret = transAsyncSend(load->asyncPool, &(msg->q));
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void httpDestroyClientCb(uv_handle_t* handle) {
|
||||
SHttpClient* http = handle->data;
|
||||
destroyHttpClient(http);
|
||||
|
@ -392,13 +441,14 @@ static void httpWalkCb(uv_handle_t* handle, void* arg) {
|
|||
return;
|
||||
}
|
||||
static void httpHandleQuit(SHttpMsg* msg) {
|
||||
int64_t chanId = msg->chanId;
|
||||
taosMemoryFree(msg);
|
||||
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, httpRef);
|
||||
tDebug("http-report receive quit, chanId:%" PRId64 "", chanId);
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, chanId);
|
||||
if (http == NULL) return;
|
||||
|
||||
uv_walk(http->loop, httpWalkCb, NULL);
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
}
|
||||
|
||||
static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t port) {
|
||||
|
@ -431,9 +481,14 @@ static void httpFailFastMayUpdate(SHashObj* pTable, char* server, int16_t port,
|
|||
return;
|
||||
}
|
||||
static void httpHandleReq(SHttpMsg* msg) {
|
||||
int32_t ignore = false;
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, httpRef);
|
||||
int64_t chanId = msg->chanId;
|
||||
int32_t ignore = false;
|
||||
char* header = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
SHttpModule* http = taosAcquireRef(httpRefMgt, chanId);
|
||||
if (http == NULL) {
|
||||
code = terrno;
|
||||
goto END;
|
||||
}
|
||||
if (httpFailFastShoudIgnoreMsg(http->connStatusTable, msg->server, msg->port)) {
|
||||
|
@ -453,123 +508,268 @@ static void httpHandleReq(SHttpMsg* msg) {
|
|||
msg->flag = HTTP_FLAT;
|
||||
}
|
||||
if (dstLen < 0) {
|
||||
code = dstLen;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t len = 2048;
|
||||
char* header = taosMemoryCalloc(1, len);
|
||||
int32_t headLen = taosBuildHttpHeader(msg->server, msg->uri, msg->len, header, len, msg->flag);
|
||||
int32_t cap = 2048;
|
||||
header = taosMemoryCalloc(1, cap);
|
||||
if (header == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
int32_t headLen = taosBuildHttpHeader(msg->server, msg->uri, msg->len, header, cap, msg->flag);
|
||||
if (headLen < 0) {
|
||||
taosMemoryFree(header);
|
||||
code = headLen;
|
||||
goto END;
|
||||
}
|
||||
|
||||
uv_buf_t* wb = taosMemoryCalloc(2, sizeof(uv_buf_t));
|
||||
if (wb == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
wb[0] = uv_buf_init((char*)header, strlen(header)); // heap var
|
||||
wb[1] = uv_buf_init((char*)msg->cont, msg->len); // heap var
|
||||
|
||||
SHttpClient* cli = taosMemoryCalloc(1, sizeof(SHttpClient));
|
||||
if (cli == NULL) {
|
||||
taosMemoryFree(wb);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
cli->conn.data = cli;
|
||||
cli->tcp.data = cli;
|
||||
cli->req.data = cli;
|
||||
cli->wbuf = wb;
|
||||
cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE);
|
||||
cli->dest = dest;
|
||||
cli->chanId = chanId;
|
||||
cli->addr = msg->server;
|
||||
cli->port = msg->port;
|
||||
cli->dest = dest;
|
||||
|
||||
taosMemoryFree(msg->uri);
|
||||
taosMemoryFree(msg);
|
||||
|
||||
uv_tcp_init(http->loop, &cli->tcp);
|
||||
cli->wbuf = wb;
|
||||
cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE);
|
||||
if (cli->rbuf == NULL) {
|
||||
tError("http-report failed to alloc read buf, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port,
|
||||
chanId, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||
destroyHttpClient(cli);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
|
||||
int err = uv_tcp_init(http->loop, &cli->tcp);
|
||||
if (err != 0) {
|
||||
tError("http-report failed to init socket handle, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port,
|
||||
chanId, uv_strerror(err));
|
||||
destroyHttpClient(cli);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
|
||||
// set up timeout to avoid stuck;
|
||||
int32_t fd = taosCreateSocketWithTimeout(5000);
|
||||
if (fd < 0) {
|
||||
tError("http-report failed to open socket, dst:%s:%d", cli->addr, cli->port);
|
||||
tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId,
|
||||
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
destroyHttpClient(cli);
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd);
|
||||
if (ret != 0) {
|
||||
tError("http-report failed to open socket, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, cli->port);
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
tError("http-report failed to open socket, reason:%s, dst:%s:%d, chanId:%" PRId64 ",reason:%s", uv_strerror(ret),
|
||||
cli->addr, cli->port, chanId, uv_strerror(ret));
|
||||
destroyHttpClient(cli);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb);
|
||||
if (ret != 0) {
|
||||
tError("http-report failed to connect to http-server, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr,
|
||||
cli->port);
|
||||
tError("http-report failed to connect to http-server,dst:%s:%d, chanId:%" PRId64 ",reson:%s", cli->addr, cli->port,
|
||||
chanId, uv_strerror(ret));
|
||||
httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0);
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
|
||||
END:
|
||||
if (ignore == false) {
|
||||
tError("http-report failed to report, reason: %s, addr: %s:%d", terrstr(), msg->server, msg->port);
|
||||
tError("http-report failed to report to addr: %s:%d, chanId:%" PRId64 ", reason:%s", msg->server, msg->port, chanId,
|
||||
tstrerror(code));
|
||||
}
|
||||
httpDestroyMsg(msg);
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosMemoryFree(header);
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
}
|
||||
|
||||
static void httpModuleDestroy(SHttpModule* http) {
|
||||
if (http == NULL) return;
|
||||
|
||||
if (http->asyncPool != NULL) {
|
||||
TRANS_DESTROY_ASYNC_POOL_MSG(http->asyncPool, SHttpMsg, httpDestroyMsgWrapper, NULL);
|
||||
transAsyncPoolDestroy(http->asyncPool);
|
||||
}
|
||||
if (http->loop) {
|
||||
uv_loop_close(http->loop);
|
||||
taosMemoryFree(http->loop);
|
||||
}
|
||||
|
||||
taosHashCleanup(http->connStatusTable);
|
||||
// not free http, http freeed by ref
|
||||
}
|
||||
|
||||
void httpModuleDestroy2(SHttpModule* http) {
|
||||
if (http == NULL) return;
|
||||
httpModuleDestroy(http);
|
||||
taosMemoryFree(http);
|
||||
}
|
||||
|
||||
static int32_t taosSendHttpReportImplByChan(const char* server, const char* uri, uint16_t port, char* pCont,
|
||||
int32_t contLen, EHttpCompFlag flag, int64_t chanId) {
|
||||
SHttpModule* load = NULL;
|
||||
SHttpMsg *msg = NULL;
|
||||
int32_t code = httpCreateMsg(server, uri, port, pCont, contLen, flag, chanId,&msg);
|
||||
if (code != 0) {
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
load = taosAcquireRef(httpRefMgt, chanId);
|
||||
if (load == NULL) {
|
||||
code = terrno;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
if (atomic_load_8(&load->quit)) {
|
||||
code = TSDB_CODE_HTTP_MODULE_QUIT;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
code = transAsyncSend(load->asyncPool, &(msg->q));
|
||||
if (code != 0) {
|
||||
code = TSDB_CODE_HTTP_MODULE_QUIT;
|
||||
goto _ERROR;
|
||||
}
|
||||
msg = NULL;
|
||||
|
||||
_ERROR:
|
||||
httpDestroyMsg(msg);
|
||||
if (load != NULL) taosReleaseRef(httpRefMgt, chanId);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag, int64_t chanId) {
|
||||
return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, chanId);
|
||||
}
|
||||
|
||||
int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag) {
|
||||
taosThreadOnce(&transHttpInit, transHttpEnvInit);
|
||||
return taosSendHttpReportImpl(server, uri, port, pCont, contLen, flag);
|
||||
return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, httpDefaultChanId);
|
||||
}
|
||||
|
||||
static void transHttpDestroyHandle(void* handle) { taosMemoryFree(handle); }
|
||||
|
||||
int64_t transInitHttpChanImpl();
|
||||
|
||||
static void transHttpEnvInit() {
|
||||
httpRefMgt = taosOpenRef(1, transHttpDestroyHandle);
|
||||
|
||||
SHttpModule* http = taosMemoryCalloc(1, sizeof(SHttpModule));
|
||||
http->loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
http->connStatusTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
http->quit = 0;
|
||||
|
||||
uv_loop_init(http->loop);
|
||||
|
||||
http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb);
|
||||
if (NULL == http->asyncPool) {
|
||||
taosMemoryFree(http->loop);
|
||||
taosMemoryFree(http);
|
||||
http = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
int err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http);
|
||||
if (err != 0) {
|
||||
taosMemoryFree(http->loop);
|
||||
taosMemoryFree(http);
|
||||
http = NULL;
|
||||
}
|
||||
httpRef = taosAddRef(httpRefMgt, http);
|
||||
httpRefMgt = taosOpenRef(64, transHttpDestroyHandle);
|
||||
httpDefaultChanId = transInitHttpChanImpl();
|
||||
}
|
||||
|
||||
void transHttpEnvDestroy() {
|
||||
// remove http
|
||||
if (httpRef == -1) {
|
||||
// remove default chanId
|
||||
taosDestroyHttpChan(httpDefaultChanId);
|
||||
httpDefaultChanId = -1;
|
||||
}
|
||||
|
||||
int64_t transInitHttpChanImpl() {
|
||||
int32_t code = 0;
|
||||
SHttpModule* http = taosMemoryCalloc(1, sizeof(SHttpModule));
|
||||
if (http == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
http->connStatusTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (http->connStatusTable == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
http->loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
if (http->loop == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
int err = uv_loop_init(http->loop);
|
||||
if (err != 0) {
|
||||
tError("http-report failed init uv, reason:%s", uv_strerror(err));
|
||||
code = TSDB_CODE_THIRDPARTY_ERROR;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb);
|
||||
if (http->asyncPool == NULL) {
|
||||
code = terrno;
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
http->quit = 0;
|
||||
|
||||
err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http);
|
||||
if (err != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _ERROR;
|
||||
}
|
||||
|
||||
int64_t ref = taosAddRef(httpRefMgt, http);
|
||||
if (ref < 0) {
|
||||
goto _ERROR;
|
||||
}
|
||||
return ref;
|
||||
|
||||
_ERROR:
|
||||
httpModuleDestroy2(http);
|
||||
return code;
|
||||
}
|
||||
int64_t taosInitHttpChan() {
|
||||
taosThreadOnce(&transHttpInit, transHttpEnvInit);
|
||||
return transInitHttpChanImpl();
|
||||
}
|
||||
|
||||
void taosDestroyHttpChan(int64_t chanId) {
|
||||
tDebug("http-report send quit, chanId:%" PRId64 "", chanId);
|
||||
|
||||
int ret = 0;
|
||||
SHttpModule* load = taosAcquireRef(httpRefMgt, chanId);
|
||||
if (load == NULL) {
|
||||
tError("http-report failed to destroy chanId %" PRId64 ", reason:%s", chanId, tstrerror(terrno));
|
||||
ret = terrno;
|
||||
return;
|
||||
}
|
||||
SHttpModule* load = taosAcquireRef(httpRefMgt, httpRef);
|
||||
|
||||
atomic_store_8(&load->quit, 1);
|
||||
httpSendQuit();
|
||||
ret = httpSendQuit(load, chanId);
|
||||
if (ret != 0) {
|
||||
tDebug("http-report already destroyed, chanId %" PRId64 ",reason:%s", chanId, tstrerror(ret));
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
return;
|
||||
}
|
||||
|
||||
taosThreadJoin(load->thread, NULL);
|
||||
|
||||
TRANS_DESTROY_ASYNC_POOL_MSG(load->asyncPool, SHttpMsg, httpDestroyMsgWrapper, NULL);
|
||||
transAsyncPoolDestroy(load->asyncPool);
|
||||
uv_loop_close(load->loop);
|
||||
taosMemoryFree(load->loop);
|
||||
httpModuleDestroy(load);
|
||||
|
||||
taosHashCleanup(load->connStatusTable);
|
||||
|
||||
taosReleaseRef(httpRefMgt, httpRef);
|
||||
taosRemoveRef(httpRefMgt, httpRef);
|
||||
}
|
||||
taosReleaseRef(httpRefMgt, chanId);
|
||||
taosRemoveRef(httpRefMgt, chanId);
|
||||
}
|
|
@ -224,14 +224,28 @@ int transSetConnOption(uv_tcp_t* stream, int keepalive) {
|
|||
|
||||
SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) {
|
||||
SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool));
|
||||
if (pool == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pool->nAsync = sz;
|
||||
pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync);
|
||||
if (pool->asyncs == NULL) {
|
||||
taosMemoryFree(pool);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int i = 0, err = 0;
|
||||
for (i = 0; i < pool->nAsync; i++) {
|
||||
uv_async_t* async = &(pool->asyncs[i]);
|
||||
|
||||
SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem));
|
||||
if (item == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
item->pThrd = arg;
|
||||
QUEUE_INIT(&item->qmsg);
|
||||
taosThreadMutexInit(&item->mtx, NULL);
|
||||
|
@ -240,6 +254,7 @@ SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb)
|
|||
err = uv_async_init(loop, async, cb);
|
||||
if (err != 0) {
|
||||
tError("failed to init async, reason:%s", uv_err_name(err));
|
||||
terrno = TSDB_CODE_THIRDPARTY_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,12 @@ SArray* taosArrayInit(size_t size, size_t elemSize) {
|
|||
|
||||
SArray* pArray = taosMemoryMalloc(sizeof(SArray));
|
||||
if (pArray == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pArray->size = 0;
|
||||
pArray->pData = taosMemoryCalloc(size, elemSize);
|
||||
if (pArray->pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pArray);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -387,13 +385,11 @@ void taosArrayClearP(SArray* pArray, void (*fp)(void*)) {
|
|||
taosArrayClear(pArray);
|
||||
}
|
||||
|
||||
void* taosArrayDestroy(SArray* pArray) {
|
||||
void taosArrayDestroy(SArray* pArray) {
|
||||
if (pArray) {
|
||||
taosMemoryFree(pArray->pData);
|
||||
taosMemoryFree(pArray);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void taosArrayDestroyP(SArray* pArray, FDelete fp) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "tutil.h"
|
||||
#include "types.h"
|
||||
#include "osString.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
|
||||
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
|
||||
|
@ -1203,54 +1204,153 @@ int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight) {
|
|||
return comparestrRegexMatch(pLeft, pRight) ? 0 : 1;
|
||||
}
|
||||
|
||||
static threadlocal regex_t pRegex;
|
||||
static threadlocal char *pOldPattern = NULL;
|
||||
static regex_t *threadGetRegComp(const char *pPattern) {
|
||||
if (NULL != pOldPattern) {
|
||||
if( strcmp(pOldPattern, pPattern) == 0) {
|
||||
return &pRegex;
|
||||
} else {
|
||||
DestoryThreadLocalRegComp();
|
||||
typedef struct UsingRegex {
|
||||
regex_t pRegex;
|
||||
int32_t lastUsedTime;
|
||||
} UsingRegex;
|
||||
|
||||
typedef struct RegexCache {
|
||||
SHashObj *regexHash;
|
||||
void *regexCacheTmr;
|
||||
void *timer;
|
||||
} RegexCache;
|
||||
static RegexCache sRegexCache;
|
||||
#define MAX_REGEX_CACHE_SIZE 20
|
||||
#define REGEX_CACHE_CLEAR_TIME 30
|
||||
|
||||
static void checkRegexCache(void* param, void* tmrId) {
|
||||
taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
||||
if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (taosHashGetSize(sRegexCache.regexHash) >= MAX_REGEX_CACHE_SIZE) {
|
||||
UsingRegex **ppUsingRegex = taosHashIterate(sRegexCache.regexHash, NULL);
|
||||
while ((ppUsingRegex != NULL)) {
|
||||
if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
|
||||
size_t len = 0;
|
||||
char* key = (char*)taosHashGetKey(ppUsingRegex, &len);
|
||||
taosHashRemove(sRegexCache.regexHash, key, len);
|
||||
}
|
||||
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
|
||||
}
|
||||
}
|
||||
pOldPattern = taosMemoryMalloc(strlen(pPattern) + 1);
|
||||
if (NULL == pOldPattern) {
|
||||
}
|
||||
|
||||
void regexCacheFree(void *ppUsingRegex) {
|
||||
regfree(&(*(UsingRegex **)ppUsingRegex)->pRegex);
|
||||
taosMemoryFree(*(UsingRegex **)ppUsingRegex);
|
||||
}
|
||||
|
||||
int32_t InitRegexCache() {
|
||||
sRegexCache.regexHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (sRegexCache.regexHash == NULL) {
|
||||
uError("failed to create RegexCache");
|
||||
return -1;
|
||||
}
|
||||
taosHashSetFreeFp(sRegexCache.regexHash, regexCacheFree);
|
||||
sRegexCache.regexCacheTmr = taosTmrInit(0, 0, 0, "REGEXCACHE");
|
||||
if (sRegexCache.regexCacheTmr == NULL) {
|
||||
uError("failed to create regex cache check timer");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sRegexCache.timer = taosTmrStart(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, NULL, sRegexCache.regexCacheTmr);
|
||||
if (sRegexCache.timer == NULL) {
|
||||
uError("failed to start regex cache timer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DestroyRegexCache(){
|
||||
uInfo("[regex cache] destory regex cache");
|
||||
taosTmrStopA(&sRegexCache.timer);
|
||||
taosHashCleanup(sRegexCache.regexHash);
|
||||
taosTmrCleanUp(sRegexCache.regexCacheTmr);
|
||||
}
|
||||
|
||||
int32_t checkRegexPattern(const char *pPattern) {
|
||||
if (pPattern == NULL) {
|
||||
return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
|
||||
}
|
||||
|
||||
regex_t regex;
|
||||
int32_t cflags = REG_EXTENDED;
|
||||
int32_t ret = regcomp(®ex, pPattern, cflags);
|
||||
if (ret != 0) {
|
||||
char msgbuf[256] = {0};
|
||||
regerror(ret, ®ex, msgbuf, tListLen(msgbuf));
|
||||
uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
|
||||
return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
|
||||
}
|
||||
regfree(®ex);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static UsingRegex **getRegComp(const char *pPattern) {
|
||||
UsingRegex **ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
|
||||
if (ppUsingRegex != NULL) {
|
||||
(*ppUsingRegex)->lastUsedTime = taosGetTimestampSec();
|
||||
return ppUsingRegex;
|
||||
}
|
||||
|
||||
UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
|
||||
if (pUsingRegex == NULL) {
|
||||
uError("Failed to Malloc when compile regex pattern %s.", pPattern);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(pOldPattern, pPattern);
|
||||
int32_t cflags = REG_EXTENDED;
|
||||
int32_t ret = regcomp(&pRegex, pPattern, cflags);
|
||||
int32_t ret = regcomp(&pUsingRegex->pRegex, pPattern, cflags);
|
||||
if (ret != 0) {
|
||||
char msgbuf[256] = {0};
|
||||
regerror(ret, &pRegex, msgbuf, tListLen(msgbuf));
|
||||
regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf));
|
||||
uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
|
||||
DestoryThreadLocalRegComp();
|
||||
taosMemoryFree(pUsingRegex);
|
||||
return NULL;
|
||||
}
|
||||
return &pRegex;
|
||||
|
||||
while (true) {
|
||||
int code = taosHashPut(sRegexCache.regexHash, pPattern, strlen(pPattern), &pUsingRegex, sizeof(UsingRegex *));
|
||||
if (code != 0 && code != TSDB_CODE_DUP_KEY) {
|
||||
regexCacheFree(&pUsingRegex);
|
||||
uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
|
||||
return NULL;
|
||||
}
|
||||
ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
|
||||
if (ppUsingRegex) {
|
||||
if (*ppUsingRegex != pUsingRegex) {
|
||||
regexCacheFree(&pUsingRegex);
|
||||
}
|
||||
pUsingRegex = (*ppUsingRegex);
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pUsingRegex->lastUsedTime = taosGetTimestampSec();
|
||||
return ppUsingRegex;
|
||||
}
|
||||
|
||||
void DestoryThreadLocalRegComp() {
|
||||
if (NULL != pOldPattern) {
|
||||
regfree(&pRegex);
|
||||
taosMemoryFree(pOldPattern);
|
||||
pOldPattern = NULL;
|
||||
}
|
||||
void releaseRegComp(UsingRegex **regex){
|
||||
taosHashRelease(sRegexCache.regexHash, regex);
|
||||
}
|
||||
|
||||
static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
|
||||
int32_t ret = 0;
|
||||
char msgbuf[256] = {0};
|
||||
regex_t *regex = threadGetRegComp(pPattern);
|
||||
if (regex == NULL) {
|
||||
UsingRegex **pUsingRegex = getRegComp(pPattern);
|
||||
if (pUsingRegex == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
regmatch_t pmatch[1];
|
||||
ret = regexec(regex, pString, 1, pmatch, 0);
|
||||
ret = regexec(&(*pUsingRegex)->pRegex, pString, 1, pmatch, 0);
|
||||
releaseRegComp(pUsingRegex);
|
||||
if (ret != 0 && ret != REG_NOMATCH) {
|
||||
regerror(ret, regex, msgbuf, sizeof(msgbuf));
|
||||
regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf));
|
||||
uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf)
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ void cfgItemFreeVal(SConfigItem *pItem) {
|
|||
}
|
||||
|
||||
if (pItem->array) {
|
||||
pItem->array = taosArrayDestroy(pItem->array);
|
||||
taosArrayDestroy(pItem->array);
|
||||
pItem->array = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED, "some vnode/qnode/mnod
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, "rpc open too many session")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_ERROR, "rpc network error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_BUSY, "rpc network busy")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_MODULE_QUIT, "http-report already quit")
|
||||
|
||||
//common & util
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized")
|
||||
|
@ -683,6 +684,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TBNAME_ERROR, "Pseudo tag tbname n
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TBNAME_DUPLICATED, "Table name duplicated")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TAG_NAME_DUPLICATED, "Tag name duplicated")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_DIFFERENT_BY_ROW_FUNC, "Some functions cannot appear in the select list at the same time")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR, "Syntax error in regular expression")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error")
|
||||
|
||||
//planner
|
||||
|
|
|
@ -104,7 +104,6 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
|
|||
}
|
||||
|
||||
destroyThreadLocalGeosCtx();
|
||||
DestoryThreadLocalRegComp();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -224,7 +223,6 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) {
|
|||
|
||||
taosUpdateItemSize(qinfo.queue, 1);
|
||||
}
|
||||
DestoryThreadLocalRegComp();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -636,7 +634,6 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) {
|
|||
}
|
||||
|
||||
destroyThreadLocalGeosCtx();
|
||||
DestoryThreadLocalRegComp();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from frame.log import *
|
||||
from frame.cases import *
|
||||
from frame.sql import *
|
||||
from frame.caseBase import *
|
||||
from frame import *
|
||||
|
||||
|
||||
class TDTestCase(TBase):
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
self.dbname = "cast_db"
|
||||
self._datetime_epoch = datetime.datetime.fromtimestamp(0)
|
||||
|
||||
def cast_without_from(self):
|
||||
# int
|
||||
int_num = 2147483648
|
||||
tdSql.query(f"select cast({int_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num)
|
||||
|
||||
tdSql.query(f"select cast(2147483647 as int) re;")
|
||||
tdSql.checkData(0, 0, 2147483647)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as float) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
|
||||
tdSql.query(f"select cast({int_num} as double) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({int_num} as varchar(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as binary(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
sql = f"select cast({int_num} as nchar(10));"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
|
||||
# float
|
||||
float_1001 = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as int) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as int unsigned) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as tinyint) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as tinyint unsigned) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as smallint) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as smallint unsigned) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as bigint) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as bigint unsigned) as re;")
|
||||
tdSql.checkData(0, 0, 3)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as double) as re;")
|
||||
tdSql.checkData(0, 0, 3.141592653589793)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as float) as re;")
|
||||
tdSql.checkData(0, 0, 3.1415927)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(float_1001) / 1000))
|
||||
|
||||
sql = f"select cast({float_1001} as varchar(5)) as re;"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, 3.141)
|
||||
|
||||
sql = f"select cast({float_1001} as binary(10)) as re;"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, 3.141593)
|
||||
|
||||
tdSql.query(f"select cast({float_1001} as nchar(5));")
|
||||
tdSql.checkData(0, 0, 3.141)
|
||||
|
||||
# str
|
||||
str_410 = "bcdefghigk" * 41
|
||||
big_str = "bcdefghigk" * 6552
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "bcd")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "bc")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "bcdefghigk")
|
||||
|
||||
tdSql.query(f"select cast('北京' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "北京")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as int) as re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as int unsigned) as re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as tinyint) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as tinyint unsigned) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as smallint) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as smallint unsigned) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as bigint) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as bigint unsigned) as re")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as float) as re;")
|
||||
tdSql.checkData(0, 0, 0.0000000)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as double) as re;")
|
||||
tdSql.checkData(0, 0, 0.000000000000000)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as bool) as re")
|
||||
tdSql.checkData(0, 0, False)
|
||||
|
||||
tdSql.query( f"select cast('{str_410}' as timestamp) as re")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
|
||||
|
||||
def run(self):
|
||||
# self.prepare_data()
|
||||
# self.all_test()
|
||||
# tdSql.execute(f"flush database {self.dbname}")
|
||||
# self.all_test()
|
||||
self.cast_without_from()
|
||||
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
||||
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
|
@ -36,7 +36,7 @@ class TDTestCase(TBase):
|
|||
"create table db.st(ts timestamp, age int) tags(area tinyint);",
|
||||
"insert into db.t1 using db.st tags(100) values('2024-01-01 10:00:01', 1);",
|
||||
"insert into db.t2 using db.st tags(110) values('2024-01-01 10:00:02', 2);",
|
||||
"insert into db.t3 using db.st tags(3) values('2024-01-01 10:00:03', 3);"
|
||||
"insert into db.t3 using db.st tags(3) values('2024-01-01 10:00:03', 3);",
|
||||
]
|
||||
tdSql.executes(sqls)
|
||||
|
||||
|
@ -44,7 +44,7 @@ class TDTestCase(TBase):
|
|||
results = [
|
||||
["2024-01-01 10:00:01", 1, 100],
|
||||
["2024-01-01 10:00:02", 2, 110],
|
||||
["2024-01-01 10:00:03", 3, 3]
|
||||
["2024-01-01 10:00:03", 3, 3],
|
||||
]
|
||||
tdSql.checkDataMem(sql, results)
|
||||
|
||||
|
@ -99,11 +99,12 @@ class TDTestCase(TBase):
|
|||
for i in range(1, 10):
|
||||
new_ts = base_ts + i * 1000
|
||||
num = i * 100
|
||||
v1, v2 = i * 10, i * 11
|
||||
sqls = [
|
||||
f"insert into ntb1 values({new_ts}, 'nihao{num}', {10*i}, {10*i}, {10*i});",
|
||||
f"insert into ntb1 values({new_ts}, 'nihao{num}', {v1}, {v1}, {v1});",
|
||||
f"insert into ntb1 values({new_ts + 1}, 'nihao{num + 1}', NULL, NULL, NULL);",
|
||||
f"delete from ntb1 where ts = {new_ts};",
|
||||
f"insert into ntb1 values({new_ts + 2}, 'nihao{num + 2}', {11*i}, {11*i}, {11*i});",
|
||||
f"insert into ntb1 values({new_ts + 2}, 'nihao{num + 2}', {v2}, {v2}, {v2});",
|
||||
]
|
||||
tdSql.executes(sqls)
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
"insert_rows": 2000000,
|
||||
"childtable_prefix": "d",
|
||||
"insert_mode": "taosc",
|
||||
"timestamp_step": 1000,
|
||||
"timestamp_step": 100,
|
||||
"start_timestamp": 1600000000000,
|
||||
"columns": [
|
||||
{ "type": "bool", "name": "bc"},
|
||||
|
|
|
@ -73,7 +73,7 @@ class TDTestCase(TBase):
|
|||
# come from s3_basic.json
|
||||
self.childtable_count = 6
|
||||
self.insert_rows = 2000000
|
||||
self.timestamp_step = 1000
|
||||
self.timestamp_step = 100
|
||||
|
||||
def createStream(self, sname):
|
||||
sql = f"create stream {sname} fill_history 1 into stm1 as select count(*) from {self.db}.{self.stb} interval(10s);"
|
||||
|
@ -262,7 +262,7 @@ class TDTestCase(TBase):
|
|||
|
||||
# come from s3_basic.json
|
||||
self.insert_rows += self.insert_rows/4
|
||||
self.timestamp_step = 500
|
||||
self.timestamp_step = 50
|
||||
|
||||
# delete
|
||||
def checkDelete(self):
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
"insert_rows": 1000000,
|
||||
"childtable_prefix": "d",
|
||||
"insert_mode": "taosc",
|
||||
"timestamp_step": 500,
|
||||
"timestamp_step": 50,
|
||||
"start_timestamp": 1600000000000,
|
||||
"columns": [
|
||||
{ "type": "bool", "name": "bc"},
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
,,n,army,python3 ./test.py -f s3/s3Basic.py -N 3
|
||||
,,y,army,./pytest.sh python3 ./test.py -f cluster/snapshot.py -N 3 -L 3 -D 2
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/function/test_func_elapsed.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/function/cast.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/test_join.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/test_compare.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f insert/test_column_tag_boundary.py
|
||||
|
@ -192,6 +193,10 @@
|
|||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/like.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/like.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/like.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/match.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/match.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/match.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/match.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/td-28068.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/td-28068.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/td-28068.py -Q 3
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
import taos
|
||||
import sys
|
||||
import datetime
|
||||
import inspect
|
||||
import threading
|
||||
import time
|
||||
|
||||
from util.log import *
|
||||
from util.sql import *
|
||||
from util.cases import *
|
||||
from util.common import tdCom
|
||||
|
||||
class TDTestCase:
|
||||
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
self.replicaVar = int(replicaVar)
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
|
||||
def initConnection(self):
|
||||
self.records = 10000000
|
||||
self.numOfTherads = 50
|
||||
self.ts = 1537146000000
|
||||
self.host = "127.0.0.1"
|
||||
self.user = "root"
|
||||
self.password = "taosdata"
|
||||
self.config = "/home/xp/git/TDengine/sim/dnode1/cfg"
|
||||
self.conn = taos.connect(
|
||||
self.host,
|
||||
self.user,
|
||||
self.password,
|
||||
self.config)
|
||||
|
||||
def initDB(self):
|
||||
tdSql.execute("drop database if exists db")
|
||||
tdSql.execute("create database if not exists db")
|
||||
|
||||
def stopTest(self):
|
||||
tdSql.execute("drop database if exists db")
|
||||
|
||||
def threadTest(self, threadID):
|
||||
print(f"Thread {threadID} starting...")
|
||||
tdsqln = tdCom.newTdSql()
|
||||
for i in range(2, 50):
|
||||
tdsqln.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*{i}dx'")
|
||||
tdsqln.checkRows(0)
|
||||
for i in range(100):
|
||||
tdsqln.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*1x'")
|
||||
tdsqln.checkRows(2)
|
||||
|
||||
tdsqln.query("select * from db.t1x")
|
||||
tdsqln.checkRows(5)
|
||||
|
||||
tdsqln.query("select * from db.t1x where c1 match '_c'")
|
||||
tdsqln.checkRows(2)
|
||||
|
||||
tdsqln.query("select * from db.t1x where c1 match '%__c'")
|
||||
tdsqln.checkRows(0)
|
||||
|
||||
tdsqln.error("select * from db.t1x where c1 match '*d'")
|
||||
|
||||
print(f"Thread {threadID} finished.")
|
||||
|
||||
def match_test(self):
|
||||
tdSql.execute("create table db.t1x (ts timestamp, c1 varchar(100))")
|
||||
tdSql.execute("create table db.t_1x (ts timestamp, c1 varchar(100))")
|
||||
|
||||
tdSql.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*1x'")
|
||||
tdSql.checkRows(2)
|
||||
for i in range(2, 50):
|
||||
tdSql.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*{i}x'")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
tdSql.error("select * from db.t1x where c1 match '*d'")
|
||||
tdSql.query("insert into db.t1x values(now, 'abc'), (now+1s, 'a%c'),(now+2s, 'a_c'),(now+3s, '_c'),(now+4s, '%c')")
|
||||
|
||||
tdSql.query("select * from db.t1x")
|
||||
tdSql.checkRows(5)
|
||||
|
||||
tdSql.query("select * from db.t1x where c1 match '_c'")
|
||||
tdSql.checkRows(2)
|
||||
|
||||
tdSql.query("select * from db.t1x where c1 match '%__c'")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.error("select * from db.t1x where c1 match '*d'")
|
||||
threads = []
|
||||
for i in range(10):
|
||||
t = threading.Thread(target=self.threadTest, args=(i,))
|
||||
threads.append(t)
|
||||
t.start()
|
||||
|
||||
time.sleep(31)
|
||||
|
||||
tdSql.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*1x'")
|
||||
tdSql.checkRows(2)
|
||||
for i in range(2, 50):
|
||||
tdSql.query(f"select distinct table_name from information_schema.ins_columns where table_name match 't.*{i}x'")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
tdSql.query("select * from db.t1x")
|
||||
tdSql.checkRows(5)
|
||||
|
||||
tdSql.query("select * from db.t1x where c1 match '_c'")
|
||||
tdSql.checkRows(2)
|
||||
|
||||
tdSql.query("select * from db.t1x where c1 match '%__c'")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
tdSql.execute("create table db.t3x (ts timestamp, c1 varchar(100))")
|
||||
|
||||
tdSql.execute("insert into db.t3x values(now, '我是中文'), (now+1s, '我是_中文'), (now+2s, '我是%中文'), (now+3s, '%中文'),(now+4s, '_中文')")
|
||||
tdSql.query("select * from db.t3x where c1 match '%中文'")
|
||||
tdSql.checkRows(2)
|
||||
tdSql.query("select * from db.t3x where c1 match '中文'")
|
||||
tdSql.checkRows(5)
|
||||
tdSql.error("select * from db.t1x where c1 match '*d'")
|
||||
|
||||
for thread in threads:
|
||||
print(f"Thread waitting for finish...")
|
||||
thread.join()
|
||||
|
||||
print(f"Mutithread test finished.")
|
||||
|
||||
def run(self):
|
||||
tdLog.printNoPrefix("==========start match_test run ...............")
|
||||
tdSql.prepare(replica = self.replicaVar)
|
||||
|
||||
self.initConnection()
|
||||
|
||||
self.initDB()
|
||||
self.match_test()
|
||||
|
||||
self.stopTest()
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
||||
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
|
@ -104,6 +104,10 @@ python3 ./test.py -f 2-query/like.py
|
|||
python3 ./test.py -f 2-query/like.py -Q 2
|
||||
python3 ./test.py -f 2-query/like.py -Q 3
|
||||
python3 ./test.py -f 2-query/like.py -Q 4
|
||||
python3 ./test.py -f 2-query/match.py
|
||||
python3 ./test.py -f 2-query/match.py -Q 2
|
||||
python3 ./test.py -f 2-query/match.py -Q 3
|
||||
python3 ./test.py -f 2-query/match.py -Q 4
|
||||
python3 ./test.py -f 3-enterprise/restore/restoreDnode.py -N 5 -M 3 -i False
|
||||
python3 ./test.py -f 3-enterprise/restore/restoreVnode.py -N 5 -M 3 -i False
|
||||
python3 ./test.py -f 3-enterprise/restore/restoreMnode.py -N 5 -M 3 -i False
|
||||
|
|
Loading…
Reference in New Issue