From da65b721d6ea0efd1b0360a406f36cd3f94e9b67 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Tue, 15 Mar 2022 20:07:48 +0800 Subject: [PATCH 01/20] rename --- source/util/src/tuuid.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/util/src/tuuid.c b/source/util/src/tuuid.c index ceca33436a..69cf7baaad 100644 --- a/source/util/src/tuuid.c +++ b/source/util/src/tuuid.c @@ -15,43 +15,43 @@ #include "tuuid.h" -static int64_t hashId = 0; -static int32_t SerialNo = 0; +static int64_t tUUIDHashId = 0; +static int32_t tUUIDSerialNo = 0; int32_t tGenIdPI32(void) { - if (hashId == 0) { + if (tUUIDHashId == 0) { char uid[64]; int32_t code = taosGetSystemUUID(uid, tListLen(uid)); if (code != TSDB_CODE_SUCCESS) { terrno = TAOS_SYSTEM_ERROR(errno); } else { - hashId = MurmurHash3_32(uid, strlen(uid)); + tUUIDHashId = MurmurHash3_32(uid, strlen(uid)); } } int64_t ts = taosGetTimestampMs(); uint64_t pid = taosGetPId(); - int32_t val = atomic_add_fetch_32(&SerialNo, 1); + int32_t val = atomic_add_fetch_32(&tUUIDSerialNo, 1); - int32_t id = ((hashId & 0x1F) << 26) | ((pid & 0x3F) << 20) | ((ts & 0xFFF) << 8) | (val & 0xFF); + int32_t id = ((tUUIDHashId & 0x1F) << 26) | ((pid & 0x3F) << 20) | ((ts & 0xFFF) << 8) | (val & 0xFF); return id; } int64_t tGenIdPI64(void) { - if (hashId == 0) { + if (tUUIDHashId == 0) { char uid[64]; int32_t code = taosGetSystemUUID(uid, tListLen(uid)); if (code != TSDB_CODE_SUCCESS) { terrno = TAOS_SYSTEM_ERROR(errno); } else { - hashId = MurmurHash3_32(uid, strlen(uid)); + tUUIDHashId = MurmurHash3_32(uid, strlen(uid)); } } int64_t ts = taosGetTimestampMs(); uint64_t pid = taosGetPId(); - int32_t val = atomic_add_fetch_32(&SerialNo, 1); + int32_t val = atomic_add_fetch_32(&tUUIDSerialNo, 1); - int64_t id = ((hashId & 0x07FF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF); + int64_t id = ((tUUIDHashId & 0x07FF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF); return id; } From b5b1417a8b0b3d9e5b19d6845b1625de817ff8d4 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 10:54:06 +0800 Subject: [PATCH 02/20] sync append entries (sync-io) --- source/libs/sync/inc/syncRaftStore.h | 12 +- source/libs/sync/src/syncIndexMgr.c | 34 +- source/libs/sync/src/syncMain.c | 235 +++++------ source/libs/sync/src/syncMessage.c | 560 +++++++++++++------------ source/libs/sync/src/syncRaftEntry.c | 42 +- source/libs/sync/src/syncRaftLog.c | 36 +- source/libs/sync/src/syncRaftStore.c | 53 ++- source/libs/sync/src/syncVoteMgr.c | 94 +++-- source/libs/sync/test/syncInitTest.cpp | 1 + 9 files changed, 565 insertions(+), 502 deletions(-) diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h index 30f7c5d9f7..62bb94c834 100644 --- a/source/libs/sync/inc/syncRaftStore.h +++ b/source/libs/sync/inc/syncRaftStore.h @@ -43,11 +43,13 @@ int32_t raftStorePersist(SRaftStore *pRaftStore); int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len); int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len); -bool raftStoreHasVoted(SRaftStore *pRaftStore); -void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId); -void raftStoreClearVote(SRaftStore *pRaftStore); -void raftStoreNextTerm(SRaftStore *pRaftStore); -void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term); +bool raftStoreHasVoted(SRaftStore *pRaftStore); +void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId); +void raftStoreClearVote(SRaftStore *pRaftStore); +void raftStoreNextTerm(SRaftStore *pRaftStore); +void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term); +cJSON *raftStore2Json(SRaftStore *pRaftStore); +char *raftStore2Str(SRaftStore *pRaftStore); // for debug ------------------- void raftStorePrint(SRaftStore *pObj); diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index 9567938197..58a61ba77e 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -70,22 +70,24 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { char u64buf[128]; cJSON *pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncIndexMgr->replicaNum); - cJSON *pReplicas = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "replicas", pReplicas); - for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { - cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i])); + if (pSyncIndexMgr != NULL) { + cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncIndexMgr->replicaNum); + cJSON *pReplicas = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "replicas", pReplicas); + for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { + cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i])); + } + int respondNum = 0; + int *arr = (int *)malloc(sizeof(int) * pSyncIndexMgr->replicaNum); + for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { + arr[i] = pSyncIndexMgr->index[i]; + } + cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum); + free(arr); + cJSON_AddItemToObject(pRoot, "index", pIndex); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); } - int respondNum = 0; - int *arr = (int *)malloc(sizeof(int) * pSyncIndexMgr->replicaNum); - for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { - arr[i] = pSyncIndexMgr->index[i]; - } - cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum); - free(arr); - cJSON_AddItemToObject(pRoot, "index", pIndex); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); cJSON *pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "pSyncIndexMgr", pRoot); @@ -94,7 +96,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index dd2c142104..48a57dc0fb 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -355,128 +355,129 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - // init by SSyncInfo - cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId); - cJSON_AddStringToObject(pRoot, "path", pSyncNode->path); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal); - cJSON_AddStringToObject(pRoot, "pWal", u64buf); + if (pSyncNode != NULL) { + // init by SSyncInfo + cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId); + cJSON_AddStringToObject(pRoot, "path", pSyncNode->path); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->rpcClient); - cJSON_AddStringToObject(pRoot, "rpcClient", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg); - cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->rpcClient); + cJSON_AddStringToObject(pRoot, "rpcClient", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg); + cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->queue); - cJSON_AddStringToObject(pRoot, "queue", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg); - cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->queue); + cJSON_AddStringToObject(pRoot, "queue", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg); + cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf); - // init internal - cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo); - cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe); - cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId); - cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId); + // init internal + cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo); + cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe); + cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId); + cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId); - cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum); - cJSON* pPeers = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers); - for (int i = 0; i < pSyncNode->peersNum; ++i) { - cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i])); + cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum); + cJSON* pPeers = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers); + for (int i = 0; i < pSyncNode->peersNum; ++i) { + cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i])); + } + cJSON* pPeersId = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "peersId", pPeersId); + for (int i = 0; i < pSyncNode->peersNum; ++i) { + cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i])); + } + + cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum); + cJSON* pReplicasId = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId); + for (int i = 0; i < pSyncNode->replicaNum; ++i) { + cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i])); + } + + // raft algorithm + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm); + cJSON_AddStringToObject(pRoot, "pFsm", u64buf); + cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum); + cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache); + cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache); + + // tla+ server vars + cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state); + cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state)); + cJSON* pRaftStore = raftStore2Json(pSyncNode->pRaftStore); + cJSON_AddItemToObject(pRoot, "pRaftStore", pRaftStore); + + // tla+ candidate vars + cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted)); + cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond)); + + // tla+ leader vars + cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex)); + cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex)); + + // tla+ log vars + cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%ld", pSyncNode->commitIndex); + cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); + + // ping timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer); + cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClock); + cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClockUser); + cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB); + cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerCounter); + cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf); + + // elect timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer); + cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClock); + cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClockUser); + cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB); + cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerCounter); + cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf); + + // heartbeat timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer); + cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClock); + cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClockUser); + cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB); + cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerCounter); + cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf); + + // callback + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing); + cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply); + cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote); + cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply); + cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries); + cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply); + cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout); + cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf); } - cJSON* pPeersId = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "peersId", pPeersId); - for (int i = 0; i < pSyncNode->peersNum; ++i) { - cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i])); - } - - cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum); - cJSON* pReplicasId = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId); - for (int i = 0; i < pSyncNode->replicaNum; ++i) { - cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i])); - } - - // raft algorithm - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm); - cJSON_AddStringToObject(pRoot, "pFsm", u64buf); - cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum); - cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache); - cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache); - - // tla+ server vars - cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state); - cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state)); - char tmpBuf[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pSyncNode->pRaftStore, tmpBuf, sizeof(tmpBuf)); - cJSON_AddStringToObject(pRoot, "pRaftStore", tmpBuf); - - // tla+ candidate vars - cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted)); - cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond)); - - // tla+ leader vars - cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex)); - cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex)); - - // tla+ log vars - cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore)); - snprintf(u64buf, sizeof(u64buf), "%ld", pSyncNode->commitIndex); - cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); - - // ping timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer); - cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClock); - cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClockUser); - cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB); - cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerCounter); - cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf); - - // elect timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer); - cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClock); - cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClockUser); - cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB); - cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerCounter); - cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf); - - // heartbeat timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer); - cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClock); - cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClockUser); - cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB); - cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerCounter); - cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf); - - // callback - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing); - cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply); - cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote); - cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply); - cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries); - cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply); - cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout); - cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SSyncNode", pRoot); diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 509ede274b..ac7cbe9ca4 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -212,17 +212,19 @@ SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncTimeout2Json(const SyncTimeout* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON_AddNumberToObject(pRoot, "timeoutType", pMsg->timeoutType); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->logicClock); - cJSON_AddStringToObject(pRoot, "logicClock", u64buf); - cJSON_AddNumberToObject(pRoot, "timerMS", pMsg->timerMS); - snprintf(u64buf, sizeof(u64buf), "%p", pMsg->data); - cJSON_AddStringToObject(pRoot, "data", u64buf); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + cJSON_AddNumberToObject(pRoot, "timeoutType", pMsg->timeoutType); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->logicClock); + cJSON_AddStringToObject(pRoot, "logicClock", u64buf); + cJSON_AddNumberToObject(pRoot, "timerMS", pMsg->timerMS); + snprintf(u64buf, sizeof(u64buf), "%p", pMsg->data); + cJSON_AddStringToObject(pRoot, "data", u64buf); + } cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncTimeout", pRoot); @@ -342,50 +344,52 @@ SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncPing2Json(const SyncPing* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + char* s; + s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + free(s); + s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); - cJSON_AddStringToObject(pDestId, "addr", u64buf); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - free(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - free(s); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncPing", pRoot); @@ -505,50 +509,52 @@ SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncPingReply2Json(const SyncPingReply* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + char* s; + s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + free(s); + s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); - cJSON_AddStringToObject(pDestId, "addr", u64buf); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - free(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - free(s); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncPingReply", pRoot); @@ -664,24 +670,26 @@ SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->seqNum); - cJSON_AddStringToObject(pRoot, "seqNum", u64buf); - cJSON_AddNumberToObject(pRoot, "isWeak", pMsg->isWeak); - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - free(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->seqNum); + cJSON_AddStringToObject(pRoot, "seqNum", u64buf); + cJSON_AddNumberToObject(pRoot, "isWeak", pMsg->isWeak); + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + + char* s; + s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + free(s); + s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); + } cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncClientRequest", pRoot); @@ -785,47 +793,49 @@ SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogIndex); + cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm); + cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogIndex); - cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm); - cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncRequestVote", pRoot); @@ -929,44 +939,46 @@ SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + cJSON_AddNumberToObject(pRoot, "vote_granted", pMsg->voteGranted); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - cJSON_AddNumberToObject(pRoot, "vote_granted", pMsg->voteGranted); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncRequestVoteReply", pRoot); @@ -1072,62 +1084,64 @@ SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) { } cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogIndex); + cJSON_AddStringToObject(pRoot, "pre_log_index", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm); + cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->commitIndex); + cJSON_AddStringToObject(pRoot, "commit_index", u64buf); + + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + char* s; + s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + free(s); + s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); - cJSON_AddStringToObject(pDestId, "addr", u64buf); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogIndex); - cJSON_AddStringToObject(pRoot, "pre_log_index", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm); - cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->commitIndex); - cJSON_AddStringToObject(pRoot, "commit_index", u64buf); - - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - free(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - free(s); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncAppendEntries", pRoot); @@ -1231,47 +1245,49 @@ SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg } cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + cJSON_AddNumberToObject(pRoot, "success", pMsg->success); + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->matchIndex); + cJSON_AddStringToObject(pRoot, "matchIndex", u64buf); } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); - cJSON_AddStringToObject(pDestId, "addr", u64buf); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128]; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - cJSON_AddNumberToObject(pRoot, "success", pMsg->success); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->matchIndex); - cJSON_AddStringToObject(pRoot, "matchIndex", u64buf); cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot); diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index f29b3022d8..41bfd7da1f 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -68,29 +68,31 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) { } cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { - char u64buf[128]; - + char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType); - cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->seqNum); - cJSON_AddStringToObject(pRoot, "seqNum", u64buf); - cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->index); - cJSON_AddStringToObject(pRoot, "index", u64buf); - cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen); - char* s; - s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - free(s); + if (pEntry != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType); + cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType); + snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->seqNum); + cJSON_AddStringToObject(pRoot, "seqNum", u64buf); + cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak); + snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->index); + cJSON_AddStringToObject(pRoot, "index", u64buf); + cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen); - s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - free(s); + char* s; + s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + free(s); + + s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); + } cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 6ebeba1991..f3fd7f84a2 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -122,26 +122,28 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { } cJSON* logStore2Json(SSyncLogStore* pLogStore) { - char u64buf[128]; - + char u64buf[128]; SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; cJSON* pRoot = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); - cJSON_AddStringToObject(pRoot, "pWal", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", logStoreLastIndex(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", logStoreLastTerm(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); - cJSON* pEntries = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "pEntries", pEntries); - SyncIndex lastIndex = logStoreLastIndex(pLogStore); - for (SyncIndex i = 0; i <= lastIndex; ++i) { - SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); - cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); - syncEntryDestory(pEntry); + if (pData != NULL && pData->pWal != NULL) { + snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + snprintf(u64buf, sizeof(u64buf), "%ld", logStoreLastIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", logStoreLastTerm(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); + + cJSON* pEntries = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "pEntries", pEntries); + SyncIndex lastIndex = logStoreLastIndex(pLogStore); + for (SyncIndex i = 0; i <= lastIndex; ++i) { + SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + syncEntryDestory(pEntry); + } } cJSON* pJson = cJSON_CreateObject(); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 5ad618b9c0..9a5401e3f1 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -164,30 +164,63 @@ void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) { raftStorePersist(pRaftStore); } +cJSON *raftStore2Json(SRaftStore *pRaftStore) { + char u64buf[128]; + cJSON *pRoot = cJSON_CreateObject(); + + if (pRaftStore != NULL) { + snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->currentTerm); + cJSON_AddStringToObject(pRoot, "currentTerm", u64buf); + + cJSON *pVoteFor = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->voteFor.addr); + cJSON_AddStringToObject(pVoteFor, "addr", u64buf); + { + uint64_t u64 = pRaftStore->voteFor.addr; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pVoteFor, "addr_host", host); + cJSON_AddNumberToObject(pVoteFor, "addr_port", port); + } + cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId); + cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor); + } + + cJSON *pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SRaftStore", pRoot); + return pJson; +} + +char *raftStore2Str(SRaftStore *pRaftStore) { + cJSON *pJson = raftStore2Json(pRaftStore); + char *serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + // for debug ------------------- void raftStorePrint(SRaftStore *pObj) { - char serialized[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pObj, serialized, sizeof(serialized)); + char *serialized = raftStore2Str(pObj); printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized); fflush(NULL); + free(serialized); } void raftStorePrint2(char *s, SRaftStore *pObj) { - char serialized[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pObj, serialized, sizeof(serialized)); + char *serialized = raftStore2Str(pObj); printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); + free(serialized); } void raftStoreLog(SRaftStore *pObj) { - char serialized[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pObj, serialized, sizeof(serialized)); + char *serialized = raftStore2Str(pObj); sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized); - fflush(NULL); + free(serialized); } void raftStoreLog2(char *s, SRaftStore *pObj) { - char serialized[RAFT_STORE_BLOCK_SIZE]; - raftStoreSerialize(pObj, serialized, sizeof(serialized)); + char *serialized = raftStore2Str(pObj); sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); - fflush(NULL); + free(serialized); } diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 5c8e70979c..5830a0a54f 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -82,30 +82,32 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { char u64buf[128]; cJSON *pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesGranted->replicaNum); - cJSON *pReplicas = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "replicas", pReplicas); - for (int i = 0; i < pVotesGranted->replicaNum; ++i) { - cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i])); - } - int *arr = (int *)malloc(sizeof(int) * pVotesGranted->replicaNum); - for (int i = 0; i < pVotesGranted->replicaNum; ++i) { - arr[i] = pVotesGranted->isGranted[i]; - } - cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum); - free(arr); - cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted); + if (pVotesGranted != NULL) { + cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesGranted->replicaNum); + cJSON *pReplicas = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "replicas", pReplicas); + for (int i = 0; i < pVotesGranted->replicaNum; ++i) { + cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i])); + } + int *arr = (int *)malloc(sizeof(int) * pVotesGranted->replicaNum); + for (int i = 0; i < pVotesGranted->replicaNum; ++i) { + arr[i] = pVotesGranted->isGranted[i]; + } + cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum); + free(arr); + cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted); - cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes); - snprintf(u64buf, sizeof(u64buf), "%lu", pVotesGranted->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - cJSON_AddNumberToObject(pRoot, "quorum", pVotesGranted->quorum); - cJSON_AddNumberToObject(pRoot, "toLeader", pVotesGranted->toLeader); - snprintf(u64buf, sizeof(u64buf), "%p", pVotesGranted->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes); + snprintf(u64buf, sizeof(u64buf), "%lu", pVotesGranted->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + cJSON_AddNumberToObject(pRoot, "quorum", pVotesGranted->quorum); + cJSON_AddNumberToObject(pRoot, "toLeader", pVotesGranted->toLeader); + snprintf(u64buf, sizeof(u64buf), "%p", pVotesGranted->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - bool majority = voteGrantedMajority(pVotesGranted); - cJSON_AddNumberToObject(pRoot, "majority", majority); + bool majority = voteGrantedMajority(pVotesGranted); + cJSON_AddNumberToObject(pRoot, "majority", majority); + } cJSON *pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SVotesGranted", pRoot); @@ -114,7 +116,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { char *voteGranted2Str(SVotesGranted *pVotesGranted) { cJSON *pJson = voteGranted2Json(pVotesGranted); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -203,29 +205,31 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { char u64buf[128]; cJSON *pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesRespond->replicaNum); - cJSON *pReplicas = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "replicas", pReplicas); - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { - cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i])); - } - int respondNum = 0; - int *arr = (int *)malloc(sizeof(int) * pVotesRespond->replicaNum); - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { - arr[i] = pVotesRespond->isRespond[i]; - if (pVotesRespond->isRespond[i]) { - respondNum++; + if (pVotesRespond != NULL) { + cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesRespond->replicaNum); + cJSON *pReplicas = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "replicas", pReplicas); + for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i])); } - } - cJSON *pIsRespond = cJSON_CreateIntArray(arr, pVotesRespond->replicaNum); - free(arr); - cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond); - cJSON_AddNumberToObject(pRoot, "respondNum", respondNum); + int respondNum = 0; + int *arr = (int *)malloc(sizeof(int) * pVotesRespond->replicaNum); + for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + arr[i] = pVotesRespond->isRespond[i]; + if (pVotesRespond->isRespond[i]) { + respondNum++; + } + } + cJSON *pIsRespond = cJSON_CreateIntArray(arr, pVotesRespond->replicaNum); + free(arr); + cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond); + cJSON_AddNumberToObject(pRoot, "respondNum", respondNum); - snprintf(u64buf, sizeof(u64buf), "%lu", pVotesRespond->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pVotesRespond->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pVotesRespond->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pVotesRespond->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + } cJSON *pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SVotesRespond", pRoot); @@ -234,7 +238,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { char *votesRespond2Str(SVotesRespond *pVotesRespond) { cJSON *pJson = votesRespond2Json(pVotesRespond); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index 7898fda8c0..c0d2336ba7 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -47,6 +47,7 @@ SSyncNode* syncNodeInit() { gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; From 6fcbca5b395b27d54c96c7c696e845b63272137d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 11:45:12 +0800 Subject: [PATCH 03/20] sync ping --- source/libs/sync/src/syncTimeout.c | 3 +- source/libs/sync/test/CMakeLists.txt | 28 +++++ source/libs/sync/test/syncInitTest.cpp | 2 - source/libs/sync/test/syncPingSelfTest.cpp | 102 ++++++++++++++++++ source/libs/sync/test/syncPingTimerTest.cpp | 1 + source/libs/sync/test/syncPingTimerTest2.cpp | 106 +++++++++++++++++++ 6 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 source/libs/sync/test/syncPingSelfTest.cpp create mode 100644 source/libs/sync/test/syncPingTimerTest2.cpp diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index 3a48b0cbb3..0d3a3c3cc5 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -24,7 +24,8 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { if (pMsg->timeoutType == SYNC_TIMEOUT_PING) { if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->pingTimerCounter); - syncNodePingAll(ths); + // syncNodePingAll(ths); + syncNodePingPeers(ths); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) { diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 6ade78936d..b542f55ec3 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -25,6 +25,8 @@ add_executable(syncTimeoutTest "") add_executable(syncPingTest "") add_executable(syncPingReplyTest "") add_executable(syncRpcMsgTest "") +add_executable(syncPingTimerTest2 "") +add_executable(syncPingSelfTest "") target_sources(syncTest @@ -135,6 +137,14 @@ target_sources(syncRpcMsgTest PRIVATE "syncRpcMsgTest.cpp" ) +target_sources(syncPingTimerTest2 + PRIVATE + "syncPingTimerTest2.cpp" +) +target_sources(syncPingSelfTest + PRIVATE + "syncPingSelfTest.cpp" +) target_include_directories(syncTest @@ -272,6 +282,16 @@ target_include_directories(syncRpcMsgTest "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncPingTimerTest2 + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) +target_include_directories(syncPingSelfTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -382,6 +402,14 @@ target_link_libraries(syncRpcMsgTest sync gtest_main ) +target_link_libraries(syncPingTimerTest2 + sync + gtest_main +) +target_link_libraries(syncPingSelfTest + sync + gtest_main +) enable_testing() diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index c0d2336ba7..a3e5f41c85 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -52,8 +52,6 @@ SSyncNode* syncNodeInit() { gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; - gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; - gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; gSyncIO->pSyncNode = pSyncNode; diff --git a/source/libs/sync/test/syncPingSelfTest.cpp b/source/libs/sync/test/syncPingSelfTest.cpp new file mode 100644 index 0000000000..05e4d99cb0 --- /dev/null +++ b/source/libs/sync/test/syncPingSelfTest.cpp @@ -0,0 +1,102 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; + +SSyncNode* syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); + + SSyncCfg* pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + SSyncNode* pSyncNode = syncNodeOpen(&syncInfo); + assert(pSyncNode != NULL); + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->pSyncNode = pSyncNode; + + return pSyncNode; +} + +SSyncNode* syncInitTest() { return syncNodeInit(); } + +void initRaftId(SSyncNode* pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char* s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + ret = syncEnvStart(); + assert(ret == 0); + + SSyncNode* pSyncNode = syncInitTest(); + assert(pSyncNode != NULL); + syncNodePrint2((char*)"", pSyncNode); + + initRaftId(pSyncNode); + + //--------------------------- + + while (1) { + syncNodePingSelf(pSyncNode); + taosMsleep(1000); + } + + return 0; +} diff --git a/source/libs/sync/test/syncPingTimerTest.cpp b/source/libs/sync/test/syncPingTimerTest.cpp index e69878632f..20d4a9ce58 100644 --- a/source/libs/sync/test/syncPingTimerTest.cpp +++ b/source/libs/sync/test/syncPingTimerTest.cpp @@ -47,6 +47,7 @@ SSyncNode* syncNodeInit() { gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; diff --git a/source/libs/sync/test/syncPingTimerTest2.cpp b/source/libs/sync/test/syncPingTimerTest2.cpp new file mode 100644 index 0000000000..2a041f3f5d --- /dev/null +++ b/source/libs/sync/test/syncPingTimerTest2.cpp @@ -0,0 +1,106 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; + +SSyncNode* syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); + + SSyncCfg* pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + SSyncNode* pSyncNode = syncNodeOpen(&syncInfo); + assert(pSyncNode != NULL); + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->pSyncNode = pSyncNode; + + return pSyncNode; +} + +SSyncNode* syncInitTest() { return syncNodeInit(); } + +void initRaftId(SSyncNode* pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char* s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + ret = syncEnvStart(); + assert(ret == 0); + + SSyncNode* pSyncNode = syncInitTest(); + assert(pSyncNode != NULL); + syncNodePrint2((char*)"", pSyncNode); + + initRaftId(pSyncNode); + + //--------------------------- + + sTrace("syncNodeStartPingTimer ..."); + ret = syncNodeStartPingTimer(pSyncNode); + assert(ret == 0); + + while (1) { + sTrace("while 1 sleep ..."); + taosMsleep(1000); + } + + return 0; +} From f8f7aabfd9ddf41338016a038f80cfac279204ab Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Wed, 16 Mar 2022 02:08:59 -0400 Subject: [PATCH 04/20] TD-13597 create/drop topic, alter database, drop index, drop qnode statement implement --- include/common/tmsg.h | 4 +- include/common/ttokendef.h | 95 +- include/libs/nodes/cmdnodes.h | 31 + include/libs/nodes/nodes.h | 5 + source/client/src/tmq.c | 4 +- source/common/src/tmsg.c | 41 +- source/dnode/mnode/impl/src/mndTopic.c | 27 +- source/dnode/mnode/impl/test/topic/topic.cpp | 3 +- source/libs/nodes/src/nodesCodeFuncs.c | 7 +- source/libs/nodes/src/nodesUtilFuncs.c | 10 + source/libs/parser/inc/parAst.h | 5 + source/libs/parser/inc/sql.y | 32 +- source/libs/parser/src/parAstCreater.c | 49 + source/libs/parser/src/parTokenizer.c | 2 +- source/libs/parser/src/parTranslater.c | 175 +- source/libs/parser/src/sql.c | 3099 +++++++++--------- source/libs/parser/test/parserAstTest.cpp | 57 + 17 files changed, 2024 insertions(+), 1622 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index f0718900c0..dc418147b0 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1157,8 +1157,8 @@ typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; int8_t igExists; char* sql; - char* physicalPlan; - char* logicalPlan; + char* ast; + char subscribeDbName[TSDB_DB_NAME_LEN]; } SCMCreateTopicReq; int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 5693091bd5..167c72a778 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -108,53 +108,54 @@ #define TK_FULLTEXT 90 #define TK_FUNCTION 91 #define TK_INTERVAL 92 -#define TK_MNODES 93 -#define TK_NK_FLOAT 94 -#define TK_NK_BOOL 95 -#define TK_NK_VARIABLE 96 -#define TK_BETWEEN 97 -#define TK_IS 98 -#define TK_NULL 99 -#define TK_NK_LT 100 -#define TK_NK_GT 101 -#define TK_NK_LE 102 -#define TK_NK_GE 103 -#define TK_NK_NE 104 -#define TK_NK_EQ 105 -#define TK_LIKE 106 -#define TK_MATCH 107 -#define TK_NMATCH 108 -#define TK_IN 109 -#define TK_FROM 110 -#define TK_AS 111 -#define TK_JOIN 112 -#define TK_INNER 113 -#define TK_SELECT 114 -#define TK_DISTINCT 115 -#define TK_WHERE 116 -#define TK_PARTITION 117 -#define TK_BY 118 -#define TK_SESSION 119 -#define TK_STATE_WINDOW 120 -#define TK_SLIDING 121 -#define TK_FILL 122 -#define TK_VALUE 123 -#define TK_NONE 124 -#define TK_PREV 125 -#define TK_LINEAR 126 -#define TK_NEXT 127 -#define TK_GROUP 128 -#define TK_HAVING 129 -#define TK_ORDER 130 -#define TK_SLIMIT 131 -#define TK_SOFFSET 132 -#define TK_LIMIT 133 -#define TK_OFFSET 134 -#define TK_ASC 135 -#define TK_DESC 136 -#define TK_NULLS 137 -#define TK_FIRST 138 -#define TK_LAST 139 +#define TK_TOPIC 93 +#define TK_AS 94 +#define TK_MNODES 95 +#define TK_NK_FLOAT 96 +#define TK_NK_BOOL 97 +#define TK_NK_VARIABLE 98 +#define TK_BETWEEN 99 +#define TK_IS 100 +#define TK_NULL 101 +#define TK_NK_LT 102 +#define TK_NK_GT 103 +#define TK_NK_LE 104 +#define TK_NK_GE 105 +#define TK_NK_NE 106 +#define TK_NK_EQ 107 +#define TK_LIKE 108 +#define TK_MATCH 109 +#define TK_NMATCH 110 +#define TK_IN 111 +#define TK_FROM 112 +#define TK_JOIN 113 +#define TK_INNER 114 +#define TK_SELECT 115 +#define TK_DISTINCT 116 +#define TK_WHERE 117 +#define TK_PARTITION 118 +#define TK_BY 119 +#define TK_SESSION 120 +#define TK_STATE_WINDOW 121 +#define TK_SLIDING 122 +#define TK_FILL 123 +#define TK_VALUE 124 +#define TK_NONE 125 +#define TK_PREV 126 +#define TK_LINEAR 127 +#define TK_NEXT 128 +#define TK_GROUP 129 +#define TK_HAVING 130 +#define TK_ORDER 131 +#define TK_SLIMIT 132 +#define TK_SOFFSET 133 +#define TK_LIMIT 134 +#define TK_OFFSET 135 +#define TK_ASC 136 +#define TK_DESC 137 +#define TK_NULLS 138 +#define TK_FIRST 139 +#define TK_LAST 140 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 21d9ff83c8..5d7174fc08 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -61,6 +61,12 @@ typedef struct SDropDatabaseStmt { bool ignoreNotExists; } SDropDatabaseStmt; +typedef struct SAlterDatabaseStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + SDatabaseOptions* pOptions; +} SAlterDatabaseStmt; + typedef struct STableOptions { ENodeType type; int32_t keep; @@ -179,11 +185,36 @@ typedef struct SCreateIndexStmt { SIndexOptions* pOptions; } SCreateIndexStmt; +typedef struct SDropIndexStmt { + ENodeType type; + char indexName[TSDB_INDEX_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; +} SDropIndexStmt; + typedef struct SCreateQnodeStmt { ENodeType type; int32_t dnodeId; } SCreateQnodeStmt; +typedef struct SDropQnodeStmt { + ENodeType type; + int32_t dnodeId; +} SDropQnodeStmt; + +typedef struct SCreateTopicStmt { + ENodeType type; + char topicName[TSDB_TABLE_NAME_LEN]; + char subscribeDbName[TSDB_DB_NAME_LEN]; + bool ignoreExists; + SNode* pQuery; +} SCreateTopicStmt; + +typedef struct SDropTopicStmt { + ENodeType type; + char topicName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; +} SDropTopicStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index cf34c6665a..4ef70fc7ab 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -77,6 +77,7 @@ typedef enum ENodeType { QUERY_NODE_VNODE_MODIF_STMT, QUERY_NODE_CREATE_DATABASE_STMT, QUERY_NODE_DROP_DATABASE_STMT, + QUERY_NODE_ALTER_DATABASE_STMT, QUERY_NODE_SHOW_DATABASES_STMT, // temp QUERY_NODE_CREATE_TABLE_STMT, QUERY_NODE_CREATE_SUBTABLE_CLAUSE, @@ -98,7 +99,11 @@ typedef enum ENodeType { QUERY_NODE_SHOW_MNODES_STMT, QUERY_NODE_SHOW_QNODES_STMT, QUERY_NODE_CREATE_INDEX_STMT, + QUERY_NODE_DROP_INDEX_STMT, QUERY_NODE_CREATE_QNODE_STMT, + QUERY_NODE_DROP_QNODE_STMT, + QUERY_NODE_CREATE_TOPIC_STMT, + QUERY_NODE_DROP_TOPIC_STMT, // logic plan node QUERY_NODE_LOGIC_PLAN_SCAN, diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index b3f71c1075..0ddd53be08 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -482,7 +482,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i } tscDebug("start to create topic, %s", topicName); - +#if 0 CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return); @@ -536,7 +536,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); tsem_wait(&pRequest->body.rspSem); - +#endif _return: qDestroyQuery(pQueryNode); /*if (sendInfo != NULL) {*/ diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index f26f19f3b2..abd341557f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1990,11 +1990,9 @@ int32_t tDeserializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pR int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTopicReq *pReq) { int32_t sqlLen = 0; - int32_t physicalPlanLen = 0; - int32_t logicalPlanLen = 0; + int32_t astLen = 0; if (pReq->sql != NULL) sqlLen = (int32_t)strlen(pReq->sql); - if (pReq->physicalPlan != NULL) physicalPlanLen = (int32_t)strlen(pReq->physicalPlan); - if (pReq->logicalPlan != NULL) logicalPlanLen = (int32_t)strlen(pReq->logicalPlan); + if (pReq->ast != NULL) astLen = (int32_t)strlen(pReq->ast); SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2003,11 +2001,9 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI32(&encoder, sqlLen) < 0) return -1; - if (tEncodeI32(&encoder, physicalPlanLen) < 0) return -1; - if (tEncodeI32(&encoder, logicalPlanLen) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->physicalPlan) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->logicalPlan) < 0) return -1; + if (tEncodeI32(&encoder, astLen) < 0) return -1; + if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; + if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; tEndEncode(&encoder); @@ -2018,8 +2014,7 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicReq *pReq) { int32_t sqlLen = 0; - int32_t physicalPlanLen = 0; - int32_t logicalPlanLen = 0; + int32_t astLen = 0; SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2028,17 +2023,20 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeI32(&decoder, &sqlLen) < 0) return -1; - if (tDecodeI32(&decoder, &physicalPlanLen) < 0) return -1; - if (tDecodeI32(&decoder, &logicalPlanLen) < 0) return -1; + if (tDecodeI32(&decoder, &astLen) < 0) return -1; - pReq->sql = calloc(1, sqlLen + 1); - pReq->physicalPlan = calloc(1, physicalPlanLen + 1); - pReq->logicalPlan = calloc(1, logicalPlanLen + 1); - if (pReq->sql == NULL || pReq->physicalPlan == NULL || pReq->logicalPlan == NULL) return -1; + if (sqlLen > 0) { + pReq->sql = calloc(1, sqlLen + 1); + if (pReq->sql == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; + } + + if (astLen > 0) { + pReq->ast = calloc(1, astLen + 1); + if (pReq->ast == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1; + } - if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->physicalPlan) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->logicalPlan) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -2047,8 +2045,7 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) { tfree(pReq->sql); - tfree(pReq->physicalPlan); - tfree(pReq->logicalPlan); + tfree(pReq->ast); } int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) { diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 7d7c5f9975..32fa3df910 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -236,6 +236,25 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { return 0; } +static int32_t mndGetPlanString(SCMCreateTopicReq *pCreate, char **pStr) { + SNode* pAst = NULL; + int32_t code = nodesStringToNode(pCreate->ast, &pAst); + + SQueryPlan* pPlan = NULL; + if (TSDB_CODE_SUCCESS == code) { + SPlanContext cxt = { .pAstRoot = pAst, .streamQuery = true }; + code = qCreateQueryPlan(&cxt, &pPlan, NULL); + } + + if (TSDB_CODE_SUCCESS == code) { + code = nodesNodeToString(pPlan, false, pStr, NULL); + } + nodesDestroyNode(pAst); + nodesDestroyNode(pPlan); + terrno = code; + return code; +} + static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) { mDebug("topic:%s to create", pCreate->name); SMqTopicObj topicObj = {0}; @@ -247,10 +266,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq topicObj.dbUid = pDb->uid; topicObj.version = 1; topicObj.sql = pCreate->sql; - topicObj.physicalPlan = pCreate->physicalPlan; - topicObj.logicalPlan = pCreate->logicalPlan; + topicObj.logicalPlan = NULL; topicObj.sqlLen = strlen(pCreate->sql); + if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &topicObj.physicalPlan)) { + mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); + return -1; + } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index f58d0a6771..79f353a4d6 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -65,8 +65,7 @@ void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql, strcpy(createReq.name, topicName); createReq.igExists = 0; createReq.sql = (char*)sql; - createReq.physicalPlan = (char*)"physicalPlan"; - createReq.logicalPlan = (char*)"logicalPlan"; + createReq.ast = (char*)"ast"; int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); void* pReq = rpcMallocCont(contLen); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 457f863a5e..a2fd32d238 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -1730,7 +1730,7 @@ static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** p } int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) { - if (NULL == pNode || NULL == pStr || NULL == pLen) { + if (NULL == pNode || NULL == pStr) { terrno = TSDB_CODE_FAILED; return TSDB_CODE_FAILED; } @@ -1750,7 +1750,10 @@ int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_ *pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson); tjsonDelete(pJson); - *pLen = strlen(*pStr) + 1; + if (NULL != pLen) { + *pLen = strlen(*pStr) + 1; + } + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index b17a4904da..75568019cb 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -92,6 +92,8 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SCreateDatabaseStmt)); case QUERY_NODE_DROP_DATABASE_STMT: return makeNode(type, sizeof(SDropDatabaseStmt)); + case QUERY_NODE_ALTER_DATABASE_STMT: + return makeNode(type, sizeof(SAlterDatabaseStmt)); case QUERY_NODE_SHOW_DATABASES_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_CREATE_TABLE_STMT: @@ -131,8 +133,16 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_CREATE_INDEX_STMT: return makeNode(type, sizeof(SCreateIndexStmt)); + case QUERY_NODE_DROP_INDEX_STMT: + return makeNode(type, sizeof(SDropIndexStmt)); case QUERY_NODE_CREATE_QNODE_STMT: return makeNode(type, sizeof(SCreateQnodeStmt)); + case QUERY_NODE_DROP_QNODE_STMT: + return makeNode(type, sizeof(SDropQnodeStmt)); + case QUERY_NODE_CREATE_TOPIC_STMT: + return makeNode(type, sizeof(SCreateTopicStmt)); + case QUERY_NODE_DROP_TOPIC_STMT: + return makeNode(type, sizeof(SDropTopicStmt)); case QUERY_NODE_LOGIC_PLAN_SCAN: return makeNode(type, sizeof(SScanLogicNode)); case QUERY_NODE_LOGIC_PLAN_JOIN: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index f2fcced1a9..31d7331d0e 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -113,6 +113,7 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt); SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal); SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions); SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName); +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions); SNode* createDefaultTableOptions(SAstCreateContext* pCxt); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal); SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pSma); @@ -134,7 +135,11 @@ SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions); SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding); +SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName); SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); +SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName); +SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index af2fb12c52..31c26e1e40 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -42,17 +42,17 @@ //%right NK_BITNOT. /************************************************ create/alter/drop/show user *****************************************/ -cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B);} -cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);} -cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);} +cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); } +cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); } +cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); } /************************************************ create/drop/show dnode **********************************************/ -cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);} -cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);} -cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);} -cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);} +cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); } +cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); } +cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } +cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); } %type dnode_endpoint { SToken } @@ -64,15 +64,17 @@ dnode_endpoint(A) ::= NK_STRING(B). dnode_host_name(A) ::= NK_ID(B). { A = B; } dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; } -/************************************************ create qnode ********************************************************/ +/************************************************ create/drop qnode ***************************************************/ cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &A); } +cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); } cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); } /************************************************ create/drop/show/use database ***************************************/ -cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);} +cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); } cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); } cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); } -cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);} +cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); } +cmd ::= ALTER DATABASE db_name(A) db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); } %type not_exists_opt { bool } %destructor not_exists_opt { } @@ -198,6 +200,7 @@ col_name(A) ::= column_name(B). cmd ::= CREATE SMA INDEX index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &A, &B, NULL, C); } cmd ::= CREATE FULLTEXT INDEX index_name(A) ON table_name(B) NK_LP col_name_list(C) NK_RP. { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &A, &B, C, NULL); } +cmd ::= DROP INDEX index_name(A) ON table_name(B). { pCxt->pRootNode = createDropIndexStmt(pCxt, &A, &B); } index_options(A) ::= . { A = NULL; } index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL @@ -212,6 +215,11 @@ func_list(A) ::= func_list(B) NK_COMMA func(C). func(A) ::= function_name(B) NK_LP expression_list(C) NK_RP. { A = createFunctionNode(pCxt, &B, C); } +/************************************************ create/drop topic ***************************************************/ +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, C, NULL); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); } +cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } + /************************************************ show vgroups ********************************************************/ cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); } cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); } @@ -270,6 +278,10 @@ user_name(A) ::= NK_ID(B). %destructor index_name { } index_name(A) ::= NK_ID(B). { A = B; } +%type topic_name { SToken } +%destructor topic_name { } +topic_name(A) ::= NK_ID(B). { A = B; } + /************************************************ expression **********************************************************/ expression(A) ::= literal(B). { A = B; } //expression(A) ::= NK_QUESTION(B). { A = B; } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index b7ecf160fd..034346362c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -799,6 +799,17 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con return (SNode*)pStmt; } +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions) { + if (!checkDbName(pCxt, pDbName)) { + return NULL; + } + SAlterDatabaseStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DATABASE_STMT); + CHECK_OUT_OF_MEM(pStmt); + strncpy(pStmt->dbName, pDbName->z, pDbName->n); + pStmt->pOptions = (SDatabaseOptions*)pOptions; + return (SNode*)pStmt; +} + SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); @@ -1022,9 +1033,47 @@ SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInt return (SNode*)pOptions; } +SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName) { + if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { + return NULL; + } + SDropIndexStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_INDEX_STMT); + CHECK_OUT_OF_MEM(pStmt); + strncpy(pStmt->indexName, pIndexName->z, pIndexName->n); + strncpy(pStmt->tableName, pTableName->z, pTableName->n); + return (SNode*)pStmt; +} + SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId) { SCreateQnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_QNODE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; return (SNode*)pStmt; } + +SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId) { + SDropQnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_QNODE_STMT); + CHECK_OUT_OF_MEM(pStmt); + pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; + return (SNode*)pStmt; +} + +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName) { + SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); + CHECK_OUT_OF_MEM(pStmt); + strncpy(pStmt->topicName, pTopicName->z, pTopicName->n); + pStmt->ignoreExists = ignoreExists; + pStmt->pQuery = pQuery; + if (NULL != pSubscribeDbName) { + strncpy(pStmt->subscribeDbName, pSubscribeDbName->z, pSubscribeDbName->n); + } + return (SNode*)pStmt; +} + +SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName) { + SDropTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_TOPIC_STMT); + CHECK_OUT_OF_MEM(pStmt); + strncpy(pStmt->topicName, pTopicName->z, pTopicName->n); + pStmt->ignoreNotExists = ignoreNotExists; + return (SNode*)pStmt; +} diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 4d50d92d9e..2d58d4e1e3 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -121,6 +121,7 @@ static SKeyword keywordTable[] = { {"TAGS", TK_TAGS}, {"TIMESTAMP", TK_TIMESTAMP}, {"TINYINT", TK_TINYINT}, + {"TOPIC", TK_TOPIC}, {"TTL", TK_TTL}, {"UNION", TK_UNION}, {"UNSIGNED", TK_UNSIGNED}, @@ -230,7 +231,6 @@ static SKeyword keywordTable[] = { // {"TBNAME", TK_TBNAME}, // {"VNODES", TK_VNODES}, // {"PARTITIONS", TK_PARTITIONS}, - // {"TOPIC", TK_TOPIC}, // {"TOPICS", TK_TOPICS}, // {"COMPACT", TK_COMPACT}, // {"MODIFY", TK_MODIFY}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 4f89e7e703..af7a38b702 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -21,14 +21,6 @@ #include "parUtil.h" #include "ttime.h" -static bool afterGroupBy(ESqlClause clause) { - return clause > SQL_CLAUSE_GROUP_BY; -} - -static bool beforeHaving(ESqlClause clause) { - return clause < SQL_CLAUSE_HAVING; -} - typedef struct STranslateContext { SParseContext* pParseCxt; int32_t errCode; @@ -41,6 +33,15 @@ typedef struct STranslateContext { } STranslateContext; static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode); +static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode); + +static bool afterGroupBy(ESqlClause clause) { + return clause > SQL_CLAUSE_GROUP_BY; +} + +static bool beforeHaving(ESqlClause clause) { + return clause < SQL_CLAUSE_HAVING; +} static EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t errCode, ...) { va_list vArgList; @@ -833,6 +834,41 @@ static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* return TSDB_CODE_SUCCESS; } +static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) { + SName name = {0}; + tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + tNameGetFullDbName(&name, pReq->db); + pReq->totalBlocks = pStmt->pOptions->numOfBlocks; + pReq->daysToKeep0 = pStmt->pOptions->keep; + pReq->daysToKeep1 = -1; + pReq->daysToKeep2 = -1; + pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; + pReq->walLevel = pStmt->pOptions->walLevel; + pReq->quorum = pStmt->pOptions->quorum; + pReq->cacheLastRow = pStmt->pOptions->cachelast; + return; +} + +static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt) { + SAlterDbReq alterReq = {0}; + buildAlterDbReq(pCxt, pStmt, &alterReq); + + pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_DB; + pCxt->pCmdMsg->msgLen = tSerializeSAlterDbReq(NULL, 0, &alterReq); + pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSAlterDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); + + return TSDB_CODE_SUCCESS; +} + static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); SNode* pNode; @@ -1201,6 +1237,27 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p } } +static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) { + SVDropTSmaReq dropSmaReq = {0}; + strcpy(dropSmaReq.indexName, pStmt->indexName); + + pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_VND_DROP_SMA; + pCxt->pCmdMsg->msgLen = tSerializeSVDropTSmaReq(NULL, &dropSmaReq); + pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + void* pBuf = pCxt->pCmdMsg->pMsg; + tSerializeSVDropTSmaReq(&pBuf, &dropSmaReq); + + return TSDB_CODE_SUCCESS; +} + static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* pStmt) { SMCreateQnodeReq createReq = { .dnodeId = pStmt->dnodeId }; @@ -1220,6 +1277,93 @@ static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* p return TSDB_CODE_SUCCESS; } +static int32_t translateDropQnode(STranslateContext* pCxt, SDropQnodeStmt* pStmt) { + SDDropQnodeReq dropReq = { .dnodeId = pStmt->dnodeId }; + + pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_DND_DROP_QNODE; + pCxt->pCmdMsg->msgLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq); + pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSMCreateDropQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); + + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* pStmt) { + SCMCreateTopicReq createReq = {0}; + + if (NULL != pStmt->pQuery) { + int32_t code = translateQuery(pCxt, pStmt->pQuery); + if (TSDB_CODE_SUCCESS == code) { + code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL); + } + if (TSDB_CODE_SUCCESS != code ) { + return code; + } + } else { + strcpy(createReq.subscribeDbName, pStmt->subscribeDbName); + } + + createReq.sql = strdup(pCxt->pParseCxt->pSql); + if (NULL == createReq.sql) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; + strcpy(name.dbname, pCxt->pParseCxt->db); + strcpy(name.tname, pStmt->topicName); + tNameExtractFullName(&name, createReq.name); + createReq.igExists = pStmt->ignoreExists; + + pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_TOPIC; + pCxt->pCmdMsg->msgLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); + pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSCMCreateTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + tFreeSCMCreateTopicReq(&createReq); + + return TSDB_CODE_SUCCESS; +} + +static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) { + SMDropTopicReq dropReq = {0}; + + SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; + strcpy(name.dbname, pCxt->pParseCxt->db); + strcpy(name.tname, pStmt->topicName); + tNameExtractFullName(&name, dropReq.name); + dropReq.igNotExists = pStmt->ignoreNotExists; + + pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_MND_DROP_TOPIC; + pCxt->pCmdMsg->msgLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq); + pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSMDropTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); + + return TSDB_CODE_SUCCESS; +} + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -1232,6 +1376,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_DROP_DATABASE_STMT: code = translateDropDatabase(pCxt, (SDropDatabaseStmt*)pNode); break; + case QUERY_NODE_ALTER_DATABASE_STMT: + code = translateAlterDatabase(pCxt, (SAlterDatabaseStmt*)pNode); + break; case QUERY_NODE_CREATE_TABLE_STMT: code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode); break; @@ -1274,9 +1421,21 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_CREATE_INDEX_STMT: code = translateCreateIndex(pCxt, (SCreateIndexStmt*)pNode); break; + case QUERY_NODE_DROP_INDEX_STMT: + code = translateDropIndex(pCxt, (SDropIndexStmt*)pNode); + break; case QUERY_NODE_CREATE_QNODE_STMT: code = translateCreateQnode(pCxt, (SCreateQnodeStmt*)pNode); break; + case QUERY_NODE_DROP_QNODE_STMT: + code = translateDropQnode(pCxt, (SDropQnodeStmt*)pNode); + break; + case QUERY_NODE_CREATE_TOPIC_STMT: + code = translateCreateTopic(pCxt, (SCreateTopicStmt*)pNode); + break; + case QUERY_NODE_DROP_TOPIC_STMT: + code = translateDropTopic(pCxt, (SDropTopicStmt*)pNode); + break; default: break; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 8b46d3600b..18b507c1b0 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -99,22 +99,22 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char -#define YYNOCODE 218 +#define YYNOCODE 220 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SToken yy5; - bool yy25; - SNodeList* yy40; - ENullOrder yy53; - EOrder yy54; - SNode* yy68; - EJoinType yy92; - EFillMode yy94; - SDataType yy372; - EOperatorType yy416; + SNodeList* yy24; + bool yy97; + SToken yy129; + SDataType yy224; + ENullOrder yy257; + EOperatorType yy260; + EFillMode yy294; + EJoinType yy332; + EOrder yy378; + SNode* yy432; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -129,17 +129,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 313 -#define YYNRULE 248 -#define YYNTOKEN 140 -#define YY_MAX_SHIFT 312 -#define YY_MIN_SHIFTREDUCE 480 -#define YY_MAX_SHIFTREDUCE 727 -#define YY_ERROR_ACTION 728 -#define YY_ACCEPT_ACTION 729 -#define YY_NO_ACTION 730 -#define YY_MIN_REDUCE 731 -#define YY_MAX_REDUCE 978 +#define YYNSTATE 333 +#define YYNRULE 255 +#define YYNTOKEN 141 +#define YY_MAX_SHIFT 332 +#define YY_MIN_SHIFTREDUCE 501 +#define YY_MAX_SHIFTREDUCE 755 +#define YY_ERROR_ACTION 756 +#define YY_ACCEPT_ACTION 757 +#define YY_NO_ACTION 758 +#define YY_MIN_REDUCE 759 +#define YY_MAX_REDUCE 1013 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -206,307 +206,322 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (963) +#define YY_ACTTAB_COUNT (1012) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 152, 236, 277, 871, 844, 252, 252, 167, 186, 784, - /* 10 */ 847, 844, 31, 29, 27, 26, 25, 846, 844, 209, - /* 20 */ 787, 787, 309, 308, 846, 31, 29, 27, 26, 25, - /* 30 */ 746, 236, 151, 871, 106, 826, 39, 824, 251, 844, - /* 40 */ 145, 957, 238, 61, 236, 856, 871, 782, 57, 857, - /* 50 */ 860, 896, 910, 145, 956, 154, 892, 969, 955, 187, - /* 60 */ 164, 610, 213, 832, 239, 166, 930, 10, 826, 907, - /* 70 */ 824, 251, 301, 300, 299, 298, 297, 296, 295, 294, - /* 80 */ 293, 292, 291, 290, 289, 288, 287, 286, 285, 599, - /* 90 */ 31, 29, 27, 26, 25, 24, 109, 23, 159, 228, - /* 100 */ 628, 629, 630, 631, 632, 633, 634, 636, 637, 638, - /* 110 */ 23, 159, 39, 628, 629, 630, 631, 632, 633, 634, - /* 120 */ 636, 637, 638, 783, 542, 275, 274, 273, 546, 272, - /* 130 */ 548, 549, 271, 551, 268, 165, 557, 265, 559, 560, - /* 140 */ 262, 259, 236, 54, 871, 694, 251, 789, 70, 252, - /* 150 */ 844, 65, 249, 238, 779, 224, 856, 208, 214, 56, - /* 160 */ 857, 860, 896, 229, 787, 601, 144, 892, 775, 205, - /* 170 */ 692, 693, 695, 696, 220, 10, 910, 82, 957, 31, - /* 180 */ 29, 27, 26, 25, 215, 210, 223, 170, 871, 64, - /* 190 */ 826, 81, 824, 906, 844, 955, 600, 238, 773, 826, - /* 200 */ 856, 825, 224, 57, 857, 860, 896, 187, 62, 910, - /* 210 */ 154, 892, 76, 723, 724, 27, 26, 25, 102, 903, - /* 220 */ 219, 220, 218, 284, 105, 957, 905, 729, 610, 82, - /* 230 */ 201, 923, 87, 223, 21, 871, 64, 284, 81, 227, - /* 240 */ 75, 844, 955, 635, 238, 104, 639, 856, 490, 86, - /* 250 */ 57, 857, 860, 896, 197, 62, 190, 154, 892, 76, - /* 260 */ 173, 68, 236, 278, 871, 78, 903, 904, 127, 908, - /* 270 */ 844, 817, 40, 238, 252, 84, 856, 250, 924, 57, - /* 280 */ 857, 860, 896, 957, 9, 8, 154, 892, 969, 787, - /* 290 */ 236, 48, 871, 178, 30, 28, 81, 953, 844, 206, - /* 300 */ 955, 238, 780, 590, 856, 833, 239, 57, 857, 860, - /* 310 */ 896, 588, 6, 161, 154, 892, 969, 30, 28, 670, - /* 320 */ 169, 99, 12, 790, 70, 914, 590, 31, 29, 27, - /* 330 */ 26, 25, 789, 70, 588, 774, 161, 189, 490, 236, - /* 340 */ 602, 871, 1, 677, 646, 12, 53, 844, 491, 492, - /* 350 */ 238, 50, 224, 856, 30, 28, 133, 857, 860, 252, - /* 360 */ 599, 253, 122, 590, 252, 1, 226, 172, 915, 665, - /* 370 */ 235, 588, 590, 161, 787, 957, 589, 591, 594, 787, - /* 380 */ 588, 171, 12, 926, 253, 281, 30, 28, 81, 280, - /* 390 */ 669, 665, 955, 789, 70, 590, 82, 9, 8, 589, - /* 400 */ 591, 594, 1, 588, 282, 161, 691, 96, 236, 195, - /* 410 */ 871, 130, 193, 59, 94, 196, 844, 134, 71, 238, - /* 420 */ 91, 253, 856, 279, 221, 58, 857, 860, 896, 625, - /* 430 */ 253, 83, 895, 892, 7, 872, 589, 591, 594, 108, - /* 440 */ 236, 2, 871, 597, 174, 589, 591, 594, 844, 772, - /* 450 */ 231, 238, 188, 253, 856, 38, 640, 58, 857, 860, - /* 460 */ 896, 726, 727, 32, 234, 892, 30, 28, 589, 591, - /* 470 */ 594, 85, 30, 28, 237, 590, 236, 603, 871, 607, - /* 480 */ 191, 590, 150, 588, 844, 161, 32, 238, 82, 588, - /* 490 */ 856, 161, 198, 72, 857, 860, 30, 28, 20, 281, - /* 500 */ 598, 668, 604, 280, 602, 590, 207, 82, 31, 29, - /* 510 */ 27, 26, 25, 588, 7, 161, 232, 199, 282, 927, - /* 520 */ 7, 851, 242, 92, 236, 937, 871, 583, 849, 594, - /* 530 */ 225, 970, 844, 253, 32, 238, 160, 279, 856, 253, - /* 540 */ 114, 138, 857, 860, 1, 204, 936, 112, 589, 591, - /* 550 */ 594, 244, 95, 119, 589, 591, 594, 236, 66, 871, - /* 560 */ 67, 5, 153, 253, 917, 844, 217, 98, 238, 203, - /* 570 */ 74, 856, 4, 63, 58, 857, 860, 896, 589, 591, - /* 580 */ 594, 665, 893, 236, 220, 871, 535, 100, 601, 530, - /* 590 */ 911, 844, 33, 68, 238, 202, 59, 856, 101, 64, - /* 600 */ 138, 857, 860, 236, 155, 871, 563, 972, 233, 567, - /* 610 */ 954, 844, 572, 257, 238, 107, 67, 856, 62, 68, - /* 620 */ 137, 857, 860, 17, 230, 236, 831, 871, 79, 903, - /* 630 */ 904, 878, 908, 844, 245, 47, 238, 49, 240, 856, - /* 640 */ 241, 69, 72, 857, 860, 236, 830, 871, 67, 163, - /* 650 */ 126, 216, 246, 844, 116, 788, 238, 158, 236, 856, - /* 660 */ 871, 255, 138, 857, 860, 247, 844, 128, 123, 238, - /* 670 */ 162, 312, 856, 125, 185, 138, 857, 860, 184, 597, - /* 680 */ 971, 60, 129, 183, 22, 182, 142, 305, 143, 838, - /* 690 */ 124, 236, 749, 871, 31, 29, 27, 26, 25, 844, - /* 700 */ 176, 177, 238, 837, 179, 856, 836, 835, 136, 857, - /* 710 */ 860, 181, 180, 55, 778, 236, 120, 871, 777, 748, - /* 720 */ 745, 740, 735, 844, 776, 501, 238, 747, 739, 856, - /* 730 */ 738, 734, 139, 857, 860, 236, 733, 871, 192, 732, - /* 740 */ 828, 175, 248, 844, 200, 41, 238, 194, 88, 856, - /* 750 */ 89, 90, 131, 857, 860, 236, 3, 871, 32, 14, - /* 760 */ 93, 36, 690, 844, 73, 97, 238, 211, 42, 856, - /* 770 */ 212, 684, 140, 857, 860, 236, 683, 871, 849, 15, - /* 780 */ 19, 34, 11, 844, 662, 43, 238, 44, 236, 856, - /* 790 */ 871, 712, 132, 857, 860, 661, 844, 711, 156, 238, - /* 800 */ 35, 716, 856, 717, 103, 141, 857, 860, 80, 715, - /* 810 */ 157, 16, 236, 8, 871, 110, 608, 13, 18, 113, - /* 820 */ 844, 111, 688, 238, 115, 236, 856, 871, 827, 868, - /* 830 */ 857, 860, 117, 844, 626, 45, 238, 243, 236, 856, - /* 840 */ 871, 118, 867, 857, 860, 46, 844, 50, 592, 238, - /* 850 */ 37, 848, 856, 121, 220, 866, 857, 860, 254, 256, - /* 860 */ 236, 564, 871, 168, 258, 260, 561, 261, 844, 64, - /* 870 */ 558, 238, 263, 236, 856, 871, 264, 148, 857, 860, - /* 880 */ 552, 844, 266, 267, 238, 550, 269, 856, 62, 270, - /* 890 */ 147, 857, 860, 236, 556, 871, 555, 222, 77, 903, - /* 900 */ 904, 844, 908, 554, 238, 541, 553, 856, 276, 51, - /* 910 */ 149, 857, 860, 236, 52, 871, 571, 570, 569, 499, - /* 920 */ 283, 844, 520, 519, 238, 518, 744, 856, 517, 516, - /* 930 */ 146, 857, 860, 236, 515, 871, 514, 513, 512, 511, - /* 940 */ 510, 844, 509, 508, 238, 303, 507, 856, 506, 505, - /* 950 */ 135, 857, 860, 504, 302, 304, 737, 306, 307, 736, - /* 960 */ 731, 310, 311, + /* 0 */ 163, 856, 240, 855, 272, 162, 272, 200, 856, 814, + /* 10 */ 854, 878, 31, 29, 27, 26, 25, 65, 880, 817, + /* 20 */ 178, 817, 256, 176, 906, 31, 29, 27, 26, 25, + /* 30 */ 779, 878, 40, 705, 55, 819, 71, 63, 880, 62, + /* 40 */ 155, 229, 66, 812, 243, 809, 906, 79, 938, 939, + /* 50 */ 626, 943, 878, 155, 175, 258, 511, 863, 259, 891, + /* 60 */ 511, 638, 58, 892, 895, 931, 512, 513, 208, 165, + /* 70 */ 927, 77, 321, 320, 319, 318, 317, 316, 315, 314, + /* 80 */ 313, 312, 311, 310, 309, 308, 307, 306, 305, 775, + /* 90 */ 959, 27, 26, 25, 31, 29, 27, 26, 25, 23, + /* 100 */ 170, 271, 656, 657, 658, 659, 660, 661, 662, 664, + /* 110 */ 665, 666, 23, 170, 271, 656, 657, 658, 659, 660, + /* 120 */ 661, 662, 664, 665, 666, 31, 29, 27, 26, 25, + /* 130 */ 10, 321, 320, 319, 318, 317, 316, 315, 314, 313, + /* 140 */ 312, 311, 310, 309, 308, 307, 306, 305, 565, 295, + /* 150 */ 294, 293, 569, 292, 571, 572, 291, 574, 288, 804, + /* 160 */ 580, 285, 582, 583, 282, 279, 24, 117, 256, 196, + /* 170 */ 906, 992, 626, 195, 624, 256, 177, 906, 194, 856, + /* 180 */ 193, 854, 83, 878, 991, 83, 258, 233, 990, 244, + /* 190 */ 891, 180, 271, 57, 892, 895, 931, 54, 182, 190, + /* 200 */ 154, 927, 51, 819, 71, 272, 192, 191, 269, 301, + /* 210 */ 819, 71, 992, 300, 805, 243, 624, 906, 751, 752, + /* 220 */ 817, 10, 234, 878, 298, 82, 258, 945, 302, 990, + /* 230 */ 891, 757, 627, 58, 892, 895, 931, 256, 186, 906, + /* 240 */ 165, 927, 77, 228, 942, 878, 201, 299, 258, 628, + /* 250 */ 30, 28, 891, 201, 113, 58, 892, 895, 931, 617, + /* 260 */ 221, 958, 165, 927, 1004, 184, 256, 615, 906, 172, + /* 270 */ 629, 235, 230, 965, 878, 304, 878, 258, 12, 272, + /* 280 */ 297, 891, 270, 881, 58, 892, 895, 931, 992, 9, + /* 290 */ 8, 165, 927, 1004, 817, 256, 272, 906, 1, 130, + /* 300 */ 83, 82, 988, 878, 181, 990, 258, 856, 40, 854, + /* 310 */ 891, 817, 112, 58, 892, 895, 931, 273, 21, 813, + /* 320 */ 165, 927, 1004, 30, 28, 698, 272, 663, 189, 183, + /* 330 */ 667, 949, 617, 99, 616, 618, 621, 114, 30, 28, + /* 340 */ 615, 817, 172, 329, 328, 803, 247, 617, 256, 674, + /* 350 */ 906, 12, 722, 83, 140, 615, 878, 172, 161, 258, + /* 360 */ 141, 72, 244, 891, 30, 28, 144, 892, 895, 49, + /* 370 */ 945, 1, 945, 617, 84, 225, 720, 721, 723, 724, + /* 380 */ 810, 615, 226, 172, 304, 992, 7, 941, 6, 940, + /* 390 */ 273, 697, 12, 864, 259, 256, 248, 906, 82, 820, + /* 400 */ 71, 136, 990, 878, 847, 273, 258, 616, 618, 621, + /* 410 */ 891, 240, 1, 59, 892, 895, 931, 256, 107, 906, + /* 420 */ 930, 927, 616, 618, 621, 878, 65, 217, 258, 950, + /* 430 */ 693, 273, 891, 251, 69, 59, 892, 895, 931, 207, + /* 440 */ 244, 83, 254, 927, 213, 961, 63, 211, 616, 618, + /* 450 */ 621, 83, 94, 30, 28, 257, 110, 938, 239, 241, + /* 460 */ 238, 249, 617, 992, 719, 617, 30, 28, 693, 93, + /* 470 */ 615, 60, 172, 615, 246, 617, 82, 104, 907, 256, + /* 480 */ 990, 906, 668, 615, 102, 172, 116, 878, 255, 32, + /* 490 */ 258, 2, 754, 755, 891, 635, 624, 73, 892, 895, + /* 500 */ 252, 7, 32, 696, 607, 9, 8, 30, 28, 185, + /* 510 */ 256, 32, 906, 632, 7, 885, 617, 625, 878, 85, + /* 520 */ 273, 258, 883, 273, 615, 891, 172, 631, 59, 892, + /* 530 */ 895, 931, 214, 273, 245, 1005, 928, 616, 618, 621, + /* 540 */ 616, 618, 621, 197, 198, 256, 199, 906, 39, 653, + /* 550 */ 616, 618, 621, 878, 202, 1, 258, 171, 90, 122, + /* 560 */ 891, 215, 209, 148, 892, 895, 120, 256, 630, 906, + /* 570 */ 264, 134, 160, 127, 273, 878, 558, 67, 258, 222, + /* 580 */ 68, 216, 891, 69, 992, 148, 892, 895, 256, 218, + /* 590 */ 906, 616, 618, 621, 629, 553, 878, 82, 95, 258, + /* 600 */ 962, 990, 60, 891, 586, 133, 147, 892, 895, 590, + /* 610 */ 256, 277, 906, 61, 802, 227, 68, 219, 878, 325, + /* 620 */ 972, 258, 132, 262, 256, 891, 906, 100, 73, 892, + /* 630 */ 895, 621, 878, 224, 971, 258, 169, 236, 256, 891, + /* 640 */ 906, 103, 148, 892, 895, 56, 878, 164, 128, 258, + /* 650 */ 173, 5, 256, 891, 906, 952, 148, 892, 895, 237, + /* 660 */ 878, 75, 106, 258, 301, 223, 1006, 891, 300, 108, + /* 670 */ 146, 892, 895, 240, 268, 4, 220, 64, 256, 96, + /* 680 */ 906, 693, 628, 302, 595, 946, 878, 33, 65, 258, + /* 690 */ 253, 69, 256, 891, 906, 109, 149, 892, 895, 70, + /* 700 */ 878, 989, 299, 258, 1007, 250, 68, 891, 63, 166, + /* 710 */ 142, 892, 895, 256, 17, 906, 115, 242, 78, 938, + /* 720 */ 939, 878, 943, 913, 258, 862, 260, 256, 891, 906, + /* 730 */ 261, 150, 892, 895, 861, 878, 265, 174, 258, 266, + /* 740 */ 124, 256, 891, 906, 267, 143, 892, 895, 48, 878, + /* 750 */ 135, 818, 258, 50, 275, 256, 891, 906, 137, 151, + /* 760 */ 892, 895, 131, 878, 872, 138, 258, 332, 152, 256, + /* 770 */ 891, 906, 153, 903, 892, 895, 139, 878, 778, 871, + /* 780 */ 258, 870, 187, 256, 891, 906, 188, 902, 892, 895, + /* 790 */ 869, 878, 808, 807, 258, 777, 774, 256, 891, 906, + /* 800 */ 768, 901, 892, 895, 763, 878, 868, 859, 258, 87, + /* 810 */ 806, 256, 891, 906, 524, 158, 892, 895, 776, 878, + /* 820 */ 773, 205, 258, 203, 204, 256, 891, 906, 767, 157, + /* 830 */ 892, 895, 766, 878, 762, 761, 258, 210, 760, 867, + /* 840 */ 891, 866, 212, 159, 892, 895, 36, 858, 256, 42, + /* 850 */ 906, 97, 98, 3, 240, 14, 878, 15, 74, 258, + /* 860 */ 101, 105, 256, 891, 906, 43, 156, 892, 895, 65, + /* 870 */ 878, 32, 231, 258, 718, 712, 92, 891, 34, 37, + /* 880 */ 145, 892, 895, 711, 76, 44, 11, 232, 690, 63, + /* 890 */ 206, 883, 689, 91, 19, 45, 20, 111, 745, 80, + /* 900 */ 938, 939, 740, 943, 35, 739, 31, 29, 27, 26, + /* 910 */ 25, 22, 81, 167, 16, 744, 41, 743, 168, 89, + /* 920 */ 8, 31, 29, 27, 26, 25, 118, 636, 13, 31, + /* 930 */ 29, 27, 26, 25, 654, 18, 263, 857, 119, 716, + /* 940 */ 121, 123, 46, 126, 125, 47, 88, 619, 51, 276, + /* 950 */ 86, 179, 38, 280, 882, 579, 587, 129, 278, 274, + /* 960 */ 584, 281, 283, 581, 284, 286, 575, 287, 289, 573, + /* 970 */ 564, 290, 52, 53, 594, 296, 593, 578, 638, 592, + /* 980 */ 303, 577, 522, 543, 576, 542, 541, 536, 540, 539, + /* 990 */ 538, 537, 535, 534, 533, 772, 532, 531, 530, 529, + /* 1000 */ 528, 527, 322, 323, 765, 764, 326, 327, 324, 759, + /* 1010 */ 330, 331, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 157, 160, 163, 162, 168, 145, 145, 157, 148, 148, - /* 10 */ 174, 168, 12, 13, 14, 15, 16, 174, 168, 178, - /* 20 */ 160, 160, 142, 143, 174, 12, 13, 14, 15, 16, - /* 30 */ 0, 160, 159, 162, 216, 162, 147, 164, 31, 168, - /* 40 */ 40, 196, 171, 154, 160, 174, 162, 158, 177, 178, - /* 50 */ 179, 180, 175, 40, 209, 184, 185, 186, 213, 39, - /* 60 */ 167, 61, 178, 170, 171, 159, 195, 60, 162, 192, - /* 70 */ 164, 31, 42, 43, 44, 45, 46, 47, 48, 49, - /* 80 */ 50, 51, 52, 53, 54, 55, 56, 57, 58, 31, - /* 90 */ 12, 13, 14, 15, 16, 181, 182, 97, 98, 68, - /* 100 */ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - /* 110 */ 97, 98, 147, 100, 101, 102, 103, 104, 105, 106, - /* 120 */ 107, 108, 109, 158, 70, 71, 72, 73, 74, 75, - /* 130 */ 76, 77, 78, 79, 80, 149, 82, 83, 84, 85, - /* 140 */ 86, 87, 160, 144, 162, 99, 31, 161, 162, 145, - /* 150 */ 168, 152, 148, 171, 155, 173, 174, 92, 31, 177, - /* 160 */ 178, 179, 180, 132, 160, 31, 184, 185, 0, 123, - /* 170 */ 124, 125, 126, 127, 145, 60, 175, 114, 196, 12, - /* 180 */ 13, 14, 15, 16, 119, 120, 160, 159, 162, 160, - /* 190 */ 162, 209, 164, 192, 168, 213, 31, 171, 0, 162, - /* 200 */ 174, 164, 173, 177, 178, 179, 180, 39, 179, 175, - /* 210 */ 184, 185, 186, 135, 136, 14, 15, 16, 189, 190, - /* 220 */ 191, 145, 193, 39, 198, 196, 192, 140, 61, 114, - /* 230 */ 204, 205, 19, 160, 97, 162, 160, 39, 209, 3, - /* 240 */ 27, 168, 213, 106, 171, 111, 109, 174, 21, 36, - /* 250 */ 177, 178, 179, 180, 61, 179, 29, 184, 185, 186, - /* 260 */ 173, 68, 160, 66, 162, 189, 190, 191, 150, 193, - /* 270 */ 168, 153, 59, 171, 145, 62, 174, 148, 205, 177, - /* 280 */ 178, 179, 180, 196, 1, 2, 184, 185, 186, 160, - /* 290 */ 160, 144, 162, 145, 12, 13, 209, 195, 168, 207, - /* 300 */ 213, 171, 155, 21, 174, 170, 171, 177, 178, 179, - /* 310 */ 180, 29, 34, 31, 184, 185, 186, 12, 13, 14, - /* 320 */ 149, 201, 40, 161, 162, 195, 21, 12, 13, 14, - /* 330 */ 15, 16, 161, 162, 29, 0, 31, 142, 21, 160, - /* 340 */ 31, 162, 60, 14, 61, 40, 60, 168, 31, 32, - /* 350 */ 171, 65, 173, 174, 12, 13, 177, 178, 179, 145, - /* 360 */ 31, 79, 148, 21, 145, 60, 130, 148, 112, 113, - /* 370 */ 40, 29, 21, 31, 160, 196, 94, 95, 96, 160, - /* 380 */ 29, 149, 40, 176, 79, 50, 12, 13, 209, 54, - /* 390 */ 4, 113, 213, 161, 162, 21, 114, 1, 2, 94, - /* 400 */ 95, 96, 60, 29, 69, 31, 61, 61, 160, 20, - /* 410 */ 162, 18, 23, 68, 68, 22, 168, 24, 25, 171, - /* 420 */ 111, 79, 174, 88, 194, 177, 178, 179, 180, 99, - /* 430 */ 79, 38, 184, 185, 60, 162, 94, 95, 96, 210, - /* 440 */ 160, 197, 162, 31, 145, 94, 95, 96, 168, 0, - /* 450 */ 68, 171, 145, 79, 174, 147, 61, 177, 178, 179, - /* 460 */ 180, 138, 139, 68, 184, 185, 12, 13, 94, 95, - /* 470 */ 96, 147, 12, 13, 14, 21, 160, 31, 162, 61, - /* 480 */ 141, 21, 141, 29, 168, 31, 68, 171, 114, 29, - /* 490 */ 174, 31, 160, 177, 178, 179, 12, 13, 2, 50, - /* 500 */ 31, 115, 31, 54, 31, 21, 122, 114, 12, 13, - /* 510 */ 14, 15, 16, 29, 60, 31, 134, 165, 69, 176, - /* 520 */ 60, 60, 121, 169, 160, 206, 162, 61, 67, 96, - /* 530 */ 214, 215, 168, 79, 68, 171, 172, 88, 174, 79, - /* 540 */ 61, 177, 178, 179, 60, 168, 206, 68, 94, 95, - /* 550 */ 96, 61, 169, 61, 94, 95, 96, 160, 68, 162, - /* 560 */ 68, 129, 168, 79, 203, 168, 128, 202, 171, 117, - /* 570 */ 200, 174, 116, 160, 177, 178, 179, 180, 94, 95, - /* 580 */ 96, 113, 185, 160, 145, 162, 61, 199, 31, 61, - /* 590 */ 175, 168, 110, 68, 171, 172, 68, 174, 187, 160, - /* 600 */ 177, 178, 179, 160, 137, 162, 61, 217, 133, 61, - /* 610 */ 212, 168, 61, 68, 171, 211, 68, 174, 179, 68, - /* 620 */ 177, 178, 179, 60, 131, 160, 169, 162, 189, 190, - /* 630 */ 191, 183, 193, 168, 91, 144, 171, 60, 168, 174, - /* 640 */ 168, 61, 177, 178, 179, 160, 169, 162, 68, 168, - /* 650 */ 153, 208, 166, 168, 160, 160, 171, 172, 160, 174, - /* 660 */ 162, 156, 177, 178, 179, 165, 168, 145, 144, 171, - /* 670 */ 172, 141, 174, 19, 26, 177, 178, 179, 30, 31, - /* 680 */ 215, 27, 146, 35, 2, 37, 151, 33, 151, 0, - /* 690 */ 36, 160, 0, 162, 12, 13, 14, 15, 16, 168, - /* 700 */ 56, 67, 171, 0, 56, 174, 0, 0, 177, 178, - /* 710 */ 179, 63, 64, 59, 0, 160, 62, 162, 0, 0, - /* 720 */ 0, 0, 0, 168, 0, 41, 171, 0, 0, 174, - /* 730 */ 0, 0, 177, 178, 179, 160, 0, 162, 21, 0, - /* 740 */ 0, 93, 88, 168, 90, 60, 171, 21, 19, 174, - /* 750 */ 34, 89, 177, 178, 179, 160, 68, 162, 68, 118, - /* 760 */ 61, 68, 61, 168, 60, 60, 171, 29, 60, 174, - /* 770 */ 68, 61, 177, 178, 179, 160, 61, 162, 67, 118, - /* 780 */ 68, 112, 118, 168, 61, 60, 171, 4, 160, 174, - /* 790 */ 162, 29, 177, 178, 179, 61, 168, 29, 29, 171, - /* 800 */ 68, 29, 174, 61, 67, 177, 178, 179, 67, 29, - /* 810 */ 29, 68, 160, 2, 162, 67, 61, 60, 60, 60, - /* 820 */ 168, 61, 61, 171, 60, 160, 174, 162, 0, 177, - /* 830 */ 178, 179, 34, 168, 99, 60, 171, 92, 160, 174, - /* 840 */ 162, 89, 177, 178, 179, 60, 168, 65, 21, 171, - /* 850 */ 60, 67, 174, 67, 145, 177, 178, 179, 66, 29, - /* 860 */ 160, 61, 162, 29, 60, 29, 61, 60, 168, 160, - /* 870 */ 61, 171, 29, 160, 174, 162, 60, 177, 178, 179, - /* 880 */ 61, 168, 29, 60, 171, 61, 29, 174, 179, 60, - /* 890 */ 177, 178, 179, 160, 81, 162, 81, 188, 189, 190, - /* 900 */ 191, 168, 193, 81, 171, 21, 81, 174, 69, 60, - /* 910 */ 177, 178, 179, 160, 60, 162, 29, 29, 21, 41, - /* 920 */ 40, 168, 29, 29, 171, 29, 0, 174, 29, 29, - /* 930 */ 177, 178, 179, 160, 29, 162, 29, 21, 29, 29, - /* 940 */ 29, 168, 29, 29, 171, 27, 29, 174, 29, 29, - /* 950 */ 177, 178, 179, 29, 29, 34, 0, 29, 28, 0, - /* 960 */ 0, 21, 20, 218, 218, 218, 218, 218, 218, 218, - /* 970 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 980 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 990 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1000 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1010 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1020 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1030 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1040 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1050 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1060 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1070 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1080 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1090 */ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, - /* 1100 */ 218, 218, 218, + /* 0 */ 158, 163, 146, 165, 146, 160, 146, 149, 163, 149, + /* 10 */ 165, 169, 12, 13, 14, 15, 16, 161, 176, 161, + /* 20 */ 158, 161, 161, 150, 163, 12, 13, 14, 15, 16, + /* 30 */ 0, 169, 148, 14, 145, 162, 163, 181, 176, 155, + /* 40 */ 40, 180, 153, 159, 161, 156, 163, 191, 192, 193, + /* 50 */ 31, 195, 169, 40, 168, 172, 21, 171, 172, 176, + /* 60 */ 21, 61, 179, 180, 181, 182, 31, 32, 29, 186, + /* 70 */ 187, 188, 42, 43, 44, 45, 46, 47, 48, 49, + /* 80 */ 50, 51, 52, 53, 54, 55, 56, 57, 58, 0, + /* 90 */ 207, 14, 15, 16, 12, 13, 14, 15, 16, 99, + /* 100 */ 100, 31, 102, 103, 104, 105, 106, 107, 108, 109, + /* 110 */ 110, 111, 99, 100, 31, 102, 103, 104, 105, 106, + /* 120 */ 107, 108, 109, 110, 111, 12, 13, 14, 15, 16, + /* 130 */ 60, 42, 43, 44, 45, 46, 47, 48, 49, 50, + /* 140 */ 51, 52, 53, 54, 55, 56, 57, 58, 70, 71, + /* 150 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 0, + /* 160 */ 82, 83, 84, 85, 86, 87, 183, 184, 161, 26, + /* 170 */ 163, 198, 31, 30, 31, 161, 160, 163, 35, 163, + /* 180 */ 37, 165, 115, 169, 211, 115, 172, 180, 215, 175, + /* 190 */ 176, 150, 31, 179, 180, 181, 182, 60, 150, 56, + /* 200 */ 186, 187, 65, 162, 163, 146, 63, 64, 149, 50, + /* 210 */ 162, 163, 198, 54, 0, 161, 31, 163, 136, 137, + /* 220 */ 161, 60, 31, 169, 66, 211, 172, 177, 69, 215, + /* 230 */ 176, 141, 31, 179, 180, 181, 182, 161, 95, 163, + /* 240 */ 186, 187, 188, 92, 194, 169, 39, 88, 172, 31, + /* 250 */ 12, 13, 176, 39, 200, 179, 180, 181, 182, 21, + /* 260 */ 206, 207, 186, 187, 188, 175, 161, 29, 163, 31, + /* 270 */ 31, 120, 121, 197, 169, 39, 169, 172, 40, 146, + /* 280 */ 164, 176, 149, 176, 179, 180, 181, 182, 198, 1, + /* 290 */ 2, 186, 187, 188, 161, 161, 146, 163, 60, 149, + /* 300 */ 115, 211, 197, 169, 160, 215, 172, 163, 148, 165, + /* 310 */ 176, 161, 94, 179, 180, 181, 182, 79, 99, 159, + /* 320 */ 186, 187, 188, 12, 13, 14, 146, 108, 146, 149, + /* 330 */ 111, 197, 21, 94, 96, 97, 98, 218, 12, 13, + /* 340 */ 29, 161, 31, 143, 144, 0, 3, 21, 161, 61, + /* 350 */ 163, 40, 101, 115, 18, 29, 169, 31, 22, 172, + /* 360 */ 24, 25, 175, 176, 12, 13, 179, 180, 181, 145, + /* 370 */ 177, 60, 177, 21, 38, 124, 125, 126, 127, 128, + /* 380 */ 156, 29, 209, 31, 39, 198, 60, 194, 34, 194, + /* 390 */ 79, 4, 40, 171, 172, 161, 68, 163, 211, 162, + /* 400 */ 163, 151, 215, 169, 154, 79, 172, 96, 97, 98, + /* 410 */ 176, 146, 60, 179, 180, 181, 182, 161, 203, 163, + /* 420 */ 186, 187, 96, 97, 98, 169, 161, 61, 172, 113, + /* 430 */ 114, 79, 176, 68, 68, 179, 180, 181, 182, 143, + /* 440 */ 175, 115, 186, 187, 20, 178, 181, 23, 96, 97, + /* 450 */ 98, 115, 19, 12, 13, 14, 191, 192, 193, 196, + /* 460 */ 195, 133, 21, 198, 61, 21, 12, 13, 114, 36, + /* 470 */ 29, 68, 31, 29, 131, 21, 211, 61, 163, 161, + /* 480 */ 215, 163, 61, 29, 68, 31, 212, 169, 40, 68, + /* 490 */ 172, 199, 139, 140, 176, 61, 31, 179, 180, 181, + /* 500 */ 135, 60, 68, 116, 61, 1, 2, 12, 13, 146, + /* 510 */ 161, 68, 163, 31, 60, 60, 21, 31, 169, 148, + /* 520 */ 79, 172, 67, 79, 29, 176, 31, 31, 179, 180, + /* 530 */ 181, 182, 146, 79, 216, 217, 187, 96, 97, 98, + /* 540 */ 96, 97, 98, 174, 161, 161, 166, 163, 148, 101, + /* 550 */ 96, 97, 98, 169, 146, 60, 172, 173, 148, 61, + /* 560 */ 176, 175, 142, 179, 180, 181, 68, 161, 31, 163, + /* 570 */ 61, 146, 142, 61, 79, 169, 61, 68, 172, 173, + /* 580 */ 68, 174, 176, 68, 198, 179, 180, 181, 161, 161, + /* 590 */ 163, 96, 97, 98, 31, 61, 169, 211, 145, 172, + /* 600 */ 178, 215, 68, 176, 61, 19, 179, 180, 181, 61, + /* 610 */ 161, 68, 163, 27, 0, 123, 68, 166, 169, 33, + /* 620 */ 208, 172, 36, 122, 161, 176, 163, 170, 179, 180, + /* 630 */ 181, 98, 169, 169, 208, 172, 173, 210, 161, 176, + /* 640 */ 163, 170, 179, 180, 181, 59, 169, 169, 62, 172, + /* 650 */ 173, 130, 161, 176, 163, 205, 179, 180, 181, 129, + /* 660 */ 169, 202, 204, 172, 50, 118, 217, 176, 54, 201, + /* 670 */ 179, 180, 181, 146, 88, 117, 90, 161, 161, 93, + /* 680 */ 163, 114, 31, 69, 61, 177, 169, 112, 161, 172, + /* 690 */ 134, 68, 161, 176, 163, 189, 179, 180, 181, 61, + /* 700 */ 169, 214, 88, 172, 219, 132, 68, 176, 181, 138, + /* 710 */ 179, 180, 181, 161, 60, 163, 213, 190, 191, 192, + /* 720 */ 193, 169, 195, 185, 172, 170, 169, 161, 176, 163, + /* 730 */ 169, 179, 180, 181, 170, 169, 91, 169, 172, 167, + /* 740 */ 161, 161, 176, 163, 166, 179, 180, 181, 145, 169, + /* 750 */ 154, 161, 172, 60, 157, 161, 176, 163, 146, 179, + /* 760 */ 180, 181, 145, 169, 0, 147, 172, 142, 152, 161, + /* 770 */ 176, 163, 152, 179, 180, 181, 147, 169, 0, 0, + /* 780 */ 172, 0, 56, 161, 176, 163, 67, 179, 180, 181, + /* 790 */ 0, 169, 0, 0, 172, 0, 0, 161, 176, 163, + /* 800 */ 0, 179, 180, 181, 0, 169, 0, 0, 172, 34, + /* 810 */ 0, 161, 176, 163, 41, 179, 180, 181, 0, 169, + /* 820 */ 0, 34, 172, 29, 27, 161, 176, 163, 0, 179, + /* 830 */ 180, 181, 0, 169, 0, 0, 172, 21, 0, 0, + /* 840 */ 176, 0, 21, 179, 180, 181, 94, 0, 161, 60, + /* 850 */ 163, 34, 89, 68, 146, 119, 169, 119, 60, 172, + /* 860 */ 61, 60, 161, 176, 163, 60, 179, 180, 181, 161, + /* 870 */ 169, 68, 29, 172, 61, 61, 19, 176, 113, 68, + /* 880 */ 179, 180, 181, 61, 27, 60, 119, 68, 61, 181, + /* 890 */ 33, 67, 61, 36, 68, 4, 2, 67, 61, 191, + /* 900 */ 192, 193, 29, 195, 68, 29, 12, 13, 14, 15, + /* 910 */ 16, 2, 67, 29, 68, 29, 59, 29, 29, 62, + /* 920 */ 2, 12, 13, 14, 15, 16, 67, 61, 60, 12, + /* 930 */ 13, 14, 15, 16, 101, 60, 92, 0, 61, 61, + /* 940 */ 60, 60, 60, 89, 34, 60, 89, 21, 65, 29, + /* 950 */ 93, 29, 60, 29, 67, 81, 61, 67, 60, 66, + /* 960 */ 61, 60, 29, 61, 60, 29, 61, 60, 29, 61, + /* 970 */ 21, 60, 60, 60, 29, 69, 29, 81, 61, 21, + /* 980 */ 40, 81, 41, 29, 81, 29, 29, 21, 29, 29, + /* 990 */ 29, 29, 29, 29, 29, 0, 29, 29, 29, 29, + /* 1000 */ 29, 29, 29, 27, 0, 0, 29, 28, 34, 0, + /* 1010 */ 21, 20, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1020 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1030 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1040 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1050 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1060 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1070 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1080 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1090 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1100 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1110 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1120 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1130 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1140 */ 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + /* 1150 */ 220, 220, 220, }; -#define YY_SHIFT_COUNT (312) +#define YY_SHIFT_COUNT (332) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (960) +#define YY_SHIFT_MAX (1009) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 393, 282, 305, 342, 342, 342, 342, 374, 342, 342, - /* 10 */ 115, 454, 484, 460, 454, 454, 454, 454, 454, 454, + /* 0 */ 336, 238, 311, 352, 352, 352, 352, 326, 352, 352, + /* 10 */ 70, 454, 495, 441, 454, 454, 454, 454, 454, 454, /* 20 */ 454, 454, 454, 454, 454, 454, 454, 454, 454, 454, - /* 30 */ 454, 454, 454, 7, 7, 7, 351, 351, 40, 40, - /* 40 */ 20, 58, 127, 127, 63, 165, 58, 40, 40, 58, - /* 50 */ 40, 58, 58, 58, 40, 184, 0, 13, 13, 351, - /* 60 */ 317, 168, 134, 134, 134, 198, 165, 58, 58, 197, - /* 70 */ 54, 648, 78, 46, 65, 227, 309, 256, 278, 256, - /* 80 */ 329, 236, 386, 412, 20, 412, 20, 446, 446, 469, - /* 90 */ 471, 473, 384, 401, 433, 384, 401, 433, 432, 438, - /* 100 */ 452, 456, 468, 469, 557, 482, 467, 475, 493, 563, - /* 110 */ 58, 401, 433, 433, 401, 433, 543, 469, 471, 197, - /* 120 */ 184, 469, 577, 412, 184, 446, 963, 963, 963, 30, - /* 130 */ 654, 496, 682, 167, 213, 315, 315, 315, 315, 315, - /* 140 */ 315, 315, 335, 449, 283, 137, 201, 201, 201, 201, - /* 150 */ 389, 193, 345, 346, 396, 323, 31, 382, 395, 330, - /* 160 */ 418, 461, 466, 479, 490, 492, 525, 528, 545, 548, - /* 170 */ 551, 580, 286, 689, 692, 703, 706, 644, 634, 707, - /* 180 */ 714, 718, 719, 720, 721, 722, 724, 684, 727, 728, - /* 190 */ 730, 731, 736, 717, 739, 726, 729, 740, 685, 716, - /* 200 */ 662, 688, 690, 641, 699, 693, 701, 704, 705, 710, - /* 210 */ 708, 715, 738, 702, 711, 725, 712, 661, 723, 734, - /* 220 */ 737, 669, 732, 741, 742, 743, 664, 783, 762, 768, - /* 230 */ 769, 772, 780, 781, 811, 735, 748, 755, 757, 758, - /* 240 */ 760, 761, 759, 764, 745, 775, 828, 798, 752, 785, - /* 250 */ 782, 784, 786, 827, 790, 792, 800, 830, 834, 804, - /* 260 */ 805, 836, 807, 809, 843, 816, 819, 853, 823, 824, - /* 270 */ 857, 829, 813, 815, 822, 825, 884, 839, 849, 854, - /* 280 */ 887, 888, 897, 878, 880, 893, 894, 896, 899, 900, - /* 290 */ 905, 907, 916, 909, 910, 911, 913, 914, 917, 919, - /* 300 */ 920, 924, 926, 925, 918, 921, 956, 928, 930, 959, - /* 310 */ 960, 940, 942, + /* 30 */ 454, 454, 454, 161, 161, 161, 185, 444, 444, 83, + /* 40 */ 83, 207, 141, 191, 191, 67, 201, 141, 83, 83, + /* 50 */ 141, 83, 141, 141, 141, 83, 236, 0, 13, 13, + /* 60 */ 444, 35, 214, 218, 218, 218, 345, 201, 141, 141, + /* 70 */ 158, 78, 143, 82, 251, 151, 39, 239, 316, 354, + /* 80 */ 316, 19, 343, 387, 465, 482, 207, 486, 496, 207, + /* 90 */ 465, 207, 537, 465, 537, 482, 236, 486, 496, 563, + /* 100 */ 492, 501, 533, 492, 501, 533, 521, 530, 547, 558, + /* 110 */ 567, 486, 651, 575, 571, 556, 573, 654, 141, 501, + /* 120 */ 533, 533, 501, 533, 645, 486, 496, 158, 236, 486, + /* 130 */ 693, 465, 236, 537, 1012, 1012, 1012, 1012, 30, 89, + /* 140 */ 586, 857, 894, 909, 917, 113, 113, 113, 113, 113, + /* 150 */ 113, 113, 159, 614, 288, 219, 77, 77, 77, 77, + /* 160 */ 424, 433, 366, 403, 416, 504, 353, 328, 365, 421, + /* 170 */ 448, 434, 455, 443, 498, 509, 512, 515, 534, 543, + /* 180 */ 548, 623, 638, 137, 764, 778, 779, 781, 726, 719, + /* 190 */ 790, 792, 793, 795, 796, 800, 804, 806, 807, 775, + /* 200 */ 810, 773, 818, 820, 794, 797, 787, 828, 832, 834, + /* 210 */ 835, 816, 838, 821, 839, 841, 752, 847, 789, 817, + /* 220 */ 763, 785, 803, 736, 799, 811, 813, 798, 801, 814, + /* 230 */ 805, 822, 843, 819, 824, 825, 826, 738, 827, 831, + /* 240 */ 830, 765, 836, 845, 837, 846, 767, 891, 873, 876, + /* 250 */ 884, 886, 888, 889, 918, 833, 859, 866, 868, 875, + /* 260 */ 877, 878, 880, 881, 844, 882, 937, 910, 854, 885, + /* 270 */ 883, 887, 890, 926, 892, 893, 895, 920, 922, 898, + /* 280 */ 899, 924, 901, 902, 933, 904, 905, 936, 907, 908, + /* 290 */ 939, 911, 874, 896, 900, 903, 949, 906, 912, 913, + /* 300 */ 945, 947, 958, 941, 940, 954, 956, 957, 959, 960, + /* 310 */ 961, 962, 966, 963, 964, 965, 967, 968, 969, 970, + /* 320 */ 971, 972, 995, 973, 976, 974, 1004, 977, 979, 1005, + /* 330 */ 1009, 989, 991, }; -#define YY_REDUCE_COUNT (128) -#define YY_REDUCE_MIN (-182) -#define YY_REDUCE_MAX (773) +#define YY_REDUCE_COUNT (137) +#define YY_REDUCE_MIN (-162) +#define YY_REDUCE_MAX (708) static const short yy_reduce_ofst[] = { - /* 0 */ 87, -18, 26, 73, -129, 102, 130, 179, 248, 280, - /* 10 */ 29, 316, 397, 364, 423, 443, 465, 485, 498, 531, - /* 20 */ 555, 575, 595, 615, 628, 652, 665, 678, 700, 713, - /* 30 */ 733, 753, 773, 709, 76, 439, -157, -150, -140, -139, - /* 40 */ -111, -127, -159, -116, -155, -107, -14, 4, 129, -94, - /* 50 */ 214, 171, 28, 232, 219, -1, -86, -86, -86, -164, - /* 60 */ -120, -35, -123, 1, 34, 147, 135, 162, 37, 118, - /* 70 */ -161, 148, -182, 92, 120, 195, 207, 230, 230, 230, - /* 80 */ 273, 229, 244, 299, 308, 307, 324, 339, 341, 332, - /* 90 */ 352, 343, 319, 354, 377, 340, 383, 394, 361, 365, - /* 100 */ 370, 388, 230, 413, 415, 411, 390, 398, 404, 448, - /* 110 */ 273, 457, 470, 472, 477, 481, 486, 494, 500, 497, - /* 120 */ 491, 495, 505, 522, 524, 530, 535, 537, 536, + /* 0 */ 90, 14, 54, -117, 76, 105, 134, 187, 234, 256, + /* 10 */ 265, 318, 349, 384, 406, 427, 449, 463, 477, 491, + /* 20 */ 517, 531, 552, 566, 580, 594, 608, 622, 636, 650, + /* 30 */ 664, 687, 701, 527, -144, 708, 386, -158, -138, -142, + /* 40 */ -140, -116, -155, -139, 7, -27, -114, -127, 59, 133, + /* 50 */ 16, 150, 41, 144, 48, 180, -111, -17, -17, -17, + /* 60 */ 107, 200, 160, 50, 193, 195, 224, 222, 237, -162, + /* 70 */ 250, 116, 182, 119, 173, 215, 296, 267, 263, 263, + /* 80 */ 263, 315, 274, 292, 363, 369, 371, 383, 380, 400, + /* 90 */ 408, 410, 420, 425, 430, 407, 453, 428, 451, 422, + /* 100 */ 412, 457, 464, 426, 471, 478, 450, 458, 459, 468, + /* 110 */ 263, 516, 508, 506, 485, 487, 503, 538, 315, 555, + /* 120 */ 557, 561, 564, 568, 572, 579, 578, 596, 603, 590, + /* 130 */ 597, 612, 617, 625, 618, 616, 620, 629, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 10 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 20 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 30 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 40 */ 753, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 50 */ 728, 728, 728, 728, 728, 751, 728, 898, 728, 728, - /* 60 */ 728, 753, 909, 909, 909, 751, 728, 728, 728, 816, - /* 70 */ 728, 728, 973, 728, 933, 728, 925, 901, 915, 902, - /* 80 */ 728, 958, 918, 728, 753, 728, 753, 728, 728, 728, - /* 90 */ 728, 728, 940, 938, 728, 940, 938, 728, 952, 948, - /* 100 */ 931, 929, 915, 728, 728, 728, 976, 964, 960, 728, - /* 110 */ 728, 938, 728, 728, 938, 728, 829, 728, 728, 728, - /* 120 */ 751, 728, 785, 728, 751, 728, 819, 819, 754, 728, - /* 130 */ 728, 728, 728, 728, 728, 870, 951, 950, 869, 875, - /* 140 */ 874, 873, 728, 728, 728, 728, 864, 865, 863, 862, - /* 150 */ 728, 728, 728, 728, 899, 728, 961, 965, 728, 728, - /* 160 */ 728, 850, 728, 728, 728, 728, 728, 728, 728, 728, - /* 170 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 180 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 190 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 200 */ 728, 922, 932, 728, 728, 728, 728, 728, 728, 728, - /* 210 */ 728, 728, 728, 728, 850, 728, 949, 728, 908, 904, - /* 220 */ 728, 728, 900, 728, 728, 959, 728, 728, 728, 728, - /* 230 */ 728, 728, 728, 728, 894, 728, 728, 728, 728, 728, - /* 240 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 250 */ 728, 849, 728, 728, 728, 728, 728, 728, 728, 813, - /* 260 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 270 */ 728, 728, 798, 796, 795, 794, 728, 791, 728, 728, - /* 280 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 290 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 300 */ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728, - /* 310 */ 728, 728, 728, + /* 0 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 10 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 20 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 30 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 40 */ 756, 783, 756, 756, 756, 756, 756, 756, 756, 756, + /* 50 */ 756, 756, 756, 756, 756, 756, 781, 756, 933, 756, + /* 60 */ 756, 756, 783, 944, 944, 944, 781, 756, 756, 756, + /* 70 */ 846, 756, 756, 1008, 756, 968, 756, 960, 936, 950, + /* 80 */ 937, 756, 993, 953, 756, 756, 783, 756, 756, 783, + /* 90 */ 756, 783, 756, 756, 756, 756, 781, 756, 756, 756, + /* 100 */ 975, 973, 756, 975, 973, 756, 987, 983, 966, 964, + /* 110 */ 950, 756, 756, 756, 1011, 999, 995, 756, 756, 973, + /* 120 */ 756, 756, 973, 756, 860, 756, 756, 756, 781, 756, + /* 130 */ 815, 756, 781, 756, 784, 849, 849, 784, 756, 756, + /* 140 */ 756, 756, 756, 756, 756, 905, 986, 985, 904, 910, + /* 150 */ 909, 908, 756, 756, 756, 756, 899, 900, 898, 897, + /* 160 */ 756, 756, 756, 756, 756, 934, 756, 996, 1000, 756, + /* 170 */ 756, 756, 884, 756, 756, 756, 756, 756, 756, 756, + /* 180 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 190 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 200 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 210 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 220 */ 756, 957, 967, 756, 756, 756, 756, 756, 756, 756, + /* 230 */ 756, 756, 756, 756, 884, 756, 984, 756, 943, 939, + /* 240 */ 756, 756, 935, 756, 756, 994, 756, 756, 756, 756, + /* 250 */ 756, 756, 756, 756, 929, 756, 756, 756, 756, 756, + /* 260 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 270 */ 756, 883, 756, 756, 756, 756, 756, 756, 756, 843, + /* 280 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 290 */ 756, 756, 828, 826, 825, 824, 756, 821, 756, 756, + /* 300 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 310 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 320 */ 756, 756, 756, 756, 756, 756, 756, 756, 756, 756, + /* 330 */ 756, 756, 756, }; /********** End of lemon-generated parsing tables *****************************/ @@ -706,131 +721,133 @@ static const char *const yyTokenName[] = { /* 90 */ "FULLTEXT", /* 91 */ "FUNCTION", /* 92 */ "INTERVAL", - /* 93 */ "MNODES", - /* 94 */ "NK_FLOAT", - /* 95 */ "NK_BOOL", - /* 96 */ "NK_VARIABLE", - /* 97 */ "BETWEEN", - /* 98 */ "IS", - /* 99 */ "NULL", - /* 100 */ "NK_LT", - /* 101 */ "NK_GT", - /* 102 */ "NK_LE", - /* 103 */ "NK_GE", - /* 104 */ "NK_NE", - /* 105 */ "NK_EQ", - /* 106 */ "LIKE", - /* 107 */ "MATCH", - /* 108 */ "NMATCH", - /* 109 */ "IN", - /* 110 */ "FROM", - /* 111 */ "AS", - /* 112 */ "JOIN", - /* 113 */ "INNER", - /* 114 */ "SELECT", - /* 115 */ "DISTINCT", - /* 116 */ "WHERE", - /* 117 */ "PARTITION", - /* 118 */ "BY", - /* 119 */ "SESSION", - /* 120 */ "STATE_WINDOW", - /* 121 */ "SLIDING", - /* 122 */ "FILL", - /* 123 */ "VALUE", - /* 124 */ "NONE", - /* 125 */ "PREV", - /* 126 */ "LINEAR", - /* 127 */ "NEXT", - /* 128 */ "GROUP", - /* 129 */ "HAVING", - /* 130 */ "ORDER", - /* 131 */ "SLIMIT", - /* 132 */ "SOFFSET", - /* 133 */ "LIMIT", - /* 134 */ "OFFSET", - /* 135 */ "ASC", - /* 136 */ "DESC", - /* 137 */ "NULLS", - /* 138 */ "FIRST", - /* 139 */ "LAST", - /* 140 */ "cmd", - /* 141 */ "user_name", - /* 142 */ "dnode_endpoint", - /* 143 */ "dnode_host_name", - /* 144 */ "not_exists_opt", - /* 145 */ "db_name", - /* 146 */ "db_options", - /* 147 */ "exists_opt", - /* 148 */ "full_table_name", - /* 149 */ "column_def_list", - /* 150 */ "tags_def_opt", - /* 151 */ "table_options", - /* 152 */ "multi_create_clause", - /* 153 */ "tags_def", - /* 154 */ "multi_drop_clause", - /* 155 */ "create_subtable_clause", - /* 156 */ "specific_tags_opt", - /* 157 */ "literal_list", - /* 158 */ "drop_table_clause", - /* 159 */ "col_name_list", - /* 160 */ "table_name", - /* 161 */ "column_def", - /* 162 */ "column_name", - /* 163 */ "type_name", - /* 164 */ "col_name", - /* 165 */ "index_name", - /* 166 */ "index_options", - /* 167 */ "func_list", - /* 168 */ "duration_literal", - /* 169 */ "sliding_opt", - /* 170 */ "func", - /* 171 */ "function_name", - /* 172 */ "expression_list", - /* 173 */ "query_expression", - /* 174 */ "literal", - /* 175 */ "table_alias", - /* 176 */ "column_alias", - /* 177 */ "expression", - /* 178 */ "column_reference", - /* 179 */ "subquery", - /* 180 */ "predicate", - /* 181 */ "compare_op", - /* 182 */ "in_op", - /* 183 */ "in_predicate_value", - /* 184 */ "boolean_value_expression", - /* 185 */ "boolean_primary", - /* 186 */ "common_expression", - /* 187 */ "from_clause", - /* 188 */ "table_reference_list", - /* 189 */ "table_reference", - /* 190 */ "table_primary", - /* 191 */ "joined_table", - /* 192 */ "alias_opt", - /* 193 */ "parenthesized_joined_table", - /* 194 */ "join_type", - /* 195 */ "search_condition", - /* 196 */ "query_specification", - /* 197 */ "set_quantifier_opt", - /* 198 */ "select_list", - /* 199 */ "where_clause_opt", - /* 200 */ "partition_by_clause_opt", - /* 201 */ "twindow_clause_opt", - /* 202 */ "group_by_clause_opt", - /* 203 */ "having_clause_opt", - /* 204 */ "select_sublist", - /* 205 */ "select_item", - /* 206 */ "fill_opt", - /* 207 */ "fill_mode", - /* 208 */ "group_by_list", - /* 209 */ "query_expression_body", - /* 210 */ "order_by_clause_opt", - /* 211 */ "slimit_clause_opt", - /* 212 */ "limit_clause_opt", - /* 213 */ "query_primary", - /* 214 */ "sort_specification_list", - /* 215 */ "sort_specification", - /* 216 */ "ordering_specification_opt", - /* 217 */ "null_ordering_opt", + /* 93 */ "TOPIC", + /* 94 */ "AS", + /* 95 */ "MNODES", + /* 96 */ "NK_FLOAT", + /* 97 */ "NK_BOOL", + /* 98 */ "NK_VARIABLE", + /* 99 */ "BETWEEN", + /* 100 */ "IS", + /* 101 */ "NULL", + /* 102 */ "NK_LT", + /* 103 */ "NK_GT", + /* 104 */ "NK_LE", + /* 105 */ "NK_GE", + /* 106 */ "NK_NE", + /* 107 */ "NK_EQ", + /* 108 */ "LIKE", + /* 109 */ "MATCH", + /* 110 */ "NMATCH", + /* 111 */ "IN", + /* 112 */ "FROM", + /* 113 */ "JOIN", + /* 114 */ "INNER", + /* 115 */ "SELECT", + /* 116 */ "DISTINCT", + /* 117 */ "WHERE", + /* 118 */ "PARTITION", + /* 119 */ "BY", + /* 120 */ "SESSION", + /* 121 */ "STATE_WINDOW", + /* 122 */ "SLIDING", + /* 123 */ "FILL", + /* 124 */ "VALUE", + /* 125 */ "NONE", + /* 126 */ "PREV", + /* 127 */ "LINEAR", + /* 128 */ "NEXT", + /* 129 */ "GROUP", + /* 130 */ "HAVING", + /* 131 */ "ORDER", + /* 132 */ "SLIMIT", + /* 133 */ "SOFFSET", + /* 134 */ "LIMIT", + /* 135 */ "OFFSET", + /* 136 */ "ASC", + /* 137 */ "DESC", + /* 138 */ "NULLS", + /* 139 */ "FIRST", + /* 140 */ "LAST", + /* 141 */ "cmd", + /* 142 */ "user_name", + /* 143 */ "dnode_endpoint", + /* 144 */ "dnode_host_name", + /* 145 */ "not_exists_opt", + /* 146 */ "db_name", + /* 147 */ "db_options", + /* 148 */ "exists_opt", + /* 149 */ "full_table_name", + /* 150 */ "column_def_list", + /* 151 */ "tags_def_opt", + /* 152 */ "table_options", + /* 153 */ "multi_create_clause", + /* 154 */ "tags_def", + /* 155 */ "multi_drop_clause", + /* 156 */ "create_subtable_clause", + /* 157 */ "specific_tags_opt", + /* 158 */ "literal_list", + /* 159 */ "drop_table_clause", + /* 160 */ "col_name_list", + /* 161 */ "table_name", + /* 162 */ "column_def", + /* 163 */ "column_name", + /* 164 */ "type_name", + /* 165 */ "col_name", + /* 166 */ "index_name", + /* 167 */ "index_options", + /* 168 */ "func_list", + /* 169 */ "duration_literal", + /* 170 */ "sliding_opt", + /* 171 */ "func", + /* 172 */ "function_name", + /* 173 */ "expression_list", + /* 174 */ "topic_name", + /* 175 */ "query_expression", + /* 176 */ "literal", + /* 177 */ "table_alias", + /* 178 */ "column_alias", + /* 179 */ "expression", + /* 180 */ "column_reference", + /* 181 */ "subquery", + /* 182 */ "predicate", + /* 183 */ "compare_op", + /* 184 */ "in_op", + /* 185 */ "in_predicate_value", + /* 186 */ "boolean_value_expression", + /* 187 */ "boolean_primary", + /* 188 */ "common_expression", + /* 189 */ "from_clause", + /* 190 */ "table_reference_list", + /* 191 */ "table_reference", + /* 192 */ "table_primary", + /* 193 */ "joined_table", + /* 194 */ "alias_opt", + /* 195 */ "parenthesized_joined_table", + /* 196 */ "join_type", + /* 197 */ "search_condition", + /* 198 */ "query_specification", + /* 199 */ "set_quantifier_opt", + /* 200 */ "select_list", + /* 201 */ "where_clause_opt", + /* 202 */ "partition_by_clause_opt", + /* 203 */ "twindow_clause_opt", + /* 204 */ "group_by_clause_opt", + /* 205 */ "having_clause_opt", + /* 206 */ "select_sublist", + /* 207 */ "select_item", + /* 208 */ "fill_opt", + /* 209 */ "fill_mode", + /* 210 */ "group_by_list", + /* 211 */ "query_expression_body", + /* 212 */ "order_by_clause_opt", + /* 213 */ "slimit_clause_opt", + /* 214 */ "limit_clause_opt", + /* 215 */ "query_primary", + /* 216 */ "sort_specification_list", + /* 217 */ "sort_specification", + /* 218 */ "ordering_specification_opt", + /* 219 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -852,240 +869,247 @@ static const char *const yyRuleName[] = { /* 11 */ "dnode_host_name ::= NK_ID", /* 12 */ "dnode_host_name ::= NK_IPTOKEN", /* 13 */ "cmd ::= CREATE QNODE ON DNODE NK_INTEGER", - /* 14 */ "cmd ::= SHOW QNODES", - /* 15 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", - /* 16 */ "cmd ::= DROP DATABASE exists_opt db_name", - /* 17 */ "cmd ::= SHOW DATABASES", - /* 18 */ "cmd ::= USE db_name", - /* 19 */ "not_exists_opt ::= IF NOT EXISTS", - /* 20 */ "not_exists_opt ::=", - /* 21 */ "exists_opt ::= IF EXISTS", - /* 22 */ "exists_opt ::=", - /* 23 */ "db_options ::=", - /* 24 */ "db_options ::= db_options BLOCKS NK_INTEGER", - /* 25 */ "db_options ::= db_options CACHE NK_INTEGER", - /* 26 */ "db_options ::= db_options CACHELAST NK_INTEGER", - /* 27 */ "db_options ::= db_options COMP NK_INTEGER", - /* 28 */ "db_options ::= db_options DAYS NK_INTEGER", - /* 29 */ "db_options ::= db_options FSYNC NK_INTEGER", - /* 30 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 31 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 32 */ "db_options ::= db_options KEEP NK_INTEGER", - /* 33 */ "db_options ::= db_options PRECISION NK_STRING", - /* 34 */ "db_options ::= db_options QUORUM NK_INTEGER", - /* 35 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 36 */ "db_options ::= db_options TTL NK_INTEGER", - /* 37 */ "db_options ::= db_options WAL NK_INTEGER", - /* 38 */ "db_options ::= db_options VGROUPS NK_INTEGER", - /* 39 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 40 */ "db_options ::= db_options STREAM_MODE NK_INTEGER", - /* 41 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 42 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 43 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 44 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 45 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 46 */ "cmd ::= SHOW TABLES", - /* 47 */ "cmd ::= SHOW STABLES", - /* 48 */ "multi_create_clause ::= create_subtable_clause", - /* 49 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 50 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", - /* 51 */ "multi_drop_clause ::= drop_table_clause", - /* 52 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 53 */ "drop_table_clause ::= exists_opt full_table_name", - /* 54 */ "specific_tags_opt ::=", - /* 55 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 56 */ "full_table_name ::= table_name", - /* 57 */ "full_table_name ::= db_name NK_DOT table_name", - /* 58 */ "column_def_list ::= column_def", - /* 59 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 60 */ "column_def ::= column_name type_name", - /* 61 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 62 */ "type_name ::= BOOL", - /* 63 */ "type_name ::= TINYINT", - /* 64 */ "type_name ::= SMALLINT", - /* 65 */ "type_name ::= INT", - /* 66 */ "type_name ::= INTEGER", - /* 67 */ "type_name ::= BIGINT", - /* 68 */ "type_name ::= FLOAT", - /* 69 */ "type_name ::= DOUBLE", - /* 70 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 71 */ "type_name ::= TIMESTAMP", - /* 72 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 73 */ "type_name ::= TINYINT UNSIGNED", - /* 74 */ "type_name ::= SMALLINT UNSIGNED", - /* 75 */ "type_name ::= INT UNSIGNED", - /* 76 */ "type_name ::= BIGINT UNSIGNED", - /* 77 */ "type_name ::= JSON", - /* 78 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 79 */ "type_name ::= MEDIUMBLOB", - /* 80 */ "type_name ::= BLOB", - /* 81 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 82 */ "type_name ::= DECIMAL", - /* 83 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 84 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 85 */ "tags_def_opt ::=", - /* 86 */ "tags_def_opt ::= tags_def", - /* 87 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 88 */ "table_options ::=", - /* 89 */ "table_options ::= table_options COMMENT NK_STRING", - /* 90 */ "table_options ::= table_options KEEP NK_INTEGER", - /* 91 */ "table_options ::= table_options TTL NK_INTEGER", - /* 92 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 93 */ "col_name_list ::= col_name", - /* 94 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 95 */ "col_name ::= column_name", - /* 96 */ "cmd ::= CREATE SMA INDEX index_name ON table_name index_options", - /* 97 */ "cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP", - /* 98 */ "index_options ::=", - /* 99 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 100 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 101 */ "func_list ::= func", - /* 102 */ "func_list ::= func_list NK_COMMA func", - /* 103 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 104 */ "cmd ::= SHOW VGROUPS", - /* 105 */ "cmd ::= SHOW db_name NK_DOT VGROUPS", - /* 106 */ "cmd ::= SHOW MNODES", - /* 107 */ "cmd ::= query_expression", - /* 108 */ "literal ::= NK_INTEGER", - /* 109 */ "literal ::= NK_FLOAT", - /* 110 */ "literal ::= NK_STRING", - /* 111 */ "literal ::= NK_BOOL", - /* 112 */ "literal ::= TIMESTAMP NK_STRING", - /* 113 */ "literal ::= duration_literal", - /* 114 */ "duration_literal ::= NK_VARIABLE", - /* 115 */ "literal_list ::= literal", - /* 116 */ "literal_list ::= literal_list NK_COMMA literal", - /* 117 */ "db_name ::= NK_ID", - /* 118 */ "table_name ::= NK_ID", - /* 119 */ "column_name ::= NK_ID", - /* 120 */ "function_name ::= NK_ID", - /* 121 */ "table_alias ::= NK_ID", - /* 122 */ "column_alias ::= NK_ID", - /* 123 */ "user_name ::= NK_ID", - /* 124 */ "index_name ::= NK_ID", - /* 125 */ "expression ::= literal", - /* 126 */ "expression ::= column_reference", - /* 127 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 128 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 129 */ "expression ::= subquery", - /* 130 */ "expression ::= NK_LP expression NK_RP", - /* 131 */ "expression ::= NK_PLUS expression", - /* 132 */ "expression ::= NK_MINUS expression", - /* 133 */ "expression ::= expression NK_PLUS expression", - /* 134 */ "expression ::= expression NK_MINUS expression", - /* 135 */ "expression ::= expression NK_STAR expression", - /* 136 */ "expression ::= expression NK_SLASH expression", - /* 137 */ "expression ::= expression NK_REM expression", - /* 138 */ "expression_list ::= expression", - /* 139 */ "expression_list ::= expression_list NK_COMMA expression", - /* 140 */ "column_reference ::= column_name", - /* 141 */ "column_reference ::= table_name NK_DOT column_name", - /* 142 */ "predicate ::= expression compare_op expression", - /* 143 */ "predicate ::= expression BETWEEN expression AND expression", - /* 144 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 145 */ "predicate ::= expression IS NULL", - /* 146 */ "predicate ::= expression IS NOT NULL", - /* 147 */ "predicate ::= expression in_op in_predicate_value", - /* 148 */ "compare_op ::= NK_LT", - /* 149 */ "compare_op ::= NK_GT", - /* 150 */ "compare_op ::= NK_LE", - /* 151 */ "compare_op ::= NK_GE", - /* 152 */ "compare_op ::= NK_NE", - /* 153 */ "compare_op ::= NK_EQ", - /* 154 */ "compare_op ::= LIKE", - /* 155 */ "compare_op ::= NOT LIKE", - /* 156 */ "compare_op ::= MATCH", - /* 157 */ "compare_op ::= NMATCH", - /* 158 */ "in_op ::= IN", - /* 159 */ "in_op ::= NOT IN", - /* 160 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 161 */ "boolean_value_expression ::= boolean_primary", - /* 162 */ "boolean_value_expression ::= NOT boolean_primary", - /* 163 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 164 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 165 */ "boolean_primary ::= predicate", - /* 166 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 167 */ "common_expression ::= expression", - /* 168 */ "common_expression ::= boolean_value_expression", - /* 169 */ "from_clause ::= FROM table_reference_list", - /* 170 */ "table_reference_list ::= table_reference", - /* 171 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 172 */ "table_reference ::= table_primary", - /* 173 */ "table_reference ::= joined_table", - /* 174 */ "table_primary ::= table_name alias_opt", - /* 175 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 176 */ "table_primary ::= subquery alias_opt", - /* 177 */ "table_primary ::= parenthesized_joined_table", - /* 178 */ "alias_opt ::=", - /* 179 */ "alias_opt ::= table_alias", - /* 180 */ "alias_opt ::= AS table_alias", - /* 181 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 182 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 183 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 184 */ "join_type ::=", - /* 185 */ "join_type ::= INNER", - /* 186 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 187 */ "set_quantifier_opt ::=", - /* 188 */ "set_quantifier_opt ::= DISTINCT", - /* 189 */ "set_quantifier_opt ::= ALL", - /* 190 */ "select_list ::= NK_STAR", - /* 191 */ "select_list ::= select_sublist", - /* 192 */ "select_sublist ::= select_item", - /* 193 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 194 */ "select_item ::= common_expression", - /* 195 */ "select_item ::= common_expression column_alias", - /* 196 */ "select_item ::= common_expression AS column_alias", - /* 197 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 198 */ "where_clause_opt ::=", - /* 199 */ "where_clause_opt ::= WHERE search_condition", - /* 200 */ "partition_by_clause_opt ::=", - /* 201 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 202 */ "twindow_clause_opt ::=", - /* 203 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", - /* 204 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 205 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 206 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 207 */ "sliding_opt ::=", - /* 208 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 209 */ "fill_opt ::=", - /* 210 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 211 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 212 */ "fill_mode ::= NONE", - /* 213 */ "fill_mode ::= PREV", - /* 214 */ "fill_mode ::= NULL", - /* 215 */ "fill_mode ::= LINEAR", - /* 216 */ "fill_mode ::= NEXT", - /* 217 */ "group_by_clause_opt ::=", - /* 218 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 219 */ "group_by_list ::= expression", - /* 220 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 221 */ "having_clause_opt ::=", - /* 222 */ "having_clause_opt ::= HAVING search_condition", - /* 223 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 224 */ "query_expression_body ::= query_primary", - /* 225 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 226 */ "query_primary ::= query_specification", - /* 227 */ "order_by_clause_opt ::=", - /* 228 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 229 */ "slimit_clause_opt ::=", - /* 230 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 231 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 232 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 233 */ "limit_clause_opt ::=", - /* 234 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 235 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 236 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 237 */ "subquery ::= NK_LP query_expression NK_RP", - /* 238 */ "search_condition ::= common_expression", - /* 239 */ "sort_specification_list ::= sort_specification", - /* 240 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 241 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 242 */ "ordering_specification_opt ::=", - /* 243 */ "ordering_specification_opt ::= ASC", - /* 244 */ "ordering_specification_opt ::= DESC", - /* 245 */ "null_ordering_opt ::=", - /* 246 */ "null_ordering_opt ::= NULLS FIRST", - /* 247 */ "null_ordering_opt ::= NULLS LAST", + /* 14 */ "cmd ::= DROP QNODE ON DNODE NK_INTEGER", + /* 15 */ "cmd ::= SHOW QNODES", + /* 16 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", + /* 17 */ "cmd ::= DROP DATABASE exists_opt db_name", + /* 18 */ "cmd ::= SHOW DATABASES", + /* 19 */ "cmd ::= USE db_name", + /* 20 */ "cmd ::= ALTER DATABASE db_name db_options", + /* 21 */ "not_exists_opt ::= IF NOT EXISTS", + /* 22 */ "not_exists_opt ::=", + /* 23 */ "exists_opt ::= IF EXISTS", + /* 24 */ "exists_opt ::=", + /* 25 */ "db_options ::=", + /* 26 */ "db_options ::= db_options BLOCKS NK_INTEGER", + /* 27 */ "db_options ::= db_options CACHE NK_INTEGER", + /* 28 */ "db_options ::= db_options CACHELAST NK_INTEGER", + /* 29 */ "db_options ::= db_options COMP NK_INTEGER", + /* 30 */ "db_options ::= db_options DAYS NK_INTEGER", + /* 31 */ "db_options ::= db_options FSYNC NK_INTEGER", + /* 32 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 33 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 34 */ "db_options ::= db_options KEEP NK_INTEGER", + /* 35 */ "db_options ::= db_options PRECISION NK_STRING", + /* 36 */ "db_options ::= db_options QUORUM NK_INTEGER", + /* 37 */ "db_options ::= db_options REPLICA NK_INTEGER", + /* 38 */ "db_options ::= db_options TTL NK_INTEGER", + /* 39 */ "db_options ::= db_options WAL NK_INTEGER", + /* 40 */ "db_options ::= db_options VGROUPS NK_INTEGER", + /* 41 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", + /* 42 */ "db_options ::= db_options STREAM_MODE NK_INTEGER", + /* 43 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 44 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 45 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 46 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 47 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 48 */ "cmd ::= SHOW TABLES", + /* 49 */ "cmd ::= SHOW STABLES", + /* 50 */ "multi_create_clause ::= create_subtable_clause", + /* 51 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 52 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", + /* 53 */ "multi_drop_clause ::= drop_table_clause", + /* 54 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 55 */ "drop_table_clause ::= exists_opt full_table_name", + /* 56 */ "specific_tags_opt ::=", + /* 57 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 58 */ "full_table_name ::= table_name", + /* 59 */ "full_table_name ::= db_name NK_DOT table_name", + /* 60 */ "column_def_list ::= column_def", + /* 61 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 62 */ "column_def ::= column_name type_name", + /* 63 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 64 */ "type_name ::= BOOL", + /* 65 */ "type_name ::= TINYINT", + /* 66 */ "type_name ::= SMALLINT", + /* 67 */ "type_name ::= INT", + /* 68 */ "type_name ::= INTEGER", + /* 69 */ "type_name ::= BIGINT", + /* 70 */ "type_name ::= FLOAT", + /* 71 */ "type_name ::= DOUBLE", + /* 72 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 73 */ "type_name ::= TIMESTAMP", + /* 74 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 75 */ "type_name ::= TINYINT UNSIGNED", + /* 76 */ "type_name ::= SMALLINT UNSIGNED", + /* 77 */ "type_name ::= INT UNSIGNED", + /* 78 */ "type_name ::= BIGINT UNSIGNED", + /* 79 */ "type_name ::= JSON", + /* 80 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 81 */ "type_name ::= MEDIUMBLOB", + /* 82 */ "type_name ::= BLOB", + /* 83 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 84 */ "type_name ::= DECIMAL", + /* 85 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 86 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 87 */ "tags_def_opt ::=", + /* 88 */ "tags_def_opt ::= tags_def", + /* 89 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 90 */ "table_options ::=", + /* 91 */ "table_options ::= table_options COMMENT NK_STRING", + /* 92 */ "table_options ::= table_options KEEP NK_INTEGER", + /* 93 */ "table_options ::= table_options TTL NK_INTEGER", + /* 94 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 95 */ "col_name_list ::= col_name", + /* 96 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 97 */ "col_name ::= column_name", + /* 98 */ "cmd ::= CREATE SMA INDEX index_name ON table_name index_options", + /* 99 */ "cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP", + /* 100 */ "cmd ::= DROP INDEX index_name ON table_name", + /* 101 */ "index_options ::=", + /* 102 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 103 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 104 */ "func_list ::= func", + /* 105 */ "func_list ::= func_list NK_COMMA func", + /* 106 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 107 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 108 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 109 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 110 */ "cmd ::= SHOW VGROUPS", + /* 111 */ "cmd ::= SHOW db_name NK_DOT VGROUPS", + /* 112 */ "cmd ::= SHOW MNODES", + /* 113 */ "cmd ::= query_expression", + /* 114 */ "literal ::= NK_INTEGER", + /* 115 */ "literal ::= NK_FLOAT", + /* 116 */ "literal ::= NK_STRING", + /* 117 */ "literal ::= NK_BOOL", + /* 118 */ "literal ::= TIMESTAMP NK_STRING", + /* 119 */ "literal ::= duration_literal", + /* 120 */ "duration_literal ::= NK_VARIABLE", + /* 121 */ "literal_list ::= literal", + /* 122 */ "literal_list ::= literal_list NK_COMMA literal", + /* 123 */ "db_name ::= NK_ID", + /* 124 */ "table_name ::= NK_ID", + /* 125 */ "column_name ::= NK_ID", + /* 126 */ "function_name ::= NK_ID", + /* 127 */ "table_alias ::= NK_ID", + /* 128 */ "column_alias ::= NK_ID", + /* 129 */ "user_name ::= NK_ID", + /* 130 */ "index_name ::= NK_ID", + /* 131 */ "topic_name ::= NK_ID", + /* 132 */ "expression ::= literal", + /* 133 */ "expression ::= column_reference", + /* 134 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 135 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 136 */ "expression ::= subquery", + /* 137 */ "expression ::= NK_LP expression NK_RP", + /* 138 */ "expression ::= NK_PLUS expression", + /* 139 */ "expression ::= NK_MINUS expression", + /* 140 */ "expression ::= expression NK_PLUS expression", + /* 141 */ "expression ::= expression NK_MINUS expression", + /* 142 */ "expression ::= expression NK_STAR expression", + /* 143 */ "expression ::= expression NK_SLASH expression", + /* 144 */ "expression ::= expression NK_REM expression", + /* 145 */ "expression_list ::= expression", + /* 146 */ "expression_list ::= expression_list NK_COMMA expression", + /* 147 */ "column_reference ::= column_name", + /* 148 */ "column_reference ::= table_name NK_DOT column_name", + /* 149 */ "predicate ::= expression compare_op expression", + /* 150 */ "predicate ::= expression BETWEEN expression AND expression", + /* 151 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 152 */ "predicate ::= expression IS NULL", + /* 153 */ "predicate ::= expression IS NOT NULL", + /* 154 */ "predicate ::= expression in_op in_predicate_value", + /* 155 */ "compare_op ::= NK_LT", + /* 156 */ "compare_op ::= NK_GT", + /* 157 */ "compare_op ::= NK_LE", + /* 158 */ "compare_op ::= NK_GE", + /* 159 */ "compare_op ::= NK_NE", + /* 160 */ "compare_op ::= NK_EQ", + /* 161 */ "compare_op ::= LIKE", + /* 162 */ "compare_op ::= NOT LIKE", + /* 163 */ "compare_op ::= MATCH", + /* 164 */ "compare_op ::= NMATCH", + /* 165 */ "in_op ::= IN", + /* 166 */ "in_op ::= NOT IN", + /* 167 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 168 */ "boolean_value_expression ::= boolean_primary", + /* 169 */ "boolean_value_expression ::= NOT boolean_primary", + /* 170 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 171 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 172 */ "boolean_primary ::= predicate", + /* 173 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 174 */ "common_expression ::= expression", + /* 175 */ "common_expression ::= boolean_value_expression", + /* 176 */ "from_clause ::= FROM table_reference_list", + /* 177 */ "table_reference_list ::= table_reference", + /* 178 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 179 */ "table_reference ::= table_primary", + /* 180 */ "table_reference ::= joined_table", + /* 181 */ "table_primary ::= table_name alias_opt", + /* 182 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 183 */ "table_primary ::= subquery alias_opt", + /* 184 */ "table_primary ::= parenthesized_joined_table", + /* 185 */ "alias_opt ::=", + /* 186 */ "alias_opt ::= table_alias", + /* 187 */ "alias_opt ::= AS table_alias", + /* 188 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 189 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 190 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 191 */ "join_type ::=", + /* 192 */ "join_type ::= INNER", + /* 193 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 194 */ "set_quantifier_opt ::=", + /* 195 */ "set_quantifier_opt ::= DISTINCT", + /* 196 */ "set_quantifier_opt ::= ALL", + /* 197 */ "select_list ::= NK_STAR", + /* 198 */ "select_list ::= select_sublist", + /* 199 */ "select_sublist ::= select_item", + /* 200 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 201 */ "select_item ::= common_expression", + /* 202 */ "select_item ::= common_expression column_alias", + /* 203 */ "select_item ::= common_expression AS column_alias", + /* 204 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 205 */ "where_clause_opt ::=", + /* 206 */ "where_clause_opt ::= WHERE search_condition", + /* 207 */ "partition_by_clause_opt ::=", + /* 208 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 209 */ "twindow_clause_opt ::=", + /* 210 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", + /* 211 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 212 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 213 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 214 */ "sliding_opt ::=", + /* 215 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 216 */ "fill_opt ::=", + /* 217 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 218 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 219 */ "fill_mode ::= NONE", + /* 220 */ "fill_mode ::= PREV", + /* 221 */ "fill_mode ::= NULL", + /* 222 */ "fill_mode ::= LINEAR", + /* 223 */ "fill_mode ::= NEXT", + /* 224 */ "group_by_clause_opt ::=", + /* 225 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 226 */ "group_by_list ::= expression", + /* 227 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 228 */ "having_clause_opt ::=", + /* 229 */ "having_clause_opt ::= HAVING search_condition", + /* 230 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 231 */ "query_expression_body ::= query_primary", + /* 232 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 233 */ "query_primary ::= query_specification", + /* 234 */ "order_by_clause_opt ::=", + /* 235 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 236 */ "slimit_clause_opt ::=", + /* 237 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 238 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 239 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 240 */ "limit_clause_opt ::=", + /* 241 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 242 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 243 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 244 */ "subquery ::= NK_LP query_expression NK_RP", + /* 245 */ "search_condition ::= common_expression", + /* 246 */ "sort_specification_list ::= sort_specification", + /* 247 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 248 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 249 */ "ordering_specification_opt ::=", + /* 250 */ "ordering_specification_opt ::= ASC", + /* 251 */ "ordering_specification_opt ::= DESC", + /* 252 */ "null_ordering_opt ::=", + /* 253 */ "null_ordering_opt ::= NULLS FIRST", + /* 254 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1212,120 +1236,121 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 140: /* cmd */ - case 146: /* db_options */ - case 148: /* full_table_name */ - case 151: /* table_options */ - case 155: /* create_subtable_clause */ - case 158: /* drop_table_clause */ - case 161: /* column_def */ - case 164: /* col_name */ - case 166: /* index_options */ - case 168: /* duration_literal */ - case 169: /* sliding_opt */ - case 170: /* func */ - case 173: /* query_expression */ - case 174: /* literal */ - case 177: /* expression */ - case 178: /* column_reference */ - case 179: /* subquery */ - case 180: /* predicate */ - case 183: /* in_predicate_value */ - case 184: /* boolean_value_expression */ - case 185: /* boolean_primary */ - case 186: /* common_expression */ - case 187: /* from_clause */ - case 188: /* table_reference_list */ - case 189: /* table_reference */ - case 190: /* table_primary */ - case 191: /* joined_table */ - case 193: /* parenthesized_joined_table */ - case 195: /* search_condition */ - case 196: /* query_specification */ - case 199: /* where_clause_opt */ - case 201: /* twindow_clause_opt */ - case 203: /* having_clause_opt */ - case 205: /* select_item */ - case 206: /* fill_opt */ - case 209: /* query_expression_body */ - case 211: /* slimit_clause_opt */ - case 212: /* limit_clause_opt */ - case 213: /* query_primary */ - case 215: /* sort_specification */ + case 141: /* cmd */ + case 147: /* db_options */ + case 149: /* full_table_name */ + case 152: /* table_options */ + case 156: /* create_subtable_clause */ + case 159: /* drop_table_clause */ + case 162: /* column_def */ + case 165: /* col_name */ + case 167: /* index_options */ + case 169: /* duration_literal */ + case 170: /* sliding_opt */ + case 171: /* func */ + case 175: /* query_expression */ + case 176: /* literal */ + case 179: /* expression */ + case 180: /* column_reference */ + case 181: /* subquery */ + case 182: /* predicate */ + case 185: /* in_predicate_value */ + case 186: /* boolean_value_expression */ + case 187: /* boolean_primary */ + case 188: /* common_expression */ + case 189: /* from_clause */ + case 190: /* table_reference_list */ + case 191: /* table_reference */ + case 192: /* table_primary */ + case 193: /* joined_table */ + case 195: /* parenthesized_joined_table */ + case 197: /* search_condition */ + case 198: /* query_specification */ + case 201: /* where_clause_opt */ + case 203: /* twindow_clause_opt */ + case 205: /* having_clause_opt */ + case 207: /* select_item */ + case 208: /* fill_opt */ + case 211: /* query_expression_body */ + case 213: /* slimit_clause_opt */ + case 214: /* limit_clause_opt */ + case 215: /* query_primary */ + case 217: /* sort_specification */ { - nodesDestroyNode((yypminor->yy68)); + nodesDestroyNode((yypminor->yy432)); } break; - case 141: /* user_name */ - case 142: /* dnode_endpoint */ - case 143: /* dnode_host_name */ - case 145: /* db_name */ - case 160: /* table_name */ - case 162: /* column_name */ - case 165: /* index_name */ - case 171: /* function_name */ - case 175: /* table_alias */ - case 176: /* column_alias */ - case 192: /* alias_opt */ + case 142: /* user_name */ + case 143: /* dnode_endpoint */ + case 144: /* dnode_host_name */ + case 146: /* db_name */ + case 161: /* table_name */ + case 163: /* column_name */ + case 166: /* index_name */ + case 172: /* function_name */ + case 174: /* topic_name */ + case 177: /* table_alias */ + case 178: /* column_alias */ + case 194: /* alias_opt */ { } break; - case 144: /* not_exists_opt */ - case 147: /* exists_opt */ - case 197: /* set_quantifier_opt */ + case 145: /* not_exists_opt */ + case 148: /* exists_opt */ + case 199: /* set_quantifier_opt */ { } break; - case 149: /* column_def_list */ - case 150: /* tags_def_opt */ - case 152: /* multi_create_clause */ - case 153: /* tags_def */ - case 154: /* multi_drop_clause */ - case 156: /* specific_tags_opt */ - case 157: /* literal_list */ - case 159: /* col_name_list */ - case 167: /* func_list */ - case 172: /* expression_list */ - case 198: /* select_list */ - case 200: /* partition_by_clause_opt */ - case 202: /* group_by_clause_opt */ - case 204: /* select_sublist */ - case 208: /* group_by_list */ - case 210: /* order_by_clause_opt */ - case 214: /* sort_specification_list */ + case 150: /* column_def_list */ + case 151: /* tags_def_opt */ + case 153: /* multi_create_clause */ + case 154: /* tags_def */ + case 155: /* multi_drop_clause */ + case 157: /* specific_tags_opt */ + case 158: /* literal_list */ + case 160: /* col_name_list */ + case 168: /* func_list */ + case 173: /* expression_list */ + case 200: /* select_list */ + case 202: /* partition_by_clause_opt */ + case 204: /* group_by_clause_opt */ + case 206: /* select_sublist */ + case 210: /* group_by_list */ + case 212: /* order_by_clause_opt */ + case 216: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy40)); + nodesDestroyList((yypminor->yy24)); } break; - case 163: /* type_name */ + case 164: /* type_name */ { } break; - case 181: /* compare_op */ - case 182: /* in_op */ + case 183: /* compare_op */ + case 184: /* in_op */ { } break; - case 194: /* join_type */ + case 196: /* join_type */ { } break; - case 207: /* fill_mode */ + case 209: /* fill_mode */ { } break; - case 216: /* ordering_specification_opt */ + case 218: /* ordering_specification_opt */ { } break; - case 217: /* null_ordering_opt */ + case 219: /* null_ordering_opt */ { } @@ -1624,254 +1649,261 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 140, -5 }, /* (0) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 140, -5 }, /* (1) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 140, -5 }, /* (2) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 140, -3 }, /* (3) cmd ::= DROP USER user_name */ - { 140, -2 }, /* (4) cmd ::= SHOW USERS */ - { 140, -3 }, /* (5) cmd ::= CREATE DNODE dnode_endpoint */ - { 140, -5 }, /* (6) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 140, -3 }, /* (7) cmd ::= DROP DNODE NK_INTEGER */ - { 140, -3 }, /* (8) cmd ::= DROP DNODE dnode_endpoint */ - { 140, -2 }, /* (9) cmd ::= SHOW DNODES */ - { 142, -1 }, /* (10) dnode_endpoint ::= NK_STRING */ - { 143, -1 }, /* (11) dnode_host_name ::= NK_ID */ - { 143, -1 }, /* (12) dnode_host_name ::= NK_IPTOKEN */ - { 140, -5 }, /* (13) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 140, -2 }, /* (14) cmd ::= SHOW QNODES */ - { 140, -5 }, /* (15) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 140, -4 }, /* (16) cmd ::= DROP DATABASE exists_opt db_name */ - { 140, -2 }, /* (17) cmd ::= SHOW DATABASES */ - { 140, -2 }, /* (18) cmd ::= USE db_name */ - { 144, -3 }, /* (19) not_exists_opt ::= IF NOT EXISTS */ - { 144, 0 }, /* (20) not_exists_opt ::= */ - { 147, -2 }, /* (21) exists_opt ::= IF EXISTS */ - { 147, 0 }, /* (22) exists_opt ::= */ - { 146, 0 }, /* (23) db_options ::= */ - { 146, -3 }, /* (24) db_options ::= db_options BLOCKS NK_INTEGER */ - { 146, -3 }, /* (25) db_options ::= db_options CACHE NK_INTEGER */ - { 146, -3 }, /* (26) db_options ::= db_options CACHELAST NK_INTEGER */ - { 146, -3 }, /* (27) db_options ::= db_options COMP NK_INTEGER */ - { 146, -3 }, /* (28) db_options ::= db_options DAYS NK_INTEGER */ - { 146, -3 }, /* (29) db_options ::= db_options FSYNC NK_INTEGER */ - { 146, -3 }, /* (30) db_options ::= db_options MAXROWS NK_INTEGER */ - { 146, -3 }, /* (31) db_options ::= db_options MINROWS NK_INTEGER */ - { 146, -3 }, /* (32) db_options ::= db_options KEEP NK_INTEGER */ - { 146, -3 }, /* (33) db_options ::= db_options PRECISION NK_STRING */ - { 146, -3 }, /* (34) db_options ::= db_options QUORUM NK_INTEGER */ - { 146, -3 }, /* (35) db_options ::= db_options REPLICA NK_INTEGER */ - { 146, -3 }, /* (36) db_options ::= db_options TTL NK_INTEGER */ - { 146, -3 }, /* (37) db_options ::= db_options WAL NK_INTEGER */ - { 146, -3 }, /* (38) db_options ::= db_options VGROUPS NK_INTEGER */ - { 146, -3 }, /* (39) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 146, -3 }, /* (40) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 140, -9 }, /* (41) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 140, -3 }, /* (42) cmd ::= CREATE TABLE multi_create_clause */ - { 140, -9 }, /* (43) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 140, -3 }, /* (44) cmd ::= DROP TABLE multi_drop_clause */ - { 140, -4 }, /* (45) cmd ::= DROP STABLE exists_opt full_table_name */ - { 140, -2 }, /* (46) cmd ::= SHOW TABLES */ - { 140, -2 }, /* (47) cmd ::= SHOW STABLES */ - { 152, -1 }, /* (48) multi_create_clause ::= create_subtable_clause */ - { 152, -2 }, /* (49) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 155, -9 }, /* (50) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 154, -1 }, /* (51) multi_drop_clause ::= drop_table_clause */ - { 154, -2 }, /* (52) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 158, -2 }, /* (53) drop_table_clause ::= exists_opt full_table_name */ - { 156, 0 }, /* (54) specific_tags_opt ::= */ - { 156, -3 }, /* (55) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 148, -1 }, /* (56) full_table_name ::= table_name */ - { 148, -3 }, /* (57) full_table_name ::= db_name NK_DOT table_name */ - { 149, -1 }, /* (58) column_def_list ::= column_def */ - { 149, -3 }, /* (59) column_def_list ::= column_def_list NK_COMMA column_def */ - { 161, -2 }, /* (60) column_def ::= column_name type_name */ - { 161, -4 }, /* (61) column_def ::= column_name type_name COMMENT NK_STRING */ - { 163, -1 }, /* (62) type_name ::= BOOL */ - { 163, -1 }, /* (63) type_name ::= TINYINT */ - { 163, -1 }, /* (64) type_name ::= SMALLINT */ - { 163, -1 }, /* (65) type_name ::= INT */ - { 163, -1 }, /* (66) type_name ::= INTEGER */ - { 163, -1 }, /* (67) type_name ::= BIGINT */ - { 163, -1 }, /* (68) type_name ::= FLOAT */ - { 163, -1 }, /* (69) type_name ::= DOUBLE */ - { 163, -4 }, /* (70) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 163, -1 }, /* (71) type_name ::= TIMESTAMP */ - { 163, -4 }, /* (72) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 163, -2 }, /* (73) type_name ::= TINYINT UNSIGNED */ - { 163, -2 }, /* (74) type_name ::= SMALLINT UNSIGNED */ - { 163, -2 }, /* (75) type_name ::= INT UNSIGNED */ - { 163, -2 }, /* (76) type_name ::= BIGINT UNSIGNED */ - { 163, -1 }, /* (77) type_name ::= JSON */ - { 163, -4 }, /* (78) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 163, -1 }, /* (79) type_name ::= MEDIUMBLOB */ - { 163, -1 }, /* (80) type_name ::= BLOB */ - { 163, -4 }, /* (81) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 163, -1 }, /* (82) type_name ::= DECIMAL */ - { 163, -4 }, /* (83) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 163, -6 }, /* (84) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 150, 0 }, /* (85) tags_def_opt ::= */ - { 150, -1 }, /* (86) tags_def_opt ::= tags_def */ - { 153, -4 }, /* (87) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 151, 0 }, /* (88) table_options ::= */ - { 151, -3 }, /* (89) table_options ::= table_options COMMENT NK_STRING */ - { 151, -3 }, /* (90) table_options ::= table_options KEEP NK_INTEGER */ - { 151, -3 }, /* (91) table_options ::= table_options TTL NK_INTEGER */ - { 151, -5 }, /* (92) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 159, -1 }, /* (93) col_name_list ::= col_name */ - { 159, -3 }, /* (94) col_name_list ::= col_name_list NK_COMMA col_name */ - { 164, -1 }, /* (95) col_name ::= column_name */ - { 140, -7 }, /* (96) cmd ::= CREATE SMA INDEX index_name ON table_name index_options */ - { 140, -9 }, /* (97) cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP */ - { 166, 0 }, /* (98) index_options ::= */ - { 166, -9 }, /* (99) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 166, -11 }, /* (100) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 167, -1 }, /* (101) func_list ::= func */ - { 167, -3 }, /* (102) func_list ::= func_list NK_COMMA func */ - { 170, -4 }, /* (103) func ::= function_name NK_LP expression_list NK_RP */ - { 140, -2 }, /* (104) cmd ::= SHOW VGROUPS */ - { 140, -4 }, /* (105) cmd ::= SHOW db_name NK_DOT VGROUPS */ - { 140, -2 }, /* (106) cmd ::= SHOW MNODES */ - { 140, -1 }, /* (107) cmd ::= query_expression */ - { 174, -1 }, /* (108) literal ::= NK_INTEGER */ - { 174, -1 }, /* (109) literal ::= NK_FLOAT */ - { 174, -1 }, /* (110) literal ::= NK_STRING */ - { 174, -1 }, /* (111) literal ::= NK_BOOL */ - { 174, -2 }, /* (112) literal ::= TIMESTAMP NK_STRING */ - { 174, -1 }, /* (113) literal ::= duration_literal */ - { 168, -1 }, /* (114) duration_literal ::= NK_VARIABLE */ - { 157, -1 }, /* (115) literal_list ::= literal */ - { 157, -3 }, /* (116) literal_list ::= literal_list NK_COMMA literal */ - { 145, -1 }, /* (117) db_name ::= NK_ID */ - { 160, -1 }, /* (118) table_name ::= NK_ID */ - { 162, -1 }, /* (119) column_name ::= NK_ID */ - { 171, -1 }, /* (120) function_name ::= NK_ID */ - { 175, -1 }, /* (121) table_alias ::= NK_ID */ - { 176, -1 }, /* (122) column_alias ::= NK_ID */ - { 141, -1 }, /* (123) user_name ::= NK_ID */ - { 165, -1 }, /* (124) index_name ::= NK_ID */ - { 177, -1 }, /* (125) expression ::= literal */ - { 177, -1 }, /* (126) expression ::= column_reference */ - { 177, -4 }, /* (127) expression ::= function_name NK_LP expression_list NK_RP */ - { 177, -4 }, /* (128) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 177, -1 }, /* (129) expression ::= subquery */ - { 177, -3 }, /* (130) expression ::= NK_LP expression NK_RP */ - { 177, -2 }, /* (131) expression ::= NK_PLUS expression */ - { 177, -2 }, /* (132) expression ::= NK_MINUS expression */ - { 177, -3 }, /* (133) expression ::= expression NK_PLUS expression */ - { 177, -3 }, /* (134) expression ::= expression NK_MINUS expression */ - { 177, -3 }, /* (135) expression ::= expression NK_STAR expression */ - { 177, -3 }, /* (136) expression ::= expression NK_SLASH expression */ - { 177, -3 }, /* (137) expression ::= expression NK_REM expression */ - { 172, -1 }, /* (138) expression_list ::= expression */ - { 172, -3 }, /* (139) expression_list ::= expression_list NK_COMMA expression */ - { 178, -1 }, /* (140) column_reference ::= column_name */ - { 178, -3 }, /* (141) column_reference ::= table_name NK_DOT column_name */ - { 180, -3 }, /* (142) predicate ::= expression compare_op expression */ - { 180, -5 }, /* (143) predicate ::= expression BETWEEN expression AND expression */ - { 180, -6 }, /* (144) predicate ::= expression NOT BETWEEN expression AND expression */ - { 180, -3 }, /* (145) predicate ::= expression IS NULL */ - { 180, -4 }, /* (146) predicate ::= expression IS NOT NULL */ - { 180, -3 }, /* (147) predicate ::= expression in_op in_predicate_value */ - { 181, -1 }, /* (148) compare_op ::= NK_LT */ - { 181, -1 }, /* (149) compare_op ::= NK_GT */ - { 181, -1 }, /* (150) compare_op ::= NK_LE */ - { 181, -1 }, /* (151) compare_op ::= NK_GE */ - { 181, -1 }, /* (152) compare_op ::= NK_NE */ - { 181, -1 }, /* (153) compare_op ::= NK_EQ */ - { 181, -1 }, /* (154) compare_op ::= LIKE */ - { 181, -2 }, /* (155) compare_op ::= NOT LIKE */ - { 181, -1 }, /* (156) compare_op ::= MATCH */ - { 181, -1 }, /* (157) compare_op ::= NMATCH */ - { 182, -1 }, /* (158) in_op ::= IN */ - { 182, -2 }, /* (159) in_op ::= NOT IN */ - { 183, -3 }, /* (160) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 184, -1 }, /* (161) boolean_value_expression ::= boolean_primary */ - { 184, -2 }, /* (162) boolean_value_expression ::= NOT boolean_primary */ - { 184, -3 }, /* (163) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 184, -3 }, /* (164) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 185, -1 }, /* (165) boolean_primary ::= predicate */ - { 185, -3 }, /* (166) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 186, -1 }, /* (167) common_expression ::= expression */ - { 186, -1 }, /* (168) common_expression ::= boolean_value_expression */ - { 187, -2 }, /* (169) from_clause ::= FROM table_reference_list */ - { 188, -1 }, /* (170) table_reference_list ::= table_reference */ - { 188, -3 }, /* (171) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 189, -1 }, /* (172) table_reference ::= table_primary */ - { 189, -1 }, /* (173) table_reference ::= joined_table */ - { 190, -2 }, /* (174) table_primary ::= table_name alias_opt */ - { 190, -4 }, /* (175) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 190, -2 }, /* (176) table_primary ::= subquery alias_opt */ - { 190, -1 }, /* (177) table_primary ::= parenthesized_joined_table */ - { 192, 0 }, /* (178) alias_opt ::= */ - { 192, -1 }, /* (179) alias_opt ::= table_alias */ - { 192, -2 }, /* (180) alias_opt ::= AS table_alias */ - { 193, -3 }, /* (181) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 193, -3 }, /* (182) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 191, -6 }, /* (183) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 194, 0 }, /* (184) join_type ::= */ - { 194, -1 }, /* (185) join_type ::= INNER */ - { 196, -9 }, /* (186) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 197, 0 }, /* (187) set_quantifier_opt ::= */ - { 197, -1 }, /* (188) set_quantifier_opt ::= DISTINCT */ - { 197, -1 }, /* (189) set_quantifier_opt ::= ALL */ - { 198, -1 }, /* (190) select_list ::= NK_STAR */ - { 198, -1 }, /* (191) select_list ::= select_sublist */ - { 204, -1 }, /* (192) select_sublist ::= select_item */ - { 204, -3 }, /* (193) select_sublist ::= select_sublist NK_COMMA select_item */ - { 205, -1 }, /* (194) select_item ::= common_expression */ - { 205, -2 }, /* (195) select_item ::= common_expression column_alias */ - { 205, -3 }, /* (196) select_item ::= common_expression AS column_alias */ - { 205, -3 }, /* (197) select_item ::= table_name NK_DOT NK_STAR */ - { 199, 0 }, /* (198) where_clause_opt ::= */ - { 199, -2 }, /* (199) where_clause_opt ::= WHERE search_condition */ - { 200, 0 }, /* (200) partition_by_clause_opt ::= */ - { 200, -3 }, /* (201) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 201, 0 }, /* (202) twindow_clause_opt ::= */ - { 201, -6 }, /* (203) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ - { 201, -4 }, /* (204) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 201, -6 }, /* (205) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 201, -8 }, /* (206) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 169, 0 }, /* (207) sliding_opt ::= */ - { 169, -4 }, /* (208) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 206, 0 }, /* (209) fill_opt ::= */ - { 206, -4 }, /* (210) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 206, -6 }, /* (211) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 207, -1 }, /* (212) fill_mode ::= NONE */ - { 207, -1 }, /* (213) fill_mode ::= PREV */ - { 207, -1 }, /* (214) fill_mode ::= NULL */ - { 207, -1 }, /* (215) fill_mode ::= LINEAR */ - { 207, -1 }, /* (216) fill_mode ::= NEXT */ - { 202, 0 }, /* (217) group_by_clause_opt ::= */ - { 202, -3 }, /* (218) group_by_clause_opt ::= GROUP BY group_by_list */ - { 208, -1 }, /* (219) group_by_list ::= expression */ - { 208, -3 }, /* (220) group_by_list ::= group_by_list NK_COMMA expression */ - { 203, 0 }, /* (221) having_clause_opt ::= */ - { 203, -2 }, /* (222) having_clause_opt ::= HAVING search_condition */ - { 173, -4 }, /* (223) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 209, -1 }, /* (224) query_expression_body ::= query_primary */ - { 209, -4 }, /* (225) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 213, -1 }, /* (226) query_primary ::= query_specification */ - { 210, 0 }, /* (227) order_by_clause_opt ::= */ - { 210, -3 }, /* (228) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 211, 0 }, /* (229) slimit_clause_opt ::= */ - { 211, -2 }, /* (230) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 211, -4 }, /* (231) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 211, -4 }, /* (232) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 212, 0 }, /* (233) limit_clause_opt ::= */ - { 212, -2 }, /* (234) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 212, -4 }, /* (235) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 212, -4 }, /* (236) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 179, -3 }, /* (237) subquery ::= NK_LP query_expression NK_RP */ - { 195, -1 }, /* (238) search_condition ::= common_expression */ - { 214, -1 }, /* (239) sort_specification_list ::= sort_specification */ - { 214, -3 }, /* (240) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 215, -3 }, /* (241) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 216, 0 }, /* (242) ordering_specification_opt ::= */ - { 216, -1 }, /* (243) ordering_specification_opt ::= ASC */ - { 216, -1 }, /* (244) ordering_specification_opt ::= DESC */ - { 217, 0 }, /* (245) null_ordering_opt ::= */ - { 217, -2 }, /* (246) null_ordering_opt ::= NULLS FIRST */ - { 217, -2 }, /* (247) null_ordering_opt ::= NULLS LAST */ + { 141, -5 }, /* (0) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 141, -5 }, /* (1) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 141, -5 }, /* (2) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 141, -3 }, /* (3) cmd ::= DROP USER user_name */ + { 141, -2 }, /* (4) cmd ::= SHOW USERS */ + { 141, -3 }, /* (5) cmd ::= CREATE DNODE dnode_endpoint */ + { 141, -5 }, /* (6) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 141, -3 }, /* (7) cmd ::= DROP DNODE NK_INTEGER */ + { 141, -3 }, /* (8) cmd ::= DROP DNODE dnode_endpoint */ + { 141, -2 }, /* (9) cmd ::= SHOW DNODES */ + { 143, -1 }, /* (10) dnode_endpoint ::= NK_STRING */ + { 144, -1 }, /* (11) dnode_host_name ::= NK_ID */ + { 144, -1 }, /* (12) dnode_host_name ::= NK_IPTOKEN */ + { 141, -5 }, /* (13) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 141, -5 }, /* (14) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 141, -2 }, /* (15) cmd ::= SHOW QNODES */ + { 141, -5 }, /* (16) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 141, -4 }, /* (17) cmd ::= DROP DATABASE exists_opt db_name */ + { 141, -2 }, /* (18) cmd ::= SHOW DATABASES */ + { 141, -2 }, /* (19) cmd ::= USE db_name */ + { 141, -4 }, /* (20) cmd ::= ALTER DATABASE db_name db_options */ + { 145, -3 }, /* (21) not_exists_opt ::= IF NOT EXISTS */ + { 145, 0 }, /* (22) not_exists_opt ::= */ + { 148, -2 }, /* (23) exists_opt ::= IF EXISTS */ + { 148, 0 }, /* (24) exists_opt ::= */ + { 147, 0 }, /* (25) db_options ::= */ + { 147, -3 }, /* (26) db_options ::= db_options BLOCKS NK_INTEGER */ + { 147, -3 }, /* (27) db_options ::= db_options CACHE NK_INTEGER */ + { 147, -3 }, /* (28) db_options ::= db_options CACHELAST NK_INTEGER */ + { 147, -3 }, /* (29) db_options ::= db_options COMP NK_INTEGER */ + { 147, -3 }, /* (30) db_options ::= db_options DAYS NK_INTEGER */ + { 147, -3 }, /* (31) db_options ::= db_options FSYNC NK_INTEGER */ + { 147, -3 }, /* (32) db_options ::= db_options MAXROWS NK_INTEGER */ + { 147, -3 }, /* (33) db_options ::= db_options MINROWS NK_INTEGER */ + { 147, -3 }, /* (34) db_options ::= db_options KEEP NK_INTEGER */ + { 147, -3 }, /* (35) db_options ::= db_options PRECISION NK_STRING */ + { 147, -3 }, /* (36) db_options ::= db_options QUORUM NK_INTEGER */ + { 147, -3 }, /* (37) db_options ::= db_options REPLICA NK_INTEGER */ + { 147, -3 }, /* (38) db_options ::= db_options TTL NK_INTEGER */ + { 147, -3 }, /* (39) db_options ::= db_options WAL NK_INTEGER */ + { 147, -3 }, /* (40) db_options ::= db_options VGROUPS NK_INTEGER */ + { 147, -3 }, /* (41) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 147, -3 }, /* (42) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 141, -9 }, /* (43) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 141, -3 }, /* (44) cmd ::= CREATE TABLE multi_create_clause */ + { 141, -9 }, /* (45) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 141, -3 }, /* (46) cmd ::= DROP TABLE multi_drop_clause */ + { 141, -4 }, /* (47) cmd ::= DROP STABLE exists_opt full_table_name */ + { 141, -2 }, /* (48) cmd ::= SHOW TABLES */ + { 141, -2 }, /* (49) cmd ::= SHOW STABLES */ + { 153, -1 }, /* (50) multi_create_clause ::= create_subtable_clause */ + { 153, -2 }, /* (51) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 156, -9 }, /* (52) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 155, -1 }, /* (53) multi_drop_clause ::= drop_table_clause */ + { 155, -2 }, /* (54) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 159, -2 }, /* (55) drop_table_clause ::= exists_opt full_table_name */ + { 157, 0 }, /* (56) specific_tags_opt ::= */ + { 157, -3 }, /* (57) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 149, -1 }, /* (58) full_table_name ::= table_name */ + { 149, -3 }, /* (59) full_table_name ::= db_name NK_DOT table_name */ + { 150, -1 }, /* (60) column_def_list ::= column_def */ + { 150, -3 }, /* (61) column_def_list ::= column_def_list NK_COMMA column_def */ + { 162, -2 }, /* (62) column_def ::= column_name type_name */ + { 162, -4 }, /* (63) column_def ::= column_name type_name COMMENT NK_STRING */ + { 164, -1 }, /* (64) type_name ::= BOOL */ + { 164, -1 }, /* (65) type_name ::= TINYINT */ + { 164, -1 }, /* (66) type_name ::= SMALLINT */ + { 164, -1 }, /* (67) type_name ::= INT */ + { 164, -1 }, /* (68) type_name ::= INTEGER */ + { 164, -1 }, /* (69) type_name ::= BIGINT */ + { 164, -1 }, /* (70) type_name ::= FLOAT */ + { 164, -1 }, /* (71) type_name ::= DOUBLE */ + { 164, -4 }, /* (72) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 164, -1 }, /* (73) type_name ::= TIMESTAMP */ + { 164, -4 }, /* (74) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 164, -2 }, /* (75) type_name ::= TINYINT UNSIGNED */ + { 164, -2 }, /* (76) type_name ::= SMALLINT UNSIGNED */ + { 164, -2 }, /* (77) type_name ::= INT UNSIGNED */ + { 164, -2 }, /* (78) type_name ::= BIGINT UNSIGNED */ + { 164, -1 }, /* (79) type_name ::= JSON */ + { 164, -4 }, /* (80) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 164, -1 }, /* (81) type_name ::= MEDIUMBLOB */ + { 164, -1 }, /* (82) type_name ::= BLOB */ + { 164, -4 }, /* (83) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 164, -1 }, /* (84) type_name ::= DECIMAL */ + { 164, -4 }, /* (85) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 164, -6 }, /* (86) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 151, 0 }, /* (87) tags_def_opt ::= */ + { 151, -1 }, /* (88) tags_def_opt ::= tags_def */ + { 154, -4 }, /* (89) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 152, 0 }, /* (90) table_options ::= */ + { 152, -3 }, /* (91) table_options ::= table_options COMMENT NK_STRING */ + { 152, -3 }, /* (92) table_options ::= table_options KEEP NK_INTEGER */ + { 152, -3 }, /* (93) table_options ::= table_options TTL NK_INTEGER */ + { 152, -5 }, /* (94) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 160, -1 }, /* (95) col_name_list ::= col_name */ + { 160, -3 }, /* (96) col_name_list ::= col_name_list NK_COMMA col_name */ + { 165, -1 }, /* (97) col_name ::= column_name */ + { 141, -7 }, /* (98) cmd ::= CREATE SMA INDEX index_name ON table_name index_options */ + { 141, -9 }, /* (99) cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP */ + { 141, -5 }, /* (100) cmd ::= DROP INDEX index_name ON table_name */ + { 167, 0 }, /* (101) index_options ::= */ + { 167, -9 }, /* (102) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 167, -11 }, /* (103) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 168, -1 }, /* (104) func_list ::= func */ + { 168, -3 }, /* (105) func_list ::= func_list NK_COMMA func */ + { 171, -4 }, /* (106) func ::= function_name NK_LP expression_list NK_RP */ + { 141, -6 }, /* (107) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 141, -6 }, /* (108) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 141, -4 }, /* (109) cmd ::= DROP TOPIC exists_opt topic_name */ + { 141, -2 }, /* (110) cmd ::= SHOW VGROUPS */ + { 141, -4 }, /* (111) cmd ::= SHOW db_name NK_DOT VGROUPS */ + { 141, -2 }, /* (112) cmd ::= SHOW MNODES */ + { 141, -1 }, /* (113) cmd ::= query_expression */ + { 176, -1 }, /* (114) literal ::= NK_INTEGER */ + { 176, -1 }, /* (115) literal ::= NK_FLOAT */ + { 176, -1 }, /* (116) literal ::= NK_STRING */ + { 176, -1 }, /* (117) literal ::= NK_BOOL */ + { 176, -2 }, /* (118) literal ::= TIMESTAMP NK_STRING */ + { 176, -1 }, /* (119) literal ::= duration_literal */ + { 169, -1 }, /* (120) duration_literal ::= NK_VARIABLE */ + { 158, -1 }, /* (121) literal_list ::= literal */ + { 158, -3 }, /* (122) literal_list ::= literal_list NK_COMMA literal */ + { 146, -1 }, /* (123) db_name ::= NK_ID */ + { 161, -1 }, /* (124) table_name ::= NK_ID */ + { 163, -1 }, /* (125) column_name ::= NK_ID */ + { 172, -1 }, /* (126) function_name ::= NK_ID */ + { 177, -1 }, /* (127) table_alias ::= NK_ID */ + { 178, -1 }, /* (128) column_alias ::= NK_ID */ + { 142, -1 }, /* (129) user_name ::= NK_ID */ + { 166, -1 }, /* (130) index_name ::= NK_ID */ + { 174, -1 }, /* (131) topic_name ::= NK_ID */ + { 179, -1 }, /* (132) expression ::= literal */ + { 179, -1 }, /* (133) expression ::= column_reference */ + { 179, -4 }, /* (134) expression ::= function_name NK_LP expression_list NK_RP */ + { 179, -4 }, /* (135) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 179, -1 }, /* (136) expression ::= subquery */ + { 179, -3 }, /* (137) expression ::= NK_LP expression NK_RP */ + { 179, -2 }, /* (138) expression ::= NK_PLUS expression */ + { 179, -2 }, /* (139) expression ::= NK_MINUS expression */ + { 179, -3 }, /* (140) expression ::= expression NK_PLUS expression */ + { 179, -3 }, /* (141) expression ::= expression NK_MINUS expression */ + { 179, -3 }, /* (142) expression ::= expression NK_STAR expression */ + { 179, -3 }, /* (143) expression ::= expression NK_SLASH expression */ + { 179, -3 }, /* (144) expression ::= expression NK_REM expression */ + { 173, -1 }, /* (145) expression_list ::= expression */ + { 173, -3 }, /* (146) expression_list ::= expression_list NK_COMMA expression */ + { 180, -1 }, /* (147) column_reference ::= column_name */ + { 180, -3 }, /* (148) column_reference ::= table_name NK_DOT column_name */ + { 182, -3 }, /* (149) predicate ::= expression compare_op expression */ + { 182, -5 }, /* (150) predicate ::= expression BETWEEN expression AND expression */ + { 182, -6 }, /* (151) predicate ::= expression NOT BETWEEN expression AND expression */ + { 182, -3 }, /* (152) predicate ::= expression IS NULL */ + { 182, -4 }, /* (153) predicate ::= expression IS NOT NULL */ + { 182, -3 }, /* (154) predicate ::= expression in_op in_predicate_value */ + { 183, -1 }, /* (155) compare_op ::= NK_LT */ + { 183, -1 }, /* (156) compare_op ::= NK_GT */ + { 183, -1 }, /* (157) compare_op ::= NK_LE */ + { 183, -1 }, /* (158) compare_op ::= NK_GE */ + { 183, -1 }, /* (159) compare_op ::= NK_NE */ + { 183, -1 }, /* (160) compare_op ::= NK_EQ */ + { 183, -1 }, /* (161) compare_op ::= LIKE */ + { 183, -2 }, /* (162) compare_op ::= NOT LIKE */ + { 183, -1 }, /* (163) compare_op ::= MATCH */ + { 183, -1 }, /* (164) compare_op ::= NMATCH */ + { 184, -1 }, /* (165) in_op ::= IN */ + { 184, -2 }, /* (166) in_op ::= NOT IN */ + { 185, -3 }, /* (167) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 186, -1 }, /* (168) boolean_value_expression ::= boolean_primary */ + { 186, -2 }, /* (169) boolean_value_expression ::= NOT boolean_primary */ + { 186, -3 }, /* (170) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 186, -3 }, /* (171) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 187, -1 }, /* (172) boolean_primary ::= predicate */ + { 187, -3 }, /* (173) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 188, -1 }, /* (174) common_expression ::= expression */ + { 188, -1 }, /* (175) common_expression ::= boolean_value_expression */ + { 189, -2 }, /* (176) from_clause ::= FROM table_reference_list */ + { 190, -1 }, /* (177) table_reference_list ::= table_reference */ + { 190, -3 }, /* (178) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 191, -1 }, /* (179) table_reference ::= table_primary */ + { 191, -1 }, /* (180) table_reference ::= joined_table */ + { 192, -2 }, /* (181) table_primary ::= table_name alias_opt */ + { 192, -4 }, /* (182) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 192, -2 }, /* (183) table_primary ::= subquery alias_opt */ + { 192, -1 }, /* (184) table_primary ::= parenthesized_joined_table */ + { 194, 0 }, /* (185) alias_opt ::= */ + { 194, -1 }, /* (186) alias_opt ::= table_alias */ + { 194, -2 }, /* (187) alias_opt ::= AS table_alias */ + { 195, -3 }, /* (188) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 195, -3 }, /* (189) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 193, -6 }, /* (190) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 196, 0 }, /* (191) join_type ::= */ + { 196, -1 }, /* (192) join_type ::= INNER */ + { 198, -9 }, /* (193) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 199, 0 }, /* (194) set_quantifier_opt ::= */ + { 199, -1 }, /* (195) set_quantifier_opt ::= DISTINCT */ + { 199, -1 }, /* (196) set_quantifier_opt ::= ALL */ + { 200, -1 }, /* (197) select_list ::= NK_STAR */ + { 200, -1 }, /* (198) select_list ::= select_sublist */ + { 206, -1 }, /* (199) select_sublist ::= select_item */ + { 206, -3 }, /* (200) select_sublist ::= select_sublist NK_COMMA select_item */ + { 207, -1 }, /* (201) select_item ::= common_expression */ + { 207, -2 }, /* (202) select_item ::= common_expression column_alias */ + { 207, -3 }, /* (203) select_item ::= common_expression AS column_alias */ + { 207, -3 }, /* (204) select_item ::= table_name NK_DOT NK_STAR */ + { 201, 0 }, /* (205) where_clause_opt ::= */ + { 201, -2 }, /* (206) where_clause_opt ::= WHERE search_condition */ + { 202, 0 }, /* (207) partition_by_clause_opt ::= */ + { 202, -3 }, /* (208) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 203, 0 }, /* (209) twindow_clause_opt ::= */ + { 203, -6 }, /* (210) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ + { 203, -4 }, /* (211) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 203, -6 }, /* (212) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 203, -8 }, /* (213) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 170, 0 }, /* (214) sliding_opt ::= */ + { 170, -4 }, /* (215) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 208, 0 }, /* (216) fill_opt ::= */ + { 208, -4 }, /* (217) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 208, -6 }, /* (218) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 209, -1 }, /* (219) fill_mode ::= NONE */ + { 209, -1 }, /* (220) fill_mode ::= PREV */ + { 209, -1 }, /* (221) fill_mode ::= NULL */ + { 209, -1 }, /* (222) fill_mode ::= LINEAR */ + { 209, -1 }, /* (223) fill_mode ::= NEXT */ + { 204, 0 }, /* (224) group_by_clause_opt ::= */ + { 204, -3 }, /* (225) group_by_clause_opt ::= GROUP BY group_by_list */ + { 210, -1 }, /* (226) group_by_list ::= expression */ + { 210, -3 }, /* (227) group_by_list ::= group_by_list NK_COMMA expression */ + { 205, 0 }, /* (228) having_clause_opt ::= */ + { 205, -2 }, /* (229) having_clause_opt ::= HAVING search_condition */ + { 175, -4 }, /* (230) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 211, -1 }, /* (231) query_expression_body ::= query_primary */ + { 211, -4 }, /* (232) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 215, -1 }, /* (233) query_primary ::= query_specification */ + { 212, 0 }, /* (234) order_by_clause_opt ::= */ + { 212, -3 }, /* (235) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 213, 0 }, /* (236) slimit_clause_opt ::= */ + { 213, -2 }, /* (237) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 213, -4 }, /* (238) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 213, -4 }, /* (239) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 214, 0 }, /* (240) limit_clause_opt ::= */ + { 214, -2 }, /* (241) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 214, -4 }, /* (242) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 214, -4 }, /* (243) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 181, -3 }, /* (244) subquery ::= NK_LP query_expression NK_RP */ + { 197, -1 }, /* (245) search_condition ::= common_expression */ + { 216, -1 }, /* (246) sort_specification_list ::= sort_specification */ + { 216, -3 }, /* (247) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 217, -3 }, /* (248) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 218, 0 }, /* (249) ordering_specification_opt ::= */ + { 218, -1 }, /* (250) ordering_specification_opt ::= ASC */ + { 218, -1 }, /* (251) ordering_specification_opt ::= DESC */ + { 219, 0 }, /* (252) null_ordering_opt ::= */ + { 219, -2 }, /* (253) null_ordering_opt ::= NULLS FIRST */ + { 219, -2 }, /* (254) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1959,31 +1991,31 @@ static YYACTIONTYPE yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0);} +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } break; case 1: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy5, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0);} +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy129, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 2: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy5, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0);} +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy129, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 3: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy129); } break; case 4: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); } break; case 5: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy5, NULL);} +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy129, NULL); } break; case 6: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0);} +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } break; case 7: /* cmd ::= DROP DNODE NK_INTEGER */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0);} +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 8: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy5);} +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy129); } break; case 9: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); } @@ -1991,742 +2023,761 @@ static YYACTIONTYPE yy_reduce( case 10: /* dnode_endpoint ::= NK_STRING */ case 11: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==11); case 12: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==12); - case 117: /* db_name ::= NK_ID */ yytestcase(yyruleno==117); - case 118: /* table_name ::= NK_ID */ yytestcase(yyruleno==118); - case 119: /* column_name ::= NK_ID */ yytestcase(yyruleno==119); - case 120: /* function_name ::= NK_ID */ yytestcase(yyruleno==120); - case 121: /* table_alias ::= NK_ID */ yytestcase(yyruleno==121); - case 122: /* column_alias ::= NK_ID */ yytestcase(yyruleno==122); - case 123: /* user_name ::= NK_ID */ yytestcase(yyruleno==123); - case 124: /* index_name ::= NK_ID */ yytestcase(yyruleno==124); -{ yylhsminor.yy5 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy5 = yylhsminor.yy5; + case 123: /* db_name ::= NK_ID */ yytestcase(yyruleno==123); + case 124: /* table_name ::= NK_ID */ yytestcase(yyruleno==124); + case 125: /* column_name ::= NK_ID */ yytestcase(yyruleno==125); + case 126: /* function_name ::= NK_ID */ yytestcase(yyruleno==126); + case 127: /* table_alias ::= NK_ID */ yytestcase(yyruleno==127); + case 128: /* column_alias ::= NK_ID */ yytestcase(yyruleno==128); + case 129: /* user_name ::= NK_ID */ yytestcase(yyruleno==129); + case 130: /* index_name ::= NK_ID */ yytestcase(yyruleno==130); + case 131: /* topic_name ::= NK_ID */ yytestcase(yyruleno==131); +{ yylhsminor.yy129 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; case 13: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 14: /* cmd ::= SHOW QNODES */ + case 14: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ +{ pCxt->pRootNode = createDropQnodeStmt(pCxt, &yymsp[0].minor.yy0); } + break; + case 15: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); } break; - case 15: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy25, &yymsp[-1].minor.yy5, yymsp[0].minor.yy68);} + case 16: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy97, &yymsp[-1].minor.yy129, yymsp[0].minor.yy432); } break; - case 16: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy25, &yymsp[0].minor.yy5); } + case 17: /* cmd ::= DROP DATABASE exists_opt db_name */ +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy97, &yymsp[0].minor.yy129); } break; - case 17: /* cmd ::= SHOW DATABASES */ + case 18: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); } break; - case 18: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy5);} + case 19: /* cmd ::= USE db_name */ +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy129); } break; - case 19: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy25 = true; } + case 20: /* cmd ::= ALTER DATABASE db_name db_options */ +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy432); } break; - case 20: /* not_exists_opt ::= */ - case 22: /* exists_opt ::= */ yytestcase(yyruleno==22); - case 187: /* set_quantifier_opt ::= */ yytestcase(yyruleno==187); -{ yymsp[1].minor.yy25 = false; } + case 21: /* not_exists_opt ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy97 = true; } break; - case 21: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy25 = true; } + case 22: /* not_exists_opt ::= */ + case 24: /* exists_opt ::= */ yytestcase(yyruleno==24); + case 194: /* set_quantifier_opt ::= */ yytestcase(yyruleno==194); +{ yymsp[1].minor.yy97 = false; } break; - case 23: /* db_options ::= */ -{ yymsp[1].minor.yy68 = createDefaultDatabaseOptions(pCxt); } + case 23: /* exists_opt ::= IF EXISTS */ +{ yymsp[-1].minor.yy97 = true; } break; - case 24: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 25: /* db_options ::= */ +{ yymsp[1].minor.yy432 = createDefaultDatabaseOptions(pCxt); } break; - case 25: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 26: /* db_options ::= db_options BLOCKS NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 26: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 27: /* db_options ::= db_options CACHE NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 27: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 28: /* db_options ::= db_options CACHELAST NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 28: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 29: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 29: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 30: /* db_options ::= db_options DAYS NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 30: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 31: /* db_options ::= db_options FSYNC NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 31: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 32: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 32: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 33: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 33: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 34: /* db_options ::= db_options KEEP NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 34: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 35: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 35: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 36: /* db_options ::= db_options QUORUM NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 36: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 37: /* db_options ::= db_options REPLICA NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 37: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 38: /* db_options ::= db_options TTL NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 38: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 39: /* db_options ::= db_options WAL NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 39: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_SINGLESTABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 40: /* db_options ::= db_options VGROUPS NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 40: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy68 = setDatabaseOption(pCxt, yymsp[-2].minor.yy68, DB_OPTION_STREAMMODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 41: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_SINGLESTABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 41: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 43: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==43); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy25, yymsp[-5].minor.yy68, yymsp[-3].minor.yy40, yymsp[-1].minor.yy40, yymsp[0].minor.yy68);} + case 42: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ +{ yylhsminor.yy432 = setDatabaseOption(pCxt, yymsp[-2].minor.yy432, DB_OPTION_STREAMMODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 42: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy40);} + case 43: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 45: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==45); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy97, yymsp[-5].minor.yy432, yymsp[-3].minor.yy24, yymsp[-1].minor.yy24, yymsp[0].minor.yy432);} break; - case 44: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy40); } + case 44: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy24);} break; - case 45: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy25, yymsp[0].minor.yy68); } + case 46: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy24); } break; - case 46: /* cmd ::= SHOW TABLES */ + case 47: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy97, yymsp[0].minor.yy432); } + break; + case 48: /* cmd ::= SHOW TABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); } break; - case 47: /* cmd ::= SHOW STABLES */ + case 49: /* cmd ::= SHOW STABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); } break; - case 48: /* multi_create_clause ::= create_subtable_clause */ - case 51: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==51); - case 58: /* column_def_list ::= column_def */ yytestcase(yyruleno==58); - case 93: /* col_name_list ::= col_name */ yytestcase(yyruleno==93); - case 101: /* func_list ::= func */ yytestcase(yyruleno==101); - case 192: /* select_sublist ::= select_item */ yytestcase(yyruleno==192); - case 239: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==239); -{ yylhsminor.yy40 = createNodeList(pCxt, yymsp[0].minor.yy68); } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 50: /* multi_create_clause ::= create_subtable_clause */ + case 53: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==53); + case 60: /* column_def_list ::= column_def */ yytestcase(yyruleno==60); + case 95: /* col_name_list ::= col_name */ yytestcase(yyruleno==95); + case 104: /* func_list ::= func */ yytestcase(yyruleno==104); + case 199: /* select_sublist ::= select_item */ yytestcase(yyruleno==199); + case 246: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==246); +{ yylhsminor.yy24 = createNodeList(pCxt, yymsp[0].minor.yy432); } + yymsp[0].minor.yy24 = yylhsminor.yy24; break; - case 49: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 52: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==52); -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-1].minor.yy40, yymsp[0].minor.yy68); } - yymsp[-1].minor.yy40 = yylhsminor.yy40; + case 51: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 54: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==54); +{ yylhsminor.yy24 = addNodeToList(pCxt, yymsp[-1].minor.yy24, yymsp[0].minor.yy432); } + yymsp[-1].minor.yy24 = yylhsminor.yy24; break; - case 50: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy68 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy25, yymsp[-7].minor.yy68, yymsp[-5].minor.yy68, yymsp[-4].minor.yy40, yymsp[-1].minor.yy40); } - yymsp[-8].minor.yy68 = yylhsminor.yy68; + case 52: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ +{ yylhsminor.yy432 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy97, yymsp[-7].minor.yy432, yymsp[-5].minor.yy432, yymsp[-4].minor.yy24, yymsp[-1].minor.yy24); } + yymsp[-8].minor.yy432 = yylhsminor.yy432; break; - case 53: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy68 = createDropTableClause(pCxt, yymsp[-1].minor.yy25, yymsp[0].minor.yy68); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 55: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy432 = createDropTableClause(pCxt, yymsp[-1].minor.yy97, yymsp[0].minor.yy432); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 54: /* specific_tags_opt ::= */ - case 85: /* tags_def_opt ::= */ yytestcase(yyruleno==85); - case 200: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==200); - case 217: /* group_by_clause_opt ::= */ yytestcase(yyruleno==217); - case 227: /* order_by_clause_opt ::= */ yytestcase(yyruleno==227); -{ yymsp[1].minor.yy40 = NULL; } + case 56: /* specific_tags_opt ::= */ + case 87: /* tags_def_opt ::= */ yytestcase(yyruleno==87); + case 207: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==207); + case 224: /* group_by_clause_opt ::= */ yytestcase(yyruleno==224); + case 234: /* order_by_clause_opt ::= */ yytestcase(yyruleno==234); +{ yymsp[1].minor.yy24 = NULL; } break; - case 55: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy40 = yymsp[-1].minor.yy40; } + case 57: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy24 = yymsp[-1].minor.yy24; } break; - case 56: /* full_table_name ::= table_name */ -{ yylhsminor.yy68 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy5, NULL); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 58: /* full_table_name ::= table_name */ +{ yylhsminor.yy432 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy129, NULL); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 57: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy68 = createRealTableNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5, NULL); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 59: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy432 = createRealTableNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, NULL); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 59: /* column_def_list ::= column_def_list NK_COMMA column_def */ - case 94: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==94); - case 102: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==102); - case 193: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==193); - case 240: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==240); -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, yymsp[0].minor.yy68); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 61: /* column_def_list ::= column_def_list NK_COMMA column_def */ + case 96: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==96); + case 105: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==105); + case 200: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==200); + case 247: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==247); +{ yylhsminor.yy24 = addNodeToList(pCxt, yymsp[-2].minor.yy24, yymsp[0].minor.yy432); } + yymsp[-2].minor.yy24 = yylhsminor.yy24; break; - case 60: /* column_def ::= column_name type_name */ -{ yylhsminor.yy68 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy5, yymsp[0].minor.yy372, NULL); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 62: /* column_def ::= column_name type_name */ +{ yylhsminor.yy432 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy224, NULL); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 61: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy68 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-2].minor.yy372, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 63: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy432 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-2].minor.yy224, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 62: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 64: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 63: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 65: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 64: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 66: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 65: /* type_name ::= INT */ - case 66: /* type_name ::= INTEGER */ yytestcase(yyruleno==66); -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_INT); } + case 67: /* type_name ::= INT */ + case 68: /* type_name ::= INTEGER */ yytestcase(yyruleno==68); +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 67: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 69: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 68: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 70: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 69: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 71: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 70: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy372 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 72: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 71: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 73: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 72: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy372 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 74: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 73: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy372 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 75: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 74: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy372 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 76: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 75: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy372 = createDataType(TSDB_DATA_TYPE_UINT); } + case 77: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 76: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy372 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 78: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy224 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 77: /* type_name ::= JSON */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_JSON); } + case 79: /* type_name ::= JSON */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 78: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy372 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 80: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 79: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 81: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 80: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 82: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 81: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy372 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 83: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 82: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy372 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 84: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 83: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy372 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 85: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 84: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy372 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 86: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy224 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 86: /* tags_def_opt ::= tags_def */ - case 191: /* select_list ::= select_sublist */ yytestcase(yyruleno==191); -{ yylhsminor.yy40 = yymsp[0].minor.yy40; } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 88: /* tags_def_opt ::= tags_def */ + case 198: /* select_list ::= select_sublist */ yytestcase(yyruleno==198); +{ yylhsminor.yy24 = yymsp[0].minor.yy24; } + yymsp[0].minor.yy24 = yylhsminor.yy24; break; - case 87: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy40 = yymsp[-1].minor.yy40; } + case 89: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy24 = yymsp[-1].minor.yy24; } break; - case 88: /* table_options ::= */ -{ yymsp[1].minor.yy68 = createDefaultTableOptions(pCxt);} + case 90: /* table_options ::= */ +{ yymsp[1].minor.yy432 = createDefaultTableOptions(pCxt);} break; - case 89: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy68 = setTableOption(pCxt, yymsp[-2].minor.yy68, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 91: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy432 = setTableOption(pCxt, yymsp[-2].minor.yy432, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 90: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy68 = setTableOption(pCxt, yymsp[-2].minor.yy68, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 92: /* table_options ::= table_options KEEP NK_INTEGER */ +{ yylhsminor.yy432 = setTableOption(pCxt, yymsp[-2].minor.yy432, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 91: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy68 = setTableOption(pCxt, yymsp[-2].minor.yy68, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 93: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy432 = setTableOption(pCxt, yymsp[-2].minor.yy432, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 92: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy68 = setTableSmaOption(pCxt, yymsp[-4].minor.yy68, yymsp[-1].minor.yy40); } - yymsp[-4].minor.yy68 = yylhsminor.yy68; + case 94: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy432 = setTableSmaOption(pCxt, yymsp[-4].minor.yy432, yymsp[-1].minor.yy24); } + yymsp[-4].minor.yy432 = yylhsminor.yy432; break; - case 95: /* col_name ::= column_name */ -{ yylhsminor.yy68 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy5); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 97: /* col_name ::= column_name */ +{ yylhsminor.yy432 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 96: /* cmd ::= CREATE SMA INDEX index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &yymsp[-3].minor.yy5, &yymsp[-1].minor.yy5, NULL, yymsp[0].minor.yy68); } + case 98: /* cmd ::= CREATE SMA INDEX index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &yymsp[-3].minor.yy129, &yymsp[-1].minor.yy129, NULL, yymsp[0].minor.yy432); } break; - case 97: /* cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &yymsp[-5].minor.yy5, &yymsp[-3].minor.yy5, yymsp[-1].minor.yy40, NULL); } + case 99: /* cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &yymsp[-5].minor.yy129, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy24, NULL); } break; - case 98: /* index_options ::= */ - case 198: /* where_clause_opt ::= */ yytestcase(yyruleno==198); - case 202: /* twindow_clause_opt ::= */ yytestcase(yyruleno==202); - case 207: /* sliding_opt ::= */ yytestcase(yyruleno==207); - case 209: /* fill_opt ::= */ yytestcase(yyruleno==209); - case 221: /* having_clause_opt ::= */ yytestcase(yyruleno==221); - case 229: /* slimit_clause_opt ::= */ yytestcase(yyruleno==229); - case 233: /* limit_clause_opt ::= */ yytestcase(yyruleno==233); -{ yymsp[1].minor.yy68 = NULL; } + case 100: /* cmd ::= DROP INDEX index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129); } break; - case 99: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy68 = createIndexOption(pCxt, yymsp[-6].minor.yy40, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), NULL, yymsp[0].minor.yy68); } + case 101: /* index_options ::= */ + case 205: /* where_clause_opt ::= */ yytestcase(yyruleno==205); + case 209: /* twindow_clause_opt ::= */ yytestcase(yyruleno==209); + case 214: /* sliding_opt ::= */ yytestcase(yyruleno==214); + case 216: /* fill_opt ::= */ yytestcase(yyruleno==216); + case 228: /* having_clause_opt ::= */ yytestcase(yyruleno==228); + case 236: /* slimit_clause_opt ::= */ yytestcase(yyruleno==236); + case 240: /* limit_clause_opt ::= */ yytestcase(yyruleno==240); +{ yymsp[1].minor.yy432 = NULL; } break; - case 100: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy68 = createIndexOption(pCxt, yymsp[-8].minor.yy40, releaseRawExprNode(pCxt, yymsp[-4].minor.yy68), releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), yymsp[0].minor.yy68); } + case 102: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy432 = createIndexOption(pCxt, yymsp[-6].minor.yy24, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), NULL, yymsp[0].minor.yy432); } break; - case 103: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy68 = createFunctionNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-1].minor.yy40); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 103: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy432 = createIndexOption(pCxt, yymsp[-8].minor.yy24, releaseRawExprNode(pCxt, yymsp[-4].minor.yy432), releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), yymsp[0].minor.yy432); } break; - case 104: /* cmd ::= SHOW VGROUPS */ + case 106: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy432 = createFunctionNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy24); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; + break; + case 107: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy97, &yymsp[-2].minor.yy129, yymsp[0].minor.yy432, NULL); } + break; + case 108: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy97, &yymsp[-2].minor.yy129, NULL, &yymsp[0].minor.yy129); } + break; + case 109: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy97, &yymsp[0].minor.yy129); } + break; + case 110: /* cmd ::= SHOW VGROUPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); } break; - case 105: /* cmd ::= SHOW db_name NK_DOT VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy5); } + case 111: /* cmd ::= SHOW db_name NK_DOT VGROUPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy129); } break; - case 106: /* cmd ::= SHOW MNODES */ + case 112: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL); } break; - case 107: /* cmd ::= query_expression */ -{ pCxt->pRootNode = yymsp[0].minor.yy68; } + case 113: /* cmd ::= query_expression */ +{ pCxt->pRootNode = yymsp[0].minor.yy432; } break; - case 108: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 114: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 109: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 115: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 110: /* literal ::= NK_STRING */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 116: /* literal ::= NK_STRING */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 111: /* literal ::= NK_BOOL */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 117: /* literal ::= NK_BOOL */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 112: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 118: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 113: /* literal ::= duration_literal */ - case 125: /* expression ::= literal */ yytestcase(yyruleno==125); - case 126: /* expression ::= column_reference */ yytestcase(yyruleno==126); - case 129: /* expression ::= subquery */ yytestcase(yyruleno==129); - case 161: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==161); - case 165: /* boolean_primary ::= predicate */ yytestcase(yyruleno==165); - case 167: /* common_expression ::= expression */ yytestcase(yyruleno==167); - case 168: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==168); - case 170: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==170); - case 172: /* table_reference ::= table_primary */ yytestcase(yyruleno==172); - case 173: /* table_reference ::= joined_table */ yytestcase(yyruleno==173); - case 177: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==177); - case 224: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==224); - case 226: /* query_primary ::= query_specification */ yytestcase(yyruleno==226); -{ yylhsminor.yy68 = yymsp[0].minor.yy68; } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 119: /* literal ::= duration_literal */ + case 132: /* expression ::= literal */ yytestcase(yyruleno==132); + case 133: /* expression ::= column_reference */ yytestcase(yyruleno==133); + case 136: /* expression ::= subquery */ yytestcase(yyruleno==136); + case 168: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==168); + case 172: /* boolean_primary ::= predicate */ yytestcase(yyruleno==172); + case 174: /* common_expression ::= expression */ yytestcase(yyruleno==174); + case 175: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==175); + case 177: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==177); + case 179: /* table_reference ::= table_primary */ yytestcase(yyruleno==179); + case 180: /* table_reference ::= joined_table */ yytestcase(yyruleno==180); + case 184: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==184); + case 231: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==231); + case 233: /* query_primary ::= query_specification */ yytestcase(yyruleno==233); +{ yylhsminor.yy432 = yymsp[0].minor.yy432; } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 114: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 120: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 115: /* literal_list ::= literal */ - case 138: /* expression_list ::= expression */ yytestcase(yyruleno==138); -{ yylhsminor.yy40 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy68)); } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 121: /* literal_list ::= literal */ + case 145: /* expression_list ::= expression */ yytestcase(yyruleno==145); +{ yylhsminor.yy24 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy432)); } + yymsp[0].minor.yy24 = yylhsminor.yy24; break; - case 116: /* literal_list ::= literal_list NK_COMMA literal */ - case 139: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==139); -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, releaseRawExprNode(pCxt, yymsp[0].minor.yy68)); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 122: /* literal_list ::= literal_list NK_COMMA literal */ + case 146: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==146); +{ yylhsminor.yy24 = addNodeToList(pCxt, yymsp[-2].minor.yy24, releaseRawExprNode(pCxt, yymsp[0].minor.yy432)); } + yymsp[-2].minor.yy24 = yylhsminor.yy24; break; - case 127: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy5, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-1].minor.yy40)); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 134: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy129, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy24)); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 128: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy5, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy5, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 135: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy129, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy129, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 130: /* expression ::= NK_LP expression NK_RP */ - case 166: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==166); -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy68)); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 137: /* expression ::= NK_LP expression NK_RP */ + case 173: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==173); +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy432)); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 131: /* expression ::= NK_PLUS expression */ + case 138: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy68)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy432)); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 132: /* expression ::= NK_MINUS expression */ + case 139: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy68), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy432), NULL)); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 133: /* expression ::= expression NK_PLUS expression */ + case 140: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 134: /* expression ::= expression NK_MINUS expression */ + case 141: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 135: /* expression ::= expression NK_STAR expression */ + case 142: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 136: /* expression ::= expression NK_SLASH expression */ + case 143: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 137: /* expression ::= expression NK_REM expression */ + case 144: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 140: /* column_reference ::= column_name */ -{ yylhsminor.yy68 = createRawExprNode(pCxt, &yymsp[0].minor.yy5, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy5)); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 147: /* column_reference ::= column_name */ +{ yylhsminor.yy432 = createRawExprNode(pCxt, &yymsp[0].minor.yy129, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129)); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 141: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5, createColumnNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5)); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 148: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129)); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 142: /* predicate ::= expression compare_op expression */ - case 147: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==147); + case 149: /* predicate ::= expression compare_op expression */ + case 154: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==154); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy416, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy260, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 143: /* predicate ::= expression BETWEEN expression AND expression */ + case 150: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy68), releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy432), releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-4].minor.yy68 = yylhsminor.yy68; + yymsp[-4].minor.yy432 = yylhsminor.yy432; break; - case 144: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 151: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[-5].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[-5].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-5].minor.yy68 = yylhsminor.yy68; + yymsp[-5].minor.yy432 = yylhsminor.yy432; break; - case 145: /* predicate ::= expression IS NULL */ + case 152: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), NULL)); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 146: /* predicate ::= expression IS NOT NULL */ + case 153: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy68), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy432), NULL)); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 148: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy416 = OP_TYPE_LOWER_THAN; } + case 155: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy260 = OP_TYPE_LOWER_THAN; } break; - case 149: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy416 = OP_TYPE_GREATER_THAN; } + case 156: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy260 = OP_TYPE_GREATER_THAN; } break; - case 150: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy416 = OP_TYPE_LOWER_EQUAL; } + case 157: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy260 = OP_TYPE_LOWER_EQUAL; } break; - case 151: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy416 = OP_TYPE_GREATER_EQUAL; } + case 158: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy260 = OP_TYPE_GREATER_EQUAL; } break; - case 152: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy416 = OP_TYPE_NOT_EQUAL; } + case 159: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy260 = OP_TYPE_NOT_EQUAL; } break; - case 153: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy416 = OP_TYPE_EQUAL; } + case 160: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy260 = OP_TYPE_EQUAL; } break; - case 154: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy416 = OP_TYPE_LIKE; } + case 161: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy260 = OP_TYPE_LIKE; } break; - case 155: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy416 = OP_TYPE_NOT_LIKE; } + case 162: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy260 = OP_TYPE_NOT_LIKE; } break; - case 156: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy416 = OP_TYPE_MATCH; } + case 163: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy260 = OP_TYPE_MATCH; } break; - case 157: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy416 = OP_TYPE_NMATCH; } + case 164: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy260 = OP_TYPE_NMATCH; } break; - case 158: /* in_op ::= IN */ -{ yymsp[0].minor.yy416 = OP_TYPE_IN; } + case 165: /* in_op ::= IN */ +{ yymsp[0].minor.yy260 = OP_TYPE_IN; } break; - case 159: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy416 = OP_TYPE_NOT_IN; } + case 166: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy260 = OP_TYPE_NOT_IN; } break; - case 160: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 167: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy24)); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 162: /* boolean_value_expression ::= NOT boolean_primary */ + case 169: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy68), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy432), NULL)); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 163: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 170: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 164: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 171: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy68); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy432); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 169: /* from_clause ::= FROM table_reference_list */ - case 199: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==199); - case 222: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==222); -{ yymsp[-1].minor.yy68 = yymsp[0].minor.yy68; } + case 176: /* from_clause ::= FROM table_reference_list */ + case 206: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==206); + case 229: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==229); +{ yymsp[-1].minor.yy432 = yymsp[0].minor.yy432; } break; - case 171: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy68 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy68, yymsp[0].minor.yy68, NULL); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 178: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy432 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy432, yymsp[0].minor.yy432, NULL); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 174: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy68 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 181: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy432 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 175: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy68 = createRealTableNode(pCxt, &yymsp[-3].minor.yy5, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 182: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy432 = createRealTableNode(pCxt, &yymsp[-3].minor.yy129, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 176: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy68 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy68), &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 183: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy432 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy432), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 178: /* alias_opt ::= */ -{ yymsp[1].minor.yy5 = nil_token; } + case 185: /* alias_opt ::= */ +{ yymsp[1].minor.yy129 = nil_token; } break; - case 179: /* alias_opt ::= table_alias */ -{ yylhsminor.yy5 = yymsp[0].minor.yy5; } - yymsp[0].minor.yy5 = yylhsminor.yy5; + case 186: /* alias_opt ::= table_alias */ +{ yylhsminor.yy129 = yymsp[0].minor.yy129; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; - case 180: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy5 = yymsp[0].minor.yy5; } + case 187: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy129 = yymsp[0].minor.yy129; } break; - case 181: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 182: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==182); -{ yymsp[-2].minor.yy68 = yymsp[-1].minor.yy68; } + case 188: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 189: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==189); +{ yymsp[-2].minor.yy432 = yymsp[-1].minor.yy432; } break; - case 183: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy68 = createJoinTableNode(pCxt, yymsp[-4].minor.yy92, yymsp[-5].minor.yy68, yymsp[-2].minor.yy68, yymsp[0].minor.yy68); } - yymsp[-5].minor.yy68 = yylhsminor.yy68; + case 190: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy432 = createJoinTableNode(pCxt, yymsp[-4].minor.yy332, yymsp[-5].minor.yy432, yymsp[-2].minor.yy432, yymsp[0].minor.yy432); } + yymsp[-5].minor.yy432 = yylhsminor.yy432; break; - case 184: /* join_type ::= */ -{ yymsp[1].minor.yy92 = JOIN_TYPE_INNER; } + case 191: /* join_type ::= */ +{ yymsp[1].minor.yy332 = JOIN_TYPE_INNER; } break; - case 185: /* join_type ::= INNER */ -{ yymsp[0].minor.yy92 = JOIN_TYPE_INNER; } + case 192: /* join_type ::= INNER */ +{ yymsp[0].minor.yy332 = JOIN_TYPE_INNER; } break; - case 186: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 193: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy68 = createSelectStmt(pCxt, yymsp[-7].minor.yy25, yymsp[-6].minor.yy40, yymsp[-5].minor.yy68); - yymsp[-8].minor.yy68 = addWhereClause(pCxt, yymsp[-8].minor.yy68, yymsp[-4].minor.yy68); - yymsp[-8].minor.yy68 = addPartitionByClause(pCxt, yymsp[-8].minor.yy68, yymsp[-3].minor.yy40); - yymsp[-8].minor.yy68 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy68, yymsp[-2].minor.yy68); - yymsp[-8].minor.yy68 = addGroupByClause(pCxt, yymsp[-8].minor.yy68, yymsp[-1].minor.yy40); - yymsp[-8].minor.yy68 = addHavingClause(pCxt, yymsp[-8].minor.yy68, yymsp[0].minor.yy68); + yymsp[-8].minor.yy432 = createSelectStmt(pCxt, yymsp[-7].minor.yy97, yymsp[-6].minor.yy24, yymsp[-5].minor.yy432); + yymsp[-8].minor.yy432 = addWhereClause(pCxt, yymsp[-8].minor.yy432, yymsp[-4].minor.yy432); + yymsp[-8].minor.yy432 = addPartitionByClause(pCxt, yymsp[-8].minor.yy432, yymsp[-3].minor.yy24); + yymsp[-8].minor.yy432 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy432, yymsp[-2].minor.yy432); + yymsp[-8].minor.yy432 = addGroupByClause(pCxt, yymsp[-8].minor.yy432, yymsp[-1].minor.yy24); + yymsp[-8].minor.yy432 = addHavingClause(pCxt, yymsp[-8].minor.yy432, yymsp[0].minor.yy432); } break; - case 188: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy25 = true; } + case 195: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy97 = true; } break; - case 189: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy25 = false; } + case 196: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy97 = false; } break; - case 190: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy40 = NULL; } + case 197: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy24 = NULL; } break; - case 194: /* select_item ::= common_expression */ + case 201: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy68); - yylhsminor.yy68 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy68), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy432); + yylhsminor.yy432 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy432), &t); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 195: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy68 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy68), &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy68 = yylhsminor.yy68; + case 202: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy432 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy432), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy432 = yylhsminor.yy432; break; - case 196: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy68 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), &yymsp[0].minor.yy5); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 203: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy432 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), &yymsp[0].minor.yy129); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 197: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy68 = createColumnNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 204: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy432 = createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 201: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 218: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==218); - case 228: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==228); -{ yymsp[-2].minor.yy40 = yymsp[0].minor.yy40; } + case 208: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 225: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==225); + case 235: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==235); +{ yymsp[-2].minor.yy24 = yymsp[0].minor.yy24; } break; - case 203: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy68 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy68), &yymsp[-1].minor.yy0); } + case 210: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy432 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy432), &yymsp[-1].minor.yy0); } break; - case 204: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy68 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy68)); } + case 211: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy432 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy432)); } break; - case 205: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy68 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy68), NULL, yymsp[-1].minor.yy68, yymsp[0].minor.yy68); } + case 212: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy432 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy432), NULL, yymsp[-1].minor.yy432, yymsp[0].minor.yy432); } break; - case 206: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy68 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy68), releaseRawExprNode(pCxt, yymsp[-3].minor.yy68), yymsp[-1].minor.yy68, yymsp[0].minor.yy68); } + case 213: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy432 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy432), releaseRawExprNode(pCxt, yymsp[-3].minor.yy432), yymsp[-1].minor.yy432, yymsp[0].minor.yy432); } break; - case 208: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy68 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy68); } + case 215: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy432 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy432); } break; - case 210: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy68 = createFillNode(pCxt, yymsp[-1].minor.yy94, NULL); } + case 217: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy432 = createFillNode(pCxt, yymsp[-1].minor.yy294, NULL); } break; - case 211: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy68 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy40)); } + case 218: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy432 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy24)); } break; - case 212: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy94 = FILL_MODE_NONE; } + case 219: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy294 = FILL_MODE_NONE; } break; - case 213: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy94 = FILL_MODE_PREV; } + case 220: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy294 = FILL_MODE_PREV; } break; - case 214: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy94 = FILL_MODE_NULL; } + case 221: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy294 = FILL_MODE_NULL; } break; - case 215: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy94 = FILL_MODE_LINEAR; } + case 222: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy294 = FILL_MODE_LINEAR; } break; - case 216: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy94 = FILL_MODE_NEXT; } + case 223: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy294 = FILL_MODE_NEXT; } break; - case 219: /* group_by_list ::= expression */ -{ yylhsminor.yy40 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); } - yymsp[0].minor.yy40 = yylhsminor.yy40; + case 226: /* group_by_list ::= expression */ +{ yylhsminor.yy24 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } + yymsp[0].minor.yy24 = yylhsminor.yy24; break; - case 220: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy40 = addNodeToList(pCxt, yymsp[-2].minor.yy40, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy68))); } - yymsp[-2].minor.yy40 = yylhsminor.yy40; + case 227: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy24 = addNodeToList(pCxt, yymsp[-2].minor.yy24, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy432))); } + yymsp[-2].minor.yy24 = yylhsminor.yy24; break; - case 223: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 230: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy68 = addOrderByClause(pCxt, yymsp[-3].minor.yy68, yymsp[-2].minor.yy40); - yylhsminor.yy68 = addSlimitClause(pCxt, yylhsminor.yy68, yymsp[-1].minor.yy68); - yylhsminor.yy68 = addLimitClause(pCxt, yylhsminor.yy68, yymsp[0].minor.yy68); + yylhsminor.yy432 = addOrderByClause(pCxt, yymsp[-3].minor.yy432, yymsp[-2].minor.yy24); + yylhsminor.yy432 = addSlimitClause(pCxt, yylhsminor.yy432, yymsp[-1].minor.yy432); + yylhsminor.yy432 = addLimitClause(pCxt, yylhsminor.yy432, yymsp[0].minor.yy432); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 225: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy68 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy68, yymsp[0].minor.yy68); } - yymsp[-3].minor.yy68 = yylhsminor.yy68; + case 232: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy432 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy432, yymsp[0].minor.yy432); } + yymsp[-3].minor.yy432 = yylhsminor.yy432; break; - case 230: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 234: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==234); -{ yymsp[-1].minor.yy68 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 237: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 241: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==241); +{ yymsp[-1].minor.yy432 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 231: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 235: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==235); -{ yymsp[-3].minor.yy68 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 238: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 242: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==242); +{ yymsp[-3].minor.yy432 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 232: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 236: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==236); -{ yymsp[-3].minor.yy68 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 239: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 243: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==243); +{ yymsp[-3].minor.yy432 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 237: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy68 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy68); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 244: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy432 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy432); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 238: /* search_condition ::= common_expression */ -{ yylhsminor.yy68 = releaseRawExprNode(pCxt, yymsp[0].minor.yy68); } - yymsp[0].minor.yy68 = yylhsminor.yy68; + case 245: /* search_condition ::= common_expression */ +{ yylhsminor.yy432 = releaseRawExprNode(pCxt, yymsp[0].minor.yy432); } + yymsp[0].minor.yy432 = yylhsminor.yy432; break; - case 241: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy68 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy68), yymsp[-1].minor.yy54, yymsp[0].minor.yy53); } - yymsp[-2].minor.yy68 = yylhsminor.yy68; + case 248: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy432 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy432), yymsp[-1].minor.yy378, yymsp[0].minor.yy257); } + yymsp[-2].minor.yy432 = yylhsminor.yy432; break; - case 242: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy54 = ORDER_ASC; } + case 249: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy378 = ORDER_ASC; } break; - case 243: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy54 = ORDER_ASC; } + case 250: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy378 = ORDER_ASC; } break; - case 244: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy54 = ORDER_DESC; } + case 251: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy378 = ORDER_DESC; } break; - case 245: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy53 = NULL_ORDER_DEFAULT; } + case 252: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy257 = NULL_ORDER_DEFAULT; } break; - case 246: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy53 = NULL_ORDER_FIRST; } + case 253: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy257 = NULL_ORDER_FIRST; } break; - case 247: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy53 = NULL_ORDER_LAST; } + case 254: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy257 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 259c4712ba..f4c1bde478 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -340,6 +340,23 @@ TEST_F(ParserTest, createDatabase) { ASSERT_TRUE(run()); } +TEST_F(ParserTest, alterDatabase) { + setDatabase("root", "test"); + + bind("alter database wxy_db BLOCKS 200"); + ASSERT_TRUE(run()); + + bind("alter database wxy_db " + "BLOCKS 200 " + "CACHELAST 1 " + "FSYNC 200 " + "KEEP 200 " + "QUORUM 2 " + "WAL 1 " + ); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, showDatabase) { setDatabase("root", "test"); @@ -406,9 +423,49 @@ TEST_F(ParserTest, createSmaIndex) { ASSERT_TRUE(run()); } +TEST_F(ParserTest, dropIndex) { + setDatabase("root", "test"); + + bind("drop index index1 on t1"); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, createQnode) { setDatabase("root", "test"); bind("create qnode on dnode 1"); ASSERT_TRUE(run()); } + +TEST_F(ParserTest, dropQnode) { + setDatabase("root", "test"); + + bind("drop qnode on dnode 1"); + ASSERT_TRUE(run()); +} + +TEST_F(ParserTest, createTopic) { + setDatabase("root", "test"); + + bind("create topic tp1 as select * from t1"); + ASSERT_TRUE(run()); + + bind("create topic if not exists tp1 as select * from t1"); + ASSERT_TRUE(run()); + + bind("create topic tp1 as test"); + ASSERT_TRUE(run()); + + bind("create topic if not exists tp1 as test"); + ASSERT_TRUE(run()); +} + +TEST_F(ParserTest, dropTopic) { + setDatabase("root", "test"); + + bind("drop topic tp1"); + ASSERT_TRUE(run()); + + bind("drop topic if exists tp1"); + ASSERT_TRUE(run()); +} From a9692987d9b411aaa74c1ac6deae54f84dcc2d73 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Mar 2022 14:34:09 +0800 Subject: [PATCH 05/20] handle except and update UT --- source/libs/transport/src/transSrv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index 040c12b880..ec42ab6402 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -214,7 +214,9 @@ static void uvHandleReq(SSrvConn* pConn) { // pHead = rpcDecompresSTransMsg(pHead); } else { pHead->msgLen = htonl(pHead->msgLen); - // impl later + if (pHead->secured == 1) { + pHead->msgLen -= sizeof(STransUserMsg); + } // } From 5967a4dff8c36f0754352758c900587e0c6e4c36 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Wed, 16 Mar 2022 02:53:25 -0400 Subject: [PATCH 06/20] TD-13597 create/drop topic, alter database, drop index, drop qnode statement implement --- source/dnode/mnode/impl/src/mndTopic.c | 17 +++++++++++++++-- source/dnode/mnode/impl/test/topic/topic.cpp | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 32fa3df910..e913cae1ac 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -237,6 +237,10 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { } static int32_t mndGetPlanString(SCMCreateTopicReq *pCreate, char **pStr) { + if (NULL == pCreate->ast) { + return TSDB_CODE_SUCCESS; + } + SNode* pAst = NULL; int32_t code = nodesStringToNode(pCreate->ast, &pAst); @@ -266,17 +270,23 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq topicObj.dbUid = pDb->uid; topicObj.version = 1; topicObj.sql = pCreate->sql; - topicObj.logicalPlan = NULL; + topicObj.physicalPlan = ""; + topicObj.logicalPlan = ""; topicObj.sqlLen = strlen(pCreate->sql); - if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &topicObj.physicalPlan)) { + char* pPlanStr = NULL; + if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &pPlanStr)) { mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); return -1; } + if (NULL != pPlanStr) { + topicObj.physicalPlan = pPlanStr; + } STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + tfree(pPlanStr); return -1; } mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name); @@ -284,6 +294,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); + tfree(pPlanStr); mndTransDrop(pTrans); return -1; } @@ -291,10 +302,12 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + tfree(pPlanStr); mndTransDrop(pTrans); return -1; } + tfree(pPlanStr); mndTransDrop(pTrans); return 0; } diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 79f353a4d6..73eefd875d 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -65,7 +65,7 @@ void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql, strcpy(createReq.name, topicName); createReq.igExists = 0; createReq.sql = (char*)sql; - createReq.ast = (char*)"ast"; + createReq.ast = NULL; int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); void* pReq = rpcMallocCont(contLen); From f7cd75544c3247a54de75bd8e5a6bf7b5bfa0bf2 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 15:09:56 +0800 Subject: [PATCH 07/20] sync raft store --- source/libs/sync/inc/syncIO.h | 6 +- source/libs/sync/inc/syncRaftStore.h | 15 +-- source/libs/sync/src/syncElection.c | 3 +- source/libs/sync/src/syncIO.c | 6 +- source/libs/sync/src/syncIndexMgr.c | 2 +- source/libs/sync/src/syncMain.c | 9 ++ source/libs/sync/src/syncRaftStore.c | 36 ++++-- source/libs/sync/src/syncVoteMgr.c | 4 +- source/libs/sync/test/CMakeLists.txt | 19 +++ source/libs/sync/test/syncElectTest.cpp | 121 ++++++++++++++++++++ source/libs/sync/test/syncRaftStoreTest.cpp | 56 ++++++--- 11 files changed, 239 insertions(+), 38 deletions(-) create mode 100644 source/libs/sync/test/syncElectTest.cpp diff --git a/source/libs/sync/inc/syncIO.h b/source/libs/sync/inc/syncIO.h index 09e93fda1c..5a4b7555bf 100644 --- a/source/libs/sync/inc/syncIO.h +++ b/source/libs/sync/inc/syncIO.h @@ -34,11 +34,11 @@ extern "C" { typedef struct SSyncIO { STaosQueue *pMsgQ; - STaosQset *pQset; + STaosQset * pQset; pthread_t consumerTid; - void *serverRpc; - void *clientRpc; + void * serverRpc; + void * clientRpc; SEpSet myAddr; tmr_h qTimer; diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h index 62bb94c834..355a08ac84 100644 --- a/source/libs/sync/inc/syncRaftStore.h +++ b/source/libs/sync/inc/syncRaftStore.h @@ -43,13 +43,14 @@ int32_t raftStorePersist(SRaftStore *pRaftStore); int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len); int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len); -bool raftStoreHasVoted(SRaftStore *pRaftStore); -void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId); -void raftStoreClearVote(SRaftStore *pRaftStore); -void raftStoreNextTerm(SRaftStore *pRaftStore); -void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term); -cJSON *raftStore2Json(SRaftStore *pRaftStore); -char *raftStore2Str(SRaftStore *pRaftStore); +bool raftStoreHasVoted(SRaftStore *pRaftStore); +void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId); +void raftStoreClearVote(SRaftStore *pRaftStore); +void raftStoreNextTerm(SRaftStore *pRaftStore); +void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term); +int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson); +cJSON * raftStore2Json(SRaftStore *pRaftStore); +char * raftStore2Str(SRaftStore *pRaftStore); // for debug ------------------- void raftStorePrint(SRaftStore *pObj); diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 77c3d07698..12e20ef762 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -50,6 +50,7 @@ int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) { } int32_t syncNodeElect(SSyncNode* pSyncNode) { + int32_t ret = 0; if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { syncNodeFollower2Candidate(pSyncNode); } @@ -62,7 +63,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm); syncNodeVoteForSelf(pSyncNode); - int32_t ret = syncNodeRequestVotePeers(pSyncNode); + ret = syncNodeRequestVotePeers(pSyncNode); assert(ret == 0); syncNodeResetElectTimer(pSyncNode); diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index 8176ac417a..e6a43f2bb5 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -29,7 +29,7 @@ static int32_t syncIODestroy(SSyncIO *io); static int32_t syncIOStartInternal(SSyncIO *io); static int32_t syncIOStopInternal(SSyncIO *io); -static void *syncIOConsumerFunc(void *param); +static void * syncIOConsumerFunc(void *param); static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey); @@ -234,9 +234,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO *io = param; + SSyncIO * io = param; STaosQall *qall; - SRpcMsg *pRpcMsg, rpcMsg; + SRpcMsg * pRpcMsg, rpcMsg; qall = taosAllocateQall(); while (1) { diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index 58a61ba77e..aa97104180 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -96,7 +96,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 48a57dc0fb..58710d7d1f 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -103,6 +103,12 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { assert(pSyncNode != NULL); memset(pSyncNode, 0, sizeof(SSyncNode)); + if (taosMkDir(pSyncInfo->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + sError("failed to create dir:%s since %s", pSyncInfo->path, terrstr()); + return NULL; + } + // init by SSyncInfo pSyncNode->vgId = pSyncInfo->vgId; pSyncNode->syncCfg = pSyncInfo->syncCfg; @@ -200,6 +206,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReplyCb; pSyncNode->FpOnTimeout = syncNodeOnTimeoutCb; + // start raft + syncNodeBecomeFollower(pSyncNode); + return pSyncNode; } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 9a5401e3f1..bb0eab0fdc 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -97,16 +97,32 @@ int32_t raftStorePersist(SRaftStore *pRaftStore) { return 0; } -static bool raftStoreFileExist(char *path) { return taosStatFile(path, NULL, NULL) >= 0; } +static bool raftStoreFileExist(char *path) { + bool b = taosStatFile(path, NULL, NULL) >= 0; + return b; +} int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) { assert(pRaftStore != NULL); cJSON *pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "current_term", pRaftStore->currentTerm); - cJSON_AddNumberToObject(pRoot, "vote_for_addr", pRaftStore->voteFor.addr); + + char u64Buf[128]; + snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->currentTerm); + cJSON_AddStringToObject(pRoot, "current_term", u64Buf); + + snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->voteFor.addr); + cJSON_AddStringToObject(pRoot, "vote_for_addr", u64Buf); + cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId); + uint64_t u64 = pRaftStore->voteFor.addr; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pRoot, "addr_host", host); + cJSON_AddNumberToObject(pRoot, "addr_port", port); + char *serialized = cJSON_Print(pRoot); int len2 = strlen(serialized); assert(len2 < len); @@ -125,10 +141,12 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) { cJSON *pRoot = cJSON_Parse(buf); cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term"); - pRaftStore->currentTerm = pCurrentTerm->valueint; + assert(cJSON_IsString(pCurrentTerm)); + sscanf(pCurrentTerm->valuestring, "%lu", &(pRaftStore->currentTerm)); cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr"); - pRaftStore->voteFor.addr = pVoteForAddr->valueint; + assert(cJSON_IsString(pVoteForAddr)); + sscanf(pVoteForAddr->valuestring, "%lu", &(pRaftStore->voteFor.addr)); cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid"); pRaftStore->voteFor.vgId = pVoteForVgid->valueint; @@ -139,11 +157,10 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) { bool raftStoreHasVoted(SRaftStore *pRaftStore) { bool b = syncUtilEmptyId(&(pRaftStore->voteFor)); - return b; + return (!b); } void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId) { - assert(!raftStoreHasVoted(pRaftStore)); assert(!syncUtilEmptyId(pRaftId)); pRaftStore->voteFor = *pRaftId; raftStorePersist(pRaftStore); @@ -164,6 +181,8 @@ void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) { raftStorePersist(pRaftStore); } +int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson) { return 0; } + cJSON *raftStore2Json(SRaftStore *pRaftStore) { char u64buf[128]; cJSON *pRoot = cJSON_CreateObject(); @@ -185,6 +204,9 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) { } cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId); cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor); + + int hasVoted = raftStoreHasVoted(pRaftStore); + cJSON_AddNumberToObject(pRoot, "hasVoted", hasVoted); } cJSON *pJson = cJSON_CreateObject(); diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 5830a0a54f..00851a7b4f 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -116,7 +116,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { char *voteGranted2Str(SVotesGranted *pVotesGranted) { cJSON *pJson = voteGranted2Json(pVotesGranted); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -238,7 +238,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { char *votesRespond2Str(SVotesRespond *pVotesRespond) { cJSON *pJson = votesRespond2Json(pVotesRespond); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index b542f55ec3..2583deb32f 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(syncPingReplyTest "") add_executable(syncRpcMsgTest "") add_executable(syncPingTimerTest2 "") add_executable(syncPingSelfTest "") +add_executable(syncElectTest "") target_sources(syncTest @@ -145,6 +146,10 @@ target_sources(syncPingSelfTest PRIVATE "syncPingSelfTest.cpp" ) +target_sources(syncElectTest + PRIVATE + "syncElectTest.cpp" +) target_include_directories(syncTest @@ -292,6 +297,16 @@ target_include_directories(syncPingSelfTest "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncElectTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) +target_include_directories(syncElectTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -410,6 +425,10 @@ target_link_libraries(syncPingSelfTest sync gtest_main ) +target_link_libraries(syncElectTest + sync + gtest_main +) enable_testing() diff --git a/source/libs/sync/test/syncElectTest.cpp b/source/libs/sync/test/syncElectTest.cpp new file mode 100644 index 0000000000..e52fe61ef5 --- /dev/null +++ b/source/libs/sync/test/syncElectTest.cpp @@ -0,0 +1,121 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 1; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; +SWal* pWal; +SSyncNode* gSyncNode; + +SSyncNode* syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./elect_test"); + + int code = walInit(); + assert(code == 0); + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; + pWal = walOpen("./elect_test_wal", &walCfg); + assert(pWal != NULL); + + syncInfo.pWal = pWal; + + SSyncCfg* pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + SSyncNode* pSyncNode = syncNodeOpen(&syncInfo); + assert(pSyncNode != NULL); + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->pSyncNode = pSyncNode; + + return pSyncNode; +} + +SSyncNode* syncInitTest() { return syncNodeInit(); } + +void initRaftId(SSyncNode* pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char* s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + ret = syncEnvStart(); + assert(ret == 0); + + gSyncNode = syncInitTest(); + assert(gSyncNode != NULL); + syncNodePrint2((char*)"", gSyncNode); + + initRaftId(gSyncNode); + + //--------------------------- + while (1) { + sTrace("while 1 sleep, state: %d, %s", gSyncNode->state, syncUtilState2String(gSyncNode->state)); + taosMsleep(1000); + } + + return 0; +} diff --git a/source/libs/sync/test/syncRaftStoreTest.cpp b/source/libs/sync/test/syncRaftStoreTest.cpp index 0c1c9b881e..688802625a 100644 --- a/source/libs/sync/test/syncRaftStoreTest.cpp +++ b/source/libs/sync/test/syncRaftStoreTest.cpp @@ -3,6 +3,7 @@ #include #include "syncIO.h" #include "syncInt.h" +#include "syncUtil.h" void logTest() { sTrace("--- sync log test: trace"); @@ -13,6 +14,21 @@ void logTest() { sFatal("--- sync log test: fatal"); } +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 5; +int32_t myIndex = 0; +SRaftId ids[TSDB_MAX_REPLICA]; + +void initRaftId() { + for (int i = 0; i < replicaNum; ++i) { + ids[i].addr = syncUtilAddr2U64("127.0.0.1", ports[i]); + ids[i].vgId = 1234; + char* s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + int main() { // taosInitLog((char *)"syncTest.log", 100000, 10); tsAsyncLog = 0; @@ -20,23 +36,35 @@ int main() { logTest(); - SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json"); + initRaftId(); + + SRaftStore* pRaftStore = raftStoreOpen("./test_raft_store.json"); assert(pRaftStore != NULL); - raftStorePrint(pRaftStore); + raftStorePrint2((char*)"==raftStoreOpen==", pRaftStore); -#if 0 - pRaftStore->currentTerm = 100; - pRaftStore->voteFor.addr = 200; - pRaftStore->voteFor.vgId = 300; - raftStorePersist(pRaftStore); - raftStorePrint(pRaftStore); -#endif + raftStoreSetTerm(pRaftStore, 100); + raftStorePrint2((char*)"==raftStoreSetTerm==", pRaftStore); - ++(pRaftStore->currentTerm); - ++(pRaftStore->voteFor.addr); - ++(pRaftStore->voteFor.vgId); - raftStorePersist(pRaftStore); - raftStorePrint(pRaftStore); + raftStoreVote(pRaftStore, &ids[0]); + raftStorePrint2((char*)"==raftStoreVote==", pRaftStore); + + raftStoreClearVote(pRaftStore); + raftStorePrint2((char*)"==raftStoreClearVote==", pRaftStore); + + raftStoreVote(pRaftStore, &ids[1]); + raftStorePrint2((char*)"==raftStoreVote==", pRaftStore); + + raftStoreNextTerm(pRaftStore); + raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore); + + raftStoreNextTerm(pRaftStore); + raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore); + + raftStoreNextTerm(pRaftStore); + raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore); + + raftStoreNextTerm(pRaftStore); + raftStorePrint2((char*)"==raftStoreNextTerm==", pRaftStore); return 0; } From 90478b87421a09e1c20e4228ebe1ace8c00fb5dc Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 15:24:11 +0800 Subject: [PATCH 08/20] sync refactor --- source/libs/sync/inc/syncEnv.h | 6 +++--- source/libs/sync/src/syncElection.c | 8 ++++++++ source/libs/sync/src/syncRequestVoteReply.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index 40ff79287b..66c7c8620d 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -31,10 +31,10 @@ extern "C" { #define TIMER_MAX_MS 0x7FFFFFFF #define ENV_TICK_TIMER_MS 1000 #define PING_TIMER_MS 1000 -#define ELECT_TIMER_MS_MIN 150 -#define ELECT_TIMER_MS_MAX 300 +#define ELECT_TIMER_MS_MIN 1500 +#define ELECT_TIMER_MS_MAX 3000 #define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN) -#define HEARTBEAT_TIMER_MS 30 +#define HEARTBEAT_TIMER_MS 300 #define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0}) diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 12e20ef762..6ae70689ef 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -63,6 +63,14 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm); syncNodeVoteForSelf(pSyncNode); + if (voteGrantedMajority(pSyncNode->pVotesGranted)) { + // only myself, to leader + assert(!pSyncNode->pVotesGranted->toLeader); + syncNodeCandidate2Leader(pSyncNode); + pSyncNode->pVotesGranted->toLeader = true; + return ret; + } + ret = syncNodeRequestVotePeers(pSyncNode); assert(ret == 0); syncNodeResetElectTimer(pSyncNode); diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 7cdeace166..802d95076c 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -57,7 +57,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) if (pMsg->voteGranted) { voteGrantedVote(ths->pVotesGranted, pMsg); if (voteGrantedMajority(ths->pVotesGranted)) { - if (ths->pVotesGranted->toLeader) { + if (!ths->pVotesGranted->toLeader) { syncNodeCandidate2Leader(ths); ths->pVotesGranted->toLeader = true; } From acfe73ed18987b145af656ee01c2b5b4da84b1c5 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 15:47:49 +0800 Subject: [PATCH 09/20] sync refactor --- source/libs/sync/src/syncRequestVote.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index be4f40aaad..062b0244bd 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -56,6 +56,8 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK && ((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId)))); if (grant) { + // maybe has already voted for pMsg->srcId + // vote again, no harm raftStoreVote(ths->pRaftStore, &(pMsg->srcId)); } From b08cdf2f824d5149257df715313b676bd3d39679 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 16:20:01 +0800 Subject: [PATCH 10/20] sync refactor --- source/libs/sync/src/syncMain.c | 22 +++++++++++++++++++-- source/libs/sync/src/syncRaftStore.c | 2 +- source/libs/sync/src/syncRequestVoteReply.c | 13 ++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 58710d7d1f..c146c2fa7a 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -510,15 +510,17 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) { } void syncNodeBecomeFollower(SSyncNode* pSyncNode) { + // maybe clear leader cache if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { pSyncNode->leaderCache = EMPTY_RAFT_ID; } + // state change pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; syncNodeStopHeartbeatTimer(pSyncNode); - int32_t electMS = syncUtilElectRandomMS(); - syncNodeRestartElectTimer(pSyncNode, electMS); + // reset elect timer + syncNodeResetElectTimer(pSyncNode); } // TLA+ Spec @@ -540,19 +542,31 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) { // /\ UNCHANGED <> // void syncNodeBecomeLeader(SSyncNode* pSyncNode) { + // state change pSyncNode->state = TAOS_SYNC_STATE_LEADER; + + // set leader cache pSyncNode->leaderCache = pSyncNode->myRaftId; for (int i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) { + // maybe overwrite myself, no harm + // just do it! pSyncNode->pNextIndex->index[i] = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1; } for (int i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) { + // maybe overwrite myself, no harm + // just do it! pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID; } + // stop elect timer syncNodeStopElectTimer(pSyncNode); + + // start heartbeat timer syncNodeStartHeartbeatTimer(pSyncNode); + + // start replicate right now! syncNodeReplicate(pSyncNode); } @@ -578,6 +592,9 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) { } // raft vote -------------- + +// just called by syncNodeVoteForSelf +// need assert void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) { assert(term == pSyncNode->pRaftStore->currentTerm); assert(!raftStoreHasVoted(pSyncNode->pRaftStore)); @@ -585,6 +602,7 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) raftStoreVote(pSyncNode->pRaftStore, pRaftId); } +// simulate get vote from outside void syncNodeVoteForSelf(SSyncNode* pSyncNode) { syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &(pSyncNode->myRaftId)); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index bb0eab0fdc..3f6db129ce 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -216,7 +216,7 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) { char *raftStore2Str(SRaftStore *pRaftStore) { cJSON *pJson = raftStore2Json(pRaftStore); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 802d95076c..10ea53864f 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -45,6 +45,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) return ret; } + assert(!(pMsg->term > ths->pRaftStore->currentTerm)); // no need this code, because if I receive reply.term, then I must have sent for that term. // if (pMsg->term > ths->pRaftStore->currentTerm) { // syncNodeUpdateTerm(ths, pMsg->term); @@ -52,17 +53,29 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) assert(pMsg->term == ths->pRaftStore->currentTerm); + // This tallies votes even when the current state is not Candidate, + // but they won't be looked at, so it doesn't matter. if (ths->state == TAOS_SYNC_STATE_CANDIDATE) { votesRespondAdd(ths->pVotesRespond, pMsg); if (pMsg->voteGranted) { + // add vote voteGrantedVote(ths->pVotesGranted, pMsg); + + // maybe to leader if (voteGrantedMajority(ths->pVotesGranted)) { if (!ths->pVotesGranted->toLeader) { syncNodeCandidate2Leader(ths); + + // prevent to leader again! ths->pVotesGranted->toLeader = true; } } + } else { + ; + // do nothing + // UNCHANGED <> } } + return ret; } From 5387e4ff7d59fcc9a1030085d48e155831d2baab Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 16:54:55 +0800 Subject: [PATCH 11/20] sync refactor --- source/libs/sync/src/syncReplication.c | 40 ++++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index b935943a1d..ca04db81b6 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -18,6 +18,7 @@ #include "syncMessage.h" #include "syncRaftEntry.h" #include "syncRaftLog.h" +#include "syncRaftStore.h" #include "syncUtil.h" // TLA+ Spec @@ -50,33 +51,54 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) { int32_t ret = 0; for (int i = 0; i < pSyncNode->peersNum; ++i) { - SRaftId* pDestId = &(pSyncNode->peersId[i]); - SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); + SRaftId* pDestId = &(pSyncNode->peersId[i]); + // set prevLogIndex + SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); SyncIndex preLogIndex = nextIndex - 1; + // set preLogTerm SyncTerm preLogTerm = 0; if (preLogIndex >= SYNC_INDEX_BEGIN) { SSyncRaftEntry* pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preLogIndex); + assert(pPreEntry != NULL); + preLogTerm = pPreEntry->term; + syncEntryDestory(pPreEntry); } - SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex); - assert(nextIndex == lastIndex); + // batch optimized + // SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex); - SSyncRaftEntry* pEntry = logStoreGetEntry(pSyncNode->pLogStore, nextIndex); - assert(pEntry != NULL); + SyncAppendEntries* pMsg = NULL; + SSyncRaftEntry* pEntry = logStoreGetEntry(pSyncNode->pLogStore, nextIndex); + if (pEntry != NULL) { + SyncAppendEntries* pMsg = syncAppendEntriesBuild(pEntry->bytes); + + // add pEntry into msg + uint32_t len; + char* serialized = syncEntrySerialize(pEntry, &len); + assert(len == pEntry->bytes); + memcpy(pMsg->data, serialized, len); + + free(serialized); + syncEntryDestory(pEntry); + + } else { + // maybe overflow, send empty record + SyncAppendEntries* pMsg = syncAppendEntriesBuild(0); + } - SyncAppendEntries* pMsg = syncAppendEntriesBuild(pEntry->bytes); pMsg->srcId = pSyncNode->myRaftId; pMsg->destId = *pDestId; + pMsg->term = pSyncNode->pRaftStore->currentTerm; pMsg->prevLogIndex = preLogIndex; pMsg->prevLogTerm = preLogTerm; pMsg->commitIndex = pSyncNode->commitIndex; - pMsg->dataLen = pEntry->bytes; - // add pEntry into msg + // send AppendEntries syncNodeAppendEntries(pSyncNode, pDestId, pMsg); + syncAppendEntriesDestroy(pMsg); } return ret; From f22226a44ec541e0c9492ab8bdeb6eb6b21620f8 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 17:16:10 +0800 Subject: [PATCH 12/20] sync refactor --- source/libs/sync/src/syncAppendEntriesReply.c | 6 ++- source/libs/sync/src/syncCommit.c | 41 +++++++++++++++++++ source/libs/sync/src/syncMain.c | 2 - 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 source/libs/sync/src/syncCommit.c diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 61eb4884e2..4fa4f89628 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -51,10 +51,10 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p assert(pMsg->term == ths->pRaftStore->currentTerm); if (pMsg->success) { - // nextIndex = reply.matchIndex + 1 + // nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); - // matchIndex = reply.matchIndex + // matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex); // maybe commit @@ -62,6 +62,8 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p } else { SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + + // notice! int64, uint64 if (nextIndex > SYNC_INDEX_BEGIN) { --nextIndex; } else { diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c new file mode 100644 index 0000000000..ec4272fdd0 --- /dev/null +++ b/source/libs/sync/src/syncCommit.c @@ -0,0 +1,41 @@ +/* + * 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 "syncInt.h" + +// \* Leader i advances its commitIndex. +// \* This is done as a separate step from handling AppendEntries responses, +// \* in part to minimize atomic regions, and in part so that leaders of +// \* single-server clusters are able to mark entries committed. +// AdvanceCommitIndex(i) == +// /\ state[i] = Leader +// /\ LET \* The set of servers that agree up through index. +// Agree(index) == {i} \cup {k \in Server : +// matchIndex[i][k] >= index} +// \* The maximum indexes for which a quorum agrees +// agreeIndexes == {index \in 1..Len(log[i]) : +// Agree(index) \in Quorum} +// \* New value for commitIndex'[i] +// newCommitIndex == +// IF /\ agreeIndexes /= {} +// /\ log[i][Max(agreeIndexes)].term = currentTerm[i] +// THEN +// Max(agreeIndexes) +// ELSE +// commitIndex[i] +// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex] +// /\ UNCHANGED <> +// +void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {} \ No newline at end of file diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index c146c2fa7a..7d2087eded 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -617,8 +617,6 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) { syncRequestVoteReplyDestroy(pMsg); } -void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {} - // for debug -------------- void syncNodePrint(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); From d1c4e9ae9227c442432f86f2fa8287e39cca944e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Mar 2022 18:15:26 +0800 Subject: [PATCH 13/20] handle except --- source/libs/transport/src/transCli.c | 107 ++++++++++++++++----------- 1 file changed, 64 insertions(+), 43 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b7bc428901..0932241abf 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -30,6 +30,7 @@ typedef struct SCliConn { void* hostThrd; SConnBuffer readBuf; void* data; + SArray* cliMsgs; queue conn; uint64_t expireTime; int hThrdIdx; @@ -106,6 +107,7 @@ static void cliAsyncCb(uv_async_t* handle); static SCliConn* cliCreateConn(SCliThrdObj* thrd); static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); static void cliDestroy(uv_handle_t* handle); +static void cliSend(SCliConn* pConn); // process data read from server, add decompress etc later static void cliHandleResp(SCliConn* conn); @@ -158,6 +160,14 @@ static void destroyThrdObj(SCliThrdObj* pThrd); static void* cliWorkThread(void* arg); +bool cliMayContinueSendMsg(SCliConn* conn) { + if (taosArrayGetSize(conn->cliMsgs) > 0) { + cliSend(conn); + return true; + } else { + return false; + } +} void cliHandleResp(SCliConn* conn) { SCliThrdObj* pThrd = conn->hostThrd; STrans* pTransInst = pThrd->pTransInst; @@ -173,18 +183,18 @@ void cliHandleResp(SCliConn* conn) { transMsg.msgType = pHead->msgType; transMsg.ahandle = NULL; - SCliMsg* pMsg = conn->data; + SCliMsg* pMsg = NULL; + if (taosArrayGetSize(conn->cliMsgs) > 0) { + pMsg = taosArrayGetP(conn->cliMsgs, 0); + taosArrayRemove(conn->cliMsgs, 0); + } + STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) { transMsg.ahandle = pTransInst->mfp ? (*pTransInst->mfp)(pTransInst->parent, transMsg.msgType) : NULL; } else { transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; } - // if (rpcMsg.ahandle == NULL) { - // tDebug("%s cli conn %p handle except", CONN_GET_INST_LABEL(conn), conn); - // return; - //} - // buf's mem alread translated to transMsg.pCont transClearBuffer(&conn->readBuf); @@ -214,12 +224,15 @@ void cliHandleResp(SCliConn* conn) { memcpy((char*)pCtx->pRsp, (char*)&transMsg, sizeof(transMsg)); tsem_post(pCtx->pSem); } + destroyCmsg(pMsg); + + if (cliMayContinueSendMsg(conn) == true) { + return; + } if (CONN_NO_PERSIST_BY_APP(conn)) { addConnToPool(pThrd->pool, conn); } - destroyCmsg(conn->data); - conn->data = NULL; uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); // start thread's timer of conn pool if not active @@ -229,7 +242,7 @@ void cliHandleResp(SCliConn* conn) { } void cliHandleExcept(SCliConn* pConn) { - if (pConn->data == NULL) { + if (taosArrayGetSize(pConn->cliMsgs) == 0) { if (pConn->broken == true || CONN_NO_PERSIST_BY_APP(pConn)) { transUnrefCliHandle(pConn); return; @@ -238,32 +251,38 @@ void cliHandleExcept(SCliConn* pConn) { SCliThrdObj* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; - SCliMsg* pMsg = pConn->data; - STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; + do { + SCliMsg* pMsg = NULL; + if (taosArrayGetSize(pConn->cliMsgs) > 0) { + pMsg = taosArrayGetP(pConn->cliMsgs, 0); + taosArrayRemove(pConn->cliMsgs, 0); + } - STransMsg transMsg = {0}; - transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; - transMsg.ahandle = NULL; + STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; - if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { - transMsg.ahandle = pTransInst->mfp ? (*pTransInst->mfp)(pTransInst->parent, transMsg.msgType) : NULL; - } else { - transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; - } + STransMsg transMsg = {0}; + transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; + transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; + transMsg.ahandle = NULL; - if (pCtx == NULL || pCtx->pSem == NULL) { - tTrace("%s cli conn %p handle resp", pTransInst->label, pConn); - (pTransInst->cfp)(pTransInst->parent, &transMsg, NULL); - } else { - tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, pConn); - memcpy((char*)(pCtx->pRsp), (char*)(&transMsg), sizeof(transMsg)); - tsem_post(pCtx->pSem); - } - destroyCmsg(pConn->data); - pConn->data = NULL; + if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { + transMsg.ahandle = pTransInst->mfp ? (*pTransInst->mfp)(pTransInst->parent, transMsg.msgType) : NULL; + } else { + transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; + } + + if (pCtx == NULL || pCtx->pSem == NULL) { + tTrace("%s cli conn %p handle resp", pTransInst->label, pConn); + (pTransInst->cfp)(pTransInst->parent, &transMsg, NULL); + } else { + tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, pConn); + memcpy((char*)(pCtx->pRsp), (char*)(&transMsg), sizeof(transMsg)); + tsem_post(pCtx->pSem); + } + destroyCmsg(pMsg); + tTrace("%s cli conn %p start to destroy", CONN_GET_INST_LABEL(pConn), pConn); + } while (taosArrayGetSize(pConn->cliMsgs) > 0); - tTrace("%s cli conn %p start to destroy", CONN_GET_INST_LABEL(pConn), pConn); transUnrefCliHandle(pConn); } @@ -398,6 +417,7 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) { conn->writeReq.data = conn; conn->connReq.data = conn; + conn->cliMsgs = taosArrayInit(2, sizeof(void*)); QUEUE_INIT(&conn->conn); conn->hostThrd = pThrd; @@ -417,6 +437,7 @@ static void cliDestroy(uv_handle_t* handle) { SCliConn* conn = handle->data; free(conn->ip); free(conn->stream); + taosArrayDestroy(conn->cliMsgs); tTrace("%s cli conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); free(conn); } @@ -426,11 +447,6 @@ static void cliSendCb(uv_write_t* req, int status) { if (status == 0) { tTrace("%s cli conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); - SCliMsg* pMsg = pConn->data; - if (pMsg == NULL) { - return; - } - destroyUserdata(&pMsg->msg); } else { tError("%s cli conn %p failed to write: %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); cliHandleExcept(pConn); @@ -442,7 +458,8 @@ static void cliSendCb(uv_write_t* req, int status) { void cliSend(SCliConn* pConn) { CONN_HANDLE_BROKEN(pConn); - SCliMsg* pCliMsg = pConn->data; + assert(taosArrayGetSize(pConn->cliMsgs) > 0); + SCliMsg* pCliMsg = taosArrayGetP(pConn->cliMsgs, 0); STransConnCtx* pCtx = pCliMsg->ctx; SCliThrdObj* pThrd = pConn->hostThrd; @@ -480,6 +497,7 @@ void cliSend(SCliConn* pConn) { TMSG_INFO(pHead->msgType), inet_ntoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), inet_ntoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); + pConn->writeReq.data = pConn; uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); return; @@ -502,8 +520,8 @@ void cliConnCb(uv_connect_t* req, int status) { uv_tcp_getsockname((uv_tcp_t*)pConn->stream, (struct sockaddr*)&pConn->locaddr, &addrlen); tTrace("%s cli conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - assert(pConn->stream == req->handle); + cliSend(pConn); } @@ -521,8 +539,11 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd) { SCliConn* conn = pMsg->msg.handle; tDebug("%s cli conn %p release to inst", CONN_GET_INST_LABEL(conn), conn); - destroyCmsg(pMsg); - conn->data = NULL; + while (taosArrayGetSize(conn->cliMsgs) > 0) { + SCliMsg* pMsg = taosArrayGetP(conn->cliMsgs, 0); + destroyCmsg(pMsg); + taosArrayRemove(conn->cliMsgs, 0); + } transDestroyBuffer(&conn->readBuf); if (conn->persist && T_REF_VAL_GET(conn) >= 2) { @@ -561,14 +582,14 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) { SCliConn* conn = cliGetConn(pMsg, pThrd); if (conn != NULL) { - conn->data = pMsg; + taosArrayPush(conn->cliMsgs, &pMsg); conn->hThrdIdx = pCtx->hThrdIdx; - transDestroyBuffer(&conn->readBuf); cliSend(conn); } else { conn = cliCreateConn(pThrd); - conn->data = pMsg; + taosArrayPush(conn->cliMsgs, &pMsg); + conn->hThrdIdx = pCtx->hThrdIdx; conn->ip = strdup(pMsg->ctx->ip); conn->port = pMsg->ctx->port; From e10f471b9525e452746c98820f8034c2766741e1 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 16 Mar 2022 18:19:26 +0800 Subject: [PATCH 14/20] refactor --- include/common/tmsg.h | 25 +--- include/util/taoserror.h | 1 + source/dnode/vnode/src/inc/tsdbDef.h | 9 +- source/dnode/vnode/src/tsdb/tsdbBDBImpl.c | 4 +- source/dnode/vnode/src/tsdb/tsdbSma.c | 170 ++++++++++++++-------- source/dnode/vnode/test/tsdbSmaTest.cpp | 121 +++++++-------- source/util/src/terror.c | 1 + 7 files changed, 184 insertions(+), 147 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index f0718900c0..40bf9a7f62 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1896,33 +1896,18 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) } return buf; } -typedef enum { - TD_TIME_UNIT_UNKNOWN = -1, - TD_TIME_UNIT_YEAR = 0, - TD_TIME_UNIT_SEASON = 1, - TD_TIME_UNIT_MONTH = 2, - TD_TIME_UNIT_WEEK = 3, - TD_TIME_UNIT_DAY = 4, - TD_TIME_UNIT_HOUR = 5, - TD_TIME_UNIT_MINUTE = 6, - TD_TIME_UNIT_SEC = 7, - TD_TIME_UNIT_MILLISEC = 8, - TD_TIME_UNIT_MICROSEC = 9, - TD_TIME_UNIT_NANOSEC = 10 -} ETDTimeUnit; - typedef struct { int8_t version; // for compatibility(default 0) - int8_t intervalUnit; - int8_t slidingUnit; + int8_t intervalUnit; // MACRO: TIME_UNIT_XXX + int8_t slidingUnit; // MACRO: TIME_UNIT_XXX char indexName[TSDB_INDEX_NAME_LEN]; - char timezone[TD_TIMEZONE_LEN]; // sma data is invalid if timezone change. + char timezone[TD_TIMEZONE_LEN]; // sma data expired if timezone changes. int32_t exprLen; int32_t tagsFilterLen; int64_t indexUid; tb_uid_t tableUid; // super/child/common table uid int64_t interval; - int64_t offset; + int64_t offset; // use unit by precision of DB int64_t sliding; char* expr; // sma expression char* tagsFilter; @@ -1967,7 +1952,7 @@ typedef struct { typedef struct { int64_t indexUid; - TSKEY skey; // startTS of one interval/sliding + TSKEY skey; // startKey of one interval/sliding window int64_t interval; int32_t dataLen; // not including head int8_t intervalUnit; diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 1c61d738b5..fe06a1c4a2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -354,6 +354,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615) #define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616) #define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0617) +#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0618) // query #define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) diff --git a/source/dnode/vnode/src/inc/tsdbDef.h b/source/dnode/vnode/src/inc/tsdbDef.h index 6f91b4d3ab..5e4c852621 100644 --- a/source/dnode/vnode/src/inc/tsdbDef.h +++ b/source/dnode/vnode/src/inc/tsdbDef.h @@ -60,10 +60,11 @@ struct STsdb { SSmaEnv * pRSmaEnv; }; -#define REPO_ID(r) ((r)->vgId) -#define REPO_CFG(r) (&(r)->config) -#define REPO_FS(r) (r)->fs -#define IS_REPO_LOCKED(r) (r)->repoLocked +#define REPO_ID(r) ((r)->vgId) +#define REPO_CFG(r) (&(r)->config) +#define REPO_FS(r) (r)->fs +#define IS_REPO_LOCKED(r) (r)->repoLocked +#define REPO_SMA_ENV(r, t) ((TSDB_SMA_TYPE_ROLLUP == (t)) ? (r)->pRSmaEnv : (r)->pTSmaEnv) int tsdbLockRepo(STsdb *pTsdb); int tsdbUnlockRepo(STsdb *pTsdb); diff --git a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c index cf3351c5d8..ee279abf47 100644 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c @@ -68,8 +68,8 @@ int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) { ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0); if (ret != 0) { - // BDB_PERR("Failed to open tsdb env", ret); - tsdbWarn("Failed to open tsdb env for path %s since %d", path ? path : "NULL", ret); + terrno = TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR; + tsdbWarn("Failed to open tsdb env for path %s since ret %d != 0", path ? path : "NULL", ret); return -1; } diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 7335e4f585..880eb403f4 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -17,7 +17,7 @@ #undef SMA_PRINT_DEBUG_LOG #define SMA_STORAGE_TSDB_DAYS 30 -#define SMA_STORAGE_TSDB_TIMES 30 +#define SMA_STORAGE_TSDB_TIMES 10 #define SMA_STORAGE_SPLIT_HOURS 24 #define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8 @@ -93,6 +93,11 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid); static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, TSKEY skey); static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey); +static void tsdbGetSmaDir(int32_t repoid, int8_t smaType, char dirName[]); + +static void tsdbGetSmaDir(int32_t repoid, int8_t smaType, char dirName[]) { + snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/data", repoid); +} static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path) { SSmaEnv *pEnv = NULL; @@ -136,7 +141,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) { return TSDB_CODE_FAILED; } - if (pEnv && *pEnv) { + if (*pEnv) { return TSDB_CODE_SUCCESS; } @@ -144,7 +149,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) { return TSDB_CODE_FAILED; } - if (*pEnv == NULL) { + if (*pEnv == NULL) { // 2nd phase check if ((*pEnv = tsdbNewSmaEnv(pTsdb, path)) == NULL) { tsdbUnlockRepo(pTsdb); return TSDB_CODE_FAILED; @@ -152,7 +157,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) { } if (tsdbUnlockRepo(pTsdb) != 0) { - tsdbFreeSmaEnv(*pEnv); + *pEnv = tsdbFreeSmaEnv(*pEnv); return TSDB_CODE_FAILED; } @@ -244,6 +249,39 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { } } +static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { + switch (smaType) { + case TSDB_SMA_TYPE_TIME_RANGE: + if (pTsdb->pTSmaEnv) { + return TSDB_CODE_SUCCESS; + } + break; + case TSDB_SMA_TYPE_ROLLUP: + if (pTsdb->pRSmaEnv) { + return TSDB_CODE_SUCCESS; + } + break; + default: + terrno = TSDB_CODE_INVALID_PARA; + return TSDB_CODE_FAILED; + } + + // SDiskID did = {0}; + SSmaEnv *pEnv = NULL; + char smaPath[TSDB_FILENAME_LEN] = "/proj/.sma/"; + if (tsdbInitSmaEnv(pTsdb, smaPath, &pEnv) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_FAILED; + } + + if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { + pTsdb->pTSmaEnv = pEnv; + } else { + pTsdb->pRSmaEnv = pEnv; + } + + return TSDB_CODE_SUCCESS; +}; + /** * @brief Update expired window according to msg from stream computing module. * @@ -253,26 +291,17 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { * @return int32_t */ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg) { - STsdbCfg *pCfg = REPO_CFG(pTsdb); - SSmaEnv * pEnv = NULL; - if (!msg || !pTsdb->pMeta) { terrno = TSDB_CODE_INVALID_PTR; return TSDB_CODE_FAILED; } - char smaPath[TSDB_FILENAME_LEN] = "/proj/.sma/"; - if (tsdbInitSmaEnv(pTsdb, smaPath, &pEnv) != TSDB_CODE_SUCCESS) { + if (tsdbCheckAndInitSmaEnv(pTsdb, smaType) != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_TDB_INIT_FAILED; return TSDB_CODE_FAILED; } - if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { - pTsdb->pTSmaEnv = pEnv; - } else if (smaType == TSDB_SMA_TYPE_ROLLUP) { - pTsdb->pRSmaEnv = pEnv; - } else { - ASSERT(0); - } + SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, smaType); // TODO: decode the msg => start int64_t indexUid = SMA_TEST_INDEX_UID; @@ -308,7 +337,6 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg) { } pItem->pSma = pSma; - // TODO: change indexName to indexUid if (taosHashPut(pItemsHash, &indexUid, sizeof(indexUid), &pItem, sizeof(pItem)) != 0) { // If error occurs during put smaStatItem, free the resources of pItem taosHashCleanup(pItem->expiredWindows); @@ -378,32 +406,32 @@ static int32_t tsdbResetExpiredWindow(SSmaStat *pStat, int64_t indexUid, TSKEY s static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) { // TODO: configurable for SMA_STORAGE_SPLIT_HOURS? switch (intervalUnit) { - case TD_TIME_UNIT_HOUR: + case TIME_UNIT_HOUR: if (interval < SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } break; - case TD_TIME_UNIT_MINUTE: + case TIME_UNIT_MINUTE: if (interval < 60 * SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } break; - case TD_TIME_UNIT_SEC: + case TIME_UNIT_SECOND: if (interval < 3600 * SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } break; - case TD_TIME_UNIT_MILLISEC: + case TIME_UNIT_MILLISECOND: if (interval < 3600 * 1e3 * SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } break; - case TD_TIME_UNIT_MICROSEC: + case TIME_UNIT_MICROSECOND: if (interval < 3600 * 1e6 * SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } break; - case TD_TIME_UNIT_NANOSEC: + case TIME_UNIT_NANOSECOND: if (interval < 3600 * 1e9 * SMA_STORAGE_SPLIT_HOURS) { return SMA_STORAGE_LEVEL_DFILESET; } @@ -429,8 +457,8 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k // TODO: insert sma data blocks into B+Tree tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d", - REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), - *(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen); + REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), + *(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen); if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) { return TSDB_CODE_FAILED; @@ -447,66 +475,73 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k return TSDB_CODE_SUCCESS; } +/** + * @brief Approximate value for week/month/year. + * + * @param interval + * @param intervalUnit + * @param precision + * @return int64_t + */ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) { - if (intervalUnit < TD_TIME_UNIT_MILLISEC) { - switch (intervalUnit) { - case TD_TIME_UNIT_YEAR: - case TD_TIME_UNIT_SEASON: - case TD_TIME_UNIT_MONTH: - case TD_TIME_UNIT_WEEK: - // illegal time unit - tsdbError("invalid interval unit: %d\n", intervalUnit); - TASSERT(0); - break; - case TD_TIME_UNIT_DAY: // the interval for tSma calculation must <= day - interval *= 86400 * 1e3; - break; - case TD_TIME_UNIT_HOUR: - interval *= 3600 * 1e3; - break; - case TD_TIME_UNIT_MINUTE: - interval *= 60 * 1e3; - break; - case TD_TIME_UNIT_SEC: - interval *= 1e3; - break; - default: - break; - } + switch (intervalUnit) { + case TIME_UNIT_YEAR: // approximate value + interval *= 365 * 86400 * 1e3; + break; + case TIME_UNIT_MONTH: // approximate value + interval *= 30 * 86400 * 1e3; + break; + case TIME_UNIT_WEEK: // approximate value + interval *= 7 * 86400 * 1e3; + break; + case TIME_UNIT_DAY: // the interval for tSma calculation must <= day + interval *= 86400 * 1e3; + break; + case TIME_UNIT_HOUR: + interval *= 3600 * 1e3; + break; + case TIME_UNIT_MINUTE: + interval *= 60 * 1e3; + break; + case TIME_UNIT_SECOND: + interval *= 1e3; + break; + default: + break; } switch (precision) { case TSDB_TIME_PRECISION_MILLI: - if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us + if (TIME_UNIT_MICROSECOND == intervalUnit) { // us return interval / 1e3; - } else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second + } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second return interval / 1e6; } else { return interval; } break; case TSDB_TIME_PRECISION_MICRO: - if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us + if (TIME_UNIT_MICROSECOND == intervalUnit) { // us return interval; - } else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second + } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second return interval / 1e3; } else { return interval * 1e3; } break; case TSDB_TIME_PRECISION_NANO: - if (TD_TIME_UNIT_MICROSEC == intervalUnit) { + if (TIME_UNIT_MICROSECOND == intervalUnit) { return interval * 1e3; - } else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second + } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second return interval; } else { return interval * 1e6; } break; default: // ms - if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us + if (TIME_UNIT_MICROSECOND == intervalUnit) { // us return interval / 1e3; - } else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second + } else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second return interval / 1e6; } else { return interval; @@ -800,10 +835,19 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) { static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySkey, int32_t nMaxResult) { + if (!pTsdb->pTSmaEnv) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbWarn("vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); + return TSDB_CODE_FAILED; + } + SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(SMA_ENV_STAT_ITEMS(pTsdb->pTSmaEnv), &indexUid, sizeof(indexUid)); if (pItem == NULL) { - // mark all window as expired and notify query module to query raw TS data. - return TSDB_CODE_SUCCESS; + // Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if + // it's NULL. + terrno = TSDB_CODE_TDB_INVALID_ACTION; + tsdbWarn("vgId:%d getTSmaDataImpl failed since no index %" PRIi64 " in local cache", REPO_ID(pTsdb), indexUid); + return TSDB_CODE_FAILED; } #if 0 @@ -815,6 +859,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ } } #endif + #if 0 if (taosHashGet(pItem->expiredWindows, &querySkey, sizeof(TSKEY)) != NULL) { // TODO: mark this window as expired. @@ -835,8 +880,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ tsdbEncodeTSmaKey(tableUid, colId, querySkey, (void **)&pSmaKey); tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb), - tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), - *(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN); + tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), + *(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN); void * result = NULL; uint32_t valueSize = 0; @@ -947,7 +992,6 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, int8_t smaType, char *msg) { * @brief Insert Time-range-wise Rollup Sma(RSma) data * * @param pTsdb - * @param param * @param msg * @return int32_t */ diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 18dca33bda..96fd35e700 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -37,9 +37,9 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { // encode STSma tSma = {0}; tSma.version = 0; - tSma.intervalUnit = TD_TIME_UNIT_DAY; + tSma.intervalUnit = TIME_UNIT_DAY; tSma.interval = 1; - tSma.slidingUnit = TD_TIME_UNIT_HOUR; + tSma.slidingUnit = TIME_UNIT_HOUR; tSma.sliding = 0; tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN); tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN); @@ -50,37 +50,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) { uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper); void *buf = calloc(bufLen, 1); - assert(buf != NULL); + ASSERT_NE(buf, nullptr); STSmaWrapper *pSW = (STSmaWrapper *)buf; uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper); - EXPECT_EQ(len, bufLen); + ASSERT_EQ(len, bufLen); // decode STSmaWrapper dstTSmaWrapper = {0}; void * result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper); - assert(result != NULL); + ASSERT_NE(result, nullptr); - EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number); + ASSERT_EQ(tSmaWrapper.number, dstTSmaWrapper.number); for (int i = 0; i < tSmaWrapper.number; ++i) { STSma *pSma = tSmaWrapper.tSma + i; STSma *qSma = dstTSmaWrapper.tSma + i; - EXPECT_EQ(pSma->version, qSma->version); - EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit); - EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit); - EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName); - EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone); - EXPECT_EQ(pSma->indexUid, qSma->indexUid); - EXPECT_EQ(pSma->tableUid, qSma->tableUid); - EXPECT_EQ(pSma->interval, qSma->interval); - EXPECT_EQ(pSma->sliding, qSma->sliding); - EXPECT_EQ(pSma->exprLen, qSma->exprLen); - EXPECT_STRCASEEQ(pSma->expr, qSma->expr); - EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); - EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); + ASSERT_EQ(pSma->version, qSma->version); + ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit); + ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit); + ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName); + ASSERT_STRCASEEQ(pSma->timezone, qSma->timezone); + ASSERT_EQ(pSma->indexUid, qSma->indexUid); + ASSERT_EQ(pSma->tableUid, qSma->tableUid); + ASSERT_EQ(pSma->interval, qSma->interval); + ASSERT_EQ(pSma->sliding, qSma->sliding); + ASSERT_EQ(pSma->exprLen, qSma->exprLen); + ASSERT_STRCASEEQ(pSma->expr, qSma->expr); + ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); + ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); } // resource release @@ -103,9 +103,9 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { // encode STSma tSma = {0}; tSma.version = 0; - tSma.intervalUnit = TD_TIME_UNIT_DAY; + tSma.intervalUnit = TIME_UNIT_DAY; tSma.interval = 1; - tSma.slidingUnit = TD_TIME_UNIT_HOUR; + tSma.slidingUnit = TIME_UNIT_HOUR; tSma.sliding = 0; tSma.indexUid = indexUid1; tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); @@ -114,10 +114,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { tSma.exprLen = strlen(expr); tSma.expr = (char *)calloc(tSma.exprLen + 1, 1); + ASSERT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1); + ASSERT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); SMeta * pMeta = NULL; @@ -129,18 +131,18 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); assert(pMeta != NULL); // save index 1 - EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); pSmaCfg->indexUid = indexUid2; tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN); pSmaCfg->version = 1; - pSmaCfg->intervalUnit = TD_TIME_UNIT_HOUR; + pSmaCfg->intervalUnit = TIME_UNIT_HOUR; pSmaCfg->interval = 1; - pSmaCfg->slidingUnit = TD_TIME_UNIT_MINUTE; + pSmaCfg->slidingUnit = TIME_UNIT_MINUTE; pSmaCfg->sliding = 5; // save index 2 - EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // get value by indexName STSma *qSmaCfg = NULL; @@ -150,8 +152,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("timezone1 = %s\n", qSmaCfg->timezone); printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); - EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); - EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid); + ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); + ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid); tdDestroyTSma(qSmaCfg); tfree(qSmaCfg); @@ -161,8 +163,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("timezone2 = %s\n", qSmaCfg->timezone); printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : ""); printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); - EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); - EXPECT_EQ(qSmaCfg->interval, tSma.interval); + ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); + ASSERT_EQ(qSmaCfg->interval, tSma.interval); tdDestroyTSma(qSmaCfg); tfree(qSmaCfg); @@ -178,25 +180,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("indexName = %s\n", indexName); ++indexCnt; } - EXPECT_EQ(indexCnt, nCntTSma); + ASSERT_EQ(indexCnt, nCntTSma); metaCloseSmaCurosr(pSmaCur); // get wrapper by table uid STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid); assert(pSW != NULL); - EXPECT_EQ(pSW->number, nCntTSma); - EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); - EXPECT_STRCASEEQ(pSW->tSma->timezone, timezone); - EXPECT_STRCASEEQ(pSW->tSma->expr, expr); - EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); - EXPECT_EQ(pSW->tSma->indexUid, indexUid1); - EXPECT_EQ(pSW->tSma->tableUid, tbUid); - EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); - EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timezone); - EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr); - EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); - EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2); - EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid); + ASSERT_EQ(pSW->number, nCntTSma); + ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); + ASSERT_STRCASEEQ(pSW->tSma->timezone, timezone); + ASSERT_STRCASEEQ(pSW->tSma->expr, expr); + ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); + ASSERT_EQ(pSW->tSma->indexUid, indexUid1); + ASSERT_EQ(pSW->tSma->tableUid, tbUid); + ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); + ASSERT_STRCASEEQ((pSW->tSma + 1)->timezone, timezone); + ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr); + ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); + ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2); + ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid); tdDestroyTSmaWrapper(pSW); tfree(pSW); @@ -208,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i)); // printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i)); } - EXPECT_EQ(taosArrayGetSize(pUids), 1); + ASSERT_EQ(taosArrayGetSize(pUids), 1); taosArrayDestroy(pUids); // resource release @@ -231,7 +233,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { const tb_uid_t tbUid = 1234567890; const int64_t indexUid1 = 2000000001; const int64_t interval1 = 1; - const int8_t intervalUnit1 = TD_TIME_UNIT_DAY; + const int8_t intervalUnit1 = TIME_UNIT_DAY; const uint32_t nCntTSma = 2; TSKEY skey1 = 1646987196; const int64_t testSmaData1 = 100; @@ -239,9 +241,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { // encode STSma tSma = {0}; tSma.version = 0; - tSma.intervalUnit = TD_TIME_UNIT_DAY; + tSma.intervalUnit = TIME_UNIT_DAY; tSma.interval = 1; - tSma.slidingUnit = TD_TIME_UNIT_HOUR; + tSma.slidingUnit = TIME_UNIT_HOUR; tSma.sliding = 0; tSma.indexUid = indexUid1; tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); @@ -250,10 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { tSma.exprLen = strlen(expr); tSma.expr = (char *)calloc(tSma.exprLen + 1, 1); + ASSERT_NE(tSma.expr, nullptr); tstrncpy(tSma.expr, expr, tSma.exprLen + 1); tSma.tagsFilterLen = strlen(tagsFilter); tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1); + ASSERT_NE(tSma.tagsFilter, nullptr); tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); SMeta * pMeta = NULL; @@ -265,7 +269,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { pMeta = metaOpen(smaTestDir, pMetaCfg, NULL); assert(pMeta != NULL); // save index 1 - EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); + ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // step 2: insert data STSmaDataWrapper *pSmaData = NULL; @@ -298,18 +302,19 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { } char *msg = (char *)calloc(100, 1); - EXPECT_EQ(tsdbUpdateSmaWindow(&tsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0); + assert(msg != NULL); + ASSERT_EQ(tsdbUpdateSmaWindow(&tsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0); // init int32_t allocCnt = 0; - int32_t allocStep = 40960; - int32_t buffer = 4096; + int32_t allocStep = 16384; + int32_t buffer = 1024; void * buf = NULL; - EXPECT_EQ(tsdbMakeRoom(&buf, allocStep), 0); + ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0); int32_t bufSize = taosTSizeof(buf); int32_t numOfTables = 10; col_id_t numOfCols = 4096; - EXPECT_GT(numOfCols, 0); + ASSERT_GT(numOfCols, 0); pSmaData = (STSmaDataWrapper *)buf; printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData); @@ -326,7 +331,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { int32_t tableDataLen = sizeof(STSmaTbData); for (col_id_t c = 0; c < numOfCols; ++c) { if (bufSize - len - tableDataLen < buffer) { - EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0); + ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0); pSmaData = (STSmaDataWrapper *)buf; pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len); bufSize = taosTSizeof(buf); @@ -353,22 +358,22 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { } pSmaData->dataLen = (len - sizeof(STSmaDataWrapper)); - EXPECT_GE(bufSize, pSmaData->dataLen); + ASSERT_GE(bufSize, pSmaData->dataLen); // execute - EXPECT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); + ASSERT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); // step 3: query uint32_t checkDataCnt = 0; for (int32_t t = 0; t < numOfTables; ++t) { for (col_id_t c = 0; c < numOfCols; ++c) { - EXPECT_EQ(tsdbGetTSmaData(&tsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t, + ASSERT_EQ(tsdbGetTSmaData(&tsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t, c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1), TSDB_CODE_SUCCESS); ++checkDataCnt; } } - + printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt); // release data diff --git a/source/util/src/terror.c b/source/util/src/terror.c index f97df62ccc..469b944bf9 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -350,6 +350,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_MESSED_MSG, "TSDB messed message") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVLD_TAG_VAL, "TSDB invalid tag value") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_CACHE_LAST_ROW, "TSDB no cache last row data") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_SMA_INDEX_IN_META, "No sma index in meta") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR, "TDB env open error") // query TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, "Invalid handle") From 18f254a0178cd1487b3e31dee4994da4f30d3d9b Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 16 Mar 2022 18:29:31 +0800 Subject: [PATCH 15/20] task deploy and task exec --- include/common/tcommon.h | 21 +++-- include/common/tmsg.h | 100 ++++++++++++++------- include/common/tmsgdef.h | 1 + include/dnode/snode/snode.h | 3 +- source/common/src/tmsg.c | 72 ++++++++++----- source/dnode/mgmt/impl/src/dndSnode.c | 27 ++++-- source/dnode/mnode/impl/inc/mndDef.h | 10 +-- source/dnode/mnode/impl/inc/mndScheduler.h | 2 + source/dnode/mnode/impl/src/mndScheduler.c | 75 ++++++++++------ source/dnode/mnode/impl/src/mndStream.c | 7 ++ source/dnode/snode/CMakeLists.txt | 3 +- source/dnode/snode/inc/sndInt.h | 31 ++----- source/dnode/snode/src/snode.c | 75 +++++++++++++--- 13 files changed, 285 insertions(+), 142 deletions(-) diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 23dd349861..cb8b077b47 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -58,7 +58,10 @@ typedef struct SDataBlockInfo { int32_t rows; int32_t rowSize; int32_t numOfCols; - union {int64_t uid; int64_t blockId;}; + union { + int64_t uid; + int64_t blockId; + }; } SDataBlockInfo; typedef struct SConstantItem { @@ -70,10 +73,10 @@ typedef struct SConstantItem { // info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList); typedef struct SSDataBlock { - SColumnDataAgg *pBlockAgg; - SArray *pDataBlock; // SArray - SArray *pConstantList; // SArray, it is a constant/tags value of the corresponding result value. - SDataBlockInfo info; + SColumnDataAgg* pBlockAgg; + SArray* pDataBlock; // SArray + SArray* pConstantList; // SArray, it is a constant/tags value of the corresponding result value. + SDataBlockInfo info; } SSDataBlock; typedef struct SVarColAttr { @@ -244,7 +247,7 @@ typedef struct SGroupbyExpr { typedef struct SFunctParam { int32_t type; - SColumn *pCol; + SColumn* pCol; SVariant param; } SFunctParam; @@ -262,12 +265,12 @@ typedef struct SResSchame { typedef struct SExprBasicInfo { SResSchema resSchema; int16_t numOfParams; // argument value of each function - SFunctParam *pParam; + SFunctParam* pParam; } SExprBasicInfo; typedef struct SExprInfo { - struct SExprBasicInfo base; - struct tExprNode *pExpr; + struct SExprBasicInfo base; + struct tExprNode* pExpr; } SExprInfo; typedef struct SStateWindow { diff --git a/include/common/tmsg.h b/include/common/tmsg.h index a3e35e1874..30f61374ea 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -24,6 +24,7 @@ #include "thash.h" #include "tlist.h" #include "trow.h" +#include "tuuid.h" #ifdef __cplusplus extern "C" { @@ -171,7 +172,7 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; int64_t dbId; int32_t vgVersion; - int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT } SBuildUseDBInput; typedef struct SField { @@ -427,10 +428,10 @@ typedef struct { int16_t slotId; }; - int16_t type; - int32_t bytes; - uint8_t precision; - uint8_t scale; + int16_t type; + int32_t bytes; + uint8_t precision; + uint8_t scale; } SColumnInfo; typedef struct { @@ -526,7 +527,7 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; int64_t dbId; int32_t vgVersion; - int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT } SUseDbReq; int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); @@ -553,15 +554,13 @@ int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq); int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq); typedef struct { - SArray *epSetList; // SArray + SArray* epSetList; // SArray } SQnodeListRsp; int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp); int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp); void tFreeSQnodeListRsp(SQnodeListRsp* pRsp); - - typedef struct { SArray* pArray; // Array of SUseDbRsp } SUseDbBatchRsp; @@ -777,7 +776,6 @@ typedef struct SVgroupInfo { int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT } SVgroupInfo; - typedef struct { int32_t numOfVgroups; SVgroupInfo vgroups[]; @@ -1062,8 +1060,8 @@ typedef struct { } STaskStatus; typedef struct { - int64_t refId; - SArray *taskStatus; //SArray + int64_t refId; + SArray* taskStatus; // SArray } SSchedulerStatusRsp; typedef struct { @@ -1072,35 +1070,31 @@ typedef struct { int8_t action; } STaskAction; - typedef struct SQueryNodeEpId { int32_t nodeId; // vgId or qnodeId SEp ep; } SQueryNodeEpId; - typedef struct { SMsgHead header; uint64_t sId; SQueryNodeEpId epId; - SArray *taskAction; //SArray + SArray* taskAction; // SArray } SSchedulerHbReq; -int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq); -int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq); -void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq); - +int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq); +int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq); +void tFreeSSchedulerHbReq(SSchedulerHbReq* pReq); typedef struct { uint64_t seqId; SQueryNodeEpId epId; - SArray *taskStatus; //SArray + SArray* taskStatus; // SArray } SSchedulerHbRsp; -int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp); -int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp); -void tFreeSSchedulerHbRsp(SSchedulerHbRsp *pRsp); - +int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp); +int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp); +void tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp); typedef struct { SMsgHead header; @@ -1370,7 +1364,7 @@ typedef struct SVCreateTbReq { } SVCreateTbReq, SVUpdateTbReq; typedef struct { - int tmp; // TODO: to avoid compile error + int tmp; // TODO: to avoid compile error } SVCreateTbRsp, SVUpdateTbRsp; int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); @@ -1382,7 +1376,7 @@ typedef struct { } SVCreateTbBatchReq; typedef struct { - int tmp; // TODO: to avoid compile error + int tmp; // TODO: to avoid compile error } SVCreateTbBatchRsp; int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq); @@ -1396,7 +1390,7 @@ typedef struct { } SVDropTbReq; typedef struct { - int tmp; // TODO: to avoid compile error + int tmp; // TODO: to avoid compile error } SVDropTbRsp; int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq); @@ -1933,7 +1927,7 @@ typedef struct { } SVCreateTSmaReq; typedef struct { - int8_t type; // 0 status report, 1 update data + int8_t type; // 0 status report, 1 update data char indexName[TSDB_INDEX_NAME_LEN]; // STimeWindow windows; } STSmaMsg; @@ -1944,7 +1938,7 @@ typedef struct { } SVDropTSmaReq; typedef struct { - int tmp; // TODO: to avoid compile error + int tmp; // TODO: to avoid compile error } SVCreateTSmaRsp, SVDropTSmaRsp; int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq); @@ -2029,7 +2023,7 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) { tlen += taosEncodeFixedI64(buf, pSma->tableUid); tlen += taosEncodeFixedI64(buf, pSma->interval); tlen += taosEncodeFixedI64(buf, pSma->sliding); - + if (pSma->exprLen > 0) { tlen += taosEncodeString(buf, pSma->expr); } @@ -2064,7 +2058,6 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) { buf = taosDecodeFixedI64(buf, &pSma->interval); buf = taosDecodeFixedI64(buf, &pSma->sliding); - if (pSma->exprLen > 0) { pSma->expr = (char*)calloc(pSma->exprLen, 1); if (pSma->expr != NULL) { @@ -2265,6 +2258,51 @@ static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* p return buf; } +enum { + STREAM_TASK_STATUS__RUNNING = 1, + STREAM_TASK_STATUS__STOP, +}; + +typedef struct { + int64_t streamId; + int32_t taskId; + int32_t level; + int8_t status; + char* qmsg; + void* executor; + // void* stateStore; + // storage handle +} SStreamTask; + +static FORCE_INLINE SStreamTask* streamTaskNew(int64_t streamId, int32_t level) { + SStreamTask* pTask = (SStreamTask*)calloc(1, sizeof(SStreamTask)); + if (pTask == NULL) { + return NULL; + } + pTask->taskId = tGenIdPI32(); + pTask->status = STREAM_TASK_STATUS__RUNNING; + pTask->qmsg = NULL; + return pTask; +} + +int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask); +int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask); +void tFreeSStreamTask(SStreamTask* pTask); + +typedef struct { + SMsgHead head; + SStreamTask* task; +} SStreamTaskDeployReq; + +typedef struct { + int32_t reserved; +} SStreamTaskDeployRsp; + +typedef struct { + SMsgHead head; + // TODO: other info needed by task +} SStreamTaskExecReq; + #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 03f8daad42..b30a325d7c 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -199,6 +199,7 @@ enum { // Requests handled by SNODE TD_NEW_MSG_SEG(TDMT_SND_MSG) + TD_DEF_MSG_TYPE(TDMT_SND_TASK_DEPLOY, "snode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) #if defined(TD_MSG_NUMBER_) TDMT_MAX diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 21a93532e0..b25f8a8666 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -16,6 +16,7 @@ #ifndef _TD_SNODE_H_ #define _TD_SNODE_H_ +#include "tcommon.h" #include "tmsg.h" #include "trpc.h" @@ -78,7 +79,7 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad); * @param pRsp The response message * @return int32_t 0 for success, -1 for failure */ -int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +// int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index f26f19f3b2..121f5271b3 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1467,8 +1467,7 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) { return 0; } - -int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq) { +int32_t tSerializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -1499,7 +1498,7 @@ int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) if (tStartEncode(&encoder) < 0) return -1; int32_t num = taosArrayGetSize(pRsp->epSetList); - if (tEncodeI32(&encoder, num) < 0) return -1; + if (tEncodeI32(&encoder, num) < 0) return -1; for (int32_t i = 0; i < num; ++i) { SEpSet *epSet = taosArrayGet(pRsp->epSetList, i); if (tEncodeSEpSet(&encoder, epSet) < 0) return -1; @@ -2491,27 +2490,27 @@ int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pR tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeU64(&encoder, pReq->sId) < 0) return -1; - if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1; + if (tEncodeU64(&encoder, pReq->sId) < 0) return -1; + if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1; if (tEncodeU16(&encoder, pReq->epId.ep.port) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1; if (pReq->taskAction) { int32_t num = taosArrayGetSize(pReq->taskAction); - if (tEncodeI32(&encoder, num) < 0) return -1; + if (tEncodeI32(&encoder, num) < 0) return -1; for (int32_t i = 0; i < num; ++i) { STaskAction *action = taosArrayGet(pReq->taskAction, i); - if (tEncodeU64(&encoder, action->queryId) < 0) return -1; - if (tEncodeU64(&encoder, action->taskId) < 0) return -1; - if (tEncodeI8(&encoder, action->action) < 0) return -1; + if (tEncodeU64(&encoder, action->queryId) < 0) return -1; + if (tEncodeU64(&encoder, action->taskId) < 0) return -1; + if (tEncodeI8(&encoder, action->action) < 0) return -1; } } else { - if (tEncodeI32(&encoder, 0) < 0) return -1; + if (tEncodeI32(&encoder, 0) < 0) return -1; } tEndEncode(&encoder); int32_t tlen = encoder.pos; tCoderClear(&encoder); - + if (buf != NULL) { SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); pHead->vgId = htonl(pReq->header.vgId); @@ -2559,29 +2558,27 @@ int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq * void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq) { taosArrayDestroy(pReq->taskAction); } - - int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1; + if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1; if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1; - if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1; + if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1; if (pRsp->taskStatus) { int32_t num = taosArrayGetSize(pRsp->taskStatus); - if (tEncodeI32(&encoder, num) < 0) return -1; + if (tEncodeI32(&encoder, num) < 0) return -1; for (int32_t i = 0; i < num; ++i) { STaskStatus *status = taosArrayGet(pRsp->taskStatus, i); - if (tEncodeU64(&encoder, status->queryId) < 0) return -1; - if (tEncodeU64(&encoder, status->taskId) < 0) return -1; - if (tEncodeI64(&encoder, status->refId) < 0) return -1; - if (tEncodeI8(&encoder, status->status) < 0) return -1; + if (tEncodeU64(&encoder, status->queryId) < 0) return -1; + if (tEncodeU64(&encoder, status->taskId) < 0) return -1; + if (tEncodeI64(&encoder, status->refId) < 0) return -1; + if (tEncodeI8(&encoder, status->status) < 0) return -1; } } else { - if (tEncodeI32(&encoder, 0) < 0) return -1; + if (tEncodeI32(&encoder, 0) < 0) return -1; } tEndEncode(&encoder); @@ -2694,3 +2691,32 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { tfree(pReq->physicalPlan); tfree(pReq->logicalPlan); } + +int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) { + if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->level) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; + if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1; + tEndEncode(pEncoder); + return pEncoder->pos; +} + +int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { + if (tStartDecode(pDecoder) < 0) return -1; + if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; + if (tDecodeCStr(pDecoder, (const char **)&pTask->qmsg) < 0) return -1; + tEndDecode(pDecoder); + return 0; +} + +void tFreeSStreamTask(SStreamTask *pTask) { + // TODO + /*free(pTask->qmsg);*/ + /*free(pTask->executor);*/ + /*free(pTask);*/ +} diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index 5ea8a841d2..8667952f2c 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -323,8 +323,8 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pReq) { } static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t numOfMsgs) { - SSnodeMgmt *pMgmt = &pDnode->smgmt; - int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + /*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/ + int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; SSnode *pSnode = dndAcquireSnode(pDnode); if (pSnode != NULL) { @@ -334,22 +334,35 @@ static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t sndProcessUMsg(pSnode, pMsg); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + } + dndReleaseSnode(pDnode, pSnode); + } else { + for (int32_t i = 0; i < numOfMsgs; i++) { + SRpcMsg *pMsg = NULL; + taosGetQitem(qall, (void **)&pMsg); + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } } - dndReleaseSnode(pDnode, pSnode); } static void dndProcessSnodeSharedQueue(SDnode *pDnode, SRpcMsg *pMsg) { - SSnodeMgmt *pMgmt = &pDnode->smgmt; - int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + /*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/ + int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; SSnode *pSnode = dndAcquireSnode(pDnode); if (pSnode != NULL) { - code = sndProcessSMsg(pSnode, pMsg); + sndProcessSMsg(pSnode, pMsg); + dndReleaseSnode(pDnode, pSnode); + } else { + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); } - dndReleaseSnode(pDnode, pSnode); #if 0 if (pMsg->msgType & 1u) { diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index a7116b72ff..8ea9cc141f 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -85,6 +85,8 @@ typedef enum { TRN_TYPE_REBALANCE = 1017, TRN_TYPE_COMMIT_OFFSET = 1018, TRN_TYPE_CREATE_STREAM = 1019, + TRN_TYPE_DROP_STREAM = 1020, + TRN_TYPE_ALTER_STREAM = 1021, TRN_TYPE_BASIC_SCOPE_END, TRN_TYPE_GLOBAL_SCOPE = 2000, TRN_TYPE_CREATE_DNODE = 2001, @@ -679,12 +681,6 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons return buf; } -typedef struct { - int32_t taskId; - int32_t level; - SSubplan* plan; -} SStreamTaskMeta; - typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN]; @@ -700,7 +696,7 @@ typedef struct { char* sql; char* logicalPlan; char* physicalPlan; - SArray* tasks; // SArray> + SArray* tasks; // SArray> } SStreamObj; int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj); diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 3bf6e0c33a..42951beca2 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -27,6 +27,8 @@ void mndCleanupScheduler(SMnode* pMnode); int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub); +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 855e244daa..16b1ba8a5c 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -31,7 +31,7 @@ #include "tname.h" #include "tuuid.h" -int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SSdb* pSdb = pMnode->pSdb; SVgObj* pVgroup = NULL; SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); @@ -41,17 +41,18 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { } ASSERT(pStream->vgNum == 0); - int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); - pStream->tasks = taosArrayInit(levelNum, sizeof(SArray)); + int32_t totLevel = LIST_LENGTH(pPlan->pSubplans); + pStream->tasks = taosArrayInit(totLevel, sizeof(SArray)); - for (int32_t i = 0; i < levelNum; i++) { - SArray* taskOneLevel = taosArrayInit(0, sizeof(SStreamTaskMeta)); - SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, i); + int32_t msgLen; + for (int32_t level = 0; level < totLevel; level++) { + SArray* taskOneLevel = taosArrayInit(0, sizeof(SStreamTask)); + SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level); int32_t opNum = LIST_LENGTH(inner->pNodeList); ASSERT(opNum == 1); - SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); - if (i == 0) { + SSubplan* plan = nodesListGetNode(inner->pNodeList, level); + if (level == 0) { ASSERT(plan->type == SUBPLAN_TYPE_SCAN); void* pIter = NULL; while (1) { @@ -63,15 +64,19 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { } pStream->vgNum++; + // send to vnode + + SStreamTask* pTask = streamTaskNew(pStream->uid, level); + plan->execNode.nodeId = pVgroup->vgId; plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup); - SStreamTaskMeta task = { - .taskId = tGenIdPI32(), - .level = i, - .plan = plan, - }; - // send to vnode - taosArrayPush(taskOneLevel, &task); + if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } + taosArrayPush(taskOneLevel, pTask); } } else if (plan->subplanType == SUBPLAN_TYPE_SCAN) { // duplicatable @@ -82,22 +87,36 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { // if has snode, set to shared thread num in snode parallel = SND_SHARED_THREAD_NUM; - for (int32_t j = 0; j < parallel; j++) { - SStreamTaskMeta task = { - .taskId = tGenIdPI32(), - .level = i, - .plan = plan, - }; - taosArrayPush(taskOneLevel, &task); + for (int32_t i = 0; i < parallel; i++) { + SStreamTask* pTask = streamTaskNew(pStream->uid, level); + + // TODO:get snode id and ep + plan->execNode.nodeId = pVgroup->vgId; + plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup); + + if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) { + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } + + taosArrayPush(taskOneLevel, pTask); } } else { // not duplicatable - SStreamTaskMeta task = { - .taskId = tGenIdPI32(), - .level = i, - .plan = plan, - }; - taosArrayPush(taskOneLevel, &task); + SStreamTask* pTask = streamTaskNew(pStream->uid, level); + + // TODO:get snode id and ep + plan->execNode.nodeId = pVgroup->vgId; + plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup); + + if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } + taosArrayPush(taskOneLevel, pTask); } taosArrayPush(pStream->tasks, taskOneLevel); } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 54ad9cd7e2..67011dfe8a 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -18,6 +18,7 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" +#include "mndScheduler.h" #include "mndShow.h" #include "mndStb.h" #include "mndTrans.h" @@ -237,6 +238,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateStreamR } sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); + if (mndScheduleStream(pMnode, pTrans, &streamObj) < 0) { + mError("stream:%ld, schedule stream since %s", streamObj.uid, terrstr()); + mndTransDrop(pTrans); + return -1; + } + if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); diff --git a/source/dnode/snode/CMakeLists.txt b/source/dnode/snode/CMakeLists.txt index dafd5d6594..d1b1abdf1d 100644 --- a/source/dnode/snode/CMakeLists.txt +++ b/source/dnode/snode/CMakeLists.txt @@ -7,8 +7,9 @@ target_include_directories( ) target_link_libraries( snode + PRIVATE executor PRIVATE transport PRIVATE os PRIVATE common PRIVATE util -) \ No newline at end of file +) diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 3fe816845d..e5f6c3c266 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -38,13 +38,8 @@ enum { STREAM_STATUS__DELETING, }; -enum { - STREAM_TASK_STATUS__RUNNING = 1, - STREAM_TASK_STATUS__STOP, -}; - typedef struct { - SHashObj* pHash; // taskId -> streamTask + SHashObj* pHash; // taskId -> SStreamTask } SStreamMeta; typedef struct SSnode { @@ -52,26 +47,16 @@ typedef struct SSnode { SSnodeOpt cfg; } SSnode; -typedef struct { - int64_t streamId; - int32_t taskId; - int32_t IdxInLevel; - int32_t level; -} SStreamTaskInfo; +SStreamMeta* sndMetaNew(); +void sndMetaDelete(SStreamMeta* pMeta); -typedef struct { - SStreamTaskInfo meta; - int8_t status; - void* executor; - void* stateStore; - // storage handle -} SStreamTask; +int32_t sndMetaDeployTask(SStreamMeta* pMeta, SStreamTask* pTask); +int32_t sndMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId); -int32_t sndCreateTask(); -int32_t sndDropTaskOfStream(int64_t streamId); +int32_t sndDropTaskOfStream(SStreamMeta* pMeta, int64_t streamId); -int32_t sndStopTaskOfStream(int64_t streamId); -int32_t sndResumeTaskOfStream(int64_t streamId); +int32_t sndStopTaskOfStream(SStreamMeta* pMeta, int64_t streamId); +int32_t sndResumeTaskOfStream(SStreamMeta* pMeta, int64_t streamId); #ifdef __cplusplus } diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 74e41d45c5..80e33bd971 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -13,40 +13,91 @@ * along with this program. If not, see . */ +#include "executor.h" #include "sndInt.h" #include "tuuid.h" SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { SSnode *pSnode = calloc(1, sizeof(SSnode)); + if (pSnode == NULL) { + return NULL; + } memcpy(&pSnode->cfg, pOption, sizeof(SSnodeOpt)); + pSnode->pMeta = sndMetaNew(); + if (pSnode->pMeta == NULL) { + free(pSnode); + return NULL; + } return pSnode; } -void sndClose(SSnode *pSnode) { free(pSnode); } +void sndClose(SSnode *pSnode) { + sndMetaDelete(pSnode->pMeta); + free(pSnode); +} int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; } -int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - *pRsp = NULL; - return 0; -} +/*int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {*/ +/**pRsp = NULL;*/ +/*return 0;*/ +/*}*/ void sndDestroy(const char *path) {} -static int32_t sndDeployTask(SSnode *pSnode, SRpcMsg *pMsg) { - SStreamTask *task = malloc(sizeof(SStreamTask)); - if (task == NULL) { +SStreamMeta *sndMetaNew() { + SStreamMeta *pMeta = calloc(1, sizeof(SStreamMeta)); + if (pMeta == NULL) { + return NULL; + } + pMeta->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (pMeta->pHash == NULL) { + free(pMeta); + return NULL; + } + return pMeta; +} + +void sndMetaDelete(SStreamMeta *pMeta) { + taosHashCleanup(pMeta->pHash); + free(pMeta); +} + +int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) { + pTask->executor = qCreateStreamExecTaskInfo(pTask->qmsg, NULL); + return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *)); +} + +int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { + SStreamTask *pTask = taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + if (pTask == NULL) { return -1; } - task->meta.taskId = tGenIdPI32(); - taosHashPut(pSnode->pMeta->pHash, &task->meta.taskId, sizeof(int32_t), &task, sizeof(void *)); - return 0; + free(pTask->qmsg); + // TODO:free executor + free(pTask); + return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t)); } int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { - // stream deployment + // stream deploy // stream stop/resume // operator exec + if (pMsg->msgType == TDMT_SND_TASK_DEPLOY) { + void *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + SStreamTask *pTask = malloc(sizeof(SStreamTask)); + if (pTask == NULL) { + return -1; + } + SCoder decoder; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, msg, pMsg->contLen - sizeof(SMsgHead), TD_DECODER); + tDecodeSStreamTask(&decoder, pTask); + tCoderClear(&decoder); + + sndMetaDeployTask(pSnode->pMeta, pTask); + } else { + // + } return 0; } From 231ac079bee6f2304da05d2d5a66dc87dc4211be Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 16 Mar 2022 19:01:45 +0800 Subject: [PATCH 16/20] refactor --- source/dnode/vnode/src/tsdb/tsdbFile.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbSma.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index b756cc9862..00e97c7b61 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = { "smal", // TSDB_FILE_SMAL "", // TSDB_FILE_MAX "meta", // TSDB_FILE_META - "sma", // TSDB_FILE_TSMA(directory name) - "sma", // TSDB_FILE_RSMA(directory name) + "tsma", // TSDB_FILE_TSMA + "rsma", // TSDB_FILE_RSMA }; static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname); diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 880eb403f4..cd8b60385f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -15,6 +15,12 @@ #include "tsdbDef.h" +static const char *TSDB_SMA_DNAME[] = { + "", // TSDB_SMA_TYPE_BLOCK + "tsma", // TSDB_SMA_TYPE_TIME_RANGE + "rsma", // TSDB_SMA_TYPE_ROLLUP +}; + #undef SMA_PRINT_DEBUG_LOG #define SMA_STORAGE_TSDB_DAYS 30 #define SMA_STORAGE_TSDB_TIMES 10 @@ -93,10 +99,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid); static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, TSKEY skey); static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey); -static void tsdbGetSmaDir(int32_t repoid, int8_t smaType, char dirName[]); +static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]); -static void tsdbGetSmaDir(int32_t repoid, int8_t smaType, char dirName[]) { - snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/data", repoid); +static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) { + snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s", vgId, TSDB_SMA_DNAME[smaType]); } static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path) { From 3d4280c705a114819646229f3bda1a4db2f7dd6c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Mar 2022 19:23:45 +0800 Subject: [PATCH 17/20] handle except --- source/libs/transport/src/transCli.c | 7 ++++++- source/libs/transport/test/transUT.cc | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0932241abf..2c5c4810af 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -582,8 +582,13 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) { SCliConn* conn = cliGetConn(pMsg, pThrd); if (conn != NULL) { - taosArrayPush(conn->cliMsgs, &pMsg); conn->hThrdIdx = pCtx->hThrdIdx; + + if (taosArrayGetSize(conn->cliMsgs) > 0) { + taosArrayPush(conn->cliMsgs, &pMsg); + return; + } + taosArrayPush(conn->cliMsgs, &pMsg); transDestroyBuffer(&conn->readBuf); cliSend(conn); } else { diff --git a/source/libs/transport/test/transUT.cc b/source/libs/transport/test/transUT.cc index b3fbade050..bdbfb4a0ae 100644 --- a/source/libs/transport/test/transUT.cc +++ b/source/libs/transport/test/transUT.cc @@ -50,6 +50,7 @@ static void *ConstructArgForSpecificMsgType(void *parent, tmsg_t msgType) { } // server except static bool handleExcept(void *parent, tmsg_t msgType) { + // return msgType == TDMT_VND_QUERY || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP; } typedef void (*CB)(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet); From 575ab144393190af14a10914d71ceaaf4fbbeebd Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 16 Mar 2022 19:28:33 +0800 Subject: [PATCH 18/20] trow bug fix --- include/common/trow.h | 30 +++++++++++++++--------------- source/libs/parser/src/parInsert.c | 6 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/common/trow.h b/include/common/trow.h index 4dd3daba4d..47edf6f1ad 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -98,13 +98,13 @@ typedef void *SRow; typedef struct { TDRowValT valType; - void *val; + void * val; } SCellVal; typedef struct { // TODO - int tmp; // TODO: to avoid compile error -} STpRow; // tuple + int tmp; // TODO: to avoid compile error +} STpRow; // tuple #pragma pack(push, 1) typedef struct { @@ -158,8 +158,8 @@ typedef struct { int16_t nBitmaps; int16_t nBoundBitmaps; int32_t offset; - void *pBitmap; - void *pOffset; + void * pBitmap; + void * pOffset; int32_t extendedRowSize; } SRowBuilder; @@ -273,7 +273,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD } int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nOffset = colIdx & TD_VTYPE_OPTR; - char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); + char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); switch (nOffset) { case 0: *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); @@ -311,7 +311,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD } int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nOffset = colIdx & TD_VTYPE_OPTR; - char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); + char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); switch (nOffset) { case 0: *pValType = (((*pDestByte) & 0xC0) >> 6); @@ -617,7 +617,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa if (tdValIsNorm(valType, val, colType)) { // ts key stored in STSRow.ts SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); - char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); + char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); pColIdx->colId = colId; pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN @@ -635,7 +635,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa // NULL/None value else { SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); - char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); + char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); pColIdx->colId = colId; pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN const void *nullVal = getNullValue(colType); @@ -697,9 +697,9 @@ static FORCE_INLINE int32_t tdAppendColValToRow(SRowBuilder *pBuilder, int16_t c } // TODO: We can avoid the type judegement by FP, but would prevent the inline scheme. if (TD_IS_TP_ROW(pRow)) { - tdAppendColValToTpRow(pBuilder, valType, val, true, colType, colIdx, offset); + tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset); } else { - tdAppendColValToKvRow(pBuilder, valType, val, true, colType, colIdx, offset, colId); + tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId); } return TSDB_CODE_SUCCESS; } @@ -771,8 +771,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v typedef struct { STSchema *pSchema; - STSRow *pRow; - void *pBitmap; + STSRow * pRow; + void * pBitmap; uint32_t offset; col_id_t maxColId; col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1 @@ -877,7 +877,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy // internal static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal) { - STSRow *pRow = pIter->pRow; + STSRow * pRow = pIter->pRow; SKvRowIdx *pKvIdx = NULL; bool colFound = false; col_id_t kvNCols = tdRowGetNCols(pRow); @@ -1068,7 +1068,7 @@ typedef struct { typedef struct { STSchema *pSchema; - STSRow *pRow; + STSRow * pRow; } STSRowReader; typedef struct { diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 28f680cfbb..6db3abb9d6 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -617,7 +617,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { const char* rowEnd = tdRowEnd(rb->pBuf); STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len); - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, true, pa->toffset, pa->colIdx); } else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' int32_t output = 0; @@ -626,9 +626,9 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; } varDataSetLen(rowEnd, output); - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, true, pa->toffset, pa->colIdx); } else { - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, true, pa->toffset, pa->colIdx); + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx); } return TSDB_CODE_SUCCESS; } From 7f4c88b756c5c42b34f29379a1efde747549edce Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 16 Mar 2022 19:40:48 +0800 Subject: [PATCH 19/20] task deploy and task exec --- include/common/tmsg.h | 4 ++++ include/common/tmsgdef.h | 1 + include/util/tencode.h | 25 ++++++++++++++++++++++++- source/common/src/tmsg.c | 8 ++++---- source/dnode/mnode/impl/src/mndDef.c | 6 +++--- source/dnode/snode/inc/sndInt.h | 5 +++-- source/dnode/snode/src/snode.c | 23 ++++++++++++++++++++++- 7 files changed, 61 insertions(+), 11 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 7e9b2186da..b449cad2a1 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2306,6 +2306,10 @@ typedef struct { // TODO: other info needed by task } SStreamTaskExecReq; +typedef struct { + int32_t reserved; +} SStreamTaskExecRsp; + #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index b30a325d7c..6a07887721 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -200,6 +200,7 @@ enum { // Requests handled by SNODE TD_NEW_MSG_SEG(TDMT_SND_MSG) TD_DEF_MSG_TYPE(TDMT_SND_TASK_DEPLOY, "snode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) + TD_DEF_MSG_TYPE(TDMT_SND_TASK_EXEC, "snode-task-exec", SStreamTaskExecReq, SStreamTaskExecRsp) #if defined(TD_MSG_NUMBER_) TDMT_MAX diff --git a/include/util/tencode.h b/include/util/tencode.h index c058eebb50..cbbd55c8a3 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -402,10 +402,33 @@ static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) { return 0; } +static FORCE_INLINE int32_t tDecodeBinaryAlloc(SCoder* pDecoder, void** val, uint64_t* len) { + if (tDecodeU64v(pDecoder, len) < 0) return -1; + + if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; + *val = malloc(*len); + if (*val == NULL) return -1; + memcpy(*val, TD_CODER_CURRENT(pDecoder), *len); + + TD_CODER_MOVE_POS(pDecoder, *len); + return 0; +} + +static FORCE_INLINE int32_t tDecodeCStrAndLenAlloc(SCoder* pDecoder, char** val, uint64_t* len) { + if (tDecodeBinaryAlloc(pDecoder, (void**)val, len) < 0) return -1; + (*len) -= 1; + return 0; +} + +static FORCE_INLINE int32_t tDecodeCStrAlloc(SCoder* pDecoder, char** val) { + uint64_t len; + return tDecodeCStrAndLenAlloc(pDecoder, val, &len); +} + static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } #ifdef __cplusplus } #endif -#endif /*_TD_UTIL_ENCODE_H_*/ \ No newline at end of file +#endif /*_TD_UTIL_ENCODE_H_*/ diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 469090c05b..794e5a8542 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2674,9 +2674,9 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; - if (tDecodeCStr(&decoder, (const char **)&pReq->sql) < 0) return -1; - if (tDecodeCStr(&decoder, (const char **)&pReq->physicalPlan) < 0) return -1; - if (tDecodeCStr(&decoder, (const char **)&pReq->logicalPlan) < 0) return -1; + if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1; + if (tDecodeCStrAlloc(&decoder, &pReq->physicalPlan) < 0) return -1; + if (tDecodeCStrAlloc(&decoder, &pReq->logicalPlan) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -2706,7 +2706,7 @@ int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; - if (tDecodeCStr(pDecoder, (const char **)&pTask->qmsg) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1; tEndDecode(pDecoder); return 0; } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 6e8d9aa79f..cc5bf843ce 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -39,8 +39,8 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1; if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1; if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1; - if (tDecodeCStr(pDecoder, (const char **)&pObj->sql) < 0) return -1; - if (tDecodeCStr(pDecoder, (const char **)&pObj->logicalPlan) < 0) return -1; - if (tDecodeCStr(pDecoder, (const char **)&pObj->physicalPlan) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1; return 0; } diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index e5f6c3c266..d1122fc4ec 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -50,8 +50,9 @@ typedef struct SSnode { SStreamMeta* sndMetaNew(); void sndMetaDelete(SStreamMeta* pMeta); -int32_t sndMetaDeployTask(SStreamMeta* pMeta, SStreamTask* pTask); -int32_t sndMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId); +int32_t sndMetaDeployTask(SStreamMeta* pMeta, SStreamTask* pTask); +SStreamTask* sndMetaGetTask(SStreamMeta* pMeta, int32_t taskId); +int32_t sndMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId); int32_t sndDropTaskOfStream(SStreamMeta* pMeta, int64_t streamId); diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 80e33bd971..2ecaeb00e9 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -68,6 +68,10 @@ int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) { return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *)); } +SStreamTask *sndMetaGetTask(SStreamMeta *pMeta, int32_t taskId) { + return taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); +} + int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { SStreamTask *pTask = taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); if (pTask == NULL) { @@ -79,6 +83,16 @@ int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t)); } +static int32_t sndProcessTaskExecReq(SSnode *pSnode, SRpcMsg *pMsg) { + SMsgHead *pHead = pMsg->pCont; + int32_t taskId = pHead->streamTaskId; + SStreamTask *pTask = sndMetaGetTask(pSnode->pMeta, taskId); + if (pTask == NULL) { + return -1; + } + return 0; +} + int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { // stream deploy // stream stop/resume @@ -95,13 +109,20 @@ int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { tCoderClear(&decoder); sndMetaDeployTask(pSnode->pMeta, pTask); + } else if (pMsg->msgType == TDMT_SND_TASK_EXEC) { + sndProcessTaskExecReq(pSnode, pMsg); } else { - // + ASSERT(0); } return 0; } int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { // operator exec + if (pMsg->msgType == TDMT_SND_TASK_EXEC) { + sndProcessTaskExecReq(pSnode, pMsg); + } else { + ASSERT(0); + } return 0; } From fda9803c176f47826aba16466267bbb5d5a7638a Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 16 Mar 2022 20:03:22 +0800 Subject: [PATCH 20/20] sync refactor --- source/libs/sync/src/syncAppendEntries.c | 20 ++++++++++++-------- source/libs/sync/src/syncCommit.c | 6 +++++- source/libs/sync/src/syncIO.c | 13 ++++++++++--- source/libs/sync/src/syncMain.c | 6 +++--- source/libs/sync/src/syncRaftLog.c | 17 ++++++++++------- source/libs/sync/test/syncElectTest.cpp | 9 ++++++--- source/libs/sync/test/syncLogStoreTest.cpp | 6 +++--- 7 files changed, 49 insertions(+), 28 deletions(-) diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 87d6669f59..888d7e16d1 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -102,7 +102,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SyncTerm localPreLogTerm = 0; if (pMsg->prevLogTerm >= SYNC_INDEX_BEGIN && pMsg->prevLogTerm <= ths->pLogStore->getLastIndex(ths->pLogStore)) { - SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogTerm); + SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex); assert(pEntry != NULL); localPreLogTerm = pEntry->term; syncEntryDestory(pEntry); @@ -111,9 +111,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { bool logOK = (pMsg->prevLogIndex == SYNC_INDEX_INVALID) || ((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) && - (pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogIndex == localPreLogTerm)); + (pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogTerm == localPreLogTerm)); - // reject + // reject request if ((pMsg->term < ths->pRaftStore->currentTerm) || ((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) { SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); @@ -134,6 +134,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // return to follower state if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { syncNodeBecomeFollower(ths); + + // need ret? + return ret; } // accept request @@ -144,17 +147,17 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { matchSuccess = true; } if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) { - SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogTerm); - assert(pEntry != NULL); - if (pMsg->prevLogTerm == pEntry->term) { + SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex); + assert(pPreEntry != NULL); + if (pMsg->prevLogTerm == pPreEntry->term) { matchSuccess = true; } - syncEntryDestory(pEntry); + syncEntryDestory(pPreEntry); } if (matchSuccess) { // delete conflict entries - if (ths->pLogStore->getLastIndex(ths->pLogStore) > pMsg->prevLogIndex) { + if (pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore)) { SyncIndex fromIndex = pMsg->prevLogIndex + 1; ths->pLogStore->truncate(ths->pLogStore, fromIndex); } @@ -178,6 +181,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); syncAppendEntriesReplyDestroy(pReply); + } else { SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); pReply->srcId = ths->myRaftId; diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index ec4272fdd0..850468f393 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "syncIndexMgr.h" #include "syncInt.h" // \* Leader i advances its commitIndex. @@ -38,4 +39,7 @@ // IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex] // /\ UNCHANGED <> // -void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {} \ No newline at end of file +void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { + syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex); + syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex); +} \ No newline at end of file diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index e6a43f2bb5..c8448c32eb 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -29,7 +29,7 @@ static int32_t syncIODestroy(SSyncIO *io); static int32_t syncIOStartInternal(SSyncIO *io); static int32_t syncIOStopInternal(SSyncIO *io); -static void * syncIOConsumerFunc(void *param); +static void *syncIOConsumerFunc(void *param); static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey); @@ -234,9 +234,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO * io = param; + SSyncIO *io = param; STaosQall *qall; - SRpcMsg * pRpcMsg, rpcMsg; + SRpcMsg *pRpcMsg, rpcMsg; qall = taosAllocateQall(); while (1) { @@ -269,6 +269,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_PING_REPLY) { if (io->FpOnSyncPingReply != NULL) { SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncPingReply(io->pSyncNode, pSyncMsg); syncPingReplyDestroy(pSyncMsg); } @@ -276,6 +277,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST) { if (io->FpOnSyncClientRequest != NULL) { SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncClientRequest(io->pSyncNode, pSyncMsg); syncClientRequestDestroy(pSyncMsg); } @@ -283,6 +285,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE) { if (io->FpOnSyncRequestVote != NULL) { SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncRequestVote(io->pSyncNode, pSyncMsg); syncRequestVoteDestroy(pSyncMsg); } @@ -290,6 +293,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) { if (io->FpOnSyncRequestVoteReply != NULL) { SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncRequestVoteReply(io->pSyncNode, pSyncMsg); syncRequestVoteReplyDestroy(pSyncMsg); } @@ -297,6 +301,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES) { if (io->FpOnSyncAppendEntries != NULL) { SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncAppendEntries(io->pSyncNode, pSyncMsg); syncAppendEntriesDestroy(pSyncMsg); } @@ -304,6 +309,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES_REPLY) { if (io->FpOnSyncAppendEntriesReply != NULL) { SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncAppendEntriesReply(io->pSyncNode, pSyncMsg); syncAppendEntriesReplyDestroy(pSyncMsg); } @@ -311,6 +317,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == SYNC_TIMEOUT) { if (io->FpOnSyncTimeout != NULL) { SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); io->FpOnSyncTimeout(io->pSyncNode, pSyncMsg); syncTimeoutDestroy(pSyncMsg); } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 7d2087eded..ff446dfc27 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -563,11 +563,11 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode) { // stop elect timer syncNodeStopElectTimer(pSyncNode); - // start heartbeat timer - syncNodeStartHeartbeatTimer(pSyncNode); - // start replicate right now! syncNodeReplicate(pSyncNode); + + // start heartbeat timer + syncNodeStartHeartbeatTimer(pSyncNode); } void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index f3fd7f84a2..01ec761a9c 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -63,15 +63,18 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; - SSyncRaftEntry* pEntry; + SSyncRaftEntry* pEntry = NULL; - SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); - walReadWithHandle(pWalHandle, index); - pEntry = syncEntryDeserialize(pWalHandle->pHead->head.body, pWalHandle->pHead->head.len); - assert(pEntry != NULL); + if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) { + SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + walReadWithHandle(pWalHandle, index); + pEntry = syncEntryDeserialize(pWalHandle->pHead->head.body, pWalHandle->pHead->head.len); + assert(pEntry != NULL); + + // need to hold, do not new every time!! + walCloseReadHandle(pWalHandle); + } - // need to hold, do not new every time!! - walCloseReadHandle(pWalHandle); return pEntry; } diff --git a/source/libs/sync/test/syncElectTest.cpp b/source/libs/sync/test/syncElectTest.cpp index e52fe61ef5..b8a1460f35 100644 --- a/source/libs/sync/test/syncElectTest.cpp +++ b/source/libs/sync/test/syncElectTest.cpp @@ -17,7 +17,7 @@ void logTest() { } uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; -int32_t replicaNum = 1; +int32_t replicaNum = 3; int32_t myIndex = 0; SRaftId ids[TSDB_MAX_REPLICA]; @@ -33,7 +33,7 @@ SSyncNode* syncNodeInit() { syncInfo.queue = gSyncIO->pMsgQ; syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./elect_test"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "./elect_test_%d", myIndex); int code = walInit(); assert(code == 0); @@ -46,7 +46,10 @@ SSyncNode* syncNodeInit() { walCfg.retentionSize = 1000; walCfg.segSize = 1000; walCfg.level = TAOS_WAL_FSYNC; - pWal = walOpen("./elect_test_wal", &walCfg); + + char tmpdir[128]; + snprintf(tmpdir, sizeof(tmpdir), "./elect_test_wal_%d", myIndex); + pWal = walOpen(tmpdir, &walCfg); assert(pWal != NULL); syncInfo.pWal = pWal; diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index 1b05f76fa2..c1cb66f382 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -81,7 +81,7 @@ SSyncNode* syncNodeInit() { SSyncNode* syncInitTest() { return syncNodeInit(); } void logStoreTest() { - logStorePrint2((char*)"logStoreTest2", pSyncNode->pLogStore); + logStorePrint2((char*)"logStoreTest", pSyncNode->pLogStore); assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_INVALID); @@ -105,10 +105,10 @@ void logStoreTest() { assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_BEGIN); } } - logStorePrint(pSyncNode->pLogStore); + logStorePrint2((char*)"after appendEntry", pSyncNode->pLogStore); pSyncNode->pLogStore->truncate(pSyncNode->pLogStore, 3); - logStorePrint(pSyncNode->pLogStore); + logStorePrint2((char*)"after truncate 3", pSyncNode->pLogStore); } void initRaftId(SSyncNode* pSyncNode) {