diff --git a/docs-cn/14-reference/02-rest-api/02-rest-api.mdx b/docs-cn/14-reference/02-rest-api/02-rest-api.mdx
index c7680ab3e9e109dbb328711f62881283241444fb..43099319b9c5bb1420c199cfa9f7def0b2c44d3d 100644
--- a/docs-cn/14-reference/02-rest-api/02-rest-api.mdx
+++ b/docs-cn/14-reference/02-rest-api/02-rest-api.mdx
@@ -16,7 +16,7 @@ RESTful 接口不依赖于任何 TDengine 的库,因此客户端不需要安
在已经安装 TDengine 服务器端的情况下,可以按照如下方式进行验证。
-下面以 Ubuntu 环境中使用 curl 工具(确认已经安装)来验证 RESTful 接口的正常。
+下面以 Ubuntu 环境中使用 curl 工具(确认已经安装)来验证 RESTful 接口的正常,验证前请确认 taosAdapter 服务已开启,在 Linux 系统上此服务默认由 systemd 管理,使用命令 `systemctl start taosadapter` 启动。
下面示例是列出所有的数据库,请把 h1.taosdata.com 和 6041(缺省值)替换为实际运行的 TDengine 服务 FQDN 和端口号:
diff --git a/include/client/taos.h b/include/client/taos.h
index b65091f52bdd218138891970f079158033cb2d69..c311e017dfcee3955b0112a7e03190ab6065fa05 100644
--- a/include/client/taos.h
+++ b/include/client/taos.h
@@ -162,7 +162,6 @@ DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
-DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h
index 9b71e8c454948b9be257986e01ee146a09a10e55..66b81efc5b32b961de01fce1dbe5a5a6cee808ef 100644
--- a/include/common/tdatablock.h
+++ b/include/common/tdatablock.h
@@ -227,6 +227,9 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n);
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData);
+void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress);
+const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData);
+
void blockDebugShowData(const SArray* dataBlocks);
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId,
@@ -246,54 +249,6 @@ static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32
colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0);
}
-static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
- int8_t needCompress) {
- int32_t* actualLen = (int32_t*)data;
- data += sizeof(int32_t);
-
- uint64_t* groupId = (uint64_t*)data;
- data += sizeof(uint64_t);
-
- int32_t* colSizes = (int32_t*)data;
- data += numOfCols * sizeof(int32_t);
-
- *dataLen = (numOfCols * sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t));
-
- int32_t numOfRows = pBlock->info.rows;
- for (int32_t col = 0; col < numOfCols; ++col) {
- SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, col);
-
- // copy the null bitmap
- if (IS_VAR_DATA_TYPE(pColRes->info.type)) {
- size_t metaSize = numOfRows * sizeof(int32_t);
- memcpy(data, pColRes->varmeta.offset, metaSize);
- data += metaSize;
- (*dataLen) += metaSize;
- } else {
- int32_t len = BitmapLen(numOfRows);
- memcpy(data, pColRes->nullbitmap, len);
- data += len;
- (*dataLen) += len;
- }
-
- if (needCompress) {
- colSizes[col] = blockCompressColData(pColRes, numOfRows, data, needCompress);
- data += colSizes[col];
- (*dataLen) += colSizes[col];
- } else {
- colSizes[col] = colDataGetLength(pColRes, numOfRows);
- (*dataLen) += colSizes[col];
- memmove(data, pColRes->pData, colSizes[col]);
- data += colSizes[col];
- }
-
- colSizes[col] = htonl(colSizes[col]);
- }
-
- *actualLen = *dataLen;
- *groupId = pBlock->info.groupId;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h
index 10bc6a61764f6500305e0712650e93d55255c58a..073d796717013feccf61867078215503c443bc37 100644
--- a/include/common/tdataformat.h
+++ b/include/common/tdataformat.h
@@ -46,6 +46,7 @@ void tTSchemaDestroy(STSchema *pTSchema);
#define COL_VAL_NULL(CID) ((SColVal){.cid = (CID), .isNull = 1})
#define COL_VAL_VALUE(CID, V) ((SColVal){.cid = (CID), .value = (V)})
+int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow);
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow);
void tTSRowFree(STSRow2 *pRow);
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
@@ -54,24 +55,24 @@ int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow);
int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow);
// STSRowBuilder
-#if 0
-int32_t tTSRowBuilderInit(STSRowBuilder *pBuilder, int32_t sver, int32_t nCols, SSchema *pSchema);
-void tTSRowBuilderClear(STSRowBuilder *pBuilder);
-void tTSRowBuilderReset(STSRowBuilder *pBuilder);
-int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, uint8_t *pData, uint32_t nData);
-int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow);
-#endif
+#define tsRowBuilderInit() ((STSRowBuilder){0})
+#define tsRowBuilderClear(B) \
+ do { \
+ if ((B)->pBuf) { \
+ taosMemoryFree((B)->pBuf); \
+ } \
+ } while (0)
// STag
int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag);
void tTagFree(STag *pTag);
bool tTagGet(const STag *pTag, STagVal *pTagVal);
-char* tTagValToData(const STagVal *pTagVal, bool isJson);
+char *tTagValToData(const STagVal *pTagVal, bool isJson);
int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
-void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
-void debugCheckTags(STag *pTag); // TODO: remove
+void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
+void debugCheckTags(STag *pTag); // TODO: remove
// STRUCT =================
struct STColumn {
@@ -106,17 +107,9 @@ struct STSRow2 {
};
struct STSRowBuilder {
- STSchema *pTSchema;
- int32_t szBitMap1;
- int32_t szBitMap2;
- int32_t szKVBuf;
- uint8_t *pKVBuf;
- int32_t szTPBuf;
- uint8_t *pTPBuf;
- int32_t iCol;
- int32_t vlenKV;
- int32_t vlenTP;
- STSRow2 row;
+ STSRow2 tsRow;
+ int32_t szBuf;
+ uint8_t *pBuf;
};
struct SValue {
@@ -154,7 +147,7 @@ struct STagVal {
};
int8_t type;
union {
- int64_t i64;
+ int64_t i64;
struct {
uint32_t nData;
uint8_t *pData;
@@ -162,7 +155,7 @@ struct STagVal {
};
};
-#define TD_TAG_JSON ((int8_t)0x40) // distinguish JSON string and JSON value with the highest bit
+#define TD_TAG_JSON ((int8_t)0x40) // distinguish JSON string and JSON value with the highest bit
#define TD_TAG_LARGE ((int8_t)0x20)
struct STag {
int8_t flags;
@@ -422,4 +415,3 @@ int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToM
#endif
#endif /*_TD_COMMON_DATA_FORMAT_H_*/
-
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index 2a4ef565dd1c6b6742446adee2daf953665b99e5..30ae6c2adb49a811803d04309f43f3068065269c 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -45,6 +45,8 @@ extern bool tsEnableSlaveQuery;
extern bool tsPrintAuth;
extern int64_t tsTickPerMin[3];
+extern int32_t tsCountAlwaysReturnValue;
+
// multi-process
extern int32_t tsMultiProcess;
extern int32_t tsMnodeShmSize;
@@ -102,7 +104,6 @@ extern int32_t tsMaxStreamComputDelay;
extern int32_t tsStreamCompStartDelay;
extern int32_t tsRetryStreamCompDelay;
extern float tsStreamComputDelayRatio; // the delayed computing ration of the whole time window
-extern int32_t tsProjectExecInterval;
extern int64_t tsMaxRetentWindow;
// build info
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index d33f6683658f197ddb58391da4eb33859f9a7bd4..e0dcfbd54442854c991f03510b1e7ba78fc9032b 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -571,13 +571,6 @@ int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pR
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
-typedef struct {
- int16_t colId; // column id
- int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
- int16_t flag; // denote if it is a tag or a normal column
- char name[TSDB_DB_FNAME_LEN];
-} SColIndex;
-
typedef struct {
int16_t lowerRelOptr;
int16_t upperRelOptr;
@@ -779,6 +772,7 @@ typedef struct {
int8_t cacheLastRow;
int32_t numOfRetensions;
SArray* pRetensions;
+ int8_t schemaless;
} SDbCfgRsp;
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
@@ -2353,19 +2347,19 @@ typedef struct {
STSma* tSma;
} STSmaWrapper;
-static FORCE_INLINE void tdDestroyTSma(STSma* pSma) {
+static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
if (pSma) {
taosMemoryFreeClear(pSma->expr);
taosMemoryFreeClear(pSma->tagsFilter);
}
}
-static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
+static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
if (pSW) {
if (pSW->tSma) {
if (deepCopy) {
for (uint32_t i = 0; i < pSW->number; ++i) {
- tdDestroyTSma(pSW->tSma + i);
+ tDestroyTSma(pSW->tSma + i);
}
}
taosMemoryFreeClear(pSW->tSma);
@@ -2373,8 +2367,8 @@ static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy)
}
}
-static FORCE_INLINE void* tdFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
- tdDestroyTSmaWrapper(pSW, deepCopy);
+static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
+ tDestroyTSmaWrapper(pSW, deepCopy);
taosMemoryFreeClear(pSW);
return NULL;
}
@@ -2401,6 +2395,17 @@ static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq) {
return 0;
}
+typedef struct {
+ int64_t tsmaIndexUid;
+ STimeWindow queryWindow;
+} SVGetTsmaExpWndsReq;
+
+typedef struct {
+ int64_t tsmaIndexUid;
+ int32_t numExpWnds;
+ TSKEY* expWndsStartTs;
+} SVGetTsmaExpWndsRsp;
+
typedef struct {
int idx;
} SMCreateFullTextReq;
diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h
index 9fa657a2a6ad78fdd70ed1b4e2ed816b06780351..e99377f9b4b27871506d1739520060b8caa51417 100644
--- a/include/common/tmsgcb.h
+++ b/include/common/tmsgcb.h
@@ -38,7 +38,7 @@ typedef enum {
QUEUE_MAX,
} EQueueType;
-typedef int32_t (*PutToQueueFp)(void* pMgmt, SRpcMsg* pMsg);
+typedef int32_t (*PutToQueueFp)(void* pMgmt, EQueueType qtype, SRpcMsg* pMsg);
typedef int32_t (*GetQueueSizeFp)(void* pMgmt, int32_t vgId, EQueueType qtype);
typedef int32_t (*SendReqFp)(const SEpSet* pEpSet, SRpcMsg* pMsg);
typedef void (*SendRspFp)(SRpcMsg* pMsg);
@@ -50,7 +50,7 @@ typedef void (*ReportStartup)(const char* name, const char* desc);
typedef struct {
void* mgmt;
void* clientRpc;
- PutToQueueFp queueFps[QUEUE_MAX];
+ PutToQueueFp putToQueueFp;
GetQueueSizeFp qsizeFp;
SendReqFp sendReqFp;
SendRspFp sendRspFp;
diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h
index ba4a221a9f6ded4b0bc5c84bd4f7dba25c57c022..fe9ffda69cb82f4c0d2113218fb44b4889158730 100644
--- a/include/common/tmsgdef.h
+++ b/include/common/tmsgdef.h
@@ -70,106 +70,102 @@ enum {
// Requests handled by DNODE
TD_NEW_MSG_SEG(TDMT_DND_MSG)
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE, "dnode-alter-mnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_MNODE, "dnode-drop-mnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_QNODE, "dnode-create-qnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_ALTER_QNODE, "dnode-alter-qnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_QNODE, "dnode-drop-qnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_SNODE, "dnode-create-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_ALTER_SNODE, "dnode-alter-snode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_SNODE, "dnode-drop-snode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_BNODE, "dnode-create-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_ALTER_BNODE, "dnode-alter-bnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_BNODE, "dnode-drop-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "dnode-create-vnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "dnode-drop-vnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_CONFIG_DNODE, "dnode-config-dnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_SERVER_STATUS, "dnode-server-status", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_NET_TEST, "dnode-net-test", NULL, NULL)
-
+ TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "create-vnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "drop-vnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_DND_SERVER_STATUS, "server-status", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_DND_NET_TEST, "net-test", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_DND_CONFIG_DNODE, "config-dnode", NULL, NULL)
+
// Requests handled by MNODE
TD_NEW_MSG_SEG(TDMT_MND_MSG)
- TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "mnode-connect", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "mnode-create-acct", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_ACCT, "mnode-alter-acct", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_ACCT, "mnode-drop-acct", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "mnode-create-user", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "mnode-alter-user", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_GET_USER_AUTH, "mnode-get-user-auth", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "mnode-alter-dnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "mnode-drop-dnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "mnode-create-mnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "mnode-alter-mnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "mnode-drop-mnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "mnode-create-qnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "mnode-alter-qnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "mnode-drop-qnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "mnode-create-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "mnode-alter-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "mnode-drop-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "mnode-create-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "mnode-alter-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "mnode-drop-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "mnode-create-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "mnode-drop-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "mnode-use-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "mnode-alter-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "mnode-sync-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "mnode-compact-db", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNC, "mnode-create-func", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNC, "mnode-retrieve-func", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNC, "mnode-drop-func", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SMA, "mnode-create-sma", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_SMA, "mnode-drop-sma", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "mnode-table-meta", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "mnode-qnode-list", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", SClientHbBatchReq, SClientHbBatchRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "mnode-systable-retrieve", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "mnode-kill-trans", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "mnode-telem-tmr", SMTimerReq, SMTimerReq)
- TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SMCreateTopicReq, SMCreateTopicRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "mnode-mq-ask-ep", SMqAskEpReq, SMqAskEpRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMqConsumerLostMsg, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "mnode-mq-consumer-recover", SMqConsumerRecoverMsg, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "mnode-mq-drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "mnode-create-stream", SCMCreateStreamReq, SCMCreateStreamRsp)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STREAM, "mnode-alter-stream", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_STREAM, "mnode-drop-stream", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_INDEX, "mnode-create-index", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_INDEX, "mnode-drop-index", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_GET_DB_CFG, "mnode-get-db-cfg", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_GET_INDEX, "mnode-get-index", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_APPLY_MSG, "mnode-apply-msg", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "connect", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "create-acct", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_ACCT, "alter-acct", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_ACCT, "drop-acct", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "create-user", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "alter-user", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "drop-user", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_GET_USER_AUTH, "get-user-auth", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "create-dnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "config-dnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "alter-dnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "drop-dnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "create-mnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "alter-mnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "drop-mnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "create-qnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "alter-qnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "drop-qnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "create-snode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "alter-snode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "drop-snode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "create-bnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "alter-bnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "drop-bnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "create-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "drop-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "use-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "alter-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "sync-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "compact-db", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNC, "create-func", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNC, "retrieve-func", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNC, "drop-func", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "create-stb", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "alter-stb", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "drop-stb", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SMA, "create-sma", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_SMA, "drop-sma", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "table-meta", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "vgroup-list", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "qnode-list", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "kill-query", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "kill-conn", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "heartbeat", SClientHbBatchReq, SClientHbBatchRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "show", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "systable-retrieve", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "status", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "kill-trans", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
+ TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "grant", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "auth", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "drop-topic", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "subscribe", SCMSubscribeReq, SCMSubscribeRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "mq-ask-ep", SMqAskEpReq, SMqAskEpRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mq-consumer-lost", SMqConsumerLostMsg, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "mq-consumer-recover", SMqConsumerRecoverMsg, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mq-do-rebalance", SMqDoRebalanceMsg, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "mq-drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "create-stream", SCMCreateStreamReq, SCMCreateStreamRsp)
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STREAM, "alter-stream", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_STREAM, "drop-stream", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_INDEX, "create-index", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_INDEX, "drop-index", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_GET_DB_CFG, "get-db-cfg", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_GET_INDEX, "get-index", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_APPLY_MSG, "apply-msg", NULL, NULL)
// Requests handled by VNODE
TD_NEW_MSG_SEG(TDMT_VND_MSG)
- TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "vnode-submit", SSubmitReq, SSubmitRsp)
- TD_DEF_MSG_TYPE(TDMT_VND_QUERY, "vnode-query", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_VND_FETCH, "vnode-fetch", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TABLE, "vnode-create-table", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TABLE, "vnode-alter-table", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_VND_DROP_TABLE, "vnode-drop-table", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "vnode-update-tag-val", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp)
+ TD_DEF_MSG_TYPE(TDMT_VND_QUERY, "query", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_FETCH, "fetch", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TABLE, "create-table", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TABLE, "alter-table", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_DROP_TABLE, "drop-table", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "update-tag-val", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL)
@@ -205,6 +201,7 @@ enum {
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT_RSMA, "vnode-submit-rsma", SSubmitReq, SSubmitRsp)
+ TD_DEF_MSG_TYPE(TDMT_VND_GET_TSMA_EXP_WNDS, "vnode-get-tsma-expired-windows", SVGetTsmaExpWndsReq, SVGetTsmaExpWndsRsp)
TD_DEF_MSG_TYPE(TDMT_VND_SYNC_TIMEOUT, "vnode-sync-timeout", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_VND_SYNC_PING, "vnode-sync-ping", NULL, NULL)
diff --git a/include/common/ttypes.h b/include/common/ttypes.h
index 31cdb28690caeb6610d4b5e4ec6307952a0760aa..16c59465cc1f71d1f9e3cc6a2e65d83939247322 100644
--- a/include/common/ttypes.h
+++ b/include/common/ttypes.h
@@ -30,7 +30,7 @@ typedef uint64_t TDRowVerT;
typedef int16_t col_id_t;
typedef int8_t col_type_t;
typedef int32_t col_bytes_t;
-typedef int32_t schema_ver_t;
+typedef int32_t schema_ver_t;
typedef int32_t func_id_t;
#pragma pack(push, 1)
@@ -49,8 +49,9 @@ typedef struct {
#define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v))
#define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE))
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len))
-#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR) || ((t) == TSDB_DATA_TYPE_JSON))
-#define IS_STR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR))
+#define IS_VAR_DATA_TYPE(t) \
+ (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR) || ((t) == TSDB_DATA_TYPE_JSON))
+#define IS_STR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0]))
#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v))
@@ -142,52 +143,56 @@ typedef struct {
} \
} while (0)
-#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \
- do { \
- switch (_inputType) { \
- case TSDB_DATA_TYPE_TINYINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_UTINYINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_SMALLINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_USMALLINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_TIMESTAMP: \
- case TSDB_DATA_TYPE_BIGINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_UBIGINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_FLOAT: \
- snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_DOUBLE: \
- snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
- break; \
- case TSDB_DATA_TYPE_UINT: \
- snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
- break; \
- default: \
- snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \
- break; \
- } \
+#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \
+ do { \
+ switch (_inputType) { \
+ case TSDB_DATA_TYPE_TINYINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_UTINYINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_SMALLINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_USMALLINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_TIMESTAMP: \
+ case TSDB_DATA_TYPE_BIGINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_UBIGINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_FLOAT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_DOUBLE: \
+ snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
+ break; \
+ case TSDB_DATA_TYPE_UINT: \
+ snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
+ break; \
+ default: \
+ snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \
+ break; \
+ } \
} while (0)
+
//TODO: use varchar(0) to represent NULL type
+#define IS_VAR_NULL_TYPE(_t, _b) ((_t) == TSDB_DATA_TYPE_VARCHAR && (_b) == 0)
#define IS_NULL_TYPE(_t) ((_t) == TSDB_DATA_TYPE_NULL)
+
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
#define IS_INTEGER_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)))
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
-#define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
+#define IS_MATHABLE_TYPE(_t) \
+ (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
#define IS_VALID_TINYINT(_t) ((_t) >= INT8_MIN && (_t) <= INT8_MAX)
#define IS_VALID_SMALLINT(_t) ((_t) >= INT16_MIN && (_t) <= INT16_MAX)
@@ -244,7 +249,7 @@ typedef struct tDataTypeDescriptor {
int16_t type;
int16_t nameLen;
int32_t bytes;
- char *name;
+ char * name;
int64_t minValue;
int64_t maxValue;
int32_t (*compFunc)(const char *const input, int32_t inputSize, const int32_t nelements, char *const output,
@@ -277,4 +282,4 @@ void *getDataMax(int32_t type);
}
#endif
-#endif /*_TD_COMMON_TTYPE_H_*/
+#endif /*_TD_COMMON_TTYPE_H_*/
diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h
index 5379a8f712cde79c29ca23e2baac2ac4985450e7..288248422b8288b98d8f0fccaef040186294cb76 100644
--- a/include/libs/executor/executor.h
+++ b/include/libs/executor/executor.h
@@ -156,18 +156,6 @@ int64_t qGetQueriedTableUid(qTaskInfo_t tinfo);
*/
int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t tagCondLen, SArray* pTableIdList);
-/**
- * Create the table group according to the group by tags info
- * @param pTableIdList
- * @param skey
- * @param groupInfo
- * @param groupByIndex
- * @param numOfIndex
- * @return
- */
-// int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGroupInfo groupInfo, SColIndex*
-// groupByIndex, int32_t numOfIndex);
-
/**
* Update the table id list of a given query.
* @param uid child table uid
diff --git a/include/libs/function/function.h b/include/libs/function/function.h
index 21b73090554cc951aac82b4d9adb1cb7d847bff2..e8cb363e08fa65385d36762face331f5de5cf1eb 100644
--- a/include/libs/function/function.h
+++ b/include/libs/function/function.h
@@ -61,56 +61,9 @@ typedef struct SFileBlockInfo {
#define TSDB_BLOCK_DIST_STEP_ROWS 8
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
-#define FUNCTION_TYPE_SCALAR 1
-#define FUNCTION_TYPE_AGG 2
-
#define TOP_BOTTOM_QUERY_LIMIT 100
#define FUNCTIONS_NAME_MAX_LENGTH 16
-#define FUNCTION_INVALID_ID -1
-#define FUNCTION_COUNT 0
-#define FUNCTION_SUM 1
-#define FUNCTION_AVG 2
-#define FUNCTION_MIN 3
-#define FUNCTION_MAX 4
-#define FUNCTION_STDDEV 5
-#define FUNCTION_PERCT 6
-#define FUNCTION_APERCT 7
-#define FUNCTION_FIRST 8
-#define FUNCTION_LAST 9
-#define FUNCTION_LAST_ROW 10
-#define FUNCTION_TOP 11
-#define FUNCTION_BOTTOM 12
-#define FUNCTION_SPREAD 13
-#define FUNCTION_TWA 14
-#define FUNCTION_LEASTSQR 15
-
-#define FUNCTION_TS 16
-#define FUNCTION_TS_DUMMY 17
-#define FUNCTION_TAG_DUMMY 18
-#define FUNCTION_TS_COMP 19
-
-#define FUNCTION_TAG 20
-#define FUNCTION_PRJ 21
-
-#define FUNCTION_TAGPRJ 22
-#define FUNCTION_ARITHM 23
-#define FUNCTION_DIFF 24
-
-#define FUNCTION_FIRST_DST 25
-#define FUNCTION_LAST_DST 26
-#define FUNCTION_STDDEV_DST 27
-#define FUNCTION_INTERP 28
-
-#define FUNCTION_RATE 29
-#define FUNCTION_IRATE 30
-#define FUNCTION_TID_TAG 31
-#define FUNCTION_DERIVATIVE 32
-#define FUNCTION_BLKINFO 33
-
-
-#define FUNCTION_COV 38
-
typedef struct SResultRowEntryInfo {
bool initialized:1; // output buffer has been initialized
bool complete:1; // query has completed
@@ -180,10 +133,9 @@ typedef struct SqlFunctionCtx {
char *pOutput; // final result output buffer, point to sdata->data
int32_t numOfParams;
SFunctParam *param; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param
- int64_t *ptsList; // corresponding timestamp array list
+ int64_t *ptsList; // corresponding timestamp array list, todo remove it
SColumnInfoData *pTsOutput; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
int32_t offset;
- SVariant tag;
struct SResultRowEntryInfo *resultInfo;
SSubsidiaryResInfo subsidiaries;
SPoint1 start;
@@ -210,9 +162,6 @@ enum {
typedef struct tExprNode {
int32_t nodeType;
union {
- SSchema *pSchema;// column node
- struct SVariant *pVal; // value node
-
struct {// function node
char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor
int32_t functionId;
@@ -255,47 +204,23 @@ struct SScalarParam {
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, SResultDataInfo* pInfo, int16_t extLength,
bool isSuperTable);
-bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* functionId);
-
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell);
int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock);
bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry);
bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry);
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// fill api
-struct SFillInfo;
-struct SFillColInfo;
-
typedef struct SPoint {
int64_t key;
void * val;
} SPoint;
-//void taosFillSetStartInfo(struct SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
-//void taosResetFillInfo(struct SFillInfo* pFillInfo, TSKEY startTimestamp);
-//void taosFillSetInputDataBlock(struct SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
-//struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const SValueNode* val);
-//bool taosFillHasMoreResults(struct SFillInfo* pFillInfo);
-//
-//struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
-// SInterval* pInterval, int32_t fillType,
-// struct SFillColInfo* pCol, const char* id);
-//
-//void* taosDestroyFillInfo(struct SFillInfo *pFillInfo);
-//int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, void** output, int32_t capacity);
-//int64_t getFillInfoStart(struct SFillInfo *pFillInfo);
-
int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// udf api
struct SUdfInfo;
-void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
-void qRemoveUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
-
/**
* create udfd proxy, called once in process that call doSetupUdf/callUdfxxx/doTeardownUdf
* @return error code
diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h
index 41c196c916b3cdef97bc68205b8b2ee0f0e472aa..15e5e14e41e2eb3b7bc0036932102d42cefecf79 100644
--- a/include/libs/nodes/nodes.h
+++ b/include/libs/nodes/nodes.h
@@ -212,6 +212,7 @@ typedef enum ENodeType {
QUERY_NODE_PHYSICAL_PLAN_INTERVAL,
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
+ QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
QUERY_NODE_PHYSICAL_PLAN_FILL,
QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW,
QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW,
diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h
index 5892bffac2f20c0cc177cb9937256f82e45a6956..eb37316402538a1c89c7f3c7dbf0fa21b57843c0 100644
--- a/include/libs/nodes/plannodes.h
+++ b/include/libs/nodes/plannodes.h
@@ -106,21 +106,28 @@ typedef struct SMergeLogicNode {
typedef enum EWindowType { WINDOW_TYPE_INTERVAL = 1, WINDOW_TYPE_SESSION, WINDOW_TYPE_STATE } EWindowType;
+typedef enum EStreamIntervalAlgorithm {
+ STREAM_INTERVAL_ALGO_FINAL = 1,
+ STREAM_INTERVAL_ALGO_SEMI,
+ STREAM_INTERVAL_ALGO_SINGLE
+} EStreamIntervalAlgorithm;
+
typedef struct SWindowLogicNode {
- SLogicNode node;
- EWindowType winType;
- SNodeList* pFuncs;
- int64_t interval;
- int64_t offset;
- int64_t sliding;
- int8_t intervalUnit;
- int8_t slidingUnit;
- int64_t sessionGap;
- SNode* pTspk;
- SNode* pStateExpr;
- int8_t triggerType;
- int64_t watermark;
- double filesFactor;
+ SLogicNode node;
+ EWindowType winType;
+ SNodeList* pFuncs;
+ int64_t interval;
+ int64_t offset;
+ int64_t sliding;
+ int8_t intervalUnit;
+ int8_t slidingUnit;
+ int64_t sessionGap;
+ SNode* pTspk;
+ SNode* pStateExpr;
+ int8_t triggerType;
+ int64_t watermark;
+ double filesFactor;
+ EStreamIntervalAlgorithm stmInterAlgo;
} SWindowLogicNode;
typedef struct SFillLogicNode {
@@ -301,6 +308,8 @@ typedef struct SIntervalPhysiNode {
} SIntervalPhysiNode;
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
+typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode;
+typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode;
typedef struct SFillPhysiNode {
SPhysiNode node;
diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h
index ca825b9e2fb460b6aa35110c89535071a50cac52..6abd1ffa6d57834b2d36b72071001019276f5e99 100644
--- a/include/libs/parser/parser.h
+++ b/include/libs/parser/parser.h
@@ -49,6 +49,7 @@ typedef struct SParseContext {
const char* pUser;
bool isSuperUser;
bool async;
+ int8_t schemalessType;
} SParseContext;
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery);
diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h
index 6e14445ac7abc12eb4ccca7a9f08f3e7ff43ddb8..af30ec4c6bf7d657dfdec1af49f871eed38b53d7 100644
--- a/include/libs/planner/planner.h
+++ b/include/libs/planner/planner.h
@@ -36,7 +36,7 @@ typedef struct SPlanContext {
int64_t watermark;
char* pMsg;
int32_t msgLen;
- double filesFactor;
+ double filesFactor;
} SPlanContext;
// Create the physical plan for the query, according to the AST.
diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h
index 331b78769029fb97764f81ce6bb646f28854918a..5cb6dbd3bcb55f7ad2411fb8eb72754475b59eab 100644
--- a/include/libs/scheduler/scheduler.h
+++ b/include/libs/scheduler/scheduler.h
@@ -100,7 +100,7 @@ int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan *pDag, in
*/
int32_t schedulerFetchRows(int64_t job, void **data);
-int32_t schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param);
+void schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param);
int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub);
@@ -121,8 +121,6 @@ void schedulerFreeJob(int64_t job);
void schedulerDestroy(void);
void schdExecCallback(SQueryResult* pResult, void* param, int32_t code);
-void schdFetchCallback(void* pResult, void* param, int32_t code);
-
#ifdef __cplusplus
}
diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h
index e541c214deba8e9b9ad3cc4e95cc2d2224f3c5a3..95af8ac30666b67b0a933477ff8ca0764d2d0a43 100644
--- a/include/libs/wal/wal.h
+++ b/include/libs/wal/wal.h
@@ -184,6 +184,7 @@ int32_t walRollback(SWal *, int64_t ver);
// notify that previous logs can be pruned safely
int32_t walBeginSnapshot(SWal *, int64_t ver);
int32_t walEndSnapshot(SWal *);
+void walRestoreFromSnapshot(SWal *, int64_t ver);
// int32_t walDataCorrupted(SWal*);
// read
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index 703f18956254b23baa20c14735f338606ddd1dae..526c8609bf50b8c82539f27c8aca2a0636115361 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -677,6 +677,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000)
#define TSDB_CODE_SML_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x3001)
#define TSDB_CODE_SML_INVALID_DATA TAOS_DEF_ERROR_CODE(0, 0x3002)
+#define TSDB_CODE_SML_INVALID_DB_CONF TAOS_DEF_ERROR_CODE(0, 0x3003)
#ifdef __cplusplus
}
diff --git a/include/util/tlist.h b/include/util/tlist.h
index 43833d7ecd84f09643546f3f3fa838edbd1dabf1..1954bda145a48f249875bda8ea3389b4fbed22be 100644
--- a/include/util/tlist.h
+++ b/include/util/tlist.h
@@ -229,7 +229,7 @@ int32_t tdListAppend(SList *list, void *data);
SListNode *tdListPopHead(SList *list);
SListNode *tdListPopTail(SList *list);
SListNode *tdListGetHead(SList *list);
-SListNode *tsListGetTail(SList *list);
+SListNode *tdListGetTail(SList *list);
SListNode *tdListPopNode(SList *list, SListNode *node);
void tdListMove(SList *src, SList *dst);
void tdListDiscard(SList *list);
diff --git a/include/util/tutil.h b/include/util/tutil.h
index 444a893a888abb5c28de0c70476af9beee32cc10..b29e1f7cfa889944b53b3603bd0c8fefc8ece1f0 100644
--- a/include/util/tutil.h
+++ b/include/util/tutil.h
@@ -57,11 +57,13 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
tMD5Init(&context);
tMD5Update(&context, inBuf, (uint32_t)len);
tMD5Final(&context);
+ char buf[TSDB_PASSWORD_LEN + 1];
- sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0],
+ sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0],
context.digest[1], context.digest[2], context.digest[3], context.digest[4], context.digest[5],
context.digest[6], context.digest[7], context.digest[8], context.digest[9], context.digest[10],
context.digest[11], context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
+ memcpy(target, buf, TSDB_PASSWORD_LEN);
}
#ifdef __cplusplus
diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h
index a2305dd45d5818b37cb0a26c0bcd1b47830b0496..c7b831893ee806a94942be6b1691c9c3e4be898d 100644
--- a/source/client/inc/clientInt.h
+++ b/source/client/inc/clientInt.h
@@ -46,6 +46,8 @@ extern "C" {
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
#define HEARTBEAT_INTERVAL 1500 // ms
+#define SYNC_ON_TOP_OF_ASYNC 0
+
enum {
RES_TYPE__QUERY = 1,
RES_TYPE__TMQ,
@@ -151,6 +153,7 @@ typedef struct STscObj {
int32_t numOfReqs; // number of sqlObj bound to this connection
SAppInstInfo* pAppInfo;
SHashObj* pRequests;
+ int8_t schemalessType;
} STscObj;
typedef struct SResultColumn {
@@ -182,7 +185,9 @@ typedef struct SReqResultInfo {
typedef struct SRequestSendRecvBody {
tsem_t rspSem; // not used now
- void* fp;
+ __taos_async_fn_t queryFp;
+ __taos_async_fn_t fetchFp;
+ void* param;
SDataBuf requestMsg;
int64_t queryJob; // query job, created according to sql query DAG.
struct SQueryPlan* pDag; // the query dag, generated according to the sql statement.
@@ -218,13 +223,21 @@ typedef struct SRequestObj {
SRequestSendRecvBody body;
} SRequestObj;
+typedef struct SSyncQueryParam {
+ tsem_t sem;
+ SRequestObj* pRequest;
+} SSyncQueryParam;
+
+void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
+
void doSetOneRowPtr(SReqResultInfo* pResultInfo);
void setResPrecision(SReqResultInfo* pResInfo, int32_t precision);
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4,
bool freeAfterUse);
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
void doFreeReqResultInfo(SReqResultInfo* pResInfo);
+SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen);
static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) {
SMqRspObj* msg = (SMqRspObj*)res;
@@ -270,7 +283,7 @@ int32_t releaseTscObj(int64_t rid);
uint64_t generateRequestId();
-void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
+void* createRequest(STscObj* pObj, void* param, int32_t type);
void destroyRequest(SRequestObj* pRequest);
SRequestObj* acquireRequest(int64_t rid);
int32_t releaseRequest(int64_t rid);
@@ -318,9 +331,9 @@ int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* v
// --- mq
void hbMgrInitMqHbRspHandle();
-SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery, void** res);
-int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList);
+SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQuery, void** res);
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList);
+void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery);
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest);
int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList);
diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c
index 4f5f23b68be93ca3449ddbc2ffd3522c1d1cd27c..4b39a515847e77bd9f2df26f446c5da69f9de75c 100644
--- a/source/client/src/clientEnv.c
+++ b/source/client/src/clientEnv.c
@@ -13,10 +13,11 @@
* along with this program. If not, see .
*/
+#include "os.h"
#include "catalog.h"
+#include "functionMgt.h"
#include "clientInt.h"
#include "clientLog.h"
-#include "os.h"
#include "query.h"
#include "scheduler.h"
#include "tcache.h"
@@ -161,6 +162,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c
taosThreadMutexInit(&pObj->mutex, NULL);
pObj->id = taosAddRef(clientConnRefPool, pObj);
+ pObj->schemalessType = 0;
tscDebug("connObj created, 0x%" PRIx64, pObj->id);
return pObj;
@@ -170,7 +172,7 @@ STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientCon
int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); }
-void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t type) {
+void *createRequest(STscObj *pObj, void *param, int32_t type) {
assert(pObj != NULL);
SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
@@ -184,9 +186,10 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty
pRequest->requestId = generateRequestId();
pRequest->metric.start = taosGetTimestampUs();
+ pRequest->body.param = param;
+
pRequest->type = type;
pRequest->pTscObj = pObj;
- pRequest->body.fp = fp; // not used it yet
pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
tsem_init(&pRequest->body.rspSem, 0, 0);
@@ -287,6 +290,7 @@ void taos_init_imp(void) {
taosSetCoreDump(true);
initTaskQueue();
+ fmFuncMgtInit();
clientConnRefPool = taosOpenRef(200, destroyTscObj);
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c
index c4bf3b50bf08a805391a0755d81e0f1d76d6459c..774ef5f2483573376121b7cf910f1f7eb1ff689b 100644
--- a/source/client/src/clientImpl.c
+++ b/source/client/src/clientImpl.c
@@ -133,7 +133,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
}
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) {
- *pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT);
+ *pRequest = createRequest(pTscObj, NULL, TSDB_SQL_SELECT);
if (*pRequest == NULL) {
tscError("failed to malloc sqlObj");
return TSDB_CODE_TSC_OUT_OF_MEMORY;
@@ -176,6 +176,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
.pTransporter = pTscObj->pAppInfo->pTransporter,
.pStmtCb = pStmtCb,
.pUser = pTscObj->user,
+ .schemalessType = pTscObj->schemalessType,
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER))};
cxt.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
@@ -191,6 +192,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
setResPrecision(&pRequest->body.resInfo, (*pQuery)->precision);
}
}
+
if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) {
TSWAP(pRequest->dbList, (*pQuery)->pDbList);
TSWAP(pRequest->tableList, (*pQuery)->pTableList);
@@ -229,6 +231,29 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
return TSDB_CODE_SUCCESS;
}
+static SAppInstInfo* getAppInfo(SRequestObj* pRequest) {
+ return pRequest->pTscObj->pAppInfo;
+}
+
+int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
+ // drop table if exists not_exists_table
+ if (NULL == pQuery->pCmdMsg) {
+ return TSDB_CODE_SUCCESS;
+ }
+
+ SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg;
+ pRequest->type = pMsgInfo->msgType;
+ pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL};
+ pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management
+
+ SAppInstInfo* pAppInfo = getAppInfo(pRequest);
+ SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
+
+ int64_t transporterId = 0;
+ asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg);
+ return TSDB_CODE_SUCCESS;
+}
+
int compareQueryNodeLoad(const void* elem1, const void* elem2) {
SQueryNodeLoad* node1 = (SQueryNodeLoad*)elem1;
SQueryNodeLoad* node2 = (SQueryNodeLoad*)elem2;
@@ -285,9 +310,11 @@ int32_t getQnodeList(SRequestObj* pRequest, SArray** pNodeList) {
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray** pNodeList) {
pRequest->type = pQuery->msgType;
+ SAppInstInfo* pAppInfo = getAppInfo(pRequest);
+
SPlanContext cxt = {.queryId = pRequest->requestId,
.acctId = pRequest->pTscObj->acctId,
- .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
+ .mgmtEpSet = getEpSet_s(&pAppInfo->mgmtEp),
.pAstRoot = pQuery->pRoot,
.showRewrite = pQuery->showRewrite,
.pMsg = pRequest->msgBuf,
@@ -297,6 +324,7 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
if (TSDB_CODE_SUCCESS == code) {
code = qCreateQueryPlan(&cxt, pPlan, *pNodeList);
}
+
return code;
}
@@ -351,7 +379,7 @@ int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNod
pRequest->body.resInfo.execRes = res.res;
- while (true) {
+ while (true) {
if (code != TSDB_CODE_SUCCESS) {
if (pRequest->body.queryJob != 0) {
schedulerFreeJob(pRequest->body.queryJob);
@@ -387,7 +415,7 @@ int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNod
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
- SQueryResult res = {.code = 0, .numOfRows = 0};
+ SQueryResult res = {0};
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
pRequest->metric.start, &res);
@@ -416,10 +444,6 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
return pRequest->code;
}
-int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList) {
- return getPlan(pRequest, pQuery, &pRequest->body.pDag, pNodeList);
-}
-
int32_t handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet *epset) {
int32_t code = 0;
SArray* pArray = NULL;
@@ -427,19 +451,19 @@ int32_t handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog
if (pRsp->nBlocks <= 0) {
return TSDB_CODE_SUCCESS;
}
-
+
pArray = taosArrayInit(pRsp->nBlocks, sizeof(STbSVersion));
if (NULL == pArray) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_OUT_OF_MEMORY;
}
-
+
for (int32_t i = 0; i < pRsp->nBlocks; ++i) {
SSubmitBlkRsp* blk = pRsp->pBlocks + i;
if (NULL == blk->tblFName || 0 == blk->tblFName[0]) {
continue;
}
-
+
STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver};
taosArrayPush(pArray, &tbSver);
}
@@ -449,7 +473,7 @@ int32_t handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog
_return:
taosArrayDestroy(pArray);
- return code;
+ return code;
}
int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet *epset) {
@@ -460,13 +484,13 @@ int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog,
if (tbNum <= 0) {
return TSDB_CODE_SUCCESS;
}
-
+
pArray = taosArrayInit(tbNum, sizeof(STbSVersion));
if (NULL == pArray) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_OUT_OF_MEMORY;
}
-
+
for (int32_t i = 0; i < tbNum; ++i) {
STbVerInfo* tbInfo = taosArrayGet(pTbArray, i);
STbSVersion tbSver = {.tbFName = tbInfo->tbFName, .sver = tbInfo->sversion, .tver = tbInfo->tversion};
@@ -478,7 +502,7 @@ int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog,
_return:
taosArrayDestroy(pArray);
- return code;
+ return code;
}
int32_t handleAlterTbExecRes(void* res, SCatalog* pCatalog) {
@@ -489,19 +513,19 @@ int32_t handleExecRes(SRequestObj* pRequest) {
if (NULL == pRequest->body.resInfo.execRes.res) {
return TSDB_CODE_SUCCESS;
}
-
+
int32_t code = 0;
SCatalog* pCatalog = NULL;
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
if (code) {
return code;
}
-
+
SEpSet epset = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
SQueryExecRes* pRes = &pRequest->body.resInfo.execRes;
-
+
switch (pRes->msgType) {
- case TDMT_VND_ALTER_TABLE:
+ case TDMT_VND_ALTER_TABLE:
case TDMT_MND_ALTER_STB: {
code = handleAlterTbExecRes(pRes->res, pCatalog);
break;
@@ -509,7 +533,7 @@ int32_t handleExecRes(SRequestObj* pRequest) {
case TDMT_VND_SUBMIT: {
code = handleSubmitExecRes(pRequest, pRes->res, pCatalog, &epset);
break;
- }
+ }
case TDMT_VND_QUERY: {
code = handleQueryExecRes(pRequest, pRes->res, pCatalog, &epset);
break;
@@ -522,30 +546,37 @@ int32_t handleExecRes(SRequestObj* pRequest) {
return code;
}
-SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery, void** res) {
- if (TSDB_CODE_SUCCESS == code) {
- switch (pQuery->execMode) {
- case QUERY_EXEC_MODE_LOCAL:
- code = execLocalCmd(pRequest, pQuery);
- break;
- case QUERY_EXEC_MODE_RPC:
- code = execDdlQuery(pRequest, pQuery);
- break;
- case QUERY_EXEC_MODE_SCHEDULE: {
- SArray* pNodeList = NULL;
- code = getPlan(pRequest, pQuery, &pRequest->body.pDag, &pNodeList);
- if (TSDB_CODE_SUCCESS == code) {
- code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList);
- }
- taosArrayDestroy(pNodeList);
- break;
+void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) {
+ SRequestObj* pRequest = (SRequestObj*) param;
+
+ // return to client
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+}
+
+SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQuery, void** res) {
+ int32_t code = 0;
+
+ switch (pQuery->execMode) {
+ case QUERY_EXEC_MODE_LOCAL:
+ code = execLocalCmd(pRequest, pQuery);
+ break;
+ case QUERY_EXEC_MODE_RPC:
+ code = execDdlQuery(pRequest, pQuery);
+ break;
+ case QUERY_EXEC_MODE_SCHEDULE: {
+ SArray* pNodeList = NULL;
+ code = getPlan(pRequest, pQuery, &pRequest->body.pDag, &pNodeList);
+ if (TSDB_CODE_SUCCESS == code) {
+ code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList);
}
- case QUERY_EXEC_MODE_EMPTY_RESULT:
- pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
- break;
- default:
- break;
+ taosArrayDestroy(pNodeList);
+ break;
}
+ case QUERY_EXEC_MODE_EMPTY_RESULT:
+ pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
+ break;
+ default:
+ break;
}
if (!keepQuery) {
@@ -582,7 +613,70 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
return pRequest;
}
- return launchQueryImpl(pRequest, pQuery, code, false, NULL);
+ return launchQueryImpl(pRequest, pQuery, false, NULL);
+}
+
+void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
+ void* pRes = NULL;
+
+ int32_t code = 0;
+ switch (pQuery->execMode) {
+ case QUERY_EXEC_MODE_LOCAL:
+ code = execLocalCmd(pRequest, pQuery);
+ break;
+ case QUERY_EXEC_MODE_RPC:
+ code = asyncExecDdlQuery(pRequest, pQuery);
+ break;
+ case QUERY_EXEC_MODE_SCHEDULE: {
+ SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
+
+ pRequest->type = pQuery->msgType;
+
+ SPlanContext cxt = {.queryId = pRequest->requestId,
+ .acctId = pRequest->pTscObj->acctId,
+ .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
+ .pAstRoot = pQuery->pRoot,
+ .showRewrite = pQuery->showRewrite,
+ .pMsg = pRequest->msgBuf,
+ .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE};
+
+ SAppInstInfo* pAppInfo = getAppInfo(pRequest);
+
+ if (TSDB_CODE_SUCCESS == code) {
+ code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pNodeList);
+ }
+
+ if (TSDB_CODE_SUCCESS == code) {
+ schedulerAsyncExecJob(pAppInfo->pTransporter, pNodeList, pRequest->body.pDag, &pRequest->body.queryJob,
+ pRequest->sqlstr, pRequest->metric.start, schedulerExecCb, pRequest);
+ // if (NULL != pRes) {
+ // code = validateSversion(pRequest, pRes);
+ // }
+ }
+
+ taosArrayDestroy(pNodeList);
+ break;
+ }
+ case QUERY_EXEC_MODE_EMPTY_RESULT:
+ pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
+ break;
+ default:
+ break;
+ }
+
+ // if (!keepQuery) {
+ // qDestroyQuery(pQuery);
+ // }
+
+ if (NULL != pRequest && TSDB_CODE_SUCCESS != code) {
+ pRequest->code = terrno;
+ }
+
+ // if (res) {
+ // *res = pRes;
+ // } else {
+// freeRequestRes(pRequest, pRes);
+// pRes = NULL;
}
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
@@ -665,17 +759,6 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
return pRequest;
}
-TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
- STscObj* pTscObj = (STscObj*)taos;
- if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
- tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
- terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
- return NULL;
- }
-
- return execQuery(pTscObj, sql, sqlLen);
-}
-
int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet) {
pEpSet->version = 0;
@@ -725,7 +808,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
return pTscObj;
}
- SRequestObj* pRequest = createRequest(pTscObj, fp, param, TDMT_MND_CONNECT);
+ SRequestObj* pRequest = createRequest(pTscObj, param, TDMT_MND_CONNECT);
if (pRequest == NULL) {
destroyTscObj(pTscObj);
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
@@ -842,8 +925,7 @@ void updateTargetEpSet(SMsgSendInfo* pSendInfo, STscObj* pTscObj, SRpcMsg* pMsg,
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
assert(pMsg->info.ahandle != NULL);
- SRequestObj* pRequest = NULL;
- STscObj* pTscObj = NULL;
+ STscObj* pTscObj = NULL;
if (pSendInfo->requestObjRefId != 0) {
SRequestObj* pRequest = (SRequestObj*)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId);
@@ -922,7 +1004,7 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
int32_t bytes = pResultInfo->fields[i].bytes;
if (IS_VAR_DATA_TYPE(type)) {
- if (pCol->offset[pResultInfo->current] != -1) {
+ if (!IS_VAR_NULL_TYPE(type, bytes) && pCol->offset[pResultInfo->current] != -1) {
char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData;
pResultInfo->length[i] = varDataLen(pStart);
@@ -943,7 +1025,7 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
}
}
-void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
+void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
assert(pRequest != NULL);
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
@@ -954,17 +1036,8 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU
return NULL;
}
- tsem_init(&schdRspSem, 0, 0);
-
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
- SSchdFetchParam param = {.pData = (void**)&pResInfo->pData, .code = &pRequest->code};
- pRequest->code = schedulerAsyncFetchRows(pRequest->body.queryJob, schdFetchCallback, ¶m);
- if (pRequest->code != TSDB_CODE_SUCCESS) {
- pResultInfo->numOfRows = 0;
- return NULL;
- }
-
- tsem_wait(&schdRspSem);
+ pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
if (pRequest->code != TSDB_CODE_SUCCESS) {
pResultInfo->numOfRows = 0;
return NULL;
@@ -993,8 +1066,12 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU
return pResultInfo->row;
}
-void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
- // return doAsyncFetchRows(pRequest, setupOneRowPtr, convertUcs4);
+static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) {
+ SSyncQueryParam* pParam = param;
+ tsem_post(&pParam->sem);
+}
+
+void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
assert(pRequest != NULL);
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
@@ -1005,29 +1082,12 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4)
return NULL;
}
- SReqResultInfo* pResInfo = &pRequest->body.resInfo;
- pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
- if (pRequest->code != TSDB_CODE_SUCCESS) {
- pResultInfo->numOfRows = 0;
- return NULL;
- }
-
- pRequest->code =
- setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4, true);
- if (pRequest->code != TSDB_CODE_SUCCESS) {
- pResultInfo->numOfRows = 0;
- return NULL;
- }
-
- tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
- pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId);
-
- if (pResultInfo->numOfRows == 0) {
- return NULL;
- }
+ SSyncQueryParam* pParam = pRequest->body.param;
+ taos_fetch_rows_a(pRequest, syncFetchFn, pParam);
+ tsem_wait(&pParam->sem);
}
- if (setupOneRowPtr) {
+ if (pRequest->code == TSDB_CODE_SUCCESS && setupOneRowPtr) {
doSetOneRowPtr(pResultInfo);
pResultInfo->current += 1;
}
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index 7d9de8da95f36528c44ce29ea787dabd2bf37050..bddc32ea207ce52802e0d3e01fa20223d1c71916 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -176,12 +176,39 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
return pResInfo->userFields;
}
+static void syncQueryFn(void* param, void* res, int32_t code) {
+ SSyncQueryParam* pParam = param;
+ pParam->pRequest = res;
+ pParam->pRequest->code = code;
+
+ tsem_post(&pParam->sem);
+}
+
TAOS_RES *taos_query(TAOS *taos, const char *sql) {
if (taos == NULL || sql == NULL) {
return NULL;
}
- return taos_query_l(taos, sql, (int32_t)strlen(sql));
+ STscObj* pTscObj = (STscObj*)taos;
+
+#if SYNC_ON_TOP_OF_ASYNC
+ SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(struct SSyncQueryParam));
+ tsem_init(¶m->sem, 0, 0);
+
+ taos_query_a(pTscObj, sql, syncQueryFn, param);
+ tsem_wait(¶m->sem);
+
+ return param->pRequest;
+#else
+ size_t sqlLen = strlen(sql);
+ if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
+ tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
+ terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
+ return NULL;
+ }
+
+ return execQuery(pTscObj, sql, sqlLen);
+#endif
}
TAOS_ROW taos_fetch_row(TAOS_RES *res) {
@@ -196,7 +223,11 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
return NULL;
}
+#if SYNC_ON_TOP_OF_ASYNC
+ return doAsyncFetchRow(pRequest, true, true);
+#else
return doFetchRows(pRequest, true, true);
+#endif
} else if (TD_RES_TMQ(res)) {
SMqRspObj *msg = ((SMqRspObj *)res);
@@ -206,6 +237,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
} else {
pResultInfo = tmqGetCurResInfo(res);
}
+
if (pResultInfo->current < pResultInfo->numOfRows) {
doSetOneRowPtr(pResultInfo);
pResultInfo->current += 1;
@@ -564,38 +596,195 @@ const char *taos_get_server_info(TAOS *taos) {
return pTscObj->ver;
}
+typedef struct SqlParseWrapper {
+ SParseContext* pCtx;
+ SCatalogReq catalogReq;
+ SRequestObj* pRequest;
+ SQuery* pQuery;
+} SqlParseWrapper;
+
+void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) {
+ SqlParseWrapper *pWrapper = (SqlParseWrapper*) param;
+ SQuery* pQuery = pWrapper->pQuery;
+ SRequestObj* pRequest = pWrapper->pRequest;
+
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ if (pQuery->haveResultSet) {
+ setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, (pQuery)->numOfResCols);
+ setResPrecision(&pRequest->body.resInfo, (pQuery)->precision);
+ }
+
+ TSWAP(pRequest->dbList, (pQuery)->pDbList);
+ TSWAP(pRequest->tableList, (pQuery)->pTableList);
+
+ taosMemoryFree(pWrapper);
+ launchAsyncQuery(pRequest, pQuery);
+ return;
+
+ _error:
+ taosMemoryFree(pWrapper);
+ tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:%" PRIx64, pRequest->self, tstrerror(code),
+ pRequest->requestId);
+ pRequest->code = code;
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+}
+
+// todo add retry before return user's callback
void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) {
+ ASSERT(fp != NULL);
+
if (taos == NULL || sql == NULL) {
- fp(param, NULL, TSDB_CODE_INVALID_PARA);
+ terrno = TSDB_CODE_INVALID_PARA;
+ fp(param, NULL, terrno);
return;
}
- SRequestObj* pRequest = NULL;
+ size_t sqlLen = strlen(sql);
+ if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
+ tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
+ terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
+
+ fp(param, NULL, terrno);
+ return;
+ }
+
+ SRequestObj *pRequest = NULL;
int32_t retryNum = 0;
int32_t code = 0;
- size_t sqlLen = strlen(sql);
+ // while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
+ code = buildRequest(taos, sql, sqlLen, &pRequest);
+ if (code != TSDB_CODE_SUCCESS) {
+ terrno = code;
+ fp(param, NULL, code);
+ return;
+ }
- while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
- pRequest = launchQuery(taos, sql, sqlLen);
- if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
- break;
- }
+ pRequest->body.queryFp = fp;
+ pRequest->body.param = param;
- code = refreshMeta(taos, pRequest);
- if (code) {
- pRequest->code = code;
- break;
- }
+ STscObj *pTscObj = pRequest->pTscObj;
- destroyRequest(pRequest);
+ SParseContext* pCxt = taosMemoryCalloc(1, sizeof(SParseContext));
+ *pCxt = (SParseContext){.requestId = pRequest->requestId,
+ .acctId = pTscObj->acctId,
+ .db = pRequest->pDb,
+ .topicQuery = false,
+ .pSql = pRequest->sqlstr,
+ .sqlLen = pRequest->sqlLen,
+ .pMsg = pRequest->msgBuf,
+ .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
+ .pTransporter = pTscObj->pAppInfo->pTransporter,
+ .pStmtCb = NULL,
+ .pUser = pTscObj->user,
+ .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
+ .async = true,};
+
+ pCxt->mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
+ code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCxt->pCatalog);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
}
+ SQuery * pQuery = NULL;
+ SCatalogReq catalogReq = {0};
+ code = qParseSqlSyntax(pCxt, &pQuery, &catalogReq);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ SqlParseWrapper *pWrapper = taosMemoryCalloc(1, sizeof(SqlParseWrapper));
+ pWrapper->pCtx = pCxt;
+ pWrapper->pQuery = pQuery;
+ pWrapper->pRequest = pRequest;
+ pWrapper->catalogReq = catalogReq;
+
+ code = catalogAsyncGetAllMeta(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, pRequest->requestId,
+ &catalogReq, retrieveMetaCallback, pWrapper, &pRequest->body.queryJob);
+
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ return;
+
+ // todo handle the retry process
+
+ // if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) {
+ // TSWAP(pRequest->dbList, (pQuery)->pDbList);
+ // TSWAP(pRequest->tableList, (pQuery)->pTableList);
+ // }
+
+ _error:
+ terrno = code;
+ pRequest->code = code;
fp(param, pRequest, code);
}
+static void fetchCallback(void* pResult, void* param, int32_t code) {
+ SRequestObj* pRequest = (SRequestObj*) param;
+
+ SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
+
+ pResultInfo->pData = pResult;
+ pResultInfo->numOfRows = 0;
+
+ if (code != TSDB_CODE_SUCCESS) {
+ pRequest->code = code;
+ pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
+ return;
+ }
+
+ if (pRequest->code != TSDB_CODE_SUCCESS) {
+ pRequest->code = code;
+ pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
+ }
+
+ pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResultInfo->pData, true, false);
+ if (pRequest->code != TSDB_CODE_SUCCESS) {
+ pResultInfo->numOfRows = 0;
+
+ pRequest->code = code;
+ pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
+ }
+
+ tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
+ pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed, pRequest->requestId);
+
+ pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
+}
+
void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
- // TODO
+ ASSERT (res != NULL && fp != NULL);
+
+ SRequestObj *pRequest = res;
+ pRequest->body.fetchFp = fp;
+
+ SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
+ if (taos_num_fields(pRequest) == 0) {
+ pResultInfo->numOfRows = 0;
+ pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
+ return;
+ }
+
+ if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
+ // All data has returned to App already, no need to try again
+ if (pResultInfo->completed) {
+ pResultInfo->numOfRows = 0;
+ pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
+ return;
+ }
+ }
+
+ schedulerAsyncFetchRows(pRequest->body.queryJob, fetchCallback, pRequest);
}
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp,
diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c
index 9de3ee1d0f1a8a529c7177329543e3379cdc6cbb..1039d36362f72f643978b964ccd874db186fbc88 100644
--- a/source/client/src/clientMsgHandler.c
+++ b/source/client/src/clientMsgHandler.c
@@ -33,7 +33,11 @@ int32_t genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
setErrno(pRequest, code);
taosMemoryFree(pMsg->pData);
- tsem_post(&pRequest->body.rspSem);
+ if (pRequest->body.queryFp != NULL) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
return code;
}
@@ -117,7 +121,12 @@ int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
}
- tsem_post(&pRequest->body.rspSem);
+
+ if (pRequest->body.queryFp) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
return code;
}
@@ -146,7 +155,13 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
if (code != TSDB_CODE_SUCCESS) {
taosMemoryFree(pMsg->pData);
setErrno(pRequest, code);
- tsem_post(&pRequest->body.rspSem);
+
+ if (pRequest->body.queryFp != NULL) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
+
return code;
}
@@ -185,7 +200,12 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
setConnectionDB(pRequest->pTscObj, db);
taosMemoryFree(pMsg->pData);
- tsem_post(&pRequest->body.rspSem);
+
+ if (pRequest->body.queryFp != NULL) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
return 0;
}
@@ -196,11 +216,13 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
taosMemoryFree(pMsg->pData);
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
- tsem_post(&pRequest->body.rspSem);
- return code;
}
- tsem_post(&pRequest->body.rspSem);
+ if (pRequest->body.queryFp != NULL) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
return code;
}
@@ -208,18 +230,20 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param;
if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code);
- tsem_post(&pRequest->body.rspSem);
- return code;
- }
-
- SDropDbRsp dropdbRsp = {0};
- tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
+ } else {
+ SDropDbRsp dropdbRsp = {0};
+ tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
- struct SCatalog* pCatalog = NULL;
- catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
- catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
+ struct SCatalog* pCatalog = NULL;
+ catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
+ catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
+ }
- tsem_post(&pRequest->body.rspSem);
+ if (pRequest->body.queryFp != NULL) {
+ pRequest->body.queryFp(pRequest->body.param, pRequest, code);
+ } else {
+ tsem_post(&pRequest->body.rspSem);
+ }
return code;
}
@@ -245,6 +269,7 @@ int32_t processAlterStbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
}
+// todo refactor: this arraylist is too large
void initMsgHandleFp() {
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp;
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp;
diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c
index 7d623072d664a4b9f1d77251812032f8c4fa4de1..c559ac58f8ae9888bbf9822b210ea414e0d0f869 100644
--- a/source/client/src/clientSml.c
+++ b/source/client/src/clientSml.c
@@ -1124,7 +1124,7 @@ static int32_t smlParseTelnetString(SSmlHandle *info, const char* sql, SSmlTable
}
static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, char *childTableName, bool isTag, SHashObj *dumplicateKey, SSmlMsgBuf *msg){
- if(isTag && len == 0){
+ if(len == 0){
return TSDB_CODE_SUCCESS;
}
@@ -2241,7 +2241,7 @@ static int32_t smlInsertData(SSmlHandle* info) {
}
info->cost.insertRpcTime = taosGetTimestampUs();
- launchQueryImpl(info->pRequest, info->pQuery, TSDB_CODE_SUCCESS, true, NULL);
+ launchQueryImpl(info->pRequest, info->pQuery, true, NULL);
info->affectedRows = taos_affected_rows(info->pRequest);
return info->pRequest->code;
@@ -2318,6 +2318,28 @@ cleanup:
return code;
}
+static int32_t isSchemalessDb(SSmlHandle* info){
+ SName name;
+ tNameSetDbName(&name, info->taos->acctId, info->taos->db, strlen(info->taos->db));
+ char dbFname[TSDB_DB_FNAME_LEN] = {0};
+ tNameGetFullDbName(&name, dbFname);
+ SDbCfgInfo pInfo = {0};
+ SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
+
+ int32_t code = catalogGetDBCfg(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, dbFname, &pInfo);
+ if (code != TSDB_CODE_SUCCESS) {
+ info->pRequest->code = code;
+ smlBuildInvalidDataMsg(&info->msgBuf, "catalogGetDBCfg error, code:", tstrerror(code));
+ return code;
+ }
+ if (!pInfo.schemaless){
+ info->pRequest->code = TSDB_CODE_SML_INVALID_DB_CONF;
+ smlBuildInvalidDataMsg(&info->msgBuf, "can not insert into schemaless db:", dbFname);
+ return TSDB_CODE_SML_INVALID_DB_CONF;
+ }
+ return TSDB_CODE_SUCCESS;
+}
+
/**
* taos_schemaless_insert() parse and insert data points into database according to
* different protocol.
@@ -2340,7 +2362,7 @@ cleanup:
*/
TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) {
- SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
if(!request){
uError("SML:taos_schemaless_insert error request is null");
return NULL;
@@ -2351,6 +2373,19 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
return (TAOS_RES*)request;
}
+ info->taos->schemalessType = 1;
+ if(request->pDb == NULL){
+ request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
+ smlBuildInvalidDataMsg(&info->msgBuf, "Database not specified", NULL);
+ goto end;
+ }
+
+ if(isSchemalessDb(info) != TSDB_CODE_SUCCESS){
+ request->code = TSDB_CODE_SML_INVALID_DB_CONF;
+ smlBuildInvalidDataMsg(&info->msgBuf, "Cannot write data to a non schemaless database", NULL);
+ goto end;
+ }
+
if (!lines) {
request->code = TSDB_CODE_SML_INVALID_DATA;
smlBuildInvalidDataMsg(&info->msgBuf, "lines is null", NULL);
@@ -2372,6 +2407,7 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
info->pRequest->code = smlProcess(info, lines, numLines);
end:
+ uDebug("result:%s", info->msgBuf.buf);
smlDestroyInfo(info);
return (TAOS_RES*)request;
}
diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c
index 3adb3684da1164363a1ffda4c26130643efc5f78..2dbba801279e3a7657d93b39607e112d4ca9f727 100644
--- a/source/client/src/clientStmt.c
+++ b/source/client/src/clientStmt.c
@@ -771,11 +771,10 @@ int stmtExec(TAOS_STMT* stmt) {
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE));
if (STMT_TYPE_QUERY == pStmt->sql.type) {
- launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true, NULL);
+ launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
} else {
STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash));
- launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true,
- (autoCreateTbl ? (void**)&pRsp : NULL));
+ launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, (autoCreateTbl ? (void**)&pRsp : NULL));
}
if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp
index b5b6ea65e0bab73e3d7801fc81fbcd29c013cc25..abeec373d9c32c811ce5281f52cf8eaf67a36e20 100644
--- a/source/client/test/clientTests.cpp
+++ b/source/client/test/clientTests.cpp
@@ -13,10 +13,12 @@
* along with this program. If not, see .
*/
-#include
-#include
-#include
#include
+#include
+#include "taoserror.h"
+#include "tglobal.h"
+#include "thash.h"
+#include "clientInt.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
@@ -24,7 +26,6 @@
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
-#include "../inc/clientInt.h"
#include "taos.h"
namespace {
@@ -41,6 +42,47 @@ void showDB(TAOS* pConn) {
printf("%s\n", str);
}
}
+
+void fetchCallback(void* param, void* res, int32_t numOfRow) {
+ printf("numOfRow = %d \n", numOfRow);
+ int numFields = taos_num_fields(res);
+ TAOS_FIELD *fields = taos_fetch_fields(res);
+ TAOS *_taos = (TAOS *)param;
+ if (numOfRow > 0) {
+ for (int i = 0; i < numOfRow; ++i) {
+ TAOS_ROW row = taos_fetch_row(res);
+
+ char temp[256] = {0};
+ taos_print_row(temp, row, fields, numFields);
+ printf("%s\n", temp);
+ }
+ taos_fetch_rows_a(res, fetchCallback, _taos);
+ } else {
+ printf("no more data, close the connection.\n");
+// taos_free_result(res);
+// taos_close(_taos);
+// taos_cleanup();
+ }
+}
+
+void queryCallback(void* param, void* res, int32_t code) {
+ if (code != TSDB_CODE_SUCCESS) {
+ printf("failed to execute, reason:%s\n", taos_errstr(res));
+ }
+ printf("start to fetch data\n");
+ taos_fetch_rows_a(res, fetchCallback, param);
+}
+
+void queryCallback1(void* param, void* res, int32_t code) {
+ if (code != TSDB_CODE_SUCCESS) {
+ printf("failed to execute, reason:%s\n", taos_errstr(res));
+ }
+
+ taos_free_result(res);
+
+ printf("exec query:\n");
+ taos_query_a(param, "select * from tm1", queryCallback, param);
+}
} // namespace
int main(int argc, char** argv) {
@@ -52,7 +94,7 @@ TEST(testCase, driverInit_Test) {
// taosInitGlobalCfg();
// taos_init();
}
-#if 0
+
TEST(testCase, connect_Test) {
// taos_options(TSDB_OPTION_CONFIGDIR, "/home/ubuntu/first/cfg");
@@ -62,7 +104,7 @@ TEST(testCase, connect_Test) {
}
taos_close(pConn);
}
-
+#if 0
TEST(testCase, create_user_Test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
assert(pConn != NULL);
@@ -432,7 +474,7 @@ TEST(testCase, create_multiple_tables) {
taos_free_result(pRes);
- pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
+ pRes = taos_query(pConn, "create table if not exists t_2 using st1 tags(1)");
if (taos_errno(pRes) != 0) {
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes);
@@ -440,7 +482,7 @@ TEST(testCase, create_multiple_tables) {
}
taos_free_result(pRes);
- pRes = taos_query(pConn, "create table t_3 using st1 tags(2)");
+ pRes = taos_query(pConn, "create table if not exists t_3 using st1 tags(2)");
if (taos_errno(pRes) != 0) {
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes);
@@ -480,9 +522,7 @@ TEST(testCase, show_table_Test) {
TAOS_RES* pRes = taos_query(pConn, "show tables");
if (taos_errno(pRes) != 0) {
printf("failed to show tables, reason:%s\n", taos_errstr(pRes));
- taos_free_result(pRes);
}
-
taos_free_result(pRes);
taos_query(pConn, "use abc1");
@@ -550,6 +590,7 @@ TEST(testCase, generated_request_id_test) {
taosHashCleanup(phash);
}
+
TEST(testCase, insert_test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
@@ -605,7 +646,7 @@ TEST(testCase, projection_query_tables) {
}
taos_free_result(pRes);
- for(int32_t i = 0; i < 1000000; i += 20) {
+ for(int32_t i = 0; i < 1000; i += 20) {
char sql[1024] = {0};
sprintf(sql,
"insert into tu values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
@@ -625,23 +666,23 @@ TEST(testCase, projection_query_tables) {
printf("start to insert next table\n");
- for(int32_t i = 0; i < 1000000; i += 20) {
- char sql[1024] = {0};
- sprintf(sql,
- "insert into tu2 values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
- "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
- "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
- "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)",
- i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, i + 7,
- i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, i + 14,
- i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19);
- TAOS_RES* p = taos_query(pConn, sql);
- if (taos_errno(p) != 0) {
- printf("failed to insert data, reason:%s\n", taos_errstr(p));
- }
-
- taos_free_result(p);
- }
+// for(int32_t i = 0; i < 1000000; i += 20) {
+// char sql[1024] = {0};
+// sprintf(sql,
+// "insert into tu2 values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
+// "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
+// "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
+// "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)",
+// i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, i + 7,
+// i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, i + 14,
+// i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19);
+// TAOS_RES* p = taos_query(pConn, sql);
+// if (taos_errno(p) != 0) {
+// printf("failed to insert data, reason:%s\n", taos_errstr(p));
+// }
+//
+// taos_free_result(p);
+// }
// pRes = taos_query(pConn, "select * from tu");
// if (taos_errno(pRes) != 0) {
@@ -692,8 +733,6 @@ TEST(testCase, projection_query_stables) {
taos_close(pConn);
}
-#endif
-
TEST(testCase, agg_query_tables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
@@ -706,7 +745,7 @@ TEST(testCase, agg_query_tables) {
}
taos_free_result(pRes);
- pRes = taos_query(pConn, "explain analyze select count(*) from tu interval(1s)");
+ pRes = taos_query(pConn, "show stables");
if (taos_errno(pRes) != 0) {
printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes);
@@ -734,5 +773,26 @@ TEST(testCase, agg_query_tables) {
taos_free_result(pRes);
taos_close(pConn);
}
+#endif
+
+/*
+--- copy the following script in the shell to setup the environment ---
+
+create database test;
+use test;
+create table m1(ts timestamp, k int) tags(a int);
+create table tm0 using m1 tags(1);
+create table tm1 using m1 tags(2);
+insert into tm0 values('2021-1-1 1:1:1.120', 1) ('2021-1-1 1:1:2.9', 2) tm1 values('2021-1-1 1:1:1.120', 11) ('2021-1-1 1:1:2.99', 22);
+
+ */
+TEST(testCase, async_api_test) {
+ TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(pConn, nullptr);
+
+ taos_query_a(pConn, "drop table test.tm0", queryCallback, pConn);
+ getchar();
+ taos_close(pConn);
+}
#pragma GCC diagnostic pop
diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp
index 217699e36071e1e4c5e93e391e77a95c4f857af8..1358d45f3063a256300728764efedbecc49d0419 100644
--- a/source/client/test/smlTest.cpp
+++ b/source/client/test/smlTest.cpp
@@ -486,7 +486,7 @@ TEST(testCase, smlProcess_influx_Test) {
pRes = taos_query(taos, "use inflx_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -607,7 +607,7 @@ TEST(testCase, smlParseLine_error_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -656,7 +656,7 @@ TEST(testCase, smlProcess_telnet_Test) {
pRes = taos_query(taos, "use telnet_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -710,7 +710,7 @@ TEST(testCase, smlProcess_json1_Test) {
pRes = taos_query(taos, "use json_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -779,7 +779,7 @@ TEST(testCase, smlProcess_json2_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -823,7 +823,7 @@ TEST(testCase, smlProcess_json3_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -895,7 +895,7 @@ TEST(testCase, smlProcess_json4_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -957,7 +957,7 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1006,7 +1006,7 @@ TEST(testCase, smlParseTelnetLine_diff_type_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1033,7 +1033,7 @@ TEST(testCase, smlParseTelnetLine_json_error_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1101,7 +1101,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1146,7 +1146,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1191,7 +1191,7 @@ TEST(testCase, sml_TD15662_Test) {
pRes = taos_query(taos, "use db_15662");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
@@ -1218,7 +1218,7 @@ TEST(testCase, sml_TD15735_Test) {
pRes = taos_query(taos, "use sml_db");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
@@ -1244,7 +1244,7 @@ TEST(testCase, sml_TD15742_Test) {
pRes = taos_query(taos, "use TD15742");
taos_free_result(pRes);
- SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
+ SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
ASSERT_NE(request, nullptr);
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
@@ -1258,4 +1258,48 @@ TEST(testCase, sml_TD15742_Test) {
destroyRequest(request);
smlDestroyInfo(info);
-}
\ No newline at end of file
+}
+
+TEST(testCase, sml_params_Test) {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
+
+ TAOS_RES* pRes = taos_query(taos, "create database if not exists param");
+ taos_free_result(pRes);
+
+ const char *sql[] = {
+ "test_ms,t0=t c0=f 1626006833641",
+ };
+ TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
+ ASSERT_EQ(taos_errno(res), TSDB_CODE_PAR_DB_NOT_SPECIFIED);
+ taos_free_result(pRes);
+
+ pRes = taos_query(taos, "use param");
+ taos_free_result(pRes);
+
+ res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
+ ASSERT_EQ(taos_errno(res), TSDB_CODE_SML_INVALID_DB_CONF);
+ taos_free_result(pRes);
+}
+
+TEST(testCase, sml_oom_Test) {
+ TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(taos, nullptr);
+
+ TAOS_RES* pRes = taos_query(taos, "create database if not exists oom schemaless 1");
+ taos_free_result(pRes);
+
+ const char *sql[] = {
+ //"test_ms,t0=t c0=f 1626006833641",
+ "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pgxbrbga\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"gviggpmi\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000",
+ "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"cexkarjn\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"rzwwuoxu\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000",
+ "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"xphrlkey\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"llsawebj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000",
+ "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jwpkipff\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"euzzhcvu\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jumhnsvw\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"fnetgdhj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"vrmmpgqe\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lnpfjapr\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"gvbhmsfr\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"kydxrxwc\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pfyarryq\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"uxptotap\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"prolhudh\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ttxaxnac\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"dfgvmjmz\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"bloextkn\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"dvjxwzsi\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"aigjomaf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"refbidtf\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vuanlfpz\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nbpajxkx\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ktzzauxh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"prcwdjct\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vmbhvjtp\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"liuddtuz\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"pddsktow\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"algldlvl\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"mlmnjgdl\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"oiynpcog\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"wmynbagb\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"asvyulrm\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ohaacrkp\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"ytyejhiq\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"bbznuerb\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"lpebcibw\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"xmqrbafv\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"lnmwpdne\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"jpcsjqun\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"mmxqmavz\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"hhsbgaow\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"uwogyuud\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ytxpaxnk\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"wouwdvtt\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"iitwikkh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"lgyzuyaq\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"bdtiigxi\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"qpnsvdhw\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"pjxihgvu\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"ksxkfetn\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ocukufqs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"qzerxmpe\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"qwcfdyxs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jldrpmmd\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lucxlfzc\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"rcewrvya\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"dknvaphs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nxtxgzdr\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"mbvuugwz\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"uikakffu\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"mwmtqsma\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"bfcxrrpa\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ksajygdj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"vmhhszyv\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"urwjgvut\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jrvytcxy\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"evqkzygh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"zitdznhg\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"tpqekrxa\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"yrrbgjtk\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"bnphiuyq\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"huknehjn\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"iudbxfke\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"fjmolwbn\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"gukzgcjs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"bjvdtlgq\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"phxnesxh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"qgpgckvc\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"yechqtfa\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pbouxywy\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"kxtuojyo\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"txaniwlj\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"fixgufrj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"okzvalwq\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"iitawgbn\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"gayvmird\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"dprkfjph\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"kmuccshq\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vkslsdsd\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"dukccdqk\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"leztxmqf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"kltixbwz\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"xqhkweef\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"idxsimvz\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vbruvcpk\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"uxandqkd\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"dsiosysh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"kxuyanpp\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"wkrktags\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"yvizzpiv\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ddnefben\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"novmfmbc\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"fnusxsfu\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"ouerfjap\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"sigognkf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"slvzhede\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"bknerect\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"tmhcdfjb\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"hpnoanpp\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"okmhelnc\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"xcernjin\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jdmiismg\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"tmnqozrf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"zgwrftkx\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zyamlwwh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nuedqcro\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lpsvyqaa\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"mneitsul\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vpleinwb\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"njxuaedy\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"sdgxpqmu\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"yjirrebp\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ikqndzfj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"ghnfdxhr\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"hrwczpvo\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nattumpb\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zoyfzazn\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"rdwemofy\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"phkgsjeg\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pyhvvjrt\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zfslyton\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"bxwjzeri\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"uovzzgjv\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"cfjmacvr\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"jefqgzqx\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"njrksxmr\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"mhvabvgn\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"kfekjltr\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lexfaaby\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"zbblsmwq\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"oqcombkx\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"rcdmhzyw\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"otksuean\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"itbdvowq\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"tswtmhex\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"xoukkzid\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"guangmpq\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"rayxzuky\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lspwucrv\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pdprzzkf\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"sddqrtza\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"kabndgkx\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"aglnqqxs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"fiwpzmdr\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"hxctooen\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pckjpwyh\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ivmvsbai\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"eljdclst\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"rwgdctie\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"zlnthxoz\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"ljtxelle\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"llfggdpy\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"tvnridze\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"hxjpgube\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zmldmquq\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"bggqwcoj\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"drksfofm\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"jcsixens\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"cdwnwhaf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nngpumuq\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"hylgooci\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"cozeyjys\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"lcgpfcsa\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"qdtzhtyd\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"txpubynb\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"gbslzbtu\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"buihcpcl\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"ayqezaiq\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zgkgtilj\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"bcjopqif\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"mfzxiaqt\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"xmnlqxoj\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"reyiklyf\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"xssuomhk\",t8=L\"ncharTagValue\" c0=False,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"liazkjll\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"nigjlblo\",t8=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"vmojyznk\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"dotkbvrz\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"kuwdyydw\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"slsfqydw\",t8=L\"ncharTagValue\" c0=t,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"zyironhd\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pktwfhzi\",t8=L\"ncharTagValue\" c0=T,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"xybavsvh\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"pyrxemvx\",t8=L\"ncharTagValue\" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"tlfihwjs\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000", "ogirwqci,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"neumakmg\",t8=L\"ncharTagValue\" c0=F,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"wxqingoa\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000",
+ };
+ pRes = taos_query(taos, "use oom");
+ taos_free_result(pRes);
+
+ TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 100, TSDB_SML_LINE_PROTOCOL, 0);
+ ASSERT_EQ(taos_errno(res), 0);
+ taos_free_result(pRes);
+}
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index b163ac32bf55bbae00d3213f8f11c42411c2fe70..5b8d214cb412bd8b439880157afbc61e07025af2 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -78,7 +78,7 @@ static const SSysDbTableSchema userDBSchema[] = {
{.name = "replica", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
{.name = "strict", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "duration", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
- {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
+ {.name = "keep", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "buffer", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
{.name = "pagesize", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
{.name = "pages", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
@@ -91,6 +91,8 @@ static const SSysDbTableSchema userDBSchema[] = {
{.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "single_stable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
{.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
+ {.name = "schemaless", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
+
// {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update
};
diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c
index 9d16de43b392ebd49699739990e8d94aa7386a1e..f77b823f3c7d8a9e3f62e98e0f967f9d66ad83d3 100644
--- a/source/common/src/tdatablock.c
+++ b/source/common/src/tdatablock.c
@@ -355,14 +355,19 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex)
return -1;
}
- int32_t index = (tsColumnIndex == -1) ? 0 : tsColumnIndex;
+ int32_t index = (tsColumnIndex == -1) ? 0 : tsColumnIndex;
+
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, index);
if (pColInfoData->info.type != TSDB_DATA_TYPE_TIMESTAMP) {
return 0;
}
- pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
- pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
+ TSKEY skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
+ TSKEY ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
+
+ pDataBlock->info.window.skey = TMIN(skey, ekey);
+ pDataBlock->info.window.ekey = TMAX(skey, ekey);
+
return 0;
}
@@ -1273,25 +1278,39 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
memmove(nullBitmap, nullBitmap + n / 8, newLen);
} else {
int32_t tail = n % 8;
- int32_t i = 0;
-
+ int32_t i = 0;
uint8_t* p = (uint8_t*)nullBitmap;
- while (i < len) {
- uint8_t v = p[i];
- p[i] = 0;
- p[i] = (v << tail);
+ if (n < 8) {
+ while (i < len) {
+ uint8_t v = p[i]; // source bitmap value
+ p[i] = (v << tail);
+
+ if (i < len - 1) {
+ uint8_t next = p[i + 1];
+ p[i] |= (next >> (8 - tail));
+ }
- if (i < len - 1) {
- uint8_t next = p[i + 1];
- p[i] |= (next >> (8 - tail));
+ i += 1;
}
+ } else if (n > 8) {
+ int32_t gap = len - newLen;
+ while(i < newLen) {
+ uint8_t v = p[i + gap];
+ p[i] = (v << tail);
+
+ if (i < newLen - 1) {
+ uint8_t next = p[i + gap + 1];
+ p[i] |= (next >> (8 - tail));
+ }
- i += 1;
+ i += 1;
+ }
}
}
}
+
static void colDataTrimFirstNRows(SColumnInfoData* pColInfoData, size_t n, size_t total) {
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
memmove(pColInfoData->varmeta.offset, &pColInfoData->varmeta.offset[n], (total - n) * sizeof(int32_t));
@@ -1803,3 +1822,99 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
taosArrayDestroy(tagArray);
return ret;
}
+
+void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress) {
+ int32_t* actualLen = (int32_t*)data;
+ data += sizeof(int32_t);
+
+ uint64_t* groupId = (uint64_t*)data;
+ data += sizeof(uint64_t);
+
+ int32_t* colSizes = (int32_t*)data;
+ data += numOfCols * sizeof(int32_t);
+
+ *dataLen = (numOfCols * sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t));
+
+ int32_t numOfRows = pBlock->info.rows;
+ for (int32_t col = 0; col < numOfCols; ++col) {
+ SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, col);
+
+ // copy the null bitmap
+ if (IS_VAR_DATA_TYPE(pColRes->info.type)) {
+ size_t metaSize = numOfRows * sizeof(int32_t);
+ memcpy(data, pColRes->varmeta.offset, metaSize);
+ data += metaSize;
+ (*dataLen) += metaSize;
+ } else {
+ int32_t len = BitmapLen(numOfRows);
+ memcpy(data, pColRes->nullbitmap, len);
+ data += len;
+ (*dataLen) += len;
+ }
+
+ if (needCompress) {
+ colSizes[col] = blockCompressColData(pColRes, numOfRows, data, needCompress);
+ data += colSizes[col];
+ (*dataLen) += colSizes[col];
+ } else {
+ colSizes[col] = colDataGetLength(pColRes, numOfRows);
+ (*dataLen) += colSizes[col];
+ memmove(data, pColRes->pData, colSizes[col]);
+ data += colSizes[col];
+ }
+
+ colSizes[col] = htonl(colSizes[col]);
+ }
+
+ *actualLen = *dataLen;
+ *groupId = pBlock->info.groupId;
+}
+
+const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData) {
+ blockDataEnsureCapacity(pBlock, numOfRows);
+ const char* pStart = pData;
+
+ int32_t dataLen = *(int32_t*)pStart;
+ pStart += sizeof(int32_t);
+
+ pBlock->info.groupId = *(uint64_t*)pStart;
+ pStart += sizeof(uint64_t);
+
+ int32_t* colLen = (int32_t*)pStart;
+ pStart += sizeof(int32_t) * numOfCols;
+
+ for (int32_t i = 0; i < numOfCols; ++i) {
+ colLen[i] = htonl(colLen[i]);
+ ASSERT(colLen[i] >= 0);
+
+ SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
+ if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
+ pColInfoData->varmeta.length = colLen[i];
+ pColInfoData->varmeta.allocLen = colLen[i];
+
+ memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows);
+ pStart += sizeof(int32_t) * numOfRows;
+
+ if (colLen[i] > 0) {
+ taosMemoryFreeClear(pColInfoData->pData);
+ pColInfoData->pData = taosMemoryMalloc(colLen[i]);
+ }
+ } else {
+ memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows));
+ pStart += BitmapLen(numOfRows);
+ }
+
+ if (colLen[i] > 0) {
+ memcpy(pColInfoData->pData, pStart, colLen[i]);
+ }
+
+ // TODO
+ // setting this flag to true temporarily so aggregate function on stable will
+ // examine NULL value for non-primary key column
+ pColInfoData->hasNull = true;
+ pStart += colLen[i];
+ }
+
+ ASSERT(pStart - pData == dataLen);
+ return pStart;
+}
\ No newline at end of file
diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c
index 65daee650840a5bea69b2c0dcb687ea76b4dc705..287dba6d3badaa1c4a1f077d8cea805981da09e7 100644
--- a/source/common/src/tdataformat.c
+++ b/source/common/src/tdataformat.c
@@ -142,202 +142,314 @@ static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) {
}
// STSRow2 ========================================================================
-static void tTupleTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 *pRow) {
- int32_t nColVal = taosArrayGetSize(pArray);
+static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) {
+ if (pb) {
+ switch (flags & 0xf) {
+ case TSROW_HAS_NULL | TSROW_HAS_NONE:
+ case TSROW_HAS_VAL | TSROW_HAS_NONE:
+ if (v) {
+ SET_BIT1(pb, idx, (uint8_t)1);
+ } else {
+ SET_BIT1(pb, idx, (uint8_t)0);
+ }
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NULL:
+ v = v - 1;
+ SET_BIT1(pb, idx, v);
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
+ SET_BIT2(pb, idx, v);
+ break;
+
+ default:
+ ASSERT(0);
+ }
+ }
+}
+#define SET_IDX(p, i, n, f) \
+ do { \
+ if ((f)&TSROW_KV_SMALL) { \
+ ((uint8_t *)(p))[i] = (n); \
+ } else if ((f)&TSROW_KV_MID) { \
+ ((uint16_t *)(p))[i] = (n); \
+ } else { \
+ ((uint32_t *)(p))[i] = (n); \
+ } \
+ } while (0)
+
+int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
+ int32_t code = 0;
STColumn *pTColumn;
SColVal *pColVal;
+ int32_t nColVal = taosArrayGetSize(pArray);
+ int32_t iColVal;
ASSERT(nColVal > 0);
- pRow->sver = pTSchema->version;
-
- // ts
- pTColumn = &pTSchema->columns[0];
- pColVal = (SColVal *)taosArrayGet(pArray, 0);
-
- ASSERT(pTColumn->colId == 0 && pColVal->cid == 0);
- ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
-
- pRow->ts = pColVal->value.ts;
-
- // other fields
- int32_t iColVal = 1;
- int32_t bidx;
- uint32_t nv = 0;
- uint8_t *pb = NULL;
- uint8_t *pf = NULL;
- uint8_t *pv = NULL;
+ // try
uint8_t flags = 0;
- for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
- bidx = iColumn - 1;
- pTColumn = &pTSchema->columns[iColumn];
+ uint32_t ntv = 0;
+ uint32_t nkv = 0;
+ int16_t nTag = 0;
+ uint32_t maxIdx = 0;
+ iColVal = 0;
+ for (int32_t iColumn = 0; iColumn < pTSchema->numOfCols; iColumn++) {
+ pTColumn = &pTSchema->columns[iColumn];
if (iColVal < nColVal) {
pColVal = (SColVal *)taosArrayGet(pArray, iColVal);
} else {
pColVal = NULL;
}
- if (pColVal) {
- if (pColVal->cid == pTColumn->colId) {
- iColVal++;
- if (pColVal->isNone) {
- goto _set_none;
- } else if (pColVal->isNull) {
- goto _set_null;
+ if (iColumn == 0) {
+ ASSERT(pColVal->cid == pTColumn->colId);
+ ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
+ ASSERT(pTColumn->colId == 0);
+
+ iColVal++;
+ } else {
+ if (pColVal) {
+ if (pColVal->cid == pTColumn->colId) {
+ iColVal++;
+
+ if (pColVal->isNone) {
+ flags |= TSROW_HAS_NONE;
+ } else if (pColVal->isNull) {
+ flags |= TSROW_HAS_NULL;
+ maxIdx = nkv;
+ nTag++;
+ nkv += tPutI16v(NULL, -pTColumn->colId);
+ } else {
+ flags |= TSROW_HAS_VAL;
+ maxIdx = nkv;
+ nTag++;
+ nkv += tPutI16v(NULL, pTColumn->colId);
+ nkv += tPutValue(NULL, &pColVal->value, pTColumn->type);
+ if (IS_VAR_DATA_TYPE(pTColumn->type)) {
+ ntv += tPutValue(NULL, &pColVal->value, pTColumn->type);
+ }
+ }
+ } else if (pColVal->cid > pTColumn->colId) {
+ flags |= TSROW_HAS_NONE;
} else {
- goto _set_value;
+ ASSERT(0);
}
- } else if (pColVal->cid > pTColumn->colId) {
- goto _set_none;
} else {
- ASSERT(0);
+ flags |= TSROW_HAS_NONE;
}
- } else {
- goto _set_none;
}
+ }
- _set_none:
- flags |= TSROW_HAS_NONE;
- // SET_BIT2(pb, bidx, 0); (todo)
- continue;
+ ASSERT(flags);
- _set_null:
- flags != TSROW_HAS_NULL;
- // SET_BIT2(pb, bidx, 1); (todo)
- continue;
+ // decide
+ uint32_t nData = 0;
+ uint32_t nDataT = 0;
+ uint32_t nDataK = 0;
+ if (flags == TSROW_HAS_NONE || flags == TSROW_HAS_NULL) {
+ nData = 0;
+ } else {
+ switch (flags) {
+ case TSROW_HAS_VAL:
+ nDataT = pTSchema->flen + ntv;
+ break;
+ case TSROW_HAS_NULL | TSROW_HAS_NONE:
+ nDataT = BIT1_SIZE(pTSchema->numOfCols - 1);
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NONE:
+ case TSROW_HAS_VAL | TSROW_HAS_NULL:
+ nDataT = BIT1_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + ntv;
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
+ nDataT = BIT2_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + ntv;
+ break;
+ default:
+ ASSERT(0);
+ }
- _set_value:
- flags != TSROW_HAS_VAL;
- // SET_BIT2(pb, bidx, 2); (todo)
- if (IS_VAR_DATA_TYPE(pTColumn->type)) {
- // nv += tPutColVal(pv ? pv + nv : pv, pColVal, pTColumn->type, 1);
+ uint8_t tflags = 0;
+ if (maxIdx <= UINT8_MAX) {
+ nDataK = sizeof(STSKVRow) + sizeof(uint8_t) * nTag + nkv;
+ tflags |= TSROW_KV_SMALL;
+ } else if (maxIdx <= UINT16_MAX) {
+ nDataK = sizeof(STSKVRow) + sizeof(uint16_t) * nTag + nkv;
+ tflags |= TSROW_KV_MID;
} else {
- // tPutColVal(pf ? pf + pTColumn->offset : pf, pColVal, pTColumn->type, 1);
+ nDataK = sizeof(STSKVRow) + sizeof(uint32_t) * nTag + nkv;
+ tflags |= TSROW_KV_BIG;
}
- continue;
- }
- ASSERT(flags);
- switch (flags & 0xf) {
- case TSROW_HAS_NONE:
- case TSROW_HAS_NULL:
- pRow->nData = 0;
- break;
- case TSROW_HAS_VAL:
- pRow->nData = pTSchema->flen + nv;
- break;
- case TSROW_HAS_NULL | TSROW_HAS_NONE:
- pRow->nData = BIT1_SIZE(pTSchema->numOfCols - 1);
- break;
- case TSROW_HAS_VAL | TSROW_HAS_NONE:
- case TSROW_HAS_VAL | TSROW_HAS_NULL:
- pRow->nData = BIT1_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + nv;
- break;
- case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
- pRow->nData = BIT2_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + nv;
- break;
- default:
- break;
+ if (nDataT < nDataK) {
+ nData = nDataT;
+ } else {
+ nData = nDataK;
+ flags |= tflags;
+ }
}
-}
-
-static void tMapTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 *pRow) {
- int32_t nColVal = taosArrayGetSize(pArray);
- STColumn *pTColumn;
- SColVal *pColVal;
- ASSERT(nColVal > 0);
-
- pRow->sver = pTSchema->version;
-
- // ts
- pTColumn = &pTSchema->columns[0];
- pColVal = (SColVal *)taosArrayGet(pArray, 0);
+ // alloc
+ if (pBuilder) {
+ // create from a builder
+ if (nData == 0) {
+ pBuilder->tsRow.nData = 0;
+ pBuilder->tsRow.pData = NULL;
+ } else {
+ if (pBuilder->szBuf < nData) {
+ uint8_t *p = taosMemoryRealloc(pBuilder->pBuf, nData);
+ if (p == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+ pBuilder->pBuf = p;
+ pBuilder->szBuf = nData;
+ }
- ASSERT(pTColumn->colId == 0 && pColVal->cid == 0);
- ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
+ pBuilder->tsRow.nData = nData;
+ pBuilder->tsRow.pData = pBuilder->pBuf;
+ }
- pRow->ts = pColVal->value.ts;
+ *ppRow = &pBuilder->tsRow;
+ } else {
+ // create a new one
+ *ppRow = (STSRow2 *)taosMemoryMalloc(sizeof(STSRow2));
+ if (*ppRow == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+ if (nData == 0) {
+ (*ppRow)->nData = 0;
+ (*ppRow)->pData = NULL;
+ } else {
+ (*ppRow)->nData = nData;
+ (*ppRow)->pData = taosMemoryMalloc(nData);
+ if ((*ppRow)->pData == NULL) {
+ taosMemoryFree(*ppRow);
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+ }
+ }
- // other fields
- int32_t iColVal = 1;
- uint32_t nv = 0;
- uint8_t *pv = NULL;
- uint8_t *pidx = NULL;
- uint8_t flags = 0;
- int16_t nCol = 0;
- for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
- pTColumn = &pTSchema->columns[iColumn];
+ // build
+ (*ppRow)->flags = flags;
+ (*ppRow)->sver = pTSchema->version;
- if (iColVal < nColVal) {
- pColVal = (SColVal *)taosArrayGet(pArray, iColVal);
+ pColVal = (SColVal *)taosArrayGet(pArray, 0);
+ (*ppRow)->ts = pColVal->value.ts;
+
+ if ((*ppRow)->pData) {
+ STSKVRow *pTSKVRow = NULL;
+ uint8_t *pidx = NULL;
+ uint8_t *pkv = NULL;
+ uint8_t *pb = NULL;
+ uint8_t *pf = NULL;
+ uint8_t *ptv = NULL;
+ nkv = 0;
+ ntv = 0;
+ iColVal = 1;
+
+ if (flags & 0xf0 == 0) {
+ switch (flags & 0xf) {
+ case TSROW_HAS_VAL:
+ pf = (*ppRow)->pData;
+ ptv = pf + pTSchema->flen;
+ break;
+ case TSROW_HAS_NULL | TSROW_HAS_NONE:
+ pb = (*ppRow)->pData;
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NONE:
+ case TSROW_HAS_VAL | TSROW_HAS_NULL:
+ pb = (*ppRow)->pData;
+ pf = pb + BIT1_SIZE(pTSchema->numOfCols - 1);
+ ptv = pf + pTSchema->flen;
+ break;
+ case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
+ pb = (*ppRow)->pData;
+ pf = pb + BIT2_SIZE(pTSchema->numOfCols - 1);
+ ptv = pf + pTSchema->flen;
+ break;
+ default:
+ ASSERT(0);
+ }
} else {
- pColVal = NULL;
+ pTSKVRow = (STSKVRow *)(*ppRow)->pData;
+ pTSKVRow->nCols = 0;
+ pidx = pTSKVRow->idx;
+ if (flags & TSROW_KV_SMALL) {
+ pkv = pidx + sizeof(uint8_t) * nTag;
+ } else if (flags & TSROW_KV_MID) {
+ pkv = pidx + sizeof(uint16_t) * nTag;
+ } else {
+ pkv = pidx + sizeof(uint32_t) * nTag;
+ }
}
- if (pColVal) {
- if (pColVal->cid == pTColumn->colId) {
- iColVal++;
- if (pColVal->isNone) {
+ for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
+ pTColumn = &pTSchema->columns[iColumn];
+ if (iColVal < nColVal) {
+ pColVal = (SColVal *)taosArrayGet(pArray, iColVal);
+ } else {
+ pColVal = NULL;
+ }
+
+ if (pColVal) {
+ if (pColVal->cid == pTColumn->colId) {
+ iColVal++;
+
+ if (pColVal->isNone) {
+ goto _set_none;
+ } else if (pColVal->isNull) {
+ goto _set_null;
+ } else {
+ goto _set_value;
+ }
+ } else if (pColVal->cid > pTColumn->colId) {
goto _set_none;
- } else if (pColVal->isNull) {
- goto _set_null;
} else {
- goto _set_value;
+ ASSERT(0);
}
- } else if (pColVal->cid > pTColumn->colId) {
- goto _set_none;
} else {
- ASSERT(0);
+ goto _set_none;
}
- } else {
- goto _set_none;
- }
- _set_none:
- flags |= TSROW_HAS_NONE;
- continue;
-
- _set_null:
- flags != TSROW_HAS_NULL;
- pidx[nCol++] = nv;
- // nv += tPutColVal(pv ? pv + nv : pv, pColVal, pTColumn->type, 0);
- continue;
-
- _set_value:
- flags != TSROW_HAS_VAL;
- pidx[nCol++] = nv;
- // nv += tPutColVal(pv ? pv + nv : pv, pColVal, pTColumn->type, 0);
- continue;
- }
-
- if (nv <= UINT8_MAX) {
- // small
- } else if (nv <= UINT16_MAX) {
- // mid
- } else {
- // large
- }
-}
+ _set_none:
+ if (flags & 0xf0 == 0) {
+ setBitMap(pb, 0, iColumn - 1, flags);
+ }
+ continue;
-// try-decide-build
-int32_t tTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
- int32_t code = 0;
- STSRow2 rowT = {0};
- STSRow2 rowM = {0};
+ _set_null:
+ if (flags & 0xf0 == 0) {
+ setBitMap(pb, 1, iColumn - 1, flags);
+ } else {
+ SET_IDX(pidx, pTSKVRow->nCols, nkv, flags);
+ pTSKVRow->nCols++;
+ nkv += tPutI16v(pkv + nkv, -pTColumn->colId);
+ }
+ continue;
- // try
- tTupleTSRowNew(pArray, pTSchema, &rowT);
- tMapTSRowNew(pArray, pTSchema, &rowM);
+ _set_value:
+ if (flags & 0xf0 == 0) {
+ setBitMap(pb, 2, iColumn - 1, flags);
- // decide & build
- if (rowT.nData <= rowM.nData) {
- tTupleTSRowNew(pArray, pTSchema, &rowT);
- } else {
- tMapTSRowNew(pArray, pTSchema, &rowM);
+ if (IS_VAR_DATA_TYPE(pTColumn->type)) {
+ *(VarDataOffsetT *)(pf + pTColumn->offset) = ntv;
+ ntv += tPutValue(ptv + ntv, &pColVal->value, pTColumn->type);
+ } else {
+ tPutValue(pf + pTColumn->offset, &pColVal->value, pTColumn->type);
+ }
+ } else {
+ SET_IDX(pidx, pTSKVRow->nCols, nkv, flags);
+ pTSKVRow->nCols++;
+ nkv += tPutI16v(pkv + nkv, pColVal->cid);
+ nkv += tPutValue(pkv + nkv, &pColVal->value, pTColumn->type);
+ }
+ continue;
+ }
}
+_exit:
return code;
}
@@ -626,266 +738,8 @@ void tTSchemaDestroy(STSchema *pTSchema) {
}
// STSRowBuilder
-#if 0
-int32_t tTSRowBuilderInit(STSRowBuilder *pBuilder, int32_t sver, int32_t nCols, SSchema *pSchema) {
- if (tTSchemaCreate(sver, pSchema, nCols, &pBuilder->pTSchema) < 0) return -1;
-
- pBuilder->szBitMap1 = BIT1_SIZE(nCols - 1);
- pBuilder->szBitMap2 = BIT2_SIZE(nCols - 1);
- pBuilder->szKVBuf =
- sizeof(STSKVRow) + sizeof(SKVIdx) * (nCols - 1) + pBuilder->pTSchema->flen + pBuilder->pTSchema->vlen;
- pBuilder->szTPBuf = pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->pTSchema->vlen;
- pBuilder->pKVBuf = taosMemoryMalloc(pBuilder->szKVBuf);
- if (pBuilder->pKVBuf == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- tTSchemaDestroy(pBuilder->pTSchema);
- return -1;
- }
- pBuilder->pTPBuf = taosMemoryMalloc(pBuilder->szTPBuf);
- if (pBuilder->pTPBuf == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- taosMemoryFree(pBuilder->pKVBuf);
- tTSchemaDestroy(pBuilder->pTSchema);
- return -1;
- }
-
- return 0;
-}
-
-void tTSRowBuilderClear(STSRowBuilder *pBuilder) {
- if (pBuilder->pTPBuf) {
- taosMemoryFree(pBuilder->pTPBuf);
- pBuilder->pTPBuf = NULL;
- }
- if (pBuilder->pKVBuf) {
- taosMemoryFree(pBuilder->pKVBuf);
- pBuilder->pKVBuf = NULL;
- }
- tTSchemaDestroy(pBuilder->pTSchema);
- pBuilder->pTSchema = NULL;
-}
-
-void tTSRowBuilderReset(STSRowBuilder *pBuilder) {
- for (int32_t iCol = pBuilder->pTSchema->numOfCols - 1; iCol >= 0; iCol--) {
- STColumn *pTColumn = &pBuilder->pTSchema->columns[iCol];
- COL_CLR_SET(pTColumn->flags);
- }
-
- pBuilder->iCol = 0;
- ((STSKVRow *)pBuilder->pKVBuf)->nCols = 0;
- pBuilder->vlenKV = 0;
- pBuilder->vlenTP = 0;
- pBuilder->row.flags = 0;
-}
-
-int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, uint8_t *pData, uint32_t nData) {
- STColumn *pTColumn = &pBuilder->pTSchema->columns[pBuilder->iCol];
- uint8_t *p;
- int32_t iCol;
- STSKVRow *pTSKVRow = (STSKVRow *)pBuilder->pKVBuf;
-
- // use interp search
- if (pTColumn->colId < cid) { // right search
- for (iCol = pBuilder->iCol + 1; iCol < pBuilder->pTSchema->numOfCols; iCol++) {
- pTColumn = &pBuilder->pTSchema->columns[iCol];
- if (pTColumn->colId >= cid) break;
- }
- } else if (pTColumn->colId > cid) { // left search
- for (iCol = pBuilder->iCol - 1; iCol >= 0; iCol--) {
- pTColumn = &pBuilder->pTSchema->columns[iCol];
- if (pTColumn->colId <= cid) break;
- }
- }
-
- if (pTColumn->colId != cid || COL_IS_SET(pTColumn->flags)) {
- return -1;
- }
-
- pBuilder->iCol = iCol;
-
- // set value
- if (cid == 0) {
- ASSERT(pData && nData == sizeof(TSKEY) && iCol == 0);
- pBuilder->row.ts = *(TSKEY *)pData;
- pTColumn->flags |= COL_SET_VAL;
- } else {
- if (pData) {
- // set VAL
-
- pBuilder->row.flags |= TSROW_HAS_VAL;
- pTColumn->flags |= COL_SET_VAL;
-
- /* KV */
- if (1) { // avoid KV at some threshold (todo)
- pTSKVRow->idx[pTSKVRow->nCols].cid = cid;
- pTSKVRow->idx[pTSKVRow->nCols].offset = pBuilder->vlenKV;
-
- p = pBuilder->pKVBuf + sizeof(STSKVRow) + sizeof(SKVIdx) * (pBuilder->pTSchema->numOfCols - 1) +
- pBuilder->vlenKV;
- if (IS_VAR_DATA_TYPE(pTColumn->type)) {
- ASSERT(nData <= pTColumn->bytes);
- pBuilder->vlenKV += tPutBinary(p, pData, nData);
- } else {
- ASSERT(nData == pTColumn->bytes);
- memcpy(p, pData, nData);
- pBuilder->vlenKV += nData;
- }
- }
-
- /* TUPLE */
- p = pBuilder->pTPBuf + pBuilder->szBitMap2 + pTColumn->offset;
- if (IS_VAR_DATA_TYPE(pTColumn->type)) {
- ASSERT(nData <= pTColumn->bytes);
- *(int32_t *)p = pBuilder->vlenTP;
-
- p = pBuilder->pTPBuf + pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->vlenTP;
- pBuilder->vlenTP += tPutBinary(p, pData, nData);
- } else {
- ASSERT(nData == pTColumn->bytes);
- memcpy(p, pData, nData);
- }
- } else {
- // set NULL
-
- pBuilder->row.flags |= TSROW_HAS_NULL;
- pTColumn->flags |= COL_SET_NULL;
-
- pTSKVRow->idx[pTSKVRow->nCols].cid = cid;
- pTSKVRow->idx[pTSKVRow->nCols].offset = -1;
- }
-
- pTSKVRow->nCols++;
- }
-
- return 0;
-}
-
-static FORCE_INLINE int tSKVIdxCmprFn(const void *p1, const void *p2) {
- SKVIdx *pKVIdx1 = (SKVIdx *)p1;
- SKVIdx *pKVIdx2 = (SKVIdx *)p2;
- if (pKVIdx1->cid > pKVIdx2->cid) {
- return 1;
- } else if (pKVIdx1->cid < pKVIdx2->cid) {
- return -1;
- }
- return 0;
-}
-static void setBitMap(uint8_t *p, STSchema *pTSchema, uint8_t flags) {
- int32_t bidx;
- STColumn *pTColumn;
-
- for (int32_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
- pTColumn = &pTSchema->columns[iCol];
- bidx = iCol - 1;
-
- switch (flags) {
- case TSROW_HAS_NULL | TSROW_HAS_NONE:
- if (pTColumn->flags & COL_SET_NULL) {
- SET_BIT1(p, bidx, (uint8_t)1);
- } else {
- SET_BIT1(p, bidx, (uint8_t)0);
- }
- break;
- case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
- if (pTColumn->flags & COL_SET_NULL) {
- SET_BIT2(p, bidx, (uint8_t)1);
- } else if (pTColumn->flags & COL_SET_VAL) {
- SET_BIT2(p, bidx, (uint8_t)2);
- } else {
- SET_BIT2(p, bidx, (uint8_t)0);
- }
- break;
- default:
- if (pTColumn->flags & COL_SET_VAL) {
- SET_BIT1(p, bidx, (uint8_t)1);
- } else {
- SET_BIT1(p, bidx, (uint8_t)0);
- }
-
- break;
- }
- }
-}
-int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) {
- int32_t nDataTP, nDataKV;
- STSKVRow *pTSKVRow = (STSKVRow *)pBuilder->pKVBuf;
- int32_t nCols = pBuilder->pTSchema->numOfCols;
-
- // error not set ts
- if (!COL_IS_SET(pBuilder->pTSchema->columns->flags)) {
- return -1;
- }
-
- ASSERT(pTSKVRow->nCols < nCols);
- if (pTSKVRow->nCols < nCols - 1) {
- pBuilder->row.flags |= TSROW_HAS_NONE;
- }
-
- ASSERT((pBuilder->row.flags & 0xf) != 0);
- *(ppRow) = &pBuilder->row;
- switch (pBuilder->row.flags & 0xf) {
- case TSROW_HAS_NONE:
- case TSROW_HAS_NULL:
- pBuilder->row.nData = 0;
- pBuilder->row.pData = NULL;
- return 0;
- case TSROW_HAS_NULL | TSROW_HAS_NONE:
- nDataTP = pBuilder->szBitMap1;
- break;
- case TSROW_HAS_VAL:
- nDataTP = pBuilder->pTSchema->flen + pBuilder->vlenTP;
- break;
- case TSROW_HAS_VAL | TSROW_HAS_NONE:
- case TSROW_HAS_VAL | TSROW_HAS_NULL:
- nDataTP = pBuilder->szBitMap1 + pBuilder->pTSchema->flen + pBuilder->vlenTP;
- break;
- case TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE:
- nDataTP = pBuilder->szBitMap2 + pBuilder->pTSchema->flen + pBuilder->vlenTP;
- break;
- default:
- ASSERT(0);
- }
-
- nDataKV = sizeof(STSKVRow) + sizeof(SKVIdx) * pTSKVRow->nCols + pBuilder->vlenKV;
- pBuilder->row.sver = pBuilder->pTSchema->version;
- if (nDataKV < nDataTP) {
- // generate KV row
-
- ASSERT((pBuilder->row.flags & 0xf) != TSROW_HAS_VAL);
-
- pBuilder->row.flags |= TSROW_KV_ROW;
- pBuilder->row.nData = nDataKV;
- pBuilder->row.pData = pBuilder->pKVBuf;
-
- qsort(pTSKVRow->idx, pTSKVRow->nCols, sizeof(SKVIdx), tSKVIdxCmprFn);
- if (pTSKVRow->nCols < nCols - 1) {
- memmove(&pTSKVRow->idx[pTSKVRow->nCols], &pTSKVRow->idx[nCols - 1], pBuilder->vlenKV);
- }
- } else {
- // generate TUPLE row
-
- pBuilder->row.nData = nDataTP;
-
- uint8_t *p;
- uint8_t flags = (pBuilder->row.flags & 0xf);
-
- if (flags == TSROW_HAS_VAL) {
- pBuilder->row.pData = pBuilder->pTPBuf + pBuilder->szBitMap2;
- } else {
- if (flags == (TSROW_HAS_VAL | TSROW_HAS_NULL | TSROW_HAS_NONE)) {
- pBuilder->row.pData = pBuilder->pTPBuf;
- } else {
- pBuilder->row.pData = pBuilder->pTPBuf + pBuilder->szBitMap2 - pBuilder->szBitMap1;
- }
-
- setBitMap(pBuilder->row.pData, pBuilder->pTSchema, flags);
- }
- }
-
- return 0;
-}
-#endif
+// STag
static int tTagValCmprFn(const void *p1, const void *p2) {
if (((STagVal *)p1)->cid < ((STagVal *)p2)->cid) {
return -1;
@@ -953,25 +807,6 @@ static void debugPrintTagVal(int8_t type, const void *val, int32_t vlen, const c
}
}
-// if (isLarge) {
-// p = (uint8_t *)&((int16_t *)pTag->idx)[pTag->nTag];
-// } else {
-// p = (uint8_t *)&pTag->idx[pTag->nTag];
-// }
-
-// (*ppArray) = taosArrayInit(pTag->nTag + 1, sizeof(STagVal));
-// if (*ppArray == NULL) {
-// code = TSDB_CODE_OUT_OF_MEMORY;
-// goto _err;
-// }
-
-// for (int16_t iTag = 0; iTag < pTag->nTag; iTag++) {
-// if (isLarge) {
-// offset = ((int16_t *)pTag->idx)[iTag];
-// } else {
-// offset = pTag->idx[iTag];
-// }
-
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln) {
int8_t isJson = pTag->flags & TD_TAG_JSON;
int8_t isLarge = pTag->flags & TD_TAG_LARGE;
@@ -1020,7 +855,7 @@ void debugCheckTags(STag *pTag) {
}
ASSERT(pTag->nTag <= 128 && pTag->nTag >= 0);
- ASSERT(pTag->ver <= 512 && pTag->ver >= 0); // temp condition for pTag->ver
+ ASSERT(pTag->ver <= 512 && pTag->ver >= 0); // temp condition for pTag->ver
}
static int32_t tPutTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) {
@@ -1133,7 +968,7 @@ int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) {
debugPrintSTag(*ppTag, __func__, __LINE__);
#endif
- debugCheckTags(*ppTag); // TODO: remove this line after debug
+ debugCheckTags(*ppTag); // TODO: remove this line after debug
return code;
_err:
@@ -1215,9 +1050,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) {
return tEncodeBinary(pEncoder, (const uint8_t *)pTag, pTag->len);
}
-int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) {
- return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL);
-}
+int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) { return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL); }
int32_t tTagToValArray(const STag *pTag, SArray **ppArray) {
int32_t code = 0;
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index 141ec4f03b76238d6c15695c7ea3a8ea112d9e4b..e77c462e5ae0fe81521f34cbd1475669747e0ee6 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -109,8 +109,11 @@ int32_t tsCompressColData = -1;
*/
int32_t tsCompatibleModel = 1;
+// count/hyperloglog function always return values in case of all NULL data or Empty data set.
+int32_t tsCountAlwaysReturnValue = 1;
+
// 10 ms for sliding time, the value will changed in case of time precision changed
-int32_t tsMinSlidingTime = 10;
+int32_t tsMinSlidingTime = 10;
// the maxinum number of distict query result
int32_t tsMaxNumOfDistinctResults = 1000 * 10000;
@@ -130,7 +133,6 @@ int32_t tsRetryStreamCompDelay = 10 * 1000;
// The delayed computing ration. 10% of the whole computing time window by default.
float tsStreamComputDelayRatio = 0.1f;
-int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once
int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance
// the maximum allowed query buffer size during query processing for each data node.
@@ -374,6 +376,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 10, 1000000, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "maxNumOfDistinctRes", tsMaxNumOfDistinctResults, 10 * 10000, 10000 * 10000, 0) != 0) return -1;
+ if (cfgAddInt32(pCfg, "countAlwaysReturnValue", tsCountAlwaysReturnValue, 0, 1, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "maxStreamCompDelay", tsMaxStreamComputDelay, 10, 1000000000, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "maxFirstStreamCompDelay", tsStreamCompStartDelay, 1000, 1000000000, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "retryStreamCompDelay", tsRetryStreamCompDelay, 10, 1000000000, 0) != 0) return -1;
@@ -567,6 +570,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsMinSlidingTime = cfgGetItem(pCfg, "minSlidingTime")->i32;
tsMinIntervalTime = cfgGetItem(pCfg, "minIntervalTime")->i32;
tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32;
+ tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32;
tsMaxStreamComputDelay = cfgGetItem(pCfg, "maxStreamCompDelay")->i32;
tsStreamCompStartDelay = cfgGetItem(pCfg, "maxFirstStreamCompDelay")->i32;
tsRetryStreamCompDelay = cfgGetItem(pCfg, "retryStreamCompDelay")->i32;
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index 0f3eec01c6b3df1051e51604256dbf853d247d01..9c6c532bcd071bf8799e28076a9ea147d5b81443 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -2278,6 +2278,7 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) {
if (tEncodeI8(&encoder, pRetension->freqUnit) < 0) return -1;
if (tEncodeI8(&encoder, pRetension->keepUnit) < 0) return -1;
}
+ if (tEncodeI8(&encoder, pRsp->schemaless) < 0) return -1;
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
@@ -2326,6 +2327,7 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) {
return -1;
}
}
+ if (tDecodeI8(&decoder, &pRsp->schemaless) < 0) return -1;
tEndDecode(&decoder);
tDecoderClear(&decoder);
diff --git a/source/common/src/tmsgcb.c b/source/common/src/tmsgcb.c
index 126a4c023a09505c8b93174c622e14654aa71b0f..b8eec655b125eadf3a8e4f199168ef4bf96109a0 100644
--- a/source/common/src/tmsgcb.c
+++ b/source/common/src/tmsgcb.c
@@ -22,41 +22,21 @@ static SMsgCb defaultMsgCb;
void tmsgSetDefault(const SMsgCb* msgcb) { defaultMsgCb = *msgcb; }
int32_t tmsgPutToQueue(const SMsgCb* msgcb, EQueueType qtype, SRpcMsg* pMsg) {
- PutToQueueFp fp = msgcb->queueFps[qtype];
- return (*fp)(msgcb->mgmt, pMsg);
+ return (*msgcb->putToQueueFp)(msgcb->mgmt, qtype, pMsg);
}
int32_t tmsgGetQueueSize(const SMsgCb* msgcb, int32_t vgId, EQueueType qtype) {
- GetQueueSizeFp fp = msgcb->qsizeFp;
- return (*fp)(msgcb->mgmt, vgId, qtype);
+ return (*msgcb->qsizeFp)(msgcb->mgmt, vgId, qtype);
}
-int32_t tmsgSendReq(const SEpSet* epSet, SRpcMsg* pMsg) {
- SendReqFp fp = defaultMsgCb.sendReqFp;
- return (*fp)(epSet, pMsg);
-}
+int32_t tmsgSendReq(const SEpSet* epSet, SRpcMsg* pMsg) { return (*defaultMsgCb.sendReqFp)(epSet, pMsg); }
-void tmsgSendRsp(SRpcMsg* pMsg) {
- SendRspFp fp = defaultMsgCb.sendRspFp;
- return (*fp)(pMsg);
-}
+void tmsgSendRsp(SRpcMsg* pMsg) { return (*defaultMsgCb.sendRspFp)(pMsg); }
-void tmsgSendRedirectRsp(SRpcMsg* pMsg, const SEpSet* pNewEpSet) {
- SendRedirectRspFp fp = defaultMsgCb.sendRedirectRspFp;
- (*fp)(pMsg, pNewEpSet);
-}
+void tmsgSendRedirectRsp(SRpcMsg* pMsg, const SEpSet* pNewEpSet) { (*defaultMsgCb.sendRedirectRspFp)(pMsg, pNewEpSet); }
-void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg) {
- RegisterBrokenLinkArgFp fp = defaultMsgCb.registerBrokenLinkArgFp;
- (*fp)(pMsg);
-}
+void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg) { (*defaultMsgCb.registerBrokenLinkArgFp)(pMsg); }
-void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type) {
- ReleaseHandleFp fp = defaultMsgCb.releaseHandleFp;
- (*fp)(pHandle, type);
-}
+void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type) { (*defaultMsgCb.releaseHandleFp)(pHandle, type); }
-void tmsgReportStartup(const char* name, const char* desc) {
- ReportStartup fp = defaultMsgCb.reportStartupFp;
- (*fp)(name, desc);
-}
\ No newline at end of file
+void tmsgReportStartup(const char* name, const char* desc) { (*defaultMsgCb.reportStartupFp)(name, desc); }
\ No newline at end of file
diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c
index 1a04e83f8127c0c71570c2cef4f300f05da11e67..2b0f6a01a0b87cdee8d071d1e53bad398ea90f97 100644
--- a/source/dnode/mgmt/exe/dmMain.c
+++ b/source/dnode/mgmt/exe/dmMain.c
@@ -216,7 +216,7 @@ int main(int argc, char const *argv[]) {
return -1;
}
- dInfo("start to run dnode");
+ dInfo("start to open dnode");
dmSetSignalHandle();
int32_t code = dmRun();
dInfo("shutting down the service");
diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
index bd034fe7d6c21dcf31e0ca4e9e83d7a23fa28fb8..9a0cfdfc9302160a21eccbe98445aad259250335 100644
--- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
+++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
@@ -65,10 +65,7 @@ int32_t mmPutNodeMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutNodeMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutNodeMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutNodeMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmPutRpcMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmPutRpcMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmPutRpcMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmPutRpcMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t mmPutRpcMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc);
#ifdef __cplusplus
}
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
index 5c5316e3a3ba5f51a59e51b10bdc7663970dd71d..8d0d503d8f6a09a7a73233bad9816ce7023a4d53 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
@@ -134,7 +134,7 @@ SArray *mmGetMsgHandles() {
// Requests handled by DNODE
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_MNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_QNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
@@ -190,7 +190,7 @@ SArray *mmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_TRANS, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c
index 1b973f3045d5dd4e2f6e5fcc4e25413068af6af5..0f3c06cb3a909d2c936895026425883f225376f1 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c
@@ -105,10 +105,7 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
pMgmt->path = pInput->path;
pMgmt->name = pInput->name;
pMgmt->msgCb = pInput->msgCb;
- pMgmt->msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)mmPutRpcMsgToQueryQueue;
- pMgmt->msgCb.queueFps[READ_QUEUE] = (PutToQueueFp)mmPutRpcMsgToReadQueue;
- pMgmt->msgCb.queueFps[WRITE_QUEUE] = (PutToQueueFp)mmPutRpcMsgToWriteQueue;
- pMgmt->msgCb.queueFps[SYNC_QUEUE] = (PutToQueueFp)mmPutRpcMsgToSyncQueue;
+ pMgmt->msgCb.putToQueueFp = (PutToQueueFp)mmPutRpcMsgToQueue;
pMgmt->msgCb.mgmt = pMgmt;
taosThreadRwlockInit(&pMgmt->lock, NULL);
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
index 1de9875d063933fe1f35bb5b5770c1aabc6b8fc3..460f2242f2752f10959c637c2b814a3a20f2e9cd 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
@@ -96,40 +96,38 @@ int32_t mmPutNodeMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return mmPutNodeMsgToWorker(&pMgmt->monitorWorker, pMsg);
}
-static inline int32_t mmPutRpcMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pRpc) {
+int32_t mmPutRpcMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
if (pMsg == NULL) return -1;
-
- dTrace("msg:%p, create and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType));
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
- taosWriteQitem(pWorker->queue, pMsg);
- return 0;
-}
-int32_t mmPutRpcMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return mmPutRpcMsgToWorker(&pMgmt->queryWorker, pMsg);
-}
-
-int32_t mmPutRpcMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return mmPutRpcMsgToWorker(&pMgmt->writeWorker, pMsg);
-}
-
-int32_t mmPutRpcMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return mmPutRpcMsgToWorker(&pMgmt->readWorker, pMsg);
-}
-
-int32_t mmPutRpcMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- int32_t code = -1;
- if (mmAcquire(pMgmt) == 0) {
- code = mmPutRpcMsgToWorker(&pMgmt->syncWorker, pMsg);
- mmRelease(pMgmt);
- }
-
- if (code != 0) {
- rpcFreeCont(pMsg->pCont);
- pMsg->pCont = NULL;
+ switch (qtype) {
+ case WRITE_QUEUE:
+ dTrace("msg:%p, is created and will put into vnode-write queue", pMsg);
+ taosWriteQitem(pMgmt->writeWorker.queue, pMsg);
+ return 0;
+ case QUERY_QUEUE:
+ dTrace("msg:%p, is created and will put into vnode-query queue", pMsg);
+ taosWriteQitem(pMgmt->queryWorker.queue, pMsg);
+ return 0;
+
+ case READ_QUEUE:
+ dTrace("msg:%p, is created and will put into vnode-read queue", pMsg);
+ taosWriteQitem(pMgmt->readWorker.queue, pMsg);
+ return 0;
+ case SYNC_QUEUE:
+ if (mmAcquire(pMgmt) == 0) {
+ dTrace("msg:%p, is created and will put into vnode-sync queue", pMsg);
+ taosWriteQitem(pMgmt->syncWorker.queue, pMsg);
+ mmRelease(pMgmt);
+ return 0;
+ } else {
+ return -1;
+ }
+ default:
+ terrno = TSDB_CODE_INVALID_PARA;
+ return -1;
}
- return code;
}
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
index 9738fb0c454a460a80fa0516b6e2e0ff1e8b05ff..54e9da24a4e1f581cbb7aa009e29efb9ceac221e 100644
--- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
+++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
@@ -42,8 +42,7 @@ int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
int32_t qmProcessGetMonitorInfoReq(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
// qmWorker.c
-int32_t qmPutRpcMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t qmPutRpcMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pMsg);
int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype);
int32_t qmStartWorker(SQnodeMgmt *pMgmt);
diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c
index 06c18ab2889c05c910ad933338dc608a1d15d676..3b425a0b4923b3384bd620fc86e421cdc211ba4a 100644
--- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c
+++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c
@@ -43,8 +43,7 @@ static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
pMgmt->path = pInput->path;
pMgmt->name = pInput->name;
pMgmt->msgCb = pInput->msgCb;
- pMgmt->msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qmPutRpcMsgToQueryQueue;
- pMgmt->msgCb.queueFps[FETCH_QUEUE] = (PutToQueueFp)qmPutRpcMsgToFetchQueue;
+ pMgmt->msgCb.putToQueueFp = (PutToQueueFp)qmPutRpcMsgToQueue;
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)qmGetQueueSize;
pMgmt->msgCb.mgmt = pMgmt;
diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
index e7fc261b67a8a6416cdbafae07552a5c9576bc22..e36efa83db24b0d6b706518ab3c789ece80c21d5 100644
--- a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
+++ b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
@@ -68,22 +68,24 @@ int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return qmPutNodeMsgToWorker(&pMgmt->monitorWorker, pMsg);
}
-static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) {
+int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
if (pMsg == NULL) return -1;
-
- dTrace("msg:%p, create and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType));
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
- taosWriteQitem(pWorker->queue, pMsg);
- return 0;
-}
-
-int32_t qmPutRpcMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return qmPutRpcMsgToWorker(pMgmt, &pMgmt->queryWorker, pRpc);
-}
-int32_t qmPutRpcMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return qmPutRpcMsgToWorker(pMgmt, &pMgmt->fetchWorker, pRpc);
+ switch (qtype) {
+ case QUERY_QUEUE:
+ dTrace("msg:%p, is created and will put into qnode-query queue", pMsg);
+ taosWriteQitem(pMgmt->queryWorker.queue, pMsg);
+ return 0;
+ case READ_QUEUE:
+ dTrace("msg:%p, is created and will put into qnode-fetch queue", pMsg);
+ taosWriteQitem(pMgmt->fetchWorker.queue, pMsg);
+ return 0;
+ default:
+ terrno = TSDB_CODE_INVALID_PARA;
+ return -1;
+ }
}
int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
index 5ec33fe810a777e654a9b64160169003f983ab77..adc18fdced4777fcfdc731993ce758e301c34ac9 100644
--- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
+++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
@@ -44,26 +44,26 @@ typedef struct SVnodeMgmt {
} SVnodeMgmt;
typedef struct {
- int32_t vgId;
- int32_t vgVersion;
- int8_t dropped;
- char path[PATH_MAX + 20];
+ int32_t vgId;
+ int32_t vgVersion;
+ int8_t dropped;
+ char path[PATH_MAX + 20];
} SWrapperCfg;
typedef struct {
- int32_t vgId;
- int32_t refCount;
- int32_t vgVersion;
- int8_t dropped;
- int8_t accessState;
- char *path;
- SVnode *pImpl;
- STaosQueue *pWriteQ;
- STaosQueue *pSyncQ;
- STaosQueue *pApplyQ;
- STaosQueue *pQueryQ;
- STaosQueue *pFetchQ;
- STaosQueue *pMergeQ;
+ int32_t vgId;
+ int32_t refCount;
+ int32_t vgVersion;
+ int8_t dropped;
+ int8_t accessState;
+ char *path;
+ SVnode *pImpl;
+ STaosQueue *pWriteQ;
+ STaosQueue *pSyncQ;
+ STaosQueue *pApplyQ;
+ STaosQueue *pQueryQ;
+ STaosQueue *pFetchQ;
+ STaosQueue *pMergeQ;
} SVnodeObj;
typedef struct {
@@ -100,21 +100,16 @@ void vmStopWorker(SVnodeMgmt *pMgmt);
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode);
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode);
-int32_t vmPutRpcMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutRpcMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutRpcMsgToApplyQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutRpcMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutRpcMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutRpcMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype);
-
-int32_t vmPutNodeMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutNodeMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc);
+
+int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
#ifdef __cplusplus
}
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c
index cf5a7ad88544bad3e9fbe21e5605b621148183fe..613f3fb994da4fca90842b971ca65b3e6db7fbc7 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c
@@ -16,6 +16,8 @@
#define _DEFAULT_SOURCE
#include "vmInt.h"
+#define MAX_CONTENT_LEN 1024 * 1024
+
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
taosThreadRwlockRdlock(&pMgmt->lock);
@@ -29,7 +31,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
SVnodeObj *pVnode = *ppVnode;
if (pVnode && num < size) {
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
- dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
+ // dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
pVnodes[num] = (*ppVnode);
num++;
pIter = taosHashIterate(pMgmt->hash, pIter);
@@ -47,7 +49,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
int32_t len = 0;
- int32_t maxLen = 1024 * 1024;
+ int32_t maxLen = MAX_CONTENT_LEN;
char *content = taosMemoryCalloc(1, maxLen + 1);
cJSON *root = NULL;
FILE *fp = NULL;
@@ -128,7 +130,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
*numOfVnodes = vnodesNum;
code = 0;
- dDebug("succcessed to read file %s", file);
+ dDebug("succcessed to read file %s, numOfVnodes:%d", file, vnodesNum);
_OVER:
if (content != NULL) taosMemoryFree(content);
@@ -156,7 +158,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
SVnodeObj **pVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
int32_t len = 0;
- int32_t maxLen = 1024 * 1024;
+ int32_t maxLen = MAX_CONTENT_LEN;
char *content = taosMemoryCalloc(1, maxLen + 1);
if (content == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -195,6 +197,6 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
taosMemoryFree(pVnodes);
}
- dDebug("successed to write %s", realfile);
+ dDebug("successed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
return taosRenameFile(file, realfile);
}
\ No newline at end of file
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
index 018d7a607c146243019b085ab858e7c7a670eda6..f08ac6b9d00f06d76a388fa78027b165c3060cda 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
@@ -180,6 +180,24 @@ static void vmGenerateWrapperCfg(SVnodeMgmt *pMgmt, SCreateVnodeReq *pCreate, SW
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCreate->vgId);
}
+static int32_t vmTsmaAdjustDays(SVnodeCfg *pCfg, SCreateVnodeReq *pReq) {
+ if (pReq->isTsma) {
+ SMsgHead *smaMsg = pReq->pTsma;
+ uint32_t contLen = (uint32_t)(htonl(smaMsg->contLen) - sizeof(SMsgHead));
+ return smaGetTSmaDays(pCfg, POINTER_SHIFT(smaMsg, sizeof(SMsgHead)), contLen, &pCfg->tsdbCfg.days);
+ }
+ return 0;
+}
+
+static int32_t vmTsmaProcessCreate(SVnode *pVnode, SCreateVnodeReq *pReq) {
+ if (pReq->isTsma) {
+ SMsgHead *smaMsg = pReq->pTsma;
+ uint32_t contLen = (uint32_t)(htonl(smaMsg->contLen) - sizeof(SMsgHead));
+ return vnodeProcessCreateTSma(pVnode, POINTER_SHIFT(smaMsg, sizeof(SMsgHead)), contLen);
+ }
+ return 0;
+}
+
int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
SCreateVnodeReq createReq = {0};
SVnodeCfg vnodeCfg = {0};
@@ -192,9 +210,16 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return -1;
}
- dDebug("vgId:%d, create vnode req is received, tsma:%d standby:%d", createReq.vgId, createReq.isTsma,
+ dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma,
createReq.standby);
vmGenerateVnodeCfg(&createReq, &vnodeCfg);
+
+ if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) {
+ dError("vgId:%d, failed to adjust tsma days since %s", createReq.vgId, terrstr());
+ code = terrno;
+ goto _OVER;
+ }
+
vmGenerateWrapperCfg(pMgmt, &createReq, &wrapperCfg);
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, createReq.vgId);
@@ -203,14 +228,16 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
tFreeSCreateVnodeReq(&createReq);
vmReleaseVnode(pMgmt, pVnode);
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
- return -1;
+ code = terrno;
+ goto _OVER;
}
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, vnodeCfg.vgId);
if (vnodeCreate(path, &vnodeCfg, pMgmt->pTfs) < 0) {
tFreeSCreateVnodeReq(&createReq);
dError("vgId:%d, failed to create vnode since %s", createReq.vgId, terrstr());
- return -1;
+ code = terrno;
+ goto _OVER;
}
SVnode *pImpl = vnodeOpen(path, pMgmt->pTfs, pMgmt->msgCb);
@@ -227,14 +254,11 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
goto _OVER;
}
- if (createReq.isTsma) {
- SMsgHead *smaMsg = createReq.pTsma;
- uint32_t contLen = (uint32_t)(htonl(smaMsg->contLen) - sizeof(SMsgHead));
- if (vnodeProcessCreateTSma(pImpl, POINTER_SHIFT(smaMsg, sizeof(SMsgHead)), contLen) < 0) {
- dError("vgId:%d, failed to create tsma since %s", createReq.vgId, terrstr());
- code = terrno;
- goto _OVER;
- };
+ code = vmTsmaProcessCreate(pImpl, &createReq);
+ if (code != 0) {
+ dError("vgId:%d, failed to create tsma since %s", createReq.vgId, terrstr());
+ code = terrno;
+ goto _OVER;
}
code = vnodeStart(pImpl);
@@ -253,6 +277,8 @@ _OVER:
if (code != 0) {
vnodeClose(pImpl);
vnodeDestroy(path, pMgmt->pTfs);
+ } else {
+ dInfo("vgId:%d, vnode is created", createReq.vgId);
}
tFreeSCreateVnodeReq(&createReq);
@@ -268,7 +294,7 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
}
int32_t vgId = dropReq.vgId;
- dDebug("vgId:%d, drop vnode req is received", vgId);
+ dDebug("vgId:%d, start to drop vnode", vgId);
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
if (pVnode == NULL) {
@@ -295,59 +321,59 @@ SArray *vmGetMsgHandles() {
SArray *pArray = taosArrayInit(32, sizeof(SMgmtHandle));
if (pArray == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
// Requests handled by VNODE
- if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY, vmPutNodeMsgToQueryQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_CONTINUE, vmPutNodeMsgToQueryQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_FETCH, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_TABLE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_UPDATE_TAG_VAL, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_META, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TABLES_META, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONSUME, vmPutNodeMsgToQueryQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_QUERY, vmPutNodeMsgToQueryQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONNECT, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_DISCONNECT, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- // if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_SET_CUR, vmPutNodeMsgToWriteQueue, 0)== NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TABLE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_SMA, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_SMA, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
-
- if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
-
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_TIMEOUT, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_PING, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_PING_REPLY, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_CLIENT_REQUEST, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_CLIENT_REQUEST_REPLY, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_REQUEST_VOTE, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_REQUEST_VOTE_REPLY, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_APPEND_ENTRIES, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_APPEND_ENTRIES_REPLY, vmPutNodeMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_CONTINUE, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_FETCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_UPDATE_TAG_VAL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TABLES_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONSUME, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_DISCONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ // if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_SET_CUR, vmPutMsgToWriteQueue, 0)== NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+
+ if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
+
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_TIMEOUT, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_PING, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_PING_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_CLIENT_REQUEST, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_CLIENT_REQUEST_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_REQUEST_VOTE, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_REQUEST_VOTE_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_APPEND_ENTRIES, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_VND_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
code = 0;
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
index 0c8d492ef449624e7462b736fcdd9c2ffb9c2ac2..23927255bb8c920bfaf9de12e91bbffe4bd1de39 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
@@ -18,21 +18,17 @@
SVnodeObj *vmAcquireVnode(SVnodeMgmt *pMgmt, int32_t vgId) {
SVnodeObj *pVnode = NULL;
- int32_t refCount = 0;
taosThreadRwlockRdlock(&pMgmt->lock);
taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode);
if (pVnode == NULL) {
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
} else {
- refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
+ int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
+ // dTrace("vgId:%d, acquire vnode, ref:%d", pVnode->vgId, refCount);
}
taosThreadRwlockUnlock(&pMgmt->lock);
- if (pVnode != NULL) {
- dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
- }
-
return pVnode;
}
@@ -41,8 +37,8 @@ void vmReleaseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
taosThreadRwlockRdlock(&pMgmt->lock);
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
+ // dTrace("vgId:%d, release vnode, ref:%d", pVnode->vgId, refCount);
taosThreadRwlockUnlock(&pMgmt->lock);
- dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
}
int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
@@ -138,7 +134,7 @@ static void *vmOpenVnodeInThread(void *param) {
}
}
- dDebug("thread:%d, total vnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
+ dDebug("thread:%d, numOfVnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
pThread->failed);
return NULL;
}
@@ -160,7 +156,7 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
pMgmt->state.totalVnodes = numOfVnodes;
- int32_t threadNum = 1; // tsNumOfCores;
+ int32_t threadNum = 1;
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
@@ -253,12 +249,7 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
pMgmt->path = pInput->path;
pMgmt->name = pInput->name;
pMgmt->msgCb = pInput->msgCb;
- pMgmt->msgCb.queueFps[WRITE_QUEUE] = (PutToQueueFp)vmPutRpcMsgToWriteQueue;
- pMgmt->msgCb.queueFps[SYNC_QUEUE] = (PutToQueueFp)vmPutRpcMsgToSyncQueue;
- pMgmt->msgCb.queueFps[APPLY_QUEUE] = (PutToQueueFp)vmPutRpcMsgToApplyQueue;
- pMgmt->msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)vmPutRpcMsgToQueryQueue;
- pMgmt->msgCb.queueFps[FETCH_QUEUE] = (PutToQueueFp)vmPutRpcMsgToFetchQueue;
- pMgmt->msgCb.queueFps[MERGE_QUEUE] = (PutToQueueFp)vmPutRpcMsgToMergeQueue;
+ pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
pMgmt->msgCb.mgmt = pMgmt;
taosThreadRwlockInit(&pMgmt->lock, NULL);
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
index 378451c301cb1c874382ae3f042f572d7a70c468..e714b9ad5c531be26adffa4774390082a8c0ad72 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
@@ -29,11 +29,11 @@ static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
tmsgSendRsp(&rsp);
}
-static void vmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
+static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SVnodeMgmt *pMgmt = pInfo->ahandle;
int32_t code = -1;
- dTrace("msg:%p, get from vnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("msg:%p, get from vnode-mgmt queue", pMsg);
switch (pMsg->msgType) {
case TDMT_MON_VM_INFO:
code = vmProcessGetMonitorInfoReq(pMgmt, pMsg);
@@ -49,11 +49,14 @@ static void vmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
break;
default:
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
- dError("msg:%p, not processed in vnode queue", pMsg);
+ dError("msg:%p, not processed in vnode-mgmt queue", pMsg);
}
if (IsReq(pMsg)) {
- if (code != 0 && terrno != 0) code = terrno;
+ if (code != 0 && terrno != 0) {
+ dError("msg:%p failed to process since %s", pMsg, terrstr());
+ code = terrno;
+ }
vmSendRsp(pMsg, code);
}
@@ -65,13 +68,15 @@ static void vmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SVnodeObj *pVnode = pInfo->ahandle;
- dTrace("msg:%p, get from vnode-query queue", pMsg);
+ dTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg);
if (code != 0) {
if (terrno != 0) code = terrno;
+ dError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, terrstr());
vmSendRsp(pMsg, code);
}
- dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
+
+ dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
@@ -79,63 +84,66 @@ static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SVnodeObj *pVnode = pInfo->ahandle;
- dTrace("msg:%p, get from vnode-fetch queue", pMsg);
+ dTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
if (code != 0) {
if (terrno != 0) code = terrno;
+ dError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
vmSendRsp(pMsg, code);
}
- dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
+
+ dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
+ int32_t code = 0;
+ SRpcMsg *pMsg = NULL;
SVnodeObj *pVnode = pInfo->ahandle;
- SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
- if (pArray == NULL) {
- dError("failed to process %d msgs in write-queue since %s", numOfMsgs, terrstr());
- return;
- }
+ int64_t sync = vnodeGetSyncHandle(pVnode->pImpl);
+ SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg **));
- for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
+ for (int32_t m = 0; m < numOfMsgs; m++) {
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
+ dTrace("vgId:%d, msg:%p get from vnode-write queue", pVnode->vgId, pMsg);
- dTrace("msg:%p, get from vnode-write queue", pMsg);
if (taosArrayPush(pArray, &pMsg) == NULL) {
- dTrace("msg:%p, failed to push to array since %s", pMsg, terrstr());
+ dError("vgId:%d, failed to push msg:%p to vnode-write array", pVnode->vgId, pMsg);
vmSendRsp(pMsg, TSDB_CODE_OUT_OF_MEMORY);
}
}
- for (int i = 0; i < taosArrayGetSize(pArray); i++) {
- SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
- SRpcMsg rsp = {.info = pMsg->info};
+ for (int32_t m = 0; m < taosArrayGetSize(pArray); m++) {
+ pMsg = *(SRpcMsg **)taosArrayGet(pArray, m);
+ code = vnodePreprocessReq(pVnode->pImpl, pMsg);
- vnodePreprocessReq(pVnode->pImpl, pMsg);
+ if (code == TSDB_CODE_ACTION_IN_PROGRESS) continue;
+ if (code != 0) {
+ dError("vgId:%d, msg:%p failed to write since %s", pVnode->vgId, pMsg, tstrerror(code));
+ vmSendRsp(pMsg, code);
+ continue;
+ }
- int32_t ret = syncPropose(vnodeGetSyncHandle(pVnode->pImpl), pMsg, false);
- if (ret == TAOS_SYNC_PROPOSE_NOT_LEADER) {
- dTrace("msg:%p, is redirect since not leader, vgId:%d ", pMsg, pVnode->vgId);
- rsp.code = TSDB_CODE_RPC_REDIRECT;
- SEpSet newEpSet;
- syncGetEpSet(vnodeGetSyncHandle(pVnode->pImpl), &newEpSet);
+ code = syncPropose(sync, pMsg, false);
+ if (code == TAOS_SYNC_PROPOSE_SUCCESS) {
+ continue;
+ } else if (code == TAOS_SYNC_PROPOSE_NOT_LEADER) {
+ dTrace("vgId:%d, msg:%p is redirect since not leader", pVnode->vgId, pMsg);
+ SEpSet newEpSet = {0};
+ syncGetEpSet(sync, &newEpSet);
newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps;
+ SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info};
tmsgSendRedirectRsp(&rsp, &newEpSet);
- } else if (ret == TAOS_SYNC_PROPOSE_OTHER_ERROR) {
- rsp.code = TSDB_CODE_SYN_INTERNAL_ERROR;
- tmsgSendRsp(&rsp);
- } else if (ret == TAOS_SYNC_PROPOSE_SUCCESS) {
- // send response in applyQ
} else {
- assert(0);
+ dError("vgId:%d, msg:%p failed to write since %s", pVnode->vgId, pMsg, tstrerror(code));
+ vmSendRsp(pMsg, code);
}
}
for (int32_t i = 0; i < numOfMsgs; i++) {
- SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
- dTrace("msg:%p, is freed", pMsg);
+ pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
+ dTrace("vgId:%d, msg:%p is freed", pVnode->vgId, pMsg);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
@@ -145,10 +153,11 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SVnodeObj *pVnode = pInfo->ahandle;
+ SRpcMsg *pMsg = NULL;
for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
- taosGetQitem(qall, (void **)&pMsg);
+ if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
+ dTrace("vgId:%d, msg:%p get from vnode-apply queue", pVnode->vgId, pMsg);
// init response rpc msg
SRpcMsg rsp = {0};
@@ -163,7 +172,7 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
// apply data into tsdb
if (vnodeProcessWriteReq(pVnode->pImpl, &originalRpcMsg, pSyncApplyMsg->fsmMeta.index, &rsp) < 0) {
rsp.code = terrno;
- dTrace("msg:%p, process write error since %s", pMsg, terrstr());
+ dError("vgId:%d, msg:%p failed to apply since %s", pVnode->vgId, pMsg, terrstr());
}
syncApplyMsgDestroy(pSyncApplyMsg);
@@ -175,6 +184,7 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
tmsgSendRsp(&rsp);
}
+ dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, rsp.code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
@@ -182,23 +192,22 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SVnodeObj *pVnode = pInfo->ahandle;
+ SRpcMsg *pMsg = NULL;
for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
- taosGetQitem(qall, (void **)&pMsg);
+ if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
+ dTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL);
if (code != 0) {
+ dError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr());
if (pMsg->info.handle != NULL) {
- SRpcMsg rsp = {
- .code = (terrno < 0) ? terrno : code,
- .info = pMsg->info,
- };
- dTrace("msg:%p, failed to process sync queue since %s", pMsg, terrstr());
- tmsgSendRsp(&rsp);
+ if (terrno != 0) code = terrno;
+ vmSendRsp(pMsg, code);
}
}
+ dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
@@ -206,24 +215,26 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SVnodeObj *pVnode = pInfo->ahandle;
+ SRpcMsg *pMsg = NULL;
for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
- taosGetQitem(qall, (void **)&pMsg);
+ if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
+ dTrace("vgId:%d, msg:%p get from vnode-merge queue", pVnode->vgId, pMsg);
- dTrace("msg:%p, get from vnode-merge queue", pMsg);
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
if (code != 0) {
+ dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr());
if (terrno != 0) code = terrno;
vmSendRsp(pMsg, code);
}
+
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
}
-static int32_t vmPutNodeMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
+static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
SMsgHead *pHead = pMsg->pCont;
int32_t code = 0;
@@ -232,7 +243,8 @@ static int32_t vmPutNodeMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
if (pVnode == NULL) {
- dError("vgId:%d, failed to put msg:%p into vnode-queue since %s", pHead->vgId, pMsg, terrstr());
+ dError("vgId:%d, failed to put msg:%p into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(),
+ TMSG_INFO(pMsg->msgType));
return terrno != 0 ? terrno : -1;
}
@@ -240,25 +252,29 @@ static int32_t vmPutNodeMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType
case QUERY_QUEUE:
vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
- dTrace("msg:%p, put into vnode-query worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pQueryQ, pMsg);
break;
case FETCH_QUEUE:
- dTrace("msg:%p, put into vnode-fetch worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pFetchQ, pMsg);
break;
case WRITE_QUEUE:
- dTrace("msg:%p, put into vnode-write worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pWriteQ, pMsg);
break;
case SYNC_QUEUE:
- dTrace("msg:%p, put into vnode-sync worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pSyncQ, pMsg);
break;
case MERGE_QUEUE:
- dTrace("msg:%p, put into vnode-merge worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p put into vnode-merge queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pMergeQ, pMsg);
break;
+ case APPLY_QUEUE:
+ dTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
+ taosWriteQitem(pVnode->pApplyQ, pMsg);
+ break;
default:
code = -1;
terrno = TSDB_CODE_INVALID_PARA;
@@ -269,110 +285,39 @@ static int32_t vmPutNodeMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType
return code;
}
-int32_t vmPutNodeMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return vmPutNodeMsgToQueue(pMgmt, pMsg, SYNC_QUEUE);
-}
+int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
-int32_t vmPutNodeMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return vmPutNodeMsgToQueue(pMgmt, pMsg, WRITE_QUEUE);
-}
+int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
-int32_t vmPutNodeMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return vmPutNodeMsgToQueue(pMgmt, pMsg, QUERY_QUEUE);
-}
+int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
-int32_t vmPutNodeMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return vmPutNodeMsgToQueue(pMgmt, pMsg, FETCH_QUEUE);
-}
+int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
-int32_t vmPutNodeMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return vmPutNodeMsgToQueue(pMgmt, pMsg, MERGE_QUEUE);
-}
+int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); }
-int32_t vmPutNodeMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SSingleWorker *pWorker = &pMgmt->mgmtWorker;
- dTrace("msg:%p, put into vnode-mgmt worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
- taosWriteQitem(pWorker->queue, pMsg);
+int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
+ dTrace("msg:%p, put into vnode-mgmt queue", pMsg);
+ taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
return 0;
}
-int32_t vmPutNodeMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SSingleWorker *pWorker = &pMgmt->monitorWorker;
- dTrace("msg:%p, put into vnode-monitor worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
- taosWriteQitem(pWorker->queue, pMsg);
+int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
+ dTrace("msg:%p, put into vnode-monitor queue", pMsg);
+ taosWriteQitem(pMgmt->monitorWorker.queue, pMsg);
return 0;
}
-static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType qtype) {
- SMsgHead *pHead = pRpc->pCont;
- SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
- if (pVnode == NULL) return -1;
-
+int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
- int32_t code = 0;
-
- if (pMsg == NULL) {
- rpcFreeCont(pRpc->pCont);
- pRpc->pCont = NULL;
- code = -1;
- } else {
- memcpy(pMsg, pRpc, sizeof(SRpcMsg));
- switch (qtype) {
- case WRITE_QUEUE:
- dTrace("msg:%p, create and put into vnode-write worker, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pWriteQ, pMsg);
- break;
- case QUERY_QUEUE:
- dTrace("msg:%p, create and put into vnode-query queue, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pQueryQ, pMsg);
- break;
- case FETCH_QUEUE:
- dTrace("msg:%p, create and put into vnode-fetch queue, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pFetchQ, pMsg);
- break;
- case APPLY_QUEUE:
- dTrace("msg:%p, create and put into vnode-apply queue, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pApplyQ, pMsg);
- break;
- case MERGE_QUEUE:
- dTrace("msg:%p, create and put into vnode-merge queue, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pMergeQ, pMsg);
- break;
- case SYNC_QUEUE:
- dTrace("msg:%p, create and put into vnode-sync queue, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
- taosWriteQitem(pVnode->pSyncQ, pMsg);
- break;
- default:
- code = -1;
- terrno = TSDB_CODE_INVALID_PARA;
- break;
- }
- }
-
- vmReleaseVnode(pMgmt, pVnode);
- return code;
-}
-
-int32_t vmPutRpcMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return vmPutRpcMsgToQueue(pMgmt, pRpc, WRITE_QUEUE);
-}
-
-int32_t vmPutRpcMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) { return vmPutRpcMsgToQueue(pMgmt, pRpc, SYNC_QUEUE); }
-
-int32_t vmPutRpcMsgToApplyQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return vmPutRpcMsgToQueue(pMgmt, pRpc, APPLY_QUEUE);
-}
+ if (pMsg == NULL) return -1;
-int32_t vmPutRpcMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return vmPutRpcMsgToQueue(pMgmt, pRpc, QUERY_QUEUE);
-}
-
-int32_t vmPutRpcMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return vmPutRpcMsgToQueue(pMgmt, pRpc, FETCH_QUEUE);
-}
+ SMsgHead *pHead = pRpc->pCont;
+ dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pMsg->msgType));
-int32_t vmPutRpcMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc) {
- return vmPutRpcMsgToQueue(pMgmt, pRpc, MERGE_QUEUE);
+ pHead->contLen = htonl(pHead->contLen);
+ pHead->vgId = htonl(pHead->vgId);
+ memcpy(pMsg, pRpc, sizeof(SRpcMsg));
+ return vmPutMsgToQueue(pMgmt, pMsg, qtype);
}
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
@@ -468,29 +413,23 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
pMPool->max = tsNumOfVnodeMergeThreads;
if (tWWorkerInit(pMPool) != 0) return -1;
- SSingleWorkerCfg cfg = {
+ SSingleWorkerCfg mgmtCfg = {
.min = 1,
.max = 1,
.name = "vnode-mgmt",
- .fp = (FItem)vmProcessQueue,
+ .fp = (FItem)vmProcessMgmtQueue,
.param = pMgmt,
};
- if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) {
- dError("failed to start vnode-mgmt worker since %s", terrstr());
- return -1;
- }
+ if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
- SSingleWorkerCfg mCfg = {
+ SSingleWorkerCfg monitorCfg = {
.min = 1,
.max = 1,
.name = "vnode-monitor",
- .fp = (FItem)vmProcessQueue,
+ .fp = (FItem)vmProcessMgmtQueue,
.param = pMgmt,
};
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
- dError("failed to start vnode-monitor worker since %s", terrstr());
- return -1;
- }
+ if (tSingleWorkerInit(&pMgmt->monitorWorker, &monitorCfg) != 0) return -1;
dDebug("vnode workers are initialized");
return 0;
diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c
index 5f1bf30523c25cb8c2bad6755ecddc4769ea108d..528beb280bfd05aa4030a3351aaf278f31b96e17 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c
@@ -50,26 +50,26 @@ static int32_t dmInitMonitor() {
}
int32_t dmInit(int8_t rtype) {
- dInfo("start to init env");
+ dInfo("start to init dnode env");
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
if (dmInitSystem() != 0) return -1;
if (dmInitMonitor() != 0) return -1;
if (dmInitDnode(dmInstance(), rtype) != 0) return -1;
- dInfo("env is initialized");
+ dInfo("dnode env is initialized");
return 0;
}
static int32_t dmCheckRepeatCleanup(SDnode *pDnode) {
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
- dError("env is already cleaned up");
+ dError("dnode env is already cleaned up");
return -1;
}
return 0;
}
void dmCleanup() {
- dDebug("start to cleanup env");
+ dDebug("start to cleanup dnode env");
SDnode *pDnode = dmInstance();
if (dmCheckRepeatCleanup(pDnode) != 0) return;
dmCleanupDnode(pDnode);
@@ -79,7 +79,7 @@ void dmCleanup() {
udfcClose();
udfStopUdfd();
taosStopCacheRefreshWorker();
- dInfo("env is cleaned up");
+ dInfo("dnode env is cleaned up");
taosCloseLog();
taosCleanupCfg();
diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
index 787f5e50190fb099d5998d4f604decd8b17feb68..ee27f27f06fe0ce502fdfd729a2b573ddb221c37 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
@@ -229,7 +229,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) {
taosThreadRwlockRdlock(&pWrapper->lock);
if (pWrapper->deployed) {
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
- dTrace("node:%s, is acquired, ref:%d", pWrapper->name, refCount);
+ // dTrace("node:%s, is acquired, ref:%d", pWrapper->name, refCount);
} else {
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
pRetWrapper = NULL;
@@ -245,7 +245,7 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
taosThreadRwlockRdlock(&pWrapper->lock);
if (pWrapper->deployed || (InParentProc(pWrapper) && pWrapper->required)) {
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
- dTrace("node:%s, is marked, ref:%d", pWrapper->name, refCount);
+ // dTrace("node:%s, is marked, ref:%d", pWrapper->name, refCount);
} else {
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
code = -1;
@@ -261,7 +261,7 @@ void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
taosThreadRwlockRdlock(&pWrapper->lock);
int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1);
taosThreadRwlockUnlock(&pWrapper->lock);
- dTrace("node:%s, is released, ref:%d", pWrapper->name, refCount);
+ // dTrace("node:%s, is released, ref:%d", pWrapper->name, refCount);
}
static void dmGetServerStartupStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c
index e5893fd94740fa20fa244bd1957a02a50e39bf08..8b939d15ce35e4a8ccb9f032025250476a3b8a82 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c
@@ -117,6 +117,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
if (pMsg == NULL) {
goto _OVER;
}
+ dTrace("msg:%p, is created, type:%s", pMsg, TMSG_INFO(pRpc->msgType));
if (dmBuildNodeMsg(pMsg, pRpc) != 0) {
goto _OVER;
diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c
index 332dd9a58a6e14f0e0eca104142b9d1258f51cb6..937c1ab7faa29191ea65f8770d0ffb2c531b3c35 100644
--- a/source/dnode/mgmt/node_util/src/dmEps.c
+++ b/source/dnode/mgmt/node_util/src/dmEps.c
@@ -148,7 +148,6 @@ int32_t dmReadEps(SDnodeData *pData) {
code = 0;
dDebug("succcessed to read file %s", file);
- dmPrintEps(pData);
_OVER:
if (content != NULL) taosMemoryFree(content);
@@ -162,6 +161,7 @@ _OVER:
taosArrayPush(pData->dnodeEps, &dnodeEp);
}
+ dDebug("reset dnode list on startup");
dmResetEps(pData, pData->dnodeEps);
if (dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
@@ -236,11 +236,13 @@ void dmUpdateEps(SDnodeData *pData, SArray *eps) {
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pData->dnodeEps);
if (numOfEps != numOfEpsOld) {
+ dDebug("new dnode list get from mnode");
dmResetEps(pData, eps);
dmWriteEps(pData);
} else {
int32_t size = numOfEps * sizeof(SDnodeEp);
if (memcmp(pData->dnodeEps->pData, eps->pData, size) != 0) {
+ dDebug("new dnode list get from mnode");
dmResetEps(pData, eps);
dmWriteEps(pData);
}
@@ -282,7 +284,7 @@ static void dmResetEps(SDnodeData *pData, SArray *dnodeEps) {
static void dmPrintEps(SDnodeData *pData) {
int32_t numOfEps = (int32_t)taosArrayGetSize(pData->dnodeEps);
- dDebug("print dnode ep list, num:%d", numOfEps);
+ dDebug("print dnode list, num:%d", numOfEps);
for (int32_t i = 0; i < numOfEps; i++) {
SDnodeEp *pEp = taosArrayGet(pData->dnodeEps, i);
dDebug("dnode:%d, fqdn:%s port:%u is_mnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode);
diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c
index 7ac6fc129d2bb591706d6ed722878359c4993515..78e706f90814950287aed067103690f9c215e8e3 100644
--- a/source/dnode/mgmt/node_util/src/dmFile.c
+++ b/source/dnode/mgmt/node_util/src/dmFile.c
@@ -135,7 +135,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
return NULL;
}
- dDebug("file:%s is locked", filepath);
+ dDebug("lock file:%s to prevent repeated starts", filepath);
return pFile;
}
diff --git a/source/dnode/mgmt/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp
index 8c945b50ac48b4b1e290875c58a98f168971bc37..857f58befce1898be621a37ea7cb33feb692d58a 100644
--- a/source/dnode/mgmt/test/mnode/dmnode.cpp
+++ b/source/dnode/mgmt/test/mnode/dmnode.cpp
@@ -94,7 +94,7 @@ TEST_F(DndTestMnode, 02_Alter_Mnode) {
void* pReq = rpcMallocCont(contLen);
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
+ SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
}
@@ -111,7 +111,7 @@ TEST_F(DndTestMnode, 02_Alter_Mnode) {
void* pReq = rpcMallocCont(contLen);
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
+ SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
}
@@ -128,7 +128,7 @@ TEST_F(DndTestMnode, 02_Alter_Mnode) {
void* pReq = rpcMallocCont(contLen);
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
+ SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
@@ -186,7 +186,7 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
void* pReq = rpcMallocCont(contLen);
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
+ SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
}
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index 2f7c357aef93c2a7991947d29994443a5fe97023..83a36f4b0d5509884b2e99e7bd0eb4663a564959 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -255,6 +255,7 @@ typedef struct {
int8_t hashMethod; // default is 1
int32_t numOfRetensions;
SArray* pRetensions;
+ int8_t schemaless;
} SDbCfg;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h
index c5c4800e0295fa48ee4bf9669200f7ce7a31eff8..4aa18ea591a7058d8ecbbdcb901b0ebdcd82181b 100644
--- a/source/dnode/mnode/impl/inc/mndTopic.h
+++ b/source/dnode/mnode/impl/inc/mndTopic.h
@@ -37,6 +37,8 @@ const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]);
int32_t mndSetTopicCommitLogs(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic);
+bool mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, const SArray *colIds);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index c062a2c5523dd42ac5bcae27dc2863c058f8e374..6d7a638c30818d64e436f2de989c7d2fe1d7b9c5 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -115,6 +115,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT8(pRaw, dataPos, pRetension->freqUnit, _OVER)
SDB_SET_INT8(pRaw, dataPos, pRetension->keepUnit, _OVER)
}
+ SDB_SET_INT8(pRaw, dataPos, pDb->cfg.schemaless, _OVER)
SDB_SET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@@ -192,6 +193,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
}
}
}
+ SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.schemaless, _OVER)
SDB_GET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
taosInitRWLatch(&pDb->lock);
@@ -380,6 +382,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->replications < TSDB_MIN_DB_REPLICA || pCfg->replications > TSDB_MAX_DB_REPLICA) return -1;
if (pCfg->replications != 1 && pCfg->replications != 3) return -1;
if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1;
+ if (pCfg->schemaless < TSDB_DB_SCHEMALESS_OFF || pCfg->schemaless > TSDB_DB_SCHEMALESS_ON) return -1;
if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1;
if (pCfg->hashMethod != 1) return -1;
if (pCfg->replications > mndGetDnodeSize(pMnode)) {
@@ -411,6 +414,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->strict < 0) pCfg->strict = TSDB_DEFAULT_DB_STRICT;
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0;
+ if (pCfg->schemaless < 0) pCfg->schemaless = TSDB_DB_SCHEMALESS_OFF;
+
}
static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
@@ -521,6 +526,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
.strict = pCreate->strict,
.cacheLastRow = pCreate->cacheLastRow,
.hashMethod = 1,
+ .schemaless = pCreate->schemaless,
};
dbObj.cfg.numOfRetensions = pCreate->numOfRetensions;
@@ -899,6 +905,7 @@ static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) {
cfgRsp.cacheLastRow = pDb->cfg.cacheLastRow;
cfgRsp.numOfRetensions = pDb->cfg.numOfRetensions;
cfgRsp.pRetensions = pDb->cfg.pRetensions;
+ cfgRsp.schemaless = pDb->cfg.schemaless;
int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &cfgRsp);
void *pRsp = rpcMallocCont(contLen);
@@ -1542,8 +1549,11 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.numOfStables, false);
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, rows, (const char *)statusB, false);
+
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
+ colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.schemaless, false);
}
}
diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c
index bf4baebd8584bd8324f3e4e53836bbd8a2002fad..7e5dbb95660dd3ec89ffc8b6dbdf93a4c3b9f619 100644
--- a/source/dnode/mnode/impl/src/mndFunc.c
+++ b/source/dnode/mnode/impl/src/mndFunc.c
@@ -538,7 +538,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char *)&isAgg, false);
- char b3[TSDB_TYPE_STR_MAX_LEN] = {0};
+ char b3[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen),
pShow->pMeta->pSchemas[cols].bytes);
diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c
index 7c94a33ffe10f93a6c809089f04bf704bcb6f676..013a991e98d1b57c88d0cbf262877afa05d587f6 100644
--- a/source/dnode/mnode/impl/src/mndMnode.c
+++ b/source/dnode/mnode/impl/src/mndMnode.c
@@ -53,10 +53,10 @@ int32_t mndInitMnode(SMnode *pMnode) {
};
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_MNODE, mndProcessCreateMnodeReq);
- mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE, mndProcessAlterMnodeReq);
+ mndSetMsgHandle(pMnode, TDMT_MND_ALTER_MNODE, mndProcessAlterMnodeReq);
mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq);
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_MNODE_RSP, mndProcessCreateMnodeRsp);
- mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE_RSP, mndProcessAlterMnodeRsp);
+ mndSetMsgHandle(pMnode, TDMT_MND_ALTER_MNODE_RSP, mndProcessAlterMnodeRsp);
mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndProcessDropMnodeRsp);
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes);
@@ -338,7 +338,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
.epSet = alterEpset,
.pCont = pReq,
.contLen = contLen,
- .msgType = TDMT_DND_ALTER_MNODE,
+ .msgType = TDMT_MND_ALTER_MNODE,
.acceptableCode = 0,
};
@@ -506,7 +506,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
.epSet = alterEpset,
.pCont = pReq,
.contLen = contLen,
- .msgType = TDMT_DND_ALTER_MNODE,
+ .msgType = TDMT_MND_ALTER_MNODE,
.acceptableCode = 0,
};
@@ -655,7 +655,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, b1, false);
- const char *roles = "OFFLINE";
+ const char *roles = "offline";
if (pObj->id == pMnode->selfDnodeId) {
roles = syncStr(TAOS_SYNC_STATE_LEADER);
}
@@ -667,9 +667,9 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char *)b2, false);
- const char *status = "READY";
- if (objStatus == SDB_STATUS_CREATING) status = "CREATING";
- if (objStatus == SDB_STATUS_DROPPING) status = "DROPPING";
+ const char *status = "ready";
+ if (objStatus == SDB_STATUS_CREATING) status = "creating";
+ if (objStatus == SDB_STATUS_DROPPING) status = "dropping";
char b3[9 + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(b3, status, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c
index 41065a3fdd54d07cb75a65fba8e1da7bdd97d3a3..c7f8415b65db611500d3df1907405a1d07b4b3c2 100644
--- a/source/dnode/mnode/impl/src/mndSubscribe.c
+++ b/source/dnode/mnode/impl/src/mndSubscribe.c
@@ -390,7 +390,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
mInfo("rebalance calculation completed, rebalanced vg:");
for (int32_t i = 0; i < taosArrayGetSize(pOutput->rebVgs); i++) {
SMqRebOutputVg *pOutputRebVg = taosArrayGet(pOutput->rebVgs, i);
- mInfo("vgId:%d moved from consumer %" PRId64 " to consumer %" PRId64, pOutputRebVg->pVgEp->vgId,
+ mInfo("vgId:%d, moved from consumer %" PRId64 " to consumer %" PRId64, pOutputRebVg->pVgEp->vgId,
pOutputRebVg->oldConsumerId, pOutputRebVg->newConsumerId);
}
diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c
index 21b5e37e1ea5b1d5f534bae0efccd07d6f9115ae..e0d565c9afb0fafe46c5ff3dd96a83ee9c76372d 100644
--- a/source/dnode/mnode/impl/src/mndTopic.c
+++ b/source/dnode/mnode/impl/src/mndTopic.c
@@ -70,6 +70,56 @@ const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]) {
return strchr(topic, '.') + 1;
}
+bool mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, const SArray *colAndTagIds) {
+ SSdb *pSdb = pMnode->pSdb;
+ void *pIter = NULL;
+ bool found = false;
+ while (1) {
+ SMqTopicObj *pTopic = NULL;
+ pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic);
+ if (pIter == NULL) break;
+ if (pTopic->subType != TOPIC_SUB_TYPE__COLUMN) {
+ sdbRelease(pSdb, pTopic);
+ continue;
+ }
+
+ SNode *pAst = NULL;
+ if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
+ ASSERT(0);
+ return false;
+ }
+
+ SHashObj *pColHash = NULL;
+ SNodeList *pNodeList;
+ nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList);
+ SNode *pNode = NULL;
+ FOREACH(pNode, pNodeList) {
+ SColumnNode *pCol = (SColumnNode *)pNode;
+ if (pCol->tableId != suid) goto NEXT;
+ if (pColHash == NULL) {
+ pColHash = taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK);
+ }
+ if (pCol->colId > 0) {
+ taosHashPut(pColHash, &pCol->colId, sizeof(int16_t), NULL, 0);
+ }
+ }
+
+ for (int32_t i = 0; i < taosArrayGetSize(colAndTagIds); i++) {
+ int16_t *pColId = taosArrayGet(colAndTagIds, i);
+ if (taosHashGet(pColHash, pColId, sizeof(int16_t)) != NULL) {
+ found = true;
+ goto NEXT;
+ }
+ }
+
+ NEXT:
+ sdbRelease(pSdb, pTopic);
+ nodesDestroyNode(pAst);
+ if (found) return false;
+ }
+ return true;
+}
+
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index 9262aa167b20372dcabc4d8b78cf311911cf2162..2577febf6611ffbdbeb8d4021df3292e99c7873b 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -705,7 +705,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
}
char buf1[20] = {0};
- const char *role = online ? syncStr(pVgroup->vnodeGid[i].role) : "OFFLINE";
+ const char *role = online ? syncStr(pVgroup->vnodeGid[i].role) : "offline";
STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt
index d72292e34bd605ec91b16788fadd9f1ff1c68cc4..40f8b0726e28446170a71bbbccde979376448fbb 100644
--- a/source/dnode/mnode/impl/test/acct/CMakeLists.txt
+++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt
@@ -5,9 +5,7 @@ target_link_libraries(
PUBLIC sut
)
-if(NOT TD_WINDOWS)
- add_test(
- NAME acctTest
- COMMAND acctTest
- )
-endif(NOT TD_WINDOWS)
+add_test(
+ NAME acctTest
+ COMMAND acctTest
+)
diff --git a/source/dnode/mnode/impl/test/func/CMakeLists.txt b/source/dnode/mnode/impl/test/func/CMakeLists.txt
index 2a8eb0a39d89275ae204e6405de2b774b4412619..17adfde801c02292a1e26a797541cd3a500e19c4 100644
--- a/source/dnode/mnode/impl/test/func/CMakeLists.txt
+++ b/source/dnode/mnode/impl/test/func/CMakeLists.txt
@@ -5,9 +5,9 @@ target_link_libraries(
PUBLIC sut
)
-if(NOT TD_WINDOWS)
+# if(NOT TD_WINDOWS)
add_test(
NAME funcTest
COMMAND funcTest
)
-endif(NOT TD_WINDOWS)
+# endif(NOT TD_WINDOWS)
diff --git a/source/dnode/mnode/impl/test/profile/CMakeLists.txt b/source/dnode/mnode/impl/test/profile/CMakeLists.txt
index b6586192b2b4c6e428c2f00fddb11527a1747707..049a4f3a9f45d6608fdb403e99b95b937e93c483 100644
--- a/source/dnode/mnode/impl/test/profile/CMakeLists.txt
+++ b/source/dnode/mnode/impl/test/profile/CMakeLists.txt
@@ -5,9 +5,9 @@ target_link_libraries(
PUBLIC sut
)
-if(NOT TD_WINDOWS)
+# if(NOT TD_WINDOWS)
add_test(
NAME profileTest
COMMAND profileTest
)
-endif(NOT TD_WINDOWS)
+# endif(NOT TD_WINDOWS)
diff --git a/source/dnode/mnode/impl/test/show/CMakeLists.txt b/source/dnode/mnode/impl/test/show/CMakeLists.txt
index 9b4e21501ed478e527adfa69a5a2297e173876e1..33ba0c5697d9188aaa1ec0328afc6f143e49413c 100644
--- a/source/dnode/mnode/impl/test/show/CMakeLists.txt
+++ b/source/dnode/mnode/impl/test/show/CMakeLists.txt
@@ -5,9 +5,9 @@ target_link_libraries(
PUBLIC sut
)
-if(NOT TD_WINDOWS)
+# if(NOT TD_WINDOWS)
add_test(
NAME showTest
COMMAND showTest
)
-endif(NOT TD_WINDOWS)
+# endif(NOT TD_WINDOWS)
diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt
index 890b8d08ab97b6f7db1bd0329466cb6f67db8910..f3aefdba029484aaa155848e364de32743efaa3c 100644
--- a/source/dnode/vnode/CMakeLists.txt
+++ b/source/dnode/vnode/CMakeLists.txt
@@ -32,11 +32,10 @@ target_sources(
"src/sma/smaEnv.c"
"src/sma/smaOpen.c"
"src/sma/smaRollup.c"
- "src/sma/smaTimeRange.c"
+ "src/sma/smaTimeRange2.c"
# tsdb
"src/tsdb/tsdbCommit.c"
- "src/tsdb/tsdbCommit2.c"
"src/tsdb/tsdbFile.c"
"src/tsdb/tsdbFS.c"
"src/tsdb/tsdbOpen.c"
diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h
index c3016eeff753d989dda58056fa508eb5f7770f0f..7bd2eadd4bf5119dc38a85beadb5986bc6e96f7f 100644
--- a/source/dnode/vnode/inc/vnode.h
+++ b/source/dnode/vnode/inc/vnode.h
@@ -148,6 +148,9 @@ bool tqNextDataBlockFilterOut(STqReadHandle *pHandle, SHashObj *filterOutUids
int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid,
int32_t *pNumOfRows, int16_t *pNumOfCols);
+// sma
+int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);
+
// need to reposition
// structs
diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h
index 52e576ee5249de37a9b30c137bff98f123999081..b610676c19db7b9cdb9528b3d8044e883d811780 100644
--- a/source/dnode/vnode/src/inc/meta.h
+++ b/source/dnode/vnode/src/inc/meta.h
@@ -28,12 +28,12 @@ typedef struct SMetaDB SMetaDB;
// metaDebug ==================
// clang-format off
-#define metaFatal(...) do { if (metaDebugFlag & DEBUG_FATAL) { taosPrintLog("META FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
-#define metaError(...) do { if (metaDebugFlag & DEBUG_ERROR) { taosPrintLog("META ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
-#define metaWarn(...) do { if (metaDebugFlag & DEBUG_WARN) { taosPrintLog("META WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
-#define metaInfo(...) do { if (metaDebugFlag & DEBUG_INFO) { taosPrintLog("META ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
-#define metaDebug(...) do { if (metaDebugFlag & DEBUG_DEBUG) { taosPrintLog("META ", DEBUG_DEBUG, metaDebugFlag, __VA_ARGS__); }} while(0)
-#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
+#define metaFatal(...) do { if (metaDebugFlag & DEBUG_FATAL) { taosPrintLog("MTA FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
+#define metaError(...) do { if (metaDebugFlag & DEBUG_ERROR) { taosPrintLog("MTA ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
+#define metaWarn(...) do { if (metaDebugFlag & DEBUG_WARN) { taosPrintLog("MTA WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
+#define metaInfo(...) do { if (metaDebugFlag & DEBUG_INFO) { taosPrintLog("MTA ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
+#define metaDebug(...) do { if (metaDebugFlag & DEBUG_DEBUG) { taosPrintLog("MTA ", DEBUG_DEBUG, metaDebugFlag, __VA_ARGS__); }} while(0)
+#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("MTA ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
// metaOpen ==================
diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h
index 03dd2ea66cb387edeed3a4949936db5affb9592b..4ca62f1de9fbe9183d74e9df1dfeca8fbde2e0fb 100644
--- a/source/dnode/vnode/src/inc/sma.h
+++ b/source/dnode/vnode/src/inc/sma.h
@@ -223,6 +223,8 @@ int32_t tdUpdateExpiredWindowImpl(SSma *pSma, const SSubmitReq *pMsg, int64_t ve
// TODO: This is the basic params, and should wrap the params to a queryHandle.
int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
+int32_t tdGetTSmaDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h
index a5907cf9912aa9af0caff46e0aea85d690076cbb..5f4f7e70daf089d22fa4e80978e787d10dc08c09 100644
--- a/source/dnode/vnode/src/inc/vnd.h
+++ b/source/dnode/vnode/src/inc/vnd.h
@@ -84,7 +84,7 @@ int32_t vnodeAsyncCommit(SVnode* pVnode);
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
void vnodeSyncStart(SVnode* pVnode);
void vnodeSyncClose(SVnode* pVnode);
-void vnodeSyncAlter(SVnode* pVnode, SRpcMsg* pMsg);
+int32_t vnodeSyncAlter(SVnode* pVnode, SRpcMsg* pMsg);
#ifdef __cplusplus
}
diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c
index f23e7f88056d6a397a5979bda11dd4f080ba0212..86637d28504bf7169c4b3f2ab4ae145af1e10661 100644
--- a/source/dnode/vnode/src/meta/metaOpen.c
+++ b/source/dnode/vnode/src/meta/metaOpen.c
@@ -53,42 +53,42 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
// open env
ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv);
if (ret < 0) {
- metaError("vgId:%d failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pTbDb
ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb);
if (ret < 0) {
- metaError("vgId:%d failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pSkmDb
ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb);
if (ret < 0) {
- metaError("vgId:%d failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pUidIdx
ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(int64_t), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pNameIdx
ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pCtbIdx
ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
@@ -100,14 +100,14 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
taosMkDir(indexFullPath);
ret = indexOpen(indexOptsCreate(), indexFullPath, (SIndex **)&pMeta->pTagIvtIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
#else
ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
#endif
@@ -115,24 +115,24 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
// open pTtlIdx
ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pSmaIdx
ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx);
if (ret < 0) {
- metaError("vgId:%d failed to open meta sma index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta sma index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open index
if (metaOpenIdx(pMeta) < 0) {
- metaError("vgId:%d failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno));
+ metaError("vgId:%d, failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
- metaDebug("vgId:%d meta is opened", TD_VID(pVnode));
+ metaDebug("vgId:%d, meta is opened", TD_VID(pVnode));
*ppMeta = pMeta;
return 0;
diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c
index a57eb4e899a2fc18d8a8a1f8c7bcd0d80a528f07..21a55d646331dd2ecb0a8c69c22edf4e6bd0f8cf 100644
--- a/source/dnode/vnode/src/meta/metaQuery.c
+++ b/source/dnode/vnode/src/meta/metaQuery.c
@@ -425,7 +425,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
for (int i = 0; i < pSW->number; ++i) {
smaId = *(tb_uid_t *)taosArrayGet(pSmaIds, i);
if (metaGetTableEntryByUid(&mr, smaId) < 0) {
- metaWarn("vgId:%d no entry for tbId: %" PRIi64 ", smaId: %" PRIi64, TD_VID(pMeta->pVnode), uid, smaId);
+ metaWarn("vgId:%d, no entry for tbId: %" PRIi64 ", smaId: %" PRIi64, TD_VID(pMeta->pVnode), uid, smaId);
continue;
}
pTSma = pSW->tSma + smaIdx;
@@ -464,7 +464,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
_err:
metaReaderClear(&mr);
taosArrayDestroy(pSmaIds);
- tdFreeTSmaWrapper(pSW, deepCopy);
+ tFreeTSmaWrapper(pSW, deepCopy);
return NULL;
}
@@ -473,7 +473,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
SMetaReader mr = {0};
metaReaderInit(&mr, pMeta, 0);
if (metaGetTableEntryByUid(&mr, indexUid) < 0) {
- metaWarn("vgId:%d failed to get table entry for smaId: %" PRIi64, TD_VID(pMeta->pVnode), indexUid);
+ metaWarn("vgId:%d, failed to get table entry for smaId: %" PRIi64, TD_VID(pMeta->pVnode), indexUid);
metaReaderClear(&mr);
return NULL;
}
@@ -576,15 +576,15 @@ SArray *metaGetSmaTbUids(SMeta *pMeta) {
const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) {
ASSERT(pEntry->type == TSDB_CHILD_TABLE);
STag *tag = (STag *)pEntry->ctbEntry.pTags;
- if (type == TSDB_DATA_TYPE_JSON){
- if(tag->nTag == 0){
+ if (type == TSDB_DATA_TYPE_JSON) {
+ if (tag->nTag == 0) {
return NULL;
}
return tag;
}
bool find = tTagGet(tag, val);
- if(!find){
+ if (!find) {
return NULL;
}
return val;
@@ -605,8 +605,6 @@ typedef struct {
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
SIdxCursor *pCursor = NULL;
- char *tagData = param->val;
-
int32_t ret = 0, valid = 0;
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
pCursor->pMeta = pMeta;
@@ -623,12 +621,16 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
int32_t nKey = 0;
int32_t nTagData = 0;
- if(IS_VAR_DATA_TYPE(param->type)){
- nTagData = strlen(param->val);
- }else{
+ void * tagData = NULL;
+
+ if (IS_VAR_DATA_TYPE(param->type)) {
+ tagData = varDataVal(param->val);
+ nTagData = varDataLen(param->val);
+ } else {
+ tagData = param->val;
nTagData = tDataTypes[param->type].bytes;
}
- ret = metaCreateTagIdxKey(pCursor->suid, pCursor->cid, param->val, nTagData, pCursor->type,
+ ret = metaCreateTagIdxKey(pCursor->suid, pCursor->cid, tagData, nTagData, pCursor->type,
param->reverse ? INT64_MAX : INT64_MIN, &pKey, &nKey);
if (ret != 0) {
goto END;
@@ -637,6 +639,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
if (tdbTbcMoveTo(pCursor->pCur, pKey, nKey, &cmp) < 0) {
goto END;
}
+
void * entryKey = NULL, *entryVal = NULL;
int32_t nEntryKey, nEntryVal;
while (1) {
@@ -649,7 +652,12 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
int32_t cmp = (*param->filterFunc)(p->data, pKey->data, pKey->type);
if (cmp == 0) {
// match
- tb_uid_t tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes);
+ tb_uid_t tuid = 0;
+ if (IS_VAR_DATA_TYPE(pKey->type)) {
+ tuid = *(tb_uid_t *)(p->data + varDataTLen(p->data));
+ } else {
+ tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes);
+ }
taosArrayPush(pUids, &tuid);
} else if (cmp == 1) {
// not match but should continue to iter
@@ -670,4 +678,4 @@ END:
taosMemoryFree(pCursor);
return ret;
-}
\ No newline at end of file
+}
diff --git a/source/dnode/vnode/src/meta/metaSma.c b/source/dnode/vnode/src/meta/metaSma.c
index 75595d83a64941e0caf6f2f399345c09a226286e..fde9d30346da782129739592ab3c34bfdb964379 100644
--- a/source/dnode/vnode/src/meta/metaSma.c
+++ b/source/dnode/vnode/src/meta/metaSma.c
@@ -57,12 +57,12 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
if (metaHandleSmaEntry(pMeta, &me) < 0) goto _err;
- metaDebug("vgId:%d tsma is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pCfg->indexName, pCfg->indexUid);
+ metaDebug("vgId:%d, tsma is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pCfg->indexName, pCfg->indexUid);
return 0;
_err:
- metaError("vgId:%d failed to create tsma: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pCfg->indexName,
+ metaError("vgId:%d, failed to create tsma: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pCfg->indexName,
pCfg->indexUid, tstrerror(terrno));
return -1;
}
diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c
index 9fef60b79fd9ff6cb46e86ba626802378ead3f1f..b45fccaf2901a15b95640ffcb7b7eb2728ed2063 100644
--- a/source/dnode/vnode/src/meta/metaTable.c
+++ b/source/dnode/vnode/src/meta/metaTable.c
@@ -49,9 +49,9 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
int vLen = 0;
const void *pKey = NULL;
const void *pVal = NULL;
- void *pBuf = NULL;
+ void * pBuf = NULL;
int32_t szBuf = 0;
- void *p = NULL;
+ void * p = NULL;
SMetaReader mr = {0};
// validate req
@@ -79,12 +79,12 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
- metaDebug("vgId:%d super table is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
+ metaDebug("vgId:%d, super table is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
return 0;
_err:
- metaError("vgId:%d failed to create super table: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
+ metaError("vgId:%d, failed to create super table: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->suid, tstrerror(terrno));
return -1;
}
@@ -105,7 +105,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
}
// drop all child tables
- TBC *pCtbIdxc = NULL;
+ TBC * pCtbIdxc = NULL;
SArray *pArray = taosArrayInit(8, sizeof(tb_uid_t));
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
@@ -153,15 +153,15 @@ _drop_super_table:
_exit:
tdbFree(pKey);
tdbFree(pData);
- metaDebug("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
+ metaDebug("vgId:%d, super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
return 0;
}
int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
SMetaEntry oStbEntry = {0};
SMetaEntry nStbEntry = {0};
- TBC *pUidIdxc = NULL;
- TBC *pTbDbc = NULL;
+ TBC * pUidIdxc = NULL;
+ TBC * pTbDbc = NULL;
const void *pData;
int nData;
int64_t oversion;
@@ -269,18 +269,18 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
- metaDebug("vgId:%d table %s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
+ metaDebug("vgId:%d, table %s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
pReq->type);
return 0;
_err:
- metaError("vgId:%d failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
+ metaError("vgId:%d, failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
return -1;
}
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) {
- void *pData = NULL;
+ void * pData = NULL;
int nData = 0;
int rc = 0;
tb_uid_t uid;
@@ -306,7 +306,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
}
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
- void *pData = NULL;
+ void * pData = NULL;
int nData = 0;
int rc = 0;
int64_t version;
@@ -341,15 +341,16 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
return 0;
}
+
static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) {
void * pVal = NULL;
int nVal = 0;
- const void *pData = NULL;
+ const void * pData = NULL;
int nData = 0;
int ret = 0;
tb_uid_t uid;
int64_t oversion;
- SSchema *pColumn = NULL;
+ SSchema * pColumn = NULL;
SMetaEntry entry = {0};
SSchemaWrapper *pSchema;
int c;
@@ -499,7 +500,7 @@ _err:
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
SMetaEntry ctbEntry = {0};
SMetaEntry stbEntry = {0};
- void *pVal = NULL;
+ void * pVal = NULL;
int nVal = 0;
int ret;
int c;
@@ -530,7 +531,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
oversion = *(int64_t *)pData;
// search table.db
- TBC *pTbDbc = NULL;
+ TBC * pTbDbc = NULL;
SDecoder dc1 = {0};
SDecoder dc2 = {0};
@@ -554,7 +555,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
metaDecodeEntry(&dc2, &stbEntry);
SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
- SSchema *pColumn = NULL;
+ SSchema * pColumn = NULL;
int32_t iCol = 0;
for (;;) {
pColumn = NULL;
@@ -584,8 +585,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
memcpy((void *)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal);
} else {
const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags;
- STag *pNewTag = NULL;
- SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
+ STag * pNewTag = NULL;
+ SArray * pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
if (!pTagArray) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
@@ -604,7 +605,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
}
taosArrayPush(pTagArray, &val);
} else {
- STagVal val = {0};
+ STagVal val = {.cid = pCol->colId};
if (tTagGet(pOldTag, &val)) {
taosArrayPush(pTagArray, &val);
}
@@ -669,8 +670,8 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
STbDbKey tbDbKey;
- void *pKey = NULL;
- void *pVal = NULL;
+ void * pKey = NULL;
+ void * pVal = NULL;
int kLen = 0;
int vLen = 0;
SEncoder coder = {0};
@@ -753,16 +754,11 @@ static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void *pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
STagIdxKey **ppTagIdxKey, int32_t *nTagIdxKey) {
- // int32_t nTagData = 0;
-
- // if (pTagData) {
- // if (IS_VAR_DATA_TYPE(type)) {
- // nTagData = varDataTLen(pTagData);
- // } else {
- // nTagData = tDataTypes[type].bytes;
- // }
- // }
- *nTagIdxKey = sizeof(STagIdxKey) + nTagData + sizeof(tb_uid_t);
+ if (IS_VAR_DATA_TYPE(type)) {
+ *nTagIdxKey = sizeof(STagIdxKey) + nTagData + VARSTR_HEADER_SIZE + sizeof(tb_uid_t);
+ } else {
+ *nTagIdxKey = sizeof(STagIdxKey) + nTagData + sizeof(tb_uid_t);
+ }
*ppTagIdxKey = (STagIdxKey *)taosMemoryMalloc(*nTagIdxKey);
if (*ppTagIdxKey == NULL) {
@@ -774,8 +770,16 @@ int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void *pTagData, int32_
(*ppTagIdxKey)->cid = cid;
(*ppTagIdxKey)->isNull = (pTagData == NULL) ? 1 : 0;
(*ppTagIdxKey)->type = type;
- if (nTagData) memcpy((*ppTagIdxKey)->data, pTagData, nTagData);
- *(tb_uid_t *)((*ppTagIdxKey)->data + nTagData) = uid;
+
+ // refactor
+ if (IS_VAR_DATA_TYPE(type)) {
+ memcpy((*ppTagIdxKey)->data, (uint16_t *)&nTagData, VARSTR_HEADER_SIZE);
+ memcpy((*ppTagIdxKey)->data + VARSTR_HEADER_SIZE, pTagData, nTagData);
+ *(tb_uid_t *)((*ppTagIdxKey)->data + VARSTR_HEADER_SIZE + nTagData) = uid;
+ } else {
+ memcpy((*ppTagIdxKey)->data, pTagData, nTagData);
+ *(tb_uid_t *)((*ppTagIdxKey)->data + nTagData) = uid;
+ }
return 0;
}
@@ -785,14 +789,14 @@ static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey) {
}
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
- void *pData = NULL;
+ void * pData = NULL;
int nData = 0;
STbDbKey tbDbKey = {0};
SMetaEntry stbEntry = {0};
- STagIdxKey *pTagIdxKey = NULL;
+ STagIdxKey * pTagIdxKey = NULL;
int32_t nTagIdxKey;
const SSchema *pTagColumn; // = &stbEntry.stbEntry.schema.pSchema[0];
- const void *pTagData = NULL; //
+ const void * pTagData = NULL; //
int32_t nTagData = 0;
SDecoder dc = {0};
@@ -849,7 +853,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
SEncoder coder = {0};
- void *pVal = NULL;
+ void * pVal = NULL;
int vLen = 0;
int rcode = 0;
SSkmDbKey skmDbKey = {0};
diff --git a/source/dnode/vnode/src/sma/sma.c b/source/dnode/vnode/src/sma/sma.c
index 7a2b6a2757ad4153313586310b01148c4efb49b1..04f65275d7d20ab41564a8e8c6e67c908b3bc649 100644
--- a/source/dnode/vnode/src/sma/sma.c
+++ b/source/dnode/vnode/src/sma/sma.c
@@ -20,7 +20,7 @@ int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg) {
int32_t code = TSDB_CODE_SUCCESS;
if ((code = tdProcessTSmaInsertImpl(pSma, indexUid, msg)) < 0) {
- smaWarn("vgId:%d insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ smaWarn("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
}
// TODO: destroy SSDataBlocks(msg)
return code;
@@ -30,7 +30,7 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg) {
int32_t code = TSDB_CODE_SUCCESS;
if ((code = tdProcessTSmaCreateImpl(pSma, version, msg)) < 0) {
- smaWarn("vgId:%d create tsma failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ smaWarn("vgId:%d, create tsma failed since %s", SMA_VID(pSma), tstrerror(terrno));
}
// TODO: destroy SSDataBlocks(msg)
return code;
@@ -39,7 +39,7 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg) {
int32_t tdUpdateExpireWindow(SSma* pSma, const SSubmitReq* pMsg, int64_t version) {
int32_t code = TSDB_CODE_SUCCESS;
if ((code = tdUpdateExpiredWindowImpl(pSma, pMsg, version)) < 0) {
- smaWarn("vgId:%d update expired sma window failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ smaWarn("vgId:%d, update expired sma window failed since %s", SMA_VID(pSma), tstrerror(terrno));
}
return code;
}
@@ -47,7 +47,15 @@ int32_t tdUpdateExpireWindow(SSma* pSma, const SSubmitReq* pMsg, int64_t version
int32_t tdGetTSmaData(SSma* pSma, char* pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
int32_t code = TSDB_CODE_SUCCESS;
if ((code = tdGetTSmaDataImpl(pSma, pData, indexUid, querySKey, nMaxResult)) < 0) {
- smaWarn("vgId:%d get tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ smaWarn("vgId:%d, get tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ }
+ return code;
+}
+
+int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t *days) {
+ int32_t code = TSDB_CODE_SUCCESS;
+ if ((code = tdGetTSmaDaysImpl(pCfg, pCont, contLen, days)) < 0) {
+ smaWarn("vgId:%d get tSma days failed since %s", pCfg->vgId, tstrerror(terrno));
}
return code;
}
diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c
index 8285b74e509f53a8ed3a9d2e5745d2f56135087e..179f573e8d72c3ae6938edb31e61ef6b9ec8a675 100644
--- a/source/dnode/vnode/src/sma/smaEnv.c
+++ b/source/dnode/vnode/src/sma/smaEnv.c
@@ -222,7 +222,7 @@ int32_t tdRefSmaStat(SSma *pSma, SSmaStat *pStat) {
if (!pStat) return 0;
int ref = T_REF_INC(pStat);
- smaDebug("vgId:%d ref sma stat:%p, val:%d", SMA_VID(pSma), pStat, ref);
+ smaDebug("vgId:%d, ref sma stat:%p, val:%d", SMA_VID(pSma), pStat, ref);
return 0;
}
@@ -230,7 +230,7 @@ int32_t tdUnRefSmaStat(SSma *pSma, SSmaStat *pStat) {
if (!pStat) return 0;
int ref = T_REF_DEC(pStat);
- smaDebug("vgId:%d unref sma stat:%p, val:%d", SMA_VID(pSma), pStat, ref);
+ smaDebug("vgId:%d, unref sma stat:%p, val:%d", SMA_VID(pSma), pStat, ref);
return 0;
}
@@ -278,7 +278,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
void *tdFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
if (pSmaStatItem) {
- tdDestroyTSma(pSmaStatItem->pTSma);
+ tDestroyTSma(pSmaStatItem->pTSma);
taosMemoryFreeClear(pSmaStatItem->pTSma);
taosHashCleanup(pSmaStatItem->expiredWindows);
taosMemoryFreeClear(pSmaStatItem);
@@ -321,7 +321,7 @@ int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
int32_t tdLockSma(SSma *pSma) {
int code = taosThreadMutexLock(&pSma->mutex);
if (code != 0) {
- smaError("vgId:%d failed to lock td since %s", SMA_VID(pSma), strerror(errno));
+ smaError("vgId:%d, failed to lock td since %s", SMA_VID(pSma), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
@@ -334,7 +334,7 @@ int32_t tdUnLockSma(SSma *pSma) {
pSma->locked = false;
int code = taosThreadMutexUnlock(&pSma->mutex);
if (code != 0) {
- smaError("vgId:%d failed to unlock td since %s", SMA_VID(pSma), strerror(errno));
+ smaError("vgId:%d, failed to unlock td since %s", SMA_VID(pSma), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
@@ -376,7 +376,7 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
if (did.level < 0 || did.id < 0) {
tdUnLockSma(pSma);
- smaError("vgId:%d init sma env failed since invalid did(%d,%d)", SMA_VID(pSma), did.level, did.id);
+ smaError("vgId:%d, init sma env failed since invalid did(%d,%d)", SMA_VID(pSma), did.level, did.id);
return TSDB_CODE_FAILED;
}
diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c
index 42c215ee7c276ac6ed7d299390bef7e2083741ce..80c8d20572bc9ef6658d3bc46116874e9ff68a42 100644
--- a/source/dnode/vnode/src/sma/smaRollup.c
+++ b/source/dnode/vnode/src/sma/smaRollup.c
@@ -58,30 +58,30 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA
if (!suid || !tbUids) {
terrno = TSDB_CODE_INVALID_PTR;
- smaError("vgId:%d failed to get rsma info for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
+ smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
return TSDB_CODE_FAILED;
}
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
- smaError("vgId:%d failed to get rsma info for uid:%" PRIi64, SMA_VID(pSma), *suid);
+ smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64, SMA_VID(pSma), *suid);
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
return TSDB_CODE_FAILED;
}
if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) {
- smaError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
+ smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
return TSDB_CODE_FAILED;
} else {
- smaDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma),
+ smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma),
pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
}
if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) {
- smaError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
+ smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno));
return TSDB_CODE_FAILED;
} else {
- smaDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma),
+ smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma),
pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
}
@@ -170,14 +170,14 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
SMeta *pMeta = pVnode->pMeta;
SMsgCb *pMsgCb = &pVnode->msgCb;
if (!pReq->rollup) {
- smaTrace("vgId:%d return directly since no rollup for stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
+ smaTrace("vgId:%d, return directly since no rollup for stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
return TSDB_CODE_SUCCESS;
}
SRSmaParam *param = &pReq->pRSmaParam;
if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) {
- smaWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
+ smaWarn("vgId:%d, no qmsg1/qmsg2 for rollup stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
return TSDB_CODE_SUCCESS;
}
@@ -192,7 +192,7 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t));
if (pRSmaInfo) {
- smaWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
+ smaWarn("vgId:%d, rsma info already exists for stb: %s, %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid);
return TSDB_CODE_SUCCESS;
}
@@ -238,7 +238,7 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
TSDB_CODE_SUCCESS) {
return TSDB_CODE_FAILED;
} else {
- smaDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, SMA_VID(pSma), pReq->suid);
+ smaDebug("vgId:%d, register rsma info succeed for suid:%" PRIi64, SMA_VID(pSma), pReq->suid);
}
return TSDB_CODE_SUCCESS;
@@ -372,11 +372,11 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3
SArray *pResult = NULL;
if (!taskInfo) {
- smaDebug("vgId:%d no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid);
+ smaDebug("vgId:%d, no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid);
return TSDB_CODE_SUCCESS;
}
- smaDebug("vgId:%d execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, taskInfo, suid);
+ smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, taskInfo, suid);
qSetStreamInput(taskInfo, pMsg, inputType, true);
while (1) {
@@ -414,7 +414,7 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3
}
taosMemoryFreeClear(pReq);
} else {
- smaDebug("vgId:%d no rsma % " PRIi8 " data generated since %s", SMA_VID(pSma), level, tstrerror(terrno));
+ smaDebug("vgId:%d, no rsma % " PRIi8 " data generated since %s", SMA_VID(pSma), level, tstrerror(terrno));
}
taosArrayDestroy(pResult);
@@ -435,11 +435,11 @@ static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &suid, sizeof(tb_uid_t));
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
- smaDebug("vgId:%d no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
+ smaDebug("vgId:%d, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
return TSDB_CODE_SUCCESS;
}
if (!pRSmaInfo->taskInfo[0]) {
- smaDebug("vgId:%d no rsma qTaskInfo for suid:%" PRIu64, SMA_VID(pSma), suid);
+ smaDebug("vgId:%d, no rsma qTaskInfo for suid:%" PRIu64, SMA_VID(pSma), suid);
return TSDB_CODE_SUCCESS;
}
diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c
index f88afcaddf82eed173f00693ea9d905ea195bd91..b72be06455d8181dca8a27ea1c58cfa72ddef39f 100644
--- a/source/dnode/vnode/src/sma/smaTimeRange.c
+++ b/source/dnode/vnode/src/sma/smaTimeRange.c
@@ -326,13 +326,13 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
if (!pDataBlocks) {
terrno = TSDB_CODE_INVALID_PTR;
- smaWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", SMA_VID(pSma));
+ smaWarn("vgId:%d, insert tSma data failed since pDataBlocks is NULL", SMA_VID(pSma));
return terrno;
}
if (taosArrayGetSize(pDataBlocks) <= 0) {
terrno = TSDB_CODE_INVALID_PARA;
- smaWarn("vgId:%d insert tSma data failed since pDataBlocks is empty", SMA_VID(pSma));
+ smaWarn("vgId:%d, insert tSma data failed since pDataBlocks is empty", SMA_VID(pSma));
return TSDB_CODE_FAILED;
}
@@ -487,11 +487,11 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
smaCloseDBF(&tSmaH.dFile);
}
tdSetTSmaDataFile(&tSmaH, indexUid, fid);
- smaDebug("@@@ vgId:%d write to DBF %s, days:%d, interval:%" PRIi64 ", storageLevel:%" PRIi32
+ smaDebug("vgId:%d, write to DBF %s, days:%d, interval:%" PRIi64 ", storageLevel:%" PRIi32
" queryKey:%" PRIi64,
SMA_VID(pSma), tSmaH.dFile.path, minutePerFile, tSmaH.interval, storageLevel, testSkey);
if (smaOpenDBF(pEnv->dbEnv, &tSmaH.dFile) != 0) {
- smaWarn("vgId:%d open DB file %s failed since %s", SMA_VID(pSma),
+ smaWarn("vgId:%d, open DB file %s failed since %s", SMA_VID(pSma),
tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno));
tdDestroyTSmaWriteH(&tSmaH);
tdUnRefSmaStat(pSma, pStat);
@@ -501,7 +501,7 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
}
if (tdInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, dataBuf, tlen, &pEnv->txn) != 0) {
- smaWarn("vgId:%d insert tsma data blocks fail for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64
+ smaWarn("vgId:%d, insert tsma data blocks fail for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64
" since %s",
SMA_VID(pSma), indexUid, skey, groupId, tstrerror(terrno));
tdSmaEndCommit(pEnv);
@@ -510,14 +510,14 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
return TSDB_CODE_FAILED;
}
- smaDebug("vgId:%d insert tsma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64,
+ smaDebug("vgId:%d, insert tsma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64,
SMA_VID(pSma), indexUid, skey, groupId);
// TODO:tsdbEndTSmaCommit();
// Step 3: reset the SSmaStat
tdResetExpiredWindow(pSma, pStat, indexUid, skey);
} else {
- smaWarn("vgId:%d invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64,
+ smaWarn("vgId:%d, invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64,
SMA_VID(pSma), skey, tlen, indexUid);
}
}
@@ -532,7 +532,7 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
int32_t tdDropTSmaData(SSma *pSma, int64_t indexUid) {
int32_t code = TSDB_CODE_SUCCESS;
if ((code = tdDropTSmaDataImpl(pSma, indexUid)) < 0) {
- smaWarn("vgId:%d drop tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ smaWarn("vgId:%d, drop tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
}
return code;
}
@@ -553,11 +553,11 @@ static int32_t tdInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyL
// TODO: insert tsma data blocks into B+Tree(TTB)
if (smaSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen, txn) != 0) {
- smaWarn("vgId:%d insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " fail",
+ smaWarn("vgId:%d, insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " fail",
SMA_VID(pSmaH->pSma), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
return TSDB_CODE_FAILED;
}
- smaDebug("vgId:%d insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " succeed",
+ smaDebug("vgId:%d, insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " succeed",
SMA_VID(pSmaH->pSma), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
@@ -565,7 +565,7 @@ static int32_t tdInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyL
void *data = tdGetSmaDataByKey(pDBFile, smaKey, keyLen, &valueSize);
ASSERT(data != NULL);
for (uint32_t v = 0; v < valueSize; v += 8) {
- smaWarn("vgId:%d insert sma data val[%d] %" PRIi64, REPO_ID(pSmaH->pTsdb), v, *(int64_t *)POINTER_SHIFT(data, v));
+ smaWarn("vgId:%d, insert sma data val[%d] %" PRIi64, REPO_ID(pSmaH->pTsdb), v, *(int64_t *)POINTER_SHIFT(data, v));
}
#endif
return TSDB_CODE_SUCCESS;
@@ -594,11 +594,11 @@ static int32_t tdResetExpiredWindow(SSma *pSma, SSmaStat *pStat, int64_t indexUi
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
// error handling
tdUnRefSmaStat(pSma, pStat);
- smaWarn("vgId:%d remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " fail", SMA_VID(pSma), skey,
+ smaWarn("vgId:%d, remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " fail", SMA_VID(pSma), skey,
indexUid);
return TSDB_CODE_FAILED;
}
- smaDebug("vgId:%d remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " succeed", SMA_VID(pSma),
+ smaDebug("vgId:%d, remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " succeed", SMA_VID(pSma),
skey, indexUid);
// TODO: use a standalone interface to received state upate notification from stream computing module.
/**
@@ -612,7 +612,7 @@ static int32_t tdResetExpiredWindow(SSma *pSma, SSmaStat *pStat, int64_t indexUi
} else {
// error handling
tdUnRefSmaStat(pSma, pStat);
- smaWarn("vgId:%d expired window %" PRIi64 " not exists for sma index %" PRIi64, SMA_VID(pSma), skey, indexUid);
+ smaWarn("vgId:%d, expired window %" PRIi64 " not exists for sma index %" PRIi64, SMA_VID(pSma), skey, indexUid);
return TSDB_CODE_FAILED;
}
@@ -632,19 +632,19 @@ static int32_t tdDropTSmaDataImpl(SSma *pSma, int64_t indexUid) {
// clear local cache
if (pEnv) {
- smaDebug("vgId:%d drop tSma local cache for %" PRIi64, SMA_VID(pSma), indexUid);
+ smaDebug("vgId:%d, drop tSma local cache for %" PRIi64, SMA_VID(pSma), indexUid);
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) {
if (tdSmaStatIsDropped(pItem)) {
- smaDebug("vgId:%d tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
+ smaDebug("vgId:%d, tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
}
tdWLockSmaEnv(pEnv);
if (tdSmaStatIsDropped(pItem)) {
tdUnLockSmaEnv(pEnv);
- smaDebug("vgId:%d tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
+ smaDebug("vgId:%d, tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
}
tdSmaStatSetDropped(pItem);
@@ -654,19 +654,19 @@ static int32_t tdDropTSmaDataImpl(SSma *pSma, int64_t indexUid) {
int32_t refVal = INT32_MAX;
while (true) {
if ((refVal = T_REF_VAL_GET(SMA_ENV_STAT(pEnv))) <= 0) {
- smaDebug("vgId:%d drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
+ smaDebug("vgId:%d, drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
break;
}
- smaDebug("vgId:%d wait 1s to drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
+ smaDebug("vgId:%d, wait 1s to drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
taosSsleep(1);
if (++nSleep > SMA_DROP_EXPIRED_TIME) {
- smaDebug("vgId:%d drop index %" PRIi64 " after wait %d (refVal=%d)", SMA_VID(pSma), indexUid, nSleep, refVal);
+ smaDebug("vgId:%d, drop index %" PRIi64 " after wait %d (refVal=%d)", SMA_VID(pSma), indexUid, nSleep, refVal);
break;
};
}
tdFreeSmaStatItem(pItem);
- smaDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64 " in local cache", SMA_VID(pSma), indexUid);
+ smaDebug("vgId:%d, getTSmaDataImpl failed since no index %" PRIi64 " in local cache", SMA_VID(pSma), indexUid);
}
}
// clear sma data files
@@ -690,7 +690,7 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
if (!pEnv) {
terrno = TSDB_CODE_INVALID_PTR;
- smaWarn("vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL", SMA_VID(pSma));
+ smaWarn("vgId:%d, getTSmaDataImpl failed since pTSmaEnv is NULL", SMA_VID(pSma));
return TSDB_CODE_FAILED;
}
@@ -703,7 +703,7 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
// it's NULL.
tdUnRefSmaStat(pSma, pStat);
terrno = TSDB_CODE_TDB_INVALID_ACTION;
- smaDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64, SMA_VID(pSma), indexUid);
+ smaDebug("vgId:%d, getTSmaDataImpl failed since no index %" PRIi64, SMA_VID(pSma), indexUid);
return TSDB_CODE_FAILED;
}
@@ -722,17 +722,17 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
if (!tdSmaStatIsOK(pItem, &smaStat)) { // TODO: multiple check for large scale sma query
tdUnRefSmaStat(pSma, pStat);
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
- smaWarn("vgId:%d getTSmaDataImpl failed from index %" PRIi64 " since %s %" PRIi8, SMA_VID(pSma), indexUid,
+ smaWarn("vgId:%d, getTSmaDataImpl failed from index %" PRIi64 " since %s %" PRIi8, SMA_VID(pSma), indexUid,
tstrerror(terrno), smaStat);
return TSDB_CODE_FAILED;
}
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) {
// TODO: mark this window as expired.
- smaDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
+ smaDebug("vgId:%d, skey %" PRIi64 " of window exists in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
indexUid);
} else {
- smaDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
+ smaDebug("vgId:%d, skey %" PRIi64 " of window not in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
indexUid);
}
@@ -750,7 +750,7 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
smaDebug("### vgId:%d read from DBF %s days:%d, interval:%" PRIi64 ", storageLevel:%" PRIi8 " queryKey:%" PRIi64,
SMA_VID(pSma), tReadH.dFile.path, tReadH.days, tReadH.interval, tReadH.storageLevel, querySKey);
if (smaOpenDBF(pEnv->dbEnv, &tReadH.dFile) != 0) {
- smaWarn("vgId:%d open DBF %s failed since %s", SMA_VID(pSma), tReadH.dFile.path, tstrerror(terrno));
+ smaWarn("vgId:%d, open DBF %s failed since %s", SMA_VID(pSma), tReadH.dFile.path, tstrerror(terrno));
return TSDB_CODE_FAILED;
}
@@ -759,13 +759,13 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
int64_t queryGroupId = 0;
tdEncodeTSmaKey(queryGroupId, querySKey, (void **)&pSmaKey);
- smaDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", SMA_VID(pSma), tReadH.dFile.path,
+ smaDebug("vgId:%d, get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", SMA_VID(pSma), tReadH.dFile.path,
*(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN);
void *result = NULL;
int32_t valueSize = 0;
if (!(result = smaGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) {
- smaWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
+ smaWarn("vgId:%d, get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
SMA_VID(pSma), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
smaCloseDBF(&tReadH.dFile);
return TSDB_CODE_FAILED;
@@ -774,7 +774,7 @@ int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY query
#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
for (uint32_t v = 0; v < valueSize; v += 8) {
- smaWarn("vgId:%d get sma data v[%d]=%" PRIi64, SMA_VID(pSma), v, *(int64_t *)POINTER_SHIFT(result, v));
+ smaWarn("vgId:%d, get sma data v[%d]=%" PRIi64, SMA_VID(pSma), v, *(int64_t *)POINTER_SHIFT(result, v));
}
#endif
taosMemoryFreeClear(result); // TODO: fill the result to output
@@ -828,7 +828,7 @@ int32_t tdDropTSma(SSma *pSma, char *pMsg) {
// TODO: send msg to stream computing to drop tSma
// if ((send msg to stream computing) < 0) {
- // tdDestroyTSma(&vCreateSmaReq);
+ // tDestroyTSma(&vCreateSmaReq);
// return -1;
// }
//
@@ -888,7 +888,7 @@ static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t inde
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
taosHashCleanup(pItem->expiredWindows);
taosMemoryFree(pItem);
- smaWarn("vgId:%d set expire window, get tsma meta failed for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
+ smaWarn("vgId:%d, set expire window, get tsma meta failed for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
indexUid, tstrerror(terrno));
return TSDB_CODE_FAILED;
}
@@ -915,12 +915,12 @@ static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t inde
taosHashCleanup(pItem->expiredWindows);
taosMemoryFreeClear(pItem->pTSma);
taosHashRemove(pItemsHash, &indexUid, sizeof(indexUid));
- smaWarn("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window fail", SMA_VID(pSma), indexUid,
+ smaWarn("vgId:%d, smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window fail", SMA_VID(pSma), indexUid,
winSKey);
return TSDB_CODE_FAILED;
}
- smaDebug("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window succeed", SMA_VID(pSma), indexUid,
+ smaDebug("vgId:%d, smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window succeed", SMA_VID(pSma), indexUid,
winSKey);
return TSDB_CODE_SUCCESS;
}
@@ -935,18 +935,18 @@ static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t inde
int32_t tdUpdateExpiredWindowImpl(SSma *pSma, const SSubmitReq *pMsg, int64_t version) {
// no time-range-sma, just return success
if (atomic_load_16(&SMA_TSMA_NUM(pSma)) <= 0) {
- smaTrace("vgId:%d not update expire window since no tSma", SMA_VID(pSma));
+ smaTrace("vgId:%d, not update expire window since no tSma", SMA_VID(pSma));
return TSDB_CODE_SUCCESS;
}
if (!SMA_META(pSma)) {
terrno = TSDB_CODE_INVALID_PTR;
- smaError("vgId:%d update expire window failed since no meta ptr", SMA_VID(pSma));
+ smaError("vgId:%d, update expire window failed since no meta ptr", SMA_VID(pSma));
return TSDB_CODE_FAILED;
}
if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_TIME_RANGE) < 0) {
- smaError("vgId:%d init sma env failed since %s", SMA_VID(pSma), terrstr(terrno));
+ smaError("vgId:%d, init sma env failed since %s", SMA_VID(pSma), terrstr(terrno));
terrno = TSDB_CODE_TDB_INIT_FAILED;
return TSDB_CODE_FAILED;
}
@@ -982,25 +982,25 @@ int32_t tdUpdateExpiredWindowImpl(SSma *pSma, const SSubmitReq *pMsg, int64_t ve
SSubmitBlkIter blkIter = {0};
if (tInitSubmitBlkIter(&msgIter, pBlock, &blkIter) < 0) {
- pSW = tdFreeTSmaWrapper(pSW, false);
+ pSW = tFreeTSmaWrapper(pSW, false);
break;
}
while (true) {
STSRow *row = tGetSubmitBlkNext(&blkIter);
if (!row) {
- pSW = tdFreeTSmaWrapper(pSW, false);
+ pSW = tFreeTSmaWrapper(pSW, false);
break;
}
if (!pSW || (pTSma && (pTSma->tableUid != msgIter.suid))) {
if (pSW) {
- pSW = tdFreeTSmaWrapper(pSW, false);
+ pSW = tFreeTSmaWrapper(pSW, false);
}
if (!(pSW = metaGetSmaInfoByTable(SMA_META(pSma), msgIter.suid, false))) {
break;
}
if ((pSW->number) <= 0 || !pSW->tSma) {
- pSW = tdFreeTSmaWrapper(pSW, false);
+ pSW = tFreeTSmaWrapper(pSW, false);
break;
}
@@ -1020,12 +1020,12 @@ int32_t tdUpdateExpiredWindowImpl(SSma *pSma, const SSubmitReq *pMsg, int64_t ve
if (lastWinSKey != winSKey) {
lastWinSKey = winSKey;
if (tdSetExpiredWindow(pSma, pItemsHash, pTSma->indexUid, winSKey, version) < 0) {
- pSW = tdFreeTSmaWrapper(pSW, false);
+ pSW = tFreeTSmaWrapper(pSW, false);
tdUnRefSmaStat(pSma, pStat);
return TSDB_CODE_FAILED;
}
} else {
- smaDebug("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window ignore as duplicated",
+ smaDebug("vgId:%d, smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window ignore as duplicated",
SMA_VID(pSma), pTSma->indexUid, winSKey);
}
}
diff --git a/source/dnode/vnode/src/sma/smaTimeRange2.c b/source/dnode/vnode/src/sma/smaTimeRange2.c
new file mode 100644
index 0000000000000000000000000000000000000000..5ef171c7991c47494efa265274852c48e0bac6b7
--- /dev/null
+++ b/source/dnode/vnode/src/sma/smaTimeRange2.c
@@ -0,0 +1,1084 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#include "sma.h"
+#include "tsdb.h"
+
+typedef STsdbCfg STSmaKeepCfg;
+
+#undef _TEST_SMA_PRINT_DEBUG_LOG_
+#define SMA_STORAGE_MINUTES_MAX 86400
+#define SMA_STORAGE_MINUTES_DAY 1440
+#define SMA_STORAGE_MINUTES_MIN 1440
+#define SMA_STORAGE_TSDB_MINUTES 86400
+#define SMA_STORAGE_TSDB_TIMES 10
+#define SMA_STORAGE_SPLIT_FACTOR 14400 // least records in tsma file TODO: the feasible value?
+#define SMA_KEY_LEN 16 // TSKEY+groupId 8+8
+#define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds
+
+#define SMA_STATE_ITEM_HASH_SLOT 32
+
+typedef struct {
+ SSma *pSma;
+ SDBFile dFile;
+ const SArray *pDataBlocks; // sma data
+ int64_t interval; // interval with the precision of DB
+} STSmaWriteH;
+
+typedef struct {
+ int32_t iter;
+ int32_t fid;
+} SmaFsIter;
+
+typedef struct {
+ STsdb *pTsdb;
+ SSma *pSma;
+ SDBFile dFile;
+ int64_t interval; // interval with the precision of DB
+ int32_t blockSize; // size of SMA block item
+ int32_t days;
+ int8_t storageLevel;
+ SmaFsIter smaFsIter;
+} STSmaReadH;
+
+typedef enum {
+ SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
+ SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
+} ESmaStorageLevel;
+
+// static func
+
+static int64_t tdGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted);
+static int32_t tdGetSmaStorageLevel(STSmaKeepCfg *pCfg, int64_t interval);
+static int32_t tdInitTSmaWriteH(STSmaWriteH *pSmaH, SSma *pSma, const SArray *pDataBlocks, int64_t interval,
+ int8_t intervalUnit);
+static int32_t tdInitTSmaReadH(STSmaReadH *pSmaH, SSma *pSma, int64_t interval, int8_t intervalUnit);
+static void tdDestroyTSmaWriteH(STSmaWriteH *pSmaH);
+static int32_t tdGetTSmaDays(SSma *pSma, int64_t interval, int32_t storageLevel);
+static int32_t tdSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid);
+static int32_t tdInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey);
+static bool tdSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
+static int32_t tdInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyLen, void *pData, int32_t dataLen,
+ TXN *txn);
+// expired window
+
+static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey, int64_t version);
+static int32_t tdResetExpiredWindow(SSma *pSma, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
+static int32_t tdDropTSmaDataImpl(SSma *pSma, int64_t indexUid);
+
+/**
+ * @brief Judge the tsma file split days
+ *
+ * @param pCfg
+ * @param pCont
+ * @param contLen
+ * @param days unit is minute
+ * @return int32_t
+ */
+int32_t tdGetTSmaDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) {
+ SDecoder coder = {0};
+ tDecoderInit(&coder, pCont, contLen);
+
+ STSma tsma = {0};
+ if (tDecodeSVCreateTSmaReq(&coder, &tsma) < 0) {
+ terrno = TSDB_CODE_MSG_DECODE_ERROR;
+ goto _err;
+ }
+ STsdbCfg *pTsdbCfg = &pCfg->tsdbCfg;
+ int64_t mInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE);
+ int64_t records = pTsdbCfg->days / mInterval;
+
+ if (records >= SMA_STORAGE_SPLIT_FACTOR) {
+ *days = pTsdbCfg->days;
+ } else {
+ int64_t daysPerFile = mInterval * SMA_STORAGE_MINUTES_DAY * 2;
+
+ if (daysPerFile > SMA_STORAGE_MINUTES_MAX) {
+ *days = SMA_STORAGE_MINUTES_MAX;
+ } else {
+ *days = (int32_t)daysPerFile;
+ }
+
+ if(*days < pTsdbCfg->days) {
+ *days = pTsdbCfg->days;
+ }
+ }
+ tDecoderClear(&coder);
+ return 0;
+_err:
+ tDecoderClear(&coder);
+ return -1;
+}
+
+// read data
+
+// implementation
+
+/**
+ * @brief
+ *
+ * @param pSmaH
+ * @param pSma
+ * @param interval
+ * @param intervalUnit
+ * @return int32_t
+ */
+static int32_t tdInitTSmaReadH(STSmaReadH *pSmaH, SSma *pSma, int64_t interval, int8_t intervalUnit) {
+ STSmaKeepCfg *pCfg = SMA_TSDB_CFG(pSma);
+ pSmaH->pSma = pSma;
+ pSmaH->interval = tdGetIntervalByPrecision(interval, intervalUnit, SMA_TSDB_CFG(pSma)->precision, true);
+ pSmaH->storageLevel = tdGetSmaStorageLevel(pCfg, interval);
+ pSmaH->days = tdGetTSmaDays(pSma, pSmaH->interval, pSmaH->storageLevel);
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief Init of tSma FS
+ *
+ * @param pReadH
+ * @param indexUid
+ * @param skey
+ * @return int32_t
+ */
+static int32_t tdInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey) {
+ SSma *pSma = pSmaH->pSma;
+
+ int32_t fid = (int32_t)(TSDB_KEY_FID(skey, pSmaH->days, SMA_TSDB_CFG(pSma)->precision));
+ char tSmaFile[TSDB_FILENAME_LEN] = {0};
+ snprintf(tSmaFile, TSDB_FILENAME_LEN, "%" PRIi64 "%sv%df%d.tsma", indexUid, TD_DIRSEP, SMA_VID(pSma), fid);
+ pSmaH->dFile.path = strdup(tSmaFile);
+ pSmaH->smaFsIter.iter = 0;
+ pSmaH->smaFsIter.fid = fid;
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief Set and open tSma file if it has key locates in queryWin.
+ *
+ * @param pReadH
+ * @param param
+ * @param queryWin
+ * @return true
+ * @return false
+ */
+static bool tdSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
+ // SArray *smaFs = pReadH->pTsdb->fs->cstatus->sf;
+ // int32_t nSmaFs = taosArrayGetSize(smaFs);
+
+ smaCloseDBF(&pReadH->dFile);
+
+#if 0
+ while (pReadH->smaFsIter.iter < nSmaFs) {
+ void *pSmaFile = taosArrayGet(smaFs, pReadH->smaFsIter.iter);
+ if (pSmaFile) { // match(indexName, queryWindow)
+ // TODO: select the file by index_name ...
+ pReadH->dFile = pSmaFile;
+ ++pReadH->smaFsIter.iter;
+ break;
+ }
+ ++pReadH->smaFsIter.iter;
+ }
+
+ if (pReadH->pDFile) {
+ tdDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
+ return true;
+ }
+#endif
+
+ return false;
+}
+
+/**
+ * @brief Approximate value for week/month/year.
+ *
+ * @param interval
+ * @param intervalUnit
+ * @param precision
+ * @param adjusted Interval already adjusted according to DB precision
+ * @return int64_t
+ */
+static int64_t tdGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted) {
+ if (adjusted) {
+ return interval;
+ }
+
+ switch (intervalUnit) {
+ case TIME_UNIT_YEAR: // approximate value
+ interval *= 365 * 86400 * 1e3;
+ break;
+ case TIME_UNIT_MONTH: // approximate value
+ interval *= 30 * 86400 * 1e3;
+ break;
+ case TIME_UNIT_WEEK: // approximate value
+ interval *= 7 * 86400 * 1e3;
+ break;
+ case TIME_UNIT_DAY: // the interval for tSma calculation must <= day
+ interval *= 86400 * 1e3;
+ break;
+ case TIME_UNIT_HOUR:
+ interval *= 3600 * 1e3;
+ break;
+ case TIME_UNIT_MINUTE:
+ interval *= 60 * 1e3;
+ break;
+ case TIME_UNIT_SECOND:
+ interval *= 1e3;
+ break;
+ default:
+ break;
+ }
+
+ switch (precision) {
+ case TSDB_TIME_PRECISION_MILLI:
+ if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
+ return interval / 1e3;
+ } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
+ return interval / 1e6;
+ } else { // ms
+ return interval;
+ }
+ break;
+ case TSDB_TIME_PRECISION_MICRO:
+ if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
+ return interval;
+ } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
+ return interval / 1e3;
+ } else { // ms
+ return interval * 1e3;
+ }
+ break;
+ case TSDB_TIME_PRECISION_NANO:
+ if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
+ return interval * 1e3;
+ } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
+ return interval;
+ } else { // ms
+ return interval * 1e6;
+ }
+ break;
+ default: // ms
+ if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
+ return interval / 1e3;
+ } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
+ return interval / 1e6;
+ } else { // ms
+ return interval;
+ }
+ break;
+ }
+ return interval;
+}
+
+static int32_t tdInitTSmaWriteH(STSmaWriteH *pSmaH, SSma *pSma, const SArray *pDataBlocks, int64_t interval,
+ int8_t intervalUnit) {
+ pSmaH->pSma = pSma;
+ pSmaH->interval = tdGetIntervalByPrecision(interval, intervalUnit, SMA_TSDB_CFG(pSma)->precision, true);
+ pSmaH->pDataBlocks = pDataBlocks;
+ pSmaH->dFile.fid = SMA_IVLD_FID;
+ return TSDB_CODE_SUCCESS;
+}
+
+static void tdDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
+ if (pSmaH) {
+ smaCloseDBF(&pSmaH->dFile);
+ }
+}
+
+static int32_t tdSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
+ SSma *pSma = pSmaH->pSma;
+ ASSERT(!pSmaH->dFile.path && !pSmaH->dFile.pDB);
+
+ pSmaH->dFile.fid = fid;
+ char tSmaFile[TSDB_FILENAME_LEN] = {0};
+ snprintf(tSmaFile, TSDB_FILENAME_LEN, "%" PRIi64 "%sv%df%d.tsma", indexUid, TD_DIRSEP, SMA_VID(pSma), fid);
+ pSmaH->dFile.path = strdup(tSmaFile);
+
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief
+ *
+ * @param pSma
+ * @param interval Interval calculated by DB's precision
+ * @param storageLevel
+ * @return int32_t
+ */
+static int32_t tdGetTSmaDays(SSma *pSma, int64_t interval, int32_t storageLevel) {
+ STsdbCfg *pCfg = SMA_TSDB_CFG(pSma);
+ int32_t daysPerFile = pCfg->days; // unit is minute
+
+ if (storageLevel == SMA_STORAGE_LEVEL_TSDB) {
+ int32_t minutes = SMA_STORAGE_TSDB_TIMES * (interval / tsTickPerMin[pCfg->precision]);
+ if (minutes > SMA_STORAGE_TSDB_MINUTES) {
+ daysPerFile = SMA_STORAGE_TSDB_MINUTES;
+ }
+ }
+
+ return daysPerFile;
+}
+
+/**
+ * @brief Judge the tSma storage level
+ *
+ * @param pCfg
+ * @param interval
+ * @return int32_t
+ */
+static int32_t tdGetSmaStorageLevel(STSmaKeepCfg *pCfg, int64_t interval) {
+ int64_t mInterval = convertTimeFromPrecisionToUnit(interval, pCfg->precision, TIME_UNIT_MINUTE);
+ if (pCfg->days / mInterval >= SMA_STORAGE_SPLIT_FACTOR) {
+ return SMA_STORAGE_LEVEL_DFILESET;
+ }
+ return SMA_STORAGE_LEVEL_TSDB;
+}
+
+/**
+ * @brief Insert/Update Time-range-wise SMA data.
+ * - If interval < SMA_STORAGE_SPLIT_HOURS(e.g. 24), save the SMA data as a part of DFileSet to e.g.
+ * v3f1900.tsma.${sma_index_name}. The days is the same with that for TS data files.
+ * - If interval >= SMA_STORAGE_SPLIT_HOURS, save the SMA data to e.g. vnode3/tsma/v3f632.tsma.${sma_index_name}. The
+ * days is 30 times of the interval, and the minimum days is SMA_STORAGE_TSDB_DAYS(30d).
+ * - The destination file of one data block for some interval is determined by its start TS key.
+ *
+ * @param pSma
+ * @param msg
+ * @return int32_t
+ */
+int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
+ STsdbCfg *pCfg = SMA_TSDB_CFG(pSma);
+ const SArray *pDataBlocks = (const SArray *)msg;
+ int64_t testSkey = TSKEY_INITIAL_VAL;
+
+ // TODO: destroy SSDataBlocks(msg)
+
+ // For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
+ // the sma data would arrive ahead of the update-expired-window msg.
+ if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
+ terrno = TSDB_CODE_TDB_INIT_FAILED;
+ return TSDB_CODE_FAILED;
+ }
+
+ if (!pDataBlocks) {
+ terrno = TSDB_CODE_INVALID_PTR;
+ smaWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", SMA_VID(pSma));
+ return terrno;
+ }
+
+ if (taosArrayGetSize(pDataBlocks) <= 0) {
+ terrno = TSDB_CODE_INVALID_PARA;
+ smaWarn("vgId:%d insert tSma data failed since pDataBlocks is empty", SMA_VID(pSma));
+ return TSDB_CODE_FAILED;
+ }
+
+ SSmaEnv *pEnv = SMA_TSMA_ENV(pSma);
+ SSmaStat *pStat = SMA_ENV_STAT(pEnv);
+ SSmaStatItem *pItem = NULL;
+
+ tdRefSmaStat(pSma, pStat);
+
+ if (pStat && SMA_STAT_ITEMS(pStat)) {
+ pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
+ }
+
+ if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tdSmaStatIsDropped(pItem)) {
+ terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_FAILED;
+ }
+
+ STSma *pTSma = pItem->pTSma;
+ STSmaWriteH tSmaH = {0};
+
+ if (tdInitTSmaWriteH(&tSmaH, pSma, pDataBlocks, pTSma->interval, pTSma->intervalUnit) != 0) {
+ return TSDB_CODE_FAILED;
+ }
+
+ char rPath[TSDB_FILENAME_LEN] = {0};
+ char aPath[TSDB_FILENAME_LEN] = {0};
+ snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid);
+ tfsAbsoluteName(SMA_TFS(pSma), SMA_ENV_DID(pEnv), rPath, aPath);
+ if (!taosCheckExistFile(aPath)) {
+ if (tfsMkdirRecurAt(SMA_TFS(pSma), rPath, SMA_ENV_DID(pEnv)) != TSDB_CODE_SUCCESS) {
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_FAILED;
+ }
+ }
+
+ // Step 1: Judge the storage level and days
+ int32_t storageLevel = tdGetSmaStorageLevel(pCfg, tSmaH.interval);
+ int32_t minutePerFile = tdGetTSmaDays(pSma, tSmaH.interval, storageLevel);
+
+ char smaKey[SMA_KEY_LEN] = {0}; // key: skey + groupId
+ char dataBuf[512] = {0}; // val: aggr data // TODO: handle 512 buffer?
+ void *pDataBuf = NULL;
+ int32_t sz = taosArrayGetSize(pDataBlocks);
+ for (int32_t i = 0; i < sz; ++i) {
+ SSDataBlock *pDataBlock = taosArrayGet(pDataBlocks, i);
+ int32_t colNum = pDataBlock->info.numOfCols;
+ int32_t rows = pDataBlock->info.rows;
+ int32_t rowSize = pDataBlock->info.rowSize;
+ int64_t groupId = pDataBlock->info.groupId;
+ for (int32_t j = 0; j < rows; ++j) {
+ printf("|");
+ TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval
+ void *pSmaKey = &smaKey;
+ bool isStartKey = false;
+
+ int32_t tlen = 0; // reset the len
+ pDataBuf = &dataBuf; // reset the buf
+ for (int32_t k = 0; k < colNum; ++k) {
+ SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
+ void *var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
+ switch (pColInfoData->info.type) {
+ case TSDB_DATA_TYPE_TIMESTAMP:
+ if (!isStartKey) {
+ isStartKey = true;
+ skey = *(TSKEY *)var;
+ testSkey = skey;
+ printf("= skey %" PRIi64 " groupId = %" PRIi64 "|", skey, groupId);
+ tdEncodeTSmaKey(groupId, skey, &pSmaKey);
+ } else {
+ printf(" %" PRIi64 " |", *(int64_t *)var);
+ tlen += taosEncodeFixedI64(&pDataBuf, *(int64_t *)var);
+ break;
+ }
+ break;
+ case TSDB_DATA_TYPE_BOOL:
+ case TSDB_DATA_TYPE_UTINYINT:
+ printf(" %15d |", *(uint8_t *)var);
+ tlen += taosEncodeFixedU8(&pDataBuf, *(uint8_t *)var);
+ break;
+ case TSDB_DATA_TYPE_TINYINT:
+ printf(" %15d |", *(int8_t *)var);
+ tlen += taosEncodeFixedI8(&pDataBuf, *(int8_t *)var);
+ break;
+ case TSDB_DATA_TYPE_SMALLINT:
+ printf(" %15d |", *(int16_t *)var);
+ tlen += taosEncodeFixedI16(&pDataBuf, *(int16_t *)var);
+ break;
+ case TSDB_DATA_TYPE_USMALLINT:
+ printf(" %15d |", *(uint16_t *)var);
+ tlen += taosEncodeFixedU16(&pDataBuf, *(uint16_t *)var);
+ break;
+ case TSDB_DATA_TYPE_INT:
+ printf(" %15d |", *(int32_t *)var);
+ tlen += taosEncodeFixedI32(&pDataBuf, *(int32_t *)var);
+ break;
+ case TSDB_DATA_TYPE_FLOAT:
+ printf(" %15f |", *(float *)var);
+ tlen += taosEncodeBinary(&pDataBuf, var, sizeof(float));
+ break;
+ case TSDB_DATA_TYPE_UINT:
+ printf(" %15u |", *(uint32_t *)var);
+ tlen += taosEncodeFixedU32(&pDataBuf, *(uint32_t *)var);
+ break;
+ case TSDB_DATA_TYPE_BIGINT:
+ printf(" %15ld |", *(int64_t *)var);
+ tlen += taosEncodeFixedI64(&pDataBuf, *(int64_t *)var);
+ break;
+ case TSDB_DATA_TYPE_DOUBLE:
+ printf(" %15lf |", *(double *)var);
+ tlen += taosEncodeBinary(&pDataBuf, var, sizeof(double));
+ case TSDB_DATA_TYPE_UBIGINT:
+ printf(" %15lu |", *(uint64_t *)var);
+ tlen += taosEncodeFixedU64(&pDataBuf, *(uint64_t *)var);
+ break;
+ case TSDB_DATA_TYPE_NCHAR: {
+ char tmpChar[100] = {0};
+ strncpy(tmpChar, varDataVal(var), varDataLen(var));
+ printf(" %s |", tmpChar);
+ tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
+ break;
+ }
+ case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
+ char tmpChar[100] = {0};
+ strncpy(tmpChar, varDataVal(var), varDataLen(var));
+ printf(" %s |", tmpChar);
+ tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
+ break;
+ }
+ case TSDB_DATA_TYPE_VARBINARY:
+ // TODO: add binary/varbinary
+ TASSERT(0);
+ default:
+ printf("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
+ TASSERT(0);
+ break;
+ }
+ }
+ printf("\n");
+ // if ((tlen > 0) && (skey != TSKEY_INITIAL_VAL)) {
+ if (tlen > 0) {
+ int32_t fid = (int32_t)(TSDB_KEY_FID(skey, minutePerFile, pCfg->precision));
+
+ // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index
+ // file
+ // - Set and open the DFile or the B+Tree file
+ // TODO: tsdbStartTSmaCommit();
+ if (fid != tSmaH.dFile.fid) {
+ if (tSmaH.dFile.fid != SMA_IVLD_FID) {
+ tdSmaEndCommit(pEnv);
+ smaCloseDBF(&tSmaH.dFile);
+ }
+ tdSetTSmaDataFile(&tSmaH, indexUid, fid);
+ smaDebug("@@@ vgId:%d write to DBF %s, days:%d, interval:%" PRIi64 ", storageLevel:%" PRIi32
+ " queryKey:%" PRIi64,
+ SMA_VID(pSma), tSmaH.dFile.path, minutePerFile, tSmaH.interval, storageLevel, testSkey);
+ if (smaOpenDBF(pEnv->dbEnv, &tSmaH.dFile) != 0) {
+ smaWarn("vgId:%d open DB file %s failed since %s", SMA_VID(pSma),
+ tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno));
+ tdDestroyTSmaWriteH(&tSmaH);
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_FAILED;
+ }
+ tdSmaBeginCommit(pEnv);
+ }
+
+ if (tdInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, dataBuf, tlen, &pEnv->txn) != 0) {
+ smaWarn("vgId:%d insert tsma data blocks fail for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64
+ " since %s",
+ SMA_VID(pSma), indexUid, skey, groupId, tstrerror(terrno));
+ tdSmaEndCommit(pEnv);
+ tdDestroyTSmaWriteH(&tSmaH);
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_FAILED;
+ }
+
+ smaDebug("vgId:%d insert tsma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64,
+ SMA_VID(pSma), indexUid, skey, groupId);
+ // TODO:tsdbEndTSmaCommit();
+
+ // Step 3: reset the SSmaStat
+ tdResetExpiredWindow(pSma, pStat, indexUid, skey);
+ } else {
+ smaWarn("vgId:%d invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64,
+ SMA_VID(pSma), skey, tlen, indexUid);
+ }
+ }
+ }
+ tdSmaEndCommit(pEnv); // TODO: not commit for every insert
+ tdDestroyTSmaWriteH(&tSmaH);
+ tdUnRefSmaStat(pSma, pStat);
+
+ return TSDB_CODE_SUCCESS;
+}
+
+int32_t tdDropTSmaData(SSma *pSma, int64_t indexUid) {
+ int32_t code = TSDB_CODE_SUCCESS;
+ if ((code = tdDropTSmaDataImpl(pSma, indexUid)) < 0) {
+ smaWarn("vgId:%d drop tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
+ }
+ return code;
+}
+
+/**
+ * @brief Insert TSma data blocks to DB File build by B+Tree
+ *
+ * @param pSmaH
+ * @param smaKey tableUid-colId-skeyOfWindow(8-2-8)
+ * @param keyLen
+ * @param pData
+ * @param dataLen
+ * @return int32_t
+ */
+static int32_t tdInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyLen, void *pData, int32_t dataLen,
+ TXN *txn) {
+ SDBFile *pDBFile = &pSmaH->dFile;
+
+ // TODO: insert tsma data blocks into B+Tree(TTB)
+ if (smaSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen, txn) != 0) {
+ smaWarn("vgId:%d insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " fail",
+ SMA_VID(pSmaH->pSma), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
+ return TSDB_CODE_FAILED;
+ }
+ smaDebug("vgId:%d insert tsma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " succeed",
+ SMA_VID(pSmaH->pSma), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
+
+#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
+ uint32_t valueSize = 0;
+ void *data = tdGetSmaDataByKey(pDBFile, smaKey, keyLen, &valueSize);
+ ASSERT(data != NULL);
+ for (uint32_t v = 0; v < valueSize; v += 8) {
+ smaWarn("vgId:%d insert sma data val[%d] %" PRIi64, REPO_ID(pSmaH->pTsdb), v, *(int64_t *)POINTER_SHIFT(data, v));
+ }
+#endif
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief When sma data received from stream computing, make the relative expired window valid.
+ *
+ * @param pSma
+ * @param pStat
+ * @param indexUid
+ * @param skey
+ * @return int32_t
+ */
+static int32_t tdResetExpiredWindow(SSma *pSma, SSmaStat *pStat, int64_t indexUid, TSKEY skey) {
+ SSmaStatItem *pItem = NULL;
+
+ tdRefSmaStat(pSma, pStat);
+
+ if (pStat && SMA_STAT_ITEMS(pStat)) {
+ pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
+ }
+ if ((pItem) && ((pItem = *(SSmaStatItem **)pItem))) {
+ // pItem resides in hash buffer all the time unless drop sma index
+ // TODO: multithread protect
+ if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
+ // error handling
+ tdUnRefSmaStat(pSma, pStat);
+ smaWarn("vgId:%d remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " fail", SMA_VID(pSma), skey,
+ indexUid);
+ return TSDB_CODE_FAILED;
+ }
+ smaDebug("vgId:%d remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " succeed", SMA_VID(pSma),
+ skey, indexUid);
+ // TODO: use a standalone interface to received state upate notification from stream computing module.
+ /**
+ * @brief state
+ * - When SMA env init in TSDB, its status is TSDB_SMA_STAT_OK.
+ * - In startup phase of stream computing module, it should notify the SMA env in TSDB to expired if needed(e.g.
+ * when batch data caculation not finised)
+ * - When TSDB_SMA_STAT_OK, the stream computing module should also notify that to the SMA env in TSDB.
+ */
+ pItem->state = TSDB_SMA_STAT_OK;
+ } else {
+ // error handling
+ tdUnRefSmaStat(pSma, pStat);
+ smaWarn("vgId:%d expired window %" PRIi64 " not exists for sma index %" PRIi64, SMA_VID(pSma), skey, indexUid);
+ return TSDB_CODE_FAILED;
+ }
+
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief Drop tSma data and local cache
+ * - insert/query reference
+ * @param pSma
+ * @param msg
+ * @return int32_t
+ */
+static int32_t tdDropTSmaDataImpl(SSma *pSma, int64_t indexUid) {
+ SSmaEnv *pEnv = atomic_load_ptr(&SMA_TSMA_ENV(pSma));
+
+ // clear local cache
+ if (pEnv) {
+ smaDebug("vgId:%d drop tSma local cache for %" PRIi64, SMA_VID(pSma), indexUid);
+
+ SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
+ if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) {
+ if (tdSmaStatIsDropped(pItem)) {
+ smaDebug("vgId:%d tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
+ return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
+ }
+
+ tdWLockSmaEnv(pEnv);
+ if (tdSmaStatIsDropped(pItem)) {
+ tdUnLockSmaEnv(pEnv);
+ smaDebug("vgId:%d tSma stat is already dropped for %" PRIi64, SMA_VID(pSma), indexUid);
+ return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
+ }
+ tdSmaStatSetDropped(pItem);
+ tdUnLockSmaEnv(pEnv);
+
+ int32_t nSleep = 0;
+ int32_t refVal = INT32_MAX;
+ while (true) {
+ if ((refVal = T_REF_VAL_GET(SMA_ENV_STAT(pEnv))) <= 0) {
+ smaDebug("vgId:%d drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
+ break;
+ }
+ smaDebug("vgId:%d wait 1s to drop index %" PRIi64 " since refVal=%d", SMA_VID(pSma), indexUid, refVal);
+ taosSsleep(1);
+ if (++nSleep > SMA_DROP_EXPIRED_TIME) {
+ smaDebug("vgId:%d drop index %" PRIi64 " after wait %d (refVal=%d)", SMA_VID(pSma), indexUid, nSleep, refVal);
+ break;
+ };
+ }
+
+ tdFreeSmaStatItem(pItem);
+ smaDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64 " in local cache", SMA_VID(pSma), indexUid);
+ }
+ }
+ // clear sma data files
+ // TODO:
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief
+ *
+ * @param pSma Return the data between queryWin and fill the pData.
+ * @param pData
+ * @param indexUid
+ * @param pQuerySKey
+ * @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM.
+ * @return int32_t
+ */
+int32_t tdGetTSmaDataImpl(SSma *pSma, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
+ SSmaEnv *pEnv = atomic_load_ptr(&SMA_TSMA_ENV(pSma));
+ SSmaStat *pStat = NULL;
+
+ if (!pEnv) {
+ terrno = TSDB_CODE_INVALID_PTR;
+ smaWarn("vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL", SMA_VID(pSma));
+ return TSDB_CODE_FAILED;
+ }
+
+ pStat = SMA_ENV_STAT(pEnv);
+
+ tdRefSmaStat(pSma, pStat);
+ SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
+ if (!pItem || !(pItem = *(SSmaStatItem **)pItem)) {
+ // Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
+ // it's NULL.
+ tdUnRefSmaStat(pSma, pStat);
+ terrno = TSDB_CODE_TDB_INVALID_ACTION;
+ smaDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64, SMA_VID(pSma), indexUid);
+ return TSDB_CODE_FAILED;
+ }
+
+#if 0
+ int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
+ for (int32_t n = 0; n < nQueryWin; ++n) {
+ TSKEY skey = taosArrayGet(pQuerySKey, n);
+ if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY))) {
+ // TODO: mark this window as expired.
+ }
+ }
+#endif
+
+#if 1
+ int8_t smaStat = 0;
+ if (!tdSmaStatIsOK(pItem, &smaStat)) { // TODO: multiple check for large scale sma query
+ tdUnRefSmaStat(pSma, pStat);
+ terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
+ smaWarn("vgId:%d getTSmaDataImpl failed from index %" PRIi64 " since %s %" PRIi8, SMA_VID(pSma), indexUid,
+ tstrerror(terrno), smaStat);
+ return TSDB_CODE_FAILED;
+ }
+
+ if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) {
+ // TODO: mark this window as expired.
+ smaDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
+ indexUid);
+ } else {
+ smaDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, SMA_VID(pSma), querySKey,
+ indexUid);
+ }
+
+ STSma *pTSma = pItem->pTSma;
+#endif
+
+#if 1
+ STSmaReadH tReadH = {0};
+ tdInitTSmaReadH(&tReadH, pSma, pTSma->interval, pTSma->intervalUnit);
+ smaCloseDBF(&tReadH.dFile);
+
+ tdUnRefSmaStat(pSma, pStat);
+
+ tdInitTSmaFile(&tReadH, indexUid, querySKey);
+ smaDebug("### vgId:%d read from DBF %s days:%d, interval:%" PRIi64 ", storageLevel:%" PRIi8 " queryKey:%" PRIi64,
+ SMA_VID(pSma), tReadH.dFile.path, tReadH.days, tReadH.interval, tReadH.storageLevel, querySKey);
+ if (smaOpenDBF(pEnv->dbEnv, &tReadH.dFile) != 0) {
+ smaWarn("vgId:%d open DBF %s failed since %s", SMA_VID(pSma), tReadH.dFile.path, tstrerror(terrno));
+ return TSDB_CODE_FAILED;
+ }
+
+ char smaKey[SMA_KEY_LEN] = {0};
+ void *pSmaKey = &smaKey;
+ int64_t queryGroupId = 0;
+ tdEncodeTSmaKey(queryGroupId, querySKey, (void **)&pSmaKey);
+
+ smaDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", SMA_VID(pSma), tReadH.dFile.path,
+ *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN);
+
+ void *result = NULL;
+ int32_t valueSize = 0;
+ if (!(result = smaGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) {
+ smaWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
+ SMA_VID(pSma), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
+ smaCloseDBF(&tReadH.dFile);
+ return TSDB_CODE_FAILED;
+ }
+#endif
+
+#ifdef _TEST_SMA_PRINT_DEBUG_LOG_
+ for (uint32_t v = 0; v < valueSize; v += 8) {
+ smaWarn("vgId:%d get sma data v[%d]=%" PRIi64, SMA_VID(pSma), v, *(int64_t *)POINTER_SHIFT(result, v));
+ }
+#endif
+ taosMemoryFreeClear(result); // TODO: fill the result to output
+
+#if 0
+ int32_t nResult = 0;
+ int64_t lastKey = 0;
+
+ while (true) {
+ if (nResult >= nMaxResult) {
+ break;
+ }
+
+ // set and open the file according to the STSma param
+ if (tdSetAndOpenTSmaFile(&tReadH, queryWin)) {
+ char bTree[100] = "\0";
+ while (strncmp(bTree, "has more nodes", 100) == 0) {
+ if (nResult >= nMaxResult) {
+ break;
+ }
+ // tdGetDataFromBTree(bTree, queryWin, lastKey)
+ // fill the pData
+ ++nResult;
+ }
+ }
+ }
+#endif
+ // read data from file and fill the result
+ smaCloseDBF(&tReadH.dFile);
+ return TSDB_CODE_SUCCESS;
+}
+
+int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg) {
+ SSmaCfg *pCfg = (SSmaCfg *)pMsg;
+
+ if (metaCreateTSma(SMA_META(pSma), version, pCfg) < 0) {
+ return -1;
+ }
+
+ tdTSmaAdd(pSma, 1);
+ return 0;
+}
+
+int32_t tdDropTSma(SSma *pSma, char *pMsg) {
+#if 0
+ SVDropTSmaReq vDropSmaReq = {0};
+ if (!tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq)) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
+
+ // TODO: send msg to stream computing to drop tSma
+ // if ((send msg to stream computing) < 0) {
+ // tDestroyTSma(&vCreateSmaReq);
+ // return -1;
+ // }
+ //
+
+ if (metaDropTSma(SMA_META(pSma), vDropSmaReq.indexUid) < 0) {
+ // TODO: handle error
+ return -1;
+ }
+
+ if (tdDropTSmaData(pSma, vDropSmaReq.indexUid) < 0) {
+ // TODO: handle error
+ return -1;
+ }
+
+ tdTSmaSub(pSma, 1);
+#endif
+
+ // TODO: return directly or go on follow steps?
+ return TSDB_CODE_SUCCESS;
+}
+
+static SSmaStatItem *tdNewSmaStatItem(int8_t state) {
+ SSmaStatItem *pItem = NULL;
+
+ pItem = (SSmaStatItem *)taosMemoryCalloc(1, sizeof(SSmaStatItem));
+ if (!pItem) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ pItem->state = state;
+ pItem->expiredWindows = taosHashInit(SMA_STATE_ITEM_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP),
+ true, HASH_ENTRY_LOCK);
+ if (!pItem->expiredWindows) {
+ taosMemoryFreeClear(pItem);
+ return NULL;
+ }
+
+ return pItem;
+}
+
+static int32_t tdSetExpiredWindow(SSma *pSma, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
+ int64_t version) {
+ SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
+ if (!pItem) {
+ // TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
+ pItem = tdNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
+ if (!pItem) {
+ // Response to stream computing: OOM
+ // For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
+ return TSDB_CODE_FAILED;
+ }
+
+ // cache smaMeta
+ STSma *pTSma = metaGetSmaInfoByIndex(SMA_META(pSma), indexUid);
+ if (!pTSma) {
+ terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
+ taosHashCleanup(pItem->expiredWindows);
+ taosMemoryFree(pItem);
+ smaWarn("vgId:%d set expire window, get tsma meta failed for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
+ indexUid, tstrerror(terrno));
+ return TSDB_CODE_FAILED;
+ }
+ pItem->pTSma = pTSma;
+
+ if (taosHashPut(pItemsHash, &indexUid, sizeof(indexUid), &pItem, sizeof(pItem)) != 0) {
+ // If error occurs during put smaStatItem, free the resources of pItem
+ taosHashCleanup(pItem->expiredWindows);
+ taosMemoryFree(pItem);
+ return TSDB_CODE_FAILED;
+ }
+ } else if (!(pItem = *(SSmaStatItem **)pItem)) {
+ terrno = TSDB_CODE_INVALID_PTR;
+ return TSDB_CODE_FAILED;
+ }
+
+ if (taosHashPut(pItem->expiredWindows, &winSKey, sizeof(TSKEY), &version, sizeof(version)) != 0) {
+ // If error occurs during taosHashPut expired windows, remove the smaIndex from pSma->pSmaStat, thus TSDB would
+ // tell query module to query raw TS data.
+ // N.B.
+ // 1) It is assumed to be extemely little probability event of fail to taosHashPut.
+ // 2) This would solve the inconsistency to some extent, but not completely, unless we record all expired
+ // windows failed to put into hash table.
+ taosHashCleanup(pItem->expiredWindows);
+ taosMemoryFreeClear(pItem->pTSma);
+ taosHashRemove(pItemsHash, &indexUid, sizeof(indexUid));
+ smaWarn("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window fail", SMA_VID(pSma), indexUid,
+ winSKey);
+ return TSDB_CODE_FAILED;
+ }
+
+ smaDebug("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window succeed", SMA_VID(pSma), indexUid,
+ winSKey);
+ return TSDB_CODE_SUCCESS;
+}
+
+/**
+ * @brief Update expired window according to msg from stream computing module.
+ *
+ * @param pSma
+ * @param msg SSubmitReq
+ * @return int32_t
+ */
+int32_t tdUpdateExpiredWindowImpl(SSma *pSma, const SSubmitReq *pMsg, int64_t version) {
+ // no time-range-sma, just return success
+ if (atomic_load_16(&SMA_TSMA_NUM(pSma)) <= 0) {
+ smaTrace("vgId:%d not update expire window since no tSma", SMA_VID(pSma));
+ return TSDB_CODE_SUCCESS;
+ }
+
+ if (!SMA_META(pSma)) {
+ terrno = TSDB_CODE_INVALID_PTR;
+ smaError("vgId:%d update expire window failed since no meta ptr", SMA_VID(pSma));
+ return TSDB_CODE_FAILED;
+ }
+
+ if (tdCheckAndInitSmaEnv(pSma, TSDB_SMA_TYPE_TIME_RANGE) < 0) {
+ smaError("vgId:%d init sma env failed since %s", SMA_VID(pSma), terrstr(terrno));
+ terrno = TSDB_CODE_TDB_INIT_FAILED;
+ return TSDB_CODE_FAILED;
+ }
+
+ // Firstly, assume that tSma can only be created on super table/normal table.
+ // getActiveTimeWindow
+
+ SSmaEnv *pEnv = SMA_TSMA_ENV(pSma);
+ SSmaStat *pStat = SMA_ENV_STAT(pEnv);
+ SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
+
+ TASSERT(pEnv && pStat && pItemsHash);
+
+ // basic procedure
+ // TODO: optimization
+ tdRefSmaStat(pSma, pStat);
+
+ SSubmitMsgIter msgIter = {0};
+ SSubmitBlk *pBlock = NULL;
+ SInterval interval = {0};
+ TSKEY lastWinSKey = INT64_MIN;
+
+ if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) {
+ return TSDB_CODE_FAILED;
+ }
+
+ while (true) {
+ tGetSubmitMsgNext(&msgIter, &pBlock);
+ if (!pBlock) break;
+
+ STSmaWrapper *pSW = NULL;
+ STSma *pTSma = NULL;
+
+ SSubmitBlkIter blkIter = {0};
+ if (tInitSubmitBlkIter(&msgIter, pBlock, &blkIter) < 0) {
+ pSW = tFreeTSmaWrapper(pSW, false);
+ break;
+ }
+
+ while (true) {
+ STSRow *row = tGetSubmitBlkNext(&blkIter);
+ if (!row) {
+ pSW = tFreeTSmaWrapper(pSW, false);
+ break;
+ }
+ if (!pSW || (pTSma && (pTSma->tableUid != msgIter.suid))) {
+ if (pSW) {
+ pSW = tFreeTSmaWrapper(pSW, false);
+ }
+ if (!(pSW = metaGetSmaInfoByTable(SMA_META(pSma), msgIter.suid, false))) {
+ break;
+ }
+ if ((pSW->number) <= 0 || !pSW->tSma) {
+ pSW = tFreeTSmaWrapper(pSW, false);
+ break;
+ }
+
+ pTSma = pSW->tSma;
+
+ interval.interval = pTSma->interval;
+ interval.intervalUnit = pTSma->intervalUnit;
+ interval.offset = pTSma->offset;
+ interval.precision = SMA_TSDB_CFG(pSma)->precision;
+ interval.sliding = pTSma->sliding;
+ interval.slidingUnit = pTSma->slidingUnit;
+ }
+
+ // TODO: process multiple tsma for one table uid
+ TSKEY winSKey = taosTimeTruncate(TD_ROW_KEY(row), &interval, interval.precision);
+
+ if (lastWinSKey != winSKey) {
+ lastWinSKey = winSKey;
+ if (tdSetExpiredWindow(pSma, pItemsHash, pTSma->indexUid, winSKey, version) < 0) {
+ pSW = tFreeTSmaWrapper(pSW, false);
+ tdUnRefSmaStat(pSma, pStat);
+ return TSDB_CODE_FAILED;
+ }
+ } else {
+ smaDebug("vgId:%d smaIndex %" PRIi64 ", put skey %" PRIi64 " to expire window ignore as duplicated",
+ SMA_VID(pSma), pTSma->indexUid, winSKey);
+ }
+ }
+ }
+
+ tdUnRefSmaStat(pSma, pStat);
+
+ return TSDB_CODE_SUCCESS;
+}
\ No newline at end of file
diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c
index 26e9dfe2e2ceba9c854c51676d304428b1b86082..d94c3e387a09dd891825a6d6ed11b96a248d9605 100644
--- a/source/dnode/vnode/src/tq/tqPush.c
+++ b/source/dnode/vnode/src/tq/tqPush.c
@@ -20,6 +20,28 @@ void tqTmrRspFunc(void* param, void* tmrId) {
atomic_store_8(&pHandle->pushHandle.tmrStopped, 1);
}
+static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubmit** ppSubmit, SMqDataBlkRsp* pRsp) {
+ SStreamDataSubmit* pSubmit = *ppSubmit;
+ while (pSubmit != NULL) {
+ ASSERT(pSubmit->ver == pHandle->pushHandle.processedVer + 1);
+ if (tqDataExec(pTq, &pHandle->execHandle, pSubmit->data, pRsp, 0) < 0) {
+ /*ASSERT(0);*/
+ }
+ // update processed
+ atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
+ streamQSetSuccess(&pHandle->pushHandle.inputQ);
+ streamDataSubmitRefDec(pSubmit);
+ if (pRsp->blockNum > 0) {
+ *ppSubmit = pSubmit;
+ return 0;
+ } else {
+ pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
+ }
+ }
+ *ppSubmit = pSubmit;
+ return -1;
+}
+
int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
SMqDataBlkRsp rsp = {0};
// 1. guard and set status executing
@@ -42,38 +64,14 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
}
// 3. exec, after each success, update processed ver
// first run
- while (pSubmit != NULL) {
- ASSERT(pSubmit->ver == pHandle->pushHandle.processedVer + 1);
- if (tqDataExec(pTq, &pHandle->execHandle, pSubmit->data, &rsp, 0) < 0) {
- /*ASSERT(0);*/
- }
- // update processed
- atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
- streamQSetSuccess(&pHandle->pushHandle.inputQ);
- streamDataSubmitRefDec(pSubmit);
- if (rsp.blockNum > 0) {
- goto SEND_RSP;
- } else {
- pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
- }
+ if (tqLoopExecFromQueue(pTq, pHandle, &pSubmit, &rsp) == 0) {
+ goto SEND_RSP;
}
// set exec status closing
atomic_store_8(&pHandle->pushHandle.execStatus, TASK_STATUS__CLOSING);
// second run
- while (pSubmit != NULL) {
- ASSERT(pSubmit->ver == pHandle->pushHandle.processedVer + 1);
- if (tqDataExec(pTq, &pHandle->execHandle, pSubmit->data, &rsp, 0) < 0) {
- /*ASSERT(0);*/
- }
- // update processed
- atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
- streamQSetSuccess(&pHandle->pushHandle.inputQ);
- streamDataSubmitRefDec(pSubmit);
- if (rsp.blockNum > 0) {
- goto SEND_RSP;
- } else {
- pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
- }
+ if (tqLoopExecFromQueue(pTq, pHandle, &pSubmit, &rsp) == 0) {
+ goto SEND_RSP;
}
// set exec status idle
atomic_store_8(&pHandle->pushHandle.execStatus, TASK_STATUS__IDLE);
diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c
index 0a85cb46383f7183efeea2dd44a869933a27587c..86929fe6d5e51c7371e5ecd2dd3d4b45cfa89080 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCommit.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c
@@ -88,6 +88,18 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i
SDataCols *pTarget, TSKEY maxKey, int maxRows, int8_t update);
int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf);
+int tsdbBegin(STsdb *pTsdb) {
+ if (!pTsdb) return 0;
+
+ STsdbMemTable *pMem;
+
+ if (tsdbMemTableCreate(pTsdb, &pTsdb->mem) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) {
SDiskID did;
SDFileSet nSet = {0};
@@ -108,7 +120,7 @@ int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) {
tsdbInitDFileSet(pRepo, &nSet, did, pSet->fid, FS_TXN_VERSION(pfs));
if (tsdbCopyDFileSet(pSet, &nSet) < 0) {
- tsdbError("vgId:%d failed to copy FSET %d from level %d to level %d since %s", REPO_ID(pRepo), pSet->fid,
+ tsdbError("vgId:%d, failed to copy FSET %d from level %d to level %d since %s", REPO_ID(pRepo), pSet->fid,
TSDB_FSET_LEVEL(pSet), did.level, tstrerror(terrno));
return -1;
}
@@ -117,7 +129,7 @@ int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) {
return -1;
}
- tsdbInfo("vgId:%d FSET %d is copied from level %d disk id %d to level %d disk id %d", REPO_ID(pRepo), pSet->fid,
+ tsdbInfo("vgId:%d, FSET %d is copied from level %d disk id %d to level %d disk id %d", REPO_ID(pRepo), pSet->fid,
TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet), did.level, did.id);
} else {
// On a correct level
@@ -158,7 +170,7 @@ int tsdbCommit(STsdb *pRepo) {
tsdbSeekCommitIter(&commith, commith.rtn.minKey);
while ((pSet = tsdbFSIterNext(&(commith.fsIter)))) {
if (pSet->fid < commith.rtn.minFid) {
- tsdbInfo("vgId:%d FSET %d on level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid,
+ tsdbInfo("vgId:%d, FSET %d on level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid,
TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet));
} else {
break;
@@ -224,14 +236,14 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->days, pCfg->precision));
pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->days, pCfg->precision));
pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->days, pCfg->precision));
- tsdbDebug("vgId:%d now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey,
+ tsdbDebug("vgId:%d, now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey,
pRtn->minFid, pRtn->midFid, pRtn->maxFid);
}
static void tsdbStartCommit(STsdb *pRepo) {
STsdbMemTable *pMem = pRepo->imem;
- tsdbInfo("vgId:%d start to commit", REPO_ID(pRepo));
+ tsdbInfo("vgId:%d, start to commit", REPO_ID(pRepo));
tsdbStartFSTxn(pRepo, 0, 0);
}
@@ -240,7 +252,7 @@ static void tsdbEndCommit(STsdb *pTsdb, int eno) {
tsdbEndFSTxn(pTsdb);
tsdbMemTableDestroy(pTsdb->imem);
pTsdb->imem = NULL;
- tsdbInfo("vgId:%d commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed");
+ tsdbInfo("vgId:%d, commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed");
}
static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo) {
@@ -413,7 +425,7 @@ static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) {
if (tsdbWriteBlockIdx(TSDB_COMMIT_HEAD_FILE(pCommith), pCommith->aBlkIdx, (void **)(&(TSDB_COMMIT_BUF(pCommith)))) <
0) {
- tsdbError("vgId:%d failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
+ tsdbError("vgId:%d, failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
tsdbCloseCommitFile(pCommith, true);
// revert the file change
tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet);
@@ -421,7 +433,7 @@ static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) {
}
if (tsdbUpdateDFileSetHeader(&(pCommith->wSet)) < 0) {
- tsdbError("vgId:%d failed to update FSET %d header since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
+ tsdbError("vgId:%d, failed to update FSET %d header since %s", REPO_ID(pRepo), fid, tstrerror(terrno));
tsdbCloseCommitFile(pCommith, true);
// revert the file change
tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet);
@@ -531,7 +543,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
return -1;
}
- tsdbDebug("vgId:%d FSET %d at level %d disk id %d is opened to read to commit", REPO_ID(pRepo), TSDB_FSET_FID(pSet),
+ tsdbDebug("vgId:%d, FSET %d at level %d disk id %d is opened to read to commit", REPO_ID(pRepo), TSDB_FSET_FID(pSet),
TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet));
} else {
pCommith->isRFileSet = false;
@@ -543,7 +555,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
tsdbInitDFileSet(pRepo, pWSet, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)));
if (tsdbCreateDFileSet(pRepo, pWSet, true) < 0) {
- tsdbError("vgId:%d failed to create FSET %d at level %d disk id %d since %s", REPO_ID(pRepo),
+ tsdbError("vgId:%d, failed to create FSET %d at level %d disk id %d since %s", REPO_ID(pRepo),
TSDB_FSET_FID(pWSet), TSDB_FSET_LEVEL(pWSet), TSDB_FSET_ID(pWSet), tstrerror(terrno));
if (pCommith->isRFileSet) {
tsdbCloseAndUnsetFSet(&(pCommith->readh));
@@ -554,7 +566,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
pCommith->isDFileSame = false;
pCommith->isLFileSame = false;
- tsdbDebug("vgId:%d FSET %d at level %d disk id %d is created to commit", REPO_ID(pRepo), TSDB_FSET_FID(pWSet),
+ tsdbDebug("vgId:%d, FSET %d at level %d disk id %d is created to commit", REPO_ID(pRepo), TSDB_FSET_FID(pWSet),
TSDB_FSET_LEVEL(pWSet), TSDB_FSET_ID(pWSet));
} else {
did.level = TSDB_FSET_LEVEL(pSet);
@@ -567,7 +579,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
SDFile *pWHeadf = TSDB_COMMIT_HEAD_FILE(pCommith);
tsdbInitDFile(pRepo, pWHeadf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_HEAD);
if (tsdbCreateDFile(pRepo, pWHeadf, true, TSDB_FILE_HEAD) < 0) {
- tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWHeadf),
+ tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWHeadf),
tstrerror(terrno));
if (pCommith->isRFileSet) {
@@ -582,7 +594,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
tsdbInitDFileEx(pWDataf, pRDataf);
// if (tsdbOpenDFile(pWDataf, O_WRONLY) < 0) {
if (tsdbOpenDFile(pWDataf, TD_FILE_WRITE) < 0) {
- tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWDataf),
+ tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWDataf),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -603,7 +615,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
// if (tsdbOpenDFile(pWLastf, O_WRONLY) < 0) {
if (tsdbOpenDFile(pWLastf, TD_FILE_WRITE) < 0) {
- tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
+ tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -618,7 +630,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
pCommith->isLFileSame = false;
if (tsdbCreateDFile(pRepo, pWLastf, true, TSDB_FILE_LAST) < 0) {
- tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
+ tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -635,11 +647,11 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
SDFile *pWSmadF = TSDB_COMMIT_SMAD_FILE(pCommith);
if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmadF))) {
- tsdbDebug("vgId:%d create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmadF));
+ tsdbDebug("vgId:%d, create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmadF));
tsdbInitDFile(pRepo, pWSmadF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAD);
if (tsdbCreateDFile(pRepo, pWSmadF, true, TSDB_FILE_SMAD) < 0) {
- tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
+ tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -652,7 +664,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
} else {
tsdbInitDFileEx(pWSmadF, pRSmadF);
if (tsdbOpenDFile(pWSmadF, O_RDWR) < 0) {
- tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
+ tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -671,7 +683,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
if ((pCommith->isLFileSame) && taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmalF))) {
tsdbInitDFileEx(pWSmalF, pRSmalF);
if (tsdbOpenDFile(pWSmalF, O_RDWR) < 0) {
- tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
+ tsdbError("vgId:%d, failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -682,11 +694,11 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
}
}
} else {
- tsdbDebug("vgId:%d create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmalF));
+ tsdbDebug("vgId:%d, create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmalF));
tsdbInitDFile(pRepo, pWSmalF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAL);
if (tsdbCreateDFile(pRepo, pWSmalF, true, TSDB_FILE_SMAL) < 0) {
- tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
+ tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
@@ -887,7 +899,7 @@ static int tsdbCommitToTable(SCommitH *pCommith, int tid) {
}
if (tsdbWriteBlockInfo(pCommith) < 0) {
- tsdbError("vgId:%d failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
+ tsdbError("vgId:%d, failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno));
return -1;
}
@@ -929,7 +941,7 @@ static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx) {
}
if (tsdbMoveBlock(pCommith, bidx) < 0) {
- tsdbError("vgId:%d failed to move block into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
+ tsdbError("vgId:%d, failed to move block into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno));
taosMemoryFreeClear(pTSchema);
return -1;
@@ -939,7 +951,7 @@ static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx) {
}
if (tsdbWriteBlockInfo(pCommith) < 0) {
- tsdbError("vgId:%d failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
+ tsdbError("vgId:%d, failed to write SBlockInfo part into file %s since %s", TSDB_COMMIT_REPO_ID(pCommith),
TSDB_FILE_FULL_NAME(TSDB_COMMIT_HEAD_FILE(pCommith)), tstrerror(terrno));
taosMemoryFreeClear(pTSchema);
return -1;
@@ -1209,7 +1221,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
pBlock->blkVer = SBlockVerLatest;
pBlock->aggrOffset = (uint64_t)offsetAggr;
- tsdbDebug("vgId:%d uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64
+ tsdbDebug("vgId:%d, uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64
" numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64,
REPO_ID(pRepo), TABLE_UID(pTable), TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len,
pBlock->numOfCols, pBlock->keyFirst, pBlock->keyLast);
diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c
deleted file mode 100644
index 844cfc094b5650899373152ef7168f6ed4909129..0000000000000000000000000000000000000000
--- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#include "tsdb.h"
-
-int tsdbBegin(STsdb *pTsdb) {
- if (!pTsdb) return 0;
-
- STsdbMemTable *pMem;
-
- if (tsdbMemTableCreate(pTsdb, &pTsdb->mem) < 0) {
- return -1;
- }
-
- return 0;
-}
diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c
index 6dfd73158ea15b3f36b23158b0de54a7a904725c..c0ca2f9594e4f30038ad2ad6636c97263805de00 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFS.c
+++ b/source/dnode/vnode/src/tsdb/tsdbFS.c
@@ -260,7 +260,7 @@ int tsdbOpenFS(STsdb *pRepo) {
tsdbGetRtnSnap(pRepo, &pRepo->rtn);
if (taosCheckExistFile(current)) {
if (tsdbOpenFSFromCurrent(pRepo) < 0) {
- tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
@@ -271,19 +271,19 @@ int tsdbOpenFS(STsdb *pRepo) {
} else {
// should skip expired fileset inside of the function
if (tsdbRestoreCurrent(pRepo) < 0) {
- tsdbError("vgId:%d failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
}
if (tsdbScanAndTryFixFS(pRepo) < 0) {
- tsdbError("vgId:%d failed to scan and fix FS since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to scan and fix FS since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
// // Load meta cache if has meta file
// if ((!(pRepo->state & TSDB_STATE_BAD_META)) && tsdbLoadMetaCache(pRepo, true) < 0) {
- // tsdbError("vgId:%d failed to open FS while loading meta cache since %s", REPO_ID(pRepo), tstrerror(terrno));
+ // tsdbError("vgId:%d, failed to open FS while loading meta cache since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
@@ -607,7 +607,7 @@ static int tsdbOpenFSFromCurrent(STsdb *pRepo) {
// current file exists, try to recover
pFile = taosOpenFile(current, TD_FILE_READ);
if (pFile == NULL) {
- tsdbError("vgId:%d failed to open file %s since %s", REPO_ID(pRepo), current, strerror(errno));
+ tsdbError("vgId:%d, failed to open file %s since %s", REPO_ID(pRepo), current, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
@@ -618,20 +618,20 @@ static int tsdbOpenFSFromCurrent(STsdb *pRepo) {
int nread = (int)taosReadFile(pFile, buffer, TSDB_FILE_HEAD_SIZE);
if (nread < 0) {
- tsdbError("vgId:%d failed to read %d bytes from file %s since %s", REPO_ID(pRepo), TSDB_FILENAME_LEN, current,
+ tsdbError("vgId:%d, failed to read %d bytes from file %s since %s", REPO_ID(pRepo), TSDB_FILENAME_LEN, current,
strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (nread < TSDB_FILE_HEAD_SIZE) {
- tsdbError("vgId:%d failed to read header of file %s, read bytes:%d", REPO_ID(pRepo), current, nread);
+ tsdbError("vgId:%d, failed to read header of file %s, read bytes:%d", REPO_ID(pRepo), current, nread);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
goto _err;
}
if (!taosCheckChecksumWhole((uint8_t *)buffer, TSDB_FILE_HEAD_SIZE)) {
- tsdbError("vgId:%d header of file %s failed checksum check", REPO_ID(pRepo), current);
+ tsdbError("vgId:%d, header of file %s failed checksum check", REPO_ID(pRepo), current);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
goto _err;
}
@@ -652,19 +652,19 @@ static int tsdbOpenFSFromCurrent(STsdb *pRepo) {
nread = (int)taosReadFile(pFile, buffer, fsheader.len);
if (nread < 0) {
- tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), current, strerror(errno));
+ tsdbError("vgId:%d, failed to read file %s since %s", REPO_ID(pRepo), current, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (nread < fsheader.len) {
- tsdbError("vgId:%d failed to read %d bytes from file %s", REPO_ID(pRepo), fsheader.len, current);
+ tsdbError("vgId:%d, failed to read %d bytes from file %s", REPO_ID(pRepo), fsheader.len, current);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
goto _err;
}
if (!taosCheckChecksumWhole((uint8_t *)buffer, fsheader.len)) {
- tsdbError("vgId:%d file %s is corrupted since wrong checksum", REPO_ID(pRepo), current);
+ tsdbError("vgId:%d, file %s is corrupted since wrong checksum", REPO_ID(pRepo), current);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
goto _err;
}
@@ -694,7 +694,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
SFSStatus *pStatus = pfs->cstatus;
// if (tsdbScanAndTryFixMFile(pRepo) < 0) {
- // tsdbError("vgId:%d failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno));
+ // tsdbError("vgId:%d, failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
@@ -704,7 +704,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
SDFileSet *pSet = (SDFileSet *)taosArrayGet(pStatus->df, i);
if (tsdbScanAndTryFixDFileSet(pRepo, pSet) < 0) {
- tsdbError("vgId:%d failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to fix MFile since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
}
@@ -724,7 +724,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
tsdbGetRootDir(REPO_ID(pRepo), pRepo->dir, rootDir);
STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), rootDir);
if (tdir == NULL) {
- tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
+ tsdbError("vgId:%d, failed to open directory %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
return -1;
}
@@ -741,7 +741,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
// }
(void)tfsRemoveFile(pf);
- tsdbDebug("vgId:%d invalid file %s is removed", REPO_ID(pRepo), pf->aname);
+ tsdbDebug("vgId:%d, invalid file %s is removed", REPO_ID(pRepo), pf->aname);
}
tfsClosedir(tdir);
@@ -758,7 +758,7 @@ static int tsdbScanDataDir(STsdb *pRepo) {
tsdbGetDataDir(REPO_ID(pRepo), pRepo->dir, dataDir);
STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), dataDir);
if (tdir == NULL) {
- tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), dataDir, tstrerror(terrno));
+ tsdbError("vgId:%d, failed to open directory %s since %s", REPO_ID(pRepo), dataDir, tstrerror(terrno));
return -1;
}
@@ -767,7 +767,7 @@ static int tsdbScanDataDir(STsdb *pRepo) {
if (!tsdbIsTFileInFS(pfs, pf)) {
(void)tfsRemoveFile(pf);
- tsdbDebug("vgId:%d invalid file %s is removed", REPO_ID(pRepo), pf->aname);
+ tsdbDebug("vgId:%d, invalid file %s is removed", REPO_ID(pRepo), pf->aname);
}
}
@@ -811,7 +811,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
fArray = taosArrayInit(1024, sizeof(STfsFile));
if (fArray == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
- tsdbError("vgId:%d failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir,
+ tsdbError("vgId:%d, failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir,
tstrerror(terrno));
regfree(®ex);
return -1;
@@ -819,7 +819,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
tdir = tfsOpendir(REPO_TFS(pRepo), dataDir);
if (tdir == NULL) {
- tsdbError("vgId:%d failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir,
+ tsdbError("vgId:%d, failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir,
tstrerror(terrno));
taosArrayDestroy(fArray);
regfree(®ex);
@@ -840,12 +840,12 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
}
} else if (code == REG_NOMATCH) {
// Not match
- tsdbInfo("vgId:%d invalid file %s exists, remove it", REPO_ID(pRepo), pf->aname);
+ tsdbInfo("vgId:%d, invalid file %s exists, remove it", REPO_ID(pRepo), pf->aname);
(void)tfsRemoveFile(pf);
continue;
} else {
// Has other error
- tsdbError("vgId:%d failed to restore DFileSet Array while run regexec since %s", REPO_ID(pRepo), strerror(code));
+ tsdbError("vgId:%d, failed to restore DFileSet Array while run regexec since %s", REPO_ID(pRepo), strerror(code));
terrno = TAOS_SYSTEM_ERROR(code);
tfsClosedir(tdir);
taosArrayDestroy(fArray);
@@ -876,7 +876,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ftype);
if (index >= taosArrayGetSize(fArray)) {
- tsdbError("vgId:%d incomplete DFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
+ tsdbError("vgId:%d, incomplete DFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
taosArrayDestroy(fArray);
return -1;
}
@@ -902,14 +902,14 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
fset.fid = tfid;
} else {
if (tfid != fset.fid) {
- tsdbError("vgId:%d incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
+ tsdbError("vgId:%d, incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
taosArrayDestroy(fArray);
return -1;
}
}
if (ttype != ftype) {
- tsdbError("vgId:%d incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
+ tsdbError("vgId:%d, incomplete dFileSet, fid:%d", REPO_ID(pRepo), fset.fid);
taosArrayDestroy(fArray);
return -1;
}
@@ -918,14 +918,14 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
// if (tsdbOpenDFile(pDFile, O_RDONLY) < 0) {
if (tsdbOpenDFile(pDFile, TD_FILE_READ) < 0) {
- tsdbError("vgId:%d failed to open DFile %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
+ tsdbError("vgId:%d, failed to open DFile %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
tstrerror(terrno));
taosArrayDestroy(fArray);
return -1;
}
if (tsdbLoadDFileHeader(pDFile, &(pDFile->info)) < 0) {
- tsdbError("vgId:%d failed to load DFile %s header since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
+ tsdbError("vgId:%d, failed to load DFile %s header since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
tstrerror(terrno));
taosArrayDestroy(fArray);
return -1;
@@ -943,7 +943,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
if (pDFile->info.size != file_size) {
int64_t tfsize = pDFile->info.size;
pDFile->info.size = file_size;
- tsdbInfo("vgId:%d file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo),
+ tsdbInfo("vgId:%d, file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pDFile), tfsize, pDFile->info.size);
}
}
@@ -952,7 +952,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
index++;
}
- tsdbInfo("vgId:%d FSET %d is restored", REPO_ID(pRepo), fset.fid);
+ tsdbInfo("vgId:%d, FSET %d is restored", REPO_ID(pRepo), fset.fid);
taosArrayPush(pfs->cstatus->df, &fset);
}
@@ -965,18 +965,18 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
static int tsdbRestoreCurrent(STsdb *pRepo) {
// // Loop to recover mfile
// if (tsdbRestoreMeta(pRepo) < 0) {
- // tsdbError("vgId:%d failed to restore current since %s", REPO_ID(pRepo), tstrerror(terrno));
+ // tsdbError("vgId:%d, failed to restore current since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// Loop to recover dfile set
if (tsdbRestoreDFileSet(pRepo) < 0) {
- tsdbError("vgId:%d failed to restore DFileSet since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to restore DFileSet since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
if (tsdbSaveFSStatus(pRepo, pRepo->fs->cstatus) < 0) {
- tsdbError("vgId:%d failed to restore current since %s", REPO_ID(pRepo), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to restore current since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
@@ -1024,11 +1024,11 @@ static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired) {
if (fset.fid < pRepo->rtn.minFid) {
++*nExpired;
}
- tsdbDebug("vgId:%d scan DFileSet %d header", REPO_ID(pRepo), fset.fid);
+ tsdbDebug("vgId:%d, scan DFileSet %d header", REPO_ID(pRepo), fset.fid);
// if (tsdbOpenDFileSet(&fset, O_RDWR) < 0) {
if (tsdbOpenDFileSet(&fset, TD_FILE_WRITE | TD_FILE_READ) < 0) {
- tsdbError("vgId:%d failed to open DFileSet %d since %s, continue", REPO_ID(pRepo), fset.fid, tstrerror(terrno));
+ tsdbError("vgId:%d, failed to open DFileSet %d since %s, continue", REPO_ID(pRepo), fset.fid, tstrerror(terrno));
continue;
}
@@ -1038,14 +1038,14 @@ static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired) {
if ((tsdbLoadDFileHeader(pDFile, &info) < 0) || pDFile->info.size != info.size ||
pDFile->info.magic != info.magic) {
if (tsdbUpdateDFileHeader(pDFile) < 0) {
- tsdbError("vgId:%d failed to update DFile header of %s since %s, continue", REPO_ID(pRepo),
+ tsdbError("vgId:%d, failed to update DFile header of %s since %s, continue", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno));
} else {
- tsdbInfo("vgId:%d DFile header of %s is updated", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
+ tsdbInfo("vgId:%d, DFile header of %s is updated", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
TSDB_FILE_FSYNC(pDFile);
}
} else {
- tsdbDebug("vgId:%d DFile header of %s is correct", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
+ tsdbDebug("vgId:%d, DFile header of %s is correct", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
}
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c
index 04be2a48deb36ea343a55fa66a74a03ad79acce9..4198a94655835dcf6a33dfbf399767add97b6365 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFile.c
+++ b/source/dnode/vnode/src/tsdb/tsdbFile.c
@@ -181,7 +181,7 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
tsdbInitDFileEx(&df, pDFile);
if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pDFile))) {
- tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
+ tsdbError("vgId:%d, data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pDFile));
// pRepo->state |= TSDB_STATE_BAD_DATA;
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
@@ -211,17 +211,17 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
}
tsdbCloseDFile(&df);
- tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
+ tsdbInfo("vgId:%d, file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
file_size, pDFile->info.size);
} else if (pDFile->info.size > file_size) {
- tsdbError("vgId:%d data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
+ tsdbError("vgId:%d, data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), file_size, pDFile->info.size);
// pRepo->state |= TSDB_STATE_BAD_DATA;
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
return 0;
} else {
- tsdbDebug("vgId:%d file %s passes the scan", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
+ tsdbDebug("vgId:%d, file %s passes the scan", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile));
}
return 0;
diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c
index 94c88a14ffb31a6f80e4bd3ed9d6ab3207d2eb65..f4d4d9414201bac528b39d27a04a7315a331ea6d 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c
@@ -52,20 +52,21 @@ struct SMemTable {
SArray *pArray; // SArray
};
+#define SL_MAX_LEVEL 5
+
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
-#define SL_NODE_HALF_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
-#define SL_HEAD_FORWARD(sl, l) SL_NODE_FORWARD((sl)->pHead, l)
-#define SL_TAIL_BACKWARD(sl, l) SL_NODE_FORWARD((sl)->pTail, l)
-
static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, SMemData **ppMemData);
static int memDataPCmprFn(const void *p1, const void *p2);
static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow);
static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl);
+static void memDataMovePos(SMemData *pMemData, TSDBROW *pRow, int8_t isForward, SMemSkipListNode **pos);
+static int32_t memDataPutRow(SVBufPool *pPool, SMemData *pMemData, TSDBROW *pRow, int8_t isForward,
+ SMemSkipListNode **pos);
// SMemTable ==============================================
int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable) {
@@ -109,6 +110,7 @@ int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmit
TSDBROW row = {.version = version};
ASSERT(pMemTable);
+ ASSERT(pSubmitBlk->nData > 0);
{
// check if table exists (todo)
@@ -116,44 +118,35 @@ int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmit
code = tsdbGetOrCreateMemData(pMemTable, pSubmitBlk->suid, pSubmitBlk->uid, &pMemData);
if (code) {
- tsdbError("vgId:%d failed to create/get table data since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
+ tsdbError("vgId:%d, failed to create/get table data since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
goto _err;
}
// do insert
int32_t nt;
- uint8_t *pt;
int32_t n = 0;
uint8_t *p = pSubmitBlk->pData;
- SVBufPool *pPool = pTsdb->pVnode->inUse;
- int8_t level;
- SMemSkipListNode *pNode;
+ int32_t nRow = 0;
+ SMemSkipListNode *pos[SL_MAX_LEVEL] = {0};
+
+ for (int8_t iLevel = 0; iLevel < SL_MAX_LEVEL; iLevel++) {
+ pos[iLevel] = pMemData->sl.pTail;
+ }
while (n < pSubmitBlk->nData) {
nt = tGetTSRow(p + n, &row.tsRow);
n += nt;
ASSERT(n <= pSubmitBlk->nData);
- // build the node
- level = tsdbMemSkipListRandLevel(&pMemData->sl);
- pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + nt + sizeof(version));
- if (pNode == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
+ memDataMovePos(pMemData, &row, nRow ? 1 : 0, pos);
+ code = memDataPutRow(pTsdb->pVnode->inUse, pMemData, &row, nRow ? 1 : 0, pos);
+ if (code) {
goto _err;
}
- pNode->level = level;
- tPutTSDBRow((uint8_t *)SL_NODE_DATA(pNode), &row);
-
- // put the node (todo)
- // set info
- if (tsdbKeyCmprFn(&row, &pMemData->minKey) < 0) pMemData->minKey = *(TSDBKEY *)&row;
- if (tsdbKeyCmprFn(&row, &pMemData->maxKey) > 0) pMemData->maxKey = *(TSDBKEY *)&row;
+ nRow++;
}
- if (tsdbKeyCmprFn(&pMemTable->minKey, &pMemData->minKey) < 0) pMemTable->minKey = pMemData->minKey;
- if (tsdbKeyCmprFn(&pMemTable->maxKey, &pMemData->maxKey) > 0) pMemTable->maxKey = pMemData->maxKey;
-
return code;
_err:
@@ -199,13 +192,13 @@ int32_t tsdbDeleteTableData2(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_ui
// update the state of pMemTable, pMemData, last and lastrow (todo)
}
- tsdbDebug("vgId:%d delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64
+ tsdbDebug("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64
" since %s",
TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code));
return code;
_err:
- tsdbError("vgId:%d failed to delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64
+ tsdbError("vgId:%d, failed to delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64
" since %s",
TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code));
return code;
@@ -227,7 +220,7 @@ static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_ui
}
// create
- pMemData = vnodeBufPoolMalloc(pPool, sizeof(*pMemData) + SL_NODE_HALF_SIZE(maxLevel) * 2);
+ pMemData = vnodeBufPoolMalloc(pPool, sizeof(*pMemData) + SL_NODE_SIZE(maxLevel) * 2);
if (pMemData == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
@@ -242,11 +235,15 @@ static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_ui
pMemData->sl.maxLevel = maxLevel;
pMemData->sl.level = 0;
pMemData->sl.pHead = (SMemSkipListNode *)&pMemData[1];
- pMemData->sl.pTail = (SMemSkipListNode *)POINTER_SHIFT(pMemData->sl.pHead, SL_NODE_HALF_SIZE(maxLevel));
+ pMemData->sl.pTail = (SMemSkipListNode *)POINTER_SHIFT(pMemData->sl.pHead, SL_NODE_SIZE(maxLevel));
+ pMemData->sl.pHead->level = maxLevel;
+ pMemData->sl.pTail->level = maxLevel;
for (int8_t iLevel = 0; iLevel < pMemData->sl.maxLevel; iLevel++) {
- SL_HEAD_FORWARD(&pMemData->sl, iLevel) = pMemData->sl.pTail;
- SL_TAIL_BACKWARD(&pMemData->sl, iLevel) = pMemData->sl.pHead;
+ SL_NODE_FORWARD(pMemData->sl.pHead, iLevel) = pMemData->sl.pTail;
+ SL_NODE_BACKWARD(pMemData->sl.pHead, iLevel) = NULL;
+ SL_NODE_BACKWARD(pMemData->sl.pTail, iLevel) = pMemData->sl.pHead;
+ SL_NODE_FORWARD(pMemData->sl.pTail, iLevel) = NULL;
}
if (idx < 0) idx = 0;
@@ -313,264 +310,87 @@ static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
return level;
}
-#if 0 //====================================================================================
-
-#define SL_MAX_LEVEL 5
-
-struct SMemSkipListCurosr {
- SMemSkipList *pSl;
- SMemSkipListNode *pNodes[SL_MAX_LEVEL];
-};
-
-typedef struct {
- int64_t version;
- uint32_t szRow;
- const STSRow *pRow;
-} STsdbRow;
+static void memDataMovePos(SMemData *pMemData, TSDBROW *pRow, int8_t isForward, SMemSkipListNode **pos) {
+ TSDBKEY *pKey;
+ int c;
-#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
-
-#define SL_HEAD_NODE(sl) ((sl)->pHead)
-#define SL_TAIL_NODE(sl) ((SMemSkipListNode *)&SL_NODE_FORWARD(SL_HEAD_NODE(sl), (sl)->maxLevel))
-#define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l)
-#define SL_TAIL_NODE_BACKWARD(n, l) SL_NODE_FORWARD(n, l)
-
-static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl);
-static int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow);
-static int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow);
-static int32_t tsdbMemSkipListCursorCreate(int8_t maxLevel, SMemSkipListCurosr **ppSlc);
-static void tsdbMemSkipListCursorDestroy(SMemSkipListCurosr *pSlc);
-static void tsdbMemSkipListCursorInit(SMemSkipListCurosr *pSlc, SMemSkipList *pSl);
-static void tsdbMemSkipListCursorPut(SMemSkipListCurosr *pSlc, SMemSkipListNode *pNode);
-static int32_t tsdbMemSkipListCursorMoveTo(SMemSkipListCurosr *pSlc, int64_t version, TSKEY ts, int32_t flags);
-static void tsdbMemSkipListCursorMoveToFirst(SMemSkipListCurosr *pSlc);
-static void tsdbMemSkipListCursorMoveToLast(SMemSkipListCurosr *pSlc);
-static int32_t tsdbMemSkipListCursorMoveToNext(SMemSkipListCurosr *pSlc);
-static int32_t tsdbMemSkipListCursorMoveToPrev(SMemSkipListCurosr *pSlc);
-static SMemSkipListNode *tsdbMemSkipListNodeCreate(SVBufPool *pPool, SMemSkipList *pSl, const STsdbRow *pTRow);
-
-// SMemTable ========================
-int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *pSubmitBlk) {
- SMemData *pMemData;
- STsdb *pTsdb = pMemTb->pTsdb;
- SVnode *pVnode = pTsdb->pVnode;
- SVBufPool *pPool = pVnode->inUse;
- tb_uid_t suid = pSubmitBlk->suid;
- tb_uid_t uid = pSubmitBlk->uid;
- int32_t iBucket;
-
- // search SMemData by hash
- iBucket = HASH_BUCKET(suid, uid, pMemTb->nBucket);
- for (pMemData = pMemTb->pBuckets[iBucket]; pMemData; pMemData = pMemData->pHashNext) {
- if (pMemData->suid == suid && pMemData->uid == uid) break;
- }
-
- // create pMemData if need
- if (pMemData == NULL) {
- int8_t maxLevel = pVnode->config.tsdbCfg.slLevel;
- int32_t tsize = sizeof(*pMemData) + SL_NODE_HALF_SIZE(maxLevel) * 2;
- SMemSkipListNode *pHead, *pTail;
-
- pMemData = vnodeBufPoolMalloc(pPool, tsize);
- if (pMemData == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- pMemData->pHashNext = NULL;
- pMemData->suid = suid;
- pMemData->uid = uid;
- pMemData->minKey = TSKEY_MAX;
- pMemData->maxKey = TSKEY_MIN;
- pMemData->minVer = -1;
- pMemData->maxVer = -1;
- pMemData->nRows = 0;
- pMemData->sl.seed = taosRand();
- pMemData->sl.maxLevel = maxLevel;
- pMemData->sl.level = 0;
- pMemData->sl.size = 0;
- pHead = SL_HEAD_NODE(&pMemData->sl);
- pTail = SL_TAIL_NODE(&pMemData->sl);
- pHead->level = maxLevel;
- pTail->level = maxLevel;
- for (int iLevel = 0; iLevel < maxLevel; iLevel++) {
- SL_HEAD_NODE_FORWARD(pHead, iLevel) = pTail;
- SL_TAIL_NODE_BACKWARD(pTail, iLevel) = pHead;
- }
-
- // add to hash
- if (pMemTb->nHash >= pMemTb->nBucket) {
- // rehash (todo)
- }
- iBucket = HASH_BUCKET(suid, uid, pMemTb->nBucket);
- pMemData->pHashNext = pMemTb->pBuckets[iBucket];
- pMemTb->pBuckets[iBucket] = pMemData;
- pMemTb->nHash++;
-
- // sort organize (todo)
- }
-
- // do insert data to SMemData
- SMemSkipListNode *forwards[SL_MAX_LEVEL];
- SMemSkipListNode *pNode;
- int32_t iRow;
- STsdbRow tRow = {.version = version};
- SEncoder ec = {0};
- SDecoder dc = {0};
-
- tDecoderInit(&dc, pSubmitBlk->pData, pSubmitBlk->nData);
- tsdbMemSkipListCursorInit(pMemTb->pSlc, &pMemData->sl);
- for (iRow = 0;; iRow++) {
- if (tDecodeIsEnd(&dc)) break;
-
- // decode row
- if (tDecodeBinary(&dc, (uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- // move cursor
- tsdbMemSkipListCursorMoveTo(pMemTb->pSlc, version, tRow.pRow->ts, 0);
-
- // encode row
- pNode = tsdbMemSkipListNodeCreate(pPool, &pMemData->sl, &tRow);
- if (pNode == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
+ if (isForward) {
+ // TODO
+ } else {
+ SMemSkipListNode *px = pMemData->sl.pTail;
+
+ for (int8_t iLevel = pMemData->sl.maxLevel - 1; iLevel >= 0; iLevel--) {
+ if (iLevel < pMemData->sl.level) {
+ SMemSkipListNode *p = SL_NODE_BACKWARD(px, iLevel);
+
+ while (p != pMemData->sl.pHead) {
+ pKey = (TSDBKEY *)SL_NODE_DATA(p);
+
+ c = tsdbKeyCmprFn(pKey, pRow);
+ if (c <= 0) {
+ break;
+ } else {
+ px = p;
+ p = SL_NODE_BACKWARD(px, iLevel);
+ }
+ }
+
+ pos[iLevel] = px;
+ }
}
-
- // put the node
- tsdbMemSkipListCursorPut(pMemTb->pSlc, pNode);
-
- // update status
- if (tRow.pRow->ts < pMemData->minKey) pMemData->minKey = tRow.pRow->ts;
- if (tRow.pRow->ts > pMemData->maxKey) pMemData->maxKey = tRow.pRow->ts;
}
- tDecoderClear(&dc);
-
- // update status
- if (pMemData->minVer == -1) pMemData->minVer = version;
- if (pMemData->maxVer == -1 || pMemData->maxVer < version) pMemData->maxVer = version;
-
- if (pMemTb->minKey < pMemData->minKey) pMemTb->minKey = pMemData->minKey;
- if (pMemTb->maxKey < pMemData->maxKey) pMemTb->maxKey = pMemData->maxKey;
- if (pMemTb->minVer == -1) pMemTb->minVer = version;
- if (pMemTb->maxVer == -1 || pMemTb->maxVer < version) pMemTb->maxVer = version;
-
- return 0;
}
-static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow) {
- if (tEncodeI64(pEncoder, pRow->version) < 0) return -1;
- if (tEncodeBinary(pEncoder, (const uint8_t *)pRow->pRow, pRow->szRow) < 0) return -1;
- return 0;
-}
+static void memMovePosFrom(SMemData *pMemData, SMemSkipListNode *pNode, TSDBROW *pRow, int8_t isForward,
+ SMemSkipListNode **pos) {
+ SMemSkipListNode *px = pNode;
+ TSDBKEY *pKey;
+ SMemSkipListNode *p;
+ int c;
-static FORCE_INLINE int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow) {
- if (tDecodeI64(pDecoder, &pRow->version) < 0) return -1;
- if (tDecodeBinary(pDecoder, (uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
- return 0;
-}
-
-static int32_t tsdbMemSkipListCursorCreate(int8_t maxLevel, SMemSkipListCurosr **ppSlc) {
- *ppSlc = (SMemSkipListCurosr *)taosMemoryCalloc(1, sizeof(**ppSlc) + sizeof(SMemSkipListNode *) * maxLevel);
- if (*ppSlc == NULL) {
- return -1;
- }
- return 0;
-}
-
-static void tsdbMemSkipListCursorDestroy(SMemSkipListCurosr *pSlc) { taosMemoryFree(pSlc); }
-
-static void tsdbMemSkipListCursorInit(SMemSkipListCurosr *pSlc, SMemSkipList *pSl) {
- SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
- pSlc->pSl = pSl;
- // for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
- // pSlc->forwards[iLevel] = pHead;
- // }
-}
-
-static void tsdbMemSkipListCursorPut(SMemSkipListCurosr *pSlc, SMemSkipListNode *pNode) {
- SMemSkipList *pSl = pSlc->pSl;
- SMemSkipListNode *pNodeNext;
-
- for (int8_t iLevel = 0; iLevel < pNode->level; iLevel++) {
- // todo
-
- ASSERT(0);
- }
-
- if (pSl->level < pNode->level) {
- pSl->level = pNode->level;
- }
-
- pSl->size += 1;
-}
-
-static int32_t tsdbMemSkipListCursorMoveTo(SMemSkipListCurosr *pSlc, int64_t version, TSKEY ts, int32_t flags) {
- SMemSkipListNode **pForwards = NULL;
- SMemSkipList *pSl = pSlc->pSl;
- int8_t maxLevel = pSl->maxLevel;
- SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
- SMemSkipListNode *pTail = SL_TAIL_NODE(pSl);
-
- if (pSl->size == 0) {
- for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
- pForwards[iLevel] = pHead;
+ if (isForward) {
+ } else {
+ ASSERT(pNode != pMemData->sl.pHead);
+
+ for (int8_t iLevel = pMemData->sl.maxLevel - 1; iLevel >= 0; iLevel--) {
+ p = SL_NODE_BACKWARD(px, iLevel);
+ while (p != pMemData->sl.pHead) {
+ pKey = (TSDBKEY *)SL_NODE_DATA(p);
+
+ c = tsdbKeyCmprFn(pKey, pRow);
+ if (c <= 0) {
+ break;
+ } else {
+ px = p;
+ p = SL_NODE_BACKWARD(px, iLevel);
+ }
+ }
+
+ pos[iLevel] = px;
}
}
-
- return 0;
-}
-
-static void tsdbMemSkipListCursorMoveToFirst(SMemSkipListCurosr *pSlc) {
- SMemSkipList *pSl = pSlc->pSl;
- SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
-
- for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
- pSlc->pNodes[iLevel] = pHead;
- }
-
- tsdbMemSkipListCursorMoveToNext(pSlc);
}
-static void tsdbMemSkipListCursorMoveToLast(SMemSkipListCurosr *pSlc) {
- SMemSkipList *pSl = pSlc->pSl;
- SMemSkipListNode *pTail = SL_TAIL_NODE(pSl);
+static int32_t memDataPutRow(SVBufPool *pPool, SMemData *pMemData, TSDBROW *pRow, int8_t isForward,
+ SMemSkipListNode **pos) {
+ int32_t code = 0;
+ int8_t level;
+ SMemSkipListNode *pNode;
- for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
- pSlc->pNodes[iLevel] = pTail;
+ level = tsdbMemSkipListRandLevel(&pMemData->sl);
+ pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + tPutTSDBRow(NULL, pRow));
+ if (pNode == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
}
- tsdbMemSkipListCursorMoveToPrev(pSlc);
-}
-
-static int32_t tsdbMemSkipListCursorMoveToNext(SMemSkipListCurosr *pSlc) {
- // TODO
- return 0;
-}
-
-static int32_t tsdbMemSkipListCursorMoveToPrev(SMemSkipListCurosr *pSlc) {
- // TODO
- return 0;
-}
-
-static SMemSkipListNode *tsdbMemSkipListNodeCreate(SVBufPool *pPool, SMemSkipList *pSl, const STsdbRow *pTRow) {
- int32_t tsize;
- int32_t ret;
- int8_t level = tsdbMemSkipListRandLevel(pSl);
- SMemSkipListNode *pNode = NULL;
- SEncoder ec = {0};
-
- tEncodeSize(tsdbEncodeRow, pTRow, tsize, ret);
- pNode = vnodeBufPoolMalloc(pPool, tsize + SL_NODE_SIZE(level));
- if (pNode) {
- pNode->level = level;
- tEncoderInit(&ec, (uint8_t *)SL_NODE_DATA(pNode), tsize);
- tsdbEncodeRow(&ec, pTRow);
- tEncoderClear(&ec);
+ // do the read put
+ if (isForward) {
+ // TODO
+ } else {
+ // TODO
}
- return pNode;
-}
-#endif
\ No newline at end of file
+_exit:
+ return code;
+}
\ No newline at end of file
diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c
index fa54c811ffc158339fda4b34cad47ba7c4f2fdac..943263e1a3c65ebf980b353e6a1b69ba52868a22 100644
--- a/source/dnode/vnode/src/tsdb/tsdbOpen.c
+++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c
@@ -74,7 +74,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
goto _err;
}
- tsdbDebug("vgId:%d tsdb is opened for %s, days:%d, keep:%d,%d,%d", TD_VID(pVnode), pTsdb->path, pTsdb->keepCfg.days,
+ tsdbDebug("vgId:%d, tsdb is opened for %s, days:%d, keep:%d,%d,%d", TD_VID(pVnode), pTsdb->path, pTsdb->keepCfg.days,
pTsdb->keepCfg.keep0, pTsdb->keepCfg.keep1, pTsdb->keepCfg.keep2);
*ppTsdb = pTsdb;
@@ -99,7 +99,7 @@ int tsdbClose(STsdb **pTsdb) {
int tsdbLockRepo(STsdb *pTsdb) {
int code = taosThreadMutexLock(&pTsdb->mutex);
if (code != 0) {
- tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
+ tsdbError("vgId:%d, failed to lock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
@@ -112,7 +112,7 @@ int tsdbUnlockRepo(STsdb *pTsdb) {
pTsdb->repoLocked = false;
int code = taosThreadMutexUnlock(&pTsdb->mutex);
if (code != 0) {
- tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
+ tsdbError("vgId:%d, failed to unlock tsdb since %s", REPO_ID(pTsdb), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c
index 61daa0c9b345837a3406ea7d2947faf61d72fe06..5f2ea80078fa676ab29752ec33dd07883e3e7802 100644
--- a/source/dnode/vnode/src/tsdb/tsdbRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbRead.c
@@ -352,15 +352,15 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle,
}
if (level == TSDB_RETENTION_L0) {
- tsdbDebug("vgId:%d read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
+ tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
TSDB_RETENTION_L0);
return VND_RSMA0(pVnode);
} else if (level == TSDB_RETENTION_L1) {
- tsdbDebug("vgId:%d read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
+ tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
TSDB_RETENTION_L1);
return VND_RSMA1(pVnode);
} else {
- tsdbDebug("vgId:%d read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
+ tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query", TD_VID(pVnode), pReadHandle,
TSDB_RETENTION_L2);
return VND_RSMA2(pVnode);
}
@@ -3555,7 +3555,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDat
return TSDB_CODE_SUCCESS;
}
- tsdbDebug("vgId:%d succeed to load block statis part for uid %" PRIu64, REPO_ID(pHandle->pTsdb),
+ tsdbDebug("vgId:%d, succeed to load block statis part for uid %" PRIu64, REPO_ID(pHandle->pTsdb),
TSDB_READ_TABLE_UID(&pHandle->rhelper));
int16_t* colIds = pHandle->suppInfo.defaultLoadColumn->pData;
diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c
index d51521c41c954821163d17a1eddf4a4ddee7f5ad..a6f2ff139437a45edbc9c42e41d1f1de16555d97 100644
--- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c
+++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c
@@ -87,7 +87,7 @@ int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet) {
TSDB_FSET_SET_CLOSED(TSDB_READ_FSET(pReadh));
// if (tsdbOpenDFileSet(TSDB_READ_FSET(pReadh), O_RDONLY) < 0) {
if (tsdbOpenDFileSet(TSDB_READ_FSET(pReadh), TD_FILE_READ) < 0) {
- tsdbError("vgId:%d failed to open file set %d since %s", TSDB_READ_REPO_ID(pReadh), TSDB_FSET_FID(pSet),
+ tsdbError("vgId:%d, failed to open file set %d since %s", TSDB_READ_REPO_ID(pReadh), TSDB_FSET_FID(pSet),
tstrerror(terrno));
return -1;
}
@@ -107,7 +107,7 @@ int tsdbLoadBlockIdx(SReadH *pReadh) {
if (pHeadf->info.offset <= 0) return 0;
if (tsdbSeekDFile(pHeadf, pHeadf->info.offset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load SBlockIdx part while seek file %s since %s, offset:%u len :%u",
+ tsdbError("vgId:%d, failed to load SBlockIdx part while seek file %s since %s, offset:%u len :%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pHeadf->info.offset,
pHeadf->info.len);
return -1;
@@ -117,7 +117,7 @@ int tsdbLoadBlockIdx(SReadH *pReadh) {
int64_t nread = tsdbReadDFile(pHeadf, TSDB_READ_BUF(pReadh), pHeadf->info.len);
if (nread < 0) {
- tsdbError("vgId:%d failed to load SBlockIdx part while read file %s since %s, offset:%u len :%u",
+ tsdbError("vgId:%d, failed to load SBlockIdx part while read file %s since %s, offset:%u len :%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pHeadf->info.offset,
pHeadf->info.len);
return -1;
@@ -125,14 +125,14 @@ int tsdbLoadBlockIdx(SReadH *pReadh) {
if (nread < pHeadf->info.len) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d SBlockIdx part in file %s is corrupted, offset:%u expected bytes:%u read bytes: %" PRId64,
+ tsdbError("vgId:%d, SBlockIdx part in file %s is corrupted, offset:%u expected bytes:%u read bytes: %" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pHeadf->info.offset, pHeadf->info.len, nread);
return -1;
}
if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), pHeadf->info.len)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d SBlockIdx part in file %s is corrupted since wrong checksum, offset:%u len :%u",
+ tsdbError("vgId:%d, SBlockIdx part in file %s is corrupted since wrong checksum, offset:%u len :%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pHeadf->info.offset, pHeadf->info.len);
return -1;
}
@@ -209,7 +209,7 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) {
SBlockIdx *pBlkIdx = pReadh->pBlkIdx;
if (tsdbSeekDFile(pHeadf, pBlkIdx->offset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load SBlockInfo part while seek file %s since %s, offset:%u len:%u",
+ tsdbError("vgId:%d, failed to load SBlockInfo part while seek file %s since %s, offset:%u len:%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pBlkIdx->offset, pBlkIdx->len);
return -1;
}
@@ -218,21 +218,21 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) {
int64_t nread = tsdbReadDFile(pHeadf, (void *)(pReadh->pBlkInfo), pBlkIdx->len);
if (nread < 0) {
- tsdbError("vgId:%d failed to load SBlockInfo part while read file %s since %s, offset:%u len :%u",
+ tsdbError("vgId:%d, failed to load SBlockInfo part while read file %s since %s, offset:%u len :%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), tstrerror(terrno), pBlkIdx->offset, pBlkIdx->len);
return -1;
}
if (nread < pBlkIdx->len) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d SBlockInfo part in file %s is corrupted, offset:%u expected bytes:%u read bytes:%" PRId64,
+ tsdbError("vgId:%d, SBlockInfo part in file %s is corrupted, offset:%u expected bytes:%u read bytes:%" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pBlkIdx->offset, pBlkIdx->len, nread);
return -1;
}
if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pBlkInfo), pBlkIdx->len)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d SBlockInfo part in file %s is corrupted since wrong checksum, offset:%u len :%u",
+ tsdbError("vgId:%d, SBlockInfo part in file %s is corrupted since wrong checksum, offset:%u len :%u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pHeadf), pBlkIdx->offset, pBlkIdx->len);
return -1;
}
@@ -467,7 +467,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
ASSERT(pBlock->numOfSubBlocks <= 1);
if (!pBlock->aggrStat) {
- tsdbDebug("vgId:%d no need to load block statis part for uid %" PRIu64 " since not exist", REPO_ID(pReadh->pRepo),
+ tsdbDebug("vgId:%d, no need to load block statis part for uid %" PRIu64 " since not exist", REPO_ID(pReadh->pRepo),
TSDB_READ_TABLE_UID(pReadh));
return TSDB_STATIS_NONE;
}
@@ -475,7 +475,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
SDFile *pDFileAggr = pBlock->last ? TSDB_READ_SMAL_FILE(pReadh) : TSDB_READ_SMAD_FILE(pReadh);
if (tsdbSeekDFile(pDFileAggr, pBlock->aggrOffset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load block statis part for uid %" PRIu64 " while seek file %s to offset %" PRIu64
+ tsdbError("vgId:%d, failed to load block statis part for uid %" PRIu64 " while seek file %s to offset %" PRIu64
" since %s",
TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr),
(uint64_t)pBlock->aggrOffset, tstrerror(terrno));
@@ -487,7 +487,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr);
if (nreadAggr < 0) {
- tsdbError("vgId:%d failed to load block statis part for uid %" PRIu64
+ tsdbError("vgId:%d, failed to load block statis part for uid %" PRIu64
" while read file %s since %s, offset:%" PRIu64 " len :%" PRIzu,
TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr),
tstrerror(terrno), (uint64_t)pBlock->aggrOffset, sizeAggr);
@@ -496,7 +496,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
if (nreadAggr < sizeAggr) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block statis part for uid %" PRIu64 " in file %s is corrupted, offset:%" PRIu64
+ tsdbError("vgId:%d, block statis part for uid %" PRIu64 " in file %s is corrupted, offset:%" PRIu64
" expected bytes:%" PRIzu " read bytes: %" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr),
(uint64_t)pBlock->aggrOffset, sizeAggr, nreadAggr);
@@ -505,7 +505,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pAggrBlkData), (uint32_t)sizeAggr)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block statis part for uid %" PRIu64
+ tsdbError("vgId:%d, block statis part for uid %" PRIu64
"in file %s is corrupted since wrong checksum, offset:%" PRIu64 " len :%" PRIzu,
TSDB_READ_REPO_ID(pReadh), TSDB_READ_TABLE_UID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr),
(uint64_t)pBlock->aggrOffset, sizeAggr);
@@ -518,7 +518,7 @@ static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) {
ASSERT(pBlock->numOfSubBlocks <= 1);
SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh);
if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load block head part while seek file %s to offset %" PRId64 " since %s",
+ tsdbError("vgId:%d, failed to load block head part while seek file %s to offset %" PRId64 " since %s",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno));
return -1;
}
@@ -528,14 +528,14 @@ static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) {
int64_t nread = tsdbReadDFile(pDFile, (void *)(pReadh->pBlkData), size);
if (nread < 0) {
- tsdbError("vgId:%d failed to load block head part while read file %s since %s, offset:%" PRId64 " len :%" PRIzu,
+ tsdbError("vgId:%d, failed to load block head part while read file %s since %s, offset:%" PRId64 " len :%" PRIzu,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), (int64_t)pBlock->offset, size);
return -1;
}
if (nread < size) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block head part in file %s is corrupted, offset:%" PRId64 " expected bytes:%" PRIzu
+ tsdbError("vgId:%d, block head part in file %s is corrupted, offset:%" PRId64 " expected bytes:%" PRIzu
" read bytes: %" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size, nread);
return -1;
@@ -543,7 +543,7 @@ static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) {
if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pBlkData), (uint32_t)size)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%" PRIzu,
+ tsdbError("vgId:%d, block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%" PRIzu,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size);
return -1;
}
@@ -671,14 +671,14 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
SBlockData *pBlockData = (SBlockData *)TSDB_READ_BUF(pReadh);
if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load block data part while seek file %s to offset %" PRId64 " since %s",
+ tsdbError("vgId:%d, failed to load block data part while seek file %s to offset %" PRId64 " since %s",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno));
return -1;
}
int64_t nread = tsdbReadDFile(pDFile, TSDB_READ_BUF(pReadh), pBlock->len);
if (nread < 0) {
- tsdbError("vgId:%d failed to load block data part while read file %s since %s, offset:%" PRId64 " len :%d",
+ tsdbError("vgId:%d, failed to load block data part while read file %s since %s, offset:%" PRId64 " len :%d",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), (int64_t)pBlock->offset,
pBlock->len);
return -1;
@@ -686,7 +686,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
if (nread < pBlock->len) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block data part in file %s is corrupted, offset:%" PRId64
+ tsdbError("vgId:%d, block data part in file %s is corrupted, offset:%" PRId64
" expected bytes:%d read bytes: %" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, pBlock->len, nread);
return -1;
@@ -695,7 +695,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
int32_t tsize = (int32_t)tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer);
if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), tsize)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%d",
+ tsdbError("vgId:%d, block head part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%d",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tsize);
return -1;
}
@@ -750,7 +750,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
pBlockCol ? pBlockCol->blen : 0, pBlock->algorithm, pBlock->numOfRows,
tLenBitmap, pDataCols->maxPoints, TSDB_READ_COMP_BUF(pReadh),
(int)taosTSizeof(TSDB_READ_COMP_BUF(pReadh))) < 0) {
- tsdbError("vgId:%d file %s is broken at column %d block offset %" PRId64 " column offset %u",
+ tsdbError("vgId:%d, file %s is broken at column %d block offset %" PRId64 " column offset %u",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tcolId, (int64_t)pBlock->offset, toffset);
return -1;
}
@@ -945,21 +945,21 @@ static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBloc
int64_t offset = pBlock->offset + tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer) +
tsdbGetBlockColOffset(pBlockCol);
if (tsdbSeekDFile(pDFile, offset, SEEK_SET) < 0) {
- tsdbError("vgId:%d failed to load block column data while seek file %s to offset %" PRId64 " since %s",
+ tsdbError("vgId:%d, failed to load block column data while seek file %s to offset %" PRId64 " since %s",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, tstrerror(terrno));
return -1;
}
int64_t nread = tsdbReadDFile(pDFile, TSDB_READ_BUF(pReadh), pBlockCol->len);
if (nread < 0) {
- tsdbError("vgId:%d failed to load block column data while read file %s since %s, offset:%" PRId64 " len :%d",
+ tsdbError("vgId:%d, failed to load block column data while read file %s since %s, offset:%" PRId64 " len :%d",
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tstrerror(terrno), offset, pBlockCol->len);
return -1;
}
if (nread < pBlockCol->len) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
- tsdbError("vgId:%d block column data in file %s is corrupted, offset:%" PRId64 " expected bytes:%d" PRIzu
+ tsdbError("vgId:%d, block column data in file %s is corrupted, offset:%" PRId64 " expected bytes:%d" PRIzu
" read bytes: %" PRId64,
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, pBlockCol->len, nread);
return -1;
@@ -968,7 +968,7 @@ static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBloc
if (tsdbCheckAndDecodeColumnData(pDataCol, pReadh->pBuf, pBlockCol->len, pBlockCol->blen, pBlock->algorithm,
pBlock->numOfRows, tLenBitmap, pCfg->maxRows, pReadh->pCBuf,
(int32_t)taosTSizeof(pReadh->pCBuf)) < 0) {
- tsdbError("vgId:%d file %s is broken at column %d offset %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
+ tsdbError("vgId:%d, file %s is broken at column %d offset %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
pBlockCol->colId, offset);
return -1;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c
index aab4da26a37119c6e0044849b1494ede2f33e552..6faf6bd1679c36dd0c9fdc0bed538f74cafc13cd 100644
--- a/source/dnode/vnode/src/tsdb/tsdbWrite.c
+++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c
@@ -28,7 +28,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *
// scan and convert
if (tsdbScanAndConvertSubmitMsg(pTsdb, pMsg) < 0) {
if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
- tsdbError("vgId:%d failed to insert data since %s", REPO_ID(pTsdb), tstrerror(terrno));
+ tsdbError("vgId:%d, failed to insert data since %s", REPO_ID(pTsdb), tstrerror(terrno));
}
return -1;
}
@@ -59,7 +59,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, STable *pTable, STSRow *
TSKEY now) {
TSKEY rowKey = TD_ROW_KEY(row);
if (rowKey < minKey || rowKey > maxKey) {
- tsdbError("vgId:%d table %s tid %d uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
+ tsdbError("vgId:%d, table %s tid %d uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
" maxKey %" PRId64 " row key %" PRId64,
REPO_ID(pTsdb), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), now, minKey, maxKey,
rowKey);
@@ -75,7 +75,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, STSRow *ro
TSKEY now) {
TSKEY rowKey = TD_ROW_KEY(row);
if (rowKey < minKey || rowKey > maxKey) {
- tsdbError("vgId:%d table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
+ tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
" maxKey %" PRId64 " row key %" PRId64,
REPO_ID(pTsdb), uid, now, minKey, maxKey, rowKey);
terrno = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
@@ -115,7 +115,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
#if 0
if (pBlock->tid <= 0 || pBlock->tid >= pMeta->maxTables) {
- tsdbError("vgId:%d failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pTsdb), pBlock->uid,
+ tsdbError("vgId:%d, failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pTsdb), pBlock->uid,
pBlock->tid);
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
return -1;
@@ -123,14 +123,14 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
STable *pTable = pMeta->tables[pBlock->tid];
if (pTable == NULL || TABLE_UID(pTable) != pBlock->uid) {
- tsdbError("vgId:%d failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pTsdb), pBlock->uid,
+ tsdbError("vgId:%d, failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pTsdb), pBlock->uid,
pBlock->tid);
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
return -1;
}
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
- tsdbError("vgId:%d invalid action trying to insert a super table %s", REPO_ID(pTsdb), TABLE_CHAR_NAME(pTable));
+ tsdbError("vgId:%d, invalid action trying to insert a super table %s", REPO_ID(pTsdb), TABLE_CHAR_NAME(pTable));
terrno = TSDB_CODE_TDB_INVALID_ACTION;
return -1;
}
diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c
index 9122913cda69d05889e1f575a5da4b61ef4a03a9..9ca4dd6efb981acdf2ff271635b7e146052c7a40 100644
--- a/source/dnode/vnode/src/vnd/vnodeBufPool.c
+++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c
@@ -30,7 +30,7 @@ int vnodeOpenBufPool(SVnode *pVnode, int64_t size) {
// create pool
ret = vnodeBufPoolCreate(size, &pPool);
if (ret < 0) {
- vError("vgId:%d failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
vnodeCloseBufPool(pVnode);
return -1;
}
@@ -40,7 +40,7 @@ int vnodeOpenBufPool(SVnode *pVnode, int64_t size) {
pVnode->pPool = pPool;
}
- vDebug("vgId:%d vnode buffer pool is opened, pool size: %" PRId64, TD_VID(pVnode), size);
+ vDebug("vgId:%d, vnode buffer pool is opened, pool size: %" PRId64, TD_VID(pVnode), size);
return 0;
}
@@ -53,7 +53,7 @@ int vnodeCloseBufPool(SVnode *pVnode) {
vnodeBufPoolDestroy(pPool);
}
- vDebug("vgId:%d vnode buffer pool is closed", TD_VID(pVnode));
+ vDebug("vgId:%d, vnode buffer pool is closed", TD_VID(pVnode));
return 0;
}
diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c
index a0db3cfe2da57c9a9b8ebc7e743ff69554763dd6..3715866bb88f3ae030d5f65c7ce938e69120f466 100644
--- a/source/dnode/vnode/src/vnd/vnodeCommit.c
+++ b/source/dnode/vnode/src/vnd/vnodeCommit.c
@@ -42,29 +42,29 @@ int vnodeBegin(SVnode *pVnode) {
// begin meta
if (metaBegin(pVnode->pMeta) < 0) {
- vError("vgId:%d failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
// begin tsdb
if (pVnode->pSma) {
if (tsdbBegin(VND_RSMA0(pVnode)) < 0) {
- vError("vgId:%d failed to begin rsma0 since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin rsma0 since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
if (tsdbBegin(VND_RSMA1(pVnode)) < 0) {
- vError("vgId:%d failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
if (tsdbBegin(VND_RSMA2(pVnode)) < 0) {
- vError("vgId:%d failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
} else {
if (tsdbBegin(pVnode->pTsdb) < 0) {
- vError("vgId:%d failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
}
@@ -110,7 +110,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
// free info binary
taosMemoryFree(data);
- vInfo("vgId:%d vnode info is saved, fname: %s", pInfo->config.vgId, fname);
+ vInfo("vgId:%d, vnode info is saved, fname: %s", pInfo->config.vgId, fname);
return 0;
@@ -132,7 +132,7 @@ int vnodeCommitInfo(const char *dir, const SVnodeInfo *pInfo) {
return -1;
}
- vInfo("vgId:%d vnode info is committed", pInfo->config.vgId);
+ vInfo("vgId:%d, vnode info is committed", pInfo->config.vgId);
return 0;
}
@@ -210,7 +210,7 @@ int vnodeCommit(SVnode *pVnode) {
SVnodeInfo info = {0};
char dir[TSDB_FILENAME_LEN];
- vInfo("vgId:%d start to commit, version: %" PRId64, TD_VID(pVnode), pVnode->state.applied);
+ vInfo("vgId:%d, start to commit, version: %" PRId64, TD_VID(pVnode), pVnode->state.applied);
pVnode->onCommit = pVnode->inUse;
pVnode->inUse = NULL;
@@ -268,7 +268,7 @@ int vnodeCommit(SVnode *pVnode) {
pVnode->pPool = pVnode->onCommit;
pVnode->onCommit = NULL;
- vInfo("vgId:%d commit over", TD_VID(pVnode));
+ vInfo("vgId:%d, commit over", TD_VID(pVnode));
return 0;
}
diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c
index 7a26c16e4ba0d4137e44262569a457d87b1a5adf..a85b8306165326bc07f643718e9b67201e668de6 100644
--- a/source/dnode/vnode/src/vnd/vnodeOpen.c
+++ b/source/dnode/vnode/src/vnd/vnodeOpen.c
@@ -23,13 +23,13 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
// check config
if (vnodeCheckCfg(pCfg) < 0) {
- vError("vgId:%d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno));
+ vError("vgId:%d, failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno));
return -1;
}
// create vnode env
if (tfsMkdir(pTfs, path) < 0) {
- vError("vgId:%d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno));
+ vError("vgId:%d, failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno));
return -1;
}
@@ -39,11 +39,11 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
info.state.applied = -1;
if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir, &info) < 0) {
- vError("vgId:%d failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno));
+ vError("vgId:%d, failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno));
return -1;
}
- vInfo("vgId:%d vnode is created", pCfg->vgId);
+ vInfo("vgId:%d, vnode is created", pCfg->vgId);
return 0;
}
@@ -70,7 +70,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1);
if (pVnode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
- vError("vgId:%d failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
return NULL;
}
@@ -86,25 +86,25 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
// open buffer pool
if (vnodeOpenBufPool(pVnode, pVnode->config.isHeap ? 0 : pVnode->config.szBuf / 3) < 0) {
- vError("vgId:%d failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open meta
if (metaOpen(pVnode, &pVnode->pMeta) < 0) {
- vError("vgId:%d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open tsdb
if (!VND_IS_RSMA(pVnode) && tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL) < 0) {
- vError("vgId:%d failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open sma
if (smaOpen(pVnode)) {
- vError("vgId:%d failed to open vnode sma since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode sma since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
@@ -113,7 +113,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
taosRealPath(tdir, NULL, sizeof(tdir));
pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg));
if (pVnode->pWal == NULL) {
- vError("vgId:%d failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
@@ -122,27 +122,27 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
taosRealPath(tdir, NULL, sizeof(tdir));
pVnode->pTq = tqOpen(tdir, pVnode, pVnode->pWal);
if (pVnode->pTq == NULL) {
- vError("vgId:%d failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open query
if (vnodeQueryOpen(pVnode)) {
- vError("vgId:%d failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno));
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
// vnode begin
if (vnodeBegin(pVnode) < 0) {
- vError("vgId:%d failed to begin since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to begin since %s", TD_VID(pVnode), tstrerror(terrno));
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
// open sync
if (vnodeSyncOpen(pVnode, dir)) {
- vError("vgId:%d failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno));
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c
index 82a174025bf180eaeea092c30577571b35564c17..7480bb3c24557563564415ff6159deeb4560cb5e 100644
--- a/source/dnode/vnode/src/vnd/vnodeSvr.c
+++ b/source/dnode/vnode/src/vnd/vnodeSvr.c
@@ -25,6 +25,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
static int vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) {
+ int32_t code = 0;
SDecoder dc = {0};
switch (pMsg->msgType) {
@@ -89,13 +90,13 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) {
} break;
case TDMT_VND_ALTER_REPLICA: {
- vnodeSyncAlter(pVnode, pMsg);
+ code = vnodeSyncAlter(pVnode, pMsg);
} break;
default:
break;
}
- return 0;
+ return code;
}
int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp) {
@@ -104,7 +105,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
int len;
int ret;
- vTrace("vgId:%d start to process write request %s, version %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
+ vTrace("vgId:%d, start to process write request %s, version %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
version);
pVnode->state.applied = version;
@@ -164,16 +165,16 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
break;
}
- vDebug("vgId:%d process %s request success, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version);
+ vTrace("vgId:%d, process %s request success, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version);
if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, version) < 0) {
- vError("vgId:%d failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
+ vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
// commit if need
if (vnodeShouldCommit(pVnode)) {
- vInfo("vgId:%d commit at version %" PRId64, TD_VID(pVnode), version);
+ vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), version);
// commit current change
vnodeCommit(pVnode);
@@ -184,7 +185,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
return 0;
_err:
- vDebug("vgId:%d process %s request failed since %s, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
+ vError("vgId:%d, process %s request failed since %s, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType),
tstrerror(terrno), version);
return -1;
}
@@ -836,13 +837,13 @@ static int vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq
}
tDecoderClear(&coder);
- vDebug("vgId:%d success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
+ vDebug("vgId:%d, success to create tsma %s:%" PRIi64 " version %" PRIi64 " for table %" PRIi64, TD_VID(pVnode),
req.indexName, req.indexUid, version, req.tableUid);
return 0;
_err:
tDecoderClear(&coder);
- vError("vgId:%d failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
+ vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s",
TD_VID(pVnode), req.indexName, req.indexUid, version, req.tableUid, terrstr(terrno));
return -1;
}
diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c
index 8792fbbb0c60d52a06b7af28ca040a1a0f22eb9b..37f765d786bf14476f64643bb3803a9e21690b51 100644
--- a/source/dnode/vnode/src/vnd/vnodeSync.c
+++ b/source/dnode/vnode/src/vnd/vnodeSync.c
@@ -50,13 +50,11 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
return 0;
}
-void vnodeSyncAlter(SVnode *pVnode, SRpcMsg *pMsg) {
+int32_t vnodeSyncAlter(SVnode *pVnode, SRpcMsg *pMsg) {
SAlterVnodeReq req = {0};
if (tDeserializeSAlterVnodeReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead), &req) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
- vError("vgId:%d, failed to alter replica since %s", TD_VID(pVnode), terrstr());
- SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
- tmsgSendRsp(&rsp);
+ return TSDB_CODE_INVALID_MSG;
}
vInfo("vgId:%d, start to alter vnode replica to %d", TD_VID(pVnode), req.replica);
@@ -68,11 +66,15 @@ void vnodeSyncAlter(SVnode *pVnode, SRpcMsg *pMsg) {
vInfo("vgId:%d, replica:%d %s:%u", TD_VID(pVnode), r, pNode->nodeFqdn, pNode->nodePort);
}
- if (syncReconfig(pVnode->sync, &cfg) != 0) {
- vError("vgId:%d, failed to propose sync reconfig since %s", TD_VID(pVnode), terrstr());
+ int32_t code = syncReconfig(pVnode->sync, &cfg);
+ if (code == TAOS_SYNC_PROPOSE_SUCCESS) {
+ // todo refactor
SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
tmsgSendRsp(&rsp);
+ return TSDB_CODE_ACTION_IN_PROGRESS;
}
+
+ return code;
}
void vnodeSyncStart(SVnode *pVnode) {
diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp
index 4d2741f751066b62ebb463b4ff8d2930f057a318..3b8c94e413ee866441f5d7514e13986d31fc4137 100644
--- a/source/dnode/vnode/test/tsdbSmaTest.cpp
+++ b/source/dnode/vnode/test/tsdbSmaTest.cpp
@@ -147,8 +147,8 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
// resource release
taosMemoryFreeClear(pSW);
- tdDestroyTSma(&tSma);
- tdDestroyTSmaWrapper(&dstTSmaWrapper);
+ tDestroyTSma(&tSma);
+ tDestroyTSmaWrapper(&dstTSmaWrapper);
}
#endif
@@ -218,7 +218,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
- tdDestroyTSma(qSmaCfg);
+ tDestroyTSma(qSmaCfg);
taosMemoryFreeClear(qSmaCfg);
qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid2, true);
@@ -229,7 +229,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
- tdDestroyTSma(qSmaCfg);
+ tDestroyTSma(qSmaCfg);
taosMemoryFreeClear(qSmaCfg);
// get index name by table uid
@@ -265,7 +265,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
- tdDestroyTSmaWrapper(pSW);
+ tDestroyTSmaWrapper(pSW);
taosMemoryFreeClear(pSW);
// get all sma table uids
@@ -282,7 +282,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
metaRemoveSmaFromDb(pMeta, indexUid1);
metaRemoveSmaFromDb(pMeta, indexUid2);
- tdDestroyTSma(&tSma);
+ tDestroyTSma(&tSma);
metaClose(pMeta);
}
#endif
@@ -576,7 +576,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
taosArrayDestroy(pDataBlocks);
// release meta
- tdDestroyTSma(&tSma);
+ tDestroyTSma(&tSma);
tfsClose(pTsdb->pTfs);
tsdbClose(pTsdb);
metaClose(pMeta);
diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h
index 239d719fa80eb3b4fbf9b075e165dc50051b3e52..cebe69639045bb164da2e07121c0fe9dc9c5477c 100644
--- a/source/libs/catalog/inc/catalogInt.h
+++ b/source/libs/catalog/inc/catalogInt.h
@@ -490,7 +490,7 @@ int32_t ctgGetTbMetaFromMnodeImpl(CTG_PARAMS, char *dbFName, char* tbName, STabl
int32_t ctgGetTbMetaFromMnode(CTG_PARAMS, const SName* pTableName, STableMetaOutput* out, SCtgTask* pTask);
int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* out, SCtgTask* pTask);
-int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param);
+int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum);
int32_t ctgLaunchJob(SCtgJob *pJob);
int32_t ctgMakeAsyncRes(SCtgJob *pJob);
diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c
index 7e0efe22dbfa2dd61a5c662c1103a1b98f579da8..040156eca20f4a1d9f6f8c24a8a4eafd9a256988 100644
--- a/source/libs/catalog/src/catalog.c
+++ b/source/libs/catalog/src/catalog.c
@@ -1028,16 +1028,21 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmt
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
}
- int32_t code = 0;
+ int32_t code = 0, taskNum = 0;
SCtgJob *pJob = NULL;
- CTG_ERR_JRET(ctgInitJob(CTG_PARAMS_LIST(), &pJob, reqId, pReq, fp, param));
+ CTG_ERR_JRET(ctgInitJob(CTG_PARAMS_LIST(), &pJob, reqId, pReq, fp, param, &taskNum));
+ if (taskNum <= 0) {
+ SMetaData* pMetaData = taosMemoryCalloc(1, sizeof(SMetaData));
+ fp(pMetaData, param, TSDB_CODE_SUCCESS);
+ CTG_API_LEAVE(TSDB_CODE_SUCCESS);
+ }
CTG_ERR_JRET(ctgLaunchJob(pJob));
- *jobId = pJob->refId;
+ // NOTE: here the assignment of jobId is invalid, may over-write the true scheduler created query job.
+// *jobId = pJob->refId;
_return:
-
if (pJob) {
taosReleaseRef(gCtgMgmt.jobPool, pJob->refId);
diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c
index eb84bf00a444fb6bc57652ee32abdf44035a0426..312f0c9250bf405b5ec67f18c1d34b51fc244aff 100644
--- a/source/libs/catalog/src/ctgAsync.c
+++ b/source/libs/catalog/src/ctgAsync.c
@@ -233,7 +233,7 @@ int32_t ctgInitGetUserTask(SCtgJob *pJob, int32_t taskIdx, SUserAuthInfo *user)
}
-int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param) {
+int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum) {
int32_t code = 0;
int32_t tbMetaNum = (int32_t)taosArrayGetSize(pReq->pTableMeta);
int32_t dbVgNum = (int32_t)taosArrayGetSize(pReq->pDbVgroup);
@@ -245,15 +245,15 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
int32_t userNum = (int32_t)taosArrayGetSize(pReq->pUser);
int32_t dbInfoNum = (int32_t)taosArrayGetSize(pReq->pDbInfo);
- int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dbCfgNum + indexNum + userNum + dbInfoNum;
- if (taskNum <= 0) {
- ctgError("empty input for job, taskNum:%d", taskNum);
- CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
+ *taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dbCfgNum + indexNum + userNum + dbInfoNum;
+ if (*taskNum <= 0) {
+ ctgError("Empty input for job, no need to retrieve meta, reqId:0x%" PRIx64, reqId);
+ return TSDB_CODE_SUCCESS;
}
-
+
*job = taosMemoryCalloc(1, sizeof(SCtgJob));
if (NULL == *job) {
- ctgError("calloc %d failed", (int32_t)sizeof(SCtgJob));
+ ctgError("failed to calloc, size:%d, reqId:0x%" PRIx64, (int32_t)sizeof(SCtgJob), reqId);
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
}
@@ -275,52 +275,52 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
pJob->indexNum = indexNum;
pJob->userNum = userNum;
pJob->dbInfoNum = dbInfoNum;
-
- pJob->pTasks = taosArrayInit(taskNum, sizeof(SCtgTask));
-
+
+ pJob->pTasks = taosArrayInit(*taskNum, sizeof(SCtgTask));
+
if (NULL == pJob->pTasks) {
- ctgError("taosArrayInit %d tasks failed", taskNum);
+ ctgError("taosArrayInit %d tasks failed", *taskNum);
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
}
int32_t taskIdx = 0;
for (int32_t i = 0; i < dbVgNum; ++i) {
- char *dbFName = taosArrayGet(pReq->pDbVgroup, i);
+ char* dbFName = taosArrayGet(pReq->pDbVgroup, i);
CTG_ERR_JRET(ctgInitGetDbVgTask(pJob, taskIdx++, dbFName));
}
for (int32_t i = 0; i < dbCfgNum; ++i) {
- char *dbFName = taosArrayGet(pReq->pDbCfg, i);
+ char* dbFName = taosArrayGet(pReq->pDbCfg, i);
CTG_ERR_JRET(ctgInitGetDbCfgTask(pJob, taskIdx++, dbFName));
}
for (int32_t i = 0; i < dbInfoNum; ++i) {
- char *dbFName = taosArrayGet(pReq->pDbInfo, i);
+ char* dbFName = taosArrayGet(pReq->pDbInfo, i);
CTG_ERR_JRET(ctgInitGetDbInfoTask(pJob, taskIdx++, dbFName));
}
for (int32_t i = 0; i < tbMetaNum; ++i) {
- SName *name = taosArrayGet(pReq->pTableMeta, i);
+ SName* name = taosArrayGet(pReq->pTableMeta, i);
CTG_ERR_JRET(ctgInitGetTbMetaTask(pJob, taskIdx++, name));
}
for (int32_t i = 0; i < tbHashNum; ++i) {
- SName *name = taosArrayGet(pReq->pTableHash, i);
+ SName* name = taosArrayGet(pReq->pTableHash, i);
CTG_ERR_JRET(ctgInitGetTbHashTask(pJob, taskIdx++, name));
}
for (int32_t i = 0; i < indexNum; ++i) {
- char *indexName = taosArrayGet(pReq->pIndex, i);
+ char* indexName = taosArrayGet(pReq->pIndex, i);
CTG_ERR_JRET(ctgInitGetIndexTask(pJob, taskIdx++, indexName));
}
for (int32_t i = 0; i < udfNum; ++i) {
- char *udfName = taosArrayGet(pReq->pUdf, i);
+ char* udfName = taosArrayGet(pReq->pUdf, i);
CTG_ERR_JRET(ctgInitGetUdfTask(pJob, taskIdx++, udfName));
}
for (int32_t i = 0; i < userNum; ++i) {
- SUserAuthInfo *user = taosArrayGet(pReq->pUser, i);
+ SUserAuthInfo* user = taosArrayGet(pReq->pUser, i);
CTG_ERR_JRET(ctgInitGetUserTask(pJob, taskIdx++, user));
}
@@ -328,22 +328,8 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
CTG_ERR_JRET(ctgInitGetQnodeTask(pJob, taskIdx++));
}
- pJob->refId = taosAddRef(gCtgMgmt.jobPool, pJob);
- if (pJob->refId < 0) {
- ctgError("add job to ref failed, error: %s", tstrerror(terrno));
- CTG_ERR_JRET(terrno);
- }
-
- taosAcquireRef(gCtgMgmt.jobPool, pJob->refId);
-
- qDebug("QID:%" PRIx64 ", job %" PRIx64 " initialized, task num %d", pJob->queryId, pJob->refId, taskNum);
-
- return TSDB_CODE_SUCCESS;
-
_return:
-
taosMemoryFreeClear(*job);
-
CTG_RET(code);
}
diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h
index 63c398618f38446260124978a803b2a63c6f0688..b8975854c9446eab43cd4a7d8c3ccb6e38b93016 100644
--- a/source/libs/executor/inc/executil.h
+++ b/source/libs/executor/inc/executil.h
@@ -75,15 +75,15 @@ typedef struct SResultRowInfo {
int32_t size; // number of result set
int32_t capacity; // max capacity
SResultRowPosition cur;
+ SList* openWindow;
} SResultRowInfo;
struct SqlFunctionCtx;
-size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
+size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
int32_t initResultRowInfo(SResultRowInfo* pResultRowInfo, int32_t size);
void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo);
-int32_t numOfClosedResultRows(SResultRowInfo* pResultRowInfo);
void closeAllResultRows(SResultRowInfo* pResultRowInfo);
void initResultRow(SResultRow *pResultRow);
@@ -92,15 +92,6 @@ bool isResultRowClosed(SResultRow* pResultRow);
struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, const int32_t* offset);
-static FORCE_INLINE SResultRow *getResultRow(SDiskbasedBuf* pBuf, SResultRowInfo *pResultRowInfo, int32_t slot) {
- ASSERT(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size);
- SResultRowPosition* pos = &pResultRowInfo->pPosition[slot];
-
- SFilePage* bufPage = (SFilePage*) getBufPage(pBuf, pos->pageId);
- SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset);
- return pRow;
-}
-
static FORCE_INLINE SResultRow *getResultRowByPos(SDiskbasedBuf* pBuf, SResultRowPosition* pos) {
SFilePage* bufPage = (SFilePage*) getBufPage(pBuf, pos->pageId);
SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset);
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index 8139e71f63dfa2a58be128fbc2ced05ab81466df..e7a3390cf3114b07be4439b23f346e11ded0f78f 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -454,13 +454,14 @@ typedef struct SIntervalAggOperatorInfo {
STimeWindow win; // query time range
bool timeWindowInterpo; // interpolation needed or not
char** pRow; // previous row/tuple of already processed datablock
+ SArray* pInterpCols; // interpolation columns
STableQueryInfo* pCurrent; // current tableQueryInfo struct
int32_t order; // current SSDataBlock scan order
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
SArray* pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
STimeWindowAggSupp twAggSup;
- struct SFillInfo* pFillInfo; // fill info
bool invertible;
+ SArray* pPrevValues; // SArray used to keep the previous not null value for interpolation.
} SIntervalAggOperatorInfo;
typedef struct SStreamFinalIntervalOperatorInfo {
@@ -832,7 +833,7 @@ int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimary
int32_t order);
int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey);
-SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize);
+SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize);
SResultWindowInfo* getSessionTimeWindow(SArray* pWinInfos, TSKEY ts, int64_t gap,
int32_t* pIndex);
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pTs, int32_t rows,
diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c
index aea9d70f316806286fbd69f0d13dc72ccae54dfe..1c45e38b632d29340472c1955d2b097377478ce0 100644
--- a/source/libs/executor/src/executil.c
+++ b/source/libs/executor/src/executil.c
@@ -101,20 +101,8 @@ void resetResultRowInfo(STaskRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRow
pResultRowInfo->size = 0;
}
-int32_t numOfClosedResultRows(SResultRowInfo *pResultRowInfo) {
- int32_t i = 0;
-// while (i < pResultRowInfo->size && pResultRowInfo->pResult[i]->closed) {
-// ++i;
-// }
-
- return i;
-}
-
void closeAllResultRows(SResultRowInfo *pResultRowInfo) {
- assert(pResultRowInfo->size >= 0 && pResultRowInfo->capacity >= pResultRowInfo->size);
-
- for (int32_t i = 0; i < pResultRowInfo->size; ++i) {
- }
+// do nothing
}
bool isResultRowClosed(SResultRow* pRow) {
@@ -258,32 +246,6 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
return (int32_t) taosArrayGetSize(pGroupResInfo->pRows);
}
-static int64_t getNumOfResultWindowRes(STaskRuntimeEnv* pRuntimeEnv, SResultRowPosition *pos, int32_t* rowCellInfoOffset) {
- STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr;
- ASSERT(0);
-
- for (int32_t j = 0; j < pQueryAttr->numOfOutput; ++j) {
- int32_t functionId = 0;//pQueryAttr->pExpr1[j].base.functionId;
-
- /*
- * ts, tag, tagprj function can not decide the output number of current query
- * the number of output result is decided by main output
- */
- if (functionId == FUNCTION_TS || functionId == FUNCTION_TAG || functionId == FUNCTION_TAGPRJ) {
- continue;
- }
-
-// SResultRowEntryInfo *pResultInfo = getResultCell(pResultRow, j, rowCellInfoOffset);
-// assert(pResultInfo != NULL);
-//
-// if (pResultInfo->numOfRes > 0) {
-// return pResultInfo->numOfRes;
-// }
- }
-
- return 0;
-}
-
static int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param) {
int32_t left = *(int32_t *)pLeft;
int32_t right = *(int32_t *)pRight;
@@ -381,7 +343,7 @@ static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupRe
}
- int64_t num = getNumOfResultWindowRes(pRuntimeEnv, &pResultRowCell->pos, rowCellInfoOffset);
+ int64_t num = 0;//getNumOfResultWindowRes(pRuntimeEnv, &pResultRowCell->pos, rowCellInfoOffset);
if (num <= 0) {
continue;
}
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index 6f2be4e14ef0aee31912a20640f70faa94e73ae1..3c46f46e198bd1fae7ebd6173df64b8dec0e6737 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -239,36 +239,6 @@ static bool hasNull(SColumn* pColumn, SColumnDataAgg* pStatis) {
return true;
}
-static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) {
- int64_t newCapacity = 0;
-
- // more than the capacity, reallocate the resources
- if (pResultRowInfo->size < pResultRowInfo->capacity) {
- return;
- }
-
- if (pResultRowInfo->capacity > 10000) {
- newCapacity = (int64_t)(pResultRowInfo->capacity * 1.25);
- } else {
- newCapacity = (int64_t)(pResultRowInfo->capacity * 1.5);
- }
-
- if (newCapacity <= pResultRowInfo->capacity) {
- newCapacity += 4;
- }
-
- char* p = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition));
- if (p == NULL) {
- longjmp(env, TSDB_CODE_OUT_OF_MEMORY);
- }
-
- pResultRowInfo->pPosition = (SResultRowPosition*)p;
-
- int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity;
- memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc);
- pResultRowInfo->capacity = (int32_t)newCapacity;
-}
-
static bool chkResultRowFromKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, char* pData,
int16_t bytes, bool masterscan, uint64_t uid) {
bool existed = false;
@@ -306,7 +276,7 @@ static bool chkResultRowFromKey(STaskRuntimeEnv* pRuntimeEnv, SResultRowInfo* pR
return p1 != NULL;
}
-SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize) {
+SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize) {
SFilePage* pData = NULL;
// in the first scan, new space needed for results
@@ -375,6 +345,8 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
// In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
// pResultRowInfo object.
if (p1 != NULL) {
+
+ // todo
pResult = getResultRowByPos(pResultBuf, p1);
ASSERT(pResult->pageId == p1->pageId && pResult->offset == p1->offset);
}
@@ -383,34 +355,28 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
// 1. close current opened time window
if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId &&
pResult->offset != pResultRowInfo->cur.offset))) {
- // todo extract function
SResultRowPosition pos = pResultRowInfo->cur;
- SFilePage* pPage = getBufPage(pResultBuf, pos.pageId);
- SResultRow* pRow = (SResultRow*)((char*)pPage + pos.offset);
- closeResultRow(pRow);
+ SFilePage* pPage = getBufPage(pResultBuf, pos.pageId);
releaseBufPage(pResultBuf, pPage);
}
// allocate a new buffer page
- prepareResultListBuffer(pResultRowInfo, pTaskInfo->env);
if (pResult == NULL) {
ASSERT(pSup->resultRowSize > 0);
- pResult = getNewResultRow_rv(pResultBuf, groupId, pSup->resultRowSize);
+ pResult = getNewResultRow(pResultBuf, groupId, pSup->resultRowSize);
+
initResultRow(pResult);
// add a new result set for a new group
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
- taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
- sizeof(SResultRowPosition));
+ taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition));
}
// 2. set the new time window to be the new active time window
- pResultRowInfo->pPosition[pResultRowInfo->size++] =
- (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
// too many time window in query
- if (pResultRowInfo->size > MAX_INTERVAL_TIME_WINDOW) {
+ if (taosHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
longjmp(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW);
}
@@ -585,11 +551,13 @@ void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow
colDataAppendInt64(pColData, 4, &pQueryWindow->ekey);
}
+
void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWindow* pWin,
SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol,
int32_t numOfTotal, int32_t numOfOutput, int32_t order) {
for (int32_t k = 0; k < numOfOutput; ++k) {
// keep it temporarily
+ // todo no need this??
bool hasAgg = pCtx[k].input.colDataAggIsSet;
int32_t numOfRows = pCtx[k].input.numOfRows;
int32_t startOffset = pCtx[k].input.startRowIndex;
@@ -609,7 +577,8 @@ void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWindow
if (fmIsWindowPseudoColumnFunc(pCtx[k].functionId)) {
SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
- char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
+
+ char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
SColumnInfoData idata = {0};
idata.info.type = TSDB_DATA_TYPE_BIGINT;
@@ -620,22 +589,23 @@ void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWindow
SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData};
pCtx[k].sfp.process(&tw, 1, &out);
pEntryInfo->numOfRes = 1;
- continue;
- }
- int32_t code = TSDB_CODE_SUCCESS;
- if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
- code = pCtx[k].fpSet.process(&pCtx[k]);
- if (code != TSDB_CODE_SUCCESS) {
- qError("%s apply functions error, code: %s", GET_TASKID(taskInfo), tstrerror(code));
- taskInfo->code = code;
- longjmp(taskInfo->env, code);
+ } else {
+ int32_t code = TSDB_CODE_SUCCESS;
+ if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
+ code = pCtx[k].fpSet.process(&pCtx[k]);
+
+ if (code != TSDB_CODE_SUCCESS) {
+ qError("%s apply functions error, code: %s", GET_TASKID(taskInfo), tstrerror(code));
+ taskInfo->code = code;
+ longjmp(taskInfo->env, code);
+ }
}
- }
- // restore it
- pCtx[k].input.colDataAggIsSet = hasAgg;
- pCtx[k].input.startRowIndex = startOffset;
- pCtx[k].input.numOfRows = numOfRows;
+ // restore it
+ pCtx[k].input.colDataAggIsSet = hasAgg;
+ pCtx[k].input.startRowIndex = startOffset;
+ pCtx[k].input.numOfRows = numOfRows;
+ }
}
}
@@ -774,12 +744,14 @@ static int32_t doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunct
for (int32_t k = 0; k < pOperator->numOfExprs; ++k) {
if (functionNeedToExecute(&pCtx[k])) {
// todo add a dummy funtion to avoid process check
- if (pCtx[k].fpSet.process != NULL) {
- int32_t code = pCtx[k].fpSet.process(&pCtx[k]);
- if (code != TSDB_CODE_SUCCESS) {
- qError("%s aggregate function error happens, code: %s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
- return code;
- }
+ if (pCtx[k].fpSet.process == NULL) {
+ continue;
+ }
+
+ int32_t code = pCtx[k].fpSet.process(&pCtx[k]);
+ if (code != TSDB_CODE_SUCCESS) {
+ qError("%s aggregate function error happens, code: %s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
+ return code;
}
}
}
@@ -1218,7 +1190,6 @@ static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
taosVariantDestroy(&pCtx[i].param[j].param);
}
- taosVariantDestroy(&pCtx[i].tag);
taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
taosMemoryFree(pCtx[i].input.pData);
taosMemoryFree(pCtx[i].input.pColumnDataAgg);
@@ -1248,9 +1219,9 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_Q
static bool isCachedLastQuery(STaskAttr* pQueryAttr) {
for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]);
- if (functionId == FUNCTION_LAST || functionId == FUNCTION_LAST_DST) {
- continue;
- }
+// if (functionId == FUNCTION_LAST || functionId == FUNCTION_LAST_DST) {
+// continue;
+// }
return false;
}
@@ -1300,7 +1271,7 @@ static int32_t updateBlockLoadStatus(STaskAttr* pQuery, int32_t status) {
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
int32_t functionId = getExprFunctionId(&pQuery->pExpr1[i]);
-
+#if 0
if (functionId == FUNCTION_TS || functionId == FUNCTION_TS_DUMMY || functionId == FUNCTION_TAG ||
functionId == FUNCTION_TAG_DUMMY) {
continue;
@@ -1311,6 +1282,8 @@ static int32_t updateBlockLoadStatus(STaskAttr* pQuery, int32_t status) {
} else {
hasOtherFunc = true;
}
+#endif
+
}
if (hasFirstLastFunc && status == BLK_DATA_NOT_LOAD) {
@@ -1786,41 +1759,13 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOf
// set the correct pointer after the memory buffer reallocated.
int32_t functionId = pBInfo->pCtx[i].functionId;
-
+#if 0
if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF ||
functionId == FUNCTION_DERIVATIVE) {
// if (i > 0) pBInfo->pCtx[i].pTsOutput = pBInfo->pCtx[i - 1].pOutput;
}
- }
-}
-
-void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput) {
- bool needCopyTs = false;
- int32_t tsNum = 0;
- char* src = NULL;
- for (int32_t i = 0; i < numOfOutput; i++) {
- int32_t functionId = pCtx[i].functionId;
- if (functionId == FUNCTION_DIFF || functionId == FUNCTION_DERIVATIVE) {
- needCopyTs = true;
- if (i > 0 && pCtx[i - 1].functionId == FUNCTION_TS_DUMMY) {
- SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data
- src = pColRes->pData;
- }
- } else if (functionId == FUNCTION_TS_DUMMY) {
- tsNum++;
- }
- }
-
- if (!needCopyTs) return;
- if (tsNum < 2) return;
- if (src == NULL) return;
+#endif
- for (int32_t i = 0; i < numOfOutput; i++) {
- int32_t functionId = pCtx[i].functionId;
- if (functionId == FUNCTION_TS_DUMMY) {
- SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i);
- memcpy(pColRes->pData, src, pColRes->info.bytes * pRes->info.rows);
- }
}
}
@@ -2577,47 +2522,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total,
SArray* pColList) {
if (pColList == NULL) { // data from other sources
- blockDataEnsureCapacity(pRes, numOfRows);
-
- int32_t dataLen = *(int32_t*)pData;
- pData += sizeof(int32_t);
-
- pRes->info.groupId = *(uint64_t*)pData;
- pData += sizeof(uint64_t);
-
- int32_t* colLen = (int32_t*)pData;
-
- char* pStart = pData + sizeof(int32_t) * numOfOutput;
- for (int32_t i = 0; i < numOfOutput; ++i) {
- colLen[i] = htonl(colLen[i]);
- ASSERT(colLen[i] >= 0);
-
- SColumnInfoData* pColInfoData = taosArrayGet(pRes->pDataBlock, i);
- if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
- pColInfoData->varmeta.length = colLen[i];
- pColInfoData->varmeta.allocLen = colLen[i];
-
- memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows);
- pStart += sizeof(int32_t) * numOfRows;
-
- if (colLen[i] > 0) {
- taosMemoryFreeClear(pColInfoData->pData);
- pColInfoData->pData = taosMemoryMalloc(colLen[i]);
- }
- } else {
- memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows));
- pStart += BitmapLen(numOfRows);
- }
-
- if (colLen[i] > 0) {
- memcpy(pColInfoData->pData, pStart, colLen[i]);
- }
-
- // TODO setting this flag to true temporarily so aggregate function on stable will
- // examine NULL value for non-primary key column
- pColInfoData->hasNull = true;
- pStart += colLen[i];
- }
+ blockCompressDecode(pRes, numOfOutput, numOfRows, pData);
} else { // extract data according to pColList
ASSERT(numOfOutput == taosArrayGetSize(pColList));
char* pStart = pData;
@@ -3587,7 +3492,7 @@ int32_t aggDecodeResultRow(SOperatorInfo* pOperator, char* result) {
offset += sizeof(int32_t);
uint64_t tableGroupId = *(uint64_t*)(result + offset);
- SResultRow* resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize);
+ SResultRow* resultRow = getNewResultRow(pSup->pResultBuf, tableGroupId, pSup->resultRowSize);
if (!resultRow) {
return TSDB_CODE_TSC_INVALID_INPUT;
}
@@ -3610,10 +3515,6 @@ int32_t aggDecodeResultRow(SOperatorInfo* pOperator, char* result) {
offset += valueLen;
initResultRow(resultRow);
- prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env);
- // pInfo->resultRowInfo.cur = pInfo->resultRowInfo.size;
- // pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] =
- // (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
pInfo->resultRowInfo.cur = (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
}
@@ -3905,18 +3806,6 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
}
}
-// todo set the attribute of query scan count
-static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr) {
- for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
- int32_t functionId = getExprFunctionId(&pQueryAttr->pExpr1[i]);
- if (functionId == FUNCTION_STDDEV || functionId == FUNCTION_PERCT) {
- return 2;
- }
- }
-
- return 1;
-}
-
static void destroyOperatorInfo(SOperatorInfo* pOperator) {
if (pOperator == NULL) {
return;
diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c
index d388b802f3ae22c7c0cf135c9eb70111be1d79a4..8c3a0c0e6e712ad07a381b3baa709b095ba955fb 100644
--- a/source/libs/executor/src/groupoperator.c
+++ b/source/libs/executor/src/groupoperator.c
@@ -110,9 +110,11 @@ static bool groupKeyCompare(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlo
return true;
}
-static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex, int32_t numOfGroupCols) {
+static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex) {
SColumnDataAgg* pColAgg = NULL;
+ size_t numOfGroupCols = taosArrayGetSize(pGroupCols);
+
for (int32_t i = 0; i < numOfGroupCols; ++i) {
SColumn* pCol = taosArrayGet(pGroupCols, i);
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId);
@@ -208,7 +210,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
// Compare with the previous row of this column, and do not set the output buffer again if they are identical.
if (!pInfo->isInit) {
- recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j, numOfGroupCols);
+ recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j);
pInfo->isInit = true;
num++;
continue;
@@ -223,7 +225,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
// The first row of a new block does not belongs to the previous existed group
if (j == 0) {
num++;
- recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j, numOfGroupCols);
+ recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j);
continue;
}
@@ -238,7 +240,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
// assign the group keys or user input constant values if required
doAssignGroupKeys(pCtx, pOperator->numOfExprs, pBlock->info.rows, rowIndex);
- recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j, numOfGroupCols);
+ recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j);
num = 1;
}
@@ -409,7 +411,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols);
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
- recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j, numOfGroupCols);
+ recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j);
int32_t len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
SDataGroupInfo* pGInfo = NULL;
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 0e682682a11330fa07f876097a9f93b0108e442d..348d85943e9ce306347a5530617131b6e00cf89a 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -531,7 +531,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
}
pInfo->scanInfo = (SScanInfo){.numOfAsc = pTableScanNode->scanSeq[0], .numOfDesc = pTableScanNode->scanSeq[1]};
- // pInfo->scanInfo = (SScanInfo){.numOfAsc = 0, .numOfDesc = 1}; // for debug purpose
+// pInfo->scanInfo = (SScanInfo){.numOfAsc = 0, .numOfDesc = 1}; // for debug purpose
pInfo->readHandle = *readHandle;
pInfo->interval = extractIntervalInfo(pTableScanNode);
diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c
index 14344daf8150799683bb8d5fac605347d611819e..41037e9f163ff476e6ba583d316357ade84e773a 100644
--- a/source/libs/executor/src/timewindowoperator.c
+++ b/source/libs/executor/src/timewindowoperator.c
@@ -1,3 +1,4 @@
+#include "function.h"
#include "executorimpl.h"
#include "functionMgt.h"
#include "tdatablock.h"
@@ -11,6 +12,11 @@ typedef enum SResultTsInterpType {
static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator);
static SSDataBlock* doStreamSessionWindowAgg(SOperatorInfo* pOperator);
+static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo);
+
+static SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SResultRow* pResult);
+static void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOperatorInfo* pInfo, SResultRow* pResult);
+
/*
* There are two cases to handle:
*
@@ -21,47 +27,11 @@ static SSDataBlock* doStreamSessionWindowAgg(SOperatorInfo* pOperator);
* is a previous result generated or not.
*/
static void setIntervalQueryRange(STableQueryInfo* pTableQueryInfo, TSKEY key, STimeWindow* pQRange) {
- // SResultRowInfo* pResultRowInfo = &pTableQueryInfo->resInfo;
- // if (pResultRowInfo->curPos != -1) {
- // return;
- // }
-
- // pTableQueryInfo->win.skey = key;
- // STimeWindow win = {.skey = key, .ekey = pQRange->ekey};
-
- /**
- * In handling the both ascending and descending order super table query, we need to find the first qualified
- * timestamp of this table, and then set the first qualified start timestamp.
- * In ascending query, the key is the first qualified timestamp. However, in the descending order query, additional
- * operations involve.
- */
- // STimeWindow w = TSWINDOW_INITIALIZER;
- //
- // TSKEY sk = TMIN(win.skey, win.ekey);
- // TSKEY ek = TMAX(win.skey, win.ekey);
- // getAlignQueryTimeWindow(pQueryAttr, win.skey, sk, ek, &w);
-
- // if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) {
- // if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
- // assert(win.ekey == pQueryAttr->window.ekey);
- // }
- //
- // pResultRowInfo->prevSKey = w.skey;
- // }
-
- // pTableQueryInfo->lastKey = pTableQueryInfo->win.skey;
+ // do nothing
}
-static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols, int32_t rows, bool ascQuery) {
- TSKEY ts = TSKEY_INITIAL_VAL;
- if (tsCols == NULL) {
- ts = ascQuery ? win->skey : win->ekey;
- } else {
-// int32_t offset = ascQuery ? 0 : rows - 1;
- ts = tsCols[0];
- }
-
- return ts;
+static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols) {
+ return tsCols == NULL? win->skey:tsCols[0];
}
static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w,
@@ -134,8 +104,10 @@ static int32_t setTimeWindowOutputBuf(SResultRowInfo* pResultRowInfo, STimeWindo
// set time window for current result
pResultRow->win = (*win);
+
*pResult = pResultRow;
setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowCellInfoOffset);
+
return TSDB_CODE_SUCCESS;
}
@@ -163,38 +135,38 @@ static void doKeepNewWindowStartInfo(SWindowRowsSup* pRowSup, const int64_t* tsL
static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey,
int16_t pos, int16_t order, int64_t* pData) {
- int32_t forwardStep = 0;
+ int32_t forwardRows = 0;
if (order == TSDB_ORDER_ASC) {
int32_t end = searchFn((char*)&pData[pos], numOfRows - pos, ekey, order);
if (end >= 0) {
- forwardStep = end;
+ forwardRows = end;
if (pData[end + pos] == ekey) {
- forwardStep += 1;
+ forwardRows += 1;
}
}
} else {
int32_t end = searchFn((char*)&pData[pos], numOfRows - pos, ekey, order);
if (end >= 0) {
- forwardStep = end;
+ forwardRows = end;
if (pData[end + pos] == ekey) {
- forwardStep += 1;
+ forwardRows += 1;
}
}
// int32_t end = searchFn((char*)pData, pos + 1, ekey, order);
// if (end >= 0) {
-// forwardStep = pos - end;
+// forwardRows = pos - end;
//
// if (pData[end] == ekey) {
-// forwardStep += 1;
+// forwardRows += 1;
// }
// }
}
- assert(forwardStep >= 0);
- return forwardStep;
+ assert(forwardRows >= 0);
+ return forwardRows;
}
int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
@@ -339,34 +311,40 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o
tw->ekey -= 1;
}
-void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SArray* pDataBlock, TSKEY prevTs,
+void doTimeWindowInterpolation(SIntervalAggOperatorInfo *pInfo, int32_t numOfExprs, SArray* pDataBlock, TSKEY prevTs,
int32_t prevRowIndex, TSKEY curTs, int32_t curRowIndex, TSKEY windowKey, int32_t type) {
- SExprInfo* pExpr = pOperator->pExpr;
+ SqlFunctionCtx* pCtx = pInfo->binfo.pCtx;
- SqlFunctionCtx* pCtx = pInfo->pCtx;
+ int32_t index = 1;
+ for (int32_t k = 0; k < numOfExprs; ++k) {
- for (int32_t k = 0; k < pOperator->numOfExprs; ++k) {
- int32_t functionId = pCtx[k].functionId;
- if (functionId != FUNCTION_TWA && functionId != FUNCTION_INTERP) {
+ // todo use flag instead of function name
+ if (strcmp(pCtx[k].pExpr->pExpr->_function.functionName, "twa") != 0) {
pCtx[k].start.key = INT64_MIN;
continue;
}
- SColIndex* pColIndex = NULL /*&pExpr[k].base.colInfo*/;
- int16_t index = pColIndex->colIndex;
- SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, index);
+// if (functionId != FUNCTION_TWA && functionId != FUNCTION_INTERP) {
+// pCtx[k].start.key = INT64_MIN;
+// continue;
+// }
- // assert(pColInfo->info.colId == pColIndex->info.colId && curTs != windowKey);
- double v1 = 0, v2 = 0, v = 0;
+ SFunctParam* pParam = &pCtx[k].param[0];
+ SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, pParam->pCol->slotId);
+
+ ASSERT(pColInfo->info.colId == pParam->pCol->colId && curTs != windowKey);
+ double v1 = 0, v2 = 0, v = 0;
if (prevRowIndex == -1) {
- // GET_TYPED_DATA(v1, double, pColInfo->info.type, (char*)pRuntimeEnv->prevRow[index]);
+ SGroupKeys* p = taosArrayGet(pInfo->pPrevValues, index);
+ GET_TYPED_DATA(v1, double, pColInfo->info.type, p->pData);
} else {
- GET_TYPED_DATA(v1, double, pColInfo->info.type, (char*)pColInfo->pData + prevRowIndex * pColInfo->info.bytes);
+ GET_TYPED_DATA(v1, double, pColInfo->info.type, colDataGetData(pColInfo, prevRowIndex));
}
- GET_TYPED_DATA(v2, double, pColInfo->info.type, (char*)pColInfo->pData + curRowIndex * pColInfo->info.bytes);
+ GET_TYPED_DATA(v2, double, pColInfo->info.type, colDataGetData(pColInfo, curRowIndex));
+#if 0
if (functionId == FUNCTION_INTERP) {
if (type == RESULT_ROW_START_INTERP) {
pCtx[k].start.key = prevTs;
@@ -386,6 +364,8 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
}
}
} else if (functionId == FUNCTION_TWA) {
+#endif
+
SPoint point1 = (SPoint){.key = prevTs, .val = &v1};
SPoint point2 = (SPoint){.key = curTs, .val = &v2};
SPoint point = (SPoint){.key = windowKey, .val = &v};
@@ -399,8 +379,13 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
pCtx[k].end.key = point.key;
pCtx[k].end.val = v;
}
+
+ index += 1;
}
+#if 0
}
+#endif
+
}
static void setNotInterpoWindowKey(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t type) {
@@ -415,62 +400,59 @@ static void setNotInterpoWindowKey(SqlFunctionCtx* pCtx, int32_t numOfOutput, in
}
}
-static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t pos,
- int32_t numOfRows, SArray* pDataBlock, const TSKEY* tsCols,
- STimeWindow* win) {
- bool ascQuery = true;
+static bool setTimeWindowInterpolationStartTs(SIntervalAggOperatorInfo *pInfo, SqlFunctionCtx* pCtx, int32_t numOfExprs, int32_t pos,
+ SSDataBlock* pBlock, const TSKEY* tsCols, STimeWindow* win) {
+ bool ascQuery = (pInfo->order == TSDB_ORDER_ASC);
+
TSKEY curTs = tsCols[pos];
- TSKEY lastTs = 0; //*(TSKEY*)pRuntimeEnv->prevRow[0];
+
+ SGroupKeys* pTsKey = taosArrayGet(pInfo->pPrevValues, 0);
+ TSKEY lastTs = *(int64_t*) pTsKey->pData;
// lastTs == INT64_MIN and pos == 0 means this is the first time window, interpolation is not needed.
// start exactly from this point, no need to do interpolation
TSKEY key = ascQuery ? win->skey : win->ekey;
if (key == curTs) {
- setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_START_INTERP);
return true;
}
- if (lastTs == INT64_MIN && ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery))) {
- setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
- return true;
+ // it is the first time window, no need to do interpolation
+ if (pTsKey->isNull && pos == 0) {
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_START_INTERP);
+ } else {
+ TSKEY prevTs = ((pos == 0) ? lastTs : tsCols[pos - 1]);
+ doTimeWindowInterpolation(pInfo, numOfExprs, pBlock->pDataBlock, prevTs, pos - 1, curTs, pos, key,
+ RESULT_ROW_START_INTERP);
}
- int32_t step = 1; // GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order);
- TSKEY prevTs = ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery)) ? lastTs : tsCols[pos - step];
-
- doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, prevTs, pos - step, curTs, pos, key,
- RESULT_ROW_START_INTERP);
return true;
}
-static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFunctionCtx* pCtx, int32_t endRowIndex,
- SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey,
- STimeWindow* win) {
- int32_t order = TSDB_ORDER_ASC;
- int32_t numOfOutput = pOperatorInfo->numOfExprs;
+static bool setTimeWindowInterpolationEndTs(SIntervalAggOperatorInfo *pInfo, SqlFunctionCtx* pCtx, int32_t numOfExprs, int32_t endRowIndex,
+ SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey, STimeWindow* win) {
+ int32_t order = pInfo->order;
TSKEY actualEndKey = tsCols[endRowIndex];
- TSKEY key = order ? win->ekey : win->skey;
+ TSKEY key = (order == TSDB_ORDER_ASC) ? win->ekey : win->skey;
// not ended in current data block, do not invoke interpolation
- if ((key > blockEkey /*&& QUERY_IS_ASC_QUERY(pQueryAttr)*/) ||
- (key < blockEkey /*&& !QUERY_IS_ASC_QUERY(pQueryAttr)*/)) {
- setNotInterpoWindowKey(pCtx, numOfOutput, RESULT_ROW_END_INTERP);
+ if ((key > blockEkey && (order == TSDB_ORDER_ASC)) || (key < blockEkey && (order == TSDB_ORDER_DESC))) {
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_END_INTERP);
return false;
}
- // there is actual end point of current time window, no interpolation need
+ // there is actual end point of current time window, no interpolation needs
if (key == actualEndKey) {
- setNotInterpoWindowKey(pCtx, numOfOutput, RESULT_ROW_END_INTERP);
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_END_INTERP);
return true;
}
- int32_t step = GET_FORWARD_DIRECTION_FACTOR(order);
- int32_t nextRowIndex = endRowIndex + step;
+ int32_t nextRowIndex = endRowIndex + 1;
assert(nextRowIndex >= 0);
TSKEY nextKey = tsCols[nextRowIndex];
- doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pDataBlock, actualEndKey, endRowIndex, nextKey,
+ doTimeWindowInterpolation(pInfo, numOfExprs, pDataBlock, actualEndKey, endRowIndex, nextKey,
nextRowIndex, key, RESULT_ROW_END_INTERP);
return true;
}
@@ -542,8 +524,8 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext,
return startPos;
}
-static bool resultRowInterpolated(SResultRow* pResult, SResultTsInterpType type) {
- assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
+static bool isResultRowInterpolated(SResultRow* pResult, SResultTsInterpType type) {
+ ASSERT(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
if (type == RESULT_ROW_START_INTERP) {
return pResult->startInterp == true;
} else {
@@ -560,34 +542,29 @@ static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
}
}
-static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBlock* pBlock, SqlFunctionCtx* pCtx,
- SResultRow* pResult, STimeWindow* win, int32_t startPos, int32_t forwardStep,
- int32_t order, bool timeWindowInterpo) {
- if (!timeWindowInterpo) {
+static void doWindowBorderInterpolation(SIntervalAggOperatorInfo *pInfo, SSDataBlock* pBlock, int32_t numOfExprs, SqlFunctionCtx* pCtx,
+ SResultRow* pResult, STimeWindow* win, int32_t startPos, int32_t forwardRows) {
+ if (!pInfo->timeWindowInterpo) {
return;
}
- assert(pBlock != NULL);
- int32_t step = GET_FORWARD_DIRECTION_FACTOR(order);
-
+ ASSERT(pBlock != NULL);
if (pBlock->pDataBlock == NULL) {
// tscError("pBlock->pDataBlock == NULL");
return;
}
- SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
+ SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex);
TSKEY* tsCols = (TSKEY*)(pColInfo->pData);
- bool done = resultRowInterpolated(pResult, RESULT_ROW_START_INTERP);
+ bool done = isResultRowInterpolated(pResult, RESULT_ROW_START_INTERP);
if (!done) { // it is not interpolated, now start to generated the interpolated value
- int32_t startRowIndex = startPos;
- bool interp = setTimeWindowInterpolationStartTs(pOperatorInfo, pCtx, startRowIndex, pBlock->info.rows,
- pBlock->pDataBlock, tsCols, win);
+ bool interp = setTimeWindowInterpolationStartTs(pInfo, pCtx, numOfExprs, startPos, pBlock, tsCols, win);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
}
} else {
- setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_START_INTERP);
}
// point interpolation does not require the end key time window interpolation.
@@ -596,29 +573,106 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc
// }
// interpolation query does not generate the time window end interpolation
- done = resultRowInterpolated(pResult, RESULT_ROW_END_INTERP);
+ done = isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP);
if (!done) {
- int32_t endRowIndex = startPos + (forwardStep - 1) * step;
+ int32_t endRowIndex = startPos + forwardRows - 1;
- TSKEY endKey = (order == TSDB_ORDER_ASC) ? pBlock->info.window.ekey : pBlock->info.window.skey;
+ TSKEY endKey = (pInfo->order == TSDB_ORDER_ASC) ? pBlock->info.window.ekey : pBlock->info.window.skey;
bool interp =
- setTimeWindowInterpolationEndTs(pOperatorInfo, pCtx, endRowIndex, pBlock->pDataBlock, tsCols, endKey, win);
+ setTimeWindowInterpolationEndTs(pInfo, pCtx, numOfExprs, endRowIndex, pBlock->pDataBlock, tsCols, endKey, win);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
}
} else {
- setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_END_INTERP);
+ setNotInterpoWindowKey(pCtx, numOfExprs, RESULT_ROW_END_INTERP);
}
}
-static void saveDataBlockLastRow(char** pRow, SArray* pDataBlock, int32_t rowIndex, int32_t numOfCols) {
- if (pDataBlock == NULL) {
+static void saveDataBlockLastRow(SArray* pPrevKeys, const SSDataBlock* pBlock, SArray* pCols) {
+ if (pBlock->pDataBlock == NULL) {
return;
}
- for (int32_t k = 0; k < numOfCols; ++k) {
- SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, k);
- memcpy(pRow[k], ((char*)pColInfo->pData) + (pColInfo->info.bytes * rowIndex), pColInfo->info.bytes);
+ size_t num = taosArrayGetSize(pPrevKeys);
+ for (int32_t k = 0; k < num; ++k) {
+ SColumn* pc = taosArrayGet(pCols, k);
+
+ SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pc->slotId);
+
+ SGroupKeys* pkey = taosArrayGet(pPrevKeys, k);
+ for(int32_t i = pBlock->info.rows - 1; i >= 0; --i) {
+ if (colDataIsNull_s(pColInfo, i)) {
+ continue;
+ }
+
+ char* val = colDataGetData(pColInfo, i);
+ if (IS_VAR_DATA_TYPE(pkey->type)) {
+ memcpy(pkey->pData, val, varDataTLen(val));
+ ASSERT(varDataTLen(val) <= pkey->bytes);
+ } else {
+ memcpy(pkey->pData, val, pkey->bytes);
+ }
+
+ break;
+ }
+ }
+}
+
+static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t numOfExprs, SResultRowInfo* pResultRowInfo,
+ SSDataBlock* pBlock, int32_t scanFlag, int64_t* tsCols, SResultRowPosition* p) {
+ SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
+
+ SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
+
+ int32_t startPos = 0;
+ int32_t numOfOutput = pOperatorInfo->numOfExprs;
+ uint64_t groupId = pBlock->info.groupId;
+
+ SResultRow* pResult = NULL;
+
+ while (1) {
+ SListNode* pn = tdListGetHead(pResultRowInfo->openWindow);
+
+ SResultRowPosition* p1 = (SResultRowPosition*)pn->data;
+ if (p->pageId == p1->pageId && p->offset == p1->offset) {
+ break;
+ }
+
+ SResultRow* pr = getResultRowByPos(pInfo->aggSup.pResultBuf, p1);
+ ASSERT(pr->offset == p1->offset && pr->pageId == p1->pageId);
+
+ if (pr->closed) {
+ ASSERT(isResultRowInterpolated(pr, RESULT_ROW_START_INTERP) && isResultRowInterpolated(pr, RESULT_ROW_END_INTERP));
+ tdListPopHead(pResultRowInfo->openWindow);
+ continue;
+ }
+
+ STimeWindow w = pr->win;
+ int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &w, (scanFlag == MAIN_SCAN), &pResult, groupId, pInfo->binfo.pCtx,
+ numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo);
+ if (ret != TSDB_CODE_SUCCESS) {
+ longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
+ }
+
+ ASSERT(!isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP));
+
+ SGroupKeys *pTsKey = taosArrayGet(pInfo->pPrevValues, 0);
+ int64_t prevTs = *(int64_t*) pTsKey->pData;
+ doTimeWindowInterpolation(pInfo, numOfOutput, pBlock->pDataBlock, prevTs, -1, tsCols[startPos], startPos,
+ w.ekey, RESULT_ROW_END_INTERP);
+
+ setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
+ setNotInterpoWindowKey(pInfo->binfo.pCtx, numOfExprs, RESULT_ROW_START_INTERP);
+
+ doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &w, &pInfo->twAggSup.timeWindowData, startPos, 0, tsCols,
+ pBlock->info.rows, numOfExprs, pInfo->order);
+
+ if (isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) {
+ closeResultRow(pr);
+ tdListPopHead(pResultRowInfo->openWindow);
+ } else { // the remains are can not be closed yet.
+ break;
+ }
}
}
@@ -698,7 +752,7 @@ static int32_t saveResult(SResultRow* result, uint64_t groupId, SArray* pUpdated
return TSDB_CODE_SUCCESS;
}
}
-
+
SResKeyPos* newPos = taosMemoryMalloc(sizeof(SResKeyPos) + sizeof(uint64_t));
if (newPos == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
@@ -713,36 +767,23 @@ static int32_t saveResult(SResultRow* result, uint64_t groupId, SArray* pUpdated
}
static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock,
- uint64_t tableGroupId, SArray* pUpdated) {
+ int32_t scanFlag, SArray* pUpdated) {
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
- int32_t numOfOutput = pOperatorInfo->numOfExprs;
-
- int32_t step = 1;
- bool ascScan = (pInfo->order == TSDB_ORDER_ASC);
-
- // int32_t prevIndex = pResultRowInfo->curPos;
-
- TSKEY* tsCols = NULL;
- if (pBlock->pDataBlock != NULL) {
- SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex);
- tsCols = (int64_t*)pColDataInfo->pData;
- if (tsCols != NULL) {
- blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex);
- }
- }
-
- int32_t startPos = 0;
- TSKEY ts = getStartTsKey(&pBlock->info.window, tsCols, pBlock->info.rows, ascScan);
+ int32_t startPos = 0;
+ int32_t numOfOutput = pOperatorInfo->numOfExprs;
+ int64_t *tsCols = extractTsCol(pBlock, pInfo);
+ uint64_t tableGroupId = pBlock->info.groupId;
+ bool ascScan = (pInfo->order == TSDB_ORDER_ASC);
+ TSKEY ts = getStartTsKey(&pBlock->info.window, tsCols);
+ SResultRow* pResult = NULL;
STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval,
pInfo->interval.precision, &pInfo->win);
- bool masterScan = true;
- SResultRow* pResult = NULL;
- int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &win, masterScan, &pResult, tableGroupId, pInfo->binfo.pCtx,
+ int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pInfo->binfo.pCtx,
numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo);
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
@@ -758,63 +799,35 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
}
}
- int32_t forwardStep = 0;
TSKEY ekey = ascScan? win.ekey:win.skey;
- forwardStep =
- getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->order);
- ASSERT(forwardStep > 0);
+ int32_t forwardRows = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->order);
+ ASSERT(forwardRows > 0);
// prev time window not interpolation yet.
- // int32_t curIndex = pResultRowInfo->curPos;
-
-#if 0
- if (prevIndex != -1 && prevIndex < curIndex && pInfo->timeWindowInterpo) {
- for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already.
- SResultRow* pRes = getResultRow(pResultRowInfo, j);
- if (pRes->closed) {
- assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && resultRowInterpolated(pRes, RESULT_ROW_END_INTERP));
- continue;
- }
-
- STimeWindow w = pRes->win;
- ret = setTimeWindowOutputBuf(pResultRowInfo, pBlock->info.uid, &w, masterScan, &pResult, tableGroupId,
- pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup,
- pTaskInfo);
- if (ret != TSDB_CODE_SUCCESS) {
- longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
- }
-
- assert(!resultRowInterpolated(pResult, RESULT_ROW_END_INTERP));
- doTimeWindowInterpolation(pOperatorInfo, &pInfo->binfo, pBlock->pDataBlock, *(TSKEY*)pInfo->pRow[0], -1,
- tsCols[startPos], startPos, w.ekey, RESULT_ROW_END_INTERP);
-
- setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
- setNotInterpoWindowKey(pInfo->binfo.pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
-
- doApplyFunctions(pInfo->binfo.pCtx, &w, &pInfo->timeWindowData, startPos, 0, tsCols, pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
- }
+ if (pInfo->timeWindowInterpo) {
+ SResultRowPosition pos = addToOpenWindowList(pResultRowInfo, pResult);
+ doInterpUnclosedTimeWindow(pOperatorInfo, numOfOutput, pResultRowInfo, pBlock, scanFlag, tsCols, &pos);
// restore current time window
- ret = setTimeWindowOutputBuf(pResultRowInfo, pBlock->info.uid, &win, masterScan, &pResult, tableGroupId,
- pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup,
- pTaskInfo);
+ ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pInfo->binfo.pCtx,
+ numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo);
if (ret != TSDB_CODE_SUCCESS) {
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
- }
-#endif
- // window start key interpolation
- doWindowBorderInterpolation(pOperatorInfo, pBlock, pInfo->binfo.pCtx, pResult, &win, startPos, forwardStep,
- pInfo->order, false);
+ // window start key interpolation
+ doWindowBorderInterpolation(pInfo, pBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &win, startPos, forwardRows);
+ }
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
- doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &win, &pInfo->twAggSup.timeWindowData, startPos, forwardStep, tsCols,
- pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
+ doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &win, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols,
+ pBlock->info.rows, numOfOutput, pInfo->order);
+
+ doCloseWindow(pResultRowInfo, pInfo, pResult);
STimeWindow nextWin = win;
while (1) {
- int32_t prevEndPos = (forwardStep - 1) * step + startPos;
+ int32_t prevEndPos = forwardRows - 1 + startPos;
startPos = getNextQualifiedWindow(&pInfo->interval, &nextWin, &pBlock->info, tsCols, prevEndPos, pInfo->order);
if (startPos < 0) {
break;
@@ -822,12 +835,13 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
// null data, failed to allocate more memory buffer
int32_t code =
- setTimeWindowOutputBuf(pResultRowInfo, &nextWin, masterScan, &pResult, tableGroupId, pInfo->binfo.pCtx,
+ setTimeWindowOutputBuf(pResultRowInfo, &nextWin, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pInfo->binfo.pCtx,
numOfOutput, pInfo->binfo.rowCellInfoOffset, &pInfo->aggSup, pTaskInfo);
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
+
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE_SMA) {
@@ -839,24 +853,59 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
}
ekey = ascScan? nextWin.ekey:nextWin.skey;
- forwardStep =
+ forwardRows =
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->order);
// window start(end) key interpolation
- doWindowBorderInterpolation(pOperatorInfo, pBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep,
- pInfo->order, false);
+ doWindowBorderInterpolation(pInfo, pBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardRows);
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
- doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardStep, tsCols,
- pBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
+ doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols,
+ pBlock->info.rows, numOfOutput, pInfo->order);
+ doCloseWindow(pResultRowInfo, pInfo, pResult);
}
if (pInfo->timeWindowInterpo) {
- int32_t rowIndex = ascScan ? (pBlock->info.rows - 1) : 0;
- saveDataBlockLastRow(pInfo->pRow, pBlock->pDataBlock, rowIndex, pBlock->info.numOfCols);
+ saveDataBlockLastRow(pInfo->pPrevValues, pBlock, pInfo->pInterpCols);
}
+}
- // updateResultRowInfoActiveIndex(pResultRowInfo, &pInfo->win, pRuntimeEnv->current->lastKey, true, false);
+void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOperatorInfo* pInfo, SResultRow* pResult) {
+ // current result is done in computing final results.
+ if (pInfo->timeWindowInterpo && isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) {
+ closeResultRow(pResult);
+ tdListPopHead(pResultRowInfo->openWindow);
+ }
+}
+
+SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SResultRow* pResult) {
+ SResultRowPosition pos = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
+ SListNode* pn = tdListGetTail(pResultRowInfo->openWindow);
+ if (pn == NULL) {
+ tdListAppend(pResultRowInfo->openWindow, &pos);
+ return pos;
+ }
+
+ SResultRowPosition* px = (SResultRowPosition*)pn->data;
+ if (px->pageId != pos.pageId || px->offset != pos.offset) {
+ tdListAppend(pResultRowInfo->openWindow, &pos);
+ }
+
+ return pos;
+}
+
+int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo) {
+ TSKEY* tsCols = NULL;
+ if (pBlock->pDataBlock != NULL) {
+ SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex);
+ tsCols = (int64_t*)pColDataInfo->pData;
+
+ if (tsCols != NULL) {
+ blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex);
+ }
+ }
+
+ return tsCols;
}
static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
@@ -885,7 +934,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
STableQueryInfo* pTableQueryInfo = pInfo->pCurrent;
setIntervalQueryRange(pTableQueryInfo, pBlock->info.window.skey, &pTaskInfo->window);
- hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, pBlock->info.groupId, NULL);
+ hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, scanFlag, NULL);
#if 0 // test for encode/decode result info
if(pOperator->fpSet.encodeResultRow){
@@ -1016,8 +1065,9 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) {
}
SStateWindowOperatorInfo* pInfo = pOperator->info;
- SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
- SOptrBasicInfo* pBInfo = &pInfo->binfo;
+
+ SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
+ SOptrBasicInfo* pBInfo = &pInfo->binfo;
if (pOperator->status == OP_RES_TO_RETURN) {
doBuildResultDatablock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
@@ -1126,8 +1176,7 @@ static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type
}
}
-void doClearWindowImpl(SResultRowPosition* p1, SDiskbasedBuf* pResultBuf,
- SOptrBasicInfo* pBinfo, int32_t numOfOutput) {
+void doClearWindowImpl(SResultRowPosition* p1, SDiskbasedBuf* pResultBuf, SOptrBasicInfo* pBinfo, int32_t numOfOutput) {
SResultRow* pResult = getResultRowByPos(pResultBuf, p1);
SqlFunctionCtx* pCtx = pBinfo->pCtx;
for (int32_t i = 0; i < numOfOutput; ++i) {
@@ -1243,7 +1292,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
break;
}
- // The timewindows that overlaps the timestamps of the input pBlock need to be recalculated and return to the
+ // The timewindow that overlaps the timestamps of the input pBlock need to be recalculated and return to the
// caller. Note that all the time window are not close till now.
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, pInfo->order, MAIN_SCAN, true);
@@ -1258,9 +1307,10 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
continue;
}
- hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, pBlock->info.groupId, pUpdated);
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey);
+ hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdated);
}
+
closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup,
&pInfo->interval, pClosed);
finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pClosed,
@@ -1269,9 +1319,9 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE_SMA) {
taosArrayAddAll(pUpdated, pClosed);
}
+
taosArrayDestroy(pClosed);
- finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pUpdated,
- pInfo->binfo.rowCellInfoOffset);
+ finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset);
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
@@ -1309,7 +1359,7 @@ void destroyStreamFinalIntervalOperatorInfo(void* param, int32_t numOfOutput) {
}
}
-bool allInvertible(SqlFunctionCtx* pFCtx, int32_t numOfCols) {
+static bool allInvertible(SqlFunctionCtx* pFCtx, int32_t numOfCols) {
for (int32_t i = 0; i < numOfCols; i++) {
if (!fmIsInvertible(pFCtx[i].functionId)) {
return false;
@@ -1318,6 +1368,50 @@ bool allInvertible(SqlFunctionCtx* pFCtx, int32_t numOfCols) {
return true;
}
+static bool timeWindowinterpNeeded(SqlFunctionCtx* pCtx, int32_t numOfCols, SIntervalAggOperatorInfo* pInfo) {
+ // the primary timestamp column
+ bool needed = false;
+ pInfo->pInterpCols = taosArrayInit(4, sizeof(SColumn));
+ pInfo->pPrevValues = taosArrayInit(4, sizeof(SGroupKeys));
+
+ { // ts column
+ SColumn c = {0};
+ c.colId = 1;
+ c.slotId = pInfo->primaryTsIndex;
+ c.type = TSDB_DATA_TYPE_TIMESTAMP;
+ c.bytes = sizeof(int64_t);
+ taosArrayPush(pInfo->pInterpCols, &c);
+
+ SGroupKeys key = {0};
+ key.bytes = c.bytes;
+ key.type = c.type;
+ key.isNull = true; // to denote no value is assigned yet
+ key.pData = taosMemoryCalloc(1, c.bytes);
+ taosArrayPush(pInfo->pPrevValues, &key);
+ }
+
+ for(int32_t i = 0; i < numOfCols; ++i) {
+ SExprInfo* pExpr = pCtx[i].pExpr;
+
+ if (strcmp(pExpr->pExpr->_function.functionName, "twa") == 0) {
+ SFunctParam* pParam = &pExpr->base.pParam[0];
+
+ SColumn c = *pParam->pCol;
+ taosArrayPush(pInfo->pInterpCols, &c);
+ needed = true;
+
+ SGroupKeys key = {0};
+ key.bytes = c.bytes;
+ key.type = c.type;
+ key.isNull = false;
+ key.pData = taosMemoryCalloc(1, c.bytes);
+ taosArrayPush(pInfo->pPrevValues, &key);
+ }
+ }
+
+ return needed;
+}
+
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId,
STimeWindowAggSupp* pTwAggSupp, SExecTaskInfo* pTaskInfo) {
@@ -1327,11 +1421,12 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
goto _error;
}
- pInfo->order = TSDB_ORDER_ASC;
- pInfo->interval = *pInterval;
+ pInfo->win = pTaskInfo->window;
+ pInfo->order = TSDB_ORDER_ASC;
+ pInfo->interval = *pInterval;
pInfo->execModel = pTaskInfo->execModel;
- pInfo->win = pTaskInfo->window;
- pInfo->twAggSup = *pTwAggSupp;
+ pInfo->twAggSup = *pTwAggSupp;
+
pInfo->primaryTsIndex = primaryTsSlotId;
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
@@ -1341,23 +1436,30 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, pResBlock, keyBufSize, pTaskInfo->id.str);
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win);
+
pInfo->invertible = allInvertible(pInfo->binfo.pCtx, numOfCols);
pInfo->invertible = false; // Todo(liuyao): Dependent TSDB API
- if (code != TSDB_CODE_SUCCESS) {
+ pInfo->timeWindowInterpo = timeWindowinterpNeeded(pInfo->binfo.pCtx, numOfCols, pInfo);
+ if (pInfo->timeWindowInterpo) {
+ pInfo->binfo.resultRowInfo.openWindow = tdListNew(sizeof(SResultRowPosition));
+ }
+
+ // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo);
+ if (code != TSDB_CODE_SUCCESS /* || pInfo->pTableQueryInfo == NULL*/) {
goto _error;
}
initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1);
- pOperator->name = "TimeIntervalAggOperator";
+ pOperator->name = "TimeIntervalAggOperator";
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERVAL;
- pOperator->blocking = true;
- pOperator->status = OP_NOT_OPENED;
- pOperator->pExpr = pExprInfo;
- pOperator->pTaskInfo = pTaskInfo;
- pOperator->numOfExprs = numOfCols;
- pOperator->info = pInfo;
+ pOperator->blocking = true;
+ pOperator->status = OP_NOT_OPENED;
+ pOperator->pExpr = pExprInfo;
+ pOperator->pTaskInfo = pTaskInfo;
+ pOperator->numOfExprs = numOfCols;
+ pOperator->info = pInfo;
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL,
destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
@@ -1816,7 +1918,7 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB
bool ascScan = true;
TSKEY* tsCols = NULL;
SResultRow* pResult = NULL;
- int32_t forwardStep = 0;
+ int32_t forwardRows = 0;
if (pSDataBlock->pDataBlock != NULL) {
SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
@@ -1826,7 +1928,7 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB
}
int32_t startPos = ascScan ? 0 : (pSDataBlock->info.rows - 1);
- TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols, pSDataBlock->info.rows, ascScan);
+ TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols);
STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts,
&pInfo->interval, pInfo->interval.precision, NULL);
while (1) {
@@ -1841,15 +1943,15 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB
pos->pos = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
*(int64_t*)pos->key = pResult->win.skey;
taosArrayPush(pUpdated, &pos);
- forwardStep =
+ forwardRows =
getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
// window start(end) key interpolation
- doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep,
- pInfo->order, false);
+ // disable it temporarily
+// doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardRows);
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
- doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardStep, tsCols,
+ doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols,
pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
- int32_t prevEndPos = (forwardStep - 1) * step + startPos;
+ int32_t prevEndPos = (forwardRows - 1) * step + startPos;
startPos = getNextQualifiedWindow(&pInfo->interval, &nextWin, &pSDataBlock->info, tsCols, prevEndPos, pInfo->order);
if (startPos < 0) {
break;
@@ -2165,7 +2267,7 @@ static int32_t setWindowOutputBuf(SResultWindowInfo* pWinInfo, SResultRow** pRes
}
if (pWinInfo->pos.pageId == -1) {
- *pResult = getNewResultRow_rv(pAggSup->pResultBuf, groupId, pAggSup->resultRowSize);
+ *pResult = getNewResultRow(pAggSup->pResultBuf, groupId, pAggSup->resultRowSize);
if (*pResult == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
@@ -2300,7 +2402,7 @@ static void doStreamSessionWindowAggImpl(SOperatorInfo* pOperator,
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
// window start(end) key interpolation
- // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardStep,
+ // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardRows,
// pInfo->order, false);
int32_t winNum = getNumCompactWindow(pAggSup->pResultRows, winIndex, gap);
if (winNum > 0) {
@@ -2497,7 +2599,7 @@ static SSDataBlock* doStreamSessionWindowAgg(SOperatorInfo* pOperator) {
}
// restore the value
pOperator->status = OP_RES_TO_RETURN;
-
+
SArray* pClosed = taosArrayInit(16, POINTER_BYTES);
closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pClosed,
pInfo->twAggSup.calTrigger);
diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h
index cac86be91752575feba4dcb016eddd84564389d1..68b83f4a1955c72e119dcadd5d409ce10639e5e1 100644
--- a/source/libs/function/inc/builtinsimpl.h
+++ b/source/libs/function/inc/builtinsimpl.h
@@ -140,6 +140,10 @@ bool uniqueFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo)
int32_t uniqueFunction(SqlFunctionCtx *pCtx);
//int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
+bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
+bool twaFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
+int32_t twaFunction(SqlFunctionCtx *pCtx);
+int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock);
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
diff --git a/source/libs/function/inc/taggfunction.h b/source/libs/function/inc/taggfunction.h
index d779cf50f4ce019ddcea41b71720347d54a34e96..c3d61d426d889cecda0723b48c6c26eae16316ff 100644
--- a/source/libs/function/inc/taggfunction.h
+++ b/source/libs/function/inc/taggfunction.h
@@ -52,13 +52,6 @@ typedef struct SInterpInfoDetail {
int8_t primaryCol;
} SInterpInfoDetail;
-typedef struct STwaInfo {
- int8_t hasResult; // flag to denote has value
- double dOutput;
- SPoint1 p;
- STimeWindow win;
-} STwaInfo;
-
bool topbot_datablock_filter(SqlFunctionCtx *pCtx, const char *minval, const char *maxval);
/**
diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c
index 5560c9c1d5ec8887dacd1ea56eec2dba5673bde5..c9c63169c931cc03fdf58d16f551f6abbdc8ba85 100644
--- a/source/libs/function/src/builtins.c
+++ b/source/libs/function/src/builtins.c
@@ -18,7 +18,6 @@
#include "querynodes.h"
#include "scalar.h"
#include "taoserror.h"
-#include "tdatablock.h"
static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) {
va_list vArgList;
@@ -362,7 +361,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
pValue->notReserved = true;
- uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
+ paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
if (!IS_INTEGER_TYPE(paraType)) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}
@@ -456,7 +455,7 @@ static int32_t translateHLL(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
"The input parameter of HYPERLOGLOG function can only be column");
}
- pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_UBIGINT].bytes, .type = TSDB_DATA_TYPE_UBIGINT};
+ pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
return TSDB_CODE_SUCCESS;
}
@@ -464,12 +463,9 @@ static bool validateStateOper(const SValueNode* pVal) {
if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) {
return false;
}
- return (0 == strcasecmp(varDataVal(pVal->datum.p), "GT") ||
- 0 == strcasecmp(varDataVal(pVal->datum.p), "GE") ||
- 0 == strcasecmp(varDataVal(pVal->datum.p), "LT") ||
- 0 == strcasecmp(varDataVal(pVal->datum.p), "LE") ||
- 0 == strcasecmp(varDataVal(pVal->datum.p), "EQ") ||
- 0 == strcasecmp(varDataVal(pVal->datum.p), "NE"));
+ return (0 == strcasecmp(varDataVal(pVal->datum.p), "GT") || 0 == strcasecmp(varDataVal(pVal->datum.p), "GE") ||
+ 0 == strcasecmp(varDataVal(pVal->datum.p), "LT") || 0 == strcasecmp(varDataVal(pVal->datum.p), "LE") ||
+ 0 == strcasecmp(varDataVal(pVal->datum.p), "EQ") || 0 == strcasecmp(varDataVal(pVal->datum.p), "NE"));
}
static int32_t translateStateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
@@ -553,7 +549,6 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
"STATEDURATION function time unit parameter should be greater than db precision");
}
-
pValue->notReserved = true;
}
@@ -838,7 +833,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
int32_t resultBytes = 0;
int32_t sepBytes = 0;
- //concat_ws separator should be constant string
+ // concat_ws separator should be constant string
if (hasSep) {
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
if (nodeType(pPara) != QUERY_NODE_VALUE) {
@@ -851,7 +846,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
for (int32_t i = 0; i < numOfParams; ++i) {
SNode* pPara = nodesListGetNode(pFunc->pParameterList, i);
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
- if (!IS_VAR_DATA_TYPE(paraType) && TSDB_DATA_TYPE_NULL != paraType) {
+ if (!IS_VAR_DATA_TYPE(paraType) && !IS_NULL_TYPE(paraType)) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}
if (TSDB_DATA_TYPE_NCHAR == paraType) {
@@ -864,6 +859,12 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes;
int32_t factor = 1;
+ if (IS_NULL_TYPE(paraType)) {
+ resultType = TSDB_DATA_TYPE_VARCHAR;
+ resultBytes = 0;
+ sepBytes = 0;
+ break;
+ }
if (TSDB_DATA_TYPE_NCHAR == resultType && TSDB_DATA_TYPE_VARCHAR == paraType) {
factor *= TSDB_NCHAR_SIZE;
}
@@ -964,7 +965,7 @@ static bool validateTimezoneFormat(const SValueNode* pVal) {
return false;
}
- char *tz = varDataVal(pVal->datum.p);
+ char* tz = varDataVal(pVal->datum.p);
int32_t len = varDataLen(pVal->datum.p);
if (len == 0) {
@@ -1008,20 +1009,20 @@ static bool validateTimezoneFormat(const SValueNode* pVal) {
}
void static addTimezoneParam(SNodeList* pList) {
- char buf[6] = {0};
- time_t t = taosTime(NULL);
- struct tm *tmInfo = taosLocalTime(&t, NULL);
+ char buf[6] = {0};
+ time_t t = taosTime(NULL);
+ struct tm* tmInfo = taosLocalTime(&t, NULL);
strftime(buf, sizeof(buf), "%z", tmInfo);
int32_t len = (int32_t)strlen(buf);
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
pVal->literal = strndup(buf, len);
- pVal->isDuration =false;
+ pVal->isDuration = false;
pVal->translate = true;
pVal->node.resType.type = TSDB_DATA_TYPE_BINARY;
pVal->node.resType.bytes = len + VARSTR_HEADER_SIZE;
pVal->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
- pVal->datum.p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE +1);
+ pVal->datum.p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE + 1);
varDataSetLen(pVal->datum.p, len);
strncpy(varDataVal(pVal->datum.p), pVal->literal, len);
@@ -1034,25 +1035,24 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
}
- //param0
+ // param0
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
if (!IS_INTEGER_TYPE(paraType) && TSDB_DATA_TYPE_TIMESTAMP != paraType) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}
- //param1
+ // param1
if (numOfParams == 2) {
SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1);
if (!validateTimezoneFormat(pValue)) {
- return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
- "Invalid timzone format");
+ return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Invalid timzone format");
}
- } else { //add default client timezone
+ } else { // add default client timezone
addTimezoneParam(pFunc->pParameterList);
}
- //set result type
+ // set result type
pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY};
return TSDB_CODE_SUCCESS;
}
@@ -1312,6 +1312,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.finalizeFunc = firstLastFinalize,
.combineFunc = lastCombine,
},
+ {
+ .name = "twa",
+ .type = FUNCTION_TYPE_TWA,
+ .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC,
+ .translateFunc = translateInNumOutDou,
+ .getEnvFunc = getTwaFuncEnv,
+ .initFunc = twaFunctionSetup,
+ .processFunc = twaFunction,
+ .finalizeFunc = twaFinalize
+ },
{
.name = "histogram",
.type = FUNCTION_TYPE_HISTOGRAM,
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index a7e93246b765199369eda8e7aba0da94a49fce3b..2f698b906cba23da49241d824ac37544514a32cc 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -14,6 +14,7 @@
*/
#include "builtinsimpl.h"
+#include "tglobal.h"
#include "cJSON.h"
#include "function.h"
#include "querynodes.h"
@@ -300,7 +301,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
- //pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
+ pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
char* in = GET_ROWCELL_INTERBUF(pResInfo);
colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes);
@@ -357,7 +358,7 @@ bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
return true;
}
-static FORCE_INLINE int32_t getNumofElem(SqlFunctionCtx* pCtx) {
+static FORCE_INLINE int32_t getNumOfElems(SqlFunctionCtx* pCtx) {
int32_t numOfElem = 0;
/*
@@ -392,11 +393,12 @@ static FORCE_INLINE int32_t getNumofElem(SqlFunctionCtx* pCtx) {
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
*/
int32_t countFunction(SqlFunctionCtx* pCtx) {
- int32_t numOfElem = getNumofElem(pCtx);
- SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
+ int32_t numOfElem = getNumOfElems(pCtx);
+ SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
SInputColumnInfoData* pInput = &pCtx->input;
- int32_t type = pInput->pData[0]->info.type;
+
+ int32_t type = pInput->pData[0]->info.type;
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
if (IS_NULL_TYPE(type)) {
@@ -407,12 +409,17 @@ int32_t countFunction(SqlFunctionCtx* pCtx) {
*((int64_t*)buf) += numOfElem;
}
- SET_VAL(pResInfo, numOfElem, 1);
+ if (tsCountAlwaysReturnValue) {
+ pResInfo->numOfRes = 1;
+ } else {
+ SET_VAL(pResInfo, 1, 1);
+ }
+
return TSDB_CODE_SUCCESS;
}
int32_t countInvertFunction(SqlFunctionCtx* pCtx) {
- int32_t numOfElem = getNumofElem(pCtx);
+ int32_t numOfElem = getNumOfElems(pCtx);
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
@@ -829,8 +836,10 @@ int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SInputColumnInfoData* pInput = &pCtx->input;
- int32_t type = pInput->pData[0]->info.type;
- SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+
+ int32_t type = pInput->pData[0]->info.type;
+ SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+
if (IS_INTEGER_TYPE(type)) {
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
} else {
@@ -1315,13 +1324,11 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SMinmaxResInfo* pRes = GET_ROWCELL_INTERBUF(pEntryInfo);
- int32_t type = pCtx->input.pData[0]->info.type;
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
+ int32_t currentRow = pBlock->info.rows;
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
-
- // todo assign the tag value
- int32_t currentRow = pBlock->info.rows;
+ pEntryInfo->isNullRes = (pEntryInfo->numOfRes == 0);
if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) {
float v = *(double*) &pRes->v;
@@ -1330,7 +1337,10 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
colDataAppend(pCol, currentRow, (const char*)&pRes->v, pEntryInfo->isNullRes);
}
- setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow);
+ if (pEntryInfo->numOfRes > 0) {
+ setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow);
+ }
+
return pEntryInfo->numOfRes;
}
@@ -1832,7 +1842,7 @@ bool percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultI
}
int32_t percentileFunction(SqlFunctionCtx* pCtx) {
- int32_t notNullElems = 0;
+ int32_t numOfElems = 0;
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
SInputColumnInfoData* pInput = &pCtx->input;
@@ -1910,11 +1920,11 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
}
char* data = colDataGetData(pCol, i);
- notNullElems += 1;
+ numOfElems += 1;
tMemBucketPut(pInfo->pMemBucket, data, 1);
}
- SET_VAL(pResInfo, notNullElems, 1);
+ SET_VAL(pResInfo, numOfElems, 1);
}
return TSDB_CODE_SUCCESS;
@@ -1988,7 +1998,7 @@ bool apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResult
}
int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
- int32_t notNullElems = 0;
+ int32_t numOfElems = 0;
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
SInputColumnInfoData* pInput = &pCtx->input;
@@ -2005,7 +2015,7 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
if (colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
- notNullElems += 1;
+ numOfElems += 1;
char* data = colDataGetData(pCol, i);
double v = 0; // value
@@ -2018,7 +2028,7 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
if (colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
- notNullElems += 1;
+ numOfElems += 1;
char* data = colDataGetData(pCol, i);
double v = 0;
@@ -2027,7 +2037,7 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
}
}
- SET_VAL(pResInfo, notNullElems, 1);
+ SET_VAL(pResInfo, numOfElems, 1);
return TSDB_CODE_SUCCESS;
}
@@ -3240,13 +3250,13 @@ static uint64_t hllCountCnt(uint8_t *buckets) {
z += buckethisto[j];
z *= 0.5;
}
+
z += m * hllSigma(buckethisto[0]/(double)m);
double E = (double)llroundl(HLL_ALPHA_INF*m*m/z);
return (uint64_t) E;
}
-
int32_t hllFunction(SqlFunctionCtx *pCtx) {
SHLLInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
@@ -3279,7 +3289,6 @@ int32_t hllFunction(SqlFunctionCtx *pCtx) {
if (count > oldcount) {
pInfo->buckets[index] = count;
}
-
}
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
@@ -3287,9 +3296,13 @@ int32_t hllFunction(SqlFunctionCtx *pCtx) {
}
int32_t hllFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
- SHLLInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+ SResultRowEntryInfo *pInfo = GET_RES_INFO(pCtx);
- pInfo->result = hllCountCnt(pInfo->buckets);
+ SHLLInfo* pHllInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+ pHllInfo->result = hllCountCnt(pHllInfo->buckets);
+ if (tsCountAlwaysReturnValue && pHllInfo->result == 0) {
+ pInfo->numOfRes = 1;
+ }
return functionFinalize(pCtx, pBlock);
}
@@ -3695,7 +3708,6 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx) {
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
SColumnInfoData* pInputCol = pInput->pData[0];
- SColumnInfoData* pTsOutput = pCtx->pTsOutput;
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
int32_t startOffset = pCtx->offset;
@@ -3718,24 +3730,6 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx) {
return pInfo->numSampled;
}
-//int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
-// SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
-// SSampleInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
-// int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
-// SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
-//
-// //int32_t currentRow = pBlock->info.rows;
-// pResInfo->numOfRes = pInfo->numSampled;
-//
-// for (int32_t i = 0; i < pInfo->numSampled; ++i) {
-// colDataAppend(pCol, i, pInfo->data + i * pInfo->colBytes, false);
-// //TODO: handle ts output
-// }
-//
-// return pResInfo->numOfRes;
-//}
-
-
bool getTailFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1);
@@ -3812,7 +3806,6 @@ int32_t tailFunction(SqlFunctionCtx* pCtx) {
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
SColumnInfoData* pInputCol = pInput->pData[0];
- SColumnInfoData* pTsOutput = pCtx->pTsOutput;
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
int32_t startOffset = pCtx->offset;
@@ -3879,7 +3872,6 @@ bool uniqueFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
pInfo->numOfPoints = 0;
pInfo->colType = pCtx->resDataInfo.type;
pInfo->colBytes = pCtx->resDataInfo.bytes;
- pInfo->hasNull = false;
if (pInfo->pHash != NULL) {
taosHashClear(pInfo->pHash);
} else {
@@ -3917,8 +3909,6 @@ static void doUniqueAdd(SUniqueInfo* pInfo, char *data, TSKEY ts, bool isNull) {
} else if (pHashItem->timestamp > ts) {
pHashItem->timestamp = ts;
}
-
- return;
}
int32_t uniqueFunction(SqlFunctionCtx* pCtx) {
@@ -3960,7 +3950,7 @@ int32_t uniqueFunction(SqlFunctionCtx* pCtx) {
int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
- SUniqueInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+ SUniqueInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
@@ -3973,3 +3963,260 @@ int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return pResInfo->numOfRes;
}
+typedef struct STwaInfo {
+ double dOutput;
+ SPoint1 p;
+ STimeWindow win;
+} STwaInfo;
+
+bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
+ pEnv->calcMemSize = sizeof(STwaInfo);
+ return true;
+}
+
+bool twaFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
+ if (!functionSetup(pCtx, pResultInfo)) {
+ return false;
+ }
+
+ STwaInfo *pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
+ pInfo->p.key = INT64_MIN;
+ pInfo->win = TSWINDOW_INITIALIZER;
+ return true;
+}
+
+static double twa_get_area(SPoint1 s, SPoint1 e) {
+ if ((s.val >= 0 && e.val >= 0)|| (s.val <=0 && e.val <= 0)) {
+ return (s.val + e.val) * (e.key - s.key) / 2;
+ }
+
+ double x = (s.key * e.val - e.key * s.val)/(e.val - s.val);
+ double val = (s.val * (x - s.key) + e.val * (e.key - x)) / 2;
+ return val;
+}
+
+#define INIT_INTP_POINT(_p, _k, _v) \
+ do { \
+ (_p).key = (_k); \
+ (_p).val = (_v); \
+ } while (0)
+
+int32_t twaFunction(SqlFunctionCtx* pCtx) {
+ SInputColumnInfoData* pInput = &pCtx->input;
+ SColumnInfoData* pInputCol = pInput->pData[0];
+
+ TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
+
+ SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
+
+ STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
+ SPoint1 *last = &pInfo->p;
+ int32_t numOfElems = 0;
+
+ int32_t i = pInput->startRowIndex;
+ if (pCtx->start.key != INT64_MIN) {
+ ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) ||
+ (pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC));
+
+ ASSERT(last->key == INT64_MIN);
+ last->key = tsList[i];
+
+ GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
+
+ pInfo->dOutput += twa_get_area(pCtx->start, *last);
+ pInfo->win.skey = pCtx->start.key;
+ numOfElems++;
+ i += 1;
+ } else if (pInfo->p.key == INT64_MIN) {
+ last->key = tsList[i];
+ GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i));
+
+ pInfo->win.skey = last->key;
+ numOfElems++;
+ i += 1;
+ }
+
+ SPoint1 st = {0};
+
+ // calculate the value of
+ switch(pInputCol->info.type) {
+ case TSDB_DATA_TYPE_TINYINT: {
+ int8_t *val = (int8_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+
+ case TSDB_DATA_TYPE_SMALLINT: {
+ int16_t *val = (int16_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_INT: {
+ int32_t *val = (int32_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_BIGINT: {
+ int64_t *val = (int64_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_FLOAT: {
+ float *val = (float*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_DOUBLE: {
+ double *val = (double*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_UTINYINT: {
+ uint8_t *val = (uint8_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_USMALLINT: {
+ uint16_t *val = (uint16_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_UINT: {
+ uint32_t *val = (uint32_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+ case TSDB_DATA_TYPE_UBIGINT: {
+ uint64_t *val = (uint64_t*) colDataGetData(pInputCol, 0);
+ for (; i < pInput->numOfRows + pInput->startRowIndex; i += 1) {
+ if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
+ continue;
+ }
+
+ INIT_INTP_POINT(st, tsList[i], val[i]);
+ pInfo->dOutput += twa_get_area(pInfo->p, st);
+ pInfo->p = st;
+ }
+ break;
+ }
+
+ default: ASSERT(0);
+ }
+
+ // the last interpolated time window value
+ if (pCtx->end.key != INT64_MIN) {
+ pInfo->dOutput += twa_get_area(pInfo->p, pCtx->end);
+ pInfo->p = pCtx->end;
+ }
+
+ pInfo->win.ekey = pInfo->p.key;
+
+ SET_VAL(pResInfo, numOfElems, 1);
+ return TSDB_CODE_SUCCESS;
+}
+
+/*
+ * To copy the input to interResBuf to avoid the input buffer space be over writen
+ * by next input data. The TWA function only applies to each table, so no merge procedure
+ * is required, we simply copy to the resut ot interResBuffer.
+ */
+//void twa_function_copy(SQLFunctionCtx *pCtx) {
+// assert(pCtx->inputType == TSDB_DATA_TYPE_BINARY);
+// SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
+//
+// memcpy(GET_ROWCELL_INTERBUF(pResInfo), pCtx->pInput, (size_t)pCtx->inputBytes);
+// pResInfo->hasResult = ((STwaInfo *)pCtx->pInput)->hasResult;
+//}
+
+int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
+ SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
+
+ STwaInfo *pInfo = (STwaInfo *)GET_ROWCELL_INTERBUF(pResInfo);
+ if (pResInfo->numOfRes == 0) {
+ pResInfo->isNullRes = 1;
+ } else {
+ // assert(pInfo->win.ekey == pInfo->p.key && pInfo->hasResult == pResInfo->hasResult);
+ if (pInfo->win.ekey == pInfo->win.skey) {
+ pInfo->dOutput = pInfo->p.val;
+ } else {
+ pInfo->dOutput = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey);
+ }
+
+ pResInfo->numOfRes = 1;
+ }
+
+ return functionFinalize(pCtx, pBlock);
+}
+
diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c
index 950655e480b2b3413f26bc56d4771461b0dc4277..e683a38cbd1fd97ac7ba081a65f2af8ac18b8fee 100644
--- a/source/libs/function/src/taggfunction.c
+++ b/source/libs/function/src/taggfunction.c
@@ -236,7 +236,7 @@ bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry) {
bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry) {
return pEntry->initialized;
}
-
+#if 0
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, SResultDataInfo* pInfo, int16_t extLength,
bool isSuperTable/*, SUdfInfo* pUdfInfo*/) {
if (!isValidDataType(dataType)) {
@@ -470,6 +470,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
return TSDB_CODE_SUCCESS;
}
+#endif
static bool function_setup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
if (pResultInfo->initialized) {
diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c
index b91af2d1577fc994ccaa6b11b8e9044ffb88b594..703b19ced7e1abeee312a414aafe6b34b936c271 100644
--- a/source/libs/function/src/texpr.c
+++ b/source/libs/function/src/texpr.c
@@ -36,12 +36,7 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
if (pNode->nodeType == TEXPR_BINARYEXPR_NODE || pNode->nodeType == TEXPR_UNARYEXPR_NODE) {
doExprTreeDestroy(&pNode, fp);
- } else if (pNode->nodeType == TEXPR_VALUE_NODE) {
- taosVariantDestroy(pNode->pVal);
- } else if (pNode->nodeType == TEXPR_COL_NODE) {
- taosMemoryFreeClear(pNode->pSchema);
}
-
taosMemoryFree(pNode);
}
@@ -49,15 +44,6 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
if (*pExpr == NULL) {
return;
}
-
- int32_t type = (*pExpr)->nodeType;
- if (type == TEXPR_VALUE_NODE) {
- taosVariantDestroy((*pExpr)->pVal);
- taosMemoryFree((*pExpr)->pVal);
- } else if (type == TEXPR_COL_NODE) {
- taosMemoryFree((*pExpr)->pSchema);
- }
-
taosMemoryFree(*pExpr);
*pExpr = NULL;
}
diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c
index 441648e52b2ef78326d73d1944bcfbfd0009abc6..472d67260730ca10522ee0d07fc1d608b132688e 100644
--- a/source/libs/function/src/tudf.c
+++ b/source/libs/function/src/tudf.c
@@ -66,7 +66,7 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
}
static int32_t udfSpawnUdfd(SUdfdData* pData) {
- fnInfo("dnode start spawning udfd");
+ fnInfo("start to init udfd");
uv_process_options_t options = {0};
char path[PATH_MAX] = {0};
@@ -140,6 +140,8 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) {
if (err != 0) {
fnError("can not spawn udfd. path: %s, error: %s", path, uv_strerror(err));
+ } else {
+ fnInfo("udfd is initialized");
}
return err;
}
diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c
index 766746dd2a695076d3ab524076bfa143ceba1c54..b41006b6dddf68e8d239e7c9c6bd348ee6177a9a 100644
--- a/source/libs/index/src/indexFilter.c
+++ b/source/libs/index/src/indexFilter.c
@@ -265,23 +265,24 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
typedef int (*Filter)(void *a, void *b, int16_t dtype);
int sifGreaterThan(void *a, void *b, int16_t dtype) {
- __compar_fn_t func = indexGetCompar(dtype);
+ __compar_fn_t func = getComparFunc(dtype, 0);
return tDoCompare(func, QUERY_GREATER_THAN, a, b);
}
int sifGreaterEqual(void *a, void *b, int16_t dtype) {
- __compar_fn_t func = indexGetCompar(dtype);
+ __compar_fn_t func = getComparFunc(dtype, 0);
return tDoCompare(func, QUERY_GREATER_EQUAL, a, b);
}
int sifLessEqual(void *a, void *b, int16_t dtype) {
- __compar_fn_t func = indexGetCompar(dtype);
+ __compar_fn_t func = getComparFunc(dtype, 0);
return tDoCompare(func, QUERY_LESS_EQUAL, a, b);
}
int sifLessThan(void *a, void *b, int16_t dtype) {
- __compar_fn_t func = indexGetCompar(dtype);
+ __compar_fn_t func = getComparFunc(dtype, 0);
return (int)tDoCompare(func, QUERY_LESS_THAN, a, b);
}
int sifEqual(void *a, void *b, int16_t dtype) {
- __compar_fn_t func = indexGetCompar(dtype);
+ __compar_fn_t func = getComparFunc(dtype, 0);
+ //__compar_fn_t func = indexGetCompar(dtype);
return (int)tDoCompare(func, QUERY_TERM, a, b);
}
static Filter sifGetFilterFunc(EIndexQueryType type, bool *reverse) {
@@ -397,38 +398,62 @@ static int32_t sifDefaultFunc(SIFParam *left, SIFParam *right, SIFParam *output)
return TSDB_CODE_QRY_INVALID_INPUT;
}
-static sif_func_t sifGetOperFn(int32_t funcId) {
+static int32_t sifGetOperFn(int32_t funcId, sif_func_t *func, SIdxFltStatus *status) {
// impl later
+ *status = SFLT_ACCURATE_INDEX;
switch (funcId) {
case OP_TYPE_GREATER_THAN:
- return sifGreaterThanFunc;
+ *func = sifGreaterThanFunc;
+ return 0;
case OP_TYPE_GREATER_EQUAL:
- return sifGreaterEqualFunc;
+ *func = sifGreaterEqualFunc;
+ return 0;
case OP_TYPE_LOWER_THAN:
- return sifLessThanFunc;
+ *func = sifLessThanFunc;
+ return 0;
case OP_TYPE_LOWER_EQUAL:
- return sifLessEqualFunc;
+ *func = sifLessEqualFunc;
+ return 0;
case OP_TYPE_EQUAL:
- return sifEqualFunc;
+ *func = sifEqualFunc;
+ return 0;
case OP_TYPE_NOT_EQUAL:
- return sifNotEqualFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifNotEqualFunc;
+ return 0;
case OP_TYPE_IN:
- return sifInFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifInFunc;
+ return 0;
case OP_TYPE_NOT_IN:
- return sifNotInFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifNotInFunc;
+ return 0;
case OP_TYPE_LIKE:
- return sifLikeFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifLikeFunc;
+ return 0;
case OP_TYPE_NOT_LIKE:
- return sifNotLikeFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifNotLikeFunc;
+ return 0;
case OP_TYPE_MATCH:
- return sifMatchFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifMatchFunc;
+ return 0;
case OP_TYPE_NMATCH:
- return sifNotMatchFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifNotMatchFunc;
+ return 0;
default:
- return sifNullFunc;
+ *status = SFLT_NOT_INDEX;
+ *func = sifNullFunc;
+ return 0;
}
- return sifNullFunc;
+ return 0;
}
+// typedef struct filterFuncDict {
+
static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
int32_t code = 0;
int32_t nParam = sifGetOperParamNum(node->opType);
@@ -441,18 +466,14 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
// ugly code, refactor later
output->arg = ctx->arg;
- sif_func_t operFn = sifGetOperFn(node->opType);
- if (ctx->noExec && operFn == NULL) {
- output->status = SFLT_NOT_INDEX;
- } else {
- output->status = SFLT_ACCURATE_INDEX;
- }
+ sif_func_t operFn = sifNullFunc;
+ code = sifGetOperFn(node->opType, &operFn, &output->status);
if (ctx->noExec) {
SIF_RET(code);
+ } else {
+ return operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output);
}
-
- return operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output);
_return:
taosMemoryFree(params);
SIF_RET(code);
@@ -477,7 +498,7 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou
} else if (node->condType == LOGIC_COND_TYPE_OR) {
taosArrayAddAll(output->result, params[m].result);
} else if (node->condType == LOGIC_COND_TYPE_NOT) {
- taosArrayAddAll(output->result, params[m].result);
+ // taosArrayAddAll(output->result, params[m].result);
}
}
} else {
diff --git a/source/libs/index/test/CMakeLists.txt b/source/libs/index/test/CMakeLists.txt
index 2835084a81b87e358916c20ce0e6c70cf6884021..040460ae5c9662404182b93780075cc88cb93c57 100644
--- a/source/libs/index/test/CMakeLists.txt
+++ b/source/libs/index/test/CMakeLists.txt
@@ -92,16 +92,14 @@ target_link_libraries (idxJsonUT
index
)
-if(NOT TD_WINDOWS)
- add_test(
- NAME idxtest
- COMMAND idxTest
- )
- add_test(
- NAME idxJsonUT
- COMMAND idxJsonUT
- )
-endif(NOT TD_WINDOWS)
+add_test(
+ NAME idxtest
+ COMMAND idxTest
+)
+add_test(
+ NAME idxJsonUT
+ COMMAND idxJsonUT
+)
add_test(
NAME idxUtilUT
COMMAND idxUtilUT
diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c
index 94661388cb90e8ac41a7cca5e24871db8b8d7d98..35b4da7013f2c9cce51c1382368cc38cd9aafa93 100644
--- a/source/libs/nodes/src/nodesCloneFuncs.c
+++ b/source/libs/nodes/src/nodesCloneFuncs.c
@@ -142,7 +142,7 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
break;
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_VARCHAR:
- case TSDB_DATA_TYPE_VARBINARY:{
+ case TSDB_DATA_TYPE_VARBINARY: {
int32_t len = varDataTLen(pSrc->datum.p) + 1;
pDst->datum.p = taosMemoryCalloc(1, len);
if (NULL == pDst->datum.p) {
@@ -399,6 +399,7 @@ static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pD
COPY_SCALAR_FIELD(triggerType);
COPY_SCALAR_FIELD(watermark);
COPY_SCALAR_FIELD(filesFactor);
+ COPY_SCALAR_FIELD(stmInterAlgo);
return (SNode*)pDst;
}
diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c
index 4bce6381cde1cda187d11f5691bdb35b4e3dfca6..54754ace51558ed23baf56dd9155c5ca1a41dbe3 100644
--- a/source/libs/nodes/src/nodesCodeFuncs.c
+++ b/source/libs/nodes/src/nodesCodeFuncs.c
@@ -230,6 +230,10 @@ const char* nodesNodeName(ENodeType type) {
return "PhysiInterval";
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
return "PhysiStreamInterval";
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
+ return "PhysiStreamFinalInterval";
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
+ return "PhysiStreamSemiInterval";
case QUERY_NODE_PHYSICAL_PLAN_FILL:
return "PhysiFill";
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
@@ -3611,6 +3615,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
return physiSortNodeToJson(pObj, pJson);
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
return physiIntervalNodeToJson(pObj, pJson);
case QUERY_NODE_PHYSICAL_PLAN_FILL:
return physiFillNodeToJson(pObj, pJson);
@@ -3728,6 +3734,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return jsonToPhysiSortNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
return jsonToPhysiIntervalNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_PLAN_FILL:
return jsonToPhysiFillNode(pJson, pObj);
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 51111ad864568649f5757e9b20f5f14190271c1a..76f15afc8e050ee57b4bc5b774f0fd1e57338972 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -260,6 +260,10 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SIntervalPhysiNode));
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
return makeNode(type, sizeof(SStreamIntervalPhysiNode));
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
+ return makeNode(type, sizeof(SStreamFinalIntervalPhysiNode));
+ case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
+ return makeNode(type, sizeof(SStreamSemiIntervalPhysiNode));
case QUERY_NODE_PHYSICAL_PLAN_FILL:
return makeNode(type, sizeof(SFillPhysiNode));
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h
index 3efe6700d2339b2234d33f868c0b42fa993d1b64..8ec20cde5a07b54a5609a6097316e4ae5e538a83 100644
--- a/source/libs/parser/inc/parInt.h
+++ b/source/libs/parser/inc/parInt.h
@@ -32,6 +32,7 @@ int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery);
int32_t translate(SParseContext* pParseCxt, SQuery* pQuery);
int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery);
+int32_t isNotSchemalessDb(SParseContext* pContext, char *dbName);
#ifdef __cplusplus
}
diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index 68c9684c97ac8eba986a339b7618e51bc02d7d79..18c1341da86bb2306cc6cb2e5b1036e9bbba7a8e 100644
--- a/source/libs/parser/src/parAstParser.c
+++ b/source/libs/parser/src/parAstParser.c
@@ -124,6 +124,10 @@ static EDealRes collectMetaKeyFromRealTable(SCollectMetaKeyFromExprCxt* pCxt, SR
pCxt->errCode = reserveUserAuthInCache(pCxt->pComCxt->pParseCxt->acctId, pCxt->pComCxt->pParseCxt->pUser,
pRealTable->table.dbName, AUTH_TYPE_READ, pCxt->pComCxt->pMetaCache);
}
+ if (TSDB_CODE_SUCCESS == pCxt->errCode) {
+ pCxt->errCode =
+ reserveDbVgInfoInCache(pCxt->pComCxt->pParseCxt->acctId, pRealTable->table.dbName, pCxt->pComCxt->pMetaCache);
+ }
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
}
diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c
index 593a597a823b831bd766ffaa02195153fcb49c2b..422c48039743185070ca5ea5f704627d26217253 100644
--- a/source/libs/parser/src/parInsert.c
+++ b/source/libs/parser/src/parInsert.c
@@ -1335,6 +1335,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
SName name;
CHECK_CODE(createSName(&name, &tbnameToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg));
+ CHECK_CODE(isNotSchemalessDb(pCxt->pComCxt, name.dbname));
+
tNameExtractFullName(&name, tbFName);
CHECK_CODE(taosHashPut(pCxt->pTableNameHashObj, tbFName, strlen(tbFName), &name, sizeof(SName)));
char dbFName[TSDB_DB_FNAME_LEN];
@@ -1411,6 +1413,23 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
return buildOutput(pCxt);
}
+int32_t isNotSchemalessDb(SParseContext* pContext, char *dbName){
+ SName name;
+ tNameSetDbName(&name, pContext->acctId, dbName, strlen(dbName));
+ char dbFname[TSDB_DB_FNAME_LEN] = {0};
+ tNameGetFullDbName(&name, dbFname);
+ SDbCfgInfo pInfo = {0};
+ int32_t code = catalogGetDBCfg(pContext->pCatalog, pContext->pTransporter, &pContext->mgmtEpSet, dbFname, &pInfo);
+ if (code != TSDB_CODE_SUCCESS) {
+ parserError("catalogGetDBCfg error, code:%s, dbFName:%s", tstrerror(code), dbFname);
+ return code;
+ }
+ if (pInfo.schemaless){
+ parserError("can not insert into schemaless db:%s", dbFname);
+ return TSDB_CODE_SML_INVALID_DB_CONF;
+ }
+ return TSDB_CODE_SUCCESS;
+}
// INSERT INTO
// tb_name
// [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)]
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index c4e63ee8807b837e4875660f400a63bf8b835ad8..2d37e9087dfce24a9305858ceaaacb1d802146e4 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -2646,6 +2646,11 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
if (TSDB_CODE_SUCCESS == code) {
code = checkTableSchema(pCxt, pStmt);
}
+ if (TSDB_CODE_SUCCESS == code) {
+ if(pCxt->pParseCxt->schemalessType == 0){
+ code = isNotSchemalessDb(pCxt->pParseCxt, pStmt->dbName);
+ }
+ }
return code;
}
@@ -2852,7 +2857,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
int32_t code = getDBCfg(pCxt, pStmt->dbName, &dbCfg);
int32_t num = taosArrayGetSize(dbCfg.pRetensions);
if (TSDB_CODE_SUCCESS != code || num < 2) {
- taosArrayDestroy(dbCfg.pRetensions);
return code;
}
for (int32_t i = 1; i < num; ++i) {
@@ -4424,6 +4428,7 @@ static SArray* serializeVgroupsCreateTableBatch(int32_t acctId, SHashObj* pVgrou
}
static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) {
+
SCreateMultiTableStmt* pStmt = (SCreateMultiTableStmt*)pQuery->pRoot;
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
@@ -4434,6 +4439,10 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
int32_t code = TSDB_CODE_SUCCESS;
SNode* pNode;
FOREACH(pNode, pStmt->pSubTables) {
+ if(pCxt->pParseCxt->schemalessType == 0 &&
+ (code = isNotSchemalessDb(pCxt->pParseCxt, ((SCreateSubTableClause*)pNode)->dbName)) != TSDB_CODE_SUCCESS){
+ return code;
+ }
code = rewriteCreateSubTable(pCxt, (SCreateSubTableClause*)pNode, pVgroupHashmap);
if (TSDB_CODE_SUCCESS != code) {
taosHashCleanup(pVgroupHashmap);
@@ -4845,9 +4854,14 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p
static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
SAlterTableStmt* pStmt = (SAlterTableStmt*)pQuery->pRoot;
+ int32_t code = TSDB_CODE_SUCCESS;
+ if(pCxt->pParseCxt->schemalessType == 0 &&
+ (code = isNotSchemalessDb(pCxt->pParseCxt, pStmt->dbName)) != TSDB_CODE_SUCCESS){
+ return code;
+ }
STableMeta* pTableMeta = NULL;
- int32_t code = getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pTableMeta);
+ code = getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pTableMeta);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
@@ -5023,9 +5037,6 @@ int32_t translate(SParseContext* pParseCxt, SQuery* pQuery) {
STranslateContext cxt = {0};
int32_t code = initTranslateContext(pParseCxt, pQuery->pMetaCache, &cxt);
- if (TSDB_CODE_SUCCESS == code) {
- code = fmFuncMgtInit();
- }
if (TSDB_CODE_SUCCESS == code) {
code = rewriteQuery(&cxt, pQuery);
}
diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp
index a5192595f0be83afa459429748dab3d8e9b65c4e..e61b060682679d526d47fe8b607573b68b45cb38 100644
--- a/source/libs/parser/test/parSelectTest.cpp
+++ b/source/libs/parser/test/parSelectTest.cpp
@@ -33,6 +33,8 @@ TEST_F(ParserSelectTest, basic) {
run("SELECT ts, t.c1 FROM (SELECT * FROM t1) t");
run("SELECT * FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1");
+
+ run("SELECT * FROM st1");
}
TEST_F(ParserSelectTest, constant) {
diff --git a/source/libs/parser/test/parTestMain.cpp b/source/libs/parser/test/parTestMain.cpp
index 820b8cca3cdc02633982a3ea797aa605db1e3fd3..ecc535feb0cdf08aa8eba88ff1b0e3d79718e9f7 100644
--- a/source/libs/parser/test/parTestMain.cpp
+++ b/source/libs/parser/test/parTestMain.cpp
@@ -35,6 +35,7 @@ namespace ParserTest {
class ParserEnv : public testing::Environment {
public:
virtual void SetUp() {
+ fmFuncMgtInit();
initMetaDataEnv();
generateMetaData();
initLog(TD_TMP_DIR_PATH "td");
diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c
index 02d415af6c0b4ca3d1c717cde22e9c61c6c96888..1cf7ae22f9eb5e64220ae443d5353df062a148a4 100644
--- a/source/libs/planner/src/planLogicCreater.c
+++ b/source/libs/planner/src/planLogicCreater.c
@@ -562,6 +562,7 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
pWindow->slidingUnit =
(NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
+ pWindow->stmInterAlgo = STREAM_INTERVAL_ALGO_SINGLE;
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
if (NULL == pWindow->pTspk) {
diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c
index e1580d3eee4e2f08cb230344e65be5e8960c3ba3..737c0fc1d557b939162e63ec3c5d4e07ea0ebb57 100644
--- a/source/libs/planner/src/planPhysiCreater.c
+++ b/source/libs/planner/src/planPhysiCreater.c
@@ -526,10 +526,10 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
pScan->accountId = pCxt->pPlanCxt->acctId;
if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLES)) {
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
- SQueryNodeLoad node = { .addr = pSubplan->execNode, .load = 0};
+ SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0};
taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode);
} else {
- SQueryNodeLoad node = { .addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0};
+ SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0};
taosArrayPush(pCxt->pExecNodeList, &node);
}
pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet;
@@ -933,11 +933,22 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
return code;
}
+static ENodeType getIntervalOperatorType(bool streamQuery, EStreamIntervalAlgorithm stmAlgo) {
+ if (streamQuery) {
+ return STREAM_INTERVAL_ALGO_FINAL == stmAlgo
+ ? QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL
+ : (STREAM_INTERVAL_ALGO_SEMI == stmAlgo ? QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL
+ : QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL);
+ } else {
+ return QUERY_NODE_PHYSICAL_PLAN_INTERVAL;
+ }
+}
+
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode,
- (pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL : QUERY_NODE_PHYSICAL_PLAN_INTERVAL));
+ getIntervalOperatorType(pCxt->pPlanCxt->streamQuery, pWindowLogicNode->stmInterAlgo));
if (NULL == pInterval) {
return TSDB_CODE_OUT_OF_MEMORY;
}
diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c
index 2ae749bef5e65d7c18ec942d008c5499494d06db..e3c8b82e3988bd7943815a645332920f9d31d08b 100644
--- a/source/libs/planner/src/planSpliter.c
+++ b/source/libs/planner/src/planSpliter.c
@@ -24,9 +24,10 @@
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
typedef struct SSplitContext {
- uint64_t queryId;
- int32_t groupId;
- bool split;
+ SPlanContext* pPlanCxt;
+ uint64_t queryId;
+ int32_t groupId;
+ bool split;
} SSplitContext;
typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan);
@@ -36,7 +37,7 @@ typedef struct SSplitRule {
FSplit splitFunc;
} SSplitRule;
-typedef bool (*FSplFindSplitNode)(SLogicSubplan* pSubplan, void* pInfo);
+typedef bool (*FSplFindSplitNode)(SSplitContext* pCxt, SLogicSubplan* pSubplan, void* pInfo);
static void splSetSubplanVgroups(SLogicSubplan* pSubplan, SLogicNode* pNode) {
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) {
@@ -63,19 +64,29 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SLogicNode* pNod
return pSubplan;
}
-static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
- ESubplanType subplanType) {
+static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SExchangeLogicNode** pOutput) {
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
if (NULL == pExchange) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pExchange->srcGroupId = pCxt->groupId;
- pExchange->node.precision = pSplitNode->precision;
- pExchange->node.pTargets = nodesCloneList(pSplitNode->pTargets);
+ pExchange->node.precision = pChild->precision;
+ pExchange->node.pTargets = nodesCloneList(pChild->pTargets);
if (NULL == pExchange->node.pTargets) {
return TSDB_CODE_OUT_OF_MEMORY;
}
+ *pOutput = pExchange;
+ return TSDB_CODE_SUCCESS;
+}
+
+static int32_t splCreateExchangeNodeForSubplan(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
+ ESubplanType subplanType) {
+ SExchangeLogicNode* pExchange = NULL;
+ if (TSDB_CODE_SUCCESS != splCreateExchangeNode(pCxt, pSplitNode, &pExchange)) {
+ return TSDB_CODE_OUT_OF_MEMORY;
+ }
+
pSubplan->subplanType = subplanType;
if (NULL == pSplitNode->pParent) {
@@ -97,7 +108,7 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, FSplFindSplitNode func, void* pInfo) {
if (!SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, flag)) {
- if (func(pSubplan, pInfo)) {
+ if (func(pCxt, pSubplan, pInfo)) {
return true;
}
}
@@ -125,41 +136,47 @@ static bool stbSplHasGatherExecFunc(const SNodeList* pFuncs) {
return false;
}
-static bool stbSplIsMultiTbScan(SScanLogicNode* pScan) {
- return (NULL != pScan->pVgroupList && pScan->pVgroupList->numOfVgroups > 1);
+static bool stbSplIsMultiTbScan(bool streamQuery, SScanLogicNode* pScan) {
+ return (NULL != pScan->pVgroupList && pScan->pVgroupList->numOfVgroups > 1) ||
+ (streamQuery && TSDB_SUPER_TABLE == pScan->pMeta->tableType);
}
-static bool stbSplHasMultiTbScan(SLogicNode* pNode) {
+static bool stbSplHasMultiTbScan(bool streamQuery, SLogicNode* pNode) {
if (1 != LIST_LENGTH(pNode->pChildren)) {
return false;
}
SNode* pChild = nodesListGetNode(pNode->pChildren, 0);
- return (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pChild) && stbSplIsMultiTbScan((SScanLogicNode*)pChild));
+ return (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pChild) && stbSplIsMultiTbScan(streamQuery, (SScanLogicNode*)pChild));
}
-static bool stbSplNeedSplit(SLogicNode* pNode) {
+static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) {
switch (nodeType(pNode)) {
// case QUERY_NODE_LOGIC_PLAN_AGG:
// return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(pNode);
- case QUERY_NODE_LOGIC_PLAN_WINDOW:
- return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(pNode);
+ case QUERY_NODE_LOGIC_PLAN_WINDOW: {
+ SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode;
+ if (WINDOW_TYPE_INTERVAL != pWindow->winType) {
+ return false;
+ }
+ return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
+ }
// case QUERY_NODE_LOGIC_PLAN_SORT:
// return stbSplHasMultiTbScan(pNode);
case QUERY_NODE_LOGIC_PLAN_SCAN:
- return stbSplIsMultiTbScan((SScanLogicNode*)pNode);
+ return stbSplIsMultiTbScan(streamQuery, (SScanLogicNode*)pNode);
default:
break;
}
return false;
}
-static SLogicNode* stbSplMatchByNode(SLogicNode* pNode) {
- if (stbSplNeedSplit(pNode)) {
+static SLogicNode* stbSplMatchByNode(bool streamQuery, SLogicNode* pNode) {
+ if (stbSplNeedSplit(streamQuery, pNode)) {
return pNode;
}
SNode* pChild;
FOREACH(pChild, pNode->pChildren) {
- SLogicNode* pSplitNode = stbSplMatchByNode((SLogicNode*)pChild);
+ SLogicNode* pSplitNode = stbSplMatchByNode(streamQuery, (SLogicNode*)pChild);
if (NULL != pSplitNode) {
return pSplitNode;
}
@@ -167,8 +184,8 @@ static SLogicNode* stbSplMatchByNode(SLogicNode* pNode) {
return NULL;
}
-static bool stbSplFindSplitNode(SLogicSubplan* pSubplan, SStableSplitInfo* pInfo) {
- SLogicNode* pSplitNode = stbSplMatchByNode(pSubplan->pNode);
+static bool stbSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SStableSplitInfo* pInfo) {
+ SLogicNode* pSplitNode = stbSplMatchByNode(pCxt->pPlanCxt->streamQuery, pSubplan->pNode);
if (NULL != pSplitNode) {
pInfo->pSplitNode = pSplitNode;
pInfo->pSubplan = pSubplan;
@@ -301,7 +318,7 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, S
return code;
}
-static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
+static int32_t stbSplSplitWindowNodeForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
SLogicNode* pPartWindow = NULL;
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
if (TSDB_CODE_SUCCESS == code) {
@@ -315,8 +332,41 @@ static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInf
return code;
}
+static int32_t stbSplCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pParent, SLogicNode* pPartChild) {
+ SExchangeLogicNode* pExchange = NULL;
+ int32_t code = splCreateExchangeNode(pCxt, pPartChild, &pExchange);
+ if (TSDB_CODE_SUCCESS == code) {
+ code = nodesListMakeAppend(&pParent->pChildren, pExchange);
+ }
+ return code;
+}
+
+static int32_t stbSplSplitWindowNodeForStream(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
+ SLogicNode* pPartWindow = NULL;
+ int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
+ if (TSDB_CODE_SUCCESS == code) {
+ ((SWindowLogicNode*)pPartWindow)->stmInterAlgo = STREAM_INTERVAL_ALGO_SEMI;
+ ((SWindowLogicNode*)pInfo->pSplitNode)->stmInterAlgo = STREAM_INTERVAL_ALGO_FINAL;
+ code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
+ splCreateScanSubplan(pCxt, pPartWindow, SPLIT_FLAG_STABLE_SPLIT));
+ }
+ pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE;
+ return code;
+}
+
+static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
+ if (pCxt->pPlanCxt->streamQuery) {
+ return stbSplSplitWindowNodeForStream(pCxt, pInfo);
+ } else {
+ return stbSplSplitWindowNodeForBatch(pCxt, pInfo);
+ }
+}
+
static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
- int32_t code = splCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pSplitNode, SUBPLAN_TYPE_MERGE);
+ int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pInfo->pSplitNode, SUBPLAN_TYPE_MERGE);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
splCreateScanSubplan(pCxt, pInfo->pSplitNode, SPLIT_FLAG_STABLE_SPLIT));
@@ -325,6 +375,10 @@ static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo)
}
static int32_t stableSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
+ if (pCxt->pPlanCxt->rSmaQuery) {
+ return TSDB_CODE_SUCCESS;
+ }
+
SStableSplitInfo info = {0};
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STABLE_SPLIT, (FSplFindSplitNode)stbSplFindSplitNode, &info)) {
return TSDB_CODE_SUCCESS;
@@ -375,7 +429,7 @@ static SJoinLogicNode* sigTbJoinSplMatchByNode(SLogicNode* pNode) {
return NULL;
}
-static bool sigTbJoinSplFindSplitNode(SLogicSubplan* pSubplan, SSigTbJoinSplitInfo* pInfo) {
+static bool sigTbJoinSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SSigTbJoinSplitInfo* pInfo) {
SJoinLogicNode* pJoin = sigTbJoinSplMatchByNode(pSubplan->pNode);
if (NULL != pJoin) {
pInfo->pJoin = pJoin;
@@ -390,7 +444,7 @@ static int32_t singleTableJoinSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan
if (!splMatch(pCxt, pSubplan, 0, (FSplFindSplitNode)sigTbJoinSplFindSplitNode, &info)) {
return TSDB_CODE_SUCCESS;
}
- int32_t code = splCreateExchangeNode(pCxt, info.pSubplan, info.pSplitNode, info.pSubplan->subplanType);
+ int32_t code = splCreateExchangeNodeForSubplan(pCxt, info.pSubplan, info.pSplitNode, info.pSubplan->subplanType);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pSplitNode, 0));
}
@@ -489,7 +543,7 @@ static SLogicNode* unAllSplMatchByNode(SLogicNode* pNode) {
return NULL;
}
-static bool unAllSplFindSplitNode(SLogicSubplan* pSubplan, SUnionAllSplitInfo* pInfo) {
+static bool unAllSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SUnionAllSplitInfo* pInfo) {
SLogicNode* pSplitNode = unAllSplMatchByNode(pSubplan->pNode);
if (NULL != pSplitNode) {
pInfo->pProject = (SProjectLogicNode*)pSplitNode;
@@ -581,7 +635,7 @@ static int32_t unDistSplCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* p
return nodesListMakeAppend(&pAgg->node.pChildren, pExchange);
}
-static bool unDistSplFindSplitNode(SLogicSubplan* pSubplan, SUnionDistinctSplitInfo* pInfo) {
+static bool unDistSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SUnionDistinctSplitInfo* pInfo) {
SLogicNode* pSplitNode = unDistSplMatchByNode(pSubplan->pNode);
if (NULL != pSplitNode) {
pInfo->pAgg = (SAggLogicNode*)pSplitNode;
@@ -623,9 +677,10 @@ static void dumpLogicSubplan(const char* pRuleName, SLogicSubplan* pSubplan) {
taosMemoryFree(pStr);
}
-static int32_t applySplitRule(SLogicSubplan* pSubplan) {
- SSplitContext cxt = {.queryId = pSubplan->id.queryId, .groupId = pSubplan->id.groupId + 1, .split = false};
- bool split = false;
+static int32_t applySplitRule(SPlanContext* pCxt, SLogicSubplan* pSubplan) {
+ SSplitContext cxt = {
+ .pPlanCxt = pCxt, .queryId = pSubplan->id.queryId, .groupId = pSubplan->id.groupId + 1, .split = false};
+ bool split = false;
do {
split = false;
for (int32_t i = 0; i < splitRuleNum; ++i) {
@@ -672,7 +727,7 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
pSubplan->id.groupId = 1;
setLogicNodeParent(pSubplan->pNode);
- int32_t code = applySplitRule(pSubplan);
+ int32_t code = applySplitRule(pCxt, pSubplan);
if (TSDB_CODE_SUCCESS == code) {
*pLogicSubplan = pSubplan;
} else {
diff --git a/source/libs/planner/test/CMakeLists.txt b/source/libs/planner/test/CMakeLists.txt
index abea60b0c798a055617abf3693be25f365fbc867..b34ffa7bb1017e25c2b08a7b077430fea74bd923 100644
--- a/source/libs/planner/test/CMakeLists.txt
+++ b/source/libs/planner/test/CMakeLists.txt
@@ -32,9 +32,9 @@ if(${BUILD_WINGETOPT})
target_link_libraries(plannerTest PUBLIC wingetopt)
endif()
-if(NOT TD_WINDOWS)
+# if(NOT TD_WINDOWS)
add_test(
NAME plannerTest
COMMAND plannerTest
)
-endif(NOT TD_WINDOWS)
+# endif(NOT TD_WINDOWS)
diff --git a/source/libs/planner/test/planOtherTest.cpp b/source/libs/planner/test/planOtherTest.cpp
index 67c09d706e34ea44ab0c4070d9bbb665a15dded1..f153604e6b6b43ca601bfe662f7a21b2f36327ff 100644
--- a/source/libs/planner/test/planOtherTest.cpp
+++ b/source/libs/planner/test/planOtherTest.cpp
@@ -33,6 +33,12 @@ TEST_F(PlanOtherTest, createStream) {
"interval(10s)");
}
+TEST_F(PlanOtherTest, createStreamUseSTable) {
+ useDb("root", "test");
+
+ run("create stream if not exists s1 as select count(*) from st1 interval(10s)");
+}
+
TEST_F(PlanOtherTest, createSmaIndex) {
useDb("root", "test");
diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp
index 42c8558239b4389e0a0c469fdaa5842b53dc2398..acac3d505306e40e83bf9969273eba7cf61ad2a0 100644
--- a/source/libs/planner/test/planTestMain.cpp
+++ b/source/libs/planner/test/planTestMain.cpp
@@ -16,6 +16,7 @@
#include
#include
+#include "functionMgt.h"
#include "getopt.h"
#include "mockCatalog.h"
#include "planTestUtil.h"
@@ -23,6 +24,7 @@
class PlannerEnv : public testing::Environment {
public:
virtual void SetUp() {
+ fmFuncMgtInit();
initMetaDataEnv();
generateMetaData();
initLog(TD_TMP_DIR_PATH "td");
diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp
index 16dcd7b6e025dd5761202308d00c20435d9a55f0..5bb6acee6014fb9352b9ac11304500df33e3ffcd 100644
--- a/source/libs/qworker/test/qworkerTests.cpp
+++ b/source/libs/qworker/test/qworkerTests.cpp
@@ -172,8 +172,7 @@ int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) {
return 0;
}
-
-int32_t qwtPutReqToQueue(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));
memcpy(newMsg, pMsg, sizeof(struct SRpcMsg));
@@ -181,7 +180,7 @@ int32_t qwtPutReqToQueue(void *node, struct SRpcMsg *pMsg) {
if (qwtTestQueryQueueWIdx >= qwtTestQueryQueueSize) {
qwtTestQueryQueueWIdx = 0;
}
-
+
qwtTestQueryQueueNum++;
if (qwtTestQueryQueueWIdx == qwtTestQueryQueueRIdx) {
@@ -702,9 +701,9 @@ void *qwtclientThread(void *param) {
while (!qwtTestStop) {
qwtTestCaseFinished = false;
-
+
qwtBuildQueryReqMsg(&queryRpc);
- qwtPutReqToQueue((void *)0x1, &queryRpc);
+ qwtPutReqToQueue((void *)0x1, QUERY_QUEUE, &queryRpc);
while (!qwtTestCaseFinished) {
taosUsleep(1);
@@ -874,7 +873,7 @@ TEST(seqTest, normalCase) {
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -907,10 +906,10 @@ TEST(seqTest, cancelFirst) {
stubSetStringToPlan();
stubSetRpcSendResponse();
-
+
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -944,10 +943,10 @@ TEST(seqTest, randCase) {
stubSetCreateExecTask();
taosSeedRand(taosGetTimestampSec());
-
+
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -1015,10 +1014,10 @@ TEST(seqTest, multithreadRand) {
stubSetGetDataBlock();
taosSeedRand(taosGetTimestampSec());
-
+
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -1081,7 +1080,7 @@ TEST(rcTest, shortExecshortDelay) {
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -1165,7 +1164,7 @@ TEST(rcTest, longExecshortDelay) {
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -1251,7 +1250,7 @@ TEST(rcTest, shortExeclongDelay) {
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
@@ -1332,10 +1331,10 @@ TEST(rcTest, dropTest) {
stubSetGetDataBlock();
taosSeedRand(taosGetTimestampSec());
-
+
SMsgCb msgCb = {0};
msgCb.mgmt = (void *)mockPointer;
- msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qwtPutReqToQueue;
+ msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue;
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, &msgCb);
ASSERT_EQ(code, 0);
diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c
index 370ea8fa2ecd6fb1dab661f931199f08e6f8f65a..2b15f5031eaf40d0bad6eeb658be2c4d232866df 100644
--- a/source/libs/scalar/src/sclfunc.c
+++ b/source/libs/scalar/src/sclfunc.c
@@ -449,7 +449,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
bool hasNull = false;
for (int32_t i = 0; i < inputNum; ++i) {
if (colDataIsNull_s(pInputData[i], k) ||
- GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_NULL) {
+ IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
colDataAppendNULL(pOutputData, k);
hasNull = true;
break;
@@ -526,7 +526,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
for (int32_t k = 0; k < numOfRows; ++k) {
if (colDataIsNull_s(pInputData[0], k) ||
- GET_PARAM_TYPE(&pInput[0]) == TSDB_DATA_TYPE_NULL) {
+ IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) {
colDataAppendNULL(pOutputData, k);
continue;
}
@@ -535,7 +535,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
bool hasNull = false;
for (int32_t i = 1; i < inputNum; ++i) {
if (colDataIsNull_s(pInputData[i], k) ||
- GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_NULL) {
+ IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
hasNull = true;
break;
}
@@ -718,7 +718,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int16_t outputType = GET_PARAM_TYPE(&pOutput[0]);
int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]);
- char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1);
+ char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows + 1, 1);
char *output = outputBuf;
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
@@ -1221,8 +1221,8 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
if (IS_VAR_DATA_TYPE(type)) { /* datetime format strings */
int32_t ret = convertStringToTimestamp(type, input[k], TSDB_TIME_PRECISION_NANO, &timeVal[k]);
if (ret != TSDB_CODE_SUCCESS) {
- colDataAppendNULL(pOutput->columnData, i);
- continue;
+ hasNull = true;
+ break;
}
} else if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP) { /* unix timestamp or ts column*/
GET_TYPED_DATA(timeVal[k], int64_t, type, input[k]);
@@ -1247,8 +1247,8 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
timeVal[k] = timeVal[k];
} else {
- colDataAppendNULL(pOutput->columnData, i);
- continue;
+ hasNull = true;
+ break;
}
}
}
diff --git a/source/libs/scheduler/src/schDbg.c b/source/libs/scheduler/src/schDbg.c
index 4b5f74114d2ae7d4ec47b09f8a48da2f3f61de8d..5c0c6fbb76974f87e06b5ba1cbcb761b864fd163 100644
--- a/source/libs/scheduler/src/schDbg.c
+++ b/source/libs/scheduler/src/schDbg.c
@@ -30,13 +30,4 @@ void schdExecCallback(SQueryResult* pResult, void* param, int32_t code) {
tsem_post(&schdRspSem);
}
-void schdFetchCallback(void* pResult, void* param, int32_t code) {
- SSchdFetchParam* fParam = (SSchdFetchParam*)param;
-
- *fParam->pData = pResult;
- *fParam->code = code;
-
- tsem_post(&schdRspSem);
-}
-
diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c
index cceadcc0346a5cb903d5c9c5c04a78228f561815..6e1319d5f43e28d5c5510bef95a68763f79a5065 100644
--- a/source/libs/scheduler/src/schJob.c
+++ b/source/libs/scheduler/src/schJob.c
@@ -21,9 +21,9 @@
#include "tref.h"
#include "trpc.h"
-FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); }
+FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { qDebug("acquire jobId:0x%"PRIx64, refId); return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); }
-FORCE_INLINE int32_t schReleaseJob(int64_t refId) { return taosReleaseRef(schMgmt.jobRef, refId); }
+FORCE_INLINE int32_t schReleaseJob(int64_t refId) { qDebug("release jobId:0x%"PRIx64, refId); return taosReleaseRef(schMgmt.jobRef, refId); }
int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel) {
pTask->plan = pPlan;
@@ -1478,8 +1478,6 @@ void schFreeJobImpl(void *job) {
int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
SSchResInfo *pRes, int64_t startTs, bool sync) {
- qDebug("QID:0x%" PRIx64 " job started", pDag->queryId);
-
if (pNodeList == NULL || taosArrayGetSize(pNodeList) <= 0) {
qDebug("QID:0x%" PRIx64 " input exec nodeList is empty", pDag->queryId);
}
@@ -1488,6 +1486,7 @@ int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_
SSchJob *pJob = NULL;
SCH_ERR_RET(schInitJob(&pJob, pDag, pTrans, pNodeList, sql, pRes, startTs, sync));
+ qDebug("QID:0x%" PRIx64 " jobId:0x%"PRIx64 " started", pDag->queryId, pJob->refId);
*job = pJob->refId;
SCH_ERR_JRET(schLaunchJob(pJob));
@@ -1499,7 +1498,7 @@ int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_
pJob->userCb = SCH_EXEC_CB;
}
- SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
+ SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%"PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId);
_return:
diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c
index 522bd8044d43709f9139092dd705ab123c7799ea..32e00c1b700a3eadfa9e15580d76950798791927 100644
--- a/source/libs/scheduler/src/scheduler.c
+++ b/source/libs/scheduler/src/scheduler.c
@@ -79,12 +79,19 @@ int32_t schedulerExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int6
int32_t schedulerAsyncExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
int64_t startTs, schedulerExecCallback fp, void* param) {
- if (NULL == pTrans || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == fp || NULL == param) {
- SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
- }
-
- SSchResInfo resInfo = {.execFp = fp, .userParam = param};
- SCH_RET(schAsyncExecJob(pTrans, pNodeList, pDag, pJob, sql, startTs, &resInfo));
+ int32_t code = 0;
+ if (NULL == pTrans || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == fp) {
+ code = TSDB_CODE_QRY_INVALID_INPUT;
+ } else {
+ SSchResInfo resInfo = {.execFp = fp, .userParam = param};
+ code = schAsyncExecJob(pTrans, pNodeList, pDag, pJob, sql, startTs, &resInfo);
+ }
+
+ if (code != TSDB_CODE_SUCCESS) {
+ fp(NULL, param, code);
+ }
+
+ return code;
}
int32_t schedulerFetchRows(int64_t job, void **pData) {
@@ -95,7 +102,7 @@ int32_t schedulerFetchRows(int64_t job, void **pData) {
int32_t code = 0;
SSchJob *pJob = schAcquireJob(job);
if (NULL == pJob) {
- qError("acquire job from jobRef list failed, may be dropped, refId:%" PRIx64, job);
+ qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job);
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
}
@@ -108,27 +115,26 @@ int32_t schedulerFetchRows(int64_t job, void **pData) {
SCH_RET(code);
}
-int32_t schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param) {
+void schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param) {
if (NULL == fp || NULL == param) {
- SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
+ fp(NULL, param, TSDB_CODE_QRY_INVALID_INPUT);
+ return;
}
- int32_t code = 0;
SSchJob *pJob = schAcquireJob(job);
if (NULL == pJob) {
- qError("acquire job from jobRef list failed, may be dropped, refId:%" PRIx64, job);
- SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
+ qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job);
+ fp(NULL, param, TSDB_CODE_SCH_STATUS_ERROR);
+ return;
}
pJob->attr.syncSchedule = false;
pJob->userRes.fetchFp = fp;
pJob->userRes.userParam = param;
- code = schAsyncFetchRows(pJob);
+ /*code = */schAsyncFetchRows(pJob);
schReleaseJob(job);
-
- SCH_RET(code);
}
int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub) {
@@ -165,7 +171,7 @@ _return:
int32_t scheduleCancelJob(int64_t job) {
SSchJob *pJob = schAcquireJob(job);
if (NULL == pJob) {
- qError("acquire job from jobRef list failed, may be dropped, refId:%" PRIx64, job);
+ qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job);
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
}
@@ -179,7 +185,7 @@ int32_t scheduleCancelJob(int64_t job) {
void schedulerFreeJob(int64_t job) {
SSchJob *pJob = schAcquireJob(job);
if (NULL == pJob) {
- qDebug("acquire job from jobRef list failed, may be dropped, refId:%" PRIx64, job);
+ qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job);
return;
}
diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c
index 620fc514c6960754762187445b167098ce4382d3..66806dbd0c8e6b40ac9331884ff0447263f0eaaa 100644
--- a/source/libs/sync/src/syncMain.c
+++ b/source/libs/sync/src/syncMain.c
@@ -1450,12 +1450,12 @@ static void syncFreeNode(void* param) {
const char* syncStr(ESyncState state) {
switch (state) {
case TAOS_SYNC_STATE_FOLLOWER:
- return "FOLLOWER";
+ return "follower";
case TAOS_SYNC_STATE_CANDIDATE:
- return "CANDIDATE";
+ return "candidate";
case TAOS_SYNC_STATE_LEADER:
- return "LEADER";
+ return "leader";
default:
- return "ERROR";
+ return "error";
}
}
diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c
index 580ab30b7800c05d6f8463700cc208cd850b9a8e..0090701ba567378c4e2aab0869a757663b9d289e 100644
--- a/source/libs/transport/src/transCli.c
+++ b/source/libs/transport/src/transCli.c
@@ -1151,7 +1151,6 @@ void transSetDefaultAddr(void* ahandle, const char* ip, const char* fqdn) {
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i];
tDebug("update epset at thread:%d, threadID:%" PRId64 "", i, thrd->thread);
- tsem_t* pSem = pCtx->pSem;
transSendAsync(thrd->asyncPool, &(cliMsg->q));
}
}
diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c
index d2a43c410708249983295dca44ca06f6f75a2b70..a9a8f8a1f40fbfd6fda3ec43d4fd1bfdf61025dc 100644
--- a/source/libs/wal/src/walWrite.c
+++ b/source/libs/wal/src/walWrite.c
@@ -18,6 +18,14 @@
#include "tchecksum.h"
#include "walInt.h"
+void walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
+ /*pWal->vers.firstVer = -1;*/
+ pWal->vers.lastVer = ver;
+ pWal->vers.commitVer = ver - 1;
+ pWal->vers.snapshotVer = ver - 1;
+ pWal->vers.verInSnapshotting = -1;
+}
+
int32_t walCommit(SWal *pWal, int64_t ver) {
ASSERT(pWal->vers.commitVer >= pWal->vers.snapshotVer);
ASSERT(pWal->vers.commitVer <= pWal->vers.lastVer);
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index d179887b2fd7cd2d0214db2204117f35517b78d7..0b1de5dd8973afa021f7281457a129afa16499ac 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -190,7 +190,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_ALREADY_EXIST, "Bnode already exists"
TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_NOT_EXIST, "Bnode not there")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_FEW_MNODES, "The replicas of mnode cannot less than 1")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "The replicas of mnode cannot exceed 3")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_CANT_DROP_MASTER, "Can't drop mnode which is LEADER")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_CANT_DROP_MASTER, "Can't drop mnode which is leader")
// mnode-acct
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, "Account already exists")
@@ -471,6 +471,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_UDF_INVALID_OUTPUT_TYPE, "udf invalid output ty
TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PROTOCOL_TYPE, "Invalid line protocol type")
TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PRECISION_TYPE, "Invalid timestamp precision type")
TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_DATA, "Invalid data type")
+TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_DB_CONF, "Invalid schemaless db config")
#ifdef TAOS_ERROR_C
};
diff --git a/source/util/src/tlist.c b/source/util/src/tlist.c
index 1d17b4a9e17aa7cafdd89ba273770e8751f09066..b1c018805157fe05ef6be97fa7be6df0255d5d5b 100644
--- a/source/util/src/tlist.c
+++ b/source/util/src/tlist.c
@@ -95,7 +95,7 @@ SListNode *tdListPopTail(SList *list) {
SListNode *tdListGetHead(SList *list) { return TD_DLIST_HEAD(list); }
-SListNode *tsListGetTail(SList *list) { return TD_DLIST_TAIL(list); }
+SListNode *tdListGetTail(SList *list) { return TD_DLIST_TAIL(list); }
SListNode *tdListPopNode(SList *list, SListNode *node) {
TD_DLIST_POP(list, node);
diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c
index 686e0696ec689b48ecff8f27c7db2eb86daa5eb2..68f96c0385b6c25a4736343917e875f84d4e2c9e 100644
--- a/source/util/src/tworker.c
+++ b/source/util/src/tworker.c
@@ -163,7 +163,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
worker->pool = pool;
}
- uInfo("worker:%s is initialized, max:%d", pool->name, pool->max);
+ uDebug("worker:%s is initialized, max:%d", pool->name, pool->max);
return 0;
}
@@ -190,7 +190,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
taosMemoryFreeClear(pool->workers);
taosThreadMutexDestroy(&pool->mutex);
- uInfo("worker:%s is closed", pool->name);
+ uDebug("worker:%s is closed", pool->name);
}
static void *tWWorkerThreadFp(SWWorker *worker) {
diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py
index 21d235ee5c3502ff3248681ada0a6f2c99a805ea..7eeddfd5c197396f5f9586cb27e576e1e05cfc31 100644
--- a/tests/pytest/util/dnodes.py
+++ b/tests/pytest/util/dnodes.py
@@ -247,7 +247,7 @@ class TDDnode:
if bool(updatecfgDict) and updatecfgDict[0] and updatecfgDict[0][0]:
print(updatecfgDict[0][0])
for key, value in updatecfgDict[0][0].items():
- if key == "clientCfg":
+ if key == "clientCfg" and self.remoteIP == "" and not platform.system().lower() == 'windows':
continue
if value == 'dataDir':
if isFirstDir:
diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt
index bb446fb248602842b579817dbdbbcc02f0a0680f..c93374956483d94550d614d7c99c77bba4bf1dd0 100644
--- a/tests/script/jenkins/basic.txt
+++ b/tests/script/jenkins/basic.txt
@@ -135,6 +135,7 @@
./test.sh -f tsim/sync/3Replica5VgElect.sim
./test.sh -f tsim/sync/oneReplica1VgElect.sim
./test.sh -f tsim/sync/oneReplica5VgElect.sim
+# ./test.sh -f tsim/sync/3Replica5VgElect3mnode.sim
# --- catalog
./test.sh -f tsim/catalog/alterInCurrent.sim
diff --git a/tests/script/tsim/bnode/basic1.sim b/tests/script/tsim/bnode/basic1.sim
index b1db6efc72afce083d9594987ccee3d10ab83ef4..80608453b8cf1243f27583a719f315462a4412d4 100644
--- a/tests/script/tsim/bnode/basic1.sim
+++ b/tests/script/tsim/bnode/basic1.sim
@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim
index aeb04293f2d5df29a07e629d32df3d96cb5d16b1..f3adb4535ec0a2b6dae2de6a277ab3a913bb711a 100644
--- a/tests/script/tsim/db/alter_option.sim
+++ b/tests/script/tsim/db/alter_option.sim
@@ -131,43 +131,43 @@ endi
sleep 3000
#sql show db.vgroups
-#if $data[0][4] == LEADER then
-# if $data[0][6] != FOLLOWER then
+#if $data[0][4] == leader then
+# if $data[0][6] != follower then
# return -1
# endi
-# if $data[0][8] != FOLLOWER then
+# if $data[0][8] != follower then
# return -1
# endi
#endi
-#if $data[0][6] == LEADER then
-# if $data[0][4] != FOLLOWER then
+#if $data[0][6] == leader then
+# if $data[0][4] != follower then
# return -1
# endi
-# if $data[0][8] != FOLLOWER then
+# if $data[0][8] != follower then
# return -1
# endi
#endi
-#if $data[0][8] == LEADER then
-# if $data[0][4] != FOLLOWER then
+#if $data[0][8] == leader then
+# if $data[0][4] != follower then
# return -1
# endi
-# if $data[0][6] != FOLLOWER then
+# if $data[0][6] != follower then
# return -1
# endi
#endi
#
-#if $data[0][4] != LEADER then
-# if $data[0][4] != FOLLOWER then
+#if $data[0][4] != leader then
+# if $data[0][4] != follower then
# return -1
# endi
#endi
-#if $data[0][6] != LEADER then
-# if $data[0][6] != FOLLOWER then
+#if $data[0][6] != leader then
+# if $data[0][6] != follower then
# return -1
# endi
#endi
-#if $data[0][8] != LEADER then
-# if $data[0][8] != FOLLOWER then
+#if $data[0][8] != leader then
+# if $data[0][8] != follower then
# return -1
# endi
#endi
diff --git a/tests/script/tsim/db/alter_replica_13.sim b/tests/script/tsim/db/alter_replica_13.sim
index 8ab6eb64fd93d3cb9b2b9882392ed2f40bc15f67..4d45b9296709b3f3367e025cca1fc3c8a31faea4 100644
--- a/tests/script/tsim/db/alter_replica_13.sim
+++ b/tests/script/tsim/db/alter_replica_13.sim
@@ -12,11 +12,11 @@ sql connect
print =============== step1: create dnodes
sql create dnode $hostname port 7200
-$loop_cnt = 0
+$x = 0
step1:
- $loop_cnt = $loop_cnt + 1
+ $ = $x + 1
sleep 1000
- if $loop_cnt == 10 then
+ if $x == 10 then
print ====> dnode not ready!
return -1
endi
@@ -73,11 +73,11 @@ print =============== step3: create dnodes
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
-$loop_cnt = 0
+$x = 0
step3:
- $loop_cnt = $loop_cnt + 1
+ $x = $x + 1
sleep 1000
- if $loop_cnt == 10 then
+ if $x == 10 then
print ====> dnode not ready!
return -1
endi
@@ -103,22 +103,38 @@ if $data(4)[4] != ready then
goto step3
endi
-return
print ============= step4: alter database
sql alter database db replica 3
-if $rows != 3 then
- return -1
+
+$x = 0
+step4:
+ $x = $x + 1
+ sleep 1000
+ if $x == 10 then
+ print ====> dnode not ready!
+ return -1
+ endi
+sql show db.vgroups
+print ===> rows: $rows
+print ===> $data00 $data01 $data02 $data03 $data04 $data05
+if $data[0][4] != leader then
+ goto step4
endi
-if $data(db)[4] != 3 then
- return -1
+if $data[0][6] != follower then
+ goto step4
endi
+if $data[0][8] != follower then
+ goto step4
+endi
+
+print ============= step5: stop dnode 2
sql select * from db.stb
if $rows != 1 then
return -1
endi
-
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
+system sh/exec.sh -n dnode4 -s stop -x SIGINT
\ No newline at end of file
diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/basic1.sim
index d5c791e902aef3404f854287cef6224767080f82..a5b5427e036e1f74a2287a2d4995c5936fd149f5 100644
--- a/tests/script/tsim/dnode/basic1.sim
+++ b/tests/script/tsim/dnode/basic1.sim
@@ -27,7 +27,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -74,7 +74,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
diff --git a/tests/script/tsim/mnode/basic1.sim b/tests/script/tsim/mnode/basic1.sim
index e922ebe37605d64d637e63aa176b53af93b06921..d93d4ca53fc2b6c56e0a8eccf7d3ac3ea74ec0ee 100644
--- a/tests/script/tsim/mnode/basic1.sim
+++ b/tests/script/tsim/mnode/basic1.sim
@@ -15,7 +15,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -59,13 +59,13 @@ endi
if $data(1)[0] != 1 then
return -1
endi
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
return -1
endi
if $data(2)[0] != 2 then
return -1
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step2
endi
@@ -95,7 +95,7 @@ endi
if $data(1)[0] != 1 then
return -1
endi
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
return -1
endi
if $data(2)[0] != null then
@@ -131,13 +131,13 @@ endi
if $data(1)[0] != 1 then
return -1
endi
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
return -1
endi
if $data(2)[0] != 2 then
return -1
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step3
endi
diff --git a/tests/script/tsim/mnode/basic2.sim b/tests/script/tsim/mnode/basic2.sim
index 18aa85cf5bb00a579b8ed7be14b264845a37948a..78558263d619ee3e9cef2e03c51790823c95b6a9 100644
--- a/tests/script/tsim/mnode/basic2.sim
+++ b/tests/script/tsim/mnode/basic2.sim
@@ -15,7 +15,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -56,13 +56,13 @@ endi
if $data(1)[0] != 1 then
return -1
endi
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
return -1
endi
if $data(2)[0] != 2 then
return -1
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step2
endi
diff --git a/tests/script/tsim/mnode/basic3.sim b/tests/script/tsim/mnode/basic3.sim
index edbf4290750605d2f5d68f4c67320ca30d8bc42a..bc70cd7a85522230a54359b8a4144eb4ce7a4eed 100644
--- a/tests/script/tsim/mnode/basic3.sim
+++ b/tests/script/tsim/mnode/basic3.sim
@@ -49,13 +49,13 @@ step2:
return -1
endi
sql show mnodes -x step2
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
goto step2
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step2
endi
-if $data(3)[2] != FOLLOWER then
+if $data(3)[2] != follower then
goto step2
endi
@@ -114,7 +114,7 @@ print $data(1)[0] $data(1)[1] $data(1)[2]
print $data(2)[0] $data(2)[1] $data(2)[2]
print $data(3)[0] $data(3)[1] $data(3)[2]
-if $data(2)[2] != OFFLINE then
+if $data(2)[2] != offline then
goto step5
endi
diff --git a/tests/script/tsim/mnode/basic4.sim b/tests/script/tsim/mnode/basic4.sim
index 11a94dbc557670ff8015245fee5ca739caccb60e..88deb5af898fde58d94f5129fb4e2a030795f29b 100644
--- a/tests/script/tsim/mnode/basic4.sim
+++ b/tests/script/tsim/mnode/basic4.sim
@@ -63,22 +63,22 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4]
print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4]
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
goto step3
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step3
endi
-if $data(3)[2] != OFFLINE then
+if $data(3)[2] != offline then
goto step3
endi
-if $data(1)[3] != READY then
+if $data(1)[3] != ready then
goto step3
endi
-if $data(2)[3] != READY then
+if $data(2)[3] != ready then
goto step3
endi
-if $data(3)[3] != CREATING then
+if $data(3)[3] != creating then
goto step3
endi
@@ -97,22 +97,22 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4]
print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4]
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
goto step4
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step4
endi
-if $data(3)[2] != FOLLOWER then
+if $data(3)[2] != follower then
goto step4
endi
-if $data(1)[3] != READY then
+if $data(1)[3] != ready then
goto step4
endi
-if $data(2)[3] != READY then
+if $data(2)[3] != ready then
goto step4
endi
-if $data(3)[3] != READY then
+if $data(3)[3] != ready then
goto step4
endi
@@ -132,22 +132,22 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4]
print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4]
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
goto step5
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step5
endi
-if $data(3)[2] != OFFLINE then
+if $data(3)[2] != offline then
goto step5
endi
-if $data(1)[3] != READY then
+if $data(1)[3] != ready then
goto step5
endi
-if $data(2)[3] != READY then
+if $data(2)[3] != ready then
goto step5
endi
-if $data(3)[3] != DROPPING then
+if $data(3)[3] != dropping then
goto step5
endi
@@ -169,19 +169,19 @@ print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4]
if $rows != 2 then
goto step6
endi
-if $data(1)[2] != LEADER then
+if $data(1)[2] != leader then
goto step6
endi
-if $data(2)[2] != FOLLOWER then
+if $data(2)[2] != follower then
goto step6
endi
if $data(3)[2] != null then
goto step6
endi
-if $data(1)[3] != READY then
+if $data(1)[3] != ready then
goto step6
endi
-if $data(2)[3] != READY then
+if $data(2)[3] != ready then
goto step6
endi
if $data(3)[3] != null then
diff --git a/tests/script/tsim/qnode/basic1.sim b/tests/script/tsim/qnode/basic1.sim
index 2351403909e9f641e2ada2789561a095a0e915d4..7108fcaf59ec420a8657dd8e061e5261ec15ce3c 100644
--- a/tests/script/tsim/qnode/basic1.sim
+++ b/tests/script/tsim/qnode/basic1.sim
@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
diff --git a/tests/script/tsim/query/explain.sim b/tests/script/tsim/query/explain.sim
index 21162a99b0928040ae115b13c117864a170ef4e9..2b0d52d25327833221ffe53953f904d74ed1784a 100644
--- a/tests/script/tsim/query/explain.sim
+++ b/tests/script/tsim/query/explain.sim
@@ -1,7 +1,7 @@
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
-print ========= start dnode1 as LEADER
+print ========= start dnode1 as leader
system sh/exec.sh -n dnode1 -s start
sql connect
diff --git a/tests/script/tsim/query/scalarNull.sim b/tests/script/tsim/query/scalarNull.sim
index c7e7aa9a349a98623033c40cebfa9c499ee0fe2a..b08ac1d3d9abe157915ec25c438d82e2774ced04 100644
--- a/tests/script/tsim/query/scalarNull.sim
+++ b/tests/script/tsim/query/scalarNull.sim
@@ -4,7 +4,7 @@ system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 2
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1
-print ========= start dnode1 as LEADER
+print ========= start dnode1 as leader
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim
index 24ddcc1b75c70865f334f553a6b0f1ee176d62ca..93cae4e3912cab0b5c36e60d28743f0c10f1e45a 100644
--- a/tests/script/tsim/query/udf.sim
+++ b/tests/script/tsim/query/udf.sim
@@ -5,7 +5,7 @@ system sh/cfg.sh -n dnode1 -c wallevel -v 2
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1
system sh/cfg.sh -n dnode1 -c udf -v 1
-print ========= start dnode1 as LEADER
+print ========= start dnode1 as leader
system sh/exec.sh -n dnode1 -s start
sleep 1000
sql connect
diff --git a/tests/script/tsim/snode/basic1.sim b/tests/script/tsim/snode/basic1.sim
index 660951c591bb9048b592e7be60492925b13b600d..a9d4867354e70a867d23e65ed03dda47b0b2524c 100644
--- a/tests/script/tsim/snode/basic1.sim
+++ b/tests/script/tsim/snode/basic1.sim
@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
diff --git a/tests/script/tsim/stream/basic0.sim b/tests/script/tsim/stream/basic0.sim
index 9edad991dc0ac5c5c960be026c1fd17073d17881..29775a5ef1d1daf90122f053da6c153bac843341 100644
--- a/tests/script/tsim/stream/basic0.sim
+++ b/tests/script/tsim/stream/basic0.sim
@@ -63,7 +63,8 @@ if $data02 != 234 then
return -1
endi
-if $data03 != 234 then
+if $data03 != 234 then
+ print expect 234, actual $data03
return -1
endi
diff --git a/tests/script/tsim/sync/3Replica1VgElect.sim b/tests/script/tsim/sync/3Replica1VgElect.sim
index 61b3b09288faecf857c5d33e7a34ac3544c4db67..e531fa82ad3d78d45447b583834c5b8842c171d1 100644
--- a/tests/script/tsim/sync/3Replica1VgElect.sim
+++ b/tests/script/tsim/sync/3Replica1VgElect.sim
@@ -105,21 +105,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
@@ -239,21 +239,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
@@ -447,21 +447,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
diff --git a/tests/script/tsim/sync/3Replica5VgElect.sim b/tests/script/tsim/sync/3Replica5VgElect.sim
index 4041263e55fa06b93ecea9930ba1dbd728579ce7..1243cf81242fe1c8c8887cd9c89b1b2b48ea9033 100644
--- a/tests/script/tsim/sync/3Replica5VgElect.sim
+++ b/tests/script/tsim/sync/3Replica5VgElect.sim
@@ -108,21 +108,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
@@ -130,21 +130,21 @@ else
goto check_vg_ready
endi
-if $data[1][4] == LEADER then
- if $data[1][6] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+if $data[1][4] == leader then
+ if $data[1][6] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
endi
endi
-elif $data[1][6] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+elif $data[1][6] == leader then
+ if $data[1][4] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
endi
endi
-elif $data[1][8] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][6] == FOLLOWER then
+elif $data[1][8] == leader then
+ if $data[1][4] == follower then
+ if $data[1][6] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
endi
endi
@@ -152,21 +152,21 @@ else
goto check_vg_ready
endi
-if $data[2][4] == LEADER then
- if $data[2][6] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+if $data[2][4] == leader then
+ if $data[2][6] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
endi
endi
-elif $data[2][6] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+elif $data[2][6] == leader then
+ if $data[2][4] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
endi
endi
-elif $data[2][8] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][6] == FOLLOWER then
+elif $data[2][8] == leader then
+ if $data[2][4] == follower then
+ if $data[2][6] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
endi
endi
@@ -174,21 +174,21 @@ else
goto check_vg_ready
endi
-if $data[3][4] == LEADER then
- if $data[3][6] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+if $data[3][4] == leader then
+ if $data[3][6] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
endi
endi
-elif $data[3][6] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+elif $data[3][6] == leader then
+ if $data[3][4] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
endi
endi
-elif $data[3][8] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][6] == FOLLOWER then
+elif $data[3][8] == leader then
+ if $data[3][4] == follower then
+ if $data[3][6] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
endi
endi
@@ -196,21 +196,21 @@ else
goto check_vg_ready
endi
-if $data[4][4] == LEADER then
- if $data[4][6] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+if $data[4][4] == leader then
+ if $data[4][6] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
endi
endi
-elif $data[4][6] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+elif $data[4][6] == leader then
+ if $data[4][4] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
endi
endi
-elif $data[4][8] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][6] == FOLLOWER then
+elif $data[4][8] == leader then
+ if $data[4][4] == follower then
+ if $data[4][6] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
endi
endi
@@ -335,21 +335,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
@@ -357,21 +357,21 @@ else
goto check_vg_ready1
endi
-if $data[1][4] == LEADER then
- if $data[1][6] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+if $data[1][4] == leader then
+ if $data[1][6] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
endi
endi
-elif $data[1][6] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+elif $data[1][6] == leader then
+ if $data[1][4] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
endi
endi
-elif $data[1][8] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][6] == FOLLOWER then
+elif $data[1][8] == leader then
+ if $data[1][4] == follower then
+ if $data[1][6] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
endi
endi
@@ -379,21 +379,21 @@ else
goto check_vg_ready1
endi
-if $data[2][4] == LEADER then
- if $data[2][6] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+if $data[2][4] == leader then
+ if $data[2][6] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
endi
endi
-elif $data[2][6] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+elif $data[2][6] == leader then
+ if $data[2][4] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
endi
endi
-elif $data[2][8] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][6] == FOLLOWER then
+elif $data[2][8] == leader then
+ if $data[2][4] == follower then
+ if $data[2][6] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
endi
endi
@@ -401,21 +401,21 @@ else
goto check_vg_ready1
endi
-if $data[3][4] == LEADER then
- if $data[3][6] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+if $data[3][4] == leader then
+ if $data[3][6] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
endi
endi
-elif $data[3][6] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+elif $data[3][6] == leader then
+ if $data[3][4] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
endi
endi
-elif $data[3][8] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][6] == FOLLOWER then
+elif $data[3][8] == leader then
+ if $data[3][4] == follower then
+ if $data[3][6] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
endi
endi
@@ -423,21 +423,21 @@ else
goto check_vg_ready1
endi
-if $data[4][4] == LEADER then
- if $data[4][6] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+if $data[4][4] == leader then
+ if $data[4][6] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
endi
endi
-elif $data[4][6] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+elif $data[4][6] == leader then
+ if $data[4][4] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
endi
endi
-elif $data[4][8] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][6] == FOLLOWER then
+elif $data[4][8] == leader then
+ if $data[4][4] == follower then
+ if $data[4][6] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
endi
endi
@@ -635,21 +635,21 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
endi
endi
-elif $data[0][6] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][8] == FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] == follower then
+ if $data[0][8] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
endi
endi
-elif $data[0][8] == LEADER then
- if $data[0][4] == FOLLOWER then
- if $data[0][6] == FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] == follower then
+ if $data[0][6] == follower then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
endi
endi
@@ -657,21 +657,21 @@ else
goto check_vg_ready3
endi
-if $data[1][4] == LEADER then
- if $data[1][6] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+if $data[1][4] == leader then
+ if $data[1][6] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
endi
endi
-elif $data[1][6] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][8] == FOLLOWER then
+elif $data[1][6] == leader then
+ if $data[1][4] == follower then
+ if $data[1][8] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
endi
endi
-elif $data[1][8] == LEADER then
- if $data[1][4] == FOLLOWER then
- if $data[1][6] == FOLLOWER then
+elif $data[1][8] == leader then
+ if $data[1][4] == follower then
+ if $data[1][6] == follower then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
endi
endi
@@ -679,21 +679,21 @@ else
goto check_vg_ready3
endi
-if $data[2][4] == LEADER then
- if $data[2][6] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+if $data[2][4] == leader then
+ if $data[2][6] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
endi
endi
-elif $data[2][6] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][8] == FOLLOWER then
+elif $data[2][6] == leader then
+ if $data[2][4] == follower then
+ if $data[2][8] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
endi
endi
-elif $data[2][8] == LEADER then
- if $data[2][4] == FOLLOWER then
- if $data[2][6] == FOLLOWER then
+elif $data[2][8] == leader then
+ if $data[2][4] == follower then
+ if $data[2][6] == follower then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
endi
endi
@@ -701,21 +701,21 @@ else
goto check_vg_ready3
endi
-if $data[3][4] == LEADER then
- if $data[3][6] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+if $data[3][4] == leader then
+ if $data[3][6] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
endi
endi
-elif $data[3][6] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][8] == FOLLOWER then
+elif $data[3][6] == leader then
+ if $data[3][4] == follower then
+ if $data[3][8] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
endi
endi
-elif $data[3][8] == LEADER then
- if $data[3][4] == FOLLOWER then
- if $data[3][6] == FOLLOWER then
+elif $data[3][8] == leader then
+ if $data[3][4] == follower then
+ if $data[3][6] == follower then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
endi
endi
@@ -723,21 +723,21 @@ else
goto check_vg_ready3
endi
-if $data[4][4] == LEADER then
- if $data[4][6] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+if $data[4][4] == leader then
+ if $data[4][6] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
endi
endi
-elif $data[4][6] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][8] == FOLLOWER then
+elif $data[4][6] == leader then
+ if $data[4][4] == follower then
+ if $data[4][8] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
endi
endi
-elif $data[4][8] == LEADER then
- if $data[4][4] == FOLLOWER then
- if $data[4][6] == FOLLOWER then
+elif $data[4][8] == leader then
+ if $data[4][4] == follower then
+ if $data[4][6] == follower then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
endi
endi
@@ -751,5 +751,6 @@ system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
+system sh/exec.sh -n dnode5 -s stop -x SIGINT
diff --git a/tests/script/tsim/sync/3Replica5VgElect3mnode.sim b/tests/script/tsim/sync/3Replica5VgElect3mnode.sim
new file mode 100644
index 0000000000000000000000000000000000000000..8df2c2007da9fdb9e940d9a26995fe49dc4da22b
--- /dev/null
+++ b/tests/script/tsim/sync/3Replica5VgElect3mnode.sim
@@ -0,0 +1,906 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/deploy.sh -n dnode2 -i 2
+system sh/deploy.sh -n dnode3 -i 3
+system sh/deploy.sh -n dnode4 -i 4
+
+system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
+
+system sh/exec.sh -n dnode1 -s start
+system sh/exec.sh -n dnode2 -s start
+system sh/exec.sh -n dnode3 -s start
+system sh/exec.sh -n dnode4 -s start
+
+### create clusters using four dnodes;
+
+
+$loop_cnt = 0
+check_dnode_ready:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 10 then
+ print ====> 1-dnode not ready!
+ return -1
+ endi
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+if $data[0][0] != 1 then
+ return -1
+endi
+if $data[0][4] != ready then
+ goto check_dnode_ready
+endi
+
+sql connect
+sql create dnode $hostname port 7200
+sql create dnode $hostname port 7300
+sql create dnode $hostname port 7400
+
+$loop_cnt = 0
+check_dnode_ready_1:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 10 then
+ print ====> dnodes not ready!
+ return -1
+endi
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+if $data[0][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[1][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[2][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[3][4] != ready then
+ goto check_dnode_ready_1
+endi
+
+$replica = 3
+$vgroups = 5
+
+print ============= create database
+sql create database db replica $replica vgroups $vgroups
+
+$loop_cnt = 0
+check_db_ready:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 100 then
+ print ====> db not ready!
+ return -1
+endi
+sql show databases
+print ===> rows: $rows
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19]
+if $rows != 3 then
+ return -1
+endi
+if $data[2][19] != ready then
+ goto check_db_ready
+endi
+
+sql use db
+
+$loop_cnt = 0
+check_vg_ready:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+if $data[0][4] == LEADER then
+ if $data[0][6] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
+ endi
+ endi
+elif $data[0][6] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
+ endi
+ endi
+elif $data[0][8] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][6] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[1][4] == LEADER then
+ if $data[1][6] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
+ endi
+ endi
+elif $data[1][6] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
+ endi
+ endi
+elif $data[1][8] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][6] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[2][4] == LEADER then
+ if $data[2][6] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
+ endi
+ endi
+elif $data[2][6] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
+ endi
+ endi
+elif $data[2][8] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][6] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[3][4] == LEADER then
+ if $data[3][6] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
+ endi
+ endi
+elif $data[3][6] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
+ endi
+ endi
+elif $data[3][8] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][6] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[4][4] == LEADER then
+ if $data[4][6] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
+ endi
+ endi
+elif $data[4][6] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
+ endi
+ endi
+elif $data[4][8] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][6] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+vg_ready:
+print ====> create stable/child table
+sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
+
+sql show stables
+if $rows != 1 then
+ return -1
+endi
+
+$ctbPrefix = ctb
+$ntbPrefix = ntb
+$tbNum = 10
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ sql create table $ctb using stb tags( $i )
+ $ntb = $ntbPrefix . $i
+ sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
+ $i = $i + 1
+endw
+
+$totalTblNum = $tbNum * 2
+sleep 1000
+sql show tables
+print ====> expect $totalTblNum and infinsert $rows in fact
+if $rows != $totalTblNum then
+ return -1
+endi
+
+sql connect
+print ================ insert data
+$dbNamme = db
+$ctbPrefix = ctb
+$ntbPrefix = ntb
+$tbNum = 10
+$rowNum = 10
+$tstart = 1640966400000 # 2022-01-01 00:00:00.000
+
+
+sql use $dbNamme
+
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ $ntb = $ntbPrefix . $i
+
+ $x = 0
+ while $x < $rowNum
+ $binary = ' . binary
+ $binary = $binary . $i
+ $binary = $binary . '
+
+ sql insert into $ctb values ($tstart , $i , $x , $binary )
+ sql insert into $ntb values ($tstart , 999 , 999 , 'binary-ntb' )
+ $tstart = $tstart + 1
+ $x = $x + 1
+ endw
+
+ $i = $i + 1
+ $tstart = 1640966400000
+endw
+
+print ================ create mnode
+
+
+sql create mnode on dnode 2;
+sql create mnode on dnode 3;
+
+
+$loop_cnt = 0
+check_mnode_ready_2:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> first create three mnode not ready!
+ return -1
+ endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][2] != LEADER then
+ goto check_mnode_ready_2
+endi
+if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_2
+endi
+if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_2
+endi
+
+
+start_switch_leader:
+
+$switch_loop_cnt = 0
+sql show vgroups
+$dnodeId = $data[0][3]
+$dnodeId = dnode . $dnodeId
+
+switch_leader_to_offine_loop:
+
+print $dnodeId
+print ====> stop $dnodeId
+system sh/exec.sh -n $dnodeId -s stop -x SIGINT
+
+
+$loop_cnt = 0
+$loop_cnt = $loop_cnt + 1
+sleep 201
+if $loop_cnt == 300 then
+ print ====> vgroups switch fail!!!
+ return -1
+endi
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+
+vg_offline_1:
+
+print ====> start $dnodeId
+system sh/exec.sh -n $dnodeId -s start
+
+$switch_loop_cnt = $switch_loop_cnt + 1
+print $switch_loop_cnt
+
+if $switch_loop_cnt == 1 then
+ sql show vgroups
+ $dnodeId = $data[1][3]
+ $dnodeId = dnode . $dnodeId
+ goto switch_leader_to_offine_loop
+elif $switch_loop_cnt == 2 then
+ sql show vgroups
+ $dnodeId = $data[2][3]
+ $dnodeId = dnode . $dnodeId
+ goto switch_leader_to_offine_loop
+elif $switch_loop_cnt == 3 then
+ sql show vgroups
+ $dnodeId = $data[3][3]
+ $dnodeId = dnode . $dnodeId
+ goto switch_leader_to_offine_loop
+elif $switch_loop_cnt == 4 then
+ sql show vgroups
+ $dnodeId = $data[4][3]
+ $dnodeId = dnode . $dnodeId
+ goto switch_leader_to_offine_loop
+else
+ goto stop_leader_to_offine_loop
+endi
+
+stop_leader_to_offine_loop:
+
+$loop_cnt = 0
+check_vg_ready1:
+$loop_cnt = $loop_cnt + 1
+print $loop_cnt
+sleep 202
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+if $data[0][4] == LEADER then
+ if $data[0][6] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
+ endi
+ endi
+elif $data[0][6] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
+ endi
+ endi
+elif $data[0][8] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][6] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[1][4] == LEADER then
+ if $data[1][6] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
+ endi
+ endi
+elif $data[1][6] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
+ endi
+ endi
+elif $data[1][8] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][6] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[2][4] == LEADER then
+ if $data[2][6] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
+ endi
+ endi
+elif $data[2][6] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
+ endi
+ endi
+elif $data[2][8] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][6] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[3][4] == LEADER then
+ if $data[3][6] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
+ endi
+ endi
+elif $data[3][6] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
+ endi
+ endi
+elif $data[3][8] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][6] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[4][4] == LEADER then
+ if $data[4][6] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
+ endi
+ endi
+elif $data[4][6] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
+ endi
+ endi
+elif $data[4][8] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][6] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+
+print ====> final test: create stable/child table
+sql create table stb1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
+
+
+sql show stables
+if $rows != 2 then
+ return -1
+endi
+
+$ctbPrefix = ctb1
+$ntbPrefix = ntb1
+$tbNum = 10
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ sql create table $ctb using stb1 tags( $i )
+ $ntb = $ntbPrefix . $i
+ sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
+ $i = $i + 1
+endw
+
+sleep 1000
+sql show stables
+if $rows != 2 then
+ return -1
+endi
+
+sql show tables
+if $rows != 40 then
+ return -1
+endi
+
+
+system sh/deploy.sh -n dnode5 -i 5
+system sh/exec.sh -n dnode5 -s start
+system sh/exec.sh -n dnode1 -s stop
+sleep 1000
+system sh/exec.sh -n dnode1 -s start
+
+sql connect
+sql create dnode $hostname port 7500
+
+$loop_cnt = 0
+check_dnode_ready3:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> 5 dnode not ready!
+ return -1
+ endi
+
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+print ===> $rows $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6]
+
+if $rows != 5 then
+ return -1
+endi
+
+if $data[4][4] != ready then
+ goto check_dnode_ready3
+endi
+
+$loop_cnt = 0
+check_mnode_ready_3:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> second mnode not ready!
+ return -1
+ endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[1][2] == LEADER then
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[2][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+
+# restart clusters
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
+system sh/exec.sh -n dnode2 -s stop -x SIGINT
+system sh/exec.sh -n dnode3 -s stop -x SIGINT
+system sh/exec.sh -n dnode4 -s stop -x SIGINT
+system sh/exec.sh -n dnode5 -s stop -x SIGINT
+
+
+
+system sh/exec.sh -n dnode1 -s start
+system sh/exec.sh -n dnode2 -s start
+system sh/exec.sh -n dnode3 -s start
+system sh/exec.sh -n dnode4 -s start
+system sh/exec.sh -n dnode5 -s start
+
+
+$loop_cnt = 0
+check_dnode_ready_2:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 10 then
+ print ====> restart and dnode not ready!
+ return -1
+ endi
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+print ===> $rows $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6]
+
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][4] != ready then
+ goto check_dnode_ready_2
+endi
+if $data[1][4] != ready then
+ goto check_dnode_ready_2
+endi
+if $data[2][4] != ready then
+ goto check_dnode_ready_2
+endi
+if $data[3][4] != ready then
+ goto check_dnode_ready_2
+endi
+
+sql use db;
+$ctbPrefix = ctb2
+$ntbPrefix = ntb2
+$tbNum = 10
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ sql create table $ctb using stb1 tags( $i )
+ $ntb = $ntbPrefix . $i
+ sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
+ $i = $i + 1
+endw
+
+sleep 1000
+sql use db
+sql show stables
+if $rows != 2 then
+ return -1
+endi
+
+sql show tables
+print $rows
+if $rows != 60 then
+ return -1
+endi
+
+
+
+$replica = 3
+$vgroups = 5
+
+print ============= create database
+sql create database db1 replica $replica vgroups $vgroups
+
+$loop_cnt = 0
+check_db_ready1:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 100 then
+ print ====> db not ready!
+ return -1
+endi
+sql show databases
+print ===> rows: $rows
+print $data(db1)[0] $data(db1)[1] $data(db1)[2] $data(db1)[3] $data(db1)[4] $data(db1)[5] $data(db1)[6] $data(db1)[7] $data(db1)[8] $data(db1)[9] $data(db1)[6] $data(db1)[11] $data(db1)[12] $data(db1)[13] $data(db1)[14] $data(db1)[15] $data(db1)[16] $data(db1)[17] $data(db1)[18] $data(db1)[19]
+if $rows != 4 then
+ return -1
+endi
+if $data(db1)[19] != ready then
+ goto check_db_ready1
+endi
+
+
+
+sql use db1
+
+$loop_cnt = 0
+check_vg_ready3:
+$loop_cnt = $loop_cnt + 1
+print $loop_cnt
+sleep 202
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+if $data[0][4] == LEADER then
+ if $data[0][6] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
+ endi
+ endi
+elif $data[0][6] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
+ endi
+ endi
+elif $data[0][8] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][6] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
+ endi
+ endi
+else
+ goto check_vg_ready3
+endi
+
+if $data[1][4] == LEADER then
+ if $data[1][6] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
+ endi
+ endi
+elif $data[1][6] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
+ endi
+ endi
+elif $data[1][8] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][6] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
+ endi
+ endi
+else
+ goto check_vg_ready3
+endi
+
+if $data[2][4] == LEADER then
+ if $data[2][6] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
+ endi
+ endi
+elif $data[2][6] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
+ endi
+ endi
+elif $data[2][8] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][6] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
+ endi
+ endi
+else
+ goto check_vg_ready3
+endi
+
+if $data[3][4] == LEADER then
+ if $data[3][6] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
+ endi
+ endi
+elif $data[3][6] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
+ endi
+ endi
+elif $data[3][8] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][6] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
+ endi
+ endi
+else
+ goto check_vg_ready3
+endi
+
+if $data[4][4] == LEADER then
+ if $data[4][6] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
+ endi
+ endi
+elif $data[4][6] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
+ endi
+ endi
+elif $data[4][8] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][6] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
+ endi
+ endi
+else
+ goto check_vg_ready3
+endi
+
+
+$loop_cnt = 0
+check_mnode_ready_3:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> third: mnode not ready!
+ return -1
+ endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[1][2] == LEADER then
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[2][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+
+
+
diff --git a/tests/script/tsim/sync/3Replica5VgElect3mnodedrop.sim b/tests/script/tsim/sync/3Replica5VgElect3mnodedrop.sim
new file mode 100644
index 0000000000000000000000000000000000000000..ae02a23c9b47d57239dc89ab71337c27f39e572e
--- /dev/null
+++ b/tests/script/tsim/sync/3Replica5VgElect3mnodedrop.sim
@@ -0,0 +1,627 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/deploy.sh -n dnode2 -i 2
+system sh/deploy.sh -n dnode3 -i 3
+system sh/deploy.sh -n dnode4 -i 4
+
+system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
+
+system sh/exec.sh -n dnode1 -s start
+system sh/exec.sh -n dnode2 -s start
+system sh/exec.sh -n dnode3 -s start
+system sh/exec.sh -n dnode4 -s start
+
+print ===> create clusters using four dnodes;
+
+$loop_cnt = 0
+check_dnode_ready:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 10 then
+ print ====> 1-dnode not ready!
+ return -1
+ endi
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+if $data[0][0] != 1 then
+ return -1
+endi
+if $data[0][4] != ready then
+ goto check_dnode_ready
+endi
+
+sql connect
+sql create dnode $hostname port 7200
+sql create dnode $hostname port 7300
+sql create dnode $hostname port 7400
+
+$loop_cnt = 0
+check_dnode_ready_1:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 10 then
+ print ====> dnodes not ready!
+ return -1
+endi
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+if $data[0][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[1][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[2][4] != ready then
+ goto check_dnode_ready_1
+endi
+if $data[3][4] != ready then
+ goto check_dnode_ready_1
+endi
+
+$replica = 3
+$vgroups = 5
+
+print ============= create database
+sql create database db replica $replica vgroups $vgroups
+
+$loop_cnt = 0
+check_db_ready:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 100 then
+ print ====> db not ready!
+ return -1
+endi
+sql show databases
+print ===> rows: $rows
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19]
+if $rows != 3 then
+ return -1
+endi
+if $data[2][19] != ready then
+ goto check_db_ready
+endi
+
+sql use db
+
+$loop_cnt = 0
+check_vg_ready:
+$loop_cnt = $loop_cnt + 1
+sleep 200
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+if $data[0][4] == LEADER then
+ if $data[0][6] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
+ endi
+ endi
+elif $data[0][6] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
+ endi
+ endi
+elif $data[0][8] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][6] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[1][4] == LEADER then
+ if $data[1][6] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
+ endi
+ endi
+elif $data[1][6] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
+ endi
+ endi
+elif $data[1][8] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][6] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[2][4] == LEADER then
+ if $data[2][6] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
+ endi
+ endi
+elif $data[2][6] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
+ endi
+ endi
+elif $data[2][8] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][6] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[3][4] == LEADER then
+ if $data[3][6] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
+ endi
+ endi
+elif $data[3][6] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
+ endi
+ endi
+elif $data[3][8] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][6] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+if $data[4][4] == LEADER then
+ if $data[4][6] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
+ endi
+ endi
+elif $data[4][6] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
+ endi
+ endi
+elif $data[4][8] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][6] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
+ endi
+ endi
+else
+ goto check_vg_ready
+endi
+
+vg_ready:
+print ====> create stable/child table
+sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
+
+sql show stables
+if $rows != 1 then
+ return -1
+endi
+
+$ctbPrefix = ctb
+$ntbPrefix = ntb
+$tbNum = 10
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ sql create table $ctb using stb tags( $i )
+ $ntb = $ntbPrefix . $i
+ sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
+ $i = $i + 1
+endw
+
+$totalTblNum = $tbNum * 2
+sleep 1000
+sql show tables
+print ====> expect $totalTblNum and infinsert $rows in fact
+if $rows != $totalTblNum then
+ return -1
+endi
+
+sql connect
+print ================ insert data
+$dbNamme = db
+$ctbPrefix = ctb
+$ntbPrefix = ntb
+$tbNum = 10
+$rowNum = 10
+$tstart = 1640966400000 # 2022-01-01 00:00:00.000
+
+
+sql use $dbNamme
+
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ $ntb = $ntbPrefix . $i
+
+ $x = 0
+ while $x < $rowNum
+ $binary = ' . binary
+ $binary = $binary . $i
+ $binary = $binary . '
+
+ sql insert into $ctb values ($tstart , $i , $x , $binary )
+ sql insert into $ntb values ($tstart , 999 , 999 , 'binary-ntb' )
+ $tstart = $tstart + 1
+ $x = $x + 1
+ endw
+
+ $i = $i + 1
+ $tstart = 1640966400000
+endw
+
+print ================ create mnode
+
+
+sql create mnode on dnode 2;
+sql create mnode on dnode 3;
+
+
+$loop_cnt = 0
+check_mnode_ready_2:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> first create three mnode not ready!
+ return -1
+ endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][2] != LEADER then
+ goto check_mnode_ready_2
+endi
+if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_2
+endi
+if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_2
+endi
+
+
+$loop_cnt = 0
+check_vg_ready1:
+$loop_cnt = $loop_cnt + 1
+print $loop_cnt
+sleep 202
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+sql show vgroups
+print ===> rows: $rows
+print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
+print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] $data[1][7] $data[1][8] $data[1][9] $data[1][10] $data[1][11]
+print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][10] $data[2][11]
+print $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] $data[3][7] $data[3][8] $data[3][9] $data[3][10] $data[3][11]
+print $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6] $data[4][7] $data[4][8] $data[4][9] $data[4][10] $data[4][11]
+if $rows != $vgroups then
+ return -1
+endi
+
+if $data[0][4] == LEADER then
+ if $data[0][6] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
+ endi
+ endi
+elif $data[0][6] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][8] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
+ endi
+ endi
+elif $data[0][8] == LEADER then
+ if $data[0][4] == FOLLOWER then
+ if $data[0][6] == FOLLOWER then
+ print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[1][4] == LEADER then
+ if $data[1][6] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
+ endi
+ endi
+elif $data[1][6] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][8] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
+ endi
+ endi
+elif $data[1][8] == LEADER then
+ if $data[1][4] == FOLLOWER then
+ if $data[1][6] == FOLLOWER then
+ print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[2][4] == LEADER then
+ if $data[2][6] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
+ endi
+ endi
+elif $data[2][6] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][8] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
+ endi
+ endi
+elif $data[2][8] == LEADER then
+ if $data[2][4] == FOLLOWER then
+ if $data[2][6] == FOLLOWER then
+ print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[3][4] == LEADER then
+ if $data[3][6] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
+ endi
+ endi
+elif $data[3][6] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][8] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
+ endi
+ endi
+elif $data[3][8] == LEADER then
+ if $data[3][4] == FOLLOWER then
+ if $data[3][6] == FOLLOWER then
+ print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+if $data[4][4] == LEADER then
+ if $data[4][6] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
+ endi
+ endi
+elif $data[4][6] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][8] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
+ endi
+ endi
+elif $data[4][8] == LEADER then
+ if $data[4][4] == FOLLOWER then
+ if $data[4][6] == FOLLOWER then
+ print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
+ endi
+ endi
+else
+ goto check_vg_ready1
+endi
+
+
+print ====> final test: create stable/child table
+sql create table stb1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
+
+
+sql show stables
+if $rows != 2 then
+ return -1
+endi
+
+$ctbPrefix = ctb1
+$ntbPrefix = ntb1
+$tbNum = 10
+$i = 0
+while $i < $tbNum
+ $ctb = $ctbPrefix . $i
+ sql create table $ctb using stb1 tags( $i )
+ $ntb = $ntbPrefix . $i
+ sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
+ $i = $i + 1
+endw
+
+sleep 1000
+sql show stables
+if $rows != 2 then
+ return -1
+endi
+
+sql show tables
+if $rows != 40 then
+ return -1
+endi
+
+
+system sh/deploy.sh -n dnode5 -i 5
+system sh/exec.sh -n dnode5 -s start
+
+sql connect
+sql create dnode $hostname port 7500
+
+$loop_cnt = 0
+check_dnode_ready3:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> 5 dnode not ready!
+ return -1
+ endi
+
+sql show dnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
+print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
+print ===> $rows $data[4][0] $data[4][1] $data[4][2] $data[4][3] $data[4][4] $data[4][5] $data[4][6]
+
+if $rows != 5 then
+ return -1
+endi
+
+if $data[4][4] != ready then
+ goto check_dnode_ready3
+endi
+
+print ===> 1:if create users sucessfully,then drop mnode leader
+sql create user chr pass '123'
+$loop_cnt = 0
+check_user_ready:
+$loop_cnt = $loop_cnt + 1
+print $loop_cnt
+sleep 200
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+
+sql show users
+print ===> rows: $rows
+print ===> $rows $data[0][0] $data[0][1] $data[0][2]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2]
+if $rows != 2 then
+ goto check_user_ready
+endi
+
+if $data[0][0] == chr then
+ goto check_user_ready_suc
+elif $data[1][0] == chr
+ goto check_user_ready_suc
+else
+ print ====> creating user failed
+ goto check_user_ready
+endi
+
+check_user_ready_suc:
+
+$loop_cnt = 0
+check_mnode_ready_3:
+ $loop_cnt = $loop_cnt + 1
+ sleep 200
+ if $loop_cnt == 100 then
+ print ====> second mnode not ready!
+ return -1
+ endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+if $data[0][0] != 1 then
+ return -1
+endi
+
+if $data[0][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[1][2] == LEADER then
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[2][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+if $data[2][2] == LEADER then
+ if $data[1][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+ if $data[0][2] != FOLLOWER then
+ goto check_mnode_ready_3
+ endi
+endi
+
+sleep 2000
+# stop leader and drop dnode
+system sh/exec.sh -n dnode1 -s stop
+sleep 2000
+
+print ===> 2:if create users sucessfully,then drop mnode leader
+sql create user chr2 pass '123'
+$loop_cnt = 0
+check_user_ready2:
+$loop_cnt = $loop_cnt + 1
+print $loop_cnt
+sleep 200
+if $loop_cnt == 300 then
+ print ====> vgroups not ready!
+ return -1
+endi
+sql show mnodes
+print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3]
+
+sql show users
+print ===> rows: $rows
+print ===> $rows $data[0][0] $data[0][1] $data[0][2]
+print ===> $rows $data[1][0] $data[1][1] $data[1][2]
+print ===> $rows $data[2][0] $data[2][1] $data[2][2]
+
+if $rows != 3 then
+ goto check_user_ready2
+endi
+
+if $data[0][0] == chr2 then
+ goto check_user_ready2_suc
+elif $data[1][0] == chr2
+ goto check_user_ready2_suc
+else
+ print ====> creating user failed
+ goto check_user_ready2
+endi
+
+check_user_ready2_suc:
+
diff --git a/tests/script/tsim/sync/oneReplica1VgElect.sim b/tests/script/tsim/sync/oneReplica1VgElect.sim
index d98b823192b82556f0327f5107d2d359176e19cb..cf8912e654c04314e96a5fb4a718a3569ddea5f5 100644
--- a/tests/script/tsim/sync/oneReplica1VgElect.sim
+++ b/tests/script/tsim/sync/oneReplica1VgElect.sim
@@ -103,13 +103,13 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
goto vg_ready
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
goto vg_ready
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
goto vg_ready
else
@@ -154,11 +154,11 @@ switch_leader_to_offine_loop:
print ====> finde vnode of leader, and stop the dnode where the vnode is located, and query stb/ntb count(*)
sql show vgroups
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][6] $data[0][11] $data[0][12] $data[0][13]
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
$dnodeId = $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
$dnodeId = $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
$dnodeId = $data[0][7]
else
print ====> no leader vnode!!!
@@ -186,13 +186,13 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == OFFLINE then
+if $data[0][4] == offline then
print ---- vgroup $dnodeId leader switch to offline
goto vg_offline_1
-elif $data[0][6] == OFFLINE then
+elif $data[0][6] == offline then
print ---- vgroup $dnodeId leader switch to offline
goto vg_offline_1
-elif $data[0][8] == OFFLINE then
+elif $data[0][8] == offline then
print ---- vgroup $dnodeId leader switch to offline
goto vg_offline_1
else
@@ -218,13 +218,13 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
goto countinu_loop
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
goto countinu_loop
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
goto countinu_loop
else
diff --git a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim
index 7ceeb2806b320014c2b35ea5c640063e44793063..06a67b3c1bfdf183f919fb7ac9c861055f566f42 100644
--- a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim
+++ b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim
@@ -104,7 +104,7 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
if $data[0][6] != NULL then
goto check_vg_ready
endi
@@ -114,7 +114,7 @@ if $data[0][4] == LEADER then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
goto vg_ready
endi
-if $data[0][6] == LEADER then
+if $data[0][6] == leader then
if $data[0][4] != NULL then
goto check_vg_ready
endi
@@ -124,7 +124,7 @@ if $data[0][6] == LEADER then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
goto vg_ready
endi
-if $data[0][8] == LEADER then
+if $data[0][8] == leader then
if $data[0][4] != NULL then
goto check_vg_ready
endi
@@ -208,11 +208,11 @@ switch_leader_loop:
print ====> finde vnode of leader, and stop the dnode where the vnode is located, and query stb/ntb count(*)
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
$dnodeId = $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
$dnodeId = $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
$dnodeId = $data[0][7]
else
print ====> no leader vnode!!!
@@ -238,7 +238,7 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
if $data[0][6] != NULL then
goto check_vg_ready_2
endi
@@ -248,7 +248,7 @@ if $data[0][4] == LEADER then
print ---- vgroup $data[0][0] leader switch to dnode $data[0][3]
goto vg_ready_2
endi
-if $data[0][6] == LEADER then
+if $data[0][6] == leader then
if $data[0][4] != NULL then
goto check_vg_ready_2
endi
@@ -258,7 +258,7 @@ if $data[0][6] == LEADER then
print ---- vgroup $data[0][0] leader switch to dnode $data[0][5]
goto vg_ready_2
endi
-if $data[0][8] == LEADER then
+if $data[0][8] == leader then
if $data[0][4] != NULL then
goto check_vg_ready_2
endi
@@ -343,7 +343,7 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
if $data[0][6] != NULL then
goto check_vg_ready_1
endi
@@ -352,7 +352,7 @@ if $data[0][4] == LEADER then
endi
goto vg_ready_1
endi
-if $data[0][6] == LEADER then
+if $data[0][6] == leader then
if $data[0][4] != NULL then
goto check_vg_ready_1
endi
@@ -361,7 +361,7 @@ if $data[0][6] == LEADER then
endi
goto vg_ready_1
endi
-if $data[0][8] == LEADER then
+if $data[0][8] == leader then
if $data[0][4] != NULL then
goto check_vg_ready_1
endi
diff --git a/tests/script/tsim/sync/oneReplica5VgElect.sim b/tests/script/tsim/sync/oneReplica5VgElect.sim
index d6d18093c341dfea8d4d2f1c22fa10cab173d71c..5af48c7491208c8f3a440665fa7bb6919c373a46 100644
--- a/tests/script/tsim/sync/oneReplica5VgElect.sim
+++ b/tests/script/tsim/sync/oneReplica5VgElect.sim
@@ -104,51 +104,51 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready
endi
-if $data[1][4] == LEADER then
+if $data[1][4] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[0][3]
-elif $data[1][6] == LEADER then
+elif $data[1][6] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[0][5]
-elif $data[1][8] == LEADER then
+elif $data[1][8] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready
endi
-if $data[2][4] == LEADER then
+if $data[2][4] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[0][3]
-elif $data[2][6] == LEADER then
+elif $data[2][6] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[0][5]
-elif $data[2][8] == LEADER then
+elif $data[2][8] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready
endi
-if $data[3][4] == LEADER then
+if $data[3][4] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[0][3]
-elif $data[3][6] == LEADER then
+elif $data[3][6] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[0][5]
-elif $data[3][8] == LEADER then
+elif $data[3][8] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready
endi
-if $data[4][4] == LEADER then
+if $data[4][4] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[0][3]
-elif $data[4][6] == LEADER then
+elif $data[4][6] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[0][5]
-elif $data[4][8] == LEADER then
+elif $data[4][8] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready
@@ -272,51 +272,51 @@ if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
else
goto check_vg_ready1
endi
-if $data[1][4] == LEADER then
+if $data[1][4] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][3]
-elif $data[1][6] == LEADER then
+elif $data[1][6] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][5]
-elif $data[1][8] == LEADER then
+elif $data[1][8] == leader then
print ---- vgroup $data[1][0] leader locate on dnode $data[1][7]
else
goto check_vg_ready1
endi
-if $data[2][4] == LEADER then
+if $data[2][4] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][3]
-elif $data[2][6] == LEADER then
+elif $data[2][6] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][5]
-elif $data[2][8] == LEADER then
+elif $data[2][8] == leader then
print ---- vgroup $data[2][0] leader locate on dnode $data[2][7]
else
goto check_vg_ready
endi
-if $data[3][4] == LEADER then
+if $data[3][4] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][3]
-elif $data[3][6] == LEADER then
+elif $data[3][6] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][5]
-elif $data[3][8] == LEADER then
+elif $data[3][8] == leader then
print ---- vgroup $data[3][0] leader locate on dnode $data[3][7]
else
goto check_vg_ready1
endi
-if $data[4][4] == LEADER then
+if $data[4][4] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][3]
-elif $data[4][6] == LEADER then
+elif $data[4][6] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][5]
-elif $data[4][8] == LEADER then
+elif $data[4][8] == leader then
print ---- vgroup $data[4][0] leader locate on dnode $data[4][7]
else
goto check_vg_ready1
diff --git a/tests/script/tsim/sync/threeReplica1VgElect.sim b/tests/script/tsim/sync/threeReplica1VgElect.sim
index 1496d7c778b475895479eb3661fae7ad86a121d3..c3e9c13793466ecdd57890d7e48a71f5b04ca190 100644
--- a/tests/script/tsim/sync/threeReplica1VgElect.sim
+++ b/tests/script/tsim/sync/threeReplica1VgElect.sim
@@ -104,7 +104,7 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
if $data[0][6] != FLLOWER then
goto check_vg_ready
endi
@@ -114,7 +114,7 @@ if $data[0][4] == LEADER then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
goto vg_ready
endi
-if $data[0][6] == LEADER then
+if $data[0][6] == leader then
if $data[0][4] != FLLOWER then
goto check_vg_ready
endi
@@ -124,7 +124,7 @@ if $data[0][6] == LEADER then
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
goto vg_ready
endi
-if $data[0][8] == LEADER then
+if $data[0][8] == leader then
if $data[0][4] != FLLOWER then
goto check_vg_ready
endi
@@ -199,11 +199,11 @@ endi
print ====> finde vnode of leader, and stop the dnode where the vnode is located, and query stb/ntb count(*)
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
$dnodeId = $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
$dnodeId = $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
$dnodeId = $data[0][7]
else
print ====> no leader vnode!!!
@@ -216,11 +216,11 @@ system sh/exec.sh -n $dnodeId -s stop -x SIGINT
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
print ---- vgroup $data[0][0] leader switch to dnode $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
print ---- vgroup $data[0][0] leader switch to dnode $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
print ---- vgroup $data[0][0] leader switch to dnode $data[0][7]
else
print ====> no leader vnode!!!
@@ -264,7 +264,7 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
if $data[0][6] != FLLOWER then
goto check_vg_ready_1
endi
@@ -273,7 +273,7 @@ if $data[0][4] == LEADER then
endi
goto vg_ready_1
endi
-if $data[0][6] == LEADER then
+if $data[0][6] == leader then
if $data[0][4] != FLLOWER then
goto check_vg_ready_1
endi
@@ -282,7 +282,7 @@ if $data[0][6] == LEADER then
endi
goto vg_ready_1
endi
-if $data[0][8] == LEADER then
+if $data[0][8] == leader then
if $data[0][4] != FLLOWER then
goto check_vg_ready_1
endi
@@ -325,27 +325,27 @@ system sh/exec.sh -n $dnodeId -s stop -x SIGINT
check_vg_ready_3:
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
- if $data[0][6] == LEADER then
+if $data[0][4] == leader then
+ if $data[0][6] == leader then
goto check_vg_ready_3
endi
- if $data[0][8] == LEADER then
+ if $data[0][8] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][5]
-elif $data[0][6] == LEADER then
- if $data[0][4] == LEADER then
+elif $data[0][6] == leader then
+ if $data[0][4] == leader then
goto check_vg_ready_3
endi
- if $data[0][8] == LEADER then
+ if $data[0][8] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][7]
-elif $data[0][8] == LEADER then
- if $data[0][4] == LEADER then
+elif $data[0][8] == leader then
+ if $data[0][4] == leader then
goto check_vg_ready_3
endi
- if $data[0][6] == LEADER then
+ if $data[0][6] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][9]
diff --git a/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim b/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim
index fc501096e687c0b7681bbf9e7fcad706f7aafced..3c21dff1b65a9737d96f9e0d9ae1b8c173fa3250 100644
--- a/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim
+++ b/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim
@@ -103,29 +103,29 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] != FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] != follower then
goto check_vg_ready
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready
endi
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
goto vg_ready
-elif $data[0][6] == LEADER then
- if $data[0][4] != FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready
endi
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
goto vg_ready
-elif $data[0][8] == LEADER then
- if $data[0][4] != FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready
endi
- if $data[0][6] != FOLLOWER then
+ if $data[0][6] != follower then
goto check_vg_ready
endi
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
@@ -193,11 +193,11 @@ switch_leader_loop:
print ====> finde vnode of leader, and stop the dnode where the vnode is located, and query stb/ntb count(*)
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
+if $data[0][4] == leader then
$dnodeId = $data[0][3]
-elif $data[0][6] == LEADER then
+elif $data[0][6] == leader then
$dnodeId = $data[0][5]
-elif $data[0][8] == LEADER then
+elif $data[0][8] == leader then
$dnodeId = $data[0][7]
else
print ====> no leader vnode!!!
@@ -226,29 +226,29 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] != FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] != follower then
goto check_vg_ready_2
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready_2
endi
print ---- vgroup $dnodeId leader switch to dnode $data[0][3]
goto vg_ready_2
-elif $data[0][6] == LEADER then
- if $data[0][4] != FOLLOWER then
+elif $data[0][6] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready_2
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready_2
endi
print ---- vgroup $dnodeId leader switch to dnode $data[0][5]
goto vg_ready_2
-elif $data[0][8] == LEADER then
- if $data[0][4] != FOLLOWER then
+elif $data[0][8] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready_2
endi
- if $data[0][6] != FOLLOWER then
+ if $data[0][6] != follower then
goto check_vg_ready_2
endi
print ---- vgroup $dnodeId leader switch to dnode $data[0][7]
@@ -329,29 +329,29 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $d
if $rows != $vgroups then
return -1
endi
-if $data[0][4] == LEADER then
- if $data[0][6] != FOLLOWER then
+if $data[0][4] == leader then
+ if $data[0][6] != follower then
goto check_vg_ready_1
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready_1
endi
goto vg_ready_1
endi
-if $data[0][6] == LEADER then
- if $data[0][4] != FOLLOWER then
+if $data[0][6] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready_1
endi
- if $data[0][8] != FOLLOWER then
+ if $data[0][8] != follower then
goto check_vg_ready_1
endi
goto vg_ready_1
endi
-if $data[0][8] == LEADER then
- if $data[0][4] != FOLLOWER then
+if $data[0][8] == leader then
+ if $data[0][4] != follower then
goto check_vg_ready_1
endi
- if $data[0][6] != FOLLOWER then
+ if $data[0][6] != follower then
goto check_vg_ready_1
endi
goto vg_ready_1
@@ -390,27 +390,27 @@ system sh/exec.sh -n $dnodeId -s stop -x SIGINT
check_vg_ready_3:
sql show vgroups
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
-if $data[0][4] == LEADER then
- if $data[0][6] == LEADER then
+if $data[0][4] == leader then
+ if $data[0][6] == leader then
goto check_vg_ready_3
endi
- if $data[0][8] == LEADER then
+ if $data[0][8] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][5]
-elif $data[0][6] == LEADER then
- if $data[0][4] == LEADER then
+elif $data[0][6] == leader then
+ if $data[0][4] == leader then
goto check_vg_ready_3
endi
- if $data[0][8] == LEADER then
+ if $data[0][8] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][7]
-elif $data[0][8] == LEADER then
- if $data[0][4] == LEADER then
+elif $data[0][8] == leader then
+ if $data[0][4] == leader then
goto check_vg_ready_3
endi
- if $data[0][6] == LEADER then
+ if $data[0][6] == leader then
goto check_vg_ready_3
endi
print ---- vgroup $data[0][0] leader locating dnode $data[0][9]
diff --git a/tests/script/tsim/testsuit.sim b/tests/script/tsim/testsuit.sim
index 0b1f0df04e9db6af2547cc1da49873082b2682b3..883dc1e7895015626c2f3a185fabfc38cf86a449 100644
--- a/tests/script/tsim/testsuit.sim
+++ b/tests/script/tsim/testsuit.sim
@@ -1,80 +1,103 @@
-#run user/pass_alter.sim
-#run user/basic1.sim
-#run user/privilege2.sim
-#run user/user_len.sim
-#run user/privilege1.sim
-#run user/pass_len.sim
-#run tstream/basic1.sim
-#run tstream/basic0.sim
-#run table/basic1.sim
-#run trans/create_db.sim
-#run stable/alter1.sim
-#run stable/vnode3.sim
-#run stable/metrics.sim
-#run stable/show.sim
-#run stable/values.sim
-#run stable/dnode3.sim
-#run stable/refcount.sim
-#run stable/disk.sim
-#run db/basic1.sim
-#run db/basic3.sim
-#run db/basic7.sim
-#run db/basic6.sim
-#run db/create_all_options.sim
-#run db/basic2.sim
-#run db/error1.sim
-#run db/taosdlog.sim
-#run db/alter_option.sim
-#run mnode/basic1.sim
-#run parser/fourArithmetic-basic.sim
-#run parser/groupby-basic.sim
-#run snode/basic1.sim
-#run query/time_process.sim
-#run query/stddev.sim
-#run query/interval-offset.sim
-#run query/charScalarFunction.sim
-#run query/complex_select.sim
-#run query/explain.sim
-#run query/crash_sql.sim
-#run query/diff.sim
-#run query/complex_limit.sim
-#run query/complex_having.sim
-#run query/udf.sim
-#run query/complex_group.sim
-#run query/interval.sim
-#run query/session.sim
-
-print ========> dead lock failed when 2 rows in outputCapacity
-run query/scalarFunction.sim
-run query/scalarNull.sim
-run query/complex_where.sim
-run tmq/basic1.sim
-run tmq/basic4.sim
-run tmq/basic1Of2Cons.sim
-run tmq/prepareBasicEnv-1vgrp.sim
-run tmq/topic.sim
-run tmq/basic4Of2Cons.sim
-run tmq/prepareBasicEnv-4vgrp.sim
-run tmq/basic3.sim
-run tmq/basic2Of2Cons.sim
-run tmq/basic2.sim
-run tmq/basic3Of2Cons.sim
-run tmq/basic2Of2ConsOverlap.sim
-run tmq/clearConsume.sim
-run qnode/basic1.sim
-run dnode/basic1.sim
-run show/basic.sim
-run insert/basic1.sim
-run insert/basic0.sim
-run insert/backquote.sim
-run insert/null.sim
-run sync/oneReplica1VgElectWithInsert.sim
-run sync/threeReplica1VgElect.sim
-run sync/oneReplica1VgElect.sim
-run sync/insertDataByRunBack.sim
-run sync/threeReplica1VgElectWihtInsert.sim
-run sma/tsmaCreateInsertData.sim
-run sma/rsmaCreateInsertQuery.sim
-run valgrind/checkError.sim
-run bnode/basic1.sim
-
+run tsim/user/pass_alter.sim
+run tsim/user/basic1.sim
+run tsim/user/privilege2.sim
+run tsim/user/user_len.sim
+run tsim/user/privilege1.sim
+run tsim/user/pass_len.sim
+run tsim/table/basic1.sim
+run tsim/trans/lossdata1.sim
+run tsim/trans/create_db.sim
+run tsim/stable/alter_metrics.sim
+run tsim/stable/tag_modify.sim
+run tsim/stable/alter_comment.sim
+run tsim/stable/column_drop.sim
+run tsim/stable/column_modify.sim
+run tsim/stable/tag_rename.sim
+run tsim/stable/vnode3.sim
+run tsim/stable/metrics.sim
+run tsim/stable/alter_insert2.sim
+run tsim/stable/show.sim
+run tsim/stable/alter_import.sim
+run tsim/stable/tag_add.sim
+run tsim/stable/tag_drop.sim
+run tsim/stable/column_add.sim
+run tsim/stable/alter_count.sim
+run tsim/stable/values.sim
+run tsim/stable/dnode3.sim
+run tsim/stable/alter_insert1.sim
+run tsim/stable/refcount.sim
+run tsim/stable/disk.sim
+run tsim/db/basic1.sim
+run tsim/db/basic3.sim
+run tsim/db/basic7.sim
+run tsim/db/basic6.sim
+run tsim/db/create_all_options.sim
+run tsim/db/basic2.sim
+run tsim/db/error1.sim
+run tsim/db/taosdlog.sim
+run tsim/db/alter_option.sim
+run tsim/mnode/basic1.sim
+run tsim/mnode/basic3.sim
+run tsim/mnode/basic2.sim
+run tsim/parser/fourArithmetic-basic.sim
+run tsim/parser/groupby-basic.sim
+run tsim/snode/basic1.sim
+run tsim/query/time_process.sim
+run tsim/query/stddev.sim
+run tsim/query/interval-offset.sim
+run tsim/query/charScalarFunction.sim
+run tsim/query/complex_select.sim
+run tsim/query/explain.sim
+run tsim/query/crash_sql.sim
+run tsim/query/diff.sim
+run tsim/query/complex_limit.sim
+run tsim/query/complex_having.sim
+run tsim/query/udf.sim
+run tsim/query/complex_group.sim
+run tsim/query/interval.sim
+run tsim/query/session.sim
+run tsim/query/scalarFunction.sim
+run tsim/query/scalarNull.sim
+run tsim/query/complex_where.sim
+run tsim/tmq/basic1.sim
+run tsim/tmq/basic4.sim
+run tsim/tmq/basic1Of2Cons.sim
+run tsim/tmq/prepareBasicEnv-1vgrp.sim
+run tsim/tmq/topic.sim
+run tsim/tmq/basic4Of2Cons.sim
+run tsim/tmq/prepareBasicEnv-4vgrp.sim
+run tsim/tmq/basic3.sim
+run tsim/tmq/basic2Of2Cons.sim
+run tsim/tmq/basic2.sim
+run tsim/tmq/basic3Of2Cons.sim
+run tsim/tmq/basic2Of2ConsOverlap.sim
+run tsim/tmq/clearConsume.sim
+run tsim/qnode/basic1.sim
+run tsim/dnode/basic1.sim
+run tsim/show/basic.sim
+run tsim/stream/basic1.sim
+run tsim/stream/triggerInterval0.sim
+run tsim/stream/triggerSession0.sim
+run tsim/stream/basic0.sim
+run tsim/stream/session0.sim
+run tsim/stream/session1.sim
+run tsim/stream/basic2.sim
+run tsim/insert/basic1.sim
+run tsim/insert/commit-merge0.sim
+run tsim/insert/basic0.sim
+run tsim/insert/update0.sim
+run tsim/insert/backquote.sim
+run tsim/insert/null.sim
+run tsim/sync/oneReplica1VgElectWithInsert.sim
+run tsim/sync/threeReplica1VgElect.sim
+run tsim/sync/oneReplica1VgElect.sim
+run tsim/sync/3Replica5VgElect.sim
+run tsim/sync/insertDataByRunBack.sim
+run tsim/sync/oneReplica5VgElect.sim
+run tsim/sync/3Replica1VgElect.sim
+run tsim/sync/threeReplica1VgElectWihtInsert.sim
+run tsim/sma/tsmaCreateInsertData.sim
+run tsim/sma/rsmaCreateInsertQuery.sim
+run tsim/valgrind/basic.sim
+run tsim/valgrind/checkError.sim
+run tsim/bnode/basic1.sim
\ No newline at end of file
diff --git a/tests/script/tsim/trans/create_db.sim b/tests/script/tsim/trans/create_db.sim
index 158a6b9f920e8e194f5336f8985bf609d9c7f2a1..e13014f9c02370f65cf1e1700b84efdc4bcdcce2 100644
--- a/tests/script/tsim/trans/create_db.sim
+++ b/tests/script/tsim/trans/create_db.sim
@@ -26,7 +26,7 @@ if $data00 != 1 then
return -1
endi
-if $data02 != LEADER then
+if $data02 != leader then
return -1
endi
diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py
index 657979658e5b048e8d51d0bf8c67bada5f321402..a219c54e5925075a2c687c9cd134ada03c09e57e 100644
--- a/tests/system-test/0-others/taosdMonitor.py
+++ b/tests/system-test/0-others/taosdMonitor.py
@@ -75,7 +75,7 @@ def telemetryInfoCheck(infoDict=''):
if k not in infoDict["cluster_info"]["dnodes"][0] or v != infoDict["cluster_info"]["dnodes"][0][k] :
tdLog.exit("dnodes info is null!")
- mnodes_info = { "mnode_id":1, "mnode_ep":f"{hostname}:{serverPort}","role": "LEADER" }
+ mnodes_info = { "mnode_id":1, "mnode_ep":f"{hostname}:{serverPort}","role": "leader" }
for k ,v in mnodes_info.items():
if k not in infoDict["cluster_info"]["mnodes"][0] or v != infoDict["cluster_info"]["mnodes"][0][k] :
diff --git a/tests/system-test/1-insert/influxdb_line_taosc_insert.py b/tests/system-test/1-insert/influxdb_line_taosc_insert.py
index 75e0c3d59cc52159cbcaaf93fae9b11a278c59d0..0ddeba46652d7d724f15cea0476c7baa8c60cc30 100644
--- a/tests/system-test/1-insert/influxdb_line_taosc_insert.py
+++ b/tests/system-test/1-insert/influxdb_line_taosc_insert.py
@@ -33,10 +33,10 @@ class TDTestCase:
def createDb(self, name="test", db_update_tag=0):
if db_update_tag == 0:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'ms'")
+ tdSql.execute(f"create database if not exists {name} precision 'ms' schemaless 1")
else:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'ms' update 1")
+ tdSql.execute(f"create database if not exists {name} precision 'ms' update 1 schemaless 1")
tdSql.execute(f'use {name}')
def timeTrans(self, time_value, ts_type):
diff --git a/tests/system-test/1-insert/opentsdb_json_taosc_insert.py b/tests/system-test/1-insert/opentsdb_json_taosc_insert.py
index 360d878dfeb48184a162016bb9499caa5c7fcacc..f9bc5bbaf421394cf936bb4aaa031649a4ffa8f5 100644
--- a/tests/system-test/1-insert/opentsdb_json_taosc_insert.py
+++ b/tests/system-test/1-insert/opentsdb_json_taosc_insert.py
@@ -36,10 +36,10 @@ class TDTestCase:
if db_update_tag == 0:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'ms'")
+ tdSql.execute(f"create database if not exists {name} precision 'ms' schemaless 1")
else:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'ms' update 1")
+ tdSql.execute(f"create database if not exists {name} precision 'ms' update 1 schemaless 1")
tdSql.execute(f'use {name}')
def timeTrans(self, time_value):
@@ -535,7 +535,7 @@ class TDTestCase:
# check result
#! bug
tdSql.execute(f"drop database if exists test_ts")
- tdSql.execute(f"create database if not exists test_ts precision 'ms'")
+ tdSql.execute(f"create database if not exists test_ts precision 'ms' schemaless 1")
tdSql.execute("use test_ts")
input_json = [{"metric": "test_ms", "timestamp": {"value": 1626006833640, "type": "ms"}, "value": True, "tags": {"t0": True}},
{"metric": "test_ms", "timestamp": {"value": 1626006833641, "type": "ms"}, "value": False, "tags": {"t0": True}}]
@@ -545,7 +545,7 @@ class TDTestCase:
tdSql.checkEqual(str(res[1][0]), "2021-07-11 20:33:53.641000")
tdSql.execute(f"drop database if exists test_ts")
- tdSql.execute(f"create database if not exists test_ts precision 'us'")
+ tdSql.execute(f"create database if not exists test_ts precision 'us' schemaless 1")
tdSql.execute("use test_ts")
input_json = [{"metric": "test_us", "timestamp": {"value": 1626006833639000, "type": "us"}, "value": True, "tags": {"t0": True}},
{"metric": "test_us", "timestamp": {"value": 1626006833639001, "type": "us"}, "value": False, "tags": {"t0": True}}]
@@ -555,7 +555,7 @@ class TDTestCase:
tdSql.checkEqual(str(res[1][0]), "2021-07-11 20:33:53.639001")
tdSql.execute(f"drop database if exists test_ts")
- tdSql.execute(f"create database if not exists test_ts precision 'ns'")
+ tdSql.execute(f"create database if not exists test_ts precision 'ns' schemaless 1")
tdSql.execute("use test_ts")
input_json = [{"metric": "test_ns", "timestamp": {"value": 1626006833639000000, "type": "ns"}, "value": True, "tags": {"t0": True}},
{"metric": "test_ns", "timestamp": {"value": 1626006833639000001, "type": "ns"}, "value": False, "tags": {"t0": True}}]
diff --git a/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py b/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py
index 6d50dd4fda16932a68edeb0e0084b2b4546c5092..23404330ed450bca999dc593b0675d4eb7d54eb0 100644
--- a/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py
+++ b/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py
@@ -36,10 +36,10 @@ class TDTestCase:
if db_update_tag == 0:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'us'")
+ tdSql.execute(f"create database if not exists {name} precision 'us' schemaless 1")
else:
tdSql.execute(f"drop database if exists {name}")
- tdSql.execute(f"create database if not exists {name} precision 'ns' update 1")
+ tdSql.execute(f"create database if not exists {name} precision 'ns' update 1 schemaless 1")
tdSql.execute(f'use {name}')
def timeTrans(self, time_value, ts_type):
@@ -393,7 +393,7 @@ class TDTestCase:
self.resCmp(input_sql, stb_name, ts_type=TDSmlTimestampType.SECOND.value)
tdSql.execute(f"drop database if exists test_ts")
- tdSql.execute(f"create database if not exists test_ts precision 'ms'")
+ tdSql.execute(f"create database if not exists test_ts precision 'ms' schemaless 1")
tdSql.execute("use test_ts")
input_sql = ['test_ms 1626006833640 t t0=t', 'test_ms 1626006833641 f t0=t']
self._conn.schemaless_insert(input_sql, TDSmlProtocolType.TELNET.value, None)
diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py
index c8cbd269f9ce2c3ae0e5bd6b0361f0eb4252b1a9..1d929646159d36a14b5ce6e9e95e1b02ad0be43a 100644
--- a/tests/system-test/2-query/mavg.py
+++ b/tests/system-test/2-query/mavg.py
@@ -288,15 +288,18 @@ class TDTestCase:
else:
tdSql.query(f"select {col} from {table_expr} {re.sub('limit [0-9]*|offset [0-9]*','',condition)}")
offset_val = condition.split("offset")[1].split(" ")[1] if "offset" in condition else 0
- pre_result = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None]
- pre_mavg = pre_mavg = np.convolve(pre_result, np.ones(k), "valid")[offset_val:]/k
- tdSql.query(self.mavg_query_form(
- sel=sel, func=func, col=col, m_comm=m_comm, k=k, r_comm=r_comm, alias=alias, fr=fr,
- table_expr=table_expr, condition=condition
- ))
- for i in range(tdSql.queryRows):
- print(f"case in {line}: ", end='')
- tdSql.checkData(i, 0, pre_mavg[i])
+ # print(f"select {col} from {table_expr} {re.sub('limit [0-9]*|offset [0-9]*','',condition)}")
+ if not tdSql.queryResult:
+ pre_result = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None]
+
+ pre_mavg = pre_mavg = np.convolve(pre_result, np.ones(k), "valid")[offset_val:]/k
+ tdSql.query(self.mavg_query_form(
+ sel=sel, func=func, col=col, m_comm=m_comm, k=k, r_comm=r_comm, alias=alias, fr=fr,
+ table_expr=table_expr, condition=condition
+ ))
+ for i in range(tdSql.queryRows):
+ print(f"case in {line}: ", end='')
+ tdSql.checkData(i, 0, pre_mavg[i])
pass
diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh
old mode 100644
new mode 100755
index f03a07e8e105ff83bf9673b0667201b82512f4bf..8481417dbd86fc7fcbbb202eafd3701a7dbbf7e1
--- a/tests/system-test/fulltest.sh
+++ b/tests/system-test/fulltest.sh
@@ -101,3 +101,4 @@ python3 ./test.py -f 7-tmq/subscribeStb1.py
python3 ./test.py -f 7-tmq/subscribeStb2.py
python3 ./test.py -f 7-tmq/subscribeStb3.py
python3 ./test.py -f 7-tmq/subscribeStb4.py
+python3 ./test.py -f 7-tmq/db.py
diff --git a/tests/test/c/sdbDump.c b/tests/test/c/sdbDump.c
index 1781dd31836376cb3e502de0bd05bde50e66288a..e5986cf4dddaa7191e7047e76b51305baefc55c1 100644
--- a/tests/test/c/sdbDump.c
+++ b/tests/test/c/sdbDump.c
@@ -86,6 +86,7 @@ void dumpDb(SSdb *pSdb, SJson *json) {
tjsonAddIntegerToObject(item, "cacheLastRow", pObj->cfg.cacheLastRow);
tjsonAddIntegerToObject(item, "hashMethod", pObj->cfg.hashMethod);
tjsonAddIntegerToObject(item, "numOfRetensions", pObj->cfg.numOfRetensions);
+ tjsonAddIntegerToObject(item, "schemaless", pObj->cfg.schemaless);
sdbRelease(pSdb, pObj);
}
diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c
index accd1dd080ec21a33cde9d803a4c4e361cb96b16..d0b582f3758c2b37f1190f61cd9cd337ec708abb 100644
--- a/tests/test/c/tmqSim.c
+++ b/tests/test/c/tmqSim.c
@@ -32,6 +32,7 @@
#define MAX_SQL_STR_LEN (1024 * 1024)
#define MAX_ROW_STR_LEN (16 * 1024)
#define MAX_CONSUMER_THREAD_CNT (16)
+#define MAX_VGROUP_CNT (32)
typedef struct {
TdThread thread;
@@ -61,6 +62,10 @@ typedef struct {
tmq_t* tmq;
tmq_list_t* topicList;
+
+ int32_t numOfVgroups;
+ int32_t rowsOfPerVgroups[MAX_VGROUP_CNT][2]; // [i][0]: vgroup id, [i][1]: rows of consume
+ int64_t ts;
} SThreadInfo;
@@ -69,7 +74,8 @@ typedef struct {
char cdbName[32];
char dbName[32];
int32_t showMsgFlag;
- int32_t showRowFlag;
+ int32_t showRowFlag;
+ int32_t saveRowFlag;
int32_t consumeDelay; // unit s
int32_t numOfThread;
SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT];
@@ -77,6 +83,7 @@ typedef struct {
static SConfInfo g_stConfInfo;
TdFilePtr g_fp = NULL;
+static int running = 1;
// char* g_pRowValue = NULL;
// TdFilePtr g_fp = NULL;
@@ -93,6 +100,8 @@ static void printHelp() {
printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag);
printf("%s%s\n", indent, "-r");
printf("%s%s%s%d\n", indent, indent, "showRowFlag, default is ", g_stConfInfo.showRowFlag);
+ printf("%s%s\n", indent, "-s");
+ printf("%s%s%s%d\n", indent, indent, "saveRowFlag, default is ", g_stConfInfo.saveRowFlag);
printf("%s%s\n", indent, "-y");
printf("%s%s%s%d\n", indent, indent, "consume delay, default is s", g_stConfInfo.consumeDelay);
exit(EXIT_SUCCESS);
@@ -135,6 +144,7 @@ void saveConfigToLogFile() {
taosFprintfFile(g_fp, "# cdbName: %s\n", g_stConfInfo.cdbName);
taosFprintfFile(g_fp, "# showMsgFlag: %d\n", g_stConfInfo.showMsgFlag);
taosFprintfFile(g_fp, "# showRowFlag: %d\n", g_stConfInfo.showRowFlag);
+ taosFprintfFile(g_fp, "# saveRowFlag: %d\n", g_stConfInfo.saveRowFlag);
taosFprintfFile(g_fp, "# consumeDelay: %d\n", g_stConfInfo.consumeDelay);
taosFprintfFile(g_fp, "# numOfThread: %d\n", g_stConfInfo.numOfThread);
@@ -165,6 +175,7 @@ void parseArgument(int32_t argc, char* argv[]) {
memset(&g_stConfInfo, 0, sizeof(SConfInfo));
g_stConfInfo.showMsgFlag = 0;
g_stConfInfo.showRowFlag = 0;
+ g_stConfInfo.saveRowFlag = 0;
g_stConfInfo.consumeDelay = 5;
for (int32_t i = 1; i < argc; i++) {
@@ -181,6 +192,8 @@ void parseArgument(int32_t argc, char* argv[]) {
g_stConfInfo.showMsgFlag = atol(argv[++i]);
} else if (strcmp(argv[i], "-r") == 0) {
g_stConfInfo.showRowFlag = atol(argv[++i]);
+ } else if (strcmp(argv[i], "-s") == 0) {
+ g_stConfInfo.saveRowFlag = atol(argv[++i]);
} else if (strcmp(argv[i], "-y") == 0) {
g_stConfInfo.consumeDelay = atol(argv[++i]);
} else {
@@ -200,6 +213,7 @@ void parseArgument(int32_t argc, char* argv[]) {
pPrint("%s consumeDelay:%d %s", GREEN, g_stConfInfo.consumeDelay, NC);
pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC);
pPrint("%s showRowFlag:%d %s", GREEN, g_stConfInfo.showRowFlag, NC);
+ pPrint("%s saveRowFlag:%d %s", GREEN, g_stConfInfo.saveRowFlag, NC);
#endif
}
@@ -225,15 +239,64 @@ void ltrim(char* str) {
// return str;
}
-static int running = 1;
-static int32_t msg_process(TAOS_RES* msg, int64_t msgIndex, int32_t threadLable) {
+void addRowsToVgroupId(SThreadInfo* pInfo, int32_t vgroupId, int32_t rows) {
+ int32_t i;
+ for (i = 0; i < pInfo->numOfVgroups; i++) {
+ if (vgroupId == pInfo->rowsOfPerVgroups[i][0]) {
+ pInfo->rowsOfPerVgroups[i][1] += rows;
+ return;
+ }
+ }
+
+ pInfo->rowsOfPerVgroups[pInfo->numOfVgroups][0] = vgroupId;
+ pInfo->rowsOfPerVgroups[pInfo->numOfVgroups][1] += rows;
+ pInfo->numOfVgroups++;
+
+ taosFprintfFile(g_fp, "consume id %d, add one new vogroup id: %d\n", pInfo->consumerId, vgroupId);
+ if (pInfo->numOfVgroups > MAX_VGROUP_CNT) {
+ taosFprintfFile(g_fp, "====consume id %d, vgroup num %d over than 32. new vgroupId: %d\n", pInfo->consumerId, pInfo->numOfVgroups, vgroupId);
+ taosCloseFile(&g_fp);
+ exit(-1);
+ }
+}
+
+int32_t saveConsumeContentToTbl(SThreadInfo* pInfo, char* buf) {
+ char sqlStr[1100] = {0};
+
+ if (strlen(buf) > 1024) {
+ taosFprintfFile(g_fp, "The length of one row[%d] is overflow 1024\n", strlen(buf));
+ taosCloseFile(&g_fp);
+ exit(-1);
+ }
+
+ TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0);
+ assert(pConn != NULL);
+
+ sprintf(sqlStr, "insert into %s.content_%d values (%"PRId64", \'%s\')", g_stConfInfo.cdbName, pInfo->consumerId, pInfo->ts++, buf);
+ TAOS_RES* pRes = taos_query(pConn, sqlStr);
+ if (taos_errno(pRes) != 0) {
+ pError("error in insert consume result, reason:%s\n", taos_errstr(pRes));
+ taosFprintfFile(g_fp, "error in insert consume result, reason:%s\n", taos_errstr(pRes));
+ taosCloseFile(&g_fp);
+ taos_free_result(pRes);
+ exit(-1);
+ }
+
+ taos_free_result(pRes);
+
+ return 0;
+}
+
+static int32_t msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) {
char buf[1024];
int32_t totalRows = 0;
-
+
// printf("topic: %s\n", tmq_get_topic_name(msg));
- // printf("vg:%d\n", tmq_get_vgroup_id(msg));
- taosFprintfFile(g_fp, "msg index:%" PRId64 ", threadLable: %d\n", msgIndex, threadLable);
- taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), tmq_get_vgroup_id(msg));
+ int32_t vgroupId = tmq_get_vgroup_id(msg);
+
+ taosFprintfFile(g_fp, "msg index:%" PRId64 ", consumerId: %d\n", msgIndex, pInfo->consumerId);
+ //taosFprintfFile(g_fp, "topic: %s, vgroupId: %d, tableName: %s\n", tmq_get_topic_name(msg), vgroupId, tmq_get_table_name(msg));
+ taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), vgroupId);
while (1) {
TAOS_ROW row = taos_fetch_row(msg);
@@ -247,11 +310,16 @@ static int32_t msg_process(TAOS_RES* msg, int64_t msgIndex, int32_t threadLable)
if (0 != g_stConfInfo.showRowFlag) {
taosFprintfFile(g_fp, "rows[%d]: %s\n", totalRows, buf);
+ if (0 != g_stConfInfo.saveRowFlag) {
+ saveConsumeContentToTbl(pInfo, buf);
+ }
}
totalRows++;
}
+ addRowsToVgroupId(pInfo, vgroupId, totalRows);
+
return totalRows;
}
@@ -344,6 +412,32 @@ int32_t saveConsumeResult(SThreadInfo* pInfo) {
taos_free_result(pRes);
+ #if 0
+ // vgroups
+ for (i = 0; i < pInfo->numOfVgroups; i++) {
+ // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int
+ sprintf(sqlStr, "insert into %s.vgroup_%d values (%"PRId64", %d, %" PRId64 ", %" PRId64 ", %d)",
+ g_stConfInfo.cdbName,
+ now,
+ pInfo->consumerId,
+ pInfo->consumeMsgCnt,
+ pInfo->consumeRowCnt,
+ pInfo->checkresult);
+
+ char tmpString[128];
+ taosFprintfFile(g_fp, "%s, consume id %d result: %s\n", getCurrentTimeString(tmpString), pInfo->consumerId ,sqlStr);
+
+ TAOS_RES* pRes = taos_query(pConn, sqlStr);
+ if (taos_errno(pRes) != 0) {
+ pError("error in save consumeinfo, reason:%s\n", taos_errstr(pRes));
+ taos_free_result(pRes);
+ exit(-1);
+ }
+
+ taos_free_result(pRes);
+ }
+ #endif
+
return 0;
}
@@ -356,11 +450,13 @@ void loop_consume(SThreadInfo* pInfo) {
char tmpString[128];
taosFprintfFile(g_fp, "%s consumer id %d start to loop pull msg\n", getCurrentTimeString(tmpString), pInfo->consumerId);
+ pInfo->ts = taosGetTimestampMs();
+
while (running) {
TAOS_RES* tmqMsg = tmq_consumer_poll(pInfo->tmq, g_stConfInfo.consumeDelay * 1000);
if (tmqMsg) {
if (0 != g_stConfInfo.showMsgFlag) {
- totalRows += msg_process(tmqMsg, totalMsgs, pInfo->consumerId);
+ totalRows += msg_process(tmqMsg, pInfo, totalMsgs);
}
taos_free_result(tmqMsg);