diff --git a/include/client/taos.h b/include/client/taos.h
index b65091f52b..c311e017df 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/tdataformat.h b/include/common/tdataformat.h
index 10bc6a6176..073d796717 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/tmsg.h b/include/common/tmsg.h
index e0dcfbd544..ee858ad506 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -241,6 +241,7 @@ typedef struct {
int32_t schemaLen; // schema length, if length is 0, no schema exists
int16_t numOfRows; // total number of rows in current submit block
// head of SSubmitBlk
+ int32_t numOfBlocks;
const void* pMsg;
} SSubmitMsgIter;
diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h
index 9fa657a2a6..e99377f9b4 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 860674b343..fe9ffda69c 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)
diff --git a/include/common/ttypes.h b/include/common/ttypes.h
index 31cdb28690..16c59465cc 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/nodes/plannodes.h b/include/libs/nodes/plannodes.h
index eb37316402..01b8d5c51e 100644
--- a/include/libs/nodes/plannodes.h
+++ b/include/libs/nodes/plannodes.h
@@ -229,6 +229,7 @@ typedef struct STableScanPhysiNode {
double ratio;
int32_t dataRequired;
SNodeList* pDynamicScanFuncs;
+ SNodeList* pPartitionKeys;
int64_t interval;
int64_t offset;
int64_t sliding;
diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h
index 331b787690..5cb6dbd3bc 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/util/tutil.h b/include/util/tutil.h
index 444a893a88..b29e1f7cfa 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 3ff61eca25..c7b831893e 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,
@@ -183,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.
@@ -219,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;
@@ -271,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);
@@ -319,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 19847d9aa2..4b39a51584 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"
@@ -171,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));
@@ -185,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);
@@ -288,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 1ae528d78c..916017543d 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;
@@ -192,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);
@@ -230,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;
@@ -286,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,
@@ -298,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;
}
@@ -352,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);
@@ -388,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);
@@ -417,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;
@@ -428,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);
}
@@ -450,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) {
@@ -461,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};
@@ -479,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) {
@@ -490,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;
@@ -510,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;
@@ -523,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) {
@@ -583,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) {
@@ -666,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;
@@ -726,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;
@@ -843,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);
@@ -923,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);
@@ -944,58 +1025,7 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
}
}
-void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
- assert(pRequest != NULL);
-
- SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
- 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;
- 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);
- 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;
- }
- }
-
- if (setupOneRowPtr) {
- doSetOneRowPtr(pResultInfo);
- pResultInfo->current += 1;
- }
-
- return pResultInfo->row;
-}
-
void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
- // return doAsyncFetchRows(pRequest, setupOneRowPtr, convertUcs4);
assert(pRequest != NULL);
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
@@ -1036,6 +1066,35 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4)
return pResultInfo->row;
}
+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;
+ 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;
+ return NULL;
+ }
+
+ SSyncQueryParam* pParam = pRequest->body.param;
+ taos_fetch_rows_a(pRequest, syncFetchFn, pParam);
+ tsem_wait(&pParam->sem);
+ }
+
+ if (pRequest->code == TSDB_CODE_SUCCESS && pResultInfo->numOfRows > 0 && setupOneRowPtr) {
+ doSetOneRowPtr(pResultInfo);
+ pResultInfo->current += 1;
+ }
+
+ return pResultInfo->row;
+}
+
static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
if (pResInfo->row == NULL) {
pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES);
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index e144885e9e..873759dfbd 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -175,12 +175,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) {
@@ -195,7 +222,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);
@@ -205,6 +236,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
} else {
pResultInfo = tmqGetCurResInfo(res);
}
+
if (pResultInfo->current < pResultInfo->numOfRows) {
doSetOneRowPtr(pResultInfo);
pResultInfo->current += 1;
@@ -563,38 +595,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) {
- pRequest = launchQuery(taos, sql, sqlLen);
- if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
- break;
- }
-
- code = refreshMeta(taos, pRequest);
- if (code) {
- pRequest->code = code;
- break;
- }
-
- destroyRequest(pRequest);
+ // while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
+ code = buildRequest(taos, sql, sqlLen, &pRequest);
+ if (code != TSDB_CODE_SUCCESS) {
+ terrno = code;
+ fp(param, NULL, code);
+ return;
}
+ pRequest->body.queryFp = fp;
+ pRequest->body.param = param;
+
+ STscObj *pTscObj = pRequest->pTscObj;
+
+ 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 9de3ee1d0f..1039d36362 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;
+ } 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);
}
- 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);
-
- 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 bcdba69692..c559ac58f8 100644
--- a/source/client/src/clientSml.c
+++ b/source/client/src/clientSml.c
@@ -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;
@@ -2362,7 +2362,7 @@ static int32_t isSchemalessDb(SSmlHandle* info){
*/
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;
diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c
index 3adb3684da..2dbba80127 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 914e5aefc2..abeec373d9 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);
@@ -567,7 +608,6 @@ TEST(testCase, insert_test) {
taos_free_result(pRes);
taos_close(pConn);
}
-#endif
TEST(testCase, projection_query_tables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
@@ -606,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)"
@@ -664,7 +704,7 @@ TEST(testCase, projection_query_tables) {
// taos_free_result(pRes);
taos_close(pConn);
}
-#if 0
+
TEST(testCase, projection_query_stables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
@@ -705,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);
@@ -735,4 +775,24 @@ TEST(testCase, agg_query_tables) {
}
#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 6dc8088cd1..1358d45f30 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);
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index 948b50c01a..5b8d214cb4 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},
diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c
index 65daee6508..287dba6d3b 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;
-
- _set_null:
- flags != TSROW_HAS_NULL;
- // SET_BIT2(pb, bidx, 1); (todo)
- continue;
-
- _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);
- } else {
- // tPutColVal(pf ? pf + pTColumn->offset : pf, pColVal, pTColumn->type, 1);
- }
- 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;
- }
-}
-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);
-
- 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;
- 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];
-
- if (iColVal < nColVal) {
- pColVal = (SColVal *)taosArrayGet(pArray, iColVal);
- } else {
- pColVal = NULL;
+ // 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);
}
- 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;
+ 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 {
+ nDataK = sizeof(STSKVRow) + sizeof(uint32_t) * nTag + nkv;
+ tflags |= TSROW_KV_BIG;
+ }
+
+ if (nDataT < nDataK) {
+ nData = nDataT;
+ } else {
+ nData = nDataK;
+ flags |= tflags;
+ }
+ }
+
+ // 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;
}
- } else if (pColVal->cid > pTColumn->colId) {
- goto _set_none;
- } else {
- ASSERT(0);
+ pBuilder->pBuf = p;
+ pBuilder->szBuf = nData;
+ }
+
+ pBuilder->tsRow.nData = nData;
+ pBuilder->tsRow.pData = pBuilder->pBuf;
+ }
+
+ *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;
+ }
+ }
+ }
+
+ // build
+ (*ppRow)->flags = flags;
+ (*ppRow)->sver = pTSchema->version;
+
+ 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 {
- goto _set_none;
+ 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;
+ }
}
- _set_none:
- flags |= TSROW_HAS_NONE;
- continue;
+ for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
+ pTColumn = &pTSchema->columns[iColumn];
+ if (iColVal < nColVal) {
+ pColVal = (SColVal *)taosArrayGet(pArray, iColVal);
+ } else {
+ pColVal = NULL;
+ }
- _set_null:
- flags != TSROW_HAS_NULL;
- pidx[nCol++] = nv;
- // nv += tPutColVal(pv ? pv + nv : pv, pColVal, pTColumn->type, 0);
- continue;
+ if (pColVal) {
+ if (pColVal->cid == pTColumn->colId) {
+ iColVal++;
- _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
- }
-}
-
-// try-decide-build
-int32_t tTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
- int32_t code = 0;
- STSRow2 rowT = {0};
- STSRow2 rowM = {0};
-
- // try
- tTupleTSRowNew(pArray, pTSchema, &rowT);
- tMapTSRowNew(pArray, pTSchema, &rowM);
-
- // decide & build
- if (rowT.nData <= rowM.nData) {
- tTupleTSRowNew(pArray, pTSchema, &rowT);
- } else {
- tMapTSRowNew(pArray, pTSchema, &rowM);
+ 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 {
+ ASSERT(0);
+ }
+ } else {
+ goto _set_none;
+ }
+
+ _set_none:
+ if (flags & 0xf0 == 0) {
+ setBitMap(pb, 0, iColumn - 1, flags);
+ }
+ continue;
+
+ _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;
+
+ _set_value:
+ if (flags & 0xf0 == 0) {
+ setBitMap(pb, 2, iColumn - 1, flags);
+
+ 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/tmsg.c b/source/common/src/tmsg.c
index ed32d5a16b..e7ee164be7 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -34,7 +34,8 @@ int32_t tInitSubmitMsgIter(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
return -1;
}
- pIter->totalLen = ntohl(pMsg->length);
+ pIter->totalLen = htonl(pMsg->length);
+ pIter->numOfBlocks = htonl(pMsg->numOfBlocks);
ASSERT(pIter->totalLen > 0);
pIter->len = 0;
pIter->pMsg = pMsg;
diff --git a/source/common/src/tmsgcb.c b/source/common/src/tmsgcb.c
index 126a4c023a..b8eec655b1 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/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
index bd034fe7d6..9a0cfdfc93 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 5c5316e3a3..8d0d503d8f 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 1b973f3045..0f3c06cb3a 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 1de9875d06..460f2242f2 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);
-}
+ 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;
-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);
+ 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;
}
-
- if (code != 0) {
- rpcFreeCont(pMsg->pCont);
- pMsg->pCont = NULL;
- }
- 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 9738fb0c45..54e9da24a4 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 06c18ab288..3b425a0b49 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 e7fc261b67..e36efa83db 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 5ec33fe810..adc18fdced 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 vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc);
-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 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 cf5a7ad885..613f3fb994 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 b0c9566184..f08ac6b9d0 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
@@ -210,7 +210,7 @@ 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);
@@ -294,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) {
@@ -321,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_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, 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_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, 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_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 0c8d492ef4..23927255bb 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 03db74abd7..bedf473379 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,13 +84,15 @@ 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);
}
@@ -99,7 +106,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
for (int32_t m = 0; m < numOfMsgs; m++) {
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
- dTrace("vgId:%d, get msg:%p from vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
+ dTrace("vgId:%d, msg:%p get from vnode-write queue", pVnode->vgId, pMsg);
if (taosArrayPush(pArray, &pMsg) == NULL) {
dError("vgId:%d, failed to push msg:%p to vnode-write array", pVnode->vgId, pMsg);
@@ -113,7 +120,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
if (code == TSDB_CODE_ACTION_IN_PROGRESS) continue;
if (code != 0) {
- dError("vgId:%d, msg:%p failed to process since %s", pVnode->vgId, pMsg, tstrerror(code));
+ dError("vgId:%d, msg:%p failed to write since %s", pVnode->vgId, pMsg, tstrerror(code));
vmSendRsp(pMsg, code);
continue;
}
@@ -129,14 +136,14 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info};
tmsgSendRedirectRsp(&rsp, &newEpSet);
} else {
- dError("vgId:%d, msg:%p failed to process since %s", pVnode->vgId, pMsg, tstrerror(code));
+ 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++) {
pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
- dTrace("vgId:%d, msg:%p, is freed", pVnode->vgId, pMsg);
+ dTrace("vgId:%d, msg:%p is freed", pVnode->vgId, pMsg);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
@@ -146,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};
@@ -164,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);
@@ -176,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);
}
@@ -183,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);
}
@@ -207,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;
@@ -233,31 +243,36 @@ 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;
}
switch (qtype) {
case QUERY_QUEUE:
- 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;
@@ -268,110 +283,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) return -1;
- 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;
- }
- }
+ SMsgHead *pHead = pRpc->pCont;
+ dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pMsg->msgType));
- 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);
-}
-
-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);
-}
-
-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) {
@@ -467,29 +411,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/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
index 787f5e5019..ee27f27f06 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 e5893fd947..8b939d15ce 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/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp
index 8c945b50ac..857f58befc 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/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index 6d7a638c30..a2a925b0bd 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -1344,6 +1344,9 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
mDebug("db:%s, version & numOfTable not changed", pDbVgVersion->dbFName);
mndReleaseDb(pMnode, pDb);
continue;
+ } else {
+ mDebug("db:%s, vgroup version changed from %d to %d", pDbVgVersion->dbFName, pDbVgVersion->vgVersion,
+ pDb->vgVersion);
}
usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c
index bf4baebd85..7e5dbb9566 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 160fc8d428..013a991e98 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,
};
diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt
index d72292e34b..40f8b0726e 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 2a8eb0a39d..17adfde801 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 b6586192b2..049a4f3a9f 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 9b4e21501e..33ba0c5697 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 05b4a270d6..f3aefdba02 100644
--- a/source/dnode/vnode/CMakeLists.txt
+++ b/source/dnode/vnode/CMakeLists.txt
@@ -36,7 +36,6 @@ target_sources(
# 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/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c
index ca31e1b32c..21a55d6463 100644
--- a/source/dnode/vnode/src/meta/metaQuery.c
+++ b/source/dnode/vnode/src/meta/metaQuery.c
@@ -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/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c
index 3b88a83395..b45fccaf29 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
@@ -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);
@@ -160,8 +160,8 @@ _exit:
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;
@@ -280,7 +280,7 @@ _err:
}
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;
@@ -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/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c
index 3990fd7165..86929fe6d5 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};
diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c
deleted file mode 100644
index 844cfc094b..0000000000
--- 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/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c
index af0fde6d62..f4d4d94142 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)
@@ -122,38 +124,29 @@ int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmit
// 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:
@@ -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 //====================================================================================
+static void memDataMovePos(SMemData *pMemData, TSDBROW *pRow, int8_t isForward, SMemSkipListNode **pos) {
+ TSDBKEY *pKey;
+ int c;
-#define SL_MAX_LEVEL 5
+ if (isForward) {
+ // TODO
+ } else {
+ SMemSkipListNode *px = pMemData->sl.pTail;
-struct SMemSkipListCurosr {
- SMemSkipList *pSl;
- SMemSkipListNode *pNodes[SL_MAX_LEVEL];
-};
+ for (int8_t iLevel = pMemData->sl.maxLevel - 1; iLevel >= 0; iLevel--) {
+ if (iLevel < pMemData->sl.level) {
+ SMemSkipListNode *p = SL_NODE_BACKWARD(px, iLevel);
-typedef struct {
- int64_t version;
- uint32_t szRow;
- const STSRow *pRow;
-} STsdbRow;
+ while (p != pMemData->sl.pHead) {
+ pKey = (TSDBKEY *)SL_NODE_DATA(p);
-#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
+ c = tsdbKeyCmprFn(pKey, pRow);
+ if (c <= 0) {
+ break;
+ } else {
+ px = p;
+ p = SL_NODE_BACKWARD(px, iLevel);
+ }
+ }
-#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;
+ pos[iLevel] = px;
+ }
+ }
}
+}
- // 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;
+static void memMovePosFrom(SMemData *pMemData, SMemSkipListNode *pNode, TSDBROW *pRow, int8_t isForward,
+ SMemSkipListNode **pos) {
+ SMemSkipListNode *px = pNode;
+ TSDBKEY *pKey;
+ SMemSkipListNode *p;
+ int c;
- pMemData = vnodeBufPoolMalloc(pPool, tsize);
- if (pMemData == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
+ 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;
}
-
- 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];
+static int32_t memDataPutRow(SVBufPool *pPool, SMemData *pMemData, TSDBROW *pRow, int8_t isForward,
+ SMemSkipListNode **pos) {
+ int32_t code = 0;
+ int8_t 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;
- }
-
- // 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 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);
+ 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;
}
- if (pSl->level < pNode->level) {
- pSl->level = pNode->level;
+ // do the read put
+ if (isForward) {
+ // TODO
+ } else {
+ // TODO
}
- 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;
- }
- }
-
- 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);
-
- for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
- pSlc->pNodes[iLevel] = pTail;
- }
-
- 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);
- }
-
- 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/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c
index 47eaf2d5a5..4b0016a746 100644
--- a/source/dnode/vnode/src/vnd/vnodeSvr.c
+++ b/source/dnode/vnode/src/vnd/vnodeSvr.c
@@ -715,8 +715,8 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
goto _exit;
}
- submitRsp.pArray = taosArrayInit(pSubmitReq->numOfBlocks, sizeof(SSubmitBlkRsp));
- newTbUids = taosArrayInit(pSubmitReq->numOfBlocks, sizeof(int64_t));
+ submitRsp.pArray = taosArrayInit(msgIter.numOfBlocks, sizeof(SSubmitBlkRsp));
+ newTbUids = taosArrayInit(msgIter.numOfBlocks, sizeof(int64_t));
if (!submitRsp.pArray) {
pRsp->code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h
index 239d719fa8..cebe696390 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 7e0efe22db..040156eca2 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 eb84bf00a4..a9e808e749 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));
}
@@ -336,14 +336,12 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
taosAcquireRef(gCtgMgmt.jobPool, pJob->refId);
- qDebug("QID:%" PRIx64 ", job %" PRIx64 " initialized, task num %d", pJob->queryId, pJob->refId, taskNum);
-
+ 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/executorInt.h b/source/libs/executor/inc/executorInt.h
index f2f0bc2055..88f308710e 100644
--- a/source/libs/executor/inc/executorInt.h
+++ b/source/libs/executor/inc/executorInt.h
@@ -27,6 +27,10 @@ typedef struct {
int32_t bytes;
} SGroupKeys, SStateKeys;
+int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList);
+uint64_t calcGroupId(char* pData, int32_t len);
+void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex);
+int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals);
#ifdef __cplusplus
}
#endif
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index e7a3390cf3..60be28167d 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -333,6 +333,12 @@ typedef struct STableScanInfo {
double sampleRatio; // data block sample ratio, 1 by default
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded.
+ SArray* pGroupCols;
+ SArray* pGroupColVals; // current group column values, SArray
+ char* keyBuf; // group by keys for hash
+ int32_t groupKeyLen; // total group by column width
+ SHashObj* pGroupSet; // quick locate the window object for each result
+
int32_t curTWinIdx;
} STableScanInfo;
@@ -727,7 +733,7 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup);
-SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo);
+SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SArray* groupKyes, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index 3c46f46e19..8388253975 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -4387,9 +4387,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
if (pDataReader == NULL && terrno != 0) {
return NULL;
}
-
+ SArray* groupKyes = extractPartitionColInfo(pTableScanNode->pPartitionKeys);
extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
- SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
+ SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, groupKyes, pTaskInfo);
STableScanInfo* pScanInfo = pOperator->info;
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c
index 8c3a0c0e6e..3691024096 100644
--- a/source/libs/executor/src/groupoperator.c
+++ b/source/libs/executor/src/groupoperator.c
@@ -24,10 +24,10 @@
#include "tcompare.h"
#include "thash.h"
#include "ttypes.h"
+#include "executorInt.h"
static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity);
static void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInfo** pGroupInfo, int32_t len);
-static uint64_t calcGroupId(char* pData, int32_t len);
static void destroyGroupOperatorInfo(void* param, int32_t numOfOutput) {
SGroupbyOperatorInfo* pInfo = (SGroupbyOperatorInfo*)param;
@@ -37,7 +37,7 @@ static void destroyGroupOperatorInfo(void* param, int32_t numOfOutput) {
taosArrayDestroy(pInfo->pGroupColVals);
}
-static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) {
+int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) {
*pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys));
if ((*pGroupColVals) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
@@ -110,7 +110,7 @@ static bool groupKeyCompare(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlo
return true;
}
-static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex) {
+void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex) {
SColumnDataAgg* pColAgg = NULL;
size_t numOfGroupCols = taosArrayGetSize(pGroupCols);
@@ -139,7 +139,7 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData
}
}
-static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
+int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
ASSERT(pKey != NULL);
size_t numOfGroupCols = taosArrayGetSize(pGroupColVals);
@@ -409,7 +409,6 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
SPartitionOperatorInfo* pInfo = pOperator->info;
- int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols);
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j);
int32_t len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
@@ -622,8 +621,13 @@ static void destroyPartitionOperatorInfo(void* param, int32_t numOfOutput) {
SPartitionOperatorInfo* pInfo = (SPartitionOperatorInfo*)param;
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
taosArrayDestroy(pInfo->pGroupCols);
+ for(int i = 0; i < taosArrayGetSize(pInfo->pGroupColVals); i++){
+ SGroupKeys key = *(SGroupKeys*)taosArrayGet(pInfo->pGroupColVals, i);
+ taosMemoryFree(key.pData);
+ }
taosArrayDestroy(pInfo->pGroupColVals);
taosMemoryFree(pInfo->keyBuf);
+ taosHashCleanup(pInfo->pGroupSet);
taosMemoryFree(pInfo->columnOffset);
}
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 348d85943e..0774ccec1c 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -33,6 +33,8 @@
#include "ttypes.h"
#include "vnode.h"
+#include "executorInt.h"
+
#define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN)
#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC))
@@ -373,6 +375,17 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
longjmp(pOperator->pTaskInfo->env, code);
}
+ recordNewGroupKeys(pTableScanInfo->pGroupCols, pTableScanInfo->pGroupColVals, pBlock, 0);
+ int32_t len = buildGroupKeys(pTableScanInfo->keyBuf, pTableScanInfo->pGroupColVals);
+
+ uint64_t *groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len);
+ if (groupId) {
+ pBlock->info.groupId = *groupId;
+ }else if(len != 0){
+ pBlock->info.groupId = calcGroupId(pTableScanInfo->keyBuf, len);
+ taosHashPut(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len, &pBlock->info.groupId, sizeof(uint64_t));
+ }
+
// current block is filter out according to filter condition, continue load the next block
if (status == FUNC_DATA_REQUIRED_FILTEROUT || pBlock->info.rows == 0) {
continue;
@@ -497,21 +510,25 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) {
taosMemoryFree(pTableScanInfo->pResBlock);
tsdbCleanupReadHandle(pTableScanInfo->dataReader);
+ taosArrayDestroy(pTableScanInfo->pGroupCols);
+ for(int i = 0; i < taosArrayGetSize(pTableScanInfo->pGroupColVals); i++){
+ SGroupKeys key = *(SGroupKeys*)taosArrayGet(pTableScanInfo->pGroupColVals, i);
+ taosMemoryFree(key.pData);
+ }
+ taosArrayDestroy(pTableScanInfo->pGroupColVals);
+ taosMemoryFree(pTableScanInfo->keyBuf);
+ taosHashCleanup(pTableScanInfo->pGroupSet);
if (pTableScanInfo->pColMatchInfo != NULL) {
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
}
}
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader,
- SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) {
+ SReadHandle* readHandle, SArray* groupKyes, SExecTaskInfo* pTaskInfo) {
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
if (pInfo == NULL || pOperator == NULL) {
- taosMemoryFreeClear(pInfo);
- taosMemoryFreeClear(pOperator);
-
- pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
- return NULL;
+ goto _error;
}
SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc;
@@ -522,7 +539,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
if (code != TSDB_CODE_SUCCESS) {
- return NULL;
+ goto _error;
}
if (pTableScanNode->scan.pScanPseudoCols != NULL) {
@@ -552,6 +569,18 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
pOperator->numOfExprs = numOfCols;
pOperator->pTaskInfo = pTaskInfo;
+ // for table group
+ pInfo->pGroupCols = groupKyes;
+ _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
+ pInfo->pGroupSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK);
+ if (pInfo->pGroupSet == NULL) {
+ goto _error;
+ }
+ code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, groupKyes);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo,
NULL, NULL, getTableScannerExecInfo);
@@ -559,6 +588,12 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
pOperator->cost.openCost = 0;
return pOperator;
+
+_error:
+ pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
+ taosMemoryFreeClear(pInfo);
+ taosMemoryFreeClear(pOperator);
+ return NULL;
}
SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskInfo) {
@@ -901,7 +936,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan
SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan;
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
- SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
+ SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, NULL, pTaskInfo);
STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info;
diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c
index 5d69cc6189..c9c63169c9 100644
--- a/source/libs/function/src/builtins.c
+++ b/source/libs/function/src/builtins.c
@@ -846,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) {
@@ -859,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;
}
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index be18150234..2f698b906c 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -1324,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;
@@ -1339,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;
}
diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c
index 611ae8d81f..67efdc5c0b 100644
--- a/source/libs/function/src/functionMgt.c
+++ b/source/libs/function/src/functionMgt.c
@@ -226,6 +226,9 @@ static SColumnNode* createColumnByFunc(const SFunctionNode* pFunc) {
}
bool fmIsDistExecFunc(int32_t funcId) {
+ if (fmIsUserDefinedFunc(funcId)) {
+ return false;
+ }
if (!fmIsVectorFunc(funcId)) {
return true;
}
diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c
index 766746dd2a..b41006b6dd 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 2835084a81..040460ae5c 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/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c
index 68c9684c97..7abe244261 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;
}
@@ -195,6 +199,22 @@ static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCre
return code;
}
+static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) {
+ int32_t code = TSDB_CODE_SUCCESS;
+ SNode* pNode = NULL;
+ FOREACH(pNode, pStmt->pTables) {
+ SDropTableClause* pClause = (SDropTableClause*)pNode;
+ code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
+ if (TSDB_CODE_SUCCESS == code) {
+ code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
+ }
+ if (TSDB_CODE_SUCCESS != code) {
+ break;
+ }
+ }
+ return code;
+}
+
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
if (TSDB_CODE_SUCCESS == code) {
@@ -337,6 +357,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt);
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
return collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTableStmt*)pStmt);
+ case QUERY_NODE_DROP_TABLE_STMT:
+ return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
case QUERY_NODE_ALTER_TABLE_STMT:
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
case QUERY_NODE_USE_DATABASE_STMT:
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index f0cba6ddc9..2d37e9087d 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -2857,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) {
@@ -5038,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/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp
index 5ad427d964..1b1b930851 100644
--- a/source/libs/parser/test/parInitialDTest.cpp
+++ b/source/libs/parser/test/parInitialDTest.cpp
@@ -24,7 +24,7 @@ class ParserInitialDTest : public ParserDdlTest {};
// todo delete
// todo desc
// todo describe
-// todo drop account
+// todo DROP account
TEST_F(ParserInitialDTest, dropBnode) {
useDb("root", "test");
@@ -62,51 +62,61 @@ TEST_F(ParserInitialDTest, dropCGroup) {
run("DROP CONSUMER GROUP IF EXISTS cg1 ON tp1");
}
-// todo drop database
-// todo drop dnode
-// todo drop function
+// todo DROP database
+// todo DROP dnode
+// todo DROP function
TEST_F(ParserInitialDTest, dropIndex) {
useDb("root", "test");
- run("drop index index1 on t1");
+ run("DROP index index1 on t1");
}
TEST_F(ParserInitialDTest, dropMnode) {
useDb("root", "test");
- run("drop mnode on dnode 1");
+ run("DROP mnode on dnode 1");
}
TEST_F(ParserInitialDTest, dropQnode) {
useDb("root", "test");
- run("drop qnode on dnode 1");
+ run("DROP qnode on dnode 1");
}
TEST_F(ParserInitialDTest, dropSnode) {
useDb("root", "test");
- run("drop snode on dnode 1");
+ run("DROP snode on dnode 1");
}
-// todo drop stable
-// todo drop stream
-// todo drop table
+TEST_F(ParserInitialDTest, dropSTable) {
+ useDb("root", "test");
+
+ run("DROP STABLE st1");
+}
+
+// todo DROP stream
+
+TEST_F(ParserInitialDTest, dropTable) {
+ useDb("root", "test");
+
+ run("DROP TABLE t1");
+}
TEST_F(ParserInitialDTest, dropTopic) {
useDb("root", "test");
- run("drop topic tp1");
+ run("DROP topic tp1");
- run("drop topic if exists tp1");
+ run("DROP topic if exists tp1");
}
TEST_F(ParserInitialDTest, dropUser) {
login("root");
useDb("root", "test");
- run("drop user wxy");
+ run("DROP user wxy");
}
} // namespace ParserTest
diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp
index a5192595f0..e61b060682 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 820b8cca3c..ecc535feb0 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/planSpliter.c b/source/libs/planner/src/planSpliter.c
index e3c8b82e39..a3d5086908 100644
--- a/source/libs/planner/src/planSpliter.c
+++ b/source/libs/planner/src/planSpliter.c
@@ -151,8 +151,8 @@ static bool stbSplHasMultiTbScan(bool streamQuery, 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_AGG:
+ return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
case QUERY_NODE_LOGIC_PLAN_WINDOW: {
SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode;
if (WINDOW_TYPE_INTERVAL != pWindow->winType) {
@@ -161,7 +161,7 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) {
return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode);
}
// case QUERY_NODE_LOGIC_PLAN_SORT:
- // return stbSplHasMultiTbScan(pNode);
+ // return stbSplHasMultiTbScan(streamQuery, pNode);
case QUERY_NODE_LOGIC_PLAN_SCAN:
return stbSplIsMultiTbScan(streamQuery, (SScanLogicNode*)pNode);
default:
@@ -295,7 +295,8 @@ static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogic
return code;
}
-static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, SLogicNode* pPartChild) {
+static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, SNodeList* pMergeKeys,
+ SLogicNode* pPartChild) {
SMergeLogicNode* pMerge = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_MERGE);
if (NULL == pMerge) {
return TSDB_CODE_OUT_OF_MEMORY;
@@ -304,25 +305,28 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, S
pMerge->srcGroupId = pCxt->groupId;
pMerge->node.pParent = pParent;
pMerge->node.precision = pPartChild->precision;
- int32_t code = nodesListMakeStrictAppend(&pMerge->pMergeKeys, nodesCloneNode(((SWindowLogicNode*)pParent)->pTspk));
- if (TSDB_CODE_SUCCESS == code) {
- pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
- if (NULL == pMerge->node.pTargets) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- }
- }
- if (TSDB_CODE_SUCCESS == code) {
- code = nodesListMakeAppend(&pParent->pChildren, pMerge);
+ pMerge->pMergeKeys = pMergeKeys;
+ pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
+ if (NULL == pMerge->node.pTargets) {
+ nodesDestroyNode(pMerge);
+ return TSDB_CODE_OUT_OF_MEMORY;
}
- return code;
+ return nodesListMakeAppend(&pParent->pChildren, pMerge);
}
static int32_t stbSplSplitWindowNodeForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
SLogicNode* pPartWindow = NULL;
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
if (TSDB_CODE_SUCCESS == code) {
- code = stbSplCreateMergeNode(pCxt, pInfo->pSplitNode, pPartWindow);
+ SNodeList* pMergeKeys = NULL;
+ code = nodesListMakeStrictAppend(&pMergeKeys, nodesCloneNode(((SWindowLogicNode*)pInfo->pSplitNode)->pTspk));
+ if (TSDB_CODE_SUCCESS == code) {
+ code = stbSplCreateMergeNode(pCxt, pInfo->pSplitNode, pMergeKeys, pPartWindow);
+ }
+ if (TSDB_CODE_SUCCESS != code) {
+ nodesDestroyList(pMergeKeys);
+ }
}
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
@@ -365,6 +369,124 @@ static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInf
}
}
+static int32_t stbSplCreatePartAggNode(SAggLogicNode* pMergeAgg, SLogicNode** pOutput) {
+ SNodeList* pFunc = pMergeAgg->pAggFuncs;
+ pMergeAgg->pAggFuncs = NULL;
+ SNodeList* pGroupKeys = pMergeAgg->pGroupKeys;
+ pMergeAgg->pGroupKeys = NULL;
+ SNodeList* pTargets = pMergeAgg->node.pTargets;
+ pMergeAgg->node.pTargets = NULL;
+ SNodeList* pChildren = pMergeAgg->node.pChildren;
+ pMergeAgg->node.pChildren = NULL;
+
+ int32_t code = TSDB_CODE_SUCCESS;
+ SAggLogicNode* pPartAgg = nodesCloneNode(pMergeAgg);
+ if (NULL == pPartAgg) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ }
+
+ if (TSDB_CODE_SUCCESS == code && NULL != pGroupKeys) {
+ pPartAgg->pGroupKeys = pGroupKeys;
+ code = createColumnByRewriteExps(pPartAgg->pGroupKeys, &pPartAgg->node.pTargets);
+ }
+ if (TSDB_CODE_SUCCESS == code && NULL != pGroupKeys) {
+ pMergeAgg->pGroupKeys = nodesCloneList(pPartAgg->node.pTargets);
+ if (NULL == pMergeAgg->pGroupKeys) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ }
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ pMergeAgg->node.pTargets = pTargets;
+ pPartAgg->node.pChildren = pChildren;
+
+ code = stbSplRewriteFuns(pFunc, &pPartAgg->pAggFuncs, &pMergeAgg->pAggFuncs);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code = createColumnByRewriteExps(pPartAgg->pAggFuncs, &pPartAgg->node.pTargets);
+ }
+
+ nodesDestroyList(pFunc);
+ if (TSDB_CODE_SUCCESS == code) {
+ *pOutput = (SLogicNode*)pPartAgg;
+ } else {
+ nodesDestroyNode(pPartAgg);
+ }
+
+ return code;
+}
+
+static int32_t stbSplSplitAggNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
+ SLogicNode* pPartAgg = NULL;
+ int32_t code = stbSplCreatePartAggNode((SAggLogicNode*)pInfo->pSplitNode, &pPartAgg);
+ if (TSDB_CODE_SUCCESS == code) {
+ code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartAgg);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
+ splCreateScanSubplan(pCxt, pPartAgg, SPLIT_FLAG_STABLE_SPLIT));
+ }
+ pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE;
+ return code;
+}
+
+static int32_t stbSplCreatePartSortNode(SSortLogicNode* pMergeSort, SLogicNode** pOutput) {
+ SNodeList* pSortKeys = pMergeSort->pSortKeys;
+ pMergeSort->pSortKeys = NULL;
+ SNodeList* pTargets = pMergeSort->node.pTargets;
+ pMergeSort->node.pTargets = NULL;
+ SNodeList* pChildren = pMergeSort->node.pChildren;
+ pMergeSort->node.pChildren = NULL;
+
+ int32_t code = TSDB_CODE_SUCCESS;
+ SSortLogicNode* pPartSort = nodesCloneNode(pMergeSort);
+ if (NULL == pPartSort) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ }
+
+ pMergeSort->node.pTargets = pTargets;
+ pPartSort->node.pChildren = pChildren;
+ if (TSDB_CODE_SUCCESS == code) {
+ pPartSort->pSortKeys = pSortKeys;
+ code = createColumnByRewriteExps(pPartSort->pSortKeys, &pPartSort->node.pTargets);
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ pMergeSort->pSortKeys = nodesCloneList(pPartSort->node.pTargets);
+ if (NULL == pMergeSort->pSortKeys) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ }
+ }
+
+ if (TSDB_CODE_SUCCESS == code) {
+ *pOutput = (SLogicNode*)pPartSort;
+ } else {
+ nodesDestroyNode(pPartSort);
+ }
+
+ return code;
+}
+
+static int32_t stbSplSplitSortNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
+ SLogicNode* pPartSort = NULL;
+ int32_t code = stbSplCreatePartSortNode((SSortLogicNode*)pInfo->pSplitNode, &pPartSort);
+ if (TSDB_CODE_SUCCESS == code) {
+ SNodeList* pMergeKeys = nodesCloneList(((SSortLogicNode*)pInfo->pSplitNode)->pSortKeys);
+ if (NULL != pMergeKeys) {
+ code = stbSplCreateMergeNode(pCxt, pInfo->pSplitNode, pMergeKeys, pPartSort);
+ if (TSDB_CODE_SUCCESS != code) {
+ nodesDestroyList(pMergeKeys);
+ }
+ } else {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ }
+ }
+ if (TSDB_CODE_SUCCESS == code) {
+ code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
+ splCreateScanSubplan(pCxt, pPartSort, SPLIT_FLAG_STABLE_SPLIT));
+ }
+ pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE;
+ return code;
+}
+
static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pInfo->pSplitNode, SUBPLAN_TYPE_MERGE);
if (TSDB_CODE_SUCCESS == code) {
@@ -386,9 +508,15 @@ static int32_t stableSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
int32_t code = TSDB_CODE_SUCCESS;
switch (nodeType(info.pSplitNode)) {
+ case QUERY_NODE_LOGIC_PLAN_AGG:
+ code = stbSplSplitAggNode(pCxt, &info);
+ break;
case QUERY_NODE_LOGIC_PLAN_WINDOW:
code = stbSplSplitWindowNode(pCxt, &info);
break;
+ case QUERY_NODE_LOGIC_PLAN_SORT:
+ code = stbSplSplitSortNode(pCxt, &info);
+ break;
case QUERY_NODE_LOGIC_PLAN_SCAN:
code = stbSplSplitScanNode(pCxt, &info);
break;
diff --git a/source/libs/planner/test/CMakeLists.txt b/source/libs/planner/test/CMakeLists.txt
index abea60b0c7..b34ffa7bb1 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/planGroupByTest.cpp b/source/libs/planner/test/planGroupByTest.cpp
index cf51603470..201df2efde 100644
--- a/source/libs/planner/test/planGroupByTest.cpp
+++ b/source/libs/planner/test/planGroupByTest.cpp
@@ -67,3 +67,11 @@ TEST_F(PlanGroupByTest, selectFunc) {
run("SELECT MAX(c1), c2 FROM t1 GROUP BY c3");
run("SELECT MAX(c1), t1.* FROM t1 GROUP BY c3");
}
+
+TEST_F(PlanGroupByTest, stable) {
+ useDb("root", "test");
+
+ run("SELECT COUNT(*) FROM st1");
+
+ run("SELECT COUNT(*) FROM st1 GROUP BY c1");
+}
diff --git a/source/libs/planner/test/planOrderByTest.cpp b/source/libs/planner/test/planOrderByTest.cpp
index d95d1bdf1d..ef6f438b55 100644
--- a/source/libs/planner/test/planOrderByTest.cpp
+++ b/source/libs/planner/test/planOrderByTest.cpp
@@ -23,20 +23,27 @@ class PlanOrderByTest : public PlannerTestBase {};
TEST_F(PlanOrderByTest, basic) {
useDb("root", "test");
- // order by key is in the projection list
- run("select c1 from t1 order by c1");
- // order by key is not in the projection list
- run("select c1 from t1 order by c2");
+ // ORDER BY key is in the projection list
+ run("SELECT c1 FROM t1 ORDER BY c1");
+ // ORDER BY key is not in the projection list
+ run("SELECT c1 FROM t1 ORDER BY c2");
}
TEST_F(PlanOrderByTest, expr) {
useDb("root", "test");
- run("select * from t1 order by c1 + 10, c2");
+ run("SELECT * FROM t1 ORDER BY c1 + 10, c2");
}
TEST_F(PlanOrderByTest, nullsOrder) {
useDb("root", "test");
- run("select * from t1 order by c1 desc nulls first");
+ run("SELECT * FROM t1 ORDER BY c1 DESC NULLS FIRST");
+}
+
+TEST_F(PlanOrderByTest, stable) {
+ useDb("root", "test");
+
+ // ORDER BY key is in the projection list
+ run("SELECT c1 FROM st1 ORDER BY c1");
}
diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp
index 42c8558239..acac3d5053 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 16dcd7b6e0..5bb6acee60 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 370ea8fa2e..2b15f5031e 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 4b5f74114d..5c0c6fbb76 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 dbad053c65..e383026f33 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;
@@ -1365,8 +1365,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);
}
@@ -1375,6 +1373,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));
@@ -1386,7 +1385,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 522bd8044d..32e00c1b70 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/transport/src/transCli.c b/source/libs/transport/src/transCli.c
index 580ab30b78..0090701ba5 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/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py
index 21d235ee5c..7eeddfd5c1 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 bb446fb248..32056e8d0c 100644
--- a/tests/script/jenkins/basic.txt
+++ b/tests/script/jenkins/basic.txt
@@ -58,7 +58,7 @@
./test.sh -f tsim/mnode/basic1.sim
./test.sh -f tsim/mnode/basic2.sim
./test.sh -f tsim/mnode/basic3.sim
-#./test.sh -f tsim/mnode/basic4.sim
+./test.sh -f tsim/mnode/basic4.sim
# ---- show
./test.sh -f tsim/show/basic.sim
@@ -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/db/alter_replica_13.sim b/tests/script/tsim/db/alter_replica_13.sim
index e20bf6937d..4d45b92967 100644
--- a/tests/script/tsim/db/alter_replica_13.sim
+++ b/tests/script/tsim/db/alter_replica_13.sim
@@ -128,7 +128,6 @@ if $data[0][8] != follower then
endi
print ============= step5: stop dnode 2
-return
sql select * from db.stb
if $rows != 1 then
diff --git a/tests/script/tsim/db/alter_replica_31.sim b/tests/script/tsim/db/alter_replica_31.sim
new file mode 100644
index 0000000000..896d6708b7
--- /dev/null
+++ b/tests/script/tsim/db/alter_replica_31.sim
@@ -0,0 +1,146 @@
+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/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
+sql connect
+
+print =============== step1: create dnodes
+sql create dnode $hostname port 7200
+sql create dnode $hostname port 7300
+sql create dnode $hostname port 7400
+
+$x = 0
+step1:
+ $x = $x + 1
+ sleep 1000
+ if $x == 10 then
+ print ====> dnode not ready!
+ return -1
+ endi
+sql show dnodes
+print ===> rows: $rows
+print ===> $data00 $data01 $data02 $data03 $data04 $data05
+print ===> $data10 $data11 $data12 $data13 $data14 $data15
+print ===> $data20 $data21 $data22 $data23 $data24 $data25
+print ===> $data30 $data31 $data32 $data33 $data24 $data35
+if $rows != 4 then
+ return -1
+endi
+if $data(1)[4] != ready then
+ goto step1
+endi
+if $data(2)[4] != ready then
+ goto step1
+endi
+if $data(3)[4] != ready then
+ goto step1
+endi
+if $data(4)[4] != ready then
+ goto step1
+endi
+
+print =============== step2: create database
+sql create database db vgroups 1 replica 3
+sql show databases
+if $rows != 3 then
+ return -1
+endi
+if $data(db)[4] != 3 then
+ return -1
+endi
+
+sql show dnodes
+if $data(2)[2] != 1 then
+ return -1
+endi
+if $data(3)[2] != 1 then
+ return -1
+endi
+if $data(4)[2] != 1 then
+ return -1
+endi
+
+# vnodes
+sql show dnodes
+if $data(2)[2] != 1 then
+ return -1
+endi
+if $data(3)[2] != 1 then
+ return -1
+endi
+if $data(4)[2] != 1 then
+ return -1
+endi
+
+# v1_dnode
+sql show db.vgroups
+print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08
+if $data(2)[3] != 4 then
+ return -1
+endi
+if $data(2)[5] != 3 then
+ return -1
+endi
+if $data(2)[7] != 2 then
+ return -1
+endi
+
+sql create table db.stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 binary(16)) comment "abd"
+sql create table db.ctb using db.stb tags(101, "102")
+sql insert into db.ctb values(now, 1, "2")
+
+sql show db.vgroups
+print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08
+
+sleep 1000
+sql select * from db.ctb
+print ===> $data00 $data01 $data02 $data03 $data04 $data05
+
+if $rows != 1 then
+ return -1
+endi
+
+sleep 3000
+
+print ============= step3: alter database
+sql alter database db replica 1
+
+$x = 0
+step3:
+ $x = $x + 1
+ sleep 1000
+ if $x == 10 then
+ print ====> dnode not ready!
+ return -1
+ endi
+sql show db.vgroups
+print ===> rows: $rows
+if $rows != 1 then
+ goto step3
+endi
+if $data(2)[3] != 4 then
+ goto step3
+endi
+if $data(2)[5] != NULL then
+ goto step3
+endi
+if $data(2)[7] != NULL then
+ goto step3
+endi
+
+print ============= step5: stop dnode 2
+return
+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/sync/3Replica5VgElect.sim b/tests/script/tsim/sync/3Replica5VgElect.sim
index 2e05e848be..1243cf8124 100644
--- a/tests/script/tsim/sync/3Replica5VgElect.sim
+++ b/tests/script/tsim/sync/3Replica5VgElect.sim
@@ -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 0000000000..8df2c2007d
--- /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 0000000000..ae02a23c9b
--- /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/testsuit.sim b/tests/script/tsim/testsuit.sim
index 0b1f0df04e..883dc1e789 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