From 0c8f62f701d263be26c84a30c0fbee300af39ba7 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 14:51:02 +0800 Subject: [PATCH 01/23] sync refactor --- source/libs/sync/inc/syncInt.h | 2 +- source/libs/sync/inc/syncRaftEntry.h | 12 ++- source/libs/sync/inc/syncRaftLog.h | 37 ++++++--- source/libs/sync/inc/syncVoteMgr.h | 8 +- source/libs/sync/src/syncMain.c | 25 ++++-- source/libs/sync/src/syncRaftLog.c | 83 +++++++++++-------- source/libs/sync/test/syncIndexMgrTest.cpp | 1 - source/libs/sync/test/syncInitTest.cpp | 1 - source/libs/sync/test/syncPingTest.cpp | 1 - .../libs/sync/test/syncVotesGrantedTest.cpp | 1 - .../libs/sync/test/syncVotesRespondTest.cpp | 1 - 11 files changed, 105 insertions(+), 67 deletions(-) diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 8b77e292c4..1ca705441d 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -116,7 +116,7 @@ typedef struct SSyncNode { SyncGroupId vgId; SSyncCfg syncCfg; char path[TSDB_FILENAME_LEN]; - char walPath[TSDB_FILENAME_LEN]; + SWal* pWal; void* rpcClient; int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg); void* queue; diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index 516bef4d48..9cc05d44a9 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -27,10 +27,14 @@ extern "C" { #include "taosdef.h" typedef struct SSyncRaftEntry { - SyncTerm term; - SyncIndex index; - SSyncBuffer data; - int8_t flag; + uint32_t bytes; + uint32_t msgType; + SyncTerm term; + SyncIndex index; + int8_t flag; + uint32_t dataLen; + char data[]; + } SSyncRaftEntry; #ifdef __cplusplus diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index ee971062cf..8205f19d91 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -24,27 +24,42 @@ extern "C" { #include #include #include "syncInt.h" +#include "syncRaftEntry.h" #include "taosdef.h" -int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf); +typedef struct SSyncLogStoreData { + SSyncNode* pSyncNode; + SWal* pWal; +} SSyncLogStoreData; -// get one log entry, user need to free pBuf->data -int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf); +SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode); -// update log store commit index with "index" -int32_t raftLogUpdateCommitIndex(struct SSyncLogStore* pLogStore, SyncIndex index); +void logStoreDestory(SSyncLogStore* pLogStore); -// truncate log with index, entries after the given index (>index) will be deleted -int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex index); +// append one log entry +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry); -// return commit index of log -SyncIndex raftLogGetCommitIndex(struct SSyncLogStore* pLogStore); +// get one log entry, user need to free pEntry->pCont +int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry); + +// truncate log with index, entries after the given index (>=index) will be deleted +int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex); // return index of last entry -SyncIndex raftLogGetLastIndex(struct SSyncLogStore* pLogStore); +SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore); // return term of last entry -SyncTerm raftLogGetLastTerm(struct SSyncLogStore* pLogStore); +SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore); + +// update log store commit index with "index" +int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index); + +// return commit index of log +SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore); + +cJSON* logStore2Json(SSyncLogStore* pLogStore); + +char* logStore2Str(SSyncLogStore* pLogStore); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncVoteMgr.h b/source/libs/sync/inc/syncVoteMgr.h index ae9cfe8d01..d437e459b9 100644 --- a/source/libs/sync/inc/syncVoteMgr.h +++ b/source/libs/sync/inc/syncVoteMgr.h @@ -45,8 +45,8 @@ void voteGrantedDestroy(SVotesGranted *pVotesGranted); bool voteGrantedMajority(SVotesGranted *pVotesGranted); void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg); void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); -cJSON * voteGranted2Json(SVotesGranted *pVotesGranted); -char * voteGranted2Str(SVotesGranted *pVotesGranted); +cJSON *voteGranted2Json(SVotesGranted *pVotesGranted); +char *voteGranted2Str(SVotesGranted *pVotesGranted); // SVotesRespond ----------------------------- typedef struct SVotesRespond { @@ -62,8 +62,8 @@ void votesRespondDestory(SVotesRespond *pVotesRespond); bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId); void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg); void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); -cJSON * votesRespond2Json(SVotesRespond *pVotesRespond); -char * votesRespond2Str(SVotesRespond *pVotesRespond); +cJSON *votesRespond2Json(SVotesRespond *pVotesRespond); +char *votesRespond2Str(SVotesRespond *pVotesRespond); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 3b8d716dbe..a7663be3a5 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -18,8 +18,10 @@ #include "syncAppendEntries.h" #include "syncAppendEntriesReply.h" #include "syncEnv.h" +#include "syncIndexMgr.h" #include "syncInt.h" #include "syncRaft.h" +#include "syncRaftLog.h" #include "syncRaftStore.h" #include "syncRequestVote.h" #include "syncRequestVoteReply.h" @@ -78,7 +80,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { pSyncNode->vgId = pSyncInfo->vgId; pSyncNode->syncCfg = pSyncInfo->syncCfg; memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path)); - memcpy(pSyncNode->walPath, pSyncInfo->walPath, sizeof(pSyncNode->walPath)); + pSyncNode->pWal = pSyncInfo->pWal; pSyncNode->rpcClient = pSyncInfo->rpcClient; pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg; pSyncNode->queue = pSyncInfo->queue; @@ -114,20 +116,26 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { // init life cycle - // init server vars + // init TLA+ server vars pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; - pSyncNode->pRaftStore = raftStoreOpen(pSyncInfo->walPath); assert(pSyncNode->pRaftStore != NULL); - // init candidate vars + // init TLA+ candidate vars pSyncNode->pVotesGranted = voteGrantedCreate(pSyncNode); assert(pSyncNode->pVotesGranted != NULL); pSyncNode->pVotesRespond = votesRespondCreate(pSyncNode); assert(pSyncNode->pVotesRespond != NULL); - // init leader vars - pSyncNode->pNextIndex = NULL; - pSyncNode->pMatchIndex = NULL; + // init TLA+ leader vars + pSyncNode->pNextIndex = syncIndexMgrCreate(pSyncNode); + assert(pSyncNode->pNextIndex != NULL); + pSyncNode->pMatchIndex = syncIndexMgrCreate(pSyncNode); + assert(pSyncNode->pMatchIndex != NULL); + + // init TLA+ log vars + pSyncNode->pLogStore = logStoreCreate(pSyncNode); + assert(pSyncNode->pLogStore != NULL); + pSyncNode->commitIndex = 0; // init ping timer pSyncNode->pPingTimer = NULL; @@ -177,7 +185,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { // init by SSyncInfo cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId); cJSON_AddStringToObject(pRoot, "path", pSyncNode->path); - cJSON_AddStringToObject(pRoot, "walPath", pSyncNode->walPath); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->rpcClient); cJSON_AddStringToObject(pRoot, "rpcClient", u64buf); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index e467057c8f..d9b053b42d 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -14,46 +14,61 @@ */ #include "syncRaftLog.h" +#include "wal.h" -int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf) { return 0; } +SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { + SSyncLogStore* pLogStore = malloc(sizeof(SSyncLogStore)); + assert(pLogStore != NULL); -// get one log entry, user need to free pBuf->data -int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf) { return 0; } + pLogStore->data = malloc(sizeof(SSyncLogStoreData)); + assert(pLogStore->data != NULL); -// TLA+ Spec -// \* 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 <> -// -int32_t raftLogupdateCommitIndex(struct SSyncLogStore* pLogStore, SyncIndex index) { return 0; } + SSyncLogStoreData* pData = pLogStore->data; + pData->pSyncNode = pSyncNode; + pData->pWal = pSyncNode->pWal; -// truncate log with index, entries after the given index (>index) will be deleted -int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex index) { return 0; } + pLogStore->appendEntry = logStoreAppendEntry; + pLogStore->getEntry = logStoreGetEntry; + pLogStore->truncate = logStoreTruncate; + pLogStore->getLastIndex = logStoreLastIndex; + pLogStore->getLastTerm = logStoreLastTerm; + pLogStore->updateCommitIndex = logStoreUpdateCommitIndex; + pLogStore->getCommitIndex = logStoreGetCommitIndex; +} -// return commit index of log -SyncIndex raftLogGetCommitIndex(struct SSyncLogStore* pLogStore) { return 0; } +void logStoreDestory(SSyncLogStore* pLogStore) { + if (pLogStore != NULL) { + free(pLogStore->data); + free(pLogStore); + } +} + +// append one log entry +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry) {} + +// get one log entry, user need to free pEntry->pCont +int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry) {} + +// truncate log with index, entries after the given index (>=index) will be deleted +int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {} // return index of last entry -SyncIndex raftLogGetLastIndex(struct SSyncLogStore* pLogStore) { return 0; } +SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {} // return term of last entry -SyncTerm raftLogGetLastTerm(struct SSyncLogStore* pLogStore) { return 0; } \ No newline at end of file +SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {} + +// update log store commit index with "index" +int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {} + +// return commit index of log +SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {} + +cJSON* logStore2Json(SSyncLogStore* pLogStore) {} + +char* logStore2Str(SSyncLogStore* pLogStore) { + cJSON* pJson = logStore2Json(pLogStore); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} \ No newline at end of file diff --git a/source/libs/sync/test/syncIndexMgrTest.cpp b/source/libs/sync/test/syncIndexMgrTest.cpp index 4e4cd9222b..9eb7b22b8e 100644 --- a/source/libs/sync/test/syncIndexMgrTest.cpp +++ b/source/libs/sync/test/syncIndexMgrTest.cpp @@ -34,7 +34,6 @@ SSyncNode* syncNodeInit() { syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); - snprintf(syncInfo.walPath, sizeof(syncInfo.walPath), "%s", "./test_wal_path"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index 669c4e68a5..4aac24487e 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -31,7 +31,6 @@ SSyncNode* syncNodeInit() { syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); - snprintf(syncInfo.walPath, sizeof(syncInfo.walPath), "%s", "./test_wal_path"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index 450e097cc8..ae7977f270 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -26,7 +26,6 @@ SSyncNode* doSync(int myIndex) { syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./path"); - snprintf(syncInfo.walPath, sizeof(syncInfo.walPath), "%s", "./wal_path"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncVotesGrantedTest.cpp b/source/libs/sync/test/syncVotesGrantedTest.cpp index 3edde509f8..a448ad44b6 100644 --- a/source/libs/sync/test/syncVotesGrantedTest.cpp +++ b/source/libs/sync/test/syncVotesGrantedTest.cpp @@ -33,7 +33,6 @@ SSyncNode* syncNodeInit() { syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); - snprintf(syncInfo.walPath, sizeof(syncInfo.walPath), "%s", "./test_wal_path"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncVotesRespondTest.cpp b/source/libs/sync/test/syncVotesRespondTest.cpp index 74d42cd531..5cff8e0e26 100644 --- a/source/libs/sync/test/syncVotesRespondTest.cpp +++ b/source/libs/sync/test/syncVotesRespondTest.cpp @@ -33,7 +33,6 @@ SSyncNode* syncNodeInit() { syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); - snprintf(syncInfo.walPath, sizeof(syncInfo.walPath), "%s", "./test_wal_path"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; From fa7f441f425f47b0aeced5e656502f993877a55d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 15:07:43 +0800 Subject: [PATCH 02/23] sync refactor --- include/libs/sync/sync.h | 25 ++--- source/libs/sync/inc/syncAppendEntries.h | 1 - source/libs/sync/inc/syncAppendEntriesReply.h | 1 - source/libs/sync/inc/syncOnMessage.h | 1 - source/libs/sync/inc/syncRaft.h | 93 ------------------- source/libs/sync/inc/syncRaftStore.h | 1 - source/libs/sync/inc/syncRequestVote.h | 1 - source/libs/sync/inc/syncRequestVoteReply.h | 1 - source/libs/sync/inc/syncSnapshot.h | 1 - source/libs/sync/inc/syncTimeout.h | 1 - source/libs/sync/inc/syncVoteMgr.h | 8 +- source/libs/sync/src/syncIO.c | 2 +- source/libs/sync/src/syncMain.c | 1 - source/libs/sync/src/syncMessage.c | 1 - source/libs/sync/src/syncRaft.c | 70 -------------- source/libs/sync/src/syncSnapshot.c | 1 - source/libs/sync/test/syncEnqTest.cpp | 1 + 17 files changed, 19 insertions(+), 191 deletions(-) delete mode 100644 source/libs/sync/inc/syncRaft.h delete mode 100644 source/libs/sync/src/syncRaft.c diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index ccbeb00bfd..c83082e3e4 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -24,6 +24,7 @@ extern "C" { #include #include "taosdef.h" #include "trpc.h" +#include "wal.h" typedef uint64_t SyncNodeId; typedef int32_t SyncGroupId; @@ -93,19 +94,13 @@ typedef struct SSyncLogStore { void* data; // append one log entry - int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SRpcMsg* pBuf); + int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SRpcMsg* pEntry); - // get one log entry, user need to free pBuf->data - int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pBuf); + // get one log entry, user need to free pEntry->pCont + int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry); - // update log store commit index with "index" - int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index); - - // truncate log with index, entries after the given index (>index) will be deleted - int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex index); - - // return commit index of log - SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore); + // truncate log with index, entries after the given index (>=index) will be deleted + int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex fromIndex); // return index of last entry SyncIndex (*getLastIndex)(struct SSyncLogStore* pLogStore); @@ -113,6 +108,12 @@ typedef struct SSyncLogStore { // return term of last entry SyncTerm (*getLastTerm)(struct SSyncLogStore* pLogStore); + // update log store commit index with "index" + int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index); + + // return commit index of log + SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore); + } SSyncLogStore; // raft need to persist two variables in storage: currentTerm, voteFor @@ -134,7 +135,7 @@ typedef struct SSyncInfo { SyncGroupId vgId; SSyncCfg syncCfg; char path[TSDB_FILENAME_LEN]; - char walPath[TSDB_FILENAME_LEN]; + SWal* pWal; SSyncFSM* pFsm; void* rpcClient; diff --git a/source/libs/sync/inc/syncAppendEntries.h b/source/libs/sync/inc/syncAppendEntries.h index 35d3046d66..5999ef8300 100644 --- a/source/libs/sync/inc/syncAppendEntries.h +++ b/source/libs/sync/inc/syncAppendEntries.h @@ -25,7 +25,6 @@ extern "C" { #include #include "syncInt.h" #include "syncMessage.h" -#include "syncRaft.h" #include "taosdef.h" // TLA+ Spec diff --git a/source/libs/sync/inc/syncAppendEntriesReply.h b/source/libs/sync/inc/syncAppendEntriesReply.h index 75b82aa531..c0c1f76707 100644 --- a/source/libs/sync/inc/syncAppendEntriesReply.h +++ b/source/libs/sync/inc/syncAppendEntriesReply.h @@ -25,7 +25,6 @@ extern "C" { #include #include "syncInt.h" #include "syncMessage.h" -#include "syncRaft.h" #include "taosdef.h" // TLA+ Spec diff --git a/source/libs/sync/inc/syncOnMessage.h b/source/libs/sync/inc/syncOnMessage.h index 8eae4fed4d..7cb186a812 100644 --- a/source/libs/sync/inc/syncOnMessage.h +++ b/source/libs/sync/inc/syncOnMessage.h @@ -23,7 +23,6 @@ extern "C" { #include #include #include -#include "syncRaft.h" #include "taosdef.h" #ifdef __cplusplus diff --git a/source/libs/sync/inc/syncRaft.h b/source/libs/sync/inc/syncRaft.h deleted file mode 100644 index bc5cf26a4c..0000000000 --- a/source/libs/sync/inc/syncRaft.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_LIBS_SYNC_RAFT_H -#define _TD_LIBS_SYNC_RAFT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include "sync.h" -#include "syncMessage.h" -#include "taosdef.h" - -#if 0 - -typedef struct SRaftId { - SyncNodeId addr; - SyncGroupId vgId; -} SRaftId; - -typedef struct SRaft { - SRaftId id; - SSyncFSM* pFsm; - - int32_t (*FpPing)(struct SRaft* ths, const RaftPing* pMsg); - - int32_t (*FpOnPing)(struct SRaft* ths, RaftPing* pMsg); - - int32_t (*FpOnPingReply)(struct SRaft* ths, RaftPingReply* pMsg); - - int32_t (*FpRequestVote)(struct SRaft* ths, const RaftRequestVote* pMsg); - - int32_t (*FpOnRequestVote)(struct SRaft* ths, RaftRequestVote* pMsg); - - int32_t (*FpOnRequestVoteReply)(struct SRaft* ths, RaftRequestVoteReply* pMsg); - - int32_t (*FpAppendEntries)(struct SRaft* ths, const RaftAppendEntries* pMsg); - - int32_t (*FpOnAppendEntries)(struct SRaft* ths, RaftAppendEntries* pMsg); - - int32_t (*FpOnAppendEntriesReply)(struct SRaft* ths, RaftAppendEntriesReply* pMsg); - -} SRaft; - -SRaft* raftOpen(SRaftId raftId, SSyncFSM* pFsm); - -void raftClose(SRaft* pRaft); - -static int32_t doRaftPing(struct SRaft* ths, const RaftPing* pMsg); - -static int32_t onRaftPing(struct SRaft* ths, RaftPing* pMsg); - -static int32_t onRaftPingReply(struct SRaft* ths, RaftPingReply* pMsg); - -static int32_t doRaftRequestVote(struct SRaft* ths, const RaftRequestVote* pMsg); - -static int32_t onRaftRequestVote(struct SRaft* ths, RaftRequestVote* pMsg); - -static int32_t onRaftRequestVoteReply(struct SRaft* ths, RaftRequestVoteReply* pMsg); - -static int32_t doRaftAppendEntries(struct SRaft* ths, const RaftAppendEntries* pMsg); - -static int32_t onRaftAppendEntries(struct SRaft* ths, RaftAppendEntries* pMsg); - -static int32_t onRaftAppendEntriesReply(struct SRaft* ths, RaftAppendEntriesReply* pMsg); - -int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak); - -static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_LIBS_SYNC_RAFT_H*/ diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h index 591a5b9963..1c25b799b4 100644 --- a/source/libs/sync/inc/syncRaftStore.h +++ b/source/libs/sync/inc/syncRaftStore.h @@ -25,7 +25,6 @@ extern "C" { #include #include "cJSON.h" #include "syncInt.h" -#include "syncRaft.h" #include "taosdef.h" #define RAFT_STORE_BLOCK_SIZE 512 diff --git a/source/libs/sync/inc/syncRequestVote.h b/source/libs/sync/inc/syncRequestVote.h index 8bb4976de2..fd4ccd5371 100644 --- a/source/libs/sync/inc/syncRequestVote.h +++ b/source/libs/sync/inc/syncRequestVote.h @@ -25,7 +25,6 @@ extern "C" { #include #include "syncInt.h" #include "syncMessage.h" -#include "syncRaft.h" #include "taosdef.h" // TLA+ Spec diff --git a/source/libs/sync/inc/syncRequestVoteReply.h b/source/libs/sync/inc/syncRequestVoteReply.h index ab9430b857..bcaf71a541 100644 --- a/source/libs/sync/inc/syncRequestVoteReply.h +++ b/source/libs/sync/inc/syncRequestVoteReply.h @@ -25,7 +25,6 @@ extern "C" { #include #include "syncInt.h" #include "syncMessage.h" -#include "syncRaft.h" #include "taosdef.h" // TLA+ Spec diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index 89fcb230fb..611f33a0f2 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -24,7 +24,6 @@ extern "C" { #include #include #include "syncInt.h" -#include "syncRaft.h" #include "taosdef.h" int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot); diff --git a/source/libs/sync/inc/syncTimeout.h b/source/libs/sync/inc/syncTimeout.h index efd5aae48e..25c26c909d 100644 --- a/source/libs/sync/inc/syncTimeout.h +++ b/source/libs/sync/inc/syncTimeout.h @@ -25,7 +25,6 @@ extern "C" { #include #include "syncInt.h" #include "syncMessage.h" -#include "syncRaft.h" #include "taosdef.h" // TLA+ Spec diff --git a/source/libs/sync/inc/syncVoteMgr.h b/source/libs/sync/inc/syncVoteMgr.h index d437e459b9..ae9cfe8d01 100644 --- a/source/libs/sync/inc/syncVoteMgr.h +++ b/source/libs/sync/inc/syncVoteMgr.h @@ -45,8 +45,8 @@ void voteGrantedDestroy(SVotesGranted *pVotesGranted); bool voteGrantedMajority(SVotesGranted *pVotesGranted); void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg); void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); -cJSON *voteGranted2Json(SVotesGranted *pVotesGranted); -char *voteGranted2Str(SVotesGranted *pVotesGranted); +cJSON * voteGranted2Json(SVotesGranted *pVotesGranted); +char * voteGranted2Str(SVotesGranted *pVotesGranted); // SVotesRespond ----------------------------- typedef struct SVotesRespond { @@ -62,8 +62,8 @@ void votesRespondDestory(SVotesRespond *pVotesRespond); bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId); void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg); void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); -cJSON *votesRespond2Json(SVotesRespond *pVotesRespond); -char *votesRespond2Str(SVotesRespond *pVotesRespond); +cJSON * votesRespond2Json(SVotesRespond *pVotesRespond); +char * votesRespond2Str(SVotesRespond *pVotesRespond); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index d37c821a24..7edf561f5b 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -15,7 +15,7 @@ #include "syncIO.h" #include -#include "syncOnMessage.h" +#include "syncMessage.h" #include "tglobal.h" #include "ttimer.h" #include "tutil.h" diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index a7663be3a5..4d19444abd 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -20,7 +20,6 @@ #include "syncEnv.h" #include "syncIndexMgr.h" #include "syncInt.h" -#include "syncRaft.h" #include "syncRaftLog.h" #include "syncRaftStore.h" #include "syncRequestVote.h" diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 14f139a803..6732cd3958 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -14,7 +14,6 @@ */ #include "syncMessage.h" -#include "syncRaft.h" #include "syncUtil.h" #include "tcoding.h" diff --git a/source/libs/sync/src/syncRaft.c b/source/libs/sync/src/syncRaft.c deleted file mode 100644 index b07c6ea797..0000000000 --- a/source/libs/sync/src/syncRaft.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "syncRaft.h" -#include "sync.h" - -#if 0 - -SRaft* raftOpen(SRaftId raftId, SSyncFSM* pFsm) { - SRaft* pRaft = (SRaft*)malloc(sizeof(SRaft)); - assert(pRaft != NULL); - - pRaft->id = raftId; - pRaft->pFsm = pFsm; - - pRaft->FpPing = doRaftPing; - pRaft->FpOnPing = onRaftPing; - pRaft->FpOnPingReply = onRaftPingReply; - - pRaft->FpRequestVote = doRaftRequestVote; - pRaft->FpOnRequestVote = onRaftRequestVote; - pRaft->FpOnRequestVoteReply = onRaftRequestVoteReply; - - pRaft->FpAppendEntries = doRaftAppendEntries; - pRaft->FpOnAppendEntries = onRaftAppendEntries; - pRaft->FpOnAppendEntriesReply = onRaftAppendEntriesReply; - - return pRaft; -} - -void raftClose(SRaft* pRaft) { - assert(pRaft != NULL); - free(pRaft); -} - -static int32_t doRaftPing(struct SRaft* ths, const RaftPing* pMsg) { return 0; } - -static int32_t onRaftPing(struct SRaft* ths, RaftPing* pMsg) { return 0; } - -static int32_t onRaftPingReply(struct SRaft* ths, RaftPingReply* pMsg) { return 0; } - -static int32_t doRaftRequestVote(struct SRaft* ths, const RaftRequestVote* pMsg) { return 0; } - -static int32_t onRaftRequestVote(struct SRaft* ths, RaftRequestVote* pMsg) { return 0; } - -static int32_t onRaftRequestVoteReply(struct SRaft* ths, RaftRequestVoteReply* pMsg) { return 0; } - -static int32_t doRaftAppendEntries(struct SRaft* ths, const RaftAppendEntries* pMsg) { return 0; } - -static int32_t onRaftAppendEntries(struct SRaft* ths, RaftAppendEntries* pMsg) { return 0; } - -static int32_t onRaftAppendEntriesReply(struct SRaft* ths, RaftAppendEntriesReply* pMsg) { return 0; } - -int32_t raftPropose(SRaft* pRaft, const SSyncBuffer* pBuf, bool isWeak) { return 0; } - -static int raftSendMsg(SRaftId destRaftId, const void* pMsg, const SRaft* pRaft) { return 0; } - -#endif \ No newline at end of file diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index da194780ff..42b2bd993b 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -14,7 +14,6 @@ */ #include "syncSnapshot.h" -#include "syncRaft.h" int32_t takeSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; } diff --git a/source/libs/sync/test/syncEnqTest.cpp b/source/libs/sync/test/syncEnqTest.cpp index e2bc9a73ae..e1706bb40b 100644 --- a/source/libs/sync/test/syncEnqTest.cpp +++ b/source/libs/sync/test/syncEnqTest.cpp @@ -2,6 +2,7 @@ #include "syncEnv.h" #include "syncIO.h" #include "syncInt.h" +#include "syncMessage.h" #include "syncRaftStore.h" void logTest() { From d87411116b3343e754c9564cedef23717a55b70d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 16:34:34 +0800 Subject: [PATCH 03/23] sync refactor --- include/libs/sync/sync.h | 2 +- source/libs/sync/inc/syncMessage.h | 15 +++++- source/libs/sync/src/syncMain.c | 25 ++++++++-- source/libs/sync/src/syncMessage.c | 76 +++++++++++++++++++++++++++++- 4 files changed, 112 insertions(+), 6 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index c83082e3e4..1e5aa18010 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -154,7 +154,7 @@ void syncCleanUp(); int64_t syncStart(const SSyncInfo* pSyncInfo); void syncStop(int64_t rid); int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak); +int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); ESyncState syncGetMyRole(int64_t rid); void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole); diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h index 3405f0f6cc..7f54dee426 100644 --- a/source/libs/sync/inc/syncMessage.h +++ b/source/libs/sync/inc/syncMessage.h @@ -123,12 +123,25 @@ SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId); typedef struct SyncClientRequest { uint32_t bytes; uint32_t msgType; - int64_t seqNum; + uint32_t originalRpcType; + uint64_t seqNum; bool isWeak; uint32_t dataLen; char data[]; } SyncClientRequest; +#define SYNC_CLIENT_REQUEST_FIX_LEN \ + (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(bool) + sizeof(uint32_t)) + +SyncClientRequest* syncClientRequestBuild(uint32_t dataLen); +void syncClientRequestDestroy(SyncClientRequest* pMsg); +void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen); +void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg); +void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); +void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg); +cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg); +SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak); + // --------------------------------------------- typedef struct SyncClientRequestReply { uint32_t bytes; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 4d19444abd..7e8754b684 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -60,13 +60,32 @@ int64_t syncStart(const SSyncInfo* pSyncInfo) { return 0; } -void syncStop(int64_t rid) {} +void syncStop(int64_t rid) { + SSyncNode* pSyncNode = NULL; // get pointer from rid + syncNodeClose(pSyncNode); +} int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) { return 0; } -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak) { return 0; } +int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { + SSyncNode* pSyncNode = NULL; // get pointer from rid + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, 0, isWeak); + SRpcMsg rpcMsg; + syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); + pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg); + syncClientRequestDestroy(pSyncMsg); + } else { + sTrace("syncForwardToPeer not leader, %s", syncUtilState2String(pSyncNode->state)); + return -1; // need define err code !! + } + return 0; +} -ESyncState syncGetMyRole(int64_t rid) { return TAOS_SYNC_STATE_LEADER; } +ESyncState syncGetMyRole(int64_t rid) { + SSyncNode* pSyncNode = NULL; // get pointer from rid + return pSyncNode->state; +} void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 6732cd3958..3af073541b 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -35,7 +35,8 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) { pRoot = syncPingReply2Json(pSyncMsg); } else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST) { - pRoot = syncRpcUnknownMsg2Json(); + SyncClientRequest* pSyncMsg = (SyncClientRequest*)pRpcMsg->pCont; + pRoot = syncClientRequest2Json(pSyncMsg); } else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST_REPLY) { pRoot = syncRpcUnknownMsg2Json(); @@ -148,6 +149,7 @@ SyncPing* syncPingBuild(uint32_t dataLen) { pMsg->bytes = bytes; pMsg->msgType = SYNC_PING; pMsg->dataLen = dataLen; + return pMsg; } void syncPingDestroy(SyncPing* pMsg) { @@ -246,6 +248,7 @@ SyncPingReply* syncPingReplyBuild(uint32_t dataLen) { pMsg->bytes = bytes; pMsg->msgType = SYNC_PING_REPLY; pMsg->dataLen = dataLen; + return pMsg; } void syncPingReplyDestroy(SyncPingReply* pMsg) { @@ -336,6 +339,73 @@ SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId) return pMsg; } +// ---- message process SyncClientRequest---- +SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) { + uint32_t bytes = SYNC_CLIENT_REQUEST_FIX_LEN + dataLen; + SyncClientRequest* pMsg = malloc(bytes); + memset(pMsg, 0, bytes); + pMsg->bytes = bytes; + pMsg->msgType = SYNC_CLIENT_REQUEST; + pMsg->seqNum = 0; + pMsg->isWeak = false; + pMsg->dataLen = dataLen; + return pMsg; +} + +void syncClientRequestDestroy(SyncClientRequest* pMsg) { + if (pMsg != NULL) { + free(pMsg); + } +} + +void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen) { + assert(pMsg->bytes <= bufLen); + memcpy(buf, pMsg, pMsg->bytes); +} + +void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg) { + memcpy(pMsg, buf, len); + assert(len == pMsg->bytes); +} + +void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg) { + memset(pRpcMsg, 0, sizeof(*pRpcMsg)); + pRpcMsg->msgType = pMsg->msgType; + pRpcMsg->contLen = pMsg->bytes; + pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); + syncClientRequestSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); +} + +void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg) { + syncClientRequestDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +} + +cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { + 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); + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncClientRequest", pRoot); + return pJson; +} + +SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak) { + SyncClientRequest* pMsg = syncClientRequestBuild(pOriginalRpcMsg->contLen); + pMsg->originalRpcType = pOriginalRpcMsg->msgType; + pMsg->seqNum = seqNum; + pMsg->isWeak = isWeak; + memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen); + return pMsg; +} + // ---- message process SyncRequestVote---- SyncRequestVote* syncRequestVoteBuild() { uint32_t bytes = sizeof(SyncRequestVote); @@ -343,6 +413,7 @@ SyncRequestVote* syncRequestVoteBuild() { memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_REQUEST_VOTE; + return pMsg; } void syncRequestVoteDestroy(SyncRequestVote* pMsg) { @@ -428,6 +499,7 @@ SyncRequestVoteReply* SyncRequestVoteReplyBuild() { memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_REQUEST_VOTE_REPLY; + return pMsg; } void syncRequestVoteReplyDestroy(SyncRequestVoteReply* pMsg) { @@ -511,6 +583,7 @@ SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen) { pMsg->bytes = bytes; pMsg->msgType = SYNC_APPEND_ENTRIES; pMsg->dataLen = dataLen; + return pMsg; } void syncAppendEntriesDestroy(SyncAppendEntries* pMsg) { @@ -603,6 +676,7 @@ SyncAppendEntriesReply* syncAppendEntriesReplyBuild() { memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->msgType = SYNC_APPEND_ENTRIES_REPLY; + return pMsg; } void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg) { From 41516e024a99952279e40b6b2f9ae1cdbab50d36 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 18:33:41 +0800 Subject: [PATCH 04/23] sync refactor --- source/libs/sync/inc/syncInt.h | 8 +- source/libs/sync/inc/syncMessage.h | 1 + source/libs/sync/src/syncIO.c | 17 ++-- source/libs/sync/src/syncMain.c | 15 +++- source/libs/sync/src/syncMessage.c | 7 ++ source/libs/sync/test/syncEnvTest.cpp | 31 +++---- source/libs/sync/test/syncIndexMgrTest.cpp | 2 +- source/libs/sync/test/syncInitTest.cpp | 2 +- source/libs/sync/test/syncPingTest.cpp | 84 ++++++++++++------- .../libs/sync/test/syncVotesGrantedTest.cpp | 2 +- .../libs/sync/test/syncVotesRespondTest.cpp | 2 +- 11 files changed, 106 insertions(+), 65 deletions(-) diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 1ca705441d..2932240ec1 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -116,6 +116,7 @@ typedef struct SSyncNode { SyncGroupId vgId; SSyncCfg syncCfg; char path[TSDB_FILENAME_LEN]; + char raftStorePath[TSDB_FILENAME_LEN * 2]; SWal* pWal; void* rpcClient; int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg); @@ -195,8 +196,6 @@ typedef struct SSyncNode { SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo); void syncNodeClose(SSyncNode* pSyncNode); -cJSON* syncNode2Json(const SSyncNode* pSyncNode); -char* syncNode2Str(const SSyncNode* pSyncNode); int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg); int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg); @@ -213,6 +212,11 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms); int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode); int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode); +// for debug +cJSON* syncNode2Json(const SSyncNode* pSyncNode); +char* syncNode2Str(const SSyncNode* pSyncNode); +void syncNodePrint(char* s, const SSyncNode* pSyncNode); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h index 7f54dee426..f41a423468 100644 --- a/source/libs/sync/inc/syncMessage.h +++ b/source/libs/sync/inc/syncMessage.h @@ -46,6 +46,7 @@ typedef enum ESyncMessageType { // --------------------------------------------- cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg); cJSON* syncRpcUnknownMsg2Json(); +char* syncRpcMsg2Str(SRpcMsg* pRpcMsg); // --------------------------------------------- typedef enum ESyncTimeoutType { diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index 7edf561f5b..2cc56443ce 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -220,12 +220,17 @@ static void *syncIOConsumerFunc(void *param) { while (1) { int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, NULL, NULL); sTrace("syncIOConsumerFunc %d msgs are received", numOfMsgs); - if (numOfMsgs <= 0) break; + if (numOfMsgs <= 0) { + break; + } for (int i = 0; i < numOfMsgs; ++i) { taosGetQitem(qall, (void **)&pRpcMsg); + + char *s = syncRpcMsg2Str(pRpcMsg); sTrace("syncIOConsumerFunc get item from queue: msgType:%d contLen:%d msg:%s", pRpcMsg->msgType, pRpcMsg->contLen, - (char *)(pRpcMsg->pCont)); + s); + free(s); if (pRpcMsg->msgType == SYNC_PING) { if (io->FpOnSyncPing != NULL) { @@ -247,7 +252,7 @@ static void *syncIOConsumerFunc(void *param) { } } else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE) { - if (io->FpOnSyncRequestVote) { + if (io->FpOnSyncRequestVote != NULL) { SyncRequestVote *pSyncMsg; pSyncMsg = syncRequestVoteBuild(pRpcMsg->contLen); syncRequestVoteFromRpcMsg(pRpcMsg, pSyncMsg); @@ -256,7 +261,7 @@ static void *syncIOConsumerFunc(void *param) { } } else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) { - if (io->FpOnSyncRequestVoteReply) { + if (io->FpOnSyncRequestVoteReply != NULL) { SyncRequestVoteReply *pSyncMsg; pSyncMsg = SyncRequestVoteReplyBuild(); syncRequestVoteReplyFromRpcMsg(pRpcMsg, pSyncMsg); @@ -265,7 +270,7 @@ static void *syncIOConsumerFunc(void *param) { } } else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES) { - if (io->FpOnSyncAppendEntries) { + if (io->FpOnSyncAppendEntries != NULL) { SyncAppendEntries *pSyncMsg; pSyncMsg = syncAppendEntriesBuild(pRpcMsg->contLen); syncAppendEntriesFromRpcMsg(pRpcMsg, pSyncMsg); @@ -274,7 +279,7 @@ static void *syncIOConsumerFunc(void *param) { } } else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES_REPLY) { - if (io->FpOnSyncAppendEntriesReply) { + if (io->FpOnSyncAppendEntriesReply != NULL) { SyncAppendEntriesReply *pSyncMsg; pSyncMsg = syncAppendEntriesReplyBuild(); syncAppendEntriesReplyFromRpcMsg(pRpcMsg, pSyncMsg); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 7e8754b684..29803ae560 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -98,6 +98,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { pSyncNode->vgId = pSyncInfo->vgId; pSyncNode->syncCfg = pSyncInfo->syncCfg; memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path)); + snprintf(pSyncNode->raftStorePath, sizeof(pSyncNode->raftStorePath), "%s/raft_store.json", pSyncInfo->path); pSyncNode->pWal = pSyncInfo->pWal; pSyncNode->rpcClient = pSyncInfo->rpcClient; pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg; @@ -136,6 +137,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { // init TLA+ server vars pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; + pSyncNode->pRaftStore = raftStoreOpen(pSyncNode->raftStorePath); assert(pSyncNode->pRaftStore != NULL); // init TLA+ candidate vars @@ -325,6 +327,13 @@ char* syncNode2Str(const SSyncNode* pSyncNode) { return serialized; } +void syncNodePrint(char* s, const SSyncNode* pSyncNode) { + char* ss = syncNode2Str(pSyncNode); + // sTrace("syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss); + fprintf(stderr, "syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss); + free(ss); +} + int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) { SEpSet epSet; syncUtilraftId2EpSet(destRaftId, &epSet); @@ -499,6 +508,8 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) { } static void syncNodeEqPingTimer(void* param, void* tmrId) { + sTrace("<-- syncNodeEqPingTimer -->"); + SSyncNode* pSyncNode = (SSyncNode*)param; if (atomic_load_64(&pSyncNode->pingTimerLogicClockUser) <= atomic_load_64(&pSyncNode->pingTimerLogicClock)) { SyncTimeout* pSyncMsg = syncTimeoutBuild2(SYNC_TIMEOUT_PING, atomic_load_64(&pSyncNode->pingTimerLogicClock), @@ -511,7 +522,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { // reset timer ms // pSyncNode->pingTimerMS += 100; - taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, &gSyncEnv->pTimerManager, + taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager, &pSyncNode->pPingTimer); } else { sTrace("syncNodeEqPingTimer: pingTimerLogicClock:%lu, pingTimerLogicClockUser:%lu", pSyncNode->pingTimerLogicClock, @@ -557,7 +568,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { // reset timer ms // pSyncNode->heartbeatTimerMS += 100; - taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, &gSyncEnv->pTimerManager, + taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager, &pSyncNode->pHeartbeatTimer); } else { sTrace("syncNodeEqHeartbeatTimer: heartbeatTimerLogicClock:%lu, heartbeatTimerLogicClockUser:%lu", diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 3af073541b..11f823a048 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -76,6 +76,13 @@ cJSON* syncRpcUnknownMsg2Json() { return pJson; } +char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) { + cJSON* pJson = syncRpcMsg2Json(pRpcMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + // ---- message process SyncTimeout---- SyncTimeout* syncTimeoutBuild() { uint32_t bytes = sizeof(SyncTimeout); diff --git a/source/libs/sync/test/syncEnvTest.cpp b/source/libs/sync/test/syncEnvTest.cpp index 1ac4357c5a..101c0efe9a 100644 --- a/source/libs/sync/test/syncEnvTest.cpp +++ b/source/libs/sync/test/syncEnvTest.cpp @@ -3,6 +3,7 @@ #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" +#include "ttime.h" void logTest() { sTrace("--- sync log test: trace"); @@ -13,24 +14,13 @@ void logTest() { sFatal("--- sync log test: fatal"); } -void doSync() { - SSyncInfo syncInfo; - syncInfo.vgId = 1; +void *pTimer = NULL; +void *pTimerMgr = NULL; +int g = 300; - SSyncCfg* pCfg = &syncInfo.syncCfg; - pCfg->replicaNum = 3; - - pCfg->nodeInfo[0].nodePort = 7010; - taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); - - pCfg->nodeInfo[1].nodePort = 7110; - taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn); - - pCfg->nodeInfo[2].nodePort = 7210; - taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn); - - SSyncNode* pSyncNode = syncNodeOpen(&syncInfo); - assert(pSyncNode != NULL); +static void timerFp(void *param, void *tmrId) { + printf("param:%p, tmrId:%p, pTimer:%p, pTimerMgr:%p \n", param, tmrId, pTimer, pTimerMgr); + taosTmrReset(timerFp, 1000, param, pTimerMgr, &pTimer); } int main() { @@ -41,13 +31,12 @@ int main() { logTest(); - // ret = syncIOStart(); - // assert(ret == 0); - ret = syncEnvStart(); assert(ret == 0); - // doSync(); + // timer + pTimerMgr = taosTmrInit(1000, 50, 10000, "SYNC-ENV-TEST"); + taosTmrStart(timerFp, 1000, &g, pTimerMgr); while (1) { taosMsleep(1000); diff --git a/source/libs/sync/test/syncIndexMgrTest.cpp b/source/libs/sync/test/syncIndexMgrTest.cpp index 9eb7b22b8e..6bad8f09cf 100644 --- a/source/libs/sync/test/syncIndexMgrTest.cpp +++ b/source/libs/sync/test/syncIndexMgrTest.cpp @@ -33,7 +33,7 @@ SSyncNode* syncNodeInit() { syncInfo.queue = gSyncIO->pMsgQ; syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index 4aac24487e..f665c5a612 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -30,7 +30,7 @@ SSyncNode* syncNodeInit() { syncInfo.queue = gSyncIO->pMsgQ; syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index ae7977f270..83f1f67eb1 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -1,8 +1,10 @@ +#include #include #include "syncEnv.h" #include "syncIO.h" #include "syncInt.h" #include "syncRaftStore.h" +#include "syncUtil.h" void logTest() { sTrace("--- sync log test: trace"); @@ -13,58 +15,65 @@ void logTest() { sFatal("--- sync log test: fatal"); } -uint16_t ports[3] = {7010, 7110, 7210}; +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; -SSyncNode* doSync(int myIndex) { - SSyncFSM* pFsm; +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; - SSyncInfo syncInfo; - syncInfo.vgId = 1; +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", "./path"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; - pCfg->replicaNum = 3; + pCfg->replicaNum = replicaNum; - pCfg->nodeInfo[0].nodePort = ports[0]; - snprintf(pCfg->nodeInfo[0].nodeFqdn, sizeof(pCfg->nodeInfo[0].nodeFqdn), "%s", "127.0.0.1"); - // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); - - pCfg->nodeInfo[1].nodePort = ports[1]; - snprintf(pCfg->nodeInfo[1].nodeFqdn, sizeof(pCfg->nodeInfo[1].nodeFqdn), "%s", "127.0.0.1"); - // taosGetFqdn(pCfg->nodeInfo[1].nodeFqdn); - - pCfg->nodeInfo[2].nodePort = ports[2]; - snprintf(pCfg->nodeInfo[2].nodeFqdn, sizeof(pCfg->nodeInfo[2].nodeFqdn), "%s", "127.0.0.1"); - // taosGetFqdn(pCfg->nodeInfo[2].nodeFqdn); + 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->FpOnSyncTimeout = pSyncNode->FpOnTimeout; gSyncIO->pSyncNode = pSyncNode; return pSyncNode; } -void timerPingAll(void* param, void* tmrId) { - SSyncNode* pSyncNode = (SSyncNode*)param; - syncNodePingAll(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*)"syncPingTest.log", 100000, 10); + // taosInitLog((char *)"syncTest.log", 100000, 10); tsAsyncLog = 0; sDebugFlag = 143 + 64; - logTest(); - - int myIndex = 0; + myIndex = 0; if (argc >= 2) { myIndex = atoi(argv[1]); } @@ -75,30 +84,45 @@ int main(int argc, char** argv) { ret = syncEnvStart(); assert(ret == 0); - SSyncNode* pSyncNode = doSync(myIndex); - gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; - gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; - gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + SSyncNode* pSyncNode = syncInitTest(); + assert(pSyncNode != NULL); + syncNodePrint((char*)"----1", pSyncNode); + initRaftId(pSyncNode); + + //--------------------------- + + sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); + syncNodePrint((char*)"----2", pSyncNode); + sTrace("sleep ..."); taosMsleep(10000); + sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); + syncNodePrint((char*)"----3", pSyncNode); - taosMsleep(10000); + sTrace("sleep ..."); + taosMsleep(5000); + sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); + syncNodePrint((char*)"----4", pSyncNode); + sTrace("sleep ..."); taosMsleep(10000); + sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); + syncNodePrint((char*)"----5", pSyncNode); while (1) { + sTrace("while 1 sleep ..."); taosMsleep(1000); } diff --git a/source/libs/sync/test/syncVotesGrantedTest.cpp b/source/libs/sync/test/syncVotesGrantedTest.cpp index a448ad44b6..504fa3034a 100644 --- a/source/libs/sync/test/syncVotesGrantedTest.cpp +++ b/source/libs/sync/test/syncVotesGrantedTest.cpp @@ -32,7 +32,7 @@ SSyncNode* syncNodeInit() { syncInfo.queue = gSyncIO->pMsgQ; syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; diff --git a/source/libs/sync/test/syncVotesRespondTest.cpp b/source/libs/sync/test/syncVotesRespondTest.cpp index 5cff8e0e26..0b6abef212 100644 --- a/source/libs/sync/test/syncVotesRespondTest.cpp +++ b/source/libs/sync/test/syncVotesRespondTest.cpp @@ -32,7 +32,7 @@ SSyncNode* syncNodeInit() { syncInfo.queue = gSyncIO->pMsgQ; syncInfo.FpEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./test_path"); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); SSyncCfg* pCfg = &syncInfo.syncCfg; pCfg->myIndex = myIndex; From c462ef61e3082da67721dcfdb43aa8b9d82316d1 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 18:35:57 +0800 Subject: [PATCH 05/23] sync refactor --- source/libs/sync/src/syncMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 29803ae560..5cd7149b72 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -544,7 +544,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { // reset timer ms pSyncNode->electTimerMS = syncUtilElectRandomMS(); - taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, &gSyncEnv->pTimerManager, + taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager, &pSyncNode->pPingTimer); } else { sTrace("syncNodeEqElectTimer: electTimerLogicClock:%lu, electTimerLogicClockUser:%lu", From 3dfb9bb02283a962835bbe55620833ee0dcab2bc Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 18:56:39 +0800 Subject: [PATCH 06/23] sync refactor --- source/libs/sync/inc/syncMessage.h | 3 +-- source/libs/sync/inc/syncRaftEntry.h | 9 +++++++-- source/libs/sync/inc/syncRaftLog.h | 4 ++-- source/libs/sync/src/syncRaftEntry.c | 4 ++++ source/libs/sync/src/syncRaftLog.c | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h index f41a423468..dcd8f7c74e 100644 --- a/source/libs/sync/inc/syncMessage.h +++ b/source/libs/sync/inc/syncMessage.h @@ -24,8 +24,7 @@ extern "C" { #include #include #include "cJSON.h" -#include "sync.h" -#include "syncRaftEntry.h" +#include "syncInt.h" #include "taosdef.h" // encode as uint32 diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index 9cc05d44a9..53cf647022 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -24,19 +24,24 @@ extern "C" { #include #include #include "syncInt.h" +#include "syncMessage.h" #include "taosdef.h" typedef struct SSyncRaftEntry { uint32_t bytes; uint32_t msgType; + uint32_t originalRpcType; + uint64_t seqNum; + bool isWeak; SyncTerm term; SyncIndex index; - int8_t flag; uint32_t dataLen; char data[]; - } SSyncRaftEntry; +SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); +void syncEntryDestory(SSyncRaftEntry* pEntry); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index 8205f19d91..634d06903c 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -37,10 +37,10 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode); void logStoreDestory(SSyncLogStore* pLogStore); // append one log entry -int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry); +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); // get one log entry, user need to free pEntry->pCont -int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry); +int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry); // truncate log with index, entries after the given index (>=index) will be deleted int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex); diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index e525d3c7c2..fff4f1b50b 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -14,3 +14,7 @@ */ #include "syncRaftEntry.h" + +SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {} + +void syncEntryDestory(SSyncRaftEntry* pEntry) {} \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index d9b053b42d..c4e1feb374 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -44,10 +44,10 @@ void logStoreDestory(SSyncLogStore* pLogStore) { } // append one log entry -int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SRpcMsg* pEntry) {} +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {} // get one log entry, user need to free pEntry->pCont -int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry) {} +int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry) {} // truncate log with index, entries after the given index (>=index) will be deleted int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {} From d083c7974407afb65449368edcc88f4e84401b30 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 19:13:09 +0800 Subject: [PATCH 07/23] sync refactor --- source/libs/sync/inc/syncRaftEntry.h | 8 ++++ source/libs/sync/src/syncRaftEntry.c | 63 +++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index 53cf647022..2d77af8835 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -39,8 +39,16 @@ typedef struct SSyncRaftEntry { char data[]; } SSyncRaftEntry; +#define SYNC_ENTRY_FIX_LEN \ + (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(bool) + sizeof(SyncTerm) + \ + sizeof(SyncIndex) + sizeof(uint32_t)) + SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); void syncEntryDestory(SSyncRaftEntry* pEntry); +void syncEntrySerialize(const SSyncRaftEntry* pEntry, char* buf, uint32_t bufLen); +void syncEntryDeserialize(const char* buf, uint32_t len, SSyncRaftEntry* pEntry); +cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); +char* syncEntry2Str(const SSyncRaftEntry* pEntry); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index fff4f1b50b..cd14ea502e 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -15,6 +15,65 @@ #include "syncRaftEntry.h" -SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {} +SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { + uint32_t bytes = SYNC_ENTRY_FIX_LEN + pMsg->bytes; + SSyncRaftEntry* pEntry = malloc(bytes); + assert(pEntry != NULL); + memset(pEntry, 0, bytes); -void syncEntryDestory(SSyncRaftEntry* pEntry) {} \ No newline at end of file + pEntry->bytes = bytes; + pEntry->msgType = pMsg->msgType; + pEntry->originalRpcType = pMsg->originalRpcType; + pEntry->seqNum = pMsg->seqNum; + pEntry->isWeak = pMsg->isWeak; + pEntry->term = term; + pEntry->index = index; + pEntry->dataLen = pMsg->dataLen; + memcpy(pEntry->data, pMsg->data, pMsg->dataLen); + + return pEntry; +} + +void syncEntryDestory(SSyncRaftEntry* pEntry) { + if (pEntry != NULL) { + free(pEntry); + } +} + +void syncEntrySerialize(const SSyncRaftEntry* pEntry, char* buf, uint32_t bufLen) { + assert(pEntry->bytes <= bufLen); + memcpy(buf, pEntry, pEntry->bytes); +} + +void syncEntryDeserialize(const char* buf, uint32_t len, SSyncRaftEntry* pEntry) { + memcpy(pEntry, buf, len); + assert(len == pEntry->bytes); +} + +cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { + 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); + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot); + return pJson; +} + +char* syncEntry2Str(const SSyncRaftEntry* pEntry) { + cJSON* pJson = syncEntry2Json(pEntry); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} \ No newline at end of file From 30be9d3e314523d0a599dc88048e6a62a57fd610 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 20:04:39 +0800 Subject: [PATCH 08/23] sync refactor --- source/libs/sync/inc/syncRaftLog.h | 4 +- source/libs/sync/src/syncRaftLog.c | 65 ++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index 634d06903c..ecdb544302 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -40,7 +40,7 @@ void logStoreDestory(SSyncLogStore* pLogStore); int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); // get one log entry, user need to free pEntry->pCont -int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry); +SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index); // truncate log with index, entries after the given index (>=index) will be deleted int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex); @@ -57,6 +57,8 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index); // return commit index of log SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore); +SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore); + cJSON* logStore2Json(SSyncLogStore* pLogStore); char* logStore2Str(SSyncLogStore* pLogStore); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index c4e1feb374..d5735d9142 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -44,25 +44,76 @@ void logStoreDestory(SSyncLogStore* pLogStore) { } // append one log entry -int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {} +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + char* buf = malloc(pEntry->bytes); + + syncEntrySerialize(pEntry, buf, pEntry->bytes); + walWrite(pWal, pEntry->index, pEntry->msgType, buf, pEntry->bytes); + walFsync(pWal, true); + + free(buf); +} // get one log entry, user need to free pEntry->pCont -int32_t logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry* pEntry) {} +SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + SSyncRaftEntry* pEntry; + + SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + walReadWithHandle(pWalHandle, index); + + // need to hold, do not new every time!! + walCloseReadHandle(pWalHandle); + return pEntry; +} // truncate log with index, entries after the given index (>=index) will be deleted -int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {} +int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + walRollback(pWal, fromIndex); +} // return index of last entry -SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {} +SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) { + SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); + SyncIndex lastIndex = pLastEntry->index; + free(pLastEntry); + return lastIndex; +} // return term of last entry -SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {} +SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) { + SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); + SyncTerm lastTerm = pLastEntry->term; + free(pLastEntry); + return lastTerm; +} // update log store commit index with "index" -int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {} +int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + walCommit(pWal, index); +} // return commit index of log -SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {} +SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) { + SSyncLogStoreData* pData = pLogStore->data; + return pData->pSyncNode->commitIndex; +} + +SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + SyncIndex lastIndex = walGetLastVer(pWal); + SSyncRaftEntry* pEntry; + pEntry = logStoreGetEntry(pLogStore, lastIndex); + return pEntry; +} cJSON* logStore2Json(SSyncLogStore* pLogStore) {} From 3c9875e955e0f3d1b52f7ef03625c8e0810558a7 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 9 Mar 2022 20:24:27 +0800 Subject: [PATCH 09/23] sync refactor --- include/libs/sync/sync.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 1e5aa18010..68ca9eff17 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -88,16 +88,19 @@ typedef struct SSyncFSM { } SSyncFSM; +struct SSyncRaftEntry; +typedef struct SSyncRaftEntry SSyncRaftEntry; + // abstract definition of log store in raft // SWal implements it typedef struct SSyncLogStore { void* data; // append one log entry - int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SRpcMsg* pEntry); + int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); // get one log entry, user need to free pEntry->pCont - int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pEntry); + SSyncRaftEntry* (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index); // truncate log with index, entries after the given index (>=index) will be deleted int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex fromIndex); From c3920c4697e0bd6fca125fb97476576adcfedefc Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 9 Mar 2022 20:44:15 +0800 Subject: [PATCH 10/23] reset smsStatWindow --- source/dnode/vnode/src/inc/tsdbFile.h | 3 ++- source/dnode/vnode/src/tsdb/tsdbSma.c | 24 ++++++++++++++++++++++++ source/dnode/vnode/test/tsdbSmaTest.cpp | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdbFile.h b/source/dnode/vnode/src/inc/tsdbFile.h index 1034ae015a..b58bfe77ab 100644 --- a/source/dnode/vnode/src/inc/tsdbFile.h +++ b/source/dnode/vnode/src/inc/tsdbFile.h @@ -58,8 +58,9 @@ typedef enum { TSDB_FILE_META, // meta TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA -} TSDB_FILE_T; +} E_TSDB_FILE_T; +typedef int32_t TSDB_FILE_T; typedef enum { TSDB_FS_VER_0 = 0, TSDB_FS_VER_MAX, diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index c5f1261282..aa9fb7c7ed 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -203,6 +203,23 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) { return TSDB_CODE_SUCCESS; } +static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, const char *indexName, void *timeWindow) { + SSmaStatItem *pItem = NULL; + + if (pTsdb->pSmaStat && pTsdb->pSmaStat->smaStatItems) { + pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName)); + } + + if (pItem != NULL) { + // TODO: reset time windows for the sma data blocks + while (true) { + TSKEY thisWindow = 0; + taosHashRemove(pItem->expiredWindows, &thisWindow, sizeof(thisWindow)); + } + } + return TSDB_CODE_SUCCESS; +} + /** * @brief Judge the tSma storage level * @@ -495,6 +512,9 @@ int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData) { return terrno; } + // reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, param->indexName, &pData->tsWindow); + return TSDB_CODE_SUCCESS; } @@ -542,6 +562,10 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) { TASSERT(0); return TSDB_CODE_INVALID_PARA; } + + // reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, param->tsma.indexName, &pData->tsWindow); + // Step 4: finish return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index f3a61bdfa4..bf3e67cdf5 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -20,6 +20,7 @@ #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -209,7 +210,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { metaClose(pMeta); } -#if 0 +#if 1 TEST(testCase, tSmaInsertTest) { STSma tSma = {0}; STSmaData* pSmaData = NULL; From a51e5761266ec0bdeeb12ec2706982ccf4171d96 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Thu, 10 Mar 2022 11:21:04 +0800 Subject: [PATCH 11/23] sync refactor --- source/libs/sync/inc/syncRaftLog.h | 3 + source/libs/sync/src/syncRaftLog.c | 35 +++++- source/libs/sync/test/CMakeLists.txt | 14 +++ source/libs/sync/test/syncInitTest.cpp | 9 +- source/libs/sync/test/syncLogStoreTest.cpp | 132 +++++++++++++++++++++ 5 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 source/libs/sync/test/syncLogStoreTest.cpp diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index ecdb544302..d59b3206b5 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -63,6 +63,9 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore); char* logStore2Str(SSyncLogStore* pLogStore); +// for debug +void logStorePrint(SSyncLogStore* pLogStore); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index d5735d9142..aa2595c199 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -115,11 +115,44 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { return pEntry; } -cJSON* logStore2Json(SSyncLogStore* pLogStore) {} +cJSON* logStore2Json(SSyncLogStore* pLogStore) { + 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), "%lu", 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 = 1; i <= lastIndex; ++i) { + SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + syncEntryDestory(pEntry); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot); + return pJson; +} char* logStore2Str(SSyncLogStore* pLogStore) { cJSON* pJson = logStore2Json(pLogStore); char* serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; +} + +// for debug +void logStorePrint(SSyncLogStore* pLogStore) { + char* s = logStore2Str(pLogStore); + sTrace("%s", s); + free(s); } \ No newline at end of file diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 5a5186c7e2..2163583f0a 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(syncUtilTest "") add_executable(syncVotesGrantedTest "") add_executable(syncVotesRespondTest "") add_executable(syncIndexMgrTest "") +add_executable(syncLogStoreTest "") target_sources(syncTest @@ -85,6 +86,10 @@ target_sources(syncIndexMgrTest PRIVATE "syncIndexMgrTest.cpp" ) +target_sources(syncLogStoreTest + PRIVATE + "syncLogStoreTest.cpp" +) target_include_directories(syncTest @@ -172,6 +177,11 @@ target_include_directories(syncIndexMgrTest "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncLogStoreTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -242,6 +252,10 @@ target_link_libraries(syncIndexMgrTest sync gtest_main ) +target_link_libraries(syncLogStoreTest + sync + gtest_main +) enable_testing() diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index f665c5a612..b6794544eb 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -53,6 +53,7 @@ SSyncNode* syncNodeInit() { gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; gSyncIO->pSyncNode = pSyncNode; return pSyncNode; @@ -88,11 +89,11 @@ int main(int argc, char** argv) { SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - char* serialized = syncNode2Str(pSyncNode); - printf("%s\n", serialized); - free(serialized); + syncNodePrint((char*)"syncInitTest", pSyncNode); initRaftId(pSyncNode); + //-------------------------------------------------------------- + return 0; -} +} \ No newline at end of file diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp new file mode 100644 index 0000000000..a859186bbe --- /dev/null +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -0,0 +1,132 @@ +#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* pSyncNode; + +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", "./"); + + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 100000; + walCfg.segSize = 100000; + walCfg.level = TAOS_WAL_WRITE; + pWal = walOpen("./wal_test", &walCfg); + + 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); + } + + 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 logStoreTest() { + logStorePrint(pSyncNode->pLogStore); + for (int i = 0; i < 5; ++i) { + SSyncRaftEntry* pEntry; + pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry); + } + logStorePrint(pSyncNode->pLogStore); + + pSyncNode->pLogStore->truncate(pSyncNode->pLogStore, 3); + logStorePrint(pSyncNode->pLogStore); +} + +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); + + pSyncNode = syncInitTest(); + assert(pSyncNode != NULL); + + syncNodePrint((char*)"syncLogStoreTest", pSyncNode); + + initRaftId(pSyncNode); + + //-------------------------------------------------------------- + + logStoreTest(); + + //-------------------------------------------------------------- + // walClose(pWal); + + return 0; +} From 651b3971c0ec4a0a901912e3bdfc8249a6701932 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Thu, 10 Mar 2022 11:56:11 +0800 Subject: [PATCH 12/23] [TD-13766]: redefine sleep api. --- include/os/osSleep.h | 10 +++ source/client/src/clientHb.c | 2 +- source/client/src/tmq.c | 10 +-- source/libs/catalog/src/catalog.c | 2 +- source/libs/catalog/test/catalogTests.cpp | 90 +++++++++---------- source/libs/qcom/test/queryTest.cpp | 6 +- source/libs/qworker/test/qworkerTests.cpp | 64 ++++++------- source/libs/scheduler/test/schedulerTests.cpp | 14 +-- .../sync/test/syncIOSendMsgClientTest.cpp | 4 +- .../sync/test/syncIOSendMsgServerTest.cpp | 2 +- source/libs/sync/test/syncIOSendMsgTest.cpp | 4 +- source/libs/sync/test/syncIOTickPingTest.cpp | 2 +- source/libs/sync/test/syncIOTickQTest.cpp | 2 +- source/libs/transport/test/pushClient.c | 4 +- source/libs/transport/test/pushServer.c | 4 +- source/libs/transport/test/rclient.c | 4 +- source/libs/transport/test/rsclient.c | 2 +- source/libs/transport/test/syncClient.c | 4 +- source/os/src/osSleep.c | 54 +++++------ source/os/src/osString.c | 7 +- source/util/test/cacheTest.cpp | 4 +- source/util/test/trefTest.c | 6 +- tests/script/api/batchprepare.c | 2 +- 23 files changed, 150 insertions(+), 153 deletions(-) diff --git a/include/os/osSleep.h b/include/os/osSleep.h index 686bdd292e..feb9472995 100644 --- a/include/os/osSleep.h +++ b/include/os/osSleep.h @@ -20,7 +20,17 @@ extern "C" { #endif +// If the error is in a third-party library, place this header file under the third-party library header file. +#ifndef ALLOW_FORBID_FUNC + #define Sleep SLEEP_FUNC_TAOS_FORBID + #define sleep SLEEP_FUNC_TAOS_FORBID + #define usleep USLEEP_FUNC_TAOS_FORBID + #define nanosleep NANOSLEEP_FUNC_TAOS_FORBID +#endif + +void taosSsleep(int32_t s); void taosMsleep(int32_t ms); +void taosUsleep(int32_t us); #ifdef __cplusplus } diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index b1e9de8000..88763b8faf 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -449,7 +449,7 @@ static void hbStopThread() { } while (2 != atomic_load_8(&clientHbMgr.threadStop)) { - usleep(10); + taosUsleep(10); } tscDebug("hb thread stopped"); diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 60103cc9c5..c60d898a9e 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -1146,13 +1146,13 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { if (taosArrayGetSize(tmq->clientTopics) == 0) { tscDebug("consumer:%ld poll but not assigned", tmq->consumerId); /*printf("over1\n");*/ - usleep(blocking_time * 1000); + taosMsleep(blocking_time); return NULL; } SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, tmq->nextTopicIdx); if (taosArrayGetSize(pTopic->vgs) == 0) { /*printf("over2\n");*/ - usleep(blocking_time * 1000); + taosMsleep(blocking_time); return NULL; } @@ -1165,14 +1165,14 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blocking_time, pTopic, pVg); if (pReq == NULL) { ASSERT(false); - usleep(blocking_time * 1000); + taosMsleep(blocking_time); return NULL; } SMqPollCbParam* param = malloc(sizeof(SMqPollCbParam)); if (param == NULL) { ASSERT(false); - usleep(blocking_time * 1000); + taosMsleep(blocking_time); return NULL; } param->tmq = tmq; @@ -1204,7 +1204,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { if (tmq_message == NULL) { if (beginVgIdx == pTopic->nextVgIdx) { - usleep(blocking_time * 1000); + taosMsleep(blocking_time); } else { continue; } diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 77d25fa164..cd4f5438d5 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -2635,7 +2635,7 @@ void catalogDestroy(void) { tsem_post(&gCtgMgmt.sem); while (CTG_IS_LOCKED(&gCtgMgmt.lock)) { - usleep(1); + taosUsleep(1); } CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 00f6a508b7..cc0e5bb1a9 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) { } if (ctgTestEnableSleep) { - usleep(taosRand() % 5); + taosUsleep(taosRand() % 5); } if (++n % ctgTestPrintNum == 0) { printf("Get:%d\n", n); @@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) { } if (ctgTestEnableSleep) { - usleep(taosRand() % 5); + taosUsleep(taosRand() % 5); } if (++n % ctgTestPrintNum == 0) { printf("Set:%d\n", n); @@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) { } if (ctgTestEnableSleep) { - usleep(taosRand() % 5); + taosUsleep(taosRand() % 5); } if (++n % ctgTestPrintNum == 0) { printf("Set:%d\n", n); @@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) { tfree(tbMeta); if (ctgTestEnableSleep) { - usleep(taosRand() % 5); + taosUsleep(taosRand() % 5); } if (++n % ctgTestPrintNum == 0) { @@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) { } if (ctgTestEnableSleep) { - usleep(taosRand() % 5); + taosUsleep(taosRand() % 5); } if (++n % ctgTestPrintNum == 0) { printf("Set:%d\n", n); @@ -880,7 +880,7 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(vgInfo.epSet.numOfEps, 3); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { - usleep(50000); + taosMsleep(50); } ctgTestSetRspTableMeta(); @@ -901,7 +901,7 @@ TEST(tableMeta, normalTable) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -949,7 +949,7 @@ TEST(tableMeta, normalTable) { allDbNum += dbNum; allStbNum += stbNum; - sleep(2); + taosSsleep(2); } ASSERT_EQ(allDbNum, 1); @@ -996,7 +996,7 @@ TEST(tableMeta, childTableCase) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1058,7 +1058,7 @@ TEST(tableMeta, childTableCase) { allDbNum += dbNum; allStbNum += stbNum; - sleep(2); + taosSsleep(2); } ASSERT_EQ(allDbNum, 1); @@ -1105,7 +1105,7 @@ TEST(tableMeta, superTableCase) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1132,7 +1132,7 @@ TEST(tableMeta, superTableCase) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (2 != n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1181,7 +1181,7 @@ TEST(tableMeta, superTableCase) { allDbNum += dbNum; allStbNum += stbNum; - sleep(2); + taosSsleep(2); } ASSERT_EQ(allDbNum, 1); @@ -1230,7 +1230,7 @@ TEST(tableMeta, rmStbMeta) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1244,7 +1244,7 @@ TEST(tableMeta, rmStbMeta) { int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM); if (n || m) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1300,7 +1300,7 @@ TEST(tableMeta, updateStbMeta) { while (true) { uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1320,7 +1320,7 @@ TEST(tableMeta, updateStbMeta) { uint64_t n = 0; ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); if (n != 3) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -1392,7 +1392,7 @@ TEST(refreshGetMeta, normal2normal) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1410,7 +1410,7 @@ TEST(refreshGetMeta, normal2normal) { tfree(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); @@ -1471,7 +1471,7 @@ TEST(refreshGetMeta, normal2notexist) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1489,7 +1489,7 @@ TEST(refreshGetMeta, normal2notexist) { tfree(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); @@ -1545,7 +1545,7 @@ TEST(refreshGetMeta, normal2child) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1563,7 +1563,7 @@ TEST(refreshGetMeta, normal2child) { tfree(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); @@ -1629,7 +1629,7 @@ TEST(refreshGetMeta, stable2child) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1648,7 +1648,7 @@ TEST(refreshGetMeta, stable2child) { tfree(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } ctgTestCurrentSTableName = ctgTestSTablename; @@ -1714,7 +1714,7 @@ TEST(refreshGetMeta, stable2stable) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1733,7 +1733,7 @@ TEST(refreshGetMeta, stable2stable) { tfree(tableMeta); while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); @@ -1802,7 +1802,7 @@ TEST(refreshGetMeta, child2stable) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } STableMeta *tableMeta = NULL; @@ -1819,7 +1819,7 @@ TEST(refreshGetMeta, child2stable) { tfree(tableMeta); while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) { - usleep(50000); + taosMsleep(50); } ctgTestCurrentSTableName = ctgTestTablename; @@ -2019,7 +2019,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { if (n > 0) { break; } - usleep(50000); + taosMsleep(50); } code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); @@ -2043,7 +2043,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { uint64_t n = 0; ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n); if (n != 3) { - usleep(50000); + taosMsleep(50); } else { break; } @@ -2100,20 +2100,20 @@ TEST(multiThread, getSetRmSameDbVgroup) { pthread_t thread1, thread2; pthread_create(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg); - sleep(1); + taosSsleep(1); pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg); while (true) { if (ctgTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(ctgTestMTRunSec); + taosSsleep(ctgTestMTRunSec); break; } } ctgTestStop = true; - sleep(1); + taosSsleep(1); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -2152,20 +2152,20 @@ TEST(multiThread, getSetRmDiffDbVgroup) { pthread_t thread1, thread2; pthread_create(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg); - sleep(1); + taosSsleep(1); pthread_create(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg); while (true) { if (ctgTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(ctgTestMTRunSec); + taosSsleep(ctgTestMTRunSec); break; } } ctgTestStop = true; - sleep(1); + taosSsleep(1); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -2203,20 +2203,20 @@ TEST(multiThread, ctableMeta) { pthread_t thread1, thread2; pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg); - sleep(1); + taosSsleep(1); pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg); while (true) { if (ctgTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(ctgTestMTRunSec); + taosSsleep(ctgTestMTRunSec); break; } } ctgTestStop = true; - sleep(2); + taosSsleep(2); catalogDestroy(); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); @@ -2267,7 +2267,7 @@ TEST(rentTest, allRent) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) { - usleep(50000); + taosMsleep(50); } code = catalogGetExpiredDBs(pCtg, &dbs, &num); @@ -2292,7 +2292,7 @@ TEST(rentTest, allRent) { } printf("*************************************************\n"); - sleep(2); + taosSsleep(2); } catalogDestroy(); diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp index 9ca7442d55..72ce0f7c37 100644 --- a/source/libs/qcom/test/queryTest.cpp +++ b/source/libs/qcom/test/queryTest.cpp @@ -63,7 +63,7 @@ int main(int argc, char** argv) { TEST(testCase, async_task_test) { SParam* p = (SParam*)calloc(1, sizeof(SParam)); taosAsyncExec(testPrint, p, NULL); - usleep(5000); + taosMsleep(5); } TEST(testCase, many_async_task_test) { @@ -73,14 +73,14 @@ TEST(testCase, many_async_task_test) { taosAsyncExec(testPrint, p, NULL); } - usleep(10000); + taosMsleep(10); } TEST(testCase, error_in_async_test) { int32_t code = 0; SParam* p = (SParam*) calloc(1, sizeof(SParam)); taosAsyncExec(testPrintError, p, &code); - usleep(1000); + taosMsleep(1); printf("Error code:%d after asynchronously exec function\n", code); } diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp index 8658c4cead..2e262abcd0 100644 --- a/source/libs/qworker/test/qworkerTests.cpp +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -308,7 +308,7 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { if (qwtTestEnableSleep) { if (runTime) { - usleep(runTime); + taosUsleep(runTime); } } @@ -590,7 +590,7 @@ void *queryThread(void *param) { qwtBuildQueryReqMsg(&queryRpc); qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); if (qwtTestEnableSleep) { - usleep(taosRand()%5); + taosUsleep(taosRand()%5); } if (++n % qwtTestPrintNum == 0) { printf("query:%d\n", n); @@ -612,7 +612,7 @@ void *readyThread(void *param) { qwtBuildReadyReqMsg(&readyMsg, &readyRpc); code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); if (qwtTestEnableSleep) { - usleep(taosRand()%5); + taosUsleep(taosRand()%5); } if (++n % qwtTestPrintNum == 0) { printf("ready:%d\n", n); @@ -634,7 +634,7 @@ void *fetchThread(void *param) { qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); if (qwtTestEnableSleep) { - usleep(taosRand()%5); + taosUsleep(taosRand()%5); } if (++n % qwtTestPrintNum == 0) { printf("fetch:%d\n", n); @@ -656,7 +656,7 @@ void *dropThread(void *param) { qwtBuildDropReqMsg(&dropMsg, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); if (qwtTestEnableSleep) { - usleep(taosRand()%5); + taosUsleep(taosRand()%5); } if (++n % qwtTestPrintNum == 0) { printf("drop:%d\n", n); @@ -678,7 +678,7 @@ void *statusThread(void *param) { qwtBuildStatusReqMsg(&statusMsg, &statusRpc); code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); if (qwtTestEnableSleep) { - usleep(taosRand()%5); + taosUsleep(taosRand()%5); } if (++n % qwtTestPrintNum == 0) { printf("status:%d\n", n); @@ -696,7 +696,7 @@ void *qwtclientThread(void *param) { void *mockPointer = (void *)0x1; SRpcMsg queryRpc = {0}; - sleep(1); + taosSsleep(1); while (!qwtTestStop) { qwtTestCaseFinished = false; @@ -705,7 +705,7 @@ void *qwtclientThread(void *param) { qwtPutReqToQueue((void *)0x1, &queryRpc); while (!qwtTestCaseFinished) { - usleep(1); + taosUsleep(1); } @@ -751,7 +751,7 @@ void *queryQueueThread(void *param) { int32_t delay = taosRand() % qwtTestReqMaxDelayUsec; if (delay) { - usleep(delay); + taosUsleep(delay); } } @@ -807,7 +807,7 @@ void *fetchQueueThread(void *param) { int32_t delay = taosRand() % qwtTestReqMaxDelayUsec; if (delay) { - usleep(delay); + taosUsleep(delay); } } @@ -982,21 +982,21 @@ TEST(seqTest, randCase) { qwtBuildReadyReqMsg(&readyMsg, &readyRpc); code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); if (qwtTestEnableSleep) { - usleep(1); + taosUsleep(1); } } else if (r >= maxr * 2/5 && r < maxr* 3/5) { printf("Fetch,%d\n", t++); qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); if (qwtTestEnableSleep) { - usleep(1); + taosUsleep(1); } } else if (r >= maxr * 3/5 && r < maxr * 4/5) { printf("Drop,%d\n", t++); qwtBuildDropReqMsg(&dropMsg, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); if (qwtTestEnableSleep) { - usleep(1); + taosUsleep(1); } } else if (r >= maxr * 4/5 && r < maxr-1) { printf("Status,%d\n", t++); @@ -1004,7 +1004,7 @@ TEST(seqTest, randCase) { code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); ASSERT_EQ(code, 0); if (qwtTestEnableSleep) { - usleep(1); + taosUsleep(1); } } else { printf("QUIT RAND NOW"); @@ -1042,15 +1042,15 @@ TEST(seqTest, multithreadRand) { while (true) { if (qwtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(qwtTestMTRunSec); + taosSsleep(qwtTestMTRunSec); break; } } qwtTestStop = true; - sleep(3); + taosSsleep(3); qWorkerDestroy(&mgmt); } @@ -1099,9 +1099,9 @@ TEST(rcTest, shortExecshortDelay) { while (true) { if (qwtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(qwtTestMTRunSec); + taosSsleep(qwtTestMTRunSec); break; } } @@ -1113,14 +1113,14 @@ TEST(rcTest, shortExecshortDelay) { break; } - sleep(1); + taosSsleep(1); if (qwtTestCaseFinished) { if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); - usleep(10); + taosUsleep(10); } } @@ -1180,9 +1180,9 @@ TEST(rcTest, longExecshortDelay) { while (true) { if (qwtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(qwtTestMTRunSec); + taosSsleep(qwtTestMTRunSec); break; } } @@ -1195,14 +1195,14 @@ TEST(rcTest, longExecshortDelay) { break; } - sleep(1); + taosSsleep(1); if (qwtTestCaseFinished) { if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); - usleep(10); + taosUsleep(10); } } @@ -1263,9 +1263,9 @@ TEST(rcTest, shortExeclongDelay) { while (true) { if (qwtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(qwtTestMTRunSec); + taosSsleep(qwtTestMTRunSec); break; } } @@ -1278,14 +1278,14 @@ TEST(rcTest, shortExeclongDelay) { break; } - sleep(1); + taosSsleep(1); if (qwtTestCaseFinished) { if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); - usleep(10); + taosUsleep(10); } } @@ -1342,15 +1342,15 @@ TEST(rcTest, dropTest) { while (true) { if (qwtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(qwtTestMTRunSec); + taosSsleep(qwtTestMTRunSec); break; } } qwtTestStop = true; - sleep(3); + taosSsleep(3); qWorkerDestroy(&mgmt); } diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index f17dcbd1f5..77353607fa 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -278,7 +278,7 @@ void *schtSendRsp(void *param) { break; } - usleep(1000); + taosMsleep(1); } pJob = schAcquireJob(job); @@ -303,7 +303,7 @@ void *schtCreateFetchRspThread(void *param) { int64_t job = *(int64_t *)param; SSchJob* pJob = schAcquireJob(job); - sleep(1); + taosSsleep(1); int32_t code = 0; SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)calloc(1, sizeof(SRetrieveTableRsp)); @@ -327,7 +327,7 @@ void *schtFetchRspThread(void *aa) { continue; } - usleep(1); + taosUsleep(1); param = (SSchCallbackParam *)calloc(1, sizeof(*param)); @@ -532,7 +532,7 @@ void* schtRunJobThread(void *aa) { void* schtFreeJobThread(void *aa) { while (!schtTestStop) { - usleep(taosRand() % 100); + taosUsleep(taosRand() % 100); schtFreeQueryJob(1); } } @@ -701,15 +701,15 @@ TEST(multiThread, forceFree) { while (true) { if (schtTestDeadLoop) { - sleep(1); + taosSsleep(1); } else { - sleep(schtTestMTRunSec); + taosSsleep(schtTestMTRunSec); break; } } schtTestStop = true; - sleep(3); + taosSsleep(3); } int main(int argc, char** argv) { diff --git a/source/libs/sync/test/syncIOSendMsgClientTest.cpp b/source/libs/sync/test/syncIOSendMsgClientTest.cpp index 83ac724789..250054fd5a 100644 --- a/source/libs/sync/test/syncIOSendMsgClientTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgClientTest.cpp @@ -39,11 +39,11 @@ int main() { rpcMsg.msgType = 77; syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg); - sleep(1); + taosSsleep(1); } while (1) { - sleep(1); + taosSsleep(1); } return 0; diff --git a/source/libs/sync/test/syncIOSendMsgServerTest.cpp b/source/libs/sync/test/syncIOSendMsgServerTest.cpp index b0f177962f..1d7402e461 100644 --- a/source/libs/sync/test/syncIOSendMsgServerTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgServerTest.cpp @@ -26,7 +26,7 @@ int main() { assert(ret == 0); while (1) { - sleep(1); + taosSsleep(1); } return 0; diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp index c25ad3b1dd..ed88fbb03e 100644 --- a/source/libs/sync/test/syncIOSendMsgTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgTest.cpp @@ -39,11 +39,11 @@ int main() { rpcMsg.msgType = 77; syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg); - sleep(1); + taosSsleep(1); } while (1) { - sleep(1); + taosSsleep(1); } return 0; diff --git a/source/libs/sync/test/syncIOTickPingTest.cpp b/source/libs/sync/test/syncIOTickPingTest.cpp index 777fc035e2..8be93e6fc0 100644 --- a/source/libs/sync/test/syncIOTickPingTest.cpp +++ b/source/libs/sync/test/syncIOTickPingTest.cpp @@ -29,7 +29,7 @@ int main() { assert(ret == 0); while (1) { - sleep(1); + taosSsleep(1); } return 0; } diff --git a/source/libs/sync/test/syncIOTickQTest.cpp b/source/libs/sync/test/syncIOTickQTest.cpp index 5615058cc3..76f5e33e82 100644 --- a/source/libs/sync/test/syncIOTickQTest.cpp +++ b/source/libs/sync/test/syncIOTickQTest.cpp @@ -29,7 +29,7 @@ int main() { assert(ret == 0); while (1) { - sleep(1); + taosSsleep(1); } return 0; } diff --git a/source/libs/transport/test/pushClient.c b/source/libs/transport/test/pushClient.c index f4babc9980..bdb754ea14 100644 --- a/source/libs/transport/test/pushClient.c +++ b/source/libs/transport/test/pushClient.c @@ -107,7 +107,7 @@ static void *sendRequest(void *param) { tDebug("recv response succefully"); - // usleep(100000000); + // taosSsleep(100); } tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); @@ -223,7 +223,7 @@ int main(int argc, char *argv[]) { } do { - usleep(1); + taosUsleep(1); } while (tcount < appThreads); gettimeofday(&systemTime, NULL); diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c index c763b7bd8a..f4ad73f743 100644 --- a/source/libs/transport/test/pushServer.c +++ b/source/libs/transport/test/pushServer.c @@ -77,7 +77,7 @@ void processShellMsg() { taosFreeQitem(pRpcMsg); { - // sleep(1); + // taosSsleep(1); SRpcMsg nRpcMsg = {0}; nRpcMsg.pCont = rpcMallocCont(msgSize); nRpcMsg.contLen = msgSize; @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) { tError("failed to start RPC server"); return -1; } - // sleep(5); + // taosSsleep(5); tInfo("RPC server is running, ctrl-c to exit"); diff --git a/source/libs/transport/test/rclient.c b/source/libs/transport/test/rclient.c index 6fc935cb61..f3940e34f9 100644 --- a/source/libs/transport/test/rclient.c +++ b/source/libs/transport/test/rclient.c @@ -84,7 +84,7 @@ static void *sendRequest(void *param) { tDebug("recv response succefully"); - // usleep(100000000); + // taosSsleep(100); } tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { } do { - usleep(1); + taosUsleep(1); } while (tcount < appThreads); gettimeofday(&systemTime, NULL); diff --git a/source/libs/transport/test/rsclient.c b/source/libs/transport/test/rsclient.c index 26a02eb05b..f2a963b83f 100644 --- a/source/libs/transport/test/rsclient.c +++ b/source/libs/transport/test/rsclient.c @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) { } do { - usleep(1); + taosUsleep(1); } while ( tcount < appThreads); gettimeofday(&systemTime, NULL); diff --git a/source/libs/transport/test/syncClient.c b/source/libs/transport/test/syncClient.c index f43fa7aae6..f84ced5374 100644 --- a/source/libs/transport/test/syncClient.c +++ b/source/libs/transport/test/syncClient.c @@ -85,7 +85,7 @@ static void *sendRequest(void *param) { tDebug("recv response succefully"); - // usleep(100000000); + // taosSsleep(100); } tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000); @@ -201,7 +201,7 @@ int main(int argc, char *argv[]) { } do { - usleep(1); + taosUsleep(1); } while (tcount < appThreads); gettimeofday(&systemTime, NULL); diff --git a/source/os/src/osSleep.c b/source/os/src/osSleep.c index 3b90fbdad8..724347b0bc 100644 --- a/source/os/src/osSleep.c +++ b/source/os/src/osSleep.c @@ -13,47 +13,35 @@ * along with this program. If not, see . */ +#define ALLOW_FORBID_FUNC #define _DEFAULT_SOURCE #include "os.h" -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) - -void taosMsleep(int32_t ms) { Sleep(ms); } - -#else +#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #include +#endif -/* - to make taosMsleep work, - signal SIGALRM shall be blocked in the calling thread, - - sigset_t set; - sigemptyset(&set); - sigaddset(&set, SIGALRM); - pthread_sigmask(SIG_BLOCK, &set, NULL); -*/ -void taosMsleep(int32_t mseconds) { -#if 1 - usleep(mseconds * 1000); +void taosSsleep(int32_t s) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + Sleep(1000 * s); #else - struct timeval timeout; - int32_t seconds, useconds; - - seconds = mseconds / 1000; - useconds = (mseconds % 1000) * 1000; - timeout.tv_sec = seconds; - timeout.tv_usec = useconds; - - /* sigset_t set; */ - /* sigemptyset(&set); */ - /* sigaddset(&set, SIGALRM); */ - /* pthread_sigmask(SIG_BLOCK, &set, NULL); */ - - select(0, NULL, NULL, NULL, &timeout); - -/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */ + sleep(s); #endif } +void taosMsleep(int32_t ms) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + Sleep(ms); +#else + usleep(ms * 1000); #endif +} + +void taosUsleep(int32_t us) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + nanosleep(1000 * us); +#else + usleep(us); +#endif +} diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 88ea4b3e15..0fab7a941e 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -291,11 +291,10 @@ int32_t twcslen(const wchar_t *wcs) { return n; } - int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { - for (int32_t i = 0; i < bytes; ++i) { - int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); - int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); + for (int32_t i = 0; i < bytes; i += TSDB_NCHAR_SIZE) { + int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i); + int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i); if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) { return f1 - f2; diff --git a/source/util/test/cacheTest.cpp b/source/util/test/cacheTest.cpp index e1c8c8c14e..748cf31b67 100644 --- a/source/util/test/cacheTest.cpp +++ b/source/util/test/cacheTest.cpp @@ -14,7 +14,7 @@ TEST(cacheTest, client_cache_test) { char data1[] = "test11"; char* cachedObj = (char*) taosCachePut(tscMetaCache, key1, strlen(key1), data1, strlen(data1)+1, 1); - sleep(REFRESH_TIME_IN_SEC+1); + taosSsleep(REFRESH_TIME_IN_SEC+1); printf("obj is still valid: %s\n", cachedObj); @@ -37,7 +37,7 @@ TEST(cacheTest, client_cache_test) { taosCacheRelease(tscMetaCache, (void**) &cachedObj2, false); - sleep(3); + taosSsleep(3); char* d = (char*) taosCacheAcquireByKey(tscMetaCache, key3, strlen(key3)); assert(d == NULL); diff --git a/source/util/test/trefTest.c b/source/util/test/trefTest.c index 586151d782..58d9d2202e 100644 --- a/source/util/test/trefTest.c +++ b/source/util/test/trefTest.c @@ -42,7 +42,7 @@ void *addRef(void *param) { pSpace->p[id] = malloc(128); pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]); } - usleep(100); + taosUsleep(100); } return NULL; @@ -60,7 +60,7 @@ void *removeRef(void *param) { if (code == 0) pSpace->rid[id] = 0; } - usleep(100); + taosUsleep(100); } return NULL; @@ -76,7 +76,7 @@ void *acquireRelease(void *param) { id = random() % pSpace->refNum; void *p = taosAcquireRef(pSpace->rsetId, (int64_t) pSpace->p[id]); if (p) { - usleep(id % 5 + 1); + taosUsleep(id % 5 + 1); taosReleaseRef(pSpace->rsetId, (int64_t) pSpace->p[id]); } } diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 386df15d86..5336a557e3 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -5089,7 +5089,7 @@ int main(int argc, char *argv[]) //pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]); while(1) { - sleep(1); + taosSsleep(1); } return 0; } From e63f352f8b124b66bad1166918ebdec635e09812 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 10 Mar 2022 12:02:55 +0800 Subject: [PATCH 13/23] Feature/sangshuduo/td 13558 taos shell refactor (#10661) * [TD-13558]: taos shell refactor add taosTools as submodule * add tools/taos-tools * add more client interface for taosTools compile * update taos-tools * update taos-tools --- .gitmodules | 3 ++ CMakeLists.txt | 26 ++++++++++++ include/client/taos.h | 4 ++ include/common/taosdef.h | 2 + source/client/src/clientMain.c | 74 ++++++++++++++++++++++++++++++++++ tools/CMakeLists.txt | 11 ++++- tools/taos-tools | 1 + 7 files changed, 120 insertions(+), 1 deletion(-) create mode 160000 tools/taos-tools diff --git a/.gitmodules b/.gitmodules index 07e4bb2b9c..bc38453f19 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "examples/rust"] path = examples/rust url = https://github.com/songtianyi/tdengine-rust-bindings.git +[submodule "tools/taos-tools"] + path = tools/taos-tools + url = https://github.com/taosdata/taos-tools diff --git a/CMakeLists.txt b/CMakeLists.txt index df3aab5cb3..9d64966861 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,32 @@ project( DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)" ) +IF ("${BUILD_TOOLS}" STREQUAL "") + IF (TD_LINUX) + IF (TD_ARM_32) + SET(BUILD_TOOLS "false") + ELSEIF (TD_ARM_64) + SET(BUILD_TOOLS "false") + ELSE () + SET(BUILD_TOOLS "false") + ENDIF () + ELSEIF (TD_DARWIN) + SET(BUILD_TOOLS "false") + ELSE () + SET(BUILD_TOOLS "false") + ENDIF () +ENDIF () + +IF ("${BUILD_TOOLS}" MATCHES "false") + MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}") + SET(TD_TAOS_TOOLS FALSE) +ELSE () + MESSAGE("") + MESSAGE("${Green} Will build taos_tools! ${ColourReset}") + MESSAGE("") + SET(TD_TAOS_TOOLS TRUE) +ENDIF () + set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib") include(${CMAKE_SUPPORT_DIR}/cmake.options) diff --git a/include/client/taos.h b/include/client/taos.h index 8b1517c6ff..5da5908779 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -256,6 +256,10 @@ DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_co void tmqShowMsg(tmq_message_t *tmq_message); int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); +typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code); + +DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT* stmt); + #ifdef __cplusplus } #endif diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 99360b8d3f..9e5e5ebdcf 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -63,6 +63,8 @@ typedef enum { extern char *qtypeStr[]; +#define TSDB_PORT_HTTP 11 + #ifdef __cplusplus } #endif diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 5bcc287116..09a0233e04 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -343,3 +343,77 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { // TODO } + +TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { + // TODO + return NULL; +} + +TAOS_RES *taos_consume(TAOS_SUB *tsub) { + // TODO + return NULL; +} + +void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { + // TODO +} + +TAOS_STMT* taos_stmt_init(TAOS* taos) { + // TODO + return NULL; +} + +int taos_stmt_close(TAOS_STMT* stmt) { + // TODO + return -1; +} + +int taos_stmt_execute(TAOS_STMT* stmt) { + // TODO + return -1; +} + +char *taos_stmt_errstr(TAOS_STMT *stmt) { + // TODO + return NULL; +} + +int taos_stmt_affected_rows(TAOS_STMT* stmt) { + // TODO + return -1; +} + +TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) { + // TODO + return NULL; +} + +int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { + // TODO + return -1; +} + +int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { + // TODO + return -1; +} + +int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { + // TODO + return -1; +} + +int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { + // TODO + return -1; +} + +int taos_stmt_add_batch(TAOS_STMT* stmt) { + // TODO + return -1; +} + +int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { + // TODO + return -1; +} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 629677c9a5..dae0a1c840 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1 +1,10 @@ -add_subdirectory(shell) \ No newline at end of file +IF (TD_TAOS_TOOLS) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/tools/taos_tools/deps/avro/lang/c/src) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/client) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/common) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/util) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/os) + ADD_SUBDIRECTORY(taos-tools) +ENDIF () + +add_subdirectory(shell) diff --git a/tools/taos-tools b/tools/taos-tools new file mode 160000 index 0000000000..f36b07f710 --- /dev/null +++ b/tools/taos-tools @@ -0,0 +1 @@ +Subproject commit f36b07f710d661dca88fdd70e73b5e3e16a960e0 From ebeb4bb7a60caaf9b082b1ae06df1dc440222822 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Thu, 10 Mar 2022 14:34:02 +0800 Subject: [PATCH 14/23] sync refactor --- source/libs/sync/inc/syncMessage.h | 3 - source/libs/sync/inc/syncRaftEntry.h | 12 ++-- source/libs/sync/inc/syncUtil.h | 3 + source/libs/sync/src/syncMessage.c | 2 +- source/libs/sync/src/syncRaftEntry.c | 44 ++++++++++++-- source/libs/sync/src/syncRaftLog.c | 19 ++++-- source/libs/sync/src/syncUtil.c | 36 +++++++++++ source/libs/sync/test/CMakeLists.txt | 16 +++++ source/libs/sync/test/syncEntryTest.cpp | 81 +++++++++++++++++++++++++ 9 files changed, 195 insertions(+), 21 deletions(-) create mode 100644 source/libs/sync/test/syncEntryTest.cpp diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h index dcd8f7c74e..6231cb8399 100644 --- a/source/libs/sync/inc/syncMessage.h +++ b/source/libs/sync/inc/syncMessage.h @@ -130,9 +130,6 @@ typedef struct SyncClientRequest { char data[]; } SyncClientRequest; -#define SYNC_CLIENT_REQUEST_FIX_LEN \ - (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(bool) + sizeof(uint32_t)) - SyncClientRequest* syncClientRequestBuild(uint32_t dataLen); void syncClientRequestDestroy(SyncClientRequest* pMsg); void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen); diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index 2d77af8835..b607849dc8 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -39,16 +39,14 @@ typedef struct SSyncRaftEntry { char data[]; } SSyncRaftEntry; -#define SYNC_ENTRY_FIX_LEN \ - (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(bool) + sizeof(SyncTerm) + \ - sizeof(SyncIndex) + sizeof(uint32_t)) - -SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); +SSyncRaftEntry* syncEntryBuild(uint32_t dataLen); +SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); void syncEntryDestory(SSyncRaftEntry* pEntry); -void syncEntrySerialize(const SSyncRaftEntry* pEntry, char* buf, uint32_t bufLen); -void syncEntryDeserialize(const char* buf, uint32_t len, SSyncRaftEntry* pEntry); +char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len); +SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len); cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); char* syncEntry2Str(const SSyncRaftEntry* pEntry); +void syncEntryPrint(const SSyncRaftEntry* pEntry); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncUtil.h b/source/libs/sync/inc/syncUtil.h index f2c979da99..2bbc1948dd 100644 --- a/source/libs/sync/inc/syncUtil.h +++ b/source/libs/sync/inc/syncUtil.h @@ -49,6 +49,9 @@ cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p); cJSON* syncUtilRaftId2Json(const SRaftId* p); char* syncUtilRaftId2Str(const SRaftId* p); const char* syncUtilState2String(ESyncState state); +bool syncUtilCanPrint(char c); +char* syncUtilprintBin(char* ptr, uint32_t len); +char* syncUtilprintBin2(char* ptr, uint32_t len); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 11f823a048..baef49d748 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -348,7 +348,7 @@ SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId) // ---- message process SyncClientRequest---- SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) { - uint32_t bytes = SYNC_CLIENT_REQUEST_FIX_LEN + dataLen; + uint32_t bytes = sizeof(SyncClientRequest) + dataLen; SyncClientRequest* pMsg = malloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index cd14ea502e..7774cbb0ce 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -14,14 +14,22 @@ */ #include "syncRaftEntry.h" +#include "syncUtil.h" -SSyncRaftEntry* syncEntryBuild(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { - uint32_t bytes = SYNC_ENTRY_FIX_LEN + pMsg->bytes; +SSyncRaftEntry* syncEntryBuild(uint32_t dataLen) { + uint32_t bytes = sizeof(SSyncRaftEntry) + dataLen; SSyncRaftEntry* pEntry = malloc(bytes); assert(pEntry != NULL); memset(pEntry, 0, bytes); - pEntry->bytes = bytes; + pEntry->dataLen = dataLen; + return pEntry; +} + +SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { + SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen); + assert(pEntry != NULL); + pEntry->msgType = pMsg->msgType; pEntry->originalRpcType = pMsg->originalRpcType; pEntry->seqNum = pMsg->seqNum; @@ -40,14 +48,23 @@ void syncEntryDestory(SSyncRaftEntry* pEntry) { } } -void syncEntrySerialize(const SSyncRaftEntry* pEntry, char* buf, uint32_t bufLen) { - assert(pEntry->bytes <= bufLen); +char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len) { + char* buf = malloc(pEntry->bytes); + assert(buf != NULL); memcpy(buf, pEntry, pEntry->bytes); + if (len != NULL) { + *len = pEntry->bytes; + } + return buf; } -void syncEntryDeserialize(const char* buf, uint32_t len, SSyncRaftEntry* pEntry) { +SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SSyncRaftEntry* pEntry = malloc(bytes); + assert(pEntry != NULL); memcpy(pEntry, buf, len); assert(len == pEntry->bytes); + return pEntry; } cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { @@ -66,6 +83,15 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { 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); + + s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + free(s); + cJSON* pJson = cJSON_CreateObject(); cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot); return pJson; @@ -76,4 +102,10 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) { char* serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; +} + +void syncEntryPrint(const SSyncRaftEntry* pEntry) { + char* s = syncEntry2Str(pEntry); + sTrace("%s", s); + free(s); } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index aa2595c199..d8a460629b 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -47,13 +47,16 @@ void logStoreDestory(SSyncLogStore* pLogStore) { int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; - char* buf = malloc(pEntry->bytes); - syncEntrySerialize(pEntry, buf, pEntry->bytes); - walWrite(pWal, pEntry->index, pEntry->msgType, buf, pEntry->bytes); + assert(pEntry->index == logStoreLastIndex(pLogStore) + 1); + uint32_t len; + char* serialized = syncEntrySerialize(pEntry, &len); + assert(serialized != NULL); + + walWrite(pWal, pEntry->index, pEntry->msgType, serialized, len); walFsync(pWal, true); - free(buf); + free(serialized); } // get one log entry, user need to free pEntry->pCont @@ -64,6 +67,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { 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); @@ -79,9 +84,15 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { // return index of last entry SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) { + /* SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); SyncIndex lastIndex = pLastEntry->index; free(pLastEntry); + */ + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + int64_t last = walGetLastVer(pWal); + SyncIndex lastIndex = last < 0 ? 0 : last; return lastIndex; } diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 3fb430a714..736260cafc 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -148,4 +148,40 @@ const char* syncUtilState2String(ESyncState state) { } else { return "TAOS_SYNC_STATE_UNKNOWN"; } +} + +bool syncUtilCanPrint(char c) { + if (c >= 32 && c <= 126) { + return true; + } else { + return false; + } +} + +char* syncUtilprintBin(char* ptr, uint32_t len) { + char* s = malloc(len + 1); + assert(s != NULL); + memset(s, 0, len + 1); + memcpy(s, ptr, len); + + for (int i = 0; i < len; ++i) { + if (!syncUtilCanPrint(s[i])) { + s[i] = '.'; + } + } + return s; +} + +char* syncUtilprintBin2(char* ptr, uint32_t len) { + uint32_t len2 = len * 4 + 1; + char* s = malloc(len2); + assert(s != NULL); + memset(s, 0, len2); + + char* p = s; + for (int i = 0; i < len; ++i) { + int n = sprintf(p, "%d,", ptr[i]); + p += n; + } + return s; } \ No newline at end of file diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 2163583f0a..bfde08ffac 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(syncVotesGrantedTest "") add_executable(syncVotesRespondTest "") add_executable(syncIndexMgrTest "") add_executable(syncLogStoreTest "") +add_executable(syncEntryTest "") target_sources(syncTest @@ -90,6 +91,10 @@ target_sources(syncLogStoreTest PRIVATE "syncLogStoreTest.cpp" ) +target_sources(syncEntryTest + PRIVATE + "syncEntryTest.cpp" +) target_include_directories(syncTest @@ -182,6 +187,11 @@ target_include_directories(syncLogStoreTest "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncEntryTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -256,6 +266,10 @@ target_link_libraries(syncLogStoreTest sync gtest_main ) +target_link_libraries(syncEntryTest + sync + gtest_main +) enable_testing() @@ -263,3 +277,5 @@ add_test( NAME sync_test COMMAND syncTest ) + + diff --git a/source/libs/sync/test/syncEntryTest.cpp b/source/libs/sync/test/syncEntryTest.cpp new file mode 100644 index 0000000000..e54daaa79a --- /dev/null +++ b/source/libs/sync/test/syncEntryTest.cpp @@ -0,0 +1,81 @@ +#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"); +} + +void test1() { + SSyncRaftEntry* pEntry = syncEntryBuild(10); + assert(pEntry != NULL); + pEntry->msgType = 1; + pEntry->originalRpcType = 2; + pEntry->seqNum = 3; + pEntry->isWeak = true; + pEntry->term = 100; + pEntry->index = 200; + strcpy(pEntry->data, "test1"); + + syncEntryPrint(pEntry); + syncEntryDestory(pEntry); +} + +void test2() { + SyncClientRequest* pSyncMsg = syncClientRequestBuild(10); + pSyncMsg->originalRpcType = 33; + pSyncMsg->seqNum = 11; + pSyncMsg->isWeak = 1; + strcpy(pSyncMsg->data, "test2"); + + SSyncRaftEntry* pEntry = syncEntryBuild2(pSyncMsg, 100, 200); + syncEntryPrint(pEntry); + + syncClientRequestDestroy(pSyncMsg); + syncEntryDestory(pEntry); +} + +void test3() { + SSyncRaftEntry* pEntry = syncEntryBuild(10); + assert(pEntry != NULL); + pEntry->msgType = 11; + pEntry->originalRpcType = 22; + pEntry->seqNum = 33; + pEntry->isWeak = true; + pEntry->term = 44; + pEntry->index = 55; + strcpy(pEntry->data, "test3"); + syncEntryPrint(pEntry); + + uint32_t len; + char* serialized = syncEntrySerialize(pEntry, &len); + assert(serialized != NULL); + SSyncRaftEntry* pEntry2 = syncEntryDeserialize(serialized, len); + syncEntryPrint(pEntry2); + + free(serialized); + syncEntryDestory(pEntry2); + syncEntryDestory(pEntry); +} + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + test1(); + test2(); + test3(); + + return 0; +} From 7ad5e7429fc10e8aa0be59b4bee388a984cb1771 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 10 Mar 2022 15:34:15 +0800 Subject: [PATCH 15/23] ajust STSma definition --- include/common/tmsg.h | 116 ++++++++++++++++-------- include/util/tdef.h | 2 +- source/dnode/vnode/src/inc/tsdbFS.h | 24 ++++- source/dnode/vnode/src/inc/tsdbFile.h | 4 +- source/dnode/vnode/src/inc/tsdbSma.h | 2 +- source/dnode/vnode/src/tsdb/tsdbFile.c | 4 +- source/dnode/vnode/src/tsdb/tsdbMain.c | 2 +- source/dnode/vnode/src/tsdb/tsdbSma.c | 6 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 102 +++++++++++++-------- 9 files changed, 171 insertions(+), 91 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 238753e5b7..bbb3f6e22d 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1856,19 +1856,27 @@ typedef enum { TD_TIME_UNIT_MICROSEC = 9, TD_TIME_UNIT_NANOSEC = 10 } ETDTimeUnit; + typedef struct { - uint8_t version; // for compatibility - uint8_t intervalUnit; - uint8_t slidingUnit; - char indexName[TSDB_INDEX_NAME_LEN + 1]; - col_id_t numOfColIds; - uint16_t numOfFuncIds; - uint64_t tableUid; // super/common table uid - int64_t interval; - int64_t sliding; - col_id_t* colIds; // sorted column ids - uint16_t* funcIds; // sorted sma function ids -} STSma; // Time-range-wise SMA + uint16_t funcId; + uint16_t nColIds; + col_id_t* colIds; // sorted colIds +} SFuncColIds; + +typedef struct { + uint8_t version; // for compatibility + uint8_t intervalUnit; + uint8_t slidingUnit; + char indexName[TSDB_INDEX_NAME_LEN]; + char timezone[TD_TIMEZONE_LEN]; + uint16_t nFuncColIds; + uint16_t tagsFilterLen; + tb_uid_t tableUid; // super/common table uid + int64_t interval; + int64_t sliding; + SFuncColIds* funcColIds; // sorted funcIds + char* tagsFilter; +} STSma; // Time-range-wise SMA typedef struct { int64_t ver; // use a general definition @@ -1877,13 +1885,13 @@ typedef struct { typedef struct { int8_t type; // 0 status report, 1 update data - char indexName[TSDB_INDEX_NAME_LEN + 1]; // + char indexName[TSDB_INDEX_NAME_LEN]; // STimeWindow windows; } STSmaMsg; typedef struct { int64_t ver; // use a general definition - char indexName[TSDB_INDEX_NAME_LEN + 1]; + char indexName[TSDB_INDEX_NAME_LEN]; } SVDropTSmaReq; typedef struct { } SVCreateTSmaRsp, SVDropTSmaRsp; @@ -1934,8 +1942,14 @@ typedef struct { static FORCE_INLINE void tdDestroyTSma(STSma* pSma) { if (pSma) { - tfree(pSma->colIds); - tfree(pSma->funcIds); + if (pSma->funcColIds != NULL) { + for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) { + tfree((pSma->funcColIds + i)->colIds); + } + tfree(pSma->funcColIds); + } + + tfree(pSma->tagsFilter); } } @@ -1957,18 +1971,24 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) { tlen += taosEncodeFixedU8(buf, pSma->intervalUnit); tlen += taosEncodeFixedU8(buf, pSma->slidingUnit); tlen += taosEncodeString(buf, pSma->indexName); - tlen += taosEncodeFixedU16(buf, pSma->numOfColIds); - tlen += taosEncodeFixedU16(buf, pSma->numOfFuncIds); - tlen += taosEncodeFixedU64(buf, pSma->tableUid); + tlen += taosEncodeString(buf, pSma->timezone); + tlen += taosEncodeFixedU16(buf, pSma->nFuncColIds); + tlen += taosEncodeFixedU16(buf, pSma->tagsFilterLen); + tlen += taosEncodeFixedI64(buf, pSma->tableUid); tlen += taosEncodeFixedI64(buf, pSma->interval); tlen += taosEncodeFixedI64(buf, pSma->sliding); - for (col_id_t i = 0; i < pSma->numOfColIds; ++i) { - tlen += taosEncodeFixedU16(buf, *(pSma->colIds + i)); + for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) { + SFuncColIds* funcColIds = pSma->funcColIds + i; + tlen += taosEncodeFixedU16(buf, funcColIds->funcId); + tlen += taosEncodeFixedU16(buf, funcColIds->nColIds); + for (uint16_t j = 0; j < funcColIds->nColIds; ++j) { + tlen += taosEncodeFixedU16(buf, *(funcColIds->colIds + j)); + } } - for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) { - tlen += taosEncodeFixedU16(buf, *(pSma->funcIds + i)); + if (pSma->tagsFilterLen > 0) { + tlen += taosEncodeString(buf, pSma->tagsFilter); } return tlen; @@ -1989,34 +2009,52 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) { buf = taosDecodeFixedU8(buf, &pSma->intervalUnit); buf = taosDecodeFixedU8(buf, &pSma->slidingUnit); buf = taosDecodeStringTo(buf, pSma->indexName); - buf = taosDecodeFixedU16(buf, &pSma->numOfColIds); - buf = taosDecodeFixedU16(buf, &pSma->numOfFuncIds); - buf = taosDecodeFixedU64(buf, &pSma->tableUid); + buf = taosDecodeStringTo(buf, pSma->timezone); + buf = taosDecodeFixedU16(buf, &pSma->nFuncColIds); + buf = taosDecodeFixedU16(buf, &pSma->tagsFilterLen); + buf = taosDecodeFixedI64(buf, &pSma->tableUid); buf = taosDecodeFixedI64(buf, &pSma->interval); buf = taosDecodeFixedI64(buf, &pSma->sliding); - if (pSma->numOfColIds > 0) { - pSma->colIds = (col_id_t*)calloc(pSma->numOfColIds, sizeof(STSma)); - if (pSma->colIds == NULL) { + if (pSma->nFuncColIds > 0) { + pSma->funcColIds = (SFuncColIds*)calloc(pSma->nFuncColIds, sizeof(SFuncColIds)); + if (pSma->funcColIds == NULL) { + tdDestroyTSma(pSma); return NULL; } - for (uint16_t i = 0; i < pSma->numOfColIds; ++i) { - buf = taosDecodeFixedU16(buf, pSma->colIds + i); + for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) { + SFuncColIds* funcColIds = pSma->funcColIds + i; + buf = taosDecodeFixedU16(buf, &funcColIds->funcId); + buf = taosDecodeFixedU16(buf, &funcColIds->nColIds); + if (funcColIds->nColIds > 0) { + funcColIds->colIds = (col_id_t*)calloc(funcColIds->nColIds, sizeof(col_id_t)); + if (funcColIds->colIds != NULL) { + for (uint16_t j = 0; j < funcColIds->nColIds; ++j) { + buf = taosDecodeFixedU16(buf, funcColIds->colIds + j); + } + } else { + tdDestroyTSma(pSma); + return NULL; + } + } else { + funcColIds->colIds = NULL; + } } } else { - pSma->colIds = NULL; + pSma->funcColIds = NULL; } - if (pSma->numOfFuncIds > 0) { - pSma->funcIds = (uint16_t*)calloc(pSma->numOfFuncIds, sizeof(STSma)); - if (pSma->funcIds == NULL) { + if (pSma->tagsFilterLen > 0) { + pSma->tagsFilter = (char*)calloc(pSma->tagsFilterLen, 1); + if (pSma->tagsFilter != NULL) { + buf = taosDecodeStringTo(buf, pSma->tagsFilter); + } else { + tdDestroyTSma(pSma); return NULL; } - for (uint16_t i = 0; i < pSma->numOfFuncIds; ++i) { - buf = taosDecodeFixedU16(buf, pSma->funcIds + i); - } + } else { - pSma->funcIds = NULL; + pSma->tagsFilter = NULL; } return buf; diff --git a/include/util/tdef.h b/include/util/tdef.h index 664588f68f..902ed871f0 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -207,7 +207,7 @@ typedef enum ELogicConditionType { #define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_FUNC_MAX_RETRIEVE 1024 -#define TSDB_INDEX_NAME_LEN 32 +#define TSDB_INDEX_NAME_LEN 33 // 32 + 1 '\0' #define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN diff --git a/source/dnode/vnode/src/inc/tsdbFS.h b/source/dnode/vnode/src/inc/tsdbFS.h index 173e991631..a7275f57fd 100644 --- a/source/dnode/vnode/src/inc/tsdbFS.h +++ b/source/dnode/vnode/src/inc/tsdbFS.h @@ -43,12 +43,30 @@ typedef struct { STsdbFSMeta meta; // FS meta SArray * df; // data file array - // SArray * v2f100.tsma.index_name + // SArray * v2t100.index_name - SArray * smaf; // sma data file array v2f1900.tsma.index_name + SArray * smaf; // sma data file array v2t1900.index_name } SFSStatus; -typedef struct { +/** + * @brief Directory structure of .tsma data files. + * + * root@cary /vnode2/tsdb $ tree .tsma/ + * .tsma/ + * ├── v2t100.index_name_1 + * ├── v2t101.index_name_1 + * ├── v2t102.index_name_1 + * ├── v2t1900.index_name_3 + * ├── v2t1901.index_name_3 + * ├── v2t1902.index_name_3 + * ├── v2t200.index_name_2 + * ├── v2t201.index_name_2 + * └── v2t202.index_name_2 + * + * 0 directories, 9 files + */ + + typedef struct { pthread_rwlock_t lock; SFSStatus *cstatus; // current status diff --git a/source/dnode/vnode/src/inc/tsdbFile.h b/source/dnode/vnode/src/inc/tsdbFile.h index b58bfe77ab..d6ce33c389 100644 --- a/source/dnode/vnode/src/inc/tsdbFile.h +++ b/source/dnode/vnode/src/inc/tsdbFile.h @@ -56,8 +56,8 @@ typedef enum { TSDB_FILE_SMAL, // .smal(Block-wise SMA) TSDB_FILE_MAX, // TSDB_FILE_META, // meta - TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA - TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA + TSDB_FILE_TSMA, // v2t100.${sma_index_name}, Time-range-wise SMA + TSDB_FILE_RSMA, // v2r100.${sma_index_name}, Time-range-wise Rollup SMA } E_TSDB_FILE_T; typedef int32_t TSDB_FILE_T; diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h index 6e4ad909ae..1a5ccbdc21 100644 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -31,7 +31,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg); int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); -int32_t tsdbFreeSmaState(SSmaStat *pSmaStat); +int32_t tsdbDestroySmaState(SSmaStat *pSmaStat); // internal func diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 00e97c7b61..b756cc9862 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 - "tsma", // TSDB_FILE_TSMA - "rsma", // TSDB_FILE_RSMA + "sma", // TSDB_FILE_TSMA(directory name) + "sma", // TSDB_FILE_RSMA(directory name) }; static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname); diff --git a/source/dnode/vnode/src/tsdb/tsdbMain.c b/source/dnode/vnode/src/tsdb/tsdbMain.c index 1b3e00f090..0c82911226 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMain.c +++ b/source/dnode/vnode/src/tsdb/tsdbMain.c @@ -89,7 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, static void tsdbFree(STsdb *pTsdb) { if (pTsdb) { tsdbFreeFS(pTsdb->fs); - tsdbFreeSmaState(pTsdb->pSmaStat); + tsdbDestroySmaState(pTsdb->pSmaStat); tfree(pTsdb->path); free(pTsdb); } diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index aa9fb7c7ed..51abcbd9dd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -128,7 +128,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { return pItem; } -int32_t tsdbFreeSmaState(SSmaStat *pSmaStat) { +int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { if (pSmaStat) { // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL); @@ -404,7 +404,7 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, i static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { pSmaH->pTsdb = pTsdb; pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); - pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); + // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); } static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel, @@ -582,7 +582,7 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) { static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) { pSmaH->pTsdb = pTsdb; pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision); - pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); + // pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t); } /** diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index bf3e67cdf5..5a5c5e1530 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -42,17 +42,20 @@ TEST(testCase, tSmaEncodeDecodeTest) { tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.sliding = 0; tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN); + tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN); tSma.tableUid = 1234567890; - tSma.numOfColIds = 2; - tSma.numOfFuncIds = 5; // sum/min/max/avg/last - tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); - tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); - - for (int32_t i = 0; i < tSma.numOfColIds; ++i) { - *(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); - } - for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { - *(tSma.funcIds + i) = (i + 2); + tSma.nFuncColIds = 5; + tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds)); + ASSERT(tSma.funcColIds != NULL); + for (int32_t n = 0; n < tSma.nFuncColIds; ++n) { + SFuncColIds *funcColIds = tSma.funcColIds + n; + funcColIds->funcId = n; + funcColIds->nColIds = 10; + funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t)); + ASSERT(funcColIds->colIds != NULL); + for (int32_t i = 0; i < funcColIds->nColIds; ++i) { + *(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); + } } STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma}; @@ -81,16 +84,21 @@ TEST(testCase, tSmaEncodeDecodeTest) { EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit); EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit); EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName); - EXPECT_EQ(pSma->numOfColIds, qSma->numOfColIds); - EXPECT_EQ(pSma->numOfFuncIds, qSma->numOfFuncIds); + EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone); + EXPECT_EQ(pSma->nFuncColIds, qSma->nFuncColIds); EXPECT_EQ(pSma->tableUid, qSma->tableUid); EXPECT_EQ(pSma->interval, qSma->interval); EXPECT_EQ(pSma->sliding, qSma->sliding); - for (uint32_t j = 0; j < pSma->numOfColIds; ++j) { - EXPECT_EQ(*(col_id_t *)(pSma->colIds + j), *(col_id_t *)(qSma->colIds + j)); - } - for (uint32_t j = 0; j < pSma->numOfFuncIds; ++j) { - EXPECT_EQ(*(uint16_t *)(pSma->funcIds + j), *(uint16_t *)(qSma->funcIds + j)); + EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen); + EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter); + for (uint32_t j = 0; j < pSma->nFuncColIds; ++j) { + SFuncColIds *pFuncColIds = pSma->funcColIds + j; + SFuncColIds *qFuncColIds = qSma->funcColIds + j; + EXPECT_EQ(pFuncColIds->funcId, qFuncColIds->funcId); + EXPECT_EQ(pFuncColIds->nColIds, qFuncColIds->nColIds); + for (uint32_t k = 0; k < pFuncColIds->nColIds; ++k) { + EXPECT_EQ(*(pFuncColIds->colIds + k), *(qFuncColIds->colIds + k)); + } } } @@ -100,9 +108,11 @@ TEST(testCase, tSmaEncodeDecodeTest) { } TEST(testCase, tSma_DB_Put_Get_Del_Test) { - const char *smaIndexName1 = "sma_index_test_1"; - const char *smaIndexName2 = "sma_index_test_2"; - const char *smaTestDir = "./smaTest"; + const char * smaIndexName1 = "sma_index_test_1"; + const char * smaIndexName2 = "sma_index_test_2"; + const char * timeZone = "Asia/Shanghai"; + const char * tagsFilter = "I'm tags filter"; + const char * smaTestDir = "./smaTest"; const uint64_t tbUid = 1234567890; const uint32_t nCntTSma = 2; // encode @@ -113,21 +123,27 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { tSma.slidingUnit = TD_TIME_UNIT_HOUR; tSma.sliding = 0; tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN); + tstrncpy(tSma.timezone, timeZone, TD_TIMEZONE_LEN); tSma.tableUid = tbUid; - tSma.numOfColIds = 2; - tSma.numOfFuncIds = 5; // sum/min/max/avg/last - tSma.colIds = (col_id_t *)calloc(tSma.numOfColIds, sizeof(col_id_t)); - tSma.funcIds = (uint16_t *)calloc(tSma.numOfFuncIds, sizeof(uint16_t)); - - for (int32_t i = 0; i < tSma.numOfColIds; ++i) { - *(tSma.colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); - } - for (int32_t i = 0; i < tSma.numOfFuncIds; ++i) { - *(tSma.funcIds + i) = (i + 2); + tSma.nFuncColIds = 5; + tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds)); + ASSERT(tSma.funcColIds != NULL); + for (int32_t n = 0; n < tSma.nFuncColIds; ++n) { + SFuncColIds *funcColIds = tSma.funcColIds + n; + funcColIds->funcId = n; + funcColIds->nColIds = 10; + funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t)); + ASSERT(funcColIds->colIds != NULL); + for (int32_t i = 0; i < funcColIds->nColIds; ++i) { + *(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID); + } } + tSma.tagsFilterLen = strlen(tagsFilter); + tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1); + tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1); SMeta * pMeta = NULL; - STSma * pSmaCfg = &tSma; + STSma * pSmaCfg = &tSma; const SMetaCfg *pMetaCfg = &defaultMetaOptions; taosRemoveDir(smaTestDir); @@ -152,6 +168,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1); assert(qSmaCfg != NULL); printf("name1 = %s\n", qSmaCfg->indexName); + printf("timezone1 = %s\n", qSmaCfg->timezone); + printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1); EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid); tdDestroyTSma(qSmaCfg); @@ -160,6 +178,8 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2); assert(qSmaCfg != NULL); printf("name2 = %s\n", qSmaCfg->indexName); + printf("timezone2 = %s\n", qSmaCfg->timezone); + printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : ""); EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2); EXPECT_EQ(qSmaCfg->interval, tSma.interval); tdDestroyTSma(qSmaCfg); @@ -170,7 +190,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { assert(pSmaCur != NULL); uint32_t indexCnt = 0; while (1) { - const char* indexName = metaSmaCursorNext(pSmaCur); + const char *indexName = metaSmaCursorNext(pSmaCur); if (indexName == NULL) { break; } @@ -185,10 +205,14 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { assert(pSW != NULL); EXPECT_EQ(pSW->number, nCntTSma); EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1); + EXPECT_STRCASEEQ(pSW->tSma->timezone, timeZone); + EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter); EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid); EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2); + EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timeZone); + EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter); EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid); - + tdDestroyTSmaWrapper(pSW); tfree(pSW); @@ -210,11 +234,11 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { metaClose(pMeta); } -#if 1 +#if 0 TEST(testCase, tSmaInsertTest) { - STSma tSma = {0}; - STSmaData* pSmaData = NULL; - STsdb tsdb = {0}; + STSma tSma = {0}; + STSmaData *pSmaData = NULL; + STsdb tsdb = {0}; // init tSma.intervalUnit = TD_TIME_UNIT_DAY; @@ -227,7 +251,7 @@ TEST(testCase, tSmaInsertTest) { int32_t dataLen = numOfColIds * numOfBlocks * blockSize; - pSmaData = (STSmaData*)malloc(sizeof(STSmaData) + dataLen); + pSmaData = (STSmaData *)malloc(sizeof(STSmaData) + dataLen); ASSERT_EQ(pSmaData != NULL, true); pSmaData->tableUid = 3232329230; pSmaData->numOfColIds = numOfColIds; @@ -235,7 +259,7 @@ TEST(testCase, tSmaInsertTest) { pSmaData->dataLen = dataLen; pSmaData->tsWindow.skey = 1640000000; pSmaData->tsWindow.ekey = 1645788649; - pSmaData->colIds = (col_id_t*)malloc(sizeof(col_id_t) * numOfColIds); + pSmaData->colIds = (col_id_t *)malloc(sizeof(col_id_t) * numOfColIds); ASSERT_EQ(pSmaData->colIds != NULL, true); for (int32_t i = 0; i < numOfColIds; ++i) { From 306dbdc0577afe113ebe9afc6f09867da5aff132 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Thu, 10 Mar 2022 16:03:55 +0800 Subject: [PATCH 16/23] [TD-13769]: modify sysinfo code. --- source/os/src/osSysinfo.c | 949 ++++++++++++++++++++------------------ 1 file changed, 504 insertions(+), 445 deletions(-) diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 02d7e6c0e9..b24a20d8c0 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -16,15 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" -bool taosCheckSystemIsSmallEnd() { - union check{ - int16_t i; - char ch[2]; - }c; - c.i=1; - return c.ch[0]==1; -} - #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) /* @@ -48,115 +39,6 @@ bool taosCheckSystemIsSmallEnd() { #include #pragma warning(pop) -int32_t taosGetTotalMemory(int64_t *totalKB) { - MEMORYSTATUSEX memsStat; - memsStat.dwLength = sizeof(memsStat); - if (!GlobalMemoryStatusEx(&memsStat)) { - return -1; - } - - *totalKB = memsStat.ullTotalPhys / 1024; - return 0; -} - -int32_t taosGetSysMemory(int64_t *usedKB) { - MEMORYSTATUSEX memsStat; - memsStat.dwLength = sizeof(memsStat); - if (!GlobalMemoryStatusEx(&memsStat)) { - return -1; - } - - int64_t nMemFree = memsStat.ullAvailPhys / 1024; - int64_t nMemTotal = memsStat.ullTotalPhys / 1024.0; - - *usedKB = nMemTotal - nMemFree; - return 0; -} - -int32_t taosGetProcMemory(int64_t *usedKB) { - unsigned bytes_used = 0; - -#if defined(_WIN64) && defined(_MSC_VER) - PROCESS_MEMORY_COUNTERS pmc; - HANDLE cur_proc = GetCurrentProcess(); - - if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) { - bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage); - } -#endif - - *usedKB = bytes_used / 1024; - return 0; -} - -int32_t taosGetCpuCores(float *numOfCores) { - SYSTEM_INFO info; - GetSystemInfo(&info); - *numOfCores = info.dwNumberOfProcessors; - return 0; -} - -int32_t taosGetCpuUsage(double *sysCpuUsage, double *procCpuUsage) { - *sysCpuUsage = 0; - *procCpuUsage = 0; - return 0; -} - -int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { - unsigned _int64 i64FreeBytesToCaller; - unsigned _int64 i64TotalBytes; - unsigned _int64 i64FreeBytes; - - BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, - (PULARGE_INTEGER)&i64FreeBytes); - if (fResult) { - diskSize->tsize = (int64_t)(i64TotalBytes); - diskSize->avail = (int64_t)(i64FreeBytesToCaller); - diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); - return 0; - } else { - // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } -} - -int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { - *receive_bytes = 0; - *transmit_bytes = 0; - return 0; -} - -int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { - IO_COUNTERS io_counter; - if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { - if (rchars) *rchars = io_counter.ReadTransferCount; - if (wchars) *wchars = io_counter.WriteTransferCount; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; - return 0; - } - return -1; -} - -void taosGetSystemInfo() { - taosGetCpuCores(&tsNumOfCores); - taosGetTotalMemory(&tsTotalMemoryKB); - - double tmp1, tmp2, tmp3, tmp4; - taosGetCpuUsage(&tmp1, &tmp2); -} - -void taosKillSystem() { - // printf("function taosKillSystem, exit!"); - exit(0); -} - -int taosSystem(const char *cmd) { - // printf("taosSystem not support"); - return -1; -} - LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile, IN MINIDUMP_TYPE DumpType, @@ -193,124 +75,13 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { return EXCEPTION_CONTINUE_SEARCH; } -void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); } - -int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { - GUID guid; - CoCreateGuid(&guid); - - sprintf(uid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], - guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); - - return 0; -} - -char *taosGetCmdlineByPID(int pid) { return ""; } - #elif defined(_TD_DARWIN_64) -/* - * darwin implementation - */ - #include #include -void taosKillSystem() { - // printf("function taosKillSystem, exit!"); - exit(0); -} - -int32_t taosGetCpuCores(float *numOfCores) { - *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); - return 0; -} - -void taosGetSystemInfo() { - long physical_pages = sysconf(_SC_PHYS_PAGES); - long page_size = sysconf(_SC_PAGESIZE); - tsTotalMemoryKB = physical_pages * page_size / 1024; - tsPageSizeKB = page_size / 1024; - tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN); -} - -int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { - if (rchars) *rchars = 0; - if (wchars) *wchars = 0; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; - return 0; -} - -int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { - *receive_bytes = 0; - *transmit_bytes = 0; - return 0; -} - -int32_t taosGetCpuUsage(double *sysCpuUsage, double *procCpuUsage) { - *sysCpuUsage = 0; - *procCpuUsage = 0; - return 0; -} - -int32_t taosGetProcMemory(int64_t *usedKB) { - *usedKB = 0; - return 0; -} - -int32_t taosGetSysMemory(int64_t *usedKB) { - *usedKB = 0; - return 0; -} - -int taosSystem(const char *cmd) { - // printf("un support funtion"); - return -1; -} - -void taosSetCoreDump() {} - -int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { - struct statvfs info; - if (statvfs(dataDir, &info)) { - // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } else { - diskSize->tsize = info.f_blocks * info.f_frsize; - diskSize->avail = info.f_bavail * info.f_frsize; - diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; - return 0; - } -} - -int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { - uuid_t uuid = {0}; - uuid_generate(uuid); - // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null - uuid_unparse_lower(uuid, uid); - return 0; -} - -char *taosGetCmdlineByPID(int pid) { - static char cmdline[1024]; - errno = 0; - - if (proc_pidpath(pid, cmdline, sizeof(cmdline)) <= 0) { - fprintf(stderr, "PID is %d, %s", pid, strerror(errno)); - return strerror(errno); - } - - return cmdline; -} - #else -/* - * linux implementation - */ - #include #include #include @@ -354,49 +125,6 @@ static void taosGetProcIOnfos() { snprintf(tsProcIOFile, sizeof(tsProcIOFile), "/proc/%d/io", tsProcId); } -int32_t taosGetTotalMemory(int64_t *totalKB) { - *totalKB = (int64_t)(sysconf(_SC_PHYS_PAGES) * tsPageSizeKB); - return 0; -} - -int32_t taosGetSysMemory(int64_t *usedKB) { - *usedKB = sysconf(_SC_AVPHYS_PAGES) * tsPageSizeKB; - return 0; -} - -int32_t taosGetProcMemory(int64_t *usedKB) { - TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM); - if (pFile == NULL) { - // printf("open file:%s failed", tsProcMemFile); - return -1; - } - - ssize_t _bytes = 0; - char *line = NULL; - while (!taosEOFFile(pFile)) { - _bytes = taosGetLineFile(pFile, &line); - if ((_bytes < 0) || (line == NULL)) { - break; - } - if (strstr(line, "VmRSS:") != NULL) { - break; - } - } - - if (line == NULL) { - // printf("read file:%s failed", tsProcMemFile); - taosCloseFile(&pFile); - return -1; - } - - char tmp[10]; - sscanf(line, "%s %" PRId64, tmp, usedKB); - - if (line != NULL) tfree(line); - taosCloseFile(&pFile); - return 0; -} - static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { @@ -450,12 +178,210 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { return 0; } +#endif + +bool taosCheckSystemIsSmallEnd() { + union check{ + int16_t i; + char ch[2]; + }c; + c.i=1; + return c.ch[0]==1; +} + +void taosGetSystemInfo() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + taosGetCpuCores(&tsNumOfCores); + taosGetTotalMemory(&tsTotalMemoryKB); + + double tmp1, tmp2, tmp3, tmp4; + taosGetCpuUsage(&tmp1, &tmp2); +#elif defined(_TD_DARWIN_64) + long physical_pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGESIZE); + tsTotalMemoryKB = physical_pages * page_size / 1024; + tsPageSizeKB = page_size / 1024; + tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN); +#else + taosGetProcIOnfos(); + taosGetCpuCores(&tsNumOfCores); + taosGetTotalMemory(&tsTotalMemoryKB); + + double tmp1, tmp2, tmp3, tmp4; + taosGetCpuUsage(&tmp1, &tmp2); +#endif +} + +int32_t taosGetEmail(char *email, int32_t maxLen) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#elif defined(_TD_DARWIN_64) + const char *filepath = "/usr/local/taos/email"; + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); + if (pFile == NULL) return false; + + if (taosReadFile(pFile, (void *)email, maxLen) < 0) { + taosCloseFile(&pFile); + return -1; + } + + taosCloseFile(&pFile); + return 0; +#else + const char *filepath = "/usr/local/taos/email"; + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); + if (pFile == NULL) return false; + + if (taosReadFile(pFile, (void *)email, maxLen) < 0) { + taosCloseFile(&pFile); + return -1; + } + + taosCloseFile(&pFile); + return 0; +#endif +} + +int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#elif defined(_TD_DARWIN_64) + char *line = NULL; + size_t size = 0; + int32_t code = -1; + + TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) return false; + + while ((size = taosGetLineFile(pFile, &line)) != -1) { + line[size - 1] = '\0'; + if (strncmp(line, "PRETTY_NAME", 11) == 0) { + const char *p = strchr(line, '=') + 1; + if (*p == '"') { + p++; + line[size - 2] = 0; + } + tstrncpy(releaseName, p, maxLen); + code = 0; + break; + } + } + + if (line != NULL) free(line); + taosCloseFile(&pFile); + return code; +#else + char *line = NULL; + size_t size = 0; + int32_t code = -1; + + TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) return false; + + while ((size = taosGetLineFile(pFile, &line)) != -1) { + line[size - 1] = '\0'; + if (strncmp(line, "PRETTY_NAME", 11) == 0) { + const char *p = strchr(line, '=') + 1; + if (*p == '"') { + p++; + line[size - 2] = 0; + } + tstrncpy(releaseName, p, maxLen); + code = 0; + break; + } + } + + if (line != NULL) free(line); + taosCloseFile(&pFile); + return code; +#endif +} + +int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#elif defined(_TD_DARWIN_64) + char *line = NULL; + size_t size = 0; + int32_t done = 0; + int32_t code = -1; + + TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) return false; + + while (done != 3 && (size = taosGetLineFile(pFile, &line)) != -1) { + line[size - 1] = '\0'; + if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) { + const char *v = strchr(line, ':') + 2; + tstrncpy(cpuModel, v, maxLen); + code = 0; + done |= 1; + } else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) { + const char *v = strchr(line, ':') + 2; + *numOfCores = atof(v); + done |= 2; + } + } + + if (line != NULL) free(line); + taosCloseFile(&pFile); + + return code; +#else + char *line = NULL; + size_t size = 0; + int32_t done = 0; + int32_t code = -1; + + TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) return false; + + while (done != 3 && (size = taosGetLineFile(pFile, &line)) != -1) { + line[size - 1] = '\0'; + if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) { + const char *v = strchr(line, ':') + 2; + tstrncpy(cpuModel, v, maxLen); + code = 0; + done |= 1; + } else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) { + const char *v = strchr(line, ':') + 2; + *numOfCores = atof(v); + done |= 2; + } + } + + if (line != NULL) free(line); + taosCloseFile(&pFile); + + return code; +#endif +} + int32_t taosGetCpuCores(float *numOfCores) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + SYSTEM_INFO info; + GetSystemInfo(&info); + *numOfCores = info.dwNumberOfProcessors; + return 0; +#elif defined(_TD_DARWIN_64) *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); return 0; +#else + *numOfCores = sysconf(_SC_NPROCESSORS_ONLN); + return 0; +#endif } int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + *sysCpuUsage = 0; + *procCpuUsage = 0; + return 0; +#elif defined(_TD_DARWIN_64) + *sysCpuUsage = 0; + *procCpuUsage = 0; + return 0; +#else static uint64_t lastSysUsed = 0; static uint64_t lastSysTotal = 0; static uint64_t lastProcTotal = 0; @@ -492,9 +418,132 @@ int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { lastProcTotal = curProcTotal; return 0; +#endif +} + +int32_t taosGetTotalMemory(int64_t *totalKB) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + MEMORYSTATUSEX memsStat; + memsStat.dwLength = sizeof(memsStat); + if (!GlobalMemoryStatusEx(&memsStat)) { + return -1; + } + + *totalKB = memsStat.ullTotalPhys / 1024; + return 0; +#elif defined(_TD_DARWIN_64) + return 0; +#else + *totalKB = (int64_t)(sysconf(_SC_PHYS_PAGES) * tsPageSizeKB); + return 0; +#endif +} + +int32_t taosGetProcMemory(int64_t *usedKB) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + unsigned bytes_used = 0; + +#if defined(_WIN64) && defined(_MSC_VER) + PROCESS_MEMORY_COUNTERS pmc; + HANDLE cur_proc = GetCurrentProcess(); + + if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) { + bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage); + } +#endif + + *usedKB = bytes_used / 1024; + return 0; +#elif defined(_TD_DARWIN_64) + *usedKB = 0; + return 0; +#else + TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) { + // printf("open file:%s failed", tsProcMemFile); + return -1; + } + + ssize_t _bytes = 0; + char *line = NULL; + while (!taosEOFFile(pFile)) { + _bytes = taosGetLineFile(pFile, &line); + if ((_bytes < 0) || (line == NULL)) { + break; + } + if (strstr(line, "VmRSS:") != NULL) { + break; + } + } + + if (line == NULL) { + // printf("read file:%s failed", tsProcMemFile); + taosCloseFile(&pFile); + return -1; + } + + char tmp[10]; + sscanf(line, "%s %" PRId64, tmp, usedKB); + + if (line != NULL) tfree(line); + taosCloseFile(&pFile); + return 0; +#endif +} + +int32_t taosGetSysMemory(int64_t *usedKB) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + MEMORYSTATUSEX memsStat; + memsStat.dwLength = sizeof(memsStat); + if (!GlobalMemoryStatusEx(&memsStat)) { + return -1; + } + + int64_t nMemFree = memsStat.ullAvailPhys / 1024; + int64_t nMemTotal = memsStat.ullTotalPhys / 1024.0; + + *usedKB = nMemTotal - nMemFree; + return 0; +#elif defined(_TD_DARWIN_64) + *usedKB = 0; + return 0; +#else + *usedKB = sysconf(_SC_AVPHYS_PAGES) * tsPageSizeKB; + return 0; +#endif } int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + unsigned _int64 i64FreeBytesToCaller; + unsigned _int64 i64TotalBytes; + unsigned _int64 i64FreeBytes; + + BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, + (PULARGE_INTEGER)&i64FreeBytes); + if (fResult) { + diskSize->tsize = (int64_t)(i64TotalBytes); + diskSize->avail = (int64_t)(i64FreeBytesToCaller); + diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); + return 0; + } else { + // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } +#elif defined(_TD_DARWIN_64) + struct statvfs info; + if (statvfs(dataDir, &info)) { + // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } else { + diskSize->tsize = info.f_blocks * info.f_frsize; + diskSize->avail = info.f_bavail * info.f_frsize; + diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize; + return 0; + } +#else struct statvfs info; if (statvfs(dataDir, &info)) { return -1; @@ -504,9 +553,79 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { diskSize->used = diskSize->total - diskSize->avail; return 0; } +#endif +} + +int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + IO_COUNTERS io_counter; + if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { + if (rchars) *rchars = io_counter.ReadTransferCount; + if (wchars) *wchars = io_counter.WriteTransferCount; + if (read_bytes) *read_bytes = 0; + if (write_bytes) *write_bytes = 0; + return 0; + } + return -1; +#elif defined(_TD_DARWIN_64) + if (rchars) *rchars = 0; + if (wchars) *wchars = 0; + if (read_bytes) *read_bytes = 0; + if (write_bytes) *write_bytes = 0; + return 0; +#else + TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) return -1; + + ssize_t _bytes = 0; + char *line = NULL; + char tmp[24]; + int readIndex = 0; + + while (!taosEOFFile(pFile)) { + _bytes = taosGetLineFile(pFile, &line); + if (_bytes < 10 || line == NULL) { + break; + } + if (strstr(line, "rchar:") != NULL) { + sscanf(line, "%s %" PRId64, tmp, rchars); + readIndex++; + } else if (strstr(line, "wchar:") != NULL) { + sscanf(line, "%s %" PRId64, tmp, wchars); + readIndex++; + } else if (strstr(line, "read_bytes:") != NULL) { // read_bytes + sscanf(line, "%s %" PRId64, tmp, read_bytes); + readIndex++; + } else if (strstr(line, "write_bytes:") != NULL) { // write_bytes + sscanf(line, "%s %" PRId64, tmp, write_bytes); + readIndex++; + } else { + } + + if (readIndex >= 4) break; + } + + if (line != NULL) tfree(line); + taosCloseFile(&pFile); + + if (readIndex < 4) { + return -1; + } + + return 0; +#endif } int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + *receive_bytes = 0; + *transmit_bytes = 0; + return 0; +#elif defined(_TD_DARWIN_64) + *receive_bytes = 0; + *transmit_bytes = 0; + return 0; +#else TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) return -1; @@ -549,66 +668,17 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { taosCloseFile(&pFile); return 0; -} - -int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { - TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM); - if (pFile == NULL) return -1; - - ssize_t _bytes = 0; - char *line = NULL; - char tmp[24]; - int readIndex = 0; - - while (!taosEOFFile(pFile)) { - _bytes = taosGetLineFile(pFile, &line); - if (_bytes < 10 || line == NULL) { - break; - } - if (strstr(line, "rchar:") != NULL) { - sscanf(line, "%s %" PRId64, tmp, rchars); - readIndex++; - } else if (strstr(line, "wchar:") != NULL) { - sscanf(line, "%s %" PRId64, tmp, wchars); - readIndex++; - } else if (strstr(line, "read_bytes:") != NULL) { // read_bytes - sscanf(line, "%s %" PRId64, tmp, read_bytes); - readIndex++; - } else if (strstr(line, "write_bytes:") != NULL) { // write_bytes - sscanf(line, "%s %" PRId64, tmp, write_bytes); - readIndex++; - } else { - } - - if (readIndex >= 4) break; - } - - if (line != NULL) tfree(line); - taosCloseFile(&pFile); - - if (readIndex < 4) { - return -1; - } - - return 0; -} - -void taosGetSystemInfo() { - taosGetProcIOnfos(); - taosGetCpuCores(&tsNumOfCores); - taosGetTotalMemory(&tsTotalMemoryKB); - - double tmp1, tmp2, tmp3, tmp4; - taosGetCpuUsage(&tmp1, &tmp2); -} - -void taosKillSystem() { - // SIGINT - // printf("taosd will shut down soon"); - kill(tsProcId, 2); +#endif } int taosSystem(const char *cmd) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + printf("taosSystem not support"); + return -1; +#elif defined(_TD_DARWIN_64) + printf("no support funtion"); + return -1; +#else FILE *fp; int res; char buf[1024]; @@ -633,9 +703,100 @@ int taosSystem(const char *cmd) { return res; } +#endif +} + +void taosKillSystem() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + printf("function taosKillSystem, exit!"); + exit(0); +#elif defined(_TD_DARWIN_64) + printf("function taosKillSystem, exit!"); + exit(0); +#else + // SIGINT + printf("taosd will shut down soon"); + kill(tsProcId, 2); +#endif +} + +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + GUID guid; + CoCreateGuid(&guid); + + sprintf(uid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], + guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + + return 0; +#elif defined(_TD_DARWIN_64) + uuid_t uuid = {0}; + uuid_generate(uuid); + // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null + uuid_unparse_lower(uuid, uid); + return 0; +#else + int len = 0; + + // fd = open("/proc/sys/kernel/random/uuid", 0); + TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ); + if (pFile == NULL) { + return -1; + } else { + len = taosReadFile(pFile, uid, uidlen); + taosCloseFile(&pFile); + } + + if (len >= 36) { + uid[36] = 0; + return 0; + } + + return 0; +#endif +} + +char *taosGetCmdlineByPID(int pid) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + return ""; +#elif defined(_TD_DARWIN_64) + static char cmdline[1024]; + errno = 0; + + if (proc_pidpath(pid, cmdline, sizeof(cmdline)) <= 0) { + fprintf(stderr, "PID is %d, %s", pid, strerror(errno)); + return strerror(errno); + } + + return cmdline; +#else + static char cmdline[1024]; + sprintf(cmdline, "/proc/%d/cmdline", pid); + + // int fd = open(cmdline, O_RDONLY); + TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ); + if (pFile != NULL) { + int n = taosReadFile(pFile, cmdline, sizeof(cmdline) - 1); + if (n < 0) n = 0; + + if (n > 0 && cmdline[n - 1] == '\n') --n; + + cmdline[n] = 0; + + taosCloseFile(&pFile); + } else { + cmdline[0] = 0; + } + + return cmdline; +#endif } void taosSetCoreDump(bool enable) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + SetUnhandledExceptionFilter(&FlCrashDump); +#elif defined(_TD_DARWIN_64) +#else if (!enable) return; // 1. set ulimit -c unlimited @@ -708,55 +869,12 @@ void taosSetCoreDump(bool enable) { // printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid); #endif -} - -int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { - int len = 0; - - // fd = open("/proc/sys/kernel/random/uuid", 0); - TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ); - if (pFile == NULL) { - return -1; - } else { - len = taosReadFile(pFile, uid, uidlen); - taosCloseFile(&pFile); - } - - if (len >= 36) { - uid[36] = 0; - return 0; - } - - return 0; -} - -char *taosGetCmdlineByPID(int pid) { - static char cmdline[1024]; - sprintf(cmdline, "/proc/%d/cmdline", pid); - - // int fd = open(cmdline, O_RDONLY); - TdFilePtr pFile = taosOpenFile(cmdline, TD_FILE_READ); - if (pFile != NULL) { - int n = taosReadFile(pFile, cmdline, sizeof(cmdline) - 1); - if (n < 0) n = 0; - - if (n > 0 && cmdline[n - 1] == '\n') --n; - - cmdline[n] = 0; - - taosCloseFile(&pFile); - } else { - cmdline[0] = 0; - } - - return cmdline; -} - #endif - -#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) +} SysNameInfo taosGetSysNameInfo() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#elif defined(_TD_DARWIN_64) SysNameInfo info = {0}; struct utsname uts; @@ -769,77 +887,18 @@ SysNameInfo taosGetSysNameInfo() { } return info; -} +#else + SysNameInfo info = {0}; -int32_t taosGetEmail(char *email, int32_t maxLen) { - const char *filepath = "/usr/local/taos/email"; - - TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); - if (pFile == NULL) return false; - - if (taosReadFile(pFile, (void *)email, maxLen) < 0) { - taosCloseFile(&pFile); - return -1; + struct utsname uts; + if (!uname(&uts)) { + tstrncpy(info.sysname, uts.sysname, sizeof(info.sysname)); + tstrncpy(info.nodename, uts.nodename, sizeof(info.nodename)); + tstrncpy(info.release, uts.release, sizeof(info.release)); + tstrncpy(info.version, uts.version, sizeof(info.version)); + tstrncpy(info.machine, uts.machine, sizeof(info.machine)); } - taosCloseFile(&pFile); - return 0; -} - -int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { - char *line = NULL; - size_t size = 0; - int32_t code = -1; - - TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); - if (pFile == NULL) return false; - - while ((size = taosGetLineFile(pFile, &line)) != -1) { - line[size - 1] = '\0'; - if (strncmp(line, "PRETTY_NAME", 11) == 0) { - const char *p = strchr(line, '=') + 1; - if (*p == '"') { - p++; - line[size - 2] = 0; - } - tstrncpy(releaseName, p, maxLen); - code = 0; - break; - } - } - - if (line != NULL) free(line); - taosCloseFile(&pFile); - return code; -} - -int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { - char *line = NULL; - size_t size = 0; - int32_t done = 0; - int32_t code = -1; - - TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM); - if (pFile == NULL) return false; - - while (done != 3 && (size = taosGetLineFile(pFile, &line)) != -1) { - line[size - 1] = '\0'; - if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) { - const char *v = strchr(line, ':') + 2; - tstrncpy(cpuModel, v, maxLen); - code = 0; - done |= 1; - } else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) { - const char *v = strchr(line, ':') + 2; - *numOfCores = atof(v); - done |= 2; - } - } - - if (line != NULL) free(line); - taosCloseFile(&pFile); - - return code; -} - + return info; #endif +} From 889d1339e598d8dd4cae3e5bd7a9410c6563157d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Thu, 10 Mar 2022 16:18:16 +0800 Subject: [PATCH 17/23] sync refactor --- source/libs/sync/inc/syncRaftEntry.h | 1 + source/libs/sync/src/syncRaftEntry.c | 6 ++++ source/libs/sync/src/syncRaftLog.c | 34 ++++++++++++---------- source/libs/sync/test/syncLogStoreTest.cpp | 33 +++++++++++++-------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index b607849dc8..be25675db4 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -47,6 +47,7 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len); cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); char* syncEntry2Str(const SSyncRaftEntry* pEntry); void syncEntryPrint(const SSyncRaftEntry* pEntry); +void syncEntryPrint2(char *s, const SSyncRaftEntry* pEntry); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 7774cbb0ce..959bf49ee7 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -108,4 +108,10 @@ void syncEntryPrint(const SSyncRaftEntry* pEntry) { char* s = syncEntry2Str(pEntry); sTrace("%s", s); free(s); +} + +void syncEntryPrint2(char* s, const SSyncRaftEntry* pEntry) { + char* ss = syncEntry2Str(pEntry); + sTrace("%s | %s", s, ss); + free(ss); } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index d8a460629b..d177d3ac9b 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -53,9 +53,11 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { char* serialized = syncEntrySerialize(pEntry, &len); assert(serialized != NULL); - walWrite(pWal, pEntry->index, pEntry->msgType, serialized, len); - walFsync(pWal, true); + int code; + code = walWrite(pWal, pEntry->index, pEntry->msgType, serialized, len); + assert(code == 0); + walFsync(pWal, true); free(serialized); } @@ -84,23 +86,20 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { // return index of last entry SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) { - /* - SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); - SyncIndex lastIndex = pLastEntry->index; - free(pLastEntry); - */ SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; - int64_t last = walGetLastVer(pWal); - SyncIndex lastIndex = last < 0 ? 0 : last; + SyncIndex lastIndex = walGetLastVer(pWal); return lastIndex; } // return term of last entry SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) { + SyncTerm lastTerm = 0; SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); - SyncTerm lastTerm = pLastEntry->term; - free(pLastEntry); + if (pLastEntry != NULL) { + lastTerm = pLastEntry->term; + free(pLastEntry); + } return lastTerm; } @@ -121,8 +120,11 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex lastIndex = walGetLastVer(pWal); - SSyncRaftEntry* pEntry; - pEntry = logStoreGetEntry(pLogStore, lastIndex); + + SSyncRaftEntry* pEntry = NULL; + if (lastIndex > 0) { + pEntry = logStoreGetEntry(pLogStore, lastIndex); + } return pEntry; } @@ -143,7 +145,7 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) { cJSON* pEntries = cJSON_CreateArray(); cJSON_AddItemToObject(pRoot, "pEntries", pEntries); SyncIndex lastIndex = logStoreLastIndex(pLogStore); - for (SyncIndex i = 1; i <= lastIndex; ++i) { + for (SyncIndex i = 0; i <= lastIndex; ++i) { SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); syncEntryDestory(pEntry); @@ -164,6 +166,8 @@ char* logStore2Str(SSyncLogStore* pLogStore) { // for debug void logStorePrint(SSyncLogStore* pLogStore) { char* s = logStore2Str(pLogStore); - sTrace("%s", s); + // sTrace("%s", s); + fprintf(stderr, "logStorePrint: [len:%lu]| %s \n", strlen(s), s); + free(s); } \ No newline at end of file diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index a859186bbe..a5eb748de6 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -35,16 +35,19 @@ SSyncNode* syncNodeInit() { syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); + 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 = 100000; - walCfg.segSize = 100000; - walCfg.level = TAOS_WAL_WRITE; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; pWal = walOpen("./wal_test", &walCfg); + assert(pWal != NULL); syncInfo.pWal = pWal; @@ -80,8 +83,20 @@ SSyncNode* syncInitTest() { return syncNodeInit(); } void logStoreTest() { logStorePrint(pSyncNode->pLogStore); for (int i = 0; i < 5; ++i) { - SSyncRaftEntry* pEntry; + int32_t dataLen = 10; + SSyncRaftEntry* pEntry = syncEntryBuild(dataLen); + assert(pEntry != NULL); + pEntry->msgType = 1; + pEntry->originalRpcType = 2; + pEntry->seqNum = 3; + pEntry->isWeak = true; + pEntry->term = 100; + pEntry->index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1; + snprintf(pEntry->data, dataLen, "value%d", i); + + //syncEntryPrint2((char*)"write entry:", pEntry); pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry); + syncEntryDestory(pEntry); } logStorePrint(pSyncNode->pLogStore); @@ -117,16 +132,10 @@ int main(int argc, char** argv) { pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodePrint((char*)"syncLogStoreTest", pSyncNode); - - initRaftId(pSyncNode); - - //-------------------------------------------------------------- + //syncNodePrint((char*)"syncLogStoreTest", pSyncNode); + //initRaftId(pSyncNode); logStoreTest(); - //-------------------------------------------------------------- - // walClose(pWal); - return 0; } From e766f3fad410502e40407dd1c552207867cc1ee5 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Thu, 10 Mar 2022 17:15:45 +0800 Subject: [PATCH 18/23] add mnode stream --- include/common/tmsg.h | 30 +- include/common/tmsgdef.h | 3 + include/dnode/mnode/sdb/sdb.h | 19 +- include/util/taoserror.h | 6 +- include/util/tdef.h | 1 + source/client/src/tmq.c | 6 +- source/common/src/tmsg.c | 50 ++- source/dnode/mnode/impl/inc/mndDef.h | 19 +- source/dnode/mnode/impl/inc/mndStream.h | 38 ++ source/dnode/mnode/impl/src/mndDef.c | 46 ++ source/dnode/mnode/impl/src/mndStream.c | 444 +++++++++++++++++++ source/dnode/mnode/impl/src/mndTopic.c | 50 +-- source/dnode/mnode/impl/test/topic/topic.cpp | 10 +- source/dnode/snode/inc/sndInt.h | 42 +- source/libs/wal/test/walMetaTest.cpp | 9 +- source/util/test/encodeTest.cpp | 10 +- 16 files changed, 702 insertions(+), 81 deletions(-) create mode 100644 source/dnode/mnode/impl/inc/mndStream.h create mode 100644 source/dnode/mnode/impl/src/mndDef.c create mode 100644 source/dnode/mnode/impl/src/mndStream.c diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 238753e5b7..a5c2c89b24 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1108,18 +1108,34 @@ typedef struct { char* sql; char* physicalPlan; char* logicalPlan; -} SMCreateTopicReq; +} SCMCreateStreamReq; -int32_t tSerializeMCreateTopicReq(void* buf, int32_t bufLen, const SMCreateTopicReq* pReq); -int32_t tDeserializeSMCreateTopicReq(void* buf, int32_t bufLen, SMCreateTopicReq* pReq); -void tFreeSMCreateTopicReq(SMCreateTopicReq* pReq); +typedef struct { + int64_t streamId; +} SCMCreateStreamRsp; + +int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq); +int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq); +void tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq); + +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + int8_t igExists; + char* sql; + char* physicalPlan; + char* logicalPlan; +} SCMCreateTopicReq; + +int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq); +int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq); +void tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq); typedef struct { int64_t topicId; -} SMCreateTopicRsp; +} SCMCreateTopicRsp; -int32_t tSerializeSMCreateTopicRsp(void* buf, int32_t bufLen, const SMCreateTopicRsp* pRsp); -int32_t tDeserializeSMCreateTopicRsp(void* buf, int32_t bufLen, SMCreateTopicRsp* pRsp); +int32_t tSerializeSCMCreateTopicRsp(void* buf, int32_t bufLen, const SCMCreateTopicRsp* pRsp); +int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicRsp* pRsp); typedef struct { int32_t topicNum; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 0f0c4729bc..6a27db89c6 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -148,6 +148,9 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg) TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "mnode-create-stream", SCMCreateStreamReq, SCMCreateStreamRsp) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STREAM, "mnode-alter-stream", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_STREAM, "mnode-drop-stream", NULL, NULL) // Requests handled by VNODE TD_NEW_MSG_SEG(TDMT_VND_MSG) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index bf48a8523c..d04e9f817e 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -113,15 +113,16 @@ typedef enum { SDB_USER = 7, SDB_AUTH = 8, SDB_ACCT = 9, - SDB_OFFSET = 10, - SDB_SUBSCRIBE = 11, - SDB_CONSUMER = 12, - SDB_TOPIC = 13, - SDB_VGROUP = 14, - SDB_STB = 15, - SDB_DB = 16, - SDB_FUNC = 17, - SDB_MAX = 18 + SDB_STREAM = 10, + SDB_OFFSET = 11, + SDB_SUBSCRIBE = 12, + SDB_CONSUMER = 13, + SDB_TOPIC = 14, + SDB_VGROUP = 15, + SDB_STB = 16, + SDB_DB = 17, + SDB_FUNC = 18, + SDB_MAX = 19 } ESdbType; typedef struct SSdb SSdb; diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 6ad34eb0c0..56ad1eea3b 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -267,9 +267,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_UNSUPPORTED_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E8) #define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9) #define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03EA) -#define TSDB_CODE_MND_MQ_PLACEHOLDER TAOS_DEF_ERROR_CODE(0, 0x03F0) - +// mnode-stream +#define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0) +#define TSDB_CODE_MND_STREAM_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F1) +#define TSDB_CODE_MND_INVALID_STREAM_OPTION TAOS_DEF_ERROR_CODE(0, 0x03F2) // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) diff --git a/include/util/tdef.h b/include/util/tdef.h index 664588f68f..ed88fa5535 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -211,6 +211,7 @@ typedef enum ELogicConditionType { #define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN +#define TSDB_STREAM_FNAME_LEN TSDB_TABLE_FNAME_LEN #define TSDB_SUBSCRIBE_KEY_LEN (TSDB_CGROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2) #define TSDB_PARTITION_KEY_LEN (TSDB_SUBSCRIBE_KEY_LEN + 20) #define TSDB_COL_NAME_LEN 65 diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 60103cc9c5..197f2e37c5 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -511,7 +511,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB); tNameFromString(&name, topicName, T_NAME_TABLE); - SMCreateTopicReq req = { + SCMCreateTopicReq req = { .igExists = 1, .physicalPlan = (char*)pStr, .sql = (char*)sql, @@ -519,13 +519,13 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i }; tNameExtractFullName(&name, req.name); - int tlen = tSerializeMCreateTopicReq(NULL, 0, &req); + int tlen = tSerializeSCMCreateTopicReq(NULL, 0, &req); void* buf = malloc(tlen); if (buf == NULL) { goto _return; } - tSerializeMCreateTopicReq(buf, tlen, &req); + tSerializeSCMCreateTopicReq(buf, tlen, &req); /*printf("formatted: %s\n", dagStr);*/ pRequest->body.requestMsg = (SDataBuf){.pData = buf, .len = tlen, .handle = NULL}; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 97b19c1c79..135ff34207 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1899,7 +1899,7 @@ int32_t tDeserializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pR return 0; } -int32_t tSerializeMCreateTopicReq(void *buf, int32_t bufLen, const SMCreateTopicReq *pReq) { +int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTopicReq *pReq) { int32_t sqlLen = 0; int32_t physicalPlanLen = 0; int32_t logicalPlanLen = 0; @@ -1927,7 +1927,7 @@ int32_t tSerializeMCreateTopicReq(void *buf, int32_t bufLen, const SMCreateTopic return tlen; } -int32_t tDeserializeSMCreateTopicReq(void *buf, int32_t bufLen, SMCreateTopicReq *pReq) { +int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicReq *pReq) { int32_t sqlLen = 0; int32_t physicalPlanLen = 0; int32_t logicalPlanLen = 0; @@ -1956,13 +1956,13 @@ int32_t tDeserializeSMCreateTopicReq(void *buf, int32_t bufLen, SMCreateTopicReq return 0; } -void tFreeSMCreateTopicReq(SMCreateTopicReq *pReq) { +void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) { tfree(pReq->sql); tfree(pReq->physicalPlan); tfree(pReq->logicalPlan); } -int32_t tSerializeSMCreateTopicRsp(void *buf, int32_t bufLen, const SMCreateTopicRsp *pRsp) { +int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -1975,7 +1975,7 @@ int32_t tSerializeSMCreateTopicRsp(void *buf, int32_t bufLen, const SMCreateTopi return tlen; } -int32_t tDeserializeSMCreateTopicRsp(void *buf, int32_t bufLen, SMCreateTopicRsp *pRsp) { +int32_t tDeserializeSCMCreateTopicRsp(void *buf, int32_t bufLen, SCMCreateTopicRsp *pRsp) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2423,3 +2423,43 @@ void *tDeserializeSVDropTSmaReq(void *buf, SVDropTSmaReq *pReq) { return buf; } + +int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateStreamReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igExists) < 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; + + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStreamReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + 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; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { + tfree(pReq->sql); + tfree(pReq->physicalPlan); + tfree(pReq->logicalPlan); +} diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index a36168b622..490a63333f 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -84,6 +84,7 @@ typedef enum { TRN_TYPE_SUBSCRIBE = 1016, TRN_TYPE_REBALANCE = 1017, TRN_TYPE_COMMIT_OFFSET = 1018, + TRN_TYPE_CREATE_STREAM = 1019, TRN_TYPE_BASIC_SCOPE_END, TRN_TYPE_GLOBAL_SCOPE = 2000, TRN_TYPE_CREATE_DNODE = 2001, @@ -662,7 +663,23 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons } typedef struct { -} SStreamScheduler; + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createTime; + int64_t updateTime; + int64_t uid; + int64_t dbUid; + int32_t version; + SRWLatch lock; + int8_t status; + // int32_t sqlLen; + char* sql; + char* logicalPlan; + char* physicalPlan; +} SStreamObj; + +int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj); +int32_t tDecodeSStreamObj(SCoder* pDecoder, SStreamObj* pObj); typedef struct SMnodeMsg { char user[TSDB_USER_LEN]; diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h new file mode 100644 index 0000000000..b1145b0c6b --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -0,0 +1,38 @@ +/* + * 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 . + */ + +#ifndef _TD_MND_STREAM_H_ +#define _TD_MND_STREAM_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitStream(SMnode *pMnode); +void mndCleanupStream(SMnode *pMnode); + +SStreamObj *mndAcquireStream(SMnode *pMnode, char *streamName); +void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream); + +SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); +SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_STREAM_H_*/ diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c new file mode 100644 index 0000000000..6e8d9aa79f --- /dev/null +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -0,0 +1,46 @@ +/* + * 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 "mndDef.h" + +int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { + if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->updateTime) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->uid) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->dbUid) < 0) return -1; + if (tEncodeI32(pEncoder, pObj->version) < 0) return -1; + if (tEncodeI8(pEncoder, pObj->status) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->physicalPlan) < 0) return -1; + return pEncoder->pos; +} + +int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { + if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pObj->db) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->updateTime) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->uid) < 0) return -1; + 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; + return 0; +} diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c new file mode 100644 index 0000000000..54ad9cd7e2 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -0,0 +1,444 @@ +/* + * 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 "mndStream.h" +#include "mndAuth.h" +#include "mndDb.h" +#include "mndDnode.h" +#include "mndMnode.h" +#include "mndShow.h" +#include "mndStb.h" +#include "mndTrans.h" +#include "mndUser.h" +#include "mndVgroup.h" +#include "tname.h" + +#define MND_STREAM_VER_NUMBER 1 +#define MND_STREAM_RESERVE_SIZE 64 + +static int32_t mndStreamActionInsert(SSdb *pSdb, SStreamObj *pStream); +static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream); +static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pStream, SStreamObj *pNewStream); +static int32_t mndProcessCreateStreamReq(SMnodeMsg *pReq); +/*static int32_t mndProcessDropStreamReq(SMnodeMsg *pReq);*/ +/*static int32_t mndProcessDropStreamInRsp(SMnodeMsg *pRsp);*/ +static int32_t mndProcessStreamMetaReq(SMnodeMsg *pReq); +static int32_t mndGetStreamMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); +static int32_t mndRetrieveStream(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextStream(SMnode *pMnode, void *pIter); + +int32_t mndInitStream(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_STREAM, + .keyType = SDB_KEY_BINARY, + .encodeFp = (SdbEncodeFp)mndStreamActionEncode, + .decodeFp = (SdbDecodeFp)mndStreamActionDecode, + .insertFp = (SdbInsertFp)mndStreamActionInsert, + .updateFp = (SdbUpdateFp)mndStreamActionUpdate, + .deleteFp = (SdbDeleteFp)mndStreamActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STREAM, mndProcessCreateStreamReq); + /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ + /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ + + mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_TP, mndGetStreamMeta); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveStream); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextStream); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupStream(SMnode *pMnode) {} + +SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + void *buf = NULL; + + SCoder encoder; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); + if (tEncodeSStreamObj(NULL, pStream) < 0) { + tCoderClear(&encoder); + goto STREAM_ENCODE_OVER; + } + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + + int32_t size = sizeof(int32_t) + tlen + MND_STREAM_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_STREAM, MND_STREAM_VER_NUMBER, size); + if (pRaw == NULL) goto STREAM_ENCODE_OVER; + + buf = malloc(tlen); + if (buf == NULL) goto STREAM_ENCODE_OVER; + + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, tlen, TD_ENCODER); + if (tEncodeSStreamObj(NULL, pStream) < 0) { + tCoderClear(&encoder); + goto STREAM_ENCODE_OVER; + } + tCoderClear(&encoder); + + int32_t dataPos = 0; + SDB_SET_INT32(pRaw, dataPos, tlen, STREAM_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, buf, tlen, STREAM_ENCODE_OVER); + SDB_SET_DATALEN(pRaw, dataPos, STREAM_ENCODE_OVER); + + terrno = TSDB_CODE_SUCCESS; + +STREAM_ENCODE_OVER: + tfree(buf); + if (terrno != TSDB_CODE_SUCCESS) { + mError("stream:%s, failed to encode to raw:%p since %s", pStream->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("stream:%s, encode to raw:%p, row:%p", pStream->name, pRaw, pStream); + return pRaw; +} + +SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + void *buf = NULL; + + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto STREAM_DECODE_OVER; + + if (sver != MND_STREAM_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + goto STREAM_DECODE_OVER; + } + + int32_t size = sizeof(SStreamObj); + SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto STREAM_DECODE_OVER; + + SStreamObj *pStream = sdbGetRowObj(pRow); + if (pStream == NULL) goto STREAM_DECODE_OVER; + + int32_t tlen; + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, dataPos, &tlen, STREAM_DECODE_OVER); + buf = malloc(tlen + 1); + if (buf == NULL) goto STREAM_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, buf, tlen, STREAM_DECODE_OVER); + + SCoder decoder; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, NULL, 0, TD_DECODER); + if (tDecodeSStreamObj(&decoder, pStream) < 0) { + goto STREAM_DECODE_OVER; + } + + terrno = TSDB_CODE_SUCCESS; + +STREAM_DECODE_OVER: + tfree(buf); + if (terrno != TSDB_CODE_SUCCESS) { + mError("stream:%s, failed to decode from raw:%p since %s", pStream->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("stream:%s, decode from raw:%p, row:%p", pStream->name, pRaw, pStream); + return pRow; +} + +static int32_t mndStreamActionInsert(SSdb *pSdb, SStreamObj *pStream) { + mTrace("stream:%s, perform insert action", pStream->name); + return 0; +} + +static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream) { + mTrace("stream:%s, perform delete action", pStream->name); + return 0; +} + +static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pOldStream, SStreamObj *pNewStream) { + mTrace("stream:%s, perform update action", pOldStream->name); + atomic_exchange_32(&pOldStream->updateTime, pNewStream->updateTime); + atomic_exchange_32(&pOldStream->version, pNewStream->version); + + taosWLockLatch(&pOldStream->lock); + + // TODO handle update + + taosWUnLockLatch(&pOldStream->lock); + return 0; +} + +SStreamObj *mndAcquireStream(SMnode *pMnode, char *streamName) { + SSdb *pSdb = pMnode->pSdb; + SStreamObj *pStream = sdbAcquire(pSdb, SDB_STREAM, streamName); + if (pStream == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { + terrno = TSDB_CODE_MND_STREAM_NOT_EXIST; + } + return pStream; +} + +void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pStream); +} + +static SDbObj *mndAcquireDbByStream(SMnode *pMnode, char *streamName) { + SName name = {0}; + tNameFromString(&name, streamName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + + char db[TSDB_STREAM_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, db); + + return mndAcquireDb(pMnode, db); +} + +static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { + if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0) { + terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION; + return -1; + } + return 0; +} + +static int32_t mndCreateStream(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateStreamReq *pCreate, SDbObj *pDb) { + mDebug("stream:%s to create", pCreate->name); + SStreamObj streamObj = {0}; + tstrncpy(streamObj.name, pCreate->name, TSDB_STREAM_FNAME_LEN); + tstrncpy(streamObj.db, pDb->name, TSDB_DB_FNAME_LEN); + streamObj.createTime = taosGetTimestampMs(); + streamObj.updateTime = streamObj.createTime; + streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); + streamObj.dbUid = pDb->uid; + streamObj.version = 1; + streamObj.sql = pCreate->sql; + streamObj.physicalPlan = pCreate->physicalPlan; + streamObj.logicalPlan = pCreate->logicalPlan; + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); + if (pTrans == NULL) { + mError("stream:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); + + SSdbRaw *pRedoRaw = mndStreamActionEncode(&streamObj); + if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +} + +static int32_t mndProcessCreateStreamReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + int32_t code = -1; + SStreamObj *pStream = NULL; + SDbObj *pDb = NULL; + SUserObj *pUser = NULL; + SCMCreateStreamReq createStreamReq = {0}; + + if (tDeserializeSCMCreateStreamReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createStreamReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto CREATE_STREAM_OVER; + } + + mDebug("stream:%s, start to create, sql:%s", createStreamReq.name, createStreamReq.sql); + + if (mndCheckCreateStreamReq(&createStreamReq) != 0) { + mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); + goto CREATE_STREAM_OVER; + } + + pStream = mndAcquireStream(pMnode, createStreamReq.name); + if (pStream != NULL) { + if (createStreamReq.igExists) { + mDebug("stream:%s, already exist, ignore exist is set", createStreamReq.name); + code = 0; + goto CREATE_STREAM_OVER; + } else { + terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST; + goto CREATE_STREAM_OVER; + } + } else if (terrno != TSDB_CODE_MND_STREAM_NOT_EXIST) { + goto CREATE_STREAM_OVER; + } + + pDb = mndAcquireDbByStream(pMnode, createStreamReq.name); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + goto CREATE_STREAM_OVER; + } + + pUser = mndAcquireUser(pMnode, pReq->user); + if (pUser == NULL) { + goto CREATE_STREAM_OVER; + } + + if (mndCheckWriteAuth(pUser, pDb) != 0) { + goto CREATE_STREAM_OVER; + } + + code = mndCreateStream(pMnode, pReq, &createStreamReq, pDb); + if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + +CREATE_STREAM_OVER: + if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); + } + + mndReleaseStream(pMnode, pStream); + mndReleaseDb(pMnode, pDb); + mndReleaseUser(pMnode, pUser); + + tFreeSCMCreateStreamReq(&createStreamReq); + return code; +} + +static int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) { + SSdb *pSdb = pMnode->pSdb; + SDbObj *pDb = mndAcquireDb(pMnode, dbName); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + return -1; + } + + int32_t numOfStreams = 0; + void *pIter = NULL; + while (1) { + SStreamObj *pStream = NULL; + pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream); + if (pIter == NULL) break; + + if (pStream->dbUid == pDb->uid) { + numOfStreams++; + } + + sdbRelease(pSdb, pStream); + } + + *pNumOfStreams = numOfStreams; + mndReleaseDb(pMnode, pDb); + return 0; +} + +static int32_t mndGetStreamMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { + SMnode *pMnode = pReq->pMnode; + SSdb *pSdb = pMnode->pSdb; + + if (mndGetNumOfStreams(pMnode, pShow->db, &pShow->numOfRows) != 0) { + return -1; + } + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchemas; + + pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "name"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sql"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pMeta->numOfColumns = cols; + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = sdbGetSize(pSdb, SDB_STREAM); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbName, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveStream(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + SStreamObj *pStream = NULL; + int32_t cols = 0; + char *pWrite; + char prefix[TSDB_DB_FNAME_LEN] = {0}; + + SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); + if (pDb == NULL) return 0; + + tstrncpy(prefix, pShow->db, TSDB_DB_FNAME_LEN); + strcat(prefix, TS_PATH_DELIMITER); + int32_t prefixLen = (int32_t)strlen(prefix); + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_STREAM, pShow->pIter, (void **)&pStream); + if (pShow->pIter == NULL) break; + + if (pStream->dbUid != pDb->uid) { + if (strncmp(pStream->name, prefix, prefixLen) != 0) { + mError("Inconsistent stream data, name:%s, db:%s, dbUid:%" PRIu64, pStream->name, pDb->name, pDb->uid); + } + + sdbRelease(pSdb, pStream); + continue; + } + + cols = 0; + + char streamName[TSDB_TABLE_NAME_LEN] = {0}; + tstrncpy(streamName, pStream->name + prefixLen, TSDB_TABLE_NAME_LEN); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, streamName); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pStream->createTime; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pStream->sql, pShow->bytes[cols]); + cols++; + + numOfRows++; + sdbRelease(pSdb, pStream); + } + + mndReleaseDb(pMnode, pDb); + pShow->numOfReads += numOfRows; + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + return numOfRows; +} + +static void mndCancelGetNextStream(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 9822550ee5..7d7c5f9975 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#define _DEFAULT_SOURCE #include "mndTopic.h" #include "mndAuth.h" #include "mndDb.h" @@ -229,7 +228,7 @@ static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMq return pDrop; } -static int32_t mndCheckCreateTopicReq(SMCreateTopicReq *pCreate) { +static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0) { terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; return -1; @@ -237,7 +236,7 @@ static int32_t mndCheckCreateTopicReq(SMCreateTopicReq *pCreate) { return 0; } -static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SMCreateTopicReq *pCreate, SDbObj *pDb) { +static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) { mDebug("topic:%s to create", pCreate->name); SMqTopicObj topicObj = {0}; tstrncpy(topicObj.name, pCreate->name, TSDB_TOPIC_FNAME_LEN); @@ -278,14 +277,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SMCreateTopicReq } static int32_t mndProcessCreateTopicReq(SMnodeMsg *pReq) { - SMnode *pMnode = pReq->pMnode; - int32_t code = -1; - SMqTopicObj *pTopic = NULL; - SDbObj *pDb = NULL; - SUserObj *pUser = NULL; - SMCreateTopicReq createTopicReq = {0}; + SMnode *pMnode = pReq->pMnode; + int32_t code = -1; + SMqTopicObj *pTopic = NULL; + SDbObj *pDb = NULL; + SUserObj *pUser = NULL; + SCMCreateTopicReq createTopicReq = {0}; - if (tDeserializeSMCreateTopicReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createTopicReq) != 0) { + if (tDeserializeSCMCreateTopicReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createTopicReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; goto CREATE_TOPIC_OVER; } @@ -338,7 +337,7 @@ CREATE_TOPIC_OVER: mndReleaseDb(pMnode, pDb); mndReleaseUser(pMnode, pUser); - tFreeSMCreateTopicReq(&createTopicReq); + tFreeSCMCreateTopicReq(&createTopicReq); return code; } @@ -409,35 +408,6 @@ static int32_t mndProcessDropTopicInRsp(SMnodeMsg *pRsp) { return 0; } -#if 0 -static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTopics) { - SSdb *pSdb = pMnode->pSdb; - SDbObj *pDb = mndAcquireDb(pMnode, dbName); - if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; - } - - int32_t numOfTopics = 0; - void *pIter = NULL; - while (1) { - SMqTopicObj *pTopic = NULL; - pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic); - if (pIter == NULL) break; - - if (pTopic->dbUid == pDb->uid) { - numOfTopics++; - } - - sdbRelease(pSdb, pTopic); - } - - *pNumOfTopics = numOfTopics; - mndReleaseDb(pMnode, pDb); - return 0; -} -#endif - static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTopics) { SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = mndAcquireDb(pMnode, dbName); diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 8a4e17d054..f58d0a6771 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -61,16 +61,16 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { } void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql, int32_t* pContLen) { - SMCreateTopicReq createReq = {0}; + SCMCreateTopicReq createReq = {0}; strcpy(createReq.name, topicName); createReq.igExists = 0; createReq.sql = (char*)sql; createReq.physicalPlan = (char*)"physicalPlan"; createReq.logicalPlan = (char*)"logicalPlan"; - int32_t contLen = tSerializeMCreateTopicReq(NULL, 0, &createReq); + int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); void* pReq = rpcMallocCont(contLen); - tSerializeMCreateTopicReq(pReq, contLen, &createReq); + tSerializeSCMCreateTopicReq(pReq, contLen, &createReq); *pContLen = contLen; return pReq; @@ -100,9 +100,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { ASSERT_EQ(pRsp->code, 0); } - { - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, ""); - } + { test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, ""); } { int32_t contLen = 0; diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index aff82e4ae7..5851e18478 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -20,6 +20,7 @@ #include "tlog.h" #include "tmsg.h" +#include "tqueue.h" #include "trpc.h" #include "snode.h" @@ -28,12 +29,51 @@ extern "C" { #endif +enum { + STREAM_STATUS__READY = 1, + STREAM_STATUS__STOPPED, + STREAM_STATUS__CREATING, + STREAM_STATUS__STOPING, + STREAM_STATUS__RESUMING, + STREAM_STATUS__DELETING, +}; + +enum { + STREAM_RUNNER__RUNNING = 1, + STREAM_RUNNER__STOP, +}; + typedef struct SSnode { SSnodeOpt cfg; } SSnode; +typedef struct { + int64_t streamId; + int32_t IdxInLevel; + int32_t level; +} SStreamInfo; + +typedef struct { + SStreamInfo meta; + int8_t status; + void* executor; + STaosQueue* queue; + void* stateStore; + // storage handle +} SStreamRunner; + +typedef struct { + SHashObj* pHash; +} SStreamMeta; + +int32_t sndCreateStream(); +int32_t sndDropStream(); + +int32_t sndStopStream(); +int32_t sndResumeStream(); + #ifdef __cplusplus } #endif -#endif /*_TD_SNODE_INT_H_*/ \ No newline at end of file +#endif /*_TD_SNODE_INT_H_*/ diff --git a/source/libs/wal/test/walMetaTest.cpp b/source/libs/wal/test/walMetaTest.cpp index 5bfea9ab5e..3908c97175 100644 --- a/source/libs/wal/test/walMetaTest.cpp +++ b/source/libs/wal/test/walMetaTest.cpp @@ -124,8 +124,13 @@ class WalRetentionEnv : public ::testing::Test { void SetUp() override { SWalCfg cfg; - cfg.rollPeriod = -1, cfg.segSize = -1, cfg.retentionPeriod = -1, cfg.retentionSize = 0, cfg.rollPeriod = 0, - cfg.vgId = 0, cfg.level = TAOS_WAL_FSYNC; + cfg.rollPeriod = -1; + cfg.segSize = -1; + cfg.retentionPeriod = -1; + cfg.retentionSize = 0; + cfg.rollPeriod = 0; + cfg.vgId = 0; + cfg.level = TAOS_WAL_FSYNC; pWal = walOpen(pathName, &cfg); ASSERT(pWal != NULL); } diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 46c95556d4..25314842fb 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -174,8 +174,8 @@ TEST(td_encode_test, encode_decode_variant_len_integer) { } TEST(td_encode_test, encode_decode_cstr) { - uint8_t * buf = new uint8_t[1024 * 1024]; - char * cstr = new char[1024 * 1024]; + uint8_t *buf = new uint8_t[1024 * 1024]; + char *cstr = new char[1024 * 1024]; const char *dcstr; SCoder encoder; SCoder decoder; @@ -208,7 +208,7 @@ TEST(td_encode_test, encode_decode_cstr) { typedef struct { int32_t A_a; int64_t A_b; - char * A_c; + char *A_c; } SStructA_v1; static int32_t tSStructA_v1_encode(SCoder *pCoder, const SStructA_v1 *pSAV1) { @@ -240,7 +240,7 @@ static int32_t tSStructA_v1_decode(SCoder *pCoder, SStructA_v1 *pSAV1) { typedef struct { int32_t A_a; int64_t A_b; - char * A_c; + char *A_c; // -------------------BELOW FEILDS ARE ADDED IN A NEW VERSION-------------- int16_t A_d; int16_t A_e; @@ -437,4 +437,4 @@ TEST(td_encode_test, compound_struct_encode_test) { tCoderClear(&decoder); } #endif -#pragma GCC diagnostic pop \ No newline at end of file +#pragma GCC diagnostic pop From 6b6c43646d27314abeabcb0f5f3a4800327346b1 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Thu, 10 Mar 2022 18:06:20 +0800 Subject: [PATCH 19/23] [TD-13770]: redefine system api. --- include/os/osSysinfo.h | 1 - include/os/osSystem.h | 12 ++ source/os/src/osSysinfo.c | 35 ---- source/os/src/osSystem.c | 279 +++++++++++++++++++++------ tools/shell/inc/shell.h | 4 - tools/shell/src/backup/shellDarwin.c | 60 +----- tools/shell/src/backup/shellImport.c | 15 +- tools/shell/src/shellLinux.c | 60 +----- tools/shell/src/shellMain.c | 4 +- 9 files changed, 247 insertions(+), 223 deletions(-) diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 54a3cfef7b..aec63f3322 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -47,7 +47,6 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes); -int32_t taosSystem(const char *cmd); void taosKillSystem(); int32_t taosGetSystemUUID(char *uid, int32_t uidlen); char *taosGetCmdlineByPID(int32_t pid); diff --git a/include/os/osSystem.h b/include/os/osSystem.h index 8554c4ad12..f130e9d8f1 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.h @@ -20,11 +20,23 @@ extern "C" { #endif +// If the error is in a third-party library, place this header file under the third-party library header file. +#ifndef ALLOW_FORBID_FUNC + #define popen POPEN_FUNC_TAOS_FORBID + #define pclose PCLOSE_FUNC_TAOS_FORBID + #define tcsetattr TCSETATTR_FUNC_TAOS_FORBID + #define tcgetattr TCGETATTR_FUNC_TAOS_FORBID +#endif + +int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize); void* taosLoadDll(const char* filename); void* taosLoadSym(void* handle, char* name); void taosCloseDll(void* handle); int32_t taosSetConsoleEcho(bool on); +void setTerminalMode(); +int32_t getOldTerminalMode(); +void resetTerminalMode(); #ifdef __cplusplus } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index b24a20d8c0..25c748a8d8 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -671,41 +671,6 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { #endif } -int taosSystem(const char *cmd) { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) - printf("taosSystem not support"); - return -1; -#elif defined(_TD_DARWIN_64) - printf("no support funtion"); - return -1; -#else - FILE *fp; - int res; - char buf[1024]; - if (cmd == NULL) { - // printf("taosSystem cmd is NULL!"); - return -1; - } - - if ((fp = popen(cmd, "r")) == NULL) { - // printf("popen cmd:%s error: %s", cmd, strerror(errno)); - return -1; - } else { - while (fgets(buf, sizeof(buf), fp)) { - // printf("popen result:%s", buf); - } - - if ((res = pclose(fp)) == -1) { - // printf("close popen file pointer fp error!"); - } else { - // printf("popen res is :%d", res); - } - - return res; - } -#endif -} - void taosKillSystem() { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) printf("function taosKillSystem, exit!"); diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index 717cae0fbd..5c98db33d1 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -13,20 +13,126 @@ * along with this program. If not, see . */ +#define ALLOW_FORBID_FUNC #define _DEFAULT_SOURCE #include "os.h" #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) +#elif defined(_TD_DARWIN_64) +#else +#include +#include +#include +#endif -/* - * windows implementation - */ +struct termios oldtio; -void* taosLoadDll(const char* filename) { return NULL; } -void* taosLoadSym(void* handle, char* name) { return NULL; } -void taosCloseDll(void* handle) {} +int32_t taosSystem(const char *cmd, char *buf, int32_t bufSize) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + FILE *fp; + if (cmd == NULL) { + // printf("taosSystem cmd is NULL!"); + return -1; + } + + if ((fp = _popen(cmd, "r")) == NULL) { + // printf("popen cmd:%s error: %s", cmd, strerror(errno)); + return -1; + } else { + while (fgets(buf, bufSize, fp)) { + // printf("popen result:%s", buf); + } + + if (!_pclose(fp)) { + // printf("close popen file pointer fp error!"); + return -1; + } else { + // printf("popen res is :%d", res); + } + + return 0; +#elif defined(_TD_DARWIN_64) + printf("no support funtion"); + return -1; +#else + FILE *fp; + int32_t res; + if (cmd == NULL) { + // printf("taosSystem cmd is NULL!"); + return -1; + } + + if ((fp = popen(cmd, "r")) == NULL) { + // printf("popen cmd:%s error: %s", cmd, strerror(errno)); + return -1; + } else { + while (fgets(buf, bufSize, fp)) { + // printf("popen result:%s", buf); + } + + if ((res = pclose(fp)) == -1) { + // printf("close popen file pointer fp error!"); + } else { + // printf("popen res is :%d", res); + } + + return res; + } +#endif +} + +void* taosLoadDll(const char* filename) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + return NULL; +#elif defined(_TD_DARWIN_64) + return NULL; +#else + void* handle = dlopen(filename, RTLD_LAZY); + if (!handle) { + //printf("load dll:%s failed, error:%s", filename, dlerror()); + return NULL; + } + + //printf("dll %s loaded", filename); + + return handle; +#endif +} + +void* taosLoadSym(void* handle, char* name) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + return NULL; +#elif defined(_TD_DARWIN_64) + return NULL; +#else + void* sym = dlsym(handle, name); + char* error = NULL; + + if ((error = dlerror()) != NULL) { + //printf("load sym:%s failed, error:%s", name, dlerror()); + return NULL; + } + + //printf("sym %s loaded", name); + + return sym; +#endif +} + +void taosCloseDll(void* handle) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + return; +#elif defined(_TD_DARWIN_64) + return; +#else + if (handle) { + dlclose(handle); + } +#endif +} int taosSetConsoleEcho(bool on) { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); DWORD mode = 0; GetConsoleMode(hStdin, &mode); @@ -38,19 +144,7 @@ int taosSetConsoleEcho(bool on) { SetConsoleMode(hStdin, mode); return 0; -} - #elif defined(_TD_DARWIN_64) - -/* - * darwin implementation - */ - -void* taosLoadDll(const char* filename) { return NULL; } -void* taosLoadSym(void* handle, char* name) { return NULL; } -void taosCloseDll(void* handle) {} - -int taosSetConsoleEcho(bool on) { #define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) int err; struct termios term; @@ -72,51 +166,7 @@ int taosSetConsoleEcho(bool on) { } return 0; -} - #else - -/* - * linux implementation - */ - -#include -#include -#include - -void* taosLoadDll(const char* filename) { - void* handle = dlopen(filename, RTLD_LAZY); - if (!handle) { - //printf("load dll:%s failed, error:%s", filename, dlerror()); - return NULL; - } - - //printf("dll %s loaded", filename); - - return handle; -} - -void* taosLoadSym(void* handle, char* name) { - void* sym = dlsym(handle, name); - char* error = NULL; - - if ((error = dlerror()) != NULL) { - //printf("load sym:%s failed, error:%s", name, dlerror()); - return NULL; - } - - //printf("sym %s loaded", name); - - return sym; -} - -void taosCloseDll(void* handle) { - if (handle) { - dlclose(handle); - } -} - -int taosSetConsoleEcho(bool on) { #define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) int err; struct termios term; @@ -138,6 +188,111 @@ int taosSetConsoleEcho(bool on) { } return 0; +#endif } +void setTerminalMode() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +#elif defined(_TD_DARWIN_64) + struct termios newtio; + + /* if (atexit() != 0) { */ + /* fprintf(stderr, "Error register exit function!\n"); */ + /* exit(EXIT_FAILURE); */ + /* } */ + + memcpy(&newtio, &oldtio, sizeof(oldtio)); + + // Set new terminal attributes. + newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP); + newtio.c_iflag |= IGNBRK; + + // newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); + newtio.c_oflag |= OPOST; + newtio.c_oflag |= ONLCR; + newtio.c_oflag &= ~(OCRNL | ONLRET); + + newtio.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHOE | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG); + newtio.c_cc[VMIN] = 1; + newtio.c_cc[VTIME] = 0; + + if (tcsetattr(0, TCSANOW, &newtio) != 0) { + fprintf(stderr, "Fail to set terminal properties!\n"); + exit(EXIT_FAILURE); + } +#else + struct termios newtio; + + /* if (atexit() != 0) { */ + /* fprintf(stderr, "Error register exit function!\n"); */ + /* exit(EXIT_FAILURE); */ + /* } */ + + memcpy(&newtio, &oldtio, sizeof(oldtio)); + + // Set new terminal attributes. + newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP); + newtio.c_iflag |= IGNBRK; + + // newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); + newtio.c_oflag |= OPOST; + newtio.c_oflag |= ONLCR; + newtio.c_oflag &= ~(OCRNL | ONLRET); + + newtio.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHOE | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG); + newtio.c_cc[VMIN] = 1; + newtio.c_cc[VTIME] = 0; + + if (tcsetattr(0, TCSANOW, &newtio) != 0) { + fprintf(stderr, "Fail to set terminal properties!\n"); + exit(EXIT_FAILURE); + } #endif +} + +int32_t getOldTerminalMode() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +#elif defined(_TD_DARWIN_64) + /* Make sure stdin is a terminal. */ + if (!isatty(STDIN_FILENO)) { + return -1; + } + + // Get the parameter of current terminal + if (tcgetattr(0, &oldtio) != 0) { + return -1; + } + + return 1; +#else + /* Make sure stdin is a terminal. */ + if (!isatty(STDIN_FILENO)) { + return -1; + } + + // Get the parameter of current terminal + if (tcgetattr(0, &oldtio) != 0) { + return -1; + } + + return 1; +#endif +} + +void resetTerminalMode() { +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + +#elif defined(_TD_DARWIN_64) + if (tcsetattr(0, TCSANOW, &oldtio) != 0) { + fprintf(stderr, "Fail to reset the terminal properties!\n"); + exit(EXIT_FAILURE); + } +#else + if (tcsetattr(0, TCSANOW, &oldtio) != 0) { + fprintf(stderr, "Fail to reset the terminal properties!\n"); + exit(EXIT_FAILURE); + } +#endif +} \ No newline at end of file diff --git a/tools/shell/inc/shell.h b/tools/shell/inc/shell.h index cf31e9d9d9..7a16ee9d2c 100644 --- a/tools/shell/inc/shell.h +++ b/tools/shell/inc/shell.h @@ -86,10 +86,6 @@ extern char PROMPT_HEADER[]; extern char CONTINUE_PROMPT[]; extern int prompt_size; extern SShellHistory history; -extern struct termios oldtio; -extern void set_terminal_mode(); -extern int get_old_terminal_mode(struct termios* tio); -extern void reset_terminal_mode(); extern SShellArguments args; extern int64_t result; diff --git a/tools/shell/src/backup/shellDarwin.c b/tools/shell/src/backup/shellDarwin.c index f2ab468574..e4cf09358b 100644 --- a/tools/shell/src/backup/shellDarwin.c +++ b/tools/shell/src/backup/shellDarwin.c @@ -358,7 +358,7 @@ int32_t shellReadCommand(TAOS *con, char *command) { void *shellLoopQuery(void *arg) { if (indicator) { - get_old_terminal_mode(&oldtio); + getOldTerminalMode(); indicator = 0; } @@ -379,12 +379,12 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. memset(command, 0, MAX_COMMAND_SIZE); - set_terminal_mode(); + setTerminalMode(); err = shellReadCommand(con, command); if (err) { break; } - reset_terminal_mode(); + resetTerminalMode(); } while (shellRunCommand(con, command) == 0); tfree(command); @@ -395,56 +395,6 @@ void *shellLoopQuery(void *arg) { return NULL; } -int get_old_terminal_mode(struct termios *tio) { - /* Make sure stdin is a terminal. */ - if (!isatty(STDIN_FILENO)) { - return -1; - } - - // Get the parameter of current terminal - if (tcgetattr(0, &oldtio) != 0) { - return -1; - } - - return 1; -} - -void reset_terminal_mode() { - if (tcsetattr(0, TCSANOW, &oldtio) != 0) { - fprintf(stderr, "Fail to reset the terminal properties!\n"); - exit(EXIT_FAILURE); - } -} - -void set_terminal_mode() { - struct termios newtio; - - /* if (atexit(reset_terminal_mode) != 0) { */ - /* fprintf(stderr, "Error register exit function!\n"); */ - /* exit(EXIT_FAILURE); */ - /* } */ - - memcpy(&newtio, &oldtio, sizeof(oldtio)); - - // Set new terminal attributes. - newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP); - newtio.c_iflag |= IGNBRK; - - // newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); - newtio.c_oflag |= OPOST; - newtio.c_oflag |= ONLCR; - newtio.c_oflag &= ~(OCRNL | ONLRET); - - newtio.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHOE | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG); - newtio.c_cc[VMIN] = 1; - newtio.c_cc[VTIME] = 0; - - if (tcsetattr(0, TCSANOW, &newtio) != 0) { - fprintf(stderr, "Fail to set terminal properties!\n"); - exit(EXIT_FAILURE); - } -} - void get_history_path(char *history) { sprintf(history, "%s/%s", getpwuid(getuid())->pw_dir, HISTORY_FILE); } void clearScreen(int ecmd_pos, int cursor_pos) { @@ -541,9 +491,9 @@ void showOnScreen(Command *cmd) { fflush(stdout); } -void cleanup_handler(void *arg) { tcsetattr(0, TCSANOW, &oldtio); } +void cleanup_handler(void *arg) { resetTerminalMode(); } void exitShell() { - tcsetattr(0, TCSANOW, &oldtio); + resetTerminalMode(); exit(EXIT_SUCCESS); } diff --git a/tools/shell/src/backup/shellImport.c b/tools/shell/src/backup/shellImport.c index 36489a448b..b42f77e87e 100644 --- a/tools/shell/src/backup/shellImport.c +++ b/tools/shell/src/backup/shellImport.c @@ -39,14 +39,14 @@ static int shellGetFilesNum(const char *directoryName, const char *prefix) char cmd[1024] = { 0 }; sprintf(cmd, "ls %s/*.%s | wc -l ", directoryName, prefix); - FILE *fp = popen(cmd, "r"); - if (fp == NULL) { + char buf[1024] = { 0 }; + if (taosSystem(cmd, buf, sizeof(buf)) < 0) { fprintf(stderr, "ERROR: failed to execute:%s, error:%s\n", cmd, strerror(errno)); exit(0); } int fileNum = 0; - if (fscanf(fp, "%d", &fileNum) != 1) { + if (sscanf(buf, "%d", &fileNum) != 1) { fprintf(stderr, "ERROR: failed to execute:%s, parse result error\n", cmd); exit(0); } @@ -56,7 +56,6 @@ static int shellGetFilesNum(const char *directoryName, const char *prefix) exit(0); } - pclose(fp); return fileNum; } @@ -65,14 +64,14 @@ static void shellParseDirectory(const char *directoryName, const char *prefix, c char cmd[1024] = { 0 }; sprintf(cmd, "ls %s/*.%s | sort", directoryName, prefix); - FILE *fp = popen(cmd, "r"); - if (fp == NULL) { + char buf[1024] = { 0 }; + if (taosSystem(cmd, buf, sizeof(buf)) < 0) { fprintf(stderr, "ERROR: failed to execute:%s, error:%s\n", cmd, strerror(errno)); exit(0); } int fileNum = 0; - while (fscanf(fp, "%128s", fileArray[fileNum++])) { + while (sscanf(buf, "%128s", fileArray[fileNum++])) { if (strcmp(fileArray[fileNum-1], shellTablesSQLFile) == 0) { fileNum--; } @@ -85,8 +84,6 @@ static void shellParseDirectory(const char *directoryName, const char *prefix, c fprintf(stderr, "ERROR: directory:%s changed while read\n", directoryName); exit(0); } - - pclose(fp); } static void shellCheckTablesSQLFile(const char *directoryName) diff --git a/tools/shell/src/shellLinux.c b/tools/shell/src/shellLinux.c index 57d6df0051..cc497688d1 100644 --- a/tools/shell/src/shellLinux.c +++ b/tools/shell/src/shellLinux.c @@ -388,7 +388,7 @@ int32_t shellReadCommand(TAOS *con, char *command) { void *shellLoopQuery(void *arg) { if (indicator) { - get_old_terminal_mode(&oldtio); + getOldTerminalMode(); indicator = 0; } @@ -409,12 +409,12 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. memset(command, 0, MAX_COMMAND_SIZE); - set_terminal_mode(); + setTerminalMode(); err = shellReadCommand(con, command); if (err) { break; } - reset_terminal_mode(); + resetTerminalMode(); } while (shellRunCommand(con, command) == 0); tfree(command); @@ -425,56 +425,6 @@ void *shellLoopQuery(void *arg) { return NULL; } -int get_old_terminal_mode(struct termios *tio) { - /* Make sure stdin is a terminal. */ - if (!isatty(STDIN_FILENO)) { - return -1; - } - - // Get the parameter of current terminal - if (tcgetattr(0, &oldtio) != 0) { - return -1; - } - - return 1; -} - -void reset_terminal_mode() { - if (tcsetattr(0, TCSANOW, &oldtio) != 0) { - fprintf(stderr, "Fail to reset the terminal properties!\n"); - exit(EXIT_FAILURE); - } -} - -void set_terminal_mode() { - struct termios newtio; - - /* if (atexit(reset_terminal_mode) != 0) { */ - /* fprintf(stderr, "Error register exit function!\n"); */ - /* exit(EXIT_FAILURE); */ - /* } */ - - memcpy(&newtio, &oldtio, sizeof(oldtio)); - - // Set new terminal attributes. - newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP); - newtio.c_iflag |= IGNBRK; - - // newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET); - newtio.c_oflag |= OPOST; - newtio.c_oflag |= ONLCR; - newtio.c_oflag &= ~(OCRNL | ONLRET); - - newtio.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHOE | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG); - newtio.c_cc[VMIN] = 1; - newtio.c_cc[VTIME] = 0; - - if (tcsetattr(0, TCSANOW, &newtio) != 0) { - fprintf(stderr, "Fail to set terminal properties!\n"); - exit(EXIT_FAILURE); - } -} - void get_history_path(char *_history) { snprintf(_history, TSDB_FILENAME_LEN, "%s/%s", getenv("HOME"), HISTORY_FILE); } void clearScreen(int ecmd_pos, int cursor_pos) { @@ -571,10 +521,10 @@ void showOnScreen(Command *cmd) { fflush(stdout); } -void cleanup_handler(void *arg) { tcsetattr(0, TCSANOW, &oldtio); } +void cleanup_handler(void *arg) { resetTerminalMode(); } void exitShell() { - /*int32_t ret =*/ tcsetattr(STDIN_FILENO, TCSANOW, &oldtio); + /*int32_t ret =*/ resetTerminalMode(); taos_cleanup(); exit(EXIT_SUCCESS); } diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index f62c43773d..2832855517 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -41,11 +41,11 @@ void *cancelHandler(void *arg) { taosReleaseRef(tscObjRef, rid); #endif #else - reset_terminal_mode(); + resetTerminalMode(); printf("\nReceive ctrl+c or other signal, quit shell.\n"); exit(0); #endif - reset_terminal_mode(); + resetTerminalMode(); printf("\nReceive ctrl+c or other signal, quit shell.\n"); exit(0); } From 1e9b417f7304553df44a690991fdd761b5f0fd72 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 10 Mar 2022 06:58:07 -0500 Subject: [PATCH 20/23] TD-13747 deal memory leaks --- source/libs/nodes/src/nodesUtilFuncs.c | 11 ++++++++ source/libs/parser/src/parTranslater.c | 35 ++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 19149028ea..658302e169 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -217,6 +217,17 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { nodesDestroyNode(pStmt->pSlimit); break; } + case QUERY_NODE_VNODE_MODIF_STMT: { + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)*pNode; + size_t size = taosArrayGetSize(pStmt->pDataBlocks); + for (size_t i = 0; i < size; ++i) { + SVgDataBlocks* pVg = taosArrayGetP(pStmt->pDataBlocks, i); + tfree(pVg->pData); + tfree(pVg); + } + taosArrayDestroy(pStmt->pDataBlocks); + break; + } case QUERY_NODE_CREATE_TABLE_STMT: { SCreateTableStmt* pStmt = (SCreateTableStmt*)*pNode; nodesDestroyList(pStmt->pCols); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 78212e7c1a..9e563235dc 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -847,6 +847,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo)); if (NULL== pCxt->pCmdMsg) { + tFreeSMCreateStbReq(&createReq); return TSDB_CODE_OUT_OF_MEMORY; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; @@ -854,10 +855,12 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq); pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen); if (NULL== pCxt->pCmdMsg->pMsg) { + tFreeSMCreateStbReq(&createReq); return TSDB_CODE_OUT_OF_MEMORY; } tSerializeSMCreateStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + tFreeSMCreateStbReq(&createReq); return TSDB_CODE_SUCCESS; } @@ -1211,15 +1214,13 @@ static int32_t setReslutSchema(STranslateContext* pCxt, SQuery* pQuery) { static void destroyTranslateContext(STranslateContext* pCxt) { if (NULL != pCxt->pNsLevel) { - + size_t size = taosArrayGetSize(pCxt->pNsLevel); + for (size_t i = 0; i < size; ++i) { + taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); + } + taosArrayDestroy(pCxt->pNsLevel); } - size_t size = taosArrayGetSize(pCxt->pNsLevel); - for (size_t i = 0; i < size; ++i) { - taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); - } - taosArrayDestroy(pCxt->pNsLevel); - if (NULL != pCxt->pCmdMsg) { tfree(pCxt->pCmdMsg->pMsg); tfree(pCxt->pCmdMsg); @@ -1306,8 +1307,6 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { tfree(pTableReq->ntbCfg.pSchema); } else if (pTableReq->type == TSDB_CHILD_TABLE) { tfree(pTableReq->ctbCfg.pTag); - } else { - assert(0); } } @@ -1333,6 +1332,16 @@ static int32_t rewriteToVnodeModifOpStmt(SQuery* pQuery, SArray* pBufArray) { return TSDB_CODE_SUCCESS; } +static void destroyCreateTbReqArray(SArray* pArray) { + size_t size = taosArrayGetSize(pArray); + for (size_t i = 0; i < size; ++i) { + SVgDataBlocks* pVg = taosArrayGetP(pArray, i); + tfree(pVg->pData); + tfree(pVg); + } + taosArrayDestroy(pArray); +} + static int32_t buildCreateTableDataBlock(const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo, SArray** pBufArray) { *pBufArray = taosArrayInit(1, POINTER_BYTES); if (NULL == *pBufArray) { @@ -1344,9 +1353,10 @@ static int32_t buildCreateTableDataBlock(const SCreateTableStmt* pStmt, const SV if (TSDB_CODE_SUCCESS == code) { code = serializeVgroupTablesBatch(&tbatch, *pBufArray); } + destroyCreateTbReqBatch(&tbatch); if (TSDB_CODE_SUCCESS != code) { - // todo : destroyCreateTbReqArray(*pBufArray); + destroyCreateTbReqArray(*pBufArray); } return code; } @@ -1362,6 +1372,9 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { } if (TSDB_CODE_SUCCESS == code) { code = rewriteToVnodeModifOpStmt(pQuery, pBufArray); + if (TSDB_CODE_SUCCESS != code) { + destroyCreateTbReqArray(pBufArray); + } } return code; @@ -1573,10 +1586,10 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) } SArray* pBufArray = serializeVgroupsTablesBatch(pVgroupHashmap); + taosHashCleanup(pVgroupHashmap); if (NULL == pBufArray) { return TSDB_CODE_OUT_OF_MEMORY; } - taosHashCleanup(pVgroupHashmap); return rewriteToVnodeModifOpStmt(pQuery, pBufArray); } From cc53df1a01bd5a19aaa0c0485a642ded36ab14ea Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 10 Mar 2022 23:12:34 +0800 Subject: [PATCH 21/23] [td-13039] fix bug in creating streamscanner. --- source/libs/executor/src/executorimpl.c | 85 +++++++++++++++---------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 7bf3371006..b1b190c816 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5372,7 +5372,7 @@ SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRunt return pOperator; } -SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SArray* pExprInfo, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { SStreamBlockScanInfo* pInfo = calloc(1, sizeof(SStreamBlockScanInfo)); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -5382,16 +5382,6 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SArray* pExp return NULL; } - // todo dynamic set the value of 4096 - pInfo->pRes = createOutputBuf_rv(pExprInfo, 4096); - - int32_t numOfOutput = (int32_t) taosArrayGetSize(pExprInfo); - SArray* pColList = taosArrayInit(numOfOutput, sizeof(int32_t)); - for(int32_t i = 0; i < numOfOutput; ++i) { - SExprInfo* pExpr = taosArrayGetP(pExprInfo, i); - taosArrayPush(pColList, &pExpr->pExpr->pSchema[0].colId); - } - // set the extract column id to streamHandle tqReadHandleSetColIdList((STqReadHandle* )streamReadHandle, pColList); int32_t code = tqReadHandleSetTbUidList(streamReadHandle, pTableIdList); @@ -5401,15 +5391,16 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SArray* pExp return NULL; } - pInfo->readerHandle = streamReadHandle; + pInfo->readerHandle = streamReadHandle; + pInfo->pRes = pResBlock; pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; pOperator->blockingOptr = false; pOperator->status = OP_IN_EXECUTING; pOperator->info = pInfo; - pOperator->numOfOutput = numOfOutput; - pOperator->nextDataFn = doStreamBlockScan; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->nextDataFn = doStreamBlockScan; pOperator->pTaskInfo = pTaskInfo; return pOperator; } @@ -8097,6 +8088,8 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId) { static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId); static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId); +static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo); +static SArray* extractScanColumnId(SNodeList* pNodeList); SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) { if (nodeType(pPhyNode) == QUERY_NODE_PHYSICAL_PLAN_PROJECT) { // ignore the project node @@ -8119,30 +8112,19 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa return createExchangeOperatorInfo(pExchange->pSrcEndPoints, pResBlock, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == nodeType(pPhyNode)) { SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table. + STableGroupInfo groupInfo = {0}; int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, &groupInfo, queryId, taskId); - SArray* idList = NULL; + SArray* tableIdList = extractTableIdList(&groupInfo); - if (groupInfo.numOfTables > 0) { - SArray* pa = taosArrayGetP(groupInfo.pGroupList, 0); - ASSERT(taosArrayGetSize(groupInfo.pGroupList) == 1); + SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); + SArray* colList = extractScanColumnId(pScanPhyNode->pScanCols); - // Transfer the Array of STableKeyInfo into uid list. - size_t numOfTables = taosArrayGetSize(pa); - idList = taosArrayInit(numOfTables, sizeof(uint64_t)); + SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, colList, tableIdList, pTaskInfo); - for (int32_t i = 0; i < numOfTables; ++i) { - STableKeyInfo* pkeyInfo = taosArrayGet(pa, i); - taosArrayPush(idList, &pkeyInfo->uid); - } - } else { - idList = taosArrayInit(4, sizeof(uint64_t)); - } - -// SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pScanPhyNode->pScanCols, idList, pTaskInfo); - taosArrayDestroy(idList); -// return pOperator; + taosArrayDestroy(tableIdList); + return pOperator; } } @@ -8203,7 +8185,24 @@ static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STa return tsdbQueryTables(readHandle, &cond, pGroupInfo, queryId, taskId); } -static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) { +SArray* extractScanColumnId(SNodeList* pNodeList) { + size_t numOfCols = LIST_LENGTH(pNodeList); + SArray* pList = taosArrayInit(numOfCols, sizeof(int16_t)); + if (pList == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + for(int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i); + SColumnNode* pColNode = (SColumnNode*) pNode->pExpr; + taosArrayPush(pList, &pColNode->colId); + } + + return pList; +} + +int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) { int32_t code = 0; if (tableType == TSDB_SUPER_TABLE) { code = tsdbQuerySTableByTagCond(metaHandle, tableUid, 0, NULL, 0, 0, NULL, pGroupInfo, NULL, 0, queryId, taskId); @@ -8214,7 +8213,25 @@ static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t return code; } -static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId) { +SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo) { + SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t)); + + if (pTableGroupInfo->numOfTables > 0) { + SArray* pa = taosArrayGetP(pTableGroupInfo->pGroupList, 0); + ASSERT(taosArrayGetSize(pTableGroupInfo->pGroupList) == 1); + + // Transfer the Array of STableKeyInfo into uid list. + size_t numOfTables = taosArrayGetSize(pa); + for (int32_t i = 0; i < numOfTables; ++i) { + STableKeyInfo* pkeyInfo = taosArrayGet(pa, i); + taosArrayPush(tableIdList, &pkeyInfo->uid); + } + } + + return tableIdList; +} + +tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId) { STableGroupInfo groupInfo = {0}; uint64_t uid = pTableScanNode->scan.uid; From 54e15db2f5b00d593e351894e062e6b87bbbb989 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 10 Mar 2022 21:02:47 -0500 Subject: [PATCH 22/23] TD-13747 show mnodes --- .gitignore | 2 +- include/common/ttokendef.h | 97 +- include/libs/nodes/nodes.h | 1 + source/libs/nodes/src/nodesUtilFuncs.c | 1 + source/libs/parser/inc/sql.y | 3 + source/libs/parser/src/parTokenizer.c | 2 +- source/libs/parser/src/parTranslater.c | 3 + source/libs/parser/src/sql.c | 2588 ++++++++++++------------ source/libs/planner/inc/planInt.h | 7 + 9 files changed, 1363 insertions(+), 1341 deletions(-) diff --git a/.gitignore b/.gitignore index 39c7a7ee5d..3eda69f60d 100644 --- a/.gitignore +++ b/.gitignore @@ -87,7 +87,7 @@ tests/comparisonTest/opentsdb/opentsdbtest/.settings/ tests/examples/JDBC/JDBCDemo/.classpath tests/examples/JDBC/JDBCDemo/.project tests/examples/JDBC/JDBCDemo/.settings/ -source/libs/parser/inc/new_sql.* +source/libs/parser/inc/sql.* # Emacs # -*- mode: gitignore; -*- diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index f5556c709c..2121b3175a 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -101,54 +101,55 @@ #define TK_VARBINARY 83 #define TK_DECIMAL 84 #define TK_SMA 85 -#define TK_NK_FLOAT 86 -#define TK_NK_BOOL 87 -#define TK_NK_VARIABLE 88 -#define TK_BETWEEN 89 -#define TK_IS 90 -#define TK_NULL 91 -#define TK_NK_LT 92 -#define TK_NK_GT 93 -#define TK_NK_LE 94 -#define TK_NK_GE 95 -#define TK_NK_NE 96 -#define TK_NK_EQ 97 -#define TK_LIKE 98 -#define TK_MATCH 99 -#define TK_NMATCH 100 -#define TK_IN 101 -#define TK_FROM 102 -#define TK_AS 103 -#define TK_JOIN 104 -#define TK_ON 105 -#define TK_INNER 106 -#define TK_SELECT 107 -#define TK_DISTINCT 108 -#define TK_WHERE 109 -#define TK_PARTITION 110 -#define TK_BY 111 -#define TK_SESSION 112 -#define TK_STATE_WINDOW 113 -#define TK_INTERVAL 114 -#define TK_SLIDING 115 -#define TK_FILL 116 -#define TK_VALUE 117 -#define TK_NONE 118 -#define TK_PREV 119 -#define TK_LINEAR 120 -#define TK_NEXT 121 -#define TK_GROUP 122 -#define TK_HAVING 123 -#define TK_ORDER 124 -#define TK_SLIMIT 125 -#define TK_SOFFSET 126 -#define TK_LIMIT 127 -#define TK_OFFSET 128 -#define TK_ASC 129 -#define TK_DESC 130 -#define TK_NULLS 131 -#define TK_FIRST 132 -#define TK_LAST 133 +#define TK_MNODES 86 +#define TK_NK_FLOAT 87 +#define TK_NK_BOOL 88 +#define TK_NK_VARIABLE 89 +#define TK_BETWEEN 90 +#define TK_IS 91 +#define TK_NULL 92 +#define TK_NK_LT 93 +#define TK_NK_GT 94 +#define TK_NK_LE 95 +#define TK_NK_GE 96 +#define TK_NK_NE 97 +#define TK_NK_EQ 98 +#define TK_LIKE 99 +#define TK_MATCH 100 +#define TK_NMATCH 101 +#define TK_IN 102 +#define TK_FROM 103 +#define TK_AS 104 +#define TK_JOIN 105 +#define TK_ON 106 +#define TK_INNER 107 +#define TK_SELECT 108 +#define TK_DISTINCT 109 +#define TK_WHERE 110 +#define TK_PARTITION 111 +#define TK_BY 112 +#define TK_SESSION 113 +#define TK_STATE_WINDOW 114 +#define TK_INTERVAL 115 +#define TK_SLIDING 116 +#define TK_FILL 117 +#define TK_VALUE 118 +#define TK_NONE 119 +#define TK_PREV 120 +#define TK_LINEAR 121 +#define TK_NEXT 122 +#define TK_GROUP 123 +#define TK_HAVING 124 +#define TK_ORDER 125 +#define TK_SLIMIT 126 +#define TK_SOFFSET 127 +#define TK_LIMIT 128 +#define TK_OFFSET 129 +#define TK_ASC 130 +#define TK_DESC 131 +#define TK_NULLS 132 +#define TK_FIRST 133 +#define TK_LAST 134 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 35356d5269..8fb52ceb85 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -92,6 +92,7 @@ typedef enum ENodeType { QUERY_NODE_DROP_DNODE_STMT, QUERY_NODE_SHOW_DNODES_STMT, QUERY_NODE_SHOW_VGROUPS_STMT, + QUERY_NODE_SHOW_MNODES_STMT, // logic plan node QUERY_NODE_LOGIC_PLAN_SCAN, diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 658302e169..4055faf299 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -120,6 +120,7 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_SHOW_DNODES_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_SHOW_VGROUPS_STMT: + case QUERY_NODE_SHOW_MNODES_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_LOGIC_PLAN_SCAN: return makeNode(type, sizeof(SScanLogicNode)); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 29e99c360a..310da2e966 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -198,6 +198,9 @@ col_name(A) ::= column_name(B). 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); } +/************************************************ show vgroups ********************************************************/ +cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL); } + /************************************************ select **************************************************************/ cmd ::= query_expression(A). { pCxt->pRootNode = A; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 089b9c30b5..eefa99dae0 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -81,6 +81,7 @@ static SKeyword keywordTable[] = { {"MAXROWS", TK_MAXROWS}, {"MINROWS", TK_MINROWS}, {"MINUS", TK_MINUS}, + {"MNODES", TK_MNODES}, {"NCHAR", TK_NCHAR}, {"NMATCH", TK_NMATCH}, {"NONE", TK_NONE}, @@ -153,7 +154,6 @@ static SKeyword keywordTable[] = { // {"UMINUS", TK_UMINUS}, // {"UPLUS", TK_UPLUS}, // {"BITNOT", TK_BITNOT}, - // {"MNODES", TK_MNODES}, // {"ACCOUNTS", TK_ACCOUNTS}, // {"MODULES", TK_MODULES}, // {"QUERIES", TK_QUERIES}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 9e563235dc..d82b3cad62 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1062,6 +1062,8 @@ static int32_t nodeTypeToShowType(ENodeType nt) { return TSDB_MGMT_TABLE_DNODE; case QUERY_NODE_SHOW_VGROUPS_STMT: return TSDB_MGMT_TABLE_VGROUP; + case QUERY_NODE_SHOW_MNODES_STMT: + return TSDB_MGMT_TABLE_MNODE; default: break; } @@ -1169,6 +1171,7 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_VGROUPS_STMT: + case QUERY_NODE_SHOW_MNODES_STMT: code = translateShow(pCxt, (SShowStmt*)pNode); break; case QUERY_NODE_SHOW_TABLES_STMT: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 34d38c1c06..c54bbd41cc 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -99,24 +99,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char -#define YYNOCODE 208 +#define YYNOCODE 209 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - ENullOrder yy9; - SDatabaseOptions* yy103; - SToken yy161; - EOrder yy162; - EFillMode yy166; - SNodeList* yy184; - EOperatorType yy220; - SDataType yy240; - EJoinType yy308; - STableOptions* yy334; - bool yy377; - SNode* yy392; + SNodeList* yy46; + SDataType yy70; + SToken yy129; + ENullOrder yy147; + bool yy185; + EOrder yy202; + SNode* yy256; + EJoinType yy266; + EOperatorType yy326; + STableOptions* yy340; + EFillMode yy360; + SDatabaseOptions* yy391; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +131,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 278 -#define YYNRULE 236 -#define YYNTOKEN 134 -#define YY_MAX_SHIFT 277 -#define YY_MIN_SHIFTREDUCE 438 -#define YY_MAX_SHIFTREDUCE 673 -#define YY_ERROR_ACTION 674 -#define YY_ACCEPT_ACTION 675 -#define YY_NO_ACTION 676 -#define YY_MIN_REDUCE 677 -#define YY_MAX_REDUCE 912 +#define YYNSTATE 279 +#define YYNRULE 237 +#define YYNTOKEN 135 +#define YY_MAX_SHIFT 278 +#define YY_MIN_SHIFTREDUCE 439 +#define YY_MAX_SHIFTREDUCE 675 +#define YY_ERROR_ACTION 676 +#define YY_ACCEPT_ACTION 677 +#define YY_NO_ACTION 678 +#define YY_MIN_REDUCE 679 +#define YY_MAX_REDUCE 915 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,285 +208,285 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (903) +#define YY_ACTTAB_COUNT (905) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 137, 149, 23, 95, 770, 719, 768, 246, 150, 781, - /* 10 */ 779, 148, 30, 28, 26, 25, 24, 781, 779, 194, - /* 20 */ 177, 805, 96, 733, 66, 30, 28, 26, 25, 24, - /* 30 */ 690, 166, 194, 221, 805, 60, 207, 132, 790, 779, - /* 40 */ 195, 208, 221, 54, 791, 728, 794, 830, 731, 58, - /* 50 */ 132, 139, 826, 903, 19, 782, 779, 731, 556, 73, - /* 60 */ 837, 838, 864, 842, 30, 28, 26, 25, 24, 270, - /* 70 */ 269, 268, 267, 266, 265, 264, 263, 262, 261, 260, - /* 80 */ 259, 258, 257, 256, 255, 254, 26, 25, 24, 22, - /* 90 */ 141, 171, 574, 575, 576, 577, 578, 579, 580, 582, - /* 100 */ 583, 584, 22, 141, 152, 574, 575, 576, 577, 578, - /* 110 */ 579, 580, 582, 583, 584, 220, 733, 66, 498, 244, - /* 120 */ 243, 242, 502, 241, 504, 505, 240, 507, 237, 41, - /* 130 */ 513, 234, 515, 516, 231, 228, 194, 194, 805, 805, - /* 140 */ 727, 184, 790, 779, 195, 220, 220, 53, 791, 170, - /* 150 */ 794, 830, 194, 77, 805, 131, 826, 206, 790, 779, - /* 160 */ 195, 205, 544, 67, 791, 204, 794, 891, 180, 623, - /* 170 */ 805, 10, 10, 548, 790, 779, 195, 274, 273, 54, - /* 180 */ 791, 76, 794, 830, 201, 889, 546, 139, 826, 71, - /* 190 */ 208, 203, 202, 30, 28, 26, 25, 24, 194, 546, - /* 200 */ 805, 94, 185, 904, 790, 779, 195, 156, 857, 125, - /* 210 */ 791, 145, 794, 180, 20, 805, 172, 167, 165, 790, - /* 220 */ 779, 195, 77, 581, 54, 791, 585, 794, 830, 194, - /* 230 */ 253, 805, 139, 826, 71, 790, 779, 195, 29, 27, - /* 240 */ 54, 791, 247, 794, 830, 93, 200, 537, 139, 826, - /* 250 */ 903, 734, 66, 858, 194, 535, 805, 146, 844, 887, - /* 260 */ 790, 779, 195, 11, 891, 54, 791, 163, 794, 830, - /* 270 */ 29, 27, 616, 139, 826, 903, 841, 114, 890, 537, - /* 280 */ 761, 188, 889, 1, 848, 50, 194, 535, 805, 146, - /* 290 */ 47, 184, 790, 779, 195, 11, 153, 119, 791, 770, - /* 300 */ 794, 768, 222, 221, 9, 8, 218, 29, 27, 154, - /* 310 */ 29, 27, 536, 538, 541, 1, 537, 891, 731, 537, - /* 320 */ 844, 733, 66, 717, 535, 221, 146, 535, 219, 146, - /* 330 */ 41, 76, 11, 77, 222, 889, 615, 61, 840, 844, - /* 340 */ 731, 726, 189, 448, 536, 538, 541, 30, 28, 26, - /* 350 */ 25, 24, 1, 449, 450, 7, 194, 839, 805, 253, - /* 360 */ 549, 592, 790, 779, 195, 21, 178, 125, 791, 157, - /* 370 */ 794, 222, 6, 611, 222, 30, 28, 26, 25, 24, - /* 380 */ 187, 536, 538, 541, 536, 538, 541, 194, 221, 805, - /* 390 */ 770, 109, 769, 790, 779, 195, 177, 88, 55, 791, - /* 400 */ 860, 794, 830, 731, 448, 77, 829, 826, 194, 177, - /* 410 */ 805, 60, 211, 98, 790, 779, 195, 191, 221, 55, - /* 420 */ 791, 155, 794, 830, 60, 58, 2, 181, 826, 184, - /* 430 */ 45, 182, 79, 731, 179, 72, 837, 838, 58, 842, - /* 440 */ 614, 724, 29, 27, 183, 51, 806, 637, 91, 837, - /* 450 */ 176, 537, 175, 62, 56, 891, 723, 29, 27, 535, - /* 460 */ 85, 146, 29, 27, 669, 670, 537, 82, 849, 76, - /* 470 */ 611, 537, 210, 889, 535, 586, 146, 672, 673, 535, - /* 480 */ 192, 146, 31, 675, 194, 571, 805, 7, 549, 861, - /* 490 */ 790, 779, 195, 9, 8, 55, 791, 216, 794, 830, - /* 500 */ 214, 186, 1, 786, 827, 130, 222, 7, 196, 217, - /* 510 */ 784, 127, 68, 164, 871, 80, 536, 538, 541, 161, - /* 520 */ 537, 222, 100, 553, 541, 851, 222, 159, 535, 160, - /* 530 */ 31, 536, 538, 541, 891, 870, 536, 538, 541, 194, - /* 540 */ 138, 805, 106, 84, 5, 790, 779, 195, 76, 63, - /* 550 */ 121, 791, 889, 794, 194, 174, 805, 158, 87, 70, - /* 560 */ 790, 779, 195, 4, 491, 125, 791, 140, 794, 89, - /* 570 */ 194, 64, 805, 611, 545, 222, 790, 779, 195, 59, - /* 580 */ 548, 67, 791, 173, 794, 536, 538, 541, 30, 28, - /* 590 */ 26, 25, 24, 194, 77, 805, 486, 845, 32, 790, - /* 600 */ 779, 195, 90, 56, 120, 791, 194, 794, 805, 519, - /* 610 */ 16, 142, 790, 779, 195, 104, 226, 122, 791, 906, - /* 620 */ 794, 905, 193, 78, 194, 718, 805, 812, 190, 103, - /* 630 */ 790, 779, 195, 888, 556, 117, 791, 523, 794, 194, - /* 640 */ 544, 805, 528, 97, 63, 790, 779, 195, 197, 64, - /* 650 */ 123, 791, 42, 794, 194, 101, 805, 40, 209, 102, - /* 660 */ 790, 779, 195, 65, 550, 118, 791, 113, 794, 212, - /* 670 */ 63, 194, 250, 805, 147, 44, 249, 790, 779, 195, - /* 680 */ 732, 46, 124, 791, 115, 794, 194, 277, 805, 128, - /* 690 */ 224, 251, 790, 779, 195, 110, 116, 802, 791, 129, - /* 700 */ 794, 194, 14, 805, 3, 31, 81, 790, 779, 195, - /* 710 */ 248, 634, 801, 791, 83, 794, 194, 35, 805, 716, - /* 720 */ 636, 69, 790, 779, 195, 86, 37, 800, 791, 630, - /* 730 */ 794, 194, 629, 805, 168, 169, 784, 790, 779, 195, - /* 740 */ 38, 18, 135, 791, 608, 794, 15, 607, 194, 92, - /* 750 */ 805, 33, 34, 8, 790, 779, 195, 75, 572, 134, - /* 760 */ 791, 194, 794, 805, 554, 663, 250, 790, 779, 195, - /* 770 */ 249, 177, 136, 791, 17, 794, 194, 12, 805, 39, - /* 780 */ 99, 658, 790, 779, 195, 251, 60, 133, 791, 640, - /* 790 */ 794, 194, 657, 805, 143, 662, 661, 790, 779, 195, - /* 800 */ 58, 144, 126, 791, 248, 794, 13, 773, 693, 772, - /* 810 */ 74, 837, 838, 112, 842, 162, 638, 639, 641, 642, - /* 820 */ 199, 57, 198, 771, 722, 721, 692, 111, 686, 681, - /* 830 */ 720, 457, 691, 685, 684, 680, 679, 213, 678, 215, - /* 840 */ 105, 43, 47, 783, 36, 108, 223, 520, 539, 225, - /* 850 */ 52, 151, 227, 107, 517, 230, 512, 514, 233, 236, - /* 860 */ 229, 508, 506, 239, 511, 497, 232, 48, 235, 238, - /* 870 */ 510, 245, 49, 525, 527, 509, 526, 476, 475, 455, - /* 880 */ 252, 469, 474, 473, 472, 471, 470, 468, 467, 683, - /* 890 */ 466, 465, 464, 463, 462, 461, 460, 271, 272, 682, - /* 900 */ 677, 275, 276, + /* 0 */ 137, 149, 23, 95, 772, 721, 770, 247, 150, 784, + /* 10 */ 782, 148, 30, 28, 26, 25, 24, 784, 782, 194, + /* 20 */ 177, 808, 201, 735, 66, 30, 28, 26, 25, 24, + /* 30 */ 692, 166, 194, 222, 808, 60, 208, 132, 793, 782, + /* 40 */ 195, 209, 222, 54, 794, 730, 797, 833, 733, 58, + /* 50 */ 132, 139, 829, 906, 19, 785, 782, 733, 558, 73, + /* 60 */ 840, 841, 867, 845, 30, 28, 26, 25, 24, 271, + /* 70 */ 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, + /* 80 */ 260, 259, 258, 257, 256, 255, 26, 25, 24, 550, + /* 90 */ 22, 141, 171, 576, 577, 578, 579, 580, 581, 582, + /* 100 */ 584, 585, 586, 22, 141, 617, 576, 577, 578, 579, + /* 110 */ 580, 581, 582, 584, 585, 586, 275, 274, 499, 245, + /* 120 */ 244, 243, 503, 242, 505, 506, 241, 508, 238, 41, + /* 130 */ 514, 235, 516, 517, 232, 229, 194, 194, 808, 808, + /* 140 */ 729, 184, 793, 782, 195, 77, 45, 53, 794, 170, + /* 150 */ 797, 833, 194, 719, 808, 131, 829, 726, 793, 782, + /* 160 */ 195, 104, 93, 125, 794, 145, 797, 894, 153, 78, + /* 170 */ 221, 772, 180, 770, 808, 103, 736, 66, 793, 782, + /* 180 */ 195, 76, 209, 54, 794, 892, 797, 833, 194, 254, + /* 190 */ 808, 139, 829, 71, 793, 782, 195, 221, 42, 54, + /* 200 */ 794, 101, 797, 833, 772, 94, 771, 139, 829, 906, + /* 210 */ 616, 156, 860, 894, 180, 254, 808, 551, 890, 50, + /* 220 */ 793, 782, 195, 10, 47, 54, 794, 893, 797, 833, + /* 230 */ 194, 892, 808, 139, 829, 71, 793, 782, 195, 29, + /* 240 */ 27, 54, 794, 677, 797, 833, 41, 187, 539, 139, + /* 250 */ 829, 906, 114, 61, 861, 763, 537, 728, 146, 221, + /* 260 */ 851, 29, 27, 618, 11, 194, 182, 808, 196, 548, + /* 270 */ 539, 793, 782, 195, 77, 639, 121, 794, 537, 797, + /* 280 */ 146, 194, 56, 808, 1, 10, 11, 793, 782, 195, + /* 290 */ 79, 51, 55, 794, 894, 797, 833, 9, 8, 62, + /* 300 */ 832, 829, 725, 223, 222, 449, 1, 219, 76, 173, + /* 310 */ 248, 152, 892, 212, 538, 540, 543, 720, 191, 733, + /* 320 */ 194, 573, 808, 735, 66, 223, 793, 782, 195, 6, + /* 330 */ 613, 125, 794, 157, 797, 77, 538, 540, 543, 194, + /* 340 */ 222, 808, 96, 220, 184, 793, 782, 195, 29, 27, + /* 350 */ 119, 794, 163, 797, 594, 733, 847, 539, 172, 167, + /* 360 */ 165, 88, 29, 27, 251, 537, 188, 146, 250, 186, + /* 370 */ 894, 539, 222, 11, 844, 109, 847, 177, 852, 537, + /* 380 */ 613, 146, 192, 252, 76, 863, 154, 733, 892, 194, + /* 390 */ 177, 808, 60, 1, 843, 793, 782, 195, 735, 66, + /* 400 */ 55, 794, 249, 797, 833, 60, 58, 7, 181, 829, + /* 410 */ 184, 449, 223, 9, 8, 179, 72, 840, 841, 58, + /* 420 */ 845, 450, 451, 538, 540, 543, 223, 85, 189, 91, + /* 430 */ 840, 176, 625, 175, 82, 847, 894, 538, 540, 543, + /* 440 */ 178, 98, 29, 27, 183, 222, 29, 27, 155, 548, + /* 450 */ 76, 539, 809, 842, 892, 539, 674, 675, 77, 537, + /* 460 */ 733, 146, 194, 537, 808, 146, 20, 2, 793, 782, + /* 470 */ 195, 29, 27, 55, 794, 583, 797, 833, 587, 211, + /* 480 */ 539, 217, 830, 551, 215, 642, 539, 7, 537, 588, + /* 490 */ 146, 1, 864, 194, 537, 808, 31, 164, 161, 793, + /* 500 */ 782, 195, 555, 874, 68, 794, 223, 797, 80, 31, + /* 510 */ 223, 162, 640, 641, 643, 644, 7, 538, 540, 543, + /* 520 */ 789, 538, 540, 543, 106, 543, 194, 787, 808, 492, + /* 530 */ 159, 63, 793, 782, 195, 223, 64, 125, 794, 140, + /* 540 */ 797, 223, 873, 185, 907, 718, 538, 540, 543, 194, + /* 550 */ 160, 808, 538, 540, 543, 793, 782, 195, 487, 84, + /* 560 */ 68, 794, 138, 797, 194, 56, 808, 5, 854, 174, + /* 570 */ 793, 782, 195, 520, 70, 120, 794, 524, 797, 194, + /* 580 */ 227, 808, 4, 87, 63, 793, 782, 195, 158, 613, + /* 590 */ 122, 794, 251, 797, 89, 194, 250, 808, 529, 547, + /* 600 */ 908, 793, 782, 195, 59, 64, 117, 794, 65, 797, + /* 610 */ 194, 252, 808, 550, 848, 63, 793, 782, 195, 32, + /* 620 */ 16, 123, 794, 142, 797, 194, 815, 808, 90, 909, + /* 630 */ 249, 793, 782, 195, 193, 891, 118, 794, 194, 797, + /* 640 */ 808, 97, 546, 190, 793, 782, 195, 197, 210, 124, + /* 650 */ 794, 194, 797, 808, 40, 102, 552, 793, 782, 195, + /* 660 */ 734, 213, 805, 794, 147, 797, 194, 46, 808, 113, + /* 670 */ 44, 225, 793, 782, 195, 115, 110, 804, 794, 194, + /* 680 */ 797, 808, 278, 3, 128, 793, 782, 195, 129, 116, + /* 690 */ 803, 794, 31, 797, 194, 14, 808, 81, 636, 83, + /* 700 */ 793, 782, 195, 35, 638, 135, 794, 194, 797, 808, + /* 710 */ 69, 86, 37, 793, 782, 195, 632, 631, 134, 794, + /* 720 */ 194, 797, 808, 168, 38, 169, 793, 782, 195, 787, + /* 730 */ 610, 136, 794, 18, 797, 194, 15, 808, 609, 92, + /* 740 */ 207, 793, 782, 195, 206, 546, 133, 794, 205, 797, + /* 750 */ 33, 194, 34, 808, 75, 8, 574, 793, 782, 195, + /* 760 */ 556, 665, 126, 794, 17, 797, 177, 202, 12, 39, + /* 770 */ 660, 659, 143, 664, 204, 203, 30, 28, 26, 25, + /* 780 */ 24, 60, 99, 663, 130, 144, 13, 776, 218, 695, + /* 790 */ 127, 67, 775, 774, 112, 58, 200, 773, 199, 724, + /* 800 */ 198, 100, 57, 21, 723, 74, 840, 841, 111, 845, + /* 810 */ 694, 688, 683, 30, 28, 26, 25, 24, 30, 28, + /* 820 */ 26, 25, 24, 722, 458, 693, 30, 28, 26, 25, + /* 830 */ 24, 52, 687, 686, 107, 682, 681, 214, 680, 216, + /* 840 */ 105, 43, 47, 786, 226, 108, 224, 541, 36, 151, + /* 850 */ 513, 230, 521, 228, 512, 511, 518, 231, 233, 236, + /* 860 */ 515, 509, 234, 239, 558, 237, 510, 507, 498, 528, + /* 870 */ 240, 527, 526, 246, 77, 456, 48, 477, 253, 476, + /* 880 */ 470, 49, 475, 474, 473, 472, 471, 469, 685, 468, + /* 890 */ 467, 466, 465, 464, 671, 672, 463, 462, 461, 272, + /* 900 */ 273, 684, 679, 276, 277, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 151, 153, 170, 171, 156, 0, 158, 157, 151, 160, - /* 10 */ 161, 143, 12, 13, 14, 15, 16, 160, 161, 154, - /* 20 */ 139, 156, 206, 155, 156, 12, 13, 14, 15, 16, - /* 30 */ 0, 166, 154, 139, 156, 154, 142, 37, 160, 161, - /* 40 */ 162, 36, 139, 165, 166, 142, 168, 169, 154, 168, - /* 50 */ 37, 173, 174, 175, 2, 160, 161, 154, 58, 178, - /* 60 */ 179, 180, 184, 182, 12, 13, 14, 15, 16, 39, + /* 0 */ 152, 154, 171, 172, 157, 0, 159, 158, 152, 161, + /* 10 */ 162, 144, 12, 13, 14, 15, 16, 161, 162, 155, + /* 20 */ 140, 157, 140, 156, 157, 12, 13, 14, 15, 16, + /* 30 */ 0, 167, 155, 140, 157, 155, 143, 37, 161, 162, + /* 40 */ 163, 36, 140, 166, 167, 143, 169, 170, 155, 169, + /* 50 */ 37, 174, 175, 176, 2, 161, 162, 155, 58, 179, + /* 60 */ 180, 181, 185, 183, 12, 13, 14, 15, 16, 39, /* 70 */ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, - /* 80 */ 50, 51, 52, 53, 54, 55, 14, 15, 16, 89, - /* 90 */ 90, 31, 92, 93, 94, 95, 96, 97, 98, 99, - /* 100 */ 100, 101, 89, 90, 143, 92, 93, 94, 95, 96, - /* 110 */ 97, 98, 99, 100, 101, 31, 155, 156, 67, 68, - /* 120 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 141, - /* 130 */ 79, 80, 81, 82, 83, 84, 154, 154, 156, 156, - /* 140 */ 152, 159, 160, 161, 162, 31, 31, 165, 166, 166, - /* 150 */ 168, 169, 154, 107, 156, 173, 174, 26, 160, 161, - /* 160 */ 162, 30, 31, 165, 166, 34, 168, 185, 154, 14, - /* 170 */ 156, 57, 57, 31, 160, 161, 162, 136, 137, 165, - /* 180 */ 166, 199, 168, 169, 53, 203, 31, 173, 174, 175, - /* 190 */ 36, 60, 61, 12, 13, 14, 15, 16, 154, 31, - /* 200 */ 156, 187, 204, 205, 160, 161, 162, 193, 194, 165, - /* 210 */ 166, 167, 168, 154, 89, 156, 112, 113, 114, 160, - /* 220 */ 161, 162, 107, 98, 165, 166, 101, 168, 169, 154, - /* 230 */ 36, 156, 173, 174, 175, 160, 161, 162, 12, 13, - /* 240 */ 165, 166, 63, 168, 169, 103, 139, 21, 173, 174, - /* 250 */ 175, 155, 156, 194, 154, 29, 156, 31, 163, 184, - /* 260 */ 160, 161, 162, 37, 185, 165, 166, 197, 168, 169, - /* 270 */ 12, 13, 14, 173, 174, 175, 181, 144, 199, 21, - /* 280 */ 147, 65, 203, 57, 184, 57, 154, 29, 156, 31, - /* 290 */ 62, 159, 160, 161, 162, 37, 153, 165, 166, 156, - /* 300 */ 168, 158, 76, 139, 1, 2, 142, 12, 13, 143, - /* 310 */ 12, 13, 86, 87, 88, 57, 21, 185, 154, 21, - /* 320 */ 163, 155, 156, 0, 29, 139, 31, 29, 142, 31, - /* 330 */ 141, 199, 37, 107, 76, 203, 4, 148, 181, 163, - /* 340 */ 154, 152, 126, 21, 86, 87, 88, 12, 13, 14, - /* 350 */ 15, 16, 57, 31, 32, 57, 154, 181, 156, 36, - /* 360 */ 31, 58, 160, 161, 162, 2, 183, 165, 166, 167, - /* 370 */ 168, 76, 105, 106, 76, 12, 13, 14, 15, 16, - /* 380 */ 3, 86, 87, 88, 86, 87, 88, 154, 139, 156, - /* 390 */ 156, 142, 158, 160, 161, 162, 139, 190, 165, 166, - /* 400 */ 164, 168, 169, 154, 21, 107, 173, 174, 154, 139, - /* 410 */ 156, 154, 29, 200, 160, 161, 162, 65, 139, 165, - /* 420 */ 166, 142, 168, 169, 154, 168, 186, 173, 174, 159, - /* 430 */ 138, 37, 103, 154, 177, 178, 179, 180, 168, 182, - /* 440 */ 108, 149, 12, 13, 14, 138, 156, 58, 178, 179, - /* 450 */ 180, 21, 182, 146, 65, 185, 149, 12, 13, 29, - /* 460 */ 58, 31, 12, 13, 129, 130, 21, 65, 104, 199, - /* 470 */ 106, 21, 136, 203, 29, 58, 31, 132, 133, 29, - /* 480 */ 128, 31, 65, 134, 154, 91, 156, 57, 31, 164, - /* 490 */ 160, 161, 162, 1, 2, 165, 166, 20, 168, 169, - /* 500 */ 23, 124, 57, 57, 174, 18, 76, 57, 159, 22, - /* 510 */ 64, 24, 25, 116, 196, 195, 86, 87, 88, 115, - /* 520 */ 21, 76, 35, 58, 88, 192, 76, 161, 29, 161, - /* 530 */ 65, 86, 87, 88, 185, 196, 86, 87, 88, 154, - /* 540 */ 161, 156, 58, 195, 123, 160, 161, 162, 199, 65, - /* 550 */ 165, 166, 203, 168, 154, 122, 156, 110, 191, 189, - /* 560 */ 160, 161, 162, 109, 58, 165, 166, 167, 168, 188, - /* 570 */ 154, 65, 156, 106, 31, 76, 160, 161, 162, 154, - /* 580 */ 31, 165, 166, 198, 168, 86, 87, 88, 12, 13, - /* 590 */ 14, 15, 16, 154, 107, 156, 58, 163, 102, 160, - /* 600 */ 161, 162, 176, 65, 165, 166, 154, 168, 156, 58, - /* 610 */ 57, 131, 160, 161, 162, 19, 65, 165, 166, 207, - /* 620 */ 168, 205, 127, 27, 154, 0, 156, 172, 125, 33, - /* 630 */ 160, 161, 162, 202, 58, 165, 166, 58, 168, 154, - /* 640 */ 31, 156, 58, 201, 65, 160, 161, 162, 139, 65, - /* 650 */ 165, 166, 56, 168, 154, 59, 156, 141, 139, 141, - /* 660 */ 160, 161, 162, 58, 31, 165, 166, 147, 168, 135, - /* 670 */ 65, 154, 47, 156, 135, 138, 51, 160, 161, 162, - /* 680 */ 154, 57, 165, 166, 139, 168, 154, 135, 156, 145, - /* 690 */ 150, 66, 160, 161, 162, 138, 140, 165, 166, 145, - /* 700 */ 168, 154, 111, 156, 65, 65, 58, 160, 161, 162, - /* 710 */ 85, 58, 165, 166, 57, 168, 154, 65, 156, 0, - /* 720 */ 58, 57, 160, 161, 162, 57, 57, 165, 166, 58, - /* 730 */ 168, 154, 58, 156, 29, 65, 64, 160, 161, 162, - /* 740 */ 57, 65, 165, 166, 58, 168, 111, 58, 154, 64, - /* 750 */ 156, 104, 65, 2, 160, 161, 162, 64, 91, 165, - /* 760 */ 166, 154, 168, 156, 58, 58, 47, 160, 161, 162, - /* 770 */ 51, 139, 165, 166, 65, 168, 154, 111, 156, 4, - /* 780 */ 64, 29, 160, 161, 162, 66, 154, 165, 166, 91, - /* 790 */ 168, 154, 29, 156, 29, 29, 29, 160, 161, 162, - /* 800 */ 168, 29, 165, 166, 85, 168, 57, 0, 0, 0, - /* 810 */ 178, 179, 180, 19, 182, 117, 118, 119, 120, 121, - /* 820 */ 64, 27, 53, 0, 0, 0, 0, 33, 0, 0, - /* 830 */ 0, 38, 0, 0, 0, 0, 0, 21, 0, 21, - /* 840 */ 19, 57, 62, 64, 57, 64, 63, 58, 21, 29, - /* 850 */ 56, 29, 57, 59, 58, 57, 78, 58, 57, 57, - /* 860 */ 29, 58, 58, 57, 78, 21, 29, 57, 29, 29, - /* 870 */ 78, 66, 57, 21, 29, 78, 29, 29, 29, 38, - /* 880 */ 37, 21, 29, 29, 29, 29, 29, 29, 29, 0, - /* 890 */ 29, 29, 29, 29, 29, 29, 29, 29, 28, 0, - /* 900 */ 0, 21, 20, 208, 208, 208, 208, 208, 208, 208, - /* 910 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 920 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 930 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 940 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 950 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 960 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 970 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 980 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 990 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 1000 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 1010 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 1020 */ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - /* 1030 */ 208, 208, 208, 208, 208, 208, 208, + /* 80 */ 50, 51, 52, 53, 54, 55, 14, 15, 16, 31, + /* 90 */ 90, 91, 31, 93, 94, 95, 96, 97, 98, 99, + /* 100 */ 100, 101, 102, 90, 91, 4, 93, 94, 95, 96, + /* 110 */ 97, 98, 99, 100, 101, 102, 137, 138, 67, 68, + /* 120 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 142, + /* 130 */ 79, 80, 81, 82, 83, 84, 155, 155, 157, 157, + /* 140 */ 153, 160, 161, 162, 163, 108, 139, 166, 167, 167, + /* 150 */ 169, 170, 155, 0, 157, 174, 175, 150, 161, 162, + /* 160 */ 163, 19, 104, 166, 167, 168, 169, 186, 154, 27, + /* 170 */ 31, 157, 155, 159, 157, 33, 156, 157, 161, 162, + /* 180 */ 163, 200, 36, 166, 167, 204, 169, 170, 155, 36, + /* 190 */ 157, 174, 175, 176, 161, 162, 163, 31, 56, 166, + /* 200 */ 167, 59, 169, 170, 157, 188, 159, 174, 175, 176, + /* 210 */ 109, 194, 195, 186, 155, 36, 157, 31, 185, 57, + /* 220 */ 161, 162, 163, 57, 62, 166, 167, 200, 169, 170, + /* 230 */ 155, 204, 157, 174, 175, 176, 161, 162, 163, 12, + /* 240 */ 13, 166, 167, 135, 169, 170, 142, 3, 21, 174, + /* 250 */ 175, 176, 145, 149, 195, 148, 29, 153, 31, 31, + /* 260 */ 185, 12, 13, 14, 37, 155, 37, 157, 160, 31, + /* 270 */ 21, 161, 162, 163, 108, 58, 166, 167, 29, 169, + /* 280 */ 31, 155, 65, 157, 57, 57, 37, 161, 162, 163, + /* 290 */ 104, 139, 166, 167, 186, 169, 170, 1, 2, 147, + /* 300 */ 174, 175, 150, 76, 140, 21, 57, 143, 200, 199, + /* 310 */ 63, 144, 204, 29, 87, 88, 89, 0, 65, 155, + /* 320 */ 155, 92, 157, 156, 157, 76, 161, 162, 163, 106, + /* 330 */ 107, 166, 167, 168, 169, 108, 87, 88, 89, 155, + /* 340 */ 140, 157, 207, 143, 160, 161, 162, 163, 12, 13, + /* 350 */ 166, 167, 198, 169, 58, 155, 164, 21, 113, 114, + /* 360 */ 115, 191, 12, 13, 47, 29, 65, 31, 51, 125, + /* 370 */ 186, 21, 140, 37, 182, 143, 164, 140, 105, 29, + /* 380 */ 107, 31, 129, 66, 200, 165, 144, 155, 204, 155, + /* 390 */ 140, 157, 155, 57, 182, 161, 162, 163, 156, 157, + /* 400 */ 166, 167, 85, 169, 170, 155, 169, 57, 174, 175, + /* 410 */ 160, 21, 76, 1, 2, 178, 179, 180, 181, 169, + /* 420 */ 183, 31, 32, 87, 88, 89, 76, 58, 127, 179, + /* 430 */ 180, 181, 14, 183, 65, 164, 186, 87, 88, 89, + /* 440 */ 184, 201, 12, 13, 14, 140, 12, 13, 143, 31, + /* 450 */ 200, 21, 157, 182, 204, 21, 133, 134, 108, 29, + /* 460 */ 155, 31, 155, 29, 157, 31, 90, 187, 161, 162, + /* 470 */ 163, 12, 13, 166, 167, 99, 169, 170, 102, 137, + /* 480 */ 21, 20, 175, 31, 23, 92, 21, 57, 29, 58, + /* 490 */ 31, 57, 165, 155, 29, 157, 65, 117, 116, 161, + /* 500 */ 162, 163, 58, 197, 166, 167, 76, 169, 196, 65, + /* 510 */ 76, 118, 119, 120, 121, 122, 57, 87, 88, 89, + /* 520 */ 57, 87, 88, 89, 58, 89, 155, 64, 157, 58, + /* 530 */ 162, 65, 161, 162, 163, 76, 65, 166, 167, 168, + /* 540 */ 169, 76, 197, 205, 206, 0, 87, 88, 89, 155, + /* 550 */ 162, 157, 87, 88, 89, 161, 162, 163, 58, 196, + /* 560 */ 166, 167, 162, 169, 155, 65, 157, 124, 193, 123, + /* 570 */ 161, 162, 163, 58, 190, 166, 167, 58, 169, 155, + /* 580 */ 65, 157, 110, 192, 65, 161, 162, 163, 111, 107, + /* 590 */ 166, 167, 47, 169, 189, 155, 51, 157, 58, 31, + /* 600 */ 206, 161, 162, 163, 155, 65, 166, 167, 58, 169, + /* 610 */ 155, 66, 157, 31, 164, 65, 161, 162, 163, 103, + /* 620 */ 57, 166, 167, 132, 169, 155, 173, 157, 177, 208, + /* 630 */ 85, 161, 162, 163, 128, 203, 166, 167, 155, 169, + /* 640 */ 157, 202, 31, 126, 161, 162, 163, 140, 140, 166, + /* 650 */ 167, 155, 169, 157, 142, 142, 31, 161, 162, 163, + /* 660 */ 155, 136, 166, 167, 136, 169, 155, 57, 157, 148, + /* 670 */ 139, 151, 161, 162, 163, 140, 139, 166, 167, 155, + /* 680 */ 169, 157, 136, 65, 146, 161, 162, 163, 146, 141, + /* 690 */ 166, 167, 65, 169, 155, 112, 157, 58, 58, 57, + /* 700 */ 161, 162, 163, 65, 58, 166, 167, 155, 169, 157, + /* 710 */ 57, 57, 57, 161, 162, 163, 58, 58, 166, 167, + /* 720 */ 155, 169, 157, 29, 57, 65, 161, 162, 163, 64, + /* 730 */ 58, 166, 167, 65, 169, 155, 112, 157, 58, 64, + /* 740 */ 26, 161, 162, 163, 30, 31, 166, 167, 34, 169, + /* 750 */ 105, 155, 65, 157, 64, 2, 92, 161, 162, 163, + /* 760 */ 58, 58, 166, 167, 65, 169, 140, 53, 112, 4, + /* 770 */ 29, 29, 29, 29, 60, 61, 12, 13, 14, 15, + /* 780 */ 16, 155, 64, 29, 18, 29, 57, 0, 22, 0, + /* 790 */ 24, 25, 0, 0, 19, 169, 64, 0, 53, 0, + /* 800 */ 86, 35, 27, 2, 0, 179, 180, 181, 33, 183, + /* 810 */ 0, 0, 0, 12, 13, 14, 15, 16, 12, 13, + /* 820 */ 14, 15, 16, 0, 38, 0, 12, 13, 14, 15, + /* 830 */ 16, 56, 0, 0, 59, 0, 0, 21, 0, 21, + /* 840 */ 19, 57, 62, 64, 29, 64, 63, 21, 57, 29, + /* 850 */ 78, 29, 58, 57, 78, 78, 58, 57, 29, 29, + /* 860 */ 58, 58, 57, 29, 58, 57, 78, 58, 21, 29, + /* 870 */ 57, 29, 21, 66, 108, 38, 57, 29, 37, 29, + /* 880 */ 21, 57, 29, 29, 29, 29, 29, 29, 0, 29, + /* 890 */ 29, 29, 29, 29, 130, 131, 29, 29, 29, 29, + /* 900 */ 28, 0, 0, 21, 20, 209, 209, 209, 209, 209, + /* 910 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 920 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 930 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 940 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 950 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 960 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 970 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 980 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 990 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 1000 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 1010 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 1020 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + /* 1030 */ 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, }; -#define YY_SHIFT_COUNT (277) +#define YY_SHIFT_COUNT (278) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (900) +#define YY_SHIFT_MAX (902) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 487, 226, 258, 295, 295, 295, 295, 298, 295, 295, - /* 10 */ 115, 445, 450, 430, 450, 450, 450, 450, 450, 450, - /* 20 */ 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, - /* 30 */ 450, 450, 114, 114, 114, 499, 499, 60, 60, 46, - /* 40 */ 84, 84, 154, 168, 84, 84, 168, 84, 168, 168, - /* 50 */ 168, 84, 194, 0, 13, 13, 499, 322, 142, 142, - /* 60 */ 142, 5, 323, 168, 168, 179, 51, 335, 131, 698, - /* 70 */ 104, 329, 364, 267, 364, 155, 377, 332, 383, 457, - /* 80 */ 397, 404, 436, 436, 397, 404, 436, 421, 433, 447, - /* 90 */ 454, 467, 543, 549, 496, 553, 480, 495, 503, 168, - /* 100 */ 609, 154, 609, 154, 633, 633, 179, 194, 543, 624, - /* 110 */ 609, 194, 633, 903, 903, 903, 30, 52, 363, 576, - /* 120 */ 181, 181, 181, 181, 181, 181, 181, 596, 625, 719, - /* 130 */ 794, 303, 125, 72, 72, 72, 72, 389, 402, 492, - /* 140 */ 417, 394, 345, 216, 352, 465, 446, 477, 484, 506, - /* 150 */ 538, 551, 579, 584, 605, 228, 639, 640, 591, 648, - /* 160 */ 653, 657, 652, 662, 664, 668, 671, 669, 674, 705, - /* 170 */ 670, 672, 683, 676, 635, 686, 689, 685, 647, 687, - /* 180 */ 693, 751, 667, 706, 707, 709, 666, 775, 752, 763, - /* 190 */ 765, 766, 767, 772, 716, 749, 807, 808, 809, 769, - /* 200 */ 756, 823, 824, 825, 826, 828, 829, 830, 793, 832, - /* 210 */ 833, 834, 835, 836, 816, 838, 818, 821, 784, 780, - /* 220 */ 779, 781, 827, 787, 783, 789, 820, 822, 795, 796, - /* 230 */ 831, 798, 799, 837, 801, 803, 839, 802, 804, 840, - /* 240 */ 806, 778, 786, 792, 797, 844, 805, 810, 815, 845, - /* 250 */ 847, 852, 841, 843, 848, 849, 853, 854, 855, 856, - /* 260 */ 857, 860, 858, 859, 861, 862, 863, 864, 865, 866, - /* 270 */ 867, 889, 868, 870, 899, 900, 880, 882, + /* 0 */ 766, 227, 249, 336, 336, 336, 336, 350, 336, 336, + /* 10 */ 166, 434, 459, 430, 459, 459, 459, 459, 459, 459, + /* 20 */ 459, 459, 459, 459, 459, 459, 459, 459, 459, 459, + /* 30 */ 459, 459, 228, 228, 228, 465, 465, 61, 61, 37, + /* 40 */ 139, 139, 146, 238, 139, 139, 238, 139, 238, 238, + /* 50 */ 238, 139, 179, 0, 13, 13, 465, 390, 58, 58, + /* 60 */ 58, 5, 153, 238, 238, 247, 51, 714, 764, 393, + /* 70 */ 245, 186, 273, 223, 273, 418, 244, 101, 284, 452, + /* 80 */ 380, 382, 436, 436, 380, 382, 436, 443, 446, 477, + /* 90 */ 472, 482, 568, 582, 516, 563, 491, 506, 517, 238, + /* 100 */ 611, 146, 611, 146, 625, 625, 247, 179, 568, 610, + /* 110 */ 611, 179, 625, 905, 905, 905, 30, 52, 801, 806, + /* 120 */ 814, 814, 814, 814, 814, 814, 814, 142, 317, 545, + /* 130 */ 775, 296, 376, 72, 72, 72, 72, 217, 369, 412, + /* 140 */ 431, 229, 323, 301, 253, 444, 463, 461, 466, 471, + /* 150 */ 500, 515, 519, 540, 550, 162, 618, 627, 583, 639, + /* 160 */ 640, 642, 638, 646, 653, 654, 658, 655, 659, 694, + /* 170 */ 660, 665, 667, 668, 624, 672, 680, 675, 645, 687, + /* 180 */ 690, 753, 664, 702, 703, 699, 656, 765, 741, 742, + /* 190 */ 743, 744, 754, 756, 718, 729, 787, 789, 792, 793, + /* 200 */ 745, 732, 797, 799, 804, 810, 811, 812, 823, 786, + /* 210 */ 825, 832, 833, 835, 836, 816, 838, 818, 821, 784, + /* 220 */ 780, 779, 781, 826, 791, 783, 794, 815, 820, 796, + /* 230 */ 798, 822, 800, 802, 829, 805, 803, 830, 808, 809, + /* 240 */ 834, 813, 772, 776, 777, 788, 847, 807, 819, 824, + /* 250 */ 840, 842, 851, 837, 841, 848, 850, 853, 854, 855, + /* 260 */ 856, 857, 859, 858, 860, 861, 862, 863, 864, 867, + /* 270 */ 868, 869, 888, 870, 872, 901, 902, 882, 884, }; #define YY_REDUCE_COUNT (115) -#define YY_REDUCE_MIN (-184) -#define YY_REDUCE_MAX (637) +#define YY_REDUCE_MIN (-169) +#define YY_REDUCE_MAX (626) static const short yy_reduce_ofst[] = { - /* 0 */ 349, -18, 14, 59, -122, 75, 100, 132, 233, 254, - /* 10 */ 270, 330, -2, 44, 202, 385, 400, 416, 439, 452, - /* 20 */ 470, 485, 500, 517, 532, 547, 562, 577, 594, 607, - /* 30 */ 622, 637, 257, -119, 632, -151, -143, -135, -17, 79, - /* 40 */ -106, -97, 189, -132, 164, 186, -152, 249, -39, 143, - /* 50 */ 166, 279, 307, -168, -168, -168, -105, 41, 95, 157, - /* 60 */ 176, -12, 292, 96, 234, 133, -150, -184, 107, 70, - /* 70 */ 207, 236, 183, 183, 183, 290, 213, 240, 336, 325, - /* 80 */ 318, 320, 366, 368, 339, 348, 379, 333, 367, 370, - /* 90 */ 381, 183, 425, 434, 426, 455, 412, 431, 442, 290, - /* 100 */ 509, 516, 519, 518, 534, 539, 520, 537, 526, 540, - /* 110 */ 545, 557, 552, 544, 554, 556, + /* 0 */ 108, -19, 17, 59, -123, 33, 75, 184, 126, 234, + /* 10 */ 250, 307, 338, -3, 165, 110, 371, 394, 409, 424, + /* 20 */ 440, 455, 470, 483, 496, 511, 524, 539, 552, 565, + /* 30 */ 580, 596, 237, -120, 626, -152, -144, -136, -18, 27, + /* 40 */ -107, -98, 104, -133, 164, 200, -153, 232, 167, 14, + /* 50 */ 242, 305, 152, -169, -169, -169, -106, -21, 192, 212, + /* 60 */ 271, -13, 7, 20, 47, 107, -151, -118, 135, 154, + /* 70 */ 170, 220, 256, 256, 256, 295, 240, 280, 342, 327, + /* 80 */ 306, 312, 368, 388, 345, 363, 400, 375, 391, 384, + /* 90 */ 405, 256, 449, 450, 451, 453, 421, 432, 439, 295, + /* 100 */ 507, 512, 508, 513, 525, 528, 521, 531, 505, 520, + /* 110 */ 535, 537, 546, 538, 542, 548, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 10 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 20 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 30 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 40 */ 674, 674, 697, 674, 674, 674, 674, 674, 674, 674, - /* 50 */ 674, 674, 695, 674, 832, 674, 674, 674, 843, 843, - /* 60 */ 843, 697, 695, 674, 674, 760, 674, 907, 674, 674, - /* 70 */ 867, 859, 835, 849, 836, 674, 892, 852, 674, 674, - /* 80 */ 874, 872, 674, 674, 874, 872, 674, 886, 882, 865, - /* 90 */ 863, 849, 674, 674, 674, 674, 910, 898, 894, 674, - /* 100 */ 674, 697, 674, 697, 674, 674, 674, 695, 674, 729, - /* 110 */ 674, 695, 674, 763, 763, 698, 674, 674, 674, 674, - /* 120 */ 885, 884, 809, 808, 807, 803, 804, 674, 674, 674, - /* 130 */ 674, 674, 674, 798, 799, 797, 796, 674, 674, 833, - /* 140 */ 674, 674, 674, 895, 899, 674, 785, 674, 674, 674, - /* 150 */ 674, 674, 674, 674, 674, 674, 856, 866, 674, 674, - /* 160 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 170 */ 674, 785, 674, 883, 674, 842, 838, 674, 674, 834, - /* 180 */ 674, 828, 674, 674, 674, 893, 674, 674, 674, 674, - /* 190 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 200 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 210 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 220 */ 784, 674, 674, 674, 674, 674, 674, 674, 757, 674, - /* 230 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 240 */ 674, 742, 740, 739, 738, 674, 735, 674, 674, 674, - /* 250 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 260 */ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674, - /* 270 */ 674, 674, 674, 674, 674, 674, 674, 674, + /* 0 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 10 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 20 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 30 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 40 */ 676, 676, 699, 676, 676, 676, 676, 676, 676, 676, + /* 50 */ 676, 676, 697, 676, 835, 676, 676, 676, 846, 846, + /* 60 */ 846, 699, 697, 676, 676, 762, 676, 676, 910, 676, + /* 70 */ 870, 862, 838, 852, 839, 676, 895, 855, 676, 676, + /* 80 */ 877, 875, 676, 676, 877, 875, 676, 889, 885, 868, + /* 90 */ 866, 852, 676, 676, 676, 676, 913, 901, 897, 676, + /* 100 */ 676, 699, 676, 699, 676, 676, 676, 697, 676, 731, + /* 110 */ 676, 697, 676, 765, 765, 700, 676, 676, 676, 676, + /* 120 */ 888, 887, 812, 811, 810, 806, 807, 676, 676, 676, + /* 130 */ 676, 676, 676, 801, 802, 800, 799, 676, 676, 836, + /* 140 */ 676, 676, 676, 898, 902, 676, 788, 676, 676, 676, + /* 150 */ 676, 676, 676, 676, 676, 676, 859, 869, 676, 676, + /* 160 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 170 */ 676, 788, 676, 886, 676, 845, 841, 676, 676, 837, + /* 180 */ 676, 831, 676, 676, 676, 896, 676, 676, 676, 676, + /* 190 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 200 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 210 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 220 */ 676, 787, 676, 676, 676, 676, 676, 676, 676, 759, + /* 230 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 240 */ 676, 676, 744, 742, 741, 740, 676, 737, 676, 676, + /* 250 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 260 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, 676, + /* 270 */ 676, 676, 676, 676, 676, 676, 676, 676, 676, }; /********** End of lemon-generated parsing tables *****************************/ @@ -679,128 +679,129 @@ static const char *const yyTokenName[] = { /* 83 */ "VARBINARY", /* 84 */ "DECIMAL", /* 85 */ "SMA", - /* 86 */ "NK_FLOAT", - /* 87 */ "NK_BOOL", - /* 88 */ "NK_VARIABLE", - /* 89 */ "BETWEEN", - /* 90 */ "IS", - /* 91 */ "NULL", - /* 92 */ "NK_LT", - /* 93 */ "NK_GT", - /* 94 */ "NK_LE", - /* 95 */ "NK_GE", - /* 96 */ "NK_NE", - /* 97 */ "NK_EQ", - /* 98 */ "LIKE", - /* 99 */ "MATCH", - /* 100 */ "NMATCH", - /* 101 */ "IN", - /* 102 */ "FROM", - /* 103 */ "AS", - /* 104 */ "JOIN", - /* 105 */ "ON", - /* 106 */ "INNER", - /* 107 */ "SELECT", - /* 108 */ "DISTINCT", - /* 109 */ "WHERE", - /* 110 */ "PARTITION", - /* 111 */ "BY", - /* 112 */ "SESSION", - /* 113 */ "STATE_WINDOW", - /* 114 */ "INTERVAL", - /* 115 */ "SLIDING", - /* 116 */ "FILL", - /* 117 */ "VALUE", - /* 118 */ "NONE", - /* 119 */ "PREV", - /* 120 */ "LINEAR", - /* 121 */ "NEXT", - /* 122 */ "GROUP", - /* 123 */ "HAVING", - /* 124 */ "ORDER", - /* 125 */ "SLIMIT", - /* 126 */ "SOFFSET", - /* 127 */ "LIMIT", - /* 128 */ "OFFSET", - /* 129 */ "ASC", - /* 130 */ "DESC", - /* 131 */ "NULLS", - /* 132 */ "FIRST", - /* 133 */ "LAST", - /* 134 */ "cmd", - /* 135 */ "user_name", - /* 136 */ "dnode_endpoint", - /* 137 */ "dnode_host_name", - /* 138 */ "not_exists_opt", - /* 139 */ "db_name", - /* 140 */ "db_options", - /* 141 */ "exists_opt", - /* 142 */ "full_table_name", - /* 143 */ "column_def_list", - /* 144 */ "tags_def_opt", - /* 145 */ "table_options", - /* 146 */ "multi_create_clause", - /* 147 */ "tags_def", - /* 148 */ "multi_drop_clause", - /* 149 */ "create_subtable_clause", - /* 150 */ "specific_tags_opt", - /* 151 */ "literal_list", - /* 152 */ "drop_table_clause", - /* 153 */ "col_name_list", - /* 154 */ "table_name", - /* 155 */ "column_def", - /* 156 */ "column_name", - /* 157 */ "type_name", - /* 158 */ "col_name", - /* 159 */ "query_expression", - /* 160 */ "literal", - /* 161 */ "duration_literal", - /* 162 */ "function_name", - /* 163 */ "table_alias", - /* 164 */ "column_alias", - /* 165 */ "expression", - /* 166 */ "column_reference", - /* 167 */ "expression_list", - /* 168 */ "subquery", - /* 169 */ "predicate", - /* 170 */ "compare_op", - /* 171 */ "in_op", - /* 172 */ "in_predicate_value", - /* 173 */ "boolean_value_expression", - /* 174 */ "boolean_primary", - /* 175 */ "common_expression", - /* 176 */ "from_clause", - /* 177 */ "table_reference_list", - /* 178 */ "table_reference", - /* 179 */ "table_primary", - /* 180 */ "joined_table", - /* 181 */ "alias_opt", - /* 182 */ "parenthesized_joined_table", - /* 183 */ "join_type", - /* 184 */ "search_condition", - /* 185 */ "query_specification", - /* 186 */ "set_quantifier_opt", - /* 187 */ "select_list", - /* 188 */ "where_clause_opt", - /* 189 */ "partition_by_clause_opt", - /* 190 */ "twindow_clause_opt", - /* 191 */ "group_by_clause_opt", - /* 192 */ "having_clause_opt", - /* 193 */ "select_sublist", - /* 194 */ "select_item", - /* 195 */ "sliding_opt", - /* 196 */ "fill_opt", - /* 197 */ "fill_mode", - /* 198 */ "group_by_list", - /* 199 */ "query_expression_body", - /* 200 */ "order_by_clause_opt", - /* 201 */ "slimit_clause_opt", - /* 202 */ "limit_clause_opt", - /* 203 */ "query_primary", - /* 204 */ "sort_specification_list", - /* 205 */ "sort_specification", - /* 206 */ "ordering_specification_opt", - /* 207 */ "null_ordering_opt", + /* 86 */ "MNODES", + /* 87 */ "NK_FLOAT", + /* 88 */ "NK_BOOL", + /* 89 */ "NK_VARIABLE", + /* 90 */ "BETWEEN", + /* 91 */ "IS", + /* 92 */ "NULL", + /* 93 */ "NK_LT", + /* 94 */ "NK_GT", + /* 95 */ "NK_LE", + /* 96 */ "NK_GE", + /* 97 */ "NK_NE", + /* 98 */ "NK_EQ", + /* 99 */ "LIKE", + /* 100 */ "MATCH", + /* 101 */ "NMATCH", + /* 102 */ "IN", + /* 103 */ "FROM", + /* 104 */ "AS", + /* 105 */ "JOIN", + /* 106 */ "ON", + /* 107 */ "INNER", + /* 108 */ "SELECT", + /* 109 */ "DISTINCT", + /* 110 */ "WHERE", + /* 111 */ "PARTITION", + /* 112 */ "BY", + /* 113 */ "SESSION", + /* 114 */ "STATE_WINDOW", + /* 115 */ "INTERVAL", + /* 116 */ "SLIDING", + /* 117 */ "FILL", + /* 118 */ "VALUE", + /* 119 */ "NONE", + /* 120 */ "PREV", + /* 121 */ "LINEAR", + /* 122 */ "NEXT", + /* 123 */ "GROUP", + /* 124 */ "HAVING", + /* 125 */ "ORDER", + /* 126 */ "SLIMIT", + /* 127 */ "SOFFSET", + /* 128 */ "LIMIT", + /* 129 */ "OFFSET", + /* 130 */ "ASC", + /* 131 */ "DESC", + /* 132 */ "NULLS", + /* 133 */ "FIRST", + /* 134 */ "LAST", + /* 135 */ "cmd", + /* 136 */ "user_name", + /* 137 */ "dnode_endpoint", + /* 138 */ "dnode_host_name", + /* 139 */ "not_exists_opt", + /* 140 */ "db_name", + /* 141 */ "db_options", + /* 142 */ "exists_opt", + /* 143 */ "full_table_name", + /* 144 */ "column_def_list", + /* 145 */ "tags_def_opt", + /* 146 */ "table_options", + /* 147 */ "multi_create_clause", + /* 148 */ "tags_def", + /* 149 */ "multi_drop_clause", + /* 150 */ "create_subtable_clause", + /* 151 */ "specific_tags_opt", + /* 152 */ "literal_list", + /* 153 */ "drop_table_clause", + /* 154 */ "col_name_list", + /* 155 */ "table_name", + /* 156 */ "column_def", + /* 157 */ "column_name", + /* 158 */ "type_name", + /* 159 */ "col_name", + /* 160 */ "query_expression", + /* 161 */ "literal", + /* 162 */ "duration_literal", + /* 163 */ "function_name", + /* 164 */ "table_alias", + /* 165 */ "column_alias", + /* 166 */ "expression", + /* 167 */ "column_reference", + /* 168 */ "expression_list", + /* 169 */ "subquery", + /* 170 */ "predicate", + /* 171 */ "compare_op", + /* 172 */ "in_op", + /* 173 */ "in_predicate_value", + /* 174 */ "boolean_value_expression", + /* 175 */ "boolean_primary", + /* 176 */ "common_expression", + /* 177 */ "from_clause", + /* 178 */ "table_reference_list", + /* 179 */ "table_reference", + /* 180 */ "table_primary", + /* 181 */ "joined_table", + /* 182 */ "alias_opt", + /* 183 */ "parenthesized_joined_table", + /* 184 */ "join_type", + /* 185 */ "search_condition", + /* 186 */ "query_specification", + /* 187 */ "set_quantifier_opt", + /* 188 */ "select_list", + /* 189 */ "where_clause_opt", + /* 190 */ "partition_by_clause_opt", + /* 191 */ "twindow_clause_opt", + /* 192 */ "group_by_clause_opt", + /* 193 */ "having_clause_opt", + /* 194 */ "select_sublist", + /* 195 */ "select_item", + /* 196 */ "sliding_opt", + /* 197 */ "fill_opt", + /* 198 */ "fill_mode", + /* 199 */ "group_by_list", + /* 200 */ "query_expression_body", + /* 201 */ "order_by_clause_opt", + /* 202 */ "slimit_clause_opt", + /* 203 */ "limit_clause_opt", + /* 204 */ "query_primary", + /* 205 */ "sort_specification_list", + /* 206 */ "sort_specification", + /* 207 */ "ordering_specification_opt", + /* 208 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -904,146 +905,147 @@ static const char *const yyRuleName[] = { /* 93 */ "col_name ::= column_name", /* 94 */ "cmd ::= SHOW VGROUPS", /* 95 */ "cmd ::= SHOW db_name NK_DOT VGROUPS", - /* 96 */ "cmd ::= query_expression", - /* 97 */ "literal ::= NK_INTEGER", - /* 98 */ "literal ::= NK_FLOAT", - /* 99 */ "literal ::= NK_STRING", - /* 100 */ "literal ::= NK_BOOL", - /* 101 */ "literal ::= TIMESTAMP NK_STRING", - /* 102 */ "literal ::= duration_literal", - /* 103 */ "duration_literal ::= NK_VARIABLE", - /* 104 */ "literal_list ::= literal", - /* 105 */ "literal_list ::= literal_list NK_COMMA literal", - /* 106 */ "db_name ::= NK_ID", - /* 107 */ "table_name ::= NK_ID", - /* 108 */ "column_name ::= NK_ID", - /* 109 */ "function_name ::= NK_ID", - /* 110 */ "table_alias ::= NK_ID", - /* 111 */ "column_alias ::= NK_ID", - /* 112 */ "user_name ::= NK_ID", - /* 113 */ "expression ::= literal", - /* 114 */ "expression ::= column_reference", - /* 115 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 116 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 117 */ "expression ::= subquery", - /* 118 */ "expression ::= NK_LP expression NK_RP", - /* 119 */ "expression ::= NK_PLUS expression", - /* 120 */ "expression ::= NK_MINUS expression", - /* 121 */ "expression ::= expression NK_PLUS expression", - /* 122 */ "expression ::= expression NK_MINUS expression", - /* 123 */ "expression ::= expression NK_STAR expression", - /* 124 */ "expression ::= expression NK_SLASH expression", - /* 125 */ "expression ::= expression NK_REM expression", - /* 126 */ "expression_list ::= expression", - /* 127 */ "expression_list ::= expression_list NK_COMMA expression", - /* 128 */ "column_reference ::= column_name", - /* 129 */ "column_reference ::= table_name NK_DOT column_name", - /* 130 */ "predicate ::= expression compare_op expression", - /* 131 */ "predicate ::= expression BETWEEN expression AND expression", - /* 132 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 133 */ "predicate ::= expression IS NULL", - /* 134 */ "predicate ::= expression IS NOT NULL", - /* 135 */ "predicate ::= expression in_op in_predicate_value", - /* 136 */ "compare_op ::= NK_LT", - /* 137 */ "compare_op ::= NK_GT", - /* 138 */ "compare_op ::= NK_LE", - /* 139 */ "compare_op ::= NK_GE", - /* 140 */ "compare_op ::= NK_NE", - /* 141 */ "compare_op ::= NK_EQ", - /* 142 */ "compare_op ::= LIKE", - /* 143 */ "compare_op ::= NOT LIKE", - /* 144 */ "compare_op ::= MATCH", - /* 145 */ "compare_op ::= NMATCH", - /* 146 */ "in_op ::= IN", - /* 147 */ "in_op ::= NOT IN", - /* 148 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 149 */ "boolean_value_expression ::= boolean_primary", - /* 150 */ "boolean_value_expression ::= NOT boolean_primary", - /* 151 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 152 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 153 */ "boolean_primary ::= predicate", - /* 154 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 155 */ "common_expression ::= expression", - /* 156 */ "common_expression ::= boolean_value_expression", - /* 157 */ "from_clause ::= FROM table_reference_list", - /* 158 */ "table_reference_list ::= table_reference", - /* 159 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 160 */ "table_reference ::= table_primary", - /* 161 */ "table_reference ::= joined_table", - /* 162 */ "table_primary ::= table_name alias_opt", - /* 163 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 164 */ "table_primary ::= subquery alias_opt", - /* 165 */ "table_primary ::= parenthesized_joined_table", - /* 166 */ "alias_opt ::=", - /* 167 */ "alias_opt ::= table_alias", - /* 168 */ "alias_opt ::= AS table_alias", - /* 169 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 170 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 171 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 172 */ "join_type ::=", - /* 173 */ "join_type ::= INNER", - /* 174 */ "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", - /* 175 */ "set_quantifier_opt ::=", - /* 176 */ "set_quantifier_opt ::= DISTINCT", - /* 177 */ "set_quantifier_opt ::= ALL", - /* 178 */ "select_list ::= NK_STAR", - /* 179 */ "select_list ::= select_sublist", - /* 180 */ "select_sublist ::= select_item", - /* 181 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 182 */ "select_item ::= common_expression", - /* 183 */ "select_item ::= common_expression column_alias", - /* 184 */ "select_item ::= common_expression AS column_alias", - /* 185 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 186 */ "where_clause_opt ::=", - /* 187 */ "where_clause_opt ::= WHERE search_condition", - /* 188 */ "partition_by_clause_opt ::=", - /* 189 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 190 */ "twindow_clause_opt ::=", - /* 191 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", - /* 192 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 193 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 194 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 195 */ "sliding_opt ::=", - /* 196 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 197 */ "fill_opt ::=", - /* 198 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 199 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 200 */ "fill_mode ::= NONE", - /* 201 */ "fill_mode ::= PREV", - /* 202 */ "fill_mode ::= NULL", - /* 203 */ "fill_mode ::= LINEAR", - /* 204 */ "fill_mode ::= NEXT", - /* 205 */ "group_by_clause_opt ::=", - /* 206 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 207 */ "group_by_list ::= expression", - /* 208 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 209 */ "having_clause_opt ::=", - /* 210 */ "having_clause_opt ::= HAVING search_condition", - /* 211 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 212 */ "query_expression_body ::= query_primary", - /* 213 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 214 */ "query_primary ::= query_specification", - /* 215 */ "order_by_clause_opt ::=", - /* 216 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 217 */ "slimit_clause_opt ::=", - /* 218 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 219 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 220 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 221 */ "limit_clause_opt ::=", - /* 222 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 223 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 224 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 225 */ "subquery ::= NK_LP query_expression NK_RP", - /* 226 */ "search_condition ::= common_expression", - /* 227 */ "sort_specification_list ::= sort_specification", - /* 228 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 229 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 230 */ "ordering_specification_opt ::=", - /* 231 */ "ordering_specification_opt ::= ASC", - /* 232 */ "ordering_specification_opt ::= DESC", - /* 233 */ "null_ordering_opt ::=", - /* 234 */ "null_ordering_opt ::= NULLS FIRST", - /* 235 */ "null_ordering_opt ::= NULLS LAST", + /* 96 */ "cmd ::= SHOW MNODES", + /* 97 */ "cmd ::= query_expression", + /* 98 */ "literal ::= NK_INTEGER", + /* 99 */ "literal ::= NK_FLOAT", + /* 100 */ "literal ::= NK_STRING", + /* 101 */ "literal ::= NK_BOOL", + /* 102 */ "literal ::= TIMESTAMP NK_STRING", + /* 103 */ "literal ::= duration_literal", + /* 104 */ "duration_literal ::= NK_VARIABLE", + /* 105 */ "literal_list ::= literal", + /* 106 */ "literal_list ::= literal_list NK_COMMA literal", + /* 107 */ "db_name ::= NK_ID", + /* 108 */ "table_name ::= NK_ID", + /* 109 */ "column_name ::= NK_ID", + /* 110 */ "function_name ::= NK_ID", + /* 111 */ "table_alias ::= NK_ID", + /* 112 */ "column_alias ::= NK_ID", + /* 113 */ "user_name ::= NK_ID", + /* 114 */ "expression ::= literal", + /* 115 */ "expression ::= column_reference", + /* 116 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 117 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 118 */ "expression ::= subquery", + /* 119 */ "expression ::= NK_LP expression NK_RP", + /* 120 */ "expression ::= NK_PLUS expression", + /* 121 */ "expression ::= NK_MINUS expression", + /* 122 */ "expression ::= expression NK_PLUS expression", + /* 123 */ "expression ::= expression NK_MINUS expression", + /* 124 */ "expression ::= expression NK_STAR expression", + /* 125 */ "expression ::= expression NK_SLASH expression", + /* 126 */ "expression ::= expression NK_REM expression", + /* 127 */ "expression_list ::= expression", + /* 128 */ "expression_list ::= expression_list NK_COMMA expression", + /* 129 */ "column_reference ::= column_name", + /* 130 */ "column_reference ::= table_name NK_DOT column_name", + /* 131 */ "predicate ::= expression compare_op expression", + /* 132 */ "predicate ::= expression BETWEEN expression AND expression", + /* 133 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 134 */ "predicate ::= expression IS NULL", + /* 135 */ "predicate ::= expression IS NOT NULL", + /* 136 */ "predicate ::= expression in_op in_predicate_value", + /* 137 */ "compare_op ::= NK_LT", + /* 138 */ "compare_op ::= NK_GT", + /* 139 */ "compare_op ::= NK_LE", + /* 140 */ "compare_op ::= NK_GE", + /* 141 */ "compare_op ::= NK_NE", + /* 142 */ "compare_op ::= NK_EQ", + /* 143 */ "compare_op ::= LIKE", + /* 144 */ "compare_op ::= NOT LIKE", + /* 145 */ "compare_op ::= MATCH", + /* 146 */ "compare_op ::= NMATCH", + /* 147 */ "in_op ::= IN", + /* 148 */ "in_op ::= NOT IN", + /* 149 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 150 */ "boolean_value_expression ::= boolean_primary", + /* 151 */ "boolean_value_expression ::= NOT boolean_primary", + /* 152 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 153 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 154 */ "boolean_primary ::= predicate", + /* 155 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 156 */ "common_expression ::= expression", + /* 157 */ "common_expression ::= boolean_value_expression", + /* 158 */ "from_clause ::= FROM table_reference_list", + /* 159 */ "table_reference_list ::= table_reference", + /* 160 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 161 */ "table_reference ::= table_primary", + /* 162 */ "table_reference ::= joined_table", + /* 163 */ "table_primary ::= table_name alias_opt", + /* 164 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 165 */ "table_primary ::= subquery alias_opt", + /* 166 */ "table_primary ::= parenthesized_joined_table", + /* 167 */ "alias_opt ::=", + /* 168 */ "alias_opt ::= table_alias", + /* 169 */ "alias_opt ::= AS table_alias", + /* 170 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 171 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 172 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 173 */ "join_type ::=", + /* 174 */ "join_type ::= INNER", + /* 175 */ "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", + /* 176 */ "set_quantifier_opt ::=", + /* 177 */ "set_quantifier_opt ::= DISTINCT", + /* 178 */ "set_quantifier_opt ::= ALL", + /* 179 */ "select_list ::= NK_STAR", + /* 180 */ "select_list ::= select_sublist", + /* 181 */ "select_sublist ::= select_item", + /* 182 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 183 */ "select_item ::= common_expression", + /* 184 */ "select_item ::= common_expression column_alias", + /* 185 */ "select_item ::= common_expression AS column_alias", + /* 186 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 187 */ "where_clause_opt ::=", + /* 188 */ "where_clause_opt ::= WHERE search_condition", + /* 189 */ "partition_by_clause_opt ::=", + /* 190 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 191 */ "twindow_clause_opt ::=", + /* 192 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", + /* 193 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 194 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 195 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 196 */ "sliding_opt ::=", + /* 197 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 198 */ "fill_opt ::=", + /* 199 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 200 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 201 */ "fill_mode ::= NONE", + /* 202 */ "fill_mode ::= PREV", + /* 203 */ "fill_mode ::= NULL", + /* 204 */ "fill_mode ::= LINEAR", + /* 205 */ "fill_mode ::= NEXT", + /* 206 */ "group_by_clause_opt ::=", + /* 207 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 208 */ "group_by_list ::= expression", + /* 209 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 210 */ "having_clause_opt ::=", + /* 211 */ "having_clause_opt ::= HAVING search_condition", + /* 212 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 213 */ "query_expression_body ::= query_primary", + /* 214 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 215 */ "query_primary ::= query_specification", + /* 216 */ "order_by_clause_opt ::=", + /* 217 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 218 */ "slimit_clause_opt ::=", + /* 219 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 220 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 221 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 222 */ "limit_clause_opt ::=", + /* 223 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 224 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 225 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 226 */ "subquery ::= NK_LP query_expression NK_RP", + /* 227 */ "search_condition ::= common_expression", + /* 228 */ "sort_specification_list ::= sort_specification", + /* 229 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 230 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 231 */ "ordering_specification_opt ::=", + /* 232 */ "ordering_specification_opt ::= ASC", + /* 233 */ "ordering_specification_opt ::= DESC", + /* 234 */ "null_ordering_opt ::=", + /* 235 */ "null_ordering_opt ::= NULLS FIRST", + /* 236 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1170,124 +1172,124 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 134: /* cmd */ - case 142: /* full_table_name */ - case 149: /* create_subtable_clause */ - case 152: /* drop_table_clause */ - case 155: /* column_def */ - case 158: /* col_name */ - case 159: /* query_expression */ - case 160: /* literal */ - case 161: /* duration_literal */ - case 165: /* expression */ - case 166: /* column_reference */ - case 168: /* subquery */ - case 169: /* predicate */ - case 172: /* in_predicate_value */ - case 173: /* boolean_value_expression */ - case 174: /* boolean_primary */ - case 175: /* common_expression */ - case 176: /* from_clause */ - case 177: /* table_reference_list */ - case 178: /* table_reference */ - case 179: /* table_primary */ - case 180: /* joined_table */ - case 182: /* parenthesized_joined_table */ - case 184: /* search_condition */ - case 185: /* query_specification */ - case 188: /* where_clause_opt */ - case 190: /* twindow_clause_opt */ - case 192: /* having_clause_opt */ - case 194: /* select_item */ - case 195: /* sliding_opt */ - case 196: /* fill_opt */ - case 199: /* query_expression_body */ - case 201: /* slimit_clause_opt */ - case 202: /* limit_clause_opt */ - case 203: /* query_primary */ - case 205: /* sort_specification */ + case 135: /* cmd */ + case 143: /* full_table_name */ + case 150: /* create_subtable_clause */ + case 153: /* drop_table_clause */ + case 156: /* column_def */ + case 159: /* col_name */ + case 160: /* query_expression */ + case 161: /* literal */ + case 162: /* duration_literal */ + case 166: /* expression */ + case 167: /* column_reference */ + case 169: /* subquery */ + case 170: /* predicate */ + case 173: /* in_predicate_value */ + case 174: /* boolean_value_expression */ + case 175: /* boolean_primary */ + case 176: /* common_expression */ + case 177: /* from_clause */ + case 178: /* table_reference_list */ + case 179: /* table_reference */ + case 180: /* table_primary */ + case 181: /* joined_table */ + case 183: /* parenthesized_joined_table */ + case 185: /* search_condition */ + case 186: /* query_specification */ + case 189: /* where_clause_opt */ + case 191: /* twindow_clause_opt */ + case 193: /* having_clause_opt */ + case 195: /* select_item */ + case 196: /* sliding_opt */ + case 197: /* fill_opt */ + case 200: /* query_expression_body */ + case 202: /* slimit_clause_opt */ + case 203: /* limit_clause_opt */ + case 204: /* query_primary */ + case 206: /* sort_specification */ { - nodesDestroyNode((yypminor->yy392)); + nodesDestroyNode((yypminor->yy256)); } break; - case 135: /* user_name */ - case 136: /* dnode_endpoint */ - case 137: /* dnode_host_name */ - case 139: /* db_name */ - case 154: /* table_name */ - case 156: /* column_name */ - case 162: /* function_name */ - case 163: /* table_alias */ - case 164: /* column_alias */ - case 181: /* alias_opt */ + case 136: /* user_name */ + case 137: /* dnode_endpoint */ + case 138: /* dnode_host_name */ + case 140: /* db_name */ + case 155: /* table_name */ + case 157: /* column_name */ + case 163: /* function_name */ + case 164: /* table_alias */ + case 165: /* column_alias */ + case 182: /* alias_opt */ { } break; - case 138: /* not_exists_opt */ - case 141: /* exists_opt */ - case 186: /* set_quantifier_opt */ + case 139: /* not_exists_opt */ + case 142: /* exists_opt */ + case 187: /* set_quantifier_opt */ { } break; - case 140: /* db_options */ + case 141: /* db_options */ { - tfree((yypminor->yy103)); + tfree((yypminor->yy391)); } break; - case 143: /* column_def_list */ - case 144: /* tags_def_opt */ - case 146: /* multi_create_clause */ - case 147: /* tags_def */ - case 148: /* multi_drop_clause */ - case 150: /* specific_tags_opt */ - case 151: /* literal_list */ - case 153: /* col_name_list */ - case 167: /* expression_list */ - case 187: /* select_list */ - case 189: /* partition_by_clause_opt */ - case 191: /* group_by_clause_opt */ - case 193: /* select_sublist */ - case 198: /* group_by_list */ - case 200: /* order_by_clause_opt */ - case 204: /* sort_specification_list */ + case 144: /* column_def_list */ + case 145: /* tags_def_opt */ + case 147: /* multi_create_clause */ + case 148: /* tags_def */ + case 149: /* multi_drop_clause */ + case 151: /* specific_tags_opt */ + case 152: /* literal_list */ + case 154: /* col_name_list */ + case 168: /* expression_list */ + case 188: /* select_list */ + case 190: /* partition_by_clause_opt */ + case 192: /* group_by_clause_opt */ + case 194: /* select_sublist */ + case 199: /* group_by_list */ + case 201: /* order_by_clause_opt */ + case 205: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy184)); + nodesDestroyList((yypminor->yy46)); } break; - case 145: /* table_options */ + case 146: /* table_options */ { - tfree((yypminor->yy334)); + tfree((yypminor->yy340)); } break; - case 157: /* type_name */ + case 158: /* type_name */ { } break; - case 170: /* compare_op */ - case 171: /* in_op */ + case 171: /* compare_op */ + case 172: /* in_op */ { } break; - case 183: /* join_type */ + case 184: /* join_type */ { } break; - case 197: /* fill_mode */ + case 198: /* fill_mode */ { } break; - case 206: /* ordering_specification_opt */ + case 207: /* ordering_specification_opt */ { } break; - case 207: /* null_ordering_opt */ + case 208: /* null_ordering_opt */ { } @@ -1586,242 +1588,243 @@ 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[] = { - { 134, -5 }, /* (0) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 134, -5 }, /* (1) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 134, -5 }, /* (2) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 134, -3 }, /* (3) cmd ::= DROP USER user_name */ - { 134, -2 }, /* (4) cmd ::= SHOW USERS */ - { 134, -3 }, /* (5) cmd ::= CREATE DNODE dnode_endpoint */ - { 134, -5 }, /* (6) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 134, -3 }, /* (7) cmd ::= DROP DNODE NK_INTEGER */ - { 134, -3 }, /* (8) cmd ::= DROP DNODE dnode_endpoint */ - { 134, -2 }, /* (9) cmd ::= SHOW DNODES */ - { 136, -1 }, /* (10) dnode_endpoint ::= NK_STRING */ - { 137, -1 }, /* (11) dnode_host_name ::= NK_ID */ - { 137, -1 }, /* (12) dnode_host_name ::= NK_IPTOKEN */ - { 134, -5 }, /* (13) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 134, -4 }, /* (14) cmd ::= DROP DATABASE exists_opt db_name */ - { 134, -2 }, /* (15) cmd ::= SHOW DATABASES */ - { 134, -2 }, /* (16) cmd ::= USE db_name */ - { 138, -3 }, /* (17) not_exists_opt ::= IF NOT EXISTS */ - { 138, 0 }, /* (18) not_exists_opt ::= */ - { 141, -2 }, /* (19) exists_opt ::= IF EXISTS */ - { 141, 0 }, /* (20) exists_opt ::= */ - { 140, 0 }, /* (21) db_options ::= */ - { 140, -3 }, /* (22) db_options ::= db_options BLOCKS NK_INTEGER */ - { 140, -3 }, /* (23) db_options ::= db_options CACHE NK_INTEGER */ - { 140, -3 }, /* (24) db_options ::= db_options CACHELAST NK_INTEGER */ - { 140, -3 }, /* (25) db_options ::= db_options COMP NK_INTEGER */ - { 140, -3 }, /* (26) db_options ::= db_options DAYS NK_INTEGER */ - { 140, -3 }, /* (27) db_options ::= db_options FSYNC NK_INTEGER */ - { 140, -3 }, /* (28) db_options ::= db_options MAXROWS NK_INTEGER */ - { 140, -3 }, /* (29) db_options ::= db_options MINROWS NK_INTEGER */ - { 140, -3 }, /* (30) db_options ::= db_options KEEP NK_INTEGER */ - { 140, -3 }, /* (31) db_options ::= db_options PRECISION NK_STRING */ - { 140, -3 }, /* (32) db_options ::= db_options QUORUM NK_INTEGER */ - { 140, -3 }, /* (33) db_options ::= db_options REPLICA NK_INTEGER */ - { 140, -3 }, /* (34) db_options ::= db_options TTL NK_INTEGER */ - { 140, -3 }, /* (35) db_options ::= db_options WAL NK_INTEGER */ - { 140, -3 }, /* (36) db_options ::= db_options VGROUPS NK_INTEGER */ - { 140, -3 }, /* (37) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 140, -3 }, /* (38) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 134, -9 }, /* (39) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 134, -3 }, /* (40) cmd ::= CREATE TABLE multi_create_clause */ - { 134, -9 }, /* (41) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 134, -3 }, /* (42) cmd ::= DROP TABLE multi_drop_clause */ - { 134, -4 }, /* (43) cmd ::= DROP STABLE exists_opt full_table_name */ - { 134, -2 }, /* (44) cmd ::= SHOW TABLES */ - { 134, -2 }, /* (45) cmd ::= SHOW STABLES */ - { 146, -1 }, /* (46) multi_create_clause ::= create_subtable_clause */ - { 146, -2 }, /* (47) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 149, -9 }, /* (48) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 148, -1 }, /* (49) multi_drop_clause ::= drop_table_clause */ - { 148, -2 }, /* (50) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 152, -2 }, /* (51) drop_table_clause ::= exists_opt full_table_name */ - { 150, 0 }, /* (52) specific_tags_opt ::= */ - { 150, -3 }, /* (53) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 142, -1 }, /* (54) full_table_name ::= table_name */ - { 142, -3 }, /* (55) full_table_name ::= db_name NK_DOT table_name */ - { 143, -1 }, /* (56) column_def_list ::= column_def */ - { 143, -3 }, /* (57) column_def_list ::= column_def_list NK_COMMA column_def */ - { 155, -2 }, /* (58) column_def ::= column_name type_name */ - { 155, -4 }, /* (59) column_def ::= column_name type_name COMMENT NK_STRING */ - { 157, -1 }, /* (60) type_name ::= BOOL */ - { 157, -1 }, /* (61) type_name ::= TINYINT */ - { 157, -1 }, /* (62) type_name ::= SMALLINT */ - { 157, -1 }, /* (63) type_name ::= INT */ - { 157, -1 }, /* (64) type_name ::= INTEGER */ - { 157, -1 }, /* (65) type_name ::= BIGINT */ - { 157, -1 }, /* (66) type_name ::= FLOAT */ - { 157, -1 }, /* (67) type_name ::= DOUBLE */ - { 157, -4 }, /* (68) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 157, -1 }, /* (69) type_name ::= TIMESTAMP */ - { 157, -4 }, /* (70) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 157, -2 }, /* (71) type_name ::= TINYINT UNSIGNED */ - { 157, -2 }, /* (72) type_name ::= SMALLINT UNSIGNED */ - { 157, -2 }, /* (73) type_name ::= INT UNSIGNED */ - { 157, -2 }, /* (74) type_name ::= BIGINT UNSIGNED */ - { 157, -1 }, /* (75) type_name ::= JSON */ - { 157, -4 }, /* (76) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 157, -1 }, /* (77) type_name ::= MEDIUMBLOB */ - { 157, -1 }, /* (78) type_name ::= BLOB */ - { 157, -4 }, /* (79) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 157, -1 }, /* (80) type_name ::= DECIMAL */ - { 157, -4 }, /* (81) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 157, -6 }, /* (82) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 144, 0 }, /* (83) tags_def_opt ::= */ - { 144, -1 }, /* (84) tags_def_opt ::= tags_def */ - { 147, -4 }, /* (85) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 145, 0 }, /* (86) table_options ::= */ - { 145, -3 }, /* (87) table_options ::= table_options COMMENT NK_STRING */ - { 145, -3 }, /* (88) table_options ::= table_options KEEP NK_INTEGER */ - { 145, -3 }, /* (89) table_options ::= table_options TTL NK_INTEGER */ - { 145, -5 }, /* (90) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 153, -1 }, /* (91) col_name_list ::= col_name */ - { 153, -3 }, /* (92) col_name_list ::= col_name_list NK_COMMA col_name */ - { 158, -1 }, /* (93) col_name ::= column_name */ - { 134, -2 }, /* (94) cmd ::= SHOW VGROUPS */ - { 134, -4 }, /* (95) cmd ::= SHOW db_name NK_DOT VGROUPS */ - { 134, -1 }, /* (96) cmd ::= query_expression */ - { 160, -1 }, /* (97) literal ::= NK_INTEGER */ - { 160, -1 }, /* (98) literal ::= NK_FLOAT */ - { 160, -1 }, /* (99) literal ::= NK_STRING */ - { 160, -1 }, /* (100) literal ::= NK_BOOL */ - { 160, -2 }, /* (101) literal ::= TIMESTAMP NK_STRING */ - { 160, -1 }, /* (102) literal ::= duration_literal */ - { 161, -1 }, /* (103) duration_literal ::= NK_VARIABLE */ - { 151, -1 }, /* (104) literal_list ::= literal */ - { 151, -3 }, /* (105) literal_list ::= literal_list NK_COMMA literal */ - { 139, -1 }, /* (106) db_name ::= NK_ID */ - { 154, -1 }, /* (107) table_name ::= NK_ID */ - { 156, -1 }, /* (108) column_name ::= NK_ID */ - { 162, -1 }, /* (109) function_name ::= NK_ID */ - { 163, -1 }, /* (110) table_alias ::= NK_ID */ - { 164, -1 }, /* (111) column_alias ::= NK_ID */ - { 135, -1 }, /* (112) user_name ::= NK_ID */ - { 165, -1 }, /* (113) expression ::= literal */ - { 165, -1 }, /* (114) expression ::= column_reference */ - { 165, -4 }, /* (115) expression ::= function_name NK_LP expression_list NK_RP */ - { 165, -4 }, /* (116) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 165, -1 }, /* (117) expression ::= subquery */ - { 165, -3 }, /* (118) expression ::= NK_LP expression NK_RP */ - { 165, -2 }, /* (119) expression ::= NK_PLUS expression */ - { 165, -2 }, /* (120) expression ::= NK_MINUS expression */ - { 165, -3 }, /* (121) expression ::= expression NK_PLUS expression */ - { 165, -3 }, /* (122) expression ::= expression NK_MINUS expression */ - { 165, -3 }, /* (123) expression ::= expression NK_STAR expression */ - { 165, -3 }, /* (124) expression ::= expression NK_SLASH expression */ - { 165, -3 }, /* (125) expression ::= expression NK_REM expression */ - { 167, -1 }, /* (126) expression_list ::= expression */ - { 167, -3 }, /* (127) expression_list ::= expression_list NK_COMMA expression */ - { 166, -1 }, /* (128) column_reference ::= column_name */ - { 166, -3 }, /* (129) column_reference ::= table_name NK_DOT column_name */ - { 169, -3 }, /* (130) predicate ::= expression compare_op expression */ - { 169, -5 }, /* (131) predicate ::= expression BETWEEN expression AND expression */ - { 169, -6 }, /* (132) predicate ::= expression NOT BETWEEN expression AND expression */ - { 169, -3 }, /* (133) predicate ::= expression IS NULL */ - { 169, -4 }, /* (134) predicate ::= expression IS NOT NULL */ - { 169, -3 }, /* (135) predicate ::= expression in_op in_predicate_value */ - { 170, -1 }, /* (136) compare_op ::= NK_LT */ - { 170, -1 }, /* (137) compare_op ::= NK_GT */ - { 170, -1 }, /* (138) compare_op ::= NK_LE */ - { 170, -1 }, /* (139) compare_op ::= NK_GE */ - { 170, -1 }, /* (140) compare_op ::= NK_NE */ - { 170, -1 }, /* (141) compare_op ::= NK_EQ */ - { 170, -1 }, /* (142) compare_op ::= LIKE */ - { 170, -2 }, /* (143) compare_op ::= NOT LIKE */ - { 170, -1 }, /* (144) compare_op ::= MATCH */ - { 170, -1 }, /* (145) compare_op ::= NMATCH */ - { 171, -1 }, /* (146) in_op ::= IN */ - { 171, -2 }, /* (147) in_op ::= NOT IN */ - { 172, -3 }, /* (148) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 173, -1 }, /* (149) boolean_value_expression ::= boolean_primary */ - { 173, -2 }, /* (150) boolean_value_expression ::= NOT boolean_primary */ - { 173, -3 }, /* (151) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 173, -3 }, /* (152) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 174, -1 }, /* (153) boolean_primary ::= predicate */ - { 174, -3 }, /* (154) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 175, -1 }, /* (155) common_expression ::= expression */ - { 175, -1 }, /* (156) common_expression ::= boolean_value_expression */ - { 176, -2 }, /* (157) from_clause ::= FROM table_reference_list */ - { 177, -1 }, /* (158) table_reference_list ::= table_reference */ - { 177, -3 }, /* (159) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 178, -1 }, /* (160) table_reference ::= table_primary */ - { 178, -1 }, /* (161) table_reference ::= joined_table */ - { 179, -2 }, /* (162) table_primary ::= table_name alias_opt */ - { 179, -4 }, /* (163) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 179, -2 }, /* (164) table_primary ::= subquery alias_opt */ - { 179, -1 }, /* (165) table_primary ::= parenthesized_joined_table */ - { 181, 0 }, /* (166) alias_opt ::= */ - { 181, -1 }, /* (167) alias_opt ::= table_alias */ - { 181, -2 }, /* (168) alias_opt ::= AS table_alias */ - { 182, -3 }, /* (169) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 182, -3 }, /* (170) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 180, -6 }, /* (171) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 183, 0 }, /* (172) join_type ::= */ - { 183, -1 }, /* (173) join_type ::= INNER */ - { 185, -9 }, /* (174) 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 */ - { 186, 0 }, /* (175) set_quantifier_opt ::= */ - { 186, -1 }, /* (176) set_quantifier_opt ::= DISTINCT */ - { 186, -1 }, /* (177) set_quantifier_opt ::= ALL */ - { 187, -1 }, /* (178) select_list ::= NK_STAR */ - { 187, -1 }, /* (179) select_list ::= select_sublist */ - { 193, -1 }, /* (180) select_sublist ::= select_item */ - { 193, -3 }, /* (181) select_sublist ::= select_sublist NK_COMMA select_item */ - { 194, -1 }, /* (182) select_item ::= common_expression */ - { 194, -2 }, /* (183) select_item ::= common_expression column_alias */ - { 194, -3 }, /* (184) select_item ::= common_expression AS column_alias */ - { 194, -3 }, /* (185) select_item ::= table_name NK_DOT NK_STAR */ - { 188, 0 }, /* (186) where_clause_opt ::= */ - { 188, -2 }, /* (187) where_clause_opt ::= WHERE search_condition */ - { 189, 0 }, /* (188) partition_by_clause_opt ::= */ - { 189, -3 }, /* (189) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 190, 0 }, /* (190) twindow_clause_opt ::= */ - { 190, -6 }, /* (191) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ - { 190, -4 }, /* (192) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 190, -6 }, /* (193) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 190, -8 }, /* (194) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 195, 0 }, /* (195) sliding_opt ::= */ - { 195, -4 }, /* (196) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 196, 0 }, /* (197) fill_opt ::= */ - { 196, -4 }, /* (198) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 196, -6 }, /* (199) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 197, -1 }, /* (200) fill_mode ::= NONE */ - { 197, -1 }, /* (201) fill_mode ::= PREV */ - { 197, -1 }, /* (202) fill_mode ::= NULL */ - { 197, -1 }, /* (203) fill_mode ::= LINEAR */ - { 197, -1 }, /* (204) fill_mode ::= NEXT */ - { 191, 0 }, /* (205) group_by_clause_opt ::= */ - { 191, -3 }, /* (206) group_by_clause_opt ::= GROUP BY group_by_list */ - { 198, -1 }, /* (207) group_by_list ::= expression */ - { 198, -3 }, /* (208) group_by_list ::= group_by_list NK_COMMA expression */ - { 192, 0 }, /* (209) having_clause_opt ::= */ - { 192, -2 }, /* (210) having_clause_opt ::= HAVING search_condition */ - { 159, -4 }, /* (211) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 199, -1 }, /* (212) query_expression_body ::= query_primary */ - { 199, -4 }, /* (213) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 203, -1 }, /* (214) query_primary ::= query_specification */ - { 200, 0 }, /* (215) order_by_clause_opt ::= */ - { 200, -3 }, /* (216) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 201, 0 }, /* (217) slimit_clause_opt ::= */ - { 201, -2 }, /* (218) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 201, -4 }, /* (219) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 201, -4 }, /* (220) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 202, 0 }, /* (221) limit_clause_opt ::= */ - { 202, -2 }, /* (222) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 202, -4 }, /* (223) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 202, -4 }, /* (224) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 168, -3 }, /* (225) subquery ::= NK_LP query_expression NK_RP */ - { 184, -1 }, /* (226) search_condition ::= common_expression */ - { 204, -1 }, /* (227) sort_specification_list ::= sort_specification */ - { 204, -3 }, /* (228) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 205, -3 }, /* (229) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 206, 0 }, /* (230) ordering_specification_opt ::= */ - { 206, -1 }, /* (231) ordering_specification_opt ::= ASC */ - { 206, -1 }, /* (232) ordering_specification_opt ::= DESC */ - { 207, 0 }, /* (233) null_ordering_opt ::= */ - { 207, -2 }, /* (234) null_ordering_opt ::= NULLS FIRST */ - { 207, -2 }, /* (235) null_ordering_opt ::= NULLS LAST */ + { 135, -5 }, /* (0) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 135, -5 }, /* (1) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 135, -5 }, /* (2) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 135, -3 }, /* (3) cmd ::= DROP USER user_name */ + { 135, -2 }, /* (4) cmd ::= SHOW USERS */ + { 135, -3 }, /* (5) cmd ::= CREATE DNODE dnode_endpoint */ + { 135, -5 }, /* (6) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 135, -3 }, /* (7) cmd ::= DROP DNODE NK_INTEGER */ + { 135, -3 }, /* (8) cmd ::= DROP DNODE dnode_endpoint */ + { 135, -2 }, /* (9) cmd ::= SHOW DNODES */ + { 137, -1 }, /* (10) dnode_endpoint ::= NK_STRING */ + { 138, -1 }, /* (11) dnode_host_name ::= NK_ID */ + { 138, -1 }, /* (12) dnode_host_name ::= NK_IPTOKEN */ + { 135, -5 }, /* (13) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 135, -4 }, /* (14) cmd ::= DROP DATABASE exists_opt db_name */ + { 135, -2 }, /* (15) cmd ::= SHOW DATABASES */ + { 135, -2 }, /* (16) cmd ::= USE db_name */ + { 139, -3 }, /* (17) not_exists_opt ::= IF NOT EXISTS */ + { 139, 0 }, /* (18) not_exists_opt ::= */ + { 142, -2 }, /* (19) exists_opt ::= IF EXISTS */ + { 142, 0 }, /* (20) exists_opt ::= */ + { 141, 0 }, /* (21) db_options ::= */ + { 141, -3 }, /* (22) db_options ::= db_options BLOCKS NK_INTEGER */ + { 141, -3 }, /* (23) db_options ::= db_options CACHE NK_INTEGER */ + { 141, -3 }, /* (24) db_options ::= db_options CACHELAST NK_INTEGER */ + { 141, -3 }, /* (25) db_options ::= db_options COMP NK_INTEGER */ + { 141, -3 }, /* (26) db_options ::= db_options DAYS NK_INTEGER */ + { 141, -3 }, /* (27) db_options ::= db_options FSYNC NK_INTEGER */ + { 141, -3 }, /* (28) db_options ::= db_options MAXROWS NK_INTEGER */ + { 141, -3 }, /* (29) db_options ::= db_options MINROWS NK_INTEGER */ + { 141, -3 }, /* (30) db_options ::= db_options KEEP NK_INTEGER */ + { 141, -3 }, /* (31) db_options ::= db_options PRECISION NK_STRING */ + { 141, -3 }, /* (32) db_options ::= db_options QUORUM NK_INTEGER */ + { 141, -3 }, /* (33) db_options ::= db_options REPLICA NK_INTEGER */ + { 141, -3 }, /* (34) db_options ::= db_options TTL NK_INTEGER */ + { 141, -3 }, /* (35) db_options ::= db_options WAL NK_INTEGER */ + { 141, -3 }, /* (36) db_options ::= db_options VGROUPS NK_INTEGER */ + { 141, -3 }, /* (37) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 141, -3 }, /* (38) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 135, -9 }, /* (39) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 135, -3 }, /* (40) cmd ::= CREATE TABLE multi_create_clause */ + { 135, -9 }, /* (41) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 135, -3 }, /* (42) cmd ::= DROP TABLE multi_drop_clause */ + { 135, -4 }, /* (43) cmd ::= DROP STABLE exists_opt full_table_name */ + { 135, -2 }, /* (44) cmd ::= SHOW TABLES */ + { 135, -2 }, /* (45) cmd ::= SHOW STABLES */ + { 147, -1 }, /* (46) multi_create_clause ::= create_subtable_clause */ + { 147, -2 }, /* (47) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 150, -9 }, /* (48) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 149, -1 }, /* (49) multi_drop_clause ::= drop_table_clause */ + { 149, -2 }, /* (50) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 153, -2 }, /* (51) drop_table_clause ::= exists_opt full_table_name */ + { 151, 0 }, /* (52) specific_tags_opt ::= */ + { 151, -3 }, /* (53) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 143, -1 }, /* (54) full_table_name ::= table_name */ + { 143, -3 }, /* (55) full_table_name ::= db_name NK_DOT table_name */ + { 144, -1 }, /* (56) column_def_list ::= column_def */ + { 144, -3 }, /* (57) column_def_list ::= column_def_list NK_COMMA column_def */ + { 156, -2 }, /* (58) column_def ::= column_name type_name */ + { 156, -4 }, /* (59) column_def ::= column_name type_name COMMENT NK_STRING */ + { 158, -1 }, /* (60) type_name ::= BOOL */ + { 158, -1 }, /* (61) type_name ::= TINYINT */ + { 158, -1 }, /* (62) type_name ::= SMALLINT */ + { 158, -1 }, /* (63) type_name ::= INT */ + { 158, -1 }, /* (64) type_name ::= INTEGER */ + { 158, -1 }, /* (65) type_name ::= BIGINT */ + { 158, -1 }, /* (66) type_name ::= FLOAT */ + { 158, -1 }, /* (67) type_name ::= DOUBLE */ + { 158, -4 }, /* (68) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 158, -1 }, /* (69) type_name ::= TIMESTAMP */ + { 158, -4 }, /* (70) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 158, -2 }, /* (71) type_name ::= TINYINT UNSIGNED */ + { 158, -2 }, /* (72) type_name ::= SMALLINT UNSIGNED */ + { 158, -2 }, /* (73) type_name ::= INT UNSIGNED */ + { 158, -2 }, /* (74) type_name ::= BIGINT UNSIGNED */ + { 158, -1 }, /* (75) type_name ::= JSON */ + { 158, -4 }, /* (76) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 158, -1 }, /* (77) type_name ::= MEDIUMBLOB */ + { 158, -1 }, /* (78) type_name ::= BLOB */ + { 158, -4 }, /* (79) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 158, -1 }, /* (80) type_name ::= DECIMAL */ + { 158, -4 }, /* (81) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 158, -6 }, /* (82) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 145, 0 }, /* (83) tags_def_opt ::= */ + { 145, -1 }, /* (84) tags_def_opt ::= tags_def */ + { 148, -4 }, /* (85) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 146, 0 }, /* (86) table_options ::= */ + { 146, -3 }, /* (87) table_options ::= table_options COMMENT NK_STRING */ + { 146, -3 }, /* (88) table_options ::= table_options KEEP NK_INTEGER */ + { 146, -3 }, /* (89) table_options ::= table_options TTL NK_INTEGER */ + { 146, -5 }, /* (90) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 154, -1 }, /* (91) col_name_list ::= col_name */ + { 154, -3 }, /* (92) col_name_list ::= col_name_list NK_COMMA col_name */ + { 159, -1 }, /* (93) col_name ::= column_name */ + { 135, -2 }, /* (94) cmd ::= SHOW VGROUPS */ + { 135, -4 }, /* (95) cmd ::= SHOW db_name NK_DOT VGROUPS */ + { 135, -2 }, /* (96) cmd ::= SHOW MNODES */ + { 135, -1 }, /* (97) cmd ::= query_expression */ + { 161, -1 }, /* (98) literal ::= NK_INTEGER */ + { 161, -1 }, /* (99) literal ::= NK_FLOAT */ + { 161, -1 }, /* (100) literal ::= NK_STRING */ + { 161, -1 }, /* (101) literal ::= NK_BOOL */ + { 161, -2 }, /* (102) literal ::= TIMESTAMP NK_STRING */ + { 161, -1 }, /* (103) literal ::= duration_literal */ + { 162, -1 }, /* (104) duration_literal ::= NK_VARIABLE */ + { 152, -1 }, /* (105) literal_list ::= literal */ + { 152, -3 }, /* (106) literal_list ::= literal_list NK_COMMA literal */ + { 140, -1 }, /* (107) db_name ::= NK_ID */ + { 155, -1 }, /* (108) table_name ::= NK_ID */ + { 157, -1 }, /* (109) column_name ::= NK_ID */ + { 163, -1 }, /* (110) function_name ::= NK_ID */ + { 164, -1 }, /* (111) table_alias ::= NK_ID */ + { 165, -1 }, /* (112) column_alias ::= NK_ID */ + { 136, -1 }, /* (113) user_name ::= NK_ID */ + { 166, -1 }, /* (114) expression ::= literal */ + { 166, -1 }, /* (115) expression ::= column_reference */ + { 166, -4 }, /* (116) expression ::= function_name NK_LP expression_list NK_RP */ + { 166, -4 }, /* (117) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 166, -1 }, /* (118) expression ::= subquery */ + { 166, -3 }, /* (119) expression ::= NK_LP expression NK_RP */ + { 166, -2 }, /* (120) expression ::= NK_PLUS expression */ + { 166, -2 }, /* (121) expression ::= NK_MINUS expression */ + { 166, -3 }, /* (122) expression ::= expression NK_PLUS expression */ + { 166, -3 }, /* (123) expression ::= expression NK_MINUS expression */ + { 166, -3 }, /* (124) expression ::= expression NK_STAR expression */ + { 166, -3 }, /* (125) expression ::= expression NK_SLASH expression */ + { 166, -3 }, /* (126) expression ::= expression NK_REM expression */ + { 168, -1 }, /* (127) expression_list ::= expression */ + { 168, -3 }, /* (128) expression_list ::= expression_list NK_COMMA expression */ + { 167, -1 }, /* (129) column_reference ::= column_name */ + { 167, -3 }, /* (130) column_reference ::= table_name NK_DOT column_name */ + { 170, -3 }, /* (131) predicate ::= expression compare_op expression */ + { 170, -5 }, /* (132) predicate ::= expression BETWEEN expression AND expression */ + { 170, -6 }, /* (133) predicate ::= expression NOT BETWEEN expression AND expression */ + { 170, -3 }, /* (134) predicate ::= expression IS NULL */ + { 170, -4 }, /* (135) predicate ::= expression IS NOT NULL */ + { 170, -3 }, /* (136) predicate ::= expression in_op in_predicate_value */ + { 171, -1 }, /* (137) compare_op ::= NK_LT */ + { 171, -1 }, /* (138) compare_op ::= NK_GT */ + { 171, -1 }, /* (139) compare_op ::= NK_LE */ + { 171, -1 }, /* (140) compare_op ::= NK_GE */ + { 171, -1 }, /* (141) compare_op ::= NK_NE */ + { 171, -1 }, /* (142) compare_op ::= NK_EQ */ + { 171, -1 }, /* (143) compare_op ::= LIKE */ + { 171, -2 }, /* (144) compare_op ::= NOT LIKE */ + { 171, -1 }, /* (145) compare_op ::= MATCH */ + { 171, -1 }, /* (146) compare_op ::= NMATCH */ + { 172, -1 }, /* (147) in_op ::= IN */ + { 172, -2 }, /* (148) in_op ::= NOT IN */ + { 173, -3 }, /* (149) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 174, -1 }, /* (150) boolean_value_expression ::= boolean_primary */ + { 174, -2 }, /* (151) boolean_value_expression ::= NOT boolean_primary */ + { 174, -3 }, /* (152) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 174, -3 }, /* (153) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 175, -1 }, /* (154) boolean_primary ::= predicate */ + { 175, -3 }, /* (155) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 176, -1 }, /* (156) common_expression ::= expression */ + { 176, -1 }, /* (157) common_expression ::= boolean_value_expression */ + { 177, -2 }, /* (158) from_clause ::= FROM table_reference_list */ + { 178, -1 }, /* (159) table_reference_list ::= table_reference */ + { 178, -3 }, /* (160) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 179, -1 }, /* (161) table_reference ::= table_primary */ + { 179, -1 }, /* (162) table_reference ::= joined_table */ + { 180, -2 }, /* (163) table_primary ::= table_name alias_opt */ + { 180, -4 }, /* (164) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 180, -2 }, /* (165) table_primary ::= subquery alias_opt */ + { 180, -1 }, /* (166) table_primary ::= parenthesized_joined_table */ + { 182, 0 }, /* (167) alias_opt ::= */ + { 182, -1 }, /* (168) alias_opt ::= table_alias */ + { 182, -2 }, /* (169) alias_opt ::= AS table_alias */ + { 183, -3 }, /* (170) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 183, -3 }, /* (171) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 181, -6 }, /* (172) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 184, 0 }, /* (173) join_type ::= */ + { 184, -1 }, /* (174) join_type ::= INNER */ + { 186, -9 }, /* (175) 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, 0 }, /* (176) set_quantifier_opt ::= */ + { 187, -1 }, /* (177) set_quantifier_opt ::= DISTINCT */ + { 187, -1 }, /* (178) set_quantifier_opt ::= ALL */ + { 188, -1 }, /* (179) select_list ::= NK_STAR */ + { 188, -1 }, /* (180) select_list ::= select_sublist */ + { 194, -1 }, /* (181) select_sublist ::= select_item */ + { 194, -3 }, /* (182) select_sublist ::= select_sublist NK_COMMA select_item */ + { 195, -1 }, /* (183) select_item ::= common_expression */ + { 195, -2 }, /* (184) select_item ::= common_expression column_alias */ + { 195, -3 }, /* (185) select_item ::= common_expression AS column_alias */ + { 195, -3 }, /* (186) select_item ::= table_name NK_DOT NK_STAR */ + { 189, 0 }, /* (187) where_clause_opt ::= */ + { 189, -2 }, /* (188) where_clause_opt ::= WHERE search_condition */ + { 190, 0 }, /* (189) partition_by_clause_opt ::= */ + { 190, -3 }, /* (190) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 191, 0 }, /* (191) twindow_clause_opt ::= */ + { 191, -6 }, /* (192) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ + { 191, -4 }, /* (193) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 191, -6 }, /* (194) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 191, -8 }, /* (195) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 196, 0 }, /* (196) sliding_opt ::= */ + { 196, -4 }, /* (197) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 197, 0 }, /* (198) fill_opt ::= */ + { 197, -4 }, /* (199) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 197, -6 }, /* (200) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 198, -1 }, /* (201) fill_mode ::= NONE */ + { 198, -1 }, /* (202) fill_mode ::= PREV */ + { 198, -1 }, /* (203) fill_mode ::= NULL */ + { 198, -1 }, /* (204) fill_mode ::= LINEAR */ + { 198, -1 }, /* (205) fill_mode ::= NEXT */ + { 192, 0 }, /* (206) group_by_clause_opt ::= */ + { 192, -3 }, /* (207) group_by_clause_opt ::= GROUP BY group_by_list */ + { 199, -1 }, /* (208) group_by_list ::= expression */ + { 199, -3 }, /* (209) group_by_list ::= group_by_list NK_COMMA expression */ + { 193, 0 }, /* (210) having_clause_opt ::= */ + { 193, -2 }, /* (211) having_clause_opt ::= HAVING search_condition */ + { 160, -4 }, /* (212) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 200, -1 }, /* (213) query_expression_body ::= query_primary */ + { 200, -4 }, /* (214) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 204, -1 }, /* (215) query_primary ::= query_specification */ + { 201, 0 }, /* (216) order_by_clause_opt ::= */ + { 201, -3 }, /* (217) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 202, 0 }, /* (218) slimit_clause_opt ::= */ + { 202, -2 }, /* (219) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 202, -4 }, /* (220) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 202, -4 }, /* (221) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 203, 0 }, /* (222) limit_clause_opt ::= */ + { 203, -2 }, /* (223) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 203, -4 }, /* (224) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 203, -4 }, /* (225) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 169, -3 }, /* (226) subquery ::= NK_LP query_expression NK_RP */ + { 185, -1 }, /* (227) search_condition ::= common_expression */ + { 205, -1 }, /* (228) sort_specification_list ::= sort_specification */ + { 205, -3 }, /* (229) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 206, -3 }, /* (230) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 207, 0 }, /* (231) ordering_specification_opt ::= */ + { 207, -1 }, /* (232) ordering_specification_opt ::= ASC */ + { 207, -1 }, /* (233) ordering_specification_opt ::= DESC */ + { 208, 0 }, /* (234) null_ordering_opt ::= */ + { 208, -2 }, /* (235) null_ordering_opt ::= NULLS FIRST */ + { 208, -2 }, /* (236) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1909,31 +1912,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.yy161, &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.yy161, 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.yy161, 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.yy161); } +{ 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.yy161, 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.yy161, &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);} break; case 8: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy161);} +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy129);} break; case 9: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); } @@ -1941,122 +1944,122 @@ 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 106: /* db_name ::= NK_ID */ yytestcase(yyruleno==106); - case 107: /* table_name ::= NK_ID */ yytestcase(yyruleno==107); - case 108: /* column_name ::= NK_ID */ yytestcase(yyruleno==108); - case 109: /* function_name ::= NK_ID */ yytestcase(yyruleno==109); - case 110: /* table_alias ::= NK_ID */ yytestcase(yyruleno==110); - case 111: /* column_alias ::= NK_ID */ yytestcase(yyruleno==111); - case 112: /* user_name ::= NK_ID */ yytestcase(yyruleno==112); -{ yylhsminor.yy161 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy161 = yylhsminor.yy161; + case 107: /* db_name ::= NK_ID */ yytestcase(yyruleno==107); + case 108: /* table_name ::= NK_ID */ yytestcase(yyruleno==108); + case 109: /* column_name ::= NK_ID */ yytestcase(yyruleno==109); + case 110: /* function_name ::= NK_ID */ yytestcase(yyruleno==110); + case 111: /* table_alias ::= NK_ID */ yytestcase(yyruleno==111); + case 112: /* column_alias ::= NK_ID */ yytestcase(yyruleno==112); + case 113: /* user_name ::= NK_ID */ yytestcase(yyruleno==113); +{ yylhsminor.yy129 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; case 13: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy377, &yymsp[-1].minor.yy161, yymsp[0].minor.yy103);} +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy129, yymsp[0].minor.yy391);} break; case 14: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy377, &yymsp[0].minor.yy161); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy185, &yymsp[0].minor.yy129); } break; case 15: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); } break; case 16: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy161);} +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy129);} break; case 17: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy377 = true; } +{ yymsp[-2].minor.yy185 = true; } break; case 18: /* not_exists_opt ::= */ case 20: /* exists_opt ::= */ yytestcase(yyruleno==20); - case 175: /* set_quantifier_opt ::= */ yytestcase(yyruleno==175); -{ yymsp[1].minor.yy377 = false; } + case 176: /* set_quantifier_opt ::= */ yytestcase(yyruleno==176); +{ yymsp[1].minor.yy185 = false; } break; case 19: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy377 = true; } +{ yymsp[-1].minor.yy185 = true; } break; case 21: /* db_options ::= */ -{ yymsp[1].minor.yy103 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy391 = createDefaultDatabaseOptions(pCxt); } break; case 22: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 23: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 24: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 25: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 26: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 27: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 28: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 29: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 30: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 31: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 32: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 33: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 34: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 35: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 36: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 37: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_SINGLESTABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_SINGLESTABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 38: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy103 = setDatabaseOption(pCxt, yymsp[-2].minor.yy103, DB_OPTION_STREAMMODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy103 = yylhsminor.yy103; +{ yylhsminor.yy391 = setDatabaseOption(pCxt, yymsp[-2].minor.yy391, DB_OPTION_STREAMMODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy391 = yylhsminor.yy391; break; case 39: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 41: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==41); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy377, yymsp[-5].minor.yy392, yymsp[-3].minor.yy184, yymsp[-1].minor.yy184, yymsp[0].minor.yy334);} +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy185, yymsp[-5].minor.yy256, yymsp[-3].minor.yy46, yymsp[-1].minor.yy46, yymsp[0].minor.yy340);} break; case 40: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy184);} +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy46);} break; case 42: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy184); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy46); } break; case 43: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy377, yymsp[0].minor.yy392); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy185, yymsp[0].minor.yy256); } break; case 44: /* cmd ::= SHOW TABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); } @@ -2068,586 +2071,589 @@ static YYACTIONTYPE yy_reduce( case 49: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==49); case 56: /* column_def_list ::= column_def */ yytestcase(yyruleno==56); case 91: /* col_name_list ::= col_name */ yytestcase(yyruleno==91); - case 180: /* select_sublist ::= select_item */ yytestcase(yyruleno==180); - case 227: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==227); -{ yylhsminor.yy184 = createNodeList(pCxt, yymsp[0].minor.yy392); } - yymsp[0].minor.yy184 = yylhsminor.yy184; + case 181: /* select_sublist ::= select_item */ yytestcase(yyruleno==181); + case 228: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==228); +{ yylhsminor.yy46 = createNodeList(pCxt, yymsp[0].minor.yy256); } + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 47: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 50: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==50); -{ yylhsminor.yy184 = addNodeToList(pCxt, yymsp[-1].minor.yy184, yymsp[0].minor.yy392); } - yymsp[-1].minor.yy184 = yylhsminor.yy184; +{ yylhsminor.yy46 = addNodeToList(pCxt, yymsp[-1].minor.yy46, yymsp[0].minor.yy256); } + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; case 48: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy392 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy377, yymsp[-7].minor.yy392, yymsp[-5].minor.yy392, yymsp[-4].minor.yy184, yymsp[-1].minor.yy184); } - yymsp[-8].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy185, yymsp[-7].minor.yy256, yymsp[-5].minor.yy256, yymsp[-4].minor.yy46, yymsp[-1].minor.yy46); } + yymsp[-8].minor.yy256 = yylhsminor.yy256; break; case 51: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy392 = createDropTableClause(pCxt, yymsp[-1].minor.yy377, yymsp[0].minor.yy392); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createDropTableClause(pCxt, yymsp[-1].minor.yy185, yymsp[0].minor.yy256); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; case 52: /* specific_tags_opt ::= */ case 83: /* tags_def_opt ::= */ yytestcase(yyruleno==83); - case 188: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==188); - case 205: /* group_by_clause_opt ::= */ yytestcase(yyruleno==205); - case 215: /* order_by_clause_opt ::= */ yytestcase(yyruleno==215); -{ yymsp[1].minor.yy184 = NULL; } + case 189: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==189); + case 206: /* group_by_clause_opt ::= */ yytestcase(yyruleno==206); + case 216: /* order_by_clause_opt ::= */ yytestcase(yyruleno==216); +{ yymsp[1].minor.yy46 = NULL; } break; case 53: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy184 = yymsp[-1].minor.yy184; } +{ yymsp[-2].minor.yy46 = yymsp[-1].minor.yy46; } break; case 54: /* full_table_name ::= table_name */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy161, NULL); } - yymsp[0].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy129, NULL); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; case 55: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-2].minor.yy161, &yymsp[0].minor.yy161, NULL); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createRealTableNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, NULL); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; case 57: /* column_def_list ::= column_def_list NK_COMMA column_def */ case 92: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==92); - case 181: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==181); - case 228: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==228); -{ yylhsminor.yy184 = addNodeToList(pCxt, yymsp[-2].minor.yy184, yymsp[0].minor.yy392); } - yymsp[-2].minor.yy184 = yylhsminor.yy184; + case 182: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==182); + case 229: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==229); +{ yylhsminor.yy46 = addNodeToList(pCxt, yymsp[-2].minor.yy46, yymsp[0].minor.yy256); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 58: /* column_def ::= column_name type_name */ -{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy161, yymsp[0].minor.yy240, NULL); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy129, yymsp[0].minor.yy70, NULL); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; case 59: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy161, yymsp[-2].minor.yy240, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-2].minor.yy70, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; case 60: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 61: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 62: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 63: /* type_name ::= INT */ case 64: /* type_name ::= INTEGER */ yytestcase(yyruleno==64); -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_INT); } break; case 65: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 66: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 67: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 68: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy240 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy70 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 69: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 70: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy240 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy70 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 71: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy240 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy70 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 72: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy240 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy70 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 73: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy240 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy70 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 74: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy240 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy70 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 75: /* type_name ::= JSON */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 76: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy240 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy70 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 77: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 78: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 79: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy240 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy70 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 80: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy240 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy70 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 81: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy240 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy70 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 82: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy240 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy70 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 84: /* tags_def_opt ::= tags_def */ - case 179: /* select_list ::= select_sublist */ yytestcase(yyruleno==179); -{ yylhsminor.yy184 = yymsp[0].minor.yy184; } - yymsp[0].minor.yy184 = yylhsminor.yy184; + case 180: /* select_list ::= select_sublist */ yytestcase(yyruleno==180); +{ yylhsminor.yy46 = yymsp[0].minor.yy46; } + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 85: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy184 = yymsp[-1].minor.yy184; } +{ yymsp[-3].minor.yy46 = yymsp[-1].minor.yy46; } break; case 86: /* table_options ::= */ -{ yymsp[1].minor.yy334 = createDefaultTableOptions(pCxt);} +{ yymsp[1].minor.yy340 = createDefaultTableOptions(pCxt);} break; case 87: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy334 = setTableOption(pCxt, yymsp[-2].minor.yy334, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy340 = setTableOption(pCxt, yymsp[-2].minor.yy340, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy340 = yylhsminor.yy340; break; case 88: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy334 = setTableOption(pCxt, yymsp[-2].minor.yy334, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy340 = setTableOption(pCxt, yymsp[-2].minor.yy340, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy340 = yylhsminor.yy340; break; case 89: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy334 = setTableOption(pCxt, yymsp[-2].minor.yy334, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy340 = setTableOption(pCxt, yymsp[-2].minor.yy340, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy340 = yylhsminor.yy340; break; case 90: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy334 = setTableSmaOption(pCxt, yymsp[-4].minor.yy334, yymsp[-1].minor.yy184); } - yymsp[-4].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy340 = setTableSmaOption(pCxt, yymsp[-4].minor.yy340, yymsp[-1].minor.yy46); } + yymsp[-4].minor.yy340 = yylhsminor.yy340; break; case 93: /* col_name ::= column_name */ -{ yylhsminor.yy392 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy161); } - yymsp[0].minor.yy392 = yylhsminor.yy392; +{ yylhsminor.yy256 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; case 94: /* cmd ::= SHOW VGROUPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); } break; case 95: /* cmd ::= SHOW db_name NK_DOT VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy161); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy129); } break; - case 96: /* cmd ::= query_expression */ -{ pCxt->pRootNode = yymsp[0].minor.yy392; } + case 96: /* cmd ::= SHOW MNODES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL); } break; - case 97: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 97: /* cmd ::= query_expression */ +{ pCxt->pRootNode = yymsp[0].minor.yy256; } break; - case 98: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 98: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 99: /* literal ::= NK_STRING */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 99: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 100: /* literal ::= NK_BOOL */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 100: /* literal ::= NK_STRING */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 101: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 101: /* literal ::= NK_BOOL */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 102: /* literal ::= duration_literal */ - case 113: /* expression ::= literal */ yytestcase(yyruleno==113); - case 114: /* expression ::= column_reference */ yytestcase(yyruleno==114); - case 117: /* expression ::= subquery */ yytestcase(yyruleno==117); - case 149: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==149); - case 153: /* boolean_primary ::= predicate */ yytestcase(yyruleno==153); - case 155: /* common_expression ::= expression */ yytestcase(yyruleno==155); - case 156: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==156); - case 158: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==158); - case 160: /* table_reference ::= table_primary */ yytestcase(yyruleno==160); - case 161: /* table_reference ::= joined_table */ yytestcase(yyruleno==161); - case 165: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==165); - case 212: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==212); - case 214: /* query_primary ::= query_specification */ yytestcase(yyruleno==214); -{ yylhsminor.yy392 = yymsp[0].minor.yy392; } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 102: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 103: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 103: /* literal ::= duration_literal */ + case 114: /* expression ::= literal */ yytestcase(yyruleno==114); + case 115: /* expression ::= column_reference */ yytestcase(yyruleno==115); + case 118: /* expression ::= subquery */ yytestcase(yyruleno==118); + case 150: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==150); + case 154: /* boolean_primary ::= predicate */ yytestcase(yyruleno==154); + case 156: /* common_expression ::= expression */ yytestcase(yyruleno==156); + case 157: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==157); + case 159: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==159); + case 161: /* table_reference ::= table_primary */ yytestcase(yyruleno==161); + case 162: /* table_reference ::= joined_table */ yytestcase(yyruleno==162); + case 166: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==166); + case 213: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==213); + case 215: /* query_primary ::= query_specification */ yytestcase(yyruleno==215); +{ yylhsminor.yy256 = yymsp[0].minor.yy256; } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 104: /* literal_list ::= literal */ - case 126: /* expression_list ::= expression */ yytestcase(yyruleno==126); -{ yylhsminor.yy184 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[0].minor.yy184 = yylhsminor.yy184; + case 104: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 105: /* literal_list ::= literal_list NK_COMMA literal */ - case 127: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==127); -{ yylhsminor.yy184 = addNodeToList(pCxt, yymsp[-2].minor.yy184, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[-2].minor.yy184 = yylhsminor.yy184; + case 105: /* literal_list ::= literal */ + case 127: /* expression_list ::= expression */ yytestcase(yyruleno==127); +{ yylhsminor.yy46 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy256)); } + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 115: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy161, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy161, yymsp[-1].minor.yy184)); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 106: /* literal_list ::= literal_list NK_COMMA literal */ + case 128: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==128); +{ yylhsminor.yy46 = addNodeToList(pCxt, yymsp[-2].minor.yy46, releaseRawExprNode(pCxt, yymsp[0].minor.yy256)); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 116: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy161, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy161, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 116: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy129, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy129, yymsp[-1].minor.yy46)); } + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; - case 118: /* expression ::= NK_LP expression NK_RP */ - case 154: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==154); -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 117: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy256 = 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.yy256 = yylhsminor.yy256; break; - case 119: /* expression ::= NK_PLUS expression */ + case 119: /* expression ::= NK_LP expression NK_RP */ + case 155: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==155); +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy256)); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; + break; + case 120: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy256)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 120: /* expression ::= NK_MINUS expression */ + case 121: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy256), NULL)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 121: /* expression ::= expression NK_PLUS expression */ + case 122: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 122: /* expression ::= expression NK_MINUS expression */ + case 123: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 123: /* expression ::= expression NK_STAR expression */ + case 124: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 124: /* expression ::= expression NK_SLASH expression */ + case 125: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 125: /* expression ::= expression NK_REM expression */ + case 126: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 128: /* column_reference ::= column_name */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy161, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy161)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 129: /* column_reference ::= column_name */ +{ yylhsminor.yy256 = createRawExprNode(pCxt, &yymsp[0].minor.yy129, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy129)); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 129: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy161, &yymsp[0].minor.yy161, createColumnNode(pCxt, &yymsp[-2].minor.yy161, &yymsp[0].minor.yy161)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 130: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129, createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy129)); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 130: /* predicate ::= expression compare_op expression */ - case 135: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==135); + case 131: /* predicate ::= expression compare_op expression */ + case 136: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==136); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy220, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy326, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 131: /* predicate ::= expression BETWEEN expression AND expression */ + case 132: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy256), releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + yymsp[-4].minor.yy256 = yylhsminor.yy256; break; - case 132: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 133: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[-5].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; + yymsp[-5].minor.yy256 = yylhsminor.yy256; break; - case 133: /* predicate ::= expression IS NULL */ + case 134: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), NULL)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 134: /* predicate ::= expression IS NOT NULL */ + case 135: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy256), NULL)); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; - case 136: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy220 = OP_TYPE_LOWER_THAN; } + case 137: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy326 = OP_TYPE_LOWER_THAN; } break; - case 137: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy220 = OP_TYPE_GREATER_THAN; } + case 138: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy326 = OP_TYPE_GREATER_THAN; } break; - case 138: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy220 = OP_TYPE_LOWER_EQUAL; } + case 139: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy326 = OP_TYPE_LOWER_EQUAL; } break; - case 139: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy220 = OP_TYPE_GREATER_EQUAL; } + case 140: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy326 = OP_TYPE_GREATER_EQUAL; } break; - case 140: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy220 = OP_TYPE_NOT_EQUAL; } + case 141: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy326 = OP_TYPE_NOT_EQUAL; } break; - case 141: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy220 = OP_TYPE_EQUAL; } + case 142: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy326 = OP_TYPE_EQUAL; } break; - case 142: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy220 = OP_TYPE_LIKE; } + case 143: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy326 = OP_TYPE_LIKE; } break; - case 143: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy220 = OP_TYPE_NOT_LIKE; } + case 144: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy326 = OP_TYPE_NOT_LIKE; } break; - case 144: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy220 = OP_TYPE_MATCH; } + case 145: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy326 = OP_TYPE_MATCH; } break; - case 145: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy220 = OP_TYPE_NMATCH; } + case 146: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy326 = OP_TYPE_NMATCH; } break; - case 146: /* in_op ::= IN */ -{ yymsp[0].minor.yy220 = OP_TYPE_IN; } + case 147: /* in_op ::= IN */ +{ yymsp[0].minor.yy326 = OP_TYPE_IN; } break; - case 147: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy220 = OP_TYPE_NOT_IN; } + case 148: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy326 = OP_TYPE_NOT_IN; } break; - case 148: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy184)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 149: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy46)); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 150: /* boolean_value_expression ::= NOT boolean_primary */ + case 151: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy256), NULL)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 151: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 152: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 152: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 153: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy256); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 157: /* from_clause ::= FROM table_reference_list */ - case 187: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==187); - case 210: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==210); -{ yymsp[-1].minor.yy392 = yymsp[0].minor.yy392; } + case 158: /* from_clause ::= FROM table_reference_list */ + case 188: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==188); + case 211: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==211); +{ yymsp[-1].minor.yy256 = yymsp[0].minor.yy256; } break; - case 159: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy392 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, NULL); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 160: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy256 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy256, yymsp[0].minor.yy256, NULL); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 162: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy161, &yymsp[0].minor.yy161); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 163: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy256 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 163: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-3].minor.yy161, &yymsp[-1].minor.yy161, &yymsp[0].minor.yy161); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 164: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy256 = createRealTableNode(pCxt, &yymsp[-3].minor.yy129, &yymsp[-1].minor.yy129, &yymsp[0].minor.yy129); } + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; - case 164: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy392 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy161); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 165: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy256 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy256), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 166: /* alias_opt ::= */ -{ yymsp[1].minor.yy161 = nil_token; } + case 167: /* alias_opt ::= */ +{ yymsp[1].minor.yy129 = nil_token; } break; - case 167: /* alias_opt ::= table_alias */ -{ yylhsminor.yy161 = yymsp[0].minor.yy161; } - yymsp[0].minor.yy161 = yylhsminor.yy161; + case 168: /* alias_opt ::= table_alias */ +{ yylhsminor.yy129 = yymsp[0].minor.yy129; } + yymsp[0].minor.yy129 = yylhsminor.yy129; break; - case 168: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy161 = yymsp[0].minor.yy161; } + case 169: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy129 = yymsp[0].minor.yy129; } break; - case 169: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 170: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==170); -{ yymsp[-2].minor.yy392 = yymsp[-1].minor.yy392; } + case 170: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 171: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==171); +{ yymsp[-2].minor.yy256 = yymsp[-1].minor.yy256; } break; - case 171: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy392 = createJoinTableNode(pCxt, yymsp[-4].minor.yy308, yymsp[-5].minor.yy392, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; + case 172: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy256 = createJoinTableNode(pCxt, yymsp[-4].minor.yy266, yymsp[-5].minor.yy256, yymsp[-2].minor.yy256, yymsp[0].minor.yy256); } + yymsp[-5].minor.yy256 = yylhsminor.yy256; break; - case 172: /* join_type ::= */ -{ yymsp[1].minor.yy308 = JOIN_TYPE_INNER; } + case 173: /* join_type ::= */ +{ yymsp[1].minor.yy266 = JOIN_TYPE_INNER; } break; - case 173: /* join_type ::= INNER */ -{ yymsp[0].minor.yy308 = JOIN_TYPE_INNER; } + case 174: /* join_type ::= INNER */ +{ yymsp[0].minor.yy266 = JOIN_TYPE_INNER; } break; - case 174: /* 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 175: /* 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.yy392 = createSelectStmt(pCxt, yymsp[-7].minor.yy377, yymsp[-6].minor.yy184, yymsp[-5].minor.yy392); - yymsp[-8].minor.yy392 = addWhereClause(pCxt, yymsp[-8].minor.yy392, yymsp[-4].minor.yy392); - yymsp[-8].minor.yy392 = addPartitionByClause(pCxt, yymsp[-8].minor.yy392, yymsp[-3].minor.yy184); - yymsp[-8].minor.yy392 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy392, yymsp[-2].minor.yy392); - yymsp[-8].minor.yy392 = addGroupByClause(pCxt, yymsp[-8].minor.yy392, yymsp[-1].minor.yy184); - yymsp[-8].minor.yy392 = addHavingClause(pCxt, yymsp[-8].minor.yy392, yymsp[0].minor.yy392); + yymsp[-8].minor.yy256 = createSelectStmt(pCxt, yymsp[-7].minor.yy185, yymsp[-6].minor.yy46, yymsp[-5].minor.yy256); + yymsp[-8].minor.yy256 = addWhereClause(pCxt, yymsp[-8].minor.yy256, yymsp[-4].minor.yy256); + yymsp[-8].minor.yy256 = addPartitionByClause(pCxt, yymsp[-8].minor.yy256, yymsp[-3].minor.yy46); + yymsp[-8].minor.yy256 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy256, yymsp[-2].minor.yy256); + yymsp[-8].minor.yy256 = addGroupByClause(pCxt, yymsp[-8].minor.yy256, yymsp[-1].minor.yy46); + yymsp[-8].minor.yy256 = addHavingClause(pCxt, yymsp[-8].minor.yy256, yymsp[0].minor.yy256); } break; - case 176: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy377 = true; } + case 177: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy185 = true; } break; - case 177: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy377 = false; } + case 178: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy185 = false; } break; - case 178: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy184 = NULL; } + case 179: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy46 = NULL; } break; - case 182: /* select_item ::= common_expression */ + case 183: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy256); + yylhsminor.yy256 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy256), &t); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 183: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy161); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 184: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy256 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy256), &yymsp[0].minor.yy129); } + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 184: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), &yymsp[0].minor.yy161); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 185: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy256 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), &yymsp[0].minor.yy129); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 185: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy392 = createColumnNode(pCxt, &yymsp[-2].minor.yy161, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 186: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy256 = createColumnNode(pCxt, &yymsp[-2].minor.yy129, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 186: /* where_clause_opt ::= */ - case 190: /* twindow_clause_opt ::= */ yytestcase(yyruleno==190); - case 195: /* sliding_opt ::= */ yytestcase(yyruleno==195); - case 197: /* fill_opt ::= */ yytestcase(yyruleno==197); - case 209: /* having_clause_opt ::= */ yytestcase(yyruleno==209); - case 217: /* slimit_clause_opt ::= */ yytestcase(yyruleno==217); - case 221: /* limit_clause_opt ::= */ yytestcase(yyruleno==221); -{ yymsp[1].minor.yy392 = NULL; } + case 187: /* where_clause_opt ::= */ + case 191: /* twindow_clause_opt ::= */ yytestcase(yyruleno==191); + case 196: /* sliding_opt ::= */ yytestcase(yyruleno==196); + case 198: /* fill_opt ::= */ yytestcase(yyruleno==198); + case 210: /* having_clause_opt ::= */ yytestcase(yyruleno==210); + case 218: /* slimit_clause_opt ::= */ yytestcase(yyruleno==218); + case 222: /* limit_clause_opt ::= */ yytestcase(yyruleno==222); +{ yymsp[1].minor.yy256 = NULL; } break; - case 189: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 206: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==206); - case 216: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==216); -{ yymsp[-2].minor.yy184 = yymsp[0].minor.yy184; } + case 190: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 207: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==207); + case 217: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==217); +{ yymsp[-2].minor.yy46 = yymsp[0].minor.yy46; } break; - case 191: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy392 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), &yymsp[-1].minor.yy0); } + case 192: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy256 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy256), &yymsp[-1].minor.yy0); } break; - case 192: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy392 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + case 193: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy256 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy256)); } break; - case 193: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy392 = createIntervalWindowNode(pCxt, yymsp[-3].minor.yy392, NULL, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 194: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy256 = createIntervalWindowNode(pCxt, yymsp[-3].minor.yy256, NULL, yymsp[-1].minor.yy256, yymsp[0].minor.yy256); } break; - case 194: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy392 = createIntervalWindowNode(pCxt, yymsp[-5].minor.yy392, yymsp[-3].minor.yy392, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 195: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy256 = createIntervalWindowNode(pCxt, yymsp[-5].minor.yy256, yymsp[-3].minor.yy256, yymsp[-1].minor.yy256, yymsp[0].minor.yy256); } break; - case 196: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy392 = yymsp[-1].minor.yy392; } + case 197: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy256 = yymsp[-1].minor.yy256; } break; - case 198: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy392 = createFillNode(pCxt, yymsp[-1].minor.yy166, NULL); } + case 199: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy256 = createFillNode(pCxt, yymsp[-1].minor.yy360, NULL); } break; - case 199: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy392 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy184)); } + case 200: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy256 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy46)); } break; - case 200: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy166 = FILL_MODE_NONE; } + case 201: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy360 = FILL_MODE_NONE; } break; - case 201: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy166 = FILL_MODE_PREV; } + case 202: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy360 = FILL_MODE_PREV; } break; - case 202: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy166 = FILL_MODE_NULL; } + case 203: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy360 = FILL_MODE_NULL; } break; - case 203: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy166 = FILL_MODE_LINEAR; } + case 204: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy360 = FILL_MODE_LINEAR; } break; - case 204: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy166 = FILL_MODE_NEXT; } + case 205: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy360 = FILL_MODE_NEXT; } break; - case 207: /* group_by_list ::= expression */ -{ yylhsminor.yy184 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[0].minor.yy184 = yylhsminor.yy184; + case 208: /* group_by_list ::= expression */ +{ yylhsminor.yy46 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 208: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy184 = addNodeToList(pCxt, yymsp[-2].minor.yy184, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy184 = yylhsminor.yy184; + case 209: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy46 = addNodeToList(pCxt, yymsp[-2].minor.yy46, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy256))); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 211: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 212: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy392 = addOrderByClause(pCxt, yymsp[-3].minor.yy392, yymsp[-2].minor.yy184); - yylhsminor.yy392 = addSlimitClause(pCxt, yylhsminor.yy392, yymsp[-1].minor.yy392); - yylhsminor.yy392 = addLimitClause(pCxt, yylhsminor.yy392, yymsp[0].minor.yy392); + yylhsminor.yy256 = addOrderByClause(pCxt, yymsp[-3].minor.yy256, yymsp[-2].minor.yy46); + yylhsminor.yy256 = addSlimitClause(pCxt, yylhsminor.yy256, yymsp[-1].minor.yy256); + yylhsminor.yy256 = addLimitClause(pCxt, yylhsminor.yy256, yymsp[0].minor.yy256); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; - case 213: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 214: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy256 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy256, yymsp[0].minor.yy256); } + yymsp[-3].minor.yy256 = yylhsminor.yy256; break; - case 218: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 222: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==222); -{ yymsp[-1].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 219: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 223: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==223); +{ yymsp[-1].minor.yy256 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 219: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 223: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==223); -{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 220: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 224: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==224); +{ yymsp[-3].minor.yy256 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 220: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 224: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==224); -{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 221: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 225: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==225); +{ yymsp[-3].minor.yy256 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 225: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy392); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 226: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy256 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy256); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 226: /* search_condition ::= common_expression */ -{ yylhsminor.yy392 = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 227: /* search_condition ::= common_expression */ +{ yylhsminor.yy256 = releaseRawExprNode(pCxt, yymsp[0].minor.yy256); } + yymsp[0].minor.yy256 = yylhsminor.yy256; break; - case 229: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy392 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[-1].minor.yy162, yymsp[0].minor.yy9); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 230: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy256 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy256), yymsp[-1].minor.yy202, yymsp[0].minor.yy147); } + yymsp[-2].minor.yy256 = yylhsminor.yy256; break; - case 230: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy162 = ORDER_ASC; } + case 231: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy202 = ORDER_ASC; } break; - case 231: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy162 = ORDER_ASC; } + case 232: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy202 = ORDER_ASC; } break; - case 232: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy162 = ORDER_DESC; } + case 233: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy202 = ORDER_DESC; } break; - case 233: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy9 = NULL_ORDER_DEFAULT; } + case 234: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy147 = NULL_ORDER_DEFAULT; } break; - case 234: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy9 = NULL_ORDER_FIRST; } + case 235: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy147 = NULL_ORDER_FIRST; } break; - case 235: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy9 = NULL_ORDER_LAST; } + case 236: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy147 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index d57f40ca35..be271cf057 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -48,6 +48,13 @@ extern "C" { } \ } while (0) +#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) +#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) +#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) +#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__) +#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__) +#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__) + int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode); int32_t optimize(SPlanContext* pCxt, SLogicNode* pLogicNode); int32_t applySplitRule(SSubLogicPlan* pSubplan); From 75c5de4762a3df5c3a6f6d87fcb7dfe6b87b631e Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 10 Mar 2022 21:39:37 -0500 Subject: [PATCH 23/23] TD-13747 bugfix --- source/libs/parser/src/parTranslater.c | 52 +++++++++++++++----------- tests/script/tsim/dnode/basic1.sim | 2 +- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index d82b3cad62..4be4e25eb8 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -499,29 +499,37 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) return TSDB_CODE_SUCCESS; } -static int32_t setTableVgroupList(STranslateContext *pCxt, SName* name, SVgroupsInfo **pVgList) { - SArray* vgroupList = NULL; - int32_t code = catalogGetTableDistVgInfo(pCxt->pParseCxt->pCatalog, pCxt->pParseCxt->pTransporter, &(pCxt->pParseCxt->mgmtEpSet), name, &vgroupList); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - size_t vgroupNum = taosArrayGetSize(vgroupList); +static int32_t setTableVgroupList(SParseContext* pCxt, SName* name, SRealTableNode* pRealTable) { + if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) { + SArray* vgroupList = NULL; + int32_t code = catalogGetTableDistVgInfo(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, name, &vgroupList); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + size_t vgroupNum = taosArrayGetSize(vgroupList); + pRealTable->pVgroupList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); + if (NULL == pRealTable->pVgroupList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pRealTable->pVgroupList->numOfVgroups = vgroupNum; + for (int32_t i = 0; i < vgroupNum; ++i) { + SVgroupInfo *vg = taosArrayGet(vgroupList, i); + pRealTable->pVgroupList->vgroups[i] = *vg; + } - SVgroupsInfo* vgList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); - if (NULL == vgList) { - return TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(vgroupList); + } else { + pRealTable->pVgroupList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo)); + if (NULL == pRealTable->pVgroupList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pRealTable->pVgroupList->numOfVgroups = 1; + int32_t code = catalogGetTableHashVgroup(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, name, pRealTable->pVgroupList->vgroups); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } - vgList->numOfVgroups = vgroupNum; - - for (int32_t i = 0; i < vgroupNum; ++i) { - SVgroupInfo *vg = taosArrayGet(vgroupList, i); - vgList->vgroups[i] = *vg; - } - - *pVgList = vgList; - taosArrayDestroy(vgroupList); - return TSDB_CODE_SUCCESS; } @@ -536,7 +544,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { if (TSDB_CODE_SUCCESS != code) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName); } - code = setTableVgroupList(pCxt, &name, &(pRealTable->pVgroupList)); + code = setTableVgroupList(pCxt->pParseCxt, &name, pRealTable); if (TSDB_CODE_SUCCESS != code) { return code; } diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/basic1.sim index 6061b6ece1..33e62de519 100644 --- a/tests/script/tsim/dnode/basic1.sim +++ b/tests/script/tsim/dnode/basic1.sim @@ -177,7 +177,7 @@ if $rows != 3 then return -1 endi -sql select * from st +sql select ts, i from st if $rows != 15 then return -1 endi