diff --git a/.clang-format b/.clang-format index 3ddd8b43f6238f30000b96d8e676892ab2dcec68..f60fd3cb2629f933b6e25452c65716799e416c9e 100644 --- a/.clang-format +++ b/.clang-format @@ -86,5 +86,6 @@ SpacesInSquareBrackets: false Standard: Auto TabWidth: 8 UseTab: Never +AlignConsecutiveDeclarations: true ... diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b752d091dee2b91e9cde8a2a6b825054901434a..fd0ada95d9043d143fe6eca3d295a18cc3b19849 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -18,7 +18,8 @@ "ms-vscode.cpptools", "ms-vscode.cmake-tools", "austin.code-gnu-global", - "visualstudioexptteam.vscodeintel" + "visualstudioexptteam.vscodeintel", + "eamodio.gitlens" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. @@ -28,5 +29,5 @@ // "postCreateCommand": "gcc -v", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + "remoteUser": "root" } diff --git a/CMakeLists.txt b/CMakeLists.txt index cda71fb3bf01ba1018a77c2741709a9d28a836c8..99e48006b19b0d12d9faa3ce2d51987d1cf4bfe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib") include(${CMAKE_SUPPORT_DIR}/cmake.options) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma -g3") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma -g3") # contrib add_subdirectory(contrib) diff --git a/contrib/test/tdev/src/main.c b/contrib/test/tdev/src/main.c index 687b175a62de275b6729713940b8722abb7a233e..5e1de83e88a2a76d2381726ded0c28fe00ab67a6 100644 --- a/contrib/test/tdev/src/main.c +++ b/contrib/test/tdev/src/main.c @@ -14,6 +14,10 @@ #define tPutB(buf, val) \ ({ \ + ((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \ + ((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \ + ((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \ + ((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \ ((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \ ((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \ ((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \ @@ -21,13 +25,33 @@ POINTER_SHIFT(buf, sizeof(val)); \ }) -#define tPutC(buf, val) \ - ({ \ - ((uint64_t *)buf)[0] = (val); \ - POINTER_SHIFT(buf, sizeof(val)); \ +#define tPutC(buf, val) \ + ({ \ + if (buf) { \ + ((uint64_t *)buf)[0] = (val); \ + POINTER_SHIFT(buf, sizeof(val)); \ + } \ + NULL; \ }) -typedef enum { A, B, C } T; +#define tPutD(buf, val) \ + ({ \ + uint64_t tmp = val; \ + for (size_t i = 0; i < sizeof(val); i++) { \ + ((uint8_t *)buf)[i] = tmp & 0xff; \ + tmp >>= 8; \ + } \ + POINTER_SHIFT(buf, sizeof(val)); \ + }) + +static inline void tPutE(void **buf, uint64_t val) { + if (buf) { + ((uint64_t *)(*buf))[0] = val; + *buf = POINTER_SHIFT(*buf, sizeof(val)); + } +} + +typedef enum { A, B, C, D, E } T; static void func(T t) { uint64_t val = 198; @@ -59,6 +83,22 @@ static void func(T t) { } } break; + case D: + for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { + pBuf = tPutD(pBuf, val); + if (POINTER_DISTANCE(buf, pBuf) == 1024) { + pBuf = buf; + } + } + break; + case E: + for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { + tPutE(&pBuf, val); + if (POINTER_DISTANCE(buf, pBuf) == 1024) { + pBuf = buf; + } + } + break; default: break; @@ -83,5 +123,11 @@ int main(int argc, char const *argv[]) { func(C); uint64_t t4 = now(); printf("C: %ld\n", t4 - t3); + func(D); + uint64_t t5 = now(); + printf("D: %ld\n", t5 - t4); + func(E); + uint64_t t6 = now(); + printf("E: %ld\n", t6 - t5); return 0; } diff --git a/include/client/taos.h b/include/client/taos.h index 735747855521120f01327dc006dcbf80d2ea348f..4669ca51f7d80dd40a9d37047cf758faa680c9c8 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -193,6 +193,9 @@ DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr); DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList); DLL_EXPORT TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision); + +DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sqlLen); + #ifdef __cplusplus } #endif diff --git a/include/common/common.h b/include/common/common.h index 1c3a0e22f7a64c4afc59282676edac18bfa2543f..0ae06e5a7f91406dbed933c9c5b95a18abcfbfdc 100644 --- a/include/common/common.h +++ b/include/common/common.h @@ -17,7 +17,7 @@ #define TDENGINE_COMMON_H #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tvariant.h" //typedef struct STimeWindow { diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 9b2bb897931c46900fec781660081eb12a6f37c2..46c0c98ff00f5b81bab4cf55518be65089817812 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -20,36 +20,38 @@ extern "C" { #endif -#include "tdef.h" #include "taos.h" +#include "tdef.h" -#define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX}) -#define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN}) +typedef uint64_t tb_uid_t; + +#define TSWINDOW_INITIALIZER ((STimeWindow){INT64_MIN, INT64_MAX}) +#define TSWINDOW_DESC_INITIALIZER ((STimeWindow){INT64_MAX, INT64_MIN}) #define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) typedef enum { - TAOS_QTYPE_RPC = 1, - TAOS_QTYPE_FWD = 2, - TAOS_QTYPE_WAL = 3, - TAOS_QTYPE_CQ = 4, + TAOS_QTYPE_RPC = 1, + TAOS_QTYPE_FWD = 2, + TAOS_QTYPE_WAL = 3, + TAOS_QTYPE_CQ = 4, TAOS_QTYPE_QUERY = 5 } EQType; typedef enum { - TSDB_SUPER_TABLE = 1, // super table - TSDB_CHILD_TABLE = 2, // table created from super table - TSDB_NORMAL_TABLE = 3, // ordinary table - TSDB_STREAM_TABLE = 4, // table created from stream computing - TSDB_TEMP_TABLE = 5, // temp table created by nest query + TSDB_SUPER_TABLE = 1, // super table + TSDB_CHILD_TABLE = 2, // table created from super table + TSDB_NORMAL_TABLE = 3, // ordinary table + TSDB_STREAM_TABLE = 4, // table created from stream computing + TSDB_TEMP_TABLE = 5, // temp table created by nest query TSDB_TABLE_MAX = 6 } ETableType; typedef enum { - TSDB_MOD_MNODE = 1, - TSDB_MOD_HTTP = 2, + TSDB_MOD_MNODE = 1, + TSDB_MOD_HTTP = 2, TSDB_MOD_MONITOR = 3, - TSDB_MOD_MQTT = 4, - TSDB_MOD_MAX = 5 + TSDB_MOD_MQTT = 4, + TSDB_MOD_MAX = 5 } EModuleType; typedef enum { @@ -64,11 +66,7 @@ typedef enum { TSDB_CHECK_ITEM_MAX } ECheckItemType; -typedef enum { - TD_ROW_DISCARD_UPDATE = 0, - TD_ROW_OVERWRITE_UPDATE = 1, - TD_ROW_PARTIAL_UPDATE = 2 -} TDUpdateConfig; +typedef enum { TD_ROW_DISCARD_UPDATE = 0, TD_ROW_OVERWRITE_UPDATE = 1, TD_ROW_PARTIAL_UPDATE = 2 } TDUpdateConfig; extern char *qtypeStr[]; diff --git a/include/common/tep.h b/include/common/tep.h index 2addc11e5a6251be8cfcb1ca4ef688edcfbde56f..c8f45e4c82d94c0b7177777cc227b98c2c1414a0 100644 --- a/include/common/tep.h +++ b/include/common/tep.h @@ -2,7 +2,7 @@ #define TDENGINE_TEP_H #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" typedef struct SCorEpSet { int32_t version; @@ -13,5 +13,6 @@ int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port); bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2); void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet); +SEpSet getEpSet_s(SCorEpSet *pEpSet); #endif // TDENGINE_TEP_H diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 42956b6bdde2b27f3921817b90a1cc871ca0a8dd..e8a56b77c95dacc3c457f84e1b5c2784e8c1043e 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -30,11 +30,12 @@ extern char tsLocalEp[]; extern uint16_t tsServerPort; extern int32_t tsStatusInterval; extern int8_t tsEnableTelemetryReporting; +extern int32_t tsNumOfSupportVnodes; // common extern int tsRpcTimer; extern int tsRpcMaxTime; -extern int tsRpcForceTcp; // all commands go to tcp protocol if this is enabled +extern int tsRpcForceTcp; // all commands go to tcp protocol if this is enabled extern int32_t tsMaxConnections; extern int32_t tsMaxShellConns; extern int32_t tsShellActivityTimer; @@ -48,14 +49,18 @@ extern int32_t tsCompressMsgSize; extern int32_t tsCompressColData; extern int32_t tsMaxNumOfDistinctResults; extern char tsTempDir[]; -extern int64_t tsMaxVnodeQueuedBytes; -extern int tsCompatibleModel; // 2.0 compatible model - -//query buffer management -extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing -extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node during query processing -extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked -extern int8_t tsKeepOriginalColumnName; +extern int tsCompatibleModel; // 2.0 compatible model +extern int8_t tsEnableSlaveQuery; +extern int8_t tsEnableAdjustMaster; +extern int8_t tsPrintAuth; +extern int64_t tsTickPerDay[3]; + +// query buffer management +extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing +extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node +extern int32_t tsRetrieveBlockingModel; // retrieve threads will be blocked +extern int8_t tsKeepOriginalColumnName; +extern int8_t tsDeadLockKillQuery; // client extern int32_t tsMaxSQLStringLen; @@ -72,27 +77,17 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the extern int32_t tsProjectExecInterval; extern int64_t tsMaxRetentWindow; -// balance -extern int8_t tsEnableSlaveQuery; - - -// interna -extern int8_t tsPrintAuth; -extern char tsVnodeDir[]; -extern char tsMnodeDir[]; -extern int64_t tsTickPerDay[3]; - // system info -extern float tsTotalLogDirGB; -extern float tsTotalTmpDirGB; -extern float tsTotalDataDirGB; -extern float tsAvailLogDirGB; -extern float tsAvailTmpDirectorySpace; -extern float tsAvailDataDirGB; -extern float tsUsedDataDirGB; -extern float tsMinimalLogDirGB; -extern float tsReservedTmpDirectorySpace; -extern float tsMinimalDataDirGB; +extern float tsTotalLogDirGB; +extern float tsTotalTmpDirGB; +extern float tsTotalDataDirGB; +extern float tsAvailLogDirGB; +extern float tsAvailTmpDirectorySpace; +extern float tsAvailDataDirGB; +extern float tsUsedDataDirGB; +extern float tsMinimalLogDirGB; +extern float tsReservedTmpDirectorySpace; +extern float tsMinimalDataDirGB; extern uint32_t tsVersion; // build info @@ -102,17 +97,13 @@ extern char gitinfo[]; extern char gitinfoOfInternal[]; extern char buildinfo[]; -#ifdef TD_TSZ -// lossy -extern char lossyColumns[]; -extern double fPrecision; -extern double dPrecision; -extern uint32_t maxRange; -extern uint32_t curRange; -extern char Compressor[]; -#endif -// long query -extern int8_t tsDeadLockKillQuery; +// lossy +extern char tsLossyColumns[]; +extern double tsFPrecision; +extern double tsDPrecision; +extern uint32_t tsMaxRange; +extern uint32_t tsCurRange; +extern char tsCompressor[]; typedef struct { char dir[TSDB_FILENAME_LEN]; diff --git a/include/common/taosmsg.h b/include/common/tmsg.h similarity index 67% rename from include/common/taosmsg.h rename to include/common/tmsg.h index ec51a67808aafdc2c183111a785cf7d0ad3013ef..884379eabdfdea5eb507c212417823a4c3e1cd05 100644 --- a/include/common/taosmsg.h +++ b/include/common/tmsg.h @@ -20,130 +20,83 @@ extern "C" { #endif +#include "encode.h" #include "taosdef.h" #include "taoserror.h" +#include "tcoding.h" #include "tdataformat.h" +#include "tlist.h" + +/* ------------------------ MESSAGE DEFINITIONS ------------------------ */ +#define TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" + +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#define TD_MSG_SEG_CODE_ +#include "tmsgdef.h" + +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" + +extern char* tMsgInfo[]; +extern int tMsgDict[]; + +#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) +#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) +#define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] +#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)) + +typedef uint16_t tmsg_t; + +/* ------------------------ ENCODE/DECODE FUNCTIONS AND MACROS ------------------------ */ +struct SMEListNode { + TD_SLIST_NODE(SMEListNode); + SEncoder coder; +}; -// message type - -#ifdef TAOS_MESSAGE_C -#define TAOS_DEFINE_MESSAGE_TYPE( name, msg ) msg, msg "-rsp", -char *taosMsg[] = { - "null", -#else -#define TAOS_DEFINE_MESSAGE_TYPE( name, msg ) name, name##_RSP, -enum { - TSDB_MESSAGE_NULL = 0, -#endif +typedef struct SMsgEncoder { + SEncoder coder; + TD_SLIST(SMEListNode) eStack; // encode stack +} SMsgEncoder; -// message from client to vnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SUBMIT, "submit" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_QUERY, "query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_FETCH, "fetch" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TABLE, "create-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TABLE, "drop-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TABLE, "alter-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_UPDATE_TAG_VAL, "update-tag-val" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLE_META, "table-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLES_META, "tables-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET_CUR, "mq-set-cur" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RES_READY, "res-ready" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TASKS_STATUS, "tasks-status" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CANCEL_TASK, "cancel-task" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TASK, "drop-task" ) - -// message from client to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_ACCT, "alter-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_ACCT, "drop-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_USER, "create-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_USER, "alter-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_USER, "drop-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DNODE, "create-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE, "config-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DNODE, "drop-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE, "create-mnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE, "drop-mnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DB, "create-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_USE_DB, "use-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_DB, "alter-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_DB, "sync-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_DB, "compact-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_FUNCTION, "create-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RETRIEVE_FUNCTION, "retrieve-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_FUNCTION, "drop-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_VGROUP_LIST, "vgroup-list" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW_RETRIEVE, "retrieve" ) -// message from client to qnode -// message from client to dnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) - -// message from vnode to vnode -// message from vnode to mnode -// message from vnode to qnode -// message from vnode to dnode - -// message from mnode to vnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-internal" ) -// message from mnode to mnode -// message from mnode to qnode -// message from mnode to dnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_MNODE_IN, "alter-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE_IN, "drop-mnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE_IN, "config-dnode-internal" ) - -// message from qnode to vnode -// message from qnode to mnode -// message from qnode to qnode -// message from qnode to dnode - -// message from dnode to vnode -// message from dnode to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STATUS, "status" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_GRANT, "grant" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH, "auth" ) -// message from dnode to qnode -// message from dnode to dnode - -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY0, "dummy0" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY1, "dummy1" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY2, "dummy2" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY3, "dummy3" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY4, "dummy4" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY5, "dummy5" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY6, "dummy6" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY7, "dummy7" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY8, "dummy8" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY9, "dummy9" ) - -#ifndef TAOS_MESSAGE_C - TSDB_MSG_TYPE_MAX // 147 -#endif +struct SMDFreeListNode { + TD_SLIST_NODE(SMDFreeListNode); + char payload[]; +}; +struct SMDListNode { + TD_SLIST_NODE(SMDListNode); + SDecoder coder; }; +typedef struct SMsgDecoder { + SDecoder coder; + TD_SLIST(SMDListNode) dStack; + TD_SLIST(SMDFreeListNode) freeList; +} SMsgDecoder; + +#define TMSG_MALLOC(SIZE, DECODER) \ + ({ \ + void* ptr = malloc((SIZE) + sizeof(struct SMDFreeListNode)); \ + if (ptr) { \ + TD_SLIST_PUSH(&((DECODER)->freeList), (struct SMDFreeListNode*)ptr); \ + ptr = POINTER_SHIFT(ptr, sizeof(struct SMDFreeListNode*)); \ + } \ + ptr; \ + }) + +void tmsgInitMsgDecoder(SMsgDecoder* pMD, td_endian_t endian, uint8_t* data, int64_t size); +void tmsgClearMsgDecoder(SMsgDecoder* pMD); + +/* ------------------------ OTHER DEFINITIONS ------------------------ */ // IE type #define TSDB_IE_TYPE_SEC 1 #define TSDB_IE_TYPE_META 2 @@ -161,6 +114,9 @@ typedef enum _mgmt_table { TSDB_MGMT_TABLE_TABLE, TSDB_MGMT_TABLE_DNODE, TSDB_MGMT_TABLE_MNODE, + TSDB_MGMT_TABLE_QNODE, + TSDB_MGMT_TABLE_SNODE, + TSDB_MGMT_TABLE_BNODE, TSDB_MGMT_TABLE_VGROUP, TSDB_MGMT_TABLE_STB, TSDB_MGMT_TABLE_MODULE, @@ -178,48 +134,46 @@ typedef enum _mgmt_table { TSDB_MGMT_TABLE_MAX, } EShowType; -#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1 -#define TSDB_ALTER_TABLE_DROP_TAG_COLUMN 2 +#define TSDB_ALTER_TABLE_ADD_TAG_COLUMN 1 +#define TSDB_ALTER_TABLE_DROP_TAG_COLUMN 2 #define TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN 3 -#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 +#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 -#define TSDB_ALTER_TABLE_ADD_COLUMN 5 -#define TSDB_ALTER_TABLE_DROP_COLUMN 6 -#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7 +#define TSDB_ALTER_TABLE_ADD_COLUMN 5 +#define TSDB_ALTER_TABLE_DROP_COLUMN 6 +#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7 #define TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN 8 -#define TSDB_FILL_NONE 0 -#define TSDB_FILL_NULL 1 -#define TSDB_FILL_SET_VALUE 2 -#define TSDB_FILL_LINEAR 3 -#define TSDB_FILL_PREV 4 -#define TSDB_FILL_NEXT 5 +#define TSDB_FILL_NONE 0 +#define TSDB_FILL_NULL 1 +#define TSDB_FILL_SET_VALUE 2 +#define TSDB_FILL_LINEAR 3 +#define TSDB_FILL_PREV 4 +#define TSDB_FILL_NEXT 5 -#define TSDB_ALTER_USER_PASSWD 0x1 +#define TSDB_ALTER_USER_PASSWD 0x1 #define TSDB_ALTER_USER_PRIVILEGES 0x2 -#define TSDB_KILL_MSG_LEN 30 +#define TSDB_KILL_MSG_LEN 30 -#define TSDB_VN_READ_ACCCESS ((char)0x1) -#define TSDB_VN_WRITE_ACCCESS ((char)0x2) +#define TSDB_VN_READ_ACCCESS ((char)0x1) +#define TSDB_VN_WRITE_ACCCESS ((char)0x2) #define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS) -#define TSDB_COL_NORMAL 0x0u // the normal column of the table -#define TSDB_COL_TAG 0x1u // the tag column type -#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column -#define TSDB_COL_TMP 0x4u // internal column generated by the previous operators -#define TSDB_COL_NULL 0x8u // the column filter NULL or not - -#define TSDB_COL_IS_TAG(f) (((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0) -#define TSDB_COL_IS_NORMAL_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL) -#define TSDB_COL_IS_UD_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC) -#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0) +#define TSDB_COL_NORMAL 0x0u // the normal column of the table +#define TSDB_COL_TAG 0x1u // the tag column type +#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column +#define TSDB_COL_TMP 0x4u // internal column generated by the previous operators +#define TSDB_COL_NULL 0x8u // the column filter NULL or not -extern char *taosMsg[]; +#define TSDB_COL_IS_TAG(f) (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0) +#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL) +#define TSDB_COL_IS_UD_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC) +#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0) typedef struct SBuildTableMetaInput { int32_t vgId; - char *tableFullName; + char* tableFullName; } SBuildTableMetaInput; typedef struct SBuildUseDBInput { @@ -227,7 +181,6 @@ typedef struct SBuildUseDBInput { int32_t vgVersion; } SBuildUseDBInput; - #pragma pack(push, 1) // null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta @@ -312,7 +265,7 @@ typedef struct { char data[]; } SMDCreateTableMsg; -//typedef struct { +// typedef struct { // int32_t len; // one create table message // char tableName[TSDB_TABLE_FNAME_LEN]; // int16_t numOfColumns; @@ -355,19 +308,7 @@ typedef struct { SMsgHead head; char name[TSDB_TABLE_FNAME_LEN]; uint64_t suid; - int32_t sverson; - uint32_t ttl; - uint32_t keep; - int32_t numOfTags; - int32_t numOfColumns; - SSchema pSchema[]; -} SCreateStbInternalMsg; - -typedef struct { - SMsgHead head; - char name[TSDB_TABLE_FNAME_LEN]; - uint64_t suid; -} SDropStbInternalMsg; +} SVDropStbReq; typedef struct { SMsgHead head; @@ -412,13 +353,25 @@ typedef struct SEpSet { char fqdn[TSDB_MAX_REPLICA][TSDB_FQDN_LEN]; } SEpSet; +static FORCE_INLINE int taosEncodeSEpSet(void** buf, const SEpSet* pEp) { + if(buf == NULL) return sizeof(SEpSet); + memcpy(buf, pEp, sizeof(SEpSet)); + //TODO: endian conversion + return sizeof(SEpSet); +} + +static FORCE_INLINE void* taosDecodeSEpSet(void* buf, SEpSet* pEpSet) { + memcpy(pEpSet, buf, sizeof(SEpSet)); + return buf; +} + typedef struct { - int32_t acctId; - uint32_t clusterId; - int32_t connId; - int8_t superUser; - int8_t reserved[5]; - SEpSet epSet; + int32_t acctId; + int64_t clusterId; + int32_t connId; + int8_t superUser; + int8_t reserved[5]; + SEpSet epSet; } SConnectRsp; typedef struct { @@ -442,7 +395,7 @@ typedef struct { int8_t type; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; - int8_t superUser; // denote if it is a super user or not + int8_t superUser; // denote if it is a super user or not int32_t reserve[8]; } SCreateUserMsg, SAlterUserMsg; @@ -465,7 +418,7 @@ typedef struct SColIndex { int16_t colId; // column id int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag int16_t flag; // denote if it is a tag or a normal column - char name[TSDB_COL_NAME_LEN + TSDB_DB_NAME_LEN + 1]; + char name[TSDB_DB_FNAME_LEN]; } SColIndex; typedef struct SColumnFilterInfo { @@ -493,7 +446,7 @@ typedef struct SColumnFilterList { int16_t numOfFilters; union { int64_t placeholder; - SColumnFilterInfo *filterInfo; + SColumnFilterInfo* filterInfo; }; } SColumnFilterList; /* @@ -578,8 +531,8 @@ typedef struct { int32_t sqlstrLen; // sql query string int32_t prevResultLen; // previous result length int32_t numOfOperator; - int32_t tableScanOperator;// table scan operator. -1 means no scan operator - int32_t udfNum; // number of udf function + int32_t tableScanOperator; // table scan operator. -1 means no scan operator + int32_t udfNum; // number of udf function int32_t udfContentOffset; int32_t udfContentLen; SColumnInfo tableCols[]; @@ -587,10 +540,6 @@ typedef struct { typedef struct { int32_t code; - union { - uint64_t qhandle; - uint64_t qId; - }; // query handle } SQueryTableRsp; // todo: the show handle should be replaced with id @@ -616,7 +565,7 @@ typedef struct SRetrieveTableRsp { } SRetrieveTableRsp; typedef struct { - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int32_t numOfVgroups; int32_t cacheBlockSize; // MB int32_t totalBlocks; @@ -640,7 +589,7 @@ typedef struct { } SCreateDbMsg; typedef struct { - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int32_t totalBlocks; int32_t daysToKeep0; int32_t daysToKeep1; @@ -742,22 +691,23 @@ typedef struct { typedef struct { int32_t sver; int32_t dnodeId; - int32_t clusterId; - int64_t rebootTime; // time stamp for last reboot - int16_t numOfCores; - int16_t numOfSupportMnodes; - int16_t numOfSupportVnodes; - int16_t numOfSupportQnodes; + int64_t clusterId; + int64_t rebootTime; + int64_t updateTime; + int32_t numOfCores; + int32_t numOfSupportVnodes; char dnodeEp[TSDB_EP_LEN]; SClusterCfg clusterCfg; SVnodeLoads vnodeLoads; } SStatusMsg; +typedef struct { + int32_t reserved; +} STransMsg; + typedef struct { int32_t dnodeId; - int32_t clusterId; - int8_t dropped; - char reserved[7]; + int64_t clusterId; } SDnodeCfg; typedef struct { @@ -787,7 +737,7 @@ typedef struct { typedef struct { int32_t vgId; int32_t dnodeId; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; uint64_t dbUid; int32_t vgVersion; int32_t cacheBlockSize; @@ -814,7 +764,7 @@ typedef struct { typedef struct { int32_t vgId; int32_t dnodeId; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; uint64_t dbUid; } SDropVnodeMsg, SSyncVnodeMsg, SCompactVnodeMsg; @@ -886,11 +836,11 @@ typedef struct SMultiTableMeta { typedef struct { int32_t dataLen; char name[TSDB_TABLE_FNAME_LEN]; - char *data; + char* data; } STagData; typedef struct { - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int32_t vgVersion; int32_t vgNum; int8_t hashMethod; @@ -904,13 +854,13 @@ typedef struct { */ typedef struct { int8_t type; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int16_t payloadLen; char payload[]; } SShowMsg; typedef struct { - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int32_t numOfVgroup; int32_t vgid[]; } SCompactMsg; @@ -921,35 +871,40 @@ typedef struct SShowRsp { } SShowRsp; typedef struct { - char ep[TSDB_EP_LEN]; // end point, hostname:port - int32_t reserve[8]; + char fqdn[TSDB_FQDN_LEN]; // end point, hostname:port + int32_t port; } SCreateDnodeMsg; typedef struct { int32_t dnodeId; - int32_t reserve[8]; } SDropDnodeMsg; typedef struct { int32_t dnodeId; char config[TSDB_DNODE_CONFIG_LEN]; - int32_t reserve[8]; } SCfgDnodeMsg; typedef struct { int32_t dnodeId; -} SCreateMnodeMsg, SDropMnodeMsg; +} SMCreateMnodeMsg, SMDropMnodeMsg, SDDropMnodeMsg; typedef struct { int32_t dnodeId; - int8_t align[3]; int8_t replica; SReplica replicas[TSDB_MAX_REPLICA]; -} SCreateMnodeInMsg, SAlterMnodeInMsg; +} SDCreateMnodeMsg, SDAlterMnodeMsg; + +typedef struct { + int32_t dnodeId; +} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg; + +typedef struct { + int32_t dnodeId; +} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg; typedef struct { int32_t dnodeId; -} SDropMnodeInMsg; +} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg; typedef struct { int32_t dnodeId; @@ -1027,35 +982,27 @@ typedef struct { // mq related typedef struct { - } SMqConnectReq; typedef struct { - } SMqConnectRsp; typedef struct { - } SMqDisconnectReq; typedef struct { - } SMqDisconnectRsp; typedef struct { - } SMqAckReq; typedef struct { - } SMqAckRsp; typedef struct { - } SMqResetReq; typedef struct { - } SMqResetRsp; // mq related end @@ -1112,33 +1059,37 @@ typedef struct { } SUpdateTagValRsp; typedef struct SSubQueryMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; - uint32_t contentLen; - char msg[]; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; + uint32_t contentLen; + char msg[]; } SSubQueryMsg; typedef struct SResReadyMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; } SResReadyMsg; +typedef struct SResReadyRsp { + int32_t code; +} SResReadyRsp; + typedef struct SResFetchMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; } SResFetchMsg; typedef struct SSchTasksStatusMsg { - uint64_t schedulerId; + uint64_t sId; } SSchTasksStatusMsg; typedef struct STaskStatus { - uint64_t queryId; - uint64_t taskId; - int8_t status; + uint64_t queryId; + uint64_t taskId; + int8_t status; } STaskStatus; typedef struct SSchedulerStatusRsp { @@ -1146,19 +1097,212 @@ typedef struct SSchedulerStatusRsp { STaskStatus status[]; } SSchedulerStatusRsp; - typedef struct STaskCancelMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; } STaskCancelMsg; +typedef struct STaskCancelRsp { + int32_t code; +} STaskCancelRsp; + typedef struct STaskDropMsg { - uint64_t schedulerId; - uint64_t queryId; - uint64_t taskId; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; } STaskDropMsg; +typedef struct STaskDropRsp { + int32_t code; +} STaskDropRsp; + +typedef struct { + int8_t igExists; + char* name; + char* physicalPlan; + char* logicalPlan; +} SCMCreateTopicReq; + +static FORCE_INLINE int tSerializeSCMCreateTopicReq(void** buf, const SCMCreateTopicReq* pReq) { + int tlen = 0; + tlen += taosEncodeString(buf, pReq->name); + tlen += taosEncodeFixedI8(buf, pReq->igExists); + tlen += taosEncodeString(buf, pReq->physicalPlan); + tlen += taosEncodeString(buf, pReq->logicalPlan); + return tlen; +} + +static FORCE_INLINE void* tDeserializeSCMCreateTopicReq(void* buf, SCMCreateTopicReq* pReq) { + buf = taosDecodeFixedI8(buf, &(pReq->igExists)); + buf = taosDecodeString(buf, &(pReq->name)); + buf = taosDecodeString(buf, &(pReq->physicalPlan)); + buf = taosDecodeString(buf, &(pReq->logicalPlan)); + return buf; +} + +typedef struct { + int64_t topicId; +} SCMCreateTopicRsp; + +static FORCE_INLINE int tSerializeSCMCreateTopicRsp(void** buf, const SCMCreateTopicRsp* pRsp) { + int tlen = 0; + tlen += taosEncodeFixedI64(buf, pRsp->topicId); + return tlen; +} + +static FORCE_INLINE void* tDeserializeSCMCreateTopicRsp(void* buf, SCMCreateTopicRsp* pRsp) { + buf = taosDecodeFixedI64(buf, &pRsp->topicId); + return buf; +} + +typedef struct { + char* topicName; + char* consumerGroup; + int64_t consumerId; +} SCMSubscribeReq; + +static FORCE_INLINE int tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) { + int tlen = 0; + tlen += taosEncodeString(buf, pReq->topicName); + tlen += taosEncodeString(buf, pReq->consumerGroup); + tlen += taosEncodeFixedI64(buf, pReq->consumerId); + return tlen; +} + +static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) { + buf = taosDecodeString(buf, &pReq->topicName); + buf = taosDecodeString(buf, &pReq->consumerGroup); + buf = taosDecodeFixedI64(buf, &pReq->consumerId); + return buf; +} + +typedef struct { + int32_t vgId; + SEpSet pEpSet; +} SCMSubscribeRsp; + +static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) { + int tlen = 0; + tlen += taosEncodeFixedI32(buf, pRsp->vgId); + tlen += taosEncodeSEpSet(buf, &pRsp->pEpSet); + return tlen; +} + +static FORCE_INLINE void* tDeserializeSCMSubscribeRsp(void* buf, SCMSubscribeRsp* pRsp) { + buf = taosDecodeFixedI32(buf, &pRsp->vgId); + buf = taosDecodeSEpSet(buf, &pRsp->pEpSet); + return buf; +} + +typedef struct { + int64_t topicId; + int64_t consumerId; + int64_t consumerGroupId; + int64_t offset; +} SMVSubscribeReq; + +typedef struct { + int64_t newOffset; +} SMVSubscribeRsp; + +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + int8_t igExists; + int32_t execLen; + void* executor; + int32_t sqlLen; + char* sql; +} SCreateTopicMsg; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igNotExists; +} SDropTopicMsg; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t alterType; + SSchema schema; +} SAlterTopicMsg; + +typedef struct { + SMsgHead head; + char name[TSDB_TABLE_FNAME_LEN]; + uint64_t tuid; + int32_t sverson; + int32_t execLen; + char* executor; + int32_t sqlLen; + char* sql; +} SDCreateTopicMsg; + +typedef struct { + SMsgHead head; + char name[TSDB_TABLE_FNAME_LEN]; + uint64_t tuid; +} SDDropTopicMsg; + +typedef struct SVCreateTbReq { + uint64_t ver; // use a general definition + char* name; + uint32_t ttl; + uint32_t keep; +#define TD_SUPER_TABLE 0 +#define TD_CHILD_TABLE 1 +#define TD_NORMAL_TABLE 2 + uint8_t type; + union { + struct { + tb_uid_t suid; + uint32_t nCols; + SSchema* pSchema; + uint32_t nTagCols; + SSchema* pTagSchema; + } stbCfg; + struct { + tb_uid_t suid; + SKVRow pTag; + } ctbCfg; + struct { + uint32_t nCols; + SSchema* pSchema; + } ntbCfg; + }; +} SVCreateTbReq; + +int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); +int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); +int tSerializeSVCreateTbReq(void** buf, const SVCreateTbReq* pReq); +void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq); + +typedef struct SVCreateTbRsp { +} SVCreateTbRsp; + +typedef struct SVShowTablesReq { + SMsgHead head; +} SVShowTablesReq; + +typedef struct SVShowTablesRsp { + int32_t id; + STableMetaMsg metaInfo; +} SVShowTablesRsp; + +typedef struct SVShowTablesFetchReq { + SMsgHead head; + int32_t id; +} SVShowTablesFetchReq; + +typedef struct SVShowTablesFetchRsp { + int64_t useconds; + int8_t completed; // all results are returned to client + int8_t precision; + int8_t compressed; + int32_t compLen; + + int32_t numOfRows; + char data[]; +} SVShowTablesFetchRsp; #pragma pack(pop) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h new file mode 100644 index 0000000000000000000000000000000000000000..d6071ebcf3be2553b34e889331419178d91f203f --- /dev/null +++ b/include/common/tmsgdef.h @@ -0,0 +1,185 @@ +/* + * 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 . + */ + +#if 0 +#undef TD_MSG_INFO_ +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#undef TD_MSG_SEG_CODE_ +#endif + +#if defined(TD_MSG_INFO_) + +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE +#define TD_NEW_MSG_SEG(TYPE) "null", +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) MSG, MSG "-rsp", + +char *tMsgInfo[] = { + +#elif defined(TD_MSG_NUMBER_) + +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE +#define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE##_NUM, TYPE##_RSP_NUM, + +enum { + +#elif defined(TD_MSG_DICT_) + +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE +#define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) + +int tMsgDict[] = { + +#elif defined(TD_MSG_SEG_CODE_) + +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE +#define TD_NEW_MSG_SEG(TYPE) TYPE##_SEG_CODE, +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) + +enum { + +#else + +#undef TD_NEW_MSG_SEG +#undef TD_DEF_MSG_TYPE +#define TD_NEW_MSG_SEG(TYPE) TYPE = ((TYPE##_SEG_CODE) << 8), +#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE, TYPE##_RSP, + +enum { +#endif + // Requests handled by DNODE + TD_NEW_MSG_SEG(TDMT_DND_MSG) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE, "dnode-alter-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_MNODE, "dnode-drop-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_QNODE, "dnode-create-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_QNODE, "dnode-alter-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_QNODE, "dnode-drop-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_SNODE, "dnode-create-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_SNODE, "dnode-alter-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_SNODE, "dnode-drop-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_BNODE, "dnode-create-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_BNODE, "dnode-alter-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_BNODE, "dnode-drop-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "dnode-create-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_ALTER_VNODE, "dnode-alter-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "dnode-drop-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_AUTH_VNODE, "dnode-auth-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_SYNC_VNODE, "dnode-sync-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_COMPACT_VNODE, "dnode-compact-vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_CONFIG_DNODE, "dnode-config-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_NETWORK_TEST, "dnode-nettest", NULL, NULL) + + // Requests handled by MNODE + TD_NEW_MSG_SEG(TDMT_MND_MSG) + TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "mnode-connect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "mnode-create-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_ACCT, "mnode-alter-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_ACCT, "mnode-drop-acct", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "mnode-create-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "mnode-alter-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "mnode-alter-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "mnode-drop-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "mnode-create-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "mnode-alter-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "mnode-drop-mnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "mnode-create-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "mnode-alter-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "mnode-drop-qnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "mnode-create-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "mnode-alter-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "mnode-drop-snode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "mnode-create-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "mnode-alter-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "mnode-drop-bnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "mnode-create-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "mnode-drop-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "mnode-use-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "mnode-alter-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "mnode-sync-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "mnode-compact-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNCTION, "mnode-create-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNCTION, "mnode-retrieve-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNCTION, "mnode-drop-function", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STB_META, "mnode-stb-meta", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TRANS, "mnode-trans", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SCMCreateTopicReq, SCMCreateTopicRsp) + TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp) + + // Requests handled by VNODE + TD_NEW_MSG_SEG(TDMT_VND_MSG) + TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "vnode-submit", SSubmitReq, SSubmitRsp) + TD_DEF_MSG_TYPE(TDMT_VND_QUERY, "vnode-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_FETCH, "vnode-fetch", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TABLE, "vnode-create-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TABLE, "vnode-alter-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TABLE, "vnode-drop-table", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "vnode-update-tag-val", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateTbReq, SVCreateTbRsp) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_DISCONNECT, "vnode-mq-disconnect", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CUR, "vnode-mq-set-cur", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_RES_READY, "vnode-res-ready", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TASKS_STATUS, "vnode-tasks-status", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TASK, "vnode-drop-task", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp) + TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp) + + TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp) + + + // Requests handled by QNODE + TD_NEW_MSG_SEG(TDMT_QND_MSG) + + // Requests handled by SNODE + TD_NEW_MSG_SEG(TDMT_SND_MSG) + +#if defined(TD_MSG_NUMBER_) + TDMT_MAX +#endif +}; diff --git a/include/common/tname.h b/include/common/tname.h index de9e309b5508aeb682c09d6df4766700900fdb16..11d97dac06d7240664f48626cd9d58ad6c555afa 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -16,18 +16,23 @@ #ifndef TDENGINE_TNAME_H #define TDENGINE_TNAME_H +#include "tdef.h" +#include "tmsg.h" + #define TSDB_DB_NAME_T 1 #define TSDB_TABLE_NAME_T 2 #define T_NAME_ACCT 0x1u #define T_NAME_DB 0x2u #define T_NAME_TABLE 0x4u +#define T_NAME_TOPIC 0x8u typedef struct SName { uint8_t type; //db_name_t, table_name_t int32_t acctId; char dbname[TSDB_DB_NAME_LEN]; char tname[TSDB_TABLE_NAME_LEN]; + char topicName[TSDB_TOPIC_NAME_LEN]; } SName; int32_t tNameExtractFullName(const SName* name, char* dst); @@ -54,4 +59,6 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type); int32_t tNameSetAcctId(SName* dst, int32_t acctId); +SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name); + #endif // TDENGINE_TNAME_H diff --git a/include/common/ttime.h b/include/common/ttime.h index ed6496aca670bb04f001e9a6f610cd1951e0dec5..e22e1d6c4ed9aeb406abce8468d3f92f4599c298 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -21,7 +21,7 @@ extern "C" { #endif #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y') diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 5f9fe5134bb9b6ac7cb5c8996b26e7a7e86017a2..90926da1203d456cd029356bab9bbb960fe1bf4e 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -13,205 +13,199 @@ * along with this program. If not, see . */ -#ifndef _TD_COMMON_TOKEN_DEF_H_ -#define _TD_COMMON_TOKEN_DEF_H_ +#ifndef TDENGINE_TTOKENDEF_H +#define TDENGINE_TTOKENDEF_H #define TK_ID 1 #define TK_BOOL 2 -#define TK_TINYINT 3 -#define TK_SMALLINT 4 -#define TK_INTEGER 5 -#define TK_BIGINT 6 -#define TK_FLOAT 7 -#define TK_DOUBLE 8 -#define TK_STRING 9 -#define TK_TIMESTAMP 10 -#define TK_BINARY 11 -#define TK_NCHAR 12 -#define TK_OR 13 -#define TK_AND 14 -#define TK_NOT 15 -#define TK_EQ 16 -#define TK_NE 17 -#define TK_ISNULL 18 -#define TK_NOTNULL 19 -#define TK_IS 20 -#define TK_LIKE 21 -#define TK_MATCH 22 -#define TK_NMATCH 23 -#define TK_GLOB 24 -#define TK_BETWEEN 25 -#define TK_IN 26 -#define TK_GT 27 -#define TK_GE 28 -#define TK_LT 29 -#define TK_LE 30 -#define TK_BITAND 31 -#define TK_BITOR 32 -#define TK_LSHIFT 33 -#define TK_RSHIFT 34 -#define TK_PLUS 35 -#define TK_MINUS 36 -#define TK_DIVIDE 37 -#define TK_TIMES 38 -#define TK_STAR 39 -#define TK_SLASH 40 -#define TK_REM 41 -#define TK_CONCAT 42 -#define TK_UMINUS 43 -#define TK_UPLUS 44 -#define TK_BITNOT 45 -#define TK_SHOW 46 -#define TK_DATABASES 47 -#define TK_TOPICS 48 -#define TK_FUNCTIONS 49 -#define TK_MNODES 50 -#define TK_DNODES 51 -#define TK_ACCOUNTS 52 -#define TK_USERS 53 -#define TK_MODULES 54 -#define TK_QUERIES 55 -#define TK_CONNECTIONS 56 -#define TK_STREAMS 57 -#define TK_VARIABLES 58 -#define TK_SCORES 59 -#define TK_GRANTS 60 -#define TK_VNODES 61 -#define TK_DOT 62 -#define TK_CREATE 63 -#define TK_TABLE 64 -#define TK_STABLE 65 -#define TK_DATABASE 66 -#define TK_TABLES 67 -#define TK_STABLES 68 -#define TK_VGROUPS 69 -#define TK_DROP 70 -#define TK_TOPIC 71 -#define TK_FUNCTION 72 -#define TK_DNODE 73 -#define TK_USER 74 -#define TK_ACCOUNT 75 -#define TK_USE 76 -#define TK_DESCRIBE 77 -#define TK_DESC 78 -#define TK_ALTER 79 -#define TK_PASS 80 -#define TK_PRIVILEGE 81 -#define TK_LOCAL 82 -#define TK_COMPACT 83 -#define TK_LP 84 -#define TK_RP 85 -#define TK_IF 86 -#define TK_EXISTS 87 -#define TK_AS 88 -#define TK_OUTPUTTYPE 89 -#define TK_AGGREGATE 90 -#define TK_BUFSIZE 91 -#define TK_PPS 92 -#define TK_TSERIES 93 -#define TK_DBS 94 -#define TK_STORAGE 95 -#define TK_QTIME 96 -#define TK_CONNS 97 -#define TK_STATE 98 -#define TK_COMMA 99 -#define TK_KEEP 100 -#define TK_CACHE 101 -#define TK_REPLICA 102 -#define TK_QUORUM 103 -#define TK_DAYS 104 -#define TK_MINROWS 105 -#define TK_MAXROWS 106 -#define TK_BLOCKS 107 -#define TK_CTIME 108 -#define TK_WAL 109 -#define TK_FSYNC 110 -#define TK_COMP 111 -#define TK_PRECISION 112 -#define TK_UPDATE 113 -#define TK_CACHELAST 114 -#define TK_PARTITIONS 115 -#define TK_UNSIGNED 116 -#define TK_TAGS 117 -#define TK_USING 118 -#define TK_NULL 119 -#define TK_NOW 120 -#define TK_SELECT 121 -#define TK_UNION 122 -#define TK_ALL 123 -#define TK_DISTINCT 124 -#define TK_FROM 125 -#define TK_VARIABLE 126 -#define TK_INTERVAL 127 -#define TK_EVERY 128 -#define TK_SESSION 129 -#define TK_STATE_WINDOW 130 -#define TK_FILL 131 -#define TK_SLIDING 132 -#define TK_ORDER 133 -#define TK_BY 134 -#define TK_ASC 135 -#define TK_GROUP 136 -#define TK_HAVING 137 -#define TK_LIMIT 138 -#define TK_OFFSET 139 -#define TK_SLIMIT 140 -#define TK_SOFFSET 141 -#define TK_WHERE 142 -#define TK_RESET 143 -#define TK_QUERY 144 -#define TK_SYNCDB 145 -#define TK_ADD 146 -#define TK_COLUMN 147 -#define TK_MODIFY 148 -#define TK_TAG 149 -#define TK_CHANGE 150 -#define TK_SET 151 -#define TK_KILL 152 -#define TK_CONNECTION 153 -#define TK_STREAM 154 -#define TK_COLON 155 -#define TK_ABORT 156 -#define TK_AFTER 157 -#define TK_ATTACH 158 -#define TK_BEFORE 159 -#define TK_BEGIN 160 -#define TK_CASCADE 161 -#define TK_CLUSTER 162 -#define TK_CONFLICT 163 -#define TK_COPY 164 -#define TK_DEFERRED 165 -#define TK_DELIMITERS 166 -#define TK_DETACH 167 -#define TK_EACH 168 -#define TK_END 169 -#define TK_EXPLAIN 170 -#define TK_FAIL 171 -#define TK_FOR 172 -#define TK_IGNORE 173 -#define TK_IMMEDIATE 174 -#define TK_INITIALLY 175 -#define TK_INSTEAD 176 -#define TK_KEY 177 -#define TK_OF 178 -#define TK_RAISE 179 -#define TK_REPLACE 180 -#define TK_RESTRICT 181 -#define TK_ROW 182 -#define TK_STATEMENT 183 -#define TK_TRIGGER 184 -#define TK_VIEW 185 -#define TK_IPTOKEN 186 -#define TK_SEMI 187 -#define TK_NONE 188 -#define TK_PREV 189 -#define TK_LINEAR 190 -#define TK_IMPORT 191 -#define TK_TBNAME 192 -#define TK_JOIN 193 -#define TK_INSERT 194 -#define TK_INTO 195 -#define TK_VALUES 196 +#define TK_INTEGER 3 +#define TK_FLOAT 4 +#define TK_STRING 5 +#define TK_TIMESTAMP 6 +#define TK_OR 7 +#define TK_AND 8 +#define TK_NOT 9 +#define TK_EQ 10 +#define TK_NE 11 +#define TK_ISNULL 12 +#define TK_NOTNULL 13 +#define TK_IS 14 +#define TK_LIKE 15 +#define TK_MATCH 16 +#define TK_NMATCH 17 +#define TK_GLOB 18 +#define TK_BETWEEN 19 +#define TK_IN 20 +#define TK_GT 21 +#define TK_GE 22 +#define TK_LT 23 +#define TK_LE 24 +#define TK_BITAND 25 +#define TK_BITOR 26 +#define TK_LSHIFT 27 +#define TK_RSHIFT 28 +#define TK_PLUS 29 +#define TK_MINUS 30 +#define TK_DIVIDE 31 +#define TK_TIMES 32 +#define TK_STAR 33 +#define TK_SLASH 34 +#define TK_REM 35 +#define TK_CONCAT 36 +#define TK_UMINUS 37 +#define TK_UPLUS 38 +#define TK_BITNOT 39 +#define TK_SHOW 40 +#define TK_DATABASES 41 +#define TK_TOPICS 42 +#define TK_FUNCTIONS 43 +#define TK_MNODES 44 +#define TK_DNODES 45 +#define TK_ACCOUNTS 46 +#define TK_USERS 47 +#define TK_MODULES 48 +#define TK_QUERIES 49 +#define TK_CONNECTIONS 50 +#define TK_STREAMS 51 +#define TK_VARIABLES 52 +#define TK_SCORES 53 +#define TK_GRANTS 54 +#define TK_VNODES 55 +#define TK_DOT 56 +#define TK_CREATE 57 +#define TK_TABLE 58 +#define TK_STABLE 59 +#define TK_DATABASE 60 +#define TK_TABLES 61 +#define TK_STABLES 62 +#define TK_VGROUPS 63 +#define TK_DROP 64 +#define TK_TOPIC 65 +#define TK_FUNCTION 66 +#define TK_DNODE 67 +#define TK_USER 68 +#define TK_ACCOUNT 69 +#define TK_USE 70 +#define TK_DESCRIBE 71 +#define TK_DESC 72 +#define TK_ALTER 73 +#define TK_PASS 74 +#define TK_PRIVILEGE 75 +#define TK_LOCAL 76 +#define TK_COMPACT 77 +#define TK_LP 78 +#define TK_RP 79 +#define TK_IF 80 +#define TK_EXISTS 81 +#define TK_PORT 82 +#define TK_IPTOKEN 83 +#define TK_AS 84 +#define TK_OUTPUTTYPE 85 +#define TK_AGGREGATE 86 +#define TK_BUFSIZE 87 +#define TK_PPS 88 +#define TK_TSERIES 89 +#define TK_DBS 90 +#define TK_STORAGE 91 +#define TK_QTIME 92 +#define TK_CONNS 93 +#define TK_STATE 94 +#define TK_COMMA 95 +#define TK_KEEP 96 +#define TK_CACHE 97 +#define TK_REPLICA 98 +#define TK_QUORUM 99 +#define TK_DAYS 100 +#define TK_MINROWS 101 +#define TK_MAXROWS 102 +#define TK_BLOCKS 103 +#define TK_CTIME 104 +#define TK_WAL 105 +#define TK_FSYNC 106 +#define TK_COMP 107 +#define TK_PRECISION 108 +#define TK_UPDATE 109 +#define TK_CACHELAST 110 +#define TK_UNSIGNED 111 +#define TK_TAGS 112 +#define TK_USING 113 +#define TK_NULL 114 +#define TK_NOW 115 +#define TK_SELECT 116 +#define TK_UNION 117 +#define TK_ALL 118 +#define TK_DISTINCT 119 +#define TK_FROM 120 +#define TK_VARIABLE 121 +#define TK_INTERVAL 122 +#define TK_EVERY 123 +#define TK_SESSION 124 +#define TK_STATE_WINDOW 125 +#define TK_FILL 126 +#define TK_SLIDING 127 +#define TK_ORDER 128 +#define TK_BY 129 +#define TK_ASC 130 +#define TK_GROUP 131 +#define TK_HAVING 132 +#define TK_LIMIT 133 +#define TK_OFFSET 134 +#define TK_SLIMIT 135 +#define TK_SOFFSET 136 +#define TK_WHERE 137 +#define TK_RESET 138 +#define TK_QUERY 139 +#define TK_SYNCDB 140 +#define TK_ADD 141 +#define TK_COLUMN 142 +#define TK_MODIFY 143 +#define TK_TAG 144 +#define TK_CHANGE 145 +#define TK_SET 146 +#define TK_KILL 147 +#define TK_CONNECTION 148 +#define TK_STREAM 149 +#define TK_COLON 150 +#define TK_ABORT 151 +#define TK_AFTER 152 +#define TK_ATTACH 153 +#define TK_BEFORE 154 +#define TK_BEGIN 155 +#define TK_CASCADE 156 +#define TK_CLUSTER 157 +#define TK_CONFLICT 158 +#define TK_COPY 159 +#define TK_DEFERRED 160 +#define TK_DELIMITERS 161 +#define TK_DETACH 162 +#define TK_EACH 163 +#define TK_END 164 +#define TK_EXPLAIN 165 +#define TK_FAIL 166 +#define TK_FOR 167 +#define TK_IGNORE 168 +#define TK_IMMEDIATE 169 +#define TK_INITIALLY 170 +#define TK_INSTEAD 171 +#define TK_KEY 172 +#define TK_OF 173 +#define TK_RAISE 174 +#define TK_REPLACE 175 +#define TK_RESTRICT 176 +#define TK_ROW 177 +#define TK_STATEMENT 178 +#define TK_TRIGGER 179 +#define TK_VIEW 180 +#define TK_SEMI 181 +#define TK_NONE 182 +#define TK_PREV 183 +#define TK_LINEAR 184 +#define TK_IMPORT 185 +#define TK_TBNAME 186 +#define TK_JOIN 187 +#define TK_INSERT 188 +#define TK_INTO 189 +#define TK_VALUES 190 #define TK_SPACE 300 @@ -223,6 +217,6 @@ #define TK_FILE 306 #define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query -#endif /*_TD_COMMON_TOKEN_DEF_H_*/ +#endif diff --git a/include/dnode/bnode/bnode.h b/include/dnode/bnode/bnode.h new file mode 100644 index 0000000000000000000000000000000000000000..23cc3ca6176eb9bd5ff88b48bc62befb56687f2d --- /dev/null +++ b/include/dnode/bnode/bnode.h @@ -0,0 +1,94 @@ +/* + * 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_BNODE_H_ +#define _TD_BNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ------------------------ TYPES EXPOSED ------------------------ */ +typedef struct SDnode SDnode; +typedef struct SBnode SBnode; +typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); + +typedef struct { + int64_t numOfErrors; +} SBnodeLoad; + +typedef struct { + int32_t sver; +} SBnodeCfg; + +typedef struct { + int32_t dnodeId; + int64_t clusterId; + SBnodeCfg cfg; + SDnode *pDnode; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SBnodeOpt; + +/* ------------------------ SBnode ------------------------ */ +/** + * @brief Start one Bnode in Dnode. + * + * @param path Path of the bnode. + * @param pOption Option of the bnode. + * @return SBnode* The bnode object. + */ +SBnode *bndOpen(const char *path, const SBnodeOpt *pOption); + +/** + * @brief Stop Bnode in Dnode. + * + * @param pBnode The bnode object to close. + */ +void bndClose(SBnode *pBnode); + +/** + * @brief Get the statistical information of Bnode + * + * @param pBnode The bnode object. + * @param pLoad Statistics of the bnode. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t bndGetLoad(SBnode *pBnode, SBnodeLoad *pLoad); + +/** + * @brief Process a query message. + * + * @param pBnode The bnode object. + * @param pMsgs The array of SRpcMsg + * @return int32_t 0 for success, -1 for failure + */ +int32_t bndProcessWMsgs(SBnode *pBnode, SArray *pMsgs); + +/** + * @brief Drop a bnode. + * + * @param path Path of the bnode. + */ +void bndDestroy(const char *path); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_BNODE_H_*/ \ No newline at end of file diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index fbe447baf9d35bcd34c2ab0202d2e9dc849785b3..2e3863c3a190db25c5461a0a2afcdb13dac24028 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -27,10 +27,9 @@ typedef struct SDnode SDnode; typedef struct { int32_t sver; - int16_t numOfCores; - int16_t numOfSupportMnodes; - int16_t numOfSupportVnodes; - int16_t numOfSupportQnodes; + int32_t numOfCores; + int32_t numOfSupportVnodes; + int16_t numOfCommitThreads; int8_t enableTelem; int32_t statusInterval; float numOfThreadsPerCore; diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index f4a6f7a4c93f778ce738ed0cf9ceae63bcb4b6e6..a288e3e6309ee64cd64579c5d72b7a43e447c72d 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -27,7 +27,6 @@ typedef struct SMnodeMsg SMnodeMsg; typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg); typedef struct SMnodeLoad { int64_t numOfDnode; @@ -57,13 +56,12 @@ typedef struct SMnodeCfg { typedef struct { int32_t dnodeId; - int32_t clusterId; + int64_t clusterId; int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; SMnodeCfg cfg; SDnode *pDnode; - PutMsgToMnodeQFp putMsgToApplyMsgFp; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; @@ -149,36 +147,12 @@ void mndCleanupMsg(SMnodeMsg *pMsg); void mndSendRsp(SMnodeMsg *pMsg, int32_t code); /** - * @brief Process the read request. + * @brief Process the read, write, sync request. * * @param pMsg The request msg. * @return int32_t 0 for success, -1 for failure. */ -void mndProcessReadMsg(SMnodeMsg *pMsg); - -/** - * @brief Process the write request. - * - * @param pMsg The request msg. - * @return int32_t 0 for success, -1 for failure. - */ -void mndProcessWriteMsg(SMnodeMsg *pMsg); - -/** - * @brief Process the sync request. - * - * @param pMsg The request msg. - * @return int32_t 0 for success, -1 for failure. - */ -void mndProcessSyncMsg(SMnodeMsg *pMsg); - -/** - * @brief Process the apply request. - * - * @param pMsg The request msg. - * @return int32_t 0 for success, -1 for failure. - */ -void mndProcessApplyMsg(SMnodeMsg *pMsg); +void mndProcessMsg(SMnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 51d7ca72025db474b34f938d3eb7c90c8d4b023b..33f9dc5a1a319b4345201ed7ce2f75cee1864da7 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -16,6 +16,8 @@ #ifndef _TD_SDB_H_ #define _TD_SDB_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif @@ -23,7 +25,7 @@ extern "C" { #define SDB_GET_INT64(pData, pRow, dataPos, val) \ { \ if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += sizeof(int64_t); \ @@ -32,7 +34,7 @@ extern "C" { #define SDB_GET_INT32(pData, pRow, dataPos, val) \ { \ if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += sizeof(int32_t); \ @@ -41,7 +43,7 @@ extern "C" { #define SDB_GET_INT16(pData, pRow, dataPos, val) \ { \ if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += sizeof(int16_t); \ @@ -50,7 +52,7 @@ extern "C" { #define SDB_GET_INT8(pData, pRow, dataPos, val) \ { \ if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += sizeof(int8_t); \ @@ -59,7 +61,7 @@ extern "C" { #define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \ { \ if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += valLen; \ @@ -69,7 +71,7 @@ extern "C" { { \ char val[valLen] = {0}; \ if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRow(pRow); \ + tfree(pRow); \ return NULL; \ } \ dataPos += valLen; \ @@ -155,15 +157,21 @@ typedef enum { SDB_TRANS = 1, SDB_CLUSTER = 2, SDB_MNODE = 3, - SDB_DNODE = 4, - SDB_USER = 5, - SDB_AUTH = 6, - SDB_ACCT = 7, - SDB_VGROUP = 8, - SDB_STB = 9, - SDB_DB = 10, - SDB_FUNC = 11, - SDB_MAX = 12 + SDB_QNODE = 4, + SDB_SNODE = 5, + SDB_BNODE = 6, + SDB_DNODE = 7, + SDB_USER = 8, + SDB_AUTH = 9, + SDB_ACCT = 10, + SDB_CONSUMER = 11, + SDB_CGROUP = 12, + SDB_TOPIC = 13, + SDB_VGROUP = 14, + SDB_STB = 15, + SDB_DB = 16, + SDB_FUNC = 17, + SDB_MAX = 18 } ESdbType; typedef struct SSdb SSdb; @@ -322,7 +330,7 @@ int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver); int32_t sdbGetRawTotalSize(SSdbRaw *pRaw); SSdbRow *sdbAllocRow(int32_t objSize); -void sdbFreeRow(SSdbRow *pRow); +void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow); void *sdbGetRowObj(SSdbRow *pRow); #ifdef __cplusplus diff --git a/include/dnode/qnode/qnode.h b/include/dnode/qnode/qnode.h index aa4c3af392dfb2e94198d0062801fe405624752c..8084175a907ff4c98b52a5f343956b8fbcc834fd 100644 --- a/include/dnode/qnode/qnode.h +++ b/include/dnode/qnode/qnode.h @@ -19,52 +19,73 @@ #ifdef __cplusplus extern "C" { #endif -#include "trpc.h" + +/* ------------------------ TYPES EXPOSED ------------------------ */ +typedef struct SDnode SDnode; +typedef struct SQnode SQnode; +typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); + +typedef struct { + int64_t numOfStartTask; + int64_t numOfStopTask; + int64_t numOfRecvedFetch; + int64_t numOfSentHb; + int64_t numOfSentFetch; + int64_t numOfTaskInQueue; + int64_t numOfFetchInQueue; + int64_t numOfErrors; +} SQnodeLoad; typedef struct { - uint64_t numOfStartTask; - uint64_t numOfStopTask; - uint64_t numOfRecvedFetch; - uint64_t numOfSentHb; - uint64_t numOfSentFetch; - uint64_t numOfTaskInQueue; - uint64_t numOfFetchInQueue; - uint64_t numOfErrors; -} SQnodeStat; + int32_t sver; +} SQnodeCfg; +typedef struct { + int32_t dnodeId; + int64_t clusterId; + SQnodeCfg cfg; + SDnode *pDnode; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SQnodeOpt; +/* ------------------------ SQnode ------------------------ */ /** - * Start one Qnode in Dnode. - * @return Error Code. + * @brief Start one Qnode in Dnode. + * + * @param pOption Option of the qnode. + * @return SQnode* The qnode object. */ -int32_t qnodeStart(); +SQnode *qndOpen(const SQnodeOpt *pOption); /** - * Stop Qnode in Dnode. + * @brief Stop Qnode in Dnode. * - * @param qnodeId Qnode ID to stop, -1 for all Qnodes. + * @param pQnode The qnode object to close. */ -void qnodeStop(int64_t qnodeId); +void qndClose(SQnode *pQnode); - /** - * Get the statistical information of Qnode + * @brief Get the statistical information of Qnode * - * @param qnodeId Qnode ID to get statistics, -1 for all - * @param stat Statistical information. - * @return Error Code. + * @param pQnode The qnode object. + * @param pLoad Statistics of the qnode. + * @return int32_t 0 for success, -1 for failure. */ -int32_t qnodeGetStatistics(int64_t qnodeId, SQnodeStat *stat); +int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad); /** - * Interface for processing Qnode messages. - * - * @param pMsg Message to be processed. - * @return Error code + * @brief Process a query or fetch message. + * + * @param pQnode The qnode object. + * @param pMsg The request message + * @param pRsp The response message + * @return int32_t 0 for success, -1 for failure */ -void qnodeProcessReq(SRpcMsg *pMsg); - - +int32_t qndProcessMsg(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp); #ifdef __cplusplus } diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h new file mode 100644 index 0000000000000000000000000000000000000000..4913d2572fa201b23df12195e0004f55b8c4b866 --- /dev/null +++ b/include/dnode/snode/snode.h @@ -0,0 +1,95 @@ +/* + * 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_SNODE_H_ +#define _TD_SNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ------------------------ TYPES EXPOSED ------------------------ */ +typedef struct SDnode SDnode; +typedef struct SSnode SSnode; +typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); + +typedef struct { + int64_t numOfErrors; +} SSnodeLoad; + +typedef struct { + int32_t sver; +} SSnodeCfg; + +typedef struct { + int32_t dnodeId; + int64_t clusterId; + SSnodeCfg cfg; + SDnode *pDnode; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SSnodeOpt; + +/* ------------------------ SSnode ------------------------ */ +/** + * @brief Start one Snode in Dnode. + * + * @param path Path of the snode. + * @param pOption Option of the snode. + * @return SSnode* The snode object. + */ +SSnode *sndOpen(const char *path, const SSnodeOpt *pOption); + +/** + * @brief Stop Snode in Dnode. + * + * @param pSnode The snode object to close. + */ +void sndClose(SSnode *pSnode); + +/** + * @brief Get the statistical information of Snode + * + * @param pSnode The snode object. + * @param pLoad Statistics of the snode. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad); + +/** + * @brief Process a query message. + * + * @param pSnode The snode object. + * @param pMsg The request message + * @param pRsp The response message + * @return int32_t 0 for success, -1 for failure + */ +int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp); + +/** + * @brief Drop a snode. + * + * @param path Path of the snode. + */ +void sndDestroy(const char *path); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_SNODE_H_*/ \ No newline at end of file diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 113a9705489e90661eed5874a6925ac00a0c0f52..cc5eabf3bf4ebffdd92aaf434ca45640e40d34e0 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -18,6 +18,7 @@ #include "mallocator.h" #include "os.h" +#include "tmsg.h" #include "trow.h" #ifdef __cplusplus @@ -25,7 +26,6 @@ extern "C" { #endif // Types exported -typedef uint64_t tb_uid_t; typedef struct SMeta SMeta; #define META_SUPER_TABLE 0 @@ -37,39 +37,7 @@ typedef struct SMetaCfg { uint64_t lruSize; } SMetaCfg; -typedef struct STbCfg { - /// name of the table - char *name; - /// time to live of the table - uint32_t ttl; - /// keep time of this table - uint32_t keep; - /// type of table - uint8_t type; - union { - /// super table configurations - struct { - /// super table UID - tb_uid_t suid; - /// row schema - STSchema *pSchema; - /// tag schema - STSchema *pTagSchema; - } stbCfg; - - /// normal table configuration - struct { - /// row schema - STSchema *pSchema; - } ntbCfg; - /// child table configuration - struct { - /// super table UID - tb_uid_t suid; - SKVRow pTag; - } ctbCfg; - }; -} STbCfg; +typedef SVCreateTbReq STbCfg; // SMeta operations SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); @@ -79,35 +47,13 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); +// For Query +int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg); + // Options void metaOptionsInit(SMetaCfg *pMetaCfg); void metaOptionsClear(SMetaCfg *pMetaCfg); -// STbCfg -#define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ - { \ - .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_SUPER_TABLE, .stbCfg = { \ - .suid = (SUID), \ - .pSchema = (PSCHEMA), \ - .pTagSchema = (PTAGSCHEMA) \ - } \ - } - -#define META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) \ - { \ - .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_CHILD_TABLE, .ctbCfg = {.suid = (SUID), .pTag = PTAG } \ - } - -#define META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) \ - { \ - .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_NORMAL_TABLE, .ntbCfg = {.pSchema = (PSCHEMA) } \ - } - -#define META_CLEAR_TB_CFG(pTbCfg) - -int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg); -void *metaDecodeTbCfg(void *pBuf, STbCfg *pTbCfg); - #ifdef __cplusplus } #endif diff --git a/include/dnode/vnode/tq/tq.h b/include/dnode/vnode/tq/tq.h index f5d5cc9a166bdd99edd22d69aa08d60044c7d9fd..5774131377e3f17ebea76ff70eee767fa876b43d 100644 --- a/include/dnode/vnode/tq/tq.h +++ b/include/dnode/vnode/tq/tq.h @@ -20,7 +20,7 @@ #include "mallocator.h" #include "os.h" #include "taoserror.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlist.h" #include "trpc.h" #include "ttimer.h" @@ -251,6 +251,8 @@ typedef struct STqMetaStore { STqMetaList* bucket[TQ_BUCKET_SIZE]; // a table head STqMetaList* unpersistHead; + // topics that are not connectted + STqMetaList* unconnectTopic; // TODO:temporaral use, to be replaced by unified tfile int fileFd; diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index e708d7b545ac2f644755d7345e0af943bdee77ca..af56d69b11f47ba2102ad3ab69ce5d84d349f1bd 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -162,16 +162,6 @@ int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); */ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); -/** - * @brief Process a consume message. - * - * @param pVnode The vnode object. - * @param pMsg The request message - * @param pRsp The response message - * @return int 0 for success, -1 for failure - */ -int vnodeProcessConsumeReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); - /* ------------------------ SVnodeCfg ------------------------ */ /** * @brief Initialize VNODE options. @@ -187,68 +177,6 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); */ void vnodeOptionsClear(SVnodeCfg *pOptions); -/* ------------------------ REQUESTS ------------------------ */ -typedef STbCfg SVCreateTableReq; -typedef struct { - tb_uid_t uid; -} SVDropTableReq; - -typedef struct { - // TODO -} SVSubmitReq; - -typedef struct { - uint64_t ver; - union { - SVCreateTableReq ctReq; - SVDropTableReq dtReq; - }; -} SVnodeReq; - -typedef struct { - int err; - char info[]; -} SVnodeRsp; - -static FORCE_INLINE void vnodeSetCreateStbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid, - STSchema *pSchema, STSchema *pTagSchema) { - pReq->ver = 0; - - pReq->ctReq.name = name; - pReq->ctReq.ttl = ttl; - pReq->ctReq.keep = keep; - pReq->ctReq.type = META_SUPER_TABLE; - pReq->ctReq.stbCfg.suid = suid; - pReq->ctReq.stbCfg.pSchema = pSchema; - pReq->ctReq.stbCfg.pTagSchema = pTagSchema; -} - -static FORCE_INLINE void vnodeSetCreateCtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid, - SKVRow pTag) { - pReq->ver = 0; - - pReq->ctReq.name = name; - pReq->ctReq.ttl = ttl; - pReq->ctReq.keep = keep; - pReq->ctReq.type = META_CHILD_TABLE; - pReq->ctReq.ctbCfg.suid = suid; - pReq->ctReq.ctbCfg.pTag = pTag; -} - -static FORCE_INLINE void vnodeSetCreateNtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, - STSchema *pSchema) { - pReq->ver = 0; - - pReq->ctReq.name = name; - pReq->ctReq.ttl = ttl; - pReq->ctReq.keep = keep; - pReq->ctReq.type = META_NORMAL_TABLE; - pReq->ctReq.ntbCfg.pSchema = pSchema; -} - -int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); -void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); - /* ------------------------ FOR COMPILE ------------------------ */ int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 592c5f707c25bff03e2fea23c790a9687eea7ef5..8f4b9e1807472e4ca4e75abb289b235c51761493 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -21,13 +21,14 @@ extern "C" { #endif #include "os.h" -#include "thash.h" -#include "tarray.h" #include "taosdef.h" -#include "transport.h" -#include "common.h" -#include "taosmsg.h" #include "query.h" +#include "tname.h" +#include "common.h" +#include "tarray.h" +#include "thash.h" +#include "tmsg.h" +#include "transport.h" struct SCatalog; @@ -45,7 +46,6 @@ typedef struct SMetaData { } SMetaData; typedef struct SCatalogCfg { - bool enableVgroupCache; uint32_t maxTblCacheNum; uint32_t maxDBCacheNum; } SCatalogCfg; @@ -61,43 +61,52 @@ int32_t catalogInit(SCatalogCfg *cfg); int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle); int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version); -int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo* dbInfo); -int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo); /** - * Get a table's meta data. + * Get a DB's all vgroup info. * @param pCatalog (input, got with catalogGetHandle) * @param pRpc (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pDBName (input, full db name) + * @param forceUpdate (input, force update db vgroup info from mnode) + * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller) + * @return error code + */ +int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, int32_t forceUpdate, SArray** pVgroupList); + +int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo); + +/** + * Get a table's meta data. + * @param pCatalog (input, got with catalogGetHandle) + * @param pTransporter (input, rpc object) + * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) * @return error code */ -int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta); +int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); /** * Force renew a table's local cached meta data. * @param pCatalog (input, got with catalogGetHandle) * @param pRpc (input, rpc object) * @param pMgmtEps (input, mnode EPs) - * @param pDBName (input, full db name) * @param pTableName (input, table name, NOT including db name) * @return error code */ -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName); +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName); /** * Force renew a table's local cached meta data and get the new one. * @param pCatalog (input, got with catalogGetHandle) * @param pRpc (input, rpc object) * @param pMgmtEps (input, mnode EPs) - * @param pDBName (input, full db name) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) * @return error code */ -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); /** @@ -105,24 +114,22 @@ int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const * @param pCatalog (input, got with catalogGetHandle) * @param pRpc (input, rpc object) * @param pMgmtEps (input, mnode EPs) - * @param pDBName (input, full db name) * @param pTableName (input, table name, NOT including db name) * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller) * @return error code */ -int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray* pVgroupList); +int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList); /** * Get a table's vgroup from its name's hash value. * @param pCatalog (input, got with catalogGetHandle) * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) - * @param pDBName (input, full db name) * @param pTableName (input, table name, NOT including db name) * @param vgInfo (output, vgroup info) * @return error code */ -int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo); +int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo); /** @@ -137,7 +144,7 @@ int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp); -int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet); +int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList); diff --git a/include/libs/index/index.h b/include/libs/index/index.h index f93c46da0c412e3529dd0c016ef7c42dc8de1686..d2b157542f7449013869fbca60a812aeebcf5730 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -85,6 +85,18 @@ SIndexTerm* indexTermCreate(int64_t suid, int32_t nColVal); void indexTermDestroy(SIndexTerm* p); +/* + * init index + * + */ +int32_t indexInit(); +/* + * destory index + * + */ + +void indexCleanUp(); + #ifdef __cplusplus } #endif diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index 250739c1e649ab47af10b63f5c3355b4b718c9ee..980219a4e90fb2e6de7fc0e330665e698cc515c0 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -44,9 +44,12 @@ typedef struct SField { } SField; typedef struct SParseBasicCtx { - const char *db; - int32_t acctId; - uint64_t requestId; + uint64_t requestId; + int32_t acctId; + const char *db; + void *pTransporter; + SEpSet mgmtEpSet; + struct SCatalog *pCatalog; } SParseBasicCtx; typedef struct SFieldInfo { @@ -163,6 +166,7 @@ typedef struct SInsertStmtInfo { typedef struct SDclStmtInfo { int16_t nodeType; int16_t msgType; + SEpSet epSet; char* pMsg; int32_t msgLen; } SDclStmtInfo; diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 7834bc6913476aff8023c6a2cb8fb51d4208e6bb..a9e1f26d2014225a5a8481b497906f1d1f34aab4 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -23,14 +23,11 @@ extern "C" { #include "parsenodes.h" typedef struct SParseContext { - SParseBasicCtx ctx; - void *pRpc; - struct SCatalog *pCatalog; - const SEpSet *pEpSet; + SParseBasicCtx ctx; int8_t schemaAttached; // denote if submit block is built with table schema or not const char *pSql; // sql string size_t sqlLen; // length of the sql string - char *pMsg; // extended error message if exists to help avoid the problem in sql statement. + char *pMsg; // extended error message if exists to help identifying the problem in sql statement. int32_t msgLen; // max length of the msg } SParseContext; @@ -44,7 +41,9 @@ typedef struct SParseContext { */ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); -bool qIsDclQuery(const SQueryNode* pQuery); +bool qIsDdlQuery(const SQueryNode* pQuery); + +void qDestroyQuery(SQueryNode* pQuery); /** * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that @@ -75,7 +74,6 @@ int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo); STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex); SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex); -SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name); int32_t getNewResColId(); void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn); @@ -84,4 +82,4 @@ void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* p } #endif -#endif /*_TD_PARSER_H_*/ \ No newline at end of file +#endif /*_TD_PARSER_H_*/ diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index d4469be5e3a5e2a03973b4c1bf0158eaf9875d2a..3ca923b0aaa9822e65a377096d20958c63d057d8 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -20,7 +20,8 @@ extern "C" { #endif -#include "taosmsg.h" +#include "tmsg.h" +#include "tarray.h" #define QUERY_TYPE_MERGE 1 #define QUERY_TYPE_PARTIAL 2 @@ -131,7 +132,7 @@ typedef struct SSubplan { typedef struct SQueryDag { uint64_t queryId; int32_t numOfSubplans; - SArray *pSubplans; // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0. + SArray *pSubplans; // SArray*>. The execution level of subplan, starting from 0. } SQueryDag; struct SQueryNode; @@ -139,7 +140,7 @@ struct SQueryNode; /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule @@ -165,8 +166,11 @@ void qDestroySubplan(SSubplan* pSubplan); */ void qDestroyQueryDag(SQueryDag* pDag); +char* qDagToString(const SQueryDag* pDag); +SQueryDag* qStringToDag(const char* pStr); + #ifdef __cplusplus } #endif -#endif /*_TD_PLANNER_H_*/ \ No newline at end of file +#endif /*_TD_PLANNER_H_*/ diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 877cfb130c3b338d701571c945d4b9b53db6bd91..4ea35f1d2c76697cd8177c5722c68f32cd14603e 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -23,6 +23,7 @@ extern "C" { #include "tarray.h" #include "thash.h" #include "tlog.h" +#include "tmsg.h" enum { JOB_TASK_STATUS_NULL = 0, @@ -73,27 +74,42 @@ typedef struct STableMeta { SSchema schema[]; } STableMeta; - typedef struct SDBVgroupInfo { + int32_t lock; int32_t vgVersion; int8_t hashMethod; SHashObj *vgInfo; //key:vgId, value:SVgroupInfo } SDBVgroupInfo; typedef struct SUseDbOutput { - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; SDBVgroupInfo dbVgroup; } SUseDbOutput; typedef struct STableMetaOutput { int32_t metaNum; char ctbFname[TSDB_TABLE_FNAME_LEN]; - char tbFname[TSDB_TABLE_FNAME_LEN]; + char tbFname[TSDB_TABLE_FNAME_LEN]; SCTableMeta ctbMeta; STableMeta *tbMeta; } STableMetaOutput; -typedef int32_t __async_exec_fn_t(void* param); +typedef struct SDataBuf { + void *pData; + uint32_t len; +} SDataBuf; + +typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code); +typedef int32_t (*__async_exec_fn_t)(void* param); + +typedef struct SMsgSendInfo { + __async_send_cb_fn_t fp; //async callback function + void *param; + uint64_t requestId; + uint64_t requestObjRefId; + int32_t msgType; + SDataBuf msgInfo; +} SMsgSendInfo; bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); @@ -109,11 +125,22 @@ int32_t cleanupTaskQueue(); */ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code); -SSchema* tGetTbnameColumnSchema(); +/** + * Asynchronously send message to server, after the response received, the callback will be incured. + * + * @param pTransporter + * @param epSet + * @param pTransporterId + * @param pInfo + * @return + */ +int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo); + +const SSchema* tGetTbnameColumnSchema(); void initQueryModuleMsgHandle(); -extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); -extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize); +extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); +extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize); #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) #define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0) diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 8e361784976c8929249198ff4bffc4366385fe07..9897467230675dae1b4b3e7909acd748504dcec7 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -42,20 +42,23 @@ typedef struct { int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt); -int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg **rsp); +int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); +int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); +int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); +int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); +int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); +int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); -void qWorkerDestroy(void **qWorkerMgmt); +int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); + +int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg); +void qWorkerDestroy(void **qWorkerMgmt); #ifdef __cplusplus } diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index 975b10353871f269abecb70d4974836d3e4a44b2..ddcfcab4dbc026888f04440aedfb2ba3c7af09b1 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -24,7 +24,6 @@ extern "C" { #include "catalog.h" typedef struct SSchedulerCfg { - int32_t clusterType; int32_t maxJobNum; } SSchedulerCfg; @@ -59,7 +58,15 @@ int32_t schedulerInit(SSchedulerCfg *cfg); * @param qnodeList Qnode address list, element is SEpAddr * @return */ -int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob); +int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, uint64_t *numOfRows); + +/** + * Process the query job, generated according to the query physical plan. + * This is a asynchronized API, and is also thread-safety. + * @param qnodeList Qnode address list, element is SEpAddr + * @return + */ +int32_t scheduleAsyncExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob); int32_t scheduleFetchRows(void *pJob, void **data); @@ -79,4 +86,4 @@ void schedulerDestroy(void); } #endif -#endif /*_TD_SCHEDULER_H_*/ \ No newline at end of file +#endif /*_TD_SCHEDULER_H_*/ diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 2afd9d48b76839682764dab87fb1dd7adc7796be..b88d45fbd661fd4c1fce9c71abcabacb9b007404 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -22,43 +22,43 @@ extern "C" { #include #include #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" -#define TAOS_CONN_SERVER 0 -#define TAOS_CONN_CLIENT 1 +#define TAOS_CONN_SERVER 0 +#define TAOS_CONN_CLIENT 1 extern int tsRpcHeadSize; typedef struct SRpcConnInfo { - uint32_t clientIp; - uint16_t clientPort; - uint32_t serverIp; - char user[TSDB_USER_LEN]; + uint32_t clientIp; + uint16_t clientPort; + uint32_t serverIp; + char user[TSDB_USER_LEN]; } SRpcConnInfo; typedef struct SRpcMsg { - uint8_t msgType; - void *pCont; + tmsg_t msgType; + void * pCont; int contLen; int32_t code; - void *handle; // rpc handle returned to app - void *ahandle; // app handle set by client + void * handle; // rpc handle returned to app + void * ahandle; // app handle set by client } SRpcMsg; typedef struct SRpcInit { - uint16_t localPort; // local port - char *label; // for debug purpose - int numOfThreads; // number of threads to handle connections - int sessions; // number of sessions allowed - int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS - int idleTime; // milliseconds, 0 means idle timer is disabled + uint16_t localPort; // local port + char * label; // for debug purpose + int numOfThreads; // number of threads to handle connections + int sessions; // number of sessions allowed + int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS + int idleTime; // milliseconds, 0 means idle timer is disabled // the following is for client app ecurity only - char *user; // user name - char spi; // security parameter index - char encrypt; // encrypt algorithm - char *secret; // key for authentication - char *ckey; // ciphering key + char *user; // user name + char spi; // security parameter index + char encrypt; // encrypt algorithm + char *secret; // key for authentication + char *ckey; // ciphering key // call back to process incoming msg, code shall be ignored by server app void (*cfp)(void *parent, SRpcMsg *, SEpSet *); @@ -70,19 +70,19 @@ typedef struct SRpcInit { } SRpcInit; int32_t rpcInit(); -void rpcCleanup(); -void *rpcOpen(const SRpcInit *pRpc); -void rpcClose(void *); -void *rpcMallocCont(int contLen); -void rpcFreeCont(void *pCont); -void *rpcReallocCont(void *ptr, int contLen); -void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); -void rpcSendResponse(const SRpcMsg *pMsg); -void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet); -int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); -void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); -int rpcReportProgress(void *pConn, char *pCont, int contLen); -void rpcCancelRequest(int64_t rid); +void rpcCleanup(); +void * rpcOpen(const SRpcInit *pRpc); +void rpcClose(void *); +void * rpcMallocCont(int contLen); +void rpcFreeCont(void *pCont); +void * rpcReallocCont(void *ptr, int contLen); +void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid); +void rpcSendResponse(const SRpcMsg *pMsg); +void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet); +int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); +void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +int rpcReportProgress(void *pConn, char *pCont, int contLen); +void rpcCancelRequest(int64_t rid); #ifdef __cplusplus } diff --git a/include/os/osEndian.h b/include/os/osEndian.h index 496012cf2811f1221705ff76e9ee79cd5d80080d..e573ba0a751589c009f9e848d7352f0e7a090ea7 100644 --- a/include/os/osEndian.h +++ b/include/os/osEndian.h @@ -20,8 +20,11 @@ extern "C" { #endif +typedef enum { TD_LITTLE_ENDIAN = 0, TD_BIG_ENDIAN } td_endian_t; + static const int32_t endian_test_var = 1; #define IS_LITTLE_ENDIAN() (*(uint8_t *)(&endian_test_var) != 0) +#define TD_RT_ENDIAN() (IS_LITTLE_ENDIAN() ? TD_LITTLE_ENDIAN : TD_BIG_ENDIAN) #ifdef __cplusplus } diff --git a/include/os/osEnv.h b/include/os/osEnv.h index b857670214699c52975fff1020e548f6b40242a6..a7fd86776c06ea6f399f6094ac52a78c0345a7e5 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -21,7 +21,6 @@ extern "C" { #endif extern char tsOsName[]; -extern char tsDnodeDir[]; extern char tsDataDir[]; extern char tsLogDir[]; extern char tsScriptDir[]; diff --git a/include/util/encode.h b/include/util/encode.h new file mode 100644 index 0000000000000000000000000000000000000000..ee35791012b61b5df89a44fa8bc9693381ce3df7 --- /dev/null +++ b/include/util/encode.h @@ -0,0 +1,476 @@ +/* + * 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_UTIL_ENCODE_H_ +#define _TD_UTIL_ENCODE_H_ + +#include "tcoding.h" +#include "tmacro.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + td_endian_t endian; + uint8_t* data; + int32_t size; + int32_t pos; +} SEncoder, SDecoder; + +#define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL) +#define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0] + +#define tRPut16(PDEST, PSRC) \ + ((uint8_t*)(PDEST))[0] = ((uint8_t*)(PSRC))[1]; \ + ((uint8_t*)(PDEST))[1] = ((uint8_t*)(PSRC))[0]; + +#define tRPut32(PDEST, PSRC) \ + ((uint8_t*)(PDEST))[0] = ((uint8_t*)(PSRC))[3]; \ + ((uint8_t*)(PDEST))[1] = ((uint8_t*)(PSRC))[2]; \ + ((uint8_t*)(PDEST))[2] = ((uint8_t*)(PSRC))[1]; \ + ((uint8_t*)(PDEST))[3] = ((uint8_t*)(PSRC))[0]; + +#define tRPut64(PDEST, PSRC) \ + ((uint8_t*)(PDEST))[0] = ((uint8_t*)(PSRC))[7]; \ + ((uint8_t*)(PDEST))[1] = ((uint8_t*)(PSRC))[6]; \ + ((uint8_t*)(PDEST))[2] = ((uint8_t*)(PSRC))[5]; \ + ((uint8_t*)(PDEST))[3] = ((uint8_t*)(PSRC))[4]; \ + ((uint8_t*)(PDEST))[4] = ((uint8_t*)(PSRC))[3]; \ + ((uint8_t*)(PDEST))[5] = ((uint8_t*)(PSRC))[2]; \ + ((uint8_t*)(PDEST))[6] = ((uint8_t*)(PSRC))[1]; \ + ((uint8_t*)(PDEST))[7] = ((uint8_t*)(PSRC))[0]; + +#define tRGet16 tRPut16 +#define tRGet32 tRPut32 +#define tRGet64 tRPut64 + +#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) +#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) +#define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) + +/* ------------------------ FOR ENCODER ------------------------ */ +static FORCE_INLINE void tInitEncoder(SEncoder* pEncoder, td_endian_t endian, uint8_t* data, int32_t size) { + pEncoder->endian = endian; + pEncoder->data = data; + pEncoder->size = (data) ? size : 0; + pEncoder->pos = 0; +} + +// 8 +static FORCE_INLINE int tEncodeU8(SEncoder* pEncoder, uint8_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val); + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +static FORCE_INLINE int tEncodeI8(SEncoder* pEncoder, int8_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + tPut(int8_t, TD_CODER_CURRENT(pEncoder), val); + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +// 16 +static FORCE_INLINE int tEncodeU16(SEncoder* pEncoder, uint16_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(uint16_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut16(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +static FORCE_INLINE int tEncodeI16(SEncoder* pEncoder, int16_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(int16_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut16(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +// 32 +static FORCE_INLINE int tEncodeU32(SEncoder* pEncoder, uint32_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(uint32_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut32(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +static FORCE_INLINE int tEncodeI32(SEncoder* pEncoder, int32_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(int32_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut32(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +// 64 +static FORCE_INLINE int tEncodeU64(SEncoder* pEncoder, uint64_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(uint64_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut64(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +static FORCE_INLINE int tEncodeI64(SEncoder* pEncoder, int64_t val) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_RT_ENDIAN() == pEncoder->endian) { + tPut(int64_t, TD_CODER_CURRENT(pEncoder), val); + } else { + tRPut64(TD_CODER_CURRENT(pEncoder), &val); + } + } + TD_CODER_MOVE_POS(pEncoder, sizeof(val)); + return 0; +} + +// 16v +static FORCE_INLINE int tEncodeU16v(SEncoder* pEncoder, uint16_t val) { + int64_t i = 0; + while (val >= ENCODE_LIMIT) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; + } + + val >>= 7; + i++; + } + + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; + } + + TD_CODER_MOVE_POS(pEncoder, i + 1); + + return 0; +} + +static FORCE_INLINE int tEncodeI16v(SEncoder* pEncoder, int16_t val) { + return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val)); +} + +// 32v +static FORCE_INLINE int tEncodeU32v(SEncoder* pEncoder, uint32_t val) { + int64_t i = 0; + while (val >= ENCODE_LIMIT) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; + } + + val >>= 7; + i++; + } + + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; + } + + TD_CODER_MOVE_POS(pEncoder, i + 1); + + return 0; +} + +static FORCE_INLINE int tEncodeI32v(SEncoder* pEncoder, int32_t val) { + return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val)); +} + +// 64v +static FORCE_INLINE int tEncodeU64v(SEncoder* pEncoder, uint64_t val) { + int64_t i = 0; + while (val >= ENCODE_LIMIT) { + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; + } + + val >>= 7; + i++; + } + + if (pEncoder->data) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; + TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; + } + + TD_CODER_MOVE_POS(pEncoder, i + 1); + + return 0; +} + +static FORCE_INLINE int tEncodeI64v(SEncoder* pEncoder, int64_t val) { + return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val)); +} + +static FORCE_INLINE int tEncodeFloat(SEncoder* pEncoder, float val) { + // TODO + return 0; +} + +static FORCE_INLINE int tEncodeDouble(SEncoder* pEncoder, double val) { + // TODO + return 0; +} + +static FORCE_INLINE int tEncodeCStr(SEncoder* pEncoder, const char* val) { + // TODO + return 0; +} + +/* ------------------------ FOR DECODER ------------------------ */ +static FORCE_INLINE void tInitDecoder(SDecoder* pDecoder, td_endian_t endian, uint8_t* data, int32_t size) { + ASSERT(!TD_IS_NULL(data)); + pDecoder->endian = endian; + pDecoder->data = data; + pDecoder->size = size; + pDecoder->pos = 0; +} + +// 8 +static FORCE_INLINE int tDecodeU8(SDecoder* pDecoder, uint8_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val); + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +static FORCE_INLINE int tDecodeI8(SDecoder* pDecoder, int8_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val); + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +// 16 +static FORCE_INLINE int tDecodeU16(SDecoder* pDecoder, uint16_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(uint16_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet16(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +static FORCE_INLINE int tDecodeI16(SDecoder* pDecoder, int16_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(int16_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet16(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +// 32 +static FORCE_INLINE int tDecodeU32(SDecoder* pDecoder, uint32_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(uint32_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet32(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +static FORCE_INLINE int tDecodeI32(SDecoder* pDecoder, int32_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(int32_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet32(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +// 64 +static FORCE_INLINE int tDecodeU64(SDecoder* pDecoder, uint64_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(uint64_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet64(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +static FORCE_INLINE int tDecodeI64(SDecoder* pDecoder, int64_t* val) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; + if (TD_RT_ENDIAN() == pDecoder->endian) { + tGet(int64_t, TD_CODER_CURRENT(pDecoder), *val); + } else { + tRGet64(val, TD_CODER_CURRENT(pDecoder)); + } + + TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); + return 0; +} + +// 16v +static FORCE_INLINE int tDecodeU16v(SDecoder* pDecoder, uint16_t* val) { + int64_t i = 0; + *val = 0; + for (;;) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; + uint16_t tval = TD_CODER_CURRENT(pDecoder)[i]; + if (tval < ENCODE_LIMIT) { + (*val) |= (tval << (7 * i)); + break; + } else { + (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); + i++; + } + } + + TD_CODER_MOVE_POS(pDecoder, i); + + return 0; +} + +static FORCE_INLINE int tDecodeI16v(SDecoder* pDecoder, int16_t* val) { + uint16_t tval; + if (tDecodeU16v(pDecoder, &tval) < 0) { + return -1; + } + *val = ZIGZAGD(int16_t, tval); + return 0; +} + +// 32v +static FORCE_INLINE int tDecodeU32v(SDecoder* pDecoder, uint32_t* val) { + int64_t i = 0; + *val = 0; + for (;;) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; + uint32_t tval = TD_CODER_CURRENT(pDecoder)[i]; + if (tval < ENCODE_LIMIT) { + (*val) |= (tval << (7 * i)); + break; + } else { + (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); + i++; + } + } + + TD_CODER_MOVE_POS(pDecoder, i); + + return 0; +} + +static FORCE_INLINE int tDecodeI32v(SDecoder* pDecoder, int32_t* val) { + uint32_t tval; + if (tDecodeU32v(pDecoder, &tval) < 0) { + return -1; + } + *val = ZIGZAGD(int32_t, tval); + return 0; +} + +// 64v +static FORCE_INLINE int tDecodeU64v(SDecoder* pDecoder, uint64_t* val) { + int64_t i = 0; + *val = 0; + for (;;) { + if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; + uint64_t tval = TD_CODER_CURRENT(pDecoder)[i]; + if (tval < ENCODE_LIMIT) { + (*val) |= (tval << (7 * i)); + break; + } else { + (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); + i++; + } + } + + TD_CODER_MOVE_POS(pDecoder, i); + + return 0; +} + +static FORCE_INLINE int tDecodeI64v(SDecoder* pDecoder, int64_t* val) { + uint64_t tval; + if (tDecodeU64v(pDecoder, &tval) < 0) { + return -1; + } + *val = ZIGZAGD(int64_t, tval); + return 0; +} + +static FORCE_INLINE int tDecodeFloat(SDecoder* pDecoder, float* val) { + // TODO + return 0; +} + +static FORCE_INLINE int tDecodeDouble(SDecoder* pDecoder, double* val) { + // TODO + return 0; +} + +static FORCE_INLINE int tDecodeCStr(SDecoder* pEncoder, const char** val) { + // TODO + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_UTIL_ENCODE_H_*/ \ No newline at end of file diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 43629508445dbdcf81449723b3b201befe468c2b..ae36ac7216534f87e0f02d885e8d8560b80db34b 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -69,6 +69,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_CHECKSUM_ERROR TAOS_DEF_ERROR_CODE(0, 0x0107) #define TSDB_CODE_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0108) #define TSDB_CODE_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0109) +#define TSDB_CODE_INVALID_PARA TAOS_DEF_ERROR_CODE(0, 0x010A) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111) #define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112) @@ -171,10 +172,15 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347) #define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348) -// mnode-mnode +// mnode-node #define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350) #define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351) -#define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x0352) +#define TSDB_CODE_MND_QNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0352) +#define TSDB_CODE_MND_QNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0353) +#define TSDB_CODE_MND_SNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0354) +#define TSDB_CODE_MND_SNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0355) +#define TSDB_CODE_MND_BNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0356) +#define TSDB_CODE_MND_BNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0357) // mnode-acct #define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) @@ -220,6 +226,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_COLUMN_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA) #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB) #define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03AC) +#define TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03AD) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) @@ -234,6 +241,15 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_TRANS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D0) #define TSDB_CODE_MND_TRANS_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D1) +// mnode-topic +#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0) +#define TSDB_CODE_MND_TOPIC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E1) +#define TSDB_CODE_MND_TOO_MANY_TOPICS TAOS_DEF_ERROR_CODE(0, 0x03E2) +#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E3) +#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E4) +#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E5) +#define TSDB_CODE_MND_NAME_CONFLICT_WITH_STB TAOS_DEF_ERROR_CODE(0, 0x03E6) + // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) #define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401) @@ -246,9 +262,27 @@ int32_t* taosGetErrno(); #define TSDB_CODE_DND_MNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0423) #define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424) #define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0425) -#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0430) -#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0431) -#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0432) +#define TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0430) +#define TSDB_CODE_DND_QNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0431) +#define TSDB_CODE_DND_QNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0432) +#define TSDB_CODE_DND_QNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0433) +#define TSDB_CODE_DND_QNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0434) +#define TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0435) +#define TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0440) +#define TSDB_CODE_DND_SNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0441) +#define TSDB_CODE_DND_SNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0442) +#define TSDB_CODE_DND_SNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0443) +#define TSDB_CODE_DND_SNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0444) +#define TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0445) +#define TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0450) +#define TSDB_CODE_DND_BNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0451) +#define TSDB_CODE_DND_BNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0452) +#define TSDB_CODE_DND_BNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0453) +#define TSDB_CODE_DND_BNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0454) +#define TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0455) +#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0460) +#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0461) +#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0462) // vnode #define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) //"Action in progress") @@ -367,132 +401,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_WAL_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x1001) //"WAL file is corrupted") #define TSDB_CODE_WAL_SIZE_LIMIT TAOS_DEF_ERROR_CODE(0, 0x1002) //"WAL size exceeds limit") -// http -#define TSDB_CODE_HTTP_SERVER_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x1100) //"http server is not onlin") -#define TSDB_CODE_HTTP_UNSUPPORT_URL TAOS_DEF_ERROR_CODE(0, 0x1101) //"url is not support") -#define TSDB_CODE_HTTP_INVALID_URL TAOS_DEF_ERROR_CODE(0, 0x1102) //invalid url format") -#define TSDB_CODE_HTTP_NO_ENOUGH_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1103) //"no enough memory") -#define TSDB_CODE_HTTP_REQUSET_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x1104) //"request size is too big") -#define TSDB_CODE_HTTP_NO_AUTH_INFO TAOS_DEF_ERROR_CODE(0, 0x1105) //"no auth info input") -#define TSDB_CODE_HTTP_NO_MSG_INPUT TAOS_DEF_ERROR_CODE(0, 0x1106) //"request is empty") -#define TSDB_CODE_HTTP_NO_SQL_INPUT TAOS_DEF_ERROR_CODE(0, 0x1107) //"no sql input") -#define TSDB_CODE_HTTP_NO_EXEC_USEDB TAOS_DEF_ERROR_CODE(0, 0x1108) //"no need to execute use db cmd") -#define TSDB_CODE_HTTP_SESSION_FULL TAOS_DEF_ERROR_CODE(0, 0x1109) //"session list was full") -#define TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR TAOS_DEF_ERROR_CODE(0, 0x110A) //"generate taosd token error") -#define TSDB_CODE_HTTP_INVALID_MULTI_REQUEST TAOS_DEF_ERROR_CODE(0, 0x110B) //"size of multi request is 0") -#define TSDB_CODE_HTTP_CREATE_GZIP_FAILED TAOS_DEF_ERROR_CODE(0, 0x110C) //"failed to create gzip") -#define TSDB_CODE_HTTP_FINISH_GZIP_FAILED TAOS_DEF_ERROR_CODE(0, 0x110D) //"failed to finish gzip") -#define TSDB_CODE_HTTP_LOGIN_FAILED TAOS_DEF_ERROR_CODE(0, 0x110E) //"failed to login") - -#define TSDB_CODE_HTTP_INVALID_VERSION TAOS_DEF_ERROR_CODE(0, 0x1120) //"invalid http version") -#define TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH TAOS_DEF_ERROR_CODE(0, 0x1121) //"invalid content length") -#define TSDB_CODE_HTTP_INVALID_AUTH_TYPE TAOS_DEF_ERROR_CODE(0, 0x1122) //"invalid type of Authorization") -#define TSDB_CODE_HTTP_INVALID_AUTH_FORMAT TAOS_DEF_ERROR_CODE(0, 0x1123) //"invalid format of Authorization") -#define TSDB_CODE_HTTP_INVALID_BASIC_AUTH TAOS_DEF_ERROR_CODE(0, 0x1124) //"invalid basic Authorization") -#define TSDB_CODE_HTTP_INVALID_TAOSD_AUTH TAOS_DEF_ERROR_CODE(0, 0x1125) //"invalid taosd Authorization") -#define TSDB_CODE_HTTP_PARSE_METHOD_FAILED TAOS_DEF_ERROR_CODE(0, 0x1126) //"failed to parse method") -#define TSDB_CODE_HTTP_PARSE_TARGET_FAILED TAOS_DEF_ERROR_CODE(0, 0x1127) //"failed to parse target") -#define TSDB_CODE_HTTP_PARSE_VERSION_FAILED TAOS_DEF_ERROR_CODE(0, 0x1128) //"failed to parse http version") -#define TSDB_CODE_HTTP_PARSE_SP_FAILED TAOS_DEF_ERROR_CODE(0, 0x1129) //"failed to parse sp") -#define TSDB_CODE_HTTP_PARSE_STATUS_FAILED TAOS_DEF_ERROR_CODE(0, 0x112A) //"failed to parse status") -#define TSDB_CODE_HTTP_PARSE_PHRASE_FAILED TAOS_DEF_ERROR_CODE(0, 0x112B) //"failed to parse phrase") -#define TSDB_CODE_HTTP_PARSE_CRLF_FAILED TAOS_DEF_ERROR_CODE(0, 0x112C) //"failed to parse crlf") -#define TSDB_CODE_HTTP_PARSE_HEADER_FAILED TAOS_DEF_ERROR_CODE(0, 0x112D) //"failed to parse header") -#define TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED TAOS_DEF_ERROR_CODE(0, 0x112E) //"failed to parse header key") -#define TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED TAOS_DEF_ERROR_CODE(0, 0x112F) //"failed to parse header val") -#define TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED TAOS_DEF_ERROR_CODE(0, 0x1130) //"failed to parse chunk size") -#define TSDB_CODE_HTTP_PARSE_CHUNK_FAILED TAOS_DEF_ERROR_CODE(0, 0x1131) //"failed to parse chunk") -#define TSDB_CODE_HTTP_PARSE_END_FAILED TAOS_DEF_ERROR_CODE(0, 0x1132) //"failed to parse end section") -#define TSDB_CODE_HTTP_PARSE_INVALID_STATE TAOS_DEF_ERROR_CODE(0, 0x1134) //"invalid parse state") -#define TSDB_CODE_HTTP_PARSE_ERROR_STATE TAOS_DEF_ERROR_CODE(0, 0x1135) //"failed to parse error section") - -#define TSDB_CODE_HTTP_GC_QUERY_NULL TAOS_DEF_ERROR_CODE(0, 0x1150) //"query size is 0") -#define TSDB_CODE_HTTP_GC_QUERY_SIZE TAOS_DEF_ERROR_CODE(0, 0x1151) //"query size can not more than 100") -#define TSDB_CODE_HTTP_GC_REQ_PARSE_ERROR TAOS_DEF_ERROR_CODE(0, 0x1152) //"parse grafana json error") - -#define TSDB_CODE_HTTP_TG_DB_NOT_INPUT TAOS_DEF_ERROR_CODE(0, 0x1160) //"database name can not be null") -#define TSDB_CODE_HTTP_TG_DB_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x1161) //"database name too long") -#define TSDB_CODE_HTTP_TG_INVALID_JSON TAOS_DEF_ERROR_CODE(0, 0x1162) //"invalid telegraf json fromat") -#define TSDB_CODE_HTTP_TG_METRICS_NULL TAOS_DEF_ERROR_CODE(0, 0x1163) //"metrics size is 0") -#define TSDB_CODE_HTTP_TG_METRICS_SIZE TAOS_DEF_ERROR_CODE(0, 0x1164) //"metrics size can not more than 1K") -#define TSDB_CODE_HTTP_TG_METRIC_NULL TAOS_DEF_ERROR_CODE(0, 0x1165) //"metric name not find") -#define TSDB_CODE_HTTP_TG_METRIC_TYPE TAOS_DEF_ERROR_CODE(0, 0x1166) //"metric name type should be string") -#define TSDB_CODE_HTTP_TG_METRIC_NAME_NULL TAOS_DEF_ERROR_CODE(0, 0x1167) //"metric name length is 0") -#define TSDB_CODE_HTTP_TG_METRIC_NAME_LONG TAOS_DEF_ERROR_CODE(0, 0x1168) //"metric name length too long") -#define TSDB_CODE_HTTP_TG_TIMESTAMP_NULL TAOS_DEF_ERROR_CODE(0, 0x1169) //"timestamp not find") -#define TSDB_CODE_HTTP_TG_TIMESTAMP_TYPE TAOS_DEF_ERROR_CODE(0, 0x116A) //"timestamp type should be integer") -#define TSDB_CODE_HTTP_TG_TIMESTAMP_VAL_NULL TAOS_DEF_ERROR_CODE(0, 0x116B) //"timestamp value smaller than 0") -#define TSDB_CODE_HTTP_TG_TAGS_NULL TAOS_DEF_ERROR_CODE(0, 0x116C) //"tags not find") -#define TSDB_CODE_HTTP_TG_TAGS_SIZE_0 TAOS_DEF_ERROR_CODE(0, 0x116D) //"tags size is 0") -#define TSDB_CODE_HTTP_TG_TAGS_SIZE_LONG TAOS_DEF_ERROR_CODE(0, 0x116E) //"tags size too long") -#define TSDB_CODE_HTTP_TG_TAG_NULL TAOS_DEF_ERROR_CODE(0, 0x116F) //"tag is null") -#define TSDB_CODE_HTTP_TG_TAG_NAME_NULL TAOS_DEF_ERROR_CODE(0, 0x1170) //"tag name is null") -#define TSDB_CODE_HTTP_TG_TAG_NAME_SIZE TAOS_DEF_ERROR_CODE(0, 0x1171) //"tag name length too long") -#define TSDB_CODE_HTTP_TG_TAG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x1172) //"tag value type should be number or string") -#define TSDB_CODE_HTTP_TG_TAG_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x1173) //"tag value is null") -#define TSDB_CODE_HTTP_TG_TABLE_NULL TAOS_DEF_ERROR_CODE(0, 0x1174) //"table is null") -#define TSDB_CODE_HTTP_TG_TABLE_SIZE TAOS_DEF_ERROR_CODE(0, 0x1175) //"table name length too long") -#define TSDB_CODE_HTTP_TG_FIELDS_NULL TAOS_DEF_ERROR_CODE(0, 0x1176) //"fields not find") -#define TSDB_CODE_HTTP_TG_FIELDS_SIZE_0 TAOS_DEF_ERROR_CODE(0, 0x1177) //"fields size is 0") -#define TSDB_CODE_HTTP_TG_FIELDS_SIZE_LONG TAOS_DEF_ERROR_CODE(0, 0x1178) //"fields size too long") -#define TSDB_CODE_HTTP_TG_FIELD_NULL TAOS_DEF_ERROR_CODE(0, 0x1179) //"field is null") -#define TSDB_CODE_HTTP_TG_FIELD_NAME_NULL TAOS_DEF_ERROR_CODE(0, 0x117A) //"field name is null") -#define TSDB_CODE_HTTP_TG_FIELD_NAME_SIZE TAOS_DEF_ERROR_CODE(0, 0x117B) //"field name length too long") -#define TSDB_CODE_HTTP_TG_FIELD_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x117C) //"field value type should be number or string") -#define TSDB_CODE_HTTP_TG_FIELD_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x117D) //"field value is null") -#define TSDB_CODE_HTTP_TG_HOST_NOT_STRING TAOS_DEF_ERROR_CODE(0, 0x117E) //"host type should be string") -#define TSDB_CODE_HTTP_TG_STABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x117F) //"stable not exist") - -#define TSDB_CODE_HTTP_OP_DB_NOT_INPUT TAOS_DEF_ERROR_CODE(0, 0x1190) //"database name can not be null") -#define TSDB_CODE_HTTP_OP_DB_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x1191) //"database name too long") -#define TSDB_CODE_HTTP_OP_INVALID_JSON TAOS_DEF_ERROR_CODE(0, 0x1192) //"invalid opentsdb json fromat") -#define TSDB_CODE_HTTP_OP_METRICS_NULL TAOS_DEF_ERROR_CODE(0, 0x1193) //"metrics size is 0") -#define TSDB_CODE_HTTP_OP_METRICS_SIZE TAOS_DEF_ERROR_CODE(0, 0x1194) //"metrics size can not more than 10K") -#define TSDB_CODE_HTTP_OP_METRIC_NULL TAOS_DEF_ERROR_CODE(0, 0x1195) //"metric name not find") -#define TSDB_CODE_HTTP_OP_METRIC_TYPE TAOS_DEF_ERROR_CODE(0, 0x1196) //"metric name type should be string") -#define TSDB_CODE_HTTP_OP_METRIC_NAME_NULL TAOS_DEF_ERROR_CODE(0, 0x1197) //"metric name length is 0") -#define TSDB_CODE_HTTP_OP_METRIC_NAME_LONG TAOS_DEF_ERROR_CODE(0, 0x1198) //"metric name length can not more than 22") -#define TSDB_CODE_HTTP_OP_TIMESTAMP_NULL TAOS_DEF_ERROR_CODE(0, 0x1199) //"timestamp not find") -#define TSDB_CODE_HTTP_OP_TIMESTAMP_TYPE TAOS_DEF_ERROR_CODE(0, 0x119A) //"timestamp type should be integer") -#define TSDB_CODE_HTTP_OP_TIMESTAMP_VAL_NULL TAOS_DEF_ERROR_CODE(0, 0x119B) //"timestamp value smaller than 0") -#define TSDB_CODE_HTTP_OP_TAGS_NULL TAOS_DEF_ERROR_CODE(0, 0x119C) //"tags not find") -#define TSDB_CODE_HTTP_OP_TAGS_SIZE_0 TAOS_DEF_ERROR_CODE(0, 0x119D) //"tags size is 0") -#define TSDB_CODE_HTTP_OP_TAGS_SIZE_LONG TAOS_DEF_ERROR_CODE(0, 0x119E) //"tags size too long") -#define TSDB_CODE_HTTP_OP_TAG_NULL TAOS_DEF_ERROR_CODE(0, 0x119F) //"tag is null") -#define TSDB_CODE_HTTP_OP_TAG_NAME_NULL TAOS_DEF_ERROR_CODE(0, 0x11A0) //"tag name is null") -#define TSDB_CODE_HTTP_OP_TAG_NAME_SIZE TAOS_DEF_ERROR_CODE(0, 0x11A1) //"tag name length too long") -#define TSDB_CODE_HTTP_OP_TAG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x11A2) //"tag value type should be boolean number or string") -#define TSDB_CODE_HTTP_OP_TAG_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x11A3) //"tag value is null") -#define TSDB_CODE_HTTP_OP_TAG_VALUE_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x11A4) //"tag value can not more than 64") -#define TSDB_CODE_HTTP_OP_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x11A5) //"value not find") -#define TSDB_CODE_HTTP_OP_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x11A6) //"value type should be boolean number or string") - -#define TSDB_CODE_HTTP_REQUEST_JSON_ERROR TAOS_DEF_ERROR_CODE(0, 0x1F00) //"http request json error") - -// odbc -#define TSDB_CODE_ODBC_OOM TAOS_DEF_ERROR_CODE(0, 0x2100) //"out of memory") -#define TSDB_CODE_ODBC_CONV_CHAR_NOT_NUM TAOS_DEF_ERROR_CODE(0, 0x2101) //"convertion not a valid literal input") -#define TSDB_CODE_ODBC_CONV_UNDEF TAOS_DEF_ERROR_CODE(0, 0x2102) //"convertion undefined") -#define TSDB_CODE_ODBC_CONV_TRUNC_FRAC TAOS_DEF_ERROR_CODE(0, 0x2103) //"convertion fractional truncated") -#define TSDB_CODE_ODBC_CONV_TRUNC TAOS_DEF_ERROR_CODE(0, 0x2104) //"convertion truncated") -#define TSDB_CODE_ODBC_CONV_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x2105) //"convertion not supported") -#define TSDB_CODE_ODBC_CONV_OOR TAOS_DEF_ERROR_CODE(0, 0x2106) //"convertion numeric value out of range") -#define TSDB_CODE_ODBC_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x2107) //"out of range") -#define TSDB_CODE_ODBC_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x2108) //"not supported yet") -#define TSDB_CODE_ODBC_INVALID_HANDLE TAOS_DEF_ERROR_CODE(0, 0x2109) //"invalid handle") -#define TSDB_CODE_ODBC_NO_RESULT TAOS_DEF_ERROR_CODE(0, 0x210a) //"no result set") -#define TSDB_CODE_ODBC_NO_FIELDS TAOS_DEF_ERROR_CODE(0, 0x210b) //"no fields returned") -#define TSDB_CODE_ODBC_INVALID_CURSOR TAOS_DEF_ERROR_CODE(0, 0x210c) //"invalid cursor") -#define TSDB_CODE_ODBC_STATEMENT_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x210d) //"statement not ready") -#define TSDB_CODE_ODBC_CONNECTION_BUSY TAOS_DEF_ERROR_CODE(0, 0x210e) //"connection still busy") -#define TSDB_CODE_ODBC_BAD_CONNSTR TAOS_DEF_ERROR_CODE(0, 0x210f) //"bad connection string") -#define TSDB_CODE_ODBC_BAD_ARG TAOS_DEF_ERROR_CODE(0, 0x2110) //"bad argument") -#define TSDB_CODE_ODBC_CONV_NOT_VALID_TS TAOS_DEF_ERROR_CODE(0, 0x2111) //"not a valid timestamp") -#define TSDB_CODE_ODBC_CONV_SRC_TOO_LARGE TAOS_DEF_ERROR_CODE(0, 0x2112) //"src too large") -#define TSDB_CODE_ODBC_CONV_SRC_BAD_SEQ TAOS_DEF_ERROR_CODE(0, 0x2113) //"src bad sequence") -#define TSDB_CODE_ODBC_CONV_SRC_INCOMPLETE TAOS_DEF_ERROR_CODE(0, 0x2114) //"src incomplete") -#define TSDB_CODE_ODBC_CONV_SRC_GENERAL TAOS_DEF_ERROR_CODE(0, 0x2115) //"src general") - // tfs #define TSDB_CODE_FS_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory") #define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) //"tfs invalid mount config") diff --git a/include/util/tbuffer.h b/include/util/tbuffer.h index d1d403e996cb9add581255d0544dfa9ef6c450d9..6bb7f67e3d52549bac2a381bc4d65ad1b6263bf5 100644 --- a/include/util/tbuffer.h +++ b/include/util/tbuffer.h @@ -16,6 +16,8 @@ #ifndef _TD_UTIL_BUFFER_H #define _TD_UTIL_BUFFER_H +#include "os.h" + #ifdef __cplusplus extern "C" { #endif @@ -71,102 +73,95 @@ int main( int argc, char** argv ) { */ typedef struct SBufferReader { - bool endian; + bool endian; const char* data; - size_t pos; - size_t size; + size_t pos; + size_t size; } SBufferReader; typedef struct SBufferWriter { - bool endian; - char* data; + bool endian; + char* data; size_t pos; size_t size; - void* (*allocator)( void*, size_t ); + void* (*allocator)(void*, size_t); } SBufferWriter; //////////////////////////////////////////////////////////////////////////////// // common functions & macros for both reader & writer -#define tbufTell( buf ) ((buf)->pos) - +#define tbufTell(buf) ((buf)->pos) //////////////////////////////////////////////////////////////////////////////// -// reader functions & macros - -// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically -#define tbufInitReader( Data, Size, Endian ) {.endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 :(Size))} - -size_t tbufSkip( SBufferReader* buf, size_t size ); - -const char* tbufRead( SBufferReader* buf, size_t size ); -void tbufReadToBuffer( SBufferReader* buf, void* dst, size_t size ); -const char* tbufReadString( SBufferReader* buf, size_t* len ); -size_t tbufReadToString( SBufferReader* buf, char* dst, size_t size ); -const char* tbufReadBinary( SBufferReader* buf, size_t *len ); -size_t tbufReadToBinary( SBufferReader* buf, void* dst, size_t size ); - -bool tbufReadBool( SBufferReader* buf ); -char tbufReadChar( SBufferReader* buf ); -int8_t tbufReadInt8( SBufferReader* buf ); -uint8_t tbufReadUint8( SBufferReader* buf ); -int16_t tbufReadInt16( SBufferReader* buf ); -uint16_t tbufReadUint16( SBufferReader* buf ); -int32_t tbufReadInt32( SBufferReader* buf ); -uint32_t tbufReadUint32( SBufferReader* buf ); -int64_t tbufReadInt64( SBufferReader* buf ); -uint64_t tbufReadUint64( SBufferReader* buf ); -float tbufReadFloat( SBufferReader* buf ); -double tbufReadDouble( SBufferReader* buf ); - - -//////////////////////////////////////////////////////////////////////////////// -// writer functions & macros - +/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */ // *Allocator*, function to allocate memory, will use 'realloc' if NULL // *Endian*, if true, writer functions of primitive types will do 'hton' automatically -#define tbufInitWriter( Allocator, Endian ) {.endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator))} -void tbufCloseWriter( SBufferWriter* buf ); - -void tbufEnsureCapacity( SBufferWriter* buf, size_t size ); -size_t tbufReserve( SBufferWriter* buf, size_t size ); -char* tbufGetData( SBufferWriter* buf, bool takeOver ); - -void tbufWrite( SBufferWriter* buf, const void* data, size_t size ); -void tbufWriteAt( SBufferWriter* buf, size_t pos, const void* data, size_t size ); -void tbufWriteStringLen( SBufferWriter* buf, const char* str, size_t len ); -void tbufWriteString( SBufferWriter* buf, const char* str ); +#define tbufInitWriter(Allocator, Endian) \ + { .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) } + +void tbufCloseWriter(SBufferWriter* buf); +void tbufEnsureCapacity(SBufferWriter* buf, size_t size); +size_t tbufReserve(SBufferWriter* buf, size_t size); +char* tbufGetData(SBufferWriter* buf, bool takeOver); +void tbufWrite(SBufferWriter* buf, const void* data, size_t size); +void tbufWriteAt(SBufferWriter* buf, size_t pos, const void* data, size_t size); +void tbufWriteStringLen(SBufferWriter* buf, const char* str, size_t len); +void tbufWriteString(SBufferWriter* buf, const char* str); // the prototype of tbufWriteBinary and tbufWrite are identical // the difference is: tbufWriteBinary writes the length of the data to the buffer // first, then the actual data, which means the reader don't need to know data // size before read. Write only write the data itself, which means the reader // need to know data size before read. -void tbufWriteBinary( SBufferWriter* buf, const void* data, size_t len ); - -void tbufWriteBool( SBufferWriter* buf, bool data ); -void tbufWriteBoolAt( SBufferWriter* buf, size_t pos, bool data ); -void tbufWriteChar( SBufferWriter* buf, char data ); -void tbufWriteCharAt( SBufferWriter* buf, size_t pos, char data ); -void tbufWriteInt8( SBufferWriter* buf, int8_t data ); -void tbufWriteInt8At( SBufferWriter* buf, size_t pos, int8_t data ); -void tbufWriteUint8( SBufferWriter* buf, uint8_t data ); -void tbufWriteUint8At( SBufferWriter* buf, size_t pos, uint8_t data ); -void tbufWriteInt16( SBufferWriter* buf, int16_t data ); -void tbufWriteInt16At( SBufferWriter* buf, size_t pos, int16_t data ); -void tbufWriteUint16( SBufferWriter* buf, uint16_t data ); -void tbufWriteUint16At( SBufferWriter* buf, size_t pos, uint16_t data ); -void tbufWriteInt32( SBufferWriter* buf, int32_t data ); -void tbufWriteInt32At( SBufferWriter* buf, size_t pos, int32_t data ); -void tbufWriteUint32( SBufferWriter* buf, uint32_t data ); -void tbufWriteUint32At( SBufferWriter* buf, size_t pos, uint32_t data ); -void tbufWriteInt64( SBufferWriter* buf, int64_t data ); -void tbufWriteInt64At( SBufferWriter* buf, size_t pos, int64_t data ); -void tbufWriteUint64( SBufferWriter* buf, uint64_t data ); -void tbufWriteUint64At( SBufferWriter* buf, size_t pos, uint64_t data ); -void tbufWriteFloat( SBufferWriter* buf, float data ); -void tbufWriteFloatAt( SBufferWriter* buf, size_t pos, float data ); -void tbufWriteDouble( SBufferWriter* buf, double data ); -void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data ); +void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len); +void tbufWriteBool(SBufferWriter* buf, bool data); +void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data); +void tbufWriteChar(SBufferWriter* buf, char data); +void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data); +void tbufWriteInt8(SBufferWriter* buf, int8_t data); +void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data); +void tbufWriteUint8(SBufferWriter* buf, uint8_t data); +void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data); +void tbufWriteInt16(SBufferWriter* buf, int16_t data); +void tbufWriteInt16At(SBufferWriter* buf, size_t pos, int16_t data); +void tbufWriteUint16(SBufferWriter* buf, uint16_t data); +void tbufWriteUint16At(SBufferWriter* buf, size_t pos, uint16_t data); +void tbufWriteInt32(SBufferWriter* buf, int32_t data); +void tbufWriteInt32At(SBufferWriter* buf, size_t pos, int32_t data); +void tbufWriteUint32(SBufferWriter* buf, uint32_t data); +void tbufWriteUint32At(SBufferWriter* buf, size_t pos, uint32_t data); +void tbufWriteInt64(SBufferWriter* buf, int64_t data); +void tbufWriteInt64At(SBufferWriter* buf, size_t pos, int64_t data); +void tbufWriteUint64(SBufferWriter* buf, uint64_t data); +void tbufWriteUint64At(SBufferWriter* buf, size_t pos, uint64_t data); +void tbufWriteFloat(SBufferWriter* buf, float data); +void tbufWriteFloatAt(SBufferWriter* buf, size_t pos, float data); +void tbufWriteDouble(SBufferWriter* buf, double data); +void tbufWriteDoubleAt(SBufferWriter* buf, size_t pos, double data); + +/* ------------------------ BUFFER READER FUNCTIONS AND MACROS ------------------------ */ +// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically +#define tbufInitReader(Data, Size, Endian) \ + { .endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 : (Size)) } + +size_t tbufSkip(SBufferReader* buf, size_t size); +const char* tbufRead(SBufferReader* buf, size_t size); +void tbufReadToBuffer(SBufferReader* buf, void* dst, size_t size); +const char* tbufReadString(SBufferReader* buf, size_t* len); +size_t tbufReadToString(SBufferReader* buf, char* dst, size_t size); +const char* tbufReadBinary(SBufferReader* buf, size_t* len); +size_t tbufReadToBinary(SBufferReader* buf, void* dst, size_t size); +bool tbufReadBool(SBufferReader* buf); +char tbufReadChar(SBufferReader* buf); +int8_t tbufReadInt8(SBufferReader* buf); +uint8_t tbufReadUint8(SBufferReader* buf); +int16_t tbufReadInt16(SBufferReader* buf); +uint16_t tbufReadUint16(SBufferReader* buf); +int32_t tbufReadInt32(SBufferReader* buf); +uint32_t tbufReadUint32(SBufferReader* buf); +int64_t tbufReadInt64(SBufferReader* buf); +uint64_t tbufReadUint64(SBufferReader* buf); +float tbufReadFloat(SBufferReader* buf); +double tbufReadDouble(SBufferReader* buf); #ifdef __cplusplus } diff --git a/include/util/tcoding.h b/include/util/tcoding.h index a2c91c5dbe13f750647764e0495dddb61d123f14..e1edf0d7922eec321a282036811e3aa470a4ff59 100644 --- a/include/util/tcoding.h +++ b/include/util/tcoding.h @@ -25,6 +25,8 @@ extern "C" { #define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode #define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode +/* ------------------------ LEGACY CODES ------------------------ */ +#if 1 // ---- Fixed U8 static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) { if (buf != NULL) { @@ -357,6 +359,19 @@ static FORCE_INLINE void *taosDecodeString(void *buf, char **value) { return POINTER_SHIFT(buf, size); } +static FORCE_INLINE void *taosDecodeStringTo(void *buf, char *value) { + uint64_t size = 0; + + buf = taosDecodeVariantU64(buf, &size); + memcpy(value, buf, (size_t)size); + + value[size] = '\0'; + + return POINTER_SHIFT(buf, size); +} + +#endif + #ifdef __cplusplus } #endif diff --git a/include/util/tdef.h b/include/util/tdef.h index f3f3643268dea8aed1049d940acdef84f116c256..233e9f0f5522f2d4f5505e443ce22a7301c1f00a 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -149,7 +149,7 @@ do { \ #define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN)) #define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER)) -#define TS_PATH_DELIMITER_LEN 1 +#define TSDB_NAME_DELIMITER_LEN 1 #define TSDB_UNI_LEN 24 #define TSDB_USER_LEN TSDB_UNI_LEN @@ -163,18 +163,20 @@ do { \ #define TSDB_NODE_NAME_LEN 64 #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string +#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string #define TSDB_DB_NAME_LEN 65 -#define TSDB_FULL_DB_NAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN) +#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN) -#define TSDB_FUNC_NAME_LEN 65 -#define TSDB_FUNC_COMMENT_LEN 4096 -#define TSDB_FUNC_CODE_LEN (65535 - 512) -#define TSDB_FUNC_BUF_SIZE 512 -#define TSDB_FUNC_TYPE_SCALAR 1 -#define TSDB_FUNC_TYPE_AGGREGATE 2 +#define TSDB_FUNC_NAME_LEN 65 +#define TSDB_FUNC_COMMENT_LEN 4096 +#define TSDB_FUNC_CODE_LEN (65535 - 512) +#define TSDB_FUNC_BUF_SIZE 512 +#define TSDB_FUNC_TYPE_SCALAR 1 +#define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_TYPE_STR_MAX_LEN 32 -#define TSDB_TABLE_FNAME_LEN (TSDB_FULL_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) +#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_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE @@ -202,7 +204,7 @@ do { \ #define TSDB_CLUSTER_ID_LEN 40 #define TSDB_FQDN_LEN 128 -#define TSDB_EP_LEN (TSDB_FQDN_LEN+6) +#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6) #define TSDB_IPv4ADDR_LEN 16 #define TSDB_FILENAME_LEN 128 #define TSDB_SHOW_SQL_LEN 512 @@ -315,12 +317,12 @@ do { \ #define TSDB_MAX_FIELD_LEN 16384 #define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 #define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 -#define PRIMARYKEY_TIMESTAMP_COL_ID 0 +#define PRIMARYKEY_TIMESTAMP_COL_ID 1 #define TSDB_MAX_RPC_THREADS 5 -#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type -#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode +#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type +#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode #define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default diff --git a/include/util/thash.h b/include/util/thash.h index d0247a0729012b860132cc691e6df745dde12a83..f38ab50893cfdad92281474bf12120f5e5bc3769 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -144,6 +144,16 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen); */ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf); +/** + * Clone the result to interval allocated buffer + * @param pHashObj + * @param key + * @param keyLen + * @param destBuf + * @return + */ +void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz); + /** * remove item with the specified key * @param pHashObj @@ -200,6 +210,26 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p); */ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen); +/** + * return the payload data with the specified key(reference number added) + * + * @param pHashObj + * @param key + * @param keyLen + * @return + */ +void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen); + +/** + * release the prevous acquired obj + * + * @param pHashObj + * @param data + * @return + */ +void taosHashRelease(SHashObj *pHashObj, void *p); + + #ifdef __cplusplus } #endif diff --git a/include/util/tmacro.h b/include/util/tmacro.h index 5cca8a10629c8d818fe52e331f3a84a11f7fd999..5ed051c02173256144b59e16dce4568e1b0072ed 100644 --- a/include/util/tmacro.h +++ b/include/util/tmacro.h @@ -35,6 +35,8 @@ typedef int8_t td_mode_flag_t; #define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNCLEARD, TD_MOD_CLEARD) +#define TD_IS_NULL(PTR) ((PTR) == NULL) + #ifdef __cplusplus } #endif diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index c78bf02cbdf73ab0fa3fb7e34814945a870f8aac..ad6a93415cfbba9b00b0ca1ebaf377e31d6a3049 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -8,7 +8,7 @@ target_include_directories( target_link_libraries( taos INTERFACE api - PRIVATE os util common transport parser catalog function qcom + PRIVATE os util common transport parser planner catalog scheduler function qcom ) ADD_SUBDIRECTORY(test) \ No newline at end of file diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index a34250ccab8f51355e0318bfc65d248234cb4d7e..706e838b948b0b92d8efce73a7809c66c0c181c3 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -22,13 +22,14 @@ extern "C" { #include "taos.h" #include "common.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tdef.h" #include "tep.h" #include "thash.h" #include "tlist.h" #include "tmsgtype.h" #include "trpc.h" +#include "query.h" typedef struct SQueryExecMetric { int64_t start; // start timestamp @@ -37,7 +38,7 @@ typedef struct SQueryExecMetric { int64_t rsp; // receive response from server } SQueryExecMetric; -typedef struct SInstanceActivity { +typedef struct SInstanceSummary { uint64_t numOfInsertsReq; uint64_t numOfInsertRows; uint64_t insertElapsedTime; @@ -48,7 +49,7 @@ typedef struct SInstanceActivity { uint64_t numOfSlowQueries; uint64_t totalRequests; uint64_t currentRequests; // the number of SRequestObj -} SInstanceActivity; +} SInstanceSummary; typedef struct SHeartBeatInfo { void *pTimer; // timer, used to send request msg to mnode @@ -57,9 +58,9 @@ typedef struct SHeartBeatInfo { typedef struct SAppInstInfo { int64_t numOfConns; SCorEpSet mgmtEp; - SInstanceActivity summary; + SInstanceSummary summary; SList *pConnList; // STscObj linked list - uint32_t clusterId; + int64_t clusterId; void *pTransporter; } SAppInstInfo; @@ -74,16 +75,16 @@ typedef struct SAppInfo { } SAppInfo; typedef struct STscObj { - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; - int32_t acctId; - uint32_t connId; - uint64_t id; // ref ID returned by taosAddRef - void *pTransporter; - pthread_mutex_t mutex; // used to protect the operation on db - int32_t numOfReqs; // number of sqlObj from this tscObj - SAppInstInfo *pAppInfo; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int32_t acctId; + uint32_t connId; + uint64_t id; // ref ID returned by taosAddRef + void *pTransporter; + pthread_mutex_t mutex; // used to protect the operation on db + int32_t numOfReqs; // number of sqlObj from this tscObj + SAppInstInfo *pAppInfo; } STscObj; typedef struct SReqResultInfo { @@ -100,16 +101,11 @@ typedef struct SReqResultInfo { uint32_t current; } SReqResultInfo; -typedef struct SReqMsg { - void *pMsg; - uint32_t len; -} SReqMsgInfo; - typedef struct SRequestSendRecvBody { tsem_t rspSem; // not used now void* fp; int64_t execId; // showId/queryId - SReqMsgInfo requestMsg; + SDataBuf requestMsg; SReqResultInfo resInfo; } SRequestSendRecvBody; @@ -119,28 +115,24 @@ typedef struct SRequestObj { uint64_t requestId; int32_t type; // request type STscObj *pTscObj; - SQueryExecMetric metric; char *sqlstr; // sql string - SRequestSendRecvBody body; + int32_t sqlLen; int64_t self; char *msgBuf; - int32_t code; void *pInfo; // sql parse info, generated by parser module + int32_t code; + uint64_t affectedRows; + SQueryExecMetric metric; + SRequestSendRecvBody body; } SRequestObj; -typedef struct SRequestMsgBody { - int32_t msgType; - SReqMsgInfo msgInfo; - uint64_t requestId; - uint64_t requestObjRefId; -} SRequestMsgBody; - -extern SAppInfo appInfo; -extern int32_t tscReqRef; -extern int32_t tscConnRef; +extern SAppInfo appInfo; +extern int32_t clientReqRefPool; +extern int32_t clientConnRefPool; -SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest); -extern int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); +extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); +int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code); +SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj*); int taos_init(); @@ -154,7 +146,7 @@ char *getConnectionDB(STscObj* pObj); void setConnectionDB(STscObj* pTscObj, const char* db); void taos_init_imp(void); -int taos_options_imp(TSDB_OPTION option, const char *str); +int taos_options_imp(TSDB_OPTION option, const char *str); void* openTransporter(const char *user, const char *auth, int32_t numOfThreads); @@ -164,8 +156,8 @@ void initMsgHandleFp(); TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port); TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); -void* doFetchRow(SRequestObj* pRequest); -void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); +void *doFetchRow(SRequestObj* pRequest); +void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); #ifdef __cplusplus } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index b54f7fedd788ea464714c17f033ac5b1bac48244..960ba95324ca90d96fc9af6f1106acdc2c37737d 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -13,12 +13,13 @@ * along with this program. If not, see . */ -#include +#include "os.h" +#include "catalog.h" #include "clientInt.h" #include "clientLog.h" -#include "os.h" #include "query.h" -#include "taosmsg.h" +#include "scheduler.h" +#include "tmsg.h" #include "tcache.h" #include "tconfig.h" #include "tglobal.h" @@ -32,26 +33,26 @@ #define TSC_VAR_RELEASED 0 SAppInfo appInfo; -int32_t tscReqRef = -1; -int32_t tscConnRef = -1; +int32_t clientReqRefPool = -1; +int32_t clientConnRefPool = -1; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; volatile int32_t tscInitRes = 0; static void registerRequest(SRequestObj* pRequest) { - STscObj *pTscObj = (STscObj *)taosAcquireRef(tscConnRef, pRequest->pTscObj->id); + STscObj *pTscObj = (STscObj *)taosAcquireRef(clientConnRefPool, pRequest->pTscObj->id); assert(pTscObj != NULL); // connection has been released already, abort creating request. - pRequest->self = taosAddRef(tscReqRef, pRequest); + pRequest->self = taosAddRef(clientReqRefPool, pRequest); int32_t num = atomic_add_fetch_32(&pTscObj->numOfReqs, 1); if (pTscObj->pAppInfo) { - SInstanceActivity *pActivity = &pTscObj->pAppInfo->summary; + SInstanceSummary *pSummary = &pTscObj->pAppInfo->summary; - int32_t total = atomic_add_fetch_32(&pActivity->totalRequests, 1); - int32_t currentInst = atomic_add_fetch_32(&pActivity->currentRequests, 1); + int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1); + int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 1); tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d", pRequest->self, pRequest->pTscObj->id, num, currentInst, total); } @@ -61,13 +62,13 @@ static void deregisterRequest(SRequestObj* pRequest) { assert(pRequest != NULL); STscObj* pTscObj = pRequest->pTscObj; - SInstanceActivity* pActivity = &pTscObj->pAppInfo->summary; + SInstanceSummary* pActivity = &pTscObj->pAppInfo->summary; int32_t currentInst = atomic_sub_fetch_32(&pActivity->currentRequests, 1); int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1); tscDebug("0x%"PRIx64" free Request from connObj: 0x%"PRIx64", current:%d, app current:%d", pRequest->self, pTscObj->id, num, currentInst); - taosReleaseRef(tscConnRef, pTscObj->id); + taosReleaseRef(clientConnRefPool, pTscObj->id); } static void tscInitLogFile() { @@ -150,7 +151,7 @@ void* createTscObj(const char* user, const char* auth, const char *db, SAppInstI } pthread_mutex_init(&pObj->mutex, NULL); - pObj->id = taosAddRef(tscConnRef, pObj); + pObj->id = taosAddRef(clientConnRefPool, pObj); tscDebug("connObj created, 0x%"PRIx64, pObj->id); return pObj; @@ -167,13 +168,11 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty // TODO generated request uuid pRequest->requestId = 0; - pRequest->metric.start = taosGetTimestampMs(); pRequest->type = type; pRequest->pTscObj = pObj; - pRequest->body.fp = fp; -// pRequest->body.requestMsg. = param; + pRequest->body.fp = fp; // not used it yet pRequest->msgBuf = calloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); tsem_init(&pRequest->body.rspSem, 0, 0); @@ -202,7 +201,7 @@ void destroyRequest(SRequestObj* pRequest) { return; } - taosReleaseRef(tscReqRef, pRequest->self); + taosReleaseRef(clientReqRefPool, pRequest->self); } void taos_init_imp(void) { @@ -229,17 +228,19 @@ void taos_init_imp(void) { rpcInit(); - SCatalogCfg cfg = {.enableVgroupCache = true, .maxDBCacheNum = 100, .maxTblCacheNum = 100}; + SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; catalogInit(&cfg); + SSchedulerCfg scfg = {.maxJobNum = 100}; + schedulerInit(&scfg); tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp); taosSetCoreDump(true); initTaskQueue(); - tscConnRef = taosOpenRef(200, destroyTscObj); - tscReqRef = taosOpenRef(40960, doDestroyRequest); + clientConnRefPool = taosOpenRef(200, destroyTscObj); + clientReqRefPool = taosOpenRef(40960, doDestroyRequest); taosGetAppName(appInfo.appName, NULL); appInfo.pid = taosGetPId(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 992d93f39b71550d2c1b60cb7984d45ed0c75128..89c31092b43c877a2972f746c45b8fb11c2d825d 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -9,12 +9,21 @@ #include "tpagedfile.h" #include "tref.h" #include "parser.h" +#include "planner.h" +#include "scheduler.h" + +#define CHECK_CODE_GOTO(expr, lable) \ + do { \ + int32_t code = expr; \ + if (TSDB_CODE_SUCCESS != code) { \ + terrno = code; \ + goto lable; \ + } \ + } while (0) static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet); -static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody); -static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody); - -static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId); +static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest); +static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); static bool stringLengthCheck(const char* str, size_t maxsize) { if (str == NULL) { @@ -113,109 +122,192 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst); } -TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { - STscObj *pTscObj = (STscObj *)taos; - if (sqlLen > (size_t) tsMaxSQLStringLen) { - tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); - terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - return NULL; - } - - nPrintTsc("%s", sql) - - SRequestObj* pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT); - if (pRequest == NULL) { +int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj** pRequest) { + *pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT); + if (*pRequest == NULL) { tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - return NULL; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } - pRequest->sqlstr = malloc(sqlLen + 1); - if (pRequest->sqlstr == NULL) { - tscError("0x%"PRIx64" failed to prepare sql string buffer", pRequest->self); - - pRequest->msgBuf = strdup("failed to prepare sql string buffer"); - terrno = pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - return pRequest; + (*pRequest)->sqlstr = malloc(sqlLen + 1); + if ((*pRequest)->sqlstr == NULL) { + tscError("0x%"PRIx64" failed to prepare sql string buffer", (*pRequest)->self); + (*pRequest)->msgBuf = strdup("failed to prepare sql string buffer"); + return TSDB_CODE_TSC_OUT_OF_MEMORY; } - strntolower(pRequest->sqlstr, sql, (int32_t)sqlLen); - pRequest->sqlstr[sqlLen] = 0; + strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen); + (*pRequest)->sqlstr[sqlLen] = 0; + (*pRequest)->sqlLen = sqlLen; - tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr); + tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr); + return TSDB_CODE_SUCCESS; +} + +int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) { + STscObj* pTscObj = pRequest->pTscObj; SParseContext cxt = { - .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)}, - .pSql = pRequest->sqlstr, - .sqlLen = sqlLen, - .pMsg = pRequest->msgBuf, + .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj), .pTransporter = pTscObj->pTransporter}, + .pSql = pRequest->sqlstr, + .sqlLen = pRequest->sqlLen, + .pMsg = pRequest->msgBuf, .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE }; - SQueryNode* pQuery = NULL; - int32_t code = qParseQuerySql(&cxt, &pQuery); - if (qIsDclQuery(pQuery)) { - SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; - pRequest->type = pDcl->msgType; - pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = pDcl->pMsg, .len = pDcl->msgLen}; - SRequestMsgBody body = buildRequestMsgImpl(pRequest); + cxt.ctx.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + + // todo OPT performance + char buf[12] = {0}; + sprintf(buf, "%"PRId64, pTscObj->pAppInfo->clusterId); + + struct SCatalog* pCatalog = NULL; + int32_t code = catalogGetHandle(buf, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + tfree(cxt.ctx.db); + return code; + } + + cxt.ctx.pCatalog = pCatalog; + code = qParseQuerySql(&cxt, pQuery); + + tfree(cxt.ctx.db); + return code; +} + +int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { + SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; + pRequest->type = pDcl->msgType; + pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen}; + + STscObj* pTscObj = pRequest->pTscObj; + SMsgSendInfo* pSendMsg = buildSendMsgInfoImpl(pRequest); + + int64_t transporterId = 0; + if (pDcl->msgType == TDMT_VND_CREATE_TABLE) { + asyncSendMsgToServer(pTscObj->pTransporter, &pDcl->epSet, &transporterId, pSendMsg); + } else { SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; + asyncSendMsgToServer(pTscObj->pTransporter, pEpSet, &transporterId, pSendMsg); + } - if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) { - struct SCatalog* pCatalog = NULL; + tsem_wait(&pRequest->body.rspSem); + destroySendMsgInfo(pSendMsg); + return TSDB_CODE_SUCCESS; +} - char buf[12] = {0}; - sprintf(buf, "%d", pTscObj->pAppInfo->clusterId); - code = catalogGetHandle(buf, &pCatalog); - if (code != 0) { - pRequest->code = code; - return pRequest; - } +int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { + pRequest->type = pQuery->type; + return qCreateQueryDag(pQuery, pDag); +} + +int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { + if (TSDB_SQL_INSERT == pRequest->type) { + return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); + } + return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); +} - SCreateTableMsg* pMsg = body.msgInfo.pMsg; +TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sqlLen) { + STscObj* pTscObj = (STscObj*)taos; + SRequestObj* pRequest = NULL; + SQueryNode* pQuery = NULL; + SQueryDag* pDag = NULL; + char *dagStr = NULL; - SName t = {0}; - tNameFromString(&t, pMsg->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE); + terrno = TSDB_CODE_SUCCESS; - char db[TSDB_DB_NAME_LEN + TS_PATH_DELIMITER_LEN + TSDB_ACCT_ID_LEN] = {0}; - tNameGetFullDbName(&t, db); + CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); - SVgroupInfo info = {0}; - catalogGetTableHashVgroup(pCatalog, pTscObj->pTransporter, pEpSet, db, tNameGetTableName(&t), &info); +//temporary disabled until planner ready +#if 0 + CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return); + //TODO: check sql valid - int64_t transporterId = 0; - SEpSet ep = {0}; - ep.inUse = info.inUse; - ep.numOfEps = info.numOfEps; - for(int32_t i = 0; i < ep.numOfEps; ++i) { - ep.port[i] = info.epAddr[i].port; - tstrncpy(ep.fqdn[i], info.epAddr[i].fqdn, tListLen(ep.fqdn[i])); - } + CHECK_CODE_GOTO(qCreateQueryDag(pQuery, &pDag), _return); - sendMsgToServer(pTscObj->pTransporter, &ep, &body, &transporterId); - } else { - int64_t transporterId = 0; - sendMsgToServer(pTscObj->pTransporter, pEpSet, &body, &transporterId); - } + dagStr = qDagToString(pDag); + if(dagStr == NULL) { + //TODO + } +#endif + + SCMCreateTopicReq req = { + .name = (char*)name, + .igExists = 0, + /*.physicalPlan = dagStr,*/ + .physicalPlan = (char*)sql, + .logicalPlan = "", + }; - tsem_wait(&pRequest->body.rspSem); - destroyRequestMsgBody(&body); + int tlen = tSerializeSCMCreateTopicReq(NULL, &req); + void* buf = malloc(tlen); + if(buf == NULL) { + goto _return; } + void* abuf = buf; + tSerializeSCMCreateTopicReq(&abuf, &req); + /*printf("formatted: %s\n", dagStr);*/ - tfree(cxt.ctx.db); + pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen }; - if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - return pRequest; + SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest); + SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; + + int64_t transporterId = 0; + asyncSendMsgToServer(pTscObj->pTransporter, pEpSet, &transporterId, body); + + tsem_wait(&pRequest->body.rspSem); + +_return: + qDestroyQuery(pQuery); + qDestroyQueryDag(pDag); + destroySendMsgInfo(body); + if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) { + pRequest->code = terrno; + } + return pRequest; +} + +TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { + STscObj *pTscObj = (STscObj *)taos; + if (sqlLen > (size_t) tsMaxSQLStringLen) { + tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); + terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; + return NULL; + } + + nPrintTsc("%s", sql) + + SRequestObj* pRequest = NULL; + SQueryNode* pQuery = NULL; + SQueryDag* pDag = NULL; + void* pJob = NULL; + + terrno = TSDB_CODE_SUCCESS; + CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); + CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return); + + if (qIsDdlQuery(pQuery)) { + CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return); + } else { + CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pDag), _return); + CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return); } +_return: + qDestroyQuery(pQuery); + qDestroyQueryDag(pDag); + if (NULL != pRequest && TSDB_CODE_SUCCESS != terrno) { + pRequest->code = terrno; + } return pRequest; } int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet) { pEpSet->version = 0; - // init mgmt ip set + // init mnode ip set SEpSet *mgmtEpSet = &(pEpSet->epSet); mgmtEpSet->numOfEps = 0; mgmtEpSet->inUse = 0; @@ -255,21 +347,20 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con return pTscObj; } - SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_MSG_TYPE_CONNECT); + SRequestObj *pRequest = createRequest(pTscObj, fp, param, TDMT_MND_CONNECT); if (pRequest == NULL) { destroyTscObj(pTscObj); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } - SRequestMsgBody body = {0}; - buildConnectMsg(pRequest, &body); + SMsgSendInfo* body = buildConnectMsg(pRequest); int64_t transporterId = 0; - sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); + asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroyRequestMsgBody(&body); + destroySendMsgInfo(body); if (pRequest->code != TSDB_CODE_SUCCESS) { const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); @@ -286,15 +377,25 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con return pTscObj; } -static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT; - pMsgBody->msgInfo.len = sizeof(SConnectMsg); - pMsgBody->requestObjRefId = pRequest->self; +static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest) { + SMsgSendInfo *pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + if (pMsgSendInfo == NULL) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + return NULL; + } + + pMsgSendInfo->msgType = TDMT_MND_CONNECT; + pMsgSendInfo->msgInfo.len = sizeof(SConnectMsg); + pMsgSendInfo->requestObjRefId = pRequest->self; + pMsgSendInfo->requestId = pRequest->requestId; + pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)]; + pMsgSendInfo->param = pRequest; SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg)); if (pConnect == NULL) { + tfree(pMsgSendInfo); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - return -1; + return NULL; } STscObj *pObj = pRequest->pTscObj; @@ -307,84 +408,62 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) pConnect->startTime = htobe64(appInfo.startTime); tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app)); - pMsgBody->msgInfo.pMsg = pConnect; - return 0; + pMsgSendInfo->msgInfo.pData = pConnect; + return pMsgSendInfo; } -static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody) { +static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { assert(pMsgBody != NULL); - tfree(pMsgBody->msgInfo.pMsg); -} - -int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId) { - char *pMsg = rpcMallocCont(pBody->msgInfo.len); - if (NULL == pMsg) { - tscError("0x%"PRIx64" msg:%s malloc failed", pBody->requestId, taosMsg[pBody->msgType]); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - return -1; - } - - memcpy(pMsg, pBody->msgInfo.pMsg, pBody->msgInfo.len); - SRpcMsg rpcMsg = { - .msgType = pBody->msgType, - .pCont = pMsg, - .contLen = pBody->msgInfo.len, - .ahandle = (void*) pBody->requestObjRefId, - .handle = NULL, - .code = 0 - }; - - rpcSendRequest(pTransporter, epSet, &rpcMsg, pTransporterId); - return TSDB_CODE_SUCCESS; + tfree(pMsgBody->msgInfo.pData); + tfree(pMsgBody); } void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - int64_t requestRefId = (int64_t)pMsg->ahandle; + SMsgSendInfo *pSendInfo = (SMsgSendInfo *) pMsg->ahandle; + assert(pMsg->ahandle != NULL); - SRequestObj *pRequest = (SRequestObj *)taosAcquireRef(tscReqRef, requestRefId); - if (pRequest == NULL) { - rpcFreeCont(pMsg->pCont); - return; - } - - assert(pRequest->self == requestRefId); - pRequest->metric.rsp = taosGetTimestampMs(); + if (pSendInfo->requestObjRefId != 0) { + SRequestObj *pRequest = (SRequestObj *)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId); + assert(pRequest->self == pSendInfo->requestObjRefId); - pRequest->code = pMsg->code; + pRequest->metric.rsp = taosGetTimestampMs(); + pRequest->code = pMsg->code; - STscObj *pTscObj = pRequest->pTscObj; - if (pEpSet) { - if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, pEpSet)) { - updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, pEpSet); + STscObj *pTscObj = pRequest->pTscObj; + if (pEpSet) { + if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, pEpSet)) { + updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, pEpSet); + } } - } - /* + /* * There is not response callback function for submit response. * The actual inserted number of points is the first number. - */ - if (pMsg->code == TSDB_CODE_SUCCESS) { - tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType], - tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start); - if (handleRequestRspFp[pRequest->type]) { - char *p = malloc(pMsg->contLen); - if (p == NULL) { - pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - terrno = pRequest->code; - } else { - memcpy(p, pMsg->pCont, pMsg->contLen); - pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, p, pMsg->contLen); - } + */ + if (pMsg->code == TSDB_CODE_SUCCESS) { + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%" PRId64 " ms", pRequest->requestId, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, + pRequest->metric.rsp - pRequest->metric.start); + } else { + tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%" PRId64 " ms", pRequest->requestId, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, + pRequest->metric.rsp - pRequest->metric.start); } + + taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); + } + + SDataBuf buf = {.len = pMsg->contLen}; + buf.pData = calloc(1, pMsg->contLen); + if (buf.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pMsg->code = TSDB_CODE_OUT_OF_MEMORY; } else { - tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, taosMsg[pMsg->msgType], - tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start); + memcpy(buf.pData, pMsg->pCont, pMsg->contLen); } - taosReleaseRef(tscReqRef, requestRefId); + pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); rpcFreeCont(pMsg->pCont); - - sem_post(&pRequest->body.rspSem); } TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) { @@ -419,16 +498,22 @@ void* doFetchRow(SRequestObj* pRequest) { SReqResultInfo* pResultInfo = &pRequest->body.resInfo; if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) { - pRequest->type = TSDB_MSG_TYPE_SHOW_RETRIEVE; + if (pRequest->type == TDMT_MND_SHOW) { + pRequest->type = TDMT_MND_SHOW_RETRIEVE; + } else if (pRequest->type == TDMT_VND_SHOW_TABLES) { + pRequest->type = TDMT_VND_SHOW_TABLES_FETCH; + } else { + // do nothing + } - SRequestMsgBody body = buildRequestMsgImpl(pRequest); + SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest); - int64_t transporterId = 0; - STscObj* pTscObj = pRequest->pTscObj; - sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); + int64_t transporterId = 0; + STscObj *pTscObj = pRequest->pTscObj; + asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroyRequestMsgBody(&body); + destroySendMsgInfo(body); pResultInfo->current = 0; if (pResultInfo->numOfRows <= pResultInfo->current) { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index f50765d37a82a2836cd671286d9bd64cdfc4f837..894b810d7b29410b64a69b76f799f7cad2cf8a49 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2,7 +2,7 @@ #include "clientInt.h" #include "clientLog.h" #include "query.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tref.h" #include "trpc.h" @@ -35,14 +35,14 @@ void taos_cleanup(void) { return; } - int32_t id = tscReqRef; - tscReqRef = -1; + int32_t id = clientReqRefPool; + clientReqRefPool = -1; taosCloseRef(id); cleanupTaskQueue(); - id = tscConnRef; - tscConnRef = -1; + id = clientConnRefPool; + clientConnRefPool = -1; taosCloseRef(id); rpcCleanup(); @@ -72,7 +72,7 @@ void taos_close(TAOS* taos) { STscObj *pTscObj = (STscObj *)taos; tscDebug("0x%"PRIx64" try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs); - taosRemoveRef(tscConnRef, pTscObj->id); + taosRemoveRef(clientConnRefPool, pTscObj->id); } int taos_errno(TAOS_RES *tres) { @@ -130,7 +130,7 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { return NULL; } - return taos_query_l(taos, sql, strlen(sql)); + return taos_query_l(taos, sql, (int32_t) strlen(sql)); } TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { @@ -140,7 +140,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { SRequestObj *pRequest = (SRequestObj *) pRes; if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT) { + pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS) { return NULL; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 2fc5e84bffe0f32ecaa86b6238ab2ba779167a9b..6575102f81bde4e8bbed632513cbabfaa2a61734 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -18,48 +18,36 @@ #include "tname.h" #include "clientInt.h" #include "clientLog.h" -#include "tmsgtype.h" -#include "trpc.h" -int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); +int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); -int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT; - pMsgBody->msgInfo.len = sizeof(SConnectMsg); - pMsgBody->requestObjRefId = pRequest->self; - - SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg)); - if (pConnect == NULL) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - return -1; - } - - // TODO refactor full_name - char *db; // ugly code to move the space - - STscObj *pObj = pRequest->pTscObj; - pthread_mutex_lock(&pObj->mutex); - db = strstr(pObj->db, TS_PATH_DELIMITER); - - db = (db == NULL) ? pObj->db : db + 1; - tstrncpy(pConnect->db, db, sizeof(pConnect->db)); - pthread_mutex_unlock(&pObj->mutex); +static void setErrno(SRequestObj* pRequest, int32_t code) { + pRequest->code = code; + terrno = code; +} - pConnect->pid = htonl(appInfo.pid); - pConnect->startTime = htobe64(appInfo.startTime); - tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app)); +int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + setErrno(pRequest, code); - pMsgBody->msgInfo.pMsg = pConnect; - return 0; + sem_post(&pRequest->body.rspSem); + return code; } -int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { +int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + sem_post(&pRequest->body.rspSem); + return code; + } + STscObj *pTscObj = pRequest->pTscObj; - SConnectRsp *pConnect = (SConnectRsp *)pMsg; + SConnectRsp *pConnect = (SConnectRsp *)pMsg->pData; pConnect->acctId = htonl(pConnect->acctId); pConnect->connId = htonl(pConnect->connId); - pConnect->clusterId = htonl(pConnect->clusterId); + pConnect->clusterId = htobe64(pConnect->clusterId); assert(pConnect->epSet.numOfEps > 0); for(int32_t i = 0; i < pConnect->epSet.numOfEps; ++i) { @@ -81,45 +69,61 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { pTscObj->pAppInfo->clusterId = pConnect->clusterId; atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); - pRequest->body.resInfo.pRspMsg = pMsg; - tscDebug("0x%" PRIx64 " clusterId:%d, totalConn:%"PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns); + // pRequest->body.resInfo.pRspMsg = pMsg->pData; + tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId, + pTscObj->pAppInfo->numOfConns); + + sem_post(&pRequest->body.rspSem); return 0; } -static int32_t buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - pMsgBody->msgInfo.len = sizeof(SRetrieveTableMsg); - pMsgBody->requestObjRefId = pRequest->self; - - SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); - if (pRetrieveMsg == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; +SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { + SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + + pMsgSendInfo->requestObjRefId = pRequest->self; + pMsgSendInfo->requestId = pRequest->requestId; + pMsgSendInfo->param = pRequest; + pMsgSendInfo->msgType = pRequest->type; + + if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { + if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { + SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); + if (pRetrieveMsg == NULL) { + return NULL; + } + + pRetrieveMsg->showId = htonl(pRequest->body.execId); + pMsgSendInfo->msgInfo.pData = pRetrieveMsg; + pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg); + } else { + SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); + if (pFetchMsg == NULL) { + return NULL; + } + + pFetchMsg->id = htonl(pRequest->body.execId); + pFetchMsg->head.vgId = htonl(13); + pMsgSendInfo->msgInfo.pData = pFetchMsg; + pMsgSendInfo->msgInfo.len = sizeof(SVShowTablesFetchReq); + } + } else { + assert(pRequest != NULL); + pMsgSendInfo->msgInfo = pRequest->body.requestMsg; } - pRetrieveMsg->showId = htonl(pRequest->body.execId); - pMsgBody->msgInfo.pMsg = pRetrieveMsg; - return TSDB_CODE_SUCCESS; + pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)]; + return pMsgSendInfo; } -SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest) { - if (pRequest->type == TSDB_MSG_TYPE_SHOW_RETRIEVE) { - SRequestMsgBody body = {0}; - buildRetrieveMnodeMsg(pRequest, &body); - return body; - } else { - assert(pRequest != NULL); - SRequestMsgBody body = { - .requestObjRefId = pRequest->self, - .msgInfo = pRequest->body.requestMsg, - .msgType = pRequest->type, - .requestId = pRequest->requestId, - }; - return body; +int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; } -} -int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { - SShowRsp* pShow = (SShowRsp *)pMsg; + SShowRsp* pShow = (SShowRsp *)pMsg->pData; pShow->showId = htonl(pShow->showId); STableMetaMsg *pMetaMsg = &(pShow->tableMeta); @@ -129,6 +133,7 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) pMetaMsg->tuid = htobe64(pMetaMsg->tuid); for (int i = 0; i < pMetaMsg->numOfColumns; ++i) { pSchema->bytes = htonl(pSchema->bytes); + pSchema->colId = htonl(pSchema->colId); pSchema++; } @@ -140,7 +145,7 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) pFields[i].bytes = pSchema[i].bytes; } - pRequest->body.resInfo.pRspMsg = pMsg; + pRequest->body.resInfo.pRspMsg = pMsg->pData; SReqResultInfo* pResInfo = &pRequest->body.resInfo; pResInfo->fields = pFields; @@ -150,51 +155,127 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t)); pRequest->body.execId = pShow->showId; + tsem_post(&pRequest->body.rspSem); return 0; } -int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { - assert(msgLen >= sizeof(SRetrieveTableRsp)); +int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj *pRequest = param; + SReqResultInfo *pResInfo = &pRequest->body.resInfo; + tfree(pResInfo->pRspMsg); - tfree(pRequest->body.resInfo.pRspMsg); - pRequest->body.resInfo.pRspMsg = pMsg; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg; + SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData; pRetrieve->numOfRows = htonl(pRetrieve->numOfRows); pRetrieve->precision = htons(pRetrieve->precision); - SReqResultInfo* pResInfo = &pRequest->body.resInfo; + pResInfo->pRspMsg = pMsg->pData; pResInfo->numOfRows = pRetrieve->numOfRows; - pResInfo->pData = pRetrieve->data; // todo fix this in async model + pResInfo->pData = pRetrieve->data; pResInfo->current = 0; setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows, pRetrieve->completed, pRequest->body.execId); + + tsem_post(&pRequest->body.rspSem); return 0; } -int32_t processCreateDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { +int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { + assert(pMsg->len >= sizeof(SRetrieveTableRsp)); + + SRequestObj* pRequest = param; + tfree(pRequest->body.resInfo.pRspMsg); + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + pRequest->body.resInfo.pRspMsg = pMsg->pData; + + SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *) pMsg->pData; + pFetchRsp->numOfRows = htonl(pFetchRsp->numOfRows); + pFetchRsp->precision = htons(pFetchRsp->precision); + + SReqResultInfo* pResInfo = &pRequest->body.resInfo; + + pResInfo->pRspMsg = pMsg->pData; + pResInfo->numOfRows = pFetchRsp->numOfRows; + pResInfo->pData = pFetchRsp->data; + + pResInfo->current = 0; + setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); + + tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows, + pFetchRsp->completed, pRequest->body.execId); + + tsem_post(&pRequest->body.rspSem); + return 0; +} + +int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo rsp with the vnode id list + SRequestObj* pRequest = param; + tsem_post(&pRequest->body.rspSem); } -int32_t processUseDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { - SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg; +int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg->pData; SName name = {0}; tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB); char db[TSDB_DB_NAME_LEN] = {0}; tNameGetDbName(&name, db); + setConnectionDB(pRequest->pTscObj, db); + tsem_post(&pRequest->body.rspSem); + return 0; } -int32_t processCreateTableRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { - assert(pMsg != NULL); +int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { + assert(pMsg != NULL && param != NULL); + SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + tsem_post(&pRequest->body.rspSem); + return code; } -int32_t processDropDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { +int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo: Remove cache in catalog cache. + SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + tsem_post(&pRequest->body.rspSem); + return code; } void initMsgHandleFp() { @@ -273,11 +354,14 @@ void initMsgHandleFp() { tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; #endif - handleRequestRspFp[TSDB_MSG_TYPE_CONNECT] = processConnectRsp; - handleRequestRspFp[TSDB_MSG_TYPE_SHOW] = processShowRsp; - handleRequestRspFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = processRetrieveMnodeRsp; - handleRequestRspFp[TSDB_MSG_TYPE_CREATE_DB] = processCreateDbRsp; - handleRequestRspFp[TSDB_MSG_TYPE_USE_DB] = processUseDbRsp; - handleRequestRspFp[TSDB_MSG_TYPE_CREATE_TABLE] = processCreateTableRsp; - handleRequestRspFp[TSDB_MSG_TYPE_DROP_DB] = processDropDbRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW)] = processShowRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = processRetrieveMnodeRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp; + + handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = processShowRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = processRetrieveVndRsp; } \ No newline at end of file diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt index a3f2ad88bb6d8fc35e17ec76dd18539655a607fd..6886206363885e5fc8dc53706585d385065b0810 100644 --- a/source/client/test/CMakeLists.txt +++ b/source/client/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(clientTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( clientTest - PUBLIC os util common transport gtest taos + PUBLIC os util common transport gtest taos qcom ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 7a1e8ca0c3d19d1dc7913ded540f0454ea639b6a..be6e048378572342f010b0b806771cd34197c978 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -49,104 +49,105 @@ int main(int argc, char** argv) { TEST(testCase, driverInit_Test) { taos_init(); } -// TEST(testCase, connect_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// taos_close(pConn); -//} -// -// TEST(testCase, create_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, create_account_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, drop_account_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, show_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show users"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} -// -// TEST(testCase, drop_user_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +#if 0 +TEST(testCase, connect_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + taos_close(pConn); +} + +TEST(testCase, create_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, create_account_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, drop_account_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, show_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "show users"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} + +TEST(testCase, drop_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop user abc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, show_db_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -// TEST(testCase, show_db_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show databases"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} + + TAOS_RES* pRes = taos_query(pConn, "show databases"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} TEST(testCase, create_db_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); TAOS_RES* pRes = taos_query(pConn, "create database abc1"); @@ -160,16 +161,41 @@ TEST(testCase, create_db_Test) { int32_t numOfFields = taos_num_fields(pRes); ASSERT_EQ(numOfFields, 0); + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database abc1 vgroups 4"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } taos_close(pConn); } -TEST(testCase, use_db_test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +TEST(testCase, create_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); - TAOS_RES* pRes = taos_query(pConn, "use abc1"); + TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); + printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); + if (taos_errno(pRes) != 0) { + printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + taos_close(pConn); +} + +TEST(testCase, drop_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); + if (taos_errno(pRes) != 0) { + printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); } TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -178,59 +204,83 @@ TEST(testCase, use_db_test) { int32_t numOfFields = taos_num_fields(pRes); ASSERT_EQ(numOfFields, 0); + taos_free_result(pRes); taos_close(pConn); } -TEST(testCase, drop_db_test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +TEST(testCase, use_db_test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); - showDB(pConn); - - TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); + TAOS_RES* pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); + printf("error in use db, reason:%s\n", taos_errstr(pRes)); } - taos_free_result(pRes); + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); - showDB(pConn); taos_close(pConn); } -// TEST(testCase, create_stable_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +TEST(testCase, drop_db_test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); +// showDB(pConn); // -// pRes = taos_query(pConn, "use abc1"); +// TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); // if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // -// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); +// showDB(pConn); +// +// pRes = taos_query(pConn, "create database abc1"); // if (taos_errno(pRes) != 0) { -// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); +// printf("create to drop db, reason:%s\n", taos_errstr(pRes)); // } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// // taos_free_result(pRes); // taos_close(pConn); -//} +} + + TEST(testCase, create_stable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} TEST(testCase, create_table_Test) { - // TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // // TAOS_RES* pRes = taos_query(pConn, "use abc1"); @@ -242,13 +292,73 @@ TEST(testCase, create_table_Test) { // taos_close(pConn); } -TEST(testCase, create_ctable_Test) {} +TEST(testCase, create_ctable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + +// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); + taos_close(pConn); +} TEST(testCase, show_stable_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "show stables"); + if (taos_errno(pRes) != 0) { + printf("failed to show stables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, show_vgroup_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); - TAOS_RES* pRes = taos_query(pConn, "show stables"); + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "show vgroups"); + if (taos_errno(pRes) != 0) { + printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -266,7 +376,7 @@ TEST(testCase, show_stable_Test) { } TEST(testCase, drop_stable_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); TAOS_RES* pRes = taos_query(pConn, "create database abc1"); @@ -289,16 +399,67 @@ TEST(testCase, drop_stable_Test) { taos_free_result(pRes); taos_close(pConn); } +#endif -//TEST(testCase, show_table_Test) { -// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +//TEST(testCase, create_topic_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in create db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// } // taos_free_result(pRes); // -// pRes = taos_query(pConn, "show tables"); +// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); +// if (taos_errno(pRes) != 0) { +// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// // taos_free_result(pRes); // +// char* sql = "select * from st1"; +// tmq_create_topic(pConn, "test_topic_1", sql, strlen(sql)); // taos_close(pConn); //} + +TEST(testCase, show_table_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "show tables"); + if (taos_errno(pRes) != 0) { + printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} diff --git a/source/common/src/tep.c b/source/common/src/tep.c index ef47a0e0c2a5abc0a21692bd88fb1030ecf07de8..9cc99e7f517b9791417fbe743416294d125e29ba 100644 --- a/source/common/src/tep.c +++ b/source/common/src/tep.c @@ -39,3 +39,12 @@ void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet) { taosCorEndWrite(&pEpSet->version); } +SEpSet getEpSet_s(SCorEpSet *pEpSet) { + SEpSet ep = {0}; + taosCorBeginRead(&pEpSet->version); + ep = pEpSet->epSet; + taosCorEndRead(&pEpSet->version); + + return ep; +} + diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 910d05e9a3eec9518f76891240cd8f5af22e4c6d..9ddadc9ba60c3cc7f9284ab68d6b71fb12f3824a 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -15,17 +15,18 @@ #define _DEFAULT_SOURCE #include "os.h" + #include "taosdef.h" #include "taoserror.h" -#include "ulog.h" -#include "tlog.h" +#include "tcompare.h" #include "tconfig.h" +#include "tep.h" #include "tglobal.h" -#include "tcompare.h" -#include "tutil.h" -#include "ttimezone.h" #include "tlocale.h" -#include "tep.h" +#include "tlog.h" +#include "ttimezone.h" +#include "tutil.h" +#include "ulog.h" // cluster char tsFirst[TSDB_EP_LEN] = {0}; @@ -36,22 +37,24 @@ uint16_t tsServerPort = 6030; int32_t tsStatusInterval = 1; // second int8_t tsEnableTelemetryReporting = 0; char tsEmail[TSDB_FQDN_LEN] = {0}; +int32_t tsNumOfSupportVnodes = 16; // common -int32_t tsRpcTimer = 300; -int32_t tsRpcMaxTime = 600; // seconds; -int32_t tsRpcForceTcp = 1; //disable this, means query, show command use udp protocol as default -int32_t tsMaxShellConns = 50000; +int32_t tsRpcTimer = 300; +int32_t tsRpcMaxTime = 600; // seconds; +int32_t tsRpcForceTcp = 1; // disable this, means query, show command use udp protocol as default +int32_t tsMaxShellConns = 50000; int32_t tsMaxConnections = 5000; -int32_t tsShellActivityTimer = 3; // second +int32_t tsShellActivityTimer = 3; // second float tsNumOfThreadsPerCore = 1.0f; int32_t tsNumOfCommitThreads = 4; float tsRatioOfQueryCores = 1.0f; -int8_t tsDaylight = 0; +int8_t tsDaylight = 0; int8_t tsEnableCoreFile = 0; int32_t tsMaxBinaryDisplayWidth = 30; -int64_t tsMaxVnodeQueuedBytes = 1024*1024*1024; //1GB - +int8_t tsEnableSlaveQuery = 1; +int8_t tsEnableAdjustMaster = 1; +int8_t tsPrintAuth = 0; /* * denote if the server needs to compress response message at the application layer to client, including query rsp, * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server. @@ -79,7 +82,7 @@ int32_t tsMaxSQLStringLen = TSDB_MAX_ALLOWED_SQL_LEN; int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN; int32_t tsMaxRegexStringLen = TSDB_REGEX_STRING_DEFAULT_LEN; -int8_t tsTscEnableRecordSql = 0; +int8_t tsTscEnableRecordSql = 0; // the maximum number of results for projection query on super table that are returned from // one virtual node, to order according to timestamp @@ -89,7 +92,7 @@ int32_t tsMaxNumOfOrderedResults = 100000; int32_t tsMinSlidingTime = 10; // the maxinum number of distict query result -int32_t tsMaxNumOfDistinctResults = 1000 * 10000; +int32_t tsMaxNumOfDistinctResults = 1000 * 10000; // 1 us for interval time range, changed accordingly int32_t tsMinIntervalTime = 1; @@ -101,7 +104,7 @@ int32_t tsMaxStreamComputDelay = 20000; int32_t tsStreamCompStartDelay = 10000; // the stream computing delay time after executing failed, change accordingly -int32_t tsRetryStreamCompDelay = 10*1000; +int32_t tsRetryStreamCompDelay = 10 * 1000; // The delayed computing ration. 10% of the whole computing time window by default. float tsStreamComputDelayRatio = 0.1f; @@ -120,30 +123,16 @@ int64_t tsQueryBufferSizeBytes = -1; int32_t tsRetrieveBlockingModel = 0; // last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name -int8_t tsKeepOriginalColumnName = 0; +int8_t tsKeepOriginalColumnName = 0; + +// long query death-lock +int8_t tsDeadLockKillQuery = 0; -// tsdb config +// tsdb config // For backward compatibility bool tsdbForceKeepFile = false; -// balance -int8_t tsEnableFlowCtrl = 1; -int8_t tsEnableSlaveQuery = 1; -int8_t tsEnableAdjustMaster = 1; - - -// monitor -char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; -char tsInternalPass[] = "secretkey"; - -// internal -int8_t tsCompactMnodeWal = 0; -int8_t tsPrintAuth = 0; -char tsVnodeDir[PATH_MAX] = {0}; -char tsDnodeDir[PATH_MAX] = {0}; -char tsMnodeDir[PATH_MAX] = {0}; - -int32_t tsDiskCfgNum = 0; +int32_t tsDiskCfgNum = 0; #ifndef _STORAGE SDiskCfg tsDiskCfg[1]; @@ -160,31 +149,28 @@ SDiskCfg tsDiskCfg[TSDB_MAX_DISKS]; int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L}; // system info -float tsTotalTmpDirGB = 0; -float tsTotalDataDirGB = 0; -float tsAvailTmpDirectorySpace = 0; -float tsAvailDataDirGB = 0; -float tsUsedDataDirGB = 0; -float tsReservedTmpDirectorySpace = 1.0f; -float tsMinimalDataDirGB = 2.0f; -int32_t tsTotalMemoryMB = 0; +float tsTotalTmpDirGB = 0; +float tsTotalDataDirGB = 0; +float tsAvailTmpDirectorySpace = 0; +float tsAvailDataDirGB = 0; +float tsUsedDataDirGB = 0; +float tsReservedTmpDirectorySpace = 1.0f; +float tsMinimalDataDirGB = 2.0f; +int32_t tsTotalMemoryMB = 0; uint32_t tsVersion = 0; -#ifdef TD_TSZ // // lossy compress 6 // -char lossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty can close lossy compress. -// below option can take effect when tsLossyColumns not empty -double fPrecision = 1E-8; // float column precision -double dPrecision = 1E-16; // double column precision -uint32_t maxRange = 500; // max range -uint32_t curRange = 100; // range -char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR -#endif +char tsLossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty + // can close lossy compress. +// below option can take effect when tsLossyColumns not empty +double tsFPrecision = 1E-8; // float column precision +double tsDPrecision = 1E-16; // double column precision +uint32_t tsMaxRange = 500; // max range +uint32_t tsCurRange = 100; // range +char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR -// long query death-lock -int8_t tsDeadLockKillQuery = 0; int32_t (*monStartSystemFp)() = NULL; void (*monStopSystemFp)() = NULL; @@ -195,13 +181,12 @@ char *qtypeStr[] = {"rpc", "fwd", "wal", "cq", "query"}; static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT; void taosSetAllDebugFlag() { - if (debugFlag != 0) { + if (debugFlag != 0) { mDebugFlag = debugFlag; dDebugFlag = debugFlag; vDebugFlag = debugFlag; jniDebugFlag = debugFlag; - odbcDebugFlag = debugFlag; - qDebugFlag = debugFlag; + qDebugFlag = debugFlag; rpcDebugFlag = debugFlag; uDebugFlag = debugFlag; sDebugFlag = debugFlag; @@ -213,12 +198,12 @@ void taosSetAllDebugFlag() { } int32_t taosCfgDynamicOptions(char *msg) { - char *option, *value; - int32_t olen, vlen; - int32_t vint = 0; + char *option, *value; + int32_t olen, vlen; + int32_t vint = 0; paGetToken(msg, &option, &olen); - if (olen == 0) return -1;; + if (olen == 0) return -1; paGetToken(option + olen + 1, &value, &vlen); if (vlen == 0) @@ -231,9 +216,9 @@ int32_t taosCfgDynamicOptions(char *msg) { for (int32_t i = 0; i < tsGlobalConfigNum; ++i) { SGlobalCfg *cfg = tsGlobalConfig + i; - //if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; + // if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; if (cfg->valType != TAOS_CFG_VTYPE_INT32 && cfg->valType != TAOS_CFG_VTYPE_INT8) continue; - + int32_t cfgLen = (int32_t)strlen(cfg->option); if (cfgLen != olen) continue; if (strncasecmp(option, cfg->option, olen) != 0) continue; @@ -262,7 +247,7 @@ int32_t taosCfgDynamicOptions(char *msg) { return 0; } if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { - taosSetAllDebugFlag(); + taosSetAllDebugFlag(); } return 0; } @@ -323,7 +308,7 @@ static void doInitGlobalConfig(void) { srand(taosSafeRand()); SGlobalCfg cfg = {0}; - + // ip address cfg.option = "firstEp"; cfg.ptr = tsFirst; @@ -366,6 +351,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); + cfg.option = "supportVnodes"; + cfg.ptr = &tsNumOfSupportVnodes; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 65536; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosAddConfigOption(cfg); + // directory cfg.option = "configDir"; cfg.ptr = configDir; @@ -442,8 +437,8 @@ static void doInitGlobalConfig(void) { cfg.ptr = &tsMaxNumOfDistinctResults; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 10*10000; - cfg.maxValue = 10000*10000; + cfg.minValue = 10 * 10000; + cfg.maxValue = 10000 * 10000; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); @@ -749,17 +744,6 @@ static void doInitGlobalConfig(void) { cfg.maxValue = 10000000; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_GB; - taosAddConfigOption(cfg); - - // module configs - cfg.option = "flowctrl"; - cfg.ptr = &tsEnableFlowCtrl; - cfg.valType = TAOS_CFG_VTYPE_INT8; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 0; - cfg.maxValue = 1; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); cfg.option = "slaveQuery"; @@ -893,16 +877,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - cfg.option = "odbcDebugFlag"; - cfg.ptr = &odbcDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - cfg.option = "uDebugFlag"; cfg.ptr = &uDebugFlag; cfg.valType = TAOS_CFG_VTYPE_INT32; @@ -1034,7 +1008,7 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // enable kill long query + // enable kill long query cfg.option = "deadLockKillQuery"; cfg.ptr = &tsDeadLockKillQuery; cfg.valType = TAOS_CFG_VTYPE_INT8; @@ -1066,7 +1040,6 @@ static void doInitGlobalConfig(void) { cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "dPrecision"; @@ -1100,23 +1073,20 @@ static void doInitGlobalConfig(void) { taosAddConfigOption(cfg); assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM); #else - //assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5); + // assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5); #endif - } -void taosInitGlobalCfg() { - pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); -} +void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); } int32_t taosCheckAndPrintCfg() { - char fqdn[TSDB_FQDN_LEN]; + char fqdn[TSDB_FQDN_LEN]; uint16_t port; if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) { taosSetAllDebugFlag(); } - + if (tsLocalFqdn[0] == 0) { taosGetFqdn(tsLocalFqdn); } @@ -1143,7 +1113,7 @@ int32_t taosCheckAndPrintCfg() { if (taosDirExist(tsTempDir) != 0) { return -1; } - + taosGetSystemInfo(); tsSetLocale(); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c new file mode 100644 index 0000000000000000000000000000000000000000..b81143ee62b6a355b6ddf4a9a59b63733c62ac32 --- /dev/null +++ b/source/common/src/tmsg.c @@ -0,0 +1,254 @@ +/* + * 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 "tmsg.h" + +#undef TD_MSG_NUMBER_ +#undef TD_MSG_DICT_ +#define TD_MSG_INFO_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" + +#undef TD_MSG_NUMBER_ +#undef TD_MSG_INFO_ +#define TD_MSG_DICT_ +#undef TD_MSG_SEG_CODE_ +#include "tmsgdef.h" + +static int tmsgStartEncode(SMsgEncoder *pME); +static void tmsgEndEncode(SMsgEncoder *pME); +static int tmsgStartDecode(SMsgDecoder *pMD); +static void tmsgEndDecode(SMsgDecoder *pMD); + +/* ------------------------ ENCODE/DECODE FUNCTIONS ------------------------ */ +void tmsgInitMsgEncoder(SMsgEncoder *pME, td_endian_t endian, uint8_t *data, int64_t size) { + tInitEncoder(&(pME->coder), endian, data, size); + TD_SLIST_INIT(&(pME->eStack)); +} + +void tmsgClearMsgEncoder(SMsgEncoder *pME) { + struct SMEListNode *pNode; + for (;;) { + pNode = TD_SLIST_HEAD(&(pME->eStack)); + if (TD_IS_NULL(pNode)) break; + TD_SLIST_POP(&(pME->eStack)); + free(pNode); + } +} + +void tmsgInitMsgDecoder(SMsgDecoder *pMD, td_endian_t endian, uint8_t *data, int64_t size) { + tInitDecoder(&pMD->coder, endian, data, size); + TD_SLIST_INIT(&(pMD->dStack)); + TD_SLIST_INIT(&(pMD->freeList)); +} + +void tmsgClearMsgDecoder(SMsgDecoder *pMD) { + { + struct SMDFreeListNode *pNode; + for (;;) { + pNode = TD_SLIST_HEAD(&(pMD->freeList)); + if (TD_IS_NULL(pNode)) break; + TD_SLIST_POP(&(pMD->freeList)); + free(pNode); + } + } + { + struct SMDListNode *pNode; + for (;;) { + pNode = TD_SLIST_HEAD(&(pMD->dStack)); + if (TD_IS_NULL(pNode)) break; + TD_SLIST_POP(&(pMD->dStack)); + free(pNode); + } + } +} + +/* ------------------------ MESSAGE ENCODE/DECODE ------------------------ */ +int tmsgSVCreateTbReqEncode(SMsgEncoder *pCoder, SVCreateTbReq *pReq) { + tmsgStartEncode(pCoder); + // TODO + + tmsgEndEncode(pCoder); + return 0; +} + +int tmsgSVCreateTbReqDecode(SMsgDecoder *pCoder, SVCreateTbReq *pReq) { + tmsgStartDecode(pCoder); + + // TODO: decode + + // Decode is not end + if (pCoder->coder.pos != pCoder->coder.size) { + // Continue decode + } + + tmsgEndDecode(pCoder); + return 0; +} + +int tSerializeSVCreateTbReq(void **buf, const SVCreateTbReq *pReq) { + int tlen = 0; + + tlen += taosEncodeFixedU64(buf, pReq->ver); + tlen += taosEncodeString(buf, pReq->name); + tlen += taosEncodeFixedU32(buf, pReq->ttl); + tlen += taosEncodeFixedU32(buf, pReq->keep); + tlen += taosEncodeFixedU8(buf, pReq->type); + + switch (pReq->type) { + case TD_SUPER_TABLE: + tlen += taosEncodeFixedU64(buf, pReq->stbCfg.suid); + tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols); + for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name); + } + tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols); + for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); + } + break; + case TD_CHILD_TABLE: + tlen += taosEncodeFixedU64(buf, pReq->ctbCfg.suid); + tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag); + break; + case TD_NORMAL_TABLE: + tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols); + for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type); + tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].colId); + tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); + tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); + } + break; + default: + ASSERT(0); + } + + return tlen; +} + +void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { + buf = taosDecodeFixedU64(buf, &(pReq->ver)); + buf = taosDecodeString(buf, &(pReq->name)); + buf = taosDecodeFixedU32(buf, &(pReq->ttl)); + buf = taosDecodeFixedU32(buf, &(pReq->keep)); + buf = taosDecodeFixedU8(buf, &(pReq->type)); + + switch (pReq->type) { + case TD_SUPER_TABLE: + buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid)); + buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols)); + pReq->stbCfg.pSchema = (SSchema *)malloc(pReq->stbCfg.nCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) { + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type)); + buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId)); + buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes)); + buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name); + } + buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols); + pReq->stbCfg.pTagSchema = (SSchema *)malloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) { + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); + buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); + buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); + } + break; + case TD_CHILD_TABLE: + buf = taosDecodeFixedU64(buf, &pReq->ctbCfg.suid); + buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag); + break; + case TD_NORMAL_TABLE: + buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols); + pReq->ntbCfg.pSchema = (SSchema *)malloc(pReq->ntbCfg.nCols * sizeof(SSchema)); + for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) { + buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type); + buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); + buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); + } + break; + default: + ASSERT(0); + } + + return buf; +} + +/* ------------------------ STATIC METHODS ------------------------ */ +static int tmsgStartEncode(SMsgEncoder *pME) { + struct SMEListNode *pNode = (struct SMEListNode *)malloc(sizeof(*pNode)); + if (TD_IS_NULL(pNode)) return -1; + + pNode->coder = pME->coder; + TD_SLIST_PUSH(&(pME->eStack), pNode); + TD_CODER_MOVE_POS(&(pME->coder), sizeof(int32_t)); + + return 0; +} + +static void tmsgEndEncode(SMsgEncoder *pME) { + int32_t size; + struct SMEListNode *pNode; + + pNode = TD_SLIST_HEAD(&(pME->eStack)); + ASSERT(pNode); + TD_SLIST_POP(&(pME->eStack)); + + size = pME->coder.pos - pNode->coder.pos; + tEncodeI32(&(pNode->coder), size); + + free(pNode); +} + +static int tmsgStartDecode(SMsgDecoder *pMD) { + struct SMDListNode *pNode; + int32_t size; + + pNode = (struct SMDListNode *)malloc(sizeof(*pNode)); + if (pNode == NULL) return -1; + + tDecodeI32(&(pMD->coder), &size); + + pNode->coder = pMD->coder; + TD_SLIST_PUSH(&(pMD->dStack), pNode); + + pMD->coder.pos = 0; + pMD->coder.size = size - sizeof(int32_t); + pMD->coder.data = TD_CODER_CURRENT(&(pNode->coder)); + + return 0; +} + +static void tmsgEndDecode(SMsgDecoder *pMD) { + ASSERT(pMD->coder.pos == pMD->coder.size); + struct SMDListNode *pNode; + + pNode = TD_SLIST_HEAD(&(pMD->dStack)); + ASSERT(pNode); + TD_SLIST_POP(&(pMD->dStack)); + + pNode->coder.pos += pMD->coder.size; + + pMD->coder = pNode->coder; + + free(pNode); +} \ No newline at end of file diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 96610164836dfe32d6219cba0f068abccbe3c7b3..f8ef9f097951c346fd2147c19b70fb20dc3ab920 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -2,7 +2,7 @@ #include "tutil.h" #include "tname.h" -#include "taosmsg.h" +#include "tmsg.h" #define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T) @@ -110,7 +110,7 @@ int32_t tNameExtractFullName(const SName* name, char* dst) { return -1; } - int32_t len = snprintf(dst, TSDB_FULL_DB_NAME_LEN, "%d.%s", name->acctId, name->dbname); + int32_t len = snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname); size_t tnameLen = strlen(name->tname); if (tnameLen > 0) { @@ -134,10 +134,10 @@ int32_t tNameLen(const SName* name) { if (name->type == TSDB_DB_NAME_T) { assert(len2 == 0); - return len + len1 + TS_PATH_DELIMITER_LEN; + return len + len1 + TSDB_NAME_DELIMITER_LEN; } else { assert(len2 > 0); - return len + len1 + len2 + TS_PATH_DELIMITER_LEN * 2; + return len + len1 + len2 + TSDB_NAME_DELIMITER_LEN * 2; } } @@ -171,8 +171,7 @@ int32_t tNameGetDbName(const SName* name, char* dst) { int32_t tNameGetFullDbName(const SName* name, char* dst) { assert(name != NULL && dst != NULL); - snprintf(dst, TSDB_ACCT_ID_LEN + TS_PATH_DELIMITER_LEN + TSDB_DB_NAME_LEN, // there is a over write risk - "%d.%s", name->acctId, name->dbname); + snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname); return 0; } @@ -260,3 +259,13 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { return 0; } + +SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name) { + SSchema s = {0}; + s.type = type; + s.bytes = bytes; + s.colId = colId; + + tstrncpy(s.name, name, tListLen(s.name)); + return s; +} \ No newline at end of file diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index 8a5a300fcfb79dd6f04f1d203469ebe827bb5cc8..27f1d4947d999fa5e183b9283e82be719cb3eb01 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -16,7 +16,6 @@ #include "taos.h" #include "taosdef.h" -#include "thash.h" #include "ttime.h" #include "ttokendef.h" #include "ttypes.h" diff --git a/source/common/test/CMakeLists.txt b/source/common/test/CMakeLists.txt index f4c849780db37fed93b93d800da1a50d75af53b5..58dde913f0814750c08cccadaaeead2ed0c0d207 100644 --- a/source/common/test/CMakeLists.txt +++ b/source/common/test/CMakeLists.txt @@ -16,3 +16,13 @@ TARGET_INCLUDE_DIRECTORIES( PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/common/" PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/common/inc" ) + +# tmsg test +# add_executable(tmsgTest "") +# target_sources(tmsgTest +# PRIVATE +# "tmsgTest.cpp" +# "../src/tmsg.c" +# ) +# target_include_directories(tmsgTest PUBLIC "${CMAKE_SOURCE_DIR}/include/common/") +# target_link_libraries(tmsgTest PUBLIC os util gtest gtest_main) \ No newline at end of file diff --git a/source/common/test/tmsgTest.cpp b/source/common/test/tmsgTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca33d24a8c82c927ba3aeb9f21d833c817e85c9d --- /dev/null +++ b/source/common/test/tmsgTest.cpp @@ -0,0 +1,11 @@ +#include + +#include "gtest/gtest.h" + +#include "tmsg.h" + +TEST(td_msg_test, simple_msg_test) { + // std::cout << TMSG_INFO(TDMT_VND_DROP_TABLE) << std::endl; + // std::cout << TMSG_INFO(TDMT_MND_DROP_SUPER_TABLE) << std::endl; + // std::cout << TMSG_INFO(TDMT_MND_CREATE_SUPER_TABLE) << std::endl; +} \ No newline at end of file diff --git a/source/dnode/CMakeLists.txt b/source/dnode/CMakeLists.txt index af132dea80f2482f697bf795e05b291c797dee88..87e4c5fc4623365d5fbedd605ba485443c1fffbf 100644 --- a/source/dnode/CMakeLists.txt +++ b/source/dnode/CMakeLists.txt @@ -1,4 +1,6 @@ add_subdirectory(mnode) add_subdirectory(vnode) add_subdirectory(qnode) +add_subdirectory(snode) +add_subdirectory(bnode) add_subdirectory(mgmt) \ No newline at end of file diff --git a/source/dnode/bnode/CMakeLists.txt b/source/dnode/bnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a284437450bce68edc6142ae346022fb3bf27bb6 --- /dev/null +++ b/source/dnode/bnode/CMakeLists.txt @@ -0,0 +1,14 @@ +aux_source_directory(src BNODE_SRC) +add_library(bnode ${BNODE_SRC}) +target_include_directories( + bnode + PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/bnode" + private "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + bnode + PRIVATE transport + PRIVATE os + PRIVATE common + PRIVATE util +) \ No newline at end of file diff --git a/source/dnode/bnode/inc/bndInt.h b/source/dnode/bnode/inc/bndInt.h new file mode 100644 index 0000000000000000000000000000000000000000..d44c520a26e426bc5ea5f39441576e687bf50946 --- /dev/null +++ b/source/dnode/bnode/inc/bndInt.h @@ -0,0 +1,45 @@ +/* + * 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_BNODE_INT_H_ +#define _TD_BNODE_INT_H_ + +#include "os.h" + +#include "tarray.h" +#include "tlog.h" +#include "tmsg.h" +#include "trpc.h" + +#include "bnode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SBnode { + int32_t dnodeId; + int64_t clusterId; + SBnodeCfg cfg; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SBnode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_BNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/bnode/src/bnode.c b/source/dnode/bnode/src/bnode.c new file mode 100644 index 0000000000000000000000000000000000000000..9570bc72a0e620f79a2f50e41ab14408be90e7af --- /dev/null +++ b/source/dnode/bnode/src/bnode.c @@ -0,0 +1,29 @@ +/* + * 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 "bndInt.h" + +SBnode *bndOpen(const char *path, const SBnodeOpt *pOption) { + SBnode *pBnode = calloc(1, sizeof(SBnode)); + return pBnode; +} + +void bndClose(SBnode *pBnode) { free(pBnode); } + +int32_t bndGetLoad(SBnode *pBnode, SBnodeLoad *pLoad) { return 0; } + +int32_t bndProcessWMsgs(SBnode *pBnode, SArray *pMsgs) { return 0; } + +void bndDestroy(const char *path) {} diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index 083935c706e06abee8d07a74e9b4515350671e39..8161b8d125ebb9f9fec4762f0327e2adc3a5449f 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -139,9 +139,8 @@ void dmnWaitSignal() { void dmnInitOption(SDnodeOpt *pOption) { pOption->sver = 30000000; //3.0.0.0 pOption->numOfCores = tsNumOfCores; - pOption->numOfSupportMnodes = 1; - pOption->numOfSupportVnodes = 1; - pOption->numOfSupportQnodes = 1; + pOption->numOfSupportVnodes = tsNumOfSupportVnodes; + pOption->numOfCommitThreads = 1; pOption->statusInterval = tsStatusInterval; pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore; pOption->ratioOfQueryCores = tsRatioOfQueryCores; diff --git a/source/dnode/mgmt/impl/CMakeLists.txt b/source/dnode/mgmt/impl/CMakeLists.txt index 51131ede6a41a1f39fb07d0b490b4e56e1455cd2..866eced51a24af28f2e688d8a7e8099d1e37b7be 100644 --- a/source/dnode/mgmt/impl/CMakeLists.txt +++ b/source/dnode/mgmt/impl/CMakeLists.txt @@ -5,6 +5,9 @@ target_link_libraries( PUBLIC cjson PUBLIC mnode PUBLIC vnode + PUBLIC qnode + PUBLIC snode + PUBLIC bnode PUBLIC wal PUBLIC sync PUBLIC taos diff --git a/source/dnode/mgmt/impl/inc/dndBnode.h b/source/dnode/mgmt/impl/inc/dndBnode.h new file mode 100644 index 0000000000000000000000000000000000000000..853b54ff692009f3115e7d6a9ad4f68cbf6cb881 --- /dev/null +++ b/source/dnode/mgmt/impl/inc/dndBnode.h @@ -0,0 +1,35 @@ +/* + * 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_DND_BNODE_H_ +#define _TD_DND_BNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dndInt.h" + +int32_t dndInitBnode(SDnode *pDnode); +void dndCleanupBnode(SDnode *pDnode); + +void dndProcessBnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_BNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index 27cc99c27cb0f5206674215a107838d8a3b3a7ce..a2015913a7680789e81df4ee0e598547af755252 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -23,15 +23,16 @@ extern "C" { int32_t dndInitDnode(SDnode *pDnode); void dndCleanupDnode(SDnode *pDnode); -void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); int32_t dndGetDnodeId(SDnode *pDnode); -int32_t dndGetClusterId(SDnode *pDnode); +int64_t dndGetClusterId(SDnode *pDnode); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); -void dndSendStatusMsg(SDnode *pDnode); + +void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); +void dndSendStatusMsg(SDnode *pDnode); +void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index d8acda530ddd1733f0ba82aa0d37c578bca41bda..954e21aefa98ba9f8a14aae9ca227e7400fb8ee5 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -20,12 +20,16 @@ extern "C" { #endif -#include "cJSON.h" #include "os.h" -#include "taosmsg.h" + +#include "cJSON.h" +#include "tcache.h" +#include "tcrc32c.h" +#include "tep.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" +#include "tmsg.h" #include "tqueue.h" #include "trpc.h" #include "tthread.h" @@ -33,7 +37,11 @@ extern "C" { #include "tworker.h" #include "dnode.h" + +#include "bnode.h" #include "mnode.h" +#include "qnode.h" +#include "snode.h" #include "vnode.h" extern int32_t dDebugFlag; @@ -46,56 +54,95 @@ extern int32_t dDebugFlag; #define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat; +typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType; typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps); +typedef struct { + EWorkerType type; + const char *name; + int32_t minNum; + int32_t maxNum; + void *queueFp; + SDnode *pDnode; + taos_queue queue; + union { + SWorkerPool pool; + SMWorkerPool mpool; + }; +} SDnodeWorker; + typedef struct { char *dnode; char *mnode; + char *snode; + char *bnode; char *vnodes; } SDnodeDir; typedef struct { - int32_t dnodeId; - int32_t dropped; - int32_t clusterId; - int64_t rebootTime; - int8_t statusSent; - SEpSet mnodeEpSet; - char *file; - SHashObj *dnodeHash; - SDnodeEps *dnodeEps; - pthread_t *threadId; - SRWLatch latch; -} SDnodeMgmt; - -typedef struct { - int32_t refCount; - int8_t deployed; - int8_t dropped; - int8_t replica; - int8_t selfIndex; - SReplica replicas[TSDB_MAX_REPLICA]; + int32_t dnodeId; + int32_t dropped; + int64_t clusterId; + int64_t rebootTime; + int64_t updateTime; + int8_t statusSent; + SEpSet mnodeEpSet; char *file; - SMnode *pMnode; + SHashObj *dnodeHash; + SDnodeEps *dnodeEps; + pthread_t *threadId; SRWLatch latch; - taos_queue pReadQ; - taos_queue pWriteQ; - taos_queue pApplyQ; - taos_queue pSyncQ; taos_queue pMgmtQ; SWorkerPool mgmtPool; - SWorkerPool readPool; - SWorkerPool writePool; - SWorkerPool syncPool; +} SDnodeMgmt; + +typedef struct { + int32_t refCount; + int8_t deployed; + int8_t dropped; + SMnode *pMnode; + SRWLatch latch; + SDnodeWorker readWorker; + SDnodeWorker writeWorker; + SDnodeWorker syncWorker; + int8_t replica; + int8_t selfIndex; + SReplica replicas[TSDB_MAX_REPLICA]; } SMnodeMgmt; +typedef struct { + int32_t refCount; + int8_t deployed; + int8_t dropped; + SQnode *pQnode; + SRWLatch latch; + SDnodeWorker queryWorker; + SDnodeWorker fetchWorker; +} SQnodeMgmt; + +typedef struct { + int32_t refCount; + int8_t deployed; + int8_t dropped; + SSnode *pSnode; + SRWLatch latch; + SDnodeWorker writeWorker; +} SSnodeMgmt; + +typedef struct { + int32_t refCount; + int8_t deployed; + int8_t dropped; + SBnode *pBnode; + SRWLatch latch; + SDnodeWorker writeWorker; +} SBnodeMgmt; + typedef struct { SHashObj *hash; int32_t openVnodes; int32_t totalVnodes; SRWLatch latch; - taos_queue pMgmtQ; - SWorkerPool mgmtPool; SWorkerPool queryPool; SWorkerPool fetchPool; SMWorkerPool syncPool; @@ -105,7 +152,7 @@ typedef struct { typedef struct { void *serverRpc; void *clientRpc; - DndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; + DndMsgFp msgFp[TDMT_MAX]; } STransMgmt; typedef struct SDnode { @@ -115,6 +162,9 @@ typedef struct SDnode { FileFd lockFd; SDnodeMgmt dmgmt; SMnodeMgmt mmgmt; + SQnodeMgmt qmgmt; + SSnodeMgmt smgmt; + SBnodeMgmt bmgmt; SVnodesMgmt vmgmt; STransMgmt tmgmt; SStartupMsg startup; diff --git a/source/dnode/mgmt/impl/inc/dndMnode.h b/source/dnode/mgmt/impl/inc/dndMnode.h index 67c51e51a82340f6b61af8a4254d37f227351606..0f7cec230e8d9d6f9153c2f5a3cf27df3d833f75 100644 --- a/source/dnode/mgmt/impl/inc/dndMnode.h +++ b/source/dnode/mgmt/impl/inc/dndMnode.h @@ -23,11 +23,14 @@ extern "C" { int32_t dndInitMnode(SDnode *pDnode); void dndCleanupMnode(SDnode *pDnode); + int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); -void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/inc/dndQnode.h b/source/dnode/mgmt/impl/inc/dndQnode.h new file mode 100644 index 0000000000000000000000000000000000000000..677c234679db6cbab2103cdc487e0a22406d716c --- /dev/null +++ b/source/dnode/mgmt/impl/inc/dndQnode.h @@ -0,0 +1,36 @@ +/* + * 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_DND_QNODE_H_ +#define _TD_DND_QNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dndInt.h" + +int32_t dndInitQnode(SDnode *pDnode); +void dndCleanupQnode(SDnode *pDnode); + +void dndProcessQnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +void dndProcessQnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_QNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/inc/dndSnode.h b/source/dnode/mgmt/impl/inc/dndSnode.h new file mode 100644 index 0000000000000000000000000000000000000000..8cb883794df6b3f370278e6ba98c45f197e790fc --- /dev/null +++ b/source/dnode/mgmt/impl/inc/dndSnode.h @@ -0,0 +1,35 @@ +/* + * 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_DND_SNODE_H_ +#define _TD_DND_SNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dndInt.h" + +int32_t dndInitSnode(SDnode *pDnode); +void dndCleanupSnode(SDnode *pDnode); + +void dndProcessSnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_SNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/inc/dndVnodes.h b/source/dnode/mgmt/impl/inc/dndVnodes.h index 35f99ee73b821b17886e3626171bba21b53e5b94..bf5f0122c131e0df025665197449f82be2f7b244 100644 --- a/source/dnode/mgmt/impl/inc/dndVnodes.h +++ b/source/dnode/mgmt/impl/inc/dndVnodes.h @@ -24,12 +24,18 @@ extern "C" { int32_t dndInitVnodes(SDnode *pDnode); void dndCleanupVnodes(SDnode *pDnode); void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pVloads); -void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); +int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); +int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); +int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); +int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); +int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/impl/inc/dndWorker.h b/source/dnode/mgmt/impl/inc/dndWorker.h new file mode 100644 index 0000000000000000000000000000000000000000..49ef88e67d31e27b2968597b7c555f06128cacf3 --- /dev/null +++ b/source/dnode/mgmt/impl/inc/dndWorker.h @@ -0,0 +1,33 @@ +/* + * 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_DND_WORKER_H_ +#define _TD_DND_WORKER_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dndInt.h" + +int32_t dndInitWorker(SDnode *pDnode, SDnodeWorker *pWorker, EWorkerType type, const char *name, int32_t minNum, + int32_t maxNum, void *queueFp); +void dndCleanupWorker(SDnodeWorker *pWorker); +int32_t dndWriteMsgToWorker(SDnodeWorker *pWorker, void *pCont, int32_t contLen); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_WORKER_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c new file mode 100644 index 0000000000000000000000000000000000000000..66b619318d0690e3640668a4db6013b1b8696c9d --- /dev/null +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -0,0 +1,379 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dndBnode.h" +#include "dndDnode.h" +#include "dndTransport.h" +#include "dndWorker.h" + +static void dndProcessBnodeQueue(SDnode *pDnode, taos_qall qall, int32_t numOfMsgs); + +static SBnode *dndAcquireBnode(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + SBnode *pBnode = NULL; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pMgmt->deployed && !pMgmt->dropped) { + refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); + pBnode = pMgmt->pBnode; + } else { + terrno = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; + } + taosRUnLockLatch(&pMgmt->latch); + + if (pBnode != NULL) { + dTrace("acquire bnode, refCount:%d", refCount); + } + return pBnode; +} + +static void dndReleaseBnode(SDnode *pDnode, SBnode *pBnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pBnode != NULL) { + refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1); + } + taosRUnLockLatch(&pMgmt->latch); + + if (pBnode != NULL) { + dTrace("release bnode, refCount:%d", refCount); + } +} + +static int32_t dndReadBnodeFile(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR; + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + cJSON *root = NULL; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/bnode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "r"); + if (fp == NULL) { + dDebug("file %s not exist", file); + code = 0; + goto PRASE_BNODE_OVER; + } + + len = (int32_t)fread(content, 1, maxLen, fp); + if (len <= 0) { + dError("failed to read %s since content is null", file); + goto PRASE_BNODE_OVER; + } + + content[len] = 0; + root = cJSON_Parse(content); + if (root == NULL) { + dError("failed to read %s since invalid json format", file); + goto PRASE_BNODE_OVER; + } + + cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); + if (!deployed || deployed->type != cJSON_Number) { + dError("failed to read %s since deployed not found", file); + goto PRASE_BNODE_OVER; + } + pMgmt->deployed = deployed->valueint; + + cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); + if (!dropped || dropped->type != cJSON_Number) { + dError("failed to read %s since dropped not found", file); + goto PRASE_BNODE_OVER; + } + pMgmt->dropped = dropped->valueint; + + code = 0; + dDebug("succcessed to read file %s, deployed:%d dropped:%d", file, pMgmt->deployed, pMgmt->dropped); + +PRASE_BNODE_OVER: + if (content != NULL) free(content); + if (root != NULL) cJSON_Delete(root); + if (fp != NULL) fclose(fp); + + terrno = code; + return code; +} + +static int32_t dndWriteBnodeFile(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/bnode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "w"); + if (fp == NULL) { + terrno = TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR; + dError("failed to write %s since %s", file, terrstr()); + return -1; + } + + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + + len += snprintf(content + len, maxLen - len, "{\n"); + len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", pMgmt->deployed); + len += snprintf(content + len, maxLen - len, " \"dropped\": %d\n", pMgmt->dropped); + len += snprintf(content + len, maxLen - len, "}\n"); + + fwrite(content, 1, len, fp); + taosFsyncFile(fileno(fp)); + fclose(fp); + free(content); + + char realfile[PATH_MAX + 20]; + snprintf(realfile, PATH_MAX + 20, "%s/bnode.json", pDnode->dir.dnode); + + if (taosRenameFile(file, realfile) != 0) { + terrno = TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR; + dError("failed to rename %s since %s", file, terrstr()); + return -1; + } + + dInfo("successed to write %s, deployed:%d dropped:%d", realfile, pMgmt->deployed, pMgmt->dropped); + return 0; +} + +static int32_t dndStartBnodeWorker(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + if (dndInitWorker(pDnode, &pMgmt->writeWorker, DND_WORKER_MULTI, "bnode-write", 0, 1, dndProcessBnodeQueue) != 0) { + dError("failed to start bnode write worker since %s", terrstr()); + return -1; + } + + return 0; +} + +static void dndStopBnodeWorker(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + + taosWLockLatch(&pMgmt->latch); + pMgmt->deployed = 0; + taosWUnLockLatch(&pMgmt->latch); + + while (pMgmt->refCount > 1) { + taosMsleep(10); + } + + dndCleanupWorker(&pMgmt->writeWorker); +} + +static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { + pOption->pDnode = pDnode; + pOption->sendMsgToDnodeFp = dndSendMsgToDnode; + pOption->sendMsgToMnodeFp = dndSendMsgToMnode; + pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->dnodeId = dndGetDnodeId(pDnode); + pOption->clusterId = dndGetClusterId(pDnode); + pOption->cfg.sver = pDnode->opt.sver; +} + +static int32_t dndOpenBnode(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + SBnodeOpt option = {0}; + dndBuildBnodeOption(pDnode, &option); + + SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option); + if (pBnode == NULL) { + dError("failed to open bnode since %s", terrstr()); + return -1; + } + + if (dndStartBnodeWorker(pDnode) != 0) { + dError("failed to start bnode worker since %s", terrstr()); + bndClose(pBnode); + return -1; + } + + pMgmt->deployed = 1; + if (dndWriteBnodeFile(pDnode) != 0) { + pMgmt->deployed = 0; + dError("failed to write bnode file since %s", terrstr()); + dndStopBnodeWorker(pDnode); + bndClose(pBnode); + return -1; + } + + taosWLockLatch(&pMgmt->latch); + pMgmt->pBnode = pBnode; + taosWUnLockLatch(&pMgmt->latch); + + dInfo("bnode open successfully"); + return 0; +} + +static int32_t dndDropBnode(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode == NULL) { + dError("failed to drop bnode since %s", terrstr()); + return -1; + } + + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 1; + taosRUnLockLatch(&pMgmt->latch); + + if (dndWriteBnodeFile(pDnode) != 0) { + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 0; + taosRUnLockLatch(&pMgmt->latch); + + dndReleaseBnode(pDnode, pBnode); + dError("failed to drop bnode since %s", terrstr()); + return -1; + } + + dndReleaseBnode(pDnode, pBnode); + dndStopBnodeWorker(pDnode); + pMgmt->deployed = 0; + dndWriteBnodeFile(pDnode); + bndClose(pBnode); + pMgmt->pBnode = NULL; + bndDestroy(pDnode->dir.bnode); + + return 0; +} + +int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDCreateBnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + return -1; + } else { + return dndOpenBnode(pDnode); + } +} + +int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDDropBnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + return -1; + } else { + return dndDropBnode(pDnode); + } +} + +static void dndSendBnodeErrorRsp(SRpcMsg *pMsg, int32_t code) { + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); +} + +static void dndSendBnodeErrorRsps(taos_qall qall, int32_t numOfMsgs, int32_t code) { + for (int32_t i = 0; i < numOfMsgs; ++i) { + SRpcMsg *pMsg = NULL; + taosGetQitem(qall, (void **)&pMsg); + dndSendBnodeErrorRsp(pMsg, code); + } +} + +static void dndProcessBnodeQueue(SDnode *pDnode, taos_qall qall, int32_t numOfMsgs) { + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode == NULL) { + dndSendBnodeErrorRsps(qall, numOfMsgs, TSDB_CODE_OUT_OF_MEMORY); + return; + } + + SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *)); + if (pArray == NULL) { + dndReleaseBnode(pDnode, pBnode); + dndSendBnodeErrorRsps(qall, numOfMsgs, TSDB_CODE_OUT_OF_MEMORY); + return; + } + + for (int32_t i = 0; i < numOfMsgs; ++i) { + SRpcMsg *pMsg = NULL; + taosGetQitem(qall, (void **)&pMsg); + void *ptr = taosArrayPush(pArray, &pMsg); + if (ptr == NULL) { + dndSendBnodeErrorRsp(pMsg, TSDB_CODE_OUT_OF_MEMORY); + } + } + + bndProcessWMsgs(pBnode, pArray); + + for (size_t i = 0; i < numOfMsgs; i++) { + SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + } + taosArrayDestroy(pArray); + dndReleaseBnode(pDnode, pBnode); +} + +static void dndWriteBnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pMsg) { + int32_t code = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; + + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode != NULL) { + code = dndWriteMsgToWorker(pWorker, pMsg, sizeof(SRpcMsg)); + } + dndReleaseBnode(pDnode, pBnode); + + if (code != 0) { + if (pMsg->msgType & 1u) { + SRpcMsg rsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rsp); + } + rpcFreeCont(pMsg->pCont); + } +} + +void dndProcessBnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { + dndWriteBnodeMsgToWorker(pDnode, &pDnode->bmgmt.writeWorker, pMsg); +} + +int32_t dndInitBnode(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + taosInitRWLatch(&pMgmt->latch); + + if (dndReadBnodeFile(pDnode) != 0) { + return -1; + } + + if (pMgmt->dropped) { + dInfo("bnode has been deployed and needs to be deleted"); + bndDestroy(pDnode->dir.bnode); + return 0; + } + + if (!pMgmt->deployed) return 0; + + return dndOpenBnode(pDnode); +} + +void dndCleanupBnode(SDnode *pDnode) { + SBnodeMgmt *pMgmt = &pDnode->bmgmt; + if (pMgmt->pBnode) { + dndStopBnodeWorker(pDnode); + bndClose(pMgmt->pBnode); + pMgmt->pBnode = NULL; + } +} diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 9e2d4d4c9b00417ce0ccf91042c93d8e41a1f962..30b069f349c4e3cb3f33e31bd0d93df42df3fce2 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -15,9 +15,27 @@ #define _DEFAULT_SOURCE #include "dndDnode.h" +#include "dndBnode.h" +#include "dndMnode.h" +#include "dndQnode.h" +#include "dndSnode.h" #include "dndTransport.h" #include "dndVnodes.h" -#include "tep.h" + +static int32_t dndInitMgmtWorker(SDnode *pDnode); +static void dndCleanupMgmtWorker(SDnode *pDnode); +static int32_t dndAllocMgmtQueue(SDnode *pDnode); +static void dndFreeMgmtQueue(SDnode *pDnode); +static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg); + +static int32_t dndReadDnodes(SDnode *pDnode); +static int32_t dndWriteDnodes(SDnode *pDnode); +static void *dnodeThreadRoutine(void *param); + +static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg); +static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg); +static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg); +static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg); int32_t dndGetDnodeId(SDnode *pDnode) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; @@ -27,10 +45,10 @@ int32_t dndGetDnodeId(SDnode *pDnode) { return dnodeId; } -int32_t dndGetClusterId(SDnode *pDnode) { +int64_t dndGetClusterId(SDnode *pDnode) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; taosRLockLatch(&pMgmt->latch); - int32_t clusterId = pMgmt->clusterId; + int64_t clusterId = pMgmt->clusterId; taosRUnLockLatch(&pMgmt->latch); return clusterId; } @@ -63,12 +81,12 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { } void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { - int32_t msgType = pMsg->msgType; + tmsg_t msgType = pMsg->msgType; SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dDebug("RPC %p, msg:%s is redirected, num:%d inUse:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse); + dDebug("RPC %p, msg:%s is redirected, num:%d use:%d", pMsg->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]); if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) { @@ -82,7 +100,7 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { } static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse); + dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); SDnodeMgmt *pMgmt = &pDnode->dmgmt; taosWLockLatch(&pMgmt->latch); @@ -165,7 +183,7 @@ static int32_t dndReadDnodes(SDnode *pDnode) { int32_t code = TSDB_CODE_DND_DNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 30000; + int32_t maxLen = 256 * 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; FILE *fp = NULL; @@ -198,11 +216,11 @@ static int32_t dndReadDnodes(SDnode *pDnode) { pMgmt->dnodeId = dnodeId->valueint; cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); - if (!clusterId || clusterId->type != cJSON_Number) { + if (!clusterId || clusterId->type != cJSON_String) { dError("failed to read %s since clusterId not found", pMgmt->file); goto PRASE_DNODE_OVER; } - pMgmt->clusterId = clusterId->valueint; + pMgmt->clusterId = atoll(clusterId->valuestring); cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_Number) { @@ -217,20 +235,20 @@ static int32_t dndReadDnodes(SDnode *pDnode) { goto PRASE_DNODE_OVER; } - int32_t numOfNodes = cJSON_GetArraySize(dnodes); - if (numOfNodes <= 0) { - dError("failed to read %s since numOfNodes:%d invalid", pMgmt->file, numOfNodes); + int32_t numOfDnodes = cJSON_GetArraySize(dnodes); + if (numOfDnodes <= 0) { + dError("failed to read %s since numOfDnodes:%d invalid", pMgmt->file, numOfDnodes); goto PRASE_DNODE_OVER; } - pMgmt->dnodeEps = calloc(1, numOfNodes * sizeof(SDnodeEp) + sizeof(SDnodeEps)); + pMgmt->dnodeEps = calloc(1, numOfDnodes * sizeof(SDnodeEp) + sizeof(SDnodeEps)); if (pMgmt->dnodeEps == NULL) { dError("failed to calloc dnodeEpList since %s", strerror(errno)); goto PRASE_DNODE_OVER; } - pMgmt->dnodeEps->num = numOfNodes; + pMgmt->dnodeEps->num = numOfDnodes; - for (int32_t i = 0; i < numOfNodes; ++i) { + for (int32_t i = 0; i < numOfDnodes; ++i) { cJSON *node = cJSON_GetArrayItem(dnodes, i); if (node == NULL) break; @@ -238,28 +256,28 @@ static int32_t dndReadDnodes(SDnode *pDnode) { cJSON *dnodeId = cJSON_GetObjectItem(node, "id"); if (!dnodeId || dnodeId->type != cJSON_Number) { - dError("failed to read %s, dnodeId not found", pMgmt->file); + dError("failed to read %s since dnodeId not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->id = dnodeId->valueint; cJSON *dnodeFqdn = cJSON_GetObjectItem(node, "fqdn"); if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { - dError("failed to read %s, dnodeFqdn not found", pMgmt->file); + dError("failed to read %s since dnodeFqdn not found", pMgmt->file); goto PRASE_DNODE_OVER; } tstrncpy(pDnodeEp->fqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); cJSON *dnodePort = cJSON_GetObjectItem(node, "port"); if (!dnodePort || dnodePort->type != cJSON_Number) { - dError("failed to read %s, dnodePort not found", pMgmt->file); + dError("failed to read %s since dnodePort not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->port = dnodePort->valueint; cJSON *isMnode = cJSON_GetObjectItem(node, "isMnode"); if (!isMnode || isMnode->type != cJSON_Number) { - dError("failed to read %s, isMnode not found", pMgmt->file); + dError("failed to read %s since isMnode not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->isMnode = isMnode->valueint; @@ -282,7 +300,7 @@ PRASE_DNODE_OVER: if (pMgmt->dnodeEps == NULL) { pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp)); pMgmt->dnodeEps->num = 1; - pMgmt->dnodeEps->eps[0].isMnode = 1; + pMgmt->dnodeEps->eps[0].isMnode = 1; taosGetFqdnPortFromEp(pDnode->opt.firstEp, pMgmt->dnodeEps->eps[0].fqdn, &pMgmt->dnodeEps->eps[0].port); } @@ -303,12 +321,12 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 30000; + int32_t maxLen = 256 * 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pMgmt->dnodeId); - len += snprintf(content + len, maxLen - len, " \"clusterId\": %d,\n", pMgmt->clusterId); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pMgmt->clusterId); len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pMgmt->dropped); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n"); for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) { @@ -331,6 +349,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { free(content); terrno = 0; + pMgmt->updateTime = taosGetTimestampMs(); dInfo("successed to write %s", pMgmt->file); return 0; } @@ -348,12 +367,11 @@ void dndSendStatusMsg(SDnode *pDnode) { taosRLockLatch(&pMgmt->latch); pStatus->sver = htonl(pDnode->opt.sver); pStatus->dnodeId = htonl(pMgmt->dnodeId); - pStatus->clusterId = htonl(pMgmt->clusterId); + pStatus->clusterId = htobe64(pMgmt->clusterId); pStatus->rebootTime = htobe64(pMgmt->rebootTime); - pStatus->numOfCores = htons(pDnode->opt.numOfCores); - pStatus->numOfSupportMnodes = htons(pDnode->opt.numOfCores); - pStatus->numOfSupportVnodes = htons(pDnode->opt.numOfCores); - pStatus->numOfSupportQnodes = htons(pDnode->opt.numOfCores); + pStatus->updateTime = htobe64(pMgmt->updateTime); + pStatus->numOfCores = htonl(pDnode->opt.numOfCores); + pStatus->numOfSupportVnodes = htonl(pDnode->opt.numOfSupportVnodes); tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN); pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval); @@ -369,7 +387,7 @@ void dndSendStatusMsg(SDnode *pDnode) { dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); - SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_STATUS}; + SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527}; pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); @@ -378,13 +396,11 @@ void dndSendStatusMsg(SDnode *pDnode) { static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; - if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) { - dInfo("set dnodeId:%d clusterId:%d dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped); - + if (pMgmt->dnodeId == 0) { + dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); taosWLockLatch(&pMgmt->latch); pMgmt->dnodeId = pCfg->dnodeId; pMgmt->clusterId = pCfg->clusterId; - pMgmt->dropped = pCfg->dropped; dndWriteDnodes(pDnode); taosWUnLockLatch(&pMgmt->latch); } @@ -410,54 +426,50 @@ static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) { taosWUnLockLatch(&pMgmt->latch); } -static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { +static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; - if (pEpSet && pEpSet->numOfEps > 0) { - dndUpdateMnodeEpSet(pDnode, pEpSet); - } - if (pMsg->code != TSDB_CODE_SUCCESS) { pMgmt->statusSent = 0; + if (pMsg->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->dropped && pMgmt->dnodeId > 0) { + dInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->dnodeId); + pMgmt->dropped = 1; + dndWriteDnodes(pDnode); + } return; } SStatusRsp *pRsp = pMsg->pCont; - SDnodeCfg *pCfg = &pRsp->dnodeCfg; - pCfg->dnodeId = htonl(pCfg->dnodeId); - pCfg->clusterId = htonl(pCfg->clusterId); - dndUpdateDnodeCfg(pDnode, pCfg); - - if (pCfg->dropped) { - pMgmt->statusSent = 0; - return; - } + if (pMsg->pCont != NULL && pMsg->contLen != 0) { + SDnodeCfg *pCfg = &pRsp->dnodeCfg; + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->clusterId = htobe64(pCfg->clusterId); + dndUpdateDnodeCfg(pDnode, pCfg); + + SDnodeEps *pDnodeEps = &pRsp->dnodeEps; + pDnodeEps->num = htonl(pDnodeEps->num); + for (int32_t i = 0; i < pDnodeEps->num; ++i) { + pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id); + pDnodeEps->eps[i].port = htons(pDnodeEps->eps[i].port); + } - SDnodeEps *pDnodeEps = &pRsp->dnodeEps; - pDnodeEps->num = htonl(pDnodeEps->num); - for (int32_t i = 0; i < pDnodeEps->num; ++i) { - pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id); - pDnodeEps->eps[i].port = htons(pDnodeEps->eps[i].port); + dndUpdateDnodeEps(pDnode, pDnodeEps); } - - dndUpdateDnodeEps(pDnode, pDnodeEps); pMgmt->statusSent = 0; } -static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } +static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); } -static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } +static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); } -static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) { +static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) { dError("config msg is received, but not supported yet"); SCfgDnodeMsg *pCfg = pMsg->pCont; - int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; - rpcSendResponse(&rspMsg); + return TSDB_CODE_OPS_NOT_SUPPORT; } -static void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) { +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) { dDebug("startup msg is received"); SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg)); @@ -478,7 +490,7 @@ static void *dnodeThreadRoutine(void *param) { pthread_testcancel(); taosMsleep(ms); - if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent) { + if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) { dndSendStatusMsg(pDnode); } } @@ -491,6 +503,7 @@ int32_t dndInitDnode(SDnode *pDnode) { pMgmt->rebootTime = taosGetTimestampMs(); pMgmt->dropped = 0; pMgmt->clusterId = 0; + taosInitRWLatch(&pMgmt->latch); char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/dnode.json", pDnode->dir.dnode); @@ -512,7 +525,20 @@ int32_t dndInitDnode(SDnode *pDnode) { return -1; } - taosInitRWLatch(&pMgmt->latch); + if (pMgmt->dropped) { + dError("dnode will not start for its already dropped"); + return -1; + } + + if (dndInitMgmtWorker(pDnode) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (dndAllocMgmtQueue(pDnode) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } pMgmt->threadId = taosCreateThread(dnodeThreadRoutine, pDnode); if (pMgmt->threadId == NULL) { @@ -528,6 +554,9 @@ int32_t dndInitDnode(SDnode *pDnode) { void dndCleanupDnode(SDnode *pDnode) { SDnodeMgmt *pMgmt = &pDnode->dmgmt; + dndCleanupMgmtWorker(pDnode); + dndFreeMgmtQueue(pDnode); + if (pMgmt->threadId != NULL) { taosDestoryThread(pMgmt->threadId); pMgmt->threadId = NULL; @@ -554,39 +583,138 @@ void dndCleanupDnode(SDnode *pDnode) { dInfo("dnode-dnode is cleaned up"); } -void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - switch (pMsg->msgType) { - case TSDB_MSG_TYPE_NETWORK_TEST: - dndProcessStartupReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_CONFIG_DNODE_IN: - dndProcessConfigDnodeReq(pDnode, pMsg); - break; - default: - dError("RPC %p, dnode req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); - SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; - rpcSendResponse(&rspMsg); +static int32_t dndInitMgmtWorker(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + SWorkerPool *pPool = &pMgmt->mgmtPool; + pPool->name = "dnode-mgmt"; + pPool->min = 1; + pPool->max = 1; + if (tWorkerInit(pPool) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; + dDebug("dnode mgmt worker is initialized"); + return 0; +} + +static void dndCleanupMgmtWorker(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + tWorkerCleanup(&pMgmt->mgmtPool); + dDebug("dnode mgmt worker is closed"); } -void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { +static int32_t dndAllocMgmtQueue(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMgmtQueue); + if (pMgmt->pMgmtQ == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + return 0; +} + +static void dndFreeMgmtQueue(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ); + pMgmt->pMgmtQ = NULL; +} + +void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + + if (pEpSet && pEpSet->numOfEps > 0 && pRpcMsg->msgType == TDMT_MND_STATUS_RSP) { + dndUpdateMnodeEpSet(pDnode, pEpSet); + } + + SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg)); + if (pMsg != NULL) *pMsg = *pRpcMsg; + + if (pMsg == NULL || taosWriteQitem(pMgmt->pMgmtQ, pMsg) != 0) { + if (pRpcMsg->msgType & 1u) { + SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY}; + rpcSendResponse(&rsp); + } + rpcFreeCont(pRpcMsg->pCont); + taosFreeQitem(pMsg); + } +} + +static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { + int32_t code = 0; + switch (pMsg->msgType) { - case TSDB_MSG_TYPE_STATUS_RSP: - dndProcessStatusRsp(pDnode, pMsg, pEpSet); + case TDMT_DND_CREATE_MNODE: + code = dndProcessCreateMnodeReq(pDnode, pMsg); + break; + case TDMT_DND_ALTER_MNODE: + code = dndProcessAlterMnodeReq(pDnode, pMsg); + break; + case TDMT_DND_DROP_MNODE: + code = dndProcessDropMnodeReq(pDnode, pMsg); + break; + case TDMT_DND_CREATE_QNODE: + code = dndProcessCreateQnodeReq(pDnode, pMsg); + break; + case TDMT_DND_DROP_QNODE: + code = dndProcessDropQnodeReq(pDnode, pMsg); + break; + case TDMT_DND_CREATE_SNODE: + code = dndProcessCreateSnodeReq(pDnode, pMsg); + break; + case TDMT_DND_DROP_SNODE: + code = dndProcessDropSnodeReq(pDnode, pMsg); + break; + case TDMT_DND_CREATE_BNODE: + code = dndProcessCreateBnodeReq(pDnode, pMsg); + break; + case TDMT_DND_DROP_BNODE: + code = dndProcessDropBnodeReq(pDnode, pMsg); + break; + case TDMT_DND_CONFIG_DNODE: + code = dndProcessConfigDnodeReq(pDnode, pMsg); break; - case TSDB_MSG_TYPE_AUTH_RSP: - dndProcessAuthRsp(pDnode, pMsg, pEpSet); + case TDMT_MND_STATUS_RSP: + dndProcessStatusRsp(pDnode, pMsg); break; - case TSDB_MSG_TYPE_GRANT_RSP: - dndProcessGrantRsp(pDnode, pMsg, pEpSet); + case TDMT_MND_AUTH_RSP: + dndProcessAuthRsp(pDnode, pMsg); + break; + case TDMT_MND_GRANT_RSP: + dndProcessGrantRsp(pDnode, pMsg); + break; + case TDMT_DND_CREATE_VNODE: + code = dndProcessCreateVnodeReq(pDnode, pMsg); + break; + case TDMT_DND_ALTER_VNODE: + code = dndProcessAlterVnodeReq(pDnode, pMsg); + break; + case TDMT_DND_DROP_VNODE: + code = dndProcessDropVnodeReq(pDnode, pMsg); + break; + case TDMT_DND_AUTH_VNODE: + code = dndProcessAuthVnodeReq(pDnode, pMsg); + break; + case TDMT_DND_SYNC_VNODE: + code = dndProcessSyncVnodeReq(pDnode, pMsg); + break; + case TDMT_DND_COMPACT_VNODE: + code = dndProcessCompactVnodeReq(pDnode, pMsg); break; default: - dError("RPC %p, dnode rsp:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + code = -1; + dError("RPC %p, dnode req:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType)); + break; + } + + if (pMsg->msgType & 1u) { + if (code != 0) code = terrno; + SRpcMsg rsp = {.code = code, .handle = pMsg->handle, .ahandle = pMsg->ahandle}; + rpcSendResponse(&rsp); } rpcFreeCont(pMsg->pCont); pMsg->pCont = NULL; + taosFreeQitem(pMsg); } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 3cf08e619ea4fd80a26f739f2b1248c490c0dd43..577cb0c3b07115a1d4f3eb0932430a9671ebaa0d 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -17,54 +17,9 @@ #include "dndMnode.h" #include "dndDnode.h" #include "dndTransport.h" +#include "dndWorker.h" -static int32_t dndInitMnodeReadWorker(SDnode *pDnode); -static int32_t dndInitMnodeWriteWorker(SDnode *pDnode); -static int32_t dndInitMnodeSyncWorker(SDnode *pDnode); -static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode); -static void dndCleanupMnodeReadWorker(SDnode *pDnode); -static void dndCleanupMnodeWriteWorker(SDnode *pDnode); -static void dndCleanupMnodeSyncWorker(SDnode *pDnode); -static void dndCleanupMnodeMgmtWorker(SDnode *pDnode); -static int32_t dndAllocMnodeReadQueue(SDnode *pDnode); -static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode); -static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode); -static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode); -static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode); -static void dndFreeMnodeReadQueue(SDnode *pDnode); -static void dndFreeMnodeWriteQueue(SDnode *pDnode); -static void dndFreeMnodeApplyQueue(SDnode *pDnode); -static void dndFreeMnodeSyncQueue(SDnode *pDnode); -static void dndFreeMnodeMgmtQueue(SDnode *pDnode); - -static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg); -static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg); -static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg); -static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg); -static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg); -static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg); -void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg); - -static int32_t dndStartMnodeWorker(SDnode *pDnode); -static void dndStopMnodeWorker(SDnode *pDnode); - -static SMnode *dndAcquireMnode(SDnode *pDnode); -static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode); - -static int32_t dndReadMnodeFile(SDnode *pDnode); -static int32_t dndWriteMnodeFile(SDnode *pDnode); - -static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption); -static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption); -static int32_t dndDropMnode(SDnode *pDnode); - -static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); -static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); -static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); +static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg); static SMnode *dndAcquireMnode(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; @@ -109,49 +64,52 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { char *content = calloc(1, maxLen + 1); cJSON *root = NULL; - FILE *fp = fopen(pMgmt->file, "r"); + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/mnode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "r"); if (fp == NULL) { - dDebug("file %s not exist", pMgmt->file); + dDebug("file %s not exist", file); code = 0; goto PRASE_MNODE_OVER; } len = (int32_t)fread(content, 1, maxLen, fp); if (len <= 0) { - dError("failed to read %s since content is null", pMgmt->file); + dError("failed to read %s since content is null", file); goto PRASE_MNODE_OVER; } content[len] = 0; root = cJSON_Parse(content); if (root == NULL) { - dError("failed to read %s since invalid json format", pMgmt->file); + dError("failed to read %s since invalid json format", file); goto PRASE_MNODE_OVER; } cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); if (!deployed || deployed->type != cJSON_Number) { - dError("failed to read %s since deployed not found", pMgmt->file); + dError("failed to read %s since deployed not found", file); goto PRASE_MNODE_OVER; } pMgmt->deployed = deployed->valueint; cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_Number) { - dError("failed to read %s since dropped not found", pMgmt->file); + dError("failed to read %s since dropped not found", file); goto PRASE_MNODE_OVER; } pMgmt->dropped = dropped->valueint; cJSON *mnodes = cJSON_GetObjectItem(root, "mnodes"); if (!mnodes || mnodes->type != cJSON_Array) { - dError("failed to read %s since nodes not found", pMgmt->file); + dError("failed to read %s since nodes not found", file); goto PRASE_MNODE_OVER; } pMgmt->replica = cJSON_GetArraySize(mnodes); if (pMgmt->replica <= 0 || pMgmt->replica > TSDB_MAX_REPLICA) { - dError("failed to read %s since mnodes size %d invalid", pMgmt->file, pMgmt->replica); + dError("failed to read %s since mnodes size %d invalid", file, pMgmt->replica); goto PRASE_MNODE_OVER; } @@ -163,28 +121,28 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { cJSON *id = cJSON_GetObjectItem(node, "id"); if (!id || id->type != cJSON_Number) { - dError("failed to read %s since id not found", pMgmt->file); + dError("failed to read %s since id not found", file); goto PRASE_MNODE_OVER; } pReplica->id = id->valueint; cJSON *fqdn = cJSON_GetObjectItem(node, "fqdn"); if (!fqdn || fqdn->type != cJSON_String || fqdn->valuestring == NULL) { - dError("failed to read %s since fqdn not found", pMgmt->file); + dError("failed to read %s since fqdn not found", file); goto PRASE_MNODE_OVER; } tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN); cJSON *port = cJSON_GetObjectItem(node, "port"); if (!port || port->type != cJSON_Number) { - dError("failed to read %s since port not found", pMgmt->file); + dError("failed to read %s since port not found", file); goto PRASE_MNODE_OVER; } pReplica->port = port->valueint; } code = 0; - dDebug("succcessed to read file %s, deployed:%d dropped:%d", pMgmt->file, pMgmt->deployed, pMgmt->dropped); + dDebug("succcessed to read file %s, deployed:%d dropped:%d", file, pMgmt->deployed, pMgmt->dropped); PRASE_MNODE_OVER: if (content != NULL) free(content); @@ -198,8 +156,8 @@ PRASE_MNODE_OVER: static int32_t dndWriteMnodeFile(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - char file[PATH_MAX + 20] = {0}; - snprintf(file, sizeof(file), "%s.bak", pMgmt->file); + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/mnode.json.bak", pDnode->dir.dnode); FILE *fp = fopen(file, "w"); if (fp == NULL) { @@ -235,52 +193,36 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { fclose(fp); free(content); - if (taosRenameFile(file, pMgmt->file) != 0) { + char realfile[PATH_MAX + 20]; + snprintf(realfile, PATH_MAX + 20, "%s/mnode.json", pDnode->dir.dnode); + + if (taosRenameFile(file, realfile) != 0) { terrno = TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR; - dError("failed to rename %s since %s", pMgmt->file, terrstr()); + dError("failed to rename %s since %s", file, terrstr()); return -1; } - dInfo("successed to write %s, deployed:%d dropped:%d", pMgmt->file, pMgmt->deployed, pMgmt->dropped); + dInfo("successed to write %s, deployed:%d dropped:%d", realfile, pMgmt->deployed, pMgmt->dropped); return 0; } static int32_t dndStartMnodeWorker(SDnode *pDnode) { - if (dndInitMnodeReadWorker(pDnode) != 0) { + SMnodeMgmt *pMgmt = &pDnode->mmgmt; + if (dndInitWorker(pDnode, &pMgmt->readWorker, DND_WORKER_SINGLE, "mnode-read", 0, 1, dndProcessMnodeQueue) != 0) { dError("failed to start mnode read worker since %s", terrstr()); return -1; } - if (dndInitMnodeWriteWorker(pDnode) != 0) { + if (dndInitWorker(pDnode, &pMgmt->writeWorker, DND_WORKER_SINGLE, "mnode-write", 0, 1, dndProcessMnodeQueue) != 0) { dError("failed to start mnode write worker since %s", terrstr()); return -1; } - if (dndInitMnodeSyncWorker(pDnode) != 0) { + if (dndInitWorker(pDnode, &pMgmt->syncWorker, DND_WORKER_SINGLE, "mnode-sync", 0, 1, dndProcessMnodeQueue) != 0) { dError("failed to start mnode sync worker since %s", terrstr()); return -1; } - if (dndAllocMnodeReadQueue(pDnode) != 0) { - dError("failed to alloc mnode read queue since %s", terrstr()); - return -1; - } - - if (dndAllocMnodeWriteQueue(pDnode) != 0) { - dError("failed to alloc mnode write queue since %s", terrstr()); - return -1; - } - - if (dndAllocMnodeApplyQueue(pDnode) != 0) { - dError("failed to alloc mnode apply queue since %s", terrstr()); - return -1; - } - - if (dndAllocMnodeSyncQueue(pDnode) != 0) { - dError("failed to alloc mnode sync queue since %s", terrstr()); - return -1; - } - return 0; } @@ -291,20 +233,13 @@ static void dndStopMnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) taosMsleep(10); - while (!taosQueueEmpty(pMgmt->pReadQ)) taosMsleep(10); - while (!taosQueueEmpty(pMgmt->pApplyQ)) taosMsleep(10); - while (!taosQueueEmpty(pMgmt->pWriteQ)) taosMsleep(10); - while (!taosQueueEmpty(pMgmt->pSyncQ)) taosMsleep(10); - - dndCleanupMnodeReadWorker(pDnode); - dndCleanupMnodeWriteWorker(pDnode); - dndCleanupMnodeSyncWorker(pDnode); + while (pMgmt->refCount > 1) { + taosMsleep(10); + } - dndFreeMnodeReadQueue(pDnode); - dndFreeMnodeWriteQueue(pDnode); - dndFreeMnodeApplyQueue(pDnode); - dndFreeMnodeSyncQueue(pDnode); + dndCleanupWorker(&pMgmt->readWorker); + dndCleanupWorker(&pMgmt->writeWorker); + dndCleanupWorker(&pMgmt->syncWorker); } static bool dndNeedDeployMnode(SDnode *pDnode) { @@ -328,7 +263,6 @@ static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendRedirectMsgFp = dndSendRedirectMsg; - pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; @@ -349,7 +283,7 @@ static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) { SReplica *pReplica = &pOption->replicas[0]; pReplica->id = 1; pReplica->port = pDnode->opt.serverPort; - tstrncpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); + memcpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->selfIndex = pOption->selfIndex; @@ -365,7 +299,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) { memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); } -static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SCreateMnodeInMsg *pMsg) { +static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeMsg *pMsg) { dndInitMnodeOption(pDnode, pOption); pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); @@ -376,7 +310,7 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC SReplica *pReplica = &pOption->replicas[i]; pReplica->id = pMsg->replicas[i].id; pReplica->port = pMsg->replicas[i].port; - tstrncpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN); + memcpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN); if (pReplica->id == pOption->dnodeId) { pOption->selfIndex = i; } @@ -403,28 +337,21 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { dError("failed to open mnode since %s", terrstr()); return -1; } - pMgmt->deployed = 1; - int32_t code = dndWriteMnodeFile(pDnode); - if (code != 0) { - dError("failed to write mnode file since %s", terrstr()); - code = terrno; - pMgmt->deployed = 0; + if (dndStartMnodeWorker(pDnode) != 0) { + dError("failed to start mnode worker since %s", terrstr()); mndClose(pMnode); mndDestroy(pDnode->dir.mnode); - terrno = code; return -1; } - code = dndStartMnodeWorker(pDnode); - if (code != 0) { - dError("failed to start mnode worker since %s", terrstr()); - code = terrno; + pMgmt->deployed = 1; + if (dndWriteMnodeFile(pDnode) != 0) { + dError("failed to write mnode file since %s", terrstr()); pMgmt->deployed = 0; dndStopMnodeWorker(pDnode); mndClose(pMnode); mndDestroy(pDnode->dir.mnode); - terrno = code; return -1; } @@ -479,16 +406,19 @@ static int32_t dndDropMnode(SDnode *pDnode) { return -1; } + dndReleaseMnode(pDnode, pMnode); dndStopMnodeWorker(pDnode); + pMgmt->deployed = 0; dndWriteMnodeFile(pDnode); mndClose(pMnode); + pMgmt->pMnode = NULL; mndDestroy(pDnode->dir.mnode); return 0; } -static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) { - SCreateMnodeInMsg *pMsg = pRpcMsg->pCont; +static SDCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) { + SDCreateMnodeMsg *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); for (int32_t i = 0; i < pMsg->replica; ++i) { pMsg->replicas[i].id = htonl(pMsg->replicas[i].id); @@ -498,8 +428,8 @@ static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) { return pMsg; } -static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SCreateMnodeInMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg->pCont); +int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDCreateMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_MNODE_ID_INVALID; @@ -514,94 +444,44 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } } -static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SAlterMnodeInMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg->pCont); +int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDAlterMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_MNODE_ID_INVALID; return -1; - } else { - SMnodeOpt option = {0}; - if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) { - return -1; - } - return dndAlterMnode(pDnode, &option); } -} - -static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDropMnodeInMsg *pMsg = pRpcMsg->pCont; - pMsg->dnodeId = htonl(pMsg->dnodeId); - if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { - terrno = TSDB_CODE_DND_MNODE_ID_INVALID; + SMnodeOpt option = {0}; + if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) { return -1; - } else { - return dndDropMnode(pDnode); } -} - -static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { - int32_t code = 0; - - switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_MNODE_IN: - code = dndProcessCreateMnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_ALTER_MNODE_IN: - code = dndProcessAlterMnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_DROP_MNODE_IN: - code = dndProcessDropMnodeReq(pDnode, pMsg); - break; - default: - code = TSDB_CODE_MSG_NOT_PROCESSED; - break; - } - - if (pMsg->msgType & 1u) { - SRpcMsg rsp = {.code = code, .handle = pMsg->handle}; - rpcSendResponse(&rsp); - } - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - taosFreeQitem(pMsg); -} -static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode != NULL) { - mndProcessReadMsg(pMsg); - dndReleaseMnode(pDnode, pMnode); - } else { - mndSendRsp(pMsg, terrno); + if (dndAlterMnode(pDnode, &option) != 0) { + return -1; } - mndCleanupMsg(pMsg); + return dndWriteMnodeFile(pDnode); } -static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; +int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDDropMnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode != NULL) { - mndProcessWriteMsg(pMsg); - dndReleaseMnode(pDnode, pMnode); + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_MNODE_ID_INVALID; + return -1; } else { - mndSendRsp(pMsg, terrno); + return dndDropMnode(pDnode); } - - mndCleanupMsg(pMsg); } -static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { +static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mndProcessApplyMsg(pMsg); + mndProcessMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { mndSendRsp(pMsg, terrno); @@ -610,278 +490,43 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { mndCleanupMsg(pMsg); } -static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; +static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg) { + int32_t code = TSDB_CODE_DND_MNODE_NOT_DEPLOYED; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mndProcessSyncMsg(pMsg); - dndReleaseMnode(pDnode, pMnode); - } else { - mndSendRsp(pMsg, terrno); - } - - mndCleanupMsg(pMsg); -} - -static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) { - assert(pQueue); - - SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg); - if (pMsg == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg); + if (pMsg == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + } else { + code = dndWriteMsgToWorker(pWorker, pMsg, 0); + } - if (taosWriteQitem(pQueue, pMsg) != 0) { - mndCleanupMsg(pMsg); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + if (code != 0) { + mndCleanupMsg(pMsg); + } } + dndReleaseMnode(pDnode, pMnode); - return 0; -} - -void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SMnode *pMnode = dndAcquireMnode(pDnode); - - SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg)); - if (pMsg == NULL || taosWriteQitem(pMgmt->pMgmtQ, pMsg) != 0) { + if (code != 0) { if (pRpcMsg->msgType & 1u) { - SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY}; + SRpcMsg rsp = {.handle = pRpcMsg->handle, .ahandle = pRpcMsg->ahandle, .code = code}; rpcSendResponse(&rsp); } rpcFreeCont(pRpcMsg->pCont); - pRpcMsg->pCont = NULL; - taosFreeQitem(pMsg); } } void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pWriteQ, pMsg) != 0) { - if (pMsg->msgType & 1u) { - SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; - rpcSendResponse(&rsp); - } - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - } - - dndReleaseMnode(pDnode, pMnode); + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pMsg); } void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pSyncQ, pMsg) != 0) { - if (pMsg->msgType & 1u) { - SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; - rpcSendResponse(&rsp); - } - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - } - - dndReleaseMnode(pDnode, pMnode); + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.syncWorker, pMsg); } void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pReadQ, pMsg) != 0) { - if (pMsg->msgType & 1u) { - SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; - rpcSendResponse(&rsp); - } - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - } - - dndReleaseMnode(pDnode, pMnode); -} - -static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - - SMnode *pMnode = dndAcquireMnode(pDnode); - if (pMnode == NULL) { - return -1; - } - - int32_t code = taosWriteQitem(pMgmt->pApplyQ, pMsg); - dndReleaseMnode(pDnode, pMnode); - return code; -} - -static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue); - if (pMgmt->pMgmtQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - return 0; -} - -static void dndFreeMnodeMgmtQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ); - pMgmt->pMgmtQ = NULL; -} - -static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SWorkerPool *pPool = &pMgmt->mgmtPool; - pPool->name = "mnode-mgmt"; - pPool->min = 1; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - dDebug("mnode mgmt worker is initialized"); - return 0; -} - -static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerCleanup(&pMgmt->mgmtPool); - dDebug("mnode mgmt worker is closed"); -} - -static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, pDnode, (FProcessItem)dndProcessMnodeReadQueue); - if (pMgmt->pReadQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dndFreeMnodeReadQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->readPool, pMgmt->pReadQ); - pMgmt->pReadQ = NULL; -} - -static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SWorkerPool *pPool = &pMgmt->readPool; - pPool->name = "mnode-read"; - pPool->min = 0; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - dDebug("mnode read worker is initialized"); - return 0; -} - -static void dndCleanupMnodeReadWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerCleanup(&pMgmt->readPool); - dDebug("mnode read worker is closed"); -} - -static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeWriteQueue); - if (pMgmt->pWriteQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dndFreeMnodeWriteQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pWriteQ); - pMgmt->pWriteQ = NULL; -} - -static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue); - if (pMgmt->pApplyQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dndFreeMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pApplyQ); - pMgmt->pApplyQ = NULL; -} - -static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SWorkerPool *pPool = &pMgmt->writePool; - pPool->name = "mnode-write"; - pPool->min = 0; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - dDebug("mnode write worker is initialized"); - return 0; -} - -static void dndCleanupMnodeWriteWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerCleanup(&pMgmt->writePool); - dDebug("mnode write worker is closed"); -} - -static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, pDnode, (FProcessItem)dndProcessMnodeSyncQueue); - if (pMgmt->pSyncQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dndFreeMnodeSyncQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerFreeQueue(&pMgmt->syncPool, pMgmt->pSyncQ); - pMgmt->pSyncQ = NULL; -} - -static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - SWorkerPool *pPool = &pMgmt->syncPool; - pPool->name = "mnode-sync"; - pPool->min = 0; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - dDebug("mnode sync worker is initialized"); - return 0; -} - -static void dndCleanupMnodeSyncWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - tWorkerCleanup(&pMgmt->syncPool); - dDebug("mnode sync worker is closed"); + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.readWorker, pMsg); } int32_t dndInitMnode(SDnode *pDnode) { @@ -889,19 +534,6 @@ int32_t dndInitMnode(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; taosInitRWLatch(&pMgmt->latch); - if (dndInitMnodeMgmtWorker(pDnode) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - char path[PATH_MAX]; - snprintf(path, PATH_MAX, "%s/mnode.json", pDnode->dir.dnode); - pMgmt->file = strdup(path); - if (pMgmt->file == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - if (dndReadMnodeFile(pDnode) != 0) { return -1; } @@ -932,13 +564,13 @@ int32_t dndInitMnode(SDnode *pDnode) { } void dndCleanupMnode(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->mmgmt; - dInfo("dnode-mnode start to clean up"); - dndStopMnodeWorker(pDnode); - dndCleanupMnodeMgmtWorker(pDnode); - tfree(pMgmt->file); - mndClose(pMgmt->pMnode); + SMnodeMgmt *pMgmt = &pDnode->mmgmt; + if (pMgmt->pMnode) { + dndStopMnodeWorker(pDnode); + mndClose(pMgmt->pMnode); + pMgmt->pMnode = NULL; + } dInfo("dnode-mnode is cleaned up"); } diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c new file mode 100644 index 0000000000000000000000000000000000000000..1f3d6ee371a41279b83bc52233ab30ce369e48a8 --- /dev/null +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -0,0 +1,358 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dndQnode.h" +#include "dndDnode.h" +#include "dndTransport.h" +#include "dndWorker.h" + +static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg); + +static SQnode *dndAcquireQnode(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + SQnode *pQnode = NULL; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pMgmt->deployed && !pMgmt->dropped) { + refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); + pQnode = pMgmt->pQnode; + } else { + terrno = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; + } + taosRUnLockLatch(&pMgmt->latch); + + if (pQnode != NULL) { + dTrace("acquire qnode, refCount:%d", refCount); + } + return pQnode; +} + +static void dndReleaseQnode(SDnode *pDnode, SQnode *pQnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pQnode != NULL) { + refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1); + } + taosRUnLockLatch(&pMgmt->latch); + + if (pQnode != NULL) { + dTrace("release qnode, refCount:%d", refCount); + } +} + +static int32_t dndReadQnodeFile(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR; + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + cJSON *root = NULL; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/qnode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "r"); + if (fp == NULL) { + dDebug("file %s not exist", file); + code = 0; + goto PRASE_QNODE_OVER; + } + + len = (int32_t)fread(content, 1, maxLen, fp); + if (len <= 0) { + dError("failed to read %s since content is null", file); + goto PRASE_QNODE_OVER; + } + + content[len] = 0; + root = cJSON_Parse(content); + if (root == NULL) { + dError("failed to read %s since invalid json format", file); + goto PRASE_QNODE_OVER; + } + + cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); + if (!deployed || deployed->type != cJSON_Number) { + dError("failed to read %s since deployed not found", file); + goto PRASE_QNODE_OVER; + } + pMgmt->deployed = deployed->valueint; + + cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); + if (!dropped || dropped->type != cJSON_Number) { + dError("failed to read %s since dropped not found", file); + goto PRASE_QNODE_OVER; + } + pMgmt->dropped = dropped->valueint; + + code = 0; + dDebug("succcessed to read file %s, deployed:%d dropped:%d", file, pMgmt->deployed, pMgmt->dropped); + +PRASE_QNODE_OVER: + if (content != NULL) free(content); + if (root != NULL) cJSON_Delete(root); + if (fp != NULL) fclose(fp); + + terrno = code; + return code; +} + +static int32_t dndWriteQnodeFile(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/qnode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "w"); + if (fp == NULL) { + terrno = TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR; + dError("failed to write %s since %s", file, terrstr()); + return -1; + } + + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + + len += snprintf(content + len, maxLen - len, "{\n"); + len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", pMgmt->deployed); + len += snprintf(content + len, maxLen - len, " \"dropped\": %d\n", pMgmt->dropped); + len += snprintf(content + len, maxLen - len, "}\n"); + + fwrite(content, 1, len, fp); + taosFsyncFile(fileno(fp)); + fclose(fp); + free(content); + + char realfile[PATH_MAX + 20]; + snprintf(realfile, PATH_MAX + 20, "%s/qnode.json", pDnode->dir.dnode); + + if (taosRenameFile(file, realfile) != 0) { + terrno = TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR; + dError("failed to rename %s since %s", file, terrstr()); + return -1; + } + + dInfo("successed to write %s, deployed:%d dropped:%d", realfile, pMgmt->deployed, pMgmt->dropped); + return 0; +} + +static int32_t dndStartQnodeWorker(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + if (dndInitWorker(pDnode, &pMgmt->queryWorker, DND_WORKER_SINGLE, "qnode-query", 0, 1, dndProcessQnodeQueue) != 0) { + dError("failed to start qnode query worker since %s", terrstr()); + return -1; + } + + if (dndInitWorker(pDnode, &pMgmt->fetchWorker, DND_WORKER_SINGLE, "qnode-fetch", 0, 1, dndProcessQnodeQueue) != 0) { + dError("failed to start qnode fetch worker since %s", terrstr()); + return -1; + } + + return 0; +} + +static void dndStopQnodeWorker(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + + taosWLockLatch(&pMgmt->latch); + pMgmt->deployed = 0; + taosWUnLockLatch(&pMgmt->latch); + + while (pMgmt->refCount > 1) { + taosMsleep(10); + } + + dndCleanupWorker(&pMgmt->queryWorker); + dndCleanupWorker(&pMgmt->fetchWorker); +} + +static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { + pOption->pDnode = pDnode; + pOption->sendMsgToDnodeFp = dndSendMsgToDnode; + pOption->sendMsgToMnodeFp = dndSendMsgToMnode; + pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->dnodeId = dndGetDnodeId(pDnode); + pOption->clusterId = dndGetClusterId(pDnode); + pOption->cfg.sver = pDnode->opt.sver; +} + +static int32_t dndOpenQnode(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + SQnodeOpt option = {0}; + dndBuildQnodeOption(pDnode, &option); + + SQnode *pQnode = qndOpen(&option); + if (pQnode == NULL) { + dError("failed to open qnode since %s", terrstr()); + return -1; + } + + if (dndStartQnodeWorker(pDnode) != 0) { + dError("failed to start qnode worker since %s", terrstr()); + qndClose(pQnode); + return -1; + } + + pMgmt->deployed = 1; + if (dndWriteQnodeFile(pDnode) != 0) { + pMgmt->deployed = 0; + dError("failed to write qnode file since %s", terrstr()); + dndStopQnodeWorker(pDnode); + qndClose(pQnode); + return -1; + } + + taosWLockLatch(&pMgmt->latch); + pMgmt->pQnode = pQnode; + taosWUnLockLatch(&pMgmt->latch); + + dInfo("qnode open successfully"); + return 0; +} + +static int32_t dndDropQnode(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode == NULL) { + dError("failed to drop qnode since %s", terrstr()); + return -1; + } + + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 1; + taosRUnLockLatch(&pMgmt->latch); + + if (dndWriteQnodeFile(pDnode) != 0) { + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 0; + taosRUnLockLatch(&pMgmt->latch); + + dndReleaseQnode(pDnode, pQnode); + dError("failed to drop qnode since %s", terrstr()); + return -1; + } + + dndReleaseQnode(pDnode, pQnode); + dndStopQnodeWorker(pDnode); + pMgmt->deployed = 0; + dndWriteQnodeFile(pDnode); + qndClose(pQnode); + pMgmt->pQnode = NULL; + + return 0; +} + +int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDCreateQnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + return -1; + } else { + return dndOpenQnode(pDnode); + } +} + +int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDDropQnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + return -1; + } else { + return dndDropQnode(pDnode); + } +} + +static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + SRpcMsg *pRsp = NULL; + int32_t code = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode != NULL) { + code = qndProcessMsg(pQnode, pMsg, &pRsp); + } + + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } + + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); +} + +static void dndWriteQnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pMsg) { + int32_t code = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode != NULL) { + code = dndWriteMsgToWorker(pWorker, pMsg, sizeof(SRpcMsg)); + } + dndReleaseQnode(pDnode, pQnode); + + if (code != 0) { + if (pMsg->msgType & 1u) { + SRpcMsg rsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rsp); + } + rpcFreeCont(pMsg->pCont); + } +} + +void dndProcessQnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { + dndWriteQnodeMsgToWorker(pDnode, &pDnode->qmgmt.queryWorker, pMsg); +} + +void dndProcessQnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { + dndWriteQnodeMsgToWorker(pDnode, &pDnode->qmgmt.queryWorker, pMsg); +} + +int32_t dndInitQnode(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + taosInitRWLatch(&pMgmt->latch); + + if (dndReadQnodeFile(pDnode) != 0) { + return -1; + } + + if (pMgmt->dropped) return 0; + if (!pMgmt->deployed) return 0; + + return dndOpenQnode(pDnode); +} + +void dndCleanupQnode(SDnode *pDnode) { + SQnodeMgmt *pMgmt = &pDnode->qmgmt; + if (pMgmt->pQnode) { + dndStopQnodeWorker(pDnode); + qndClose(pMgmt->pQnode); + pMgmt->pQnode = NULL; + } +} diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c new file mode 100644 index 0000000000000000000000000000000000000000..ab4ca191a9e74d63ba7f8d441009f5c5e8f0187c --- /dev/null +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -0,0 +1,354 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dndSnode.h" +#include "dndDnode.h" +#include "dndTransport.h" +#include "dndWorker.h" + +static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg); + +static SSnode *dndAcquireSnode(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + SSnode *pSnode = NULL; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pMgmt->deployed && !pMgmt->dropped) { + refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); + pSnode = pMgmt->pSnode; + } else { + terrno = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + } + taosRUnLockLatch(&pMgmt->latch); + + if (pSnode != NULL) { + dTrace("acquire snode, refCount:%d", refCount); + } + return pSnode; +} + +static void dndReleaseSnode(SDnode *pDnode, SSnode *pSnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + int32_t refCount = 0; + + taosRLockLatch(&pMgmt->latch); + if (pSnode != NULL) { + refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1); + } + taosRUnLockLatch(&pMgmt->latch); + + if (pSnode != NULL) { + dTrace("release snode, refCount:%d", refCount); + } +} + +static int32_t dndReadSnodeFile(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR; + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + cJSON *root = NULL; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/snode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "r"); + if (fp == NULL) { + dDebug("file %s not exist", file); + code = 0; + goto PRASE_SNODE_OVER; + } + + len = (int32_t)fread(content, 1, maxLen, fp); + if (len <= 0) { + dError("failed to read %s since content is null", file); + goto PRASE_SNODE_OVER; + } + + content[len] = 0; + root = cJSON_Parse(content); + if (root == NULL) { + dError("failed to read %s since invalid json format", file); + goto PRASE_SNODE_OVER; + } + + cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); + if (!deployed || deployed->type != cJSON_Number) { + dError("failed to read %s since deployed not found", file); + goto PRASE_SNODE_OVER; + } + pMgmt->deployed = deployed->valueint; + + cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); + if (!dropped || dropped->type != cJSON_Number) { + dError("failed to read %s since dropped not found", file); + goto PRASE_SNODE_OVER; + } + pMgmt->dropped = dropped->valueint; + + code = 0; + dDebug("succcessed to read file %s, deployed:%d dropped:%d", file, pMgmt->deployed, pMgmt->dropped); + +PRASE_SNODE_OVER: + if (content != NULL) free(content); + if (root != NULL) cJSON_Delete(root); + if (fp != NULL) fclose(fp); + + terrno = code; + return code; +} + +static int32_t dndWriteSnodeFile(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + + char file[PATH_MAX + 20]; + snprintf(file, PATH_MAX + 20, "%s/snode.json", pDnode->dir.dnode); + + FILE *fp = fopen(file, "w"); + if (fp == NULL) { + terrno = TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR; + dError("failed to write %s since %s", file, terrstr()); + return -1; + } + + int32_t len = 0; + int32_t maxLen = 4096; + char *content = calloc(1, maxLen + 1); + + len += snprintf(content + len, maxLen - len, "{\n"); + len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", pMgmt->deployed); + len += snprintf(content + len, maxLen - len, " \"dropped\": %d\n", pMgmt->dropped); + len += snprintf(content + len, maxLen - len, "}\n"); + + fwrite(content, 1, len, fp); + taosFsyncFile(fileno(fp)); + fclose(fp); + free(content); + + char realfile[PATH_MAX + 20]; + snprintf(realfile, PATH_MAX + 20, "%s/snode.json", pDnode->dir.dnode); + + if (taosRenameFile(file, realfile) != 0) { + terrno = TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR; + dError("failed to rename %s since %s", file, terrstr()); + return -1; + } + + dInfo("successed to write %s, deployed:%d dropped:%d", realfile, pMgmt->deployed, pMgmt->dropped); + return 0; +} + +static int32_t dndStartSnodeWorker(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + if (dndInitWorker(pDnode, &pMgmt->writeWorker, DND_WORKER_SINGLE, "snode-write", 0, 1, dndProcessSnodeQueue) != 0) { + dError("failed to start snode write worker since %s", terrstr()); + return -1; + } + + return 0; +} + +static void dndStopSnodeWorker(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + + taosWLockLatch(&pMgmt->latch); + pMgmt->deployed = 0; + taosWUnLockLatch(&pMgmt->latch); + + while (pMgmt->refCount > 1) { + taosMsleep(10); + } + + dndCleanupWorker(&pMgmt->writeWorker); +} + +static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { + pOption->pDnode = pDnode; + pOption->sendMsgToDnodeFp = dndSendMsgToDnode; + pOption->sendMsgToMnodeFp = dndSendMsgToMnode; + pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->dnodeId = dndGetDnodeId(pDnode); + pOption->clusterId = dndGetClusterId(pDnode); + pOption->cfg.sver = pDnode->opt.sver; +} + +static int32_t dndOpenSnode(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + SSnodeOpt option = {0}; + dndBuildSnodeOption(pDnode, &option); + + SSnode *pSnode = sndOpen(pDnode->dir.snode, &option); + if (pSnode == NULL) { + dError("failed to open snode since %s", terrstr()); + return -1; + } + + if (dndStartSnodeWorker(pDnode) != 0) { + dError("failed to start snode worker since %s", terrstr()); + sndClose(pSnode); + return -1; + } + + pMgmt->deployed = 1; + if (dndWriteSnodeFile(pDnode) != 0) { + pMgmt->deployed = 0; + dError("failed to write snode file since %s", terrstr()); + dndStopSnodeWorker(pDnode); + sndClose(pSnode); + return -1; + } + + taosWLockLatch(&pMgmt->latch); + pMgmt->pSnode = pSnode; + taosWUnLockLatch(&pMgmt->latch); + + dInfo("snode open successfully"); + return 0; +} + +static int32_t dndDropSnode(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode == NULL) { + dError("failed to drop snode since %s", terrstr()); + return -1; + } + + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 1; + taosRUnLockLatch(&pMgmt->latch); + + if (dndWriteSnodeFile(pDnode) != 0) { + taosRLockLatch(&pMgmt->latch); + pMgmt->dropped = 0; + taosRUnLockLatch(&pMgmt->latch); + + dndReleaseSnode(pDnode, pSnode); + dError("failed to drop snode since %s", terrstr()); + return -1; + } + + dndReleaseSnode(pDnode, pSnode); + dndStopSnodeWorker(pDnode); + pMgmt->deployed = 0; + dndWriteSnodeFile(pDnode); + sndClose(pSnode); + pMgmt->pSnode = NULL; + sndDestroy(pDnode->dir.snode); + + return 0; +} + +int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDCreateSnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + return -1; + } else { + return dndOpenSnode(pDnode); + } +} + +int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { + SDDropSnodeMsg *pMsg = pRpcMsg->pCont; + pMsg->dnodeId = htonl(pMsg->dnodeId); + + if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { + terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + return -1; + } else { + return dndDropSnode(pDnode); + } +} + +static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + SRpcMsg *pRsp = NULL; + int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode != NULL) { + code = sndProcessMsg(pSnode, pMsg, &pRsp); + } + + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } + + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); +} + +static void dndWriteSnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pMsg) { + int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode != NULL) { + code = dndWriteMsgToWorker(pWorker, pMsg, sizeof(SRpcMsg)); + } + dndReleaseSnode(pDnode, pSnode); + + if (code != 0) { + if (pMsg->msgType & 1u) { + SRpcMsg rsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rsp); + } + rpcFreeCont(pMsg->pCont); + } +} + +void dndProcessSnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { + dndWriteSnodeMsgToWorker(pDnode, &pDnode->smgmt.writeWorker, pMsg); +} + +int32_t dndInitSnode(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + taosInitRWLatch(&pMgmt->latch); + + if (dndReadSnodeFile(pDnode) != 0) { + return -1; + } + + if (pMgmt->dropped) { + dInfo("snode has been deployed and needs to be deleted"); + sndDestroy(pDnode->dir.snode); + return 0; + } + + if (!pMgmt->deployed) return 0; + + return dndOpenSnode(pDnode); +} + +void dndCleanupSnode(SDnode *pDnode) { + SSnodeMgmt *pMgmt = &pDnode->smgmt; + if (pMgmt->pSnode) { + dndStopSnodeWorker(pDnode); + sndClose(pMgmt->pSnode); + pMgmt->pSnode = NULL; + } +} diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index f8556c3e207baf7c6dabdfa0e46420410005331a..e5be16937bb4bc5eb909eba8cccf4f94ac2578c6 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -30,119 +30,140 @@ #define INTERNAL_SECRET "_secret" static void dndInitMsgFp(STransMgmt *pMgmt) { - // msg from client to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_SUBMIT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_FETCH] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_MQ_SET_CUR] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_RES_READY] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_TASKS_STATUS] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CANCEL_TASK] = dndProcessVnodeFetchMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TASK] = dndProcessVnodeFetchMsg; - - // msg from client to mnode - pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_ACCT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_USER] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_USE_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_DB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_RETRIEVE_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_VGROUP_LIST] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SHOW] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = dndProcessMnodeReadMsg; - - // message from client to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dndProcessDnodeReq; - - // message from mnode to vnode - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN_RSP] = dndProcessMnodeWriteMsg; - - // message from mnode to dnode - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = dndProcessVnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = dndProcessMnodeMgmtMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = dndProcessDnodeReq; - pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dndProcessMnodeWriteMsg; - - // message from dnode to mnode - pMgmt->msgFp[TSDB_MSG_TYPE_GRANT] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TSDB_MSG_TYPE_STATUS] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dndProcessDnodeRsp; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH] = dndProcessMnodeReadMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dndProcessDnodeRsp; + // Requests handled by DNODE + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_MNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_QNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_QNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_QNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_QNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_SNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_SNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_SNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_SNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_BNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_BNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_BNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_BNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_SYNC_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_SYNC_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_AUTH_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_AUTH_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_COMPACT_VNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_COMPACT_VNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CONFIG_DNODE)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CONFIG_DNODE_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_DND_NETWORK_TEST)] = dndProcessMgmtMsg; + + // Requests handled by MNODE + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONNECT)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_ACCT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_USER)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONFIG_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_MNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_MNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_QNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_QNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_SNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_SNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_BNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_BNODE)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_USE_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SYNC_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_COMPACT_DB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_FUNCTION)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_STB)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STB_META)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_VGROUP_LIST)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_KILL_QUERY)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_KILL_CONN)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_HEARTBEAT)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH_RSP)] = dndProcessMgmtMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_TOPIC)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_TOPIC)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_TOPIC)] = dndProcessMnodeWriteMsg; + + // Requests handled by VNODE + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SUBMIT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_QUERY)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONSUME)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_QUERY)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONNECT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_DISCONNECT)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CUR)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_RES_READY)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TASKS_STATUS)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CANCEL_TASK)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TASK)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_STB_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_STB_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_STB)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_STB_RSP)] = dndProcessMnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TABLE)] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = dndProcessVnodeFetchMsg; } static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnode *pDnode = parent; STransMgmt *pMgmt = &pDnode->tmgmt; - int32_t msgType = pMsg->msgType; + tmsg_t msgType = pMsg->msgType; if (dndGetStat(pDnode) == DND_STAT_STOPPED) { if (pMsg == NULL || pMsg->pCont == NULL) return; - dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]); + dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); return; } - DndMsgFp fp = pMgmt->msgFp[msgType]; + DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { (*fp)(pDnode, pMsg, pEpSet); - dTrace("RPC %p, rsp:%s is processed, code:0x%0X", pMsg->handle, taosMsg[msgType], pMsg->code & 0XFFFF); + dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); } else { - dError("RPC %p, rsp:%s not processed", pMsg->handle, taosMsg[msgType]); + dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); } } @@ -186,21 +207,21 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnode *pDnode = param; STransMgmt *pMgmt = &pDnode->tmgmt; - int32_t msgType = pMsg->msgType; - if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { - dTrace("RPC %p, network test req, app:%p will be processed", pMsg->handle, pMsg->ahandle); - dndProcessDnodeReq(pDnode, pMsg, pEpSet); + tmsg_t msgType = pMsg->msgType; + if (msgType == TDMT_DND_NETWORK_TEST) { + dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pMsg->handle, pMsg->ahandle, pMsg->code); + dndProcessStartupReq(pDnode, pMsg); return; } if (dndGetStat(pDnode) == DND_STAT_STOPPED) { - dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); return; } else if (dndGetStat(pDnode) != DND_STAT_RUNNING) { - dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); @@ -208,18 +229,19 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { } if (pMsg->pCont == NULL) { - dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, TMSG_INFO(msgType), + pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN}; rpcSendResponse(&rspMsg); return; } - DndMsgFp fp = pMgmt->msgFp[msgType]; + DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { - dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); (*fp)(pDnode, pMsg, pEpSet); } else { - dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, taosMsg[msgType], pMsg->ahandle); + dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); @@ -281,7 +303,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); tstrncpy(pMsg->user, user, TSDB_USER_LEN); - SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TSDB_MSG_TYPE_AUTH}; + SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TDMT_MND_AUTH}; SRpcMsg rpcRsp = {0}; dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); @@ -363,6 +385,7 @@ void dndCleanupTrans(SDnode *pDnode) { void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { STransMgmt *pMgmt = &pDnode->tmgmt; + if (pMgmt->clientRpc == NULL) return; rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL); } diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index 598d6e47bed1987587dbc7fcc9dff25df68457dc..3eab3e5aec734dc1993bcd37b745529204b1e562 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -22,7 +22,7 @@ typedef struct { int32_t vgVersion; int8_t dropped; uint64_t dbUid; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; char path[PATH_MAX + 20]; } SWrapperCfg; @@ -56,11 +56,9 @@ typedef struct { static int32_t dndInitVnodeReadWorker(SDnode *pDnode); static int32_t dndInitVnodeWriteWorker(SDnode *pDnode); static int32_t dndInitVnodeSyncWorker(SDnode *pDnode); -static int32_t dndInitVnodeMgmtWorker(SDnode *pDnode); static void dndCleanupVnodeReadWorker(SDnode *pDnode); static void dndCleanupVnodeWriteWorker(SDnode *pDnode); static void dndCleanupVnodeSyncWorker(SDnode *pDnode); -static void dndCleanupVnodeMgmtWorker(SDnode *pDnode); static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode); static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode); static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode); @@ -77,12 +75,10 @@ static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg); static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs); static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs); static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs); -static void dndProcessVnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg); void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg); static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId); @@ -96,13 +92,6 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode); static int32_t dndOpenVnodes(SDnode *pDnode); static void dndCloseVnodes(SDnode *pDnode); -static int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); -static int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); -static int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); -static int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); -static int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); -static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); - static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) { SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodeObj *pVnode = NULL; @@ -330,7 +319,7 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SWrapperCfg **ppCfgs, int32_ dError("failed to read %s since db not found", file); goto PRASE_VNODE_OVER; } - tstrncpy(pCfg->db, db->valuestring, TSDB_FULL_DB_NAME_LEN); + tstrncpy(pCfg->db, db->valuestring, TSDB_DB_FNAME_LEN); } *ppCfgs = pCfgs; @@ -580,7 +569,7 @@ static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) { } static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWrapperCfg *pCfg) { - memcpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN); + memcpy(pCfg->db, pCreate->db, TSDB_DB_FNAME_LEN); pCfg->dbUid = pCreate->dbUid; pCfg->dropped = 0; snprintf(pCfg->path, sizeof(pCfg->path), "%s/vnode%d", pDnode->dir.vnodes, pCreate->vgId); @@ -600,7 +589,7 @@ static SAuthVnodeMsg *vnodeParseAuthVnodeReq(SRpcMsg *rpcMsg) { return pAuth; } -static int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SCreateVnodeMsg *pCreate = dndParseCreateVnodeReq(rpcMsg); dDebug("vgId:%d, create vnode req is received", pCreate->vgId); @@ -641,7 +630,7 @@ static int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return 0; } -static int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SAlterVnodeMsg *pAlter = (SAlterVnodeMsg *)dndParseCreateVnodeReq(rpcMsg); dDebug("vgId:%d, alter vnode req is received", pAlter->vgId); @@ -680,7 +669,7 @@ static int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return code; } -static int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SDropVnodeMsg *pDrop = vnodeParseDropVnodeReq(rpcMsg); int32_t vgId = pDrop->vgId; @@ -707,7 +696,7 @@ static int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return 0; } -static int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg); int32_t code = 0; @@ -725,7 +714,7 @@ static int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return 0; } -static int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg); int32_t vgId = pAuth->vgId; @@ -747,7 +736,7 @@ static int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return 0; } -static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { +int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { SCompactVnodeMsg *pCompact = (SCompactVnodeMsg *)vnodeParseDropVnodeReq(rpcMsg); int32_t vgId = pCompact->vgId; @@ -769,39 +758,6 @@ static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) { return 0; } -static void dndProcessVnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { - int32_t code = 0; - - switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_VNODE_IN: - code = dndProcessCreateVnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_ALTER_VNODE_IN: - code = dndProcessAlterVnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_DROP_VNODE_IN: - code = dndProcessDropVnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_AUTH_VNODE_IN: - code = dndProcessAuthVnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_SYNC_VNODE_IN: - code = dndProcessSyncVnodeReq(pDnode, pMsg); - break; - case TSDB_MSG_TYPE_COMPACT_VNODE_IN: - code = dndProcessCompactVnodeReq(pDnode, pMsg); - break; - default: - code = TSDB_CODE_MSG_NOT_PROCESSED; - break; - } - - SRpcMsg rsp = {.code = code, .handle = pMsg->handle, .ahandle = pMsg->ahandle}; - rpcSendResponse(&rsp); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); -} - static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg) { SRpcMsg *pRsp = NULL; vnodeProcessQueryReq(pVnode->pImpl, pMsg, &pRsp); @@ -829,6 +785,7 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp); if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; rpcSendResponse(pRsp); free(pRsp); } else { @@ -908,11 +865,6 @@ static SVnodeObj *dndAcquireVnodeFromMsg(SDnode *pDnode, SRpcMsg *pMsg) { return pVnode; } -void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SVnodesMgmt *pMgmt = &pDnode->vmgmt; - dndWriteRpcMsgToVnodeQueue(pMgmt->pMgmtQ, pMsg); -} - void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { SVnodeObj *pVnode = dndAcquireVnodeFromMsg(pDnode, pMsg); if (pVnode != NULL) { @@ -956,35 +908,6 @@ static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMs return code; } -static int32_t dndInitVnodeMgmtWorker(SDnode *pDnode) { - SVnodesMgmt *pMgmt = &pDnode->vmgmt; - SWorkerPool *pPool = &pMgmt->mgmtPool; - pPool->name = "vnode-mgmt"; - pPool->min = 1; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - pMgmt->pMgmtQ = tWorkerAllocQueue(pPool, pDnode, (FProcessItem)dndProcessVnodeMgmtQueue); - if (pMgmt->pMgmtQ == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - dDebug("vnode mgmt worker is initialized"); - return 0; -} - -static void dndCleanupVnodeMgmtWorker(SDnode *pDnode) { - SVnodesMgmt *pMgmt = &pDnode->vmgmt; - tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ); - tWorkerCleanup(&pMgmt->mgmtPool); - pMgmt->pMgmtQ = NULL; - dDebug("vnode mgmt worker is closed"); -} - static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) { SVnodesMgmt *pMgmt = &pDnode->vmgmt; pVnode->pQueryQ = tWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FProcessItem)dndProcessVnodeQueryQueue); @@ -1166,11 +1089,6 @@ int32_t dndInitVnodes(SDnode *pDnode) { return -1; } - if (dndInitVnodeMgmtWorker(pDnode) != 0) { - dError("failed to init vnodes mgmt worker since %s", terrstr()); - return -1; - } - if (dndOpenVnodes(pDnode) != 0) { dError("failed to open vnodes since %s", terrstr()); return -1; @@ -1186,7 +1104,6 @@ void dndCleanupVnodes(SDnode *pDnode) { dndCleanupVnodeReadWorker(pDnode); dndCleanupVnodeWriteWorker(pDnode); dndCleanupVnodeSyncWorker(pDnode); - dndCleanupVnodeMgmtWorker(pDnode); dInfo("dnode-vnodes is cleaned up"); } diff --git a/source/dnode/mgmt/impl/src/dndWorker.c b/source/dnode/mgmt/impl/src/dndWorker.c new file mode 100644 index 0000000000000000000000000000000000000000..b1107fd185059de390ffb04daf5331dd26d68c23 --- /dev/null +++ b/source/dnode/mgmt/impl/src/dndWorker.c @@ -0,0 +1,110 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dndWorker.h" + +int32_t dndInitWorker(SDnode *pDnode, SDnodeWorker *pWorker, EWorkerType type, const char *name, int32_t minNum, + int32_t maxNum, void *queueFp) { + if (pDnode == NULL || pWorker == NULL || name == NULL || minNum < 0 || maxNum <= 0 || queueFp == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } + + pWorker->type = type; + pWorker->name = name; + pWorker->minNum = minNum; + pWorker->maxNum = maxNum; + pWorker->queueFp = queueFp; + pWorker->pDnode = pDnode; + + if (pWorker->type == DND_WORKER_SINGLE) { + SWorkerPool *pPool = &pWorker->pool; + pPool->name = name; + pPool->min = minNum; + pPool->max = maxNum; + if (tWorkerInit(pPool) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pWorker->queue = tWorkerAllocQueue(pPool, pDnode, (FProcessItem)queueFp); + if (pWorker->queue == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + } else if (pWorker->type == DND_WORKER_MULTI) { + SMWorkerPool *pPool = &pWorker->mpool; + pPool->name = name; + pPool->max = maxNum; + if (tMWorkerInit(pPool) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pWorker->queue = tMWorkerAllocQueue(pPool, pDnode, (FProcessItems)queueFp); + if (pWorker->queue == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + } else { + terrno = TSDB_CODE_INVALID_PARA; + } + + return 0; +} + +void dndCleanupWorker(SDnodeWorker *pWorker) { + while (!taosQueueEmpty(pWorker->queue)) { + taosMsleep(10); + } + + if (pWorker->type == DND_WORKER_SINGLE) { + tWorkerCleanup(&pWorker->pool); + tWorkerFreeQueue(&pWorker->pool, pWorker->queue); + } else if (pWorker->type == DND_WORKER_MULTI) { + tMWorkerCleanup(&pWorker->mpool); + tMWorkerFreeQueue(&pWorker->mpool, pWorker->queue); + } else { + } +} + +int32_t dndWriteMsgToWorker(SDnodeWorker *pWorker, void *pCont, int32_t contLen) { + if (pWorker == NULL || pWorker->queue == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } + + void *pMsg = NULL; + if (contLen != 0) { + pMsg = taosAllocateQitem(contLen); + if (pMsg != NULL) { + memcpy(pMsg, pCont, contLen); + } + } else { + pMsg = pCont; + } + + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (taosWriteQitem(pWorker->queue, pMsg) != 0) { + taosFreeQitem(pMsg); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index a4996ecb3bfc0792add96700c51c4b83dcf6d80e..88a96dadc4bd50f04c45c5960334b63bd211e422 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -19,8 +19,6 @@ #include "dndTransport.h" #include "dndVnodes.h" #include "sync.h" -#include "tcache.h" -#include "tcrc32c.h" #include "wal.h" EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; } @@ -86,12 +84,14 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOption) { char path[PATH_MAX + 100]; snprintf(path, sizeof(path), "%s%smnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.mnode = tstrdup(path); - snprintf(path, sizeof(path), "%s%svnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.vnodes = tstrdup(path); - snprintf(path, sizeof(path), "%s%sdnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.dnode = tstrdup(path); + snprintf(path, sizeof(path), "%s%ssnode", pOption->dataDir, TD_DIRSEP); + pDnode->dir.snode = tstrdup(path); + snprintf(path, sizeof(path), "%s%sbnode", pOption->dataDir, TD_DIRSEP); + pDnode->dir.bnode = tstrdup(path); if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL) { dError("failed to malloc dir object"); @@ -117,22 +117,28 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOption) { return -1; } + if (taosMkDir(pDnode->dir.snode) != 0) { + dError("failed to create dir:%s since %s", pDnode->dir.snode, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (taosMkDir(pDnode->dir.bnode) != 0) { + dError("failed to create dir:%s since %s", pDnode->dir.bnode, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + memcpy(&pDnode->opt, pOption, sizeof(SDnodeOpt)); return 0; } static void dndCleanupEnv(SDnode *pDnode) { - if (pDnode->dir.mnode != NULL) { - tfree(pDnode->dir.mnode); - } - - if (pDnode->dir.vnodes != NULL) { - tfree(pDnode->dir.vnodes); - } - - if (pDnode->dir.dnode != NULL) { - tfree(pDnode->dir.dnode); - } + tfree(pDnode->dir.mnode); + tfree(pDnode->dir.vnodes); + tfree(pDnode->dir.dnode); + tfree(pDnode->dir.snode); + tfree(pDnode->dir.bnode); if (pDnode->lockFd >= 0) { taosUnLockFile(pDnode->lockFd); @@ -176,7 +182,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { return NULL; } - if (vnodeInit(1) != 0) { + if (vnodeInit(pDnode->opt.numOfCommitThreads) != 0) { dError("failed to init vnode env"); dndCleanup(pDnode); return NULL; diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index a29926c8026950028690bf3d07fa224ee1dd5084..b0596bed08df617db6510da4c2ba773c9660b0d7 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -7,7 +7,10 @@ add_subdirectory(cluster) add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) -# add_subdirectory(mnode) +add_subdirectory(mnode) +add_subdirectory(qnode) +add_subdirectory(snode) +add_subdirectory(bnode) add_subdirectory(profile) add_subdirectory(show) add_subdirectory(stb) diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mgmt/impl/test/acct/acct.cpp index 69ddae675d12e353a610769592565b18d0078ada..be0ad4ab0f544ce0435468eecede11264e7d6406 100644 --- a/source/dnode/mgmt/impl/test/acct/acct.cpp +++ b/source/dnode/mgmt/impl/test/acct/acct.cpp @@ -30,7 +30,7 @@ TEST_F(DndTestAcct, 01_CreateAcct) { SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -40,7 +40,7 @@ TEST_F(DndTestAcct, 02_AlterAcct) { SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -50,7 +50,7 @@ TEST_F(DndTestAcct, 03_DropAcct) { SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_ACCT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } @@ -61,7 +61,7 @@ TEST_F(DndTestAcct, 04_ShowAcct) { SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); pReq->type = TSDB_MGMT_TABLE_ACCT; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea769a701c4136b9839445154abb413f7e10b594 --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. STEST_SRC) +add_executable(dnode_test_bnode ${STEST_SRC}) +target_link_libraries( + dnode_test_bnode + PUBLIC sut +) + +add_test( + NAME dnode_test_bnode + COMMAND dnode_test_bnode +) diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1a85522c45da91268b4a5617ea53f2b87612af3 --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/bnode.cpp @@ -0,0 +1,154 @@ +/** + * @file dnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module dnode-msg tests + * @version 0.1 + * @date 2021-12-15 + * + * @copyright Copyright (c) 2021 + * + */ + +#include "base.h" + +class DndTestBnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/dnode_test_bnode1", 9068); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9068"; + + server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase DndTestBnode::test; +TestServer DndTestBnode::server2; + +TEST_F(DndTestBnode, 01_ShowBnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + CHECK_META("show bnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + CHECK_META("show bnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckTimestamp(); + } +} + +TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } +} + +TEST_F(DndTestBnode, 04_Create_Bnode) { + { + // create dnode + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9069); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + taosMsleep(1300); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + // create bnode + int32_t contLen = sizeof(SMCreateBnodeMsg); + + SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckBinary("localhost:9069", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + // drop bnode + int32_t contLen = sizeof(SMDropBnodeMsg); + + SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9068", TSDB_EP_LEN); + CheckTimestamp(); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp index 7230c3eb74ca2e0cb08454f1f170b046918c4cc7..773482678977a7096b5469d141fa21d2568dae25 100644 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ b/source/dnode/mgmt/impl/test/cluster/cluster.cpp @@ -28,14 +28,14 @@ Testbase DndTestCluster::test; TEST_F(DndTestCluster, 01_ShowCluster) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); CHECK_META( "show cluster", 3); - CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "id"); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); - IgnoreInt32(); + IgnoreInt64(); IgnoreBinary(TSDB_CLUSTER_ID_LEN); CheckTimestamp(); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 378f46aa4defe07fa739b170b3cf04f442d99d60..5c67c10817547cb5d81666afa402238b6397c960 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -27,24 +27,25 @@ Testbase DndTestDb::test; TEST_F(DndTestDb, 01_ShowDb) { test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups"); - CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); - CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); - CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "days"); - CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); - CHECK_SCHEMA(7, TSDB_DATA_TYPE_INT, 4, "cache"); - CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "blocks"); - CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "minrows"); - CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "maxrows"); - CHECK_SCHEMA(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); - CHECK_SCHEMA(12, TSDB_DATA_TYPE_INT, 4, "fsync"); - CHECK_SCHEMA(13, TSDB_DATA_TYPE_TINYINT, 1, "comp"); - CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); - CHECK_SCHEMA(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); - CHECK_SCHEMA(16, TSDB_DATA_TYPE_TINYINT, 1, "update"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "ntables"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_SMALLINT, 2, "days"); + CHECK_SCHEMA(7, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); + CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "cache"); + CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "blocks"); + CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "minrows"); + CHECK_SCHEMA(11, TSDB_DATA_TYPE_INT, 4, "maxrows"); + CHECK_SCHEMA(12, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); + CHECK_SCHEMA(13, TSDB_DATA_TYPE_INT, 4, "fsync"); + CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "comp"); + CHECK_SCHEMA(15, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); + CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); + CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update"); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 0); @@ -76,19 +77,20 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); // ntables CheckInt16(1); // replica CheckInt16(1); // quorum CheckInt16(10); // days @@ -136,7 +138,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->quorum = 2; pReq->cacheLastRow = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -147,6 +149,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); CheckInt16(1); // replica CheckInt16(2); // quorum CheckInt16(10); // days @@ -166,7 +169,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { test.Restart(); test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -174,6 +177,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups + CheckInt32(0); CheckInt16(1); // replica CheckInt16(2); // quorum CheckInt16(10); // days @@ -195,13 +199,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 0); @@ -233,13 +237,13 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - CHECK_META("show databases", 17); + CHECK_META("show databases", 18); test.SendShowRetrieveMsg(); EXPECT_EQ(test.GetShowRows(), 1); @@ -252,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { strcpy(pReq->db, "1.d2"); pReq->vgVersion = htonl(-1); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_USE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_USE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index c9708ec1cfcb8fdec5ddf10cd63918100187c010..54d7e73be6542d8391dfdfddaf5f3f7857a7db1d 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -57,7 +57,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) { CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes"); - CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "support_vnodes"); CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status"); CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); @@ -68,7 +68,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) { CheckInt16(1); CheckBinary("localhost:9041", TSDB_EP_LEN); CheckInt16(0); - CheckInt16(1); + CheckInt16(16); CheckBinary("ready", 10); CheckTimestamp(); CheckBinary("", 24); @@ -81,7 +81,7 @@ TEST_F(DndTestDnode, 02_ConfigDnode) { pReq->dnodeId = htonl(1); strcpy(pReq->config, "ddebugflag 131"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONFIG_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -91,9 +91,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->ep, "localhost:9042"); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9042); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -111,8 +112,8 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckBinary("localhost:9042", TSDB_EP_LEN); CheckInt16(0); CheckInt16(0); - CheckInt16(1); - CheckInt16(1); + CheckInt16(16); + CheckInt16(16); CheckBinary("ready", 10); CheckBinary("ready", 10); CheckTimestamp(); @@ -126,7 +127,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -139,7 +140,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckInt16(1); CheckBinary("localhost:9041", TSDB_EP_LEN); CheckInt16(0); - CheckInt16(1); + CheckInt16(16); CheckBinary("ready", 10); CheckTimestamp(); CheckBinary("", 24); @@ -148,9 +149,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->ep, "localhost:9043"); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9043); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -159,9 +161,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->ep, "localhost:9044"); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9044); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -170,9 +173,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { int32_t contLen = sizeof(SCreateDnodeMsg); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->ep, "localhost:9045"); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9045); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -195,10 +199,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckInt16(0); CheckInt16(0); CheckInt16(0); - CheckInt16(1); - CheckInt16(1); - CheckInt16(1); - CheckInt16(1); + CheckInt16(16); + CheckInt16(16); + CheckInt16(16); + CheckInt16(16); CheckBinary("ready", 10); CheckBinary("ready", 10); CheckBinary("ready", 10); @@ -238,10 +242,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckInt16(0); CheckInt16(0); CheckInt16(0); - CheckInt16(1); - CheckInt16(1); - CheckInt16(1); - CheckInt16(1); + CheckInt16(16); + CheckInt16(16); + CheckInt16(16); + CheckInt16(16); CheckBinary("ready", 10); CheckBinary("ready", 10); CheckBinary("ready", 10); diff --git a/source/dnode/mgmt/impl/test/mnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/mnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6b3b16fb68743aa3c9503fcdc83369ab433c953 --- /dev/null +++ b/source/dnode/mgmt/impl/test/mnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. MTEST_SRC) +add_executable(dnode_test_mnode ${MTEST_SRC}) +target_link_libraries( + dnode_test_mnode + PUBLIC sut +) + +add_test( + NAME dnode_test_mnode + COMMAND dnode_test_mnode +) diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9b1ef45bdd419f17aa97b0f60cb43d9837efebe --- /dev/null +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -0,0 +1,301 @@ +/** + * @file dnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module dnode-msg tests + * @version 0.1 + * @date 2021-12-15 + * + * @copyright Copyright (c) 2021 + * + */ + +#include "base.h" + +class DndTestMnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/dnode_test_mnode1", 9061); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9061"; + + server2.Start("/tmp/dnode_test_mnode2", fqdn, 9062, firstEp); + server3.Start("/tmp/dnode_test_mnode3", fqdn, 9063, firstEp); + server4.Start("/tmp/dnode_test_mnode4", fqdn, 9064, firstEp); + server5.Start("/tmp/dnode_test_mnode5", fqdn, 9065, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + server3.Stop(); + server4.Stop(); + server5.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; + static TestServer server3; + static TestServer server4; + static TestServer server5; +}; + +Testbase DndTestMnode::test; +TestServer DndTestMnode::server2; +TestServer DndTestMnode::server3; +TestServer DndTestMnode::server4; +TestServer DndTestMnode::server5; + +TEST_F(DndTestMnode, 01_ShowDnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); + CHECK_META("show mnodes", 5); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, 12 + VARSTR_HEADER_SIZE, "role"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9061", TSDB_EP_LEN); + CheckBinary("master", 12); + CheckInt64(0); + CheckTimestamp(); +} + +TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateMnodeMsg); + + SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); + } +} + +TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateMnodeMsg); + + SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } +} + +TEST_F(DndTestMnode, 04_Create_Mnode) { + { + // create dnode + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9062); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + taosMsleep(1300); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + // create mnode + int32_t contLen = sizeof(SMCreateMnodeMsg); + + SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9061", TSDB_EP_LEN); + CheckBinary("localhost:9062", TSDB_EP_LEN); + CheckBinary("master", 12); + CheckBinary("slave", 12); + CheckInt64(0); + CheckInt64(0); + CheckTimestamp(); + CheckTimestamp(); + } + + { + // drop mnode + int32_t contLen = sizeof(SMDropMnodeMsg); + + SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9061", TSDB_EP_LEN); + CheckBinary("master", 12); + CheckInt64(0); + CheckTimestamp(); + } +} +// { +// int32_t contLen = sizeof(SDropDnodeMsg); + +// SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); +// pReq->dnodeId = htonl(2); + +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); +// ASSERT_NE(pMsg, nullptr); +// ASSERT_EQ(pMsg->code, 0); +// } + +// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// CHECK_META("show dnodes", 7); +// test.SendShowRetrieveMsg(); +// EXPECT_EQ(test.GetShowRows(), 1); + +// CheckInt16(1); +// CheckBinary("localhost:9061", TSDB_EP_LEN); +// CheckInt16(0); +// CheckInt16(1); +// CheckBinary("ready", 10); +// CheckTimestamp(); +// CheckBinary("", 24); + +// { +// int32_t contLen = sizeof(SCreateDnodeMsg); + +// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); +// strcpy(pReq->ep, "localhost:9063"); + +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pMsg, nullptr); +// ASSERT_EQ(pMsg->code, 0); +// } + +// { +// int32_t contLen = sizeof(SCreateDnodeMsg); + +// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); +// strcpy(pReq->ep, "localhost:9064"); + +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pMsg, nullptr); +// ASSERT_EQ(pMsg->code, 0); +// } + +// { +// int32_t contLen = sizeof(SCreateDnodeMsg); + +// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); +// strcpy(pReq->ep, "localhost:9065"); + +// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pMsg, nullptr); +// ASSERT_EQ(pMsg->code, 0); +// } + +// taosMsleep(1300); +// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// CHECK_META("show dnodes", 7); +// test.SendShowRetrieveMsg(); +// EXPECT_EQ(test.GetShowRows(), 4); + +// CheckInt16(1); +// CheckInt16(3); +// CheckInt16(4); +// CheckInt16(5); +// CheckBinary("localhost:9061", TSDB_EP_LEN); +// CheckBinary("localhost:9063", TSDB_EP_LEN); +// CheckBinary("localhost:9064", TSDB_EP_LEN); +// CheckBinary("localhost:9065", TSDB_EP_LEN); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(1); +// CheckInt16(1); +// CheckInt16(1); +// CheckInt16(1); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckBinary("", 24); +// CheckBinary("", 24); +// CheckBinary("", 24); +// CheckBinary("", 24); + +// // restart +// uInfo("stop all server"); +// test.Restart(); +// server2.Restart(); +// server3.Restart(); +// server4.Restart(); +// server5.Restart(); + +// taosMsleep(1300); +// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// CHECK_META("show dnodes", 7); +// test.SendShowRetrieveMsg(); +// EXPECT_EQ(test.GetShowRows(), 4); + +// CheckInt16(1); +// CheckInt16(3); +// CheckInt16(4); +// CheckInt16(5); +// CheckBinary("localhost:9061", TSDB_EP_LEN); +// CheckBinary("localhost:9063", TSDB_EP_LEN); +// CheckBinary("localhost:9064", TSDB_EP_LEN); +// CheckBinary("localhost:9065", TSDB_EP_LEN); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(0); +// CheckInt16(1); +// CheckInt16(1); +// CheckInt16(1); +// CheckInt16(1); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckBinary("ready", 10); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckTimestamp(); +// CheckBinary("", 24); +// CheckBinary("", 24); +// CheckBinary("", 24); +// CheckBinary("", 24); +// } diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 2e82d4d1aa6d1c5007ef7453cb4fe956118823c5..87e6bfde747926e58cc5b4257ca1ea9ca9e025bb 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -35,14 +35,14 @@ TEST_F(DndTestProfile, 01_ConnectMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); pRsp->acctId = htonl(pRsp->acctId); - pRsp->clusterId = htonl(pRsp->clusterId); + pRsp->clusterId = htobe64(pRsp->clusterId); pRsp->connId = htonl(pRsp->connId); pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]); @@ -67,7 +67,7 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, "invalid_db"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB); ASSERT_EQ(pMsg->contLen, 0); @@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -138,7 +138,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -153,7 +153,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION); ASSERT_EQ(pMsg->contLen, 0); @@ -167,14 +167,14 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); pRsp->acctId = htonl(pRsp->acctId); - pRsp->clusterId = htonl(pRsp->clusterId); + pRsp->clusterId = htobe64(pRsp->clusterId); pRsp->connId = htonl(pRsp->connId); pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]); @@ -198,7 +198,7 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } @@ -211,7 +211,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->connId = htonl(connId); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->contLen, 0); @@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -261,7 +261,7 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { pReq->connId = htonl(2345); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2edb6de8b8c7433cfa76ff214a6f13c26557ea70 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. QTEST_SRC) +add_executable(dnode_test_qnode ${QTEST_SRC}) +target_link_libraries( + dnode_test_qnode + PUBLIC sut +) + +add_test( + NAME dnode_test_qnode + COMMAND dnode_test_qnode +) diff --git a/source/dnode/mgmt/impl/test/qnode/qnode.cpp b/source/dnode/mgmt/impl/test/qnode/qnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40464de81692eb59b9e372eab28be0342fda71a8 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/qnode.cpp @@ -0,0 +1,154 @@ +/** + * @file dnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module dnode-msg tests + * @version 0.1 + * @date 2021-12-15 + * + * @copyright Copyright (c) 2021 + * + */ + +#include "base.h" + +class DndTestQnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/dnode_test_qnode1", 9064); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9064"; + + server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase DndTestQnode::test; +TestServer DndTestQnode::server2; + +TEST_F(DndTestQnode, 01_ShowQnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + CHECK_META("show qnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateQnodeMsg); + + SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + CHECK_META("show qnodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckTimestamp(); + } +} + +TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateQnodeMsg); + + SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } +} + +TEST_F(DndTestQnode, 04_Create_Qnode) { + { + // create dnode + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9065); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + taosMsleep(1300); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + // create qnode + int32_t contLen = sizeof(SMCreateQnodeMsg); + + SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckBinary("localhost:9065", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + // drop qnode + int32_t contLen = sizeof(SMDropQnodeMsg); + + SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9064", TSDB_EP_LEN); + CheckTimestamp(); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp index bec681cb8fed2115f70ebbb147a3c21926060a36..a0df0f29218a63e5141adaa9244605c569802353 100644 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ b/source/dnode/mgmt/impl/test/show/show.cpp @@ -32,7 +32,7 @@ TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { pReq->type = TSDB_MGMT_TABLE_MAX; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } @@ -44,7 +44,7 @@ TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { pReq->type = TSDB_MGMT_TABLE_START; strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } @@ -57,7 +57,7 @@ TEST_F(DndTestShow, 02_ShowMsg_Conn) { strcpy(pReq->app, "dnode_test_show"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..180b1ec163b7caa84538b8eec656c2f588b12c68 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. STEST_SRC) +add_executable(dnode_test_snode ${STEST_SRC}) +target_link_libraries( + dnode_test_snode + PUBLIC sut +) + +add_test( + NAME dnode_test_snode + COMMAND dnode_test_snode +) diff --git a/source/dnode/mgmt/impl/test/snode/snode.cpp b/source/dnode/mgmt/impl/test/snode/snode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a14a575bebeb39599dc5e2e0e6fd8f7ee8bf9423 --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/snode.cpp @@ -0,0 +1,154 @@ +/** + * @file dnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module dnode-msg tests + * @version 0.1 + * @date 2021-12-15 + * + * @copyright Copyright (c) 2021 + * + */ + +#include "base.h" + +class DndTestSnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/dnode_test_snode1", 9066); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9066"; + + server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase DndTestSnode::test; +TestServer DndTestSnode::server2; + +TEST_F(DndTestSnode, 01_ShowSnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + CHECK_META("show snodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateSnodeMsg); + + SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + CHECK_META("show snodes", 3); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckTimestamp(); + } +} + +TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { + { + int32_t contLen = sizeof(SMCreateSnodeMsg); + + SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } +} + +TEST_F(DndTestSnode, 04_Create_Snode) { + { + // create dnode + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9067); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + taosMsleep(1300); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + // create snode + int32_t contLen = sizeof(SMCreateSnodeMsg); + + SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckBinary("localhost:9067", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + // drop snode + int32_t contLen = sizeof(SMDropSnodeMsg); + + SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9066", TSDB_EP_LEN); + CheckTimestamp(); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index 992ebaf902668c8d646d71969891c9d16831a601..dca0f4851658caa57ec264a9ce9c896e5e44fc45 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -51,7 +51,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -68,7 +68,6 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pReq->pSchema[0]; - pSchema->colId = htonl(0); pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_TIMESTAMP; strcpy(pSchema->name, "ts"); @@ -76,7 +75,6 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pReq->pSchema[1]; - pSchema->colId = htonl(1); pSchema->bytes = htonl(4); pSchema->type = TSDB_DATA_TYPE_INT; strcpy(pSchema->name, "col1"); @@ -84,7 +82,6 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pReq->pSchema[2]; - pSchema->colId = htonl(2); pSchema->bytes = htonl(2); pSchema->type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema->name, "tag1"); @@ -92,7 +89,6 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pReq->pSchema[3]; - pSchema->colId = htonl(3); pSchema->bytes = htonl(8); pSchema->type = TSDB_DATA_TYPE_BIGINT; strcpy(pSchema->name, "tag2"); @@ -100,13 +96,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pReq->pSchema[4]; - pSchema->colId = htonl(4); pSchema->bytes = htonl(16); pSchema->type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema->name, "tag3"); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_STB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -133,7 +128,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen); strcpy(pReq->tableFname, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_TABLE_META, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_STB_META, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -151,8 +146,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pSchema->bytes = htonl(pSchema->bytes); } - EXPECT_STREQ(pRsp->tbFname, ""); - EXPECT_STREQ(pRsp->stbFname, "1.d1.stb"); + EXPECT_STREQ(pRsp->tbFname, "1.d1.stb"); + EXPECT_STREQ(pRsp->stbFname, ""); EXPECT_EQ(pRsp->numOfColumns, 2); EXPECT_EQ(pRsp->numOfTags, 3); EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); @@ -167,10 +162,42 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { SSchema* pSchema = &pRsp->pSchema[0]; EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); - EXPECT_EQ(pSchema->colId, 0); + EXPECT_EQ(pSchema->colId, 1); EXPECT_EQ(pSchema->bytes, 8); EXPECT_STREQ(pSchema->name, "ts"); } + + { + SSchema* pSchema = &pRsp->pSchema[1]; + EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); + EXPECT_EQ(pSchema->colId, 2); + EXPECT_EQ(pSchema->bytes, 4); + EXPECT_STREQ(pSchema->name, "col1"); + } + + { + SSchema* pSchema = &pRsp->pSchema[2]; + EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TINYINT); + EXPECT_EQ(pSchema->colId, 3); + EXPECT_EQ(pSchema->bytes, 2); + EXPECT_STREQ(pSchema->name, "tag1"); + } + + { + SSchema* pSchema = &pRsp->pSchema[3]; + EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BIGINT); + EXPECT_EQ(pSchema->colId, 4); + EXPECT_EQ(pSchema->bytes, 8); + EXPECT_STREQ(pSchema->name, "tag2"); + } + + { + SSchema* pSchema = &pRsp->pSchema[4]; + EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); + EXPECT_EQ(pSchema->colId, 5); + EXPECT_EQ(pSchema->bytes, 16); + EXPECT_STREQ(pSchema->name, "tag3"); + } } // restart @@ -192,7 +219,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen); strcpy(pReq->name, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_STB, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index b0de6f5c0c2b878bf57b7eede971126642959156..fef7ad9d430fd20719fcd378a9e8eed99bf48a0f 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -20,7 +20,7 @@ #include "os.h" #include "dnode.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tconfig.h" #include "tdataformat.h" #include "tglobal.h" @@ -37,7 +37,7 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); - SRpcMsg* SendMsg(int8_t msgType, void* pCont, int32_t contLen); + SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); private: void InitLog(const char* path); diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 59e99b1e1d9b740ac78079d2c899dd00e36b141b..e14dc94d31bb126a286780c79d19cfb42c37e114 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -24,13 +24,13 @@ void Testbase::InitLog(const char* path) { tmrDebugFlag = 0; uDebugFlag = 143; rpcDebugFlag = 0; - odbcDebugFlag = 0; qDebugFlag = 0; wDebugFlag = 0; sDebugFlag = 0; tsdbDebugFlag = 0; cqDebugFlag = 0; tscEmbeddedInUtil = 1; + tsAsyncLog = 0; taosRemoveDir(path); taosMkDir(path); @@ -47,7 +47,7 @@ void Testbase::Init(const char* path, int16_t port) { char firstEp[TSDB_EP_LEN] = {0}; snprintf(firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port); - InitLog("/tmp/tdlog"); + InitLog("/tmp/td"); server.Start(path, fqdn, port, firstEp); client.Init("root", "taosdata", fqdn, port); taosMsleep(1100); @@ -60,7 +60,7 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } -SRpcMsg* Testbase::SendMsg(int8_t msgType, void* pCont, int32_t contLen) { +SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; rpcMsg.contLen = contLen; @@ -75,7 +75,7 @@ void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { pShow->type = showType; strcpy(pShow->db, db); - SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW, pShow, contLen); + SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen); SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; ASSERT(pShowRsp != nullptr); @@ -124,7 +124,7 @@ void Testbase::SendShowRetrieveMsg() { pRetrieve->showId = htonl(showId); pRetrieve->free = 0; - SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW_RETRIEVE, pRetrieve, contLen); + SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index fce3da15073e830908390fe95d9b98f0fcc5bada..13429cec28217886cdb44e5fe8672b43746402f8 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -18,7 +18,7 @@ static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; client->SetRpcRsp(pMsg); - uInfo("response:%s from dnode, code:0x%x", taosMsg[pMsg->msgType], pMsg->code); + uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code); tsem_post(client->GetSem()); } diff --git a/source/dnode/mgmt/impl/test/sut/src/server.cpp b/source/dnode/mgmt/impl/test/sut/src/server.cpp index e96f7deaf5e1c9466a5b94a29cc8d1ad25c8f6d4..8ac5f6214430a1e46f757f755e97b2fca28c4119 100644 --- a/source/dnode/mgmt/impl/test/sut/src/server.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/server.cpp @@ -26,9 +26,8 @@ SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t p SDnodeOpt option = {0}; option.sver = 1; option.numOfCores = 1; - option.numOfSupportMnodes = 1; - option.numOfSupportVnodes = 1; - option.numOfSupportQnodes = 1; + option.numOfSupportVnodes = 16; + option.numOfCommitThreads = 1; option.statusInterval = 1; option.numOfThreadsPerCore = 1; option.ratioOfQueryCores = 1; diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp index a1810e7adaaa7011775dd2e9fbcc3892cce720e6..aa160304c844c00225cef8cc962070763e225143 100644 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ b/source/dnode/mgmt/impl/test/user/user.cpp @@ -51,7 +51,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -63,7 +63,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -94,7 +94,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -124,7 +124,7 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_USER, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index c534fcbabe96b28af1a917bbca718ad6210070b5..718fbea50d9f880e4d61b469fd750a0c878b7cca 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -60,7 +60,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -100,7 +100,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -119,9 +119,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pReq; rpcMsg.contLen = sizeof(SDropVnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + rpcMsg.msgType = TDMT_DND_DROP_VNODE; - SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen); + SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mnode/impl/inc/mndBalance.h b/source/dnode/mnode/impl/inc/mndBnode.h similarity index 81% rename from source/dnode/mnode/impl/inc/mndBalance.h rename to source/dnode/mnode/impl/inc/mndBnode.h index fa3679d0333eaf12a7537ca23f3bce5989a87b50..cefc0b1859fd314e8ebd7d673aa936fa79227e14 100644 --- a/source/dnode/mnode/impl/inc/mndBalance.h +++ b/source/dnode/mnode/impl/inc/mndBnode.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MND_BALANCE_H_ -#define _TD_MND_BALANCE_H_ +#ifndef _TD_MND_BNODE_H_ +#define _TD_MND_BNODE_H_ #include "mndInt.h" @@ -22,11 +22,11 @@ extern "C" { #endif -int32_t mndInitBalance(SMnode *pMnode); -void mndCleanupBalance(SMnode *pMnode); +int32_t mndInitBnode(SMnode *pMnode); +void mndCleanupBnode(SMnode *pMnode); #ifdef __cplusplus } #endif -#endif /*_TD_MND_BALANCE_H_*/ +#endif /*_TD_MND_BNODE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h new file mode 100644 index 0000000000000000000000000000000000000000..60f186d7d2ea4210c54df2af805d16111ba582cd --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndConsumer.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_CONSUMER_H_ +#define _TD_MND_CONSUMER_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitConsumer(SMnode *pMnode); +void mndCleanupConsumer(SMnode *pMnode); + +SConsumerObj *mndAcquireConsumer(SMnode *pMnode, int32_t consumerId); +void mndReleaseConsumer(SMnode *pMnode, SConsumerObj *pConsumer); + +SCGroupObj *mndAcquireCGroup(SMnode *pMnode, char *consumerGroup); +void mndReleaseCGroup(SMnode *pMnode, SCGroupObj *pCGroup); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_CONSUMER_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index da5492057458b09aed332168919ce1b38a46e959..338024c20abef97d785bd6faaa5956e0d46cc1d5 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -20,7 +20,7 @@ #include "cJSON.h" #include "sync.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "tlog.h" #include "trpc.h" @@ -62,21 +62,18 @@ typedef enum { typedef enum { TRN_STAGE_PREPARE = 0, - TRN_STAGE_EXECUTE = 1, - TRN_STAGE_ROLLBACK = 2, - TRN_STAGE_COMMIT = 3, - TRN_STAGE_OVER = 4, + TRN_STAGE_REDO_LOG = 1, + TRN_STAGE_REDO_ACTION = 2, + TRN_STAGE_UNDO_LOG = 3, + TRN_STAGE_UNDO_ACTION = 4, + TRN_STAGE_COMMIT_LOG = 5, + TRN_STAGE_COMMIT = 6, + TRN_STAGE_ROLLBACK = 7, + TRN_STAGE_FINISHED = 8 } ETrnStage; typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy; -typedef enum { - DND_STATUS_OFFLINE = 0, - DND_STATUS_READY = 1, - DND_STATUS_CREATING = 2, - DND_STATUS_DROPPING = 3 -} EDndStatus; - typedef enum { DND_REASON_ONLINE = 0, DND_REASON_STATUS_MSG_TIMEOUT, @@ -95,7 +92,10 @@ typedef struct { int32_t id; ETrnStage stage; ETrnPolicy policy; + int32_t code; + int32_t failedTimes; void *rpcHandle; + void *rpcAHandle; SArray *redoLogs; SArray *undoLogs; SArray *commitLogs; @@ -104,7 +104,7 @@ typedef struct { } STrans; typedef struct { - int32_t id; + int64_t id; char name[TSDB_CLUSTER_ID_LEN]; int64_t createdTime; int64_t updateTime; @@ -117,14 +117,9 @@ typedef struct { int64_t rebootTime; int64_t lastAccessTime; int32_t accessTimes; - int16_t numOfMnodes; int16_t numOfVnodes; - int16_t numOfQnodes; - int16_t numOfSupportMnodes; - int16_t numOfSupportVnodes; - int16_t numOfSupportQnodes; - int16_t numOfCores; - EDndStatus status; + int32_t numOfSupportVnodes; + int32_t numOfCores; EDndReason offlineReason; uint16_t port; char fqdn[TSDB_FQDN_LEN]; @@ -141,6 +136,27 @@ typedef struct { SDnodeObj *pDnode; } SMnodeObj; +typedef struct { + int32_t id; + int64_t createdTime; + int64_t updateTime; + SDnodeObj *pDnode; +} SQnodeObj; + +typedef struct { + int32_t id; + int64_t createdTime; + int64_t updateTime; + SDnodeObj *pDnode; +} SSnodeObj; + +typedef struct { + int32_t id; + int64_t createdTime; + int64_t updateTime; + SDnodeObj *pDnode; +} SBnodeObj; + typedef struct { int32_t maxUsers; int32_t maxDbs; @@ -202,7 +218,7 @@ typedef struct { } SDbCfg; typedef struct { - char name[TSDB_FULL_DB_NAME_LEN]; + char name[TSDB_DB_FNAME_LEN]; char acct[TSDB_USER_LEN]; int64_t createdTime; int64_t updateTime; @@ -225,7 +241,7 @@ typedef struct { int32_t version; uint32_t hashBegin; uint32_t hashEnd; - char dbName[TSDB_FULL_DB_NAME_LEN]; + char dbName[TSDB_DB_FNAME_LEN]; int64_t dbUid; int32_t numOfTables; int32_t numOfTimeSeries; @@ -239,7 +255,7 @@ typedef struct { typedef struct { char name[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int64_t createdTime; int64_t updateTime; uint64_t uid; @@ -279,34 +295,64 @@ typedef struct { int32_t payloadLen; void *pIter; SMnode *pMnode; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int16_t offset[TSDB_MAX_COLUMNS]; int32_t bytes[TSDB_MAX_COLUMNS]; char payload[]; } SShowObj; +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createTime; + int64_t updateTime; + uint64_t uid; + uint64_t dbUid; + int32_t version; + SRWLatch lock; + int32_t execLen; + void* executor; + int32_t sqlLen; + char* sql; + char* logicalPlan; + char* physicalPlan; +} STopicObj; + +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createTime; + int64_t updateTime; + uint64_t uid; + //uint64_t dbUid; + int32_t version; + SRWLatch lock; + +} SConsumerObj; + +typedef struct { + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createTime; + int64_t updateTime; + uint64_t uid; + //uint64_t dbUid; + int32_t version; + SRWLatch lock; + +} SCGroupObj; + typedef struct SMnodeMsg { char user[TSDB_USER_LEN]; - char db[TSDB_FULL_DB_NAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int32_t acctId; SMnode *pMnode; - int16_t received; - int16_t successed; - int16_t expected; - int16_t retry; - int32_t code; int64_t createdTime; SRpcMsg rpcMsg; int32_t contLen; void *pCont; } SMnodeMsg; -typedef struct { - int32_t id; - int32_t code; - void *rpcHandle; -} STransMsg; - #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index 764dfbffc150a6d09cb9162264a079a823792368..c76186c0a29bc6a0c78458afbf6781a77cd81cb3 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -28,7 +28,7 @@ SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId); void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode); SEpSet mndGetDnodeEpset(SDnodeObj *pDnode); int32_t mndGetDnodeSize(SMnode *pMnode); -bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode); +bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index ba72d9553721b9220aa520b8bb11b46c1b7baeb5..daa87af1f5da02237458c5e5cbee3ccad2ebc3e6 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -19,6 +19,7 @@ #include "mndDef.h" #include "sdb.h" #include "tcache.h" +#include "tep.h" #include "tqueue.h" #include "ttime.h" @@ -61,13 +62,21 @@ typedef struct { char email[TSDB_FQDN_LEN]; } STelemMgmt; +typedef struct { + int32_t errCode; + sem_t syncSem; + SSyncNode *pSyncNode; + ESyncState state; +} SSyncMgmt; + typedef struct SMnode { int32_t dnodeId; - int32_t clusterId; + int64_t clusterId; int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; tmr_h timer; + tmr_h transTimer; char *path; SMnodeCfg cfg; int64_t checkTime; @@ -77,17 +86,17 @@ typedef struct SMnode { SShowMgmt showMgmt; SProfileMgmt profileMgmt; STelemMgmt telemMgmt; - MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; + SSyncMgmt syncMgmt; + MndMsgFp msgFp[TDMT_MAX]; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; - PutMsgToMnodeQFp putMsgToApplyMsgFp; } SMnode; void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); -void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); uint64_t mndGenerateUid(char *name, int32_t len) ; diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index 906d11aec2b123a7cffc6a7a9d5fd28a44afe356..5df13915632469075f995fd33c2b36ee79aa9271 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -27,6 +27,7 @@ void mndCleanupMnode(SMnode *pMnode); bool mndIsMnode(SMnode *pMnode, int32_t dnodeId); void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet); char *mndGetRoleStr(int32_t role); +void mndUpdateMnodeRole(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/qnode/inc/qnodeInt.h b/source/dnode/mnode/impl/inc/mndQnode.h similarity index 79% rename from source/dnode/qnode/inc/qnodeInt.h rename to source/dnode/mnode/impl/inc/mndQnode.h index 43df47845be66929e14b565b5ad038073da03e4d..5d177b3f6db6e2f8c81be3c4461bdea0870ba322 100644 --- a/source/dnode/qnode/inc/qnodeInt.h +++ b/source/dnode/mnode/impl/inc/mndQnode.h @@ -13,15 +13,20 @@ * along with this program. If not, see . */ -#ifndef _TD_QNODE_INT_H_ -#define _TD_QNODE_INT_H_ +#ifndef _TD_MND_QNODE_H_ +#define _TD_MND_QNODE_H_ + +#include "mndInt.h" #ifdef __cplusplus extern "C" { #endif +int32_t mndInitQnode(SMnode *pMnode); +void mndCleanupQnode(SMnode *pMnode); + #ifdef __cplusplus } #endif -#endif /*_TD_QNODE_INT_H_*/ \ No newline at end of file +#endif /*_TD_MND_QNODE_H_*/ diff --git a/source/dnode/mnode/impl/src/mndBalance.c b/source/dnode/mnode/impl/inc/mndSnode.h similarity index 74% rename from source/dnode/mnode/impl/src/mndBalance.c rename to source/dnode/mnode/impl/inc/mndSnode.h index 6ce89b96a3c12ad0257505f78b54472b2db0abc4..8d64879605aa0ef6562ca94b88733111619bfe61 100644 --- a/source/dnode/mnode/impl/src/mndBalance.c +++ b/source/dnode/mnode/impl/inc/mndSnode.h @@ -13,9 +13,20 @@ * along with this program. If not, see . */ -#define _DEFAULT_SOURCE -#include "os.h" +#ifndef _TD_MND_SNODE_H_ +#define _TD_MND_SNODE_H_ + #include "mndInt.h" -int32_t mndInitBalance(SMnode *pMnode) { return 0; } -void mndCleanupBalance(SMnode *pMnode) {} \ No newline at end of file +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitSnode(SMnode *pMnode); +void mndCleanupSnode(SMnode *pMnode); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_SNODE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndStb.h b/source/dnode/mnode/impl/inc/mndStb.h index 58cae73c7fa0e58fbd7bd82d55adfaa06fc345cc..48847dc6a3d8879276f38ba02e90876325a00e20 100644 --- a/source/dnode/mnode/impl/inc/mndStb.h +++ b/source/dnode/mnode/impl/inc/mndStb.h @@ -25,6 +25,9 @@ extern "C" { int32_t mndInitStb(SMnode *pMnode); void mndCleanupStb(SMnode *pMnode); +SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName); +void mndReleaseStb(SMnode *pMnode, SStbObj *pStb); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h new file mode 100644 index 0000000000000000000000000000000000000000..d092f47d4b3f8f4bf0f5cc925ca4a99a63a59731 --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndTopic.h @@ -0,0 +1,35 @@ +/* + * 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_TOPIC_H_ +#define _TD_MND_TOPIC_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitTopic(SMnode *pMnode); +void mndCleanupTopic(SMnode *pMnode); + +STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName); +void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_TOPIC_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index a8d37ba655ef52c6f4fdf4b77938cab4bb0a6046..201fcde1a932b2ff6da777ceb15a733b4f32cb0a 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -24,7 +24,7 @@ extern "C" { typedef struct { SEpSet epSet; - int8_t msgType; + tmsg_t msgType; int8_t msgSent; int8_t msgReceived; int32_t errCode; @@ -35,7 +35,7 @@ typedef struct { int32_t mndInitTrans(SMnode *pMnode); void mndCleanupTrans(SMnode *pMnode); -STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle); +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg); void mndTransDrop(STrans *pTrans); int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw); int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw); @@ -44,11 +44,7 @@ int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); -void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code); -void mndTransHandleActionRsp(SMnodeMsg *pMsg); - -char *mndTransStageStr(ETrnStage stage); -char *mndTransPolicyStr(ETrnPolicy policy); +void mndTransProcessRsp(SMnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index 8a3a2c798af479ca3a419cf2be2560735b100d81..6d391450b7c37833e8382c850f7f28ec0132d7e7 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -29,6 +29,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup); SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup); int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups); SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup); +int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId); SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup); SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup); diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 4c2706f4819a8477a99353a3a05409894aad20c0..767f628306ad2e563baccdd15972f762ffbbd21d 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndAcctActionUpdate, .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_ACCT, mndProcessCreateAcctMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_ACCT, mndProcessAlterAcctMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_ACCT, mndProcessDropAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); return sdbSetTable(pMnode->pSdb, table); } diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c new file mode 100644 index 0000000000000000000000000000000000000000..2d14e0f92e828b267fb768f26d8d76fb06625683 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -0,0 +1,446 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "mndBnode.h" +#include "mndDnode.h" +#include "mndShow.h" +#include "mndTrans.h" + +#define TSDB_BNODE_VER_NUMBER 1 +#define TSDB_BNODE_RESERVE_SIZE 64 + +static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj); +static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw); +static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj); +static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj); +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode); +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg); +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg); +static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); + +int32_t mndInitBnode(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_BNODE, + .keyType = SDB_KEY_INT32, + .encodeFp = (SdbEncodeFp)mndBnodeActionEncode, + .decodeFp = (SdbDecodeFp)mndBnodeActionDecode, + .insertFp = (SdbInsertFp)mndBnodeActionInsert, + .updateFp = (SdbUpdateFp)mndBnodeActionUpdate, + .deleteFp = (SdbDeleteFp)mndBnodeActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_BNODE, mndProcessCreateBnodeReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_BNODE, mndProcessDropBnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_BNODE_RSP, mndProcessCreateBnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_BNODE_RSP, mndProcessDropBnodeRsp); + + mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndGetBnodeMeta); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndRetrieveBnodes); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndCancelGetNextBnode); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupBnode(SMnode *pMnode) {} + +static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) { + SSdb *pSdb = pMnode->pSdb; + SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId); + if (pObj == NULL) { + terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; + } + return pObj; +} + +static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pObj); +} + +static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) { + SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_INT32(pRaw, dataPos, pObj->id); + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE) + + return pRaw; +} + +static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != TSDB_BNODE_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode snode since %s", terrstr()); + return NULL; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); + SBnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) + SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE) + + return pRow; +} + +static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { + mTrace("snode:%d, perform insert action", pObj->id); + pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); + if (pObj->pDnode == NULL) { + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr()); + return -1; + } + + return 0; +} + +static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { + mTrace("snode:%d, perform delete action", pObj->id); + if (pObj->pDnode != NULL) { + sdbRelease(pSdb, pObj->pDnode); + pObj->pDnode = NULL; + } + + return 0; +} + +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) { + mTrace("snode:%d, perform update action", pOldBnode->id); + pOldBnode->updateTime = pNewBnode->updateTime; + return 0; +} + +static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { + SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDCreateBnodeMsg); + action.msgType = TDMT_DND_CREATE_BNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { + SBnodeObj snodeObj = {0}; + snodeObj.id = pDnode->id; + snodeObj.createdTime = taosGetTimestampMs(); + snodeObj.updateTime = snodeObj.createdTime; + + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + goto CREATE_BNODE_OVER; + } + mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); + + if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto CREATE_BNODE_OVER; + } + + if (mndSetCreateBnodeCommitLogs(pTrans, &snodeObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto CREATE_BNODE_OVER; + } + + if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_BNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto CREATE_BNODE_OVER; + } + + code = 0; + +CREATE_BNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont; + + pCreate->dnodeId = htonl(pCreate->dnodeId); + + mDebug("snode:%d, start to create", pCreate->dnodeId); + + SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId); + if (pObj != NULL) { + mError("snode:%d, snode already exist", pObj->id); + mndReleaseBnode(pMnode, pObj); + return -1; + } + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); + if (pDnode == NULL) { + mError("snode:%d, dnode not exist", pCreate->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate); + mndReleaseDnode(pMnode, pDnode); + + if (code != 0) { + mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndSetDropBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + return 0; +} + +static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { + SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropBnodeMsg); + action.msgType = TDMT_DND_DROP_BNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); + goto DROP_BNODE_OVER; + } + + mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); + + if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto DROP_BNODE_OVER; + } + + if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto DROP_BNODE_OVER; + } + + if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_BNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto DROP_BNODE_OVER; + } + + code = 0; + +DROP_BNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; + pDrop->dnodeId = htonl(pDrop->dnodeId); + + mDebug("snode:%d, start to drop", pDrop->dnodeId); + + if (pDrop->dnodeId <= 0) { + terrno = TSDB_CODE_SDB_APP_ERROR; + mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); + return -1; + } + + SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId); + if (pObj == NULL) { + mError("snode:%d, not exist", pDrop->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndDropBnode(pMnode, pMsg, pObj); + if (code != 0) { + mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + return -1; + } + + sdbRelease(pMnode->pSdb, pMnode); + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "id"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "endpoint"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(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_BNODE); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + int32_t cols = 0; + SBnodeObj *pObj = NULL; + char *pWrite; + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_BNODE, pShow->pIter, (void **)&pObj); + if (pShow->pIter == NULL) break; + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pObj->id; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pObj->createdTime; + cols++; + + numOfRows++; + sdbRelease(pSdb, pObj); + } + + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfReads += numOfRows; + + return numOfRows; +} + +static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index cf8511c0541cc4642e2e18c104496a4acbb259ee..f656c27dcd224db8cb6c80dee9e609c40668ef88 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -67,7 +67,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { if (pRaw == NULL) return NULL; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pCluster->id); + SDB_SET_INT64(pRaw, dataPos, pCluster->id); SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime) SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime) SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) @@ -91,7 +91,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { if (pCluster == NULL) return NULL; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pCluster->id) + SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->id) SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime) SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) @@ -101,17 +101,17 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { } static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%d, perform insert action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform insert action", pCluster->id); return 0; } static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%d, perform delete action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform delete action", pCluster->id); return 0; } static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) { - mTrace("cluster:%d, perform update action", pOldCluster->id); + mTrace("cluster:%" PRId64 ", perform update action", pOldCluster->id); return 0; } @@ -125,17 +125,17 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { strcpy(clusterObj.name, "tdengine2.0"); mError("failed to get name from system, set to default val %s", clusterObj.name); } else { - mDebug("cluster:%d, name is %s", clusterObj.id, clusterObj.name); + mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); } clusterObj.id = MurmurHash3_32(clusterObj.name, TSDB_CLUSTER_ID_LEN); - clusterObj.id = abs(clusterObj.id); + clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id); pMnode->clusterId = clusterObj.id; SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj); if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("cluster:%d, will be created while deploy sdb", clusterObj.id); + mDebug("cluster:%" PRId64 ", will be created while deploy sdb", clusterObj.id); return sdbWrite(pMnode->pSdb, pRaw); } @@ -143,8 +143,8 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg int32_t cols = 0; SSchema *pSchema = pMeta->pSchema; - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; strcpy(pSchema[cols].name, "id"); pSchema[cols].bytes = htonl(pShow->bytes[cols]); cols++; @@ -192,7 +192,7 @@ static int32_t mndRetrieveClusters(SMnodeMsg *pMsg, SShowObj *pShow, char *data, cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pCluster->id; + *(int64_t *)pWrite = pCluster->id; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c new file mode 100644 index 0000000000000000000000000000000000000000..9e7cdbf09e17a2836c948713c5f0222347ee0aeb --- /dev/null +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -0,0 +1,373 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "mndConsumer.h" +#include "mndDb.h" +#include "mndDnode.h" +#include "mndMnode.h" +#include "mndShow.h" +#include "mndStb.h" +#include "mndTopic.h" +#include "mndTrans.h" +#include "mndUser.h" +#include "mndVgroup.h" +#include "tname.h" + +#define MND_CONSUMER_VER_NUMBER 1 +#define MND_CONSUMER_RESERVE_SIZE 64 + +static SSdbRaw *mndConsumerActionEncode(SConsumerObj *pConsumer); +static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw); +static int32_t mndConsumerActionInsert(SSdb *pSdb, SConsumerObj *pConsumer); +static int32_t mndConsumerActionDelete(SSdb *pSdb, SConsumerObj *pConsumer); +static int32_t mndConsumerActionUpdate(SSdb *pSdb, SConsumerObj *pConsumer, SConsumerObj *pNewConsumer); +static int32_t mndProcessCreateConsumerMsg(SMnodeMsg *pMsg); +static int32_t mndProcessDropConsumerMsg(SMnodeMsg *pMsg); +static int32_t mndProcessDropConsumerInRsp(SMnodeMsg *pMsg); +static int32_t mndProcessConsumerMetaMsg(SMnodeMsg *pMsg); +static int32_t mndGetConsumerMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveConsumer(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter); + +static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg); +static int32_t mndProcessSubscribeRsp(SMnodeMsg *pMsg); +static int32_t mndProcessSubscribeInternalReq(SMnodeMsg *pMsg); +static int32_t mndProcessSubscribeInternalRsp(SMnodeMsg *pMsg); + +int32_t mndInitConsumer(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_CONSUMER, + .keyType = SDB_KEY_BINARY, + .encodeFp = (SdbEncodeFp)mndConsumerActionEncode, + .decodeFp = (SdbDecodeFp)mndConsumerActionDecode, + .insertFp = (SdbInsertFp)mndConsumerActionInsert, + .updateFp = (SdbUpdateFp)mndConsumerActionUpdate, + .deleteFp = (SdbDeleteFp)mndConsumerActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq); + mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE_RSP, mndProcessSubscribeRsp); + mndSetMsgHandle(pMnode, TDMT_VND_SUBSCRIBE, mndProcessSubscribeInternalReq); + mndSetMsgHandle(pMnode, TDMT_VND_SUBSCRIBE_RSP, mndProcessSubscribeInternalRsp); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupConsumer(SMnode *pMnode) {} + +static SSdbRaw *mndConsumerActionEncode(SConsumerObj *pConsumer) { + int32_t size = sizeof(SConsumerObj) + MND_CONSUMER_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_BINARY(pRaw, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN); + SDB_SET_BINARY(pRaw, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN); + SDB_SET_INT64(pRaw, dataPos, pConsumer->createTime); + SDB_SET_INT64(pRaw, dataPos, pConsumer->updateTime); + SDB_SET_INT64(pRaw, dataPos, pConsumer->uid); + /*SDB_SET_INT64(pRaw, dataPos, pConsumer->dbUid);*/ + SDB_SET_INT32(pRaw, dataPos, pConsumer->version); + + SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE); + SDB_SET_DATALEN(pRaw, dataPos); + + return pRaw; +} + +static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != MND_CONSUMER_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode consumer since %s", terrstr()); + return NULL; + } + + int32_t size = sizeof(SConsumerObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); + SConsumerObj *pConsumer = sdbGetRowObj(pRow); + if (pConsumer == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->name, TSDB_TABLE_FNAME_LEN); + SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->db, TSDB_DB_FNAME_LEN); + SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->createTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->updateTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->uid); + /*SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->dbUid);*/ + SDB_GET_INT32(pRaw, pRow, dataPos, &pConsumer->version); + + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_CONSUMER_RESERVE_SIZE); + + return pRow; +} + +static int32_t mndConsumerActionInsert(SSdb *pSdb, SConsumerObj *pConsumer) { + mTrace("consumer:%s, perform insert action", pConsumer->name); + return 0; +} + +static int32_t mndConsumerActionDelete(SSdb *pSdb, SConsumerObj *pConsumer) { + mTrace("consumer:%s, perform delete action", pConsumer->name); + return 0; +} + +static int32_t mndConsumerActionUpdate(SSdb *pSdb, SConsumerObj *pOldConsumer, SConsumerObj *pNewConsumer) { + mTrace("consumer:%s, perform update action", pOldConsumer->name); + atomic_exchange_32(&pOldConsumer->updateTime, pNewConsumer->updateTime); + atomic_exchange_32(&pOldConsumer->version, pNewConsumer->version); + + taosWLockLatch(&pOldConsumer->lock); + + // TODO handle update + + taosWUnLockLatch(&pOldConsumer->lock); + return 0; +} + +SConsumerObj *mndAcquireConsumer(SMnode *pMnode, int32_t consumerId) { + SSdb *pSdb = pMnode->pSdb; + SConsumerObj *pConsumer = sdbAcquire(pSdb, SDB_CONSUMER, &consumerId); + if (pConsumer == NULL) { + /*terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;*/ + } + return pConsumer; +} + +void mndReleaseConsumer(SMnode *pMnode, SConsumerObj *pConsumer) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pConsumer); +} + +static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + char *msgStr = pMsg->rpcMsg.pCont; + SCMSubscribeReq *pSubscribe; + tDeserializeSCMSubscribeReq(msgStr, pSubscribe); + // add consumerGroupId -> list to sdb + // add consumerId -> list to sdb + // add consumer -> list to sdb + return 0; +} + +static int32_t mndProcessSubscribeRsp(SMnodeMsg *pMsg) { return 0; } + +static int32_t mndProcessSubscribeInternalReq(SMnodeMsg *pMsg) { return 0; } + +static int32_t mndProcessSubscribeInternalRsp(SMnodeMsg *pMsg) { return 0; } + +static int32_t mndProcessDropConsumerInRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessConsumerMetaMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; + + mDebug("consumer:%s, start to retrieve meta", pInfo->tableFname); + +#if 0 + SDbObj *pDb = mndAcquireDbByConsumer(pMnode, pInfo->tableFname); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + mError("consumer:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + SConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pInfo->tableFname); + if (pConsumer == NULL) { + mndReleaseDb(pMnode, pDb); + terrno = TSDB_CODE_MND_INVALID_CONSUMER; + mError("consumer:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + taosRLockLatch(&pConsumer->lock); + int32_t totalCols = pConsumer->numOfColumns + pConsumer->numOfTags; + int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema); + + STableMetaMsg *pMeta = rpcMallocCont(contLen); + if (pMeta == NULL) { + taosRUnLockLatch(&pConsumer->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseConsumer(pMnode, pConsumer); + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("consumer:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + memcpy(pMeta->consumerFname, pConsumer->name, TSDB_TABLE_FNAME_LEN); + pMeta->numOfTags = htonl(pConsumer->numOfTags); + pMeta->numOfColumns = htonl(pConsumer->numOfColumns); + pMeta->precision = pDb->cfg.precision; + pMeta->tableType = TSDB_SUPER_TABLE; + pMeta->update = pDb->cfg.update; + pMeta->sversion = htonl(pConsumer->version); + pMeta->tuid = htonl(pConsumer->uid); + + for (int32_t i = 0; i < totalCols; ++i) { + SSchema *pSchema = &pMeta->pSchema[i]; + SSchema *pSrcSchema = &pConsumer->pSchema[i]; + memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); + pSchema->type = pSrcSchema->type; + pSchema->colId = htonl(pSrcSchema->colId); + pSchema->bytes = htonl(pSrcSchema->bytes); + } + taosRUnLockLatch(&pConsumer->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseConsumer(pMnode, pConsumer); + + pMsg->pCont = pMeta; + pMsg->contLen = contLen; + + mDebug("consumer:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pConsumer->numOfColumns, pConsumer->numOfTags); +#endif + return 0; +} + +static int32_t mndGetNumOfConsumers(SMnode *pMnode, char *dbName, int32_t *pNumOfConsumers) { + SSdb *pSdb = pMnode->pSdb; + + SDbObj *pDb = mndAcquireDb(pMnode, dbName); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + return -1; + } + + int32_t numOfConsumers = 0; + void *pIter = NULL; + while (1) { + SConsumerObj *pConsumer = NULL; + pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); + if (pIter == NULL) break; + + if (strcmp(pConsumer->db, dbName) == 0) { + numOfConsumers++; + } + + sdbRelease(pSdb, pConsumer); + } + + *pNumOfConsumers = numOfConsumers; + return 0; +} + +static int32_t mndGetConsumerMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + if (mndGetNumOfConsumers(pMnode, pShow->db, &pShow->numOfRows) != 0) { + return -1; + } + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + 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 = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "columns"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "tags"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(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_CONSUMER); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveConsumer(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + SConsumerObj *pConsumer = NULL; + int32_t cols = 0; + char *pWrite; + char prefix[64] = {0}; + + tstrncpy(prefix, pShow->db, 64); + strcat(prefix, TS_PATH_DELIMITER); + int32_t prefixLen = (int32_t)strlen(prefix); + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_CONSUMER, pShow->pIter, (void **)&pConsumer); + if (pShow->pIter == NULL) break; + + if (strncmp(pConsumer->name, prefix, prefixLen) != 0) { + sdbRelease(pSdb, pConsumer); + continue; + } + + cols = 0; + + char consumerName[TSDB_TABLE_NAME_LEN] = {0}; + tstrncpy(consumerName, pConsumer->name + prefixLen, TSDB_TABLE_NAME_LEN); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, consumerName); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pConsumer->createTime; + cols++; + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pConsumer->numOfColumns;*/ + /*cols++;*/ + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pConsumer->numOfTags;*/ + /*cols++;*/ + + numOfRows++; + sdbRelease(pSdb, pConsumer); + } + + pShow->numOfReads += numOfRows; + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + return numOfRows; +} + +static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 108896c121eeb1d3d93ffd3a1a9c93cc6f413235..d05e301024ce376f4ab6e0b4b7224d821261015d 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -48,12 +48,12 @@ int32_t mndInitDb(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndDbActionUpdate, .deleteFp = (SdbDeleteFp)mndDbActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_DB, mndProcessCreateDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_DB, mndProcessAlterDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_DB, mndProcessDropDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_USE_DB, mndProcessUseDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SYNC_DB, mndProcessSyncDbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_COMPACT_DB, mndProcessCompactDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DB, mndProcessCreateDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_DB, mndProcessAlterDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_DB, mndProcessDropDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SYNC_DB, mndProcessSyncDbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_DB, mndGetDbMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs); @@ -69,7 +69,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { if (pRaw == NULL) return NULL; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_FULL_DB_NAME_LEN) + SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN) SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN) SDB_SET_INT64(pRaw, dataPos, pDb->createdTime) SDB_SET_INT64(pRaw, dataPos, pDb->updateTime) @@ -116,7 +116,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { if (pDb == NULL) return NULL; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->name, TSDB_FULL_DB_NAME_LEN) + SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->name, TSDB_DB_FNAME_LEN) SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->acct, TSDB_USER_LEN) SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->updateTime) @@ -311,7 +311,7 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.pCont = pMsg; action.contLen = sizeof(SCreateVnodeMsg); - action.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN; + action.msgType = TDMT_DND_CREATE_VNODE; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); return -1; @@ -340,7 +340,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj action.pCont = pMsg; action.contLen = sizeof(SDropVnodeMsg); - action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; + action.msgType = TDMT_DND_DROP_VNODE; if (mndTransAppendUndoAction(pTrans, &action) != 0) { free(pMsg); return -1; @@ -353,11 +353,11 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreate, SUserObj *pUser) { SDbObj dbObj = {0}; - memcpy(dbObj.name, pCreate->db, TSDB_FULL_DB_NAME_LEN); + memcpy(dbObj.name, pCreate->db, TSDB_DB_FNAME_LEN); memcpy(dbObj.acct, pUser->acct, TSDB_USER_LEN); dbObj.createdTime = taosGetTimestampMs(); dbObj.updateTime = dbObj.createdTime; - dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN); + dbObj.uid = mndGenerateUid(dbObj.name, TSDB_DB_FNAME_LEN); dbObj.cfgVersion = 1; dbObj.vgVersion = 1; dbObj.hashMethod = 1; @@ -400,7 +400,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat } int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to create since %s", pCreate->db, terrstr()); goto CREATE_DB_OVER; @@ -541,32 +541,74 @@ static int32_t mndSetDbCfgFromAlterDbMsg(SDbObj *pDb, SAlterDbMsg *pAlter) { } static int32_t mndSetUpdateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { - SSdbRaw *pRedoRaw = mndDbActionEncode(pNewDb); + SSdbRaw *pRedoRaw = mndDbActionEncode(pOldDb); if (pRedoRaw == NULL) return -1; if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_UPDATING) != 0) return -1; return 0; } -static int32_t mndSetUpdateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { - SSdbRaw *pUndoRaw = mndDbActionEncode(pOldDb); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1; +static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { + SSdbRaw *pCommitRaw = mndDbActionEncode(pNewDb); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; return 0; } -static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } +static int32_t mndBuildUpdateVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + STransAction action = {0}; + SVnodeGid *pVgid = pVgroup->vnodeGid + vn; + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + SAlterVnodeMsg *pMsg = (SAlterVnodeMsg *)mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup); + if (pMsg == NULL) return -1; + + action.pCont = pMsg; + action.contLen = sizeof(SAlterVnodeMsg); + action.msgType = TDMT_DND_ALTER_VNODE; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } -static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } + return 0; +} + +static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + if (pVgroup->dbUid == pNewDb->uid) { + if (mndBuildUpdateVgroupAction(pMnode, pTrans, pNewDb, pVgroup) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + } + + sdbRelease(pSdb, pVgroup); + } -static int32_t mndSetUpdateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; } + return 0; +} static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbObj *pNewDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to update since %s", pOldDb->name, terrstr()); return terrno; @@ -579,11 +621,6 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO goto UPDATE_DB_OVER; } - if (mndSetUpdateDbUndoLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) { - mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); - goto UPDATE_DB_OVER; - } - if (mndSetUpdateDbCommitLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) { mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); goto UPDATE_DB_OVER; @@ -594,11 +631,6 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO goto UPDATE_DB_OVER; } - if (mndSetUpdateDbUndoActions(pMnode, pTrans, pOldDb, pNewDb) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto UPDATE_DB_OVER; - } - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); goto UPDATE_DB_OVER; @@ -660,31 +692,87 @@ static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) return 0; } -static int32_t mndSetDropDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { - SSdbRaw *pUndoRaw = mndDbActionEncode(pDb); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1; - - return 0; -} - static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { SSdbRaw *pCommitRaw = mndDbActionEncode(pDb); if (pCommitRaw == NULL) return -1; if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + if (pVgroup->dbUid == pDb->uid) { + SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup); + if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED); + } + + sdbRelease(pSdb, pVgroup); + } + return 0; } -static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } +static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + STransAction action = {0}; + SVnodeGid * pVgid = pVgroup->vnodeGid + vn; + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup); + if (pMsg == NULL) return -1; + + action.pCont = pMsg; + action.contLen = sizeof(SCreateVnodeMsg); + action.msgType = TDMT_DND_DROP_VNODE; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } + + return 0; +} + +static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + if (pVgroup->dbUid == pDb->uid) { + if (mndBuildDropVgroupAction(pMnode, pTrans, pDb, pVgroup) != 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + } + + sdbRelease(pSdb, pVgroup); + } -static int32_t mndSetDropDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } + return 0; +} static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { mError("db:%s, failed to drop since %s", pDb->name, terrstr()); return -1; @@ -697,11 +785,6 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { goto DROP_DB_OVER; } - if (mndSetDropDbUndoLogs(pMnode, pTrans, pDb) != 0) { - mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr()); - goto DROP_DB_OVER; - } - if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) { mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); goto DROP_DB_OVER; @@ -712,11 +795,6 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) { goto DROP_DB_OVER; } - if (mndSetDropDbUndoActions(pMnode, pTrans, pDb) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_DB_OVER; - } - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); goto DROP_DB_OVER; @@ -813,7 +891,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { } } - memcpy(pRsp->db, pDb->name, TSDB_FULL_DB_NAME_LEN); + memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN); pRsp->vgVersion = htonl(pDb->vgVersion); pRsp->vgNum = htonl(vindex); pRsp->hashMethod = pDb->hashMethod; @@ -828,9 +906,9 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { static int32_t mndProcessSyncDbMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; SSyncDbMsg *pSync = pMsg->rpcMsg.pCont; - SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db); + SDbObj *pDb = mndAcquireDb(pMnode, pSync->db); if (pDb == NULL) { - mError("db:%s, failed to process sync db msg since %s", pMsg->db, terrstr()); + mError("db:%s, failed to process sync db msg since %s", pSync->db, terrstr()); return -1; } @@ -841,9 +919,9 @@ static int32_t mndProcessSyncDbMsg(SMnodeMsg *pMsg) { static int32_t mndProcessCompactDbMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; SCompactDbMsg *pCompact = pMsg->rpcMsg.pCont; - SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db); + SDbObj *pDb = mndAcquireDb(pMnode, pCompact->db); if (pDb == NULL) { - mError("db:%s, failed to process compact db msg since %s", pMsg->db, terrstr()); + mError("db:%s, failed to process compact db msg since %s", pCompact->db, terrstr()); return -1; } @@ -876,6 +954,12 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe pSchema[cols].bytes = htonl(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "ntables"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 2; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; strcpy(pSchema[cols].name, "replica"); @@ -1017,6 +1101,10 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 *(int16_t *)pWrite = pDb->cfg.numOfVgroups; cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = 0; // todo + cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int16_t *)pWrite = pDb->cfg.replications; cols++; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 9751771773c53fa55ec965a1fed8be02013f7588..ca20ba61a10e2b499aab65e3a25829a2f7419e22 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -18,8 +18,7 @@ #include "mndMnode.h" #include "mndShow.h" #include "mndTrans.h" -#include "tep.h" -#include "ttime.h" +#include "mndVgroup.h" #define TSDB_DNODE_VER_NUMBER 1 #define TSDB_DNODE_RESERVE_SIZE 64 @@ -41,8 +40,6 @@ static const char *offlineReason[] = { "unknown", }; -static const char *dnodeStatus[] = {"offline", "ready", "creating", "dropping"}; - static int32_t mndCreateDefaultDnode(SMnode *pMnode); static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode); static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw); @@ -73,11 +70,11 @@ int32_t mndInitDnode(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndDnodeActionUpdate, .deleteFp = (SdbDeleteFp)mndDnodeActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_DNODE, mndProcessCreateDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_DNODE, mndProcessDropDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONFIG_DNODE, mndProcessConfigDnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP, mndProcessConfigDnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_STATUS, mndProcessStatusMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeMsg); + mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp); + mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndGetConfigMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndRetrieveConfigs); @@ -209,10 +206,12 @@ int32_t mndGetDnodeSize(SMnode *pMnode) { return sdbGetSize(pSdb, SDB_DNODE); } -bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode) { - int64_t ms = taosGetTimestampMs(); - int64_t interval = ABS(pDnode->lastAccessTime - ms); +bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) { + int64_t interval = ABS(pDnode->lastAccessTime - curMs); if (interval > 3500 * pMnode->cfg.statusInterval) { + if (pDnode->rebootTime > 0) { + pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT; + } return false; } return true; @@ -276,12 +275,11 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) { static void mndParseStatusMsg(SStatusMsg *pStatus) { pStatus->sver = htonl(pStatus->sver); pStatus->dnodeId = htonl(pStatus->dnodeId); - pStatus->clusterId = htonl(pStatus->clusterId); + pStatus->clusterId = htobe64(pStatus->clusterId); pStatus->rebootTime = htobe64(pStatus->rebootTime); - pStatus->numOfCores = htons(pStatus->numOfCores); - pStatus->numOfSupportMnodes = htons(pStatus->numOfSupportMnodes); - pStatus->numOfSupportVnodes = htons(pStatus->numOfSupportVnodes); - pStatus->numOfSupportQnodes = htons(pStatus->numOfSupportQnodes); + pStatus->updateTime = htobe64(pStatus->updateTime); + pStatus->numOfCores = htonl(pStatus->numOfCores); + pStatus->numOfSupportVnodes = htonl(pStatus->numOfSupportVnodes); pStatus->clusterCfg.statusInterval = htonl(pStatus->clusterCfg.statusInterval); pStatus->clusterCfg.checkTime = htobe64(pStatus->clusterCfg.checkTime); } @@ -289,98 +287,99 @@ static void mndParseStatusMsg(SStatusMsg *pStatus) { static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; SStatusMsg *pStatus = pMsg->rpcMsg.pCont; + SDnodeObj *pDnode = NULL; + int32_t code = -1; + mndParseStatusMsg(pStatus); - SDnodeObj *pDnode = NULL; if (pStatus->dnodeId == 0) { pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp); if (pDnode == NULL) { mDebug("dnode:%s, not created yet", pStatus->dnodeEp); terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - return -1; + goto PROCESS_STATUS_MSG_OVER; } } else { pDnode = mndAcquireDnode(pMnode, pStatus->dnodeId); if (pDnode == NULL) { pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp); - if (pDnode != NULL && pDnode->status != DND_STATUS_READY) { + if (pDnode != NULL) { pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH; } mError("dnode:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp); - mndReleaseDnode(pMnode, pDnode); terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - return -1; + goto PROCESS_STATUS_MSG_OVER; } } - if (pStatus->sver != pMnode->cfg.sver) { - if (pDnode != NULL && pDnode->status != DND_STATUS_READY) { - pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH; - } - mndReleaseDnode(pMnode, pDnode); - mError("dnode:%d, status msg version:%d not match cluster:%d", pStatus->dnodeId, pStatus->sver, pMnode->cfg.sver); - terrno = TSDB_CODE_MND_INVALID_MSG_VERSION; - return -1; - } + int64_t curMs = taosGetTimestampMs(); + bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); + bool needCheckCfg = !(online && pDnode->rebootTime == pStatus->rebootTime); - if (pStatus->dnodeId == 0) { - mDebug("dnode:%d %s, first access, set clusterId %d", pDnode->id, pDnode->ep, pMnode->clusterId); - } else { - if (pStatus->clusterId != pMnode->clusterId) { - if (pDnode != NULL && pDnode->status != DND_STATUS_READY) { - pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH; + if (needCheckCfg) { + if (pStatus->sver != pMnode->cfg.sver) { + if (pDnode != NULL) { + pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH; } - mError("dnode:%d, clusterId %d not match exist %d", pDnode->id, pStatus->clusterId, pMnode->clusterId); - mndReleaseDnode(pMnode, pDnode); - terrno != TSDB_CODE_MND_INVALID_CLUSTER_ID; - return -1; + mError("dnode:%d, status msg version:%d not match cluster:%d", pStatus->dnodeId, pStatus->sver, pMnode->cfg.sver); + terrno = TSDB_CODE_MND_INVALID_MSG_VERSION; + goto PROCESS_STATUS_MSG_OVER; + } + + if (pStatus->dnodeId == 0) { + mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { - pDnode->accessTimes++; - mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); + if (pStatus->clusterId != pMnode->clusterId) { + if (pDnode != NULL) { + pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH; + } + mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, pStatus->clusterId, + pMnode->clusterId); + terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID; + goto PROCESS_STATUS_MSG_OVER; + } else { + pDnode->accessTimes++; + mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); + } } - } - if (pDnode->status == DND_STATUS_OFFLINE) { // Verify whether the cluster parameters are consistent when status change from offline to ready int32_t ret = mndCheckClusterCfgPara(pMnode, &pStatus->clusterCfg); if (0 != ret) { pDnode->offlineReason = ret; mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]); - mndReleaseDnode(pMnode, pDnode); terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG; - return -1; + goto PROCESS_STATUS_MSG_OVER; } mInfo("dnode:%d, from offline to online", pDnode->id); - } - pDnode->rebootTime = pStatus->rebootTime; - pDnode->numOfCores = pStatus->numOfCores; - pDnode->numOfSupportMnodes = pStatus->numOfSupportMnodes; - pDnode->numOfSupportVnodes = pStatus->numOfSupportVnodes; - pDnode->numOfSupportQnodes = pStatus->numOfSupportQnodes; - pDnode->lastAccessTime = taosGetTimestampMs(); - pDnode->status = DND_STATUS_READY; - - int32_t numOfEps = mndGetDnodeSize(pMnode); - int32_t contLen = sizeof(SStatusRsp) + numOfEps * sizeof(SDnodeEp); - SStatusRsp *pRsp = rpcMallocCont(contLen); - if (pRsp == NULL) { - mndReleaseDnode(pMnode, pDnode); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + pDnode->rebootTime = pStatus->rebootTime; + pDnode->numOfCores = pStatus->numOfCores; + pDnode->numOfSupportVnodes = pStatus->numOfSupportVnodes; + + int32_t numOfEps = mndGetDnodeSize(pMnode); + int32_t contLen = sizeof(SStatusRsp) + numOfEps * sizeof(SDnodeEp); + SStatusRsp *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto PROCESS_STATUS_MSG_OVER; + } + + pRsp->dnodeCfg.dnodeId = htonl(pDnode->id); + pRsp->dnodeCfg.clusterId = htobe64(pMnode->clusterId); + mndGetDnodeData(pMnode, &pRsp->dnodeEps, numOfEps); + + pMsg->contLen = contLen; + pMsg->pCont = pRsp; } - pRsp->dnodeCfg.dnodeId = htonl(pDnode->id); - pRsp->dnodeCfg.dropped = 0; - pRsp->dnodeCfg.clusterId = htonl(pMnode->clusterId); - mndGetDnodeData(pMnode, &pRsp->dnodeEps, numOfEps); + pDnode->lastAccessTime = curMs; + code = 0; - pMsg->contLen = contLen; - pMsg->pCont = pRsp; +PROCESS_STATUS_MSG_OVER: mndReleaseDnode(pMnode, pDnode); - - return 0; + return code; } static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *pCreate) { @@ -388,20 +387,16 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg * dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE); dnodeObj.createdTime = taosGetTimestampMs(); dnodeObj.updateTime = dnodeObj.createdTime; - taosGetFqdnPortFromEp(pCreate->ep, dnodeObj.fqdn, &dnodeObj.port); + dnodeObj.port = pCreate->port; + memcpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN); + snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port); - if (dnodeObj.fqdn[0] == 0 || dnodeObj.port <= 0) { - terrno = TSDB_CODE_MND_INVALID_DNODE_EP; - mError("dnode:%s, failed to create since %s", pCreate->ep, terrstr()); - return terrno; - } - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("dnode:%s, failed to create since %s", pCreate->ep, terrstr()); + mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr()); return -1; } - mDebug("trans:%d, used to create dnode:%s", pTrans->id, pCreate->ep); + mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep); SSdbRaw *pRedoRaw = mndDnodeActionEncode(&dnodeObj); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { @@ -425,17 +420,20 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; SCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont; - mDebug("dnode:%s, start to create", pCreate->ep); + mDebug("dnode:%s:%d, start to create", pCreate->fqdn, pCreate->port); - if (pCreate->ep[0] == 0) { + pCreate->port = htonl(pCreate->port); + if (pCreate->fqdn[0] == 0 || pCreate->port <= 0 || pCreate->port > UINT16_MAX) { terrno = TSDB_CODE_MND_INVALID_DNODE_EP; - mError("dnode:%s, failed to create since %s", pCreate->ep, terrstr()); + mError("dnode:%s:%d, failed to create since %s", pCreate->fqdn, pCreate->port, terrstr()); return -1; } - SDnodeObj *pDnode = mndAcquireDnodeByEp(pMnode, pCreate->ep); + char ep[TSDB_EP_LEN]; + snprintf(ep, TSDB_EP_LEN, "%s:%d", pCreate->fqdn, pCreate->port); + SDnodeObj *pDnode = mndAcquireDnodeByEp(pMnode, ep); if (pDnode != NULL) { - mError("dnode:%d, already exist", pDnode->id); + mError("dnode:%d, already exist, %s:%u", pDnode->id, pCreate->fqdn, pCreate->port); mndReleaseDnode(pMnode, pDnode); terrno = TSDB_CODE_MND_DNODE_ALREADY_EXIST; return -1; @@ -444,7 +442,7 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) { int32_t code = mndCreateDnode(pMnode, pMsg, pCreate); if (code != 0) { - mError("dnode:%s, failed to create since %s", pCreate->ep, terrstr()); + mError("dnode:%s:%d, failed to create since %s", pCreate->fqdn, pCreate->port, terrstr()); return -1; } @@ -452,7 +450,7 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) { } static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr()); return -1; @@ -527,7 +525,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) { pCfgDnode->dnodeId = htonl(pCfg->dnodeId); memcpy(pCfgDnode->config, pCfg->config, TSDB_DNODE_CONFIG_LEN); - SRpcMsg rpcMsg = {.msgType = TSDB_MSG_TYPE_CONFIG_DNODE_IN, + SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pCfgDnode, .contLen = sizeof(SCfgDnodeMsg), .ahandle = pMsg->rpcMsg.ahandle}; @@ -643,7 +641,7 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * pShow->bytes[cols] = 2; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; - strcpy(pSchema[cols].name, "max_vnodes"); + strcpy(pSchema[cols].name, "support_vnodes"); pSchema[cols].bytes = htonl(pShow->bytes[cols]); cols++; @@ -687,10 +685,12 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i int32_t cols = 0; SDnodeObj *pDnode = NULL; char *pWrite; + int64_t curMs = taosGetTimestampMs(); while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode); if (pShow->pIter == NULL) break; + bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); cols = 0; @@ -703,7 +703,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pDnode->numOfVnodes; + *(int16_t *)pWrite = mndGetVnodesNum(pMnode, pDnode->id); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -711,8 +711,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - const char *status = dnodeStatus[pDnode->status]; - STR_TO_VARSTR(pWrite, status); + STR_TO_VARSTR(pWrite, online ? "ready" : "offline"); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -720,11 +719,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - if (pDnode->status == DND_STATUS_READY) { - STR_TO_VARSTR(pWrite, ""); - } else { - STR_TO_VARSTR(pWrite, offlineReason[pDnode->offlineReason]); - } + STR_TO_VARSTR(pWrite, online ? "" : offlineReason[pDnode->offlineReason]); cols++; numOfRows++; diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index a513c9d57d8fe3c7a0279fa71236ab2d8be87f70..638d984c694957611cd7a091cdd6dc915bdd4c02 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -44,9 +44,9 @@ int32_t mndInitFunc(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndFuncActionUpdate, .deleteFp = (SdbDeleteFp)mndFuncActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_FUNCTION, mndProcessCreateFuncMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_FUNCTION, mndProcessDropFuncMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_RETRIEVE_FUNCTION, mndProcessRetrieveFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_FUNCTION, mndProcessCreateFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_FUNCTION, mndProcessDropFuncMsg); + mndSetMsgHandle(pMnode, TDMT_MND_RETRIEVE_FUNCTION, mndProcessRetrieveFuncMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndGetFuncMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndRetrieveFuncs); @@ -147,7 +147,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncMsg *pC pFunc->pCode = pFunc->pData + pCreate->commentSize; memcpy(pFunc->pCode, pCreate->pCont + pCreate->commentSize, pFunc->codeSize); - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { free(pFunc); mError("func:%s, failed to create since %s", pCreate->name, terrstr()); @@ -195,7 +195,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncMsg *pC } static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pMsg, SFuncObj *pFunc) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("func:%s, failed to drop since %s", pFunc->name, terrstr()); return -1; @@ -441,7 +441,7 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le } if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { - int32_t bytes = len > 0 ? (int)(len - VARSTR_HEADER_SIZE) : len; + int32_t bytes = len > 0 ? (int32_t)(len - VARSTR_HEADER_SIZE) : len; snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes / 4 : bytes); buf[buflen - 1] = 0; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 869b6e538b711b8782144041c450a410210fb67a..b76d72d79c1cba7443e6405717295d38c9671fac 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -23,14 +23,15 @@ #define TSDB_MNODE_RESERVE_SIZE 64 static int32_t mndCreateDefaultMnode(SMnode *pMnode); -static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pMnodeObj); +static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj); static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw); -static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pMnodeObj); -static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj); +static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj); +static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj); static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode); -static int32_t mndProcessCreateMnodeMsg(SMnodeMsg *pMsg); -static int32_t mndProcessDropMnodeMsg(SMnodeMsg *pMsg); +static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg); +static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg); static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg); static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); @@ -46,10 +47,11 @@ int32_t mndInitMnode(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndMnodeActionUpdate, .deleteFp = (SdbDeleteFp)mndMnodeActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_MNODE, mndProcessCreateMnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_MNODE, mndProcessDropMnodeMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP, mndProcessCreateMnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_MNODE_IN_RSP, mndProcessDropMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_MNODE, mndProcessCreateMnodeReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_MNODE_RSP, mndProcessCreateMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE_RSP, mndProcessAlterMnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndProcessDropMnodeRsp); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndGetMnodeMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes); @@ -69,9 +71,9 @@ static SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) { return pObj; } -static void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pMnodeObj) { +static void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) { SSdb *pSdb = pMnode->pSdb; - sdbRelease(pSdb, pMnodeObj); + sdbRelease(pSdb, pObj); } char *mndGetRoleStr(int32_t showType) { @@ -87,6 +89,24 @@ char *mndGetRoleStr(int32_t showType) { } } +void mndUpdateMnodeRole(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + while (1) { + SMnodeObj *pObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj); + if (pIter == NULL) break; + + if (pObj->id == 1) { + pObj->role = TAOS_SYNC_STATE_LEADER; + } else { + pObj->role = TAOS_SYNC_STATE_CANDIDATE; + } + + sdbRelease(pSdb, pObj); + } +} + static int32_t mndCreateDefaultMnode(SMnode *pMnode) { SMnodeObj mnodeObj = {0}; mnodeObj.id = 1; @@ -101,14 +121,14 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { return sdbWrite(pMnode->pSdb, pRaw); } -static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pMnodeObj) { +static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) { SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, TSDB_MNODE_VER_NUMBER, sizeof(SMnodeObj) + TSDB_MNODE_RESERVE_SIZE); if (pRaw == NULL) return NULL; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pMnodeObj->id); - SDB_SET_INT64(pRaw, dataPos, pMnodeObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pMnodeObj->updateTime) + SDB_SET_INT32(pRaw, dataPos, pObj->id); + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE) return pRaw; @@ -125,42 +145,38 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) { } SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj)); - SMnodeObj *pMnodeObj = sdbGetRowObj(pRow); - if (pMnodeObj == NULL) return NULL; + SMnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pMnodeObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->updateTime) + SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_MNODE_RESERVE_SIZE) return pRow; } -static void mnodeResetMnode(SMnodeObj *pMnodeObj) { - pMnodeObj->role = TAOS_SYNC_STATE_FOLLOWER; - pMnodeObj->roleTerm = 0; - pMnodeObj->roleTime = 0; -} +static void mnodeResetMnode(SMnodeObj *pObj) { pObj->role = TAOS_SYNC_STATE_FOLLOWER; } -static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pMnodeObj) { - mTrace("mnode:%d, perform insert action", pMnodeObj->id); - pMnodeObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pMnodeObj->id); - if (pMnodeObj->pDnode == NULL) { +static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { + mTrace("mnode:%d, perform insert action", pObj->id); + pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); + if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - mError("mnode:%d, failed to perform insert action since %s", pMnodeObj->id, terrstr()); + mError("mnode:%d, failed to perform insert action since %s", pObj->id, terrstr()); return -1; } - mnodeResetMnode(pMnodeObj); + mnodeResetMnode(pObj); return 0; } -static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) { - mTrace("mnode:%d, perform delete action", pMnodeObj->id); - if (pMnodeObj->pDnode != NULL) { - sdbRelease(pSdb, pMnodeObj->pDnode); - pMnodeObj->pDnode = NULL; +static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { + mTrace("mnode:%d, perform delete action", pObj->id); + if (pObj->pDnode != NULL) { + sdbRelease(pSdb, pObj->pDnode); + pObj->pDnode = NULL; } return 0; @@ -168,8 +184,6 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) { static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) { mTrace("mnode:%d, perform update action", pOldMnode->id); - pOldMnode->id = pNewMnode->id; - pOldMnode->createdTime = pNewMnode->createdTime; pOldMnode->updateTime = pNewMnode->updateTime; return 0; } @@ -177,12 +191,12 @@ static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj bool mndIsMnode(SMnode *pMnode, int32_t dnodeId) { SSdb *pSdb = pMnode->pSdb; - SMnodeObj *pMnodeObj = sdbAcquire(pSdb, SDB_MNODE, &dnodeId); - if (pMnodeObj == NULL) { + SMnodeObj *pObj = sdbAcquire(pSdb, SDB_MNODE, &dnodeId); + if (pObj == NULL) { return false; } - sdbRelease(pSdb, pMnodeObj); + sdbRelease(pSdb, pObj); return true; } @@ -193,14 +207,14 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { void *pIter = NULL; while (1) { - SMnodeObj *pMnodeObj = NULL; - pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMnodeObj); + SMnodeObj *pObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj); if (pIter == NULL) break; - if (pMnodeObj->pDnode == NULL) break; + if (pObj->pDnode == NULL) break; - pEpSet->port[pEpSet->numOfEps] = htons(pMnodeObj->pDnode->port); - tstrncpy(pEpSet->fqdn[pEpSet->numOfEps], pMnodeObj->pDnode->fqdn, TSDB_FQDN_LEN); - if (pMnodeObj->role == TAOS_SYNC_STATE_LEADER) { + pEpSet->port[pEpSet->numOfEps] = htons(pObj->pDnode->port); + memcpy(pEpSet->fqdn[pEpSet->numOfEps], pObj->pDnode->fqdn, TSDB_FQDN_LEN); + if (pObj->role == TAOS_SYNC_STATE_LEADER) { pEpSet->inUse = pEpSet->numOfEps; } @@ -208,77 +222,177 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { } } -static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateMnodeMsg *pCreate) { +static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateMnodeUndoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndMnodeActionEncode(pObj); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int32_t numOfReplicas = 0; + + SDCreateMnodeMsg createMsg = {0}; + while (1) { + SMnodeObj *pMObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); + if (pIter == NULL) break; + + SReplica *pReplica = &createMsg.replicas[numOfReplicas]; + pReplica->id = htonl(pMObj->id); + pReplica->port = htons(pMObj->pDnode->port); + memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); + numOfReplicas++; + + sdbRelease(pSdb, pMObj); + } + + SReplica *pReplica = &createMsg.replicas[numOfReplicas]; + pReplica->id = htonl(pDnode->id); + pReplica->port = htons(pDnode->port); + memcpy(pReplica->fqdn, pDnode->fqdn, TSDB_FQDN_LEN); + numOfReplicas++; + + createMsg.replica = numOfReplicas; + + while (1) { + SMnodeObj *pMObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); + if (pIter == NULL) break; + + STransAction action = {0}; + + SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg)); + if (pMsg == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pMObj); + return -1; + } + memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg)); + + pMsg->dnodeId = htonl(pMObj->id); + action.epSet = mndGetDnodeEpset(pMObj->pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDAlterMnodeMsg); + action.msgType = TDMT_DND_ALTER_MNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pMObj); + return -1; + } + + sdbRelease(pSdb, pMObj); + } + + { + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + + SDCreateMnodeMsg *pMsg = malloc(sizeof(SDCreateMnodeMsg)); + if (pMsg == NULL) return -1; + memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg)); + pMsg->dnodeId = htonl(pObj->id); + + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDCreateMnodeMsg); + action.msgType = TDMT_DND_CREATE_MNODE; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } + + return 0; +} + +static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateMnodeMsg *pCreate) { SMnodeObj mnodeObj = {0}; - mnodeObj.id = 1; // todo + mnodeObj.id = pDnode->id; mnodeObj.createdTime = taosGetTimestampMs(); mnodeObj.updateTime = mnodeObj.createdTime; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("dnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - return -1; + mError("mnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + goto CREATE_MNODE_OVER; } - mDebug("trans:%d, used to create dnode:%d", pTrans->id, pCreate->dnodeId); + mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId); - SSdbRaw *pRedoRaw = mndMnodeActionEncode(&mnodeObj); - if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { - mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto CREATE_MNODE_OVER; } - sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING); - SSdbRaw *pUndoRaw = mndMnodeActionEncode(&mnodeObj); - if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) { - mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto CREATE_MNODE_OVER; } - sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED); - SSdbRaw *pCommitRaw = mndMnodeActionEncode(&mnodeObj); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_MNODE_OVER; } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + goto CREATE_MNODE_OVER; } + code = 0; + +CREATE_MNODE_OVER: mndTransDrop(pTrans); - return 0; + return code; } -static int32_t mndProcessCreateMnodeMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont; + SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); mDebug("mnode:%d, start to create", pCreate->dnodeId); - SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); - if (pDnode == NULL) { - mError("mnode:%d, dnode not exist", pDnode->id); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + SMnodeObj *pObj = mndAcquireMnode(pMnode, pCreate->dnodeId); + if (pObj != NULL) { + mndReleaseMnode(pMnode, pObj); + mError("mnode:%d, mnode already exist", pObj->id); + terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST; return -1; } - mndReleaseDnode(pMnode, pDnode); - SMnodeObj *pMnodeObj = mndAcquireMnode(pMnode, pCreate->dnodeId); - if (pMnodeObj != NULL) { - mError("mnode:%d, mnode already exist", pMnodeObj->id); - terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST; + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); + if (pDnode == NULL) { + mError("mnode:%d, dnode not exist", pCreate->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; return -1; } - int32_t code = mndCreateMnode(pMnode, pMsg, pCreate); + int32_t code = mndCreateMnode(pMnode, pMsg, pDnode, pCreate); + mndReleaseDnode(pMnode, pDnode); if (code != 0) { mError("mnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); @@ -288,51 +402,142 @@ static int32_t mndProcessCreateMnodeMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pMnodeObj) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); +static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + return 0; +} + +static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int32_t numOfReplicas = 0; + + SDAlterMnodeMsg alterMsg = {0}; + while (1) { + SMnodeObj *pMObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); + if (pIter == NULL) break; + + if (pMObj->id != pObj->id) { + SReplica *pReplica = &alterMsg.replicas[numOfReplicas]; + pReplica->id = htonl(pMObj->id); + pReplica->port = htons(pMObj->pDnode->port); + memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); + numOfReplicas++; + } + + sdbRelease(pSdb, pMObj); + } + + alterMsg.replica = numOfReplicas; + + while (1) { + SMnodeObj *pMObj = NULL; + pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); + if (pIter == NULL) break; + if (pMObj->id != pObj->id) { + STransAction action = {0}; + + SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg)); + if (pMsg == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pMObj); + return -1; + } + memcpy(pMsg, &alterMsg, sizeof(SDAlterMnodeMsg)); + + pMsg->dnodeId = htonl(pMObj->id); + action.epSet = mndGetDnodeEpset(pMObj->pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDAlterMnodeMsg); + action.msgType = TDMT_DND_ALTER_MNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pMObj); + return -1; + } + } + + sdbRelease(pSdb, pMObj); + } + + { + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + + SDDropMnodeMsg *pMsg = malloc(sizeof(SDDropMnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pObj->id); + + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropMnodeMsg); + action.msgType = TDMT_DND_DROP_MNODE; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + } + + return 0; +} + +static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pObj) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); if (pTrans == NULL) { - mError("mnode:%d, failed to drop since %s", pMnodeObj->id, terrstr()); - return -1; + mError("mnode:%d, failed to drop since %s", pObj->id, terrstr()); + goto DROP_MNODE_OVER; } - mDebug("trans:%d, used to drop user:%d", pTrans->id, pMnodeObj->id); - SSdbRaw *pRedoRaw = mndMnodeActionEncode(pMnodeObj); - if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { - mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id); + + if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto DROP_MNODE_OVER; } - sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING); - SSdbRaw *pUndoRaw = mndMnodeActionEncode(pMnodeObj); - if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) { - mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto DROP_MNODE_OVER; } - sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY); - SSdbRaw *pCommitRaw = mndMnodeActionEncode(pMnodeObj); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_MNODE_OVER; } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; + goto DROP_MNODE_OVER; } + code = 0; + +DROP_MNODE_OVER: mndTransDrop(pTrans); - return 0; + return code; } -static int32_t mndProcessDropMnodeMsg(SMnodeMsg *pMsg) { +static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - SDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont; + SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("mnode:%d, start to drop", pDrop->dnodeId); @@ -343,27 +548,38 @@ static int32_t mndProcessDropMnodeMsg(SMnodeMsg *pMsg) { return -1; } - SMnodeObj *pMnodeObj = mndAcquireMnode(pMnode, pDrop->dnodeId); - if (pMnodeObj == NULL) { + SMnodeObj *pObj = mndAcquireMnode(pMnode, pDrop->dnodeId); + if (pObj == NULL) { mError("mnode:%d, not exist", pDrop->dnodeId); terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; return -1; } - int32_t code = mndDropMnode(pMnode, pMsg, pMnodeObj); + int32_t code = mndDropMnode(pMnode, pMsg, pObj); if (code != 0) { mError("mnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg) { return 0; } +static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} -static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg) { return 0; } +static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { SMnode *pMnode = pMsg->pMnode; @@ -414,6 +630,7 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + mndUpdateMnodeRole(pMnode); return 0; } @@ -422,46 +639,39 @@ static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; - SMnodeObj *pMnodeObj = NULL; + SMnodeObj *pObj = NULL; char *pWrite; while (numOfRows < rows) { - pShow->pIter = sdbFetch(pSdb, SDB_MNODE, pShow->pIter, (void **)&pMnodeObj); + pShow->pIter = sdbFetch(pSdb, SDB_MNODE, pShow->pIter, (void **)&pObj); if (pShow->pIter == NULL) break; cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pMnodeObj->id; + *(int16_t *)pWrite = pObj->id; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - - SDnodeObj *pDnode = mndAcquireDnode(pMnode, pMnodeObj->id); - if (pDnode != NULL) { - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->ep, pShow->bytes[cols]); - } else { - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols]); - } - mndReleaseDnode(pMnode, pDnode); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - char *roles = mndGetRoleStr(pMnodeObj->role); + char *roles = mndGetRoleStr(pObj->role); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pMnodeObj->roleTime; + *(int64_t *)pWrite = pObj->roleTime; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pMnodeObj->createdTime; + *(int64_t *)pWrite = pObj->createdTime; cols++; numOfRows++; - sdbRelease(pSdb, pMnodeObj); + sdbRelease(pSdb, pObj); } mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index a4b73e0f3f2547bf6a013eae16c927e1658a0ad7..77efeb8481c29d6db6c15189646fb4e77506c2c4 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -68,10 +68,10 @@ int32_t mndInitProfile(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_HEARTBEAT, mndProcessHeartBeatMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONNECT, mndProcessConnectMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_QUERY, mndProcessKillQueryMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_CONN, mndProcessKillConnectionMsg); + mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CONNECT, mndProcessConnectMsg); + mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryMsg); + mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnectionMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndGetConnsMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); @@ -118,17 +118,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000); if (pConn == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("conn:%d, data:%p failed to put into cache since %s, user:%s", connId, pConn, pInfo->user, terrstr()); + mError("conn:%d, failed to put into cache since %s, user:%s", connId, pInfo->user, terrstr()); return NULL; } else { - mTrace("conn:%d, data:%p created, user:%s", pConn->id, pConn, pInfo->user); + mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, pInfo->user); return pConn; } } static void mndFreeConn(SConnObj *pConn) { tfree(pConn->pQueries); - mTrace("conn:%d, data:%p destroyed", pConn->id, pConn); + mTrace("conn:%d, is destroyed, data:%p", pConn->id, pConn); } static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) { @@ -143,13 +143,13 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) { int32_t keepTime = pMnode->cfg.shellActivityTimer * 3; pConn->lastAccessTimeMs = keepTime * 1000 + (uint64_t)taosGetTimestampMs(); - mTrace("conn:%d, data:%p acquired from cache", pConn->id, pConn); + mTrace("conn:%d, acquired from cache, data:%p", pConn->id, pConn); return pConn; } static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn) { if (pConn == NULL) return; - mTrace("conn:%d, data:%p released from cache", pConn->id, pConn); + mTrace("conn:%d, released from cache, data:%p", pConn->id, pConn); SProfileMgmt *pMgmt = &pMnode->profileMgmt; taosCacheRelease(pMgmt->cache, (void **)&pConn, false); @@ -194,7 +194,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) { taosIp2String(info.clientIp, ip); if (pReq->db[0]) { - snprintf(pMsg->db, TSDB_FULL_DB_NAME_LEN, "%d%s%s", pMsg->acctId, TS_PATH_DELIMITER, pReq->db); + snprintf(pMsg->db, TSDB_DB_FNAME_LEN, "%d%s%s", pMsg->acctId, TS_PATH_DELIMITER, pReq->db); SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db); if (pDb == NULL) { terrno = TSDB_CODE_MND_INVALID_DB; @@ -225,7 +225,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) { mndReleaseUser(pMnode, pUser); } - pRsp->clusterId = htonl(pMnode->clusterId); + pRsp->clusterId = htobe64(pMnode->clusterId); pRsp->connId = htonl(pConn->id); mndGetMnodeEpSet(pMnode, &pRsp->epSet); mndReleaseConn(pMnode, pConn); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c new file mode 100644 index 0000000000000000000000000000000000000000..3b27764c7cae6a5bf70a5cc7aba1dba3d7a55064 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -0,0 +1,446 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "mndQnode.h" +#include "mndDnode.h" +#include "mndShow.h" +#include "mndTrans.h" + +#define TSDB_QNODE_VER_NUMBER 1 +#define TSDB_QNODE_RESERVE_SIZE 64 + +static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj); +static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw); +static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj); +static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj); +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode); +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg); +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg); +static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter); + +int32_t mndInitQnode(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_QNODE, + .keyType = SDB_KEY_INT32, + .encodeFp = (SdbEncodeFp)mndQnodeActionEncode, + .decodeFp = (SdbDecodeFp)mndQnodeActionDecode, + .insertFp = (SdbInsertFp)mndQnodeActionInsert, + .updateFp = (SdbUpdateFp)mndQnodeActionUpdate, + .deleteFp = (SdbDeleteFp)mndQnodeActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_QNODE, mndProcessCreateQnodeReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_QNODE, mndProcessDropQnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_QNODE_RSP, mndProcessCreateQnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_QNODE_RSP, mndProcessDropQnodeRsp); + + mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndGetQnodeMeta); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndRetrieveQnodes); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndCancelGetNextQnode); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupQnode(SMnode *pMnode) {} + +static SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId) { + SSdb *pSdb = pMnode->pSdb; + SQnodeObj *pObj = sdbAcquire(pSdb, SDB_QNODE, &qnodeId); + if (pObj == NULL) { + terrno = TSDB_CODE_MND_QNODE_NOT_EXIST; + } + return pObj; +} + +static void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pObj); +} + +static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) { + SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, TSDB_QNODE_VER_NUMBER, sizeof(SQnodeObj) + TSDB_QNODE_RESERVE_SIZE); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_INT32(pRaw, dataPos, pObj->id); + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE) + + return pRaw; +} + +static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != TSDB_QNODE_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode qnode since %s", terrstr()); + return NULL; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj)); + SQnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) + SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_QNODE_RESERVE_SIZE) + + return pRow; +} + +static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) { + mTrace("qnode:%d, perform insert action", pObj->id); + pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); + if (pObj->pDnode == NULL) { + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("qnode:%d, failed to perform insert action since %s", pObj->id, terrstr()); + return -1; + } + + return 0; +} + +static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { + mTrace("qnode:%d, perform delete action", pObj->id); + if (pObj->pDnode != NULL) { + sdbRelease(pSdb, pObj->pDnode); + pObj->pDnode = NULL; + } + + return 0; +} + +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) { + mTrace("qnode:%d, perform update action", pOldQnode->id); + pOldQnode->updateTime = pNewQnode->updateTime; + return 0; +} + +static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { + SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDCreateQnodeMsg); + action.msgType = TDMT_DND_CREATE_QNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) { + SQnodeObj qnodeObj = {0}; + qnodeObj.id = pDnode->id; + qnodeObj.createdTime = taosGetTimestampMs(); + qnodeObj.updateTime = qnodeObj.createdTime; + + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + goto CREATE_QNODE_OVER; + } + mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); + + if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto CREATE_QNODE_OVER; + } + + if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto CREATE_QNODE_OVER; + } + + if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_QNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto CREATE_QNODE_OVER; + } + + code = 0; + +CREATE_QNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont; + + pCreate->dnodeId = htonl(pCreate->dnodeId); + + mDebug("qnode:%d, start to create", pCreate->dnodeId); + + SQnodeObj *pObj = mndAcquireQnode(pMnode, pCreate->dnodeId); + if (pObj != NULL) { + mError("qnode:%d, qnode already exist", pObj->id); + mndReleaseQnode(pMnode, pObj); + return -1; + } + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); + if (pDnode == NULL) { + mError("qnode:%d, dnode not exist", pCreate->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndCreateQnode(pMnode, pMsg, pDnode, pCreate); + mndReleaseDnode(pMnode, pDnode); + + if (code != 0) { + mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndSetDropQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + return 0; +} + +static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { + SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropQnodeMsg); + action.msgType = TDMT_DND_DROP_QNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("qnode:%d, failed to drop since %s", pObj->id, terrstr()); + goto DROP_QNODE_OVER; + } + + mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); + + if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto DROP_QNODE_OVER; + } + + if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto DROP_QNODE_OVER; + } + + if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_QNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto DROP_QNODE_OVER; + } + + code = 0; + +DROP_QNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont; + pDrop->dnodeId = htonl(pDrop->dnodeId); + + mDebug("qnode:%d, start to drop", pDrop->dnodeId); + + if (pDrop->dnodeId <= 0) { + terrno = TSDB_CODE_SDB_APP_ERROR; + mError("qnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); + return -1; + } + + SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId); + if (pObj == NULL) { + mError("qnode:%d, not exist", pDrop->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndDropQnode(pMnode, pMsg, pObj); + if (code != 0) { + mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + return -1; + } + + sdbRelease(pMnode->pSdb, pMnode); + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "id"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "endpoint"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(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_QNODE); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + int32_t cols = 0; + SQnodeObj *pObj = NULL; + char *pWrite; + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_QNODE, pShow->pIter, (void **)&pObj); + if (pShow->pIter == NULL) break; + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pObj->id; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pObj->createdTime; + cols++; + + numOfRows++; + sdbRelease(pSdb, pObj); + } + + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfReads += numOfRows; + + return numOfRows; +} + +static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 41f09e85a99b55637a44388d2bd1106ba43b961d..af633355efea374dc20730882dab6c8002bf35fa 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -36,8 +36,8 @@ int32_t mndInitShow(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SHOW, mndProcessShowMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SHOW_RETRIEVE, mndProcessRetrieveMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveMsg); return 0; } @@ -55,32 +55,25 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { int32_t showId = atomic_add_fetch_32(&pMgmt->showId, 1); if (showId == 0) atomic_add_fetch_32(&pMgmt->showId, 1); - int32_t size = sizeof(SShowObj) + pMsg->payloadLen; - SShowObj *pShow = calloc(1, size); - if (pShow != NULL) { - pShow->id = showId; - pShow->pMnode = pMnode; - pShow->type = pMsg->type; - pShow->payloadLen = pMsg->payloadLen; - memcpy(pShow->db, pMsg->db, TSDB_FULL_DB_NAME_LEN); - memcpy(pShow->payload, pMsg->payload, pMsg->payloadLen); - } else { - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to process show-meta msg:%s since %s", mndShowStr(pMsg->type), terrstr()); - return NULL; - } + int32_t size = sizeof(SShowObj) + pMsg->payloadLen; + SShowObj showObj = {0}; + showObj.id = showId; + showObj.pMnode = pMnode; + showObj.type = pMsg->type; + showObj.payloadLen = pMsg->payloadLen; + memcpy(showObj.db, pMsg->db, TSDB_DB_FNAME_LEN); + memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen); int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000; - SShowObj *pShowRet = taosCachePut(pMgmt->cache, &showId, sizeof(int32_t), pShow, size, keepTime); - free(pShow); - if (pShowRet == NULL) { + SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int32_t), &showObj, size, keepTime); + if (pShow == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("show:%d, failed to put into cache since %s", showId, terrstr()); return NULL; - } else { - mTrace("show:%d, data:%p created", showId, pShowRet); - return pShowRet; } + + mTrace("show:%d, is created, data:%p", showId, pShow); + return pShow; } static void mndFreeShowObj(SShowObj *pShow) { @@ -94,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) { } } - mTrace("show:%d, data:%p destroyed", pShow->id, pShow); + mTrace("show:%d, is destroyed, data:%p", pShow->id, pShow); } static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) { @@ -106,14 +99,14 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) { return NULL; } - mTrace("show:%d, data:%p acquired from cache", pShow->id, pShow); + mTrace("show:%d, acquired from cache, data:%p", pShow->id, pShow); return pShow; } static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { if (pShow == NULL) return; - mTrace("show:%d, data:%p released from cache, force:%d", pShow->id, pShow, forceRemove); - + mTrace("show:%d, released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); + // A bug in tcache.c forceRemove = 0; @@ -158,8 +151,8 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { } int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:%d, data:%p get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow, - pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); + mDebug("show:%d, get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; @@ -195,16 +188,15 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (retrieveFp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:%d, data:%p failed to retrieve data since %s", pShow->id, pShow, terrstr()); + mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:%d, data:%p start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow, - pShow->numOfReads, pShow->numOfRows, mndShowStr(pShow->type)); + mDebug("show:%d, start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, + pShow->numOfRows, mndShowStr(pShow->type)); if (mndCheckRetrieveFinished(pShow)) { - mDebug("show:%d, data:%p read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow, pShow->numOfReads, - pShow->numOfRows); + mDebug("show:%d, read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows); pShow->numOfReads = pShow->numOfRows; } @@ -227,7 +219,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:%d, data:%p failed to retrieve data since %s", pShow->id, pShow, terrstr()); + mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr()); return -1; } @@ -236,7 +228,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead); } - mDebug("show:%d, data:%p stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, pShow, rowsRead, rowsToRead); + mDebug("show:%d, stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision @@ -246,10 +238,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; - mDebug("show:%d, data:%p retrieve completed", pShow->id, pShow); + mDebug("show:%d, retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); } else { - mDebug("show:%d, data:%p retrieve not completed yet", pShow->id, pShow); + mDebug("show:%d, retrieve not completed yet", pShow->id); mndReleaseShowObj(pShow, false); } @@ -270,6 +262,12 @@ char *mndShowStr(int32_t showType) { return "show dnodes"; case TSDB_MGMT_TABLE_MNODE: return "show mnodes"; + case TSDB_MGMT_TABLE_QNODE: + return "show qnodes"; + case TSDB_MGMT_TABLE_SNODE: + return "show snodes"; + case TSDB_MGMT_TABLE_BNODE: + return "show bnodes"; case TSDB_MGMT_TABLE_VGROUP: return "show vgroups"; case TSDB_MGMT_TABLE_STB: diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c new file mode 100644 index 0000000000000000000000000000000000000000..a4825c0e82d98cf47544f1795991f32294689b7b --- /dev/null +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -0,0 +1,446 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "mndSnode.h" +#include "mndDnode.h" +#include "mndShow.h" +#include "mndTrans.h" + +#define TSDB_SNODE_VER_NUMBER 1 +#define TSDB_SNODE_RESERVE_SIZE 64 + +static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj); +static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw); +static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj); +static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj); +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode); +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg); +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg); +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg); +static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter); + +int32_t mndInitSnode(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_SNODE, + .keyType = SDB_KEY_INT32, + .encodeFp = (SdbEncodeFp)mndSnodeActionEncode, + .decodeFp = (SdbDecodeFp)mndSnodeActionDecode, + .insertFp = (SdbInsertFp)mndSnodeActionInsert, + .updateFp = (SdbUpdateFp)mndSnodeActionUpdate, + .deleteFp = (SdbDeleteFp)mndSnodeActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_SNODE, mndProcessCreateSnodeReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_SNODE, mndProcessDropSnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_SNODE_RSP, mndProcessCreateSnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_SNODE_RSP, mndProcessDropSnodeRsp); + + mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndGetSnodeMeta); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndRetrieveSnodes); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndCancelGetNextSnode); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupSnode(SMnode *pMnode) {} + +static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { + SSdb *pSdb = pMnode->pSdb; + SSnodeObj *pObj = sdbAcquire(pSdb, SDB_SNODE, &snodeId); + if (pObj == NULL) { + terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; + } + return pObj; +} + +static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pObj); +} + +static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) { + SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, TSDB_SNODE_VER_NUMBER, sizeof(SSnodeObj) + TSDB_SNODE_RESERVE_SIZE); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_INT32(pRaw, dataPos, pObj->id); + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE) + + return pRaw; +} + +static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != TSDB_SNODE_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode snode since %s", terrstr()); + return NULL; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj)); + SSnodeObj *pObj = sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) + SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) + SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_SNODE_RESERVE_SIZE) + + return pRow; +} + +static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) { + mTrace("snode:%d, perform insert action", pObj->id); + pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); + if (pObj->pDnode == NULL) { + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr()); + return -1; + } + + return 0; +} + +static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { + mTrace("snode:%d, perform delete action", pObj->id); + if (pObj->pDnode != NULL) { + sdbRelease(pSdb, pObj->pDnode); + pObj->pDnode = NULL; + } + + return 0; +} + +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) { + mTrace("snode:%d, perform update action", pOldSnode->id); + pOldSnode->updateTime = pNewSnode->updateTime; + return 0; +} + +static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} + +static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDCreateSnodeMsg); + action.msgType = TDMT_DND_CREATE_SNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) { + SSnodeObj snodeObj = {0}; + snodeObj.id = pDnode->id; + snodeObj.createdTime = taosGetTimestampMs(); + snodeObj.updateTime = snodeObj.createdTime; + + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + goto CREATE_SNODE_OVER; + } + mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); + + if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto CREATE_SNODE_OVER; + } + + if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto CREATE_SNODE_OVER; + } + + if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto CREATE_SNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto CREATE_SNODE_OVER; + } + + code = 0; + +CREATE_SNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont; + + pCreate->dnodeId = htonl(pCreate->dnodeId); + + mDebug("snode:%d, start to create", pCreate->dnodeId); + + SSnodeObj *pObj = mndAcquireSnode(pMnode, pCreate->dnodeId); + if (pObj != NULL) { + mError("snode:%d, snode already exist", pObj->id); + mndReleaseSnode(pMnode, pObj); + return -1; + } + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); + if (pDnode == NULL) { + mError("snode:%d, dnode not exist", pCreate->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndCreateSnode(pMnode, pMsg, pDnode, pCreate); + mndReleaseDnode(pMnode, pDnode); + + if (code != 0) { + mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndSetDropSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + return 0; +} + +static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg)); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pMsg->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pMsg; + action.contLen = sizeof(SDDropSnodeMsg); + action.msgType = TDMT_DND_DROP_SNODE; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pMsg); + return -1; + } + + return 0; +} + +static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); + if (pTrans == NULL) { + mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); + goto DROP_SNODE_OVER; + } + + mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); + + if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); + goto DROP_SNODE_OVER; + } + + if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) { + mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); + goto DROP_SNODE_OVER; + } + + if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { + mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); + goto DROP_SNODE_OVER; + } + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + goto DROP_SNODE_OVER; + } + + code = 0; + +DROP_SNODE_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont; + pDrop->dnodeId = htonl(pDrop->dnodeId); + + mDebug("snode:%d, start to drop", pDrop->dnodeId); + + if (pDrop->dnodeId <= 0) { + terrno = TSDB_CODE_SDB_APP_ERROR; + mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); + return -1; + } + + SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId); + if (pObj == NULL) { + mError("snode:%d, not exist", pDrop->dnodeId); + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + return -1; + } + + int32_t code = mndDropSnode(pMnode, pMsg, pObj); + if (code != 0) { + mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + return -1; + } + + sdbRelease(pMnode->pSdb, pMnode); + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + pShow->bytes[cols] = 2; + pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; + strcpy(pSchema[cols].name, "id"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "endpoint"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(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_SNODE); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + int32_t cols = 0; + SSnodeObj *pObj = NULL; + char *pWrite; + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_SNODE, pShow->pIter, (void **)&pObj); + if (pShow->pIter == NULL) break; + + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = pObj->id; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pObj->createdTime; + cols++; + + numOfRows++; + sdbRelease(pSdb, pObj); + } + + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfReads += numOfRows; + + return numOfRows; +} + +static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index a51312a2a924e5d51cd5c8279426faf6e6016b59..918f43f2bdbfb695bc5fec741171dd0e882c8336 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -52,13 +52,13 @@ int32_t mndInitStb(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndStbActionUpdate, .deleteFp = (SdbDeleteFp)mndStbActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB, mndProcessCreateStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB, mndProcessAlterStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB, mndProcessDropStbMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB_IN_RSP, mndProcessCreateStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB_IN_RSP, mndProcessAlterStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB_IN_RSP, mndProcessDropStbInRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessStbMetaMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessCreateStbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessAlterStbMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessDropStbMsg); + mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndProcessCreateStbInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndProcessAlterStbInRsp); + mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndProcessDropStbInRsp); + mndSetMsgHandle(pMnode, TDMT_MND_STB_META, mndProcessStbMetaMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STB, mndGetStbMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STB, mndRetrieveStb); @@ -76,7 +76,7 @@ static SSdbRaw *mndStbActionEncode(SStbObj *pStb) { int32_t dataPos = 0; SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_FULL_DB_NAME_LEN) + SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN) SDB_SET_INT64(pRaw, dataPos, pStb->createdTime) SDB_SET_INT64(pRaw, dataPos, pStb->updateTime) SDB_SET_INT64(pRaw, dataPos, pStb->uid) @@ -117,7 +117,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_FULL_DB_NAME_LEN) + SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_DB_FNAME_LEN) SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->updateTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->uid) @@ -177,7 +177,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb } SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName); if (pStb == NULL) { terrno = TSDB_CODE_MND_STB_NOT_EXIST; @@ -200,40 +200,46 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { return mndAcquireDb(pMnode, db); } -static SCreateStbInternalMsg *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) { - int32_t totalCols = pStb->numOfTags + pStb->numOfColumns; - int32_t contLen = totalCols * sizeof(SSchema) + sizeof(SCreateStbInternalMsg); - - SCreateStbInternalMsg *pCreate = calloc(1, contLen); - if (pCreate == NULL) { +static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) { + SVCreateTbReq req; + void * buf; + int bsize; + SMsgHead * pMsgHead; + + req.ver = 0; + req.name = pStb->name; + req.ttl = 0; + req.keep = 0; + req.type = TD_SUPER_TABLE; + req.stbCfg.suid = pStb->uid; + req.stbCfg.nCols = pStb->numOfColumns; + req.stbCfg.pSchema = pStb->pSchema; + req.stbCfg.nTagCols = pStb->numOfTags; + req.stbCfg.pTagSchema = pStb->pSchema + pStb->numOfColumns; + + bsize = tSerializeSVCreateTbReq(NULL, &req); + buf = malloc(sizeof(SMsgHead) + bsize); + if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - pCreate->head.contLen = htonl(contLen); - pCreate->head.vgId = htonl(pVgroup->vgId); - memcpy(pCreate->name, pStb->name, TSDB_TABLE_FNAME_LEN); - pCreate->suid = htobe64(pStb->uid); - pCreate->sverson = htonl(pStb->version); - pCreate->ttl = 0; - pCreate->keep = 0; - pCreate->numOfTags = htonl(pStb->numOfTags); - pCreate->numOfColumns = htonl(pStb->numOfColumns); + pMsgHead = (SMsgHead *)buf; - memcpy(pCreate->pSchema, pStb->pSchema, totalCols * sizeof(SSchema)); - for (int32_t t = 0; t < totalCols; ++t) { - SSchema *pSchema = &pCreate->pSchema[t]; - pSchema->bytes = htonl(pSchema->bytes); - pSchema->colId = htonl(pSchema->colId); - } + pMsgHead->contLen = htonl(sizeof(SMsgHead) + bsize); + pMsgHead->vgId = htonl(pVgroup->vgId); + + void *pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tSerializeSVCreateTbReq(&pBuf, &req); - return pCreate; + *pContLen = sizeof(SMsgHead) + bsize; + return buf; } -static SDropStbInternalMsg *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) { - int32_t contLen = sizeof(SDropStbInternalMsg); +static SVDropStbReq *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) { + int32_t contLen = sizeof(SVDropStbReq); - SDropStbInternalMsg *pDrop = calloc(1, contLen); + SVDropStbReq *pDrop = calloc(1, contLen); if (pDrop == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -253,7 +259,6 @@ static int32_t mndCheckCreateStbMsg(SCreateStbMsg *pCreate) { int32_t totalCols = pCreate->numOfColumns + pCreate->numOfTags; for (int32_t i = 0; i < totalCols; ++i) { SSchema *pSchema = &pCreate->pSchema[i]; - pSchema->colId = htonl(pSchema->colId); pSchema->bytes = htonl(pSchema->bytes); } @@ -279,10 +284,6 @@ static int32_t mndCheckCreateStbMsg(SCreateStbMsg *pCreate) { terrno = TSDB_CODE_MND_INVALID_STB_OPTION; return -1; } - if (pSchema->colId < 0 || pSchema->colId >= maxColId) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; - } if (pSchema->bytes <= 0) { terrno = TSDB_CODE_MND_INVALID_STB_OPTION; return -1; @@ -324,16 +325,17 @@ static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void *pIter = NULL; + void * pIter = NULL; + int contLen; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; if (pVgroup->dbUid != pDb->uid) continue; - SCreateStbInternalMsg *pMsg = mndBuildCreateStbMsg(pMnode, pVgroup, pStb); + void *pMsg = mndBuildCreateStbMsg(pMnode, pVgroup, pStb, &contLen); if (pMsg == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); @@ -344,8 +346,8 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; - action.contLen = htonl(pMsg->head.contLen); - action.msgType = TSDB_MSG_TYPE_CREATE_STB_IN; + action.contLen = contLen; + action.msgType = TDMT_VND_CREATE_STB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); @@ -359,16 +361,16 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void *pIter = NULL; + void * pIter = NULL; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; if (pVgroup->dbUid != pDb->uid) continue; - SDropStbInternalMsg *pMsg = mndBuildDropStbMsg(pMnode, pVgroup, pStb); + SVDropStbReq *pMsg = mndBuildDropStbMsg(pMnode, pVgroup, pStb); if (pMsg == NULL) { sdbCancelFetch(pSdb, pIter); sdbRelease(pSdb, pVgroup); @@ -379,8 +381,8 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pMsg; - action.contLen = sizeof(SDropStbInternalMsg); - action.msgType = TSDB_MSG_TYPE_DROP_STB_IN; + action.contLen = sizeof(SVDropStbReq); + action.msgType = TDMT_VND_DROP_STB; if (mndTransAppendUndoAction(pTrans, &action) != 0) { free(pMsg); sdbCancelFetch(pSdb, pIter); @@ -396,7 +398,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCreate, SDbObj *pDb) { SStbObj stbObj = {0}; tstrncpy(stbObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); - tstrncpy(stbObj.db, pDb->name, TSDB_FULL_DB_NAME_LEN); + tstrncpy(stbObj.db, pDb->name, TSDB_DB_FNAME_LEN); stbObj.createdTime = taosGetTimestampMs(); stbObj.updateTime = stbObj.createdTime; stbObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); @@ -414,8 +416,12 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre } memcpy(stbObj.pSchema, pCreate->pSchema, totalSize); + for (int32_t i = 0; i < totalCols; ++i) { + stbObj.pSchema[i].colId = i + 1; + } + int32_t code = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("stb:%s, failed to create since %s", pCreate->name, terrstr()); return -1; @@ -461,7 +467,7 @@ CREATE_STB_OVER: } static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SCreateStbMsg *pCreate = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to create", pCreate->name); @@ -484,6 +490,15 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { } } + // topic should have different name with stb + SStbObj *pTopic = mndAcquireStb(pMnode, pCreate->name); + if (pTopic != NULL) { + sdbRelease(pMnode->pSdb, pTopic); + terrno = TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC; + mError("stb:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + SDbObj *pDb = mndAcquireDbByStb(pMnode, pCreate->name); if (pDb == NULL) { terrno = TSDB_CODE_MND_DB_NOT_SELECTED; @@ -504,7 +519,7 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { } static int32_t mndProcessCreateStbInRsp(SMnodeMsg *pMsg) { - mndTransHandleActionRsp(pMsg); + mndTransProcessRsp(pMsg); return 0; } @@ -536,7 +551,7 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) { static int32_t mndUpdateStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pOldStb, SStbObj *pNewStb) { return 0; } static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SAlterStbMsg *pAlter = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to alter", pAlter->name); @@ -568,7 +583,7 @@ static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) { } static int32_t mndProcessAlterStbInRsp(SMnodeMsg *pMsg) { - mndTransHandleActionRsp(pMsg); + mndTransProcessRsp(pMsg); return 0; } @@ -605,7 +620,7 @@ static int32_t mndSetDropStbUndoActions(SMnode *pMnode, STrans *pTrans, SStbObj static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("stb:%s, failed to drop since %s", pStb->name, terrstr()); return -1; @@ -650,7 +665,7 @@ DROP_STB_OVER: } static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; SDropStbMsg *pDrop = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to drop", pDrop->name); @@ -680,12 +695,12 @@ static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) { } static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { - mndTransHandleActionRsp(pMsg); + mndTransProcessRsp(pMsg); return 0; } static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode * pMnode = pMsg->pMnode; STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to retrieve meta", pInfo->tableFname); @@ -719,7 +734,7 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { return -1; } - memcpy(pMeta->stbFname, pStb->name, TSDB_TABLE_FNAME_LEN); + memcpy(pMeta->tbFname, pStb->name, TSDB_TABLE_FNAME_LEN); pMeta->numOfTags = htonl(pStb->numOfTags); pMeta->numOfColumns = htonl(pStb->numOfColumns); pMeta->precision = pDb->cfg.precision; @@ -757,7 +772,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs } int32_t numOfStbs = 0; - void *pIter = NULL; + void * pIter = NULL; while (1) { SStbObj *pStb = NULL; pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb); @@ -776,7 +791,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { SMnode *pMnode = pMsg->pMnode; - SSdb *pSdb = pMnode->pSdb; + SSdb * pSdb = pMnode->pSdb; if (mndGetNumOfStbs(pMnode, pShow->db, &pShow->numOfRows) != 0) { return -1; @@ -825,8 +840,8 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM } static void mndExtractTableName(char *tableId, char *name) { - int pos = -1; - int num = 0; + int32_t pos = -1; + int32_t num = 0; for (pos = 0; tableId[pos] != 0; ++pos) { if (tableId[pos] == '.') num++; if (num == 2) break; @@ -846,6 +861,11 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 char *pWrite; char prefix[64] = {0}; + SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); + if (pDb == NULL) { + return TSDB_CODE_MND_INVALID_DB; + } + tstrncpy(prefix, pShow->db, 64); strcat(prefix, TS_PATH_DELIMITER); int32_t prefixLen = (int32_t)strlen(prefix); @@ -854,7 +874,7 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); if (pShow->pIter == NULL) break; - if (strncmp(pStb->name, prefix, prefixLen) != 0) { + if (pStb->dbUid != pDb->uid) { sdbRelease(pSdb, pStb); continue; } @@ -883,6 +903,7 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 sdbRelease(pSdb, pStb); } + mndReleaseDb(pMnode, pDb); pShow->numOfReads += numOfRows; mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); return numOfRows; @@ -891,4 +912,4 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 59161b32f290ff7c2eb9c4b724c8d43257f51ca0..6a2fca836f1c3446aad94d96aa267c56df46e459 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -14,23 +14,54 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "mndInt.h" -#include "mndTrans.h" +#include "mndSync.h" -int32_t mndInitSync(SMnode *pMnode) { return 0; } -void mndCleanupSync(SMnode *pMnode) {} +int32_t mndInitSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_init(&pMgmt->syncSem, 0, 0); + + pMgmt->state = TAOS_SYNC_STATE_LEADER; + pMgmt->pSyncNode = NULL; + return 0; +} + +void mndCleanupSync(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + tsem_destroy(&pMgmt->syncSem); +} + +static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { + SMnode *pMnode = pData; + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + + pMgmt->errCode = 0; + tsem_post(&pMgmt->syncSem); + + return 0; +} int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { - int32_t code = 0; +#if 1 + return 0; +#else + if (pMnode->replica == 1) return 0; + + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + pMgmt->errCode = 0; + + SSyncBuffer buf = {.data = pRaw, .len = sdbGetRawTotalSize(pRaw)}; + + bool isWeak = false; + int32_t code = syncPropose(pMgmt->pSyncNode, &buf, pMnode, isWeak); - // int32_t len = sdbGetRawTotalSize(pRaw); - // SSdbRaw *pReceived = calloc(1, len); - // memcpy(pReceived, pRaw, len); - // mDebug("trans:%d, data:%p recv from sync, code:0x%x pMsg:%p", pMsg->id, pReceived, code & 0xFFFF, pMsg); + if (code != 0) return code; - // mndTransApply(pMnode, pReceived, code); - return code; + tsem_wait(&pMgmt->syncSem); + return pMgmt->errCode; +#endif } -bool mndIsMaster(SMnode *pMnode) { return true; } \ No newline at end of file +bool mndIsMaster(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + return pMgmt->state == TAOS_SYNC_STATE_LEADER; +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c new file mode 100644 index 0000000000000000000000000000000000000000..24e32e07b47c7eb5e4f0f500a7a0b76ce3c0d578 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -0,0 +1,496 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#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_TOPIC_VER_NUMBER 1 +#define MND_TOPIC_RESERVE_SIZE 64 + +static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic); +static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw); +static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic); +static int32_t mndTopicActionDelete(SSdb *pSdb, STopicObj *pTopic); +static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pTopic, STopicObj *pNewTopic); +static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg); +static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg); +static int32_t mndProcessDropTopicInRsp(SMnodeMsg *pMsg); +static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg); +static int32_t mndGetTopicMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveTopic(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter); + +int32_t mndInitTopic(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_TOPIC, + .keyType = SDB_KEY_BINARY, + .encodeFp = (SdbEncodeFp)mndTopicActionEncode, + .decodeFp = (SdbDecodeFp)mndTopicActionDecode, + .insertFp = (SdbInsertFp)mndTopicActionInsert, + .updateFp = (SdbUpdateFp)mndTopicActionUpdate, + .deleteFp = (SdbDeleteFp)mndTopicActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TOPIC, mndProcessCreateTopicMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicMsg); + mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndProcessDropTopicInRsp); + + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupTopic(SMnode *pMnode) {} + +static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { + int32_t size = sizeof(STopicObj) + MND_TOPIC_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); + if (pRaw == NULL) return NULL; + + int32_t dataPos = 0; + SDB_SET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); + SDB_SET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_LEN); + SDB_SET_INT64(pRaw, dataPos, pTopic->createTime); + SDB_SET_INT64(pRaw, dataPos, pTopic->updateTime); + SDB_SET_INT64(pRaw, dataPos, pTopic->uid); + SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid); + SDB_SET_INT32(pRaw, dataPos, pTopic->version); + SDB_SET_INT32(pRaw, dataPos, pTopic->execLen); + SDB_SET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen); + SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen); + SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen); + + SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE); + SDB_SET_DATALEN(pRaw, dataPos); + + return pRaw; +} + +static SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + + if (sver != MND_TOPIC_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + mError("failed to decode topic since %s", terrstr()); + return NULL; + } + + int32_t size = sizeof(STopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + SSdbRow *pRow = sdbAllocRow(size); + STopicObj *pTopic = sdbGetRowObj(pRow); + if (pTopic == NULL) return NULL; + + int32_t dataPos = 0; + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->db, TSDB_DB_FNAME_LEN); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->createTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->updateTime); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->uid); + SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->dbUid); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->version); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->execLen); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->executor, pTopic->execLen); + SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->sqlLen); + SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->sql, pTopic->sqlLen); + + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TOPIC_RESERVE_SIZE); + + return pRow; +} + +static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic) { + mTrace("topic:%s, perform insert action", pTopic->name); + return 0; +} + +static int32_t mndTopicActionDelete(SSdb *pSdb, STopicObj *pTopic) { + mTrace("topic:%s, perform delete action", pTopic->name); + return 0; +} + +static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj *pNewTopic) { + mTrace("topic:%s, perform update action", pOldTopic->name); + atomic_exchange_32(&pOldTopic->updateTime, pNewTopic->updateTime); + atomic_exchange_32(&pOldTopic->version, pNewTopic->version); + + taosWLockLatch(&pOldTopic->lock); + + //TODO handle update + + taosWUnLockLatch(&pOldTopic->lock); + return 0; +} + +STopicObj *mndAcquireTopic(SMnode *pMnode, char *topicName) { + SSdb *pSdb = pMnode->pSdb; + STopicObj *pTopic = sdbAcquire(pSdb, SDB_TOPIC, topicName); + if (pTopic == NULL) { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + } + return pTopic; +} + +void mndReleaseTopic(SMnode *pMnode, STopicObj *pTopic) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pTopic); +} + +static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) { + SName name = {0}; + tNameFromString(&name, topicName, T_NAME_ACCT | T_NAME_DB | T_NAME_TOPIC); + + char db[TSDB_TABLE_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, db); + + return mndAcquireDb(pMnode, db); +} + +static SDDropTopicMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, STopicObj *pTopic) { + int32_t contLen = sizeof(SDDropTopicMsg); + + SDDropTopicMsg *pDrop = calloc(1, contLen); + if (pDrop == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pDrop->head.contLen = htonl(contLen); + pDrop->head.vgId = htonl(pVgroup->vgId); + memcpy(pDrop->name, pTopic->name, TSDB_TABLE_FNAME_LEN); + pDrop->tuid = htobe64(pTopic->uid); + + return pDrop; +} + +static int32_t mndCheckCreateTopicMsg(SCMCreateTopicReq *pCreate) { + // deserialize and other stuff + return 0; +} + +static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCMCreateTopicReq *pCreate, SDbObj *pDb) { + STopicObj topicObj = {0}; + tstrncpy(topicObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); + tstrncpy(topicObj.db, pDb->name, TSDB_DB_FNAME_LEN); + topicObj.createTime = taosGetTimestampMs(); + topicObj.updateTime = topicObj.createTime; + topicObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); + topicObj.dbUid = pDb->uid; + topicObj.version = 1; + + SSdbRaw *pTopicRaw = mndTopicActionEncode(&topicObj); + if (pTopicRaw == NULL) return -1; + if (sdbSetRawStatus(pTopicRaw, SDB_STATUS_READY) != 0) return -1; + return sdbWrite(pMnode->pSdb, pTopicRaw); +} + +static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + char *msgStr = pMsg->rpcMsg.pCont; + SCMCreateTopicReq* pCreate; + tDeserializeSCMCreateTopicReq(msgStr, pCreate); + + mDebug("topic:%s, start to create", pCreate->name); + + if (mndCheckCreateTopicMsg(pCreate) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + STopicObj *pTopic = mndAcquireTopic(pMnode, pCreate->name); + if (pTopic != NULL) { + sdbRelease(pMnode->pSdb, pTopic); + if (pCreate->igExists) { + mDebug("topic:%s, already exist, ignore exist is set", pCreate->name); + return 0; + } else { + terrno = TSDB_CODE_MND_TOPIC_ALREADY_EXIST; + mError("db:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + } + + SDbObj *pDb = mndAcquireDbByTopic(pMnode, pCreate->name); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + int32_t code = mndCreateTopic(pMnode, pMsg, pCreate, pDb); + mndReleaseDb(pMnode, pDb); + + if (code != 0) { + terrno = code; + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndDropTopic(SMnode *pMnode, SMnodeMsg *pMsg, STopicObj *pTopic) { + return 0; +} + +static int32_t mndProcessDropTopicMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + SDropTopicMsg *pDrop = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to drop", pDrop->name); + + STopicObj *pTopic = mndAcquireTopic(pMnode, pDrop->name); + if (pTopic == NULL) { + if (pDrop->igNotExists) { + mDebug("topic:%s, not exist, ignore not exist is set", pDrop->name); + return 0; + } else { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + mError("topic:%s, failed to drop since %s", pDrop->name, terrstr()); + return -1; + } + } + + int32_t code = mndDropTopic(pMnode, pMsg, pTopic); + mndReleaseTopic(pMnode, pTopic); + + if (code != 0) { + terrno = code; + mError("topic:%s, failed to drop since %s", pDrop->name, terrstr()); + return -1; + } + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +static int32_t mndProcessDropTopicInRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; + + mDebug("topic:%s, start to retrieve meta", pInfo->tableFname); + +#if 0 + SDbObj *pDb = mndAcquireDbByTopic(pMnode, pInfo->tableFname); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + mError("topic:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + STopicObj *pTopic = mndAcquireTopic(pMnode, pInfo->tableFname); + if (pTopic == NULL) { + mndReleaseDb(pMnode, pDb); + terrno = TSDB_CODE_MND_INVALID_TOPIC; + mError("topic:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + taosRLockLatch(&pTopic->lock); + int32_t totalCols = pTopic->numOfColumns + pTopic->numOfTags; + int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema); + + STableMetaMsg *pMeta = rpcMallocCont(contLen); + if (pMeta == NULL) { + taosRUnLockLatch(&pTopic->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseTopic(pMnode, pTopic); + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("topic:%s, failed to get meta since %s", pInfo->tableFname, terrstr()); + return -1; + } + + memcpy(pMeta->topicFname, pTopic->name, TSDB_TABLE_FNAME_LEN); + pMeta->numOfTags = htonl(pTopic->numOfTags); + pMeta->numOfColumns = htonl(pTopic->numOfColumns); + pMeta->precision = pDb->cfg.precision; + pMeta->tableType = TSDB_SUPER_TABLE; + pMeta->update = pDb->cfg.update; + pMeta->sversion = htonl(pTopic->version); + pMeta->tuid = htonl(pTopic->uid); + + for (int32_t i = 0; i < totalCols; ++i) { + SSchema *pSchema = &pMeta->pSchema[i]; + SSchema *pSrcSchema = &pTopic->pSchema[i]; + memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); + pSchema->type = pSrcSchema->type; + pSchema->colId = htonl(pSrcSchema->colId); + pSchema->bytes = htonl(pSrcSchema->bytes); + } + taosRUnLockLatch(&pTopic->lock); + mndReleaseDb(pMnode, pDb); + mndReleaseTopic(pMnode, pTopic); + + pMsg->pCont = pMeta; + pMsg->contLen = contLen; + + mDebug("topic:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pTopic->numOfColumns, pTopic->numOfTags); +#endif + return 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) { + STopicObj *pTopic = NULL; + pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic); + if (pIter == NULL) break; + + if (strcmp(pTopic->db, dbName) == 0) { + numOfTopics++; + } + + sdbRelease(pSdb, pTopic); + } + + *pNumOfTopics = numOfTopics; + return 0; +} + +static int32_t mndGetTopicMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + + if (mndGetNumOfTopics(pMnode, pShow->db, &pShow->numOfRows) != 0) { + return -1; + } + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchema; + + 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 = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "columns"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "tags"); + pSchema[cols].bytes = htonl(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htonl(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_TOPIC); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); + + return 0; +} + +static void mndExtractTableName(char *tableId, char *name) { + int32_t pos = -1; + int32_t num = 0; + for (pos = 0; tableId[pos] != 0; ++pos) { + if (tableId[pos] == '.') num++; + if (num == 2) break; + } + + if (num == 2) { + strcpy(name, tableId + pos + 1); + } +} + +static int32_t mndRetrieveTopic(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pMsg->pMnode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + STopicObj *pTopic = NULL; + int32_t cols = 0; + char *pWrite; + char prefix[64] = {0}; + + tstrncpy(prefix, pShow->db, 64); + strcat(prefix, TS_PATH_DELIMITER); + int32_t prefixLen = (int32_t)strlen(prefix); + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_TOPIC, pShow->pIter, (void **)&pTopic); + if (pShow->pIter == NULL) break; + + if (strncmp(pTopic->name, prefix, prefixLen) != 0) { + sdbRelease(pSdb, pTopic); + continue; + } + + cols = 0; + + char topicName[TSDB_TABLE_NAME_LEN] = {0}; + tstrncpy(topicName, pTopic->name + prefixLen, TSDB_TABLE_NAME_LEN); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, topicName); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pTopic->createTime; + cols++; + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pTopic->numOfColumns;*/ + /*cols++;*/ + + /*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/ + /**(int32_t *)pWrite = pTopic->numOfTags;*/ + /*cols++;*/ + + numOfRows++; + sdbRelease(pSdb, pTopic); + } + + pShow->numOfReads += numOfRows; + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + return numOfRows; +} + +static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 54cd6ab501a0a9294b0f35e575c365d44e14b7bd..9263fca695c8625b8364503fb859bae93b7fb44f 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -17,9 +17,9 @@ #include "mndTrans.h" #include "mndSync.h" -#define TSDB_TRANS_VER_NUMBER 1 -#define TSDB_TRN_ARRAY_SIZE 8 -#define TSDB_TRN_RESERVE_SIZE 64 +#define MND_TRANS_VER_NUMBER 1 +#define MND_TRANS_ARRAY_SIZE 8 +#define MND_TRANS_RESERVE_SIZE 64 static SSdbRaw *mndTransActionEncode(STrans *pTrans); static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw); @@ -27,8 +27,6 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans); static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOldTrans); static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans); -static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle); -static void mndTransSendRpcRsp(STrans *pTrans, int32_t code); static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw); static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction); static void mndTransDropLogs(SArray *pArray); @@ -37,14 +35,23 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray); static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray); static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans); static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans); -static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans); +static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformUndoLogStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans); +static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); + static void mndTransExecute(SMnode *pMnode, STrans *pTrans); +static void mndTransSendRpcRsp(STrans *pTrans); +static int32_t mndProcessTransMsg(SMnodeMsg *pMsg); +static int32_t mndProcessTransRsp(SMnodeMsg *pMsg); int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, @@ -55,13 +62,15 @@ int32_t mndInitTrans(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndTransActionUpdate, .deleteFp = (SdbDeleteFp)mndTransActionDelete}; + mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransMsg); + mndSetMsgHandle(pMnode, TDMT_MND_TRANS_RSP, mndProcessTransRsp); return sdbSetTable(pMnode->pSdb, table); } void mndCleanupTrans(SMnode *pMnode) {} static SSdbRaw *mndTransActionEncode(STrans *pTrans) { - int32_t rawDataLen = sizeof(STrans) + TSDB_TRN_RESERVE_SIZE; + int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE; int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs); @@ -93,7 +102,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { rawDataLen += (sizeof(STransAction) + pAction->contLen); } - SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER_NUMBER, rawDataLen); + SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, MND_TRANS_VER_NUMBER, rawDataLen); if (pRaw == NULL) { mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr()); return NULL; @@ -132,7 +141,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { for (int32_t i = 0; i < redoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->redoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT8(pRaw, dataPos, pAction->msgType) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType) SDB_SET_INT32(pRaw, dataPos, pAction->contLen) SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen); } @@ -140,12 +149,12 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { for (int32_t i = 0; i < undoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->undoActions, i); SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT8(pRaw, dataPos, pAction->msgType) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType) SDB_SET_INT32(pRaw, dataPos, pAction->contLen) SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen); } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_TRN_RESERVE_SIZE) + SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE) SDB_SET_DATALEN(pRaw, dataPos); mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos); return pRaw; @@ -155,12 +164,9 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { int32_t code = 0; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) { - mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr()); - return NULL; - } + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; - if (sver != TSDB_TRANS_VER_NUMBER) { + if (sver != MND_TRANS_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; mError("failed to get check soft ver from raw:%p since %s", pRaw, terrstr()); return NULL; @@ -173,11 +179,11 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { return NULL; } - pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); - pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); + pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); + pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || pTrans->redoActions == NULL || pTrans->undoActions == NULL) { @@ -243,7 +249,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < redoActionNum; ++i) { STransAction action = {0}; SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType) + SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) action.pCont = malloc(action.contLen); if (action.pCont == NULL) { @@ -262,7 +268,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < undoActionNum; ++i) { STransAction action = {0}; SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType) + SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) action.pCont = malloc(action.contLen); if (action.pCont == NULL) { @@ -278,7 +284,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { } } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_TRN_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TRANS_RESERVE_SIZE) TRANS_DECODE_OVER: if (code != 0) { @@ -288,18 +294,18 @@ TRANS_DECODE_OVER: return NULL; } - mTrace("trans:%d, decode from raw:%p", pTrans->id, pRaw); + mTrace("trans:%d, decode from raw:%p, data:%p", pTrans->id, pRaw, pTrans); return pRow; } static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { pTrans->stage = TRN_STAGE_PREPARE; - mTrace("trans:%d, perform insert action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage)); + mTrace("trans:%d, perform insert action, data:%p", pTrans->id, pTrans); return 0; } static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { - mTrace("trans:%d, perform delete action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage)); + mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); mndTransDropLogs(pTrans->redoLogs); mndTransDropLogs(pTrans->undoLogs); @@ -311,7 +317,7 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { } static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) { - mTrace("trans:%d, perform update action, stage:%s", pOldTrans->id, mndTransStageStr(pNewTrans->stage)); + mTrace("trans:%d, perform update action, data:%p", pOldTrans->id, pOldTrans); pOldTrans->stage = pNewTrans->stage; return 0; } @@ -330,35 +336,7 @@ void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) { sdbRelease(pSdb, pTrans); } -char *mndTransStageStr(ETrnStage stage) { - switch (stage) { - case TRN_STAGE_PREPARE: - return "prepare"; - case TRN_STAGE_EXECUTE: - return "execute"; - case TRN_STAGE_COMMIT: - return "commit"; - case TRN_STAGE_ROLLBACK: - return "rollback"; - case TRN_STAGE_OVER: - return "over"; - default: - return "undefined"; - } -} - -char *mndTransPolicyStr(ETrnPolicy policy) { - switch (policy) { - case TRN_POLICY_ROLLBACK: - return "prepare"; - case TRN_POLICY_RETRY: - return "retry"; - default: - return "undefined"; - } -} - -STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) { STrans *pTrans = calloc(1, sizeof(STrans)); if (pTrans == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -369,12 +347,13 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS); pTrans->stage = TRN_STAGE_PREPARE; pTrans->policy = policy; - pTrans->rpcHandle = rpcHandle; - pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *)); - pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); - pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction)); + pTrans->rpcHandle = pMsg->handle; + pTrans->rpcAHandle = pMsg->ahandle; + pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->commitLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); + pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); + pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || pTrans->redoActions == NULL || pTrans->undoActions == NULL) { @@ -383,14 +362,14 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { return NULL; } - mDebug("trans:%d, is created", pTrans->id); + mDebug("trans:%d, is created, data:%p", pTrans->id, pTrans); return pTrans; } static void mndTransDropLogs(SArray *pArray) { for (int32_t i = 0; i < pArray->size; ++i) { SSdbRaw *pRaw = taosArrayGetP(pArray, i); - tfree(pRaw); + sdbFreeRaw(pRaw); } taosArrayDestroy(pArray); @@ -412,15 +391,10 @@ void mndTransDrop(STrans *pTrans) { mndTransDropActions(pTrans->redoActions); mndTransDropActions(pTrans->undoActions); - // mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans); + mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans); tfree(pTrans); } -static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) { - pTrans->rpcHandle = rpcHandle; - mTrace("trans:%d, set rpc handle:%p", pTrans->id, rpcHandle); -} - static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) { if (pArray == NULL || pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -436,23 +410,11 @@ static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) { return 0; } -int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = mndTransAppendLog(pTrans->redoLogs, pRaw); - mTrace("trans:%d, raw:%p append to redo logs, code:0x%x", pTrans->id, pRaw, code); - return code; -} +int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) { return mndTransAppendLog(pTrans->redoLogs, pRaw); } -int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = mndTransAppendLog(pTrans->undoLogs, pRaw); - mTrace("trans:%d, raw:%p append to undo logs, code:0x%x", pTrans->id, pRaw, code); - return code; -} +int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) { return mndTransAppendLog(pTrans->undoLogs, pRaw); } -int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = mndTransAppendLog(pTrans->commitLogs, pRaw); - mTrace("trans:%d, raw:%p append to commit logs, code:0x%x", pTrans->id, pRaw, code); - return code; -} +int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) { return mndTransAppendLog(pTrans->commitLogs, pRaw); } static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) { void *ptr = taosArrayPush(pArray, pAction); @@ -465,20 +427,14 @@ static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) { } int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction) { - int32_t code = mndTransAppendAction(pTrans->redoActions, pAction); - mTrace("trans:%d, msg:%s append to redo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code); - return code; + return mndTransAppendAction(pTrans->redoActions, pAction); } int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction) { - int32_t code = mndTransAppendAction(pTrans->undoActions, pAction); - mTrace("trans:%d, msg:%s append to undo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code); - return code; + return mndTransAppendAction(pTrans->undoActions, pAction); } -int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { - mDebug("trans:%d, prepare transaction", pTrans->id); - +static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) { SSdbRaw *pRaw = mndTransActionEncode(pTrans); if (pRaw == NULL) { mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr()); @@ -486,7 +442,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { } sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mTrace("trans:%d, sync to other nodes", pTrans->id); + mDebug("trans:%d, sync to other nodes", pTrans->id); int32_t code = mndSyncPropose(pMnode, pRaw); if (code != 0) { mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); @@ -494,7 +450,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { return -1; } - mTrace("trans:%d, sync finished", pTrans->id); + mDebug("trans:%d, sync finished", pTrans->id); code = sdbWrite(pMnode->pSdb, pRaw); if (code != 0) { @@ -502,97 +458,65 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { return -1; } + return 0; +} + +int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { + mDebug("trans:%d, prepare transaction", pTrans->id); + if (mndTransSync(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + return -1; + } + mDebug("trans:%d, prepare finished", pTrans->id); + STrans *pNewTrans = mndAcquireTrans(pMnode, pTrans->id); if (pNewTrans == NULL) { - mError("trans:%d, failed to ready from sdb since %s", pTrans->id, terrstr()); + mError("trans:%d, failed to read from sdb since %s", pTrans->id, terrstr()); return -1; } pNewTrans->rpcHandle = pTrans->rpcHandle; + pNewTrans->rpcAHandle = pTrans->rpcAHandle; mndTransExecute(pMnode, pNewTrans); mndReleaseTrans(pMnode, pNewTrans); return 0; } -int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) { - mDebug("trans:%d, commit transaction", pTrans->id); +static int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) { + if (taosArrayGetSize(pTrans->commitLogs) == 0 && taosArrayGetSize(pTrans->redoActions) == 0) return 0; - SSdbRaw *pRaw = mndTransActionEncode(pTrans); - if (pRaw == NULL) { - mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr()); + mDebug("trans:%d, commit transaction", pTrans->id); + if (mndTransSync(pMnode, pTrans) != 0) { + mError("trans:%d, failed to commit since %s", pTrans->id, terrstr()); return -1; } - sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); - - if (taosArrayGetSize(pTrans->commitLogs) != 0) { - mTrace("trans:%d, sync to other nodes", pTrans->id); - int32_t code = mndSyncPropose(pMnode, pRaw); - if (code != 0) { - mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); - sdbFreeRaw(pRaw); - return -1; - } - - mTrace("trans:%d, sync finished", pTrans->id); - code = sdbWrite(pMnode->pSdb, pRaw); - if (code != 0) { - mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); - return -1; - } - } - mDebug("trans:%d, commit finished", pTrans->id); return 0; } -int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { +static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { mDebug("trans:%d, rollback transaction", pTrans->id); - - SSdbRaw *pRaw = mndTransActionEncode(pTrans); - if (pRaw == NULL) { - mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr()); - return -1; - } - sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); - - mTrace("trans:%d, sync to other nodes", pTrans->id); - int32_t code = mndSyncPropose(pMnode, pRaw); - if (code != 0) { - mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); - sdbFreeRaw(pRaw); + if (mndTransSync(pMnode, pTrans) != 0) { + mError("trans:%d, failed to rollback since %s", pTrans->id, terrstr()); return -1; } - - mTrace("trans:%d, sync finished", pTrans->id); - code = sdbWrite(pMnode->pSdb, pRaw); - if (code != 0) { - mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); - return -1; - } - mDebug("trans:%d, rollback finished", pTrans->id); return 0; } -static void mndTransSendRpcRsp(STrans *pTrans, int32_t code) { - if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; - mDebug("trans:%d, send rpc rsp, RPC:%p code:0x%x", pTrans->id, pTrans->rpcHandle, code & 0xFFFF); - +static void mndTransSendRpcRsp(STrans *pTrans) { if (pTrans->rpcHandle != NULL) { - SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = code}; + mDebug("trans:%d, send rsp, ahandle:%p code:0x%x", pTrans->id, pTrans->rpcAHandle, pTrans->code & 0xFFFF); + SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; rpcSendResponse(&rspMsg); } } -void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code) { - // todo -} - -void mndTransHandleActionRsp(SMnodeMsg *pMsg) { +void mndTransProcessRsp(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; - int64_t sig = (int64_t)(pMsg->rpcMsg.ahandle); - int32_t transId = (int32_t)(sig >> 32); - int32_t action = (int32_t)((sig << 32) >> 32); + int64_t signature = (int64_t)(pMsg->rpcMsg.ahandle); + int32_t transId = (int32_t)(signature >> 32); + int32_t action = (int32_t)((signature << 32) >> 32); STrans *pTrans = mndAcquireTrans(pMnode, transId); if (pTrans == NULL) { @@ -601,20 +525,22 @@ void mndTransHandleActionRsp(SMnodeMsg *pMsg) { } SArray *pArray = NULL; - if (pTrans->stage == TRN_STAGE_EXECUTE) { + if (pTrans->stage == TRN_STAGE_REDO_ACTION) { pArray = pTrans->redoActions; - } else if (pTrans->stage == TRN_STAGE_ROLLBACK) { + } else if (pTrans->stage == TRN_STAGE_UNDO_ACTION) { pArray = pTrans->undoActions; } else { + mError("trans:%d, invalid trans stage:%d while recv action rsp", pTrans->id, pTrans->stage); + goto HANDLE_ACTION_RSP_OVER; } if (pArray == NULL) { - mError("trans:%d, invalid trans stage:%s", transId, mndTransStageStr(pTrans->stage)); + mError("trans:%d, invalid trans stage:%d", transId, pTrans->stage); goto HANDLE_ACTION_RSP_OVER; } int32_t actionNum = taosArrayGetSize(pTrans->redoActions); - if (action < 0 || action > actionNum) { + if (action < 0 || action >= actionNum) { mError("trans:%d, invalid action:%d", transId, action); goto HANDLE_ACTION_RSP_OVER; } @@ -622,10 +548,10 @@ void mndTransHandleActionRsp(SMnodeMsg *pMsg) { STransAction *pAction = taosArrayGet(pArray, action); if (pAction != NULL) { pAction->msgReceived = 1; - pAction->errCode = pMsg->code; + pAction->errCode = pMsg->rpcMsg.code; } - mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->code); + mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->rpcMsg.code); mndTransExecute(pMnode, pTrans); HANDLE_ACTION_RSP_OVER: @@ -636,6 +562,8 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) { SSdb *pSdb = pMnode->pSdb; int32_t arraySize = taosArrayGetSize(pArray); + if (arraySize == 0) return 0; + for (int32_t i = 0; i < arraySize; ++i) { SSdbRaw *pRaw = taosArrayGetP(pArray, i); int32_t code = sdbWriteNotFree(pSdb, pRaw); @@ -648,50 +576,34 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) { } static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->redoLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->redoLogs); - if (code != 0) { - mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute redo logs finished", pTrans->id) - } - } - - return code; + return mndTransExecuteLogs(pMnode, pTrans->redoLogs); } static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->undoLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->undoLogs); - if (code != 0) { - mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute undo logs finished", pTrans->id) - } - } - - return code; + return mndTransExecuteLogs(pMnode, pTrans->undoLogs); } static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; - if (taosArrayGetSize(pTrans->commitLogs) != 0) { - code = mndTransExecuteLogs(pMnode, pTrans->commitLogs); - if (code != 0) { - mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr()) - } else { - mDebug("trans:%d, execute commit logs finished", pTrans->id) - } - } + return mndTransExecuteLogs(pMnode, pTrans->commitLogs); +} + +static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) { + int32_t numOfActions = taosArrayGetSize(pArray); - return code; + for (int32_t action = 0; action < numOfActions; ++action) { + STransAction *pAction = taosArrayGet(pArray, action); + if (pAction == NULL) continue; + if (pAction->msgSent && pAction->msgReceived && pAction->errCode == 0) continue; + + pAction->msgSent = 0; + pAction->msgReceived = 0; + pAction->errCode = 0; + mDebug("trans:%d, action:%d is reset and will be re-executed", pTrans->id, action); + } } -static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) { +static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pArray) { int32_t numOfActions = taosArrayGetSize(pArray); - if (numOfActions == 0) return 0; for (int32_t action = 0; action < numOfActions; ++action) { STransAction *pAction = taosArrayGet(pArray, action); @@ -718,24 +630,42 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg); } - int32_t numOfReceivedMsgs = 0; - int32_t errorCode = 0; + return 0; +} + +static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) { + int32_t numOfActions = taosArrayGetSize(pArray); + if (numOfActions == 0) return 0; + + if (mndTransSendActionMsg(pMnode, pTrans, pArray) != 0) { + return -1; + } + + int32_t numOfReceived = 0; + int32_t errCode = 0; for (int32_t action = 0; action < numOfActions; ++action) { STransAction *pAction = taosArrayGet(pArray, action); if (pAction == NULL) continue; if (pAction->msgSent && pAction->msgReceived) { - numOfReceivedMsgs++; + numOfReceived++; if (pAction->errCode != 0) { - errorCode = pAction->errCode; + errCode = pAction->errCode; } } } - if (numOfReceivedMsgs == numOfActions) { - mDebug("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errorCode); - terrno = errorCode; - return errorCode; + if (numOfReceived == numOfActions) { + if (errCode == 0) { + mDebug("trans:%d, all %d actions execute successfully", pTrans->id, numOfActions); + return 0; + } else { + mError("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errCode); + mndTransResetActions(pMnode, pTrans, pArray); + terrno = errCode; + return errCode; + } } else { + mDebug("trans:%d, %d of %d actions executed, code:0x%x", pTrans->id, numOfReceived, numOfActions, errCode); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } } @@ -748,89 +678,231 @@ static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) { return mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions); } -static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) { +static bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + pTrans->stage = TRN_STAGE_REDO_LOG; + mDebug("trans:%d, stage from prepare to redoLog", pTrans->id); + return continueExec; +} + +static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; int32_t code = mndTransExecuteRedoLogs(pMnode, pTrans); if (code == 0) { - pTrans->stage = TRN_STAGE_EXECUTE; - mDebug("trans:%d, stage from prepare to execute", pTrans->id); + pTrans->code = 0; + pTrans->stage = TRN_STAGE_REDO_ACTION; + mDebug("trans:%d, stage from redoLog to redoAction", pTrans->id); } else { - pTrans->stage = TRN_STAGE_ROLLBACK; - mError("trans:%d, stage from prepare to rollback since %s", pTrans->id, terrstr()); + pTrans->code = terrno; + pTrans->stage = TRN_STAGE_UNDO_LOG; + mError("trans:%d, stage from redoLog to undoLog", pTrans->id); } - return 0; + return continueExec; } -static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) { +static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; int32_t code = mndTransExecuteRedoActions(pMnode, pTrans); if (code == 0) { + pTrans->code = 0; pTrans->stage = TRN_STAGE_COMMIT; - mDebug("trans:%d, stage from execute to commit", pTrans->id); + mDebug("trans:%d, stage from redoAction to commit", pTrans->id); + continueExec = true; } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mDebug("trans:%d, stage keep on execute since %s", pTrans->id, tstrerror(code)); - return code; + mDebug("trans:%d, stage keep on redoAction since %s", pTrans->id, tstrerror(code)); + continueExec = false; } else { + pTrans->code = terrno; if (pTrans->policy == TRN_POLICY_ROLLBACK) { - pTrans->stage = TRN_STAGE_ROLLBACK; - mError("trans:%d, stage from execute to rollback since %s", pTrans->id, terrstr()); + pTrans->stage = TRN_STAGE_UNDO_ACTION; + mError("trans:%d, stage from redoAction to undoAction since %s", pTrans->id, terrstr()); + continueExec = true; } else { - pTrans->stage = TRN_STAGE_EXECUTE; - mError("trans:%d, stage keep on execute since %s", pTrans->id, terrstr()); + pTrans->failedTimes++; + mError("trans:%d, stage keep on redoAction since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes); + continueExec = false; } } - return 0; + return continueExec; } -static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) { - mndTransExecuteCommitLogs(pMnode, pTrans); - pTrans->stage = TRN_STAGE_OVER; - return 0; +static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + int32_t code = mndTransCommit(pMnode, pTrans); + + if (code == 0) { + pTrans->code = 0; + pTrans->stage = TRN_STAGE_COMMIT_LOG; + mDebug("trans:%d, stage from commit to commitLog", pTrans->id); + continueExec = true; + } else { + pTrans->code = terrno; + if (pTrans->policy == TRN_POLICY_ROLLBACK) { + pTrans->stage = TRN_STAGE_REDO_ACTION; + mError("trans:%d, stage from commit to redoAction since %s, failedTimes:%d", pTrans->id, terrstr(), + pTrans->failedTimes); + continueExec = true; + } else { + pTrans->failedTimes++; + mError("trans:%d, stage keep on commit since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes); + continueExec = false; + } + } + + return continueExec; } -static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { - int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); +static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + int32_t code = mndTransExecuteCommitLogs(pMnode, pTrans); if (code == 0) { - mDebug("trans:%d, rollbacked", pTrans->id); + pTrans->code = 0; + pTrans->stage = TRN_STAGE_FINISHED; + mDebug("trans:%d, stage from commitLog to finished", pTrans->id); + continueExec = true; } else { + pTrans->code = terrno; + pTrans->failedTimes++; + mError("trans:%d, stage keep on commitLog since %s", pTrans->id, terrstr()); + continueExec = false; + ; + } + + return continueExec; +} + +static bool mndTransPerformUndoLogStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + int32_t code = mndTransExecuteUndoLogs(pMnode, pTrans); + + if (code == 0) { pTrans->stage = TRN_STAGE_ROLLBACK; + mDebug("trans:%d, stage from undoLog to rollback", pTrans->id); + continueExec = true; + } else { + mDebug("trans:%d, stage keep on undoLog since %s", pTrans->id, terrstr()); + continueExec = false; + } + + return continueExec; +} + +static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); + + if (code == 0) { + pTrans->stage = TRN_STAGE_REDO_LOG; + mDebug("trans:%d, stage from undoAction to undoLog", pTrans->id); + continueExec = true; + } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mDebug("trans:%d, stage keep on undoAction since %s", pTrans->id, tstrerror(code)); + continueExec = false; + } else { + pTrans->failedTimes++; + mError("trans:%d, stage keep on undoAction since %s", pTrans->id, terrstr()); + continueExec = false; + } + + return continueExec; +} + +static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = true; + int32_t code = mndTransRollback(pMnode, pTrans); + + if (code == 0) { + pTrans->stage = TRN_STAGE_FINISHED; + mDebug("trans:%d, stage from rollback to finished", pTrans->id); + continueExec = true; + ; + } else { + pTrans->failedTimes++; mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr()); + continueExec = false; } - return code; + return continueExec; +} + +static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) { + bool continueExec = false; + + SSdbRaw *pRaw = mndTransActionEncode(pTrans); + if (pRaw == NULL) { + mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr()); + } + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + + int32_t code = sdbWrite(pMnode->pSdb, pRaw); + if (code != 0) { + mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr()); + } + + mDebug("trans:%d, finished, code:0x%x, failedTimes:%d", pTrans->id, pTrans->code, pTrans->failedTimes); + return continueExec; } static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { - int32_t code = 0; + bool continueExec = true; - while (code == 0) { + while (continueExec) { switch (pTrans->stage) { case TRN_STAGE_PREPARE: - code = mndTransPerformPrepareStage(pMnode, pTrans); + continueExec = mndTransPerformPrepareStage(pMnode, pTrans); + break; + case TRN_STAGE_REDO_LOG: + continueExec = mndTransPerformRedoLogStage(pMnode, pTrans); + break; + case TRN_STAGE_REDO_ACTION: + continueExec = mndTransPerformRedoActionStage(pMnode, pTrans); + break; + case TRN_STAGE_UNDO_LOG: + continueExec = mndTransPerformUndoLogStage(pMnode, pTrans); + break; + case TRN_STAGE_UNDO_ACTION: + continueExec = mndTransPerformUndoActionStage(pMnode, pTrans); break; - case TRN_STAGE_EXECUTE: - code = mndTransPerformExecuteStage(pMnode, pTrans); + case TRN_STAGE_COMMIT_LOG: + continueExec = mndTransPerformCommitLogStage(pMnode, pTrans); break; case TRN_STAGE_COMMIT: - code = mndTransCommit(pMnode, pTrans); - if (code == 0) { - mndTransPerformCommitStage(pMnode, pTrans); - } + continueExec = mndTransPerformCommitStage(pMnode, pTrans); break; case TRN_STAGE_ROLLBACK: - code = mndTransPerformRollbackStage(pMnode, pTrans); - if (code == 0) { - code = mndTransRollback(pMnode, pTrans); - } + continueExec = mndTransPerformRollbackStage(pMnode, pTrans); + break; + case TRN_STAGE_FINISHED: + continueExec = mndTransPerfromFinishedStage(pMnode, pTrans); break; default: - mndTransSendRpcRsp(pTrans, 0); - return; + continueExec = false; + break; } } - mndTransSendRpcRsp(pTrans, code); + if (pTrans->stage == TRN_STAGE_FINISHED) { + mndTransSendRpcRsp(pTrans); + } +} + +static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + STrans *pTrans = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans); + if (pIter == NULL) break; + + mndTransExecute(pMnode, pTrans); + sdbRelease(pMnode->pSdb, pTrans); + } } + +static int32_t mndProcessTransRsp(SMnodeMsg *pMsg) { return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index c96e6a80db3ec6b19f1ea609632a8022c65dad79..0926cf0c48db62d80e3114f3dd55a98730f14795 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -47,9 +47,9 @@ int32_t mndInitUser(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_USER, mndProcessAlterUserMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_USER, mndProcessDropUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); @@ -197,7 +197,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, userObj.updateTime = userObj.createdTime; userObj.superUser = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to create since %s", user, terrstr()); return -1; @@ -267,7 +267,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { } static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to update since %s", pOldUser->user, terrstr()); return -1; @@ -342,7 +342,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { } static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to drop since %s", pUser->user, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index c65436efcb844d3b9387fdc9467673205d03d4dc..1b0026cd139ea298d12ec3fa143bf2be3e1b3f8e 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -51,11 +51,11 @@ int32_t mndInitVgroup(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndVgroupActionDelete, .deleteFp = (SdbDeleteFp)mndVgroupActionUpdate}; - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP, mndProcessCreateVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP, mndProcessAlterVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_VNODE_IN_RSP, mndProcessDropVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP, mndProcessSyncVnodeRsp); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP, mndProcessCompactVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_CREATE_VNODE_RSP, mndProcessCreateVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_ALTER_VNODE_RSP, mndProcessAlterVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_DROP_VNODE_RSP, mndProcessDropVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_SYNC_VNODE_RSP, mndProcessSyncVnodeRsp); + mndSetMsgHandle(pMnode, TDMT_DND_COMPACT_VNODE_RSP, mndProcessCompactVnodeRsp); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndGetVgroupMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndRetrieveVgroups); @@ -80,13 +80,12 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) { SDB_SET_INT32(pRaw, dataPos, pVgroup->version) SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin) SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd) - SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_FULL_DB_NAME_LEN) + SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid) SDB_SET_INT8(pRaw, dataPos, pVgroup->replica) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId) - SDB_SET_INT8(pRaw, dataPos, pVgid->role) } SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE) SDB_SET_DATALEN(pRaw, dataPos); @@ -115,13 +114,15 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->version) SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashBegin) SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashEnd) - SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_FULL_DB_NAME_LEN) + SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->dbUid) SDB_GET_INT8(pRaw, pRow, dataPos, &pVgroup->replica) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId) - SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pVgid->role) + if (pVgroup->replica == 1) { + pVgid->role = TAOS_SYNC_STATE_LEADER; + } } SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE) @@ -172,7 +173,7 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb pCreate->vgId = htonl(pVgroup->vgId); pCreate->dnodeId = htonl(pDnode->id); - memcpy(pCreate->db, pDb->name, TSDB_FULL_DB_NAME_LEN); + memcpy(pCreate->db, pDb->name, TSDB_DB_FNAME_LEN); pCreate->dbUid = htobe64(pDb->uid); pCreate->vgVersion = htonl(pVgroup->version); pCreate->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize); @@ -231,56 +232,110 @@ SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *p pDrop->dnodeId = htonl(pDnode->id); pDrop->vgId = htonl(pVgroup->vgId); - memcpy(pDrop->db, pDb->name, TSDB_FULL_DB_NAME_LEN); + memcpy(pDrop->db, pDb->name, TSDB_DB_FNAME_LEN); pDrop->dbUid = htobe64(pDb->uid); return pDrop; } -static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) { +static SArray *mndBuildDnodesArray(SMnode *pMnode) { SSdb *pSdb = pMnode->pSdb; - int32_t allocedVnodes = 0; - void *pIter = NULL; + int32_t numOfDnodes = mndGetDnodeSize(pMnode); + SArray *pArray = taosArrayInit(numOfDnodes, sizeof(SDnodeObj)); + if (pArray == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } - while (allocedVnodes < pVgroup->replica) { + void *pIter = NULL; + while (1) { SDnodeObj *pDnode = NULL; pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); if (pIter == NULL) break; - // todo - if (mndIsDnodeInReadyStatus(pMnode, pDnode)) { - SVnodeGid *pVgid = &pVgroup->vnodeGid[allocedVnodes]; - pVgid->dnodeId = pDnode->id; - if (pVgroup->replica == 1) { - pVgid->role = TAOS_SYNC_STATE_LEADER; - } else { - pVgid->role = TAOS_SYNC_STATE_FOLLOWER; - } - allocedVnodes++; + int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id); + + bool isMnode = mndIsMnode(pMnode, pDnode->id); + if (isMnode) { + pDnode->numOfVnodes++; } + + int64_t curMs = taosGetTimestampMs(); + bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); + if (online) { + taosArrayPush(pArray, pDnode); + } + + mDebug("dnode:%d, vnodes:%d supportVnodes:%d isMnode:%d online:%d", pDnode->id, numOfVnodes, + pDnode->numOfSupportVnodes, isMnode, online); sdbRelease(pSdb, pDnode); } - if (allocedVnodes != pVgroup->replica) { - terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; - return -1; + return pArray; +} + +static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) { + float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes; + float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes; + return d1Score > d2Score ? 1 : 0; +} + +static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) { + SSdb *pSdb = pMnode->pSdb; + int32_t allocedVnodes = 0; + void *pIter = NULL; + + taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); + + for (int32_t v = 0; v < pVgroup->replica; ++v) { + SVnodeGid *pVgid = &pVgroup->vnodeGid[v]; + SDnodeObj *pDnode = taosArrayGet(pArray, v); + if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) { + terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; + return -1; + } + + pVgid->dnodeId = pDnode->id; + if (pVgroup->replica == 1) { + pVgid->role = TAOS_SYNC_STATE_LEADER; + } else { + pVgid->role = TAOS_SYNC_STATE_FOLLOWER; + } + + mDebug("db:%s, vgId:%d, vindex:%d dnodeId:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId); + pDnode->numOfVnodes++; } + return 0; } int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { - SVgObj *pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj)); + int32_t code = -1; + SArray *pArray = NULL; + SVgObj *pVgroups = NULL; + + pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj)); if (pVgroups == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + goto ALLOC_VGROUP_OVER; } + pArray = mndBuildDnodesArray(pMnode); + if (pArray == NULL) { + goto ALLOC_VGROUP_OVER; + } + + mDebug("db:%s, total %d dnodes used to create %d vgroups (%d vnodes)", pDb->name, (int32_t)taosArrayGetSize(pArray), + pDb->cfg.numOfVgroups, pDb->cfg.numOfVgroups * pDb->cfg.replications); + int32_t allocedVgroups = 0; int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); uint32_t hashMin = 0; uint32_t hashMax = UINT32_MAX; uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups; + if (maxVgId < 2) maxVgId = 2; + for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) { SVgObj *pVgroup = &pVgroups[v]; pVgroup->vgId = maxVgId++; @@ -294,21 +349,27 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1; } - memcpy(pVgroup->dbName, pDb->name, TSDB_FULL_DB_NAME_LEN); + memcpy(pVgroup->dbName, pDb->name, TSDB_DB_FNAME_LEN); pVgroup->dbUid = pDb->uid; pVgroup->replica = pDb->cfg.replications; - if (mndGetAvailableDnode(pMnode, pVgroup) != 0) { + if (mndGetAvailableDnode(pMnode, pVgroup, pArray) != 0) { terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; - free(pVgroups); - return -1; + goto ALLOC_VGROUP_OVER; } allocedVgroups++; } *ppVgroups = pVgroups; - return 0; + code = 0; + + mDebug("db:%s, %d vgroups is alloced, replica:%d", pDb->name, pDb->cfg.numOfVgroups, pDb->cfg.replications); + +ALLOC_VGROUP_OVER: + if (code != 0) free(pVgroups); + taosArrayDestroy(pArray); + return code; } SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup) { @@ -333,13 +394,22 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup) { } static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) { - mndTransHandleActionRsp(pMsg); + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); + return 0; +} + +static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { + mndTransProcessRsp(pMsg); return 0; } -static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { return 0; } -static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { return 0; } static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; } + static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; } static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) { @@ -470,7 +540,7 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) { sdbCancelFetch(pSdb, pIter); } -static int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) { +int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) { SSdb *pSdb = pMnode->pSdb; int32_t numOfVnodes = 0; void *pIter = NULL; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index fb0b95dc4a696f9a7b2751f3735d73d059838c60..e902e13a36ffe57873dd32dfe60f49bad32d5695 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -16,17 +16,20 @@ #define _DEFAULT_SOURCE #include "mndAcct.h" #include "mndAuth.h" -#include "mndBalance.h" +#include "mndBnode.h" #include "mndCluster.h" #include "mndDb.h" #include "mndDnode.h" #include "mndFunc.h" #include "mndMnode.h" #include "mndProfile.h" +#include "mndQnode.h" #include "mndShow.h" +#include "mndSnode.h" #include "mndStb.h" #include "mndSync.h" #include "mndTelem.h" +#include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -49,6 +52,20 @@ void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) { } } +static void mndTransReExecute(void *param, void *tmrId) { + SMnode *pMnode = param; + if (mndIsMaster(pMnode)) { + STransMsg *pMsg = rpcMallocCont(sizeof(STransMsg)); + SEpSet epSet = {.inUse = 0, .numOfEps = 1}; + epSet.port[0] = pMnode->replicas[pMnode->selfIndex].port; + memcpy(epSet.fqdn[0], pMnode->replicas[pMnode->selfIndex].fqdn, TSDB_FQDN_LEN); + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; + mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + } + + taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer); +} + static int32_t mndInitTimer(SMnode *pMnode) { if (pMnode->timer == NULL) { pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND"); @@ -59,11 +76,18 @@ static int32_t mndInitTimer(SMnode *pMnode) { return -1; } + if (taosTmrReset(mndTransReExecute, 1000, pMnode, pMnode->timer, &pMnode->transTimer)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + return 0; } static void mndCleanupTimer(SMnode *pMnode) { if (pMnode->timer != NULL) { + taosTmrStop(pMnode->transTimer); + pMnode->transTimer = NULL; taosTmrCleanUp(pMnode->timer); pMnode->timer = NULL; } @@ -124,14 +148,18 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-qnode", mndInitSnode, mndCleanupSnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-qnode", mndInitBnode, mndCleanupBnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1; if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; if (pMnode->clusterId <= 0) { if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; @@ -139,7 +167,6 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; } if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1; if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; @@ -178,8 +205,10 @@ static int32_t mndExecSteps(SMnode *pMnode) { // (*pMnode->reportProgress)(pStep->name, "start initialize"); if ((*pStep->initFp)(pMnode) != 0) { + int32_t code = terrno; mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); mndCleanupSteps(pMnode, pos); + terrno = code; return -1; } else { mDebug("step:%s is initialized", pStep->name); @@ -198,7 +227,6 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->pDnode = pOption->pDnode; - pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; @@ -213,8 +241,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo); if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 || - pMnode->cfg.statusInterval < 1) { + pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) { terrno = TSDB_CODE_MND_INVALID_OPTIONS; return -1; } @@ -225,7 +252,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { } return 0; -} +} SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { mDebug("start to open mnode in %s", path); @@ -367,14 +394,14 @@ void mndSendRsp(SMnodeMsg *pMsg, int32_t code) { rpcSendResponse(&rpcRsp); } -static void mndProcessRpcMsg(SMnodeMsg *pMsg) { +void mndProcessMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; int32_t code = 0; - int32_t msgType = pMsg->rpcMsg.msgType; + tmsg_t msgType = pMsg->rpcMsg.msgType; void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); - mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, taosMsg[msgType]); + mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType)); if (isReq && !mndIsMaster(pMnode)) { code = TSDB_CODE_APP_NOT_READY; @@ -388,10 +415,10 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) { goto PROCESS_RPC_END; } - MndMsgFp fp = pMnode->msgFp[msgType]; + MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(msgType)]; if (fp == NULL) { code = TSDB_CODE_MSG_NOT_PROCESSED; - mError("msg:%p, app:%p failed to process since not handle", pMsg, ahandle); + mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle); goto PROCESS_RPC_END; } @@ -421,23 +448,16 @@ PROCESS_RPC_END: } } -void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { - if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) { - pMnode->msgFp[msgType] = fp; +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) { + tmsg_t type = TMSG_INDEX(msgType); + if (type >= 0 && type < TDMT_MAX) { + pMnode->msgFp[type] = fp; } } -void mndProcessReadMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } - -void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } - -void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } - -void mndProcessApplyMsg(SMnodeMsg *pMsg) {} - uint64_t mndGenerateUid(char *name, int32_t len) { int64_t us = taosGetTimestampUs(); int32_t hashval = MurmurHash3_32(name, len); uint64_t x = (us & 0x000000FFFFFFFFFF) << 24; return x + ((hashval & ((1ul << 16) - 1ul)) << 8) + (taosRand() & ((1ul << 8) - 1ul)); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 7e2e2602a88a944a7b2be8a2995d13f671cb4914..da90451202ef07edfdff8e9ca3bf350ab1c2c61f 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -18,7 +18,7 @@ #include "os.h" #include "sdb.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" @@ -72,6 +72,7 @@ typedef struct SSdb { } SSdb; int32_t sdbWriteFile(SSdb *pSdb); +void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); #ifdef __cplusplus } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 77614e399e1c8940b7b3eada86ce28b798f16732..97bc0ecbdbb9aee8bb1bc031b0b5bf3f18af486b 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -16,6 +16,8 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" +static int32_t sdbCreateDir(SSdb *pSdb); + SSdb *sdbInit(SSdbOpt *pOption) { mDebug("start to init sdb in %s", pOption->path); @@ -40,6 +42,11 @@ SSdb *sdbInit(SSdbOpt *pOption) { return NULL; } + if (sdbCreateDir(pSdb) != 0) { + sdbCleanup(pSdb); + return NULL; + } + for (ESdbType i = 0; i < SDB_MAX; ++i) { taosInitRWLatch(&pSdb->locks[i]); } @@ -53,8 +60,8 @@ void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); // if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); - sdbWriteFile(pSdb); + mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); + sdbWriteFile(pSdb); // } if (pSdb->currDir != NULL) { @@ -73,16 +80,12 @@ void sdbCleanup(SSdb *pSdb) { SHashObj *hash = pSdb->hashObjs[i]; if (hash == NULL) continue; - SdbDeleteFp deleteFp = pSdb->deleteFps[i]; - SSdbRow **ppRow = taosHashIterate(hash, NULL); + SSdbRow **ppRow = taosHashIterate(hash, NULL); while (ppRow != NULL) { SSdbRow *pRow = *ppRow; if (pRow == NULL) continue; - if (deleteFp != NULL) { - (*deleteFp)(pSdb, pRow->pObj); - } - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); ppRow = taosHashIterate(hash, ppRow); } } @@ -133,4 +136,26 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { mDebug("sdb table:%d is initialized", sdbType); return 0; -} \ No newline at end of file +} + +static int32_t sdbCreateDir(SSdb *pSdb) { + if (taosMkDir(pSdb->currDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); + return -1; + } + + if (taosMkDir(pSdb->syncDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->syncDir, terrstr()); + return -1; + } + + if (taosMkDir(pSdb->tmpDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr()); + return -1; + } + + return 0; +} diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index af37e9e1d5a60f8a609304ddcc956e30f9ef7d31..78cf0a3492ffa279af42bbdda6a19ba0b2907715 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -17,28 +17,6 @@ #include "sdbInt.h" #include "tchecksum.h" -static int32_t sdbCreateDir(SSdb *pSdb) { - if (taosMkDir(pSdb->currDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); - return -1; - } - - if (taosMkDir(pSdb->syncDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->syncDir, terrstr()); - return -1; - } - - if (taosMkDir(pSdb->tmpDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr()); - return -1; - } - - return 0; -} - static int32_t sdbRunDeployFp(SSdb *pSdb) { mDebug("start to deploy sdb"); @@ -77,7 +55,7 @@ int32_t sdbReadFile(SSdb *pSdb) { free(pRaw); terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to read file:%s since %s", file, terrstr()); - return -1; + return 0; } while (1) { @@ -173,7 +151,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { code = TAOS_SYSTEM_ERROR(terrno); taosHashCancelIterate(hash, ppRow); - free(pRaw); + sdbFreeRaw(pRaw); break; } @@ -181,7 +159,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { code = TAOS_SYSTEM_ERROR(terrno); taosHashCancelIterate(hash, ppRow); - free(pRaw); + sdbFreeRaw(pRaw); break; } } else { @@ -190,7 +168,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { break; } - free(pRaw); + sdbFreeRaw(pRaw); ppRow = taosHashIterate(hash, ppRow); } taosWUnLockLatch(pLock); @@ -225,10 +203,6 @@ int32_t sdbWriteFile(SSdb *pSdb) { } int32_t sdbDeploy(SSdb *pSdb) { - if (sdbCreateDir(pSdb) != 0) { - return -1; - } - if (sdbRunDeployFp(pSdb) != 0) { return -1; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 1c8b82fd92cd3ac8ef536a744533e077c4a79588..06c2563910818f13fb3aa8f157410e17a30eb5c2 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -16,6 +16,57 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" +static const char *sdbTableName(ESdbType type) { + switch (type) { + case SDB_TRANS: + return "trans"; + case SDB_CLUSTER: + return "cluster"; + case SDB_MNODE: + return "mnode"; + case SDB_QNODE: + return "qnode"; + case SDB_SNODE: + return "snode"; + case SDB_BNODE: + return "bnode"; + case SDB_DNODE: + return "dnode"; + case SDB_USER: + return "user"; + case SDB_AUTH: + return "auth"; + case SDB_ACCT: + return "acct"; + case SDB_TOPIC: + return "topic"; + case SDB_VGROUP: + return "vgId"; + case SDB_STB: + return "stb"; + case SDB_DB: + return "db"; + case SDB_FUNC: + return "func"; + default: + return "undefine"; + } +} + +void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { + EKeyType keyType = pSdb->keyTypes[pRow->type]; + + if (keyType == SDB_KEY_BINARY) { + mTrace("%s:%s, refCount:%d oper:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper); + } else if (keyType == SDB_KEY_INT32) { + mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper); + } else if (keyType == SDB_KEY_INT64) { + mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount, + oper); + } else { + } +} + static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { if (type >= SDB_MAX || type <= SDB_START) { terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE; @@ -55,17 +106,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = taosHashGet(hash, pRow->pObj, keySize); if (pOldRow != NULL) { taosWUnLockLatch(pLock); - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE; return terrno; } - pRow->refCount = 1; + pRow->refCount = 0; pRow->status = pRaw->status; + sdbPrintOper(pSdb, pRow, "insertRow"); if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) { taosWUnLockLatch(pLock); - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE; return terrno; } @@ -83,7 +135,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosWLockLatch(pLock); taosHashRemove(hash, pRow->pObj, keySize); taosWUnLockLatch(pLock); - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); terrno = code; return terrno; } @@ -113,7 +165,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj); } - sdbFreeRow(pNewRow); + sdbFreeRow(pSdb, pNewRow); return code; } @@ -126,7 +178,7 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow **ppOldRow = taosHashGet(hash, pRow->pObj, keySize); if (ppOldRow == NULL || *ppOldRow == NULL) { taosWUnLockLatch(pLock); - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; return terrno; } @@ -136,8 +188,8 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); - sdbRelease(pSdb, pOldRow->pObj); - sdbFreeRow(pRow); + // sdbRelease(pSdb, pOldRow->pObj); + sdbFreeRow(pSdb, pRow); return code; } @@ -199,8 +251,10 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { SSdbRow *pRow = *ppRow; switch (pRow->status) { case SDB_STATUS_READY: + case SDB_STATUS_UPDATING: atomic_add_fetch_32(&pRow->refCount, 1); pRet = pRow->pObj; + sdbPrintOper(pSdb, pRow, "acquireRow"); break; case SDB_STATUS_CREATING: terrno = TSDB_CODE_SDB_OBJ_CREATING; @@ -227,13 +281,9 @@ void sdbRelease(SSdb *pSdb, void *pObj) { taosRLockLatch(pLock); int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); + sdbPrintOper(pSdb, pRow, "releaseRow"); if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) { - SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type]; - if (deleteFp != NULL) { - (*deleteFp)(pSdb, pRow->pObj); - } - - sdbFreeRow(pRow); + sdbFreeRow(pSdb, pRow); } taosRUnLockLatch(pLock); @@ -250,9 +300,9 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { if (pIter != NULL) { SSdbRow *pLastRow = *(SSdbRow **)pIter; - int32_t ref = atomic_sub_fetch_32(&pLastRow->refCount, 1); + int32_t ref = atomic_load_32(&pLastRow->refCount); if (ref <= 0 && pLastRow->status == SDB_STATUS_DROPPED) { - sdbFreeRow(pLastRow); + sdbFreeRow(pSdb, pLastRow); } } @@ -265,6 +315,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { } atomic_add_fetch_32(&pRow->refCount, 1); + sdbPrintOper(pSdb, pRow, "fetchRow"); *ppObj = pRow->pObj; break; } diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index 5a0020199f0652376de73ec5c243301b4ac2371f..e37559808e2b5242354be6187c07fc49a732a940 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -27,12 +27,12 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { pRaw->sver = sver; pRaw->dataLen = dataLen; - // mTrace("raw:%p, is created, len:%d", pRaw, dataLen); + mTrace("raw:%p, is created, len:%d", pRaw, dataLen); return pRaw; } void sdbFreeRaw(SSdbRaw *pRaw) { - // mTrace("raw:%p, is freed", pRaw); + mTrace("raw:%p, is freed", pRaw); free(pRaw); } diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index ec1dcf39e68c7948f54d10434615338fa8f566f3..4c889a6d04a303ec94ec4dfa61571259694166e3 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -35,4 +35,13 @@ void *sdbGetRowObj(SSdbRow *pRow) { return pRow->pObj; } -void sdbFreeRow(SSdbRow *pRow) { tfree(pRow); } +void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) { + // remove attached object such as trans + SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type]; + if (deleteFp != NULL) { + (*deleteFp)(pSdb, pRow->pObj); + } + + sdbPrintOper(pSdb, pRow, "freeRow"); + tfree(pRow); +} diff --git a/source/dnode/qnode/CMakeLists.txt b/source/dnode/qnode/CMakeLists.txt index d9f932a6318d1b13607c019b612d2bb76e36144c..f6f78f7357f7e769b1d0b12325c1a4852c4bcc6c 100644 --- a/source/dnode/qnode/CMakeLists.txt +++ b/source/dnode/qnode/CMakeLists.txt @@ -4,4 +4,11 @@ target_include_directories( qnode PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/qnode" private "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + qnode + PRIVATE transport + PRIVATE os + PRIVATE common + PRIVATE util ) \ No newline at end of file diff --git a/source/dnode/qnode/inc/qndInt.h b/source/dnode/qnode/inc/qndInt.h new file mode 100644 index 0000000000000000000000000000000000000000..e9f1229a9da3336cf307d9b39942f6dd15e93cf0 --- /dev/null +++ b/source/dnode/qnode/inc/qndInt.h @@ -0,0 +1,44 @@ +/* + * 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_QNODE_INT_H_ +#define _TD_QNODE_INT_H_ + +#include "os.h" + +#include "tlog.h" +#include "tmsg.h" +#include "trpc.h" + +#include "qnode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SQnode { + int32_t dnodeId; + int64_t clusterId; + SQnodeCfg cfg; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SQnode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_QNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index 6dea4a4e57392be988126c579648f39a8270b9bf..8d2a72b2683f916145bd9aaf52181b68dc1cd571 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -11,4 +11,21 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "qndInt.h" + +SQnode *qndOpen(const SQnodeOpt *pOption) { + SQnode *pQnode = calloc(1, sizeof(SQnode)); + return pQnode; +} + +void qndClose(SQnode *pQnode) { free(pQnode); } + +int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; } + +int32_t qndProcessMsg(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + *pRsp = NULL; + return 0; +} + diff --git a/source/dnode/snode/CMakeLists.txt b/source/dnode/snode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a94dd9edd8055a330d5ff733e9804942dc4f3ef8 --- /dev/null +++ b/source/dnode/snode/CMakeLists.txt @@ -0,0 +1,14 @@ +aux_source_directory(src SNODE_SRC) +add_library(snode ${SNODE_SRC}) +target_include_directories( + snode + PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/snode" + private "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + snode + PRIVATE transport + PRIVATE os + PRIVATE common + PRIVATE util +) \ No newline at end of file diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h new file mode 100644 index 0000000000000000000000000000000000000000..8827c92eef3f10f555df1caaf725f5f015262885 --- /dev/null +++ b/source/dnode/snode/inc/sndInt.h @@ -0,0 +1,44 @@ +/* + * 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_SNODE_INT_H_ +#define _TD_SNODE_INT_H_ + +#include "os.h" + +#include "tlog.h" +#include "tmsg.h" +#include "trpc.h" + +#include "snode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SSnode { + int32_t dnodeId; + int64_t clusterId; + SSnodeCfg cfg; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SSnode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_SNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c new file mode 100644 index 0000000000000000000000000000000000000000..5d21a037e7211960722ee2a341142507537920e1 --- /dev/null +++ b/source/dnode/snode/src/snode.c @@ -0,0 +1,32 @@ +/* + * 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 "sndInt.h" + +SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { + SSnode *pSnode = calloc(1, sizeof(SSnode)); + return pSnode; +} + +void sndClose(SSnode *pSnode) { free(pSnode); } + +int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; } + +int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + *pRsp = NULL; + return 0; +} + +void sndDestroy(const char *path) {} \ No newline at end of file diff --git a/source/dnode/vnode/impl/CMakeLists.txt b/source/dnode/vnode/impl/CMakeLists.txt index 6972605afd9c1dd93b7fd0b3198c3837b5351f88..944a4276dbad03558d5321bb157fa0f89c513fd5 100644 --- a/source/dnode/vnode/impl/CMakeLists.txt +++ b/source/dnode/vnode/impl/CMakeLists.txt @@ -15,9 +15,10 @@ target_link_libraries( PUBLIC wal PUBLIC sync PUBLIC cjson + PUBLIC qworker ) # test if(${BUILD_TEST}) - add_subdirectory(test) -endif(${BUILD_TEST}) \ No newline at end of file +# add_subdirectory(test) +endif(${BUILD_TEST}) diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 605557d4eace479f8cad786c658b2092b3e63d23..78214ce14da0099c832268fdc66be3fd86ed869d 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -34,6 +34,7 @@ #include "vnodeRequest.h" #include "vnodeStateMgr.h" #include "vnodeSync.h" +#include "vnodeQuery.h" #ifdef __cplusplus extern "C" { @@ -72,6 +73,7 @@ struct SVnode { SVnodeSync* pSync; SVnodeFS* pFs; tsem_t canCommit; + SQHandle* pQuery; }; int vnodeScheduleTask(SVnodeTask* task); diff --git a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h index bdafbf31a7b828551f54ec694ce1480f1f74cf58..eb821a4b6cef8df3de8092bd0c94bf8d91c889e6 100644 --- a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h +++ b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h @@ -22,17 +22,14 @@ extern "C" { #endif -typedef struct SVArenaNode SVArenaNode; -typedef struct SVMemAllocator SVMemAllocator; - -struct SVArenaNode { +typedef struct SVArenaNode { TD_SLIST_NODE(SVArenaNode); uint64_t size; // current node size void * ptr; char data[]; -}; +} SVArenaNode; -struct SVMemAllocator { +typedef struct SVMemAllocator { T_REF_DECLARE() TD_DLIST_NODE(SVMemAllocator); uint64_t capacity; @@ -40,7 +37,7 @@ struct SVMemAllocator { uint64_t lsize; SVArenaNode *pNode; TD_SLIST(SVArenaNode) nlist; -}; +} SVMemAllocator; SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); void vmaDestroy(SVMemAllocator *pVMA); diff --git a/source/common/src/taosmsg.c b/source/dnode/vnode/impl/inc/vnodeQuery.h similarity index 70% rename from source/common/src/taosmsg.c rename to source/dnode/vnode/impl/inc/vnodeQuery.h index b35e3f1478fde0cfc75243bba74f6a35bec629ad..d43f5b1cf1e4958baff459f05062a62c9521f2c9 100644 --- a/source/common/src/taosmsg.c +++ b/source/dnode/vnode/impl/inc/vnodeQuery.h @@ -13,8 +13,22 @@ * along with this program. If not, see . */ -#define TAOS_MESSAGE_C +#ifndef _TD_VNODE_READ_H_ +#define _TD_VNODE_READ_H_ -#include "taosmsg.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "vnodeInt.h" +#include "qworker.h" +typedef struct SQWorkerMgmt SQHandle; + +int vnodeQueryOpen(SVnode *pVnode); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_READ_H_*/ diff --git a/source/dnode/vnode/impl/inc/vnodeRequest.h b/source/dnode/vnode/impl/inc/vnodeRequest.h index d70fc84cabe23acc0219bb037a180b528c9de105..93b4589bad78153a3853a5d6c759a639d5f5540e 100644 --- a/source/dnode/vnode/impl/inc/vnodeRequest.h +++ b/source/dnode/vnode/impl/inc/vnodeRequest.h @@ -23,8 +23,8 @@ extern "C" { #endif // SVDropTableReq -int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq); -void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq); +// int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq); +// void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/src/vnodeInt.c b/source/dnode/vnode/impl/src/vnodeInt.c index 5deaffe6d220134ac6f8c5f0cfd4607be2ef304a..0f33fa65cd888eae518bc1079b1d35c9feb0e6e8 100644 --- a/source/dnode/vnode/impl/src/vnodeInt.c +++ b/source/dnode/vnode/impl/src/vnodeInt.c @@ -24,22 +24,7 @@ int32_t vnodeSync(SVnode *pVnode) { return 0; } int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { return 0; } -int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - vInfo("query message is processed"); - return 0; -} - -int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - vInfo("fetch message is processed"); - return 0; -} - int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { vInfo("sync message is processed"); return 0; } - -int vnodeProcessConsumeReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - vInfo("consume message is processed"); - return 0; -} diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index c98f3e0800eaa0726c29708864040aa5d1a379ca..2b0363c97f2b8b86945a64303e6aac12a72204b9 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -127,6 +127,11 @@ static int vnodeOpenImpl(SVnode *pVnode) { return -1; } + // Open Query + if (vnodeQueryOpen(pVnode)) { + return -1; + } + // TODO return 0; } diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c new file mode 100644 index 0000000000000000000000000000000000000000..6632676d8bb336513295f25280c495a831d97382 --- /dev/null +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -0,0 +1,69 @@ +/* + * 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 "vnodeQuery.h" +#include "vnodeDef.h" + +int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); } + +int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + vInfo("query message is processed"); + return qWorkerProcessQueryMsg(pVnode, pVnode->pQuery, pMsg); +} + +int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + vInfo("fetch message is processed"); + switch (pMsg->msgType) { + case TDMT_VND_FETCH: + return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_RES_READY: + return qWorkerProcessReadyMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_TASKS_STATUS: + return qWorkerProcessStatusMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_CANCEL_TASK: + return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_DROP_TASK: + return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_SHOW_TABLES: + return qWorkerProcessShowMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_SHOW_TABLES_FETCH: + return qWorkerProcessShowFetchMsg(pVnode, pVnode->pQuery, pMsg); + default: + vError("unknown msg type:%d in fetch queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + +static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + STableInfoMsg *pReq = (STableInfoMsg *)(pMsg->pCont); + STableMetaMsg *pRspMsg; + int ret; + + if (metaGetTableInfo(pVnode->pMeta, pReq->tableFname, &pRspMsg) < 0) { + return -1; + } + + *pRsp = malloc(sizeof(SRpcMsg)); + if (TD_IS_NULL(*pRsp)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + free(pMsg); + return -1; + } + + // TODO + (*pRsp)->pCont = pRspMsg; + + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 249bde4e56c32cd2362da9d6f4646ed096e4049c..4b481bf3995af03e272253213b214ae12476fe30 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -15,18 +15,20 @@ #include "vnodeDef.h" +#if 0 + static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); -int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, tmsg_t type) { int tsize = 0; tsize += taosEncodeFixedU64(buf, pReq->ver); switch (type) { - case TSDB_MSG_TYPE_CREATE_TABLE: + case TDMT_VND_CREATE_STB: tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq)); break; - case TSDB_MSG_TYPE_SUBMIT: + case TDMT_VND_SUBMIT: /* code */ break; default: @@ -36,11 +38,11 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { return tsize; } -void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { +void *vnodeParseReq(void *buf, SVnodeReq *pReq, tmsg_t type) { buf = taosDecodeFixedU64(buf, &(pReq->ver)); switch (type) { - case TSDB_MSG_TYPE_CREATE_TABLE: + case TDMT_VND_CREATE_STB: buf = vnodeParseCreateTableReq(buf, &(pReq->ctReq)); break; @@ -113,4 +115,5 @@ int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) { // TODO -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 5ec03f1fd3f7d7f4f2448d388146df311561dd35..3b1442a02caea4314dc99a35f3de3cfd8b821715 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -17,7 +17,7 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) { switch (pMsg->msgType) { - case TSDB_MSG_TYPE_MQ_SET_CUR: + case TDMT_VND_MQ_SET_CUR: if (tqSetCursor(pVnode->pTq, pMsg->pCont) < 0) { // TODO: handle error } @@ -28,13 +28,12 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) { int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { SRpcMsg * pMsg; - SVnodeReq *pVnodeReq; for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); // ser request version - void * pBuf = pMsg->pCont; + void * pBuf = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int64_t ver = pVnode->state.processed++; taosEncodeFixedU64(&pBuf, ver); @@ -51,8 +50,8 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { } int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - SVnodeReq vReq; - void * ptr = vnodeMalloc(pVnode, pMsg->contLen); + SVCreateTbReq vCreateTbReq; + void * ptr = vnodeMalloc(pVnode, pMsg->contLen); if (ptr == NULL) { // TODO: handle error } @@ -62,34 +61,34 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // todo: change the interface here uint64_t ver; - taosDecodeFixedU64(pMsg->pCont, &ver); + taosDecodeFixedU64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) { // TODO: handle error } - vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType); - switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_STB_IN: - case TSDB_MSG_TYPE_CREATE_TABLE: - if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) { + case TDMT_VND_CREATE_STB: + case TDMT_VND_CREATE_TABLE: + tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq); + if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { // TODO: handle error } // TODO: maybe need to clear the requst struct break; - case TSDB_MSG_TYPE_DROP_STB_IN: - case TSDB_MSG_TYPE_DROP_TABLE: - if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { - // TODO: handle error - } + case TDMT_VND_DROP_STB: + case TDMT_VND_DROP_TABLE: + // if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { + // // TODO: handle error + // } break; - case TSDB_MSG_TYPE_SUBMIT: + case TDMT_VND_SUBMIT: if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) { // TODO: handle error } break; default: + ASSERT(0); break; } diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index aa9fc741d95122f8c60a44967e4b996d3b98deb5..71ffdd1d0f5065aa974d0648ef26ec8cad60274a 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -84,14 +84,14 @@ static void vtBuildCreateStbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) { SVnodeReq vCreateSTbReq; vnodeSetCreateStbReq(&vCreateSTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); - zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + zs = vnodeBuildReq(NULL, &vCreateSTbReq, TDMT_VND_CREATE_STB); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); - pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pMsg->msgType = TDMT_VND_CREATE_STB; pMsg->contLen = zs; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); pBuf = pMsg->pCont; - vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateSTbReq, TDMT_VND_CREATE_STB); META_CLEAR_TB_CFG(&vCreateSTbReq); tdFreeSchema(pSchema); @@ -108,14 +108,14 @@ static void vtBuildCreateCtbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) { SVnodeReq vCreateCTbReq; vnodeSetCreateCtbReq(&vCreateCTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pTag); - tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + tz = vnodeBuildReq(NULL, &vCreateCTbReq, TDMT_VND_CREATE_TABLE); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); - pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pMsg->msgType = TDMT_VND_CREATE_TABLE; pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); void *pBuf = pMsg->pCont; - vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateCTbReq, TDMT_VND_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateCTbReq); free(pTag); @@ -133,7 +133,7 @@ static void vtBuildSubmitReq(SRpcMsg **ppMsg) { int tz = 1024; // TODO pMsg = (SRpcMsg *)malloc(sizeof(*pMsg) + tz); - pMsg->msgType = TSDB_MSG_TYPE_SUBMIT; + pMsg->msgType = TDMT_VND_SUBMIT; pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); diff --git a/source/dnode/vnode/meta/inc/metaQuery.h b/source/dnode/vnode/meta/inc/metaQuery.h index 110df8dd4556ce49cbc95d4c0acbe082c289796d..ca3b68b41536a38760ef933ee86dc91ce2c3a509 100644 --- a/source/dnode/vnode/meta/inc/metaQuery.h +++ b/source/dnode/vnode/meta/inc/metaQuery.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_META_QUERY_H_ -#define _TD_META_QUERY_H_ +#ifndef _VNODE_QUERY_H_ +#define _VNODE_QUERY_H_ #ifdef __cplusplus extern "C" { @@ -24,4 +24,4 @@ extern "C" { } #endif -#endif /*_TD_META_QUERY_H_*/ \ No newline at end of file +#endif /*_VNODE_QUERY_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/meta/inc/metaTbCfg.h b/source/dnode/vnode/meta/inc/metaTbCfg.h index 68c609d6b44ab8cc94a0d7891d2621d0f0aba40a..b4ee095967a313dce7078176f3d2b94e0585dc09 100644 --- a/source/dnode/vnode/meta/inc/metaTbCfg.h +++ b/source/dnode/vnode/meta/inc/metaTbCfg.h @@ -22,11 +22,11 @@ extern "C" { #endif -#define META_SUPER_TABLE 0 -#define META_CHILD_TABLE 1 -#define META_NORMAL_TABLE 2 +#define META_SUPER_TABLE TD_SUPER_TABLE +#define META_CHILD_TABLE TD_CHILD_TABLE +#define META_NORMAL_TABLE TD_NORMAL_TABLE -int metaValidateTbOptions(SMeta *pMeta, const STbCfg *); +int metaValidateTbCfg(SMeta *pMeta, const STbCfg *); size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize); #ifdef __cplusplus diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 3c1ccc72dce40e5f823a737b0ad63d8c8d74dca5..4ef7dc01a46eb937f402fc8656c9cf8366427995 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -125,11 +125,11 @@ void metaCloseDB(SMeta *pMeta) { } int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { - tb_uid_t uid; - char buf[512]; - void * pBuf; - DBT key, value; - STSchema *pSchema = NULL; + tb_uid_t uid; + char buf[512]; + void * pBuf; + DBT key, value; + SSchema *pSchema = NULL; if (pTbCfg->type == META_SUPER_TABLE) { uid = pTbCfg->stbCfg.suid; @@ -156,9 +156,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { } // save schema + uint32_t ncols; if (pTbCfg->type == META_SUPER_TABLE) { + ncols = pTbCfg->stbCfg.nCols; pSchema = pTbCfg->stbCfg.pSchema; } else if (pTbCfg->type == META_NORMAL_TABLE) { + ncols = pTbCfg->ntbCfg.nCols; pSchema = pTbCfg->ntbCfg.pSchema; } @@ -166,12 +169,18 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { pBuf = buf; memset(&key, 0, sizeof(key)); memset(&value, 0, sizeof(key)); - SSchemaKey schemaKey = {uid, schemaVersion(pSchema)}; + SSchemaKey schemaKey = {uid, 0 /*TODO*/}; key.data = &schemaKey; key.size = sizeof(schemaKey); - tdEncodeSchema(&pBuf, pSchema); + taosEncodeFixedU32(&pBuf, ncols); + for (size_t i = 0; i < ncols; i++) { + taosEncodeFixedI8(&pBuf, pSchema[i].type); + taosEncodeFixedI32(&pBuf, pSchema[i].colId); + taosEncodeFixedI32(&pBuf, pSchema[i].bytes); + taosEncodeString(&pBuf, pSchema[i].name); + } value.data = buf; value.size = POINTER_DISTANCE(pBuf, buf); @@ -342,7 +351,7 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *pSKey pDbt[0].size = sizeof(pTbCfg->ctbCfg.suid); // Second key is the first tag - void *pTagVal = tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, 0); + void *pTagVal = tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId); pDbt[1].data = varDataVal(pTagVal); pDbt[1].size = varDataLen(pTagVal); @@ -367,7 +376,15 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) { tsize += taosEncodeFixedU8(buf, pTbCfg->type); if (pTbCfg->type == META_SUPER_TABLE) { - tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema); + tsize += taosEncodeVariantU32(buf, pTbCfg->stbCfg.nTagCols); + for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { + tsize += taosEncodeFixedI8(buf, pTbCfg->stbCfg.pSchema[i].type); + tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].colId); + tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].bytes); + tsize += taosEncodeString(buf, pTbCfg->stbCfg.pSchema[i].name); + } + + // tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema); } else if (pTbCfg->type == META_CHILD_TABLE) { tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid); tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag); @@ -386,7 +403,14 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { buf = taosDecodeFixedU8(buf, &(pTbCfg->type)); if (pTbCfg->type == META_SUPER_TABLE) { - buf = tdDecodeSchema(buf, &(pTbCfg->stbCfg.pTagSchema)); + buf = taosDecodeVariantU32(buf, &(pTbCfg->stbCfg.nTagCols)); + pTbCfg->stbCfg.pTagSchema = (SSchema *)malloc(sizeof(SSchema) * pTbCfg->stbCfg.nTagCols); + for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { + buf = taosDecodeFixedI8(buf, &(pTbCfg->stbCfg.pSchema[i].type)); + buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].colId); + buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].bytes); + buf = taosDecodeStringTo(buf, pTbCfg->stbCfg.pSchema[i].name); + } } else if (pTbCfg->type == META_CHILD_TABLE) { buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid)); buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag)); @@ -404,4 +428,82 @@ static void metaClearTbCfg(STbCfg *pTbCfg) { } else if (pTbCfg->type == META_CHILD_TABLE) { tfree(pTbCfg->ctbCfg.pTag); } +} + +/* ------------------------ FOR QUERY ------------------------ */ +int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) { + DBT key = {0}; + DBT value = {0}; + SMetaDB * pMetaDB = pMeta->pDB; + int ret; + STbCfg tbCfg; + SSchemaKey schemaKey; + DBT key1 = {0}; + DBT value1 = {0}; + uint32_t ncols; + void * pBuf; + int tlen; + STableMetaMsg *pMsg; + SSchema * pSchema; + + key.data = tbname; + key.size = strlen(tbname) + 1; + + ret = pMetaDB->pNameIdx->get(pMetaDB->pNameIdx, NULL, &key, &value, 0); + if (ret != 0) { + // TODO + return -1; + } + + metaDecodeTbInfo(value.data, &tbCfg); + + switch (tbCfg.type) { + case META_SUPER_TABLE: + schemaKey.uid = tbCfg.stbCfg.suid; + schemaKey.sver = 0; + + key1.data = &schemaKey; + key1.size = sizeof(schemaKey); + + ret = pMetaDB->pSchemaDB->get(pMetaDB->pSchemaDB, &key1, &value1, NULL, 0); + if (ret != 0) { + // TODO + return -1; + } + pBuf = value1.data; + pBuf = taosDecodeFixedU32(pBuf, &ncols); + + tlen = sizeof(STableMetaMsg) + (tbCfg.stbCfg.nTagCols + ncols) * sizeof(SSchema); + pMsg = calloc(1, tlen); + if (pMsg == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + strcpy(pMsg->tbFname, tbCfg.name); + pMsg->numOfTags = tbCfg.stbCfg.nTagCols; + pMsg->numOfColumns = ncols; + pMsg->tableType = tbCfg.type; + pMsg->sversion = 0; + pMsg->tversion = 0; + pMsg->suid = tbCfg.stbCfg.suid; + pMsg->tuid = tbCfg.stbCfg.suid; + memcpy(pMsg->pSchema, tbCfg.stbCfg.pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols); + memcpy(POINTER_SHIFT(pMsg->pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols), tbCfg.stbCfg.pTagSchema, + sizeof(SSchema) * tbCfg.stbCfg.nTagCols); + break; + case META_CHILD_TABLE: + ASSERT(0); + break; + case META_NORMAL_TABLE: + ASSERT(0); + break; + default: + ASSERT(0); + break; + } + + *ppMsg = pMsg; + + return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index fc0f19302f45c438836ae9e0e4afd0c5aa234efc..1398639f39dccb660de7d39480fa1524f694a248 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -17,7 +17,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { // Validate the tbOptions - if (metaValidateTbOptions(pMeta, pTbCfg) < 0) { + if (metaValidateTbCfg(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } diff --git a/source/dnode/vnode/meta/src/metaTbCfg.c b/source/dnode/vnode/meta/src/metaTbCfg.c index da181a68fc2397273c8772761f91c0e06a256961..4e02b64ce043c41ff40b04abdfedd2f2296f9bff 100644 --- a/source/dnode/vnode/meta/src/metaTbCfg.c +++ b/source/dnode/vnode/meta/src/metaTbCfg.c @@ -16,7 +16,7 @@ #include "metaDef.h" #include "tcoding.h" -int metaValidateTbOptions(SMeta *pMeta, const STbCfg *pTbOptions) { +int metaValidateTbCfg(SMeta *pMeta, const STbCfg *pTbOptions) { // TODO return 0; } @@ -46,58 +46,4 @@ size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t } return tlen; -} - -int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg) { - int tsize = 0; - - tsize += taosEncodeString(pBuf, pTbCfg->name); - tsize += taosEncodeFixedU32(pBuf, pTbCfg->ttl); - tsize += taosEncodeFixedU32(pBuf, pTbCfg->keep); - tsize += taosEncodeFixedU8(pBuf, pTbCfg->type); - - switch (pTbCfg->type) { - case META_SUPER_TABLE: - tsize += taosEncodeFixedU64(pBuf, pTbCfg->stbCfg.suid); - tsize += tdEncodeSchema(pBuf, pTbCfg->stbCfg.pSchema); - tsize += tdEncodeSchema(pBuf, pTbCfg->stbCfg.pTagSchema); - break; - case META_CHILD_TABLE: - tsize += taosEncodeFixedU64(pBuf, pTbCfg->ctbCfg.suid); - tsize += tdEncodeKVRow(pBuf, pTbCfg->ctbCfg.pTag); - break; - case META_NORMAL_TABLE: - tsize += tdEncodeSchema(pBuf, pTbCfg->ntbCfg.pSchema); - break; - default: - break; - } - - return tsize; -} - -void *metaDecodeTbCfg(void *pBuf, STbCfg *pTbCfg) { - pBuf = taosDecodeString(pBuf, &(pTbCfg->name)); - pBuf = taosDecodeFixedU32(pBuf, &(pTbCfg->ttl)); - pBuf = taosDecodeFixedU32(pBuf, &(pTbCfg->keep)); - pBuf = taosDecodeFixedU8(pBuf, &(pTbCfg->type)); - - switch (pTbCfg->type) { - case META_SUPER_TABLE: - pBuf = taosDecodeFixedU64(pBuf, &(pTbCfg->stbCfg.suid)); - pBuf = tdDecodeSchema(pBuf, &(pTbCfg->stbCfg.pSchema)); - pBuf = tdDecodeSchema(pBuf, &(pTbCfg->stbCfg.pTagSchema)); - break; - case META_CHILD_TABLE: - pBuf = taosDecodeFixedU64(pBuf, &(pTbCfg->ctbCfg.suid)); - pBuf = tdDecodeKVRow(pBuf, &(pTbCfg->ctbCfg.pTag)); - break; - case META_NORMAL_TABLE: - pBuf = tdDecodeSchema(pBuf, &(pTbCfg->ntbCfg.pSchema)); - break; - default: - break; - } - - return pBuf; } \ No newline at end of file diff --git a/source/dnode/vnode/tsdb/inc/tsdbDef.h b/source/dnode/vnode/tsdb/inc/tsdbDef.h index b1375c9477e9d31f076e0d6b364aed3b48e89b44..ded28727e420bfaec50a5128fcf6815f508a9e74 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbDef.h +++ b/source/dnode/vnode/tsdb/inc/tsdbDef.h @@ -17,7 +17,7 @@ #define _TD_TSDB_DEF_H_ #include "mallocator.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlist.h" #include "thash.h" #include "tskiplist.h" diff --git a/source/dnode/vnode/tsdb/src/tsdbHealth.c b/source/dnode/vnode/tsdb/src/tsdbHealth.c index 8198c480334912b1ce373ceca7b82409f5a644f2..4205f3e90fc692faf64c538f0104d727a95d55ee 100644 --- a/source/dnode/vnode/tsdb/src/tsdbHealth.c +++ b/source/dnode/vnode/tsdb/src/tsdbHealth.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "query.h" #include "tglobal.h" diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 7f2ddb5723eac9c8e6d6cbd279c05ad1ba2506c2..31b59394639761c941d98660daeac589232b16b6 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -31,6 +31,11 @@ extern "C" { #define CTG_DEFAULT_INVALID_VERSION (-1) +enum { + CTG_READ = 1, + CTG_WRITE, +}; + typedef struct SVgroupListCache { int32_t vgroupVersion; SHashObj *cache; // key:vgId, value:SVgroupInfo @@ -41,12 +46,12 @@ typedef struct SDBVgroupCache { } SDBVgroupCache; typedef struct STableMetaCache { + SRWLatch stableLock; SHashObj *cache; //key:fulltablename, value:STableMeta SHashObj *stableCache; //key:suid, value:STableMeta* } STableMetaCache; typedef struct SCatalog { - SVgroupListCache vgroupCache; SDBVgroupCache dbCache; STableMetaCache tableCache; } SCatalog; @@ -67,12 +72,36 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); #define ctgTrace(...) do { if (ctgDebugFlag & DEBUG_TRACE) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgDebugL(...) do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLongString("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0) - #define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0) #define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define CTG_LOCK(type, _lock) do { \ + if (CTG_READ == (type)) { \ + if ((*(_lock)) < 0) assert(0); \ + taosRLockLatch(_lock); \ + ctgDebug("CTG RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } else { \ + if ((*(_lock)) < 0) assert(0); \ + taosWLockLatch(_lock); \ + ctgDebug("CTG WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } \ +} while (0) + +#define CTG_UNLOCK(type, _lock) do { \ + if (CTG_READ == (type)) { \ + if ((*(_lock)) <= 0) assert(0); \ + taosRUnLockLatch(_lock); \ + ctgDebug("CTG RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } else { \ + if ((*(_lock)) <= 0) assert(0); \ + taosWUnLockLatch(_lock); \ + ctgDebug("CTG WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } \ +} while (0) + + #ifdef __cplusplus } #endif diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index bc7a8b8aff670a5e8a249f4911d47e0b0f244085..b632ac772c69d3dbc27df46f5ea1aac3cf0989c1 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -13,31 +13,35 @@ * along with this program. If not, see . */ -#include "catalogInt.h" #include "trpc.h" #include "query.h" #include "tname.h" +#include "catalogInt.h" SCatalogMgmt ctgMgmt = {0}; -int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, SDBVgroupInfo *dbInfo, int32_t *exist) { +int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, SDBVgroupInfo **dbInfo, bool *inCache) { if (NULL == pCatalog->dbCache.cache) { - *exist = 0; + *inCache = false; return TSDB_CODE_SUCCESS; } - SDBVgroupInfo *info = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName)); + SDBVgroupInfo *info = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); if (NULL == info) { - *exist = 0; + *inCache = false; return TSDB_CODE_SUCCESS; } - if (dbInfo) { - *dbInfo = *info; + CTG_LOCK(CTG_READ, &info->lock); + if (NULL == info->vgInfo) { + CTG_UNLOCK(CTG_READ, &info->lock); + *inCache = false; + return TSDB_CODE_SUCCESS; } - *exist = 1; + *dbInfo = info; + *inCache = true; return TSDB_CODE_SUCCESS; } @@ -49,22 +53,11 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; - CTG_ERR_RET(queryBuildMsg[TSDB_MSG_TYPE_USE_DB](input, &msg, 0, &msgLen)); - - char *pMsg = rpcMallocCont(msgLen); - if (NULL == pMsg) { - ctgError("rpc malloc %d failed", msgLen); - tfree(msg); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); - } - - memcpy(pMsg, msg, msgLen); - - tfree(msg); + CTG_ERR_RET(queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)](input, &msg, 0, &msgLen)); SRpcMsg rpcMsg = { - .msgType = TSDB_MSG_TYPE_USE_DB, - .pCont = pMsg, + .msgType = TDMT_MND_USE_DB, + .pCont = msg, .contLen = msgLen, }; @@ -76,62 +69,66 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp CTG_ERR_RET(rpcRsp.code); } - CTG_ERR_RET(queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB](out, rpcRsp.pCont, rpcRsp.contLen)); + CTG_ERR_RET(queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)](out, rpcRsp.pCont, rpcRsp.contLen)); return TSDB_CODE_SUCCESS; } -int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const char *dbName, const char* pTableName, STableMeta** pTableMeta, int32_t *exist) { +int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist) { if (NULL == pCatalog->tableCache.cache) { *exist = 0; return TSDB_CODE_SUCCESS; } char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); - snprintf(tbFullName, sizeof(tbFullName), "%s.%s", dbName, pTableName); + *pTableMeta = NULL; - STableMeta *tbMeta = taosHashGet(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName)); + size_t sz = 0; + STableMeta *tbMeta = taosHashGetCloneExt(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName), NULL, (void **)pTableMeta, &sz); - if (NULL == tbMeta) { + if (NULL == *pTableMeta) { *exist = 0; return TSDB_CODE_SUCCESS; } - if (tbMeta->tableType == TSDB_CHILD_TABLE) { - STableMeta **stbMeta = taosHashGet(pCatalog->tableCache.stableCache, &tbMeta->suid, sizeof(tbMeta->suid)); - if (NULL == stbMeta || NULL == *stbMeta) { - *exist = 0; - return TSDB_CODE_SUCCESS; - } - - if ((*stbMeta)->suid != tbMeta->suid) { - ctgError("stable cache error, expected suid:%"PRId64 ",actual suid:%"PRId64, tbMeta->suid, (*stbMeta)->suid); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); - } + *exist = 1; - int32_t metaSize = sizeof(STableMeta) + ((*stbMeta)->tableInfo.numOfTags + (*stbMeta)->tableInfo.numOfColumns) * sizeof(SSchema); - *pTableMeta = calloc(1, metaSize); - if (NULL == *pTableMeta) { - ctgError("calloc size[%d] failed", metaSize); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); - } + if (tbMeta->tableType != TSDB_CHILD_TABLE) { + return TSDB_CODE_SUCCESS; + } + + CTG_LOCK(CTG_READ, &pCatalog->tableCache.stableLock); + + STableMeta **stbMeta = taosHashGet(pCatalog->tableCache.stableCache, &tbMeta->suid, sizeof(tbMeta->suid)); + if (NULL == stbMeta || NULL == *stbMeta) { + CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock); + qError("no stable:%"PRIx64 " meta in cache", tbMeta->suid); + tfree(*pTableMeta); + *exist = 0; + return TSDB_CODE_SUCCESS; + } - memcpy(*pTableMeta, tbMeta, sizeof(SCTableMeta)); - memcpy(&(*pTableMeta)->sversion, &(*stbMeta)->sversion, metaSize - sizeof(SCTableMeta)); - } else { - int32_t metaSize = sizeof(STableMeta) + (tbMeta->tableInfo.numOfTags + tbMeta->tableInfo.numOfColumns) * sizeof(SSchema); - *pTableMeta = calloc(1, metaSize); - if (NULL == *pTableMeta) { - ctgError("calloc size[%d] failed", metaSize); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); - } + if ((*stbMeta)->suid != tbMeta->suid) { + CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock); + tfree(*pTableMeta); + ctgError("stable cache error, expected suid:%"PRId64 ",actual suid:%"PRId64, tbMeta->suid, (*stbMeta)->suid); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } - memcpy(*pTableMeta, tbMeta, metaSize); + int32_t metaSize = sizeof(STableMeta) + ((*stbMeta)->tableInfo.numOfTags + (*stbMeta)->tableInfo.numOfColumns) * sizeof(SSchema); + *pTableMeta = realloc(*pTableMeta, metaSize); + if (NULL == *pTableMeta) { + CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock); + ctgError("calloc size[%d] failed", metaSize); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } - *exist = 1; + memcpy(&(*pTableMeta)->sversion, &(*stbMeta)->sversion, metaSize - sizeof(SCTableMeta)); + + CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock); return TSDB_CODE_SUCCESS; } @@ -146,8 +143,43 @@ void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) { } } +int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMetaOutput* output) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == output) { + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); + + SBuildTableMetaInput bInput = {.vgId = 0, .tableFullName = tbFullName}; + char *msg = NULL; + SEpSet *pVnodeEpSet = NULL; + int32_t msgLen = 0; + + CTG_ERR_RET(queryBuildMsg[TMSG_INDEX(TDMT_MND_STB_META)](&bInput, &msg, 0, &msgLen)); + + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_STB_META, + .pCont = msg, + .contLen = msgLen, + }; + + SRpcMsg rpcRsp = {0}; + + rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp); + + if (TSDB_CODE_SUCCESS != rpcRsp.code) { + ctgError("error rsp for table meta, code:%x", rpcRsp.code); + CTG_ERR_RET(rpcRsp.code); + } + + CTG_ERR_RET(queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_STB_META)](output, rpcRsp.pCont, rpcRsp.contLen)); -int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char *pDBName, const char* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { + return TSDB_CODE_SUCCESS; +} + + +int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char *pDBName, const char* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pDBName || NULL == pTableName || NULL == vgroupInfo || NULL == output) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } @@ -161,10 +193,10 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; - CTG_ERR_RET(queryBuildMsg[TSDB_MSG_TYPE_TABLE_META](&bInput, &msg, 0, &msgLen)); + CTG_ERR_RET(queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)](&bInput, &msg, 0, &msgLen)); SRpcMsg rpcMsg = { - .msgType = TSDB_MSG_TYPE_TABLE_META, + .msgType = TDMT_VND_TABLE_META, .pCont = msg, .contLen = msgLen, }; @@ -181,7 +213,7 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE CTG_ERR_RET(rpcRsp.code); } - CTG_ERR_RET(queryProcessMsgRsp[TSDB_MSG_TYPE_TABLE_META](output, rpcRsp.pCont, rpcRsp.contLen)); + CTG_ERR_RET(queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)](output, rpcRsp.pCont, rpcRsp.contLen)); return TSDB_CODE_SUCCESS; } @@ -197,41 +229,66 @@ int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) { return TSDB_CODE_SUCCESS; } -int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *pMgmtEps, SDBVgroupInfo *dbInfo, SArray* vgroupList) { +int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *pMgmtEps, SDBVgroupInfo *dbInfo, SArray** vgroupList) { SHashObj *vgroupHash = NULL; SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; + int32_t code = 0; + + vgList = taosArrayInit(taosHashGetSize(dbInfo->vgInfo), sizeof(SVgroupInfo)); + if (NULL == vgList) { + ctgError("taosArrayInit failed"); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + } void *pIter = taosHashIterate(dbInfo->vgInfo, NULL); while (pIter) { vgInfo = pIter; - if (NULL == taosArrayPush(vgroupList, vgInfo)) { + if (NULL == taosArrayPush(vgList, vgInfo)) { ctgError("taosArrayPush failed"); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } pIter = taosHashIterate(dbInfo->vgInfo, pIter); vgInfo = NULL; } + *vgroupList = vgList; + vgList = NULL; + return TSDB_CODE_SUCCESS; + +_return: + + if (vgList) { + taosArrayDestroy(vgList); + } + + CTG_RET(code); } -int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const char *pDBName, const char *pTableName, SVgroupInfo *pVgroup) { +int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) { + int32_t code = 0; + + CTG_LOCK(CTG_READ, &dbInfo->lock); + int32_t vgNum = taosHashGetSize(dbInfo->vgInfo); + char db[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(pTableName, db); + if (vgNum <= 0) { - ctgError("db[%s] vgroup cache invalid, vgroup number:%d", pDBName, vgNum); + ctgError("db[%s] vgroup cache invalid, vgroup number:%d", db, vgNum); CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED); } tableNameHashFp fp = NULL; SVgroupInfo *vgInfo = NULL; - CTG_ERR_RET(ctgGetHashFunction(dbInfo->hashMethod, &fp)); + CTG_ERR_JRET(ctgGetHashFunction(dbInfo->hashMethod, &fp)); char tbFullName[TSDB_TABLE_FNAME_LEN]; - - snprintf(tbFullName, sizeof(tbFullName), "%s.%s", pDBName, pTableName); + tNameExtractFullName(pTableName, tbFullName); uint32_t hashValue = (*fp)(tbFullName, (uint32_t)strlen(tbFullName)); @@ -248,32 +305,36 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const char *pDBName, co if (NULL == vgInfo) { ctgError("no hash range found for hashvalue[%u]", hashValue); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } *pVgroup = *vgInfo; - return TSDB_CODE_SUCCESS; +_return: + + CTG_UNLOCK(CTG_READ, &dbInfo->lock); + + CTG_RET(TSDB_CODE_SUCCESS); } -int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, bool forceUpdate, STableMeta** pTableMeta) { - if (NULL == pCatalog || NULL == pDBName || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) { +int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } - + int32_t exist = 0; if (!forceUpdate) { - CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pDBName, pTableName, pTableMeta, &exist)); + CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); if (exist) { return TSDB_CODE_SUCCESS; } } - CTG_ERR_RET(catalogRenewTableMeta(pCatalog, pRpc, pMgmtEps, pDBName, pTableName)); + CTG_ERR_RET(catalogRenewTableMeta(pCatalog, pRpc, pMgmtEps, pTableName)); - CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pDBName, pTableName, pTableMeta, &exist)); + CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); if (0 == exist) { ctgError("get table meta from cache failed, but fetch succeed"); @@ -285,89 +346,130 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output) { + int32_t code = 0; + if (output->metaNum != 1 && output->metaNum != 2) { ctgError("invalid table meta number[%d] got from meta rsp", output->metaNum); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } if (NULL == output->tbMeta) { ctgError("no valid table meta got from meta rsp"); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } if (NULL == pCatalog->tableCache.cache) { pCatalog->tableCache.cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->tableCache.cache) { ctgError("init hash[%d] for tablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } } - if (NULL == pCatalog->tableCache.cache) { - pCatalog->tableCache.cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->tableCache.cache) { - ctgError("init hash[%d] for tablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); - } - + if (NULL == pCatalog->tableCache.stableCache) { pCatalog->tableCache.stableCache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->tableCache.stableCache) { ctgError("init hash[%d] for stablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } } if (output->metaNum == 2) { if (taosHashPut(pCatalog->tableCache.cache, output->ctbFname, strlen(output->ctbFname), &output->ctbMeta, sizeof(output->ctbMeta)) != 0) { ctgError("push ctable[%s] to table cache failed", output->ctbFname); - goto error_exit; + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } if (TSDB_SUPER_TABLE != output->tbMeta->tableType) { ctgError("table type[%d] error, expected:%d", output->tbMeta->tableType, TSDB_SUPER_TABLE); - goto error_exit; + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } } - if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, sizeof(*output->tbMeta)) != 0) { - ctgError("push table[%s] to table cache failed", output->tbFname); - goto error_exit; - } + int32_t tbSize = sizeof(*output->tbMeta) + sizeof(SSchema) * (output->tbMeta->tableInfo.numOfColumns + output->tbMeta->tableInfo.numOfTags); if (TSDB_SUPER_TABLE == output->tbMeta->tableType) { - if (taosHashPut(pCatalog->tableCache.stableCache, &output->tbMeta->suid, sizeof(output->tbMeta->suid), &output->tbMeta, POINTER_BYTES) != 0) { + CTG_LOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); + if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) { + CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); + ctgError("push table[%s] to table cache failed", output->tbFname); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + } + + STableMeta *tbMeta = taosHashGet(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname)); + if (taosHashPut(pCatalog->tableCache.stableCache, &output->tbMeta->suid, sizeof(output->tbMeta->suid), &tbMeta, POINTER_BYTES) != 0) { + CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); ctgError("push suid[%"PRIu64"] to stable cache failed", output->tbMeta->suid); - goto error_exit; + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + } + CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); + } else { + if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) { + ctgError("push table[%s] to table cache failed", output->tbFname); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } } + +_return: + tfree(output->tbMeta); - return TSDB_CODE_SUCCESS; + CTG_RET(code); +} + + +int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo** dbInfo) { + bool inCache = false; + if (0 == forceUpdate) { + CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); -error_exit: - if (pCatalog->vgroupCache.cache) { - taosHashCleanup(pCatalog->vgroupCache.cache); - pCatalog->vgroupCache.cache = NULL; + if (inCache) { + return TSDB_CODE_SUCCESS; + } } - pCatalog->vgroupCache.vgroupVersion = CTG_DEFAULT_INVALID_VERSION; + SUseDbOutput DbOut = {0}; + SBuildUseDBInput input = {0}; + + strncpy(input.db, dbName, sizeof(input.db)); + input.db[sizeof(input.db) - 1] = 0; + input.vgVersion = CTG_DEFAULT_INVALID_VERSION; + + CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut)); + + CTG_ERR_RET(catalogUpdateDBVgroup(pCatalog, dbName, &DbOut.dbVgroup)); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); + + return TSDB_CODE_SUCCESS; } + int32_t catalogInit(SCatalogCfg *cfg) { - ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == ctgMgmt.pCluster) { - CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CACHE_CLUSTER_NUMBER); + if (ctgMgmt.pCluster) { + ctgError("catalog already init"); + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } if (cfg) { memcpy(&ctgMgmt.cfg, cfg, sizeof(*cfg)); + + if (ctgMgmt.cfg.maxDBCacheNum == 0) { + ctgMgmt.cfg.maxDBCacheNum = CTG_DEFAULT_CACHE_DB_NUMBER; + } + + if (ctgMgmt.cfg.maxTblCacheNum == 0) { + ctgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TABLEMETA_NUMBER; + } } else { - ctgMgmt.cfg.enableVgroupCache = true; ctgMgmt.cfg.maxDBCacheNum = CTG_DEFAULT_CACHE_DB_NUMBER; ctgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TABLEMETA_NUMBER; } + ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (NULL == ctgMgmt.pCluster) { + CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CACHE_CLUSTER_NUMBER); + } + return TSDB_CODE_SUCCESS; } @@ -382,21 +484,19 @@ int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle } size_t clen = strlen(clusterId); - SCatalog *clusterCtg = (SCatalog *)taosHashGet(ctgMgmt.pCluster, clusterId, clen); + SCatalog **ctg = (SCatalog **)taosHashGet(ctgMgmt.pCluster, clusterId, clen); - if (clusterCtg) { - *catalogHandle = clusterCtg; + if (ctg && (*ctg)) { + *catalogHandle = *ctg; return TSDB_CODE_SUCCESS; } - clusterCtg = calloc(1, sizeof(*clusterCtg)); + SCatalog *clusterCtg = calloc(1, sizeof(SCatalog)); if (NULL == clusterCtg) { - ctgError("calloc %d failed", (int32_t)sizeof(*clusterCtg)); + ctgError("calloc %d failed", (int32_t)sizeof(SCatalog)); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } - clusterCtg->vgroupCache.vgroupVersion = CTG_DEFAULT_INVALID_VERSION; - if (taosHashPut(ctgMgmt.pCluster, clusterId, clen, &clusterCtg, POINTER_BYTES)) { ctgError("put cluster %s cache to hash failed", clusterId); tfree(clusterCtg); @@ -418,25 +518,86 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, return TSDB_CODE_SUCCESS; } - SDBVgroupInfo * dbInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName)); + SDBVgroupInfo * dbInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); if (NULL == dbInfo) { *version = CTG_DEFAULT_INVALID_VERSION; return TSDB_CODE_SUCCESS; } *version = dbInfo->vgVersion; + taosHashRelease(pCatalog->dbCache.cache, dbInfo); return TSDB_CODE_SUCCESS; } -int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) { +int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SArray** vgroupList) { + if (NULL == pCatalog || NULL == dbName || NULL == pRpc || NULL == pMgmtEps || NULL == vgroupList) { + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + SDBVgroupInfo* db = NULL; + int32_t code = 0; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; + + CTG_ERR_JRET(ctgGetDBVgroup(pCatalog, pRpc, pMgmtEps, dbName, forceUpdate, &db)); + + vgList = taosArrayInit(taosHashGetSize(db->vgInfo), sizeof(SVgroupInfo)); + if (NULL == vgList) { + ctgError("taosArrayInit failed"); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + } + + void *pIter = taosHashIterate(db->vgInfo, NULL); + while (pIter) { + vgInfo = pIter; + + if (NULL == taosArrayPush(vgList, vgInfo)) { + ctgError("taosArrayPush failed"); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + } + + pIter = taosHashIterate(db->vgInfo, pIter); + vgInfo = NULL; + } + + *vgroupList = vgList; + vgList = NULL; + +_return: + + if (db) { + CTG_UNLOCK(CTG_READ, &db->lock); + taosHashRelease(pCatalog->dbCache.cache, db); + } + + if (vgList) { + taosArrayDestroy(vgList); + vgList = NULL; + } + + CTG_RET(code); +} + + +int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) { if (NULL == pCatalog || NULL == dbName || NULL == dbInfo) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } if (dbInfo->vgVersion < 0) { if (pCatalog->dbCache.cache) { - taosHashRemove(pCatalog->dbCache.cache, dbName, strlen(dbName)); + SDBVgroupInfo *oldInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); + if (oldInfo) { + CTG_LOCK(CTG_WRITE, &oldInfo->lock); + if (oldInfo->vgInfo) { + taosHashCleanup(oldInfo->vgInfo); + oldInfo->vgInfo = NULL; + } + CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); + + taosHashRelease(pCatalog->dbCache.cache, oldInfo); + } } ctgWarn("remove db [%s] from cache", dbName); @@ -444,16 +605,22 @@ int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName } if (NULL == pCatalog->dbCache.cache) { - pCatalog->dbCache.cache = taosHashInit(CTG_DEFAULT_CACHE_DB_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->dbCache.cache) { ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } } else { - SDBVgroupInfo *oldInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName)); - if (oldInfo && oldInfo->vgInfo) { - taosHashCleanup(oldInfo->vgInfo); - oldInfo->vgInfo = NULL; + SDBVgroupInfo *oldInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); + if (oldInfo) { + CTG_LOCK(CTG_WRITE, &oldInfo->lock); + if (oldInfo->vgInfo) { + taosHashCleanup(oldInfo->vgInfo); + oldInfo->vgInfo = NULL; + } + CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); + + taosHashRelease(pCatalog->dbCache.cache, oldInfo); } } @@ -465,119 +632,116 @@ int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName return TSDB_CODE_SUCCESS; } - - - -int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo* dbInfo) { - if (NULL == pCatalog || NULL == dbName || NULL == pRpc || NULL == pMgmtEps) { - CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); - } - - int32_t exist = 0; - - if (0 == forceUpdate) { - CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &exist)); - - if (exist) { - return TSDB_CODE_SUCCESS; - } - } - - SUseDbOutput DbOut = {0}; - SBuildUseDBInput input = {0}; - - strncpy(input.db, dbName, sizeof(input.db)); - input.db[sizeof(input.db) - 1] = 0; - input.vgVersion = CTG_DEFAULT_INVALID_VERSION; - - CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut)); - - CTG_ERR_RET(catalogUpdateDBVgroupCache(pCatalog, dbName, &DbOut.dbVgroup)); - - if (dbInfo) { - *dbInfo = DbOut.dbVgroup; - } - - return TSDB_CODE_SUCCESS; -} - -int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, false, pTableMeta); +int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta); } -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName) { - if (NULL == pCatalog || NULL == pDBName || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName) { +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } SVgroupInfo vgroupInfo = {0}; - - CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &vgroupInfo)); + int32_t code = 0; + + CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo)); STableMetaOutput output = {0}; - CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &vgroupInfo, &output)); + //CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &vgroupInfo, &output)); - CTG_ERR_RET(ctgUpdateTableMetaCache(pCatalog, &output)); + CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); + + CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output)); + +_return: tfree(output.tbMeta); - return TSDB_CODE_SUCCESS; + CTG_RET(code); } -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, true, pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, true, pTableMeta); } -int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray* pVgroupList) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pDBName || NULL == pTableName || NULL == pVgroupList) { +int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pVgroupList) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } STableMeta *tbMeta = NULL; int32_t code = 0; SVgroupInfo vgroupInfo = {0}; - SDBVgroupInfo dbVgroup = {0}; + SDBVgroupInfo* dbVgroup = NULL; + SArray *vgList = NULL; + + *pVgroupList = NULL; - CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &tbMeta)); + CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pTableName, &tbMeta)); - CTG_ERR_JRET(catalogGetDBVgroup(pCatalog, pRpc, pMgmtEps, pDBName, false, &dbVgroup)); + char db[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(pTableName, db); + CTG_ERR_JRET(ctgGetDBVgroup(pCatalog, pRpc, pMgmtEps, db, false, &dbVgroup)); if (tbMeta->tableType == TSDB_SUPER_TABLE) { - CTG_ERR_JRET(ctgGetVgInfoFromDB(pCatalog, pRpc, pMgmtEps, &dbVgroup, pVgroupList)); + CTG_ERR_JRET(ctgGetVgInfoFromDB(pCatalog, pRpc, pMgmtEps, dbVgroup, pVgroupList)); } else { int32_t vgId = tbMeta->vgId; - if (NULL == taosHashGetClone(dbVgroup.vgInfo, &vgId, sizeof(vgId), &vgroupInfo)) { + if (NULL == taosHashGetClone(dbVgroup->vgInfo, &vgId, sizeof(vgId), &vgroupInfo)) { ctgError("vgId[%d] not found in vgroup list", vgId); - CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + vgList = taosArrayInit(1, sizeof(SVgroupInfo)); + if (NULL == vgList) { + ctgError("taosArrayInit failed"); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } - if (NULL == taosArrayPush(pVgroupList, &vgroupInfo)) { + if (NULL == taosArrayPush(vgList, &vgroupInfo)) { ctgError("push vgroupInfo to array failed"); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } + + *pVgroupList = vgList; + vgList = NULL; } _return: tfree(tbMeta); + + if (dbVgroup) { + CTG_UNLOCK(CTG_READ, &dbVgroup->lock); + taosHashRelease(pCatalog->dbCache.cache, dbVgroup); + } + + if (vgList) { + taosArrayDestroy(vgList); + vgList = NULL; + } CTG_RET(code); } -int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter, const SEpSet *pMgmtEps, const char *pDBName, const char *pTableName, SVgroupInfo *pVgroup) { - SDBVgroupInfo dbInfo = {0}; +int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter, const SEpSet *pMgmtEps, const SName *pTableName, SVgroupInfo *pVgroup) { + SDBVgroupInfo* dbInfo = NULL; int32_t code = 0; - int32_t vgId = 0; - CTG_ERR_RET(catalogGetDBVgroup(pCatalog, pTransporter, pMgmtEps, pDBName, false, &dbInfo)); + char db[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(pTableName, db); - if (dbInfo.vgVersion < 0 || NULL == dbInfo.vgInfo) { - ctgError("db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p", pDBName, dbInfo.vgVersion, dbInfo.vgInfo); - CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED); - } + CTG_ERR_RET(ctgGetDBVgroup(pCatalog, pTransporter, pMgmtEps, db, false, &dbInfo)); + + CTG_ERR_JRET(ctgGetVgInfoFromHashValue(dbInfo, pTableName, pVgroup)); + +_return: - CTG_ERR_RET(ctgGetVgInfoFromHashValue(&dbInfo, pDBName, pTableName, pVgroup)); + if (dbInfo) { + CTG_UNLOCK(CTG_READ, &dbInfo->lock); + taosHashRelease(pCatalog->dbCache.cache, dbInfo); + } CTG_RET(code); } @@ -591,23 +755,23 @@ int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* p int32_t code = 0; if (pReq->pTableName) { - char dbName[TSDB_FULL_DB_NAME_LEN]; int32_t tbNum = (int32_t)taosArrayGetSize(pReq->pTableName); - if (tbNum > 0) { - pRsp->pTableMeta = taosArrayInit(tbNum, POINTER_BYTES); - if (NULL == pRsp->pTableMeta) { - ctgError("taosArrayInit num[%d] failed", tbNum); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); - } + if (tbNum <= 0) { + ctgError("empty table name list"); + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + pRsp->pTableMeta = taosArrayInit(tbNum, POINTER_BYTES); + if (NULL == pRsp->pTableMeta) { + ctgError("taosArrayInit num[%d] failed", tbNum); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } for (int32_t i = 0; i < tbNum; ++i) { SName *name = taosArrayGet(pReq->pTableName, i); STableMeta *pTableMeta = NULL; - snprintf(dbName, sizeof(dbName), "%d.%s", name->acctId, name->dbname); - - CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, dbName, name->tname, &pTableMeta)); + CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, name, &pTableMeta)); if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) { ctgError("taosArrayPush failed, idx:%d", i); @@ -629,13 +793,14 @@ _return: } taosArrayDestroy(pRsp->pTableMeta); + pRsp->pTableMeta = NULL; } CTG_RET(code); } -int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pQnodeEpSet) { +int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pQnodeList) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 22b5b7adc4d78c563096c0d1e9765d4689a01993..0ad00046cd3409ed21f4650ad19c89062ff2fe53 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -32,27 +32,28 @@ #include "stub.h" #include "addr_any.h" -typedef struct SAppInstInfo { - int64_t numOfConns; - SCorEpSet mgmtEp; -} SAppInstInfo; - -typedef struct STscObj { - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - char acctId[TSDB_ACCT_ID_LEN]; - char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; - uint32_t connId; - uint64_t id; // ref ID returned by taosAddRef -// struct SSqlObj *sqlList; - void *pTransporter; - pthread_mutex_t mutex; // used to protect the operation on db - int32_t numOfReqs; // number of sqlObj from this tscObj - SAppInstInfo *pAppInfo; -} STscObj; + namespace { +void ctgTestSetPrepareTableMeta(); +void ctgTestSetPrepareCTableMeta(); +void ctgTestSetPrepareSTableMeta(); + + +int32_t ctgTestVgNum = 10; +int32_t ctgTestColNum = 2; +int32_t ctgTestTagNum = 1; +int32_t ctgTestSVersion = 1; +int32_t ctgTestTVersion = 1; + +char *ctgTestClusterId = "cluster1"; +char *ctgTestDbname = "1.db1"; +char *ctgTestTablename = "table1"; +char *ctgTestCTablename = "ctable1"; +char *ctgTestSTablename = "stable1"; + + void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg)); strcpy(pReq->db, "1.db1"); @@ -79,7 +80,7 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pReq; rpcMsg.contLen = sizeof(SCreateDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB; + rpcMsg.msgType = TDMT_MND_CREATE_DB; SRpcMsg rpcRsp = {0}; @@ -88,56 +89,563 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { ASSERT_EQ(rpcRsp.code, 0); } -void __rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { +void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { SUseDbRsp *rspMsg = NULL; //todo + pRsp->code =0; + pRsp->contLen = sizeof(SUseDbRsp) + ctgTestVgNum * sizeof(SVgroupInfo); + pRsp->pCont = calloc(1, pRsp->contLen); + rspMsg = (SUseDbRsp *)pRsp->pCont; + strcpy(rspMsg->db, ctgTestDbname); + rspMsg->vgVersion = htonl(1); + rspMsg->vgNum = htonl(ctgTestVgNum); + rspMsg->hashMethod = 0; + + SVgroupInfo *vg = NULL; + uint32_t hashUnit = UINT32_MAX / ctgTestVgNum; + for (int32_t i = 0; i < ctgTestVgNum; ++i) { + vg = &rspMsg->vgroupInfo[i]; + + vg->vgId = htonl(i + 1); + vg->hashBegin = htonl(i * hashUnit); + vg->hashEnd = htonl(hashUnit * (i + 1) - 1); + vg->numOfEps = i % TSDB_MAX_REPLICA + 1; + vg->inUse = i % vg->numOfEps; + for (int32_t n = 0; n < vg->numOfEps; ++n) { + SEpAddrMsg *addr = &vg->epAddr[n]; + strcpy(addr->fqdn, "a0"); + addr->port = htons(n + 22); + } + } + + vg->hashEnd = htonl(UINT32_MAX); + + return; +} + + + + +void ctgTestPrepareTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + STableMetaMsg *rspMsg = NULL; //todo + + pRsp->code =0; + pRsp->contLen = sizeof(STableMetaMsg) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema); + pRsp->pCont = calloc(1, pRsp->contLen); + rspMsg = (STableMetaMsg *)pRsp->pCont; + sprintf(rspMsg->tbFname, "%s.%s", ctgTestDbname, ctgTestTablename); + rspMsg->numOfTags = 0; + rspMsg->numOfColumns = htonl(ctgTestColNum); + rspMsg->precision = 1; + rspMsg->tableType = TSDB_NORMAL_TABLE; + rspMsg->update = 1; + rspMsg->sversion = htonl(ctgTestSVersion); + rspMsg->tversion = htonl(ctgTestTVersion); + rspMsg->suid = 0; + rspMsg->tuid = htobe64(0x0000000000000001); + rspMsg->vgId = htonl(8); + + SSchema *s = NULL; + s = &rspMsg->pSchema[0]; + s->type = TSDB_DATA_TYPE_TIMESTAMP; + s->colId = htonl(0); + s->bytes = htonl(8); + strcpy(s->name, "ts"); + + s = &rspMsg->pSchema[1]; + s->type = TSDB_DATA_TYPE_INT; + s->colId = htonl(1); + s->bytes = htonl(4); + strcpy(s->name, "col1"); + + return; +} + + +void ctgTestPrepareCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + STableMetaMsg *rspMsg = NULL; //todo + + pRsp->code =0; + pRsp->contLen = sizeof(STableMetaMsg) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema); + pRsp->pCont = calloc(1, pRsp->contLen); + rspMsg = (STableMetaMsg *)pRsp->pCont; + sprintf(rspMsg->tbFname, "%s.%s", ctgTestDbname, ctgTestCTablename); + sprintf(rspMsg->stbFname, "%s.%s", ctgTestDbname, ctgTestSTablename); + rspMsg->numOfTags = htonl(ctgTestTagNum); + rspMsg->numOfColumns = htonl(ctgTestColNum); + rspMsg->precision = 1; + rspMsg->tableType = TSDB_CHILD_TABLE; + rspMsg->update = 1; + rspMsg->sversion = htonl(ctgTestSVersion); + rspMsg->tversion = htonl(ctgTestTVersion); + rspMsg->suid = htobe64(0x0000000000000002); + rspMsg->tuid = htobe64(0x0000000000000003); + rspMsg->vgId = htonl(9); + + SSchema *s = NULL; + s = &rspMsg->pSchema[0]; + s->type = TSDB_DATA_TYPE_TIMESTAMP; + s->colId = htonl(0); + s->bytes = htonl(8); + strcpy(s->name, "ts"); + + s = &rspMsg->pSchema[1]; + s->type = TSDB_DATA_TYPE_INT; + s->colId = htonl(1); + s->bytes = htonl(4); + strcpy(s->name, "col1s"); + + s = &rspMsg->pSchema[2]; + s->type = TSDB_DATA_TYPE_BINARY; + s->colId = htonl(2); + s->bytes = htonl(12); + strcpy(s->name, "tag1s"); + + + return; +} + + +void ctgTestPrepareSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + STableMetaMsg *rspMsg = NULL; //todo + + pRsp->code =0; + pRsp->contLen = sizeof(STableMetaMsg) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema); + pRsp->pCont = calloc(1, pRsp->contLen); + rspMsg = (STableMetaMsg *)pRsp->pCont; + sprintf(rspMsg->tbFname, "%s.%s", ctgTestDbname, ctgTestSTablename); + sprintf(rspMsg->stbFname, "%s.%s", ctgTestDbname, ctgTestSTablename); + rspMsg->numOfTags = htonl(ctgTestTagNum); + rspMsg->numOfColumns = htonl(ctgTestColNum); + rspMsg->precision = 1; + rspMsg->tableType = TSDB_SUPER_TABLE; + rspMsg->update = 1; + rspMsg->sversion = htonl(ctgTestSVersion); + rspMsg->tversion = htonl(ctgTestTVersion); + rspMsg->suid = htobe64(0x0000000000000002); + rspMsg->tuid = htobe64(0x0000000000000003); + rspMsg->vgId = 0; + + SSchema *s = NULL; + s = &rspMsg->pSchema[0]; + s->type = TSDB_DATA_TYPE_TIMESTAMP; + s->colId = htonl(0); + s->bytes = htonl(8); + strcpy(s->name, "ts"); + + s = &rspMsg->pSchema[1]; + s->type = TSDB_DATA_TYPE_INT; + s->colId = htonl(1); + s->bytes = htonl(4); + strcpy(s->name, "col1s"); + + s = &rspMsg->pSchema[2]; + s->type = TSDB_DATA_TYPE_BINARY; + s->colId = htonl(2); + s->bytes = htonl(12); + strcpy(s->name, "tag1s"); + + + return; +} + +void ctgTestPrepareDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp); + + ctgTestSetPrepareTableMeta(); + + return; +} + + +void ctgTestPrepareDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp); + + ctgTestSetPrepareCTableMeta(); + + return; +} + +void ctgTestPrepareDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp); + + ctgTestSetPrepareSTableMeta(); + return; } -void initTestEnv() { + +void ctgTestSetPrepareDbVgroups() { static Stub stub; - stub.set(rpcSendRecv, __rpcSendRecv); + stub.set(rpcSendRecv, ctgTestPrepareDbVgroups); { AddrAny any("libtransport.so"); std::map result; any.get_global_func_addr_dynsym("^rpcSendRecv$", result); for (const auto& f : result) { - stub.set(f.second, __rpcSendRecv); + stub.set(f.second, ctgTestPrepareDbVgroups); } } } +void ctgTestSetPrepareTableMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareTableMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareTableMeta); + } + } +} + +void ctgTestSetPrepareCTableMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareCTableMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareCTableMeta); + } + } +} + +void ctgTestSetPrepareSTableMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareSTableMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareSTableMeta); + } + } +} +void ctgTestSetPrepareDbVgroupsAndNormalMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndNormalMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareDbVgroupsAndNormalMeta); + } + } } -TEST(testCase, normalCase) { - STscObj* pConn = (STscObj *)taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; +void ctgTestSetPrepareDbVgroupsAndChildMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndChildMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareDbVgroupsAndChildMeta); + } + } +} + +void ctgTestSetPrepareDbVgroupsAndSuperMeta() { + static Stub stub; + stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndSuperMeta); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, ctgTestPrepareDbVgroupsAndSuperMeta); + } + } +} + + +} + +TEST(tableMeta, normalTable) { struct SCatalog* pCtg = NULL; void *mockPointer = (void *)0x1; SVgroupInfo vgInfo = {0}; + ctgTestSetPrepareDbVgroups(); + initQueryModuleMsgHandle(); - sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); int32_t code = catalogInit(NULL); ASSERT_EQ(code, 0); - code = catalogGetHandle(clusterId, &pCtg); + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); + ASSERT_EQ(code, 0); + ASSERT_EQ(vgInfo.vgId, 8); + ASSERT_EQ(vgInfo.numOfEps, 3); + + ctgTestSetPrepareTableMeta(); + + STableMeta *tableMeta = NULL; + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 8); + ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + tableMeta = NULL; + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 8); + ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + catalogDestroy(); +} + +TEST(tableMeta, childTableCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo vgInfo = {0}; + + ctgTestSetPrepareDbVgroupsAndChildMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestCTablename); + + STableMeta *tableMeta = NULL; + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 9); + ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + tableMeta = NULL; + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 9); + ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + tableMeta = NULL; - code = catalogGetTableHashVgroup(pCtg, pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet, dbname, tablename, &vgInfo); + strcpy(n.tname, ctgTestSTablename); + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 0); + ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - taos_close(pConn); + catalogDestroy(); } +TEST(tableMeta, superTableCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo vgInfo = {0}; + + ctgTestSetPrepareDbVgroupsAndSuperMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestSTablename); + + STableMeta *tableMeta = NULL; + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 0); + ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + ctgTestSetPrepareCTableMeta(); + + tableMeta = NULL; + + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestCTablename); + code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 9); + ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + tableMeta = NULL; + code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 9); + ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + + + + catalogDestroy(); +} + +TEST(tableDistVgroup, normalTable) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; + + ctgTestSetPrepareDbVgroupsAndNormalMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); + vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); + ASSERT_EQ(vgInfo->vgId, 8); + ASSERT_EQ(vgInfo->numOfEps, 3); + + catalogDestroy(); +} + +TEST(tableDistVgroup, childTableCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; + + ctgTestSetPrepareDbVgroupsAndChildMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestCTablename); + + code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); + vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); + ASSERT_EQ(vgInfo->vgId, 9); + ASSERT_EQ(vgInfo->numOfEps, 4); + + + catalogDestroy(); +} + +TEST(tableDistVgroup, superTableCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; + + ctgTestSetPrepareDbVgroupsAndSuperMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = T_NAME_TABLE, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestSTablename); + + code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10); + vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); + ASSERT_EQ(vgInfo->vgId, 1); + ASSERT_EQ(vgInfo->numOfEps, 1); + vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1); + ASSERT_EQ(vgInfo->vgId, 2); + ASSERT_EQ(vgInfo->numOfEps, 2); + vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2); + ASSERT_EQ(vgInfo->vgId, 3); + ASSERT_EQ(vgInfo->numOfEps, 3); + + + catalogDestroy(); +} + + int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 1f7795e06f864b4c9bd516d86a578a16690f93a5..ac91f906c7a3a07a535b4f2e9cb33a4778d8f09f 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "thash.h" #include "executil.h" diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f37c7727f71af38a75ef59e86d0d2ffefd7566a9..f119627c69e387daaff29e8b37d4e88b09c27b86 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -14,14 +14,13 @@ */ #include #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "ttime.h" #include "exception.h" #include "executorimpl.h" #include "thash.h" -//#include "queryLog.h" #include "function.h" #include "tcompare.h" #include "tcompression.h" @@ -7685,7 +7684,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp type = s.type; bytes = s.bytes; } else if (pExprs[i].base.pColumns->info.colId == TSDB_TBNAME_COLUMN_INDEX && functionId == FUNCTION_TAGPRJ) { // parse the normal column - SSchema* s = tGetTbnameColumnSchema(); + const SSchema* s = tGetTbnameColumnSchema(); type = s->type; bytes = s->bytes; } else if (pExprs[i].base.pColumns->info.colId <= TSDB_UD_COLUMN_INDEX && pExprs[i].base.pColumns->info.colId > TSDB_RES_COL_ID) { @@ -7716,7 +7715,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp type = pCol->type; bytes = pCol->bytes; } else { - SSchema* s = tGetTbnameColumnSchema(); + const SSchema* s = tGetTbnameColumnSchema(); type = s->type; bytes = s->bytes; diff --git a/source/libs/function/inc/texpr.h b/source/libs/function/inc/texpr.h index 4ef0a7ab21e489b786f67ce4a775c4f0372dd419..eb4ab1b6e3a880817e6f9e048053d193039e4c2c 100644 --- a/source/libs/function/inc/texpr.h +++ b/source/libs/function/inc/texpr.h @@ -22,7 +22,7 @@ extern "C" { #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "taosdef.h" #include "tskiplist.h" #include "function.h" diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c index 00f59e8b87f80fe1fc09a93dbc3de01cabe22324..3af4a8fe5772e1a36a0104cb42c1bad5d8f9998e 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -16,7 +16,7 @@ #include "tscalarfunction.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "thash.h" #include "ttypes.h" diff --git a/source/libs/function/src/texpr.c b/source/libs/function/src/texpr.c index 70a7e9973fc80cb453bd2b3b347751454e4dfe4b..aa3e6ba0f0664b6c781b75e6cf70818b1e037ae1 100644 --- a/source/libs/function/src/texpr.c +++ b/source/libs/function/src/texpr.c @@ -18,7 +18,7 @@ #include "exception.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tbuffer.h" #include "tcompare.h" diff --git a/source/libs/function/src/tfill.c b/source/libs/function/src/tfill.c index 9575416a0305735a005d746e4522adac1543a8f4..db1bb3e7b8dd68f71c6e25bd7de52693d1b3f2d0 100644 --- a/source/libs/function/src/tfill.c +++ b/source/libs/function/src/tfill.c @@ -17,7 +17,7 @@ #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "ttypes.h" #include "tfill.h" diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index 23238ebab7c2c7936b8458b0df53944f3a3e0703..2229ac85618fc02f13f9d2bc0a7c8d4fd3f3b508 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -16,7 +16,7 @@ #include "thistogram.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" /** diff --git a/source/libs/index/CMakeLists.txt b/source/libs/index/CMakeLists.txt index 4805bd3b77ced7b51d76d8e47c83e2b01dc66a59..50e76abd3f4dc7c0d255baf08fce3d2a34a95606 100644 --- a/source/libs/index/CMakeLists.txt +++ b/source/libs/index/CMakeLists.txt @@ -3,7 +3,9 @@ add_library(index ${INDEX_SRC}) target_include_directories( index PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index" + PUBLIC "${CMAKE_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + ) target_link_libraries( index diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 2584a847ff2343db27a2f2acaf00a3f68c7aad68..048c9e804e6114017f2f91ed7bb2e70c50b52841 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -49,9 +49,10 @@ struct SIndex { SHashObj* colObj; // < field name, field id> int64_t suid; // current super table id, -1 is normal table - int colId; // field id allocated to cache int32_t cVersion; // current version allocated to cache + char* path; + SIndexStat stat; pthread_mutex_t mtx; }; @@ -88,41 +89,50 @@ typedef struct SIndexTermQuery { EIndexQueryType qType; } SIndexTermQuery; -#define indexFatal(...) \ - do { \ - if (sDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("index FATAL ", 255, __VA_ARGS__); \ - } \ +typedef struct Iterate Iterate; + +typedef struct IterateValue { + int8_t type; + char* colVal; + SArray* val; +} IterateValue; + +typedef struct Iterate { + void* iter; + IterateValue val; + bool (*next)(Iterate* iter); + IterateValue* (*getValue)(Iterate* iter); +} Iterate; + +void iterateValueDestroy(IterateValue* iv, bool destroy); + +extern void* indexQhandle; + +int indexFlushCacheTFile(SIndex* sIdx, void*); + +#define indexFatal(...) \ + do { \ + if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); } \ } while (0) -#define indexError(...) \ - do { \ - if (sDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("index ERROR ", 255, __VA_ARGS__); \ - } \ +#define indexError(...) \ + do { \ + if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("index ERROR ", 255, __VA_ARGS__); } \ } while (0) -#define indexWarn(...) \ - do { \ - if (sDebugFlag & DEBUG_WARN) { \ - taosPrintLog("index WARN ", 255, __VA_ARGS__); \ - } \ +#define indexWarn(...) \ + do { \ + if (sDebugFlag & DEBUG_WARN) { taosPrintLog("index WARN ", 255, __VA_ARGS__); } \ } while (0) -#define indexInfo(...) \ - do { \ - if (sDebugFlag & DEBUG_INFO) { \ - taosPrintLog("index ", 255, __VA_ARGS__); \ - } \ +#define indexInfo(...) \ + do { \ + if (sDebugFlag & DEBUG_INFO) { taosPrintLog("index ", 255, __VA_ARGS__); } \ } while (0) -#define indexDebug(...) \ - do { \ - if (sDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \ - } \ +#define indexDebug(...) \ + do { \ + if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \ } while (0) -#define indexTrace(...) \ - do { \ - if (sDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \ - } \ +#define indexTrace(...) \ + do { \ + if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \ } while (0) #ifdef __cplusplus diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/index_cache.h index fb4f478ae99fdc7654536a98d67d5e3d8ac407fa..12b66bca2cab9ff4b658f7aeaacd9268facca6a3 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/index_cache.h @@ -22,31 +22,60 @@ // ----------------- key structure in skiplist --------------------- /* A data row, the format is like below: - * content: |<--totalLen-->|<-- fieldid-->|<--field type-->|<-- value len--->| - * |<-- value -->|<--uid -->|<--version--->|<-- itermType -->| - * len : |<--int32_t -->|<-- int16_t-->|<-- int8_t --->|<--- int32_t --->| - * <--valuelen->|<--uint64_t->| * <-- int32_t-->|<-- int8_t --->| + * content: |<--totalLen-->|<-- value len--->|<-- value -->|<--uid -->|<--version--->|<-- itermType -->| + * len : |<--int32_t -->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->| */ #ifdef __cplusplus extern "C" { #endif +typedef struct MemTable { + T_REF_DECLARE() + SSkipList* mem; +} MemTable; typedef struct IndexCache { T_REF_DECLARE() - SSkipList* skiplist; + MemTable *mem, *imm; + SIndex* index; + char* colName; + int32_t version; + int32_t nTerm; + int8_t type; + + pthread_mutex_t mtx; } IndexCache; +#define CACHE_VERSION(cache) atomic_load_32(&cache->version) +typedef struct CacheTerm { + // key + char* colVal; + int32_t version; + // value + uint64_t uid; + int8_t colType; + SIndexOperOnColumn operaType; +} CacheTerm; // -IndexCache* indexCacheCreate(); + +IndexCache* indexCacheCreate(SIndex* idx, const char* colName, int8_t type); void indexCacheDestroy(void* cache); -int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid); +Iterate* indexCacheIteratorCreate(IndexCache* cache); +void indexCacheIteratorDestroy(Iterate* iiter); + +int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid); // int indexCacheGet(void *cache, uint64_t *rst); -int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s); +int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s); + +void indexCacheRef(IndexCache* cache); +void indexCacheUnRef(IndexCache* cache); + +void indexCacheDebug(IndexCache* cache); +void indexCacheDestroyImm(IndexCache* cache); #ifdef __cplusplus } #endif diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 3c572787fc4b4fa17f7e870b5af44aa95b3ef115..73c79b2619512a3f769911f86d2ae65fe45af8b6 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -319,6 +319,8 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min); StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback); FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut); + +void fstStreamBuilderDestroy(FstStreamBuilder* b); // set up bound range // refator, simple code by marco diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/index_fst_automation.h index c7269eda0f30a845c5b9a1810a5a4aea4baa56eb..be056f38fa183e1460dac83c9fd90b70e69c40e9 100644 --- a/source/libs/index/inc/index_fst_automation.h +++ b/source/libs/index/inc/index_fst_automation.h @@ -23,7 +23,7 @@ extern "C" { typedef struct AutomationCtx AutomationCtx; -typedef enum AutomationType { AUTOMATION_PREFIX, AUTMMATION_MATCH } AutomationType; +typedef enum AutomationType { AUTOMATION_ALWAYS, AUTOMATION_PREFIX, AUTMMATION_MATCH } AutomationType; typedef struct StartWith { AutomationCtx* autoSelf; diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index ba0bd52e10280cd0139a6dc852b61c7f75b91a77..1504a69a08ebcf07a3617b7d8daf123ca06c3738 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -37,6 +37,7 @@ typedef struct WriterCtx { struct { int fd; bool readOnly; + char buf[256]; } file; struct { int32_t capa; @@ -53,7 +54,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off static int writeCtxDoFlush(WriterCtx* ctx); WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity); -void writerCtxDestroy(WriterCtx* w); +void writerCtxDestroy(WriterCtx* w, bool remove); typedef uint32_t CheckSummer; diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/index_tfile.h index 416b10bd14c63ebea97b40d80175f033e0e3d7f8..d8e69b5fdece6eeae9d0ce4809fb2d04f2b91e4c 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/index_tfile.h @@ -105,13 +105,20 @@ void tfileCacheDestroy(TFileCache* tcache); TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key); void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader); +TFileReader* tfileGetReaderByCol(IndexTFile* tf, char* colName); + +TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const char* colName); TFileReader* tfileReaderCreate(WriterCtx* ctx); void tfileReaderDestroy(TFileReader* reader); int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* result); +void tfileReaderRef(TFileReader* reader); +void tfileReaderUnRef(TFileReader* reader); +TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t type); +void tfileWriterClose(TFileWriter* tw); TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header); void tfileWriterDestroy(TFileWriter* tw); -int tfileWriterPut(TFileWriter* tw, void* data); +int tfileWriterPut(TFileWriter* tw, void* data, bool order); int tfileWriterFinish(TFileWriter* tw); // @@ -119,6 +126,14 @@ IndexTFile* indexTFileCreate(const char* path); int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid); int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result); +Iterate* tfileIteratorCreate(TFileReader* reader); +void tfileIteratorDestroy(Iterate* iterator); + +TFileValue* tfileValueCreate(char* val); + +int tfileValuePush(TFileValue* tf, uint64_t val); +void tfileValueDestroy(TFileValue* tf); + #ifdef __cplusplus } diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index f0546afaf591f0f815cb4802f70f73e85ae010c7..6d64bdbd65858fe42fba06f090d69ad357e1ab36 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -18,11 +18,24 @@ #include "index_cache.h" #include "index_tfile.h" #include "tdef.h" +#include "tsched.h" #ifdef USE_LUCENE #include "lucene++/Lucene_c.h" #endif +#define INDEX_NUM_OF_THREADS 4 +#define INDEX_QUEUE_SIZE 200 + +void* indexQhandle = NULL; + +int32_t indexInit() { + indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index"); + return indexQhandle == NULL ? -1 : 0; + // do nothing +} +void indexCleanUp() { taosCleanUpScheduler(indexQhandle); } + static int uidCompare(const void* a, const void* b) { uint64_t u1 = *(uint64_t*)a; uint64_t u2 = *(uint64_t*)b; @@ -38,16 +51,16 @@ typedef struct SIdxColInfo { } SIdxColInfo; static pthread_once_t isInit = PTHREAD_ONCE_INIT; -static void indexInit(); - +// static void indexInit(); static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result); -static int indexFlushCacheToTindex(SIndex* sIdx); static void indexInterResultsDestroy(SArray* results); static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType, SArray* finalResult); +static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch); + int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { - pthread_once(&isInit, indexInit); + // pthread_once(&isInit, indexInit); SIndex* sIdx = calloc(1, sizeof(SIndex)); if (sIdx == NULL) { return -1; } @@ -57,14 +70,16 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #endif #ifdef USE_INVERTED_INDEX - sIdx->cache = (void*)indexCacheCreate(); - sIdx->tindex = NULL; + // sIdx->cache = (void*)indexCacheCreate(sIdx); + sIdx->tindex = indexTFileCreate(path); sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - sIdx->colId = 1; sIdx->cVersion = 1; + sIdx->path = calloc(1, strlen(path) + 1); + memcpy(sIdx->path, path, strlen(path)); pthread_mutex_init(&sIdx->mtx, NULL); *index = sIdx; + return 0; #endif @@ -80,6 +95,12 @@ void indexClose(SIndex* sIdx) { #ifdef USE_INVERTED_INDEX indexCacheDestroy(sIdx->cache); + void* iter = taosHashIterate(sIdx->colObj, NULL); + while (iter) { + IndexCache** pCache = iter; + if (*pCache) { indexCacheUnRef(*pCache); } + iter = taosHashIterate(sIdx->colObj, iter); + } taosHashCleanup(sIdx->colObj); pthread_mutex_destroy(&sIdx->mtx); #endif @@ -110,29 +131,23 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { pthread_mutex_lock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { SIndexTerm* p = taosArrayGetP(fVals, i); - SIdxColInfo* fi = taosHashGet(index->colObj, p->colName, p->nColName); - if (fi == NULL) { - SIdxColInfo tfi = {.colId = index->colId}; - index->cVersion++; - index->colId++; - taosHashPut(index->colObj, p->colName, p->nColName, &tfi, sizeof(tfi)); - } else { - // TODO, del + IndexCache** cache = taosHashGet(index->colObj, p->colName, p->nColName); + if (cache == NULL) { + IndexCache* pCache = indexCacheCreate(index, p->colName, p->colType); + taosHashPut(index->colObj, p->colName, p->nColName, &pCache, sizeof(void*)); } } pthread_mutex_unlock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { SIndexTerm* p = taosArrayGetP(fVals, i); - SIdxColInfo* fi = taosHashGet(index->colObj, p->colName, p->nColName); - assert(fi != NULL); - int32_t colId = fi->colId; - int32_t version = index->cVersion; - int ret = indexCachePut(index->cache, p, colId, version, uid); + IndexCache** cache = taosHashGet(index->colObj, p->colName, p->nColName); + assert(*cache != NULL); + int ret = indexCachePut(*cache, p, uid); if (ret != 0) { return ret; } } -#endif +#endif return 0; } int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result) { @@ -159,9 +174,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result int tsz = 0; index_multi_search(index->index, (const char**)fields, (const char**)keys, types, nQuery, opera, &tResult, &tsz); - for (int i = 0; i < tsz; i++) { - taosArrayPush(result, &tResult[i]); - } + for (int i = 0; i < tsz; i++) { taosArrayPush(result, &tResult[i]); } for (int i = 0; i < nQuery; i++) { free(fields[i]); @@ -207,14 +220,15 @@ SIndexOpts* indexOptsCreate() { #endif return NULL; } -void indexOptsDestroy(SIndexOpts* opts){ +void indexOptsDestroy(SIndexOpts* opts) { #ifdef USE_LUCENE #endif -} /* - * @param: oper - * - */ - + return; +} +/* + * @param: oper + * + */ SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType opera) { SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)malloc(sizeof(SIndexMultiTermQuery)); if (p == NULL) { return NULL; } @@ -236,13 +250,8 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde return 0; } -SIndexTerm* indexTermCreate(int64_t suid, - SIndexOperOnColumn oper, - uint8_t colType, - const char* colName, - int32_t nColName, - const char* colVal, - int32_t nColVal) { +SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName, + int32_t nColName, const char* colVal, int32_t nColVal) { SIndexTerm* t = (SIndexTerm*)calloc(1, (sizeof(SIndexTerm))); if (t == NULL) { return NULL; } @@ -265,9 +274,7 @@ void indexTermDestroy(SIndexTerm* p) { free(p); } -SIndexMultiTerm* indexMultiTermCreate() { - return taosArrayInit(4, sizeof(SIndexTerm*)); -} +SIndexMultiTerm* indexMultiTermCreate() { return taosArrayInit(4, sizeof(SIndexTerm*)); } int indexMultiTermAdd(SIndexMultiTerm* terms, SIndexTerm* term) { taosArrayPush(terms, &term); @@ -281,32 +288,26 @@ void indexMultiTermDestroy(SIndexMultiTerm* terms) { taosArrayDestroy(terms); } -void indexInit() { - // do nothing -} static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) { - int32_t version = -1; - int16_t colId = -1; - SIdxColInfo* colInfo = NULL; - SIndexTerm* term = query->term; const char* colName = term->colName; int32_t nColName = term->nColName; + // Get col info + IndexCache* cache = NULL; pthread_mutex_lock(&sIdx->mtx); - colInfo = taosHashGet(sIdx->colObj, colName, nColName); - if (colInfo == NULL) { + IndexCache** pCache = taosHashGet(sIdx->colObj, colName, nColName); + if (pCache == NULL) { pthread_mutex_unlock(&sIdx->mtx); return -1; } - colId = colInfo->colId; - version = colInfo->cVersion; + cache = *pCache; pthread_mutex_unlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); // TODO: iterator mem and tidex - STermValueType s; - if (0 == indexCacheSearch(sIdx->cache, query, colId, version, *result, &s)) { + STermValueType s = kTypeValue; + if (0 == indexCacheSearch(cache, query, *result, &s)) { if (s == kTypeDeletion) { indexInfo("col: %s already drop by other opera", term->colName); // coloum already drop by other oper, no need to query tindex @@ -353,10 +354,146 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType } return 0; } -static int indexFlushCacheToTindex(SIndex* sIdx) { - if (sIdx == NULL) { return -1; } +static void indexMergeSameKey(SArray* result, TFileValue* tv) { + int32_t sz = result ? taosArrayGetSize(result) : 0; + if (sz > 0) { + // TODO(yihao): remove duplicate tableid + TFileValue* lv = taosArrayGetP(result, sz - 1); + if (strcmp(lv->colVal, tv->colVal) == 0) { + taosArrayAddAll(lv->tableId, tv->tableId); + tfileValueDestroy(tv); + } else { + taosArrayPush(result, &tv); + } + } else { + taosArrayPush(result, &tv); + } +} +static void indexDestroyTempResult(SArray* result) { + int32_t sz = result ? taosArrayGetSize(result) : 0; + for (size_t i = 0; i < sz; i++) { + TFileValue* tv = taosArrayGetP(result, i); + tfileValueDestroy(tv); + } + taosArrayDestroy(result); +} +int indexFlushCacheTFile(SIndex* sIdx, void* cache) { + if (sIdx == NULL) { return -1; } indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + IndexCache* pCache = (IndexCache*)cache; + TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->colName); + // handle flush + Iterate* cacheIter = indexCacheIteratorCreate(pCache); + Iterate* tfileIter = tfileIteratorCreate(pReader); + + SArray* result = taosArrayInit(1024, sizeof(void*)); + + bool cn = cacheIter ? cacheIter->next(cacheIter) : false; + bool tn = tfileIter ? tfileIter->next(tfileIter) : false; + while (cn == true && tn == true) { + IterateValue* cv = cacheIter->getValue(cacheIter); + IterateValue* tv = tfileIter->getValue(tfileIter); + + // dump value + int comp = strcmp(cv->colVal, tv->colVal); + if (comp == 0) { + TFileValue* tfv = tfileValueCreate(cv->colVal); + taosArrayAddAll(tfv->tableId, cv->val); + taosArrayAddAll(tfv->tableId, tv->val); + indexMergeSameKey(result, tfv); + + cn = cacheIter->next(cacheIter); + tn = tfileIter->next(tfileIter); + continue; + } else if (comp < 0) { + TFileValue* tfv = tfileValueCreate(cv->colVal); + taosArrayAddAll(tfv->tableId, cv->val); + + indexMergeSameKey(result, tfv); + // copy to final Result; + cn = cacheIter->next(cacheIter); + } else { + TFileValue* tfv = tfileValueCreate(tv->colVal); + taosArrayAddAll(tfv->tableId, tv->val); + + indexMergeSameKey(result, tfv); + // copy to final result + tn = tfileIter->next(tfileIter); + } + } + while (cn == true) { + IterateValue* cv = cacheIter->getValue(cacheIter); + TFileValue* tfv = tfileValueCreate(cv->colVal); + taosArrayAddAll(tfv->tableId, cv->val); + indexMergeSameKey(result, tfv); + cn = cacheIter->next(cacheIter); + } + while (tn == true) { + IterateValue* tv = tfileIter->getValue(tfileIter); + TFileValue* tfv = tfileValueCreate(tv->colVal); + if (tv->val == NULL) { + // HO + printf("NO...."); + } + taosArrayAddAll(tfv->tableId, tv->val); + indexMergeSameKey(result, tfv); + tn = tfileIter->next(tfileIter); + } + int ret = indexGenTFile(sIdx, pCache, result); + indexDestroyTempResult(result); + indexCacheDestroyImm(pCache); + + indexCacheIteratorDestroy(cacheIter); + tfileIteratorDestroy(tfileIter); + + tfileReaderUnRef(pReader); + indexCacheUnRef(pCache); return 0; } +void iterateValueDestroy(IterateValue* value, bool destroy) { + if (destroy) { + taosArrayDestroy(value->val); + value->val = NULL; + } else { + if (value->val != NULL) { taosArrayClear(value->val); } + } + // free(value->colVal); + value->colVal = NULL; +} +static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { + int32_t version = CACHE_VERSION(cache); + uint8_t colType = cache->type; + + TFileWriter* tw = tfileWriterOpen(sIdx->path, sIdx->suid, version, cache->colName, colType); + if (tw == NULL) { + indexError("failed to open file to write"); + return -1; + } + + int ret = tfileWriterPut(tw, batch, true); + if (ret != 0) { + indexError("failed to write into tindex "); + goto END; + } + tfileWriterClose(tw); + + TFileReader* reader = tfileReaderOpen(sIdx->path, sIdx->suid, version, cache->colName); + + char buf[128] = {0}; + TFileHeader* header = &reader->header; + TFileCacheKey key = {.suid = header->suid, + .colName = header->colName, + .nColName = strlen(header->colName), + .colType = header->colType}; + pthread_mutex_lock(&sIdx->mtx); + + IndexTFile* ifile = (IndexTFile*)sIdx->tindex; + tfileCachePut(ifile->cache, &key, reader); + + pthread_mutex_unlock(&sIdx->mtx); + return ret; +END: + tfileWriterClose(tw); +} diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index bb6a5e048af60a4822716395baa094a1c9cec600..882091afb9a64f271b0bad4ada809f13d285a82b 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -16,151 +16,354 @@ #include "index_cache.h" #include "index_util.h" #include "tcompare.h" +#include "tsched.h" #define MAX_INDEX_KEY_LEN 256 // test only, change later +#define MEM_TERM_LIMIT 200 // ref index_cache.h:22 -#define CACHE_KEY_LEN(p) \ - (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + sizeof(p->operType)) +//#define CACHE_KEY_LEN(p) \ +// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + +// sizeof(p->operType)) -static char* getIndexKey(const void* pData) { - return NULL; -} -static int32_t compareKey(const void* l, const void* r) { - char* lp = (char*)l; - char* rp = (char*)r; - - // skip total len, not compare - int32_t ll, rl; // len - memcpy(&ll, lp, sizeof(int32_t)); - memcpy(&rl, rp, sizeof(int32_t)); - lp += sizeof(int32_t); - rp += sizeof(int32_t); - - // compare field id - int16_t lf, rf; // field id - memcpy(&lf, lp, sizeof(lf)); - memcpy(&rf, rp, sizeof(rf)); - if (lf != rf) { return lf < rf ? -1 : 1; } - lp += sizeof(lf); - rp += sizeof(rf); - - // compare field type - int8_t lft, rft; - memcpy(&lft, lp, sizeof(lft)); - memcpy(&rft, rp, sizeof(rft)); - lp += sizeof(lft); - rp += sizeof(rft); - assert(rft == rft); - - // skip value len - int32_t lfl, rfl; - memcpy(&lfl, lp, sizeof(lfl)); - memcpy(&rfl, rp, sizeof(rfl)); - lp += sizeof(lfl); - rp += sizeof(rfl); - - // compare value - int32_t i, j; - for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) { - if (lp[i] == rp[j]) { - continue; - } else { - return lp[i] < rp[j] ? -1 : 1; - } - } - if (i < lfl) { - return 1; - } else if (j < rfl) { - return -1; - } - lp += lfl; - rp += rfl; - - // skip uid - uint64_t lu, ru; - memcpy(&lu, lp, sizeof(lu)); - memcpy(&ru, rp, sizeof(ru)); - lp += sizeof(lu); - rp += sizeof(ru); - - // compare version, desc order - int32_t lv, rv; - memcpy(&lv, lp, sizeof(lv)); - memcpy(&rv, rp, sizeof(rv)); - if (lv != rv) { return lv > rv ? -1 : 1; } - - lp += sizeof(lv); - rp += sizeof(rv); - // not care item type +static void indexMemRef(MemTable* tbl); +static void indexMemUnRef(MemTable* tbl); - return 0; -} -IndexCache* indexCacheCreate() { +static void cacheTermDestroy(CacheTerm* ct); +static char* getIndexKey(const void* pData); +static int32_t compareKey(const void* l, const void* r); + +static MemTable* indexInternalCacheCreate(int8_t type); + +static void doMergeWork(SSchedMsg* msg); +static bool indexCacheIteratorNext(Iterate* itera); + +static IterateValue* indexCacheIteratorGetValue(Iterate* iter); + +IndexCache* indexCacheCreate(SIndex* idx, const char* colName, int8_t type) { IndexCache* cache = calloc(1, sizeof(IndexCache)); if (cache == NULL) { indexError("failed to create index cache"); return NULL; - } - cache->skiplist = - tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey); + }; + cache->mem = indexInternalCacheCreate(type); + + cache->colName = calloc(1, strlen(colName) + 1); + memcpy(cache->colName, colName, strlen(colName)); + cache->type = type; + cache->index = idx; + cache->version = 0; + + pthread_mutex_init(&cache->mtx, NULL); + indexCacheRef(cache); return cache; } +void indexCacheDebug(IndexCache* cache) { + MemTable* tbl = NULL; + + pthread_mutex_lock(&cache->mtx); + tbl = cache->mem; + indexMemRef(tbl); + pthread_mutex_unlock(&cache->mtx); + + { + SSkipList* slt = tbl->mem; + SSkipListIterator* iter = tSkipListCreateIter(slt); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); + if (ct != NULL) { + // TODO, add more debug info + indexInfo("{colVal: %s, version: %d} \t", ct->colVal, ct->version); + } + } + tSkipListDestroyIter(iter); + + indexMemUnRef(tbl); + } + + { + pthread_mutex_lock(&cache->mtx); + tbl = cache->imm; + indexMemRef(tbl); + pthread_mutex_unlock(&cache->mtx); + if (tbl != NULL) { + SSkipList* slt = tbl->mem; + SSkipListIterator* iter = tSkipListCreateIter(slt); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); + if (ct != NULL) { + // TODO, add more debug info + indexInfo("{colVal: %s, version: %d} \t", ct->colVal, ct->version); + } + } + tSkipListDestroyIter(iter); + } + + indexMemUnRef(tbl); + } +} +void indexCacheDestroySkiplist(SSkipList* slt) { + SSkipListIterator* iter = tSkipListCreateIter(slt); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); + if (ct != NULL) {} + } + tSkipListDestroyIter(iter); + tSkipListDestroy(slt); +} +void indexCacheDestroyImm(IndexCache* cache) { + if (cache == NULL) { return; } + + MemTable* tbl = NULL; + pthread_mutex_lock(&cache->mtx); + tbl = cache->imm; + cache->imm = NULL; // or throw int bg thread + pthread_mutex_unlock(&cache->mtx); + + indexMemUnRef(tbl); + indexMemUnRef(tbl); +} void indexCacheDestroy(void* cache) { IndexCache* pCache = cache; if (pCache == NULL) { return; } - tSkipListDestroy(pCache->skiplist); + indexMemUnRef(pCache->mem); + indexMemUnRef(pCache->imm); + free(pCache->colName); + free(pCache); } -int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid) { +Iterate* indexCacheIteratorCreate(IndexCache* cache) { + Iterate* iiter = calloc(1, sizeof(Iterate)); + if (iiter == NULL) { return NULL; } + + pthread_mutex_lock(&cache->mtx); + + indexMemRef(cache->imm); + + MemTable* tbl = cache->imm; + iiter->val.val = taosArrayInit(1, sizeof(uint64_t)); + iiter->iter = tbl != NULL ? tSkipListCreateIter(tbl->mem) : NULL; + iiter->next = indexCacheIteratorNext; + iiter->getValue = indexCacheIteratorGetValue; + + pthread_mutex_unlock(&cache->mtx); + + return iiter; +} +void indexCacheIteratorDestroy(Iterate* iter) { + if (iter == NULL) { return; } + tSkipListDestroyIter(iter->iter); + iterateValueDestroy(&iter->val, true); + free(iter); +} + +int indexCacheSchedToMerge(IndexCache* pCache) { + SSchedMsg schedMsg = {0}; + schedMsg.fp = doMergeWork; + schedMsg.ahandle = pCache; + schedMsg.thandle = NULL; + schedMsg.msg = NULL; + + taosScheduleTask(indexQhandle, &schedMsg); +} +static void indexCacheMakeRoomForWrite(IndexCache* cache) { + while (true) { + if (cache->nTerm < MEM_TERM_LIMIT) { + cache->nTerm += 1; + break; + } else if (cache->imm != NULL) { + // TODO: wake up by condition variable + pthread_mutex_unlock(&cache->mtx); + taosMsleep(50); + pthread_mutex_lock(&cache->mtx); + } else { + indexCacheRef(cache); + cache->imm = cache->mem; + cache->mem = indexInternalCacheCreate(cache->type); + cache->nTerm = 1; + // sched to merge + // unref cache in bgwork + indexCacheSchedToMerge(cache); + } + } +} + +int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { if (cache == NULL) { return -1; } IndexCache* pCache = cache; + indexCacheRef(pCache); // encode data - int32_t total = CACHE_KEY_LEN(term); - - char* buf = calloc(1, total); - char* p = buf; - - SERIALIZE_VAR_TO_BUF(p, total, int32_t); - SERIALIZE_VAR_TO_BUF(p, colId, int16_t); + CacheTerm* ct = calloc(1, sizeof(CacheTerm)); + if (cache == NULL) { return -1; } + // set up key + ct->colType = term->colType; + ct->colVal = (char*)calloc(1, sizeof(char) * (term->nColVal + 1)); + memcpy(ct->colVal, term->colVal, term->nColVal); + ct->version = atomic_add_fetch_32(&pCache->version, 1); + // set value + ct->uid = uid; + ct->operaType = term->operType; - SERIALIZE_MEM_TO_BUF(p, term, colType); - SERIALIZE_MEM_TO_BUF(p, term, nColVal); - SERIALIZE_STR_MEM_TO_BUF(p, term, colVal, term->nColVal); + // ugly code, refactor later + pthread_mutex_lock(&pCache->mtx); - SERIALIZE_VAR_TO_BUF(p, version, int32_t); - SERIALIZE_VAR_TO_BUF(p, uid, uint64_t); + indexCacheMakeRoomForWrite(pCache); + MemTable* tbl = pCache->mem; + indexMemRef(tbl); + tSkipListPut(tbl->mem, (char*)ct); + indexMemUnRef(tbl); - SERIALIZE_MEM_TO_BUF(p, term, operType); + pthread_mutex_unlock(&pCache->mtx); - tSkipListPut(pCache->skiplist, (void*)buf); + indexCacheUnRef(pCache); return 0; // encode end } -int indexCacheDel(void* cache, int32_t fieldId, const char* fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) { +int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) { IndexCache* pCache = cache; return 0; } -int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s) { + +static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SArray* result, STermValueType* s) { + if (mem == NULL) { return 0; } + char* key = getIndexKey(ct); + + SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + while (tSkipListIterNext(iter)) { + SSkipListNode* node = tSkipListIterGet(iter); + if (node != NULL) { + CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); + if (c->operaType == ADD_VALUE || qtype == QUERY_TERM) { + if (strcmp(c->colVal, ct->colVal) == 0) { + taosArrayPush(result, &c->uid); + *s = kTypeValue; + } else { + break; + } + } else if (c->operaType == DEL_VALUE) { + // table is del, not need + *s = kTypeDeletion; + break; + } + } + } + tSkipListDestroyIter(iter); + return 0; +} +int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { if (cache == NULL) { return -1; } - IndexCache* pCache = cache; + IndexCache* pCache = cache; + + MemTable *mem = NULL, *imm = NULL; + pthread_mutex_lock(&pCache->mtx); + mem = pCache->mem; + imm = pCache->imm; + indexMemRef(mem); + indexMemRef(imm); + pthread_mutex_unlock(&pCache->mtx); + SIndexTerm* term = query->term; EIndexQueryType qtype = query->qType; + CacheTerm ct = {.colVal = term->colVal, .version = atomic_load_32(&pCache->version)}; + indexCacheDebug(pCache); - int32_t keyLen = CACHE_KEY_LEN(term); - char* buf = calloc(1, keyLen); - if (qtype == QUERY_TERM) { - // - } else if (qtype == QUERY_PREFIX) { - // - } else if (qtype == QUERY_SUFFIX) { - // - } else if (qtype == QUERY_REGEX) { - // + int ret = indexQueryMem(mem, &ct, qtype, result, s); + if (ret == 0 && *s != kTypeDeletion) { + // continue search in imm + ret = indexQueryMem(imm, &ct, qtype, result, s); } + // cacheTermDestroy(ct); - return 0; + indexMemUnRef(mem); + indexMemUnRef(imm); + + return ret; +} + +void indexCacheRef(IndexCache* cache) { + if (cache == NULL) { return; } + int ref = T_REF_INC(cache); + UNUSED(ref); +} +void indexCacheUnRef(IndexCache* cache) { + if (cache == NULL) { return; } + int ref = T_REF_DEC(cache); + if (ref == 0) { indexCacheDestroy(cache); } +} + +void indexMemRef(MemTable* tbl) { + if (tbl == NULL) { return; } + int ref = T_REF_INC(tbl); + UNUSED(ref); } +void indexMemUnRef(MemTable* tbl) { + if (tbl == NULL) { return; } + int ref = T_REF_DEC(tbl); + if (ref == 0) { + SSkipList* slt = tbl->mem; + indexCacheDestroySkiplist(slt); + free(tbl); + } +} + +static void cacheTermDestroy(CacheTerm* ct) { + if (ct == NULL) { return; } + free(ct->colVal); + free(ct); +} +static char* getIndexKey(const void* pData) { + CacheTerm* p = (CacheTerm*)pData; + return (char*)p; +} + +static int32_t compareKey(const void* l, const void* r) { + CacheTerm* lt = (CacheTerm*)l; + CacheTerm* rt = (CacheTerm*)r; + + // compare colVal + int32_t cmp = strcmp(lt->colVal, rt->colVal); + if (cmp == 0) { return rt->version - lt->version; } + return cmp; +} + +static MemTable* indexInternalCacheCreate(int8_t type) { + MemTable* tbl = calloc(1, sizeof(MemTable)); + indexMemRef(tbl); + if (type == TSDB_DATA_TYPE_BINARY) { + tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, type, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey); + } + return tbl; +} + +static void doMergeWork(SSchedMsg* msg) { + IndexCache* pCache = msg->ahandle; + SIndex* sidx = (SIndex*)pCache->index; + indexFlushCacheTFile(sidx, pCache); +} +static bool indexCacheIteratorNext(Iterate* itera) { + SSkipListIterator* iter = itera->iter; + if (iter == NULL) { return false; } + IterateValue* iv = &itera->val; + iterateValueDestroy(iv, false); + + bool next = tSkipListIterNext(iter); + if (next) { + SSkipListNode* node = tSkipListIterGet(iter); + CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node); + + iv->type = ct->operaType; + iv->colVal = calloc(1, strlen(ct->colVal) + 1); + memcpy(iv->colVal, ct->colVal, strlen(ct->colVal)); + + taosArrayPush(iv->val, &ct->uid); + } + return next; +} + +static IterateValue* indexCacheIteratorGetValue(Iterate* iter) { return &iter->val; } diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 18514cd0d5498eba9a31d8d28b197557bdf23bd8..18024fa39110c3a6acb3052e76e84c332ef425bf 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1083,7 +1083,7 @@ bool fstBoundWithDataExceededBy(FstBoundWithData* bound, FstSlice* slice) { } else if (bound->type == Excluded) { return comp >= 0 ? true : false; } else { - return true; + return false; } } bool fstBoundWithDataIsEmpty(FstBoundWithData* bound) { @@ -1224,7 +1224,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb void* start = automFuncs[aut->type].start(aut); if (automFuncs[aut->type].isMatch(aut, start)) { FstSlice s = fstSliceCreate(NULL, 0); - return swsResultCreate(&s, output, callback(start)); + return swsResultCreate(&s, output, callback == NULL ? NULL : callback(start)); } } SArray* nodes = taosArrayInit(8, sizeof(FstNode*)); @@ -1237,10 +1237,12 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb } FstTransition trn; fstNodeGetTransitionAt(p->node, p->trans, &trn); - Output out = p->out.out + trn.out; - void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp); - void* tState = callback(nextState); - bool isMatch = automFuncs[aut->type].isMatch(aut, nextState); + + Output out = p->out.out + trn.out; + void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp); + void* tState = (callback == NULL) ? NULL : callback(nextState); + bool isMatch = automFuncs[aut->type].isMatch(aut, nextState); + FstNode* nextNode = fstGetNode(sws->fst, trn.addr); taosArrayPush(nodes, &nextNode); taosArrayPush(sws->inp, &(trn.inp)); diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/index_fst_automation.c index eb4c479c9406d4be367df458235c47f7b87ff9f8..590ff294bf8f1841fc27e4519df1d23f668adcd5 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/index_fst_automation.c @@ -17,7 +17,9 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { StartWithStateValue* nsv = calloc(1, sizeof(StartWithStateValue)); - if (nsv == NULL) { return NULL; } + if (nsv == NULL) { + return NULL; + } nsv->kind = kind; nsv->type = ty; @@ -35,7 +37,9 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp } void startWithStateValueDestroy(void* val) { StartWithStateValue* sv = (StartWithStateValue*)val; - if (sv == NULL) { return; } + if (sv == NULL) { + return; + } if (sv->type == FST_INT) { // @@ -48,7 +52,9 @@ void startWithStateValueDestroy(void* val) { } StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { StartWithStateValue* nsv = calloc(1, sizeof(StartWithStateValue)); - if (nsv == NULL) { return NULL; } + if (nsv == NULL) { + return NULL; + } nsv->kind = sv->kind; nsv->type = sv->type; @@ -64,6 +70,13 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { return nsv; } +// iterate fst +static void* alwaysMatchStart(AutomationCtx* ctx) { return NULL; } +static bool alwaysMatchIsMatch(AutomationCtx* ctx, void* state) { return true; } +static bool alwaysMatchCanMatch(AutomationCtx* ctx, void* state) { return true; } +static bool alwaysMatchWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } +static void* alwaysMatchAccpet(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; } +static void* alwaysMatchAccpetEof(AutomationCtx* ctx, void* state) { return NULL; } // prefix query, impl later static void* prefixStart(AutomationCtx* ctx) { @@ -78,17 +91,20 @@ static bool prefixCanMatch(AutomationCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; return ssv->val >= 0; } -static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { - return true; -} +static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) { StartWithStateValue* ssv = (StartWithStateValue*)state; - if (ssv == NULL || ctx == NULL) { return NULL; } + if (ssv == NULL || ctx == NULL) { + return NULL; + } char* data = ctx->data; - if (ssv->kind == Done) { return startWithStateValueCreate(Done, FST_INT, &ssv->val); } + if (ssv->kind == Done) { + return startWithStateValueCreate(Done, FST_INT, &ssv->val); + } if ((strlen(data) > ssv->val) && data[ssv->val] == byte) { - int val = ssv->val + 1; + int val = ssv->val + 1; + StartWithStateValue* nsv = startWithStateValueCreate(Running, FST_INT, &val); if (prefixIsMatch(ctx, nsv)) { nsv->kind = Done; @@ -99,34 +115,22 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) { } return NULL; } -static void* prefixAcceptEof(AutomationCtx* ctx, void* state) { - return NULL; -} +static void* prefixAcceptEof(AutomationCtx* ctx, void* state) { return NULL; } // pattern query, impl later -static void* patternStart(AutomationCtx* ctx) { - return NULL; -} -static bool patternIsMatch(AutomationCtx* ctx, void* data) { - return true; -} -static bool patternCanMatch(AutomationCtx* ctx, void* data) { - return true; -} -static bool patternWillAlwaysMatch(AutomationCtx* ctx, void* state) { - return true; -} +static void* patternStart(AutomationCtx* ctx) { return NULL; } +static bool patternIsMatch(AutomationCtx* ctx, void* data) { return true; } +static bool patternCanMatch(AutomationCtx* ctx, void* data) { return true; } +static bool patternWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } -static void* patternAccept(AutomationCtx* ctx, void* state, uint8_t byte) { - return NULL; -} +static void* patternAccept(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; } -static void* patternAcceptEof(AutomationCtx* ctx, void* state) { - return NULL; -} +static void* patternAcceptEof(AutomationCtx* ctx, void* state) { return NULL; } AutomationFunc automFuncs[] = { + {alwaysMatchStart, alwaysMatchIsMatch, alwaysMatchCanMatch, alwaysMatchWillAlwaysMatch, alwaysMatchAccpet, + alwaysMatchAccpetEof}, {prefixStart, prefixIsMatch, prefixCanMatch, prefixWillAlwaysMatch, prefixAccept, prefixAcceptEof}, {patternStart, patternIsMatch, patternCanMatch, patternWillAlwaysMatch, patternAccept, patternAcceptEof} // add more search type @@ -134,10 +138,16 @@ AutomationFunc automFuncs[] = { AutomationCtx* automCtxCreate(void* data, AutomationType atype) { AutomationCtx* ctx = calloc(1, sizeof(AutomationCtx)); - if (ctx == NULL) { return NULL; } + if (ctx == NULL) { + return NULL; + } StartWithStateValue* sv = NULL; - if (atype == AUTOMATION_PREFIX) { + if (atype == AUTOMATION_ALWAYS) { + int val = 0; + sv = startWithStateValueCreate(Running, FST_INT, &val); + ctx->stdata = (void*)sv; + } else if (atype == AUTOMATION_PREFIX) { int val = 0; sv = startWithStateValueCreate(Running, FST_INT, &val); ctx->stdata = (void*)sv; @@ -146,11 +156,14 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { // add more search type } - char* src = (char*)data; - size_t len = strlen(src); - char* dst = (char*)malloc(len * sizeof(char) + 1); - memcpy(dst, src, len); - dst[len] = 0; + char* dst = NULL; + if (data != NULL) { + char* src = (char*)data; + size_t len = strlen(src); + dst = (char*)malloc(len * sizeof(char) + 1); + memcpy(dst, src, len); + dst[len] = 0; + } ctx->data = dst; ctx->type = atype; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index c8fbdd7690bc3ec0243a01dab89fb53d959854f2..710db563d9e39ddea08832c03db6b0628afc2cc2 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -52,7 +52,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off } static int writeCtxDoFlush(WriterCtx* ctx) { if (ctx->type == TFile) { - // tfFsync(ctx->fd); + tfFsync(ctx->file.fd); // tfFlush(ctx->file.fd); } else { // do nothing @@ -73,6 +73,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int } else { ctx->file.fd = tfOpenReadWrite(path); } + memcpy(ctx->file.buf, path, strlen(path)); if (ctx->file.fd < 0) { indexError("open file error %d", errno); goto END; @@ -95,11 +96,15 @@ END: free(ctx); return NULL; } -void writerCtxDestroy(WriterCtx* ctx) { +void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { free(ctx->mem.buf); } else { tfClose(ctx->file.fd); + if (remove) { + indexError("rm file %s", ctx->file.buf); + unlink(ctx->file.buf); + } } free(ctx); } @@ -138,10 +143,8 @@ int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len) return nRead; } -uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter* write) { - return 0; -} -int fstCountingWriterFlush(FstCountingWriter* write) { +uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter* write) { return 0; } +int fstCountingWriterFlush(FstCountingWriter* write) { WriterCtx* ctx = write->wrt; ctx->flush(ctx); // write->wtr->flush diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index e02a3e03276e659e7decd0ff17d94b7a8e4d9162..17322e301e3b2227d610b7af45819d617b063a25 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -23,8 +23,16 @@ #include "taosdef.h" #include "tcompare.h" +typedef struct TFileFstIter { + FstStreamBuilder* fb; + StreamWithState* st; + AutomationCtx* ctx; + TFileReader* rdr; +} TFileFstIter; + #define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t)) +static int tfileUidCompare(const void* a, const void* b); static int tfileStrCompare(const void* a, const void* b); static int tfileValueCompare(const void* a, const void* b, const void* param); static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds); @@ -33,11 +41,9 @@ static int tfileWriteHeader(TFileWriter* writer); static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset); static int tfileWriteData(TFileWriter* write, TFileValue* tval); -static int tfileReadLoadHeader(TFileReader* reader); -static int tfileReadLoadFst(TFileReader* reader); -static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* result); -static void tfileReadRef(TFileReader* reader); -static void tfileReadUnRef(TFileReader* reader); +static int tfileReaderLoadHeader(TFileReader* reader); +static int tfileReaderLoadFst(TFileReader* reader); +static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result); static int tfileGetFileList(const char* path, SArray* result); static int tfileRmExpireFile(SArray* result); @@ -47,6 +53,13 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version); static void tfileSerialCacheKey(TFileCacheKey* key, char* buf); +static TFileReader* tfileReaderCreateImpl(WriterCtx* ctx) { + TFileReader* reader = tfileReaderCreate(ctx); + tfileReaderRef(reader); + // tfileSerialCacheKey(&key, buf); + return reader; +} + TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); if (tcache == NULL) { return NULL; } @@ -68,30 +81,19 @@ TFileCache* tfileCacheCreate(const char* path) { continue; } - WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); if (wc == NULL) { - indexError("failed to open index: %s", file); + indexError("failed to open index:%s", file); goto End; } - TFileReader* reader = tfileReaderCreate(wc); - if (0 != tfileReadLoadHeader(reader)) { - tfileReaderDestroy(reader); - indexError("failed to load index header, index file: %s", file); - goto End; - } - - if (0 != tfileReadLoadFst(reader)) { - tfileReaderDestroy(reader); - indexError("failed to load index fst, index file: %s", file); - goto End; - } - tfileReadRef(reader); - // loader fst and validate it + char buf[128] = {0}; + TFileReader* reader = tfileReaderCreateImpl(wc); TFileHeader* header = &reader->header; - TFileCacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; - - char buf[128] = {0}; + TFileCacheKey key = {.suid = header->suid, + .colName = header->colName, + .nColName = strlen(header->colName), + .colType = header->colType}; tfileSerialCacheKey(&key, buf); taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); } @@ -109,9 +111,10 @@ void tfileCacheDestroy(TFileCache* tcache) { TFileReader** reader = taosHashIterate(tcache->tableCache, NULL); while (reader) { TFileReader* p = *reader; - indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName, p->header.colType); + indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName, + p->header.colType); - tfileReadUnRef(p); + tfileReaderUnRef(p); reader = taosHashIterate(tcache->tableCache, reader); } taosHashCleanup(tcache->tableCache); @@ -122,40 +125,54 @@ TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) { char buf[128] = {0}; tfileSerialCacheKey(key, buf); - TFileReader* reader = taosHashGet(tcache->tableCache, buf, strlen(buf)); - tfileReadRef(reader); + TFileReader** reader = taosHashGet(tcache->tableCache, buf, strlen(buf)); + if (reader == NULL) { return NULL; } + tfileReaderRef(*reader); - return reader; + return *reader; } void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader) { char buf[128] = {0}; tfileSerialCacheKey(key, buf); // remove last version index reader TFileReader** p = taosHashGet(tcache->tableCache, buf, strlen(buf)); - if (*p != NULL) { + if (p != NULL) { TFileReader* oldReader = *p; taosHashRemove(tcache->tableCache, buf, strlen(buf)); - tfileReadUnRef(oldReader); + tfileReaderUnRef(oldReader); } - tfileReadRef(reader); + tfileReaderRef(reader); taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); return; } - TFileReader* tfileReaderCreate(WriterCtx* ctx) { TFileReader* reader = calloc(1, sizeof(TFileReader)); if (reader == NULL) { return NULL; } // T_REF_INC(reader); reader->ctx = ctx; + + if (0 != tfileReaderLoadHeader(reader)) { + tfileReaderDestroy(reader); + indexError("failed to load index header, suid: %" PRIu64 ", colName: %s", reader->header.suid, + reader->header.colName); + return NULL; + } + + if (0 != tfileReaderLoadFst(reader)) { + tfileReaderDestroy(reader); + indexError("failed to load index fst, suid: %" PRIu64 ", colName: %s", reader->header.suid, reader->header.colName); + return NULL; + } + return reader; } void tfileReaderDestroy(TFileReader* reader) { if (reader == NULL) { return; } // T_REF_INC(reader); fstDestroy(reader->fst); - writerCtxDestroy(reader->ctx); + writerCtxDestroy(reader->ctx, true); free(reader); } @@ -169,10 +186,12 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* resul uint64_t offset; FstSlice key = fstSliceCreate(term->colVal, term->nColVal); if (fstGet(reader->fst, &key, &offset)) { - indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName, term->colVal); - ret = tfileReadLoadTableIds(reader, offset, result); + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName, + term->colVal); + ret = tfileReaderLoadTableIds(reader, offset, result); } else { - indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName, term->colVal); + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName, + term->colVal); } fstSliceDestroy(&key); } else if (qtype == QUERY_PREFIX) { @@ -181,10 +200,43 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* resul } else { // handle later } - tfileReadUnRef(reader); + tfileReaderUnRef(reader); return ret; } +TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) { + char filename[128] = {0}; + int32_t coldId = 1; + tfileGenFileName(filename, suid, coldId, version); + + char fullname[256] = {0}; + snprintf(fullname, sizeof(fullname), "%s/%s", path, filename); + WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64); + if (wcx == NULL) { return NULL; } + + TFileHeader tfh = {0}; + tfh.suid = suid; + tfh.version = version; + memcpy(tfh.colName, colName, strlen(colName)); + tfh.colType = colType; + + return tfileWriterCreate(wcx, &tfh); +} +TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const char* colName) { + char filename[128] = {0}; + int32_t coldId = 1; + tfileGenFileName(filename, suid, coldId, version); + + char fullname[256] = {0}; + snprintf(fullname, sizeof(fullname), "%s/%s", path, filename); + WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); + if (wc == NULL) { return NULL; } + + TFileReader* reader = tfileReaderCreateImpl(wc); + return reader; + + // tfileSerialCacheKey(&key, buf); +} TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { // char pathBuf[128] = {0}; // sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version); @@ -205,36 +257,32 @@ TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { tw->ctx = ctx; tw->header = *header; tfileWriteHeader(tw); - tw->fb = fstBuilderCreate(ctx, 0); - if (tw->fb == NULL) { - tfileWriterDestroy(tw); - return NULL; - } return tw; } -int tfileWriterPut(TFileWriter* tw, void* data) { +int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // sort by coltype and write to tindex - __compar_fn_t fn; - - int8_t colType = tw->header.colType; - if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { - fn = tfileStrCompare; - } else { - fn = getComparFunc(colType, 0); + if (order == false) { + __compar_fn_t fn; + int8_t colType = tw->header.colType; + if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { + fn = tfileStrCompare; + } else { + fn = getComparFunc(colType, 0); + } + taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); } - taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); - int32_t bufLimit = 4096, offset = 0; - char* buf = calloc(1, sizeof(char) * bufLimit); - char* p = buf; + int32_t bufLimit = 64 * 4096, offset = 0; + // char* buf = calloc(1, sizeof(char) * bufLimit); + // char* p = buf; int32_t sz = taosArrayGetSize((SArray*)data); int32_t fstOffset = tw->offset; // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - + // taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -246,27 +294,41 @@ int tfileWriterPut(TFileWriter* tw, void* data) { int32_t tbsz = taosArrayGetSize(v->tableId); // check buf has enough space or not int32_t ttsz = TF_TABLE_TATOAL_SIZE(tbsz); - if (offset + ttsz > bufLimit) { - // batch write - tw->ctx->write(tw->ctx, buf, offset); - offset = 0; - memset(buf, 0, bufLimit); - p = buf; - } + // if (offset + ttsz >= bufLimit) { + // // batch write + // indexInfo("offset: %d, ttsz: %d", offset, ttsz); + // // std::cout << "offset: " << offset << std::endl; + // // std::cout << "ttsz:" << ttsz < < < std::endl; + // tw->ctx->write(tw->ctx, buf, offset); + // offset = 0; + // memset(buf, 0, bufLimit); + // p = buf; + //} + // if (ttsz >= bufLimit) { + //} + char* buf = calloc(1, ttsz * sizeof(char)); + char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); - offset += ttsz; - p = buf + offset; + tw->ctx->write(tw->ctx, buf, ttsz); + // offset += ttsz; + // p = buf + offset; // set up value offset v->offset = tw->offset; tw->offset += ttsz; + free(buf); } - if (offset != 0) { - // write reversed data in buf to tindex - tw->ctx->write(tw->ctx, buf, offset); - } - tfree(buf); + // if (offset != 0) { + // write reversed data in buf to tindex + // tw->ctx->write(tw->ctx, buf, offset); + //} + // tfree(buf); + tw->fb = fstBuilderCreate(tw->ctx, 0); + if (tw->fb == NULL) { + tfileWriterClose(tw); + return -1; + } // write fst for (size_t i = 0; i < sz; i++) { // TODO, fst batch write later @@ -280,10 +342,14 @@ int tfileWriterPut(TFileWriter* tw, void* data) { tw->fb = NULL; return 0; } +void tfileWriterClose(TFileWriter* tw) { + if (tw == NULL) { return; } + writerCtxDestroy(tw->ctx, false); + free(tw); +} void tfileWriterDestroy(TFileWriter* tw) { if (tw == NULL) { return; } - - writerCtxDestroy(tw->ctx); + writerCtxDestroy(tw->ctx, false); free(tw); } @@ -294,9 +360,7 @@ IndexTFile* indexTFileCreate(const char* path) { tfile->cache = tfileCacheCreate(path); return tfile; } -void IndexTFileDestroy(IndexTFile* tfile) { - free(tfile); -} +void IndexTFileDestroy(IndexTFile* tfile) { free(tfile); } int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; @@ -304,18 +368,98 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; - TFileCacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; - TFileReader* reader = tfileCacheGet(pTfile->cache, &key); + TFileCacheKey key = { + .suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; + TFileReader* reader = tfileCacheGet(pTfile->cache, &key); + if (reader == NULL) { return 0; } return tfileReaderSearch(reader, query, result); } int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) { - // TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version = - // 1}; + // TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = + // term->nColName, .version = 1}; return 0; } +static bool tfileIteratorNext(Iterate* iiter) { + IterateValue* iv = &iiter->val; + iterateValueDestroy(iv, false); + // SArray* tblIds = iv->val; + + char* colVal = NULL; + uint64_t offset = 0; + + TFileFstIter* tIter = iiter->iter; + StreamWithStateResult* rt = streamWithStateNextWith(tIter->st, NULL); + if (rt == NULL) { return false; } + + int32_t sz = 0; + char* ch = (char*)fstSliceData(&rt->data, &sz); + colVal = calloc(1, sz + 1); + memcpy(colVal, ch, sz); + + offset = (uint64_t)(rt->out.out); + swsResultDestroy(rt); + // set up iterate value + if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { return false; } + + iv->colVal = colVal; + + // std::string key(ch, sz); +} + +static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; } + +static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { + TFileFstIter* tIter = calloc(1, sizeof(Iterate)); + if (tIter == NULL) { return NULL; } + + tIter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS); + tIter->fb = fstSearch(reader->fst, tIter->ctx); + tIter->st = streamBuilderIntoStream(tIter->fb); + tIter->rdr = reader; + return tIter; +} + +Iterate* tfileIteratorCreate(TFileReader* reader) { + if (reader == NULL) { return NULL; } + + Iterate* iter = calloc(1, sizeof(Iterate)); + iter->iter = tfileFstIteratorCreate(reader); + if (iter->iter == NULL) { + free(iter); + return NULL; + } + iter->next = tfileIteratorNext; + iter->getValue = tifileIterateGetValue; + iter->val.val = taosArrayInit(1, sizeof(uint64_t)); + return iter; +} +void tfileIteratorDestroy(Iterate* iter) { + if (iter == NULL) { return; } + IterateValue* iv = &iter->val; + iterateValueDestroy(iv, true); + + TFileFstIter* tIter = iter->iter; + streamWithStateDestroy(tIter->st); + fstStreamBuilderDestroy(tIter->fb); + automCtxDestroy(tIter->ctx); + + free(iter); +} + +TFileReader* tfileGetReaderByCol(IndexTFile* tf, char* colName) { + if (tf == NULL) { return NULL; } + TFileCacheKey key = {.suid = 0, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; + return tfileCacheGet(tf->cache, &key); +} + +static int tfileUidCompare(const void* a, const void* b) { + uint64_t l = *(uint64_t*)a; + uint64_t r = *(uint64_t*)b; + return l - r; +} static int tfileStrCompare(const void* a, const void* b) { int ret = strcmp((char*)a, (char*)b); if (ret == 0) { return ret; } @@ -330,6 +474,23 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) { return fn(av->colVal, bv->colVal); } + +TFileValue* tfileValueCreate(char* val) { + TFileValue* tf = calloc(1, sizeof(TFileValue)); + if (tf == NULL) { return NULL; } + tf->colVal = val; + tf->tableId = taosArrayInit(32, sizeof(uint64_t)); + return tf; +} +int tfileValuePush(TFileValue* tf, uint64_t val) { + if (tf == NULL) { return -1; } + taosArrayPush(tf->tableId, &val); + return 0; +} +void tfileValueDestroy(TFileValue* tf) { + taosArrayDestroy(tf->tableId); + free(tf); +} static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { int sz = taosArrayGetSize(ids); SERIALIZE_VAR_TO_BUF(buf, sz, int32_t); @@ -343,6 +504,7 @@ static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset) { int32_t fstOffset = offset + sizeof(tw->header.fstOffset); tw->header.fstOffset = fstOffset; if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { return -1; } + tw->offset += sizeof(fstOffset); return 0; } static int tfileWriteHeader(TFileWriter* writer) { @@ -372,18 +534,18 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) { } return 0; } -static int tfileReadLoadHeader(TFileReader* reader) { +static int tfileReaderLoadHeader(TFileReader* reader) { // TODO simple tfile header later char buf[TFILE_HEADER_SIZE] = {0}; - int64_t nread = reader->ctx->read(reader->ctx, buf, sizeof(buf)); + int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); return 0; } -static int tfileReadLoadFst(TFileReader* reader) { +static int tfileReaderLoadFst(TFileReader* reader) { // current load fst into memory, refactor it later - static int FST_MAX_SIZE = 16 * 1024; + static int FST_MAX_SIZE = 64 * 1024; char* buf = calloc(1, sizeof(char) * FST_MAX_SIZE); if (buf == NULL) { return -1; } @@ -398,9 +560,9 @@ static int tfileReadLoadFst(TFileReader* reader) { free(buf); fstSliceDestroy(&st); - return reader->fst == NULL ? 0 : -1; + return reader->fst != NULL ? 0 : -1; } -static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) { +static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) { int32_t nid; WriterCtx* ctx = reader->ctx; @@ -414,20 +576,23 @@ static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* re nread = ctx->read(ctx, buf, total); assert(total == nread); - for (int32_t i = 0; i < nid; i++) { - taosArrayPush(result, (uint64_t*)buf + i); - } + for (int32_t i = 0; i < nid; i++) { taosArrayPush(result, (uint64_t*)buf + i); } free(buf); return 0; } -static void tfileReadRef(TFileReader* reader) { +void tfileReaderRef(TFileReader* reader) { + if (reader == NULL) { return; } int ref = T_REF_INC(reader); UNUSED(ref); } -static void tfileReadUnRef(TFileReader* reader) { +void tfileReaderUnRef(TFileReader* reader) { + if (reader == NULL) { return; } int ref = T_REF_DEC(reader); - if (ref == 0) { tfileReaderDestroy(reader); } + if (ref == 0) { + // do nothing + tfileReaderDestroy(reader); + } } static int tfileGetFileList(const char* path, SArray* result) { @@ -459,7 +624,9 @@ static int tfileCompare(const void* a, const void* b) { size_t aLen = strlen(aName); size_t bLen = strlen(bName); - return strncmp(aName, bName, aLen > bLen ? aLen : bLen); + int ret = strncmp(aName, bName, aLen > bLen ? aLen : bLen); + if (ret == 0) { return ret; } + return ret < 0 ? -1 : 1; } // tfile name suid-colId-version.tindex static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version) { @@ -474,9 +641,9 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, return -1; } static void tfileSerialCacheKey(TFileCacheKey* key, char* buf) { - SERIALIZE_MEM_TO_BUF(buf, key, suid); - SERIALIZE_VAR_TO_BUF(buf, '_', char); - SERIALIZE_MEM_TO_BUF(buf, key, colType); - SERIALIZE_VAR_TO_BUF(buf, '_', char); + // SERIALIZE_MEM_TO_BUF(buf, key, suid); + // SERIALIZE_VAR_TO_BUF(buf, '_', char); + // SERIALIZE_MEM_TO_BUF(buf, key, colType); + // SERIALIZE_VAR_TO_BUF(buf, '_', char); SERIALIZE_STR_MEM_TO_BUF(buf, key, colName, key->nColName); } diff --git a/source/libs/index/test/CMakeLists.txt b/source/libs/index/test/CMakeLists.txt index 6eb532b41e5e619aa3169ebaea37c09924df4ec1..3957554748dd7797822313524141da0486d4e14d 100644 --- a/source/libs/index/test/CMakeLists.txt +++ b/source/libs/index/test/CMakeLists.txt @@ -1,13 +1,23 @@ add_executable(indexTest "") +add_executable(fstTest "") target_sources(indexTest PRIVATE "indexTests.cc" ) +target_sources(fstTest + PRIVATE + "fstTest.cc" +) target_include_directories ( indexTest PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories ( fstTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/index" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries (indexTest os util @@ -15,8 +25,16 @@ target_link_libraries (indexTest gtest_main index ) - -add_test( - NAME index_test - COMMAND indexTest +target_link_libraries (fstTest + os + util + common + gtest_main + index ) + + +#add_test( +# NAME index_test +# COMMAND indexTest +#) diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc new file mode 100644 index 0000000000000000000000000000000000000000..a4d8bb36f11c86b155c599c94bb8ce79c9466c5e --- /dev/null +++ b/source/libs/index/test/fstTest.cc @@ -0,0 +1,172 @@ + +#include +#include +#include +#include "index.h" +#include "indexInt.h" +#include "index_cache.h" +#include "index_fst.h" +#include "index_fst_counting_writer.h" +#include "index_fst_util.h" +#include "index_tfile.h" +#include "tskiplist.h" +#include "tutil.h" + +void* callback(void* s) { return s; } + +static std::string fileName = "/tmp/tindex.tindex"; +class FstWriter { + public: + FstWriter() { + remove(fileName.c_str()); + _wc = writerCtxCreate(TFile, fileName.c_str(), false, 64 * 1024 * 1024); + _b = fstBuilderCreate(_wc, 0); + } + bool Put(const std::string& key, uint64_t val) { + FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); + bool ok = fstBuilderInsert(_b, skey, val); + fstSliceDestroy(&skey); + return ok; + } + ~FstWriter() { + fstBuilderFinish(_b); + fstBuilderDestroy(_b); + + writerCtxDestroy(_wc, false); + } + + private: + FstBuilder* _b; + WriterCtx* _wc; +}; + +class FstReadMemory { + public: + FstReadMemory(size_t size) { + _wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024); + _w = fstCountingWriterCreate(_wc); + _size = size; + memset((void*)&_s, 0, sizeof(_s)); + } + bool init() { + char* buf = (char*)calloc(1, sizeof(char) * _size); + int nRead = fstCountingWriterRead(_w, (uint8_t*)buf, _size); + if (nRead <= 0) { return false; } + _size = nRead; + _s = fstSliceCreate((uint8_t*)buf, _size); + _fst = fstCreate(&_s); + free(buf); + return _fst != NULL; + } + bool Get(const std::string& key, uint64_t* val) { + FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); + bool ok = fstGet(_fst, &skey, val); + fstSliceDestroy(&skey); + return ok; + } + bool GetWithTimeCostUs(const std::string& key, uint64_t* val, uint64_t* elapse) { + int64_t s = taosGetTimestampUs(); + bool ok = this->Get(key, val); + int64_t e = taosGetTimestampUs(); + *elapse = e - s; + return ok; + } + // add later + bool Search(AutomationCtx* ctx, std::vector& result) { + FstStreamBuilder* sb = fstSearch(_fst, ctx); + StreamWithState* st = streamBuilderIntoStream(sb); + StreamWithStateResult* rt = NULL; + while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + // result.push_back((uint64_t)(rt->out.out)); + FstSlice* s = &rt->data; + int32_t sz = 0; + char* ch = (char*)fstSliceData(s, &sz); + std::string key(ch, sz); + printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out)); + swsResultDestroy(rt); + } + for (size_t i = 0; i < result.size(); i++) {} + std::cout << std::endl; + return true; + } + bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { + int64_t s = taosGetTimestampUs(); + bool ok = this->Search(ctx, result); + int64_t e = taosGetTimestampUs(); + return ok; + } + + ~FstReadMemory() { + fstCountingWriterDestroy(_w); + fstDestroy(_fst); + fstSliceDestroy(&_s); + writerCtxDestroy(_wc, false); + } + + private: + FstCountingWriter* _w; + Fst* _fst; + FstSlice _s; + WriterCtx* _wc; + size_t _size; +}; + +#define L 100 +#define M 100 +#define N 100 + +int Performance_fstWriteRecords(FstWriter* b) { + std::string str("aa"); + for (int i = 0; i < L; i++) { + str[0] = 'a' + i; + str.resize(2); + for (int j = 0; j < M; j++) { + str[1] = 'a' + j; + str.resize(2); + for (int k = 0; k < N; k++) { + str.push_back('a'); + b->Put(str, k); + printf("(%d, %d, %d, %s)\n", i, j, k, str.c_str()); + } + } + } + return L * M * N; +} +void checkFstCheckIterator() { + tfInit(); + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; + Performance_fstWriteRecords(fw); + int64_t e = taosGetTimestampUs(); + + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + + // prefix search + std::vector result; + + AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); + m->Search(ctx, result); + std::cout << "size: " << result.size() << std::endl; + // assert(result.size() == count); + for (int i = 0; i < result.size(); i++) { + // assert(result[i] == i); // check result + } + + free(ctx); + delete m; + tfCleanup(); +} +int main() { + checkFstCheckIterator(); + // checkFstPrefixSearch(); + return 1; +} diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index f8dae787b898706b5b194858337613e48df0b93f..588205c67ff95b4a1836b37c17681b33f2fbd414 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -2,7 +2,8 @@ * 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. + * 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 @@ -16,12 +17,30 @@ #include #include "index.h" #include "indexInt.h" +#include "index_cache.h" #include "index_fst.h" #include "index_fst_counting_writer.h" #include "index_fst_util.h" #include "index_tfile.h" +#include "tskiplist.h" #include "tutil.h" +using namespace std; +class DebugInfo { + public: + DebugInfo(const char* str) : info(str) { + std::cout << "------------" << info << "\t" + << "begin" + << "-------------" << std::endl; + } + ~DebugInfo() { + std::cout << "-----------" << info << "\t" + << "end" + << "--------------" << std::endl; + } + private: + std::string info; +}; class FstWriter { public: FstWriter() { @@ -38,7 +57,7 @@ class FstWriter { fstBuilderFinish(_b); fstBuilderDestroy(_b); - writerCtxDestroy(_wc); + writerCtxDestroy(_wc, false); } private: @@ -83,9 +102,7 @@ class FstReadMemory { StreamWithState* st = streamBuilderIntoStream(sb); StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { - result.push_back((uint64_t)(rt->out.out)); - } + while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { result.push_back((uint64_t)(rt->out.out)); } return true; } bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { @@ -99,7 +116,7 @@ class FstReadMemory { fstCountingWriterDestroy(_w); fstDestroy(_fst); fstSliceDestroy(&_s); - writerCtxDestroy(_wc); + writerCtxDestroy(_wc, true); } private: @@ -110,58 +127,6 @@ class FstReadMemory { size_t _size; }; -// TEST(IndexTest, index_create_test) { -// SIndexOpts *opts = indexOptsCreate(); -// SIndex *index = indexOpen(opts, "./test"); -// if (index == NULL) { -// std::cout << "index open failed" << std::endl; -// } -// -// -// // write -// for (int i = 0; i < 100000; i++) { -// SIndexMultiTerm* terms = indexMultiTermCreate(); -// std::string val = "field"; -// -// indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size()); -// -// val.append(std::to_string(i)); -// indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size()); -// -// val.insert(0, std::to_string(i)); -// indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size()); -// -// val.append("const"); -// indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size()); -// -// -// indexPut(index, terms, i); -// indexMultiTermDestroy(terms); -// } -// -// -// // query -// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST); -// -// indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX); -// indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM); -// -// SArray *result = (SArray *)taosArrayInit(10, sizeof(int)); -// indexSearch(index, multiQuery, result); -// -// std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl; -// for (int i = 0; i < taosArrayGetSize(result); i++) { -// int *v = (int *)taosArrayGet(result, i); -// std::cout << "value --->" << *v << std::endl; -// } -// // add more test case -// indexMultiTermQueryDestroy(multiQuery); -// -// indexOptsDestroy(opts); -// indexClose(index); -// // -//} - #define L 100 #define M 100 #define N 100 @@ -183,7 +148,6 @@ int Performance_fstWriteRecords(FstWriter* b) { } return L * M * N; } - void Performance_fstReadRecords(FstReadMemory* m) { std::string str("aa"); for (int i = 0; i < M; i++) { @@ -218,7 +182,6 @@ void checkFstPerf() { Performance_fstReadRecords(m); delete m; } - void checkFstPrefixSearch() { FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); @@ -296,7 +259,6 @@ void validateFst() { } delete m; } - class IndexEnv : public ::testing::Test { protected: virtual void SetUp() { @@ -315,79 +277,147 @@ class IndexEnv : public ::testing::Test { SIndex* index; }; -// TEST_F(IndexEnv, testPut) { -// // single index column -// { -// std::string colName("tag1"), colVal("Hello world"); -// SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), -// colVal.size()); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); -// -// for (size_t i = 0; i < 100; i++) { -// int tableId = i; -// int ret = indexPut(index, terms, tableId); -// assert(ret == 0); +/// TEST_F(IndexEnv, testPut) { +// / // single index column +// / { +// / std::string colName("tag1"), colVal("Hello world"); +// / SIndexTerm* term = +// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), / +// colVal.size()); +// SIndexMultiTerm* terms = indexMultiTermCreate(); +// indexMultiTermAdd(terms, term); +// / / for (size_t i = 0; i < 100; i++) { +// / int tableId = i; +// / int ret = indexPut(index, terms, tableId); +// / assert(ret == 0); +// / // } -// indexMultiTermDestroy(terms); +// / indexMultiTermDestroy(terms); +// / // } -// // multi index column -// { -// SIndexMultiTerm* terms = indexMultiTermCreate(); -// { -// std::string colName("tag1"), colVal("Hello world"); -// SIndexTerm* term = -// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); -// indexMultiTermAdd(terms, term); +// / // multi index column +// / { +// / SIndexMultiTerm* terms = indexMultiTermCreate(); +// / { +// / std::string colName("tag1"), colVal("Hello world"); +// / SIndexTerm* term = +// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), +// colVal.size()); +// / indexMultiTermAdd(terms, term); +// / // } -// { -// std::string colName("tag2"), colVal("Hello world"); -// SIndexTerm* term = -// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); -// indexMultiTermAdd(terms, term); +// / { +// / std::string colName("tag2"), colVal("Hello world"); +// / SIndexTerm* term = +// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), +// colVal.size()); +// / indexMultiTermAdd(terms, term); +// / // } -// -// for (int i = 0; i < 100; i++) { -// int tableId = i; -// int ret = indexPut(index, terms, tableId); -// assert(ret == 0); +// / / for (int i = 0; i < 100; i++) { +// / int tableId = i; +// / int ret = indexPut(index, terms, tableId); +// / assert(ret == 0); +// / // } -// indexMultiTermDestroy(terms); +// / indexMultiTermDestroy(terms); +// / // } -// // +// / // +// / //} -class IndexTFileEnv : public ::testing::Test { - protected: - virtual void SetUp() { - taosRemoveDir(dir); - taosMkDir(dir); - tfInit(); - std::string colName("voltage"); +class TFileObj { + public: + TFileObj(const std::string& path = "/tmp/tindex", const std::string& colName = "voltage") + : path_(path), colName_(colName) { + colId_ = 10; + // Do Nothing + // + } + int Put(SArray* tv) { + if (reader_ != NULL) { + tfileReaderDestroy(reader_); + reader_ = NULL; + } + if (writer_ == NULL) { InitWriter(); } + return tfileWriterPut(writer_, tv, false); + } + bool InitWriter() { + TFileHeader header; header.suid = 1; header.version = 1; - memcpy(header.colName, colName.c_str(), colName.size()); + memcpy(header.colName, colName_.c_str(), colName_.size()); header.colType = TSDB_DATA_TYPE_BINARY; - std::string path(dir); + std::string path(path_); int colId = 2; char buf[64] = {0}; - sprintf(buf, "%" PRIu64 "-%d-%d.tindex", header.suid, colId, header.version); + sprintf(buf, "%" PRIu64 "-%d-%d.tindex", header.suid, colId_, header.version); path.append("/").append(buf); - ctx = writerCtxCreate(TFile, path.c_str(), false, 64 * 1024 * 1024); + fileName_ = path; + + WriterCtx* ctx = writerCtxCreate(TFile, path.c_str(), false, 64 * 1024 * 1024); + + writer_ = tfileWriterCreate(ctx, &header); + return writer_ != NULL ? true : false; + } + bool InitReader() { + WriterCtx* ctx = writerCtxCreate(TFile, fileName_.c_str(), true, 64 * 1024 * 1024); + reader_ = tfileReaderCreate(ctx); + return reader_ != NULL ? true : false; + } + int Get(SIndexTermQuery* query, SArray* result) { + if (writer_ != NULL) { + tfileWriterDestroy(writer_); + writer_ = NULL; + } + if (reader_ == NULL && InitReader()) { + // + // + } + return tfileReaderSearch(reader_, query, result); + } + ~TFileObj() { + if (writer_) { tfileWriterDestroy(writer_); } + if (reader_) { tfileReaderDestroy(reader_); } + } + + private: + std::string path_; + std::string colName_; + std::string fileName_; + + TFileWriter* writer_; + TFileReader* reader_; + + int colId_; +}; - twrite = tfileWriterCreate(ctx, &header); +class IndexTFileEnv : public ::testing::Test { + protected: + virtual void SetUp() { + taosRemoveDir(dir.c_str()); + taosMkDir(dir.c_str()); + tfInit(); + fObj = new TFileObj(dir, colName); } virtual void TearDown() { // indexClose(index); // indexeptsDestroy(opts); + delete fObj; tfCleanup(); - tfileWriterDestroy(twrite); + // tfileWriterDestroy(twrite); } - const char* dir = "/tmp/tindex"; - WriterCtx* ctx = NULL; - TFileHeader header; - TFileWriter* twrite = NULL; + TFileObj* fObj; + std::string dir = "/tmp/tindex"; + std::string colName = "voltage"; + + int coldId = 2; + int version = 1; + int colType = TSDB_DATA_TYPE_BINARY; }; static TFileValue* genTFileValue(const char* val) { @@ -397,7 +427,7 @@ static TFileValue* genTFileValue(const char* val) { memcpy(tv->colVal, val, vlen); tv->tableId = (SArray*)taosArrayInit(1, sizeof(uint64_t)); - for (size_t i = 0; i < 10; i++) { + for (size_t i = 0; i < 200; i++) { uint64_t v = i; taosArrayPush(tv->tableId, &v); } @@ -409,21 +439,334 @@ static void destroyTFileValue(void* val) { taosArrayDestroy(tv->tableId); free(tv); } - TEST_F(IndexTFileEnv, test_tfile_write) { - TFileValue* v1 = genTFileValue("c"); - TFileValue* v2 = genTFileValue("a"); + TFileValue* v1 = genTFileValue("ab"); SArray* data = (SArray*)taosArrayInit(4, sizeof(void*)); taosArrayPush(data, &v1); - taosArrayPush(data, &v2); + // taosArrayPush(data, &v2); + // taosArrayPush(data, &v3); + // taosArrayPush(data, &v4); + + fObj->Put(data); + for (size_t i = 0; i < taosArrayGetSize(data); i++) { destroyTFileValue(taosArrayGetP(data, i)); } + taosArrayDestroy(data); + + std::string colName("voltage"); + std::string colVal("ab"); + SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; + + SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + fObj->Get(&query, result); + assert(taosArrayGetSize(result) == 200); + indexTermDestroy(term); - tfileWriterPut(twrite, data); // tfileWriterDestroy(twrite); +} +class CacheObj { + public: + CacheObj() { + // TODO + cache = indexCacheCreate(NULL, "voltage", TSDB_DATA_TYPE_BINARY); + } + int Put(SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid) { + int ret = indexCachePut(cache, term, uid); + if (ret != 0) { + // + std::cout << "failed to put into cache: " << ret << std::endl; + } + return ret; + } + void Debug() { + // + indexCacheDebug(cache); + } + int Get(SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s) { + int ret = indexCacheSearch(cache, query, result, s); + if (ret != 0) { + // + std::cout << "failed to get from cache:" << ret << std::endl; + } + return ret; + } + ~CacheObj() { + // TODO + indexCacheDestroy(cache); + } - for (size_t i = 0; i < taosArrayGetSize(data); i++) { - destroyTFileValue(taosArrayGetP(data, i)); + private: + IndexCache* cache = NULL; +}; + +class IndexCacheEnv : public ::testing::Test { + protected: + virtual void SetUp() { + // TODO + coj = new CacheObj(); } - taosArrayDestroy(data); + virtual void TearDown() { + delete coj; + // formate + } + CacheObj* coj; +}; + +#define MAX_TERM_KEY_LEN 128 +TEST_F(IndexCacheEnv, cache_test) { + int version = 0; + int16_t colId = 0; + int16_t othColId = 10; + + uint64_t suid = 0; + std::string colName("voltage"); + { + std::string colVal("v1"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v2"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + coj->Debug(); + std::cout << "--------first----------" << std::endl; + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, othColId, version++, suid++); + } + { + std::string colVal("v4"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, othColId, version++, suid++); + } + coj->Debug(); + std::cout << "--------second----------" << std::endl; + { + std::string colVal("v4"); + for (size_t i = 0; i < 10; i++) { + colVal[colVal.size() - 1] = 'a' + i; + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + coj->Put(term, colId, version++, suid++); + } + } + coj->Debug(); + // begin query + { + std::string colVal("v3"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; + SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); + STermValueType valType; + + coj->Get(&query, colId, 10000, ret, &valType); + std::cout << "size : " << taosArrayGetSize(ret) << std::endl; + assert(taosArrayGetSize(ret) == 4); + } + { + std::string colVal("v2"); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexTermQuery query = {.term = term, .qType = QUERY_TERM}; + SArray* ret = (SArray*)taosArrayInit(4, sizeof(suid)); + STermValueType valType; + + coj->Get(&query, colId, 10000, ret, &valType); + assert(taosArrayGetSize(ret) == 1); + } +} +class IndexObj { + public: + IndexObj() { + // opt + numOfWrite = 0; + numOfRead = 0; + indexInit(); + } + int Init(const std::string& dir) { + taosRemoveDir(dir.c_str()); + taosMkDir(dir.c_str()); + int ret = indexOpen(&opts, dir.c_str(), &idx); + if (ret != 0) { + // opt + std::cout << "failed to open index: %s" << dir << std::endl; + } + return ret; + } + int WriteMillonData(const std::string& colName, const std::string& colVal = "Hello world", + size_t numOfTable = 100 * 10000) { + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + for (size_t i = 0; i < numOfTable; i++) { + int ret = Put(terms, i); + assert(ret == 0); + } + indexMultiTermDestroy(terms); + return numOfTable; + } + + int Put(SIndexMultiTerm* fvs, uint64_t uid) { + numOfWrite += taosArrayGetSize(fvs); + return indexPut(idx, fvs, uid); + } + int Search(SIndexMultiTermQuery* multiQ, SArray* result) { + SArray* query = multiQ->query; + numOfRead = taosArrayGetSize(query); + return indexSearch(idx, multiQ, result); + } + + int SearchOne(const std::string& colName, const std::string& colVal) { + SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermQueryAdd(mq, term, QUERY_TERM); + + SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + if (Search(mq, result) == 0) { std::cout << "search one successfully" << std::endl; } + return taosArrayGetSize(result); + // assert(taosArrayGetSize(result) == targetSize); + } + void Debug() { + std::cout << "numOfWrite:" << numOfWrite << std::endl; + std::cout << "numOfRead:" << numOfRead << std::endl; + } + + ~IndexObj() { + indexCleanUp(); + indexClose(idx); + } + + private: + SIndexOpts opts; + SIndex* idx; + int numOfWrite; + int numOfRead; +}; + +class IndexEnv2 : public ::testing::Test { + protected: + virtual void SetUp() { + tfInit(); + index = new IndexObj(); + // + } + virtual void TearDown() { + delete index; + tfCleanup(); + } + IndexObj* index; +}; +TEST_F(IndexEnv2, testIndexOpen) { + std::string path = "/tmp"; + if (index->Init(path) != 0) { + std::cout << "failed to init index" << std::endl; + exit(1); + } + + int targetSize = 200; + { + std::string colName("tag1"), colVal("Hello"); + + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + for (size_t i = 0; i < targetSize; i++) { + int tableId = i; + int ret = index->Put(terms, tableId); + assert(ret == 0); + } + indexMultiTermDestroy(terms); + } + { + size_t size = 200; + std::string colName("tag1"), colVal("hello"); + + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + for (size_t i = 0; i < size; i++) { + int tableId = i; + int ret = index->Put(terms, tableId); + assert(ret == 0); + } + indexMultiTermDestroy(terms); + } + + { + std::string colName("tag1"), colVal("Hello"); + + SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermQueryAdd(mq, term, QUERY_TERM); + + SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + index->Search(mq, result); + std::cout << "target size: " << taosArrayGetSize(result) << std::endl; + // assert(taosArrayGetSize(result) == targetSize); + } +} + +TEST_F(IndexEnv2, testIndex_TrigeFlush) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} + int numOfTable = 100 * 10000; + index->WriteMillonData("tag1", "Hello world", numOfTable); + int target = index->SearchOne("tag1", "Hello world"); + assert(numOfTable == target); +} +TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} +} +TEST_F(IndexEnv2, testIndex_multi_thread_write) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} +} +TEST_F(IndexEnv2, testIndex_multi_thread_read) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} +} + +TEST_F(IndexEnv2, testIndex_restart) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} +} + +TEST_F(IndexEnv2, testIndex_performance) { + std::string path = "/tmp"; + if (index->Init(path) != 0) {} } +TEST_F(IndexEnv2, testIndexMultiTag) {} diff --git a/source/libs/parser/inc/astGenerator.h b/source/libs/parser/inc/astGenerator.h index 6ae40b0d7163bc127fcd92a2bd04a557316fa87b..0febc5ea33171d96916d5c155b3762bafe1f3fe0 100644 --- a/source/libs/parser/inc/astGenerator.h +++ b/source/libs/parser/inc/astGenerator.h @@ -156,7 +156,7 @@ typedef struct SCreateDbInfo { SToken dbname; int32_t replica; int32_t cacheBlockSize; - int32_t maxTablesPerVnode; + int32_t numOfVgroups; int32_t numOfBlocks; int32_t daysPerFile; int32_t minRowsPerBlock; diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index c0c3c8386b5237707881204efd00dcda07896126..ba33767a05b5edeb3594aaf075102d6246bf3e1a 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -2,14 +2,17 @@ #define TDENGINE_ASTTOMSG_H #include "parserInt.h" -#include "taosmsg.h" +#include "tmsg.h" + SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen); +SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); -SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); +SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); #endif // TDENGINE_ASTTOMSG_H diff --git a/source/libs/parser/inc/parserUtil.h b/source/libs/parser/inc/parserUtil.h index 3d8729e72d57eb9dd8f8b0bbcd46a128ed865766..764b36339435171d1a540f979afe111e0d7dbf69 100644 --- a/source/libs/parser/inc/parserUtil.h +++ b/source/libs/parser/inc/parserUtil.h @@ -62,7 +62,7 @@ void cleanupTagCond(STagCond* pTagCond); void cleanupColumnCond(SArray** pCond); uint32_t convertRelationalOperator(SToken *pToken); -int32_t getExprFunctionId(SExprInfo *pExprInfo); +int32_t getExprFunctionId(SExprInfo *pExprInfo); STableMeta* tableMetaDup(const STableMeta* pTableMeta); @@ -70,6 +70,19 @@ bool isDclSqlStatement(SSqlInfo* pSqlInfo); bool isDdlSqlStatement(SSqlInfo* pSqlInfo); bool isDqlSqlStatement(SSqlInfo* pSqlInfo); +typedef struct SKvParam { + SKVRowBuilder *builder; + SSchema *schema; + char buf[TSDB_MAX_TAGS_LEN]; +} SKvParam; + +int32_t KvRowAppend(const void *value, int32_t len, void *param); + +typedef int32_t (*_row_append_fn_t)(const void *value, int32_t len, void *param); +int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, char* tmpTokenBuf, _row_append_fn_t func, void* param, SMsgBuf* pMsgBuf); + +int32_t createSName(SName* pName, SToken* pTableName, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); + #ifdef __cplusplus } #endif diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 183b71483be7d275f5745678e4882bc6ed444db3..bf59a0f80a873f96779c638cbbacd4d1d5a0f9d0 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -6,7 +6,7 @@ %default_type {SToken} %extra_argument {SSqlInfo* pInfo} -%fallback ID BOOL TINYINT SMALLINT INTEGER BIGINT FLOAT DOUBLE STRING TIMESTAMP BINARY NCHAR. +%fallback ID BOOL INTEGER FLOAT STRING TIMESTAMP. %left OR. %left AND. @@ -200,7 +200,8 @@ ifnotexists(X) ::= . { X.n = 0;} /////////////////////////////////THE CREATE STATEMENT/////////////////////////////////////// //create option for dnode/db/user/account -cmd ::= CREATE DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);} +cmd ::= CREATE DNODE ids(X) PORT ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &X, &Y);} +cmd ::= CREATE DNODE IPTOKEN(X) PORT ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &X, &Y);} cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);} cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} @@ -279,6 +280,7 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; } prec(Y) ::= PRECISION STRING(X). { Y = X; } update(Y) ::= UPDATE INTEGER(X). { Y = X; } cachelast(Y) ::= CACHELAST INTEGER(X). { Y = X; } +vgroups(Y) ::= VGROUPS INTEGER(X). { Y = X; } //partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; } %type db_optr {SCreateDbInfo} @@ -299,6 +301,7 @@ db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; } db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; } db_optr(Y) ::= db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); } +db_optr(Y) ::= db_optr(Z) vgroups(X). { Y = Z; Y.numOfVgroups = strtol(X.z, NULL, 10); } //%type topic_optr {SCreateDbInfo} // @@ -398,13 +401,13 @@ create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP T // create table by using super table // create table table_name using super_table_name tags(tag_values1, tag_values2) %type create_from_stable{SCreatedTableInfo} -create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. { +create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist1(Y) RP. { X.n += F.n; V.n += Z.n; A = createNewChildTableInfo(&X, NULL, Y, &V, &U); } -create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist(Y) RP. { +create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist1(Y) RP. { X.n += F.n; V.n += Z.n; A = createNewChildTableInfo(&X, P, Y, &V, &U); @@ -437,6 +440,24 @@ column(A) ::= ids(X) typename(Y). { tSetColumnInfo(&A, &X, &Y); } +%type tagitemlist1 {SArray*} +%destructor tagitemlist1 {taosArrayDestroy($$);} + +tagitemlist1(A) ::= tagitemlist1(X) COMMA tagitem1(Y). { taosArrayPush(X, &Y); A = X;} +tagitemlist1(A) ::= tagitem1(Y). { A = taosArrayInit(4, sizeof(SToken)); taosArrayPush(A, &Y); } + +%type tagitem1 {SToken} +tagitem1(A) ::= MINUS(X) INTEGER(Y). { A.n = X.n + Y.n; A.type = Y.type; } +tagitem1(A) ::= MINUS(X) FLOAT(Y). { A.n = X.n + Y.n; A.type = Y.type; } +tagitem1(A) ::= PLUS(X) INTEGER(Y). { A.n = X.n + Y.n; A.type = Y.type; } +tagitem1(A) ::= PLUS(X) FLOAT(Y). { A.n = X.n + Y.n; A.type = Y.type; } +tagitem1(A) ::= INTEGER(X). { A = X; } +tagitem1(A) ::= FLOAT(X). { A = X; } +tagitem1(A) ::= STRING(X). { A = X; } +tagitem1(A) ::= BOOL(X). { A = X; } +tagitem1(A) ::= NULL(X). { A = X; } +tagitem1(A) ::= NOW(X). { A = X; } + %type tagitemlist {SArray*} %destructor tagitemlist {taosArrayDestroy($$);} diff --git a/source/libs/parser/inc/ttokendef.h b/source/libs/parser/inc/ttokendef.h deleted file mode 100644 index ccb62b33208ef2b5c766cdfeacd4899006db604e..0000000000000000000000000000000000000000 --- a/source/libs/parser/inc/ttokendef.h +++ /dev/null @@ -1,228 +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 TDENGINE_TTOKENDEF_H -#define TDENGINE_TTOKENDEF_H - -#define TK_ID 1 -#define TK_BOOL 2 -#define TK_TINYINT 3 -#define TK_SMALLINT 4 -#define TK_INTEGER 5 -#define TK_BIGINT 6 -#define TK_FLOAT 7 -#define TK_DOUBLE 8 -#define TK_STRING 9 -#define TK_TIMESTAMP 10 -#define TK_BINARY 11 -#define TK_NCHAR 12 -#define TK_OR 13 -#define TK_AND 14 -#define TK_NOT 15 -#define TK_EQ 16 -#define TK_NE 17 -#define TK_ISNULL 18 -#define TK_NOTNULL 19 -#define TK_IS 20 -#define TK_LIKE 21 -#define TK_MATCH 22 -#define TK_NMATCH 23 -#define TK_GLOB 24 -#define TK_BETWEEN 25 -#define TK_IN 26 -#define TK_GT 27 -#define TK_GE 28 -#define TK_LT 29 -#define TK_LE 30 -#define TK_BITAND 31 -#define TK_BITOR 32 -#define TK_LSHIFT 33 -#define TK_RSHIFT 34 -#define TK_PLUS 35 -#define TK_MINUS 36 -#define TK_DIVIDE 37 -#define TK_TIMES 38 -#define TK_STAR 39 -#define TK_SLASH 40 -#define TK_REM 41 -#define TK_CONCAT 42 -#define TK_UMINUS 43 -#define TK_UPLUS 44 -#define TK_BITNOT 45 -#define TK_SHOW 46 -#define TK_DATABASES 47 -#define TK_TOPICS 48 -#define TK_FUNCTIONS 49 -#define TK_MNODES 50 -#define TK_DNODES 51 -#define TK_ACCOUNTS 52 -#define TK_USERS 53 -#define TK_MODULES 54 -#define TK_QUERIES 55 -#define TK_CONNECTIONS 56 -#define TK_STREAMS 57 -#define TK_VARIABLES 58 -#define TK_SCORES 59 -#define TK_GRANTS 60 -#define TK_VNODES 61 -#define TK_DOT 62 -#define TK_CREATE 63 -#define TK_TABLE 64 -#define TK_STABLE 65 -#define TK_DATABASE 66 -#define TK_TABLES 67 -#define TK_STABLES 68 -#define TK_VGROUPS 69 -#define TK_DROP 70 -#define TK_TOPIC 71 -#define TK_FUNCTION 72 -#define TK_DNODE 73 -#define TK_USER 74 -#define TK_ACCOUNT 75 -#define TK_USE 76 -#define TK_DESCRIBE 77 -#define TK_DESC 78 -#define TK_ALTER 79 -#define TK_PASS 80 -#define TK_PRIVILEGE 81 -#define TK_LOCAL 82 -#define TK_COMPACT 83 -#define TK_LP 84 -#define TK_RP 85 -#define TK_IF 86 -#define TK_EXISTS 87 -#define TK_AS 88 -#define TK_OUTPUTTYPE 89 -#define TK_AGGREGATE 90 -#define TK_BUFSIZE 91 -#define TK_PPS 92 -#define TK_TSERIES 93 -#define TK_DBS 94 -#define TK_STORAGE 95 -#define TK_QTIME 96 -#define TK_CONNS 97 -#define TK_STATE 98 -#define TK_COMMA 99 -#define TK_KEEP 100 -#define TK_CACHE 101 -#define TK_REPLICA 102 -#define TK_QUORUM 103 -#define TK_DAYS 104 -#define TK_MINROWS 105 -#define TK_MAXROWS 106 -#define TK_BLOCKS 107 -#define TK_CTIME 108 -#define TK_WAL 109 -#define TK_FSYNC 110 -#define TK_COMP 111 -#define TK_PRECISION 112 -#define TK_UPDATE 113 -#define TK_CACHELAST 114 -#define TK_UNSIGNED 115 -#define TK_TAGS 116 -#define TK_USING 117 -#define TK_NULL 118 -#define TK_NOW 119 -#define TK_SELECT 120 -#define TK_UNION 121 -#define TK_ALL 122 -#define TK_DISTINCT 123 -#define TK_FROM 124 -#define TK_VARIABLE 125 -#define TK_INTERVAL 126 -#define TK_EVERY 127 -#define TK_SESSION 128 -#define TK_STATE_WINDOW 129 -#define TK_FILL 130 -#define TK_SLIDING 131 -#define TK_ORDER 132 -#define TK_BY 133 -#define TK_ASC 134 -#define TK_GROUP 135 -#define TK_HAVING 136 -#define TK_LIMIT 137 -#define TK_OFFSET 138 -#define TK_SLIMIT 139 -#define TK_SOFFSET 140 -#define TK_WHERE 141 -#define TK_RESET 142 -#define TK_QUERY 143 -#define TK_SYNCDB 144 -#define TK_ADD 145 -#define TK_COLUMN 146 -#define TK_MODIFY 147 -#define TK_TAG 148 -#define TK_CHANGE 149 -#define TK_SET 150 -#define TK_KILL 151 -#define TK_CONNECTION 152 -#define TK_STREAM 153 -#define TK_COLON 154 -#define TK_ABORT 155 -#define TK_AFTER 156 -#define TK_ATTACH 157 -#define TK_BEFORE 158 -#define TK_BEGIN 159 -#define TK_CASCADE 160 -#define TK_CLUSTER 161 -#define TK_CONFLICT 162 -#define TK_COPY 163 -#define TK_DEFERRED 164 -#define TK_DELIMITERS 165 -#define TK_DETACH 166 -#define TK_EACH 167 -#define TK_END 168 -#define TK_EXPLAIN 169 -#define TK_FAIL 170 -#define TK_FOR 171 -#define TK_IGNORE 172 -#define TK_IMMEDIATE 173 -#define TK_INITIALLY 174 -#define TK_INSTEAD 175 -#define TK_KEY 176 -#define TK_OF 177 -#define TK_RAISE 178 -#define TK_REPLACE 179 -#define TK_RESTRICT 180 -#define TK_ROW 181 -#define TK_STATEMENT 182 -#define TK_TRIGGER 183 -#define TK_VIEW 184 -#define TK_IPTOKEN 185 -#define TK_SEMI 186 -#define TK_NONE 187 -#define TK_PREV 188 -#define TK_LINEAR 189 -#define TK_IMPORT 190 -#define TK_TBNAME 191 -#define TK_JOIN 192 -#define TK_INSERT 193 -#define TK_INTO 194 -#define TK_VALUES 195 - - - -#define TK_SPACE 300 -#define TK_COMMENT 301 -#define TK_ILLEGAL 302 -#define TK_HEX 303 // hex number 0x123 -#define TK_OCT 304 // oct number -#define TK_BIN 305 // bin format data 0b111 -#define TK_FILE 306 -#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query - -#endif - - diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index b6a6b73ccc258a5a8d5c12a1961d8f22fabba411..3d12f0f3b7ae8e18239ef3c0a7962c3ffacd1166 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -13,11 +13,12 @@ * along with this program. If not, see . */ -#include "astGenerator.h" -#include #include "os.h" #include "taos.h" +#include "tmsg.h" +#include "parserInt.h" #include "tmsgtype.h" +#include "astGenerator.h" SArray *tListItemAppend(SArray *pList, SVariant *pVar, uint8_t sortOrder) { if (pList == NULL) { @@ -276,7 +277,7 @@ bool tSqlExprIsLeaf(tSqlExpr *pExpr) { return (pExpr->pRight == NULL && pExpr->pLeft == NULL) && (pExpr->tokenId == 0 || (pExpr->tokenId == TK_ID) || - (pExpr->tokenId >= TK_BOOL && pExpr->tokenId <= TK_NCHAR) || + (pExpr->tokenId == TK_BOOL || pExpr->tokenId == TK_STRING || pExpr->tokenId == TK_FLOAT) || (pExpr->tokenId == TK_NULL) || (pExpr->tokenId == TK_SET)); } @@ -947,25 +948,21 @@ void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam) { } void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) { - pDBInfo->compressionLevel = -1; - - pDBInfo->walLevel = -1; - pDBInfo->fsyncPeriod = -1; - pDBInfo->commitTime = -1; - pDBInfo->maxTablesPerVnode = -1; - + pDBInfo->compressionLevel= -1; + pDBInfo->walLevel = -1; + pDBInfo->fsyncPeriod = -1; + pDBInfo->commitTime = -1; + pDBInfo->numOfVgroups = 2; pDBInfo->cacheBlockSize = -1; pDBInfo->numOfBlocks = -1; pDBInfo->maxRowsPerBlock = -1; pDBInfo->minRowsPerBlock = -1; pDBInfo->daysPerFile = -1; - - pDBInfo->replica = -1; - pDBInfo->quorum = -1; - pDBInfo->keep = NULL; - - pDBInfo->update = -1; - pDBInfo->cachelast = -1; + pDBInfo->replica = -1; + pDBInfo->quorum = -1; + pDBInfo->keep = NULL; + pDBInfo->update = -1; + pDBInfo->cachelast = -1; memset(&pDBInfo->precision, 0, sizeof(SToken)); } diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 00f3d3f7162cb4df8de51d7755fce8911dbfaa57..6b0e0ed828ff70739a09659b1cf2bba8b6c6e3cb 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -1,5 +1,5 @@ -#include #include "parserInt.h" +#include "astGenerator.h" #include "parserUtil.h" SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { @@ -86,11 +86,10 @@ SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, cha return pMsg; } -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen) { +SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, char* msgBuf, int32_t msgLen) { SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); pShowMsg->type = pShowInfo->showType; - if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { SToken* pPattern = &pShowInfo->pattern; if (pPattern->type > 0) { // only show tables support wildcard query @@ -105,6 +104,12 @@ SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t m pShowMsg->payloadLen = htons(pEpAddr->n); } + if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) { + SName n = {0}; + tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db)); + tNameGetFullDbName(&n, pShowMsg->db); + } + return pShowMsg; } @@ -176,19 +181,20 @@ static int32_t setTimePrecision(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreate static void doSetDbOptions(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb) { pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize); - pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks); - pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); - pMsg->commitTime = htonl((int32_t)pCreateDb->commitTime); - pMsg->minRows = htonl(pCreateDb->minRowsPerBlock); - pMsg->maxRows = htonl(pCreateDb->maxRowsPerBlock); - pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod); - pMsg->compression = pCreateDb->compressionLevel; - pMsg->walLevel = (char)pCreateDb->walLevel; - pMsg->replications = pCreateDb->replica; - pMsg->quorum = pCreateDb->quorum; - pMsg->ignoreExist = pCreateDb->ignoreExists; - pMsg->update = pCreateDb->update; - pMsg->cacheLastRow = pCreateDb->cachelast; + pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks); + pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); + pMsg->commitTime = htonl((int32_t)pCreateDb->commitTime); + pMsg->minRows = htonl(pCreateDb->minRowsPerBlock); + pMsg->maxRows = htonl(pCreateDb->maxRowsPerBlock); + pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod); + pMsg->compression = (int8_t) pCreateDb->compressionLevel; + pMsg->walLevel = (char)pCreateDb->walLevel; + pMsg->replications = pCreateDb->replica; + pMsg->quorum = pCreateDb->quorum; + pMsg->ignoreExist = pCreateDb->ignoreExists; + pMsg->update = pCreateDb->update; + pMsg->cacheLastRow = pCreateDb->cachelast; + pMsg->numOfVgroups = htonl(pCreateDb->numOfVgroups); } int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) { @@ -202,8 +208,6 @@ int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbS return TSDB_CODE_TSC_INVALID_OPERATION; } - // todo configurable - pCreateDbMsg->numOfVgroups = htonl(2); return TSDB_CODE_SUCCESS; } @@ -227,45 +231,6 @@ SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCt return pCreateMsg; } -int32_t createSName(SName* pName, SToken* pTableName, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { - const char* msg1 = "name too long"; - const char* msg2 = "acctId too long"; - - int32_t code = TSDB_CODE_SUCCESS; - char* p = strnchr(pTableName->z, TS_PATH_DELIMITER[0], pTableName->n, false); - - if (p != NULL) { // db has been specified in sql string so we ignore current db path - code = tNameSetAcctId(pName, pParseCtx->acctId); - if (code != 0) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - char name[TSDB_TABLE_FNAME_LEN] = {0}; - strncpy(name, pTableName->z, pTableName->n); - - code = tNameFromString(pName, name, T_NAME_DB|T_NAME_TABLE); - if (code != 0) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - } else { // get current DB name first, and then set it into path - if (pTableName->n >= TSDB_TABLE_NAME_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - tNameSetDbName(pName, pParseCtx->acctId, pParseCtx->db, strlen(pParseCtx->db)); - - char name[TSDB_TABLE_FNAME_LEN] = {0}; - strncpy(name, pTableName->z, pTableName->n); - - code = tNameFromString(pName, name, T_NAME_TABLE); - if (code != 0) { - code = buildInvalidOperationMsg(pMsgBuf, msg1); - } - } - - return code; -} - SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { SSchema* pSchema; @@ -350,7 +315,7 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le return pCreateTableMsg; } -SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { +SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0); SName name = {0}; @@ -360,13 +325,77 @@ SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* return NULL; } - SDropTableMsg *pDropTableMsg = (SDropTableMsg*) calloc(1, sizeof(SDropTableMsg)); + SDropStbMsg *pDropTableMsg = (SDropStbMsg*) calloc(1, sizeof(SDropStbMsg)); code = tNameExtractFullName(&name, pDropTableMsg->name); assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T); - pDropTableMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; + pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; *len = sizeof(SDropTableMsg); return pDropTableMsg; } +SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { + const char* msg1 = "invalid host name (name too long, maximum length 128)"; + const char* msg2 = "dnode name can not be string"; + const char* msg3 = "port should be an integer that is less than 65535"; + const char* msg4 = "failed prepare create dnode message"; + + if (taosArrayGetSize(pInfo->pMiscInfo->a) != 2) { + buildInvalidOperationMsg(pMsgBuf, msg1); + return NULL; + } + + SToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0); + if (id->type != TK_ID && id->type != TK_IPTOKEN) { + buildInvalidOperationMsg(pMsgBuf, msg2); + return NULL; + } + + SToken* port = taosArrayGet(pInfo->pMiscInfo->a, 1); + if (port->type != TK_INTEGER) { + buildInvalidOperationMsg(pMsgBuf, msg3); + return NULL; + } + + bool isSign = false; + int64_t val = 0; + + toInteger(port->z, port->n, 10, &val, &isSign); + if (val >= UINT16_MAX) { + buildInvalidOperationMsg(pMsgBuf, msg3); + return NULL; + } + + SCreateDnodeMsg *pCreate = (SCreateDnodeMsg *) calloc(1, sizeof(SCreateDnodeMsg)); + if (pCreate == NULL) { + buildInvalidOperationMsg(pMsgBuf, msg4); + return NULL; + } + + strncpy(pCreate->fqdn, id->z, id->n); + pCreate->port = htonl(val); + + *len = sizeof(SCreateDnodeMsg); + return pCreate; +} + +SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { + SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0); + + + char* end = NULL; + SDropDnodeMsg * pDrop = (SDropDnodeMsg *)calloc(1, sizeof(SDropDnodeMsg)); + pDrop->dnodeId = strtoll(pzName->z, &end, 10); + pDrop->dnodeId = htonl(pDrop->dnodeId); + *len = sizeof(SDropDnodeMsg); + + if (end - pzName->z != pzName->n) { + buildInvalidOperationMsg(pMsgBuf, "invalid dnode id"); + tfree(pDrop); + return NULL; + } + + return pDrop; +} + diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index 5d64323332b220be624132bc61513a0db3e0f72d..b2466fd2dcccb2938ef060991c2696f29916ccf2 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -3986,7 +3986,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer return buildInvalidOperationMsg(pMsgBuf, "not support sql expression"); } - SCatalogReq req = {0}; SMetaData data = {0}; @@ -4023,508 +4022,5 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer validateSqlNode(p, pQueryInfo, &buf); } - - return code; -} - -// todo remove it -static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, void** output, int32_t* outputLen, SMsgBuf* pMsgBuf) { - const char* msg1 = "invalid name"; - const char* msg2 = "wildcard string should be less than %d characters"; - const char* msg3 = "database name too long"; - const char* msg4 = "pattern is invalid"; - const char* msg5 = "database name is empty"; - const char* msg6 = "pattern string is empty"; - - /* - * database prefix in pInfo->pMiscInfo->a[0] - * wildcard in like clause in pInfo->pMiscInfo->a[1] - */ - int16_t showType = pShowInfo->showType; - if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP) { - SToken* pDbPrefixToken = &pShowInfo->prefix; - if (pDbPrefixToken->type != 0) { - if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - - if (pDbPrefixToken->n <= 0) { - return buildInvalidOperationMsg(pMsgBuf, msg5); - } - - if (parserValidateIdToken(pDbPrefixToken) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - // int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pRequest->pTsc), pDbPrefixToken); - // if (ret != TSDB_CODE_SUCCESS) { - // return buildInvalidOperationMsg(pMsgBuf, msg1); - // } - } - - // show table/stable like 'xxxx', set the like pattern for show tables - SToken* pPattern = &pShowInfo->pattern; - if (pPattern->type != 0) { - if (pPattern->type == TK_ID && pPattern->z[0] == TS_ESCAPE_CHAR) { - return buildInvalidOperationMsg(pMsgBuf, msg4); - } - - pPattern->n = strdequote(pPattern->z); - if (pPattern->n <= 0) { - return buildInvalidOperationMsg(pMsgBuf, msg6); - } - - if (pPattern->n > tsMaxWildCardsLen) { - char tmp[64] = {0}; - sprintf(tmp, msg2, tsMaxWildCardsLen); - return buildInvalidOperationMsg(pMsgBuf, tmp); - } - } - } else if (showType == TSDB_MGMT_TABLE_VNODES) { - if (pShowInfo->prefix.type == 0) { - return buildInvalidOperationMsg(pMsgBuf, "No specified dnode ep"); - } - - if (pShowInfo->prefix.type == TK_STRING) { - pShowInfo->prefix.n = strdequote(pShowInfo->prefix.z); - } - } - - *output = buildShowMsg(pShowInfo, pCtx->requestId, pMsgBuf->buf, pMsgBuf->len); - *outputLen = sizeof(SShowMsg)/* + htons(pShowMsg->payloadLen)*/; - return TSDB_CODE_SUCCESS; -} - -// can only perform the parameters based on the macro definitation -static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) { - char msg[512] = {0}; - - if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) { - snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - if (pCreate->replications != -1 && - (pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) { - snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, - TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - int32_t blocks = ntohl(pCreate->totalBlocks); - if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) { - snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks, - TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - if (pCreate->quorum != -1 && - (pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) { - snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum, - TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - int32_t val = htonl(pCreate->daysPerFile); - if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) { - snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, - TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - val = htonl(pCreate->cacheBlockSize); - if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) { - snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, - TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO && - pCreate->precision != TSDB_TIME_PRECISION_NANO) { - snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision, - TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - val = htonl(pCreate->commitTime); - if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) { - snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, - TSDB_MIN_COMMIT_TIME, TSDB_MAX_COMMIT_TIME); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - val = htonl(pCreate->fsyncPeriod); - if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) { - snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, - TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - if (pCreate->compression != -1 && - (pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) { - snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, - TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - return TSDB_CODE_SUCCESS; -} - -/* is contained in pFieldList or not */ -static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { - size_t numOfCols = taosArrayGetSize(pFieldList); - for (int32_t j = startIndex; j < numOfCols; ++j) { - TAOS_FIELD* field = taosArrayGet(pFieldList, j); - if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true; - } - - return false; -} - -static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, int32_t maxColumns, SMsgBuf* pMsgBuf) { - const char* msg2 = "row length exceeds max length"; - const char* msg3 = "duplicated column names"; - const char* msg4 = "invalid data type"; - const char* msg5 = "invalid binary/nchar column length"; - const char* msg6 = "invalid column name"; - const char* msg7 = "too many columns"; - const char* msg8 = "illegal number of columns"; - - size_t numOfCols = taosArrayGetSize(pFieldList); - if (numOfCols > maxColumns) { - return buildInvalidOperationMsg(pMsgBuf, msg7); - } - - int32_t rowLen = 0; - for (int32_t i = 0; i < numOfCols; ++i) { - TAOS_FIELD* pField = taosArrayGet(pFieldList, i); - if (!isValidDataType(pField->type)) { - return buildInvalidOperationMsg(pMsgBuf, msg4); - } - - if (pField->bytes == 0) { - return buildInvalidOperationMsg(pMsgBuf, msg5); - } - - if ((pField->type == TSDB_DATA_TYPE_BINARY && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_BINARY_LEN)) || - (pField->type == TSDB_DATA_TYPE_NCHAR && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_NCHAR_LEN))) { - return buildInvalidOperationMsg(pMsgBuf, msg5); - } - - SToken nameToken = {.z = pField->name, .n = strlen(pField->name), .type = TK_ID}; - if (parserValidateNameToken(&nameToken) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg6); - } - - // field name must be unique - if (has(pFieldList, i + 1, pField->name) == true) { - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - - rowLen += pField->bytes; - } - - // max row length must be less than TSDB_MAX_BYTES_PER_ROW - if (rowLen > maxRowLength) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { - assert(pFieldList != NULL); - - const char* msg1 = "first column must be timestamp"; - const char* msg2 = "row length exceeds max length"; - const char* msg3 = "duplicated column names"; - const char* msg4 = "invalid data type"; - const char* msg5 = "invalid binary/nchar column length"; - const char* msg6 = "invalid column name"; - const char* msg7 = "too many columns"; - const char* msg8 = "illegal number of columns"; - - // first column must be timestamp - SField* pField = taosArrayGet(pFieldList, 0); - if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - // number of fields no less than 2 - size_t numOfCols = taosArrayGetSize(pFieldList); - if (numOfCols <= 1) { - return buildInvalidOperationMsg(pMsgBuf, msg8); - } - - return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf); -} - -static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* pMsgBuf) { - assert(pTagsList != NULL); - - const char* msg1 = "invalid number of tag columns"; - const char* msg3 = "duplicated column names"; - - // number of fields at least 1 - size_t numOfTags = taosArrayGetSize(pTagsList); - if (numOfTags < 1) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - // field name must be unique - for (int32_t i = 0; i < numOfTags; ++i) { - SField* p = taosArrayGet(pTagsList, i); - if (has(pFieldList, 0, p->name) == true) { - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - } - - return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf); -} - -int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { - const char* msg1 = "invalid table name"; - - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - - SArray* pFieldList = pCreateTable->colInfo.pColumns; - SArray* pTagList = pCreateTable->colInfo.pTagColumns; - assert(pFieldList != NULL); - - // if sql specifies db, use it, otherwise use default db - SToken* pzTableName = &(pCreateTable->name); - - if (parserValidateNameToken(pzTableName) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - if (validateTableColumnInfo(pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS || - (pTagList != NULL && validateTagParams(pTagList, pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - return TSDB_CODE_SUCCESS; -} - -int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, int32_t msgBufLen) { - int32_t code = 0; - - SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; - SMsgBuf *pMsgBuf = &m; - - switch (pInfo->type) { - case TSDB_SQL_CREATE_USER: - case TSDB_SQL_ALTER_USER: { - const char* msg1 = "not support options"; - const char* msg2 = "invalid user/account name"; - const char* msg3 = "name too long"; - const char* msg4 = "invalid user rights"; - - SUserInfo* pUser = &pInfo->pMiscInfo->user; - SToken* pName = &pUser->user; - SToken* pPwd = &pUser->passwd; - - if (pName->n >= TSDB_USER_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - - if (parserValidateIdToken(pName) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - if (pInfo->type == TSDB_SQL_CREATE_USER) { - if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } else { - if (pUser->type == TSDB_ALTER_USER_PASSWD) { - if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - assert(pPwd->type == TSDB_DATA_TYPE_NULL); - - SToken* pPrivilege = &pUser->privilege; - if (strncasecmp(pPrivilege->z, "super", 5) == 0 && pPrivilege->n == 5) { - // pCmd->count = 1; - } else if (strncasecmp(pPrivilege->z, "normal", 4) == 0 && pPrivilege->n == 4) { - // pCmd->count = 2; - } else { - return buildInvalidOperationMsg(pMsgBuf, msg4); - } - } else { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - } - - pDcl->pMsg = (char*)buildUserManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER)? TSDB_MSG_TYPE_CREATE_USER:TSDB_MSG_TYPE_ALTER_USER; - break; - } - - case TSDB_SQL_CREATE_ACCT: - case TSDB_SQL_ALTER_ACCT: { - const char* msg1 = "invalid state option, available options[no, r, w, all]"; - const char* msg2 = "invalid user/account name"; - const char* msg3 = "name too long"; - - SToken* pName = &pInfo->pMiscInfo->user.user; - SToken* pPwd = &pInfo->pMiscInfo->user.passwd; - - if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - if (pName->n >= TSDB_USER_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - - if (parserValidateNameToken(pName) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt; - if (pAcctOpt->stat.n > 0) { - if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { - } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { - } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { - } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { - } else { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - } - - pDcl->pMsg = (char*)buildAcctManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT)? TSDB_MSG_TYPE_CREATE_ACCT:TSDB_MSG_TYPE_ALTER_ACCT; - break; - } - - case TSDB_SQL_DROP_ACCT: - case TSDB_SQL_DROP_USER: { - pDcl->pMsg = (char*)buildDropUserMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); - pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT)? TSDB_MSG_TYPE_DROP_ACCT:TSDB_MSG_TYPE_DROP_USER; - break; - } - - case TSDB_SQL_SHOW: { - code = setShowInfo(&pInfo->pMiscInfo->showOpt, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, pMsgBuf); - pDcl->msgType = TSDB_MSG_TYPE_SHOW; - break; - } - - case TSDB_SQL_USE_DB: { - const char* msg = "invalid db name"; - - SToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0); - if (parserValidateNameToken(pToken) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - SName n = {0}; - int32_t ret = tNameSetDbName(&n, pCtx->acctId, pToken->z, pToken->n); - if (ret != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg); - } - - SUseDbMsg *pUseDbMsg = (SUseDbMsg *) calloc(1, sizeof(SUseDbMsg)); - tNameExtractFullName(&n, pUseDbMsg->db); - - pDcl->pMsg = (char*)pUseDbMsg; - pDcl->msgLen = sizeof(SUseDbMsg); - pDcl->msgType = TSDB_MSG_TYPE_USE_DB; - break; - } - - case TSDB_SQL_ALTER_DB: - case TSDB_SQL_CREATE_DB: { - const char* msg1 = "invalid db name"; - const char* msg2 = "name too long"; - - SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); - if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg2); - } - - char buf[TSDB_DB_NAME_LEN] = {0}; - SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); - - if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pCtx, pMsgBuf); - if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - strncpy(pCreateMsg->db, token.z, token.n); - - pDcl->pMsg = (char*)pCreateMsg; - pDcl->msgLen = sizeof(SCreateDbMsg); - pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB)? TSDB_MSG_TYPE_CREATE_DB:TSDB_MSG_TYPE_ALTER_DB; - break; - } - - case TSDB_SQL_DROP_DB: { - const char* msg1 = "invalid database name"; - - assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1); - SToken* dbName = taosArrayGet(pInfo->pMiscInfo->a, 0); - - SName name = {0}; - code = tNameSetDbName(&name, pCtx->acctId, dbName->z, dbName->n); - if (code != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); - } - - SDropDbMsg *pDropDbMsg = (SDropDbMsg*) calloc(1, sizeof(SDropDbMsg)); - - code = tNameExtractFullName(&name, pDropDbMsg->db); - pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T); - - pDcl->msgType = TSDB_MSG_TYPE_DROP_DB; - pDcl->msgLen = sizeof(SDropDbMsg); - pDcl->pMsg = (char*)pDropDbMsg; - return TSDB_CODE_SUCCESS; - } - - case TSDB_SQL_CREATE_TABLE: { - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - - if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { - if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { - return code; - } - pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); - pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE)? TSDB_MSG_TYPE_CREATE_TABLE:TSDB_MSG_TYPE_CREATE_STB; - } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { - // if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { - // return code; - // } - - } else if (pCreateTable->type == TSQL_CREATE_STREAM) { - // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { - // return code; - } - - break; - } - - case TSDB_SQL_DROP_TABLE: { - pDcl->pMsg = (char*)buildDropTableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); - if (pDcl->pMsg == NULL) { - return terrno; - } - - pDcl->msgType = TSDB_MSG_TYPE_DROP_STB; - return TSDB_CODE_SUCCESS; - break; - } - - default: - break; - } - return code; } diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c new file mode 100644 index 0000000000000000000000000000000000000000..8a09ea9ed8a22aa2a22778562c846618d7db1868 --- /dev/null +++ b/source/libs/parser/src/dCDAstProcess.c @@ -0,0 +1,763 @@ +#include +#include +#include "astToMsg.h" +#include "parserInt.h" +#include "parserUtil.h" +#include "queryInfoUtil.h" +#include "tglobal.h" + +/* is contained in pFieldList or not */ +static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { + size_t numOfCols = taosArrayGetSize(pFieldList); + for (int32_t j = startIndex; j < numOfCols; ++j) { + TAOS_FIELD* field = taosArrayGet(pFieldList, j); + if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true; + } + + return false; +} + +static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** output, int32_t* outputLen, + SEpSet* pEpSet, SMsgBuf* pMsgBuf) { + const char* msg1 = "invalid name"; + const char* msg2 = "wildcard string should be less than %d characters"; + const char* msg3 = "database name too long"; + const char* msg4 = "pattern is invalid"; + const char* msg5 = "database name is empty"; + const char* msg6 = "pattern string is empty"; + + /* + * database prefix in pInfo->pMiscInfo->a[0] + * wildcard in like clause in pInfo->pMiscInfo->a[1] + */ + int16_t showType = pShowInfo->showType; + if (showType == TSDB_MGMT_TABLE_TABLE) { + SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); + *pEpSet = pCtx->mgmtEpSet; + + // catalogGetDBVgroupVersion() + pShowReq->head.vgId = htonl(13); + *outputLen = sizeof(SVShowTablesReq); + *output = pShowReq; + } else { + if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP) { + SToken* pDbPrefixToken = &pShowInfo->prefix; + if (pDbPrefixToken->type != 0) { + if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + + if (pDbPrefixToken->n <= 0) { + return buildInvalidOperationMsg(pMsgBuf, msg5); + } + + if (parserValidateIdToken(pDbPrefixToken) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + // int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pRequest->pTsc), pDbPrefixToken); + // if (ret != TSDB_CODE_SUCCESS) { + // return buildInvalidOperationMsg(pMsgBuf, msg1); + // } + } + + // show table/stable like 'xxxx', set the like pattern for show tables + SToken* pPattern = &pShowInfo->pattern; + if (pPattern->type != 0) { + if (pPattern->type == TK_ID && pPattern->z[0] == TS_ESCAPE_CHAR) { + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + + pPattern->n = strdequote(pPattern->z); + if (pPattern->n <= 0) { + return buildInvalidOperationMsg(pMsgBuf, msg6); + } + + if (pPattern->n > tsMaxWildCardsLen) { + char tmp[64] = {0}; + sprintf(tmp, msg2, tsMaxWildCardsLen); + return buildInvalidOperationMsg(pMsgBuf, tmp); + } + } + } else if (showType == TSDB_MGMT_TABLE_VNODES) { + if (pShowInfo->prefix.type == 0) { + return buildInvalidOperationMsg(pMsgBuf, "No specified dnode ep"); + } + + if (pShowInfo->prefix.type == TK_STRING) { + pShowInfo->prefix.n = strdequote(pShowInfo->prefix.z); + } + } + + *pEpSet = pCtx->mgmtEpSet; + *output = buildShowMsg(pShowInfo, pCtx, pMsgBuf->buf, pMsgBuf->len); + *outputLen = sizeof(SShowMsg) /* + htons(pShowMsg->payloadLen)*/; + } + + return TSDB_CODE_SUCCESS; +} + +// can only perform the parameters based on the macro definitation +static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) { + char msg[512] = {0}; + + if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) { + snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->replications != -1 && + (pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) { + snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, + TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + int32_t blocks = ntohl(pCreate->totalBlocks); + if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) { + snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks, + TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->quorum != -1 && + (pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) { + snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum, + TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + int32_t val = htonl(pCreate->daysPerFile); + if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) { + snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, TSDB_MIN_DAYS_PER_FILE, + TSDB_MAX_DAYS_PER_FILE); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->cacheBlockSize); + if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) { + snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, + TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO && + pCreate->precision != TSDB_TIME_PRECISION_NANO) { + snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision, + TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->commitTime); + if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) { + snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, TSDB_MIN_COMMIT_TIME, + TSDB_MAX_COMMIT_TIME); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->fsyncPeriod); + if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) { + snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, TSDB_MIN_FSYNC_PERIOD, + TSDB_MAX_FSYNC_PERIOD); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + if (pCreate->compression != -1 && + (pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) { + snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, + TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + val = htonl(pCreate->numOfVgroups); + if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) { + snprintf(msg, tListLen(msg), "invalid number of vgroups for DB:%d valid range: [%d, %d]", val, + TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, int32_t maxColumns, SMsgBuf* pMsgBuf) { + const char* msg2 = "row length exceeds max length"; + const char* msg3 = "duplicated column names"; + const char* msg4 = "invalid data type"; + const char* msg5 = "invalid binary/nchar column length"; + const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; + const char* msg8 = "illegal number of columns"; + + size_t numOfCols = taosArrayGetSize(pFieldList); + if (numOfCols > maxColumns) { + return buildInvalidOperationMsg(pMsgBuf, msg7); + } + + int32_t rowLen = 0; + for (int32_t i = 0; i < numOfCols; ++i) { + TAOS_FIELD* pField = taosArrayGet(pFieldList, i); + if (!isValidDataType(pField->type)) { + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + + if (pField->bytes == 0) { + return buildInvalidOperationMsg(pMsgBuf, msg5); + } + + if ((pField->type == TSDB_DATA_TYPE_BINARY && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_BINARY_LEN)) || + (pField->type == TSDB_DATA_TYPE_NCHAR && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_NCHAR_LEN))) { + return buildInvalidOperationMsg(pMsgBuf, msg5); + } + + SToken nameToken = {.z = pField->name, .n = strlen(pField->name), .type = TK_ID}; + if (parserValidateNameToken(&nameToken) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg6); + } + + // field name must be unique + if (has(pFieldList, i + 1, pField->name) == true) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + + rowLen += pField->bytes; + } + + // max row length must be less than TSDB_MAX_BYTES_PER_ROW + if (rowLen > maxRowLength) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { + assert(pFieldList != NULL); + + const char* msg1 = "first column must be timestamp"; + const char* msg2 = "row length exceeds max length"; + const char* msg3 = "duplicated column names"; + const char* msg4 = "invalid data type"; + const char* msg5 = "invalid binary/nchar column length"; + const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; + const char* msg8 = "illegal number of columns"; + + // first column must be timestamp + SField* pField = taosArrayGet(pFieldList, 0); + if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + // number of fields no less than 2 + size_t numOfCols = taosArrayGetSize(pFieldList); + if (numOfCols <= 1) { + return buildInvalidOperationMsg(pMsgBuf, msg8); + } + + return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf); +} + +static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* pMsgBuf) { + assert(pTagsList != NULL); + + const char* msg1 = "invalid number of tag columns"; + const char* msg3 = "duplicated column names"; + + // number of fields at least 1 + size_t numOfTags = taosArrayGetSize(pTagsList); + if (numOfTags < 1) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + // field name must be unique + for (int32_t i = 0; i < numOfTags; ++i) { + SField* p = taosArrayGet(pTagsList, i); + if (has(pFieldList, 0, p->name) == true) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + } + + return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf); +} + +int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { + const char* msg1 = "invalid table name"; + + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + + SArray* pFieldList = pCreateTable->colInfo.pColumns; + SArray* pTagList = pCreateTable->colInfo.pTagColumns; + assert(pFieldList != NULL); + + // if sql specifies db, use it, otherwise use default db + SToken* pzTableName = &(pCreateTable->name); + + if (parserValidateNameToken(pzTableName) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + if (validateTableColumnInfo(pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS || + (pTagList != NULL && validateTagParams(pTagList, pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len, + SEpSet* pEpSet) { + const char* msg1 = "invalid table name"; + const char* msg2 = "tags number not matched"; + const char* msg3 = "tag value too long"; + const char* msg4 = "illegal value or data overflow"; + + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + + // super table name, create table by using dst + int32_t numOfTables = (int32_t)taosArrayGetSize(pCreateTable->childTableInfo); + for (int32_t j = 0; j < numOfTables; ++j) { + SCreatedTableInfo* pCreateTableInfo = taosArrayGet(pCreateTable->childTableInfo, j); + + SToken* pSTableNameToken = &pCreateTableInfo->stbName; + + char buf[TSDB_TABLE_FNAME_LEN]; + SToken sTblToken; + sTblToken.z = buf; + + int32_t code = parserValidateNameToken(pSTableNameToken); + if (code != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + SName name = {0}; + code = createSName(&name, pSTableNameToken, pCtx, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + SArray* pValList = pCreateTableInfo->pTagVals; + + size_t numOfInputTag = taosArrayGetSize(pValList); + STableMeta* pSuperTableMeta = NULL; + + catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); + assert(pSuperTableMeta != NULL); + + // too long tag values will return invalid sql, not be truncated automatically + SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); + STableComInfo tinfo = getTableInfo(pSuperTableMeta); + STagData* pTag = &pCreateTableInfo->tagdata; + + SKVRowBuilder kvRowBuilder = {0}; + if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + SArray* pNameList = NULL; + size_t nameSize = 0; + int32_t schemaSize = getNumOfTags(pSuperTableMeta); + + if (pCreateTableInfo->pTagNames) { + pNameList = pCreateTableInfo->pTagNames; + nameSize = taosArrayGetSize(pNameList); + + if (numOfInputTag != nameSize || schemaSize < numOfInputTag) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + bool findColumnIndex = false; + for (int32_t i = 0; i < nameSize; ++i) { + SToken* sToken = taosArrayGet(pNameList, i); + + char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // create tmp buf to avoid alter orginal sqlstr + strncpy(tmpTokenBuf, sToken->z, sToken->n); + sToken->z = tmpTokenBuf; + + // if (TK_STRING == sToken->type) { + // tscDequoteAndTrimToken(sToken); + // } + + // if (TK_ID == sToken->type) { + // tscRmEscapeAndTrimToken(sToken); + // } + + SListItem* pItem = taosArrayGet(pValList, i); + + findColumnIndex = false; + + // todo speedup by using hash list + for (int32_t t = 0; t < schemaSize; ++t) { + if (strncmp(sToken->z, pTagSchema[t].name, sToken->n) == 0 && strlen(pTagSchema[t].name) == sToken->n) { + SSchema* pSchema = &pTagSchema[t]; + + char tagVal[TSDB_MAX_TAGS_LEN] = {0}; + if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { + if (pItem->pVar.nLen > pSchema->bytes) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { + if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { + // code = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision); + // if (code != TSDB_CODE_SUCCESS) { + // return buildInvalidOperationMsg(pMsgBuf, msg4); + // } + } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { + pItem->pVar.i = convertTimePrecision(pItem->pVar.i, TSDB_TIME_PRECISION_NANO, tinfo.precision); + } + } + + code = taosVariantDump(&(pItem->pVar), tagVal, pSchema->type, true); + + // check again after the convert since it may be converted from binary to nchar. + if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { + int16_t len = varDataTLen(tagVal); + if (len > pSchema->bytes) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + } + + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + + tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal); + + findColumnIndex = true; + break; + } + } + + if (!findColumnIndex) { + tdDestroyKVRowBuilder(&kvRowBuilder); + // return buildInvalidOperationMsg(pMsgBuf, "invalid tag name", sToken->z); + } + } + } else { + if (schemaSize != numOfInputTag) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + for (int32_t i = 0; i < numOfInputTag; ++i) { + SSchema* pSchema = &pTagSchema[i]; + SToken* pItem = taosArrayGet(pValList, i); + + if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { + if (pItem->n > pSchema->bytes) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { + // if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { + //// code = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision); + // if (code != TSDB_CODE_SUCCESS) { + // return buildInvalidOperationMsg(pMsgBuf, msg4); + // } + // } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { + // pItem->pVar.i = convertTimePrecision(pItem->pVar.i, TSDB_TIME_PRECISION_NANO, tinfo.precision); + // } + } + + char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; + SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; + + char* endPtr = NULL; + code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); + + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(&kvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + } + } + + SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); + tdDestroyKVRowBuilder(&kvRowBuilder); + if (row == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + tdSortKVRowByColIdx(row); + + SName tableName = {0}; + code = createSName(&tableName, &pCreateTableInfo->name, pCtx, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + struct SVCreateTbReq req = {0}; + req.type = TD_CHILD_TABLE; + req.name = strdup(tNameGetTableName(&tableName)); + req.ctbCfg.suid = pSuperTableMeta->suid; + req.ctbCfg.pTag = row; + + int32_t serLen = sizeof(SMsgHead) + tSerializeSVCreateTbReq(NULL, &req); + char* buf1 = calloc(1, serLen); + *pOutput = buf1; + buf1 += sizeof(SMsgHead); + tSerializeSVCreateTbReq((void*)&buf1, &req); + *len = serLen; + + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); + + pEpSet->inUse = info.inUse; + pEpSet->numOfEps = info.numOfEps; + for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { + pEpSet->port[i] = info.epAddr[i].port; + tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); + } + + ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); + ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, + int32_t msgBufLen) { + int32_t code = 0; + + SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; + SMsgBuf* pMsgBuf = &m; + + switch (pInfo->type) { + case TSDB_SQL_CREATE_USER: + case TSDB_SQL_ALTER_USER: { + const char* msg1 = "not support options"; + const char* msg2 = "invalid user/account name"; + const char* msg3 = "name too long"; + const char* msg4 = "invalid user rights"; + + SUserInfo* pUser = &pInfo->pMiscInfo->user; + SToken* pName = &pUser->user; + SToken* pPwd = &pUser->passwd; + + if (pName->n >= TSDB_USER_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + + if (parserValidateIdToken(pName) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + if (pInfo->type == TSDB_SQL_CREATE_USER) { + if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + } else { + if (pUser->type == TSDB_ALTER_USER_PASSWD) { + if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { + assert(pPwd->type == TSDB_DATA_TYPE_NULL); + + SToken* pPrivilege = &pUser->privilege; + if (strncasecmp(pPrivilege->z, "super", 5) == 0 && pPrivilege->n == 5) { + // pCmd->count = 1; + } else if (strncasecmp(pPrivilege->z, "normal", 4) == 0 && pPrivilege->n == 4) { + // pCmd->count = 2; + } else { + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + } else { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + pDcl->pMsg = (char*)buildUserManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER) ? TDMT_MND_CREATE_USER : TDMT_MND_ALTER_USER; + break; + } + + case TSDB_SQL_CREATE_ACCT: + case TSDB_SQL_ALTER_ACCT: { + const char* msg1 = "invalid state option, available options[no, r, w, all]"; + const char* msg2 = "invalid user/account name"; + const char* msg3 = "name too long"; + + SToken* pName = &pInfo->pMiscInfo->user.user; + SToken* pPwd = &pInfo->pMiscInfo->user.passwd; + + if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + if (pName->n >= TSDB_USER_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + + if (parserValidateNameToken(pName) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt; + if (pAcctOpt->stat.n > 0) { + if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { + } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { + } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { + } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { + } else { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + pDcl->pMsg = (char*)buildAcctManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT) ? TDMT_MND_CREATE_ACCT : TDMT_MND_ALTER_ACCT; + break; + } + + case TSDB_SQL_DROP_ACCT: + case TSDB_SQL_DROP_USER: { + pDcl->pMsg = (char*)buildDropUserMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT) ? TDMT_MND_DROP_ACCT : TDMT_MND_DROP_USER; + break; + } + + case TSDB_SQL_SHOW: { + SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; + code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, pMsgBuf); + pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE)? TDMT_VND_SHOW_TABLES:TDMT_MND_SHOW; + break; + } + + case TSDB_SQL_USE_DB: { + const char* msg = "invalid db name"; + + SToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0); + if (parserValidateNameToken(pToken) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + SName n = {0}; + int32_t ret = tNameSetDbName(&n, pCtx->acctId, pToken->z, pToken->n); + if (ret != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + SUseDbMsg* pUseDbMsg = (SUseDbMsg*)calloc(1, sizeof(SUseDbMsg)); + tNameExtractFullName(&n, pUseDbMsg->db); + + pDcl->pMsg = (char*)pUseDbMsg; + pDcl->msgLen = sizeof(SUseDbMsg); + pDcl->msgType = TDMT_MND_USE_DB; + break; + } + + case TSDB_SQL_ALTER_DB: + case TSDB_SQL_CREATE_DB: { + const char* msg1 = "invalid db name"; + const char* msg2 = "name too long"; + + SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); + if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + char buf[TSDB_DB_NAME_LEN] = {0}; + SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); + + if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pCtx, pMsgBuf); + if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + pDcl->pMsg = (char*)pCreateMsg; + pDcl->msgLen = sizeof(SCreateDbMsg); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB) ? TDMT_MND_CREATE_DB : TDMT_MND_ALTER_DB; + break; + } + + case TSDB_SQL_DROP_DB: { + const char* msg1 = "invalid database name"; + + assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1); + SToken* dbName = taosArrayGet(pInfo->pMiscInfo->a, 0); + + SName name = {0}; + code = tNameSetDbName(&name, pCtx->acctId, dbName->z, dbName->n); + if (code != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + SDropDbMsg* pDropDbMsg = (SDropDbMsg*)calloc(1, sizeof(SDropDbMsg)); + + code = tNameExtractFullName(&name, pDropDbMsg->db); + pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; + assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T); + + pDcl->msgType = TDMT_MND_DROP_DB; + pDcl->msgLen = sizeof(SDropDbMsg); + pDcl->pMsg = (char*)pDropDbMsg; + return TSDB_CODE_SUCCESS; + } + + case TSDB_SQL_CREATE_TABLE: { + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + + if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { + if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { + return code; + } + pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; + } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { + if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet)) != + TSDB_CODE_SUCCESS) { + return code; + } + + pDcl->msgType = TDMT_VND_CREATE_TABLE; + } else if (pCreateTable->type == TSQL_CREATE_STREAM) { + // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + // return code; + } + + break; + } + + case TSDB_SQL_DROP_TABLE: { + pDcl->pMsg = (char*)buildDropStableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); + if (pDcl->pMsg == NULL) { + code = terrno; + } + + pDcl->msgType = TDMT_MND_DROP_STB; + break; + } + + case TSDB_SQL_CREATE_DNODE: { + pDcl->pMsg = (char*)buildCreateDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); + if (pDcl->pMsg == NULL) { + code = terrno; + } + + pDcl->msgType = TDMT_MND_CREATE_DNODE; + break; + } + + case TSDB_SQL_DROP_DNODE: { + pDcl->pMsg = (char*)buildDropDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); + if (pDcl->pMsg == NULL) { + code = terrno; + } + + pDcl->msgType = TDMT_MND_DROP_DNODE; + break; + } + + default: + break; + } + + return code; +} diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index 2f3d5aab77ecaea9bf30ab2113f6636bcee7e231..b315ea613f86f19d17cc2a32c5f24342b8f04caa 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -18,7 +18,7 @@ #include "catalog.h" #include "parserUtil.h" #include "queryInfoUtil.h" -#include "taosmsg.h" +#include "tmsg.h" #define IS_RAW_PAYLOAD(t) \ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index fb7790452d8ddbbc447c7d9b3753ef094e086808..66966f75db59f9e01a710b7429312bfc5d911e8a 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -51,8 +51,8 @@ enum { typedef struct SInsertParseContext { SParseContext* pComCxt; // input - const char* pSql; // input - SMsgBuf msg; // input + char *pSql; // input + SMsgBuf msg; // input STableMeta* pTableMeta; // each table SParsedDataColInfo tags; // each table SKVRowBuilder tagsBuilder; // each table @@ -64,80 +64,6 @@ typedef struct SInsertParseContext { SInsertStmtInfo* pOutput; } SInsertParseContext; -typedef int32_t (*FRowAppend)(const void *value, int32_t len, void *param); - -typedef struct SKvParam { - char buf[TSDB_MAX_TAGS_LEN]; - SKVRowBuilder* builder; - SSchema* schema; -} SKvParam; - -static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; -static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; - -static bool isNullStr(SToken *pToken) { - return (pToken->type == TK_NULL) || ((pToken->type == TK_STRING) && (pToken->n != 0) && - (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)); -} - -static FORCE_INLINE int32_t toDouble(SToken *pToken, double *value, char **endPtr) { - errno = 0; - *value = strtold(pToken->z, endPtr); - - // not a valid integer number, return error - if ((*endPtr - pToken->z) != pToken->n) { - return TK_ILLEGAL; - } - - return pToken->type; -} - -static int32_t toInt64(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) { - errno = 0; - int32_t ret = 0; - - char* endPtr = NULL; - if (type == TK_FLOAT) { - double v = strtod(z, &endPtr); - if ((errno == ERANGE && v == HUGE_VALF) || isinf(v) || isnan(v)) { - ret = -1; - } else if ((issigned && (v < INT64_MIN || v > INT64_MAX)) || ((!issigned) && (v < 0 || v > UINT64_MAX))) { - ret = -1; - } else { - *value = (int64_t) round(v); - } - - errno = 0; - return ret; - } - - int32_t radix = 10; - if (type == TK_HEX) { - radix = 16; - } else if (type == TK_BIN) { - radix = 2; - } - - // the string may be overflow according to errno - if (!issigned) { - const char *p = z; - while(*p != 0 && *p == ' ') p++; - if (*p != 0 && *p == '-') { return -1;} - - *value = strtoull(z, &endPtr, radix); - } else { - *value = strtoll(z, &endPtr, radix); - } - - // not a valid integer number, return error - if (endPtr - z != n || errno == ERANGE) { - ret = -1; - } - - errno = 0; - return ret; -} - static int32_t skipInsertInto(SInsertParseContext* pCxt) { SToken sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -162,7 +88,7 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD strncpy(fullDbName + n, pStname->z, p - pStname->z); strncpy(tableName, p + 1, pStname->n - (p - pStname->z) - 1); } else { - snprintf(fullDbName, TSDB_FULL_DB_NAME_LEN, "%d.%s", pCxt->pComCxt->ctx.acctId, pCxt->pComCxt->ctx.db); + snprintf(fullDbName, TSDB_DB_FNAME_LEN, "%d.%s", pCxt->pComCxt->ctx.acctId, pCxt->pComCxt->ctx.db); strncpy(tableName, pStname->z, pStname->n); } @@ -170,12 +96,15 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD } static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { - char fullDbName[TSDB_FULL_DB_NAME_LEN] = {0}; - char tableName[TSDB_TABLE_NAME_LEN] = {0}; - CHECK_CODE(buildName(pCxt, pTname, fullDbName, tableName)); - CHECK_CODE(catalogGetTableMeta(pCxt->pComCxt->pCatalog, pCxt->pComCxt->pRpc, pCxt->pComCxt->pEpSet, fullDbName, tableName, &pCxt->pTableMeta)); + SName name = {0}; + createSName(&name, pTname, &pCxt->pComCxt->ctx, &pCxt->msg); + + char tableName[TSDB_TABLE_FNAME_LEN] = {0}; + tNameExtractFullName(&name, tableName); + SParseBasicCtx* pBasicCtx = &pCxt->pComCxt->ctx; + CHECK_CODE(catalogGetTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta)); SVgroupInfo vg; - CHECK_CODE(catalogGetTableHashVgroup(pCxt->pComCxt->pCatalog, pCxt->pComCxt->pRpc, pCxt->pComCxt->pEpSet, fullDbName, tableName, &vg)); + CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); return TSDB_CODE_SUCCESS; } @@ -263,23 +192,21 @@ static int32_t checkTimestamp(STableDataBlocks *pDataBlocks, const char *start) return TSDB_CODE_SUCCESS; } -static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec, int64_t *time) { +static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time, SMsgBuf* pMsgBuf) { int32_t index = 0; - SToken sToken; + SToken sToken; int64_t interval; - int64_t useconds = 0; - const char* pTokenEnd = pCxt->pSql; + int64_t ts = 0; + char* pTokenEnd = *end; if (pToken->type == TK_NOW) { - useconds = taosGetTimestamp(timePrec); - } else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) { - // do nothing + ts = taosGetTimestamp(timePrec); } else if (pToken->type == TK_INTEGER) { - useconds = taosStr2int64(pToken->z); - } else { - // strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); + bool isSigned = false; + toInteger(pToken->z, pToken->n, 10, &ts, &isSigned); + } else { // parse the RFC-3339/ISO-8601 timestamp format string if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp format", pToken->z); + return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z); } return TSDB_CODE_SUCCESS; @@ -288,8 +215,8 @@ static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec for (int k = pToken->n; pToken->z[k] != '\0'; k++) { if (pToken->z[k] == ' ' || pToken->z[k] == '\t') continue; if (pToken->z[k] == ',') { - pCxt->pSql = pTokenEnd; - *time = useconds; + *end = pTokenEnd; + *time = ts; return 0; } @@ -311,7 +238,7 @@ static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec pTokenEnd += index; if (valueToken.n < 2) { - return buildSyntaxErrMsg(&pCxt->msg, "value expected in timestamp", sToken.z); + return buildSyntaxErrMsg(pMsgBuf, "value expected in timestamp", sToken.z); } char unit = 0; @@ -320,34 +247,15 @@ static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec } if (sToken.type == TK_PLUS) { - useconds += interval; + ts += interval; } else { - useconds = useconds - interval; + ts = ts - interval; } - pCxt->pSql = pTokenEnd; + *end = pTokenEnd; } - *time = useconds; - return TSDB_CODE_SUCCESS; -} - -static FORCE_INLINE int32_t KvRowAppend(const void *value, int32_t len, void *param) { - SKvParam* pa = (SKvParam*)param; - if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { - STR_WITH_SIZE_TO_VARSTR(pa->buf, value, len); - tdAddColToKVRow(pa->builder, pa->schema->colId, pa->schema->type, pa->buf); - } else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) { - // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' - int32_t output = 0; - if (!taosMbsToUcs4(value, len, varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) { - return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; - } - varDataSetLen(pa->buf, output); - tdAddColToKVRow(pa->builder, pa->schema->colId, pa->schema->type, pa->buf); - } else { - tdAddColToKVRow(pa->builder, pa->schema->colId, pa->schema->type, value); - } + *time = ts; return TSDB_CODE_SUCCESS; } @@ -381,194 +289,6 @@ static FORCE_INLINE int32_t MemRowAppend(const void *value, int32_t len, void *p return TSDB_CODE_SUCCESS; } -static FORCE_INLINE int32_t checkAndTrimValue(SInsertParseContext* pCxt, SToken* pToken, SSchema* pSchema, char* tmpTokenBuf) { - int16_t type = pToken->type; - if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && - type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || - (pToken->n == 0) || (type == TK_RP)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid data or symbol", pToken->z); - } - - if (IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid numeric data", pToken->z); - } - - // Remove quotation marks - if (TK_STRING == type) { - if (pToken->n >= TSDB_MAX_BYTES_PER_ROW) { - return buildSyntaxErrMsg(&pCxt->msg, "too long string", pToken->z); - } - // delete escape character: \\, \', \" - char delim = pToken->z[0]; - int32_t cnt = 0; - int32_t j = 0; - for (uint32_t k = 1; k < pToken->n - 1; ++k) { - if (pToken->z[k] == '\\' || (pToken->z[k] == delim && pToken->z[k + 1] == delim)) { - tmpTokenBuf[j] = pToken->z[k + 1]; - cnt++; - j++; - k++; - continue; - } - tmpTokenBuf[j] = pToken->z[k]; - j++; - } - tmpTokenBuf[j] = 0; - pToken->z = tmpTokenBuf; - pToken->n -= 2 + cnt; - } - - return TSDB_CODE_SUCCESS; -} - -static FORCE_INLINE int32_t parseOneValue(SInsertParseContext* pCxt, SToken* pToken, SSchema* pSchema, int16_t timePrec, char* tmpTokenBuf, FRowAppend func, void* param) { - int64_t iv; - int32_t ret; - char * endptr = NULL; - - CHECK_CODE(checkAndTrimValue(pCxt, pToken, pSchema, tmpTokenBuf)); - - if (isNullStr(pToken)) { - if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { - int64_t tmpVal = 0; - return func(&tmpVal, pSchema->bytes, param); - } - return func(getNullValue(pSchema->type), 0, param); - } - - switch (pSchema->type) { - case TSDB_DATA_TYPE_BOOL: { - if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) { - if (strncmp(pToken->z, "true", pToken->n) == 0) { - return func(&TRUE_VALUE, pSchema->bytes, param); - } else if (strncmp(pToken->z, "false", pToken->n) == 0) { - return func(&FALSE_VALUE, pSchema->bytes, param); - } else { - return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); - } - } else if (pToken->type == TK_INTEGER) { - return func(((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); - } else if (pToken->type == TK_FLOAT) { - return func(((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); - } else { - return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); - } - break; - } - case TSDB_DATA_TYPE_TINYINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, true)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid tinyint data", pToken->z); - } else if (!IS_VALID_TINYINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "data overflow", pToken->z); - } - uint8_t tmpVal = (uint8_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_UTINYINT:{ - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, false)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned tinyint data", pToken->z); - } else if (!IS_VALID_UTINYINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "unsigned tinyint data overflow", pToken->z); - } - uint8_t tmpVal = (uint8_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_SMALLINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, true)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid smallint data", pToken->z); - } else if (!IS_VALID_SMALLINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "smallint data overflow", pToken->z); - } - int16_t tmpVal = (int16_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_USMALLINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, false)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned smallint data", pToken->z); - } else if (!IS_VALID_USMALLINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "unsigned smallint data overflow", pToken->z); - } - uint16_t tmpVal = (uint16_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_INT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, true)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid int data", pToken->z); - } else if (!IS_VALID_INT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "int data overflow", pToken->z); - } - int32_t tmpVal = (int32_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_UINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, false)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned int data", pToken->z); - } else if (!IS_VALID_UINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "unsigned int data overflow", pToken->z); - } - uint32_t tmpVal = (uint32_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_BIGINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, true)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid bigint data", pToken->z); - } else if (!IS_VALID_BIGINT(iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "bigint data overflow", pToken->z); - } - return func(&iv, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_UBIGINT: { - if (TSDB_CODE_SUCCESS != toInt64(pToken->z, pToken->type, pToken->n, &iv, false)) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned bigint data", pToken->z); - } else if (!IS_VALID_UBIGINT((uint64_t)iv)) { - return buildSyntaxErrMsg(&pCxt->msg, "unsigned bigint data overflow", pToken->z); - } - uint64_t tmpVal = (uint64_t)iv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_FLOAT: { - double dv; - if (TK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { - return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z); - } - if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) || isnan(dv)) { - return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z); - } - float tmpVal = (float)dv; - return func(&tmpVal, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_DOUBLE: { - double dv; - if (TK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { - return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z); - } - if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { - return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z); - } - return func(&dv, pSchema->bytes, param); - } - case TSDB_DATA_TYPE_BINARY: { - // too long values will return invalid sql, not be truncated automatically - if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { - return buildSyntaxErrMsg(&pCxt->msg, "string data overflow", pToken->z); - } - return func(pToken->z, pToken->n, param); - } - case TSDB_DATA_TYPE_NCHAR: { - return func(pToken->z, pToken->n, param); - } - case TSDB_DATA_TYPE_TIMESTAMP: { - int64_t tmpVal; - if (parseTime(pCxt, pToken, timePrec, &tmpVal) != TSDB_CODE_SUCCESS) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp", pToken->z); - } - return func(&tmpVal, pSchema->bytes, param); - } - } - - return TSDB_CODE_FAILED; -} - // pSql -> tag1_name, ...) static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList, SSchema* pSchema) { int32_t nCols = pColList->numOfCols; @@ -644,7 +364,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, NEXT_TOKEN(pCxt->pSql, sToken); SSchema* pSchema = &pTagsSchema[pCxt->tags.boundedColumns[i]]; param.schema = pSchema; - CHECK_CODE(parseOneValue(pCxt, &sToken, pSchema, precision, tmpTokenBuf, KvRowAppend, ¶m)); + CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); } SKVRow row = tdGetKVRowFromBuilder(&pCxt->tagsBuilder); @@ -709,7 +429,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); - CHECK_CODE(parseOneValue(pCxt, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m)); + CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m, &pCxt->msg)); if (PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { TSKEY tsKey = memRowKey(row); @@ -894,7 +614,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { SInsertParseContext context = { .pComCxt = pContext, - .pSql = pContext->pSql, + .pSql = (char*) pContext->pSql, .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, .pTableMeta = NULL, .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 9922642df31e7e86611193a70b3fadd4dfb1bfdd..2ccd76723b03a4dfd0a8e82f26c73c6386963457 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -31,7 +31,7 @@ bool isInsertSql(const char* pStr, size_t length) { } while (1); } -bool qIsDclQuery(const SQueryNode* pQuery) { +bool qIsDdlQuery(const SQueryNode* pQuery) { return TSDB_SQL_INSERT != pQuery->type && TSDB_SQL_SELECT != pQuery->type; } @@ -44,11 +44,12 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (!isDqlSqlStatement(&info)) { - SDclStmtInfo* pDcl = calloc(1, sizeof(SQueryStmtInfo)); + SDclStmtInfo* pDcl = calloc(1, sizeof(SDclStmtInfo)); if (NULL == pDcl) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code. return terrno; } + pDcl->nodeType = info.type; int32_t code = qParserValidateDclSqlNode(&info, &pCxt->ctx, pDcl, pCxt->pMsg, pCxt->msgLen); if (code == TSDB_CODE_SUCCESS) { @@ -227,3 +228,7 @@ void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) { taosArrayDestroy(pMetaReq->pTableName); taosArrayDestroy(pMetaReq->pUdf); } + +void qDestroyQuery(SQueryNode* pQuery) { + // todo +} diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index 307062ef155d952e7c95dcdcfe6b1b480d26fdff..6c7ecbe0ed8094f89a2fdf0451d758f5203a8b7b 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -13,19 +13,20 @@ * along with this program. If not, see . */ - -#include "taosmsg.h" +#include "parserUtil.h" +#include +#include +#include "function.h" #include "parser.h" +#include "parserInt.h" +#include "queryInfoUtil.h" #include "taoserror.h" -#include "tutil.h" -#include "ttypes.h" -#include "thash.h" #include "tbuffer.h" -#include "parserInt.h" -#include "parserUtil.h" +#include "thash.h" +#include "tmsg.h" #include "tmsgtype.h" -#include "queryInfoUtil.h" -#include "function.h" +#include "ttypes.h" +#include "tutil.h" typedef struct STableFilterCond { uint64_t uid; @@ -562,16 +563,6 @@ TAOS_FIELD createField(const SSchema* pSchema) { return f; } -SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name) { - SSchema s = {0}; - s.type = type; - s.bytes = bytes; - s.colId = colId; - - tstrncpy(s.name, name, tListLen(s.name)); - return s; -} - void setColumn(SColumn* pColumn, uint64_t uid, const char* tableName, int8_t flag, const SSchema* pSchema) { pColumn->uid = uid; pColumn->flag = flag; @@ -1627,313 +1618,357 @@ bool isDqlSqlStatement(SSqlInfo* pSqlInfo) { return pSqlInfo->type == TSDB_SQL_SELECT; } -#if 0 -int32_t tscCreateQueryFromQueryInfo(SQueryStmtInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr) { - memset(pQueryAttr, 0, sizeof(SQueryAttr)); - - int16_t numOfCols = (int16_t) taosArrayGetSize(pQueryInfo->colList); - int16_t numOfOutput = (int16_t) getNumOfExprs(pQueryInfo); - - pQueryAttr->topBotQuery = tscIsTopBotQuery(pQueryInfo); - pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo); - pQueryAttr->stabledev = isStabledev(pQueryInfo); - pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo); - pQueryAttr->diffQuery = tscIsDiffDerivQuery(pQueryInfo); - pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo); - pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo); - pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type); - pQueryAttr->groupbyColumn = (!pQueryInfo->stateWindow) && tscGroupbyColumn(pQueryInfo); - pQueryAttr->queryBlockDist = isBlockDistQuery(pQueryInfo); - pQueryAttr->pointInterpQuery = tscIsPointInterpQuery(pQueryInfo); - pQueryAttr->timeWindowInterpo = timeWindowInterpoRequired(pQueryInfo); - pQueryAttr->distinct = pQueryInfo->distinct; - pQueryAttr->sw = pQueryInfo->sessionWindow; - pQueryAttr->stateWindow = pQueryInfo->stateWindow; - pQueryAttr->multigroupResult = pQueryInfo->multigroupResult; - - pQueryAttr->numOfCols = numOfCols; - pQueryAttr->numOfOutput = numOfOutput; - pQueryAttr->limit = pQueryInfo->limit; - pQueryAttr->slimit = pQueryInfo->slimit; - pQueryAttr->order = pQueryInfo->order; - pQueryAttr->fillType = pQueryInfo->fillType; - pQueryAttr->havingNum = pQueryInfo->havingFieldNum; - pQueryAttr->pUdfInfo = pQueryInfo->pUdfInfo; - - if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor - pQueryAttr->window = pQueryInfo->window; - } else { - pQueryAttr->window.skey = pQueryInfo->window.ekey; - pQueryAttr->window.ekey = pQueryInfo->window.skey; +static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; +static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; + +static FORCE_INLINE int32_t toDouble(SToken *pToken, double *value, char **endPtr) { + errno = 0; + *value = strtold(pToken->z, endPtr); + + // not a valid integer number, return error + if ((*endPtr - pToken->z) != pToken->n) { + return TK_ILLEGAL; } - memcpy(&pQueryAttr->interval, &pQueryInfo->interval, sizeof(pQueryAttr->interval)); + return pToken->type; +} - STableMetaInfo* pTableMetaInfo = pQueryInfo->pTableMetaInfo[0]; +static bool isNullStr(SToken *pToken) { + return (pToken->type == TK_NULL) || ((pToken->type == TK_STRING) && (pToken->n != 0) && + (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)); +} - if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { - pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr)); - *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr; - pQueryAttr->pGroupbyExpr->columnInfo = taosArrayDup(pQueryInfo->groupbyExpr.columnInfo); - } else { - assert(pQueryInfo->groupbyExpr.columnInfo == NULL); +static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, char* tmpTokenBuf, SMsgBuf* pMsgBuf) { + if ((pToken->type != TK_NOW && pToken->type != TK_INTEGER && pToken->type != TK_STRING && pToken->type != TK_FLOAT && pToken->type != TK_BOOL && + pToken->type != TK_NULL && pToken->type != TK_HEX && pToken->type != TK_OCT && pToken->type != TK_BIN) || + (pToken->n == 0) || (pToken->type == TK_RP)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z); } - pQueryAttr->pExpr1 = calloc(pQueryAttr->numOfOutput, sizeof(SExprInfo)); - for(int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { - SExprInfo* pExpr = getExprInfo(pQueryInfo, i); - ExprInfoCopy(&pQueryAttr->pExpr1[i], pExpr); + if (IS_NUMERIC_TYPE(type) && pToken->n == 0) { + return buildSyntaxErrMsg(pMsgBuf, "invalid numeric data", pToken->z); + } - if (pQueryAttr->pExpr1[i].base.functionId == FUNCTION_ARITHM) { - for (int32_t j = 0; j < pQueryAttr->pExpr1[i].base.numOfParams; ++j) { - buildArithmeticExprFromMsg(&pQueryAttr->pExpr1[i], NULL); - } + // Remove quotation marks + if (TK_STRING == type) { + if (pToken->n >= TSDB_MAX_BYTES_PER_ROW) { + return buildSyntaxErrMsg(pMsgBuf, "too long string", pToken->z); } - } - pQueryAttr->tableCols = calloc(numOfCols, sizeof(SColumnInfo)); - for(int32_t i = 0; i < numOfCols; ++i) { - SColumn* pCol = taosArrayGetP(pQueryInfo->colList, i); - if (!isValidDataType(pCol->info.type) || pCol->info.type == TSDB_DATA_TYPE_NULL) { - assert(0); + // delete escape character: \\, \', \" + char delim = pToken->z[0]; + int32_t cnt = 0; + int32_t j = 0; + for (uint32_t k = 1; k < pToken->n - 1; ++k) { + if (pToken->z[k] == '\\' || (pToken->z[k] == delim && pToken->z[k + 1] == delim)) { + tmpTokenBuf[j] = pToken->z[k + 1]; + cnt++; + j++; + k++; + continue; + } + tmpTokenBuf[j] = pToken->z[k]; + j++; } - pQueryAttr->tableCols[i] = pCol->info; - pQueryAttr->tableCols[i].flist.filterInfo = tFilterInfoDup(pCol->info.flist.filterInfo, pQueryAttr->tableCols[i].flist.numOfFilters); + tmpTokenBuf[j] = 0; + pToken->z = tmpTokenBuf; + pToken->n -= 2 + cnt; } - // global aggregate query - if (pQueryAttr->stableQuery && (pQueryAttr->simpleAgg || pQueryAttr->interval.interval > 0) && tscIsTwoStageSTableQuery(pQueryInfo, 0)) { - createGlobalAggregateExpr(pQueryAttr, pQueryInfo); - } + return TSDB_CODE_SUCCESS; +} - // for simple table, not for super table - if (pQueryInfo->arithmeticOnAgg) { - pQueryAttr->numOfExpr2 = (int32_t) taosArrayGetSize(pQueryInfo->exprList1); - pQueryAttr->pExpr2 = calloc(pQueryAttr->numOfExpr2, sizeof(SExprInfo)); - for(int32_t i = 0; i < pQueryAttr->numOfExpr2; ++i) { - SExprInfo* p = taosArrayGetP(pQueryInfo->exprList1, i); - ExprInfoCopy(&pQueryAttr->pExpr2[i], p); +static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time, SMsgBuf* pMsgBuf) { + int32_t index = 0; + SToken sToken; + int64_t interval; + int64_t ts = 0; + char* pTokenEnd = *end; + + if (pToken->type == TK_NOW) { + ts = taosGetTimestamp(timePrec); + } else if (pToken->type == TK_INTEGER) { + bool isSigned = false; + toInteger(pToken->z, pToken->n, 10, &ts, &isSigned); + } else { // parse the RFC-3339/ISO-8601 timestamp format string + if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { + return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z); } - } - - // tag column info - int32_t code = createTagColumnInfo(pQueryAttr, pQueryInfo, pTableMetaInfo); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - if (pQueryAttr->fillType != TSDB_FILL_NONE) { - pQueryAttr->fillVal = calloc(pQueryAttr->numOfOutput, sizeof(int64_t)); - memcpy(pQueryAttr->fillVal, pQueryInfo->fillVal, pQueryInfo->numOfFillVal * sizeof(int64_t)); + return TSDB_CODE_SUCCESS; } - pQueryAttr->srcRowSize = 0; - pQueryAttr->maxTableColumnWidth = 0; - for (int16_t i = 0; i < numOfCols; ++i) { - pQueryAttr->srcRowSize += pQueryAttr->tableCols[i].bytes; - if (pQueryAttr->maxTableColumnWidth < pQueryAttr->tableCols[i].bytes) { - pQueryAttr->maxTableColumnWidth = pQueryAttr->tableCols[i].bytes; + for (int k = pToken->n; pToken->z[k] != '\0'; k++) { + if (pToken->z[k] == ' ' || pToken->z[k] == '\t') continue; + if (pToken->z[k] == ',') { + *end = pTokenEnd; + *time = ts; + return 0; } + + break; } - pQueryAttr->interBufSize = getOutputInterResultBufSize(pQueryAttr); + /* + * time expression: + * e.g., now+12a, now-5h + */ + SToken valueToken; + index = 0; + sToken = tStrGetToken(pTokenEnd, &index, false); + pTokenEnd += index; - if (pQueryAttr->numOfCols <= 0 && !tscQueryTags(pQueryInfo) && !pQueryAttr->queryBlockDist) { - tscError("%p illegal value of numOfCols in query msg: %" PRIu64 ", table cols:%d", addr, - (uint64_t)pQueryAttr->numOfCols, numOfCols); + if (sToken.type == TK_MINUS || sToken.type == TK_PLUS) { + index = 0; + valueToken = tStrGetToken(pTokenEnd, &index, false); + pTokenEnd += index; - return TSDB_CODE_TSC_INVALID_OPERATION; - } + if (valueToken.n < 2) { + return buildSyntaxErrMsg(pMsgBuf, "value expected in timestamp", sToken.z); + } - if (pQueryAttr->interval.interval < 0) { - tscError("%p illegal value of aggregation time interval in query msg: %" PRId64, addr, - (int64_t)pQueryInfo->interval.interval); - return TSDB_CODE_TSC_INVALID_OPERATION; - } + char unit = 0; + if (parseAbsoluteDuration(valueToken.z, valueToken.n, &interval, &unit, timePrec) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } - if (pQueryAttr->pGroupbyExpr != NULL && pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) { - tscError("%p illegal value of numOfGroupCols in query msg: %d", addr, pQueryInfo->groupbyExpr.numOfGroupCols); - return TSDB_CODE_TSC_INVALID_OPERATION; + if (sToken.type == TK_PLUS) { + ts += interval; + } else { + ts = ts - interval; + } + + *end = pTokenEnd; } + *time = ts; return TSDB_CODE_SUCCESS; } -static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSqlObj* pSql) { - int32_t code = TSDB_CODE_SUCCESS; - SSqlCmd* pCmd = &pSql->cmd; +int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, char* tmpTokenBuf, _row_append_fn_t func, void* param, SMsgBuf* pMsgBuf) { + int64_t iv; + char *endptr = NULL; + bool isSigned = false; - char tablename[TSDB_TABLE_FNAME_LEN] = {0}; - int32_t len = 0; + int32_t code = checkAndTrimValue(pToken, pSchema->type, tmpTokenBuf, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - if (nextStr == NULL) { - tstrncpy(tablename, *str, TSDB_TABLE_FNAME_LEN); - len = (int32_t) strlen(tablename); - } else { - len = (int32_t)(nextStr - (*str)); - if (len >= TSDB_TABLE_NAME_LEN) { - sprintf(pCmd->payload, "table name too long"); - return TSDB_CODE_TSC_INVALID_OPERATION; + if (isNullStr(pToken)) { + if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { + int64_t tmpVal = 0; + return func(&tmpVal, pSchema->bytes, param); } - memcpy(tablename, *str, nextStr - (*str)); - tablename[len] = '\0'; + return func(getNullValue(pSchema->type), 0, param); } - (*str) = nextStr + 1; - len = (int32_t)strtrim(tablename); - - SToken sToken = {.n = len, .type = TK_ID, .z = tablename}; - tGetToken(tablename, &sToken.type); - - // Check if the table name available or not - if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) { - sprintf(pCmd->payload, "table name is invalid"); - return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; - } + switch (pSchema->type) { + case TSDB_DATA_TYPE_BOOL: { + if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) { + if (strncmp(pToken->z, "true", pToken->n) == 0) { + return func(&TRUE_VALUE, pSchema->bytes, param); + } else if (strncmp(pToken->z, "false", pToken->n) == 0) { + return func(&FALSE_VALUE, pSchema->bytes, param); + } else { + return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); + } + } else if (pToken->type == TK_INTEGER) { + return func(((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + } else if (pToken->type == TK_FLOAT) { + return func(((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param); + } else { + return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); + } + } - SName name = {0}; - if ((code = tscSetTableFullName(&name, &sToken, pSql)) != TSDB_CODE_SUCCESS) { - return code; - } + case TSDB_DATA_TYPE_TINYINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid tinyint data", pToken->z); + } else if (!IS_VALID_TINYINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "tinyint data overflow", pToken->z); + } - memset(tablename, 0, tListLen(tablename)); - tNameExtractFullName(&name, tablename); + uint8_t tmpVal = (uint8_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } - char* p = strdup(tablename); - taosArrayPush(pNameArray, &p); - return TSDB_CODE_SUCCESS; -} + case TSDB_DATA_TYPE_UTINYINT:{ + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned tinyint data", pToken->z); + } else if (!IS_VALID_UTINYINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "unsigned tinyint data overflow", pToken->z); + } + uint8_t tmpVal = (uint8_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } -int32_t nameComparFn(const void* n1, const void* n2) { - int32_t ret = strcmp(*(char**)n1, *(char**)n2); - if (ret == 0) { - return 0; - } else { - return ret > 0? 1:-1; - } -} + case TSDB_DATA_TYPE_SMALLINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid smallint data", pToken->z); + } else if (!IS_VALID_SMALLINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "smallint data overflow", pToken->z); + } + int16_t tmpVal = (int16_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } -static void freeContent(void* p) { - char* ptr = *(char**)p; - tfree(ptr); -} + case TSDB_DATA_TYPE_USMALLINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned smallint data", pToken->z); + } else if (!IS_VALID_USMALLINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "unsigned smallint data overflow", pToken->z); + } + uint16_t tmpVal = (uint16_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } + case TSDB_DATA_TYPE_INT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid int data", pToken->z); + } else if (!IS_VALID_INT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "int data overflow", pToken->z); + } + int32_t tmpVal = (int32_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } -int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) { - SSqlCmd *pCmd = &pSql->cmd; + case TSDB_DATA_TYPE_UINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned int data", pToken->z); + } else if (!IS_VALID_UINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "unsigned int data overflow", pToken->z); + } + uint32_t tmpVal = (uint32_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } - pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + case TSDB_DATA_TYPE_BIGINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid bigint data", pToken->z); + } else if (!IS_VALID_BIGINT(iv)) { + return buildSyntaxErrMsg(pMsgBuf, "bigint data overflow", pToken->z); + } + return func(&iv, pSchema->bytes, param); + } - int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; - char *str = (char *)pNameList; + case TSDB_DATA_TYPE_UBIGINT: { + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv, &isSigned)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned bigint data", pToken->z); + } else if (!IS_VALID_UBIGINT((uint64_t)iv)) { + return buildSyntaxErrMsg(pMsgBuf, "unsigned bigint data overflow", pToken->z); + } + uint64_t tmpVal = (uint64_t)iv; + return func(&tmpVal, pSchema->bytes, param); + } - SQueryStmtInfo *pQueryInfo = tscGetQueryInfoS(pCmd); - if (pQueryInfo == NULL) { - pSql->res.code = terrno; - return terrno; - } + case TSDB_DATA_TYPE_FLOAT: { + double dv; + if (TK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { + return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); + } + if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) || isnan(dv)) { + return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); + } + float tmpVal = (float)dv; + return func(&tmpVal, pSchema->bytes, param); + } - char *nextStr; - while (1) { - nextStr = strchr(str, ','); - if (nextStr == NULL) { - code = doAddTableName(nextStr, &str, pNameArray, pSql); - break; + case TSDB_DATA_TYPE_DOUBLE: { + double dv; + if (TK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { + return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); + } + if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { + return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); + } + return func(&dv, pSchema->bytes, param); } - code = doAddTableName(nextStr, &str, pNameArray, pSql); - if (code != TSDB_CODE_SUCCESS) { - return code; + case TSDB_DATA_TYPE_BINARY: { + // Too long values will raise the invalid sql error message + if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { + return buildSyntaxErrMsg(pMsgBuf, "string data overflow", pToken->z); + } + + return func(pToken->z, pToken->n, param); } - if (taosArrayGetSize(pNameArray) > TSDB_MULTI_TABLEMETA_MAX_NUM) { - code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; - sprintf(pCmd->payload, "tables over the max number"); - return code; + case TSDB_DATA_TYPE_NCHAR: { + return func(pToken->z, pToken->n, param); } - } - size_t len = taosArrayGetSize(pNameArray); - if (len == 1) { - return TSDB_CODE_SUCCESS; - } + case TSDB_DATA_TYPE_TIMESTAMP: { + int64_t tmpVal; + if (parseTime(end, pToken, timePrec, &tmpVal, pMsgBuf) != TSDB_CODE_SUCCESS) { + return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp", pToken->z); + } - if (len > TSDB_MULTI_TABLEMETA_MAX_NUM) { - code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; - sprintf(pCmd->payload, "tables over the max number"); - return code; + return func(&tmpVal, pSchema->bytes, param); + } } - taosArraySort(pNameArray, nameComparFn); - taosArrayRemoveDuplicate(pNameArray, nameComparFn, freeContent); - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } -bool vgroupInfoIdentical(SNewVgroupInfo *pExisted, SVgroupMsg* src) { - assert(pExisted != NULL && src != NULL); - if (pExisted->numOfEps != src->numOfEps) { - return false; - } +int32_t KvRowAppend(const void *value, int32_t len, void *param) { + SKvParam* pa = (SKvParam*) param; - for(int32_t i = 0; i < pExisted->numOfEps; ++i) { - if (pExisted->ep[i].port != src->epAddr[i].port) { - return false; - } + int32_t type = pa->schema->type; + int32_t colId = pa->schema->colId; - if (strncmp(pExisted->ep[i].fqdn, src->epAddr[i].fqdn, tListLen(pExisted->ep[i].fqdn)) != 0) { - return false; + if (TSDB_DATA_TYPE_BINARY == type) { + STR_WITH_SIZE_TO_VARSTR(pa->buf, value, len); + tdAddColToKVRow(pa->builder, colId, type, pa->buf); + } else if (TSDB_DATA_TYPE_NCHAR == type) { + // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' + int32_t output = 0; + if (!taosMbsToUcs4(value, len, varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) { + return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; } + + varDataSetLen(pa->buf, output); + tdAddColToKVRow(pa->builder, colId, type, pa->buf); + } else { + tdAddColToKVRow(pa->builder, colId, type, value); } - return true; + return TSDB_CODE_SUCCESS; } -SNewVgroupInfo createNewVgroupInfo(SVgroupMsg *pVgroupMsg) { - assert(pVgroupMsg != NULL); +int32_t createSName(SName* pName, SToken* pTableName, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { + const char* msg1 = "name too long"; - SNewVgroupInfo info = {0}; - info.numOfEps = pVgroupMsg->numOfEps; - info.vgId = pVgroupMsg->vgId; - info.inUse = 0; // 0 is the default value of inUse in case of multiple replica + int32_t code = TSDB_CODE_SUCCESS; + char* p = strnchr(pTableName->z, TS_PATH_DELIMITER[0], pTableName->n, false); - assert(info.numOfEps >= 1 && info.vgId >= 1); - for(int32_t i = 0; i < pVgroupMsg->numOfEps; ++i) { - tstrncpy(info.ep[i].fqdn, pVgroupMsg->epAddr[i].fqdn, TSDB_FQDN_LEN); - info.ep[i].port = pVgroupMsg->epAddr[i].port; - } + if (p != NULL) { // db has been specified in sql string so we ignore current db path + tNameSetAcctId(pName, pParseCtx->acctId); - return info; -} + char name[TSDB_TABLE_FNAME_LEN] = {0}; + strncpy(name, pTableName->z, pTableName->n); -char* cloneCurrentDBName(SSqlObj* pSql) { - char *p = NULL; - HttpContext *pCtx = NULL; + code = tNameFromString(pName, name, T_NAME_DB|T_NAME_TABLE); + if (code != 0) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } else { // get current DB name first, and then set it into path + if (pTableName->n >= TSDB_TABLE_NAME_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } - pthread_mutex_lock(&pSql->pTscObj->mutex); - STscObj *pTscObj = pSql->pTscObj; - switch (pTscObj->from) { - case TAOS_REQ_FROM_HTTP: - pCtx = pSql->param; - if (pCtx && pCtx->db[0] != '\0') { - char db[TSDB_FULL_DB_NAME_LEN] = {0}; - int32_t len = sprintf(db, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pCtx->db); - assert(len <= sizeof(db)); + tNameSetDbName(pName, pParseCtx->acctId, pParseCtx->db, strlen(pParseCtx->db)); - p = strdup(db); - } - break; - default: - break; - } - if (p == NULL) { - p = strdup(pSql->pTscObj->db); + char name[TSDB_TABLE_FNAME_LEN] = {0}; + strncpy(name, pTableName->z, pTableName->n); + + code = tNameFromString(pName, name, T_NAME_TABLE); + if (code != 0) { + code = buildInvalidOperationMsg(pMsgBuf, msg1); + } } - pthread_mutex_unlock(&pSql->pTscObj->mutex); - return p; + return code; } - -#endif \ No newline at end of file diff --git a/source/libs/parser/src/queryInfoUtil.c b/source/libs/parser/src/queryInfoUtil.c index 1ae0d9211a2925b27b415becfab1fc385d242965..d7aa75857672e9321b4556553e21a6994988b3c8 100644 --- a/source/libs/parser/src/queryInfoUtil.c +++ b/source/libs/parser/src/queryInfoUtil.c @@ -26,7 +26,7 @@ size_t getNumOfExprs(SQueryStmtInfo* pQueryInfo) { } SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) { - assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < getNumOfColumns(pTableMeta)); + assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta))); SSchema* pSchema = (SSchema*) pTableMeta->schema; return &pSchema[colIndex]; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 5295faf645c137e749eac0b0f3ed30b2e393a562..f7f56510daf1ccfb5e9eebae56ce006622082a3e 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -97,30 +97,30 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 276 +#define YYNOCODE 274 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SSessionWindowVal yy39; - SCreateDbInfo yy42; - SVariant yy43; - int yy44; - tSqlExpr* yy46; - SLimit yy55; - SCreatedTableInfo yy96; - SArray* yy131; - SSqlNode* yy256; - SCreateTableSql* yy272; - SField yy290; - SSubclause* yy303; - int32_t yy310; - SCreateAcctInfo yy341; - int64_t yy459; - SIntervalVal yy530; - SWindowStateVal yy538; - SRelationInfo* yy544; + SWindowStateVal yy6; + SRelationInfo* yy10; + SCreateDbInfo yy16; + int32_t yy46; + int yy47; + SSessionWindowVal yy97; + SField yy106; + SCreatedTableInfo yy150; + SArray* yy165; + tSqlExpr* yy202; + int64_t yy207; + SCreateAcctInfo yy211; + SSqlNode* yy278; + SCreateTableSql* yy326; + SLimit yy367; + SVariant yy425; + SSubclause* yy503; + SIntervalVal yy532; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -130,17 +130,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 358 -#define YYNRULE 288 -#define YYNTOKEN 196 -#define YY_MAX_SHIFT 357 -#define YY_MIN_SHIFTREDUCE 564 -#define YY_MAX_SHIFTREDUCE 851 -#define YY_ERROR_ACTION 852 -#define YY_ACCEPT_ACTION 853 -#define YY_NO_ACTION 854 -#define YY_MIN_REDUCE 855 -#define YY_MAX_REDUCE 1142 +#define YYNSTATE 366 +#define YYNRULE 303 +#define YYNTOKEN 191 +#define YY_MAX_SHIFT 365 +#define YY_MIN_SHIFTREDUCE 587 +#define YY_MAX_SHIFTREDUCE 889 +#define YY_ERROR_ACTION 890 +#define YY_ACCEPT_ACTION 891 +#define YY_NO_ACTION 892 +#define YY_MIN_REDUCE 893 +#define YY_MAX_REDUCE 1195 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -206,287 +206,294 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (762) +#define YY_ACTTAB_COUNT (782) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 94, 615, 233, 244, 356, 227, 1004, 239, 243, 616, - /* 10 */ 615, 1004, 21, 55, 56, 241, 59, 60, 616, 1004, - /* 20 */ 247, 49, 48, 47, 200, 58, 315, 63, 61, 64, - /* 30 */ 62, 987, 988, 33, 991, 54, 53, 853, 357, 52, - /* 40 */ 51, 50, 55, 56, 97, 59, 60, 650, 248, 247, - /* 50 */ 49, 48, 47, 201, 58, 315, 63, 61, 64, 62, - /* 60 */ 976, 203, 974, 975, 54, 53, 203, 977, 52, 51, - /* 70 */ 50, 978, 1119, 979, 980, 54, 53, 1119, 992, 52, - /* 80 */ 51, 50, 55, 56, 1017, 59, 60, 159, 79, 247, - /* 90 */ 49, 48, 47, 27, 58, 315, 63, 61, 64, 62, - /* 100 */ 269, 313, 693, 990, 54, 53, 203, 998, 52, 51, - /* 110 */ 50, 345, 55, 57, 788, 59, 60, 1119, 36, 247, - /* 120 */ 49, 48, 47, 615, 58, 315, 63, 61, 64, 62, - /* 130 */ 1017, 616, 335, 334, 54, 53, 152, 615, 52, 51, - /* 140 */ 50, 56, 36, 59, 60, 616, 230, 247, 49, 48, - /* 150 */ 47, 240, 58, 315, 63, 61, 64, 62, 159, 1066, - /* 160 */ 229, 287, 54, 53, 1001, 73, 52, 51, 50, 565, - /* 170 */ 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, - /* 180 */ 576, 577, 578, 150, 237, 228, 59, 60, 1001, 313, - /* 190 */ 247, 49, 48, 47, 250, 58, 315, 63, 61, 64, - /* 200 */ 62, 203, 275, 274, 74, 54, 53, 753, 754, 52, - /* 210 */ 51, 50, 1118, 42, 311, 351, 350, 310, 309, 308, - /* 220 */ 349, 307, 306, 305, 348, 304, 347, 346, 289, 22, - /* 230 */ 90, 970, 958, 959, 960, 961, 962, 963, 964, 965, - /* 240 */ 966, 967, 968, 969, 971, 972, 212, 1017, 246, 803, - /* 250 */ 36, 36, 792, 213, 795, 36, 798, 168, 36, 134, - /* 260 */ 133, 132, 214, 231, 246, 803, 320, 85, 792, 251, - /* 270 */ 795, 249, 798, 323, 322, 277, 63, 61, 64, 62, - /* 280 */ 206, 255, 225, 226, 54, 53, 316, 85, 52, 51, - /* 290 */ 50, 12, 238, 324, 85, 93, 1001, 1001, 225, 226, - /* 300 */ 325, 1000, 717, 43, 1001, 714, 261, 715, 207, 716, - /* 310 */ 194, 192, 190, 159, 1027, 265, 264, 189, 138, 137, - /* 320 */ 136, 135, 36, 43, 96, 268, 42, 77, 351, 350, - /* 330 */ 43, 65, 84, 349, 221, 252, 253, 348, 36, 347, - /* 340 */ 346, 3, 39, 175, 119, 113, 123, 65, 36, 103, - /* 350 */ 107, 99, 106, 128, 131, 122, 257, 36, 254, 36, - /* 360 */ 330, 329, 125, 159, 326, 804, 799, 300, 1001, 734, - /* 370 */ 36, 121, 800, 52, 51, 50, 794, 256, 797, 1024, - /* 380 */ 327, 804, 799, 345, 1001, 1065, 173, 793, 800, 796, - /* 390 */ 331, 149, 147, 146, 1001, 355, 354, 143, 256, 332, - /* 400 */ 256, 333, 903, 1001, 770, 1001, 78, 174, 185, 1002, - /* 410 */ 352, 940, 337, 70, 92, 731, 1001, 913, 718, 719, - /* 420 */ 904, 82, 270, 185, 790, 83, 185, 750, 80, 760, - /* 430 */ 761, 703, 292, 705, 294, 91, 37, 704, 989, 32, - /* 440 */ 7, 154, 826, 66, 24, 37, 37, 66, 95, 805, - /* 450 */ 245, 66, 317, 738, 71, 614, 23, 69, 76, 208, - /* 460 */ 769, 69, 791, 23, 14, 112, 13, 111, 16, 23, - /* 470 */ 15, 295, 4, 722, 720, 723, 721, 18, 118, 17, - /* 480 */ 117, 20, 1113, 19, 130, 129, 1112, 1111, 223, 692, - /* 490 */ 224, 204, 205, 209, 202, 210, 801, 211, 216, 217, - /* 500 */ 218, 215, 199, 1003, 1138, 1130, 1019, 802, 1076, 1075, - /* 510 */ 235, 1072, 1071, 44, 236, 336, 266, 1058, 169, 151, - /* 520 */ 1026, 148, 1037, 1034, 1035, 1018, 272, 1057, 1039, 999, - /* 530 */ 1015, 276, 153, 232, 278, 280, 31, 158, 283, 163, - /* 540 */ 170, 160, 997, 161, 749, 162, 164, 165, 166, 171, - /* 550 */ 172, 301, 917, 297, 290, 807, 284, 298, 299, 302, - /* 560 */ 303, 197, 40, 75, 314, 912, 321, 1137, 109, 72, - /* 570 */ 46, 1136, 1133, 288, 176, 328, 1129, 115, 1128, 1125, - /* 580 */ 177, 286, 937, 41, 38, 198, 901, 279, 124, 899, - /* 590 */ 126, 127, 897, 896, 258, 187, 188, 893, 892, 891, - /* 600 */ 890, 889, 888, 282, 887, 191, 193, 884, 882, 880, - /* 610 */ 878, 195, 875, 196, 871, 45, 120, 271, 81, 86, - /* 620 */ 338, 281, 1059, 339, 340, 341, 222, 343, 342, 242, - /* 630 */ 296, 344, 353, 851, 259, 260, 219, 220, 850, 104, - /* 640 */ 916, 915, 262, 263, 849, 832, 895, 894, 831, 267, - /* 650 */ 291, 139, 69, 886, 180, 140, 179, 938, 178, 181, - /* 660 */ 182, 184, 183, 939, 141, 885, 8, 142, 877, 2, - /* 670 */ 1, 876, 725, 28, 273, 167, 87, 751, 155, 157, - /* 680 */ 762, 156, 234, 756, 88, 29, 758, 89, 285, 9, - /* 690 */ 30, 10, 11, 25, 293, 26, 96, 98, 101, 34, - /* 700 */ 100, 628, 35, 102, 663, 661, 660, 659, 657, 656, - /* 710 */ 655, 652, 619, 312, 105, 5, 318, 806, 319, 6, - /* 720 */ 808, 108, 110, 67, 68, 695, 37, 694, 691, 114, - /* 730 */ 644, 116, 642, 634, 640, 636, 638, 632, 630, 665, - /* 740 */ 664, 662, 658, 654, 653, 186, 617, 144, 582, 855, - /* 750 */ 854, 854, 854, 854, 854, 854, 854, 854, 854, 854, - /* 760 */ 854, 145, + /* 0 */ 249, 638, 364, 230, 162, 639, 248, 55, 56, 638, + /* 10 */ 59, 60, 1031, 639, 252, 49, 48, 47, 94, 58, + /* 20 */ 323, 63, 61, 64, 62, 674, 1080, 891, 365, 54, + /* 30 */ 53, 206, 82, 52, 51, 50, 253, 55, 56, 638, + /* 40 */ 59, 60, 1171, 639, 252, 49, 48, 47, 21, 58, + /* 50 */ 323, 63, 61, 64, 62, 1017, 203, 1015, 1016, 54, + /* 60 */ 53, 206, 1018, 52, 51, 50, 1019, 206, 1020, 1021, + /* 70 */ 832, 835, 1172, 55, 56, 1070, 59, 60, 1172, 1118, + /* 80 */ 252, 49, 48, 47, 81, 58, 323, 63, 61, 64, + /* 90 */ 62, 321, 319, 274, 1077, 54, 53, 206, 638, 52, + /* 100 */ 51, 50, 639, 55, 57, 353, 59, 60, 1172, 826, + /* 110 */ 252, 49, 48, 47, 155, 58, 323, 63, 61, 64, + /* 120 */ 62, 42, 319, 359, 358, 54, 53, 162, 357, 52, + /* 130 */ 51, 50, 356, 87, 355, 354, 162, 162, 588, 589, + /* 140 */ 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, + /* 150 */ 600, 601, 153, 56, 231, 59, 60, 236, 1057, 252, + /* 160 */ 49, 48, 47, 87, 58, 323, 63, 61, 64, 62, + /* 170 */ 772, 43, 32, 86, 54, 53, 255, 204, 52, 51, + /* 180 */ 50, 309, 209, 280, 279, 59, 60, 941, 839, 252, + /* 190 */ 49, 48, 47, 188, 58, 323, 63, 61, 64, 62, + /* 200 */ 294, 43, 92, 242, 54, 53, 300, 1045, 52, 51, + /* 210 */ 50, 1119, 93, 292, 42, 317, 359, 358, 316, 315, + /* 220 */ 314, 357, 313, 312, 311, 356, 310, 355, 354, 99, + /* 230 */ 22, 1010, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, + /* 240 */ 1006, 1007, 1008, 1009, 1011, 1012, 1013, 215, 251, 841, + /* 250 */ 830, 833, 836, 256, 216, 254, 776, 331, 330, 250, + /* 260 */ 137, 136, 135, 217, 1033, 266, 719, 328, 87, 251, + /* 270 */ 841, 830, 833, 836, 270, 269, 228, 229, 831, 834, + /* 280 */ 324, 4, 63, 61, 64, 62, 755, 752, 753, 754, + /* 290 */ 54, 53, 343, 342, 52, 51, 50, 228, 229, 747, + /* 300 */ 744, 745, 746, 52, 51, 50, 43, 3, 39, 178, + /* 310 */ 152, 150, 149, 257, 258, 105, 77, 101, 108, 1039, + /* 320 */ 96, 791, 792, 260, 36, 65, 244, 245, 273, 36, + /* 330 */ 79, 197, 195, 193, 36, 305, 210, 224, 192, 141, + /* 340 */ 140, 139, 138, 36, 36, 36, 65, 122, 116, 126, + /* 350 */ 36, 211, 1028, 1029, 33, 1032, 131, 134, 125, 638, + /* 360 */ 36, 842, 837, 639, 243, 128, 36, 232, 838, 54, + /* 370 */ 53, 1042, 240, 52, 51, 50, 1042, 241, 36, 36, + /* 380 */ 36, 1042, 842, 837, 1166, 261, 332, 333, 334, 838, + /* 390 */ 1042, 1042, 1042, 335, 176, 12, 840, 1042, 756, 757, + /* 400 */ 262, 95, 259, 339, 338, 337, 171, 1042, 363, 362, + /* 410 */ 146, 748, 749, 1041, 246, 80, 808, 1070, 1045, 1070, + /* 420 */ 261, 340, 341, 345, 282, 1042, 1042, 1042, 124, 177, + /* 430 */ 98, 261, 952, 942, 769, 233, 27, 234, 188, 188, + /* 440 */ 1043, 275, 353, 360, 979, 84, 85, 788, 1030, 798, + /* 450 */ 799, 71, 74, 729, 297, 731, 299, 37, 325, 7, + /* 460 */ 742, 743, 730, 157, 828, 66, 24, 740, 741, 37, + /* 470 */ 37, 67, 97, 864, 807, 760, 761, 843, 67, 637, + /* 480 */ 14, 78, 13, 70, 70, 115, 1165, 114, 16, 23, + /* 490 */ 15, 75, 72, 23, 1111, 23, 829, 758, 759, 133, + /* 500 */ 132, 18, 121, 17, 120, 20, 1164, 19, 1129, 226, + /* 510 */ 322, 227, 207, 1056, 718, 208, 212, 205, 213, 214, + /* 520 */ 1044, 219, 1072, 220, 1191, 221, 218, 202, 1128, 1183, + /* 530 */ 238, 1125, 1124, 239, 344, 271, 154, 44, 172, 1079, + /* 540 */ 151, 1110, 1090, 1087, 1088, 1071, 277, 1092, 1040, 156, + /* 550 */ 1068, 281, 235, 283, 31, 161, 285, 165, 288, 173, + /* 560 */ 163, 168, 787, 845, 164, 276, 1038, 174, 166, 169, + /* 570 */ 167, 291, 175, 956, 302, 303, 304, 76, 307, 308, + /* 580 */ 200, 40, 320, 951, 950, 329, 1190, 112, 73, 1189, + /* 590 */ 1186, 179, 46, 336, 295, 1182, 118, 287, 1181, 1178, + /* 600 */ 180, 976, 41, 38, 201, 939, 127, 937, 129, 130, + /* 610 */ 935, 934, 263, 190, 191, 931, 930, 929, 928, 293, + /* 620 */ 927, 926, 925, 194, 196, 922, 920, 918, 916, 198, + /* 630 */ 913, 199, 909, 289, 284, 83, 88, 45, 286, 1112, + /* 640 */ 306, 123, 346, 225, 247, 347, 301, 348, 349, 351, + /* 650 */ 222, 223, 350, 352, 361, 955, 954, 106, 889, 264, + /* 660 */ 265, 888, 267, 268, 887, 870, 933, 869, 272, 183, + /* 670 */ 182, 977, 932, 181, 142, 184, 185, 187, 186, 143, + /* 680 */ 144, 924, 978, 923, 2, 70, 145, 915, 914, 296, + /* 690 */ 8, 28, 1, 763, 278, 170, 789, 89, 158, 160, + /* 700 */ 800, 159, 237, 794, 90, 29, 796, 91, 290, 9, + /* 710 */ 30, 10, 11, 25, 26, 298, 100, 34, 98, 103, + /* 720 */ 652, 102, 690, 35, 104, 687, 685, 684, 683, 681, + /* 730 */ 680, 679, 676, 642, 326, 327, 107, 111, 109, 318, + /* 740 */ 113, 110, 5, 68, 844, 846, 6, 69, 721, 37, + /* 750 */ 117, 119, 720, 717, 668, 666, 658, 664, 660, 662, + /* 760 */ 656, 654, 689, 688, 686, 682, 678, 677, 189, 640, + /* 770 */ 893, 605, 892, 892, 892, 892, 892, 892, 892, 892, + /* 780 */ 147, 148, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 206, 1, 242, 205, 199, 200, 246, 242, 205, 9, - /* 10 */ 1, 246, 263, 13, 14, 242, 16, 17, 9, 246, - /* 20 */ 20, 21, 22, 23, 263, 25, 26, 27, 28, 29, - /* 30 */ 30, 237, 238, 239, 240, 35, 36, 197, 198, 39, - /* 40 */ 40, 41, 13, 14, 206, 16, 17, 5, 205, 20, - /* 50 */ 21, 22, 23, 263, 25, 26, 27, 28, 29, 30, - /* 60 */ 221, 263, 223, 224, 35, 36, 263, 228, 39, 40, - /* 70 */ 41, 232, 274, 234, 235, 35, 36, 274, 240, 39, - /* 80 */ 40, 41, 13, 14, 244, 16, 17, 199, 88, 20, - /* 90 */ 21, 22, 23, 84, 25, 26, 27, 28, 29, 30, - /* 100 */ 260, 86, 5, 0, 35, 36, 263, 199, 39, 40, - /* 110 */ 41, 92, 13, 14, 85, 16, 17, 274, 199, 20, - /* 120 */ 21, 22, 23, 1, 25, 26, 27, 28, 29, 30, - /* 130 */ 244, 9, 35, 36, 35, 36, 199, 1, 39, 40, - /* 140 */ 41, 14, 199, 16, 17, 9, 260, 20, 21, 22, - /* 150 */ 23, 243, 25, 26, 27, 28, 29, 30, 199, 271, - /* 160 */ 241, 273, 35, 36, 245, 99, 39, 40, 41, 47, - /* 170 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 180 */ 58, 59, 60, 61, 241, 63, 16, 17, 245, 86, - /* 190 */ 20, 21, 22, 23, 70, 25, 26, 27, 28, 29, - /* 200 */ 30, 263, 265, 266, 138, 35, 36, 126, 127, 39, - /* 210 */ 40, 41, 274, 100, 101, 102, 103, 104, 105, 106, - /* 220 */ 107, 108, 109, 110, 111, 112, 113, 114, 269, 46, - /* 230 */ 271, 221, 222, 223, 224, 225, 226, 227, 228, 229, - /* 240 */ 230, 231, 232, 233, 234, 235, 63, 244, 1, 2, - /* 250 */ 199, 199, 5, 70, 7, 199, 9, 250, 199, 76, - /* 260 */ 77, 78, 79, 260, 1, 2, 83, 84, 5, 145, - /* 270 */ 7, 147, 9, 149, 150, 268, 27, 28, 29, 30, - /* 280 */ 263, 70, 35, 36, 35, 36, 39, 84, 39, 40, - /* 290 */ 41, 84, 241, 241, 84, 88, 245, 245, 35, 36, - /* 300 */ 241, 245, 2, 120, 245, 5, 143, 7, 263, 9, - /* 310 */ 64, 65, 66, 199, 199, 152, 153, 71, 72, 73, - /* 320 */ 74, 75, 199, 120, 117, 142, 100, 144, 102, 103, - /* 330 */ 120, 84, 122, 107, 151, 35, 36, 111, 199, 113, - /* 340 */ 114, 64, 65, 66, 64, 65, 66, 84, 199, 72, - /* 350 */ 73, 74, 75, 73, 74, 75, 145, 199, 147, 199, - /* 360 */ 149, 150, 82, 199, 241, 118, 119, 90, 245, 39, - /* 370 */ 199, 80, 125, 39, 40, 41, 5, 199, 7, 264, - /* 380 */ 241, 118, 119, 92, 245, 271, 208, 5, 125, 7, - /* 390 */ 241, 64, 65, 66, 245, 67, 68, 69, 199, 241, - /* 400 */ 199, 241, 204, 245, 78, 245, 206, 208, 210, 208, - /* 410 */ 219, 220, 241, 99, 247, 99, 245, 204, 118, 119, - /* 420 */ 204, 85, 85, 210, 1, 85, 210, 85, 261, 85, - /* 430 */ 85, 85, 85, 85, 85, 271, 99, 85, 238, 84, - /* 440 */ 124, 99, 85, 99, 99, 99, 99, 99, 99, 85, - /* 450 */ 62, 99, 15, 123, 140, 85, 99, 121, 84, 263, - /* 460 */ 134, 121, 39, 99, 146, 146, 148, 148, 146, 99, - /* 470 */ 148, 116, 84, 5, 5, 7, 7, 146, 146, 148, - /* 480 */ 148, 146, 263, 148, 80, 81, 263, 263, 263, 115, - /* 490 */ 263, 263, 263, 263, 263, 263, 125, 263, 263, 263, - /* 500 */ 263, 263, 263, 246, 246, 246, 244, 125, 236, 236, - /* 510 */ 236, 236, 236, 262, 236, 236, 199, 272, 248, 199, - /* 520 */ 199, 62, 199, 199, 199, 244, 244, 272, 199, 244, - /* 530 */ 259, 267, 199, 267, 267, 267, 249, 199, 199, 255, - /* 540 */ 199, 258, 199, 257, 125, 256, 254, 253, 252, 199, - /* 550 */ 199, 91, 199, 199, 132, 118, 129, 199, 199, 199, - /* 560 */ 199, 199, 199, 137, 199, 199, 199, 199, 199, 139, - /* 570 */ 136, 199, 199, 135, 199, 199, 199, 199, 199, 199, - /* 580 */ 199, 130, 199, 199, 199, 199, 199, 131, 199, 199, - /* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, - /* 600 */ 199, 199, 199, 128, 199, 199, 199, 199, 199, 199, - /* 610 */ 199, 199, 199, 199, 199, 141, 98, 201, 201, 201, - /* 620 */ 97, 201, 201, 53, 94, 96, 201, 95, 57, 201, - /* 630 */ 201, 93, 86, 5, 154, 5, 201, 201, 5, 206, - /* 640 */ 209, 209, 154, 5, 5, 102, 201, 201, 101, 143, - /* 650 */ 116, 202, 121, 201, 212, 202, 216, 218, 217, 215, - /* 660 */ 213, 211, 214, 220, 202, 201, 84, 202, 201, 203, - /* 670 */ 207, 201, 85, 84, 99, 251, 99, 85, 84, 99, - /* 680 */ 85, 84, 1, 85, 84, 99, 85, 84, 84, 133, - /* 690 */ 99, 133, 84, 84, 116, 84, 117, 80, 72, 89, - /* 700 */ 88, 5, 89, 88, 9, 5, 5, 5, 5, 5, - /* 710 */ 5, 5, 87, 15, 80, 84, 26, 85, 61, 84, - /* 720 */ 118, 148, 148, 16, 16, 5, 99, 5, 85, 148, - /* 730 */ 5, 148, 5, 5, 5, 5, 5, 5, 5, 5, - /* 740 */ 5, 5, 5, 5, 5, 99, 87, 21, 62, 0, - /* 750 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 760 */ 275, 21, 275, 275, 275, 275, 275, 275, 275, 275, - /* 770 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 780 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 790 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 800 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 810 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 820 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 830 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 840 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 850 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 860 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 870 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 880 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 890 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 900 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 910 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 920 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 930 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 940 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, - /* 950 */ 275, 275, 275, 275, 275, 275, 275, 275, + /* 0 */ 200, 1, 194, 195, 194, 5, 200, 7, 8, 1, + /* 10 */ 10, 11, 0, 5, 14, 15, 16, 17, 245, 19, + /* 20 */ 20, 21, 22, 23, 24, 3, 194, 192, 193, 29, + /* 30 */ 30, 261, 259, 33, 34, 35, 200, 7, 8, 1, + /* 40 */ 10, 11, 272, 5, 14, 15, 16, 17, 261, 19, + /* 50 */ 20, 21, 22, 23, 24, 216, 261, 218, 219, 29, + /* 60 */ 30, 261, 223, 33, 34, 35, 227, 261, 229, 230, + /* 70 */ 3, 4, 272, 7, 8, 240, 10, 11, 272, 269, + /* 80 */ 14, 15, 16, 17, 84, 19, 20, 21, 22, 23, + /* 90 */ 24, 83, 80, 258, 262, 29, 30, 261, 1, 33, + /* 100 */ 34, 35, 5, 7, 8, 88, 10, 11, 272, 79, + /* 110 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, + /* 120 */ 24, 96, 80, 98, 99, 29, 30, 194, 103, 33, + /* 130 */ 34, 35, 107, 78, 109, 110, 194, 194, 41, 42, + /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + /* 150 */ 53, 54, 55, 8, 57, 10, 11, 243, 244, 14, + /* 160 */ 15, 16, 17, 78, 19, 20, 21, 22, 23, 24, + /* 170 */ 33, 116, 78, 118, 29, 30, 64, 261, 33, 34, + /* 180 */ 35, 63, 261, 263, 264, 10, 11, 199, 121, 14, + /* 190 */ 15, 16, 17, 205, 19, 20, 21, 22, 23, 24, + /* 200 */ 267, 116, 269, 238, 29, 30, 112, 242, 33, 34, + /* 210 */ 35, 269, 269, 271, 96, 97, 98, 99, 100, 101, + /* 220 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, + /* 230 */ 40, 216, 217, 218, 219, 220, 221, 222, 223, 224, + /* 240 */ 225, 226, 227, 228, 229, 230, 231, 57, 1, 2, + /* 250 */ 3, 4, 5, 141, 64, 143, 119, 145, 146, 56, + /* 260 */ 70, 71, 72, 73, 236, 139, 3, 77, 78, 1, + /* 270 */ 2, 3, 4, 5, 148, 149, 29, 30, 3, 4, + /* 280 */ 33, 78, 21, 22, 23, 24, 2, 3, 4, 5, + /* 290 */ 29, 30, 29, 30, 33, 34, 35, 29, 30, 2, + /* 300 */ 3, 4, 5, 33, 34, 35, 116, 58, 59, 60, + /* 310 */ 58, 59, 60, 29, 30, 66, 67, 68, 69, 194, + /* 320 */ 201, 122, 123, 64, 194, 78, 29, 30, 138, 194, + /* 330 */ 140, 58, 59, 60, 194, 86, 261, 147, 65, 66, + /* 340 */ 67, 68, 69, 194, 194, 194, 78, 58, 59, 60, + /* 350 */ 194, 261, 233, 234, 235, 236, 67, 68, 69, 1, + /* 360 */ 194, 114, 115, 5, 239, 76, 194, 237, 121, 29, + /* 370 */ 30, 241, 237, 33, 34, 35, 241, 237, 194, 194, + /* 380 */ 194, 241, 114, 115, 261, 194, 237, 237, 237, 121, + /* 390 */ 241, 241, 241, 237, 203, 78, 121, 241, 114, 115, + /* 400 */ 141, 84, 143, 237, 145, 146, 248, 241, 61, 62, + /* 410 */ 63, 114, 115, 241, 238, 201, 72, 240, 242, 240, + /* 420 */ 194, 237, 237, 237, 266, 241, 241, 241, 74, 203, + /* 430 */ 113, 194, 199, 199, 95, 258, 78, 258, 205, 205, + /* 440 */ 203, 79, 88, 214, 215, 79, 79, 79, 234, 79, + /* 450 */ 79, 95, 95, 79, 79, 79, 79, 95, 9, 120, + /* 460 */ 3, 4, 79, 95, 1, 95, 95, 3, 4, 95, + /* 470 */ 95, 95, 95, 79, 130, 3, 4, 79, 95, 79, + /* 480 */ 142, 78, 144, 117, 117, 142, 261, 144, 142, 95, + /* 490 */ 144, 134, 136, 95, 270, 95, 33, 3, 4, 74, + /* 500 */ 75, 142, 142, 144, 144, 142, 261, 144, 232, 261, + /* 510 */ 194, 261, 261, 244, 111, 261, 261, 261, 261, 261, + /* 520 */ 242, 261, 240, 261, 244, 261, 261, 261, 232, 244, + /* 530 */ 232, 232, 232, 232, 232, 194, 194, 260, 246, 194, + /* 540 */ 56, 270, 194, 194, 194, 240, 240, 194, 240, 194, + /* 550 */ 257, 265, 265, 265, 247, 194, 265, 254, 194, 194, + /* 560 */ 256, 251, 121, 114, 255, 196, 194, 194, 253, 250, + /* 570 */ 252, 126, 194, 194, 194, 194, 194, 133, 194, 194, + /* 580 */ 194, 194, 194, 194, 194, 194, 194, 194, 135, 194, + /* 590 */ 194, 194, 132, 194, 128, 194, 194, 124, 194, 194, + /* 600 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, + /* 610 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 131, + /* 620 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, + /* 630 */ 194, 194, 194, 125, 127, 196, 196, 137, 196, 196, + /* 640 */ 87, 94, 93, 196, 196, 47, 196, 90, 92, 91, + /* 650 */ 196, 196, 51, 89, 80, 204, 204, 201, 3, 150, + /* 660 */ 3, 3, 150, 3, 3, 98, 196, 97, 139, 207, + /* 670 */ 211, 213, 196, 212, 197, 210, 208, 206, 209, 197, + /* 680 */ 197, 196, 215, 196, 198, 117, 197, 196, 196, 112, + /* 690 */ 78, 78, 202, 79, 95, 249, 79, 95, 78, 95, + /* 700 */ 79, 78, 1, 79, 78, 95, 79, 78, 78, 129, + /* 710 */ 95, 129, 78, 78, 78, 112, 74, 85, 113, 66, + /* 720 */ 3, 84, 3, 85, 84, 5, 3, 3, 3, 3, + /* 730 */ 3, 3, 3, 81, 20, 55, 74, 144, 82, 9, + /* 740 */ 144, 82, 78, 10, 79, 114, 78, 10, 3, 95, + /* 750 */ 144, 144, 3, 79, 3, 3, 3, 3, 3, 3, + /* 760 */ 3, 3, 3, 3, 3, 3, 3, 3, 95, 81, + /* 770 */ 0, 56, 273, 273, 273, 273, 273, 273, 273, 273, + /* 780 */ 15, 15, 273, 273, 273, 273, 273, 273, 273, 273, + /* 790 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 800 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 810 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 820 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 830 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 840 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 850 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 860 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 870 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 880 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 890 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 900 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 910 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 920 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 930 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 940 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 950 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, + /* 970 */ 273, 273, 273, }; -#define YY_SHIFT_COUNT (357) +#define YY_SHIFT_COUNT (365) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (749) +#define YY_SHIFT_MAX (770) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 183, 113, 226, 15, 247, 263, 263, 9, 136, 136, - /* 10 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 20 */ 136, 0, 122, 263, 300, 300, 300, 203, 203, 136, - /* 30 */ 136, 81, 136, 103, 136, 136, 136, 136, 291, 15, - /* 40 */ 19, 19, 42, 762, 263, 263, 263, 263, 263, 263, - /* 50 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, - /* 60 */ 263, 263, 263, 263, 263, 263, 300, 300, 300, 210, - /* 70 */ 97, 97, 97, 97, 97, 97, 97, 136, 136, 136, - /* 80 */ 330, 136, 136, 136, 203, 203, 136, 136, 136, 136, - /* 90 */ 326, 326, 316, 203, 136, 136, 136, 136, 136, 136, - /* 100 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 110 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 120 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 130 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 140 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - /* 150 */ 136, 459, 459, 459, 419, 419, 419, 419, 459, 459, - /* 160 */ 426, 430, 422, 434, 438, 451, 427, 475, 456, 474, - /* 170 */ 459, 459, 459, 460, 460, 15, 459, 459, 518, 523, - /* 180 */ 570, 530, 529, 571, 532, 538, 42, 459, 459, 546, - /* 190 */ 546, 459, 546, 459, 546, 459, 459, 762, 762, 29, - /* 200 */ 69, 69, 99, 69, 127, 170, 249, 249, 249, 249, - /* 210 */ 249, 249, 277, 246, 280, 40, 40, 40, 40, 124, - /* 220 */ 211, 163, 207, 334, 334, 371, 382, 328, 327, 337, - /* 230 */ 336, 340, 342, 344, 345, 314, 66, 346, 347, 348, - /* 240 */ 349, 352, 355, 357, 364, 423, 388, 437, 370, 318, - /* 250 */ 319, 322, 468, 469, 331, 332, 374, 335, 404, 628, - /* 260 */ 480, 630, 633, 488, 638, 639, 543, 547, 506, 531, - /* 270 */ 534, 582, 587, 589, 575, 577, 592, 594, 595, 597, - /* 280 */ 598, 580, 600, 601, 603, 681, 604, 586, 556, 591, - /* 290 */ 558, 608, 534, 609, 578, 611, 579, 617, 610, 612, - /* 300 */ 626, 696, 613, 615, 695, 700, 701, 702, 703, 704, - /* 310 */ 705, 706, 625, 698, 634, 631, 632, 602, 635, 690, - /* 320 */ 657, 707, 573, 574, 627, 627, 627, 627, 708, 581, - /* 330 */ 583, 627, 627, 627, 720, 722, 643, 627, 725, 727, - /* 340 */ 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, - /* 350 */ 738, 739, 646, 659, 726, 740, 686, 749, + /* 0 */ 190, 118, 25, 42, 247, 268, 268, 358, 38, 38, + /* 10 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 20 */ 38, 0, 97, 268, 284, 297, 297, 85, 85, 38, + /* 30 */ 38, 199, 38, 12, 38, 38, 38, 38, 354, 42, + /* 40 */ 17, 17, 22, 782, 268, 268, 268, 268, 268, 268, + /* 50 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 60 */ 268, 268, 268, 268, 268, 268, 284, 297, 284, 284, + /* 70 */ 55, 263, 263, 263, 263, 263, 263, 8, 263, 38, + /* 80 */ 38, 38, 137, 38, 38, 38, 85, 85, 38, 38, + /* 90 */ 38, 38, 344, 344, 339, 85, 38, 38, 38, 38, + /* 100 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 110 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 120 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 130 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 140 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, + /* 150 */ 38, 38, 38, 38, 484, 484, 484, 441, 441, 441, + /* 160 */ 441, 484, 484, 444, 453, 466, 460, 488, 445, 508, + /* 170 */ 473, 507, 500, 484, 484, 484, 553, 553, 42, 484, + /* 180 */ 484, 547, 549, 598, 557, 556, 601, 558, 564, 22, + /* 190 */ 484, 484, 574, 574, 484, 574, 484, 574, 484, 484, + /* 200 */ 782, 782, 30, 66, 66, 96, 66, 145, 175, 261, + /* 210 */ 261, 261, 261, 261, 261, 249, 273, 289, 340, 340, + /* 220 */ 340, 340, 112, 259, 126, 317, 270, 270, 67, 275, + /* 230 */ 347, 252, 362, 366, 367, 368, 370, 371, 356, 357, + /* 240 */ 374, 375, 376, 377, 457, 464, 383, 94, 394, 398, + /* 250 */ 463, 203, 449, 400, 338, 343, 346, 472, 494, 359, + /* 260 */ 360, 403, 363, 425, 655, 509, 657, 658, 512, 660, + /* 270 */ 661, 567, 570, 529, 568, 577, 612, 614, 613, 599, + /* 280 */ 602, 617, 620, 621, 623, 624, 604, 626, 627, 629, + /* 290 */ 701, 630, 610, 580, 615, 582, 634, 577, 635, 603, + /* 300 */ 636, 605, 642, 632, 637, 653, 717, 638, 640, 719, + /* 310 */ 720, 723, 724, 725, 726, 727, 728, 729, 652, 730, + /* 320 */ 662, 656, 659, 664, 665, 631, 668, 714, 680, 733, + /* 330 */ 593, 596, 654, 654, 654, 654, 737, 606, 607, 654, + /* 340 */ 654, 654, 745, 749, 674, 654, 751, 752, 753, 754, + /* 350 */ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, + /* 360 */ 673, 688, 765, 766, 715, 770, }; -#define YY_REDUCE_COUNT (198) -#define YY_REDUCE_MIN (-251) -#define YY_REDUCE_MAX (470) +#define YY_REDUCE_COUNT (201) +#define YY_REDUCE_MIN (-230) +#define YY_REDUCE_MAX (492) static const short yy_reduce_ofst[] = { - /* 0 */ -160, 10, -161, -206, -202, -197, -157, -63, -81, -112, - /* 10 */ -41, -57, 51, 52, 59, 123, 139, 149, 158, 160, - /* 20 */ 171, 115, -195, -62, -240, -235, -227, -114, 3, 114, - /* 30 */ 164, 7, -92, -162, 178, 199, 201, 56, 198, 200, - /* 40 */ 213, 216, 191, 167, -251, -239, -210, 17, 45, 196, - /* 50 */ 219, 223, 224, 225, 227, 228, 229, 230, 231, 232, - /* 60 */ 234, 235, 236, 237, 238, 239, 257, 258, 259, 262, - /* 70 */ 272, 273, 274, 275, 276, 278, 279, 317, 320, 321, - /* 80 */ 251, 323, 324, 325, 281, 282, 329, 333, 338, 339, - /* 90 */ 245, 255, 270, 285, 341, 343, 350, 351, 353, 354, - /* 100 */ 358, 359, 360, 361, 362, 363, 365, 366, 367, 368, - /* 110 */ 369, 372, 373, 375, 376, 377, 378, 379, 380, 381, - /* 120 */ 383, 384, 385, 386, 387, 389, 390, 391, 392, 393, - /* 130 */ 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - /* 140 */ 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - /* 150 */ 415, 416, 417, 418, 264, 266, 267, 268, 420, 421, - /* 160 */ 271, 283, 286, 289, 284, 292, 294, 296, 424, 287, - /* 170 */ 425, 428, 429, 431, 432, 433, 435, 436, 439, 441, - /* 180 */ 440, 442, 444, 447, 448, 450, 443, 445, 446, 449, - /* 190 */ 453, 452, 462, 464, 465, 467, 470, 463, 466, + /* 0 */ -165, 15, -161, 119, -200, -194, -164, -80, 130, -58, + /* 10 */ -67, 135, 140, 149, 150, 151, 156, 166, 184, 185, + /* 20 */ 186, -168, -192, -230, -86, -35, 176, 177, 179, -190, + /* 30 */ -57, 158, 125, 28, 191, 226, 237, 172, -12, 214, + /* 40 */ 233, 234, 229, -227, -213, -205, -84, -79, 75, 90, + /* 50 */ 123, 225, 245, 248, 250, 251, 254, 255, 256, 257, + /* 60 */ 258, 260, 262, 264, 265, 266, 269, 278, 280, 285, + /* 70 */ 282, 276, 296, 298, 299, 300, 301, 316, 302, 341, + /* 80 */ 342, 345, 277, 348, 349, 350, 305, 306, 353, 355, + /* 90 */ 361, 364, 224, 271, 292, 308, 365, 372, 373, 378, + /* 100 */ 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, + /* 110 */ 390, 391, 392, 393, 395, 396, 397, 399, 401, 402, + /* 120 */ 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + /* 130 */ 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, + /* 140 */ 424, 426, 427, 428, 429, 430, 431, 432, 433, 434, + /* 150 */ 435, 436, 437, 438, 369, 439, 440, 286, 287, 288, + /* 160 */ 291, 442, 443, 293, 304, 309, 303, 315, 318, 310, + /* 170 */ 319, 446, 307, 447, 448, 450, 451, 452, 456, 454, + /* 180 */ 455, 458, 461, 459, 462, 465, 468, 469, 471, 467, + /* 190 */ 470, 476, 477, 482, 485, 483, 487, 489, 491, 492, + /* 200 */ 490, 486, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 852, 914, 902, 911, 1121, 1121, 1121, 852, 852, 852, - /* 10 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 20 */ 852, 1028, 872, 1121, 852, 852, 852, 852, 852, 852, - /* 30 */ 852, 1043, 852, 911, 852, 852, 852, 852, 920, 911, - /* 40 */ 920, 920, 852, 1023, 852, 852, 852, 852, 852, 852, - /* 50 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 60 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 70 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 80 */ 1030, 1036, 1033, 852, 852, 852, 1038, 852, 852, 852, - /* 90 */ 1062, 1062, 1021, 852, 852, 852, 852, 852, 852, 852, - /* 100 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 110 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 120 */ 852, 852, 852, 852, 900, 852, 898, 852, 852, 852, - /* 130 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 140 */ 852, 852, 852, 883, 852, 852, 852, 852, 852, 852, - /* 150 */ 870, 874, 874, 874, 852, 852, 852, 852, 874, 874, - /* 160 */ 1069, 1073, 1055, 1067, 1063, 1050, 1048, 1046, 1054, 1077, - /* 170 */ 874, 874, 874, 918, 918, 911, 874, 874, 936, 934, - /* 180 */ 932, 924, 930, 926, 928, 922, 852, 874, 874, 909, - /* 190 */ 909, 874, 909, 874, 909, 874, 874, 957, 973, 852, - /* 200 */ 1078, 1068, 852, 1120, 1108, 1107, 1116, 1115, 1114, 1106, - /* 210 */ 1105, 1104, 852, 852, 852, 1100, 1103, 1102, 1101, 852, - /* 220 */ 852, 852, 852, 1110, 1109, 852, 852, 852, 852, 852, - /* 230 */ 852, 852, 852, 852, 852, 1074, 1070, 852, 852, 852, - /* 240 */ 852, 852, 852, 852, 852, 852, 1080, 852, 852, 852, - /* 250 */ 852, 852, 852, 852, 852, 852, 981, 852, 852, 852, - /* 260 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 1020, - /* 270 */ 852, 852, 852, 852, 1032, 1031, 852, 852, 852, 852, - /* 280 */ 852, 852, 852, 852, 852, 852, 852, 1064, 852, 1056, - /* 290 */ 852, 852, 993, 852, 852, 852, 852, 852, 852, 852, - /* 300 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 310 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 320 */ 852, 852, 852, 852, 1139, 1134, 1135, 1132, 852, 852, - /* 330 */ 852, 1131, 1126, 1127, 852, 852, 852, 1124, 852, 852, - /* 340 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, - /* 350 */ 852, 852, 942, 852, 881, 879, 852, 852, + /* 0 */ 890, 953, 940, 949, 1174, 1174, 1174, 890, 890, 890, + /* 10 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 20 */ 890, 1081, 910, 1174, 890, 890, 890, 890, 890, 890, + /* 30 */ 890, 1096, 890, 949, 890, 890, 890, 890, 959, 949, + /* 40 */ 959, 959, 890, 1076, 890, 890, 890, 890, 890, 890, + /* 50 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 60 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 70 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 80 */ 890, 890, 1083, 1089, 1086, 890, 890, 890, 1091, 890, + /* 90 */ 890, 890, 1115, 1115, 1074, 890, 890, 890, 890, 890, + /* 100 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 110 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 120 */ 890, 890, 890, 890, 890, 890, 890, 938, 890, 936, + /* 130 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 140 */ 890, 890, 890, 890, 890, 890, 921, 890, 890, 890, + /* 150 */ 890, 890, 890, 908, 912, 912, 912, 890, 890, 890, + /* 160 */ 890, 912, 912, 1122, 1126, 1108, 1120, 1116, 1103, 1101, + /* 170 */ 1099, 1107, 1130, 912, 912, 912, 957, 957, 949, 912, + /* 180 */ 912, 975, 973, 971, 963, 969, 965, 967, 961, 890, + /* 190 */ 912, 912, 947, 947, 912, 947, 912, 947, 912, 912, + /* 200 */ 997, 1014, 890, 1131, 1121, 890, 1173, 1161, 1160, 1169, + /* 210 */ 1168, 1167, 1159, 1158, 1157, 890, 890, 890, 1153, 1156, + /* 220 */ 1155, 1154, 890, 890, 890, 890, 1163, 1162, 890, 890, + /* 230 */ 890, 890, 890, 890, 890, 890, 890, 890, 1127, 1123, + /* 240 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 250 */ 890, 1133, 890, 890, 890, 890, 890, 890, 890, 890, + /* 260 */ 890, 1022, 890, 890, 890, 890, 890, 890, 890, 890, + /* 270 */ 890, 890, 890, 890, 1073, 890, 890, 890, 890, 1085, + /* 280 */ 1084, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 290 */ 890, 890, 1117, 890, 1109, 890, 890, 1034, 890, 890, + /* 300 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 310 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 320 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 330 */ 890, 890, 1192, 1187, 1188, 1185, 890, 890, 890, 1184, + /* 340 */ 1179, 1180, 890, 890, 890, 1177, 890, 890, 890, 890, + /* 350 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, + /* 360 */ 981, 890, 919, 917, 890, 890, }; /********** End of lemon-generated parsing tables *****************************/ @@ -509,16 +516,10 @@ static const YYCODETYPE yyFallback[] = { 0, /* $ => nothing */ 0, /* ID => nothing */ 1, /* BOOL => ID */ - 1, /* TINYINT => ID */ - 1, /* SMALLINT => ID */ 1, /* INTEGER => ID */ - 1, /* BIGINT => ID */ 1, /* FLOAT => ID */ - 1, /* DOUBLE => ID */ 1, /* STRING => ID */ 1, /* TIMESTAMP => ID */ - 1, /* BINARY => ID */ - 1, /* NCHAR => ID */ 0, /* OR => nothing */ 0, /* AND => nothing */ 0, /* NOT => nothing */ @@ -594,6 +595,8 @@ static const YYCODETYPE yyFallback[] = { 0, /* RP => nothing */ 0, /* IF => nothing */ 0, /* EXISTS => nothing */ + 0, /* PORT => nothing */ + 1, /* IPTOKEN => ID */ 0, /* AS => nothing */ 0, /* OUTPUTTYPE => nothing */ 0, /* AGGREGATE => nothing */ @@ -691,7 +694,6 @@ static const YYCODETYPE yyFallback[] = { 1, /* STATEMENT => ID */ 1, /* TRIGGER => ID */ 1, /* VIEW => ID */ - 1, /* IPTOKEN => ID */ 1, /* SEMI => ID */ 1, /* NONE => ID */ 1, /* PREV => ID */ @@ -791,278 +793,276 @@ static const char *const yyTokenName[] = { /* 0 */ "$", /* 1 */ "ID", /* 2 */ "BOOL", - /* 3 */ "TINYINT", - /* 4 */ "SMALLINT", - /* 5 */ "INTEGER", - /* 6 */ "BIGINT", - /* 7 */ "FLOAT", - /* 8 */ "DOUBLE", - /* 9 */ "STRING", - /* 10 */ "TIMESTAMP", - /* 11 */ "BINARY", - /* 12 */ "NCHAR", - /* 13 */ "OR", - /* 14 */ "AND", - /* 15 */ "NOT", - /* 16 */ "EQ", - /* 17 */ "NE", - /* 18 */ "ISNULL", - /* 19 */ "NOTNULL", - /* 20 */ "IS", - /* 21 */ "LIKE", - /* 22 */ "MATCH", - /* 23 */ "NMATCH", - /* 24 */ "GLOB", - /* 25 */ "BETWEEN", - /* 26 */ "IN", - /* 27 */ "GT", - /* 28 */ "GE", - /* 29 */ "LT", - /* 30 */ "LE", - /* 31 */ "BITAND", - /* 32 */ "BITOR", - /* 33 */ "LSHIFT", - /* 34 */ "RSHIFT", - /* 35 */ "PLUS", - /* 36 */ "MINUS", - /* 37 */ "DIVIDE", - /* 38 */ "TIMES", - /* 39 */ "STAR", - /* 40 */ "SLASH", - /* 41 */ "REM", - /* 42 */ "CONCAT", - /* 43 */ "UMINUS", - /* 44 */ "UPLUS", - /* 45 */ "BITNOT", - /* 46 */ "SHOW", - /* 47 */ "DATABASES", - /* 48 */ "TOPICS", - /* 49 */ "FUNCTIONS", - /* 50 */ "MNODES", - /* 51 */ "DNODES", - /* 52 */ "ACCOUNTS", - /* 53 */ "USERS", - /* 54 */ "MODULES", - /* 55 */ "QUERIES", - /* 56 */ "CONNECTIONS", - /* 57 */ "STREAMS", - /* 58 */ "VARIABLES", - /* 59 */ "SCORES", - /* 60 */ "GRANTS", - /* 61 */ "VNODES", - /* 62 */ "DOT", - /* 63 */ "CREATE", - /* 64 */ "TABLE", - /* 65 */ "STABLE", - /* 66 */ "DATABASE", - /* 67 */ "TABLES", - /* 68 */ "STABLES", - /* 69 */ "VGROUPS", - /* 70 */ "DROP", - /* 71 */ "TOPIC", - /* 72 */ "FUNCTION", - /* 73 */ "DNODE", - /* 74 */ "USER", - /* 75 */ "ACCOUNT", - /* 76 */ "USE", - /* 77 */ "DESCRIBE", - /* 78 */ "DESC", - /* 79 */ "ALTER", - /* 80 */ "PASS", - /* 81 */ "PRIVILEGE", - /* 82 */ "LOCAL", - /* 83 */ "COMPACT", - /* 84 */ "LP", - /* 85 */ "RP", - /* 86 */ "IF", - /* 87 */ "EXISTS", - /* 88 */ "AS", - /* 89 */ "OUTPUTTYPE", - /* 90 */ "AGGREGATE", - /* 91 */ "BUFSIZE", - /* 92 */ "PPS", - /* 93 */ "TSERIES", - /* 94 */ "DBS", - /* 95 */ "STORAGE", - /* 96 */ "QTIME", - /* 97 */ "CONNS", - /* 98 */ "STATE", - /* 99 */ "COMMA", - /* 100 */ "KEEP", - /* 101 */ "CACHE", - /* 102 */ "REPLICA", - /* 103 */ "QUORUM", - /* 104 */ "DAYS", - /* 105 */ "MINROWS", - /* 106 */ "MAXROWS", - /* 107 */ "BLOCKS", - /* 108 */ "CTIME", - /* 109 */ "WAL", - /* 110 */ "FSYNC", - /* 111 */ "COMP", - /* 112 */ "PRECISION", - /* 113 */ "UPDATE", - /* 114 */ "CACHELAST", - /* 115 */ "UNSIGNED", - /* 116 */ "TAGS", - /* 117 */ "USING", - /* 118 */ "NULL", - /* 119 */ "NOW", - /* 120 */ "SELECT", - /* 121 */ "UNION", - /* 122 */ "ALL", - /* 123 */ "DISTINCT", - /* 124 */ "FROM", - /* 125 */ "VARIABLE", - /* 126 */ "INTERVAL", - /* 127 */ "EVERY", - /* 128 */ "SESSION", - /* 129 */ "STATE_WINDOW", - /* 130 */ "FILL", - /* 131 */ "SLIDING", - /* 132 */ "ORDER", - /* 133 */ "BY", - /* 134 */ "ASC", - /* 135 */ "GROUP", - /* 136 */ "HAVING", - /* 137 */ "LIMIT", - /* 138 */ "OFFSET", - /* 139 */ "SLIMIT", - /* 140 */ "SOFFSET", - /* 141 */ "WHERE", - /* 142 */ "RESET", - /* 143 */ "QUERY", - /* 144 */ "SYNCDB", - /* 145 */ "ADD", - /* 146 */ "COLUMN", - /* 147 */ "MODIFY", - /* 148 */ "TAG", - /* 149 */ "CHANGE", - /* 150 */ "SET", - /* 151 */ "KILL", - /* 152 */ "CONNECTION", - /* 153 */ "STREAM", - /* 154 */ "COLON", - /* 155 */ "ABORT", - /* 156 */ "AFTER", - /* 157 */ "ATTACH", - /* 158 */ "BEFORE", - /* 159 */ "BEGIN", - /* 160 */ "CASCADE", - /* 161 */ "CLUSTER", - /* 162 */ "CONFLICT", - /* 163 */ "COPY", - /* 164 */ "DEFERRED", - /* 165 */ "DELIMITERS", - /* 166 */ "DETACH", - /* 167 */ "EACH", - /* 168 */ "END", - /* 169 */ "EXPLAIN", - /* 170 */ "FAIL", - /* 171 */ "FOR", - /* 172 */ "IGNORE", - /* 173 */ "IMMEDIATE", - /* 174 */ "INITIALLY", - /* 175 */ "INSTEAD", - /* 176 */ "KEY", - /* 177 */ "OF", - /* 178 */ "RAISE", - /* 179 */ "REPLACE", - /* 180 */ "RESTRICT", - /* 181 */ "ROW", - /* 182 */ "STATEMENT", - /* 183 */ "TRIGGER", - /* 184 */ "VIEW", - /* 185 */ "IPTOKEN", - /* 186 */ "SEMI", - /* 187 */ "NONE", - /* 188 */ "PREV", - /* 189 */ "LINEAR", - /* 190 */ "IMPORT", - /* 191 */ "TBNAME", - /* 192 */ "JOIN", - /* 193 */ "INSERT", - /* 194 */ "INTO", - /* 195 */ "VALUES", - /* 196 */ "error", - /* 197 */ "program", - /* 198 */ "cmd", - /* 199 */ "ids", - /* 200 */ "dbPrefix", - /* 201 */ "cpxName", - /* 202 */ "ifexists", - /* 203 */ "alter_db_optr", - /* 204 */ "acct_optr", - /* 205 */ "exprlist", - /* 206 */ "ifnotexists", - /* 207 */ "db_optr", - /* 208 */ "typename", - /* 209 */ "bufsize", - /* 210 */ "pps", - /* 211 */ "tseries", - /* 212 */ "dbs", - /* 213 */ "streams", - /* 214 */ "storage", - /* 215 */ "qtime", - /* 216 */ "users", - /* 217 */ "conns", - /* 218 */ "state", - /* 219 */ "intitemlist", - /* 220 */ "intitem", - /* 221 */ "keep", - /* 222 */ "cache", - /* 223 */ "replica", - /* 224 */ "quorum", - /* 225 */ "days", - /* 226 */ "minrows", - /* 227 */ "maxrows", - /* 228 */ "blocks", - /* 229 */ "ctime", - /* 230 */ "wal", - /* 231 */ "fsync", - /* 232 */ "comp", - /* 233 */ "prec", - /* 234 */ "update", - /* 235 */ "cachelast", - /* 236 */ "signed", - /* 237 */ "create_table_args", - /* 238 */ "create_stable_args", - /* 239 */ "create_table_list", - /* 240 */ "create_from_stable", - /* 241 */ "columnlist", - /* 242 */ "tagitemlist", - /* 243 */ "tagNamelist", - /* 244 */ "select", - /* 245 */ "column", - /* 246 */ "tagitem", - /* 247 */ "selcollist", - /* 248 */ "from", - /* 249 */ "where_opt", - /* 250 */ "interval_option", - /* 251 */ "sliding_opt", - /* 252 */ "session_option", - /* 253 */ "windowstate_option", - /* 254 */ "fill_opt", - /* 255 */ "groupby_opt", - /* 256 */ "having_opt", - /* 257 */ "orderby_opt", - /* 258 */ "slimit_opt", - /* 259 */ "limit_opt", - /* 260 */ "union", - /* 261 */ "sclp", - /* 262 */ "distinct", - /* 263 */ "expr", - /* 264 */ "as", - /* 265 */ "tablelist", - /* 266 */ "sub", - /* 267 */ "tmvar", - /* 268 */ "intervalKey", - /* 269 */ "sortlist", - /* 270 */ "sortitem", - /* 271 */ "item", - /* 272 */ "sortorder", - /* 273 */ "grouplist", - /* 274 */ "expritem", + /* 3 */ "INTEGER", + /* 4 */ "FLOAT", + /* 5 */ "STRING", + /* 6 */ "TIMESTAMP", + /* 7 */ "OR", + /* 8 */ "AND", + /* 9 */ "NOT", + /* 10 */ "EQ", + /* 11 */ "NE", + /* 12 */ "ISNULL", + /* 13 */ "NOTNULL", + /* 14 */ "IS", + /* 15 */ "LIKE", + /* 16 */ "MATCH", + /* 17 */ "NMATCH", + /* 18 */ "GLOB", + /* 19 */ "BETWEEN", + /* 20 */ "IN", + /* 21 */ "GT", + /* 22 */ "GE", + /* 23 */ "LT", + /* 24 */ "LE", + /* 25 */ "BITAND", + /* 26 */ "BITOR", + /* 27 */ "LSHIFT", + /* 28 */ "RSHIFT", + /* 29 */ "PLUS", + /* 30 */ "MINUS", + /* 31 */ "DIVIDE", + /* 32 */ "TIMES", + /* 33 */ "STAR", + /* 34 */ "SLASH", + /* 35 */ "REM", + /* 36 */ "CONCAT", + /* 37 */ "UMINUS", + /* 38 */ "UPLUS", + /* 39 */ "BITNOT", + /* 40 */ "SHOW", + /* 41 */ "DATABASES", + /* 42 */ "TOPICS", + /* 43 */ "FUNCTIONS", + /* 44 */ "MNODES", + /* 45 */ "DNODES", + /* 46 */ "ACCOUNTS", + /* 47 */ "USERS", + /* 48 */ "MODULES", + /* 49 */ "QUERIES", + /* 50 */ "CONNECTIONS", + /* 51 */ "STREAMS", + /* 52 */ "VARIABLES", + /* 53 */ "SCORES", + /* 54 */ "GRANTS", + /* 55 */ "VNODES", + /* 56 */ "DOT", + /* 57 */ "CREATE", + /* 58 */ "TABLE", + /* 59 */ "STABLE", + /* 60 */ "DATABASE", + /* 61 */ "TABLES", + /* 62 */ "STABLES", + /* 63 */ "VGROUPS", + /* 64 */ "DROP", + /* 65 */ "TOPIC", + /* 66 */ "FUNCTION", + /* 67 */ "DNODE", + /* 68 */ "USER", + /* 69 */ "ACCOUNT", + /* 70 */ "USE", + /* 71 */ "DESCRIBE", + /* 72 */ "DESC", + /* 73 */ "ALTER", + /* 74 */ "PASS", + /* 75 */ "PRIVILEGE", + /* 76 */ "LOCAL", + /* 77 */ "COMPACT", + /* 78 */ "LP", + /* 79 */ "RP", + /* 80 */ "IF", + /* 81 */ "EXISTS", + /* 82 */ "PORT", + /* 83 */ "IPTOKEN", + /* 84 */ "AS", + /* 85 */ "OUTPUTTYPE", + /* 86 */ "AGGREGATE", + /* 87 */ "BUFSIZE", + /* 88 */ "PPS", + /* 89 */ "TSERIES", + /* 90 */ "DBS", + /* 91 */ "STORAGE", + /* 92 */ "QTIME", + /* 93 */ "CONNS", + /* 94 */ "STATE", + /* 95 */ "COMMA", + /* 96 */ "KEEP", + /* 97 */ "CACHE", + /* 98 */ "REPLICA", + /* 99 */ "QUORUM", + /* 100 */ "DAYS", + /* 101 */ "MINROWS", + /* 102 */ "MAXROWS", + /* 103 */ "BLOCKS", + /* 104 */ "CTIME", + /* 105 */ "WAL", + /* 106 */ "FSYNC", + /* 107 */ "COMP", + /* 108 */ "PRECISION", + /* 109 */ "UPDATE", + /* 110 */ "CACHELAST", + /* 111 */ "UNSIGNED", + /* 112 */ "TAGS", + /* 113 */ "USING", + /* 114 */ "NULL", + /* 115 */ "NOW", + /* 116 */ "SELECT", + /* 117 */ "UNION", + /* 118 */ "ALL", + /* 119 */ "DISTINCT", + /* 120 */ "FROM", + /* 121 */ "VARIABLE", + /* 122 */ "INTERVAL", + /* 123 */ "EVERY", + /* 124 */ "SESSION", + /* 125 */ "STATE_WINDOW", + /* 126 */ "FILL", + /* 127 */ "SLIDING", + /* 128 */ "ORDER", + /* 129 */ "BY", + /* 130 */ "ASC", + /* 131 */ "GROUP", + /* 132 */ "HAVING", + /* 133 */ "LIMIT", + /* 134 */ "OFFSET", + /* 135 */ "SLIMIT", + /* 136 */ "SOFFSET", + /* 137 */ "WHERE", + /* 138 */ "RESET", + /* 139 */ "QUERY", + /* 140 */ "SYNCDB", + /* 141 */ "ADD", + /* 142 */ "COLUMN", + /* 143 */ "MODIFY", + /* 144 */ "TAG", + /* 145 */ "CHANGE", + /* 146 */ "SET", + /* 147 */ "KILL", + /* 148 */ "CONNECTION", + /* 149 */ "STREAM", + /* 150 */ "COLON", + /* 151 */ "ABORT", + /* 152 */ "AFTER", + /* 153 */ "ATTACH", + /* 154 */ "BEFORE", + /* 155 */ "BEGIN", + /* 156 */ "CASCADE", + /* 157 */ "CLUSTER", + /* 158 */ "CONFLICT", + /* 159 */ "COPY", + /* 160 */ "DEFERRED", + /* 161 */ "DELIMITERS", + /* 162 */ "DETACH", + /* 163 */ "EACH", + /* 164 */ "END", + /* 165 */ "EXPLAIN", + /* 166 */ "FAIL", + /* 167 */ "FOR", + /* 168 */ "IGNORE", + /* 169 */ "IMMEDIATE", + /* 170 */ "INITIALLY", + /* 171 */ "INSTEAD", + /* 172 */ "KEY", + /* 173 */ "OF", + /* 174 */ "RAISE", + /* 175 */ "REPLACE", + /* 176 */ "RESTRICT", + /* 177 */ "ROW", + /* 178 */ "STATEMENT", + /* 179 */ "TRIGGER", + /* 180 */ "VIEW", + /* 181 */ "SEMI", + /* 182 */ "NONE", + /* 183 */ "PREV", + /* 184 */ "LINEAR", + /* 185 */ "IMPORT", + /* 186 */ "TBNAME", + /* 187 */ "JOIN", + /* 188 */ "INSERT", + /* 189 */ "INTO", + /* 190 */ "VALUES", + /* 191 */ "error", + /* 192 */ "program", + /* 193 */ "cmd", + /* 194 */ "ids", + /* 195 */ "dbPrefix", + /* 196 */ "cpxName", + /* 197 */ "ifexists", + /* 198 */ "alter_db_optr", + /* 199 */ "acct_optr", + /* 200 */ "exprlist", + /* 201 */ "ifnotexists", + /* 202 */ "db_optr", + /* 203 */ "typename", + /* 204 */ "bufsize", + /* 205 */ "pps", + /* 206 */ "tseries", + /* 207 */ "dbs", + /* 208 */ "streams", + /* 209 */ "storage", + /* 210 */ "qtime", + /* 211 */ "users", + /* 212 */ "conns", + /* 213 */ "state", + /* 214 */ "intitemlist", + /* 215 */ "intitem", + /* 216 */ "keep", + /* 217 */ "cache", + /* 218 */ "replica", + /* 219 */ "quorum", + /* 220 */ "days", + /* 221 */ "minrows", + /* 222 */ "maxrows", + /* 223 */ "blocks", + /* 224 */ "ctime", + /* 225 */ "wal", + /* 226 */ "fsync", + /* 227 */ "comp", + /* 228 */ "prec", + /* 229 */ "update", + /* 230 */ "cachelast", + /* 231 */ "vgroups", + /* 232 */ "signed", + /* 233 */ "create_table_args", + /* 234 */ "create_stable_args", + /* 235 */ "create_table_list", + /* 236 */ "create_from_stable", + /* 237 */ "columnlist", + /* 238 */ "tagitemlist1", + /* 239 */ "tagNamelist", + /* 240 */ "select", + /* 241 */ "column", + /* 242 */ "tagitem1", + /* 243 */ "tagitemlist", + /* 244 */ "tagitem", + /* 245 */ "selcollist", + /* 246 */ "from", + /* 247 */ "where_opt", + /* 248 */ "interval_option", + /* 249 */ "sliding_opt", + /* 250 */ "session_option", + /* 251 */ "windowstate_option", + /* 252 */ "fill_opt", + /* 253 */ "groupby_opt", + /* 254 */ "having_opt", + /* 255 */ "orderby_opt", + /* 256 */ "slimit_opt", + /* 257 */ "limit_opt", + /* 258 */ "union", + /* 259 */ "sclp", + /* 260 */ "distinct", + /* 261 */ "expr", + /* 262 */ "as", + /* 263 */ "tablelist", + /* 264 */ "sub", + /* 265 */ "tmvar", + /* 266 */ "intervalKey", + /* 267 */ "sortlist", + /* 268 */ "sortitem", + /* 269 */ "item", + /* 270 */ "sortorder", + /* 271 */ "grouplist", + /* 272 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1127,237 +1127,252 @@ static const char *const yyRuleName[] = { /* 54 */ "ifexists ::=", /* 55 */ "ifnotexists ::= IF NOT EXISTS", /* 56 */ "ifnotexists ::=", - /* 57 */ "cmd ::= CREATE DNODE ids", - /* 58 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 59 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 60 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 61 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 62 */ "cmd ::= CREATE USER ids PASS ids", - /* 63 */ "bufsize ::=", - /* 64 */ "bufsize ::= BUFSIZE INTEGER", - /* 65 */ "pps ::=", - /* 66 */ "pps ::= PPS INTEGER", - /* 67 */ "tseries ::=", - /* 68 */ "tseries ::= TSERIES INTEGER", - /* 69 */ "dbs ::=", - /* 70 */ "dbs ::= DBS INTEGER", - /* 71 */ "streams ::=", - /* 72 */ "streams ::= STREAMS INTEGER", - /* 73 */ "storage ::=", - /* 74 */ "storage ::= STORAGE INTEGER", - /* 75 */ "qtime ::=", - /* 76 */ "qtime ::= QTIME INTEGER", - /* 77 */ "users ::=", - /* 78 */ "users ::= USERS INTEGER", - /* 79 */ "conns ::=", - /* 80 */ "conns ::= CONNS INTEGER", - /* 81 */ "state ::=", - /* 82 */ "state ::= STATE ids", - /* 83 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 84 */ "intitemlist ::= intitemlist COMMA intitem", - /* 85 */ "intitemlist ::= intitem", - /* 86 */ "intitem ::= INTEGER", - /* 87 */ "keep ::= KEEP intitemlist", - /* 88 */ "cache ::= CACHE INTEGER", - /* 89 */ "replica ::= REPLICA INTEGER", - /* 90 */ "quorum ::= QUORUM INTEGER", - /* 91 */ "days ::= DAYS INTEGER", - /* 92 */ "minrows ::= MINROWS INTEGER", - /* 93 */ "maxrows ::= MAXROWS INTEGER", - /* 94 */ "blocks ::= BLOCKS INTEGER", - /* 95 */ "ctime ::= CTIME INTEGER", - /* 96 */ "wal ::= WAL INTEGER", - /* 97 */ "fsync ::= FSYNC INTEGER", - /* 98 */ "comp ::= COMP INTEGER", - /* 99 */ "prec ::= PRECISION STRING", - /* 100 */ "update ::= UPDATE INTEGER", - /* 101 */ "cachelast ::= CACHELAST INTEGER", - /* 102 */ "db_optr ::=", - /* 103 */ "db_optr ::= db_optr cache", - /* 104 */ "db_optr ::= db_optr replica", - /* 105 */ "db_optr ::= db_optr quorum", - /* 106 */ "db_optr ::= db_optr days", - /* 107 */ "db_optr ::= db_optr minrows", - /* 108 */ "db_optr ::= db_optr maxrows", - /* 109 */ "db_optr ::= db_optr blocks", - /* 110 */ "db_optr ::= db_optr ctime", - /* 111 */ "db_optr ::= db_optr wal", - /* 112 */ "db_optr ::= db_optr fsync", - /* 113 */ "db_optr ::= db_optr comp", - /* 114 */ "db_optr ::= db_optr prec", - /* 115 */ "db_optr ::= db_optr keep", - /* 116 */ "db_optr ::= db_optr update", - /* 117 */ "db_optr ::= db_optr cachelast", - /* 118 */ "alter_db_optr ::=", - /* 119 */ "alter_db_optr ::= alter_db_optr replica", - /* 120 */ "alter_db_optr ::= alter_db_optr quorum", - /* 121 */ "alter_db_optr ::= alter_db_optr keep", - /* 122 */ "alter_db_optr ::= alter_db_optr blocks", - /* 123 */ "alter_db_optr ::= alter_db_optr comp", - /* 124 */ "alter_db_optr ::= alter_db_optr update", - /* 125 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 126 */ "typename ::= ids", - /* 127 */ "typename ::= ids LP signed RP", - /* 128 */ "typename ::= ids UNSIGNED", - /* 129 */ "signed ::= INTEGER", - /* 130 */ "signed ::= PLUS INTEGER", - /* 131 */ "signed ::= MINUS INTEGER", - /* 132 */ "cmd ::= CREATE TABLE create_table_args", - /* 133 */ "cmd ::= CREATE TABLE create_stable_args", - /* 134 */ "cmd ::= CREATE STABLE create_stable_args", - /* 135 */ "cmd ::= CREATE TABLE create_table_list", - /* 136 */ "create_table_list ::= create_from_stable", - /* 137 */ "create_table_list ::= create_table_list create_from_stable", - /* 138 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 139 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 140 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", - /* 141 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", - /* 142 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 143 */ "tagNamelist ::= ids", - /* 144 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 145 */ "columnlist ::= columnlist COMMA column", - /* 146 */ "columnlist ::= column", - /* 147 */ "column ::= ids typename", - /* 148 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 149 */ "tagitemlist ::= tagitem", - /* 150 */ "tagitem ::= INTEGER", - /* 151 */ "tagitem ::= FLOAT", - /* 152 */ "tagitem ::= STRING", - /* 153 */ "tagitem ::= BOOL", - /* 154 */ "tagitem ::= NULL", - /* 155 */ "tagitem ::= NOW", - /* 156 */ "tagitem ::= MINUS INTEGER", - /* 157 */ "tagitem ::= MINUS FLOAT", - /* 158 */ "tagitem ::= PLUS INTEGER", - /* 159 */ "tagitem ::= PLUS FLOAT", - /* 160 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", - /* 161 */ "select ::= LP select RP", - /* 162 */ "union ::= select", - /* 163 */ "union ::= union UNION ALL select", - /* 164 */ "union ::= union UNION select", - /* 165 */ "cmd ::= union", - /* 166 */ "select ::= SELECT selcollist", - /* 167 */ "sclp ::= selcollist COMMA", - /* 168 */ "sclp ::=", - /* 169 */ "selcollist ::= sclp distinct expr as", - /* 170 */ "selcollist ::= sclp STAR", - /* 171 */ "as ::= AS ids", - /* 172 */ "as ::= ids", - /* 173 */ "as ::=", - /* 174 */ "distinct ::= DISTINCT", - /* 175 */ "distinct ::=", - /* 176 */ "from ::= FROM tablelist", - /* 177 */ "from ::= FROM sub", - /* 178 */ "sub ::= LP union RP", - /* 179 */ "sub ::= LP union RP ids", - /* 180 */ "sub ::= sub COMMA LP union RP ids", - /* 181 */ "tablelist ::= ids cpxName", - /* 182 */ "tablelist ::= ids cpxName ids", - /* 183 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 184 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 185 */ "tmvar ::= VARIABLE", - /* 186 */ "interval_option ::= intervalKey LP tmvar RP", - /* 187 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 188 */ "interval_option ::=", - /* 189 */ "intervalKey ::= INTERVAL", - /* 190 */ "intervalKey ::= EVERY", - /* 191 */ "session_option ::=", - /* 192 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 193 */ "windowstate_option ::=", - /* 194 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 195 */ "fill_opt ::=", - /* 196 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 197 */ "fill_opt ::= FILL LP ID RP", - /* 198 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 199 */ "sliding_opt ::=", - /* 200 */ "orderby_opt ::=", - /* 201 */ "orderby_opt ::= ORDER BY sortlist", - /* 202 */ "sortlist ::= sortlist COMMA item sortorder", - /* 203 */ "sortlist ::= item sortorder", - /* 204 */ "item ::= ids cpxName", - /* 205 */ "sortorder ::= ASC", - /* 206 */ "sortorder ::= DESC", - /* 207 */ "sortorder ::=", - /* 208 */ "groupby_opt ::=", - /* 209 */ "groupby_opt ::= GROUP BY grouplist", - /* 210 */ "grouplist ::= grouplist COMMA item", - /* 211 */ "grouplist ::= item", - /* 212 */ "having_opt ::=", - /* 213 */ "having_opt ::= HAVING expr", - /* 214 */ "limit_opt ::=", - /* 215 */ "limit_opt ::= LIMIT signed", - /* 216 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 217 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 218 */ "slimit_opt ::=", - /* 219 */ "slimit_opt ::= SLIMIT signed", - /* 220 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 221 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 222 */ "where_opt ::=", - /* 223 */ "where_opt ::= WHERE expr", - /* 224 */ "expr ::= LP expr RP", - /* 225 */ "expr ::= ID", - /* 226 */ "expr ::= ID DOT ID", - /* 227 */ "expr ::= ID DOT STAR", - /* 228 */ "expr ::= INTEGER", - /* 229 */ "expr ::= MINUS INTEGER", - /* 230 */ "expr ::= PLUS INTEGER", - /* 231 */ "expr ::= FLOAT", - /* 232 */ "expr ::= MINUS FLOAT", - /* 233 */ "expr ::= PLUS FLOAT", - /* 234 */ "expr ::= STRING", - /* 235 */ "expr ::= NOW", - /* 236 */ "expr ::= VARIABLE", - /* 237 */ "expr ::= PLUS VARIABLE", - /* 238 */ "expr ::= MINUS VARIABLE", - /* 239 */ "expr ::= BOOL", - /* 240 */ "expr ::= NULL", - /* 241 */ "expr ::= ID LP exprlist RP", - /* 242 */ "expr ::= ID LP STAR RP", - /* 243 */ "expr ::= expr IS NULL", - /* 244 */ "expr ::= expr IS NOT NULL", - /* 245 */ "expr ::= expr LT expr", - /* 246 */ "expr ::= expr GT expr", - /* 247 */ "expr ::= expr LE expr", - /* 248 */ "expr ::= expr GE expr", - /* 249 */ "expr ::= expr NE expr", - /* 250 */ "expr ::= expr EQ expr", - /* 251 */ "expr ::= expr BETWEEN expr AND expr", - /* 252 */ "expr ::= expr AND expr", - /* 253 */ "expr ::= expr OR expr", - /* 254 */ "expr ::= expr PLUS expr", - /* 255 */ "expr ::= expr MINUS expr", - /* 256 */ "expr ::= expr STAR expr", - /* 257 */ "expr ::= expr SLASH expr", - /* 258 */ "expr ::= expr REM expr", - /* 259 */ "expr ::= expr LIKE expr", - /* 260 */ "expr ::= expr MATCH expr", - /* 261 */ "expr ::= expr NMATCH expr", - /* 262 */ "expr ::= expr IN LP exprlist RP", - /* 263 */ "exprlist ::= exprlist COMMA expritem", - /* 264 */ "exprlist ::= expritem", - /* 265 */ "expritem ::= expr", - /* 266 */ "expritem ::=", - /* 267 */ "cmd ::= RESET QUERY CACHE", - /* 268 */ "cmd ::= SYNCDB ids REPLICA", - /* 269 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 270 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 271 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 272 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 273 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 274 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 275 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 276 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 277 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 278 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 279 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 280 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 281 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 282 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 283 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 284 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 285 */ "cmd ::= KILL CONNECTION INTEGER", - /* 286 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 287 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 57 */ "cmd ::= CREATE DNODE ids PORT ids", + /* 58 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", + /* 59 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", + /* 60 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", + /* 61 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 62 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 63 */ "cmd ::= CREATE USER ids PASS ids", + /* 64 */ "bufsize ::=", + /* 65 */ "bufsize ::= BUFSIZE INTEGER", + /* 66 */ "pps ::=", + /* 67 */ "pps ::= PPS INTEGER", + /* 68 */ "tseries ::=", + /* 69 */ "tseries ::= TSERIES INTEGER", + /* 70 */ "dbs ::=", + /* 71 */ "dbs ::= DBS INTEGER", + /* 72 */ "streams ::=", + /* 73 */ "streams ::= STREAMS INTEGER", + /* 74 */ "storage ::=", + /* 75 */ "storage ::= STORAGE INTEGER", + /* 76 */ "qtime ::=", + /* 77 */ "qtime ::= QTIME INTEGER", + /* 78 */ "users ::=", + /* 79 */ "users ::= USERS INTEGER", + /* 80 */ "conns ::=", + /* 81 */ "conns ::= CONNS INTEGER", + /* 82 */ "state ::=", + /* 83 */ "state ::= STATE ids", + /* 84 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", + /* 85 */ "intitemlist ::= intitemlist COMMA intitem", + /* 86 */ "intitemlist ::= intitem", + /* 87 */ "intitem ::= INTEGER", + /* 88 */ "keep ::= KEEP intitemlist", + /* 89 */ "cache ::= CACHE INTEGER", + /* 90 */ "replica ::= REPLICA INTEGER", + /* 91 */ "quorum ::= QUORUM INTEGER", + /* 92 */ "days ::= DAYS INTEGER", + /* 93 */ "minrows ::= MINROWS INTEGER", + /* 94 */ "maxrows ::= MAXROWS INTEGER", + /* 95 */ "blocks ::= BLOCKS INTEGER", + /* 96 */ "ctime ::= CTIME INTEGER", + /* 97 */ "wal ::= WAL INTEGER", + /* 98 */ "fsync ::= FSYNC INTEGER", + /* 99 */ "comp ::= COMP INTEGER", + /* 100 */ "prec ::= PRECISION STRING", + /* 101 */ "update ::= UPDATE INTEGER", + /* 102 */ "cachelast ::= CACHELAST INTEGER", + /* 103 */ "vgroups ::= VGROUPS INTEGER", + /* 104 */ "db_optr ::=", + /* 105 */ "db_optr ::= db_optr cache", + /* 106 */ "db_optr ::= db_optr replica", + /* 107 */ "db_optr ::= db_optr quorum", + /* 108 */ "db_optr ::= db_optr days", + /* 109 */ "db_optr ::= db_optr minrows", + /* 110 */ "db_optr ::= db_optr maxrows", + /* 111 */ "db_optr ::= db_optr blocks", + /* 112 */ "db_optr ::= db_optr ctime", + /* 113 */ "db_optr ::= db_optr wal", + /* 114 */ "db_optr ::= db_optr fsync", + /* 115 */ "db_optr ::= db_optr comp", + /* 116 */ "db_optr ::= db_optr prec", + /* 117 */ "db_optr ::= db_optr keep", + /* 118 */ "db_optr ::= db_optr update", + /* 119 */ "db_optr ::= db_optr cachelast", + /* 120 */ "db_optr ::= db_optr vgroups", + /* 121 */ "alter_db_optr ::=", + /* 122 */ "alter_db_optr ::= alter_db_optr replica", + /* 123 */ "alter_db_optr ::= alter_db_optr quorum", + /* 124 */ "alter_db_optr ::= alter_db_optr keep", + /* 125 */ "alter_db_optr ::= alter_db_optr blocks", + /* 126 */ "alter_db_optr ::= alter_db_optr comp", + /* 127 */ "alter_db_optr ::= alter_db_optr update", + /* 128 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 129 */ "typename ::= ids", + /* 130 */ "typename ::= ids LP signed RP", + /* 131 */ "typename ::= ids UNSIGNED", + /* 132 */ "signed ::= INTEGER", + /* 133 */ "signed ::= PLUS INTEGER", + /* 134 */ "signed ::= MINUS INTEGER", + /* 135 */ "cmd ::= CREATE TABLE create_table_args", + /* 136 */ "cmd ::= CREATE TABLE create_stable_args", + /* 137 */ "cmd ::= CREATE STABLE create_stable_args", + /* 138 */ "cmd ::= CREATE TABLE create_table_list", + /* 139 */ "create_table_list ::= create_from_stable", + /* 140 */ "create_table_list ::= create_table_list create_from_stable", + /* 141 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 142 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", + /* 144 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", + /* 145 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 146 */ "tagNamelist ::= ids", + /* 147 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 148 */ "columnlist ::= columnlist COMMA column", + /* 149 */ "columnlist ::= column", + /* 150 */ "column ::= ids typename", + /* 151 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", + /* 152 */ "tagitemlist1 ::= tagitem1", + /* 153 */ "tagitem1 ::= MINUS INTEGER", + /* 154 */ "tagitem1 ::= MINUS FLOAT", + /* 155 */ "tagitem1 ::= PLUS INTEGER", + /* 156 */ "tagitem1 ::= PLUS FLOAT", + /* 157 */ "tagitem1 ::= INTEGER", + /* 158 */ "tagitem1 ::= FLOAT", + /* 159 */ "tagitem1 ::= STRING", + /* 160 */ "tagitem1 ::= BOOL", + /* 161 */ "tagitem1 ::= NULL", + /* 162 */ "tagitem1 ::= NOW", + /* 163 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 164 */ "tagitemlist ::= tagitem", + /* 165 */ "tagitem ::= INTEGER", + /* 166 */ "tagitem ::= FLOAT", + /* 167 */ "tagitem ::= STRING", + /* 168 */ "tagitem ::= BOOL", + /* 169 */ "tagitem ::= NULL", + /* 170 */ "tagitem ::= NOW", + /* 171 */ "tagitem ::= MINUS INTEGER", + /* 172 */ "tagitem ::= MINUS FLOAT", + /* 173 */ "tagitem ::= PLUS INTEGER", + /* 174 */ "tagitem ::= PLUS FLOAT", + /* 175 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 176 */ "select ::= LP select RP", + /* 177 */ "union ::= select", + /* 178 */ "union ::= union UNION ALL select", + /* 179 */ "union ::= union UNION select", + /* 180 */ "cmd ::= union", + /* 181 */ "select ::= SELECT selcollist", + /* 182 */ "sclp ::= selcollist COMMA", + /* 183 */ "sclp ::=", + /* 184 */ "selcollist ::= sclp distinct expr as", + /* 185 */ "selcollist ::= sclp STAR", + /* 186 */ "as ::= AS ids", + /* 187 */ "as ::= ids", + /* 188 */ "as ::=", + /* 189 */ "distinct ::= DISTINCT", + /* 190 */ "distinct ::=", + /* 191 */ "from ::= FROM tablelist", + /* 192 */ "from ::= FROM sub", + /* 193 */ "sub ::= LP union RP", + /* 194 */ "sub ::= LP union RP ids", + /* 195 */ "sub ::= sub COMMA LP union RP ids", + /* 196 */ "tablelist ::= ids cpxName", + /* 197 */ "tablelist ::= ids cpxName ids", + /* 198 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 199 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 200 */ "tmvar ::= VARIABLE", + /* 201 */ "interval_option ::= intervalKey LP tmvar RP", + /* 202 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 203 */ "interval_option ::=", + /* 204 */ "intervalKey ::= INTERVAL", + /* 205 */ "intervalKey ::= EVERY", + /* 206 */ "session_option ::=", + /* 207 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 208 */ "windowstate_option ::=", + /* 209 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 210 */ "fill_opt ::=", + /* 211 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 212 */ "fill_opt ::= FILL LP ID RP", + /* 213 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 214 */ "sliding_opt ::=", + /* 215 */ "orderby_opt ::=", + /* 216 */ "orderby_opt ::= ORDER BY sortlist", + /* 217 */ "sortlist ::= sortlist COMMA item sortorder", + /* 218 */ "sortlist ::= item sortorder", + /* 219 */ "item ::= ids cpxName", + /* 220 */ "sortorder ::= ASC", + /* 221 */ "sortorder ::= DESC", + /* 222 */ "sortorder ::=", + /* 223 */ "groupby_opt ::=", + /* 224 */ "groupby_opt ::= GROUP BY grouplist", + /* 225 */ "grouplist ::= grouplist COMMA item", + /* 226 */ "grouplist ::= item", + /* 227 */ "having_opt ::=", + /* 228 */ "having_opt ::= HAVING expr", + /* 229 */ "limit_opt ::=", + /* 230 */ "limit_opt ::= LIMIT signed", + /* 231 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 232 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 233 */ "slimit_opt ::=", + /* 234 */ "slimit_opt ::= SLIMIT signed", + /* 235 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 236 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 237 */ "where_opt ::=", + /* 238 */ "where_opt ::= WHERE expr", + /* 239 */ "expr ::= LP expr RP", + /* 240 */ "expr ::= ID", + /* 241 */ "expr ::= ID DOT ID", + /* 242 */ "expr ::= ID DOT STAR", + /* 243 */ "expr ::= INTEGER", + /* 244 */ "expr ::= MINUS INTEGER", + /* 245 */ "expr ::= PLUS INTEGER", + /* 246 */ "expr ::= FLOAT", + /* 247 */ "expr ::= MINUS FLOAT", + /* 248 */ "expr ::= PLUS FLOAT", + /* 249 */ "expr ::= STRING", + /* 250 */ "expr ::= NOW", + /* 251 */ "expr ::= VARIABLE", + /* 252 */ "expr ::= PLUS VARIABLE", + /* 253 */ "expr ::= MINUS VARIABLE", + /* 254 */ "expr ::= BOOL", + /* 255 */ "expr ::= NULL", + /* 256 */ "expr ::= ID LP exprlist RP", + /* 257 */ "expr ::= ID LP STAR RP", + /* 258 */ "expr ::= expr IS NULL", + /* 259 */ "expr ::= expr IS NOT NULL", + /* 260 */ "expr ::= expr LT expr", + /* 261 */ "expr ::= expr GT expr", + /* 262 */ "expr ::= expr LE expr", + /* 263 */ "expr ::= expr GE expr", + /* 264 */ "expr ::= expr NE expr", + /* 265 */ "expr ::= expr EQ expr", + /* 266 */ "expr ::= expr BETWEEN expr AND expr", + /* 267 */ "expr ::= expr AND expr", + /* 268 */ "expr ::= expr OR expr", + /* 269 */ "expr ::= expr PLUS expr", + /* 270 */ "expr ::= expr MINUS expr", + /* 271 */ "expr ::= expr STAR expr", + /* 272 */ "expr ::= expr SLASH expr", + /* 273 */ "expr ::= expr REM expr", + /* 274 */ "expr ::= expr LIKE expr", + /* 275 */ "expr ::= expr MATCH expr", + /* 276 */ "expr ::= expr NMATCH expr", + /* 277 */ "expr ::= expr IN LP exprlist RP", + /* 278 */ "exprlist ::= exprlist COMMA expritem", + /* 279 */ "exprlist ::= expritem", + /* 280 */ "expritem ::= expr", + /* 281 */ "expritem ::=", + /* 282 */ "cmd ::= RESET QUERY CACHE", + /* 283 */ "cmd ::= SYNCDB ids REPLICA", + /* 284 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 285 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 286 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 287 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 288 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 289 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 290 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 291 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 292 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 293 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 294 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 295 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 296 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 297 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 298 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 299 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 300 */ "cmd ::= KILL CONNECTION INTEGER", + /* 301 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 302 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1478,60 +1493,61 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 205: /* exprlist */ - case 247: /* selcollist */ - case 261: /* sclp */ + case 200: /* exprlist */ + case 245: /* selcollist */ + case 259: /* sclp */ { -tSqlExprListDestroy((yypminor->yy131)); +tSqlExprListDestroy((yypminor->yy165)); } break; - case 219: /* intitemlist */ - case 221: /* keep */ - case 241: /* columnlist */ - case 242: /* tagitemlist */ - case 243: /* tagNamelist */ - case 254: /* fill_opt */ - case 255: /* groupby_opt */ - case 257: /* orderby_opt */ - case 269: /* sortlist */ - case 273: /* grouplist */ -{ -taosArrayDestroy((yypminor->yy131)); + case 214: /* intitemlist */ + case 216: /* keep */ + case 237: /* columnlist */ + case 238: /* tagitemlist1 */ + case 239: /* tagNamelist */ + case 243: /* tagitemlist */ + case 252: /* fill_opt */ + case 253: /* groupby_opt */ + case 255: /* orderby_opt */ + case 267: /* sortlist */ + case 271: /* grouplist */ +{ +taosArrayDestroy((yypminor->yy165)); } break; - case 239: /* create_table_list */ + case 235: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy272)); +destroyCreateTableSql((yypminor->yy326)); } break; - case 244: /* select */ + case 240: /* select */ { -destroySqlNode((yypminor->yy256)); +destroySqlNode((yypminor->yy278)); } break; - case 248: /* from */ - case 265: /* tablelist */ - case 266: /* sub */ + case 246: /* from */ + case 263: /* tablelist */ + case 264: /* sub */ { -destroyRelationInfo((yypminor->yy544)); +destroyRelationInfo((yypminor->yy10)); } break; - case 249: /* where_opt */ - case 256: /* having_opt */ - case 263: /* expr */ - case 274: /* expritem */ + case 247: /* where_opt */ + case 254: /* having_opt */ + case 261: /* expr */ + case 272: /* expritem */ { -tSqlExprDestroy((yypminor->yy46)); +tSqlExprDestroy((yypminor->yy202)); } break; - case 260: /* union */ + case 258: /* union */ { -destroyAllSqlNode((yypminor->yy303)); +destroyAllSqlNode((yypminor->yy503)); } break; - case 270: /* sortitem */ + case 268: /* sortitem */ { -taosVariantDestroy(&(yypminor->yy43)); +taosVariantDestroy(&(yypminor->yy425)); } break; /********* End destructor definitions *****************************************/ @@ -1825,294 +1841,309 @@ 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[] = { - { 197, -1 }, /* (0) program ::= cmd */ - { 198, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 198, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 198, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ - { 198, -2 }, /* (4) cmd ::= SHOW MNODES */ - { 198, -2 }, /* (5) cmd ::= SHOW DNODES */ - { 198, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ - { 198, -2 }, /* (7) cmd ::= SHOW USERS */ - { 198, -2 }, /* (8) cmd ::= SHOW MODULES */ - { 198, -2 }, /* (9) cmd ::= SHOW QUERIES */ - { 198, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ - { 198, -2 }, /* (11) cmd ::= SHOW STREAMS */ - { 198, -2 }, /* (12) cmd ::= SHOW VARIABLES */ - { 198, -2 }, /* (13) cmd ::= SHOW SCORES */ - { 198, -2 }, /* (14) cmd ::= SHOW GRANTS */ - { 198, -2 }, /* (15) cmd ::= SHOW VNODES */ - { 198, -3 }, /* (16) cmd ::= SHOW VNODES ids */ - { 200, 0 }, /* (17) dbPrefix ::= */ - { 200, -2 }, /* (18) dbPrefix ::= ids DOT */ - { 201, 0 }, /* (19) cpxName ::= */ - { 201, -2 }, /* (20) cpxName ::= DOT ids */ - { 198, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 198, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 198, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ - { 198, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ - { 198, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 198, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ - { 198, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 198, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ - { 198, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 198, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ - { 198, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ - { 198, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ - { 198, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ - { 198, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ - { 198, -3 }, /* (35) cmd ::= DROP DNODE ids */ - { 198, -3 }, /* (36) cmd ::= DROP USER ids */ - { 198, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ - { 198, -2 }, /* (38) cmd ::= USE ids */ - { 198, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ - { 198, -3 }, /* (40) cmd ::= DESC ids cpxName */ - { 198, -5 }, /* (41) cmd ::= ALTER USER ids PASS ids */ - { 198, -5 }, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 198, -4 }, /* (43) cmd ::= ALTER DNODE ids ids */ - { 198, -5 }, /* (44) cmd ::= ALTER DNODE ids ids ids */ - { 198, -3 }, /* (45) cmd ::= ALTER LOCAL ids */ - { 198, -4 }, /* (46) cmd ::= ALTER LOCAL ids ids */ - { 198, -4 }, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 198, -4 }, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 198, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 198, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ - { 199, -1 }, /* (51) ids ::= ID */ - { 199, -1 }, /* (52) ids ::= STRING */ - { 202, -2 }, /* (53) ifexists ::= IF EXISTS */ - { 202, 0 }, /* (54) ifexists ::= */ - { 206, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ - { 206, 0 }, /* (56) ifnotexists ::= */ - { 198, -3 }, /* (57) cmd ::= CREATE DNODE ids */ - { 198, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 198, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 198, -8 }, /* (60) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 198, -9 }, /* (61) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 198, -5 }, /* (62) cmd ::= CREATE USER ids PASS ids */ - { 209, 0 }, /* (63) bufsize ::= */ - { 209, -2 }, /* (64) bufsize ::= BUFSIZE INTEGER */ - { 210, 0 }, /* (65) pps ::= */ - { 210, -2 }, /* (66) pps ::= PPS INTEGER */ - { 211, 0 }, /* (67) tseries ::= */ - { 211, -2 }, /* (68) tseries ::= TSERIES INTEGER */ - { 212, 0 }, /* (69) dbs ::= */ - { 212, -2 }, /* (70) dbs ::= DBS INTEGER */ - { 213, 0 }, /* (71) streams ::= */ - { 213, -2 }, /* (72) streams ::= STREAMS INTEGER */ - { 214, 0 }, /* (73) storage ::= */ - { 214, -2 }, /* (74) storage ::= STORAGE INTEGER */ - { 215, 0 }, /* (75) qtime ::= */ - { 215, -2 }, /* (76) qtime ::= QTIME INTEGER */ - { 216, 0 }, /* (77) users ::= */ - { 216, -2 }, /* (78) users ::= USERS INTEGER */ - { 217, 0 }, /* (79) conns ::= */ - { 217, -2 }, /* (80) conns ::= CONNS INTEGER */ - { 218, 0 }, /* (81) state ::= */ - { 218, -2 }, /* (82) state ::= STATE ids */ - { 204, -9 }, /* (83) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 219, -3 }, /* (84) intitemlist ::= intitemlist COMMA intitem */ - { 219, -1 }, /* (85) intitemlist ::= intitem */ - { 220, -1 }, /* (86) intitem ::= INTEGER */ - { 221, -2 }, /* (87) keep ::= KEEP intitemlist */ - { 222, -2 }, /* (88) cache ::= CACHE INTEGER */ - { 223, -2 }, /* (89) replica ::= REPLICA INTEGER */ - { 224, -2 }, /* (90) quorum ::= QUORUM INTEGER */ - { 225, -2 }, /* (91) days ::= DAYS INTEGER */ - { 226, -2 }, /* (92) minrows ::= MINROWS INTEGER */ - { 227, -2 }, /* (93) maxrows ::= MAXROWS INTEGER */ - { 228, -2 }, /* (94) blocks ::= BLOCKS INTEGER */ - { 229, -2 }, /* (95) ctime ::= CTIME INTEGER */ - { 230, -2 }, /* (96) wal ::= WAL INTEGER */ - { 231, -2 }, /* (97) fsync ::= FSYNC INTEGER */ - { 232, -2 }, /* (98) comp ::= COMP INTEGER */ - { 233, -2 }, /* (99) prec ::= PRECISION STRING */ - { 234, -2 }, /* (100) update ::= UPDATE INTEGER */ - { 235, -2 }, /* (101) cachelast ::= CACHELAST INTEGER */ - { 207, 0 }, /* (102) db_optr ::= */ - { 207, -2 }, /* (103) db_optr ::= db_optr cache */ - { 207, -2 }, /* (104) db_optr ::= db_optr replica */ - { 207, -2 }, /* (105) db_optr ::= db_optr quorum */ - { 207, -2 }, /* (106) db_optr ::= db_optr days */ - { 207, -2 }, /* (107) db_optr ::= db_optr minrows */ - { 207, -2 }, /* (108) db_optr ::= db_optr maxrows */ - { 207, -2 }, /* (109) db_optr ::= db_optr blocks */ - { 207, -2 }, /* (110) db_optr ::= db_optr ctime */ - { 207, -2 }, /* (111) db_optr ::= db_optr wal */ - { 207, -2 }, /* (112) db_optr ::= db_optr fsync */ - { 207, -2 }, /* (113) db_optr ::= db_optr comp */ - { 207, -2 }, /* (114) db_optr ::= db_optr prec */ - { 207, -2 }, /* (115) db_optr ::= db_optr keep */ - { 207, -2 }, /* (116) db_optr ::= db_optr update */ - { 207, -2 }, /* (117) db_optr ::= db_optr cachelast */ - { 203, 0 }, /* (118) alter_db_optr ::= */ - { 203, -2 }, /* (119) alter_db_optr ::= alter_db_optr replica */ - { 203, -2 }, /* (120) alter_db_optr ::= alter_db_optr quorum */ - { 203, -2 }, /* (121) alter_db_optr ::= alter_db_optr keep */ - { 203, -2 }, /* (122) alter_db_optr ::= alter_db_optr blocks */ - { 203, -2 }, /* (123) alter_db_optr ::= alter_db_optr comp */ - { 203, -2 }, /* (124) alter_db_optr ::= alter_db_optr update */ - { 203, -2 }, /* (125) alter_db_optr ::= alter_db_optr cachelast */ - { 208, -1 }, /* (126) typename ::= ids */ - { 208, -4 }, /* (127) typename ::= ids LP signed RP */ - { 208, -2 }, /* (128) typename ::= ids UNSIGNED */ - { 236, -1 }, /* (129) signed ::= INTEGER */ - { 236, -2 }, /* (130) signed ::= PLUS INTEGER */ - { 236, -2 }, /* (131) signed ::= MINUS INTEGER */ - { 198, -3 }, /* (132) cmd ::= CREATE TABLE create_table_args */ - { 198, -3 }, /* (133) cmd ::= CREATE TABLE create_stable_args */ - { 198, -3 }, /* (134) cmd ::= CREATE STABLE create_stable_args */ - { 198, -3 }, /* (135) cmd ::= CREATE TABLE create_table_list */ - { 239, -1 }, /* (136) create_table_list ::= create_from_stable */ - { 239, -2 }, /* (137) create_table_list ::= create_table_list create_from_stable */ - { 237, -6 }, /* (138) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 238, -10 }, /* (139) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 240, -10 }, /* (140) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 240, -13 }, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 243, -3 }, /* (142) tagNamelist ::= tagNamelist COMMA ids */ - { 243, -1 }, /* (143) tagNamelist ::= ids */ - { 237, -5 }, /* (144) create_table_args ::= ifnotexists ids cpxName AS select */ - { 241, -3 }, /* (145) columnlist ::= columnlist COMMA column */ - { 241, -1 }, /* (146) columnlist ::= column */ - { 245, -2 }, /* (147) column ::= ids typename */ - { 242, -3 }, /* (148) tagitemlist ::= tagitemlist COMMA tagitem */ - { 242, -1 }, /* (149) tagitemlist ::= tagitem */ - { 246, -1 }, /* (150) tagitem ::= INTEGER */ - { 246, -1 }, /* (151) tagitem ::= FLOAT */ - { 246, -1 }, /* (152) tagitem ::= STRING */ - { 246, -1 }, /* (153) tagitem ::= BOOL */ - { 246, -1 }, /* (154) tagitem ::= NULL */ - { 246, -1 }, /* (155) tagitem ::= NOW */ - { 246, -2 }, /* (156) tagitem ::= MINUS INTEGER */ - { 246, -2 }, /* (157) tagitem ::= MINUS FLOAT */ - { 246, -2 }, /* (158) tagitem ::= PLUS INTEGER */ - { 246, -2 }, /* (159) tagitem ::= PLUS FLOAT */ - { 244, -14 }, /* (160) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 244, -3 }, /* (161) select ::= LP select RP */ - { 260, -1 }, /* (162) union ::= select */ - { 260, -4 }, /* (163) union ::= union UNION ALL select */ - { 260, -3 }, /* (164) union ::= union UNION select */ - { 198, -1 }, /* (165) cmd ::= union */ - { 244, -2 }, /* (166) select ::= SELECT selcollist */ - { 261, -2 }, /* (167) sclp ::= selcollist COMMA */ - { 261, 0 }, /* (168) sclp ::= */ - { 247, -4 }, /* (169) selcollist ::= sclp distinct expr as */ - { 247, -2 }, /* (170) selcollist ::= sclp STAR */ - { 264, -2 }, /* (171) as ::= AS ids */ - { 264, -1 }, /* (172) as ::= ids */ - { 264, 0 }, /* (173) as ::= */ - { 262, -1 }, /* (174) distinct ::= DISTINCT */ - { 262, 0 }, /* (175) distinct ::= */ - { 248, -2 }, /* (176) from ::= FROM tablelist */ - { 248, -2 }, /* (177) from ::= FROM sub */ - { 266, -3 }, /* (178) sub ::= LP union RP */ - { 266, -4 }, /* (179) sub ::= LP union RP ids */ - { 266, -6 }, /* (180) sub ::= sub COMMA LP union RP ids */ - { 265, -2 }, /* (181) tablelist ::= ids cpxName */ - { 265, -3 }, /* (182) tablelist ::= ids cpxName ids */ - { 265, -4 }, /* (183) tablelist ::= tablelist COMMA ids cpxName */ - { 265, -5 }, /* (184) tablelist ::= tablelist COMMA ids cpxName ids */ - { 267, -1 }, /* (185) tmvar ::= VARIABLE */ - { 250, -4 }, /* (186) interval_option ::= intervalKey LP tmvar RP */ - { 250, -6 }, /* (187) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 250, 0 }, /* (188) interval_option ::= */ - { 268, -1 }, /* (189) intervalKey ::= INTERVAL */ - { 268, -1 }, /* (190) intervalKey ::= EVERY */ - { 252, 0 }, /* (191) session_option ::= */ - { 252, -7 }, /* (192) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 253, 0 }, /* (193) windowstate_option ::= */ - { 253, -4 }, /* (194) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 254, 0 }, /* (195) fill_opt ::= */ - { 254, -6 }, /* (196) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 254, -4 }, /* (197) fill_opt ::= FILL LP ID RP */ - { 251, -4 }, /* (198) sliding_opt ::= SLIDING LP tmvar RP */ - { 251, 0 }, /* (199) sliding_opt ::= */ - { 257, 0 }, /* (200) orderby_opt ::= */ - { 257, -3 }, /* (201) orderby_opt ::= ORDER BY sortlist */ - { 269, -4 }, /* (202) sortlist ::= sortlist COMMA item sortorder */ - { 269, -2 }, /* (203) sortlist ::= item sortorder */ - { 271, -2 }, /* (204) item ::= ids cpxName */ - { 272, -1 }, /* (205) sortorder ::= ASC */ - { 272, -1 }, /* (206) sortorder ::= DESC */ - { 272, 0 }, /* (207) sortorder ::= */ - { 255, 0 }, /* (208) groupby_opt ::= */ - { 255, -3 }, /* (209) groupby_opt ::= GROUP BY grouplist */ - { 273, -3 }, /* (210) grouplist ::= grouplist COMMA item */ - { 273, -1 }, /* (211) grouplist ::= item */ - { 256, 0 }, /* (212) having_opt ::= */ - { 256, -2 }, /* (213) having_opt ::= HAVING expr */ - { 259, 0 }, /* (214) limit_opt ::= */ - { 259, -2 }, /* (215) limit_opt ::= LIMIT signed */ - { 259, -4 }, /* (216) limit_opt ::= LIMIT signed OFFSET signed */ - { 259, -4 }, /* (217) limit_opt ::= LIMIT signed COMMA signed */ - { 258, 0 }, /* (218) slimit_opt ::= */ - { 258, -2 }, /* (219) slimit_opt ::= SLIMIT signed */ - { 258, -4 }, /* (220) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 258, -4 }, /* (221) slimit_opt ::= SLIMIT signed COMMA signed */ - { 249, 0 }, /* (222) where_opt ::= */ - { 249, -2 }, /* (223) where_opt ::= WHERE expr */ - { 263, -3 }, /* (224) expr ::= LP expr RP */ - { 263, -1 }, /* (225) expr ::= ID */ - { 263, -3 }, /* (226) expr ::= ID DOT ID */ - { 263, -3 }, /* (227) expr ::= ID DOT STAR */ - { 263, -1 }, /* (228) expr ::= INTEGER */ - { 263, -2 }, /* (229) expr ::= MINUS INTEGER */ - { 263, -2 }, /* (230) expr ::= PLUS INTEGER */ - { 263, -1 }, /* (231) expr ::= FLOAT */ - { 263, -2 }, /* (232) expr ::= MINUS FLOAT */ - { 263, -2 }, /* (233) expr ::= PLUS FLOAT */ - { 263, -1 }, /* (234) expr ::= STRING */ - { 263, -1 }, /* (235) expr ::= NOW */ - { 263, -1 }, /* (236) expr ::= VARIABLE */ - { 263, -2 }, /* (237) expr ::= PLUS VARIABLE */ - { 263, -2 }, /* (238) expr ::= MINUS VARIABLE */ - { 263, -1 }, /* (239) expr ::= BOOL */ - { 263, -1 }, /* (240) expr ::= NULL */ - { 263, -4 }, /* (241) expr ::= ID LP exprlist RP */ - { 263, -4 }, /* (242) expr ::= ID LP STAR RP */ - { 263, -3 }, /* (243) expr ::= expr IS NULL */ - { 263, -4 }, /* (244) expr ::= expr IS NOT NULL */ - { 263, -3 }, /* (245) expr ::= expr LT expr */ - { 263, -3 }, /* (246) expr ::= expr GT expr */ - { 263, -3 }, /* (247) expr ::= expr LE expr */ - { 263, -3 }, /* (248) expr ::= expr GE expr */ - { 263, -3 }, /* (249) expr ::= expr NE expr */ - { 263, -3 }, /* (250) expr ::= expr EQ expr */ - { 263, -5 }, /* (251) expr ::= expr BETWEEN expr AND expr */ - { 263, -3 }, /* (252) expr ::= expr AND expr */ - { 263, -3 }, /* (253) expr ::= expr OR expr */ - { 263, -3 }, /* (254) expr ::= expr PLUS expr */ - { 263, -3 }, /* (255) expr ::= expr MINUS expr */ - { 263, -3 }, /* (256) expr ::= expr STAR expr */ - { 263, -3 }, /* (257) expr ::= expr SLASH expr */ - { 263, -3 }, /* (258) expr ::= expr REM expr */ - { 263, -3 }, /* (259) expr ::= expr LIKE expr */ - { 263, -3 }, /* (260) expr ::= expr MATCH expr */ - { 263, -3 }, /* (261) expr ::= expr NMATCH expr */ - { 263, -5 }, /* (262) expr ::= expr IN LP exprlist RP */ - { 205, -3 }, /* (263) exprlist ::= exprlist COMMA expritem */ - { 205, -1 }, /* (264) exprlist ::= expritem */ - { 274, -1 }, /* (265) expritem ::= expr */ - { 274, 0 }, /* (266) expritem ::= */ - { 198, -3 }, /* (267) cmd ::= RESET QUERY CACHE */ - { 198, -3 }, /* (268) cmd ::= SYNCDB ids REPLICA */ - { 198, -7 }, /* (269) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 198, -7 }, /* (270) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 198, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 198, -7 }, /* (272) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 198, -7 }, /* (273) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 198, -8 }, /* (274) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 198, -9 }, /* (275) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 198, -7 }, /* (276) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 198, -7 }, /* (277) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 198, -7 }, /* (278) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 198, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 198, -7 }, /* (280) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 198, -7 }, /* (281) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 198, -8 }, /* (282) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 198, -9 }, /* (283) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 198, -7 }, /* (284) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 198, -3 }, /* (285) cmd ::= KILL CONNECTION INTEGER */ - { 198, -5 }, /* (286) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 198, -5 }, /* (287) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 192, -1 }, /* (0) program ::= cmd */ + { 193, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 193, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 193, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ + { 193, -2 }, /* (4) cmd ::= SHOW MNODES */ + { 193, -2 }, /* (5) cmd ::= SHOW DNODES */ + { 193, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ + { 193, -2 }, /* (7) cmd ::= SHOW USERS */ + { 193, -2 }, /* (8) cmd ::= SHOW MODULES */ + { 193, -2 }, /* (9) cmd ::= SHOW QUERIES */ + { 193, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ + { 193, -2 }, /* (11) cmd ::= SHOW STREAMS */ + { 193, -2 }, /* (12) cmd ::= SHOW VARIABLES */ + { 193, -2 }, /* (13) cmd ::= SHOW SCORES */ + { 193, -2 }, /* (14) cmd ::= SHOW GRANTS */ + { 193, -2 }, /* (15) cmd ::= SHOW VNODES */ + { 193, -3 }, /* (16) cmd ::= SHOW VNODES ids */ + { 195, 0 }, /* (17) dbPrefix ::= */ + { 195, -2 }, /* (18) dbPrefix ::= ids DOT */ + { 196, 0 }, /* (19) cpxName ::= */ + { 196, -2 }, /* (20) cpxName ::= DOT ids */ + { 193, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 193, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 193, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + { 193, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ + { 193, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 193, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ + { 193, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 193, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + { 193, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 193, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + { 193, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + { 193, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ + { 193, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ + { 193, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ + { 193, -3 }, /* (35) cmd ::= DROP DNODE ids */ + { 193, -3 }, /* (36) cmd ::= DROP USER ids */ + { 193, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ + { 193, -2 }, /* (38) cmd ::= USE ids */ + { 193, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ + { 193, -3 }, /* (40) cmd ::= DESC ids cpxName */ + { 193, -5 }, /* (41) cmd ::= ALTER USER ids PASS ids */ + { 193, -5 }, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 193, -4 }, /* (43) cmd ::= ALTER DNODE ids ids */ + { 193, -5 }, /* (44) cmd ::= ALTER DNODE ids ids ids */ + { 193, -3 }, /* (45) cmd ::= ALTER LOCAL ids */ + { 193, -4 }, /* (46) cmd ::= ALTER LOCAL ids ids */ + { 193, -4 }, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 193, -4 }, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 193, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 193, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ + { 194, -1 }, /* (51) ids ::= ID */ + { 194, -1 }, /* (52) ids ::= STRING */ + { 197, -2 }, /* (53) ifexists ::= IF EXISTS */ + { 197, 0 }, /* (54) ifexists ::= */ + { 201, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ + { 201, 0 }, /* (56) ifnotexists ::= */ + { 193, -5 }, /* (57) cmd ::= CREATE DNODE ids PORT ids */ + { 193, -5 }, /* (58) cmd ::= CREATE DNODE IPTOKEN PORT ids */ + { 193, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 193, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 193, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ + { 204, 0 }, /* (64) bufsize ::= */ + { 204, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ + { 205, 0 }, /* (66) pps ::= */ + { 205, -2 }, /* (67) pps ::= PPS INTEGER */ + { 206, 0 }, /* (68) tseries ::= */ + { 206, -2 }, /* (69) tseries ::= TSERIES INTEGER */ + { 207, 0 }, /* (70) dbs ::= */ + { 207, -2 }, /* (71) dbs ::= DBS INTEGER */ + { 208, 0 }, /* (72) streams ::= */ + { 208, -2 }, /* (73) streams ::= STREAMS INTEGER */ + { 209, 0 }, /* (74) storage ::= */ + { 209, -2 }, /* (75) storage ::= STORAGE INTEGER */ + { 210, 0 }, /* (76) qtime ::= */ + { 210, -2 }, /* (77) qtime ::= QTIME INTEGER */ + { 211, 0 }, /* (78) users ::= */ + { 211, -2 }, /* (79) users ::= USERS INTEGER */ + { 212, 0 }, /* (80) conns ::= */ + { 212, -2 }, /* (81) conns ::= CONNS INTEGER */ + { 213, 0 }, /* (82) state ::= */ + { 213, -2 }, /* (83) state ::= STATE ids */ + { 199, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 214, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ + { 214, -1 }, /* (86) intitemlist ::= intitem */ + { 215, -1 }, /* (87) intitem ::= INTEGER */ + { 216, -2 }, /* (88) keep ::= KEEP intitemlist */ + { 217, -2 }, /* (89) cache ::= CACHE INTEGER */ + { 218, -2 }, /* (90) replica ::= REPLICA INTEGER */ + { 219, -2 }, /* (91) quorum ::= QUORUM INTEGER */ + { 220, -2 }, /* (92) days ::= DAYS INTEGER */ + { 221, -2 }, /* (93) minrows ::= MINROWS INTEGER */ + { 222, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ + { 223, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ + { 224, -2 }, /* (96) ctime ::= CTIME INTEGER */ + { 225, -2 }, /* (97) wal ::= WAL INTEGER */ + { 226, -2 }, /* (98) fsync ::= FSYNC INTEGER */ + { 227, -2 }, /* (99) comp ::= COMP INTEGER */ + { 228, -2 }, /* (100) prec ::= PRECISION STRING */ + { 229, -2 }, /* (101) update ::= UPDATE INTEGER */ + { 230, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ + { 231, -2 }, /* (103) vgroups ::= VGROUPS INTEGER */ + { 202, 0 }, /* (104) db_optr ::= */ + { 202, -2 }, /* (105) db_optr ::= db_optr cache */ + { 202, -2 }, /* (106) db_optr ::= db_optr replica */ + { 202, -2 }, /* (107) db_optr ::= db_optr quorum */ + { 202, -2 }, /* (108) db_optr ::= db_optr days */ + { 202, -2 }, /* (109) db_optr ::= db_optr minrows */ + { 202, -2 }, /* (110) db_optr ::= db_optr maxrows */ + { 202, -2 }, /* (111) db_optr ::= db_optr blocks */ + { 202, -2 }, /* (112) db_optr ::= db_optr ctime */ + { 202, -2 }, /* (113) db_optr ::= db_optr wal */ + { 202, -2 }, /* (114) db_optr ::= db_optr fsync */ + { 202, -2 }, /* (115) db_optr ::= db_optr comp */ + { 202, -2 }, /* (116) db_optr ::= db_optr prec */ + { 202, -2 }, /* (117) db_optr ::= db_optr keep */ + { 202, -2 }, /* (118) db_optr ::= db_optr update */ + { 202, -2 }, /* (119) db_optr ::= db_optr cachelast */ + { 202, -2 }, /* (120) db_optr ::= db_optr vgroups */ + { 198, 0 }, /* (121) alter_db_optr ::= */ + { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr replica */ + { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr quorum */ + { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr keep */ + { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr blocks */ + { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr comp */ + { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr update */ + { 198, -2 }, /* (128) alter_db_optr ::= alter_db_optr cachelast */ + { 203, -1 }, /* (129) typename ::= ids */ + { 203, -4 }, /* (130) typename ::= ids LP signed RP */ + { 203, -2 }, /* (131) typename ::= ids UNSIGNED */ + { 232, -1 }, /* (132) signed ::= INTEGER */ + { 232, -2 }, /* (133) signed ::= PLUS INTEGER */ + { 232, -2 }, /* (134) signed ::= MINUS INTEGER */ + { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_table_args */ + { 193, -3 }, /* (136) cmd ::= CREATE TABLE create_stable_args */ + { 193, -3 }, /* (137) cmd ::= CREATE STABLE create_stable_args */ + { 193, -3 }, /* (138) cmd ::= CREATE TABLE create_table_list */ + { 235, -1 }, /* (139) create_table_list ::= create_from_stable */ + { 235, -2 }, /* (140) create_table_list ::= create_table_list create_from_stable */ + { 233, -6 }, /* (141) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 234, -10 }, /* (142) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 236, -10 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + { 236, -13 }, /* (144) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + { 239, -3 }, /* (145) tagNamelist ::= tagNamelist COMMA ids */ + { 239, -1 }, /* (146) tagNamelist ::= ids */ + { 233, -5 }, /* (147) create_table_args ::= ifnotexists ids cpxName AS select */ + { 237, -3 }, /* (148) columnlist ::= columnlist COMMA column */ + { 237, -1 }, /* (149) columnlist ::= column */ + { 241, -2 }, /* (150) column ::= ids typename */ + { 238, -3 }, /* (151) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + { 238, -1 }, /* (152) tagitemlist1 ::= tagitem1 */ + { 242, -2 }, /* (153) tagitem1 ::= MINUS INTEGER */ + { 242, -2 }, /* (154) tagitem1 ::= MINUS FLOAT */ + { 242, -2 }, /* (155) tagitem1 ::= PLUS INTEGER */ + { 242, -2 }, /* (156) tagitem1 ::= PLUS FLOAT */ + { 242, -1 }, /* (157) tagitem1 ::= INTEGER */ + { 242, -1 }, /* (158) tagitem1 ::= FLOAT */ + { 242, -1 }, /* (159) tagitem1 ::= STRING */ + { 242, -1 }, /* (160) tagitem1 ::= BOOL */ + { 242, -1 }, /* (161) tagitem1 ::= NULL */ + { 242, -1 }, /* (162) tagitem1 ::= NOW */ + { 243, -3 }, /* (163) tagitemlist ::= tagitemlist COMMA tagitem */ + { 243, -1 }, /* (164) tagitemlist ::= tagitem */ + { 244, -1 }, /* (165) tagitem ::= INTEGER */ + { 244, -1 }, /* (166) tagitem ::= FLOAT */ + { 244, -1 }, /* (167) tagitem ::= STRING */ + { 244, -1 }, /* (168) tagitem ::= BOOL */ + { 244, -1 }, /* (169) tagitem ::= NULL */ + { 244, -1 }, /* (170) tagitem ::= NOW */ + { 244, -2 }, /* (171) tagitem ::= MINUS INTEGER */ + { 244, -2 }, /* (172) tagitem ::= MINUS FLOAT */ + { 244, -2 }, /* (173) tagitem ::= PLUS INTEGER */ + { 244, -2 }, /* (174) tagitem ::= PLUS FLOAT */ + { 240, -14 }, /* (175) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + { 240, -3 }, /* (176) select ::= LP select RP */ + { 258, -1 }, /* (177) union ::= select */ + { 258, -4 }, /* (178) union ::= union UNION ALL select */ + { 258, -3 }, /* (179) union ::= union UNION select */ + { 193, -1 }, /* (180) cmd ::= union */ + { 240, -2 }, /* (181) select ::= SELECT selcollist */ + { 259, -2 }, /* (182) sclp ::= selcollist COMMA */ + { 259, 0 }, /* (183) sclp ::= */ + { 245, -4 }, /* (184) selcollist ::= sclp distinct expr as */ + { 245, -2 }, /* (185) selcollist ::= sclp STAR */ + { 262, -2 }, /* (186) as ::= AS ids */ + { 262, -1 }, /* (187) as ::= ids */ + { 262, 0 }, /* (188) as ::= */ + { 260, -1 }, /* (189) distinct ::= DISTINCT */ + { 260, 0 }, /* (190) distinct ::= */ + { 246, -2 }, /* (191) from ::= FROM tablelist */ + { 246, -2 }, /* (192) from ::= FROM sub */ + { 264, -3 }, /* (193) sub ::= LP union RP */ + { 264, -4 }, /* (194) sub ::= LP union RP ids */ + { 264, -6 }, /* (195) sub ::= sub COMMA LP union RP ids */ + { 263, -2 }, /* (196) tablelist ::= ids cpxName */ + { 263, -3 }, /* (197) tablelist ::= ids cpxName ids */ + { 263, -4 }, /* (198) tablelist ::= tablelist COMMA ids cpxName */ + { 263, -5 }, /* (199) tablelist ::= tablelist COMMA ids cpxName ids */ + { 265, -1 }, /* (200) tmvar ::= VARIABLE */ + { 248, -4 }, /* (201) interval_option ::= intervalKey LP tmvar RP */ + { 248, -6 }, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + { 248, 0 }, /* (203) interval_option ::= */ + { 266, -1 }, /* (204) intervalKey ::= INTERVAL */ + { 266, -1 }, /* (205) intervalKey ::= EVERY */ + { 250, 0 }, /* (206) session_option ::= */ + { 250, -7 }, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 251, 0 }, /* (208) windowstate_option ::= */ + { 251, -4 }, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 252, 0 }, /* (210) fill_opt ::= */ + { 252, -6 }, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 252, -4 }, /* (212) fill_opt ::= FILL LP ID RP */ + { 249, -4 }, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ + { 249, 0 }, /* (214) sliding_opt ::= */ + { 255, 0 }, /* (215) orderby_opt ::= */ + { 255, -3 }, /* (216) orderby_opt ::= ORDER BY sortlist */ + { 267, -4 }, /* (217) sortlist ::= sortlist COMMA item sortorder */ + { 267, -2 }, /* (218) sortlist ::= item sortorder */ + { 269, -2 }, /* (219) item ::= ids cpxName */ + { 270, -1 }, /* (220) sortorder ::= ASC */ + { 270, -1 }, /* (221) sortorder ::= DESC */ + { 270, 0 }, /* (222) sortorder ::= */ + { 253, 0 }, /* (223) groupby_opt ::= */ + { 253, -3 }, /* (224) groupby_opt ::= GROUP BY grouplist */ + { 271, -3 }, /* (225) grouplist ::= grouplist COMMA item */ + { 271, -1 }, /* (226) grouplist ::= item */ + { 254, 0 }, /* (227) having_opt ::= */ + { 254, -2 }, /* (228) having_opt ::= HAVING expr */ + { 257, 0 }, /* (229) limit_opt ::= */ + { 257, -2 }, /* (230) limit_opt ::= LIMIT signed */ + { 257, -4 }, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ + { 257, -4 }, /* (232) limit_opt ::= LIMIT signed COMMA signed */ + { 256, 0 }, /* (233) slimit_opt ::= */ + { 256, -2 }, /* (234) slimit_opt ::= SLIMIT signed */ + { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 256, -4 }, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ + { 247, 0 }, /* (237) where_opt ::= */ + { 247, -2 }, /* (238) where_opt ::= WHERE expr */ + { 261, -3 }, /* (239) expr ::= LP expr RP */ + { 261, -1 }, /* (240) expr ::= ID */ + { 261, -3 }, /* (241) expr ::= ID DOT ID */ + { 261, -3 }, /* (242) expr ::= ID DOT STAR */ + { 261, -1 }, /* (243) expr ::= INTEGER */ + { 261, -2 }, /* (244) expr ::= MINUS INTEGER */ + { 261, -2 }, /* (245) expr ::= PLUS INTEGER */ + { 261, -1 }, /* (246) expr ::= FLOAT */ + { 261, -2 }, /* (247) expr ::= MINUS FLOAT */ + { 261, -2 }, /* (248) expr ::= PLUS FLOAT */ + { 261, -1 }, /* (249) expr ::= STRING */ + { 261, -1 }, /* (250) expr ::= NOW */ + { 261, -1 }, /* (251) expr ::= VARIABLE */ + { 261, -2 }, /* (252) expr ::= PLUS VARIABLE */ + { 261, -2 }, /* (253) expr ::= MINUS VARIABLE */ + { 261, -1 }, /* (254) expr ::= BOOL */ + { 261, -1 }, /* (255) expr ::= NULL */ + { 261, -4 }, /* (256) expr ::= ID LP exprlist RP */ + { 261, -4 }, /* (257) expr ::= ID LP STAR RP */ + { 261, -3 }, /* (258) expr ::= expr IS NULL */ + { 261, -4 }, /* (259) expr ::= expr IS NOT NULL */ + { 261, -3 }, /* (260) expr ::= expr LT expr */ + { 261, -3 }, /* (261) expr ::= expr GT expr */ + { 261, -3 }, /* (262) expr ::= expr LE expr */ + { 261, -3 }, /* (263) expr ::= expr GE expr */ + { 261, -3 }, /* (264) expr ::= expr NE expr */ + { 261, -3 }, /* (265) expr ::= expr EQ expr */ + { 261, -5 }, /* (266) expr ::= expr BETWEEN expr AND expr */ + { 261, -3 }, /* (267) expr ::= expr AND expr */ + { 261, -3 }, /* (268) expr ::= expr OR expr */ + { 261, -3 }, /* (269) expr ::= expr PLUS expr */ + { 261, -3 }, /* (270) expr ::= expr MINUS expr */ + { 261, -3 }, /* (271) expr ::= expr STAR expr */ + { 261, -3 }, /* (272) expr ::= expr SLASH expr */ + { 261, -3 }, /* (273) expr ::= expr REM expr */ + { 261, -3 }, /* (274) expr ::= expr LIKE expr */ + { 261, -3 }, /* (275) expr ::= expr MATCH expr */ + { 261, -3 }, /* (276) expr ::= expr NMATCH expr */ + { 261, -5 }, /* (277) expr ::= expr IN LP exprlist RP */ + { 200, -3 }, /* (278) exprlist ::= exprlist COMMA expritem */ + { 200, -1 }, /* (279) exprlist ::= expritem */ + { 272, -1 }, /* (280) expritem ::= expr */ + { 272, 0 }, /* (281) expritem ::= */ + { 193, -3 }, /* (282) cmd ::= RESET QUERY CACHE */ + { 193, -3 }, /* (283) cmd ::= SYNCDB ids REPLICA */ + { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 193, -3 }, /* (300) cmd ::= KILL CONNECTION INTEGER */ + { 193, -5 }, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 193, -5 }, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2193,9 +2224,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 132: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==132); - case 133: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==133); - case 134: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==134); + case 135: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==135); + case 136: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==136); + case 137: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==137); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2371,16 +2402,16 @@ static void yy_reduce( { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 47: /* cmd ::= ALTER DATABASE ids alter_db_optr */ -{ SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &t);} +{ SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy16, &t);} break; case 48: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy341);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy211);} break; case 49: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy341);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; case 50: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy131);} +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy165);} break; case 51: /* ids ::= ID */ case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); @@ -2392,746 +2423,776 @@ static void yy_reduce( break; case 54: /* ifexists ::= */ case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); - case 175: /* distinct ::= */ yytestcase(yyruleno==175); + case 190: /* distinct ::= */ yytestcase(yyruleno==190); { yymsp[1].minor.yy0.n = 0;} break; case 55: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 57: /* cmd ::= CREATE DNODE ids */ -{ setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} + case 57: /* cmd ::= CREATE DNODE ids PORT ids */ + case 58: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==58); +{ setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 58: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy341);} + case 59: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; - case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &yymsp[-2].minor.yy0);} + case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy16, &yymsp[-2].minor.yy0);} break; - case 60: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy290, &yymsp[0].minor.yy0, 1);} + case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 1);} break; - case 61: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy290, &yymsp[0].minor.yy0, 2);} + case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 2);} break; - case 62: /* cmd ::= CREATE USER ids PASS ids */ + case 63: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 63: /* bufsize ::= */ - case 65: /* pps ::= */ yytestcase(yyruleno==65); - case 67: /* tseries ::= */ yytestcase(yyruleno==67); - case 69: /* dbs ::= */ yytestcase(yyruleno==69); - case 71: /* streams ::= */ yytestcase(yyruleno==71); - case 73: /* storage ::= */ yytestcase(yyruleno==73); - case 75: /* qtime ::= */ yytestcase(yyruleno==75); - case 77: /* users ::= */ yytestcase(yyruleno==77); - case 79: /* conns ::= */ yytestcase(yyruleno==79); - case 81: /* state ::= */ yytestcase(yyruleno==81); + case 64: /* bufsize ::= */ + case 66: /* pps ::= */ yytestcase(yyruleno==66); + case 68: /* tseries ::= */ yytestcase(yyruleno==68); + case 70: /* dbs ::= */ yytestcase(yyruleno==70); + case 72: /* streams ::= */ yytestcase(yyruleno==72); + case 74: /* storage ::= */ yytestcase(yyruleno==74); + case 76: /* qtime ::= */ yytestcase(yyruleno==76); + case 78: /* users ::= */ yytestcase(yyruleno==78); + case 80: /* conns ::= */ yytestcase(yyruleno==80); + case 82: /* state ::= */ yytestcase(yyruleno==82); { yymsp[1].minor.yy0.n = 0; } break; - case 64: /* bufsize ::= BUFSIZE INTEGER */ - case 66: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==66); - case 68: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==68); - case 70: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==70); - case 72: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==72); - case 74: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==74); - case 76: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==76); - case 78: /* users ::= USERS INTEGER */ yytestcase(yyruleno==78); - case 80: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==80); - case 82: /* state ::= STATE ids */ yytestcase(yyruleno==82); + case 65: /* bufsize ::= BUFSIZE INTEGER */ + case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); + case 69: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==69); + case 71: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==71); + case 73: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==73); + case 75: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==75); + case 77: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==77); + case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); + case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); + case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 83: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ -{ - yylhsminor.yy341.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy341.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy341.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy341.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy341.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy341.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy341.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy341.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy341.stat = yymsp[0].minor.yy0; -} - yymsp[-8].minor.yy341 = yylhsminor.yy341; - break; - case 84: /* intitemlist ::= intitemlist COMMA intitem */ - case 148: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==148); -{ yylhsminor.yy131 = tListItemAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy43, -1); } - yymsp[-2].minor.yy131 = yylhsminor.yy131; - break; - case 85: /* intitemlist ::= intitem */ - case 149: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==149); -{ yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[0].minor.yy43, -1); } - yymsp[0].minor.yy131 = yylhsminor.yy131; - break; - case 86: /* intitem ::= INTEGER */ - case 150: /* tagitem ::= INTEGER */ yytestcase(yyruleno==150); - case 151: /* tagitem ::= FLOAT */ yytestcase(yyruleno==151); - case 152: /* tagitem ::= STRING */ yytestcase(yyruleno==152); - case 153: /* tagitem ::= BOOL */ yytestcase(yyruleno==153); -{ toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } - yymsp[0].minor.yy43 = yylhsminor.yy43; - break; - case 87: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy131 = yymsp[0].minor.yy131; } - break; - case 88: /* cache ::= CACHE INTEGER */ - case 89: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==89); - case 90: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==90); - case 91: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==91); - case 92: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==92); - case 93: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==93); - case 94: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==94); - case 95: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==95); - case 96: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==96); - case 97: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==97); - case 98: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==98); - case 99: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==99); - case 100: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==100); - case 101: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==101); + case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ +{ + yylhsminor.yy211.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy211.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy211.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy211.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy211.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy211.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy211.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy211.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy211.stat = yymsp[0].minor.yy0; +} + yymsp[-8].minor.yy211 = yylhsminor.yy211; + break; + case 85: /* intitemlist ::= intitemlist COMMA intitem */ + case 163: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==163); +{ yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } + yymsp[-2].minor.yy165 = yylhsminor.yy165; + break; + case 86: /* intitemlist ::= intitem */ + case 164: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==164); +{ yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } + yymsp[0].minor.yy165 = yylhsminor.yy165; + break; + case 87: /* intitem ::= INTEGER */ + case 165: /* tagitem ::= INTEGER */ yytestcase(yyruleno==165); + case 166: /* tagitem ::= FLOAT */ yytestcase(yyruleno==166); + case 167: /* tagitem ::= STRING */ yytestcase(yyruleno==167); + case 168: /* tagitem ::= BOOL */ yytestcase(yyruleno==168); +{ toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } + yymsp[0].minor.yy425 = yylhsminor.yy425; + break; + case 88: /* keep ::= KEEP intitemlist */ +{ yymsp[-1].minor.yy165 = yymsp[0].minor.yy165; } + break; + case 89: /* cache ::= CACHE INTEGER */ + case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); + case 91: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==91); + case 92: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==92); + case 93: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==93); + case 94: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==94); + case 95: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==95); + case 96: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==96); + case 97: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==97); + case 98: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==98); + case 99: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==99); + case 100: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==100); + case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); + case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); + case 103: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==103); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 102: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy42);} + case 104: /* db_optr ::= */ +{setDefaultCreateDbOption(&yymsp[1].minor.yy16);} + break; + case 105: /* db_optr ::= db_optr cache */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 103: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 106: /* db_optr ::= db_optr replica */ + case 122: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==122); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 104: /* db_optr ::= db_optr replica */ - case 119: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==119); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 107: /* db_optr ::= db_optr quorum */ + case 123: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==123); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 105: /* db_optr ::= db_optr quorum */ - case 120: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==120); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 108: /* db_optr ::= db_optr days */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 106: /* db_optr ::= db_optr days */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 109: /* db_optr ::= db_optr minrows */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 107: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 110: /* db_optr ::= db_optr maxrows */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 108: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 111: /* db_optr ::= db_optr blocks */ + case 125: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==125); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 109: /* db_optr ::= db_optr blocks */ - case 122: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==122); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 112: /* db_optr ::= db_optr ctime */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 110: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 113: /* db_optr ::= db_optr wal */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 111: /* db_optr ::= db_optr wal */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 114: /* db_optr ::= db_optr fsync */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 112: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 115: /* db_optr ::= db_optr comp */ + case 126: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==126); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 113: /* db_optr ::= db_optr comp */ - case 123: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==123); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 116: /* db_optr ::= db_optr prec */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 114: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 117: /* db_optr ::= db_optr keep */ + case 124: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==124); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.keep = yymsp[0].minor.yy165; } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 115: /* db_optr ::= db_optr keep */ - case 121: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==121); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.keep = yymsp[0].minor.yy131; } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 118: /* db_optr ::= db_optr update */ + case 127: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==127); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 116: /* db_optr ::= db_optr update */ - case 124: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==124); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 119: /* db_optr ::= db_optr cachelast */ + case 128: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==128); +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 117: /* db_optr ::= db_optr cachelast */ - case 125: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==125); -{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 120: /* db_optr ::= db_optr vgroups */ +{ yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfVgroups = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 118: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy42);} + case 121: /* alter_db_optr ::= */ +{ setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 126: /* typename ::= ids */ + case 129: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy290, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy106, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy290 = yylhsminor.yy290; + yymsp[0].minor.yy106 = yylhsminor.yy106; break; - case 127: /* typename ::= ids LP signed RP */ + case 130: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy459 <= 0) { + if (yymsp[-1].minor.yy207 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy290, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy106, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy459; // negative value of name length - tSetColumnType(&yylhsminor.yy290, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy207; // negative value of name length + tSetColumnType(&yylhsminor.yy106, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy290 = yylhsminor.yy290; + yymsp[-3].minor.yy106 = yylhsminor.yy106; break; - case 128: /* typename ::= ids UNSIGNED */ + case 131: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yylhsminor.yy290, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy106, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy290 = yylhsminor.yy290; + yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 129: /* signed ::= INTEGER */ -{ yylhsminor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy459 = yylhsminor.yy459; + case 132: /* signed ::= INTEGER */ +{ yylhsminor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy207 = yylhsminor.yy207; break; - case 130: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 133: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 131: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy459 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} + case 134: /* signed ::= MINUS INTEGER */ +{ yymsp[-1].minor.yy207 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 135: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy272;} + case 138: /* cmd ::= CREATE TABLE create_table_list */ +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy326;} break; - case 136: /* create_table_list ::= create_from_stable */ + case 139: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy96); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy150); pCreateTable->type = TSQL_CREATE_CTABLE; - yylhsminor.yy272 = pCreateTable; + yylhsminor.yy326 = pCreateTable; } - yymsp[0].minor.yy272 = yylhsminor.yy272; + yymsp[0].minor.yy326 = yylhsminor.yy326; break; - case 137: /* create_table_list ::= create_table_list create_from_stable */ + case 140: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy272->childTableInfo, &yymsp[0].minor.yy96); - yylhsminor.yy272 = yymsp[-1].minor.yy272; + taosArrayPush(yymsp[-1].minor.yy326->childTableInfo, &yymsp[0].minor.yy150); + yylhsminor.yy326 = yymsp[-1].minor.yy326; } - yymsp[-1].minor.yy272 = yylhsminor.yy272; + yymsp[-1].minor.yy326 = yylhsminor.yy326; break; - case 138: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 141: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-1].minor.yy131, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } - yymsp[-5].minor.yy272 = yylhsminor.yy272; + yymsp[-5].minor.yy326 = yylhsminor.yy326; break; - case 139: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 142: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy272 = yylhsminor.yy272; + yymsp[-9].minor.yy326 = yylhsminor.yy326; break; - case 140: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy131, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy150 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy165, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy96 = yylhsminor.yy96; + yymsp[-9].minor.yy150 = yylhsminor.yy150; break; - case 141: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + case 144: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy150 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy96 = yylhsminor.yy96; + yymsp[-12].minor.yy150 = yylhsminor.yy150; break; - case 142: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy0); yylhsminor.yy131 = yymsp[-2].minor.yy131; } - yymsp[-2].minor.yy131 = yylhsminor.yy131; + case 145: /* tagNamelist ::= tagNamelist COMMA ids */ +{taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165; } + yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 143: /* tagNamelist ::= ids */ -{yylhsminor.yy131 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy131 = yylhsminor.yy131; + case 146: /* tagNamelist ::= ids */ +{yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 144: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 147: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy272 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy256, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } - yymsp[-4].minor.yy272 = yylhsminor.yy272; + yymsp[-4].minor.yy326 = yylhsminor.yy326; break; - case 145: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy290); yylhsminor.yy131 = yymsp[-2].minor.yy131; } - yymsp[-2].minor.yy131 = yylhsminor.yy131; + case 148: /* columnlist ::= columnlist COMMA column */ +{taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy106); yylhsminor.yy165 = yymsp[-2].minor.yy165; } + yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 146: /* columnlist ::= column */ -{yylhsminor.yy131 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy290);} - yymsp[0].minor.yy131 = yylhsminor.yy131; + case 149: /* columnlist ::= column */ +{yylhsminor.yy165 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy106);} + yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 147: /* column ::= ids typename */ + case 150: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy290, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy290); + tSetColumnInfo(&yylhsminor.yy106, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy106); } - yymsp[-1].minor.yy290 = yylhsminor.yy290; + yymsp[-1].minor.yy106 = yylhsminor.yy106; + break; + case 151: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ +{ taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165;} + yymsp[-2].minor.yy165 = yylhsminor.yy165; + break; + case 152: /* tagitemlist1 ::= tagitem1 */ +{ yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy165 = yylhsminor.yy165; + break; + case 153: /* tagitem1 ::= MINUS INTEGER */ + case 154: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==154); + case 155: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==155); + case 156: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==156); +{ yylhsminor.yy0.n = yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n; yylhsminor.yy0.type = yymsp[0].minor.yy0.type; } + yymsp[-1].minor.yy0 = yylhsminor.yy0; + break; + case 157: /* tagitem1 ::= INTEGER */ + case 158: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==158); + case 159: /* tagitem1 ::= STRING */ yytestcase(yyruleno==159); + case 160: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==160); + case 161: /* tagitem1 ::= NULL */ yytestcase(yyruleno==161); + case 162: /* tagitem1 ::= NOW */ yytestcase(yyruleno==162); +{ yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 154: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } - yymsp[0].minor.yy43 = yylhsminor.yy43; + case 169: /* tagitem ::= NULL */ +{ yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } + yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 155: /* tagitem ::= NOW */ -{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} - yymsp[0].minor.yy43 = yylhsminor.yy43; + case 170: /* tagitem ::= NOW */ +{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} + yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 156: /* tagitem ::= MINUS INTEGER */ - case 157: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==157); - case 158: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==158); - case 159: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==159); + case 171: /* tagitem ::= MINUS INTEGER */ + case 172: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==172); + case 173: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==173); + case 174: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==174); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - taosVariantCreate(&yylhsminor.yy43, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); + taosVariantCreate(&yylhsminor.yy425, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); } - yymsp[-1].minor.yy43 = yylhsminor.yy43; + yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 160: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 175: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { - yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy131, yymsp[-11].minor.yy544, yymsp[-10].minor.yy46, yymsp[-4].minor.yy131, yymsp[-2].minor.yy131, &yymsp[-9].minor.yy530, &yymsp[-7].minor.yy39, &yymsp[-6].minor.yy538, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, &yymsp[0].minor.yy55, &yymsp[-1].minor.yy55, yymsp[-3].minor.yy46); + yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy165, yymsp[-11].minor.yy10, yymsp[-10].minor.yy202, yymsp[-4].minor.yy165, yymsp[-2].minor.yy165, &yymsp[-9].minor.yy532, &yymsp[-7].minor.yy97, &yymsp[-6].minor.yy6, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy165, &yymsp[0].minor.yy367, &yymsp[-1].minor.yy367, yymsp[-3].minor.yy202); } - yymsp[-13].minor.yy256 = yylhsminor.yy256; + yymsp[-13].minor.yy278 = yylhsminor.yy278; break; - case 161: /* select ::= LP select RP */ -{yymsp[-2].minor.yy256 = yymsp[-1].minor.yy256;} + case 176: /* select ::= LP select RP */ +{yymsp[-2].minor.yy278 = yymsp[-1].minor.yy278;} break; - case 162: /* union ::= select */ -{ yylhsminor.yy303 = setSubclause(NULL, yymsp[0].minor.yy256); } - yymsp[0].minor.yy303 = yylhsminor.yy303; + case 177: /* union ::= select */ +{ yylhsminor.yy503 = setSubclause(NULL, yymsp[0].minor.yy278); } + yymsp[0].minor.yy503 = yylhsminor.yy503; break; - case 163: /* union ::= union UNION ALL select */ -{ yylhsminor.yy303 = appendSelectClause(yymsp[-3].minor.yy303, SQL_TYPE_UNIONALL, yymsp[0].minor.yy256); } - yymsp[-3].minor.yy303 = yylhsminor.yy303; + case 178: /* union ::= union UNION ALL select */ +{ yylhsminor.yy503 = appendSelectClause(yymsp[-3].minor.yy503, SQL_TYPE_UNIONALL, yymsp[0].minor.yy278); } + yymsp[-3].minor.yy503 = yylhsminor.yy503; break; - case 164: /* union ::= union UNION select */ -{ yylhsminor.yy303 = appendSelectClause(yymsp[-2].minor.yy303, SQL_TYPE_UNION, yymsp[0].minor.yy256); } - yymsp[-2].minor.yy303 = yylhsminor.yy303; + case 179: /* union ::= union UNION select */ +{ yylhsminor.yy503 = appendSelectClause(yymsp[-2].minor.yy503, SQL_TYPE_UNION, yymsp[0].minor.yy278); } + yymsp[-2].minor.yy503 = yylhsminor.yy503; break; - case 165: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy303, NULL, TSDB_SQL_SELECT); } + case 180: /* cmd ::= union */ +{ setSqlInfo(pInfo, yymsp[0].minor.yy503, NULL, TSDB_SQL_SELECT); } break; - case 166: /* select ::= SELECT selcollist */ + case 181: /* select ::= SELECT selcollist */ { - yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy131, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy165, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + yymsp[-1].minor.yy278 = yylhsminor.yy278; break; - case 167: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy131 = yymsp[-1].minor.yy131;} - yymsp[-1].minor.yy131 = yylhsminor.yy131; + case 182: /* sclp ::= selcollist COMMA */ +{yylhsminor.yy165 = yymsp[-1].minor.yy165;} + yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 168: /* sclp ::= */ - case 200: /* orderby_opt ::= */ yytestcase(yyruleno==200); -{yymsp[1].minor.yy131 = 0;} + case 183: /* sclp ::= */ + case 215: /* orderby_opt ::= */ yytestcase(yyruleno==215); +{yymsp[1].minor.yy165 = 0;} break; - case 169: /* selcollist ::= sclp distinct expr as */ + case 184: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy131 = tSqlExprListAppend(yymsp[-3].minor.yy131, yymsp[-1].minor.yy46, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy165 = tSqlExprListAppend(yymsp[-3].minor.yy165, yymsp[-1].minor.yy202, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy131 = yylhsminor.yy131; + yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 170: /* selcollist ::= sclp STAR */ + case 185: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy131 = tSqlExprListAppend(yymsp[-1].minor.yy131, pNode, 0, 0); + yylhsminor.yy165 = tSqlExprListAppend(yymsp[-1].minor.yy165, pNode, 0, 0); } - yymsp[-1].minor.yy131 = yylhsminor.yy131; + yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 171: /* as ::= AS ids */ + case 186: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 172: /* as ::= ids */ + case 187: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 173: /* as ::= */ + case 188: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 174: /* distinct ::= DISTINCT */ + case 189: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 176: /* from ::= FROM tablelist */ - case 177: /* from ::= FROM sub */ yytestcase(yyruleno==177); -{yymsp[-1].minor.yy544 = yymsp[0].minor.yy544;} + case 191: /* from ::= FROM tablelist */ + case 192: /* from ::= FROM sub */ yytestcase(yyruleno==192); +{yymsp[-1].minor.yy10 = yymsp[0].minor.yy10;} break; - case 178: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy544 = addSubquery(NULL, yymsp[-1].minor.yy303, NULL);} + case 193: /* sub ::= LP union RP */ +{yymsp[-2].minor.yy10 = addSubquery(NULL, yymsp[-1].minor.yy503, NULL);} break; - case 179: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy544 = addSubquery(NULL, yymsp[-2].minor.yy303, &yymsp[0].minor.yy0);} + case 194: /* sub ::= LP union RP ids */ +{yymsp[-3].minor.yy10 = addSubquery(NULL, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} break; - case 180: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy544 = addSubquery(yymsp[-5].minor.yy544, yymsp[-2].minor.yy303, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy544 = yylhsminor.yy544; + case 195: /* sub ::= sub COMMA LP union RP ids */ +{yylhsminor.yy10 = addSubquery(yymsp[-5].minor.yy10, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy10 = yylhsminor.yy10; break; - case 181: /* tablelist ::= ids cpxName */ + case 196: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy544 = yylhsminor.yy544; + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; - case 182: /* tablelist ::= ids cpxName ids */ + case 197: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy544 = yylhsminor.yy544; + yymsp[-2].minor.yy10 = yylhsminor.yy10; break; - case 183: /* tablelist ::= tablelist COMMA ids cpxName */ + case 198: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy544 = setTableNameList(yymsp[-3].minor.yy544, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy10 = setTableNameList(yymsp[-3].minor.yy10, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy544 = yylhsminor.yy544; + yymsp[-3].minor.yy10 = yylhsminor.yy10; break; - case 184: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 199: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy544 = setTableNameList(yymsp[-4].minor.yy544, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy10 = setTableNameList(yymsp[-4].minor.yy10, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy544 = yylhsminor.yy544; + yymsp[-4].minor.yy10 = yylhsminor.yy10; break; - case 185: /* tmvar ::= VARIABLE */ + case 200: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 186: /* interval_option ::= intervalKey LP tmvar RP */ -{yylhsminor.yy530.interval = yymsp[-1].minor.yy0; yylhsminor.yy530.offset.n = 0; yylhsminor.yy530.token = yymsp[-3].minor.yy310;} - yymsp[-3].minor.yy530 = yylhsminor.yy530; + case 201: /* interval_option ::= intervalKey LP tmvar RP */ +{yylhsminor.yy532.interval = yymsp[-1].minor.yy0; yylhsminor.yy532.offset.n = 0; yylhsminor.yy532.token = yymsp[-3].minor.yy46;} + yymsp[-3].minor.yy532 = yylhsminor.yy532; break; - case 187: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ -{yylhsminor.yy530.interval = yymsp[-3].minor.yy0; yylhsminor.yy530.offset = yymsp[-1].minor.yy0; yylhsminor.yy530.token = yymsp[-5].minor.yy310;} - yymsp[-5].minor.yy530 = yylhsminor.yy530; + case 202: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ +{yylhsminor.yy532.interval = yymsp[-3].minor.yy0; yylhsminor.yy532.offset = yymsp[-1].minor.yy0; yylhsminor.yy532.token = yymsp[-5].minor.yy46;} + yymsp[-5].minor.yy532 = yylhsminor.yy532; break; - case 188: /* interval_option ::= */ -{memset(&yymsp[1].minor.yy530, 0, sizeof(yymsp[1].minor.yy530));} + case 203: /* interval_option ::= */ +{memset(&yymsp[1].minor.yy532, 0, sizeof(yymsp[1].minor.yy532));} break; - case 189: /* intervalKey ::= INTERVAL */ -{yymsp[0].minor.yy310 = TK_INTERVAL;} + case 204: /* intervalKey ::= INTERVAL */ +{yymsp[0].minor.yy46 = TK_INTERVAL;} break; - case 190: /* intervalKey ::= EVERY */ -{yymsp[0].minor.yy310 = TK_EVERY; } + case 205: /* intervalKey ::= EVERY */ +{yymsp[0].minor.yy46 = TK_EVERY; } break; - case 191: /* session_option ::= */ -{yymsp[1].minor.yy39.col.n = 0; yymsp[1].minor.yy39.gap.n = 0;} + case 206: /* session_option ::= */ +{yymsp[1].minor.yy97.col.n = 0; yymsp[1].minor.yy97.gap.n = 0;} break; - case 192: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 207: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy39.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy39.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy97.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy97.gap = yymsp[-1].minor.yy0; } break; - case 193: /* windowstate_option ::= */ -{ yymsp[1].minor.yy538.col.n = 0; yymsp[1].minor.yy538.col.z = NULL;} + case 208: /* windowstate_option ::= */ +{ yymsp[1].minor.yy6.col.n = 0; yymsp[1].minor.yy6.col.z = NULL;} break; - case 194: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ yymsp[-3].minor.yy538.col = yymsp[-1].minor.yy0; } + case 209: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ yymsp[-3].minor.yy6.col = yymsp[-1].minor.yy0; } break; - case 195: /* fill_opt ::= */ -{ yymsp[1].minor.yy131 = 0; } + case 210: /* fill_opt ::= */ +{ yymsp[1].minor.yy165 = 0; } break; - case 196: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 211: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { SVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); taosVariantCreate(&A, yymsp[-3].minor.yy0.z, yymsp[-3].minor.yy0.n, yymsp[-3].minor.yy0.type); - tListItemInsert(yymsp[-1].minor.yy131, &A, -1, 0); - yymsp[-5].minor.yy131 = yymsp[-1].minor.yy131; + tListItemInsert(yymsp[-1].minor.yy165, &A, -1, 0); + yymsp[-5].minor.yy165 = yymsp[-1].minor.yy165; } break; - case 197: /* fill_opt ::= FILL LP ID RP */ + case 212: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy131 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy165 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 198: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 213: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 199: /* sliding_opt ::= */ + case 214: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 201: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} + case 216: /* orderby_opt ::= ORDER BY sortlist */ +{yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 202: /* sortlist ::= sortlist COMMA item sortorder */ + case 217: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy131 = tListItemAppend(yymsp[-3].minor.yy131, &yymsp[-1].minor.yy43, yymsp[0].minor.yy44); + yylhsminor.yy165 = tListItemAppend(yymsp[-3].minor.yy165, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } - yymsp[-3].minor.yy131 = yylhsminor.yy131; + yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 203: /* sortlist ::= item sortorder */ + case 218: /* sortlist ::= item sortorder */ { - yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[-1].minor.yy43, yymsp[0].minor.yy44); + yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } - yymsp[-1].minor.yy131 = yylhsminor.yy131; + yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 204: /* item ::= ids cpxName */ + case 219: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - taosVariantCreate(&yylhsminor.yy43, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); + taosVariantCreate(&yylhsminor.yy425, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); } - yymsp[-1].minor.yy43 = yylhsminor.yy43; + yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 205: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy44 = TSDB_ORDER_ASC; } + case 220: /* sortorder ::= ASC */ +{ yymsp[0].minor.yy47 = TSDB_ORDER_ASC; } break; - case 206: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy44 = TSDB_ORDER_DESC;} + case 221: /* sortorder ::= DESC */ +{ yymsp[0].minor.yy47 = TSDB_ORDER_DESC;} break; - case 207: /* sortorder ::= */ -{ yymsp[1].minor.yy44 = TSDB_ORDER_ASC; } + case 222: /* sortorder ::= */ +{ yymsp[1].minor.yy47 = TSDB_ORDER_ASC; } break; - case 208: /* groupby_opt ::= */ -{ yymsp[1].minor.yy131 = 0;} + case 223: /* groupby_opt ::= */ +{ yymsp[1].minor.yy165 = 0;} break; - case 209: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} + case 224: /* groupby_opt ::= GROUP BY grouplist */ +{ yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 210: /* grouplist ::= grouplist COMMA item */ + case 225: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy131 = tListItemAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy43, -1); + yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } - yymsp[-2].minor.yy131 = yylhsminor.yy131; + yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 211: /* grouplist ::= item */ + case 226: /* grouplist ::= item */ { - yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[0].minor.yy43, -1); + yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } - yymsp[0].minor.yy131 = yylhsminor.yy131; + yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 212: /* having_opt ::= */ - case 222: /* where_opt ::= */ yytestcase(yyruleno==222); - case 266: /* expritem ::= */ yytestcase(yyruleno==266); -{yymsp[1].minor.yy46 = 0;} + case 227: /* having_opt ::= */ + case 237: /* where_opt ::= */ yytestcase(yyruleno==237); + case 281: /* expritem ::= */ yytestcase(yyruleno==281); +{yymsp[1].minor.yy202 = 0;} break; - case 213: /* having_opt ::= HAVING expr */ - case 223: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==223); -{yymsp[-1].minor.yy46 = yymsp[0].minor.yy46;} + case 228: /* having_opt ::= HAVING expr */ + case 238: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==238); +{yymsp[-1].minor.yy202 = yymsp[0].minor.yy202;} break; - case 214: /* limit_opt ::= */ - case 218: /* slimit_opt ::= */ yytestcase(yyruleno==218); -{yymsp[1].minor.yy55.limit = -1; yymsp[1].minor.yy55.offset = 0;} + case 229: /* limit_opt ::= */ + case 233: /* slimit_opt ::= */ yytestcase(yyruleno==233); +{yymsp[1].minor.yy367.limit = -1; yymsp[1].minor.yy367.offset = 0;} break; - case 215: /* limit_opt ::= LIMIT signed */ - case 219: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==219); -{yymsp[-1].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-1].minor.yy55.offset = 0;} + case 230: /* limit_opt ::= LIMIT signed */ + case 234: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==234); +{yymsp[-1].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-1].minor.yy367.offset = 0;} break; - case 216: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy55.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[0].minor.yy459;} + case 231: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 217: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[-2].minor.yy459;} + case 232: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 220: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy55.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[0].minor.yy459;} + case 235: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 221: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[-2].minor.yy459;} + case 236: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 224: /* expr ::= LP expr RP */ -{yylhsminor.yy46 = yymsp[-1].minor.yy46; yylhsminor.yy46->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy46->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 239: /* expr ::= LP expr RP */ +{yylhsminor.yy202 = yymsp[-1].minor.yy202; yylhsminor.yy202->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy202->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 225: /* expr ::= ID */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 240: /* expr ::= ID */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 226: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 241: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 227: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 242: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 228: /* expr ::= INTEGER */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 243: /* expr ::= INTEGER */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 229: /* expr ::= MINUS INTEGER */ - case 230: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==230); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy46 = yylhsminor.yy46; + case 244: /* expr ::= MINUS INTEGER */ + case 245: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==245); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 231: /* expr ::= FLOAT */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 246: /* expr ::= FLOAT */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 232: /* expr ::= MINUS FLOAT */ - case 233: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==233); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy46 = yylhsminor.yy46; + case 247: /* expr ::= MINUS FLOAT */ + case 248: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==248); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 234: /* expr ::= STRING */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 249: /* expr ::= STRING */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 235: /* expr ::= NOW */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 250: /* expr ::= NOW */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 236: /* expr ::= VARIABLE */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 251: /* expr ::= VARIABLE */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 237: /* expr ::= PLUS VARIABLE */ - case 238: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==238); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy46 = yylhsminor.yy46; + case 252: /* expr ::= PLUS VARIABLE */ + case 253: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==253); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 239: /* expr ::= BOOL */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 254: /* expr ::= BOOL */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 240: /* expr ::= NULL */ -{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 255: /* expr ::= NULL */ +{ yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 241: /* expr ::= ID LP exprlist RP */ -{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(yymsp[-1].minor.yy131, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy46 = yylhsminor.yy46; + case 256: /* expr ::= ID LP exprlist RP */ +{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(yymsp[-1].minor.yy165, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 242: /* expr ::= ID LP STAR RP */ -{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy46 = yylhsminor.yy46; + case 257: /* expr ::= ID LP STAR RP */ +{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 243: /* expr ::= expr IS NULL */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, NULL, TK_ISNULL);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 258: /* expr ::= expr IS NULL */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, NULL, TK_ISNULL);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 244: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-3].minor.yy46, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy46 = yylhsminor.yy46; + case 259: /* expr ::= expr IS NOT NULL */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-3].minor.yy202, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 245: /* expr ::= expr LT expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LT);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 260: /* expr ::= expr LT expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LT);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 246: /* expr ::= expr GT expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GT);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 261: /* expr ::= expr GT expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GT);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 247: /* expr ::= expr LE expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LE);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 262: /* expr ::= expr LE expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LE);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 248: /* expr ::= expr GE expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GE);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 263: /* expr ::= expr GE expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GE);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 249: /* expr ::= expr NE expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_NE);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 264: /* expr ::= expr NE expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NE);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 250: /* expr ::= expr EQ expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_EQ);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 265: /* expr ::= expr EQ expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_EQ);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 251: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy46); yylhsminor.yy46 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy46, yymsp[-2].minor.yy46, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy46, TK_LE), TK_AND);} - yymsp[-4].minor.yy46 = yylhsminor.yy46; + case 266: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy202); yylhsminor.yy202 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy202, yymsp[-2].minor.yy202, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy202, TK_LE), TK_AND);} + yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 252: /* expr ::= expr AND expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_AND);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 267: /* expr ::= expr AND expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_AND);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 253: /* expr ::= expr OR expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_OR); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 268: /* expr ::= expr OR expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_OR); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 254: /* expr ::= expr PLUS expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_PLUS); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 269: /* expr ::= expr PLUS expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_PLUS); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 255: /* expr ::= expr MINUS expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_MINUS); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 270: /* expr ::= expr MINUS expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MINUS); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 256: /* expr ::= expr STAR expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_STAR); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 271: /* expr ::= expr STAR expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_STAR); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 257: /* expr ::= expr SLASH expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_DIVIDE);} - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 272: /* expr ::= expr SLASH expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_DIVIDE);} + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 258: /* expr ::= expr REM expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_REM); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 273: /* expr ::= expr REM expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_REM); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 259: /* expr ::= expr LIKE expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LIKE); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 274: /* expr ::= expr LIKE expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LIKE); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 260: /* expr ::= expr MATCH expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_MATCH); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 275: /* expr ::= expr MATCH expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MATCH); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 261: /* expr ::= expr NMATCH expr */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_NMATCH); } - yymsp[-2].minor.yy46 = yylhsminor.yy46; + case 276: /* expr ::= expr NMATCH expr */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NMATCH); } + yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 262: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy46 = tSqlExprCreate(yymsp[-4].minor.yy46, (tSqlExpr*)yymsp[-1].minor.yy131, TK_IN); } - yymsp[-4].minor.yy46 = yylhsminor.yy46; + case 277: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy202 = tSqlExprCreate(yymsp[-4].minor.yy202, (tSqlExpr*)yymsp[-1].minor.yy165, TK_IN); } + yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 263: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy131 = tSqlExprListAppend(yymsp[-2].minor.yy131,yymsp[0].minor.yy46,0, 0);} - yymsp[-2].minor.yy131 = yylhsminor.yy131; + case 278: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy165 = tSqlExprListAppend(yymsp[-2].minor.yy165,yymsp[0].minor.yy202,0, 0);} + yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 264: /* exprlist ::= expritem */ -{yylhsminor.yy131 = tSqlExprListAppend(0,yymsp[0].minor.yy46,0, 0);} - yymsp[0].minor.yy131 = yylhsminor.yy131; + case 279: /* exprlist ::= expritem */ +{yylhsminor.yy165 = tSqlExprListAppend(0,yymsp[0].minor.yy202,0, 0);} + yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 265: /* expritem ::= expr */ -{yylhsminor.yy46 = yymsp[0].minor.yy46;} - yymsp[0].minor.yy46 = yylhsminor.yy46; + case 280: /* expritem ::= expr */ +{yylhsminor.yy202 = yymsp[0].minor.yy202;} + yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 267: /* cmd ::= RESET QUERY CACHE */ + case 282: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 268: /* cmd ::= SYNCDB ids REPLICA */ + case 283: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 269: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 284: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 270: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 285: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); @@ -3140,21 +3201,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 271: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 286: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 272: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 287: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 273: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 288: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3165,7 +3226,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 274: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 289: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3179,33 +3240,33 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 275: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 290: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tListItemAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tListItemAppend(A, &yymsp[0].minor.yy43, -1); + A = tListItemAppend(A, &yymsp[0].minor.yy425, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 276: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 291: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 277: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 292: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 278: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 293: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3216,21 +3277,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 279: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 294: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 280: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 295: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 281: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 296: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3241,7 +3302,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 282: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 297: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3255,32 +3316,32 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 283: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 298: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tListItemAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tListItemAppend(A, &yymsp[0].minor.yy43, -1); + A = tListItemAppend(A, &yymsp[0].minor.yy425, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 284: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 299: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= KILL CONNECTION INTEGER */ + case 300: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 286: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 301: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 287: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 302: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/source/libs/parser/src/ttokenizer.c b/source/libs/parser/src/ttokenizer.c index 4e6b77a3d653088f091b8711b6e5843b59fe7ce7..8e5b22aaa3b6f1aa9a46529d701e8a461da844a3 100644 --- a/source/libs/parser/src/ttokenizer.c +++ b/source/libs/parser/src/ttokenizer.c @@ -31,17 +31,17 @@ typedef struct SKeyword { static SKeyword keywordTable[] = { {"ID", TK_ID}, {"BOOL", TK_BOOL}, - {"TINYINT", TK_TINYINT}, - {"SMALLINT", TK_SMALLINT}, +// {"TINYINT", TK_TINYINT}, +// {"SMALLINT", TK_SMALLINT}, {"INTEGER", TK_INTEGER}, {"INT", TK_INTEGER}, - {"BIGINT", TK_BIGINT}, +// {"BIGINT", TK_BIGINT}, {"FLOAT", TK_FLOAT}, - {"DOUBLE", TK_DOUBLE}, +// {"DOUBLE", TK_DOUBLE}, {"STRING", TK_STRING}, {"TIMESTAMP", TK_TIMESTAMP}, - {"BINARY", TK_BINARY}, - {"NCHAR", TK_NCHAR}, +// {"BINARY", TK_BINARY}, +// {"NCHAR", TK_NCHAR}, {"OR", TK_OR}, {"AND", TK_AND}, {"NOT", TK_NOT}, @@ -70,7 +70,7 @@ static SKeyword keywordTable[] = { {"STAR", TK_STAR}, {"SLASH", TK_SLASH}, {"REM ", TK_REM}, - {"||", TK_CONCAT}, + {"||", TK_CONCAT}, {"UMINUS", TK_UMINUS}, {"UPLUS", TK_UPLUS}, {"BITNOT", TK_BITNOT}, @@ -227,6 +227,7 @@ static SKeyword keywordTable[] = { {"OUTPUTTYPE", TK_OUTPUTTYPE}, {"AGGREGATE", TK_AGGREGATE}, {"BUFSIZE", TK_BUFSIZE}, + {"PORT", TK_PORT}, }; static const char isIdChar[] = { @@ -671,7 +672,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { } } - t0.z = str + (*i); + t0.z = (char*) str + (*i); *i += t0.n; return t0; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index d7f410a01eadc3cc7151a660b09dc3ee33d45884..e8d975c22e93ac2a30882301d36e7aaa22a959c2 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -45,12 +45,12 @@ int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandl return 0; } -int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) { - return mockCatalogService->catalogGetTableMeta(pDBName, pTableName, pTableMeta); +int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta); } -int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) { - return mockCatalogService->catalogGetTableHashVgroup(pDBName, pTableName, vgInfo); +int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) { + return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo); } void initMetaDataEnv() { diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 520ef3a89bd25a10e8e125ac54bcd3c2e2e4a4ea..3be358fec8478ffd482da55bfabe64f917c62a3c 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -94,9 +94,14 @@ public: return 0; } - int32_t catalogGetTableMeta(const char* pDbFullName, const char* pTableName, STableMeta** pTableMeta) const { + int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { std::unique_ptr table; - int32_t code = copyTableSchemaMeta(toDbname(pDbFullName), pTableName, &table); + + char db[TSDB_DB_NAME_LEN] = {0}; + tNameGetDbName(pTableName, db); + + const char* tname = tNameGetTableName(pTableName); + int32_t code = copyTableSchemaMeta(db, tname, &table); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -104,8 +109,9 @@ public: return TSDB_CODE_SUCCESS; } - int32_t catalogGetTableHashVgroup(const char* pDbFullName, const char* pTableName, SVgroupInfo* vgInfo) const { + int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { // todo + vgInfo->vgId = 1; return 0; } @@ -283,10 +289,10 @@ std::shared_ptr MockCatalogService::getTableMeta(const std::strin return impl_->getTableMeta(db, tbname); } -int32_t MockCatalogService::catalogGetTableMeta(const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const { - return impl_->catalogGetTableMeta(pDBName, pTableName, pTableMeta); +int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { + return impl_->catalogGetTableMeta(pTableName, pTableMeta); } -int32_t MockCatalogService::catalogGetTableHashVgroup(const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) const { - return impl_->catalogGetTableHashVgroup(pDBName, pTableName, vgInfo); +int32_t MockCatalogService::catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { + return impl_->catalogGetTableHashVgroup(pTableName, vgInfo); } \ No newline at end of file diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index 889a45439715792d09a33d4c9073b4175a275dca..b9713316351d458cbf6631480b0881a5fd901858 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -57,8 +57,8 @@ public: void showTables() const; std::shared_ptr getTableMeta(const std::string& db, const std::string& tbname) const; - int32_t catalogGetTableMeta(const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const; - int32_t catalogGetTableHashVgroup(const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) const; + int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const; + int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; private: std::unique_ptr impl_; diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index f2cb4864fba79e06e16b454ea8e0f9f695e828b0..423aa1a7bedcdc3a8920925924c4c06260448602 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -715,7 +715,7 @@ TEST(testCase, show_user_Test) { ASSERT_EQ(info1.valid, true); SDclStmtInfo output; - SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc", .pTransporter = NULL}; int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0); @@ -736,7 +736,7 @@ TEST(testCase, create_user_Test) { ASSERT_EQ(isDclSqlStatement(&info1), true); SDclStmtInfo output; - SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc"}; int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0); diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index ed29839905d47f2e40753123b3c50bd8464d9f84..35c6d59ffe1214f68f1b9930d18684baed769d81 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -24,7 +24,7 @@ extern "C" { #include "tarray.h" #include "planner.h" #include "parser.h" -#include "taosmsg.h" +#include "tmsg.h" #define QNODE_TAGSCAN 1 #define QNODE_TABLESCAN 2 diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 8388458b4c0ea0d04d505aac5f765d890a485d88..97c9cec7c7b31345c2065daf79f6a4f389a3e10b 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -207,6 +207,7 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { } taosArrayPush(currentLevel, &subplan); pCxt->pCurrentSubplan = subplan; + ++(pCxt->pDag->numOfSubplans); return subplan; } @@ -293,11 +294,14 @@ static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { SArray* vgs = (SArray*)pPlanNode->pExtInfo; size_t numOfVg = taosArrayGetSize(vgs); for (int32_t i = 0; i < numOfVg; ++i) { + STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); subplan->pNode = NULL; subplan->pDataSink = createDataInserter(pCxt, blocks); + subplan->type = QUERY_TYPE_MODIFY; + RECOVERY_CURRENT_SUBPLAN(pCxt); } } diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 5a1b2a6da298d03c81e6e3bae15052693d2f27f7..9b2c9c1796cafb2b0b66dbbc2c0d5a19c37a8867 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -857,3 +857,84 @@ int32_t stringToSubplan(const char* str, SSubplan** subplan) { *subplan = subplanFromJson(json); return (NULL == *subplan ? TSDB_CODE_FAILED : TSDB_CODE_SUCCESS); } + +cJSON* qDagToJson(const SQueryDag* pDag) { + cJSON* pRoot = cJSON_CreateObject(); + if(pRoot == NULL) { + return NULL; + } + cJSON_AddNumberToObject(pRoot, "numOfSubplans", pDag->numOfSubplans); + cJSON_AddNumberToObject(pRoot, "queryId", pDag->queryId); + cJSON *pLevels = cJSON_CreateArray(); + if(pLevels == NULL) { + cJSON_Delete(pRoot); + return NULL; + } + cJSON_AddItemToObject(pRoot, "pSubplans", pLevels); + size_t level = taosArrayGetSize(pDag->pSubplans); + for(size_t i = 0; i < level; i++) { + const SArray* pSubplans = (const SArray*)taosArrayGetP(pDag->pSubplans, i); + size_t num = taosArrayGetSize(pSubplans); + cJSON* plansOneLevel = cJSON_CreateArray(); + if(plansOneLevel == NULL) { + cJSON_Delete(pRoot); + return NULL; + } + cJSON_AddItemToArray(pLevels, plansOneLevel); + for(size_t j = 0; j < num; j++) { + cJSON* pSubplan = subplanToJson((const SSubplan*)taosArrayGetP(pSubplans, j)); + if(pSubplan == NULL) { + cJSON_Delete(pRoot); + return NULL; + } + cJSON_AddItemToArray(plansOneLevel, pSubplan); + } + } + return pRoot; +} + +char* qDagToString(const SQueryDag* pDag) { + cJSON* pRoot = qDagToJson(pDag); + return cJSON_Print(pRoot); +} + +SQueryDag* qJsonToDag(const cJSON* pRoot) { + SQueryDag* pDag = malloc(sizeof(SQueryDag)); + if(pDag == NULL) { + return NULL; + } + pDag->numOfSubplans = cJSON_GetNumberValue(cJSON_GetObjectItem(pRoot, "numOfSubplans")); + pDag->queryId = cJSON_GetNumberValue(cJSON_GetObjectItem(pRoot, "queryId")); + pDag->pSubplans = taosArrayInit(0, sizeof(SArray)); + if (pDag->pSubplans == NULL) { + free(pDag); + return NULL; + } + cJSON* pLevels = cJSON_GetObjectItem(pRoot, "pSubplans"); + int level = cJSON_GetArraySize(pLevels); + for(int i = 0; i < level; i++) { + SArray* plansOneLevel = taosArrayInit(0, sizeof(void*)); + if(plansOneLevel == NULL) { + for(int j = 0; j < i; j++) { + taosArrayDestroy(taosArrayGetP(pDag->pSubplans, j)); + } + taosArrayDestroy(pDag->pSubplans); + free(pDag); + return NULL; + } + cJSON* pItem = cJSON_GetArrayItem(pLevels, i); + int sz = cJSON_GetArraySize(pItem); + for(int j = 0; j < sz; j++) { + cJSON* pSubplanJson = cJSON_GetArrayItem(pItem, j); + SSubplan* pSubplan = subplanFromJson(pSubplanJson); + taosArrayPush(plansOneLevel, &pSubplan); + } + taosArrayPush(pDag->pSubplans, plansOneLevel); + } + return pDag; +} + +SQueryDag* qStringToDag(const char* pStr) { + cJSON* pRoot = cJSON_Parse(pStr); + return qJsonToDag(pRoot); +} diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index e8523249e4cede000d0e6114409c3893ad3fa55b..638177140000a19f49690a6d5a831fc3e41aa433 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -24,7 +24,7 @@ void qDestroyQueryDag(struct SQueryDag* pDag) { // todo } -int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SEpSet* pEpSet, struct SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) { SQueryPlanNode* logicPlan; int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index f14fd50e034f950b4b048fd8d19dabe6b606f1d4..02d06bb49d03c2aadc8cf0fa185cffd47cfbe9f3 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -60,7 +60,7 @@ protected: return code; } SQueryDag* dag = nullptr; - code = qCreateQueryDag(query, nullptr, &dag); + code = qCreateQueryDag(query, &dag); dag_.reset(dag); return code; } @@ -83,7 +83,7 @@ protected: } } - SQueryDag* reslut() { + SQueryDag* result() { return dag_.get(); } @@ -149,16 +149,23 @@ TEST_F(PhyPlanTest, tableScanTest) { pushScan("test", "t1", QNODE_TABLESCAN); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); explain(); - SQueryDag* dag = reslut(); + SQueryDag* dag = result(); // todo check } +TEST_F(PhyPlanTest, serializeTest) { + pushScan("test", "t1", QNODE_TABLESCAN); + ASSERT_EQ(run(), TSDB_CODE_SUCCESS); + SQueryDag* dag = result(); + cout << qDagToString(dag) << endl; +} + // select * from supertable TEST_F(PhyPlanTest, superTableScanTest) { pushScan("test", "st1", QNODE_TABLESCAN); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); explain(); - SQueryDag* dag = reslut(); + SQueryDag* dag = result(); // todo check } @@ -166,6 +173,6 @@ TEST_F(PhyPlanTest, superTableScanTest) { TEST_F(PhyPlanTest, insertTest) { ASSERT_EQ(run("test", "insert into t1 values (now, 1, \"beijing\")"), TSDB_CODE_SUCCESS); explain(); - SQueryDag* dag = reslut(); + SQueryDag* dag = result(); // todo check } diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 829f426c9ddf1e2be1d3cab0220188eb1ad0d0c8..90a4388485337eb46329cf17cf1eb705f05f5953 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -1,8 +1,9 @@ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #include "tglobal.h" #include "tsched.h" +#include "trpc.h" #define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS) #define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS) @@ -14,7 +15,7 @@ static struct SSchema _s = { .name = "tbname", }; -SSchema* tGetTbnameColumnSchema() { +const SSchema* tGetTbnameColumnSchema() { return &_s; } @@ -103,7 +104,7 @@ int32_t cleanupTaskQueue() { static void execHelper(struct SSchedMsg* pSchedMsg) { assert(pSchedMsg != NULL && pSchedMsg->ahandle != NULL); - __async_exec_fn_t* execFn = (__async_exec_fn_t*) pSchedMsg->ahandle; + __async_exec_fn_t execFn = (__async_exec_fn_t) pSchedMsg->ahandle; int32_t code = execFn(pSchedMsg->thandle); if (code != 0 && pSchedMsg->msg != NULL) { *(int32_t*) pSchedMsg->msg = code; @@ -121,3 +122,27 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code) taosScheduleTask(pTaskQueue, &schedMsg); } + +int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo) { + char *pMsg = rpcMallocCont(pInfo->msgInfo.len); + if (NULL == pMsg) { + qError("0x%"PRIx64" msg:%s malloc failed", pInfo->requestId, TMSG_INFO(pInfo->msgType)); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + return -1; + } + + memcpy(pMsg, pInfo->msgInfo.pData, pInfo->msgInfo.len); + SRpcMsg rpcMsg = { + .msgType = pInfo->msgType, + .pCont = pMsg, + .contLen = pInfo->msgInfo.len, + .ahandle = (void*) pInfo, + .handle = NULL, + .code = 0 + }; + + assert(pInfo->fp != NULL); + + rpcSendRequest(pTransporter, epSet, &rpcMsg, pTransporterId); + return TSDB_CODE_SUCCESS; +} \ No newline at end of file diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index eb5527f076f7e5ca59607af66d3582c9d0264dfc..27ca406fc47745d2857719865d079f371c22064b 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -13,13 +13,14 @@ * along with this program. If not, see . */ -#include "taosmsg.h" +#include "tmsg.h" #include "queryInt.h" #include "query.h" +#include "trpc.h" -int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen) = {0}; +int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen) = {0}; -int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize) = {0}; +int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize) = {0}; int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int32_t *msgLen) { if (NULL == input || NULL == msg || NULL == msgLen) { @@ -31,7 +32,7 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 int32_t estimateSize = sizeof(STableInfoMsg); if (NULL == *msg || msgSize < estimateSize) { tfree(*msg); - *msg = calloc(1, estimateSize); + *msg = rpcMallocCont(estimateSize); if (NULL == *msg) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -59,7 +60,7 @@ int32_t queryBuildUseDbMsg(void* input, char **msg, int32_t msgSize, int32_t *ms int32_t estimateSize = sizeof(SUseDbMsg); if (NULL == *msg || msgSize < estimateSize) { tfree(*msg); - *msg = calloc(1, estimateSize); + *msg = rpcMallocCont(estimateSize); if (NULL == *msg) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -92,8 +93,8 @@ int32_t queryProcessUseDBRsp(void* output, char *msg, int32_t msgSize) { return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE; } - pRsp->vgVersion = htonl(pRsp->vgVersion); - pRsp->vgNum = htonl(pRsp->vgNum); + pRsp->vgVersion = ntohl(pRsp->vgVersion); + pRsp->vgNum = ntohl(pRsp->vgNum); if (pRsp->vgNum < 0) { qError("invalid db[%s] vgroup number[%d]", pRsp->db, pRsp->vgNum); @@ -115,12 +116,12 @@ int32_t queryProcessUseDBRsp(void* output, char *msg, int32_t msgSize) { } for (int32_t i = 0; i < pRsp->vgNum; ++i) { - pRsp->vgroupInfo[i].vgId = htonl(pRsp->vgroupInfo[i].vgId); - pRsp->vgroupInfo[i].hashBegin = htonl(pRsp->vgroupInfo[i].hashBegin); - pRsp->vgroupInfo[i].hashEnd = htonl(pRsp->vgroupInfo[i].hashEnd); + pRsp->vgroupInfo[i].vgId = ntohl(pRsp->vgroupInfo[i].vgId); + pRsp->vgroupInfo[i].hashBegin = ntohl(pRsp->vgroupInfo[i].hashBegin); + pRsp->vgroupInfo[i].hashEnd = ntohl(pRsp->vgroupInfo[i].hashEnd); for (int32_t n = 0; n < pRsp->vgroupInfo[i].numOfEps; ++n) { - pRsp->vgroupInfo[i].epAddr[n].port = htons(pRsp->vgroupInfo[i].epAddr[n].port); + pRsp->vgroupInfo[i].epAddr[n].port = ntohs(pRsp->vgroupInfo[i].epAddr[n].port); } if (0 != taosHashPut(pOut->dbVgroup.vgInfo, &pRsp->vgroupInfo[i].vgId, sizeof(pRsp->vgroupInfo[i].vgId), &pRsp->vgroupInfo[i], sizeof(pRsp->vgroupInfo[i]))) { @@ -142,13 +143,13 @@ _return: } static int32_t queryConvertTableMetaMsg(STableMetaMsg* pMetaMsg) { - pMetaMsg->numOfTags = htonl(pMetaMsg->numOfTags); - pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns); - pMetaMsg->sversion = htonl(pMetaMsg->sversion); - pMetaMsg->tversion = htonl(pMetaMsg->tversion); + pMetaMsg->numOfTags = ntohl(pMetaMsg->numOfTags); + pMetaMsg->numOfColumns = ntohl(pMetaMsg->numOfColumns); + pMetaMsg->sversion = ntohl(pMetaMsg->sversion); + pMetaMsg->tversion = ntohl(pMetaMsg->tversion); pMetaMsg->tuid = htobe64(pMetaMsg->tuid); pMetaMsg->suid = htobe64(pMetaMsg->suid); - pMetaMsg->vgId = htonl(pMetaMsg->vgId); + pMetaMsg->vgId = ntohl(pMetaMsg->vgId); if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) { qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags); @@ -179,8 +180,8 @@ static int32_t queryConvertTableMetaMsg(STableMetaMsg* pMetaMsg) { int32_t numOfTotalCols = pMetaMsg->numOfColumns + pMetaMsg->numOfTags; for (int i = 0; i < numOfTotalCols; ++i) { - pSchema->bytes = htonl(pSchema->bytes); - pSchema->colId = htonl(pSchema->colId); + pSchema->bytes = ntohl(pSchema->bytes); + pSchema->colId = ntohl(pSchema->colId); pSchema++; } @@ -202,7 +203,8 @@ int32_t queryCreateTableMetaFromMsg(STableMetaMsg* msg, bool isSuperTable, STabl qError("calloc size[%d] failed", metaSize); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - + + pTableMeta->vgId = isSuperTable ? 0 : msg->vgId; pTableMeta->tableType = isSuperTable ? TSDB_SUPER_TABLE : msg->tableType; pTableMeta->uid = msg->suid; pTableMeta->suid = msg->suid; @@ -213,12 +215,12 @@ int32_t queryCreateTableMetaFromMsg(STableMetaMsg* msg, bool isSuperTable, STabl pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; + memcpy(pTableMeta->schema, msg->pSchema, sizeof(SSchema) * total); + for(int32_t i = 0; i < msg->numOfColumns; ++i) { pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; } - memcpy(pTableMeta->schema, msg->pSchema, sizeof(SSchema) * total); - *pMeta = pTableMeta; return TSDB_CODE_SUCCESS; @@ -264,11 +266,13 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { void initQueryModuleMsgHandle() { - queryBuildMsg[TSDB_MSG_TYPE_TABLE_META] = queryBuildTableMetaReqMsg; - queryBuildMsg[TSDB_MSG_TYPE_USE_DB] = queryBuildUseDbMsg; + queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_STB_META)] = queryBuildTableMetaReqMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; - queryProcessMsgRsp[TSDB_MSG_TYPE_TABLE_META] = queryProcessTableMetaRsp; - queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB] = queryProcessUseDBRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_STB_META)] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; } diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp index d2aedff8fdee781d1531e3aeea04e523f1a90beb..ddf89c62727c5a0d8f2a4fce9d66d48d7fca7d0b 100644 --- a/source/libs/qcom/test/queryTest.cpp +++ b/source/libs/qcom/test/queryTest.cpp @@ -15,7 +15,7 @@ #include #include -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #pragma GCC diagnostic ignored "-Wwrite-strings" diff --git a/source/libs/qworker/CMakeLists.txt b/source/libs/qworker/CMakeLists.txt index 4eafa50bdc200615391cfc2f364fc9c9c20430bd..001756d7c3f74656a8e5d0a41267a3b9d5071f0b 100644 --- a/source/libs/qworker/CMakeLists.txt +++ b/source/libs/qworker/CMakeLists.txt @@ -10,3 +10,5 @@ target_link_libraries( qworker PRIVATE os util transport planner qcom ) + +ADD_SUBDIRECTORY(test) \ No newline at end of file diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index 6f454e2f8199404778e076bfb7b183601cf51dee..91927c370a8cb432f27d434dcae57b1a54412428 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -42,25 +42,41 @@ enum { QW_WRITE, }; -typedef struct SQWorkerTaskStatus { +enum { + QW_EXIST_ACQUIRE = 1, + QW_EXIST_RET_ERR, +}; + +enum { + QW_NOT_EXIST_RET_ERR = 1, + QW_NOT_EXIST_ADD, +}; + +enum { + QW_ADD_RET_ERR = 1, + QW_ADD_ACQUIRE, +}; + + +typedef struct SQWTaskStatus { SRWLatch lock; int32_t code; int8_t status; int8_t ready; bool cancel; bool drop; -} SQWorkerTaskStatus; +} SQWTaskStatus; typedef struct SQWorkerResCache { SRWLatch lock; void *data; } SQWorkerResCache; -typedef struct SQWorkerSchStatus { +typedef struct SQWSchStatus { int32_t lastAccessTs; // timestamp in second SRWLatch tasksLock; SHashObj *tasksHash; // key:queryId+taskId, value: SQWorkerTaskStatus -} SQWorkerSchStatus; +} SQWSchStatus; // Qnode/Vnode level task management typedef struct SQWorkerMgmt { @@ -71,7 +87,7 @@ typedef struct SQWorkerMgmt { SHashObj *resHash; //key: queryId+taskId, value: SQWorkerResCache } SQWorkerMgmt; -#define QW_GOT_RES_DATA(data) (false) +#define QW_GOT_RES_DATA(data) (true) #define QW_LOW_RES_DATA(data) (false) #define QW_TASK_NOT_EXIST(code) (TSDB_CODE_QRY_SCH_NOT_EXIST == (code) || TSDB_CODE_QRY_TASK_NOT_EXIST == (code)) @@ -86,8 +102,31 @@ typedef struct SQWorkerMgmt { #define QW_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); terrno = _code; return _code; } } while (0) #define QW_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) -#define QW_LOCK(type, _lock) (QW_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) -#define QW_UNLOCK(type, _lock) (QW_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) +#define QW_LOCK(type, _lock) do { \ + if (QW_READ == (type)) { \ + if ((*(_lock)) < 0) assert(0); \ + taosRLockLatch(_lock); \ + qDebug("QW RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } else { \ + if ((*(_lock)) < 0) assert(0); \ + taosWLockLatch(_lock); \ + qDebug("QW WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } \ +} while (0) + +#define QW_UNLOCK(type, _lock) do { \ + if (QW_READ == (type)) { \ + if ((*(_lock)) <= 0) assert(0); \ + taosRUnLockLatch(_lock); \ + qDebug("QW RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } else { \ + if ((*(_lock)) <= 0) assert(0); \ + taosWUnLockLatch(_lock); \ + qDebug("QW WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + } \ +} while (0) + +static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId, SQWSchStatus **sch, int32_t nOpt); #ifdef __cplusplus diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 628077a0208f8ce3c8d7e6df74254f6b1c130e90..d5ecd40ccd140a5c140604bfd6ba69cf17e21342 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1,41 +1,46 @@ -#include "taosmsg.h" -#include "query.h" #include "qworker.h" -#include "qworkerInt.h" +#include "tname.h" #include "planner.h" +#include "query.h" +#include "qworkerInt.h" +#include "tmsg.h" -int32_t qwCheckStatusSwitch(int8_t oriStatus, int8_t newStatus) { +int32_t qwValidateStatus(int8_t oriStatus, int8_t newStatus) { int32_t code = 0; if (oriStatus == newStatus) { - if (newStatus == JOB_TASK_STATUS_CANCELLING) { - return TSDB_CODE_SUCCESS; - } - QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } switch (oriStatus) { case JOB_TASK_STATUS_NULL: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_FAILED ) { + if (newStatus != JOB_TASK_STATUS_EXECUTING + && newStatus != JOB_TASK_STATUS_FAILED + && newStatus != JOB_TASK_STATUS_NOT_START) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; case JOB_TASK_STATUS_NOT_START: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_FAILED) { + if (newStatus != JOB_TASK_STATUS_CANCELLED) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; case JOB_TASK_STATUS_EXECUTING: - if (newStatus != JOB_TASK_STATUS_SUCCEED && newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_CANCELLING) { + if (newStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED + && newStatus != JOB_TASK_STATUS_FAILED + && newStatus != JOB_TASK_STATUS_CANCELLING + && newStatus != JOB_TASK_STATUS_CANCELLED + && newStatus != JOB_TASK_STATUS_DROPPING) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; case JOB_TASK_STATUS_PARTIAL_SUCCEED: - if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_CANCELLING) { + if (newStatus != JOB_TASK_STATUS_EXECUTING + && newStatus != JOB_TASK_STATUS_SUCCEED + && newStatus != JOB_TASK_STATUS_CANCELLED) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } @@ -49,6 +54,10 @@ int32_t qwCheckStatusSwitch(int8_t oriStatus, int8_t newStatus) { break; case JOB_TASK_STATUS_CANCELLED: + case JOB_TASK_STATUS_DROPPING: + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + break; + default: qError("invalid task status:%d", oriStatus); return TSDB_CODE_QRY_APP_ERROR; @@ -58,17 +67,17 @@ int32_t qwCheckStatusSwitch(int8_t oriStatus, int8_t newStatus) { _return: - qError("invalid task status:%d", oriStatus); + qError("invalid task status, from %d to %d", oriStatus, newStatus); QW_ERR_RET(code); } -int32_t qwUpdateTaskInfo(SQWorkerTaskStatus *task, int8_t type, void *data) { +int32_t qwUpdateTaskInfo(SQWTaskStatus *task, int8_t type, void *data) { int32_t code = 0; switch (type) { case QW_TASK_INFO_STATUS: { int8_t newStatus = *(int8_t *)data; - QW_ERR_RET(qwCheckStatusSwitch(task->status, newStatus)); + QW_ERR_RET(qwValidateStatus(task->status, newStatus)); task->status = newStatus; break; } @@ -80,9 +89,9 @@ int32_t qwUpdateTaskInfo(SQWorkerTaskStatus *task, int8_t type, void *data) { return TSDB_CODE_SUCCESS; } -int32_t qwAddTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, void *data) { - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); +int32_t qwAddTaskResCache(SQWorkerMgmt *mgmt, uint64_t qId, uint64_t tId, void *data) { + char id[sizeof(qId) + sizeof(tId)] = {0}; + QW_SET_QTID(id, qId, tId); SQWorkerResCache resCache = {0}; resCache.data = data; @@ -90,7 +99,7 @@ int32_t qwAddTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, v QW_LOCK(QW_WRITE, &mgmt->resLock); if (0 != taosHashPut(mgmt->resHash, id, sizeof(id), &resCache, sizeof(SQWorkerResCache))) { QW_UNLOCK(QW_WRITE, &mgmt->resLock); - qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to resHash failed", queryId, taskId); + qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to resHash failed", qId, tId); return TSDB_CODE_QRY_APP_ERROR; } @@ -99,37 +108,8 @@ int32_t qwAddTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, v return TSDB_CODE_SUCCESS; } - -int32_t qwGetTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, void **data) { - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); - - SQWorkerResCache *resCache = taosHashGet(mgmt->resHash, id, sizeof(id)); - if (NULL == resCache) { - qError("no task res for queryId[%"PRIx64"] taskId[%"PRIx64"]", queryId, taskId); - return TSDB_CODE_QRY_APP_ERROR; - } - - *data = resCache->data; - - return TSDB_CODE_SUCCESS; -} - - -static FORCE_INLINE int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t schedulerId, SQWorkerSchStatus **sch) { - QW_LOCK(rwType, &mgmt->schLock); - *sch = taosHashGet(mgmt->schHash, &schedulerId, sizeof(schedulerId)); - if (NULL == (*sch)) { - QW_LOCK(rwType, &mgmt->schLock); - return TSDB_CODE_QRY_SCH_NOT_EXIST; - } - - return TSDB_CODE_SUCCESS; -} - - -static FORCE_INLINE int32_t qwInsertAndAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t schedulerId, SQWorkerSchStatus **sch) { - SQWorkerSchStatus newSch = {0}; +static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId, SQWSchStatus **sch) { + SQWSchStatus newSch = {0}; newSch.tasksHash = taosHashInit(mgmt->cfg.maxSchTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == newSch.tasksHash) { qError("taosHashInit %d failed", mgmt->cfg.maxSchTaskNum); @@ -138,19 +118,18 @@ static FORCE_INLINE int32_t qwInsertAndAcquireScheduler(int32_t rwType, SQWorker while (true) { QW_LOCK(QW_WRITE, &mgmt->schLock); - int32_t code = taosHashPut(mgmt->schHash, &schedulerId, sizeof(schedulerId), &newSch, sizeof(newSch)); + int32_t code = taosHashPut(mgmt->schHash, &sId, sizeof(sId), &newSch, sizeof(newSch)); if (0 != code) { if (!HASH_NODE_EXIST(code)) { QW_UNLOCK(QW_WRITE, &mgmt->schLock); - qError("taosHashPut schedulerId[%"PRIx64"] to scheduleHash failed", schedulerId); + qError("taosHashPut sId[%"PRIx64"] to scheduleHash failed", sId); taosHashCleanup(newSch.tasksHash); return TSDB_CODE_QRY_APP_ERROR; } } QW_UNLOCK(QW_WRITE, &mgmt->schLock); - if (TSDB_CODE_SUCCESS == qwAcquireScheduler(rwType, mgmt, schedulerId, sch)) { - taosHashCleanup(newSch.tasksHash); + if (TSDB_CODE_SUCCESS == qwAcquireScheduler(rwType, mgmt, sId, sch, QW_NOT_EXIST_ADD)) { return TSDB_CODE_SUCCESS; } } @@ -159,63 +138,122 @@ static FORCE_INLINE int32_t qwInsertAndAcquireScheduler(int32_t rwType, SQWorker } +static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId, SQWSchStatus **sch, int32_t nOpt) { + QW_LOCK(rwType, &mgmt->schLock); + *sch = taosHashGet(mgmt->schHash, &sId, sizeof(sId)); + if (NULL == (*sch)) { + QW_UNLOCK(rwType, &mgmt->schLock); + + if (QW_NOT_EXIST_ADD == nOpt) { + return qwAddScheduler(rwType, mgmt, sId, sch); + } else if (QW_NOT_EXIST_RET_ERR == nOpt) { + return TSDB_CODE_QRY_SCH_NOT_EXIST; + } else { + assert(0); + } + } + + return TSDB_CODE_SUCCESS; +} + + + static FORCE_INLINE void qwReleaseScheduler(int32_t rwType, SQWorkerMgmt *mgmt) { QW_UNLOCK(rwType, &mgmt->schLock); } -static FORCE_INLINE int32_t qwAcquireTask(int32_t rwType, SQWorkerSchStatus *sch, uint64_t queryId, uint64_t taskId, SQWorkerTaskStatus **task) { - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); +static int32_t qwAcquireTaskImpl(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t tId, SQWTaskStatus **task) { + char id[sizeof(qId) + sizeof(tId)] = {0}; + QW_SET_QTID(id, qId, tId); QW_LOCK(rwType, &sch->tasksLock); *task = taosHashGet(sch->tasksHash, id, sizeof(id)); if (NULL == (*task)) { QW_UNLOCK(rwType, &sch->tasksLock); + return TSDB_CODE_QRY_TASK_NOT_EXIST; } return TSDB_CODE_SUCCESS; } -static FORCE_INLINE int32_t qwInsertAndAcquireTask(int32_t rwType, SQWorkerSchStatus *sch, uint64_t queryId, uint64_t taskId, int8_t status, bool *inserted, SQWorkerTaskStatus **task) { - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); +static int32_t qwAcquireTask(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t tId, SQWTaskStatus **task) { + return qwAcquireTaskImpl(rwType, sch, qId, tId, task); +} + + +static FORCE_INLINE void qwReleaseTask(int32_t rwType, SQWSchStatus *sch) { + QW_UNLOCK(rwType, &sch->tasksLock); +} + + +int32_t qwAddTaskToSch(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t tId, int8_t status, int32_t eOpt, SQWTaskStatus **task) { + int32_t code = 0; + + char id[sizeof(qId) + sizeof(tId)] = {0}; + QW_SET_QTID(id, qId, tId); + + SQWTaskStatus ntask = {0}; + ntask.status = status; while (true) { - *inserted = false; - QW_LOCK(QW_WRITE, &sch->tasksLock); - int32_t code = taosHashPut(sch->tasksHash, id, sizeof(id), &status, sizeof(status)); + int32_t code = taosHashPut(sch->tasksHash, id, sizeof(id), &ntask, sizeof(ntask)); if (0 != code) { QW_UNLOCK(QW_WRITE, &sch->tasksLock); if (HASH_NODE_EXIST(code)) { - if (qwAcquireTask(rwType, sch, queryId, taskId, task)) { - continue; + if (QW_EXIST_ACQUIRE == eOpt && rwType && task) { + if (qwAcquireTask(rwType, sch, qId, tId, task)) { + continue; + } + } else if (QW_EXIST_RET_ERR == eOpt) { + return TSDB_CODE_QRY_TASK_ALREADY_EXIST; + } else { + assert(0); } break; } else { - qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to scheduleHash failed", queryId, taskId); + qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to scheduleHash failed", qId, tId); return TSDB_CODE_QRY_APP_ERROR; } } + QW_UNLOCK(QW_WRITE, &sch->tasksLock); - *inserted = true; - - if (TSDB_CODE_SUCCESS == qwAcquireTask(rwType, sch, queryId, taskId, task)) { - return TSDB_CODE_SUCCESS; + if (rwType && task) { + if (TSDB_CODE_SUCCESS == qwAcquireTask(rwType, sch, qId, tId, task)) { + return TSDB_CODE_SUCCESS; + } + } else { + break; } - } + } return TSDB_CODE_SUCCESS; } -static FORCE_INLINE void qwReleaseTask(int32_t rwType, SQWorkerSchStatus *sch) { - QW_UNLOCK(rwType, &sch->tasksLock); +static int32_t qwAddTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int32_t status, int32_t eOpt, SQWSchStatus **sch, SQWTaskStatus **task) { + SQWSchStatus *tsch = NULL; + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &tsch, QW_NOT_EXIST_ADD)); + + int32_t code = qwAddTaskToSch(QW_READ, tsch, qId, tId, status, eOpt, task); + if (code) { + qwReleaseScheduler(QW_WRITE, mgmt); + } + + if (NULL == task) { + qwReleaseScheduler(QW_READ, mgmt); + } else if (sch) { + *sch = tsch; + } + + QW_RET(code); } + + static FORCE_INLINE int32_t qwAcquireTaskResCache(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, SQWorkerResCache **res) { char id[sizeof(queryId) + sizeof(taskId)] = {0}; QW_SET_QTID(id, queryId, taskId); @@ -235,27 +273,24 @@ static FORCE_INLINE void qwReleaseTaskResCache(int32_t rwType, SQWorkerMgmt *mgm } -int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, SSchedulerStatusRsp **rsp) { - SQWorkerSchStatus *schStatus = NULL; +int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp) { + SQWSchStatus *sch = NULL; int32_t taskNum = 0; - if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &schStatus)) { - qWarn("no scheduler for schedulerId[%"PRIx64"]", schedulerId); - } else { - schStatus->lastAccessTs = taosGetTimestampSec(); + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); + + sch->lastAccessTs = taosGetTimestampSec(); - QW_LOCK(QW_READ, &schStatus->tasksLock); - taskNum = taosHashGetSize(schStatus->tasksHash); - } + QW_LOCK(QW_READ, &sch->tasksLock); + + taskNum = taosHashGetSize(sch->tasksHash); int32_t size = sizeof(SSchedulerStatusRsp) + sizeof((*rsp)->status[0]) * taskNum; *rsp = calloc(1, size); if (NULL == *rsp) { qError("calloc %d failed", size); - if (schStatus) { - QW_UNLOCK(QW_READ, &schStatus->tasksLock); - qwReleaseScheduler(QW_READ, mgmt); - } + QW_UNLOCK(QW_READ, &sch->tasksLock); + qwReleaseScheduler(QW_READ, mgmt); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -264,23 +299,19 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, SScheduler size_t keyLen = 0; int32_t i = 0; - if (schStatus) { - void *pIter = taosHashIterate(schStatus->tasksHash, NULL); - while (pIter) { - SQWorkerTaskStatus *taskStatus = (SQWorkerTaskStatus *)pIter; - taosHashGetKey(pIter, &key, &keyLen); + void *pIter = taosHashIterate(sch->tasksHash, NULL); + while (pIter) { + SQWTaskStatus *taskStatus = (SQWTaskStatus *)pIter; + taosHashGetKey(pIter, &key, &keyLen); - QW_GET_QTID(key, (*rsp)->status[i].queryId, (*rsp)->status[i].taskId); - (*rsp)->status[i].status = taskStatus->status; - - pIter = taosHashIterate(schStatus->tasksHash, pIter); - } - } + QW_GET_QTID(key, (*rsp)->status[i].queryId, (*rsp)->status[i].taskId); + (*rsp)->status[i].status = taskStatus->status; + + pIter = taosHashIterate(sch->tasksHash, pIter); + } - if (schStatus) { - QW_UNLOCK(QW_READ, &schStatus->tasksLock); - qwReleaseScheduler(QW_READ, mgmt); - } + QW_UNLOCK(QW_READ, &sch->tasksLock); + qwReleaseScheduler(QW_READ, mgmt); (*rsp)->num = taskNum; @@ -289,115 +320,81 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, SScheduler -int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t schedulerId) { - SQWorkerSchStatus *schStatus = NULL; +int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t sId) { + SQWSchStatus *sch = NULL; - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &schStatus)); + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); - schStatus->lastAccessTs = taosGetTimestampSec(); + sch->lastAccessTs = taosGetTimestampSec(); qwReleaseScheduler(QW_READ, mgmt); return TSDB_CODE_SUCCESS; } - -int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t *taskStatus) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwUpdateTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int8_t status) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); - QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); - *taskStatus = task->status; + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, qId, tId, &task)); + QW_LOCK(QW_WRITE, &task->lock); + qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &status); + QW_UNLOCK(QW_WRITE, &task->lock); + _return: - if (task) { - qwReleaseTask(QW_READ, sch); - } - if (sch) { - qwReleaseScheduler(QW_READ, mgmt); - } + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); QW_RET(code); } -int32_t qwSwitchTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t taskStatus) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId, int8_t *taskStatus) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - bool inserted = false; - if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { - if (qwCheckStatusSwitch(JOB_TASK_STATUS_NULL, taskStatus)) { - qError("switch status error, not start to %d", taskStatus); - QW_ERR_RET(TSDB_CODE_QRY_APP_ERROR); - } - - QW_ERR_RET(qwInsertAndAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + if (qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)) { + *taskStatus = JOB_TASK_STATUS_NULL; + return TSDB_CODE_SUCCESS; } if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { - if (qwCheckStatusSwitch(JOB_TASK_STATUS_NOT_START, taskStatus)) { - qwReleaseScheduler(QW_READ, mgmt); - qError("switch status error, not start to %d", taskStatus); - QW_ERR_RET(TSDB_CODE_QRY_APP_ERROR); - } - - QW_ERR_JRET(qwInsertAndAcquireTask(QW_READ, sch, queryId, taskId, taskStatus, &inserted, &task)); - - if (inserted) { - qwReleaseTask(QW_READ, sch); - qwReleaseScheduler(QW_READ, mgmt); - return TSDB_CODE_SUCCESS; - } - - QW_LOCK(QW_WRITE, &task->lock); - code = qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &taskStatus); - QW_UNLOCK(QW_WRITE, &task->lock); - - qwReleaseTask(QW_READ, sch); - qwReleaseScheduler(QW_READ, mgmt); + qwReleaseScheduler(QW_READ, mgmt); - QW_RET(code); + *taskStatus = JOB_TASK_STATUS_NULL; + return TSDB_CODE_SUCCESS; } - QW_LOCK(QW_WRITE, &task->lock); - code = qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &taskStatus); - QW_UNLOCK(QW_WRITE, &task->lock); - -_return: + *taskStatus = task->status; qwReleaseTask(QW_READ, sch); - qwReleaseScheduler(QW_READ, mgmt); - + qwReleaseScheduler(QW_READ, mgmt); + QW_RET(code); } -int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { - QW_ERR_RET(qwSwitchTaskStatus(mgmt, schedulerId, queryId, taskId, JOB_TASK_STATUS_NOT_START)); - - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); - } + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_ADD)); if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { - code = qwSwitchTaskStatus(mgmt, schedulerId, queryId, taskId, JOB_TASK_STATUS_NOT_START); + qwReleaseScheduler(QW_READ, mgmt); + + code = qwAddTask(mgmt, sId, queryId, taskId, JOB_TASK_STATUS_NOT_START, QW_EXIST_ACQUIRE, &sch, &task); if (code) { qwReleaseScheduler(QW_READ, mgmt); QW_ERR_RET(code); } - - QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); } QW_LOCK(QW_WRITE, &task->lock); @@ -423,6 +420,7 @@ int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, } QW_UNLOCK(QW_WRITE, &task->lock); + qwReleaseTask(QW_READ, sch); qwReleaseScheduler(QW_READ, mgmt); @@ -449,9 +447,9 @@ _return: -int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; char id[sizeof(queryId) + sizeof(taskId)] = {0}; QW_SET_QTID(id, queryId, taskId); @@ -462,15 +460,15 @@ int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, u } QW_UNLOCK(QW_WRITE, &mgmt->resLock); - if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_WRITE, mgmt, schedulerId, &sch)) { - qWarn("scheduler %"PRIx64" doesn't exist", schedulerId); + if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_WRITE, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)) { + qWarn("scheduler %"PRIx64" doesn't exist", sId); return TSDB_CODE_SUCCESS; } if (qwAcquireTask(QW_WRITE, sch, queryId, taskId, &task)) { qwReleaseScheduler(QW_WRITE, mgmt); - qWarn("scheduler %"PRIx64" queryId %"PRIx64" taskId:%"PRIx64" doesn't exist", schedulerId, queryId, taskId); + qWarn("scheduler %"PRIx64" queryId %"PRIx64" taskId:%"PRIx64" doesn't exist", sId, queryId, taskId); return TSDB_CODE_SUCCESS; } @@ -483,21 +481,21 @@ int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, u } -int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { - qWarn("scheduler %"PRIx64" doesn't exist", schedulerId); - return TSDB_CODE_SUCCESS; - } + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_ADD)); if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { qwReleaseScheduler(QW_READ, mgmt); - qWarn("scheduler %"PRIx64" queryId %"PRIx64" taskId:%"PRIx64" doesn't exist", schedulerId, queryId, taskId); - return TSDB_CODE_SUCCESS; + code = qwAddTask(mgmt, sId, queryId, taskId, JOB_TASK_STATUS_NOT_START, QW_EXIST_ACQUIRE, &sch, &task); + if (code) { + qwReleaseScheduler(QW_READ, mgmt); + QW_ERR_RET(code); + } } QW_LOCK(QW_WRITE, &task->lock); @@ -508,7 +506,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t quer int8_t newStatus = 0; if (task->status == JOB_TASK_STATUS_EXECUTING) { - newStatus = JOB_TASK_STATUS_CANCELLING; + newStatus = JOB_TASK_STATUS_DROPPING; QW_ERR_JRET(qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus)); } else if (task->status == JOB_TASK_STATUS_CANCELLING || task->status == JOB_TASK_STATUS_DROPPING || task->status == JOB_TASK_STATUS_NOT_START) { QW_UNLOCK(QW_WRITE, &task->lock); @@ -521,7 +519,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t quer qwReleaseTask(QW_READ, sch); qwReleaseScheduler(QW_READ, mgmt); - QW_ERR_RET(qwDropTask(mgmt, schedulerId, queryId, taskId)); + QW_ERR_RET(qwDropTask(mgmt, sId, queryId, taskId)); return TSDB_CODE_SUCCESS; } @@ -553,38 +551,189 @@ _return: int32_t qwBuildAndSendQueryRsp(SRpcMsg *pMsg, int32_t code) { + SQueryTableRsp *pRsp = (SQueryTableRsp *)rpcMallocCont(sizeof(SQueryTableRsp)); + pRsp->code = code; + + SRpcMsg rpcRsp = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = code, + }; + rpcSendResponse(&rpcRsp); + + return TSDB_CODE_SUCCESS; } int32_t qwBuildAndSendReadyRsp(SRpcMsg *pMsg, int32_t code) { + SResReadyRsp *pRsp = (SResReadyRsp *)rpcMallocCont(sizeof(SResReadyRsp)); + pRsp->code = code; + + SRpcMsg rpcRsp = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = code, + }; + rpcSendResponse(&rpcRsp); + + return TSDB_CODE_SUCCESS; } int32_t qwBuildAndSendStatusRsp(SRpcMsg *pMsg, SSchedulerStatusRsp *sStatus) { + int32_t size = 0; + + if (sStatus) { + size = sizeof(SSchedulerStatusRsp) + sizeof(sStatus->status[0]) * sStatus->num; + } else { + size = sizeof(SSchedulerStatusRsp); + } + + SSchedulerStatusRsp *pRsp = (SSchedulerStatusRsp *)rpcMallocCont(size); + if (sStatus) { + memcpy(pRsp, sStatus, size); + } else { + pRsp->num = 0; + } + + SRpcMsg rpcRsp = { + .msgType = pMsg->msgType + 1, + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = size, + .code = 0, + }; + + rpcSendResponse(&rpcRsp); + + return TSDB_CODE_SUCCESS; } int32_t qwBuildAndSendFetchRsp(SRpcMsg *pMsg, void *data) { + SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); + memset(pRsp, 0, sizeof(SRetrieveTableRsp)); + + //TODO fill msg + pRsp->completed = true; + + SRpcMsg rpcRsp = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = 0, + }; + + rpcSendResponse(&rpcRsp); + return TSDB_CODE_SUCCESS; +} + +int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code) { + STaskCancelRsp *pRsp = (STaskCancelRsp *)rpcMallocCont(sizeof(STaskCancelRsp)); + pRsp->code = code; + + SRpcMsg rpcRsp = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = code, + }; + + rpcSendResponse(&rpcRsp); + + return TSDB_CODE_SUCCESS; } +int32_t qwBuildAndSendDropRsp(SRpcMsg *pMsg, int32_t code) { + STaskDropRsp *pRsp = (STaskDropRsp *)rpcMallocCont(sizeof(STaskDropRsp)); + pRsp->code = code; -int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg) { + SRpcMsg rpcRsp = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = code, + }; + rpcSendResponse(&rpcRsp); + return TSDB_CODE_SUCCESS; } -int32_t qwBuildAndSendDropRsp(SRpcMsg *pMsg) { +int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) { + int32_t numOfCols = 6; + SVShowTablesRsp *pRsp = (SVShowTablesRsp *)rpcMallocCont(sizeof(SVShowTablesRsp) + sizeof(SSchema) * numOfCols); + int32_t cols = 0; + SSchema *pSchema = pRsp->metaInfo.pSchema; + + const SSchema *s = tGetTbnameColumnSchema(); + *pSchema = createSchema(s->type, htonl(s->bytes), htonl(cols++), "name"); + pSchema++; + + int32_t type = TSDB_DATA_TYPE_TIMESTAMP; + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "created"); + pSchema++; + + type = TSDB_DATA_TYPE_SMALLINT; + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "columns"); + pSchema++; + + *pSchema = createSchema(s->type, htonl(s->bytes), htonl(cols++), "stable"); + pSchema++; + + type = TSDB_DATA_TYPE_BIGINT; + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "uid"); + pSchema++; + + type = TSDB_DATA_TYPE_INT; + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "vgId"); + + pRsp->metaInfo.numOfColumns = htonl(cols); + + SRpcMsg rpcMsg = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = code, + }; + + rpcSendResponse(&rpcMsg); + return TSDB_CODE_SUCCESS; } +int32_t qwBuildAndSendShowFetchRsp(SRpcMsg *pMsg, SVShowTablesFetchReq* pFetchReq) { + SVShowTablesFetchRsp *pRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp)); + int32_t handle = htonl(pFetchReq->id); + pRsp->numOfRows = 0; + SRpcMsg rpcMsg = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pRsp, + .contLen = sizeof(*pRsp), + .code = 0, + }; -int32_t qwCheckAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg, int32_t rspCode) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; + rpcSendResponse(&rpcMsg); + return TSDB_CODE_SUCCESS; +} + +int32_t qwCheckAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg, int32_t rspCode) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); @@ -612,10 +761,8 @@ _return: if (task) { QW_UNLOCK(QW_WRITE, &task->lock); - } - - if (sch) { qwReleaseTask(QW_READ, sch); + } qwReleaseScheduler(QW_READ, mgmt); @@ -623,12 +770,12 @@ _return: QW_RET(code); } -int32_t qwSetAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwSetAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); @@ -651,9 +798,6 @@ _return: if (task) { QW_UNLOCK(QW_WRITE, &task->lock); - } - - if (sch) { qwReleaseTask(QW_READ, sch); } @@ -662,15 +806,15 @@ _return: QW_RET(code); } -int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, bool *needStop) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId, bool *needStop) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; int8_t status = JOB_TASK_STATUS_CANCELLED; *needStop = false; - if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { + if (qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)) { return TSDB_CODE_SUCCESS; } @@ -682,11 +826,13 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_ QW_LOCK(QW_READ, &task->lock); if ((!task->cancel) && (!task->drop)) { + qError("no cancel or drop, but task:%"PRIx64" exists", taskId); + QW_UNLOCK(QW_READ, &task->lock); qwReleaseTask(QW_READ, sch); qwReleaseScheduler(QW_READ, mgmt); - return TSDB_CODE_SUCCESS; + QW_RET(TSDB_CODE_QRY_APP_ERROR); } QW_UNLOCK(QW_READ, &task->lock); @@ -697,34 +843,45 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_ QW_LOCK(QW_WRITE, &task->lock); qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &status); QW_UNLOCK(QW_WRITE, &task->lock); - } else if (task->drop) { + } + + if (task->drop) { qwReleaseTask(QW_READ, sch); qwReleaseScheduler(QW_READ, mgmt); - qwDropTask(mgmt, schedulerId, queryId, taskId); + return qwDropTask(mgmt, sId, queryId, taskId); } + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + return TSDB_CODE_SUCCESS; } - -int32_t qwHandleFetch(SQWorkerResCache *res, SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwHandleFetch(SQWorkerResCache *res, SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; + int32_t needRsp = true; + void *data = NULL; - QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + QW_ERR_JRET(qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_RET_ERR)); QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); QW_LOCK(QW_READ, &task->lock); - if (task->status != JOB_TASK_STATUS_EXECUTING && task->status != JOB_TASK_STATUS_PARTIAL_SUCCEED && task->status != JOB_TASK_STATUS_SUCCEED) { + if (task->cancel || task->drop) { + qError("task is already cancelled or dropped"); + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + if (task->status != JOB_TASK_STATUS_EXECUTING && task->status != JOB_TASK_STATUS_PARTIAL_SUCCEED) { qError("invalid status %d for fetch", task->status); QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } if (QW_GOT_RES_DATA(res->data)) { - QW_ERR_JRET(qwBuildAndSendFetchRsp(pMsg, res->data)); + data = res->data; if (QW_LOW_RES_DATA(res->data)) { if (task->status == JOB_TASK_STATUS_PARTIAL_SUCCEED) { //TODO add query back to queue @@ -737,53 +894,67 @@ int32_t qwHandleFetch(SQWorkerResCache *res, SQWorkerMgmt *mgmt, uint64_t schedu } //TODO SET FLAG FOR QUERY TO SEND RSP WHEN RES READY + + needRsp = false; } _return: if (task) { QW_UNLOCK(QW_READ, &task->lock); + qwReleaseTask(QW_READ, sch); } if (sch) { - qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); } - qwReleaseScheduler(QW_READ, mgmt); + if (needRsp) { + qwBuildAndSendFetchRsp(pMsg, res->data); + } QW_RET(code); } -int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t status, int32_t errCode) { - SQWorkerSchStatus *sch = NULL; - SQWorkerTaskStatus *task = NULL; +int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int8_t status, int32_t errCode) { + SQWSchStatus *sch = NULL; + SQWTaskStatus *task = NULL; int32_t code = 0; int8_t newStatus = JOB_TASK_STATUS_CANCELLED; - code = qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch); + code = qwAcquireScheduler(QW_READ, mgmt, sId, &sch, QW_NOT_EXIST_ADD); if (code) { - qError("schedulerId:%"PRIx64" not in cache", schedulerId); + qError("sId:%"PRIx64" not in cache", sId); QW_ERR_RET(code); } - code = qwAcquireTask(QW_READ, sch, queryId, taskId, &task); + code = qwAcquireTask(QW_READ, sch, qId, tId, &task); if (code) { qwReleaseScheduler(QW_READ, mgmt); - qError("schedulerId:%"PRIx64" queryId:%"PRIx64" taskId:%"PRIx64" not in cache", schedulerId, queryId, taskId); - QW_ERR_RET(code); + + if (JOB_TASK_STATUS_PARTIAL_SUCCEED == status || JOB_TASK_STATUS_SUCCEED == status) { + qError("sId:%"PRIx64" queryId:%"PRIx64" taskId:%"PRIx64" not in cache", sId, qId, tId); + QW_ERR_RET(code); + } + + QW_ERR_RET(qwAddTask(mgmt, sId, qId, tId, status, QW_EXIST_ACQUIRE, &sch, &task)); } if (task->cancel) { QW_LOCK(QW_WRITE, &task->lock); qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus); QW_UNLOCK(QW_WRITE, &task->lock); - } else if (task->drop) { + } + + if (task->drop) { qwReleaseTask(QW_READ, sch); qwReleaseScheduler(QW_READ, mgmt); - qwDropTask(mgmt, schedulerId, queryId, taskId); + qwDropTask(mgmt, sId, qId, tId); return TSDB_CODE_SUCCESS; - } else { + } + + if (!(task->cancel || task->drop)) { QW_LOCK(QW_WRITE, &task->lock); qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &status); task->code = errCode; @@ -796,7 +967,6 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t qu return TSDB_CODE_SUCCESS; } - int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) { SQWorkerMgmt *mgmt = calloc(1, sizeof(SQWorkerMgmt)); if (NULL == mgmt) { @@ -832,31 +1002,37 @@ int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) { return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg **rsp) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } + int32_t code = 0; SSubQueryMsg *msg = pMsg->pCont; if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { - QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + qError("invalid query msg"); + QW_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } + + msg->sId = htobe64(msg->sId); + msg->queryId = htobe64(msg->queryId); + msg->taskId = htobe64(msg->taskId); + msg->contentLen = ntohl(msg->contentLen); bool queryDone = false; - bool queryRsp = false; + bool queryRsped = false; bool needStop = false; SSubplan *plan = NULL; - int32_t code = 0; - QW_ERR_JRET(qwCheckTaskCancelDrop(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, &needStop)); + QW_ERR_JRET(qwCheckTaskCancelDrop(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, &needStop)); if (needStop) { qWarn("task need stop"); - QW_ERR_RET(TSDB_CODE_QRY_TASK_CANCELLED); + QW_ERR_JRET(TSDB_CODE_QRY_TASK_CANCELLED); } code = qStringToSubplan(msg->msg, &plan); if (TSDB_CODE_SUCCESS != code) { - qError("schId:%"PRIx64",qId:%"PRIx64",taskId:%"PRIx64" string to subplan failed, code:%d", msg->schedulerId, msg->queryId, msg->taskId, code); + qError("schId:%"PRIx64",qId:%"PRIx64",taskId:%"PRIx64" string to subplan failed, code:%d", msg->sId, msg->queryId, msg->taskId, code); QW_ERR_JRET(code); } @@ -867,12 +1043,12 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRp if (code) { QW_ERR_JRET(code); } else { - QW_ERR_JRET(qwSwitchTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, JOB_TASK_STATUS_EXECUTING)); + QW_ERR_JRET(qwAddTask(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, JOB_TASK_STATUS_EXECUTING, QW_EXIST_RET_ERR, NULL, NULL)); } QW_ERR_JRET(qwBuildAndSendQueryRsp(pMsg, TSDB_CODE_SUCCESS)); - queryRsp = true; + queryRsped = true; //TODO call executer to execute subquery code = 0; @@ -883,78 +1059,93 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRp if (code) { QW_ERR_JRET(code); } else { - QW_ERR_JRET(qwAddTaskResult(qWorkerMgmt, msg->queryId, msg->taskId, data)); + QW_ERR_JRET(qwAddTaskResCache(qWorkerMgmt, msg->queryId, msg->taskId, data)); - QW_ERR_JRET(qwSwitchTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, JOB_TASK_STATUS_PARTIAL_SUCCEED)); - } + QW_ERR_JRET(qwUpdateTaskStatus(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, JOB_TASK_STATUS_PARTIAL_SUCCEED)); + } _return: - if (queryRsp) { - code = qwCheckAndSendReadyRsp(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg, code); + if (queryRsped) { + code = qwCheckAndSendReadyRsp(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, pMsg, code); } else { code = qwBuildAndSendQueryRsp(pMsg, code); } int8_t status = 0; - if (TSDB_CODE_SUCCESS != code || queryDone) { - if (code) { - status = JOB_TASK_STATUS_FAILED; //TODO set CANCELLED from code - } else { - status = JOB_TASK_STATUS_SUCCEED; - } - - qwQueryPostProcess(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, status, code); + if (TSDB_CODE_SUCCESS != code) { + status = JOB_TASK_STATUS_FAILED; + } else if (queryDone) { + status = JOB_TASK_STATUS_SUCCEED; + } else { + status = JOB_TASK_STATUS_PARTIAL_SUCCEED; } + + qwQueryPostProcess(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, status, code); QW_RET(code); } -int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp){ - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg){ + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } SResReadyMsg *msg = pMsg->pCont; - if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + if (NULL == msg || pMsg->contLen < sizeof(*msg)) { + qError("invalid task status msg"); QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - QW_ERR_RET(qwSetAndSendReadyRsp(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg)); + msg->sId = htobe64(msg->sId); + msg->queryId = htobe64(msg->queryId); + msg->taskId = htobe64(msg->taskId); + + QW_ERR_RET(qwSetAndSendReadyRsp(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, pMsg)); return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } + int32_t code = 0; SSchTasksStatusMsg *msg = pMsg->pCont; - if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + if (NULL == msg || pMsg->contLen < sizeof(*msg)) { + qError("invalid task status msg"); QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } + msg->sId = htobe64(msg->sId); + SSchedulerStatusRsp *sStatus = NULL; - QW_ERR_RET(qwGetSchTasksStatus(qWorkerMgmt, msg->schedulerId, &sStatus)); + QW_ERR_JRET(qwGetSchTasksStatus(qWorkerMgmt, msg->sId, &sStatus)); + +_return: QW_ERR_RET(qwBuildAndSendStatusRsp(pMsg, sStatus)); return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } SResFetchMsg *msg = pMsg->pCont; - if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + if (NULL == msg || pMsg->contLen < sizeof(*msg)) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - QW_ERR_RET(qwUpdateSchLastAccess(qWorkerMgmt, msg->schedulerId)); + msg->sId = htobe64(msg->sId); + msg->queryId = htobe64(msg->queryId); + msg->taskId = htobe64(msg->taskId); + + QW_ERR_RET(qwUpdateSchLastAccess(qWorkerMgmt, msg->sId)); void *data = NULL; SQWorkerResCache *res = NULL; @@ -962,7 +1153,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRp QW_ERR_RET(qwAcquireTaskResCache(QW_READ, qWorkerMgmt, msg->queryId, msg->taskId, &res)); - QW_ERR_JRET(qwHandleFetch(res, qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg)); + QW_ERR_JRET(qwHandleFetch(res, qWorkerMgmt, msg->sId, msg->queryId, msg->taskId, pMsg)); _return: @@ -971,40 +1162,99 @@ _return: QW_RET(code); } -int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } + int32_t code = 0; STaskCancelMsg *msg = pMsg->pCont; - if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + if (NULL == msg || pMsg->contLen < sizeof(*msg)) { + qError("invalid task cancel msg"); QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - QW_ERR_RET(qwCancelTask(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId)); + msg->sId = htobe64(msg->sId); + msg->queryId = htobe64(msg->queryId); + msg->taskId = htobe64(msg->taskId); + + QW_ERR_JRET(qwCancelTask(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId)); - QW_ERR_RET(qwBuildAndSendCancelRsp(pMsg)); +_return: + + QW_ERR_RET(qwBuildAndSendCancelRsp(pMsg, code)); return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { - if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { +int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } + int32_t code = 0; STaskDropMsg *msg = pMsg->pCont; - if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + if (NULL == msg || pMsg->contLen < sizeof(*msg)) { + qError("invalid task drop msg"); QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - QW_ERR_RET(qwCancelDropTask(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId)); + msg->sId = htobe64(msg->sId); + msg->queryId = htobe64(msg->queryId); + msg->taskId = htobe64(msg->taskId); + + QW_ERR_JRET(qwCancelDropTask(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId)); + +_return: - QW_ERR_RET(qwBuildAndSendDropRsp(pMsg)); + QW_ERR_RET(qwBuildAndSendDropRsp(pMsg, code)); return TSDB_CODE_SUCCESS; } +int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { + return TSDB_CODE_QRY_INVALID_INPUT; + } + + int32_t code = 0; + SVShowTablesReq *pReq = pMsg->pCont; + QW_ERR_RET(qwBuildAndSendShowRsp(pMsg, code)); +} + +int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { + return TSDB_CODE_QRY_INVALID_INPUT; + } + + SVShowTablesFetchReq *pFetchReq = pMsg->pCont; + QW_ERR_RET(qwBuildAndSendShowFetchRsp(pMsg, pFetchReq)); +} + +int32_t qWorkerContinueQuery(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { + int32_t code = 0; + int8_t status = 0; + bool queryDone = false; + uint64_t sId, qId, tId; + + //TODO call executer to continue execute subquery + code = 0; + void *data = NULL; + queryDone = false; + //TODO call executer to continue execute subquery + + if (TSDB_CODE_SUCCESS != code) { + status = JOB_TASK_STATUS_FAILED; + } else if (queryDone) { + status = JOB_TASK_STATUS_SUCCEED; + } else { + status = JOB_TASK_STATUS_PARTIAL_SUCCEED; + } + + code = qwQueryPostProcess(qWorkerMgmt, sId, qId, tId, status, code); + + QW_RET(code); +} void qWorkerDestroy(void **qWorkerMgmt) { if (NULL == qWorkerMgmt || NULL == *qWorkerMgmt) { diff --git a/source/libs/qworker/test/CMakeLists.txt b/source/libs/qworker/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d755ad487ca64959ad92b2b4964f821785de922 --- /dev/null +++ b/source/libs/qworker/test/CMakeLists.txt @@ -0,0 +1,18 @@ + +MESSAGE(STATUS "build qworker unit test") + +# GoogleTest requires at least C++11 +SET(CMAKE_CXX_STANDARD 11) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +ADD_EXECUTABLE(qworkerTest ${SOURCE_LIST}) +TARGET_LINK_LIBRARIES( + qworkerTest + PUBLIC os util common transport gtest qcom planner qworker +) + +TARGET_INCLUDE_DIRECTORIES( + qworkerTest + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/qworker/" + PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/qworker/inc" +) diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7bc1c4ff40f49024d3c5b69470f66740bf25c1ab --- /dev/null +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -0,0 +1,478 @@ +/* + * 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 +#include +#include +#pragma GCC diagnostic ignored "-Wwrite-strings" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#include "os.h" + +#include "taos.h" +#include "tdef.h" +#include "tvariant.h" +#include "tep.h" +#include "trpc.h" +#include "planner.h" +#include "qworker.h" +#include "stub.h" +#include "addr_any.h" + + +namespace { + +bool testStop = false; + +int32_t qwtStringToPlan(const char* str, SSubplan** subplan) { + return 0; +} + +void qwtRpcSendResponse(const SRpcMsg *pRsp) { + if (TDMT_VND_TASKS_STATUS_RSP == pRsp->msgType) { + SSchedulerStatusRsp *rsp = (SSchedulerStatusRsp *)pRsp->pCont; + printf("task num:%d\n", rsp->num); + for (int32_t i = 0; i < rsp->num; ++i) { + STaskStatus *task = &rsp->status[i]; + printf("qId:%"PRIx64",tId:%"PRIx64",status:%d\n", task->queryId, task->taskId, task->status); + } + } + return; +} + + + +void stubSetStringToPlan() { + static Stub stub; + stub.set(qStringToSubplan, qwtStringToPlan); + { + AddrAny any("libplanner.so"); + std::map result; + any.get_global_func_addr_dynsym("^qStringToSubplan$", result); + for (const auto& f : result) { + stub.set(f.second, qwtStringToPlan); + } + } +} + +void stubSetRpcSendResponse() { + static Stub stub; + stub.set(rpcSendResponse, qwtRpcSendResponse); + { + AddrAny any("libplanner.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendResponse$", result); + for (const auto& f : result) { + stub.set(f.second, qwtRpcSendResponse); + } + } +} + +void *queryThread(void *param) { + SRpcMsg queryRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + SSubQueryMsg *queryMsg = (SSubQueryMsg *)calloc(1, sizeof(SSubQueryMsg) + 100); + queryMsg->queryId = htobe64(1); + queryMsg->sId = htobe64(1); + queryMsg->taskId = htobe64(1); + queryMsg->contentLen = htonl(100); + queryRpc.pCont = queryMsg; + queryRpc.contLen = sizeof(SSubQueryMsg) + 100; + + while (!testStop) { + qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); + usleep(rand()%5); + if (++n % 50000 == 0) { + printf("query:%d\n", n); + } + } + + return NULL; +} + +void *readyThread(void *param) { + SRpcMsg readyRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + SResReadyMsg readyMsg = {0}; + readyMsg.sId = htobe64(1); + readyMsg.queryId = htobe64(1); + readyMsg.taskId = htobe64(1); + readyRpc.pCont = &readyMsg; + readyRpc.contLen = sizeof(SResReadyMsg); + + while (!testStop) { + code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); + usleep(rand()%5); + if (++n % 50000 == 0) { + printf("ready:%d\n", n); + } + } + + return NULL; +} + +void *fetchThread(void *param) { + SRpcMsg fetchRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + SResFetchMsg fetchMsg = {0}; + fetchMsg.sId = htobe64(1); + fetchMsg.queryId = htobe64(1); + fetchMsg.taskId = htobe64(1); + fetchRpc.pCont = &fetchMsg; + fetchRpc.contLen = sizeof(SResFetchMsg); + + while (!testStop) { + code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); + usleep(rand()%5); + if (++n % 50000 == 0) { + printf("fetch:%d\n", n); + } + } + + return NULL; +} + +void *dropThread(void *param) { + SRpcMsg dropRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + STaskDropMsg dropMsg = {0}; + dropMsg.sId = htobe64(1); + dropMsg.queryId = htobe64(1); + dropMsg.taskId = htobe64(1); + dropRpc.pCont = &dropMsg; + dropRpc.contLen = sizeof(STaskDropMsg); + + while (!testStop) { + code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); + usleep(rand()%5); + if (++n % 50000 == 0) { + printf("drop:%d\n", n); + } + } + + return NULL; +} + +void *statusThread(void *param) { + SRpcMsg statusRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + SSchTasksStatusMsg statusMsg = {0}; + statusMsg.sId = htobe64(1); + statusRpc.pCont = &statusMsg; + statusRpc.contLen = sizeof(SSchTasksStatusMsg); + statusRpc.msgType = TDMT_VND_TASKS_STATUS; + + while (!testStop) { + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + usleep(rand()%5); + if (++n % 50000 == 0) { + printf("status:%d\n", n); + } + } + + return NULL; +} + + + + + +} + + +TEST(seqTest, normalCase) { + void *mgmt = NULL; + int32_t code = 0; + void *mockPointer = (void *)0x1; + SRpcMsg queryRpc = {0}; + SRpcMsg readyRpc = {0}; + SRpcMsg fetchRpc = {0}; + SRpcMsg dropRpc = {0}; + SRpcMsg statusRpc = {0}; + + SSubQueryMsg *queryMsg = (SSubQueryMsg *)calloc(1, sizeof(SSubQueryMsg) + 100); + queryMsg->queryId = htobe64(1); + queryMsg->sId = htobe64(1); + queryMsg->taskId = htobe64(1); + queryMsg->contentLen = htonl(100); + queryRpc.pCont = queryMsg; + queryRpc.contLen = sizeof(SSubQueryMsg) + 100; + + SResReadyMsg readyMsg = {0}; + readyMsg.sId = htobe64(1); + readyMsg.queryId = htobe64(1); + readyMsg.taskId = htobe64(1); + readyRpc.pCont = &readyMsg; + readyRpc.contLen = sizeof(SResReadyMsg); + + SResFetchMsg fetchMsg = {0}; + fetchMsg.sId = htobe64(1); + fetchMsg.queryId = htobe64(1); + fetchMsg.taskId = htobe64(1); + fetchRpc.pCont = &fetchMsg; + fetchRpc.contLen = sizeof(SResFetchMsg); + + STaskDropMsg dropMsg = {0}; + dropMsg.sId = htobe64(1); + dropMsg.queryId = htobe64(1); + dropMsg.taskId = htobe64(1); + dropRpc.pCont = &dropMsg; + dropRpc.contLen = sizeof(STaskDropMsg); + + SSchTasksStatusMsg statusMsg = {0}; + statusMsg.sId = htobe64(1); + statusRpc.pCont = &statusMsg; + statusRpc.contLen = sizeof(SSchTasksStatusMsg); + statusRpc.msgType = TDMT_VND_TASKS_STATUS; + + stubSetStringToPlan(); + stubSetRpcSendResponse(); + + code = qWorkerInit(NULL, &mgmt); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + qWorkerDestroy(&mgmt); +} + +TEST(seqTest, cancelFirst) { + void *mgmt = NULL; + int32_t code = 0; + void *mockPointer = (void *)0x1; + SRpcMsg queryRpc = {0}; + SRpcMsg dropRpc = {0}; + SRpcMsg statusRpc = {0}; + + SSubQueryMsg *queryMsg = (SSubQueryMsg *)calloc(1, sizeof(SSubQueryMsg) + 100); + queryMsg->queryId = htobe64(1); + queryMsg->sId = htobe64(1); + queryMsg->taskId = htobe64(1); + queryMsg->contentLen = htonl(100); + queryRpc.pCont = queryMsg; + queryRpc.contLen = sizeof(SSubQueryMsg) + 100; + + STaskDropMsg dropMsg = {0}; + dropMsg.sId = htobe64(1); + dropMsg.queryId = htobe64(1); + dropMsg.taskId = htobe64(1); + dropRpc.pCont = &dropMsg; + dropRpc.contLen = sizeof(STaskDropMsg); + + SSchTasksStatusMsg statusMsg = {0}; + statusMsg.sId = htobe64(1); + statusRpc.pCont = &statusMsg; + statusRpc.contLen = sizeof(SSchTasksStatusMsg); + statusRpc.msgType = TDMT_VND_TASKS_STATUS; + + stubSetStringToPlan(); + stubSetRpcSendResponse(); + + code = qWorkerInit(NULL, &mgmt); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); + ASSERT_EQ(code, 0); + + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + + qWorkerDestroy(&mgmt); +} + +TEST(seqTest, randCase) { + void *mgmt = NULL; + int32_t code = 0; + void *mockPointer = (void *)0x1; + SRpcMsg queryRpc = {0}; + SRpcMsg readyRpc = {0}; + SRpcMsg fetchRpc = {0}; + SRpcMsg dropRpc = {0}; + SRpcMsg statusRpc = {0}; + + SSubQueryMsg *queryMsg = (SSubQueryMsg *)calloc(1, sizeof(SSubQueryMsg) + 100); + queryMsg->queryId = htobe64(1); + queryMsg->sId = htobe64(1); + queryMsg->taskId = htobe64(1); + queryMsg->contentLen = htonl(100); + queryRpc.pCont = queryMsg; + queryRpc.contLen = sizeof(SSubQueryMsg) + 100; + + SResReadyMsg readyMsg = {0}; + readyMsg.sId = htobe64(1); + readyMsg.queryId = htobe64(1); + readyMsg.taskId = htobe64(1); + readyRpc.pCont = &readyMsg; + readyRpc.contLen = sizeof(SResReadyMsg); + + SResFetchMsg fetchMsg = {0}; + fetchMsg.sId = htobe64(1); + fetchMsg.queryId = htobe64(1); + fetchMsg.taskId = htobe64(1); + fetchRpc.pCont = &fetchMsg; + fetchRpc.contLen = sizeof(SResFetchMsg); + + STaskDropMsg dropMsg = {0}; + dropMsg.sId = htobe64(1); + dropMsg.queryId = htobe64(1); + dropMsg.taskId = htobe64(1); + dropRpc.pCont = &dropMsg; + dropRpc.contLen = sizeof(STaskDropMsg); + + SSchTasksStatusMsg statusMsg = {0}; + statusMsg.sId = htobe64(1); + statusRpc.pCont = &statusMsg; + statusRpc.contLen = sizeof(SSchTasksStatusMsg); + statusRpc.msgType = TDMT_VND_TASKS_STATUS; + + stubSetStringToPlan(); + stubSetRpcSendResponse(); + + srand(time(NULL)); + + code = qWorkerInit(NULL, &mgmt); + ASSERT_EQ(code, 0); + + int32_t t = 0; + int32_t maxr = 10001; + while (true) { + int32_t r = rand() % maxr; + + if (r >= 0 && r < maxr/5) { + printf("Query,%d\n", t++); + code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc); + } else if (r >= maxr/5 && r < maxr * 2/5) { + printf("Ready,%d\n", t++); + code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); + } else if (r >= maxr * 2/5 && r < maxr* 3/5) { + printf("Fetch,%d\n", t++); + code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc); + } else if (r >= maxr * 3/5 && r < maxr * 4/5) { + printf("Drop,%d\n", t++); + code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc); + } else if (r >= maxr * 4/5 && r < maxr-1) { + printf("Status,%d\n", t++); + statusMsg.sId = htobe64(1); + code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc); + ASSERT_EQ(code, 0); + } else { + printf("QUIT RAND NOW"); + break; + } + } + + qWorkerDestroy(&mgmt); +} + +TEST(seqTest, multithreadRand) { + void *mgmt = NULL; + int32_t code = 0; + void *mockPointer = (void *)0x1; + + stubSetStringToPlan(); + stubSetRpcSendResponse(); + + srand(time(NULL)); + + code = qWorkerInit(NULL, &mgmt); + ASSERT_EQ(code, 0); + + pthread_attr_t thattr; + pthread_attr_init(&thattr); + + pthread_t t1,t2,t3,t4,t5; + pthread_create(&(t1), &thattr, queryThread, mgmt); + pthread_create(&(t2), &thattr, readyThread, NULL); + pthread_create(&(t3), &thattr, fetchThread, NULL); + pthread_create(&(t4), &thattr, dropThread, NULL); + pthread_create(&(t5), &thattr, statusThread, NULL); + + int32_t t = 0; + int32_t maxr = 10001; + sleep(300); + testStop = true; + sleep(1); + + qWorkerDestroy(&mgmt); +} + + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + + + diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 3fab91edacd77096fbacceee5df3f762452ad16d..c327e4cfead62c33da5d63af0651d868f2c56b34 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -31,57 +31,86 @@ extern "C" { #define SCH_MAX_CONDIDATE_EP_NUM TSDB_MAX_REPLICA +enum { + SCH_READ = 1, + SCH_WRITE, +}; + typedef struct SSchedulerMgmt { uint64_t taskId; - uint64_t schedulerId; + uint64_t sId; SSchedulerCfg cfg; - SHashObj *Jobs; // key: queryId, value: SQueryJob* + SHashObj *jobs; // key: queryId, value: SQueryJob* } SSchedulerMgmt; -typedef struct SQueryTask { +typedef struct SSchCallbackParam { + uint64_t queryId; + uint64_t taskId; +} SSchCallbackParam; + +typedef struct SSchLevel { + int32_t level; + int8_t status; + SRWLatch lock; + int32_t taskFailed; + int32_t taskSucceed; + int32_t taskNum; + SArray *subTasks; // Element is SQueryTask +} SSchLevel; + + +typedef struct SSchTask { uint64_t taskId; // task id + SSchLevel *level; // level SSubplan *plan; // subplan char *msg; // operator tree + int32_t msgLen; // msg length int8_t status; // task status SEpAddr execAddr; // task actual executed node address SQueryProfileSummary summary; // task execution summary int32_t childReady; // child task ready number SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* -} SQueryTask; +} SSchTask; -typedef struct SQueryLevel { - int32_t level; - int8_t status; - int32_t taskNum; - SArray *subTasks; // Element is SQueryTask -} SQueryLevel; +typedef struct SSchJobAttr { + bool needFetch; + bool syncSchedule; + bool queryJob; +} SSchJobAttr; -typedef struct SQueryJob { +typedef struct SSchJob { uint64_t queryId; int32_t levelNum; int32_t levelIdx; int8_t status; + SSchJobAttr attr; SQueryProfileSummary summary; - SEpSet dataSrcEps; - SEpAddr resEp; + SEpSet dataSrcEps; + SEpAddr resEp; void *transport; SArray *qnodeList; tsem_t rspSem; int32_t userFetch; int32_t remoteFetch; - void *res; + SSchTask *fetchTask; + int32_t errCode; + void *res; + int32_t resNumOfRows; + SHashObj *execTasks; // executing tasks, key:taskid, value:SQueryTask* SHashObj *succTasks; // succeed tasks, key:taskid, value:SQueryTask* + SHashObj *failTasks; // failed tasks, key:taskid, value:SQueryTask* SArray *levels; // Element is SQueryLevel, starting from 0. SArray *subPlans; // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0. -} SQueryJob; +} SSchJob; #define SCH_HAS_QNODE_IN_CLUSTER(type) (false) //TODO CLUSTER TYPE #define SCH_TASK_READY_TO_LUNCH(task) ((task)->childReady >= taosArrayGetSize((task)->children)) // MAY NEED TO ENHANCE -#define SCH_IS_DATA_SRC_TASK(task) (task->plan->type == QUERY_TYPE_SCAN) +#define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN) +#define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY) #define SCH_JOB_ERR_LOG(param, ...) qError("QID:%"PRIx64 param, job->queryId, __VA_ARGS__) #define SCH_TASK_ERR_LOG(param, ...) qError("QID:%"PRIx64",TID:%"PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) @@ -91,8 +120,12 @@ typedef struct SQueryJob { #define SCH_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); terrno = _code; return _code; } } while (0) #define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) +#define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) + -extern int32_t schLaunchTask(SQueryJob *job, SQueryTask *task); +extern int32_t schLaunchTask(SSchJob *job, SSchTask *task); +extern int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType); #ifdef __cplusplus } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 83507c8dd7bf4753c8addf614af1b5bd11e6948d..12c07d69eeafb017297b83f423b753fde527cb55 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -14,49 +14,19 @@ */ #include "schedulerInt.h" -#include "taosmsg.h" +#include "tmsg.h" #include "query.h" #include "catalog.h" SSchedulerMgmt schMgmt = {0}; -int32_t schBuildAndSendRequest(void *pRpc, const SEpSet* pMgmtEps, __taos_async_fn_t fp) { -/* - SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_SQL_CONNECT); - if (pRequest == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SRequestMsgBody body = {0}; - buildConnectMsg(pRequest, &body); - - int64_t transporterId = 0; - sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); - - tsem_wait(&pRequest->body.rspSem); - destroyConnectMsg(&body); - - if (pRequest->code != TSDB_CODE_SUCCESS) { - const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); - printf("failed to connect to server, reason: %s\n\n", errorMsg); - - destroyRequest(pRequest); - taos_close(pTscObj); - pTscObj = NULL; - } else { - tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p", pTscObj->id, pTscObj->connId, pTscObj->pTransporter); - destroyRequest(pRequest); - } -*/ -} - -int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) { +int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { for (int32_t i = 0; i < job->levelNum; ++i) { - SQueryLevel *level = taosArrayGet(job->levels, i); + SSchLevel *level = taosArrayGet(job->levels, i); for (int32_t m = 0; m < level->taskNum; ++m) { - SQueryTask *task = taosArrayGet(level->subTasks, m); + SSchTask *task = taosArrayGet(level->subTasks, m); SSubplan *plan = task->plan; int32_t childNum = plan->pChildern ? (int32_t)taosArrayGetSize(plan->pChildern) : 0; int32_t parentNum = plan->pParents ? (int32_t)taosArrayGetSize(plan->pParents) : 0; @@ -70,14 +40,14 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) { } for (int32_t n = 0; n < childNum; ++n) { - SSubplan *child = taosArrayGet(plan->pChildern, n); - SQueryTask *childTask = taosHashGet(planToTask, &child, POINTER_BYTES); - if (childTask) { + SSubplan **child = taosArrayGet(plan->pChildern, n); + SSchTask **childTask = taosHashGet(planToTask, child, POINTER_BYTES); + if (NULL == childTask || NULL == *childTask) { qError("subplan relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - if (NULL == taosArrayPush(task->children, &childTask)) { + if (NULL == taosArrayPush(task->children, childTask)) { qError("taosArrayPush failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -92,14 +62,14 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) { } for (int32_t n = 0; n < parentNum; ++n) { - SSubplan *parent = taosArrayGet(plan->pParents, n); - SQueryTask *parentTask = taosHashGet(planToTask, &parent, POINTER_BYTES); - if (parentTask) { + SSubplan **parent = taosArrayGet(plan->pParents, n); + SSchTask **parentTask = taosHashGet(planToTask, parent, POINTER_BYTES); + if (NULL == parentTask || NULL == *parentTask) { qError("subplan relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - if (NULL == taosArrayPush(task->parents, &parentTask)) { + if (NULL == taosArrayPush(task->parents, parentTask)) { qError("taosArrayPush failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -107,13 +77,13 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) { } } - SQueryLevel *level = taosArrayGet(job->levels, 0); - if (level->taskNum > 1) { + SSchLevel *level = taosArrayGet(job->levels, 0); + if (job->attr.queryJob && level->taskNum > 1) { qError("invalid plan info, level 0, taskNum:%d", level->taskNum); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - SQueryTask *task = taosArrayGet(level->subTasks, 0); + SSchTask *task = taosArrayGet(level->subTasks, 0); if (task->parents && taosArrayGetSize(task->parents) > 0) { qError("invalid plan info, level 0, parentNum:%d", (int32_t)taosArrayGetSize(task->parents)); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); @@ -124,7 +94,7 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) { } -int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) { +int32_t schValidateAndBuildJob(SQueryDag *dag, SSchJob *job) { int32_t code = 0; job->queryId = dag->queryId; @@ -146,25 +116,35 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - job->levels = taosArrayInit(levelNum, sizeof(SQueryLevel)); + job->levels = taosArrayInit(levelNum, sizeof(SSchLevel)); if (NULL == job->levels) { qError("taosArrayInit %d failed", levelNum); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + job->attr.needFetch = true; + job->levelNum = levelNum; job->levelIdx = levelNum - 1; job->subPlans = dag->pSubplans; - SQueryLevel level = {0}; + SSchLevel level = {0}; SArray *levelPlans = NULL; int32_t levelPlanNum = 0; + SSchLevel *pLevel = NULL; level.status = JOB_TASK_STATUS_NOT_START; for (int32_t i = 0; i < levelNum; ++i) { - level.level = i; + if (NULL == taosArrayPush(job->levels, &level)) { + qError("taosArrayPush failed"); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + pLevel = taosArrayGet(job->levels, i); + + pLevel->level = i; levelPlans = taosArrayGetP(dag->pSubplans, i); if (NULL == levelPlans) { qError("no level plans for level %d", i); @@ -177,23 +157,31 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) { SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } - level.taskNum = levelPlanNum; + pLevel->taskNum = levelPlanNum; - level.subTasks = taosArrayInit(levelPlanNum, sizeof(SQueryTask)); - if (NULL == level.subTasks) { + pLevel->subTasks = taosArrayInit(levelPlanNum, sizeof(SSchTask)); + if (NULL == pLevel->subTasks) { qError("taosArrayInit %d failed", levelPlanNum); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } for (int32_t n = 0; n < levelPlanNum; ++n) { - SSubplan *plan = taosArrayGet(levelPlans, n); - SQueryTask task = {0}; + SSubplan *plan = taosArrayGetP(levelPlans, n); + SSchTask task = {0}; + + if (plan->type == QUERY_TYPE_MODIFY) { + job->attr.needFetch = false; + } else { + job->attr.queryJob = true; + } + task.taskId = atomic_add_fetch_64(&schMgmt.taskId, 1); task.plan = plan; + task.level = pLevel; task.status = JOB_TASK_STATUS_NOT_START; - void *p = taosArrayPush(level.subTasks, &task); + void *p = taosArrayPush(pLevel->subTasks, &task); if (NULL == p) { qError("taosArrayPush failed"); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -205,10 +193,6 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) { } } - if (NULL == taosArrayPush(job->levels, &level)) { - qError("taosArrayPush failed"); - SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } } SCH_ERR_JRET(schBuildTaskRalation(job, planToTask)); @@ -220,8 +204,8 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) { return TSDB_CODE_SUCCESS; _return: - if (level.subTasks) { - taosArrayDestroy(level.subTasks); + if (pLevel->subTasks) { + taosArrayDestroy(pLevel->subTasks); } if (planToTask) { @@ -231,7 +215,7 @@ _return: SCH_RET(code); } -int32_t schSetTaskExecEpSet(SQueryJob *job, SEpSet *epSet) { +int32_t schSetTaskExecEpSet(SSchJob *job, SEpSet *epSet) { if (epSet->numOfEps >= SCH_MAX_CONDIDATE_EP_NUM) { return TSDB_CODE_SUCCESS; } @@ -258,7 +242,7 @@ int32_t schSetTaskExecEpSet(SQueryJob *job, SEpSet *epSet) { } -int32_t schPushTaskToExecList(SQueryJob *job, SQueryTask *task) { +int32_t schPushTaskToExecList(SSchJob *job, SSchTask *task) { if (0 != taosHashPut(job->execTasks, &task->taskId, sizeof(task->taskId), &task, POINTER_BYTES)) { qError("taosHashPut failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -267,13 +251,13 @@ int32_t schPushTaskToExecList(SQueryJob *job, SQueryTask *task) { return TSDB_CODE_SUCCESS; } -int32_t schMoveTaskToSuccList(SQueryJob *job, SQueryTask *task, bool *moved) { +int32_t schMoveTaskToSuccList(SSchJob *job, SSchTask *task, bool *moved) { if (0 != taosHashRemove(job->execTasks, &task->taskId, sizeof(task->taskId))) { qWarn("remove task[%"PRIx64"] from execTasks failed", task->taskId); return TSDB_CODE_SUCCESS; } - if (0 != taosHashPut(job->execTasks, &task->taskId, sizeof(task->taskId), &task, POINTER_BYTES)) { + if (0 != taosHashPut(job->succTasks, &task->taskId, sizeof(task->taskId), &task, POINTER_BYTES)) { qError("taosHashPut failed"); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -283,73 +267,22 @@ int32_t schMoveTaskToSuccList(SQueryJob *job, SQueryTask *task, bool *moved) { return TSDB_CODE_SUCCESS; } - -int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { - int32_t msgSize = 0; - void *msg = NULL; - - switch (msgType) { - case TSDB_MSG_TYPE_QUERY: { - if (NULL == task->msg) { - qError("query msg is NULL"); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); - } - - int32_t len = strlen(task->msg); - msgSize = sizeof(SSubQueryMsg) + len + 1; - msg = calloc(1, msgSize); - if (NULL == msg) { - qError("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SSubQueryMsg *pMsg = msg; - - pMsg->schedulerId = htobe64(schMgmt.schedulerId); - pMsg->queryId = htobe64(job->queryId); - pMsg->taskId = htobe64(task->taskId); - pMsg->contentLen = htonl(len); - memcpy(pMsg->msg, task->msg, len); - pMsg->msg[len] = 0; - break; - } - case TSDB_MSG_TYPE_RES_READY: { - msgSize = sizeof(SResReadyMsg); - msg = calloc(1, msgSize); - if (NULL == msg) { - qError("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SResReadyMsg *pMsg = msg; - pMsg->queryId = htobe64(job->queryId); - pMsg->taskId = htobe64(task->taskId); - break; - } - case TSDB_MSG_TYPE_FETCH: { - msgSize = sizeof(SResFetchMsg); - msg = calloc(1, msgSize); - if (NULL == msg) { - qError("calloc %d failed", msgSize); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - SResFetchMsg *pMsg = msg; - pMsg->queryId = htobe64(job->queryId); - pMsg->taskId = htobe64(task->taskId); - break; - } - default: - qError("unknown msg type:%d", msgType); - break; +int32_t schMoveTaskToFailList(SSchJob *job, SSchTask *task, bool *moved) { + if (0 != taosHashRemove(job->execTasks, &task->taskId, sizeof(task->taskId))) { + qWarn("remove task[%"PRIx64"] from execTasks failed, it may not exist", task->taskId); } - //TODO SEND MSG + if (0 != taosHashPut(job->failTasks, &task->taskId, sizeof(task->taskId), &task, POINTER_BYTES)) { + qError("taosHashPut failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + *moved = true; + return TSDB_CODE_SUCCESS; } -int32_t schTaskCheckAndSetRetry(SQueryJob *job, SQueryTask *task, int32_t errCode, bool *needRetry) { +int32_t schTaskCheckAndSetRetry(SSchJob *job, SSchTask *task, int32_t errCode, bool *needRetry) { // TODO set retry or not based on task type/errCode/retry times/job status/available eps... // TODO if needRetry, set task retry info @@ -359,7 +292,7 @@ int32_t schTaskCheckAndSetRetry(SQueryJob *job, SQueryTask *task, int32_t errCod } -int32_t schFetchFromRemote(SQueryJob *job) { +int32_t schFetchFromRemote(SSchJob *job) { int32_t code = 0; if (atomic_val_compare_exchange_32(&job->remoteFetch, 0, 1) != 0) { @@ -367,7 +300,7 @@ int32_t schFetchFromRemote(SQueryJob *job) { return TSDB_CODE_SUCCESS; } - SCH_ERR_JRET(schAsyncSendMsg(job, NULL, TSDB_MSG_TYPE_FETCH)); + SCH_ERR_JRET(schBuildAndSendMsg(job, job->fetchTask, TDMT_VND_FETCH)); return TSDB_CODE_SUCCESS; @@ -378,8 +311,12 @@ _return: } -int32_t schProcessOnJobSuccess(SQueryJob *job) { - job->status = JOB_TASK_STATUS_SUCCEED; +int32_t schProcessOnJobPartialSuccess(SSchJob *job) { + job->status = JOB_TASK_STATUS_PARTIAL_SUCCEED; + + if ((!job->attr.needFetch) && job->attr.syncSchedule) { + tsem_post(&job->rspSem); + } if (job->userFetch) { SCH_ERR_RET(schFetchFromRemote(job)); @@ -388,26 +325,27 @@ int32_t schProcessOnJobSuccess(SQueryJob *job) { return TSDB_CODE_SUCCESS; } -int32_t schProcessOnJobFailure(SQueryJob *job) { +int32_t schProcessOnJobFailure(SSchJob *job, int32_t errCode) { job->status = JOB_TASK_STATUS_FAILED; + job->errCode = errCode; atomic_val_compare_exchange_32(&job->remoteFetch, 1, 0); - if (job->userFetch) { + if (job->userFetch || ((!job->attr.needFetch) && job->attr.syncSchedule)) { tsem_post(&job->rspSem); } return TSDB_CODE_SUCCESS; } -int32_t schProcessOnDataFetched(SQueryJob *job) { +int32_t schProcessOnDataFetched(SSchJob *job) { atomic_val_compare_exchange_32(&job->remoteFetch, 1, 0); tsem_post(&job->rspSem); } -int32_t schProcessOnTaskSuccess(SQueryJob *job, SQueryTask *task) { +int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { bool moved = false; SCH_ERR_RET(schMoveTaskToSuccList(job, task, &moved)); @@ -418,17 +356,40 @@ int32_t schProcessOnTaskSuccess(SQueryJob *job, SQueryTask *task) { task->status = JOB_TASK_STATUS_SUCCEED; - int32_t parentNum = (int32_t)taosArrayGetSize(task->parents); + int32_t parentNum = task->parents ? (int32_t)taosArrayGetSize(task->parents) : 0; if (parentNum == 0) { if (task->plan->level != 0) { qError("level error"); SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - strncpy(job->resEp.fqdn, task->execAddr.fqdn, sizeof(job->resEp.fqdn)); - job->resEp.port = task->execAddr.port; + int32_t taskDone = 0; + + if (SCH_TASK_NEED_WAIT_ALL(task)) { + SCH_LOCK(SCH_WRITE, &task->level->lock); + task->level->taskSucceed++; + taskDone = task->level->taskSucceed + task->level->taskFailed; + SCH_UNLOCK(SCH_WRITE, &task->level->lock); + + if (taskDone < task->level->taskNum) { + qDebug("wait all tasks, done:%d, all:%d", taskDone, task->level->taskNum); + return TSDB_CODE_SUCCESS; + } + + if (task->level->taskFailed > 0) { + job->status = JOB_TASK_STATUS_FAILED; + SCH_ERR_RET(schProcessOnJobFailure(job, TSDB_CODE_QRY_APP_ERROR)); - SCH_ERR_RET(schProcessOnJobSuccess(job)); + return TSDB_CODE_SUCCESS; + } + } else { + strncpy(job->resEp.fqdn, task->execAddr.fqdn, sizeof(job->resEp.fqdn)); + job->resEp.port = task->execAddr.port; + } + + job->fetchTask = task; + + SCH_ERR_RET(schProcessOnJobPartialSuccess(job)); return TSDB_CODE_SUCCESS; } @@ -441,29 +402,48 @@ int32_t schProcessOnTaskSuccess(SQueryJob *job, SQueryTask *task) { } for (int32_t i = 0; i < parentNum; ++i) { - SQueryTask *par = taosArrayGet(task->parents, i); + SSchTask *par = *(SSchTask **)taosArrayGet(task->parents, i); ++par->childReady; SCH_ERR_RET(qSetSubplanExecutionNode(par->plan, task->plan->id.templateId, &task->execAddr)); if (SCH_TASK_READY_TO_LUNCH(par)) { - SCH_ERR_RET(schLaunchTask(job, task)); + SCH_ERR_RET(schLaunchTask(job, par)); } } return TSDB_CODE_SUCCESS; } -int32_t schProcessOnTaskFailure(SQueryJob *job, SQueryTask *task, int32_t errCode) { +int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { bool needRetry = false; + bool moved = false; + int32_t taskDone = 0; SCH_ERR_RET(schTaskCheckAndSetRetry(job, task, errCode, &needRetry)); if (!needRetry) { SCH_TASK_ERR_LOG("task failed[%x], no more retry", errCode); + + SCH_ERR_RET(schMoveTaskToFailList(job, task, &moved)); + if (!moved) { + SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + } + + if (SCH_TASK_NEED_WAIT_ALL(task)) { + SCH_LOCK(SCH_WRITE, &task->level->lock); + task->level->taskFailed++; + taskDone = task->level->taskSucceed + task->level->taskFailed; + SCH_UNLOCK(SCH_WRITE, &task->level->lock); + + if (taskDone < task->level->taskNum) { + qDebug("wait all tasks, done:%d, all:%d", taskDone, task->level->taskNum); + return TSDB_CODE_SUCCESS; + } + } job->status = JOB_TASK_STATUS_FAILED; - SCH_ERR_RET(schProcessOnJobFailure(job)); + SCH_ERR_RET(schProcessOnJobFailure(job, errCode)); return TSDB_CODE_SUCCESS; } @@ -473,34 +453,63 @@ int32_t schProcessOnTaskFailure(SQueryJob *job, SQueryTask *task, int32_t errCod return TSDB_CODE_SUCCESS; } -int32_t schHandleRspMsg(SQueryJob *job, SQueryTask *task, int32_t msgType, int32_t rspCode) { +int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; switch (msgType) { - case TSDB_MSG_TYPE_QUERY: - if (rspCode != TSDB_CODE_SUCCESS) { - SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); - } else { - code = schAsyncSendMsg(job, task, TSDB_MSG_TYPE_RES_READY); - if (code) { - goto _task_error; + case TDMT_VND_SUBMIT_RSP: { + SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; + if (rsp->code != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + } else { + job->resNumOfRows += rsp->affectedRows; + + code = schProcessOnTaskSuccess(job, task); + if (code) { + goto _task_error; + } } + break; } - break; - case TSDB_MSG_TYPE_RES_READY: - if (rspCode != TSDB_CODE_SUCCESS) { - SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); - } else { - code = schProcessOnTaskSuccess(job, task); - if (code) { - goto _task_error; - } + case TDMT_VND_QUERY_RSP: { + SQueryTableRsp *rsp = (SQueryTableRsp *)msg; + + if (rsp->code != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + } else { + code = schBuildAndSendMsg(job, task, TDMT_VND_RES_READY); + if (code) { + goto _task_error; + } + } + break; + } + case TDMT_VND_RES_READY_RSP: { + SResReadyRsp *rsp = (SResReadyRsp *)msg; + + if (rsp->code != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + } else { + code = schProcessOnTaskSuccess(job, task); + if (code) { + goto _task_error; + } + } + break; + } + case TDMT_VND_FETCH_RSP: { + SCH_ERR_JRET(rspCode); + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)msg; + + job->res = rsp; + job->resNumOfRows = rsp->numOfRows; + + SCH_ERR_JRET(schProcessOnDataFetched(job)); + break; + } + case TDMT_VND_DROP_TASK: { + } - break; - case TSDB_MSG_TYPE_FETCH: - SCH_ERR_JRET(rspCode); - SCH_ERR_JRET(schProcessOnDataFetched(job)); - break; default: qError("unknown msg type:%d received", msgType); return TSDB_CODE_QRY_INVALID_INPUT; @@ -513,17 +522,221 @@ _task_error: return TSDB_CODE_SUCCESS; _return: - code = schProcessOnJobFailure(job); + code = schProcessOnJobFailure(job, code); return code; } +int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, int32_t rspCode) { + int32_t code = 0; + SSchCallbackParam *pParam = (SSchCallbackParam *)param; + + SSchJob **job = taosHashGet(schMgmt.jobs, &pParam->queryId, sizeof(pParam->queryId)); + if (NULL == job || NULL == (*job)) { + qError("taosHashGet queryId:%"PRIx64" not exist", pParam->queryId); + SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + SSchTask **task = taosHashGet((*job)->execTasks, &pParam->taskId, sizeof(pParam->taskId)); + if (NULL == task || NULL == (*task)) { + qError("taosHashGet taskId:%"PRIx64" not exist", pParam->taskId); + SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + schProcessRspMsg(*job, *task, msgType, pMsg->pData, pMsg->len, rspCode); + +_return: + tfree(param); + + SCH_RET(code); +} + +int32_t schHandleSubmitCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_SUBMIT_RSP, code); +} +int32_t schHandleQueryCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); +} +int32_t schHandleFetchCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code); +} +int32_t schHandleReadyCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_RES_READY_RSP, code); +} +int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { + SSchCallbackParam *pParam = (SSchCallbackParam *)param; + qDebug("drop task rsp received, queryId:%"PRIx64 ",taksId:%"PRIx64 ",code:%d", pParam->queryId, pParam->taskId, code); +} + +int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { + switch (msgType) { + case TDMT_VND_SUBMIT: + *fp = schHandleSubmitCallback; + break; + case TDMT_VND_QUERY: + *fp = schHandleQueryCallback; + break; + case TDMT_VND_RES_READY: + *fp = schHandleReadyCallback; + break; + case TDMT_VND_FETCH: + *fp = schHandleFetchCallback; + break; + case TDMT_VND_DROP_TASK: + *fp = schHandleDropCallback; + break; + default: + qError("unknown msg type:%d", msgType); + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t tId, int32_t msgType, void *msg, uint32_t msgSize) { + int32_t code = 0; + SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); + if (NULL == pMsgSendInfo) { + qError("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SSchCallbackParam *param = calloc(1, sizeof(SSchCallbackParam)); + if (NULL == param) { + qError("calloc %d failed", (int32_t)sizeof(SSchCallbackParam)); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + __async_send_cb_fn_t fp = NULL; + SCH_ERR_JRET(schGetCallbackFp(msgType, &fp)); + + param->queryId = qId; + param->taskId = tId; + + pMsgSendInfo->param = param; + pMsgSendInfo->msgInfo.pData = msg; + pMsgSendInfo->msgInfo.len = msgSize; + pMsgSendInfo->msgType = msgType; + + pMsgSendInfo->fp = fp; + + int64_t transporterId = 0; + SCH_ERR_JRET(asyncSendMsgToServer(transport, epSet, &transporterId, pMsgSendInfo)); + + return TSDB_CODE_SUCCESS; + +_return: + tfree(param); + tfree(pMsgSendInfo); + + SCH_RET(code); +} + + +int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { + uint32_t msgSize = 0; + void *msg = NULL; + int32_t code = 0; + + switch (msgType) { + case TDMT_VND_SUBMIT: { + if (NULL == task->msg || task->msgLen <= 0) { + qError("submit msg is NULL"); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + msgSize = task->msgLen; + msg = task->msg; + break; + } + case TDMT_VND_QUERY: { + if (NULL == task->msg) { + qError("query msg is NULL"); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + + msgSize = sizeof(SSubQueryMsg) + task->msgLen; + msg = calloc(1, msgSize); + if (NULL == msg) { + qError("calloc %d failed", msgSize); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SSubQueryMsg *pMsg = msg; + + pMsg->sId = htobe64(schMgmt.sId); + pMsg->queryId = htobe64(job->queryId); + pMsg->taskId = htobe64(task->taskId); + pMsg->contentLen = htonl(task->msgLen); + memcpy(pMsg->msg, task->msg, task->msgLen); + break; + } + case TDMT_VND_RES_READY: { + msgSize = sizeof(SResReadyMsg); + msg = calloc(1, msgSize); + if (NULL == msg) { + qError("calloc %d failed", msgSize); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SResReadyMsg *pMsg = msg; + pMsg->sId = htobe64(schMgmt.sId); + pMsg->queryId = htobe64(job->queryId); + pMsg->taskId = htobe64(task->taskId); + break; + } + case TDMT_VND_FETCH: { + if (NULL == task) { + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + msgSize = sizeof(SResFetchMsg); + msg = calloc(1, msgSize); + if (NULL == msg) { + qError("calloc %d failed", msgSize); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SResFetchMsg *pMsg = msg; + pMsg->sId = htobe64(schMgmt.sId); + pMsg->queryId = htobe64(job->queryId); + pMsg->taskId = htobe64(task->taskId); + break; + } + case TDMT_VND_DROP_TASK:{ + msgSize = sizeof(STaskDropMsg); + msg = calloc(1, msgSize); + if (NULL == msg) { + qError("calloc %d failed", msgSize); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + STaskDropMsg *pMsg = msg; + pMsg->sId = htobe64(schMgmt.sId); + pMsg->queryId = htobe64(job->queryId); + pMsg->taskId = htobe64(task->taskId); + break; + } + default: + qError("unknown msg type:%d", msgType); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); + break; + } + + SCH_ERR_JRET(schAsyncSendMsg(job->transport, &task->plan->execEpSet, job->queryId, task->taskId, msgType, msg, msgSize)); + + return TSDB_CODE_SUCCESS; + +_return: + + tfree(msg); + SCH_RET(code); +} -int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) { +int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SSubplan *plan = task->plan; - int32_t len = 0; - SCH_ERR_RET(qSubPlanToString(plan, &task->msg, &len)); + SCH_ERR_RET(qSubPlanToString(plan, &task->msg, &task->msgLen)); if (plan->execEpSet.numOfEps <= 0) { SCH_ERR_RET(schSetTaskExecEpSet(job, &plan->execEpSet)); } @@ -532,8 +745,10 @@ int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) { SCH_TASK_ERR_LOG("invalid execEpSet num:%d", plan->execEpSet.numOfEps); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } + + int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TDMT_VND_SUBMIT : TDMT_VND_QUERY; - SCH_ERR_RET(schAsyncSendMsg(job, task, TSDB_MSG_TYPE_QUERY)); + SCH_ERR_RET(schBuildAndSendMsg(job, task, msgType)); SCH_ERR_RET(schPushTaskToExecList(job, task)); @@ -542,10 +757,12 @@ int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) { return TSDB_CODE_SUCCESS; } -int32_t schLaunchJob(SQueryJob *job) { - SQueryLevel *level = taosArrayGet(job->levels, job->levelIdx); + + +int32_t schLaunchJob(SSchJob *job) { + SSchLevel *level = taosArrayGet(job->levels, job->levelIdx); for (int32_t i = 0; i < level->taskNum; ++i) { - SQueryTask *task = taosArrayGet(level->subTasks, i); + SSchTask *task = taosArrayGet(level->subTasks, i); SCH_ERR_RET(schLaunchTask(job, task)); } @@ -554,40 +771,76 @@ int32_t schLaunchJob(SQueryJob *job) { return TSDB_CODE_SUCCESS; } +void schDropJobAllTasks(SSchJob *job) { + void *pIter = taosHashIterate(job->succTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + schBuildAndSendMsg(job, task, TDMT_VND_DROP_TASK); + + pIter = taosHashIterate(job->succTasks, pIter); + } + + pIter = taosHashIterate(job->failTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + schBuildAndSendMsg(job, task, TDMT_VND_DROP_TASK); + + pIter = taosHashIterate(job->succTasks, pIter); + } +} + +uint64_t schGenSchId(void) { + uint64_t sId = 0; + + // TODO + + qDebug("Gen sId:0x%"PRIx64, sId); + + return sId; +} + int32_t schedulerInit(SSchedulerCfg *cfg) { + if (schMgmt.jobs) { + qError("scheduler already init"); + return TSDB_CODE_QRY_INVALID_INPUT; + } + if (cfg) { schMgmt.cfg = *cfg; + + if (schMgmt.cfg.maxJobNum <= 0) { + schMgmt.cfg.maxJobNum = SCHEDULE_DEFAULT_JOB_NUMBER; + } } else { schMgmt.cfg.maxJobNum = SCHEDULE_DEFAULT_JOB_NUMBER; } - schMgmt.Jobs = taosHashInit(schMgmt.cfg.maxJobNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); - if (NULL == schMgmt.Jobs) { + schMgmt.jobs = taosHashInit(schMgmt.cfg.maxJobNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + if (NULL == schMgmt.jobs) { SCH_ERR_LRET(TSDB_CODE_QRY_OUT_OF_MEMORY, "init %d schduler jobs failed", schMgmt.cfg.maxJobNum); } - schMgmt.schedulerId = 1; //TODO GENERATE A UUID + schMgmt.sId = schGenSchId(); return TSDB_CODE_SUCCESS; } -int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob) { - if (NULL == transport || NULL == transport ||NULL == pDag || NULL == pDag->pSubplans || NULL == pJob) { - SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); - } - - if (taosArrayGetSize(qnodeList) <= 0) { +int32_t scheduleExecJobImpl(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, bool syncSchedule) { + if (qnodeList && taosArrayGetSize(qnodeList) <= 0) { qInfo("qnodeList is empty"); } int32_t code = 0; - SQueryJob *job = calloc(1, sizeof(SQueryJob)); + SSchJob *job = calloc(1, sizeof(SSchJob)); if (NULL == job) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + job->attr.syncSchedule = syncSchedule; job->transport = transport; job->qnodeList = qnodeList; @@ -605,60 +858,126 @@ int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, voi SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + job->failTasks = taosHashInit(pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + if (NULL == job->failTasks) { + qError("taosHashInit %d failed", pDag->numOfSubplans); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + tsem_init(&job->rspSem, 0, 0); - - if (0 != taosHashPut(schMgmt.Jobs, &job->queryId, sizeof(job->queryId), &job, POINTER_BYTES)) { - qError("taosHashPut queryId:%"PRIx64" failed", job->queryId); - SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); + + code = taosHashPut(schMgmt.jobs, &job->queryId, sizeof(job->queryId), &job, POINTER_BYTES); + if (0 != code) { + if (HASH_NODE_EXIST(code)) { + qError("taosHashPut queryId:%"PRIx64" already exist", job->queryId); + SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } else { + qError("taosHashPut queryId:%"PRIx64" failed", job->queryId); + SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); + } } job->status = JOB_TASK_STATUS_NOT_START; SCH_ERR_JRET(schLaunchJob(job)); - *(SQueryJob **)pJob = job; + *(SSchJob **)pJob = job; + + if (syncSchedule) { + tsem_wait(&job->rspSem); + } return TSDB_CODE_SUCCESS; _return: - *(SQueryJob **)pJob = NULL; + *(SSchJob **)pJob = NULL; scheduleFreeJob(job); SCH_RET(code); } +int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, uint64_t *numOfRows) { + if (NULL == transport || /* NULL == qnodeList || */ NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == numOfRows) { + SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + *numOfRows = 0; + + SCH_ERR_RET(scheduleExecJobImpl(transport, qnodeList, pDag, pJob, true)); + + SSchJob *job = *(SSchJob **)pJob; + + *numOfRows = job->resNumOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t scheduleAsyncExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob) { + if (NULL == transport || NULL == qnodeList ||NULL == pDag || NULL == pDag->pSubplans || NULL == pJob) { + SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + return scheduleExecJobImpl(transport, qnodeList, pDag, pJob, false); +} + + int32_t scheduleFetchRows(void *pJob, void **data) { if (NULL == pJob || NULL == data) { - return TSDB_CODE_QRY_INVALID_INPUT; + SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SQueryJob *job = pJob; + SSchJob *job = pJob; int32_t code = 0; + if (!job->attr.needFetch) { + qError("no need to fetch data"); + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + if (job->status == JOB_TASK_STATUS_FAILED) { + job->res = NULL; + SCH_RET(job->errCode); + } + + if (job->status == JOB_TASK_STATUS_SUCCEED) { + job->res = NULL; + return TSDB_CODE_SUCCESS; + } + if (atomic_val_compare_exchange_32(&job->userFetch, 0, 1) != 0) { qError("prior fetching not finished"); - return TSDB_CODE_QRY_APP_ERROR; + SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - if (job->status == JOB_TASK_STATUS_SUCCEED) { + if (job->status == JOB_TASK_STATUS_PARTIAL_SUCCEED) { SCH_ERR_JRET(schFetchFromRemote(job)); } tsem_wait(&job->rspSem); + if (job->status == JOB_TASK_STATUS_FAILED) { + code = job->errCode; + } + + if (job->res && ((SRetrieveTableRsp *)job->res)->completed) { + job->status = JOB_TASK_STATUS_SUCCEED; + } + *data = job->res; job->res = NULL; _return: atomic_val_compare_exchange_32(&job->userFetch, 1, 0); - return code; + SCH_RET(code); } int32_t scheduleCancelJob(void *pJob) { //TODO + //TODO MOVE ALL TASKS FROM EXEC LIST TO FAIL LIST + return TSDB_CODE_SUCCESS; } @@ -667,10 +986,10 @@ void scheduleFreeJob(void *pJob) { return; } - SQueryJob *job = pJob; + SSchJob *job = pJob; if (job->status > 0) { - if (0 != taosHashRemove(schMgmt.Jobs, &job->queryId, sizeof(job->queryId))) { + if (0 != taosHashRemove(schMgmt.jobs, &job->queryId, sizeof(job->queryId))) { qError("remove job:%"PRIx64"from mgmt failed", job->queryId); // maybe already freed return; } @@ -678,15 +997,17 @@ void scheduleFreeJob(void *pJob) { if (job->status == JOB_TASK_STATUS_EXECUTING) { scheduleCancelJob(pJob); } + + schDropJobAllTasks(job); } //TODO free job } void schedulerDestroy(void) { - if (schMgmt.Jobs) { - taosHashCleanup(schMgmt.Jobs); //TODO - schMgmt.Jobs = NULL; + if (schMgmt.jobs) { + taosHashCleanup(schMgmt.jobs); //TODO + schMgmt.jobs = NULL; } } diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index 9e94553058e923086808cdb462d27ffa95e9a96e..6163bc0c1a4d22bc1b612a4218f8a485ff9cd802 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -26,72 +26,310 @@ #include "taos.h" #include "tdef.h" #include "tvariant.h" -#include "catalog.h" -#include "scheduler.h" +#include "catalog.h" +#include "scheduler.h" #include "tep.h" #include "trpc.h" - +#include "schedulerInt.h" +#include "stub.h" +#include "addr_any.h" + namespace { -void mockBuildDag(SQueryDag *dag) { - uint64_t qId = 0x111111111111; - - dag->queryId = qId; - dag->numOfSubplans = 2; - dag->pSubplans = taosArrayInit(dag->numOfSubplans, POINTER_BYTES); - SArray *scan = taosArrayInit(1, sizeof(SSubplan)); - SArray *merge = taosArrayInit(1, sizeof(SSubplan)); - - SSubplan scanPlan = {0}; - SSubplan mergePlan = {0}; - - scanPlan.id.queryId = qId; - scanPlan.id.templateId = 0x2222222222; - scanPlan.id.subplanId = 0x3333333333; - scanPlan.type = QUERY_TYPE_SCAN; - scanPlan.level = 1; - scanPlan.execEpSet.numOfEps = 1; - scanPlan.pChildern = NULL; - scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); - - mergePlan.id.queryId = qId; - mergePlan.id.templateId = 0x4444444444; - mergePlan.id.subplanId = 0x5555555555; - mergePlan.type = QUERY_TYPE_MERGE; - mergePlan.level = 0; - mergePlan.execEpSet.numOfEps = 1; - mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); - mergePlan.pParents = NULL; - - SSubplan *mergePointer = (SSubplan *)taosArrayPush(merge, &mergePlan); - SSubplan *scanPointer = (SSubplan *)taosArrayPush(scan, &scanPlan); - - taosArrayPush(mergePointer->pChildern, &scanPointer); - taosArrayPush(scanPointer->pParents, &mergePointer); - - taosArrayPush(dag->pSubplans, &merge); - taosArrayPush(dag->pSubplans, &scan); -} - + +extern "C" int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode); + +void schtBuildQueryDag(SQueryDag *dag) { + uint64_t qId = 0x0000000000000001; + + dag->queryId = qId; + dag->numOfSubplans = 2; + dag->pSubplans = taosArrayInit(dag->numOfSubplans, POINTER_BYTES); + SArray *scan = taosArrayInit(1, sizeof(SSubplan)); + SArray *merge = taosArrayInit(1, sizeof(SSubplan)); + + SSubplan scanPlan = {0}; + SSubplan mergePlan = {0}; + + scanPlan.id.queryId = qId; + scanPlan.id.templateId = 0x0000000000000002; + scanPlan.id.subplanId = 0x0000000000000003; + scanPlan.type = QUERY_TYPE_SCAN; + scanPlan.level = 1; + scanPlan.execEpSet.numOfEps = 1; + scanPlan.execEpSet.port[0] = 6030; + strcpy(scanPlan.execEpSet.fqdn[0], "ep0"); + scanPlan.pChildern = NULL; + scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); + scanPlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); + + mergePlan.id.queryId = qId; + mergePlan.id.templateId = 0x4444444444; + mergePlan.id.subplanId = 0x5555555555; + mergePlan.type = QUERY_TYPE_MERGE; + mergePlan.level = 0; + mergePlan.execEpSet.numOfEps = 0; + mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); + mergePlan.pParents = NULL; + mergePlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); + + SSubplan *mergePointer = (SSubplan *)taosArrayPush(merge, &mergePlan); + SSubplan *scanPointer = (SSubplan *)taosArrayPush(scan, &scanPlan); + + taosArrayPush(mergePointer->pChildern, &scanPointer); + taosArrayPush(scanPointer->pParents, &mergePointer); + + taosArrayPush(dag->pSubplans, &merge); + taosArrayPush(dag->pSubplans, &scan); +} + +void schtBuildInsertDag(SQueryDag *dag) { + uint64_t qId = 0x0000000000000002; + + dag->queryId = qId; + dag->numOfSubplans = 2; + dag->pSubplans = taosArrayInit(1, POINTER_BYTES); + SArray *inserta = taosArrayInit(dag->numOfSubplans, sizeof(SSubplan)); + + SSubplan insertPlan[2] = {0}; + + insertPlan[0].id.queryId = qId; + insertPlan[0].id.templateId = 0x0000000000000003; + insertPlan[0].id.subplanId = 0x0000000000000004; + insertPlan[0].type = QUERY_TYPE_MODIFY; + insertPlan[0].level = 0; + insertPlan[0].execEpSet.numOfEps = 1; + insertPlan[0].execEpSet.port[0] = 6030; + strcpy(insertPlan[0].execEpSet.fqdn[0], "ep0"); + insertPlan[0].pChildern = NULL; + insertPlan[0].pParents = NULL; + insertPlan[0].pNode = NULL; + insertPlan[0].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); + + insertPlan[1].id.queryId = qId; + insertPlan[1].id.templateId = 0x0000000000000003; + insertPlan[1].id.subplanId = 0x0000000000000005; + insertPlan[1].type = QUERY_TYPE_MODIFY; + insertPlan[1].level = 0; + insertPlan[1].execEpSet.numOfEps = 1; + insertPlan[1].execEpSet.port[0] = 6030; + strcpy(insertPlan[1].execEpSet.fqdn[0], "ep1"); + insertPlan[1].pChildern = NULL; + insertPlan[1].pParents = NULL; + insertPlan[1].pNode = NULL; + insertPlan[1].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); + + + taosArrayPush(inserta, &insertPlan[0]); + taosArrayPush(inserta, &insertPlan[1]); + + taosArrayPush(dag->pSubplans, &inserta); +} + + +int32_t schtPlanToString(const SSubplan *subplan, char** str, int32_t* len) { + *str = (char *)calloc(1, 20); + *len = 20; + return 0; +} + +int32_t schtExecNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { + return 0; +} + + +void schtSetPlanToString() { + static Stub stub; + stub.set(qSubPlanToString, schtPlanToString); + { + AddrAny any("libplanner.so"); + std::map result; + any.get_global_func_addr_dynsym("^qSubPlanToString$", result); + for (const auto& f : result) { + stub.set(f.second, schtPlanToString); + } + } +} + +void schtSetExecNode() { + static Stub stub; + stub.set(qSetSubplanExecutionNode, schtExecNode); + { + AddrAny any("libplanner.so"); + std::map result; + any.get_global_func_addr_dynsym("^qSetSubplanExecutionNode$", result); + for (const auto& f : result) { + stub.set(f.second, schtExecNode); + } + } } -TEST(testCase, normalCase) { - void *mockPointer = (void *)0x1; +void *schtSendRsp(void *param) { + SSchJob *job = NULL; + int32_t code = 0; + + while (true) { + job = *(SSchJob **)param; + if (job) { + break; + } + + usleep(1000); + } + + void *pIter = taosHashIterate(job->execTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + SShellSubmitRspMsg rsp = {0}; + rsp.affectedRows = 10; + schProcessRspMsg(job, task, TDMT_VND_SUBMIT, (char *)&rsp, sizeof(rsp), 0); + + pIter = taosHashIterate(job->execTasks, pIter); + } + + return NULL; +} + +void *pInsertJob = NULL; + + +} + +TEST(queryTest, normalCase) { + void *mockPointer = (void *)0x1; char *clusterId = "cluster1"; char *dbname = "1.db1"; char *tablename = "table1"; - SVgroupInfo vgInfo = {0}; - void *pJob = NULL; - SQueryDag dag = {0}; - SArray *qnodeList = taosArrayInit(1, sizeof(SEpAddr)); - - int32_t code = schedulerInit(NULL); + SVgroupInfo vgInfo = {0}; + void *pJob = NULL; + SQueryDag dag = {0}; + SArray *qnodeList = taosArrayInit(1, sizeof(SEpAddr)); + + SEpAddr qnodeAddr = {0}; + strcpy(qnodeAddr.fqdn, "qnode0.ep"); + qnodeAddr.port = 6031; + taosArrayPush(qnodeList, &qnodeAddr); + + int32_t code = schedulerInit(NULL); ASSERT_EQ(code, 0); - - mockBuildDag(&dag); - - code = scheduleExecJob(mockPointer, qnodeList, &dag, &pJob); + + schtBuildQueryDag(&dag); + + schtSetPlanToString(); + schtSetExecNode(); + + code = scheduleAsyncExecJob(mockPointer, qnodeList, &dag, &pJob); ASSERT_EQ(code, 0); -} + + SSchJob *job = (SSchJob *)pJob; + void *pIter = taosHashIterate(job->execTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + SQueryTableRsp rsp = {0}; + code = schProcessRspMsg(job, task, TDMT_VND_QUERY, (char *)&rsp, sizeof(rsp), 0); + + ASSERT_EQ(code, 0); + pIter = taosHashIterate(job->execTasks, pIter); + } + + pIter = taosHashIterate(job->execTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + SResReadyRsp rsp = {0}; + code = schProcessRspMsg(job, task, TDMT_VND_RES_READY, (char *)&rsp, sizeof(rsp), 0); + + ASSERT_EQ(code, 0); + pIter = taosHashIterate(job->execTasks, pIter); + } + + pIter = taosHashIterate(job->execTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + SQueryTableRsp rsp = {0}; + code = schProcessRspMsg(job, task, TDMT_VND_QUERY, (char *)&rsp, sizeof(rsp), 0); + + ASSERT_EQ(code, 0); + pIter = taosHashIterate(job->execTasks, pIter); + } + + pIter = taosHashIterate(job->execTasks, NULL); + while (pIter) { + SSchTask *task = *(SSchTask **)pIter; + + SResReadyRsp rsp = {0}; + code = schProcessRspMsg(job, task, TDMT_VND_RES_READY, (char *)&rsp, sizeof(rsp), 0); + ASSERT_EQ(code, 0); + + pIter = taosHashIterate(job->execTasks, pIter); + } + + SRetrieveTableRsp rsp = {0}; + rsp.completed = 1; + rsp.numOfRows = 10; + code = schProcessRspMsg(job, NULL, TDMT_VND_FETCH, (char *)&rsp, sizeof(rsp), 0); + + ASSERT_EQ(code, 0); + + + void *data = NULL; + + code = scheduleFetchRows(job, &data); + ASSERT_EQ(code, 0); + + SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data; + ASSERT_EQ(pRsp->completed, 1); + ASSERT_EQ(pRsp->numOfRows, 10); + + data = NULL; + code = scheduleFetchRows(job, &data); + ASSERT_EQ(code, 0); + ASSERT_EQ(data, (void*)NULL); + + scheduleFreeJob(pJob); +} + + + + +TEST(insertTest, normalCase) { + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; + SVgroupInfo vgInfo = {0}; + SQueryDag dag = {0}; + uint64_t numOfRows = 0; + SArray *qnodeList = taosArrayInit(1, sizeof(SEpAddr)); + + SEpAddr qnodeAddr = {0}; + strcpy(qnodeAddr.fqdn, "qnode0.ep"); + qnodeAddr.port = 6031; + taosArrayPush(qnodeList, &qnodeAddr); + + int32_t code = schedulerInit(NULL); + ASSERT_EQ(code, 0); + + schtBuildInsertDag(&dag); + + schtSetPlanToString(); + + pthread_attr_t thattr; + pthread_attr_init(&thattr); + + pthread_t thread1; + pthread_create(&(thread1), &thattr, schtSendRsp, &pInsertJob); + + code = scheduleExecJob(mockPointer, qnodeList, &dag, &pInsertJob, &numOfRows); + ASSERT_EQ(code, 0); + ASSERT_EQ(numOfRows, 20); + + scheduleFreeJob(pInsertJob); +} + + int main(int argc, char** argv) { @@ -101,4 +339,4 @@ int main(int argc, char** argv) { - + diff --git a/source/libs/transport/inc/rpcHead.h b/source/libs/transport/inc/rpcHead.h index 5b401ac54be194a38bad2f7680155f5edb8350b4..6e98bbd563a7653007d8b664d75ac24cc275cd76 100644 --- a/source/libs/transport/inc/rpcHead.h +++ b/source/libs/transport/inc/rpcHead.h @@ -52,7 +52,7 @@ typedef struct { char user[TSDB_UNI_LEN]; // user ID uint16_t port; // for UDP only, port may be changed char empty[1]; // reserved - uint8_t msgType; // message type + uint16_t msgType; // message type int32_t msgLen; // message length including the header iteslf uint32_t msgVer; int32_t code; // code in response message diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 2f710f3efdd0d106dc092e546c5c10f7fc504bbc..19fe803035ee654a9841b0ba0bb442f614736304 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -23,7 +23,7 @@ #include "tref.h" #include "taoserror.h" #include "tglobal.h" -#include "taosmsg.h" +#include "tmsg.h" #include "trpc.h" #include "thash.h" #include "rpcLog.h" @@ -74,7 +74,7 @@ typedef struct { SEpSet epSet; // ip list provided by app void *ahandle; // handle provided by app struct SRpcConn *pConn; // pConn allocated - char msgType; // message type + tmsg_t msgType; // message type uint8_t *pCont; // content provided by app int32_t contLen; // content length int32_t code; // error code @@ -108,8 +108,8 @@ typedef struct SRpcConn { uint16_t tranId; // outgoing transcation ID, for build message uint16_t outTranId; // outgoing transcation ID uint16_t inTranId; // transcation ID for incoming msg - uint8_t outType; // message type for outgoing request - uint8_t inType; // message type for incoming request + tmsg_t outType; // message type for outgoing request + tmsg_t inType; // message type for incoming request void *chandle; // handle passed by TCP/UDP connection layer void *ahandle; // handle provided by upper app layter int retry; // number of retry for sending request @@ -409,11 +409,11 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t // connection type is application specific. // for TDengine, all the query, show commands shall have TCP connection - char type = pMsg->msgType; - if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_SHOW_RETRIEVE - || type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_VGROUP_LIST - || type == TSDB_MSG_TYPE_TABLES_META || type == TSDB_MSG_TYPE_TABLE_META - || type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_STATUS || type == TSDB_MSG_TYPE_ALTER_TABLE) + tmsg_t type = pMsg->msgType; + if (type == TDMT_VND_QUERY || type == TDMT_MND_SHOW_RETRIEVE + || type == TDMT_VND_FETCH || type == TDMT_MND_VGROUP_LIST + || type == TDMT_VND_TABLES_META || type == TDMT_VND_TABLE_META + || type == TDMT_MND_SHOW || type == TDMT_MND_STATUS || type == TDMT_VND_ALTER_TABLE) pContext->connType = RPC_CONN_TCPC; pContext->rid = taosAddRef(tsRpcRefId, pContext); @@ -605,7 +605,7 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle; pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort); if (pConn->chandle == NULL) { - tError("failed to connect to:0x%x:%d", pConn->peerIp, pConn->peerPort); + tError("failed to connect to:%s:%d", taosIpStr(pConn->peerIp), pConn->peerPort); terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcCloseConn(pConn); @@ -837,16 +837,16 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->inTranId == pHead->tranId) { if (pConn->inType == pHead->msgType) { if (pHead->code == 0) { - tDebug("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]); + tDebug("%s, %s is retransmitted", pConn->info, TMSG_INFO(pHead->msgType)); rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); } else { // do nothing, it is heart beat from client } } else if (pConn->inType == 0) { - tDebug("%s, %s is already processed, tranId:%d", pConn->info, taosMsg[pHead->msgType], pConn->inTranId); + tDebug("%s, %s is already processed, tranId:%d", pConn->info, TMSG_INFO(pHead->msgType), pConn->inTranId); rpcSendMsgToPeer(pConn, pConn->pRspMsg, pConn->rspMsgLen); // resend the response } else { - tDebug("%s, mismatched message %s and tranId", pConn->info, taosMsg[pHead->msgType]); + tDebug("%s, mismatched message %s and tranId", pConn->info, TMSG_INFO(pHead->msgType)); } // do not reply any message @@ -957,19 +957,19 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv, SRpcReqCont sid = htonl(pHead->destId); *ppContext = NULL; - if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) { + if (TMSG_INDEX(pHead->msgType) >= TDMT_MAX || TMSG_INDEX(pHead->msgType) <= 0) { tDebug("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL; } if (sid < 0 || sid >= pRpc->sessions) { tDebug("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid, - pRpc->sessions, taosMsg[pHead->msgType]); + pRpc->sessions, TMSG_INFO(pHead->msgType)); terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL; } if (rpcIsReq(pHead->msgType) && htonl(pHead->msgVer) != tsVersion >> 8) { - tDebug("%s sid:%d, invalid client version:%x/%x %s", pRpc->label, sid, htonl(pHead->msgVer), tsVersion, taosMsg[pHead->msgType]); + tDebug("%s sid:%d, invalid client version:%x/%x %s", pRpc->label, sid, htonl(pHead->msgVer), tsVersion, TMSG_INFO(pHead->msgType)); terrno = TSDB_CODE_RPC_INVALID_VERSION; return NULL; } @@ -1094,9 +1094,9 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { SRpcReqContext *pContext; pConn = rpcProcessMsgHead(pRpc, pRecv, &pContext); - if (pHead->msgType >= 1 && pHead->msgType < TSDB_MSG_TYPE_MAX) { + if (TMSG_INDEX(pHead->msgType) >= 1 && TMSG_INDEX(pHead->msgType) < TDMT_MAX) { tDebug("%s %p %p, %s received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, - pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType], pRecv->ip, pRecv->port, terrno, pRecv->msgLen, + pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), pRecv->ip, pRecv->port, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); } else { tDebug("%s %p %p, %d received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, @@ -1112,11 +1112,11 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE) { rpcCloseConn(pConn); } - if (pHead->msgType + 1 > 1 && pHead->msgType+1 < TSDB_MSG_TYPE_MAX) { - tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType+1], code); + if (TMSG_INDEX(pHead->msgType) + 1 > 1 && TMSG_INDEX(pHead->msgType) + 1 < TDMT_MAX) { + tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType+1), code); } else { - tError("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType], code); - } + tError("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), code); + } } } else { // msg is passed to app only parsing is ok rpcProcessIncomingMsg(pConn, pHead, pContext); @@ -1262,7 +1262,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) { memset(msg, 0, sizeof(SRpcHead)); pReplyHead->version = pRecvHead->version; - pReplyHead->msgType = (char)(pRecvHead->msgType + 1); + pReplyHead->msgType = (tmsg_t)(pRecvHead->msgType + 1); pReplyHead->spi = 0; pReplyHead->encrypt = pRecvHead->encrypt; pReplyHead->tranId = pRecvHead->tranId; @@ -1292,7 +1292,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) { SRpcHead *pHead = rpcHeadFromCont(pContext->pCont); char *msg = (char *)pHead; int msgLen = rpcMsgLenFromCont(pContext->contLen); - char msgType = pContext->msgType; + tmsg_t msgType = pContext->msgType; pContext->numOfTry++; SRpcConn *pConn = rpcSetupConnToServer(pContext); @@ -1343,12 +1343,12 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) { if ( rpcIsReq(pHead->msgType)) { tDebug("%s, %s is sent to %s:%hu, len:%d sig:0x%08x:0x%08x:%d", - pConn->info, taosMsg[pHead->msgType], pConn->peerFqdn, pConn->peerPort, + pConn->info, TMSG_INFO(pHead->msgType), pConn->peerFqdn, pConn->peerPort, msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } else { if (pHead->code == 0) pConn->secured = 1; // for success response, set link as secured tDebug("%s, %s is sent to 0x%x:%hu, code:0x%x len:%d sig:0x%08x:0x%08x:%d", - pConn->info, taosMsg[pHead->msgType], pConn->peerIp, pConn->peerPort, + pConn->info, TMSG_INFO(pHead->msgType), pConn->peerIp, pConn->peerPort, htonl(pHead->code), msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } @@ -1373,7 +1373,7 @@ static void rpcProcessConnError(void *param, void *id) { tDebug("%s %p, connection error happens", pRpc->label, pContext->ahandle); - if (pContext->numOfTry >= pContext->epSet.numOfEps || pContext->msgType == TSDB_MSG_TYPE_FETCH) { + if (pContext->numOfTry >= pContext->epSet.numOfEps || pContext->msgType == TDMT_VND_FETCH) { rpcMsg.msgType = pContext->msgType+1; rpcMsg.ahandle = pContext->ahandle; rpcMsg.code = pContext->code; @@ -1396,17 +1396,17 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) { rpcLockConn(pConn); if (pConn->outType && pConn->user[0]) { - tDebug("%s, expected %s is not received", pConn->info, taosMsg[(int)pConn->outType + 1]); + tDebug("%s, expected %s is not received", pConn->info, TMSG_INFO((int)pConn->outType + 1)); pConn->pTimer = NULL; pConn->retry++; if (pConn->retry < 4) { - tDebug("%s, re-send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort); + tDebug("%s, re-send msg:%s to %s:%hu", pConn->info, TMSG_INFO(pConn->outType), pConn->peerFqdn, pConn->peerPort); rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); } else { // close the connection - tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort); + tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, TMSG_INFO(pConn->outType), pConn->peerFqdn, pConn->peerPort); if (pConn->pContext) { pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; pConn->pContext->pConn = NULL; diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt index d343945a8005ec6f57cbfc9efbcc6c235e7f6d4b..bf1774b45b024b48de8cb98a98d58a6c5d9084c1 100644 --- a/source/util/CMakeLists.txt +++ b/source/util/CMakeLists.txt @@ -12,4 +12,6 @@ target_link_libraries( PUBLIC zlib PUBLIC lz4_static PUBLIC api -) \ No newline at end of file +) + +ADD_SUBDIRECTORY(test) diff --git a/source/util/src/tbuffer.c b/source/util/src/tbuffer.c index 7c1eeaaf4f8e37cf7b5adbbf7e8a342218520868..ddd283ae0f84776203a0906913d32168fcf85775 100644 --- a/source/util/src/tbuffer.c +++ b/source/util/src/tbuffer.c @@ -13,14 +13,14 @@ * along with this program. If not, see . */ -#include "os.h" #include "tbuffer.h" #include "exception.h" +#include "os.h" //#include "taoserror.h" typedef union Un4B { uint32_t ui; - float f; + float f; } Un4B; #if __STDC_VERSION__ >= 201112L static_assert(sizeof(Un4B) == sizeof(uint32_t), "sizeof(Un4B) must equal to sizeof(uint32_t)"); @@ -29,7 +29,7 @@ static_assert(sizeof(Un4B) == sizeof(float), "sizeof(Un4B) must equal to sizeof( typedef union Un8B { uint64_t ull; - double d; + double d; } Un8B; #if __STDC_VERSION__ >= 201112L static_assert(sizeof(Un8B) == sizeof(uint64_t), "sizeof(Un8B) must equal to sizeof(uint64_t)"); @@ -40,172 +40,172 @@ static_assert(sizeof(Un8B) == sizeof(double), "sizeof(Un8B) must equal to sizeof // reader functions size_t tbufSkip(SBufferReader* buf, size_t size) { - if( (buf->pos + size) > buf->size ) { - THROW( -1 ); + if ((buf->pos + size) > buf->size) { + THROW(-1); } size_t old = buf->pos; buf->pos += size; return old; } -const char* tbufRead( SBufferReader* buf, size_t size ) { +const char* tbufRead(SBufferReader* buf, size_t size) { const char* ret = buf->data + buf->pos; - tbufSkip( buf, size ); + tbufSkip(buf, size); return ret; } -void tbufReadToBuffer( SBufferReader* buf, void* dst, size_t size ) { - assert( dst != NULL ); +void tbufReadToBuffer(SBufferReader* buf, void* dst, size_t size) { + assert(dst != NULL); // always using memcpy, leave optimization to compiler - memcpy( dst, tbufRead(buf, size), size ); + memcpy(dst, tbufRead(buf, size), size); } -static size_t tbufReadLength( SBufferReader* buf ) { +static size_t tbufReadLength(SBufferReader* buf) { // maximum length is 65535, if larger length is required // this function and the corresponding write function need to be // revised. - uint16_t l = tbufReadUint16( buf ); + uint16_t l = tbufReadUint16(buf); return l; } -const char* tbufReadString( SBufferReader* buf, size_t* len ) { - size_t l = tbufReadLength( buf ); +const char* tbufReadString(SBufferReader* buf, size_t* len) { + size_t l = tbufReadLength(buf); const char* ret = buf->data + buf->pos; - tbufSkip( buf, l + 1 ); - if( ret[l] != 0 ) { - THROW( -1 ); + tbufSkip(buf, l + 1); + if (ret[l] != 0) { + THROW(-1); } - if( len != NULL ) { + if (len != NULL) { *len = l; } return ret; } -size_t tbufReadToString( SBufferReader* buf, char* dst, size_t size ) { - assert( dst != NULL ); - size_t len; - const char* str = tbufReadString( buf, &len ); +size_t tbufReadToString(SBufferReader* buf, char* dst, size_t size) { + assert(dst != NULL); + size_t len; + const char* str = tbufReadString(buf, &len); if (len >= size) { len = size - 1; } - memcpy( dst, str, len ); + memcpy(dst, str, len); dst[len] = 0; return len; } -const char* tbufReadBinary( SBufferReader* buf, size_t *len ) { - size_t l = tbufReadLength( buf ); +const char* tbufReadBinary(SBufferReader* buf, size_t* len) { + size_t l = tbufReadLength(buf); const char* ret = buf->data + buf->pos; - tbufSkip( buf, l ); - if( len != NULL ) { + tbufSkip(buf, l); + if (len != NULL) { *len = l; } return ret; } -size_t tbufReadToBinary( SBufferReader* buf, void* dst, size_t size ) { - assert( dst != NULL ); - size_t len; - const char* data = tbufReadBinary( buf, &len ); - if( len >= size ) { +size_t tbufReadToBinary(SBufferReader* buf, void* dst, size_t size) { + assert(dst != NULL); + size_t len; + const char* data = tbufReadBinary(buf, &len); + if (len >= size) { len = size; } - memcpy( dst, data, len ); + memcpy(dst, data, len); return len; } -bool tbufReadBool( SBufferReader* buf ) { +bool tbufReadBool(SBufferReader* buf) { bool ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); return ret; } -char tbufReadChar( SBufferReader* buf ) { +char tbufReadChar(SBufferReader* buf) { char ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); return ret; } -int8_t tbufReadInt8( SBufferReader* buf ) { +int8_t tbufReadInt8(SBufferReader* buf) { int8_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); return ret; } -uint8_t tbufReadUint8( SBufferReader* buf ) { +uint8_t tbufReadUint8(SBufferReader* buf) { uint8_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); return ret; } -int16_t tbufReadInt16( SBufferReader* buf ) { +int16_t tbufReadInt16(SBufferReader* buf) { int16_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return (int16_t)ntohs( ret ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return (int16_t)ntohs(ret); } return ret; } -uint16_t tbufReadUint16( SBufferReader* buf ) { +uint16_t tbufReadUint16(SBufferReader* buf) { uint16_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return ntohs( ret ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return ntohs(ret); } return ret; } -int32_t tbufReadInt32( SBufferReader* buf ) { +int32_t tbufReadInt32(SBufferReader* buf) { int32_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return (int32_t)ntohl( ret ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return (int32_t)ntohl(ret); } return ret; } -uint32_t tbufReadUint32( SBufferReader* buf ) { +uint32_t tbufReadUint32(SBufferReader* buf) { uint32_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return ntohl( ret ); + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return ntohl(ret); } return ret; } -int64_t tbufReadInt64( SBufferReader* buf ) { +int64_t tbufReadInt64(SBufferReader* buf) { int64_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return (int64_t)htobe64( ret ); // TODO: ntohll + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return (int64_t)htobe64(ret); // TODO: ntohll } return ret; } -uint64_t tbufReadUint64( SBufferReader* buf ) { +uint64_t tbufReadUint64(SBufferReader* buf) { uint64_t ret; - tbufReadToBuffer( buf, &ret, sizeof(ret) ); - if( buf->endian ) { - return htobe64( ret ); // TODO: ntohll + tbufReadToBuffer(buf, &ret, sizeof(ret)); + if (buf->endian) { + return htobe64(ret); // TODO: ntohll } return ret; } -float tbufReadFloat( SBufferReader* buf ) { +float tbufReadFloat(SBufferReader* buf) { Un4B _un; - tbufReadToBuffer( buf, &_un, sizeof(_un) ); - if( buf->endian ) { - _un.ui = ntohl( _un.ui ); + tbufReadToBuffer(buf, &_un, sizeof(_un)); + if (buf->endian) { + _un.ui = ntohl(_un.ui); } return _un.f; } double tbufReadDouble(SBufferReader* buf) { Un8B _un; - tbufReadToBuffer( buf, &_un, sizeof(_un) ); - if( buf->endian ) { - _un.ull = htobe64( _un.ull ); + tbufReadToBuffer(buf, &_un, sizeof(_un)); + if (buf->endian) { + _un.ull = htobe64(_un.ull); } return _un.d; } @@ -213,38 +213,38 @@ double tbufReadDouble(SBufferReader* buf) { //////////////////////////////////////////////////////////////////////////////// // writer functions -void tbufCloseWriter( SBufferWriter* buf ) { +void tbufCloseWriter(SBufferWriter* buf) { tfree(buf->data); -// (*buf->allocator)( buf->data, 0 ); // potential memory leak. + // (*buf->allocator)( buf->data, 0 ); // potential memory leak. buf->data = NULL; buf->pos = 0; buf->size = 0; } -void tbufEnsureCapacity( SBufferWriter* buf, size_t size ) { +void tbufEnsureCapacity(SBufferWriter* buf, size_t size) { size += buf->pos; - if( size > buf->size ) { + if (size > buf->size) { size_t nsize = size + buf->size; - char* data = (*buf->allocator)( buf->data, nsize ); + char* data = (*buf->allocator)(buf->data, nsize); // TODO: the exception should be thrown by the allocator function - if( data == NULL ) { - THROW( -1 ); + if (data == NULL) { + THROW(-1); } buf->data = data; buf->size = nsize; } } -size_t tbufReserve( SBufferWriter* buf, size_t size ) { - tbufEnsureCapacity( buf, size ); +size_t tbufReserve(SBufferWriter* buf, size_t size) { + tbufEnsureCapacity(buf, size); size_t old = buf->pos; buf->pos += size; return old; } -char* tbufGetData( SBufferWriter* buf, bool takeOver ) { +char* tbufGetData(SBufferWriter* buf, bool takeOver) { char* ret = buf->data; - if( takeOver ) { + if (takeOver) { buf->pos = 0; buf->size = 0; buf->data = NULL; @@ -252,192 +252,174 @@ char* tbufGetData( SBufferWriter* buf, bool takeOver ) { return ret; } -void tbufWrite( SBufferWriter* buf, const void* data, size_t size ) { - assert( data != NULL ); - tbufEnsureCapacity( buf, size ); - memcpy( buf->data + buf->pos, data, size ); +void tbufWrite(SBufferWriter* buf, const void* data, size_t size) { + assert(data != NULL); + tbufEnsureCapacity(buf, size); + memcpy(buf->data + buf->pos, data, size); buf->pos += size; } -void tbufWriteAt( SBufferWriter* buf, size_t pos, const void* data, size_t size ) { - assert( data != NULL ); +void tbufWriteAt(SBufferWriter* buf, size_t pos, const void* data, size_t size) { + assert(data != NULL); // this function can only be called to fill the gap on previous writes, // so 'pos + size <= buf->pos' must be true - assert( pos + size <= buf->pos ); - memcpy( buf->data + pos, data, size ); + assert(pos + size <= buf->pos); + memcpy(buf->data + pos, data, size); } -static void tbufWriteLength( SBufferWriter* buf, size_t len ) { +static void tbufWriteLength(SBufferWriter* buf, size_t len) { // maximum length is 65535, if larger length is required // this function and the corresponding read function need to be // revised. - assert( len <= 0xffff ); - tbufWriteUint16( buf, (uint16_t)len ); + assert(len <= 0xffff); + tbufWriteUint16(buf, (uint16_t)len); } -void tbufWriteStringLen( SBufferWriter* buf, const char* str, size_t len ) { - tbufWriteLength( buf, len ); - tbufWrite( buf, str, len ); - tbufWriteChar( buf, '\0' ); +void tbufWriteStringLen(SBufferWriter* buf, const char* str, size_t len) { + tbufWriteLength(buf, len); + tbufWrite(buf, str, len); + tbufWriteChar(buf, '\0'); } -void tbufWriteString( SBufferWriter* buf, const char* str ) { - tbufWriteStringLen( buf, str, strlen(str) ); -} +void tbufWriteString(SBufferWriter* buf, const char* str) { tbufWriteStringLen(buf, str, strlen(str)); } -void tbufWriteBinary( SBufferWriter* buf, const void* data, size_t len ) { - tbufWriteLength( buf, len ); - tbufWrite( buf, data, len ); +void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len) { + tbufWriteLength(buf, len); + tbufWrite(buf, data, len); } -void tbufWriteBool( SBufferWriter* buf, bool data ) { - tbufWrite( buf, &data, sizeof(data) ); -} +void tbufWriteBool(SBufferWriter* buf, bool data) { tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteBoolAt( SBufferWriter* buf, size_t pos, bool data ) { - tbufWriteAt( buf, pos, &data, sizeof(data) ); -} +void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data) { tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteChar( SBufferWriter* buf, char data ) { - tbufWrite( buf, &data, sizeof(data) ); -} +void tbufWriteChar(SBufferWriter* buf, char data) { tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteCharAt( SBufferWriter* buf, size_t pos, char data ) { - tbufWriteAt( buf, pos, &data, sizeof(data) ); -} +void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data) { tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteInt8( SBufferWriter* buf, int8_t data ) { - tbufWrite( buf, &data, sizeof(data) ); -} +void tbufWriteInt8(SBufferWriter* buf, int8_t data) { tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteInt8At( SBufferWriter* buf, size_t pos, int8_t data ) { - tbufWriteAt( buf, pos, &data, sizeof(data) ); -} +void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteUint8( SBufferWriter* buf, uint8_t data ) { - tbufWrite( buf, &data, sizeof(data) ); -} +void tbufWriteUint8(SBufferWriter* buf, uint8_t data) { tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteUint8At( SBufferWriter* buf, size_t pos, uint8_t data ) { - tbufWriteAt( buf, pos, &data, sizeof(data) ); -} +void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteInt16( SBufferWriter* buf, int16_t data ) { - if( buf->endian ) { - data = (int16_t)htons( data ); +void tbufWriteInt16(SBufferWriter* buf, int16_t data) { + if (buf->endian) { + data = (int16_t)htons(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteInt16At( SBufferWriter* buf, size_t pos, int16_t data ) { - if( buf->endian ) { - data = (int16_t)htons( data ); +void tbufWriteInt16At(SBufferWriter* buf, size_t pos, int16_t data) { + if (buf->endian) { + data = (int16_t)htons(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteUint16( SBufferWriter* buf, uint16_t data ) { - if( buf->endian ) { - data = htons( data ); +void tbufWriteUint16(SBufferWriter* buf, uint16_t data) { + if (buf->endian) { + data = htons(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteUint16At( SBufferWriter* buf, size_t pos, uint16_t data ) { - if( buf->endian ) { - data = htons( data ); +void tbufWriteUint16At(SBufferWriter* buf, size_t pos, uint16_t data) { + if (buf->endian) { + data = htons(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteInt32( SBufferWriter* buf, int32_t data ) { - if( buf->endian ) { - data = (int32_t)htonl( data ); +void tbufWriteInt32(SBufferWriter* buf, int32_t data) { + if (buf->endian) { + data = (int32_t)htonl(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteInt32At( SBufferWriter* buf, size_t pos, int32_t data ) { - if( buf->endian ) { - data = (int32_t)htonl( data ); +void tbufWriteInt32At(SBufferWriter* buf, size_t pos, int32_t data) { + if (buf->endian) { + data = (int32_t)htonl(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteUint32( SBufferWriter* buf, uint32_t data ) { - if( buf->endian ) { - data = htonl( data ); +void tbufWriteUint32(SBufferWriter* buf, uint32_t data) { + if (buf->endian) { + data = htonl(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteUint32At( SBufferWriter* buf, size_t pos, uint32_t data ) { - if( buf->endian ) { - data = htonl( data ); +void tbufWriteUint32At(SBufferWriter* buf, size_t pos, uint32_t data) { + if (buf->endian) { + data = htonl(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteInt64( SBufferWriter* buf, int64_t data ) { - if( buf->endian ) { - data = (int64_t)htobe64( data ); +void tbufWriteInt64(SBufferWriter* buf, int64_t data) { + if (buf->endian) { + data = (int64_t)htobe64(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteInt64At( SBufferWriter* buf, size_t pos, int64_t data ) { - if( buf->endian ) { - data = (int64_t)htobe64( data ); +void tbufWriteInt64At(SBufferWriter* buf, size_t pos, int64_t data) { + if (buf->endian) { + data = (int64_t)htobe64(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteUint64( SBufferWriter* buf, uint64_t data ) { - if( buf->endian ) { - data = htobe64( data ); +void tbufWriteUint64(SBufferWriter* buf, uint64_t data) { + if (buf->endian) { + data = htobe64(data); } - tbufWrite( buf, &data, sizeof(data) ); + tbufWrite(buf, &data, sizeof(data)); } -void tbufWriteUint64At( SBufferWriter* buf, size_t pos, uint64_t data ) { - if( buf->endian ) { - data = htobe64( data ); +void tbufWriteUint64At(SBufferWriter* buf, size_t pos, uint64_t data) { + if (buf->endian) { + data = htobe64(data); } - tbufWriteAt( buf, pos, &data, sizeof(data) ); + tbufWriteAt(buf, pos, &data, sizeof(data)); } -void tbufWriteFloat( SBufferWriter* buf, float data ) { +void tbufWriteFloat(SBufferWriter* buf, float data) { Un4B _un; _un.f = data; - if( buf->endian ) { - _un.ui = htonl( _un.ui ); + if (buf->endian) { + _un.ui = htonl(_un.ui); } - tbufWrite( buf, &_un, sizeof(_un) ); + tbufWrite(buf, &_un, sizeof(_un)); } -void tbufWriteFloatAt( SBufferWriter* buf, size_t pos, float data ) { +void tbufWriteFloatAt(SBufferWriter* buf, size_t pos, float data) { Un4B _un; _un.f = data; - if( buf->endian ) { - _un.ui = htonl( _un.ui ); + if (buf->endian) { + _un.ui = htonl(_un.ui); } - tbufWriteAt( buf, pos, &_un, sizeof(_un) ); + tbufWriteAt(buf, pos, &_un, sizeof(_un)); } -void tbufWriteDouble( SBufferWriter* buf, double data ) { +void tbufWriteDouble(SBufferWriter* buf, double data) { Un8B _un; _un.d = data; - if( buf->endian ) { - _un.ull = htobe64( _un.ull ); + if (buf->endian) { + _un.ull = htobe64(_un.ull); } - tbufWrite( buf, &_un, sizeof(_un) ); + tbufWrite(buf, &_un, sizeof(_un)); } -void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data ) { +void tbufWriteDoubleAt(SBufferWriter* buf, size_t pos, double data) { Un8B _un; _un.d = data; - if( buf->endian ) { - _un.ull = htobe64( _un.ull ); + if (buf->endian) { + _un.ull = htobe64(_un.ull); } - tbufWriteAt( buf, pos, &_un, sizeof(_un) ); + tbufWriteAt(buf, pos, &_un, sizeof(_un)); } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 65057501b9e7c592a81459732be2d0703d7604bf..9fa5b3198bc80f19d6e0038d82754d1df88a03be 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -79,6 +79,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, "Data file corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_CHECKSUM_ERROR, "Checksum error") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid config message") TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed") @@ -181,10 +182,15 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG, "Invalid dnode cfg") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_EP, "Invalid dnode end point") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_ID, "Invalid dnode id") -// mnode-mnode +// mnode-node TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_ALREADY_EXIST, "Mnode already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_NOT_EXIST, "Mnode not there") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "Too many mnodes") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_QNODE_ALREADY_EXIST, "Qnode already exists") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_QNODE_NOT_EXIST, "Qnode not there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_ALREADY_EXIST, "Snode already exists") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_NOT_EXIST, "Snode not there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_ALREADY_EXIST, "Bnode already exists") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_NOT_EXIST, "Bnode not there") // mnode-acct TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, "Account already exists") @@ -256,6 +262,24 @@ TAOS_DEFINE_ERROR(TSDB_CODE_DND_MNODE_ID_INVALID, "Mnode Id invalid") TAOS_DEFINE_ERROR(TSDB_CODE_DND_MNODE_ID_NOT_FOUND, "Mnode Id not found") TAOS_DEFINE_ERROR(TSDB_CODE_DND_MNODE_READ_FILE_ERROR, "Read mnode.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR, "Write mnode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED, "Qnode already deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_NOT_DEPLOYED, "Qnode not deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_ID_INVALID, "Qnode Id invalid") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_ID_NOT_FOUND, "Qnode Id not found") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_READ_FILE_ERROR, "Read qnode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR, "Write qnode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED, "Snode already deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_NOT_DEPLOYED, "Snode not deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_ID_INVALID, "Snode Id invalid") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_ID_NOT_FOUND, "Snode Id not found") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_READ_FILE_ERROR, "Read snode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR, "Write snode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED, "Bnode already deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_NOT_DEPLOYED, "Bnode not deployed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_ID_INVALID, "Bnode Id invalid") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_ID_NOT_FOUND, "Bnode Id not found") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_READ_FILE_ERROR, "Read bnode.json error") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR, "Write bnode.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_VNODE_TOO_MANY_VNODES, "Too many vnode directories") TAOS_DEFINE_ERROR(TSDB_CODE_DND_VNODE_READ_FILE_ERROR, "Read vnodes.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR, "Write vnodes.json error") @@ -360,132 +384,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, "Unexpected generic er TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_SIZE_LIMIT, "WAL size exceeds limit") -// http -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_SERVER_OFFLINE, "http server is not onlin") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_UNSUPPORT_URL, "url is not support") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_URL, "invalid url format") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_ENOUGH_MEMORY, "no enough memory") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_REQUSET_TOO_BIG, "request size is too big") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_AUTH_INFO, "no auth info input") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_MSG_INPUT, "request is empty") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_SQL_INPUT, "no sql input") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_EXEC_USEDB, "no need to execute use db cmd") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_SESSION_FULL, "session list was full") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR, "generate taosd token error") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_MULTI_REQUEST, "size of multi request is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_CREATE_GZIP_FAILED, "failed to create gzip") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_FINISH_GZIP_FAILED, "failed to finish gzip") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_LOGIN_FAILED, "failed to login") - -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_VERSION, "invalid http version") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH, "invalid content length") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_TYPE, "invalid type of Authorization") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_FORMAT, "invalid format of Authorization") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_BASIC_AUTH, "invalid basic Authorization") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_TAOSD_AUTH, "invalid taosd Authorization") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_METHOD_FAILED, "failed to parse method") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_TARGET_FAILED, "failed to parse target") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_VERSION_FAILED, "failed to parse http version") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_SP_FAILED, "failed to parse sp") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_STATUS_FAILED, "failed to parse status") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_PHRASE_FAILED, "failed to parse phrase") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CRLF_FAILED, "failed to parse crlf") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_FAILED, "failed to parse header") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED, "failed to parse header key") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED, "failed to parse header val") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED, "failed to parse chunk size") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_FAILED, "failed to parse chunk") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_END_FAILED, "failed to parse end section") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_INVALID_STATE, "invalid parse state") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_ERROR_STATE, "failed to parse error section") - -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_QUERY_NULL, "query size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_QUERY_SIZE, "query size can not more than 100") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_REQ_PARSE_ERROR, "parse grafana json error") - -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_DB_NOT_INPUT, "database name can not be null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_DB_TOO_LONG, "database name too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_INVALID_JSON, "invalid telegraf json fromat") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRICS_NULL, "metrics size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRICS_SIZE, "metrics size can not more than 1K") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NULL, "metric name not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_TYPE, "metric name type should be string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NAME_NULL, "metric name length is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NAME_LONG, "metric name length too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_NULL, "timestamp not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_TYPE, "timestamp type should be integer") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_VAL_NULL, "timestamp value smaller than 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_NULL, "tags not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_SIZE_0, "tags size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_SIZE_LONG, "tags size too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NULL, "tag is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NAME_NULL, "tag name is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NAME_SIZE, "tag name length too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_VALUE_TYPE, "tag value type should be number or string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_VALUE_NULL, "tag value is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TABLE_NULL, "table is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TABLE_SIZE, "table name length too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_NULL, "fields not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_SIZE_0, "fields size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_SIZE_LONG, "fields size too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NULL, "field is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NAME_NULL, "field name is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NAME_SIZE, "field name length too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_VALUE_TYPE, "field value type should be number or string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_VALUE_NULL, "field value is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_HOST_NOT_STRING, "host type should be string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_STABLE_NOT_EXIST, "stable not exist") - -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_DB_NOT_INPUT, "database name can not be null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_DB_TOO_LONG, "database name too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_INVALID_JSON, "invalid opentsdb json fromat") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRICS_NULL, "metrics size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRICS_SIZE, "metrics size can not more than 10K") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NULL, "metric name not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_TYPE, "metric name type should be string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NAME_NULL, "metric name length is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NAME_LONG, "metric name length can not more than 22") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_NULL, "timestamp not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_TYPE, "timestamp type should be integer") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_VAL_NULL, "timestamp value smaller than 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_NULL, "tags not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_SIZE_0, "tags size is 0") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_SIZE_LONG, "tags size too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NULL, "tag is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NAME_NULL, "tag name is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NAME_SIZE, "tag name length too long") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_TYPE, "tag value type should be boolean, number or string") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_NULL, "tag value is null") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_TOO_LONG, "tag value can not more than 64") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_NULL, "value not find") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_TYPE, "value type should be boolean, number or string") - -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_REQUEST_JSON_ERROR, "http request json error") - -// odbc -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_OOM, "out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_CHAR_NOT_NUM, "convertion not a valid literal input") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_UNDEF, "convertion undefined") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_TRUNC_FRAC, "convertion fractional truncated") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_TRUNC, "convertion truncated") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_NOT_SUPPORT, "convertion not supported") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_OOR, "convertion numeric value out of range") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_OUT_OF_RANGE, "out of range") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_NOT_SUPPORT, "not supported yet") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_INVALID_HANDLE, "invalid handle") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_NO_RESULT, "no result set") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_NO_FIELDS, "no fields returned") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_INVALID_CURSOR, "invalid cursor") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_STATEMENT_NOT_READY, "statement not ready") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONNECTION_BUSY, "connection still busy") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_BAD_CONNSTR, "bad connection string") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_BAD_ARG, "bad argument") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_NOT_VALID_TS, "not a valid timestamp") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_TOO_LARGE, "src too large") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_BAD_SEQ, "src bad sequence") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_INCOMPLETE, "src incomplete") -TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_GENERAL, "src general") - // tfs TAOS_DEFINE_ERROR(TSDB_CODE_FS_OUT_OF_MEMORY, "tfs out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG, "tfs invalid mount config") diff --git a/source/util/src/thash.c b/source/util/src/thash.c index cfe14f00e14d2f00f09ffbf276c81c9eca14bfe6..840a1ef390a529c5aebdce673f3e6d1800e8e8ff 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -362,7 +362,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo return data; } -void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* d) { +void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void* d, bool acquire) { if (taosHashTableEmpty(pHashObj) || keyLen == 0 || key == NULL) { return NULL; } @@ -404,6 +404,10 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* memcpy(d, GET_HASH_NODE_DATA(pNode), pNode->dataLen); } + if (acquire) { + pNode->count++; + } + data = GET_HASH_NODE_DATA(pNode); } @@ -415,6 +419,15 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* return data; } +void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* d) { + return taosHashGetCloneImpl(pHashObj, key, keyLen, d, false); +} + +void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen) { + return taosHashGetCloneImpl(pHashObj, key, keyLen, NULL, true); +} + + int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, void *data, size_t dsize*/) { if (pHashObj == NULL || taosHashTableEmpty(pHashObj)) { return -1; @@ -919,3 +932,9 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { __rd_unlock(&pHashObj->lock, pHashObj->type); } + +void taosHashRelease(SHashObj *pHashObj, void *p) { + taosHashCancelIterate(pHashObj, p); +} + + diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 5bac59f913462efd0118852d6f39fb047b3713e2..95f2fe76e6b0a70dba8fa575147f62952391109a 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -19,7 +19,7 @@ #include "tnote.h" #include "tutil.h" #include "ulog.h" -#include "zlib.h" +//#include "zlib.h" #define MAX_LOGLINE_SIZE (1000) #define MAX_LOGLINE_BUFFER_SIZE (MAX_LOGLINE_SIZE + 10) @@ -85,7 +85,6 @@ int32_t dDebugFlag = 135; int32_t vDebugFlag = 135; int32_t cDebugFlag = 131; int32_t jniDebugFlag = 131; -int32_t odbcDebugFlag = 131; int32_t qDebugFlag = 131; int32_t rpcDebugFlag = 131; int32_t uDebugFlag = 131; @@ -724,7 +723,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { int32_t len = 0; char *data = malloc(compressSize); FILE *srcFp = NULL; - gzFile dstFp = NULL; +// gzFile dstFp = NULL; srcFp = fopen(srcFileName, "r"); if (srcFp == NULL) { @@ -738,25 +737,25 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { goto cmp_end; } - dstFp = gzdopen(fd, "wb6f"); - if (dstFp == NULL) { - ret = -3; - close(fd); - goto cmp_end; - } - - while (!feof(srcFp)) { - len = (int32_t)fread(data, 1, compressSize, srcFp); - (void)gzwrite(dstFp, data, len); - } +// dstFp = gzdopen(fd, "wb6f"); +// if (dstFp == NULL) { +// ret = -3; +// close(fd); +// goto cmp_end; +// } +// +// while (!feof(srcFp)) { +// len = (int32_t)fread(data, 1, compressSize, srcFp); +// (void)gzwrite(dstFp, data, len); +// } cmp_end: if (srcFp) { fclose(srcFp); } - if (dstFp) { - gzclose(dstFp); - } +// if (dstFp) { +// gzclose(dstFp); +// } free(data); return ret; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 11972e84cba613ed6dd757d91c6083eb6c0b520d..fb7b71b845e5f5a5584f651e14b20d67fa3d6eb4 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -38,6 +38,7 @@ int32_t tWorkerInit(SWorkerPool *pool) { void tWorkerCleanup(SWorkerPool *pool) { for (int i = 0; i < pool->max; ++i) { SWorker *worker = pool->workers + i; + if (worker == NULL) continue; if (taosCheckPthreadValid(worker->thread)) { taosQsetThreadResume(pool->qset); } @@ -45,6 +46,7 @@ void tWorkerCleanup(SWorkerPool *pool) { for (int i = 0; i < pool->max; ++i) { SWorker *worker = pool->workers + i; + if (worker == NULL) continue; if (taosCheckPthreadValid(worker->thread)) { pthread_join(worker->thread, NULL); } diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index a60c6cff2809dcc2a55f5cce3e593ef06045a975..79aaa1beb0a48856814f310c1824a695b1ee0082 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -13,17 +13,22 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR)) LIST(REMOVE_ITEM SOURCE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/trefTest.c) ADD_EXECUTABLE(utilTest ${SOURCE_LIST}) - TARGET_LINK_LIBRARIES(utilTest tutil common os gtest pthread gcov) + TARGET_LINK_LIBRARIES(utilTest util common os gtest pthread gcov) + LIST(REMOVE_ITEM SOURCE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/cacheTest.cpp) + LIST(APPEND SOURCE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/hashTest.cpp) + ADD_EXECUTABLE(hashTest ${SOURCE_LIST}) + TARGET_LINK_LIBRARIES(hashTest util common os gtest pthread gcov) + LIST(APPEND BIN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/trefTest.c) ADD_EXECUTABLE(trefTest ${BIN_SRC}) - TARGET_LINK_LIBRARIES(trefTest common tutil) + TARGET_LINK_LIBRARIES(trefTest common util) ENDIF() #IF (TD_LINUX) # ADD_EXECUTABLE(trefTest ./trefTest.c) -# TARGET_LINK_LIBRARIES(trefTest tutil common) +# TARGET_LINK_LIBRARIES(trefTest util common) #ENDIF () INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) diff --git a/source/util/test/hashTest.cpp b/source/util/test/hashTest.cpp index bc3fed74c4eb9dbb5ac1eceb26c497300e6bcf67..ac1bae243468a13e97b219a25cab479ab1d28ac2 100644 --- a/source/util/test/hashTest.cpp +++ b/source/util/test/hashTest.cpp @@ -4,10 +4,15 @@ #include #include -#include "hash.h" +#include "thash.h" #include "taos.h" namespace { + +typedef struct TESTSTRUCT { + char *p; +}TESTSTRUCT; + // the simple test code for basic operations void simpleTest() { SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); @@ -141,6 +146,52 @@ void invalidOperationTest() { } +void acquireRleaseTest() { + SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + ASSERT_EQ(taosHashGetSize(hashTable), 0); + + int32_t key = 2; + int32_t code = 0; + int32_t num = 0; + TESTSTRUCT data = {0}; + const char *str1 = "abcdefg"; + const char *str2 = "aaaaaaa"; + const char *str3 = "123456789"; + + data.p = (char *)malloc(10); + strcpy(data.p, str1); + + code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data)); + ASSERT_EQ(code, 0); + + TESTSTRUCT* pdata = (TESTSTRUCT*)taosHashAcquire(hashTable, &key, sizeof(key)); + ASSERT_TRUE(pdata != nullptr); + ASSERT_TRUE(strcmp(pdata->p, str1) == 0); + + code = taosHashRemove(hashTable, &key, sizeof(key)); + ASSERT_EQ(code, 0); + ASSERT_TRUE(strcmp(pdata->p, str1) == 0); + + num = taosHashGetSize(hashTable); + ASSERT_EQ(num, 1); + + strcpy(pdata->p, str3); + + data.p = (char *)malloc(10); + strcpy(data.p, str2); + code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data)); + ASSERT_EQ(code, 0); + num = taosHashGetSize(hashTable); + ASSERT_EQ(num, 2); + + printf("%s,expect:%s", pdata->p, str3); + ASSERT_TRUE(strcmp(pdata->p, str3) == 0); + + taosHashRelease(hashTable, pdata); + num = taosHashGetSize(hashTable); + ASSERT_EQ(num, 1); +} + } int main(int argc, char** argv) { @@ -153,4 +204,5 @@ TEST(testCase, hashTest) { stringKeyTest(); noLockPerformanceTest(); multithreadsTest(); + acquireRleaseTest(); } diff --git a/source/util/test/skiplistTest.cpp b/source/util/test/skiplistTest.cpp index df4c5af5e2ab62efab287f3dd00650fc29805c98..f2e696b0e5b880190f4e7965a10b9265b99b070a 100644 --- a/source/util/test/skiplistTest.cpp +++ b/source/util/test/skiplistTest.cpp @@ -5,7 +5,7 @@ #include #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tskiplist.h" #include "tutil.h" diff --git a/src/client/inc/tscGlobalmerge.h b/src/client/inc/tscGlobalmerge.h index a462d78ff0d0b57cc05bbe3bde273700e426ba4e..7aa16f843f3d40f8a183a076bc781270d206c35a 100644 --- a/src/client/inc/tscGlobalmerge.h +++ b/src/client/inc/tscGlobalmerge.h @@ -22,7 +22,7 @@ extern "C" { #include "qExtbuffer.h" #include "qFill.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" #include "qExecutor.h" diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 653c7770ef323f8b8608c6a99ccc734ed871ca6e..7dc9c0e28bc9859e439b9bcb368bac85a1b39c49 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -25,7 +25,7 @@ extern "C" { #include "../../../include/client/taos.h" #include "qAggMain.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tcache.h" #include "tglobal.h" diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index dcfb2d6a877f81b394f2a535c587444d39955553..31e60ff2790ff260454a1621e476bd0e5db481b8 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "../../../include/client/taos.h" #include "qTableMeta.h" diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 17742d71e1e31f2f04e6ed10ae1b77cba1561c5d..ab582ec249ea43bdd78f6794a068481d5ecc7493 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -15,7 +15,7 @@ #include "os.h" #include "../../../include/client/taos.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tscLog.h" #include "tscSubquery.h" #include "tscUtil.h" diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index a9f65b84ce6d60f423d2958c9ff3ecbbee631187..e4b1602661f978b8e64c2a1dcee35a920d2ef1ae 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -18,7 +18,7 @@ #include "tsclient.h" #include "tsocket.h" #include "ttimer.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcq.h" #include "../../../include/client/taos.h" diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4fc78d73e450ec605168ea7f3200ecf8eade4142..eb3f8be25abd87e611179262bf4be8e998ef0c0c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -28,7 +28,7 @@ #include "qTableMeta.h" #include "qUtil.h" #include "regex.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "texpr.h" #include "tfilter.h" diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7a754ee698abc77a754b48abba03efd73e410911..42799927e68f0d9d56a4ae7bdfe1e5ea04f29f1c 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -313,7 +313,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { char *pMsg = rpcMallocCont(pCmd->payloadLen); if (NULL == pMsg) { - tscError("0x%"PRIx64" msg:%s malloc failed", pSql->self, taosMsg[pSql->cmd.msgType]); + tscError("0x%"PRIx64" msg:%s malloc failed", pSql->self, TMSG_INFO(pSql->cmd.msgType)); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -489,7 +489,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { * There is not response callback function for submit response. * The actual inserted number of points is the first number. */ - if (rpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT_RSP && pRes->pRsp != NULL) { + if (rpcMsg->msgType == TDMT_VND_SUBMIT_RSP && pRes->pRsp != NULL) { SShellSubmitRspMsg *pMsg = (SShellSubmitRspMsg*)pRes->pRsp; pMsg->code = htonl(pMsg->code); pMsg->numOfRows = htonl(pMsg->numOfRows); @@ -639,7 +639,7 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg); - pSql->cmd.msgType = TSDB_MSG_TYPE_FETCH; + pSql->cmd.msgType = TDMT_VND_FETCH; pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); @@ -651,7 +651,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; // pSql->cmd.payloadLen is set during copying data into payload - pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; + pSql->cmd.msgType = TDMT_VND_SUBMIT; SNewVgroupInfo vgroupInfo = {0}; taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo); @@ -1150,7 +1150,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tscDebug("0x%"PRIx64" msg built success, len:%d bytes", pSql->self, msgLen); pCmd->payloadLen = msgLen; - pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY; + pSql->cmd.msgType = TDMT_VND_QUERY; pQueryMsg->head.contLen = htonl(msgLen); assert(msgLen + minMsgSize() <= (int32_t)pCmd->allocSize); @@ -1166,7 +1166,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCreateDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg *)pCmd->payload; @@ -1182,7 +1182,7 @@ int32_t tscBuildCreateFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; SCreateFuncMsg *pCreateFuncMsg = (SCreateFuncMsg *)pCmd->payload; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_FUNCTION; + pCmd->msgType = TDMT_MND_CREATE_FUNCTION; pCmd->payloadLen = sizeof(SCreateFuncMsg) + htonl(pCreateFuncMsg->codeLen); @@ -1203,7 +1203,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SStrToken* t0 = taosArrayGet(pInfo->pMiscInfo->a, 0); strncpy(pCreate->ep, t0->z, t0->n); - pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; + pCmd->msgType = TDMT_MND_CREATE_DNODE; return TSDB_CODE_SUCCESS; } @@ -1249,7 +1249,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } } - pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT; + pCmd->msgType = TDMT_MND_CREATE_ACCT; return TSDB_CODE_SUCCESS; } @@ -1277,9 +1277,9 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; + pCmd->msgType = TDMT_MND_ALTER_USER; } else { - pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; + pCmd->msgType = TDMT_MND_CREATE_USER; } return TSDB_CODE_SUCCESS; @@ -1288,7 +1288,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCfgDnodeMsg); - pCmd->msgType = TSDB_MSG_TYPE_CONFIG_DNODE; + pCmd->msgType = TDMT_MND_CONFIG_DNODE; return TSDB_CODE_SUCCESS; } @@ -1310,14 +1310,14 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_DROP_DB : TSDB_MSG_TYPE_DROP_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_DROP_DB : TSDB_MSG_TYPE_DROP_TP; return TSDB_CODE_SUCCESS; } int32_t tscBuildDropFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_DROP_FUNCTION; + pCmd->msgType = TDMT_MND_DROP_FUNCTION; pCmd->payloadLen = sizeof(SDropFuncMsg); @@ -1340,7 +1340,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropTableMsg->supertable = (pInfo->pMiscInfo->tableType == TSDB_SUPER_TABLE)? 1:0; pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; + pCmd->msgType = TDMT_MND_DROP_TABLE; return TSDB_CODE_SUCCESS; } @@ -1358,7 +1358,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SDropDnodeMsg * pDrop = (SDropDnodeMsg *)pCmd->payload; tstrncpy(pDrop->ep, dnodeEp, tListLen(pDrop->ep)); - pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; + pCmd->msgType = TDMT_MND_DROP_DNODE; return TSDB_CODE_SUCCESS; } @@ -1370,7 +1370,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tstrncpy(user, pCmd->payload, TSDB_USER_LEN); pCmd->payloadLen = sizeof(SDropUserMsg); - pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TSDB_MSG_TYPE_DROP_USER:TSDB_MSG_TYPE_DROP_ACCT; + pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TDMT_MND_DROP_USER:TDMT_MND_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1395,7 +1395,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SUseDbMsg *pUseDbMsg = (SUseDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pUseDbMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_USE_DB; + pCmd->msgType = TDMT_MND_USE_DB; return TSDB_CODE_SUCCESS; } @@ -1412,14 +1412,14 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { SSyncDbMsg *pSyncMsg = (SSyncDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pSyncMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_SYNC_DB; + pCmd->msgType = TDMT_MND_SYNC_DB; return TSDB_CODE_SUCCESS; } int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW; + pCmd->msgType = TDMT_MND_SHOW; pCmd->payloadLen = sizeof(SShowMsg) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1473,10 +1473,10 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { switch (pCmd->command) { case TSDB_SQL_KILL_QUERY: - pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; + pCmd->msgType = TDMT_MND_KILL_QUERY; break; case TSDB_SQL_KILL_CONNECTION: - pCmd->msgType = TSDB_MSG_TYPE_KILL_CONN; + pCmd->msgType = TDMT_MND_KILL_CONN; break; case TSDB_SQL_KILL_STREAM: pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; @@ -1592,7 +1592,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); pCreateTableMsg->contLen = htonl(msgLen); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; + pCmd->msgType = TDMT_MND_CREATE_TABLE; assert(msgLen + minMsgSize() <= size); return TSDB_CODE_SUCCESS; @@ -1645,7 +1645,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pAlterTableMsg); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; + pCmd->msgType = TDMT_VND_ALTER_TABLE; assert(msgLen + minMsgSize() <= size); @@ -1654,7 +1654,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { SSqlCmd* pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_UPDATE_TAG_VAL; + pCmd->msgType = TDMT_VND_UPDATE_TAG_VAL; SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload; pCmd->payloadLen = htonl(pUpdateMsg->head.contLen); @@ -1674,7 +1674,7 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SAlterDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TDMT_MND_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg* )pCmd->payload; pAlterDbMsg->dbType = -1; @@ -1741,7 +1741,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; + pCmd->msgType = TDMT_MND_SHOW_RETRIEVE; pCmd->payloadLen = sizeof(SRetrieveTableMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1861,7 +1861,7 @@ int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STscObj *pObj = pSql->pTscObj; SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CONNECT; + pCmd->msgType = TDMT_MND_CONNECT; pCmd->payloadLen = sizeof(SConnectMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1898,7 +1898,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildMultiTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + pCmd->msgType = TDMT_VND_TABLES_META; assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize); tscDebug("0x%"PRIx64" build load multi-tablemeta msg completed, numOfTables:%d, msg size:%d", pSql->self, pCmd->count, @@ -1996,7 +1996,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pthread_mutex_unlock(&pObj->mutex); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_HEARTBEAT; + pCmd->msgType = TDMT_MND_HEARTBEAT; return TSDB_CODE_SUCCESS; } @@ -2838,7 +2838,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn } pNew->cmd.payloadLen = (int32_t)(pMsg - (char*)pInfoMsg); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLE_META; + pNew->cmd.msgType = TDMT_VND_TABLE_META; } int32_t code = tscBuildAndSendRequest(pNew, NULL); @@ -2913,7 +2913,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg } pNew->cmd.payloadLen = (int32_t) ((start - pInfo->tableNames) + sizeof(SMultiTableInfoMsg)); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLES_META; + pNew->cmd.msgType = TDMT_VND_TABLES_META; registerSqlObj(pNew); tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, udf:%d, msg size:%d", pSql->self, diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9f2b79e891ed303a891f87e40fc29802714a4f5a..c8a305e804d5fcd8db1e0f7af919022d012ac63e 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tscLog.h" #include "tscUtil.h" #include "tsched.h" diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index badc97ba35937dd0ec10cbd3c11732b8d735b348..897a629d57ef3666045e45a7cbb450dc91250e42 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tconfig.h" #include "tglobal.h" #include "tnote.h" diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 986ce41a9cd0a743e2e0d63987ced1f038a27f03..b7d88f94ca3146bbb7746145cbaca5e8cf6cee46 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -16,7 +16,7 @@ #include "tscUtil.h" #include "hash.h" #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "texpr.h" #include "tkey.h" #include "tmd5.h" @@ -5011,7 +5011,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt SSqlCmd *pCmd = &pSql->cmd; pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; + pCmd->msgType = TDMT_VND_TABLES_META; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)pNameList; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index d2558e4650a45b1e831deaca144bf99e7a9af40d..d610ed605fb7d10c3f678fa474f311a2896a4785 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -22,7 +22,7 @@ #include "../../../include/client/taos.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcq.h" #include "tdataformat.h" #include "tglobal.h" @@ -520,7 +520,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { pMsg->length = pMsg->header.contLen; pMsg->numOfBlocks = htonl(1); - pHead->msgType = TSDB_MSG_TYPE_SUBMIT; + pHead->msgType = TDMT_VND_SUBMIT; pHead->version = 0; // write into vnode write queue diff --git a/src/cq/test/cqtest.c b/src/cq/test/cqtest.c index b1153397bac9cf9b2bb1f209b2765e2fe25f8244..ee52152ad86e75e7e453e0c4ac70983f62e84fc2 100644 --- a/src/cq/test/cqtest.c +++ b/src/cq/test/cqtest.c @@ -16,7 +16,7 @@ //#define _DEFAULT_SOURCE #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tlog.h" #include "tcq.h" diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 089e30ac3728761c68fe155f960c8650a32c2f7a..65c8a45d009c2dfb7cfe592a226a405f3e709e26 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -20,7 +20,7 @@ #include #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tdataformat.h" #include "tname.h" diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 3d59dfff4e06358481d60b04de3373fe91396006..8e0192000472decc29229bfe26730d53865a6709 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -20,7 +20,7 @@ #include "../../../include/client/taos.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "tsclient.h" #include "tsdb.h" diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index d4a9ed0cbcef0a52085dcd60569270037fb57908..1238348237332f70064a4b771ee32adc62fef334 100644 --- a/src/query/inc/qExtbuffer.h +++ b/src/query/inc/qExtbuffer.h @@ -20,7 +20,7 @@ extern "C" { #endif #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tarray.h" #include "tutil.h" diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 0c60319f399dd8ebce533993165b5d9008ddcc99..ecb5c664aaf81d0839539cba241fbd152557a638 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -21,7 +21,7 @@ extern "C" { #endif #include "../../../include/client/taos.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tstrbuild.h" #include "ttoken.h" #include "tvariant.h" diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 50806fdfd6e9198b318e3a8a4aa3fcd928b527c1..d37aaf5a6d579166978baeb2b4bb7413dcd64edb 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -438,6 +438,12 @@ column(A) ::= ids(X) typename(Y). { tSetColumnInfo(&A, &X, &Y); } +%type tagitemlist1 {SArray*} +%destructor tagitemlist1 {taosArrayDestroy($$);} + +%type tagitem1 {SToken} + + %type tagitemlist {SArray*} %destructor tagitemlist {taosArrayDestroy($$);} diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 037b60343ed3872ca2e4df5ce320ad6227f318d9..d57532ac8f65ab27258a55d70542d310c51376b6 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -15,7 +15,7 @@ #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "texpr.h" #include "ttype.h" #include "tsdb.h" diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 85f961b82967c4ce2623f6dcaf8be928566394e1..be1bfb81437c345361941b890991c33779f907de 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -14,7 +14,7 @@ */ #include "os.h" #include "qFill.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tglobal.h" #include "exception.h" diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index 35cd7eeac272762ea53ebb7468ba7c38407332b3..35e95a684568221597f66c37e94dd415328167da 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -19,7 +19,7 @@ #include "qExecutor.h" #include "queryLog.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "tulog.h" diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index cdcc164152dddbc34d03508a2bdd7379d6e50892..47ea63eeb0bd735ecba7811d767f121e4dd05415 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -17,7 +17,7 @@ #include "qAggMain.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "ttype.h" #include "qFill.h" diff --git a/src/query/src/qFilterfunc.c b/src/query/src/qFilterfunc.c index 1c1ec21d653b5b96fe792aa05641191a441b8e8d..6ad7a6ef63edc7cd420c3a7829397b26c294b858 100644 --- a/src/query/src/qFilterfunc.c +++ b/src/query/src/qFilterfunc.c @@ -17,7 +17,7 @@ #include "os.h" #include "qExecutor.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcompare.h" #include "ttype.h" diff --git a/src/query/src/qHistogram.c b/src/query/src/qHistogram.c index 5fa35d0ee586e72401bca1d984006c39e2e84e98..b406c0f70370117701466dd58504d7344f45a8b1 100644 --- a/src/query/src/qHistogram.c +++ b/src/query/src/qHistogram.c @@ -16,7 +16,7 @@ #include "qHistogram.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tlosertree.h" /** diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index cca7bc6148b8dc9c2cfbff985b47fc3b8076aeea..b4ad30b291957b00d6337d7b16c592d5af1cb0ff 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -16,7 +16,7 @@ #include "qSqlparser.h" #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tmsgtype.h" #include "tstrbuild.h" #include "ttoken.h" diff --git a/src/query/src/qTableMeta.c b/src/query/src/qTableMeta.c index f687b8aa1ffc530d0c4a71c553809dd3bfb83932..4e8954ed6fca766b606cb6345949918f6d2d14af 100644 --- a/src/query/src/qTableMeta.c +++ b/src/query/src/qTableMeta.c @@ -1,6 +1,6 @@ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "qTableMeta.h" #include "ttokendef.h" #include "taosdef.h" diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 1460fbdc0fd0324da28bf1161c34c564584258cd..3bf031ebd5b5afee8c6255be6dcd8e0b8193c653 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tcache.h" #include "tglobal.h" diff --git a/src/query/tests/astTest.cpp b/src/query/tests/astTest.cpp index 75a703ac1fbf89f2a60e0bdbec2f8be397a451db..b7df7499831817c676c59a1547e5af59c3d42504 100644 --- a/src/query/tests/astTest.cpp +++ b/src/query/tests/astTest.cpp @@ -4,7 +4,7 @@ #include #include "texpr.h" -#include "taosmsg.h" +#include "tmsg.h" #include "tsdb.h" #include "tskiplist.h" diff --git a/tests/script/general/db/basic1.sim b/tests/script/general/db/basic1.sim index 9ec1aabe98ba21af5927faec2e26aef1c3a14aeb..44d53917f20af93e7fec51f5044591ebbefde5c5 100644 --- a/tests/script/general/db/basic1.sim +++ b/tests/script/general/db/basic1.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 sql connect print =============== create database @@ -15,7 +14,7 @@ if $data00 != d1 then return -1 endi -if $data02 != 0 then +if $data02 != 2 then return -1 endi @@ -51,7 +50,7 @@ if $data00 != d4 then return -1 endi -if $data02 != 0 then +if $data02 != 2 then return -1 endi @@ -59,4 +58,31 @@ if $data03 != 0 then return -1 endi +print =============== show vgroups +sql show databases + +if $rows != 1 then + return -1 +endi + +sql_error use d1 + +sql use d4 +sql show vgroups + +if $rows != 2 then + return -1 +endi + +print =============== show dnodes +sql show dnodes + +if $data00 != 1 then + return -1 +endi + +if $data02 != 2 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/autocreate.sim b/tests/script/general/http/autocreate.sim deleted file mode 100644 index 39af990b50d18fbcb6e7972d2adb67a1eb9900e3..0000000000000000000000000000000000000000 --- a/tests/script/general/http/autocreate.sim +++ /dev/null @@ -1,33 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database db -sql use db -sql create table if not exists db.win_cpu(ts timestamp,f_percent_dpc_time double,f_percent_idle_time double,f_percent_interrupt_time double,f_percent_privileged_time double,f_percent_processor_time double,f_percent_user_time double) tags(t_host binary(32),t_instance binary(32),t_objectname binary(32)); - -print =============== step2 - auto create - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'import into db.win_cpu_windows_1_processor using db.win_cpu tags('windows','1','Processor') values(1564641722000,0.000000,95.598305,0.000000,0.000000,0.000000,0.000000);' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content -#if $system_content != @{"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10],["2017-12-25 21:28:51.022",11]],"rows":11}@ then -# return -1 -#endi - -sql select * from db.win_cpu_windows_1_processor -print rows: $rows -if $rows != 1 then - return -1 -endi - -#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/bug.go b/tests/script/general/http/bug.go deleted file mode 100644 index 9455a48c564dafc4084008bd51ba04614f82c6f9..0000000000000000000000000000000000000000 --- a/tests/script/general/http/bug.go +++ /dev/null @@ -1,344 +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 . - */ - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "os" - "sync" - "sync/atomic" - "time" - "flag" -) - -var ( - token string - url string - config Config - request int64 - period int64 - errorNum int64 -) - -type Config struct { - HostIp string `json:"hostIp"` - ConnNum int `json:"connNum"` - InsertModel string `json:"insertModel"` - WaitTime int `json:"waitTime"` - TableDesc string `json:"tableDesc"` - TablePrefix string `json:"tablePrefix"` - TablePerConn int `json:"tablePerConn"` - TableCreate bool `json:"tableCreate"` - TableStart int `json:"tableStart"` - DbName string `json:"dbName"` - DbReplica int `json:"dbReplica"` - DbKeep int `json:"dbKeep"` - DbDays int `json:"dbDays"` - MetricsName string `json:"metricsName"` - TagNum int `json:"tagNum"` - DataNum int `json:"dataNum"` - DataBegin int64 `json:"dataBegin"` - DataInterval int `json:"dataInterval"` - DataBatch int `json:"dataBatch"` - DataInsert bool `json:"dataInsert"` - DataRandom bool `json:"dataRandom"` -} - -type TokenResult struct { - Status string `json:"status"` - Code int `json:"code"` - Desc string `json:"desc"` -} - -type JsonResult struct { - Status string `json:"status"` - Code int `json:"code"` -} - -func readFile(filename string) { - file, err := os.Open(filename) - if err != nil { - println("taos_cloud.json not found") - panic(err) - } - defer file.Close() - - dec := json.NewDecoder(file) - err = dec.Decode(&config) - if err != nil { - println("taos_cloud.json parse error") - panic(err) - } - - if config.TagNum <= 0 { - config.TagNum = 1 - } - request = 0 - period = 0 - errorNum = 0 - - fmt.Println("================config parameters======================") - fmt.Println("HostIp:", config.HostIp) - fmt.Println("connNum:", config.ConnNum) - fmt.Println("insertModel:", config.InsertModel) - fmt.Println("waitTime:", config.WaitTime) - fmt.Println("tableDesc:", config.TableDesc) - fmt.Println("tablePrefix:", config.TablePrefix) - fmt.Println("tablePerConn:", config.TablePerConn) - fmt.Println("tableCreate:", config.TableCreate) - fmt.Println("tableStart:", config.TableStart) - fmt.Println("dbName:", config.DbName) - fmt.Println("dbReplica:", config.DbReplica) - fmt.Println("dbKeep:", config.DbKeep) - fmt.Println("dbDays:", config.DbDays) - fmt.Println("metricsName:", config.MetricsName) - fmt.Println("tagNum:", config.TagNum) - fmt.Println("dataNum:", config.DataNum) - fmt.Println("dataBegin:", config.DataBegin) - fmt.Println("dataInterval:", config.DataInterval) - fmt.Println("dataBatch:", config.DataBatch) - fmt.Println("dataInsert:", config.DataInsert) - fmt.Println("dataRandom:", config.DataRandom) - - fmt.Println("================http token=============================") - token, err = getToken() - url = fmt.Sprintf("http://%s:%d/rest/sql", config.HostIp, 6020) - - fmt.Println("httpToken:", token) - fmt.Println("httpUrl:", url) - - if err != nil { - panic(err) - } -} - -func getToken() (string, error) { - resp, err := http.Get(fmt.Sprintf("http://%s:%d/rest/login/%s/%s", config.HostIp, 6020, "root", "taosdata")) - if err != nil { - return "", err - } - - defer resp.Body.Close() - - var tokenResult TokenResult - - data, err := ioutil.ReadAll(resp.Body) - - if err != nil { - return "", err - } - - err = json.Unmarshal(data, &tokenResult) - if err != nil { - return "", err - } - - if tokenResult.Status != "succ" { - fmt.Println("get http token failed") - fmt.Println(tokenResult) - return "", err - } - - return tokenResult.Desc, nil -} - -func exec(client *http.Client, sql string) { - for times := 0; times < 10; times++ { - - req, err1 := http.NewRequest("POST", url, bytes.NewReader([]byte(sql))) - if err1 != nil { - continue - } - req.Header.Add("Authorization", "Taosd "+token) - - begin := time.Now() - resp, err := client.Do(req) - - if err != nil { - continue - } - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - resp.Body.Close() - continue - } - - spend := (time.Since(begin).Nanoseconds()) - - var jsonResult JsonResult - err = json.Unmarshal(data, &jsonResult) - if err != nil { - resp.Body.Close() - continue - } - - if jsonResult.Status != "succ" { - resp.Body.Close() - continue - } - atomic.AddInt64(&request, 1) - if (request < 103) { - return - } - - atomic.AddInt64(&period, spend) - if request%5000 == 0 && request != 0 { - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.ConnNum) - dps := qps * float64(config.DataBatch) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) - } - return - } - fmt.Println("xxxx>sql:", sql, ", retryTimes:", 10) - errorNum++ -} - -func insertTable(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - - for j := 0; j < config.DataNum; j++ { - for i := 0; i < config.TablePerConn; i++ { - tmVal := int64(j)*int64(config.DataInterval) + tmStart + 1 - tbIndex := i + tbStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("import into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - exec(client, sql) - time.Sleep(time.Millisecond * time.Duration(10)) - } - } -} - -func insertLoop(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - for j := 0; j < config.DataNum; j++ { - - for i := 0; i < config.TablePerConn; i++ { - tbIndex := i + tbStart - - tmVal := int64(j)*int64(config.DataInterval) + tmStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("insert into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - for k := 1; k < config.DataBatch; k++ { - tmVal := int64(j)*int64(config.DataInterval) + int64(k) + tmStart - - dataVal := j + k - if config.DataRandom { - dataVal = rand.Intn(1000) - } - sql += fmt.Sprintf("values(%d, %d)", tmVal, dataVal) - } - - j += (config.DataBatch - 1) - - exec(client, sql) - - if config.WaitTime != 0 { - time.Sleep(time.Millisecond * time.Duration(config.WaitTime)) - } - } - - } -} - -func insertTb(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - if !config.DataInsert { - return - } - - if config.InsertModel == "insertTable" { - insertTable(conn) - } else { - insertLoop(conn) - } -} - -func selectData(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - client := &http.Client{} - - - tbStart := conn*config.TablePerConn + config.TableStart - for j := 0; j < config.DataNum; j++ { - tbIndex := 0 + tbStart - sql := fmt.Sprintf("select max(i),min(i) from db.mt where tbname in ('%s%d'", config.TablePrefix, tbIndex) - for i := 1; i < 2000; i++ { - tbIndex := i + tbStart - sql += fmt.Sprintf(",'%s%d'", config.TablePrefix, tbIndex) - } - sql += ") group by orgno" - - //sql := fmt.Sprintf("select count(*) from db.mt") - //sql := fmt.Sprintf("select max(i),min(i) from db.mt", config.TablePrefix, tbIndex) - - exec(client, sql) - time.Sleep(time.Millisecond * time.Duration(10)) - } -} - -func main() { - filename := flag.String("config", "taos_cloud.json", "config file name") - - flag.Parse() - - readFile(*filename) - - fmt.Println("\n================http test start======================") - - var wg sync.WaitGroup - - fmt.Println("\n================select data ========================") - - - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go insertTb(&wg, i) - } - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go selectData(&wg, i) - } - wg.Wait() - - fmt.Println("\n================http test stop ======================") -} diff --git a/tests/script/general/http/chunked.sim b/tests/script/general/http/chunked.sim deleted file mode 100644 index c5855e5d2953ca36d95cd84a5590c47ef693d406..0000000000000000000000000000000000000000 --- a/tests/script/general/http/chunked.sim +++ /dev/null @@ -1,37 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c maxSQLLength -v 340032 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database d1 -sql use d1 - -sql create table table_rest (ts timestamp, i int) -print sql length is 270KB -restful d1 table_rest 1591072800 10000 -restful d1 table_rest 1591172800 10000 -restful d1 table_rest 1591272800 10000 -restful d1 table_rest 1591372800 10000 -restful d1 table_rest 1591472800 10000 -restful d1 table_rest 1591572800 10000 -restful d1 table_rest 1591672800 10000 -restful d1 table_rest 1591772800 10000 -restful d1 table_rest 1591872800 10000 -restful d1 table_rest 1591972800 10000 - -sql select * from table_rest; -print rows: $rows -if $rows != 100000 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/grafana.sim b/tests/script/general/http/grafana.sim deleted file mode 100644 index 414b859bd3dcaa78ab7d814afd660c9894857cc3..0000000000000000000000000000000000000000 --- a/tests/script/general/http/grafana.sim +++ /dev/null @@ -1,182 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -#system sh/cfg.sh -n dnode1 -c adminRowLimit -v 10 -system sh/cfg.sh -n dnode1 -c httpDebugFlag -v 135 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data - -sql create database d1 -sql use d1 -sql create table table_gc (ts timestamp, db binary(10), tb binary(20), col binary(20)) -sql create table m1 (ts timestamp, v1 int, v2 float) -sql create table m2 (ts timestamp, v1 int, v2 float) - -sql insert into table_gc values('2017-12-25 21:28:41.022', 'd1', 'm1', 'v1') -sql insert into table_gc values('2017-12-25 21:28:42.022', 'd1', 'm1', 'v2') -sql insert into table_gc values('2017-12-25 21:28:43.022', 'd1', 'm2', 'v1') -sql insert into table_gc values('2017-12-25 21:28:44.022', 'd1', 'm2', 'v2') - -sql insert into m1 values(1514208523020, 1, 4.1) -sql insert into m1 values(1514208523021, 2, 5.1) -sql insert into m1 values(1514208523022, 3, 6.1) - -sql insert into m2 values(1514208523024, 3, 6.1) -sql insert into m2 values(1514208523025, 2, 5.1) -sql insert into m2 values(1514208523026, 1, 4.1) - -sql create table mt (ts timestamp, i int) tags(a int, b binary(10)) -sql create table t1 using mt tags (1, 'a') -sql create table t2 using mt tags (2, 'b') -sql create table t3 using mt tags (3, 'c') -sql insert into t1 values('2017-12-25 21:25:41', 1) -sql insert into t1 values('2017-12-25 21:26:41', 1) -sql insert into t1 values('2017-12-25 21:27:41', 1) -sql insert into t1 values('2017-12-25 21:28:41', 1) -sql insert into t1 values('2017-12-25 21:29:41', 1) -sql insert into t2 values('2017-12-25 21:25:41', 2) -sql insert into t2 values('2017-12-25 21:26:41', 2) -sql insert into t2 values('2017-12-25 21:27:41', 2) -sql insert into t2 values('2017-12-25 21:28:41', 2) -sql insert into t3 values('2017-12-25 21:25:41', 3) -sql insert into t3 values('2017-12-25 21:26:41', 3) -sql insert into t3 values('2017-12-25 21:27:41', 3) - -print =============== step2 - login - -system_content curl 127.0.0.1:7111/grafana/ -print 1-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/grafana/xx -print 2-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/grafana/login/xx/xx/ -print 3-> $system_content -if $system_content != @{"status":"error","code":849,"desc":"Invalid user"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/grafana/root/1/123/1/1/3 -print 4-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/grafana/login/1/root/1/ -print 5-> $system_content -if $system_content != @{"status":"error","code":849,"desc":"Invalid user"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:7111/grafana/root/1/login -print 6-> $system_content -if $system_content != @{"status":"error","code":4387,"desc":"invalid format of Authorization"}@ then - return -1 -endi - -system_content curl -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:7111/grafana/root/1/login -print 7-> $system_content -if $system_content != @{"status":"error","code":4387,"desc":"invalid format of Authorization"}@ then - return -1 -endi - -sleep 2000 -system_content curl 127.0.0.1:7111/grafana/login/root/taosdata -print 8-> $system_content -if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then - return -1 -endi - -print =============== step3 - heartbeat - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' 127.0.0.1:7111/grafana/d1/table_gc -print 9-> $system_content -if $system_content != @{"message":"Grafana server receive a quest from you!"}@ then - return -1 -endi - -print =============== step4 - search - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' 127.0.0.1:7111/grafana/heartbeat -print 10-> $system_content -if $system_content != @{"message":"Grafana server receive a quest from you!"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' 127.0.0.1:7111/grafana/d1/table_invalid/search -print 11-> $system_content -if $system_content != @{"message":"Grafana server receive a quest from you!"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' 127.0.0.1:7111/grafana/d1/m1/search -print 12-> $system_content -if $system_content != @{"message":"Grafana server receive a quest from you!"}@ then - return -1 -endi - -print =============== step5 - query - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"taosd","sql":"select first(v1) from d1.m1 where ts > 1514208523020 and ts < 1514208523030 interval(1m)"},{"refId":"B","alias":"system","sql":"select first(v2) from d1.m1 where ts > 1514208523020 and ts < 1514208523030 interval(1m)"}]' 127.0.0.1:7111/grafana/query -print 13-> $system_content -if $system_content != @[{"refId":"A","target":"taosd","datapoints":[[2,1514208480000]]},{"refId":"B","target":"system","datapoints":[[5.10000,1514208480000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"","sql":"select first(v1) from d1.m1 where ts > 1514208523020 and ts < 1514208523030 interval(1m)"},{"refId":"B","alias":"","sql":"select first(v2) from d1.m1 where ts > 1514208523020 and ts < 1514208523030 interval(1m)"}]' 127.0.0.1:7111/grafana/query -print 14-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[2,1514208480000]]},{"refId":"B","target":"B","datapoints":[[5.10000,1514208480000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"","sql":"select count(v1) from d1.m1"},{"refId":"B","alias":"","sql":"select count(v2) from d1.m1"}]' 127.0.0.1:7111/grafana/query -print 15-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[3,"-"]]},{"refId":"B","target":"B","datapoints":[[3,"-"]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"","sql":"select count(v1) from d1.m1"},{"refId":"B","alias":"","sql":"select count(v2) from d1.m1"}]' 127.0.0.1:7111/grafana/query -print 15-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[3,"-"]]},{"refId":"B","target":"B","datapoints":[[3,"-"]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"","sql":"select count(i) from d1.mt group by a"},{"refId":"B","alias":"","sql":"select sum(i) from d1.mt group by b"}]' 127.0.0.1:7111/grafana/query -print 16-> $system_content -if $system_content != @[{"refId":"A","target":"{a:1,}","datapoints":[[5,"-"]]},{"refId":"A","target":"{a:2,}","datapoints":[[4,"-"]]},{"refId":"A","target":"{a:3,}","datapoints":[[3,"-"]]},{"refId":"B","target":"{b:a}","datapoints":[[5,"-"]]},{"refId":"B","target":"{b:b}","datapoints":[[8,"-"]]},{"refId":"B","target":"{b:c}","datapoints":[[9,"-"]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"count","sql":"select count(i) from d1.mt group by a"},{"refId":"B","alias":"sum-","sql":"select sum(i) from d1.mt group by b"}]' 127.0.0.1:7111/grafana/query -print 17-> $system_content -if $system_content != @[{"refId":"A","target":"count{a:1,}","datapoints":[[5,"-"]]},{"refId":"A","target":"count{a:2,}","datapoints":[[4,"-"]]},{"refId":"A","target":"count{a:3,}","datapoints":[[3,"-"]]},{"refId":"B","target":"sum-{b:a}","datapoints":[[5,"-"]]},{"refId":"B","target":"sum-{b:b}","datapoints":[[8,"-"]]},{"refId":"B","target":"sum-{b:c}","datapoints":[[9,"-"]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"count","sql":"select count(i) from d1.mt interval(1m) group by a "}]' 127.0.0.1:7111/grafana/query -print 18-> $system_content -if $system_content != @[{"refId":"A","target":"count{a:1,}","datapoints":[[1,1514208300000],[1,1514208360000],[1,1514208420000],[1,1514208480000],[1,1514208540000]]},{"refId":"A","target":"count{a:2,}","datapoints":[[1,1514208300000],[1,1514208360000],[1,1514208420000],[1,1514208480000]]},{"refId":"A","target":"count{a:3,}","datapoints":[[1,1514208300000],[1,1514208360000],[1,1514208420000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '[{"refId":"A","alias":"","sql":"select sum(v2), count(v1) from d1.m1"},{"refId":"B","alias":"","sql":"select count(v2), sum(v2) from d1.m1"}]' 127.0.0.1:7111/grafana/query -print 19-> $system_content -if $system_content != @[{"refId":"A","target":"{count(v1):3}","datapoints":[[15.299999714,"-"]]},{"refId":"B","target":"{sum(v2):15.299999714}","datapoints":[[3,"-"]]}]@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/grafana_bug.sim b/tests/script/general/http/grafana_bug.sim deleted file mode 100644 index ed184e17c6deceaa118c512a8ccf5f5b4df3ffbc..0000000000000000000000000000000000000000 --- a/tests/script/general/http/grafana_bug.sim +++ /dev/null @@ -1,271 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -#system sh/cfg.sh -n dnode1 -c adminRowLimit -v 10 -system sh/cfg.sh -n dnode1 -c httpDebugFlag -v 135 -system sh/exec.sh -n dnode1 -s start - -sql connect -sleep 2000 - -print ============================ dnode1 start - -print =============== step0 - prepare data - -sql create database db -sql use db - -sql create table tb (ts timestamp, val int, val1 int, val2 int) -sql create table tb2 (ts timestamp, val int, val1 int, val2 int) -sql create table t2 (ts timestamp, val int) -sql create table tb3 (ts timestamp, val int, val1 int, val2 int) - -sql insert into tb values('2020-01-01 00:00:00.000', 1, 11, 21) -sql insert into tb values('2020-01-02 00:00:00.000', 1, 12, 22) -sql insert into tb values('2020-01-03 00:00:00.000', 2, 13, 23) -sql insert into tb values('2020-01-04 00:00:00.000', 2, 14, 24) - - -sql insert into tb2 values('2020-01-01 00:00:00.000', 21, 211, 221) -sql insert into tb2 values('2020-01-02 00:00:00.000', 21, 212, 222) -sql insert into tb2 values('2020-01-03 00:00:00.000', 22, 213, 223) -sql insert into tb2 values('2020-01-04 00:00:00.000', 22, 214, 224) - - -sql insert into tb3 values('2020-01-01 00:00:00.000', NULL, NULL, NULL) -sql insert into tb3 values('2020-01-02 00:00:00.000', NULL, NULL, NULL) -print =============== step1 - one query, 1 column, with timestamp - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[null,1577980800000],[null,1578067200000]]}]@ then - return -1 -endi - -print =============== step2 - one query, 2 column, with timestamp - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step2-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[2,1577980800000],[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step3 - one query, 3 column, with timestamp - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val,val1 from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step3.1-> $system_content -if $system_content != @[{"refId":"A","target":"{val1:13,}","datapoints":[[2,1577980800000]]},{"refId":"A","target":"{val1:14,}","datapoints":[[2,1578067200000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val,val1 from db.tb "} ]' 127.0.0.1:7111/grafana/query -print step3.2-> $system_content -if $system_content != @[{"refId":"A","target":"{val1:11,}","datapoints":[[1,1577808000000]]},{"refId":"A","target":"{val1:12,}","datapoints":[[1,1577894400000]]},{"refId":"A","target":"{val1:13,}","datapoints":[[2,1577980800000]]},{"refId":"A","target":"{val1:14,}","datapoints":[[2,1578067200000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val1,val from db.tb "} ]' 127.0.0.1:7111/grafana/query -print step3.3-> $system_content -if $system_content != @[{"refId":"A","target":"{val:1,}","datapoints":[[11,1577808000000],[12,1577894400000]]},{"refId":"A","target":"{val:2,}","datapoints":[[13,1577980800000],[14,1578067200000]]}]@ then - return -1 -endi - -print =============== step4 - one query, 4 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val2,val1,val from db.tb "} ]' 127.0.0.1:7111/grafana/query -print step4.1-> $system_content -if $system_content != @[{"refId":"A","target":"{val1:11,, val:1,}","datapoints":[[21,1577808000000]]},{"refId":"A","target":"{val1:12,, val:1,}","datapoints":[[22,1577894400000]]},{"refId":"A","target":"{val1:13,, val:2,}","datapoints":[[23,1577980800000]]},{"refId":"A","target":"{val1:14,, val:2,}","datapoints":[[24,1578067200000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select ts,val,val1,val2 from db.tb "} ]' 127.0.0.1:7111/grafana/query -print step4.2-> $system_content -if $system_content != @[{"refId":"A","target":"{val1:11,, val2:21,}","datapoints":[[1,1577808000000]]},{"refId":"A","target":"{val1:12,, val2:22,}","datapoints":[[1,1577894400000]]},{"refId":"A","target":"{val1:13,, val2:23,}","datapoints":[[2,1577980800000]]},{"refId":"A","target":"{val1:14,, val2:24,}","datapoints":[[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step5 - one query, 1 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"A","datapoints":[[2,"-"],[2,"-"]]}]@ then - return -1 -endi - -print =============== step6 - one query, 2 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select val1,val2 from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{val2:23,}","datapoints":[[13,"-"]]},{"refId":"A","target":"{val2:24,}","datapoints":[[14,"-"]]}]@ then - return -1 -endi - -print =============== step7 - one query, 3 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select val1,val2,val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{val2:23,, val:2,}","datapoints":[[13,"-"]]},{"refId":"A","target":"{val2:24,, val:2,}","datapoints":[[14,"-"]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select val1,val2,val from db.tb"} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{val2:21,, val:1,}","datapoints":[[11,"-"]]},{"refId":"A","target":"{val2:22,, val:1,}","datapoints":[[12,"-"]]},{"refId":"A","target":"{val2:23,, val:2,}","datapoints":[[13,"-"]]},{"refId":"A","target":"{val2:24,, val:2,}","datapoints":[[14,"-"]]}]@ then - return -1 -endi - -print =============== step8 - one query, no return -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select val1,val2,val from db.tb where ts >= 1677980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[]@ then - return -1 -endi - -print =============== step9 - one query, insert sql -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"insert into db.t2 values(now, 1) "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[]@ then - return -1 -endi - -print =============== step10 - one query, error sql -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select * from db.tt "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[]@ then - return -1 -endi - -print =============== step11 - two query, 1 column, with timestamp, 1 column, with timestamp - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"","sql":"select ts from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[null,1577980800000],[null,1578067200000]]},{"refId":"A","target":"A","datapoints":[[null,1577980800000],[null,1578067200000]]}]@ then - return -1 -endi - -print =============== step12 - two query, 1 column, with timestamp, 2 column, with timestamp - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"","sql":"select ts,val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[null,1577980800000],[null,1578067200000]]},{"refId":"A","target":"A","datapoints":[[2,1577980800000],[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step13 - two query, 1 column, with timestamp, 3 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"","sql":"select ts,val,val1 from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[null,1577980800000],[null,1578067200000]]},{"refId":"A","target":"{val1:13,}","datapoints":[[2,1577980800000]]},{"refId":"A","target":"{val1:14,}","datapoints":[[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step14 - two query, 2 column, with timestamp, 2 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val2 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[223,1577980800000],[224,1578067200000]]},{"refId":"A","target":"AA","datapoints":[[2,1577980800000],[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step15 - two query, 2 column, with timestamp, 3 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val2, val1 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB{val1:213,}","datapoints":[[223,1577980800000]]},{"refId":"B","target":"BB{val1:214,}","datapoints":[[224,1578067200000]]},{"refId":"A","target":"AA","datapoints":[[2,1577980800000],[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step16 - two query, 3 column, with timestamp, 4 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val, val1, val2, val1 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val,val1 from db.tb where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB{val1:213,, val2:223,, val1:213,}","datapoints":[[22,1577980800000]]},{"refId":"B","target":"BB{val1:214,, val2:224,, val1:214,}","datapoints":[[22,1578067200000]]},{"refId":"A","target":"AA{val1:13,}","datapoints":[[2,1577980800000]]},{"refId":"A","target":"AA{val1:14,}","datapoints":[[2,1578067200000]]}]@ then - return -1 -endi - -print =============== step17 - two query, 2 column, with timestamp, no return -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val from db.tb where ts >= 1677980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,1577980800000],[22,1578067200000]]}]@ then - return -1 -endi - -print =============== step18 - two query, 2 column, with timestamp, invalid sql -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val from db.tb222 where ts >= 1677980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,1577980800000],[22,1578067200000]]}]@ then - return -1 -endi - -print =============== step19 - two query, 2 column, with timestamp, insert sql -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select ts, val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"insert into db.t2 values(now, 1)"} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,1577980800000],[22,1578067200000]]}]@ then - return -1 -endi - -print =============== step20 - two query, 1 column, no timestamp, 1 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,"-"],[22,"-"]]},{"refId":"A","target":"AA","datapoints":[[null,1577980800000],[null,1578067200000]]}]@ then - return -1 -endi - -print =============== step21 - two query, 1 column, no timestamp, 2 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val2 from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,"-"],[22,"-"]]},{"refId":"A","target":"AA","datapoints":[[223,1577980800000],[224,1578067200000]]}]@ then - return -1 -endi - -print =============== step22 - two query, 1 column, no timestamp, 3 column, with timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select ts,val1, val2 from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB","datapoints":[[22,"-"],[22,"-"]]},{"refId":"A","target":"AA{val2:223,}","datapoints":[[213,1577980800000]]},{"refId":"A","target":"AA{val2:224,}","datapoints":[[214,1578067200000]]}]@ then - return -1 -endi - -print =============== step23 - two query, 2 column, no timestamp, 1 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val1,val2 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select val1 from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB{val2:223,}","datapoints":[[213,"-"]]},{"refId":"B","target":"BB{val2:224,}","datapoints":[[214,"-"]]},{"refId":"A","target":"AA","datapoints":[[213,"-"],[214,"-"]]}]@ then - return -1 -endi - -print =============== step24 - two query, 2 column, no timestamp, 2 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val1,val2 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select val,val1 from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB{val2:223,}","datapoints":[[213,"-"]]},{"refId":"B","target":"BB{val2:224,}","datapoints":[[214,"-"]]},{"refId":"A","target":"AA{val1:213,}","datapoints":[[22,"-"]]},{"refId":"A","target":"AA{val1:214,}","datapoints":[[22,"-"]]}]@ then - return -1 -endi - -print =============== step25 - two query, 2 column, no timestamp, 3 column, no timestamp -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"B","alias":"BB","sql":"select val1,val2 from db.tb2 where ts >= 1577980800000 "},{"refId":"A","alias":"AA","sql":"select val,val1,val2 from db.tb2 where ts >= 1577980800000 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"B","target":"BB{val2:223,}","datapoints":[[213,"-"]]},{"refId":"B","target":"BB{val2:224,}","datapoints":[[214,"-"]]},{"refId":"A","target":"AA{val1:213,, val2:223,}","datapoints":[[22,"-"]]},{"refId":"A","target":"AA{val1:214,, val2:224,}","datapoints":[[22,"-"]]}]@ then - return -1 -endi - -print =============== step26 - 2 column, no timestamp, NULL -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select * from db.tb3 "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{val1:nil, val2:nil}","datapoints":[[null,1577808000000],[null,1577894400000]]}]@ then - return -1 -endi - -sql create table tt (ts timestamp ,i int) tags(j binary(20),k binary(20)); -sql insert into t1 using tt tags('jnetworki','t1') values('2020-01-01 00:00:00.000',1)('2020-01-01 00:01:00.000',2)('2020-01-01 00:02:00.000',3)('2020-01-01 00:03:00.000',4)('2020-01-01 00:04:00.000',5); - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select max(i) from db.tt where j like \u0027%network%\u0027 and ts >= \u00272020-01-01 00:00:00.000\u0027 and ts < \u00272020-01-01 00:05:00.000\u0027 interval(5m) group by k "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{k:t1}","datapoints":[[5,1577808000000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select max(i) from db.tt where j like \u0027jnetwo%\u0027 and ts >= \u00272020-01-01 00:00:00.000\u0027 and ts < \u00272020-01-01 00:05:00.000\u0027 interval(5m) group by k "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{k:t1}","datapoints":[[5,1577808000000]]}]@ then - return -1 -endi - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d '[ {"refId":"A","alias":"","sql":"select max(i) from db.tt where j like \u0027%networki\u0027 and ts >= \u00272020-01-01 00:00:00.000\u0027 and ts < \u00272020-01-01 00:05:00.000\u0027 interval(5m) group by k "} ]' 127.0.0.1:7111/grafana/query -print step1-> $system_content -if $system_content != @[{"refId":"A","target":"{k:t1}","datapoints":[[5,1577808000000]]}]@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/gzip.sim b/tests/script/general/http/gzip.sim deleted file mode 100644 index ce358d84a177b79f8333c2bb4ce370b79b4e0eca..0000000000000000000000000000000000000000 --- a/tests/script/general/http/gzip.sim +++ /dev/null @@ -1,39 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c maxSQLLength -v 340032 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database d1 -sql use d1 - -sql create table table_rest (ts timestamp, i int) -print sql length is 270KB -restful d1 table_rest 1591072800 10000 gzip -restful d1 table_rest 1591172800 10000 gzip -restful d1 table_rest 1591272800 10000 gzip -restful d1 table_rest 1591372800 10000 gzip -restful d1 table_rest 1591472800 10000 gzip -restful d1 table_rest 1591572800 10000 gzip -restful d1 table_rest 1591672800 10000 gzip -restful d1 table_rest 1591772800 10000 gzip -restful d1 table_rest 1591872800 10000 gzip -restful d1 table_rest 1591972800 10000 gzip - -sql select * from table_rest; -print rows: $rows -if $rows != 100000 then - return -1 -endi - -system curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_rest' 127.0.0.1:7111/rest/sql --compressed - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/http.json b/tests/script/general/http/http.json deleted file mode 100644 index 087f4eab5b2d43ec1286c515aa7ef89ce2c42a92..0000000000000000000000000000000000000000 --- a/tests/script/general/http/http.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "hostIp": "192.168.100.128", - "connNum": 1, - "insertModel": "insertTable", - "waitTime": 0, - "tableDesc": "ts timestamp i int", - "tablePrefix": "t", - "tablePerConn": 1, - "tableCreate": true, - "tableStart": 1, - "dbName": "db", - "dbReplica": 1, - "dbKeep": 3650, - "dbDays": 7, - "metricsName": "mt", - "tagNum": 10, - "dataNum": 100, - "dataBegin": 1485878400000, - "dataInterval": 1000, - "dataBatch": 1, - "dataInsert": true, - "dataRandom": false -} diff --git a/tests/script/general/http/httpTestNew.go b/tests/script/general/http/httpTestNew.go deleted file mode 100644 index 9ca7733d445ba58dfa6c5fc07bd94e5174a2b7d7..0000000000000000000000000000000000000000 --- a/tests/script/general/http/httpTestNew.go +++ /dev/null @@ -1,247 +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 . - */ - -package main - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "os" - "sync" - "sync/atomic" - "time" -) - -var ( - token string - url string - config Config - request int64 - begin time.Time - errorNum int64 -) - -type Config struct { - HostIp string `json:"hostIp"` - TableNum int `json:"tableNum"` - DbName string `json:"dbName"` - MetricsName string `json:"metricsName"` - DataNum int `json:"dataNum"` - BatchNum int `json:"batchNum"` -} - -type TokenResult struct { - Status string `json:"status"` - Code int `json:"code"` - Desc string `json:"desc"` -} - -type JsonResult struct { - Status string `json:"status"` - Code int `json:"code"` -} - -func readFile(filename string) { - file, err := os.Open(filename) - if err != nil { - println("taos.json not found") - panic(err) - } - defer file.Close() - - dec := json.NewDecoder(file) - err = dec.Decode(&config) - if err != nil { - println("taos.json parse error") - panic(err) - } - - request = 0 - errorNum = 0 - - fmt.Println("================config parameters======================") - fmt.Println("HostIp:", config.HostIp) - fmt.Println("TableNum:", config.TableNum) - fmt.Println("dbName:", config.DbName) - fmt.Println("metricsName:", config.MetricsName) - fmt.Println("dataNum:", config.DataNum) - fmt.Println("batchNum:", config.BatchNum) - - fmt.Println("================http token=============================") - token, err = getToken() - url = fmt.Sprintf("http://%s:%d/rest/sql", config.HostIp, 6020) - - fmt.Println("httpToken:", token) - fmt.Println("httpUrl:", url) - - if err != nil { - panic(err) - } -} - -func getToken() (string, error) { - resp, err := http.Get(fmt.Sprintf("http://%s:%d/rest/login/%s/%s", config.HostIp, 6020, "root", "taosdata")) - if err != nil { - return "", err - } - - defer resp.Body.Close() - - var tokenResult TokenResult - - data, err := ioutil.ReadAll(resp.Body) - - if err != nil { - return "", err - } - - err = json.Unmarshal(data, &tokenResult) - if err != nil { - return "", err - } - - if tokenResult.Status != "succ" { - fmt.Println("get http token failed") - fmt.Println(tokenResult) - return "", err - } - - return tokenResult.Desc, nil -} - -func exec(client *http.Client, sql string) { - for reTryTimes := 0; reTryTimes < 10; reTryTimes++ { - - req, err1 := http.NewRequest("POST", url, bytes.NewReader([]byte(sql))) - if err1 != nil { - continue - } - req.Header.Add("Authorization", "Taosd "+token) - - resp, err := client.Do(req) - - if err != nil { - continue - } - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - resp.Body.Close() - continue - } - - var jsonResult JsonResult - err = json.Unmarshal(data, &jsonResult) - if err != nil { - resp.Body.Close() - continue - } - - if jsonResult.Status != "succ" { - resp.Body.Close() - continue - } - - atomic.AddInt64(&request, 1) - - if (request*int64(config.BatchNum))%100000 == 0 && request != 0 { - spend := time.Since(begin).Seconds() - if spend >= 1 && spend < 10000000 { - total := (request - errorNum - 2 - int64(config.TableNum)) * int64(config.BatchNum) - fmt.Printf("request:%d, error:%d, insert:%d, spend:%.2f seconds, dps:%.1f \n", request, errorNum, total, spend, float64(total)/float64(spend)) - } - } - - return - } - - //fmt.Println("exec failed, sql:", sql) - errorNum++ -} - -func createDb() { - fmt.Println("================create database =====================") - - client := &http.Client{} - sql := fmt.Sprintf("create database %s", config.DbName) - exec(client, sql) -} - -func createTb() { - fmt.Println("================create table ========================") - - client := &http.Client{} - sql := fmt.Sprintf("create table %s.%s(ts timestamp, f1 int, f2 int) tags (tb int)", config.DbName, config.MetricsName) - exec(client, sql) - - for i := 0; i < config.TableNum; i++ { - sql := fmt.Sprintf("create table %s.t%d using %s.%s tags(%d)", config.DbName, i, config.DbName, config.MetricsName, i) - exec(client, sql) - } -} - -func insertData(wg *sync.WaitGroup, tableIndex int) { - defer wg.Done() - - client := &http.Client{} - beginTime := int64(1519833600000) - - for i := 0; i < config.DataNum; i += config.BatchNum { - var sql bytes.Buffer - sql.WriteString(fmt.Sprintf("insert into %s.t%d values", config.DbName, tableIndex)) - - for j := 0; j < config.BatchNum; j++ { - sql.WriteString(fmt.Sprintf("(%d,%d,%d)", beginTime+int64(i)+int64(j), rand.Intn(1000), rand.Intn(1000))) - } - exec(client, sql.String()) - } -} - -func main() { - filename := flag.String("config", "http.json", "config file name") - - flag.Parse() - - readFile(*filename) - - fmt.Println("\n================http test start======================") - - createDb() - createTb() - - begin = time.Now() - - var wg sync.WaitGroup - - fmt.Println("================insert data ========================") - for i := 0; i < config.TableNum; i++ { - wg.Add(1) - go insertData(&wg, i) - } - - wg.Wait() - - fmt.Println("\n================http test stop ======================") - - spend := time.Since(begin).Seconds() - - total := (request - errorNum - 2 - int64(config.TableNum)) * int64(config.BatchNum) - fmt.Printf("request:%d, error:%d, insert:%d, spend:%.2f seconds, dps:%.1f \n", request, errorNum, total, spend, float64(total)/float64(spend)) -} diff --git a/tests/script/general/http/httpTest_cloud.go b/tests/script/general/http/httpTest_cloud.go deleted file mode 100644 index 1d849a245f281a73e4e3ef0c36a2f72e87eb472c..0000000000000000000000000000000000000000 --- a/tests/script/general/http/httpTest_cloud.go +++ /dev/null @@ -1,387 +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 . - */ - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "os" - "sync" - "sync/atomic" - "time" - "flag" -) - -var ( - token string - url string - config Config - request int64 - period int64 - errorNum int64 -) - -type Config struct { - HostIp string `json:"hostIp"` - ConnNum int `json:"connNum"` - InsertModel string `json:"insertModel"` - WaitTime int `json:"waitTime"` - TableDesc string `json:"tableDesc"` - TablePrefix string `json:"tablePrefix"` - TablePerConn int `json:"tablePerConn"` - TableCreate bool `json:"tableCreate"` - TableStart int `json:"tableStart"` - DbName string `json:"dbName"` - DbReplica int `json:"dbReplica"` - DbKeep int `json:"dbKeep"` - DbDays int `json:"dbDays"` - MetricsName string `json:"metricsName"` - TagNum int `json:"tagNum"` - DataNum int `json:"dataNum"` - DataBegin int64 `json:"dataBegin"` - DataInterval int `json:"dataInterval"` - DataBatch int `json:"dataBatch"` - DataInsert bool `json:"dataInsert"` - DataRandom bool `json:"dataRandom"` -} - -type TokenResult struct { - Status string `json:"status"` - Code int `json:"code"` - Desc string `json:"desc"` -} - -type JsonResult struct { - Status string `json:"status"` - Code int `json:"code"` -} - -func readFile(filename string) { - file, err := os.Open(filename) - if err != nil { - println("taos_cloud.json not found") - panic(err) - } - defer file.Close() - - dec := json.NewDecoder(file) - err = dec.Decode(&config) - if err != nil { - println("taos_cloud.json parse error") - panic(err) - } - - if config.TagNum <= 0 { - config.TagNum = 1 - } - request = 0 - period = 0 - errorNum = 0 - - fmt.Println("================config parameters======================") - fmt.Println("HostIp:", config.HostIp) - fmt.Println("connNum:", config.ConnNum) - fmt.Println("insertModel:", config.InsertModel) - fmt.Println("waitTime:", config.WaitTime) - fmt.Println("tableDesc:", config.TableDesc) - fmt.Println("tablePrefix:", config.TablePrefix) - fmt.Println("tablePerConn:", config.TablePerConn) - fmt.Println("tableCreate:", config.TableCreate) - fmt.Println("tableStart:", config.TableStart) - fmt.Println("dbName:", config.DbName) - fmt.Println("dbReplica:", config.DbReplica) - fmt.Println("dbKeep:", config.DbKeep) - fmt.Println("dbDays:", config.DbDays) - fmt.Println("metricsName:", config.MetricsName) - fmt.Println("tagNum:", config.TagNum) - fmt.Println("dataNum:", config.DataNum) - fmt.Println("dataBegin:", config.DataBegin) - fmt.Println("dataInterval:", config.DataInterval) - fmt.Println("dataBatch:", config.DataBatch) - fmt.Println("dataInsert:", config.DataInsert) - fmt.Println("dataRandom:", config.DataRandom) - - fmt.Println("================http token=============================") - token, err = getToken() - url = fmt.Sprintf("http://%s:%d/rest/sql", config.HostIp, 6020) - - fmt.Println("httpToken:", token) - fmt.Println("httpUrl:", url) - - if err != nil { - panic(err) - } -} - -func getToken() (string, error) { - resp, err := http.Get(fmt.Sprintf("http://%s:%d/rest/login/%s/%s", config.HostIp, 6020, "tiger", "tiger")) - if err != nil { - return "", err - } - - defer resp.Body.Close() - - var tokenResult TokenResult - - data, err := ioutil.ReadAll(resp.Body) - - if err != nil { - return "", err - } - - err = json.Unmarshal(data, &tokenResult) - if err != nil { - return "", err - } - - if tokenResult.Status != "succ" { - fmt.Println("get http token failed") - fmt.Println(tokenResult) - return "", err - } - - return tokenResult.Desc, nil -} - -func exec(client *http.Client, sql string) { - for times := 0; times < 10; times++ { - - req, err1 := http.NewRequest("POST", url, bytes.NewReader([]byte(sql))) - if err1 != nil { - continue - } - req.Header.Add("Authorization", "Taosd "+token) - - begin := time.Now() - resp, err := client.Do(req) - - if err != nil { - continue - } - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - resp.Body.Close() - continue - } - - spend := (time.Since(begin).Nanoseconds()) - - var jsonResult JsonResult - err = json.Unmarshal(data, &jsonResult) - if err != nil { - resp.Body.Close() - continue - } - - if jsonResult.Status != "succ" { - resp.Body.Close() - continue - } - atomic.AddInt64(&request, 1) - if (request < 103) { - return - } - - atomic.AddInt64(&period, spend) - if request%5000 == 0 && request != 0 { - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.ConnNum) - dps := qps * float64(config.DataBatch) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) - } - return - } - fmt.Println("xxxx>sql:", sql, ", retryTimes:", 10) - errorNum++ -} - -func createDb() { - if !config.TableCreate { - return - } - - client := &http.Client{} - - fmt.Println("\n================create database =====================") - sql := fmt.Sprintf("create database %s keep %d", config.DbName, config.DbKeep) - exec(client, sql) -} - -func createTb() { - if !config.TableCreate { - return - } - client := &http.Client{} - - fmt.Println("\n================create table ========================") - sql := fmt.Sprintf("create table %s.%s(%s) tags (orgno int)", config.DbName, config.MetricsName, config.TableDesc) - exec(client, sql) - tbNum := config.TablePerConn*config.ConnNum + config.TableStart - for i := config.TableStart; i < tbNum; i++ { - sql := fmt.Sprintf("create table %s.%s%d using %s.%s tags(%d)", config.DbName, config.TablePrefix, i, config.DbName, config.MetricsName, i%config.TagNum+1) - exec(client, sql) - } - -} - -func insertTable(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - for i := 0; i < config.TablePerConn; i++ { - tbIndex := i + tbStart - - for j := 0; j < config.DataNum; j++ { - tmVal := int64(j)*int64(config.DataInterval) + tmStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("insert into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - for k := 1; k < config.DataBatch; k++ { - tmVal := int64(j)*int64(config.DataInterval) + int64(k) + tmStart - - dataVal := j + k - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql += fmt.Sprintf("(%d, %d)", tmVal, dataVal) - } - - j += (config.DataBatch - 1) - - exec(client, sql) - if config.WaitTime != 0 { - time.Sleep(time.Millisecond * time.Duration(config.WaitTime)) - } - } - } -} - -func insertLoop(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - for j := 0; j < config.DataNum; j++ { - - for i := 0; i < config.TablePerConn; i++ { - tbIndex := i + tbStart - - tmVal := int64(j)*int64(config.DataInterval) + tmStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("insert into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - for k := 1; k < config.DataBatch; k++ { - tmVal := int64(j)*int64(config.DataInterval) + int64(k) + tmStart - - dataVal := j + k - if config.DataRandom { - dataVal = rand.Intn(1000) - } - sql += fmt.Sprintf("values(%d, %d)", tmVal, dataVal) - } - - j += (config.DataBatch - 1) - - exec(client, sql) - - if config.WaitTime != 0 { - time.Sleep(time.Millisecond * time.Duration(config.WaitTime)) - } - } - - } -} - -func insertTb(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - if !config.DataInsert { - return - } - - if config.InsertModel == "insertTable" { - insertTable(conn) - } else { - insertLoop(conn) - } -} - -func selectData(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - client := &http.Client{} - - for i := 0; i < config.DataNum; i++ { - exec(client, config.TableDesc) - } -} - -func main() { - filename := flag.String("config", "taos_cloud.json", "config file name") - - flag.Parse() - - readFile(*filename) - - fmt.Println("\n================http test start======================") - - var wg sync.WaitGroup - - if config.InsertModel == "selectData" { - fmt.Println("\n================select data ========================") - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go selectData(&wg, i) - } - } else { - createDb() - createTb() - - if config.DataInsert { - fmt.Println("\n================insert data ========================") - } - - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go insertTb(&wg, i) - } - } - - wg.Wait() - - fmt.Println("\n================http test stop ======================") - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.ConnNum) - dps := qps * float64(config.DataBatch) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) -} diff --git a/tests/script/general/http/httpTest_private.go b/tests/script/general/http/httpTest_private.go deleted file mode 100644 index 66f19ec896e372e39feaae126d606922038e97dd..0000000000000000000000000000000000000000 --- a/tests/script/general/http/httpTest_private.go +++ /dev/null @@ -1,387 +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 . - */ - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "math/rand" - "net/http" - "os" - "sync" - "sync/atomic" - "time" - "flag" -) - -var ( - token string - url string - config Config - request int64 - period int64 - errorNum int64 -) - -type Config struct { - HostIp string `json:"hostIp"` - ConnNum int `json:"connNum"` - InsertModel string `json:"insertModel"` - WaitTime int `json:"waitTime"` - TableDesc string `json:"tableDesc"` - TablePrefix string `json:"tablePrefix"` - TablePerConn int `json:"tablePerConn"` - TableCreate bool `json:"tableCreate"` - TableStart int `json:"tableStart"` - DbName string `json:"dbName"` - DbReplica int `json:"dbReplica"` - DbKeep int `json:"dbKeep"` - DbDays int `json:"dbDays"` - MetricsName string `json:"metricsName"` - TagNum int `json:"tagNum"` - DataNum int `json:"dataNum"` - DataBegin int64 `json:"dataBegin"` - DataInterval int `json:"dataInterval"` - DataBatch int `json:"dataBatch"` - DataInsert bool `json:"dataInsert"` - DataRandom bool `json:"dataRandom"` -} - -type TokenResult struct { - Status string `json:"status"` - Code int `json:"code"` - Desc string `json:"desc"` -} - -type JsonResult struct { - Status string `json:"status"` - Code int `json:"code"` -} - -func readFile(filename string) { - file, err := os.Open(filename) - if err != nil { - println("taos_cloud.json not found") - panic(err) - } - defer file.Close() - - dec := json.NewDecoder(file) - err = dec.Decode(&config) - if err != nil { - println("taos_cloud.json parse error") - panic(err) - } - - if config.TagNum <= 0 { - config.TagNum = 1 - } - request = 0 - period = 0 - errorNum = 0 - - fmt.Println("================config parameters======================") - fmt.Println("HostIp:", config.HostIp) - fmt.Println("connNum:", config.ConnNum) - fmt.Println("insertModel:", config.InsertModel) - fmt.Println("waitTime:", config.WaitTime) - fmt.Println("tableDesc:", config.TableDesc) - fmt.Println("tablePrefix:", config.TablePrefix) - fmt.Println("tablePerConn:", config.TablePerConn) - fmt.Println("tableCreate:", config.TableCreate) - fmt.Println("tableStart:", config.TableStart) - fmt.Println("dbName:", config.DbName) - fmt.Println("dbReplica:", config.DbReplica) - fmt.Println("dbKeep:", config.DbKeep) - fmt.Println("dbDays:", config.DbDays) - fmt.Println("metricsName:", config.MetricsName) - fmt.Println("tagNum:", config.TagNum) - fmt.Println("dataNum:", config.DataNum) - fmt.Println("dataBegin:", config.DataBegin) - fmt.Println("dataInterval:", config.DataInterval) - fmt.Println("dataBatch:", config.DataBatch) - fmt.Println("dataInsert:", config.DataInsert) - fmt.Println("dataRandom:", config.DataRandom) - - fmt.Println("================http token=============================") - token, err = getToken() - url = fmt.Sprintf("http://%s:%d/rest/sql", config.HostIp, 6020) - - fmt.Println("httpToken:", token) - fmt.Println("httpUrl:", url) - - if err != nil { - panic(err) - } -} - -func getToken() (string, error) { - resp, err := http.Get(fmt.Sprintf("http://%s:%d/rest/login/%s/%s", config.HostIp, 6020, "root", "taosdata")) - if err != nil { - return "", err - } - - defer resp.Body.Close() - - var tokenResult TokenResult - - data, err := ioutil.ReadAll(resp.Body) - - if err != nil { - return "", err - } - - err = json.Unmarshal(data, &tokenResult) - if err != nil { - return "", err - } - - if tokenResult.Status != "succ" { - fmt.Println("get http token failed") - fmt.Println(tokenResult) - return "", err - } - - return tokenResult.Desc, nil -} - -func exec(client *http.Client, sql string) { - for times := 0; times < 1; times++ { - - req, err1 := http.NewRequest("POST", url, bytes.NewReader([]byte(sql))) - if err1 != nil { - continue - } - req.Header.Add("Authorization", "Taosd "+token) - - begin := time.Now() - resp, err := client.Do(req) - - if err != nil { - continue - } - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - resp.Body.Close() - continue - } - - spend := (time.Since(begin).Nanoseconds()) - - var jsonResult JsonResult - err = json.Unmarshal(data, &jsonResult) - if err != nil { - resp.Body.Close() - continue - } - - if jsonResult.Status != "succ" { - resp.Body.Close() - continue - } - atomic.AddInt64(&request, 1) - if (request < 103) { - return - } - - atomic.AddInt64(&period, spend) - if request%5000 == 0 && request != 0 { - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.ConnNum) - dps := qps * float64(config.DataBatch) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) - } - return - } - fmt.Println("xxxx>sql:", sql, ", retryTimes:", 10) - errorNum++ -} - -func createDb() { - if !config.TableCreate { - return - } - - client := &http.Client{} - - fmt.Println("\n================create database =====================") - sql := fmt.Sprintf("create database %s keep %d", config.DbName, config.DbKeep) - exec(client, sql) -} - -func createTb() { - if !config.TableCreate { - return - } - client := &http.Client{} - - fmt.Println("\n================create table ========================") - sql := fmt.Sprintf("create table %s.%s(%s) tags (orgno int)", config.DbName, config.MetricsName, config.TableDesc) - exec(client, sql) - tbNum := config.TablePerConn*config.ConnNum + config.TableStart - for i := config.TableStart; i < tbNum; i++ { - sql := fmt.Sprintf("create table %s.%s%d using %s.%s tags(%d)", config.DbName, config.TablePrefix, i, config.DbName, config.MetricsName, i%config.TagNum+1) - exec(client, sql) - } - -} - -func insertTable(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - for j := 0; j < config.DataNum; j++ { - for i := 0; i < config.TablePerConn; i++ { - tbIndex := i + tbStart - - tmVal := int64(j)*int64(config.DataInterval) + tmStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("insert into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - for k := 1; k < config.DataBatch; k++ { - tmVal := int64(j)*int64(config.DataInterval) + int64(k) + tmStart - - dataVal := j + k - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql += fmt.Sprintf("(%d, %d)", tmVal, dataVal) - } - - - exec(client, sql) - if config.WaitTime != 0 { - time.Sleep(time.Millisecond * time.Duration(config.WaitTime)) - } - } - j += (config.DataBatch - 1) - } -} - -func insertLoop(conn int) { - client := &http.Client{} - - tbStart := conn*config.TablePerConn + config.TableStart - tmStart := config.DataBegin - - for j := 0; j < config.DataNum; j++ { - - for i := 0; i < config.TablePerConn; i++ { - tbIndex := i + tbStart - - tmVal := int64(j)*int64(config.DataInterval) + tmStart - - dataVal := j - if config.DataRandom { - dataVal = rand.Intn(1000) - } - - sql := fmt.Sprintf("insert into %s.%s%d values(%d, %d)", config.DbName, config.TablePrefix, tbIndex, tmVal, dataVal) - for k := 1; k < config.DataBatch; k++ { - tmVal := int64(j)*int64(config.DataInterval) + int64(k) + tmStart - - dataVal := j + k - if config.DataRandom { - dataVal = rand.Intn(1000) - } - sql += fmt.Sprintf("values(%d, %d)", tmVal, dataVal) - } - - j += (config.DataBatch - 1) - - exec(client, sql) - - if config.WaitTime != 0 { - time.Sleep(time.Millisecond * time.Duration(config.WaitTime)) - } - } - - } -} - -func insertTb(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - if !config.DataInsert { - return - } - - if config.InsertModel == "insertTable" { - insertTable(conn) - } else { - insertLoop(conn) - } -} - -func selectData(wg *sync.WaitGroup, conn int) { - defer wg.Done() - - client := &http.Client{} - - for i := 0; i < config.DataNum; i++ { - exec(client, config.TableDesc) - } -} - -func main() { - filename := flag.String("config", "taos_cloud.json", "config file name") - - flag.Parse() - - readFile(*filename) - - fmt.Println("\n================http test start======================") - - var wg sync.WaitGroup - - if config.InsertModel == "selectData" { - fmt.Println("\n================select data ========================") - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go selectData(&wg, i) - } - } else { - createDb() - createTb() - - if config.DataInsert { - fmt.Println("\n================insert data ========================") - } - - for i := 0; i < config.ConnNum; i++ { - wg.Add(1) - go insertTb(&wg, i) - } - } - - wg.Wait() - - fmt.Println("\n================http test stop ======================") - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.ConnNum) - dps := qps * float64(config.DataBatch) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) -} diff --git a/tests/script/general/http/prepare.sim b/tests/script/general/http/prepare.sim deleted file mode 100644 index 4bf6b6119833563f85ee8f8de1a2393bf07a2e71..0000000000000000000000000000000000000000 --- a/tests/script/general/http/prepare.sim +++ /dev/null @@ -1,54 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database d1 -sql use d1 - -sql create table t1 (ts timestamp, i int, b binary(100)) - -sql insert into t1 values('2017-12-25 21:28:41.022', 1, 11) -sql insert into t1 values('2017-12-25 21:28:42.022', 2, '22') -sql insert into t1 values('2017-12-25 21:28:43.022', 3, "33") -sql insert into t1 values('2017-12-25 21:28:44.022', 4, '44"') -sql insert into t1 values('2017-12-25 21:28:45.022', 5, "55'") -sql insert into t1 values('2017-12-25 21:28:46.022', 6, "66'6'") -sql insert into t1 values('2017-12-25 21:28:47.022', 7, '77"7"') -sql insert into t1 values('2017-12-25 21:28:48.022', 8, '88""88') -sql insert into t1 values('2017-12-25 21:28:49.022', 9, '99\99') -sql insert into t1 values('2017-12-25 21:28:51.022', 11, '11\\11') -sql insert into t1 values('2017-12-25 21:28:52.022', 12, '22\\11') -sql insert into t1 values('2017-12-25 21:28:53.022', 13, '33\\"33') -sql insert into t1 values('2017-12-25 21:28:54.022', 14, '44\\""44') - -sleep 4000 - -print =============== step2 - login - -system_content curl 127.0.0.1:7111/rest/login/root/taosdata -print curl 127.0.0.1:7111/rest/login/root/taosdata -----> $system_content - -if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then - return -1 -endi - -return - -print =============== step3 - query data - -system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwia2V5IjoiYkVsOExjdkxVZDdhOHFkdE5abXRPTnJ5cDIwMW1hMDQiLCJzdWIiOiJyb290In0.k7CkgmpOJImIkLqZqzASlPmkdeEw7Wfk4XUrqGZX-LQ' -d 'select * from t1' 127.0.0.1:7111/rest/sql/d1 -print curl 127.0.0.1:7111/rest/sql/d1 -----> $system_content -if $system_content != @{"status":"succ","head":["ts","i","b"],"data":[["2017-12-25 21:28:54.022",14,"44\\\\\"\"44"],["2017-12-25 21:28:53.022",13,"33\\\\\"33"],["2017-12-25 21:28:52.022",12,"22\\\\11"],["2017-12-25 21:28:51.022",11,"11\\\\11"],["2017-12-25 21:28:49.022",9,"99\\99"],["2017-12-25 21:28:48.022",8,"88\"\"88"],["2017-12-25 21:28:47.022",7,"77\"7\""],["2017-12-25 21:28:46.022",6,"66'6'"],["2017-12-25 21:28:45.022",5,"55'"],["2017-12-25 21:28:44.022",4,"44\""],["2017-12-25 21:28:43.022",3,"33"],["2017-12-25 21:28:42.022",2,"22"],["2017-12-25 21:28:41.022",1,"11"]],"rows":13}@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/restful.sim b/tests/script/general/http/restful.sim deleted file mode 100644 index 6ebf5644e7a99593ebac0302c3dcdbc0a27fc8c1..0000000000000000000000000000000000000000 --- a/tests/script/general/http/restful.sim +++ /dev/null @@ -1,82 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 -system sh/exec.sh -n dnode1 -s start - -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database d1 -sql use d1 - -sql create table table_rest (ts timestamp, i int) - -sql insert into table_rest values('2017-12-25 21:28:41.022', 1) -sql insert into table_rest values('2017-12-25 21:28:42.022', 2) -sql insert into table_rest values('2017-12-25 21:28:43.022', 3) -sql insert into table_rest values('2017-12-25 21:28:44.022', 4) -sql insert into table_rest values('2017-12-25 21:28:45.022', 5) -sql insert into table_rest values('2017-12-25 21:28:46.022', 6) -sql insert into table_rest values('2017-12-25 21:28:47.022', 7) -sql insert into table_rest values('2017-12-25 21:28:48.022', 8) -sql insert into table_rest values('2017-12-25 21:28:49.022', 9) -sql insert into table_rest values('2017-12-25 21:28:50.022', 10) - -print =============== step2 - login - -system_content curl 127.0.0.1:7111/rest/login/root/taosdata -print curl 127.0.0.1:7111/rest/login/root/taosdata -----> $system_content - -if $system_content != {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"} then - return -1 -endi - -print =============== step3 - query data - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_rest' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content -if $system_content != @{"status":"succ","head":["ts","i"],"column_meta":[["ts",9,8],["i",4,4]],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}@ then - return -1 -endi - -print =============== step4 - insert data -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.table_rest values('2017-12-25 21:28:51.022', 11)" 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[1]],"rows":1}@ then - return -1 -endi - -print =============== step5 - query data - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_rest' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content -if $system_content != @{"status":"succ","head":["ts","i"],"column_meta":[["ts",9,8],["i",4,4]],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10],["2017-12-25 21:28:51.022",11]],"rows":11}@ then - return -1 -endi - -print =============== step6 - query no db data - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show dnodes' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content - -print =============== step7 - change password -sql create user u1 PASS 'abcd@1234' -sql create user u2 PASS 'abcd_1234' - -system_content curl 127.0.0.1:7111/rest/login/u1/abcd@1234 -print curl 127.0.0.1:7111/rest/login/u1/abcd@1234 -----> $system_content -if $system_content != @{"status":"succ","code":0,"desc":"jIlItaLFFIPa8qdtNZmtONryp201ma04SXX8PEJowKAB/46k1gwnPNryp201ma04"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/rest/login/u2/aabcd_1234 -print curl 127.0.0.1:7111/rest/login/u2/abcd_1234 -----> $system_content -if $system_content != @{"status":"error","code":3,"desc":"Authentication failure"}@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/http/restful_dbname.sim b/tests/script/general/http/restful_dbname.sim deleted file mode 100644 index 75cd198507dda306c736cbcdeef4a044f66da9de..0000000000000000000000000000000000000000 --- a/tests/script/general/http/restful_dbname.sim +++ /dev/null @@ -1,124 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c httpDbNameMandatory -v 1 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect -sql drop database if exists db - -print ============================ dnode1 start - -print =============== step1 - login - -system_content curl 127.0.0.1:7111/rest/login/root/taosdata -print curl 127.0.0.1:7111/rest/login/root/taosdata -----> $system_content - -if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then - return -1 -endi - -print =============== step2 - execute sql without db_name - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest (now, 1)' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest values (now, 1)' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql - -if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then - return -1 -endi - -print =============== step3 - execute sql with db_name - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql/databases - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql/databases - -if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql/db - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql/db - -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql/db - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql/db - -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest (now, 1)' 127.0.0.1:7111/rest/sql/db - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest values (1629904789233, 1)' 127.0.0.1:7111/rest/sql/db - -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[1]],"rows":1}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql/db - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql/db - -if $system_content != @{"status":"succ","head":["ts","i"],"column_meta":[["ts",9,8],["i",4,4]],"data":[["2021-08-25 23:19:49.233",1]],"rows":1}@ then - return -1 -endi - -print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql/db - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql/db - -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim deleted file mode 100644 index a5d3ac2b862f3b2b72b0453a2c1bb2b578672246..0000000000000000000000000000000000000000 --- a/tests/script/general/http/restful_full.sim +++ /dev/null @@ -1,240 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/exec.sh -n dnode1 -s start - -#sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - login - -system_content curl 127.0.0.1:7111/rest/ -print 1-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - print $system_content - return -1 -endi - -system_content curl 127.0.0.1:7111/rest/xx -print 2-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/rest/login -print 3-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -#4 -system_content curl 127.0.0.1:7111/rest/login/root -print 4-> $system_content -if $system_content != @{"status":"error","code":4357,"desc":"no auth info input"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/rest/login/root/123 -print 5-> $system_content -if $system_content != @{"status":"error","code":3,"desc":"Authentication failure"}@ then - return -1 -endi - -system_content curl 127.0.0.1:7111/rest/login/root/123/1/1/3 -print 6-> $system_content -if $system_content != @{"status":"error","code":3,"desc":"Authentication failure"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/login/root/1 -print 7-> $system_content -if $system_content != @{"status":"error","code":3,"desc":"Authentication failure"}@ then - return -1 -endi - -#8 -system_content curl -H 'Authorization: Beare eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9' -d 'show databases' 127.0.0.1:7111/rest/login/root/1 -print 8-> $system_content -if $system_content != @{"status":"error","code":4386,"desc":"invalid type of Authorization"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:7111/rest/login/root/1 -print 8-> $system_content -if $system_content != @{"status":"error","code":4387,"desc":"invalid format of Authorization"}@ then - return -1 -endi - -system_content curl -H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cudGFvc2RhdGEuY29tIiwicGFzcyI6InRhb3NkYXRhIiwic3ViIjoicm9vdCJ9.xPv3b5odlR7YF8G_QWASjIRbMtA5v4ItToJ35fFgi' -d 'show databases' 127.0.0.1:7111/rest/login/root/1 -print 9-> $system_content -if $system_content != @{"status":"error","code":4387,"desc":"invalid format of Authorization"}@ then - return -1 -endi - -sleep 2000 - -system_content curl 127.0.0.1:7111/rest/login/root/taosdata/ -print 10-> $system_content -if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then - return -1 -endi - -print =============== step2 - no db - -#11 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql -print 11-> $system_content -if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep2","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep2",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 127.0.0.1:7111/rest/sql -print 12-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d1' 127.0.0.1:7111/rest/sql -print 13-> $system_content -if $system_content != @{"status":"error","code":897,"desc":"Database already exists"}@ then - return -1 -endi - -#14 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d '' 127.0.0.1:7111/rest/sql -print 14-> $system_content -if $system_content != @{"status":"error","code":4359,"desc":"no sql input"}@ then - return -1 -endi - -#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'use d1' 127.0.0.1:7111/rest/sql -#print 15-> $system_content -#if $system_content != @{"status":"error","code":5017,"desc":"no need to execute use db cmd"}@ then -#if $system_content != @{"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}@ then -# return -1 -#endi - -#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' use d1' 127.0.0.1:7111/rest/sql -#print 16-> $system_content -#if $system_content != @{"status":"error","code":5017,"desc":"no need to execute use db cmd"}@ then -# return -1 -#endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' used1' 127.0.0.1:7111/rest/sql -print 17-> $system_content -if $system_content != @{"status":"error","code":534,"desc":"Syntax error in SQL"}@ then - return -1 -endi - -#18 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:7111/rest/sql -print 18-> $system_content -if $system_content != @{"status":"error","code":896,"desc":"Database not specified or available"}@ then - return -1 -endi - -print =============== step3 - db - -#19 -#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:7111/rest/sql/d4 -#print 19-> $system_content -#if $system_content != @{"status":"error","code":1000,"desc":"invalid DB"}@ then -# return -1 -#endi - -#system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' show tables;' 127.0.0.1:7111/rest/sql/d1 -#print 20-> $system_content -#if $system_content != @{"status":"succ","head":["name","created time","columns","metric"],"data":[],"rows":0}@ then -# return -1 -#endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1;' 127.0.0.1:7111/rest/sql -print 21-> $system_content -if $system_content != @{"status":"error","code":866,"desc":"Table does not exist"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d1.t1 (ts timestamp, speed int)' 127.0.0.1:7111/rest/sql -print 22-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:7111/rest/sql -print 23-> $system_content -if $system_content != @{"status":"succ","head":["ts","speed"],"column_meta":[["ts",9,8],["speed",4,4]],"data":[],"rows":0}@ then - return -1 -endi - -#24 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:41.022', 1)" 127.0.0.1:7111/rest/sql -print 24-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[1]],"rows":1}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:7111/rest/sql -print 25-> $system_content -if $system_content != @{"status":"succ","head":["ts","speed"],"column_meta":[["ts",9,8],["speed",4,4]],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then - return -1 -endi - -#26 -print 25-> no print -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:42.022', 2)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:43.022', 3)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:44.022', 4)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:45.022', 5)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:46.022', 6)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:47.022', 7)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:48.022', 8)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:49.022', 9)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:50.022', 10)" 127.0.0.1:7111/rest/sql - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d1.t1 values('2017-12-25 21:28:51.022', 11)" 127.0.0.1:7111/rest/sql - -#27 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d1.t1 ' 127.0.0.1:7111/rest/sql -print 27-> $system_content -if $system_content != @{"status":"succ","head":["ts","speed"],"column_meta":[["ts",9,8],["speed",4,4]],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10],["2017-12-25 21:28:51.022",11]],"rows":11}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database d2' 127.0.0.1:7111/rest/sql -print 28-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' create table d2.t1 (ts timestamp, speed int)' 127.0.0.1:7111/rest/sql -print 29-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then - return -1 -endi - -#30 -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d "insert into d2.t1 values('2017-12-25 21:28:41.022', 1)" 127.0.0.1:7111/rest/sql -print 30-> $system_content -if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[1]],"rows":1}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d ' select * from d2.t1 ' 127.0.0.1:7111/rest/sql -print 31-> $system_content -if $system_content != @{"status":"succ","head":["ts","speed"],"column_meta":[["ts",9,8],["speed",4,4]],"data":[["2017-12-25 21:28:41.022",1]],"rows":1}@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/http/restful_insert.sim b/tests/script/general/http/restful_insert.sim deleted file mode 100644 index b77a1dd49785bf9ad1f86e803f63e2ba0e40a8d7..0000000000000000000000000000000000000000 --- a/tests/script/general/http/restful_insert.sim +++ /dev/null @@ -1,53 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data -sql create database d1 -sql use d1 - -sql create table d1.table_rest0 (ts timestamp, i int) -sql create table d1.table_rest1 (ts timestamp, i int) -sql create table d1.table_rest2 (ts timestamp, i int) -sql create table d1.table_rest3 (ts timestamp, i int) -sql create table d1.table_rest4 (ts timestamp, i int) -sql create table d1.table_rest5 (ts timestamp, i int) -sql create table d1.table_rest6 (ts timestamp, i int) -sql create table d1.table_rest7 (ts timestamp, i int) -sql create table d1.table_rest8 (ts timestamp, i int) -sql create table d1.table_rest9 (ts timestamp, i int) - -print =============== step2 - login - -system_content curl 127.0.0.1:7111/rest/login/root/taosdata -print curl 127.0.0.1:7111/rest/login/root/taosdata -----> $system_content - -if $system_content != {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"} then - return -1 -endi - -print =============== step3 - query data - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into d1.table_rest1 values('now+1s', 1) d1.table_rest2 values('now+1s', 1) d1.table_rest3 values('now+1s', 1) d1.table_rest4 values('now+1s', 1) ' 127.0.0.1:7111/rest/sql - -print =============== step5 - query data - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_rest1' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/restful_limit.sim b/tests/script/general/http/restful_limit.sim deleted file mode 100644 index 48a4fdf7d3f90d8d58337992b0b8198cb43e953c..0000000000000000000000000000000000000000 --- a/tests/script/general/http/restful_limit.sim +++ /dev/null @@ -1,46 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - prepare data - -$dbPrefix = db -$tbPrefix = tb -$mtPrefix = st - -print =============== step1 -$i = 0 -$db = $dbPrefix . $i -$mt = $mtPrefix . $i - -sql create database $db -sql use $db -sql create table $mt (ts timestamp, tbcol bigint, t1 bigint, t2 bigint, t3 bigint, t4 bigint, t5 bigint, t6 bigint, t7 bigint, t8 bigint, t9 bigint, t0 nchar(20)) TAGS(tgcol bigint) - -$i = 0 -while $i < 2 - $tb = $tbPrefix . $i - sql create table $tb using $mt tags( 0 ) - $x = 0 - while $x < 2000 - $ms = $x . m - sql insert into $tb values (now + $ms , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '浣犲ソ' ) - $x = $x + 1 - endw - $i = $i + 1 -endw - -system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from db0.st0 limit 100' 127.0.0.1:7111/rest/sql -print curl 127.0.0.1:7111/rest/sql -----> $system_content - -#system_content curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d "select * from db0.st0 where tbname in ('tb0', 'tb1') limit 1000" 127.0.0.1:7111/rest/sql -#print curl 127.0.0.1:7111/rest/sql -----> $system_content - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/http/taos.json b/tests/script/general/http/taos.json deleted file mode 100644 index abc25f19a2e43282a4e474b95387ccf9a6d6b077..0000000000000000000000000000000000000000 --- a/tests/script/general/http/taos.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "hostIp": "192.168.100.128", - "connNum": 1, - "insertModel": "insertTable", - "waitTime": 0, - "tableDesc": "ts timestamp, i int", - "tablePrefix": "t", - "tablePerConn": 1, - "tableCreate": true, - "tableStart": 1, - "dbName": "db", - "dbReplica": 1, - "dbKeep": 3650, - "dbDays": 7, - "metricsName": "mt", - "tagNum": 10, - "dataNum": 1000, - "dataBegin": 1485878400000, - "dataInterval": 1000, - "dataBatch": 1000, - "dataInsert": true, - "dataRandom": false -} diff --git a/tests/script/general/http/taos_cloud.json b/tests/script/general/http/taos_cloud.json deleted file mode 100644 index c54186b65c58d7a390bb6bc6dbb6130fb09e4b70..0000000000000000000000000000000000000000 --- a/tests/script/general/http/taos_cloud.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "hostIp": "192.168.100.128", - "connNum": 10, - "insertModel": "insertTable", - "waitTime": 0, - "tableDesc": "ts timestamp, i int", - "tablePrefix": "t", - "tablePerConn": 1, - "tableCreate": true, - "tableStart": 1, - "dbName": "db", - "dbKeep": 3650, - "metricsName": "mt", - "tagNum": 10, - "dataNum": 1000, - "dataBegin": 1517414400000, - "dataInterval": 1000, - "dataBatch": 1000, - "dataInsert": true, - "dataRandom": false -} diff --git a/tests/script/general/http/telegraf.json b/tests/script/general/http/telegraf.json deleted file mode 100644 index baf7c5e71148ab360119523740357707eb637b05..0000000000000000000000000000000000000000 --- a/tests/script/general/http/telegraf.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "hostIp": "192.168.0.1", - "machineNum": 100, - "loopNum": 100, - "dbName": "db", - "dataBegin": 1485878400000 -} diff --git a/tests/script/general/http/telegraf.req b/tests/script/general/http/telegraf.req deleted file mode 100644 index 1a3b73299974b31549a218e448e3278a3803d564..0000000000000000000000000000000000000000 --- a/tests/script/general/http/telegraf.req +++ /dev/null @@ -1,621 +0,0 @@ -{ - "metrics": [{ - "fields": { - "result_code": 2, - "result_type": "connection_failed" - }, - "name": "net_response", - "tags": { - "host": "panshi-gsl", - "port": "80", - "protocol": "tcp", - "result": "connection_failed", - "server": "localhost" - }, - "timestamp": 1536750390000 - },{ - "fields": { - "load1": 0.27, - "load15": 0.09, - "load5": 0.22, - "n_cpus": 4, - "n_users": 4 - }, - "name": "system", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - },{ - "fields": { - "uptime": 122 - }, - "name": "system", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "uptime_format": " 0:02" - }, - "name": "system", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "bytes_recv": 19964, - "bytes_sent": 11077, - "drop_in": 0, - "drop_out": 0, - "err_in": 0, - "err_out": 0, - "packets_recv": 237, - "packets_sent": 124 - }, - "name": "net", - "tags": { - "host": "panshi-gsl", - "interface": "eth0" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "usage_guest": 0, - "usage_guest_nice": 0, - "usage_idle": 99.39879759519036, - "usage_iowait": 0, - "usage_irq": 0, - "usage_nice": 0, - "usage_softirq": 0, - "usage_steal": 0, - "usage_system": 0.300601202404812, - "usage_user": 0.30060120240480753 - }, - "name": "cpu", - "tags": { - "cpu": "cpu0", - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "usage_guest": 0, - "usage_guest_nice": 0, - "usage_idle": 99.79959919839683, - "usage_iowait": 0, - "usage_irq": 0, - "usage_nice": 0, - "usage_softirq": 0, - "usage_steal": 0, - "usage_system": 0.2004008016032065, - "usage_user": 0 - }, - "name": "cpu", - "tags": { - "cpu": "cpu1", - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "usage_guest": 0, - "usage_guest_nice": 0, - "usage_idle": 99.7999999999999, - "usage_iowait": 0, - "usage_irq": 0, - "usage_nice": 0, - "usage_softirq": 0, - "usage_steal": 0, - "usage_system": 0.10000000000000217, - "usage_user": 0.09999999999999995 - }, - "name": "cpu", - "tags": { - "cpu": "cpu2", - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "usage_guest": 0, - "usage_guest_nice": 0, - "usage_idle": 99.7999999999999, - "usage_iowait": 0, - "usage_irq": 0, - "usage_nice": 0, - "usage_softirq": 0.09999999999999988, - "usage_steal": 0, - "usage_system": 0.09999999999999995, - "usage_user": 0 - }, - "name": "cpu", - "tags": { - "cpu": "cpu3", - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "usage_guest": 0, - "usage_guest_nice": 0, - "usage_idle": 99.74956173303289, - "usage_iowait": 0, - "usage_irq": 0, - "usage_nice": 0, - "usage_softirq": 0.025043826696719312, - "usage_steal": 0, - "usage_system": 0.12521913348359823, - "usage_user": 0.10017530678687725 - }, - "name": "cpu", - "tags": { - "cpu": "cpu-total", - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "icmp_inaddrmaskreps": 0, - "icmp_inaddrmasks": 0, - "icmp_indestunreachs": 1, - "icmp_inechoreps": 0, - "icmp_inechos": 0, - "icmp_inerrors": 0, - "icmp_inmsgs": 1, - "icmp_inparmprobs": 0, - "icmp_inredirects": 0, - "icmp_insrcquenchs": 0, - "icmp_intimeexcds": 0, - "icmp_intimestampreps": 0, - "icmp_intimestamps": 0, - "icmp_outaddrmaskreps": 0, - "icmp_outaddrmasks": 0, - "icmp_outdestunreachs": 5, - "icmp_outechoreps": 0, - "icmp_outechos": 0, - "icmp_outerrors": 0, - "icmp_outmsgs": 5, - "icmp_outparmprobs": 0, - "icmp_outredirects": 0, - "icmp_outsrcquenchs": 0, - "icmp_outtimeexcds": 0, - "icmp_outtimestampreps": 0, - "icmp_outtimestamps": 0, - "icmpmsg_intype3": 1, - "icmpmsg_outtype3": 5, - "ip_defaultttl": 64, - "ip_forwarding": 2, - "ip_forwdatagrams": 0, - "ip_fragcreates": 0, - "ip_fragfails": 0, - "ip_fragoks": 0, - "ip_inaddrerrors": 0, - "ip_indelivers": 132, - "ip_indiscards": 0, - "ip_inhdrerrors": 0, - "ip_inreceives": 132, - "ip_inunknownprotos": 0, - "ip_outdiscards": 0, - "ip_outnoroutes": 40, - "ip_outrequests": 134, - "ip_reasmfails": 0, - "ip_reasmoks": 0, - "ip_reasmreqds": 0, - "ip_reasmtimeout": 0, - "tcp_activeopens": 11, - "tcp_attemptfails": 11, - "tcp_currestab": 0, - "tcp_estabresets": 0, - "tcp_inerrs": 0, - "tcp_insegs": 22, - "tcp_maxconn": -1, - "tcp_outrsts": 11, - "tcp_outsegs": 22, - "tcp_passiveopens": 0, - "tcp_retranssegs": 0, - "tcp_rtoalgorithm": 1, - "tcp_rtomax": 120000, - "tcp_rtomin": 200, - "udp_indatagrams": 101, - "udp_inerrors": 0, - "udp_noports": 5, - "udp_outdatagrams": 109, - "udp_rcvbuferrors": 0, - "udp_sndbuferrors": 0, - "udplite_indatagrams": 0, - "udplite_inerrors": 0, - "udplite_noports": 0, - "udplite_outdatagrams": 0, - "udplite_rcvbuferrors": 0, - "udplite_sndbuferrors": 0 - }, - "name": "net", - "tags": { - "host": "panshi-gsl", - "interface": "all" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "io_time": 44, - "iops_in_progress": 0, - "read_bytes": 569344, - "read_time": 44, - "reads": 108, - "weighted_io_time": 44, - "write_bytes": 0, - "write_time": 0, - "writes": 0 - }, - "name": "diskio", - "tags": { - "host": "panshi-gsl", - "name": "sda5" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "io_time": 4900, - "iops_in_progress": 0, - "read_bytes": 262294528, - "read_time": 13607, - "reads": 8122, - "weighted_io_time": 27970, - "write_bytes": 12054528, - "write_time": 14369, - "writes": 1073 - }, - "name": "diskio", - "tags": { - "host": "panshi-gsl", - "name": "sda" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "io_time": 4874, - "iops_in_progress": 0, - "read_bytes": 261522432, - "read_time": 13538, - "reads": 7963, - "weighted_io_time": 27901, - "write_bytes": 12054528, - "write_time": 14369, - "writes": 1073 - }, - "name": "diskio", - "tags": { - "host": "panshi-gsl", - "name": "sda1" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "io_time": 15, - "iops_in_progress": 0, - "read_bytes": 2048, - "read_time": 15, - "reads": 2, - "weighted_io_time": 15, - "write_bytes": 0, - "write_time": 0, - "writes": 0 - }, - "name": "diskio", - "tags": { - "host": "panshi-gsl", - "name": "sda2" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "free": 4106956800, - "inodes_free": 526746, - "inodes_total": 752192, - "inodes_used": 225446, - "total": 12112691200, - "used": 7390433280, - "used_percent": 64.27922535963918 - }, - "name": "disk", - "tags": { - "device": "rootfs", - "fstype": "rootfs", - "host": "panshi-gsl", - "mode": "rw", - "path": "/" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "free": 4106956800, - "inodes_free": 526746, - "inodes_total": 752192, - "inodes_used": 225446, - "total": 12112691200, - "used": 7390433280, - "used_percent": 64.27922535963918 - }, - "name": "disk", - "tags": { - "device": "disk/by-uuid/d4becabf-b49c-4c1c-a4ea-b2f593018766", - "fstype": "ext3", - "host": "panshi-gsl", - "mode": "rw", - "path": "/" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "boot_time": 1536750268, - "context_switches": 135890, - "entropy_avail": 514, - "interrupts": 112317, - "processes_forked": 3595 - }, - "name": "kernel", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "active": 211845120, - "available": 3829399552, - "available_percent": 92.37877479393148, - "buffered": 12083200, - "cached": 254320640, - "commit_limit": 2648322048, - "committed_as": 549027840, - "dirty": 49152, - "free": 3562995712, - "high_free": 0, - "high_total": 0, - "huge_page_size": 2097152, - "huge_pages_free": 0, - "huge_pages_total": 0, - "inactive": 214351872, - "low_free": 0, - "low_total": 0, - "mapped": 81797120, - "page_tables": 13062144, - "shared": 2682880, - "slab": 33386496, - "swap_cached": 0, - "swap_free": 575660032, - "swap_total": 575660032, - "total": 4145324032, - "used": 315924480, - "used_percent": 7.621225206068523, - "vmalloc_chunk": 35184198369280, - "vmalloc_total": 35184372087808, - "vmalloc_used": 168906752, - "wired": 0, - "write_back": 0, - "write_back_tmp": 0 - }, - "name": "mem", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "IpExtInBcastOctets": 1291, - "IpExtInBcastPkts": 6, - "IpExtInMcastOctets": 0, - "IpExtInMcastPkts": 0, - "IpExtInNoRoutes": 0, - "IpExtInOctets": 12160, - "IpExtInTruncatedPkts": 0, - "IpExtOutBcastOctets": 0, - "IpExtOutBcastPkts": 0, - "IpExtOutMcastOctets": 0, - "IpExtOutMcastPkts": 0, - "IpExtOutOctets": 9881, - "TcpExtArpFilter": 0, - "TcpExtDelayedACKLocked": 0, - "TcpExtDelayedACKLost": 0, - "TcpExtDelayedACKs": 0, - "TcpExtEmbryonicRsts": 0, - "TcpExtListenDrops": 0, - "TcpExtListenOverflows": 0, - "TcpExtLockDroppedIcmps": 0, - "TcpExtOfoPruned": 0, - "TcpExtOutOfWindowIcmps": 0, - "TcpExtPAWSActive": 0, - "TcpExtPAWSEstab": 0, - "TcpExtPAWSPassive": 0, - "TcpExtPruneCalled": 0, - "TcpExtRcvPruned": 0, - "TcpExtSyncookiesFailed": 0, - "TcpExtSyncookiesRecv": 0, - "TcpExtSyncookiesSent": 0, - "TcpExtTCPAbortFailed": 0, - "TcpExtTCPAbortOnClose": 0, - "TcpExtTCPAbortOnData": 0, - "TcpExtTCPAbortOnLinger": 0, - "TcpExtTCPAbortOnMemory": 0, - "TcpExtTCPAbortOnSyn": 0, - "TcpExtTCPAbortOnTimeout": 0, - "TcpExtTCPDSACKIgnoredNoUndo": 0, - "TcpExtTCPDSACKIgnoredOld": 0, - "TcpExtTCPDSACKOfoRecv": 0, - "TcpExtTCPDSACKOfoSent": 0, - "TcpExtTCPDSACKOldSent": 0, - "TcpExtTCPDSACKRecv": 0, - "TcpExtTCPDSACKUndo": 0, - "TcpExtTCPDirectCopyFromBacklog": 0, - "TcpExtTCPDirectCopyFromPrequeue": 0, - "TcpExtTCPFACKReorder": 0, - "TcpExtTCPFastRetrans": 0, - "TcpExtTCPForwardRetrans": 0, - "TcpExtTCPFullUndo": 0, - "TcpExtTCPHPAcks": 0, - "TcpExtTCPHPHits": 0, - "TcpExtTCPHPHitsToUser": 0, - "TcpExtTCPLoss": 0, - "TcpExtTCPLossFailures": 0, - "TcpExtTCPLossUndo": 0, - "TcpExtTCPLostRetransmit": 0, - "TcpExtTCPMD5NotFound": 0, - "TcpExtTCPMD5Unexpected": 0, - "TcpExtTCPMemoryPressures": 0, - "TcpExtTCPPartialUndo": 0, - "TcpExtTCPPrequeueDropped": 0, - "TcpExtTCPPrequeued": 0, - "TcpExtTCPPureAcks": 0, - "TcpExtTCPRcvCollapsed": 0, - "TcpExtTCPRenoFailures": 0, - "TcpExtTCPRenoRecovery": 0, - "TcpExtTCPRenoRecoveryFail": 0, - "TcpExtTCPRenoReorder": 0, - "TcpExtTCPSACKDiscard": 0, - "TcpExtTCPSACKReneging": 0, - "TcpExtTCPSACKReorder": 0, - "TcpExtTCPSackFailures": 0, - "TcpExtTCPSackMerged": 0, - "TcpExtTCPSackRecovery": 0, - "TcpExtTCPSackRecoveryFail": 0, - "TcpExtTCPSackShiftFallback": 0, - "TcpExtTCPSackShifted": 0, - "TcpExtTCPSchedulerFailed": 0, - "TcpExtTCPSlowStartRetrans": 0, - "TcpExtTCPSpuriousRTOs": 0, - "TcpExtTCPTSReorder": 0, - "TcpExtTCPTimeouts": 0, - "TcpExtTW": 0, - "TcpExtTWKilled": 0, - "TcpExtTWRecycled": 0 - }, - "name": "nstat", - "tags": { - "host": "panshi-gsl", - "name": "netstat" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "IcmpInAddrMaskReps": 0, - "IcmpInAddrMasks": 0, - "IcmpInDestUnreachs": 1, - "IcmpInEchoReps": 0, - "IcmpInEchos": 0, - "IcmpInErrors": 0, - "IcmpInMsgs": 1, - "IcmpInParmProbs": 0, - "IcmpInRedirects": 0, - "IcmpInSrcQuenchs": 0, - "IcmpInTimeExcds": 0, - "IcmpInTimestampReps": 0, - "IcmpInTimestamps": 0, - "IcmpMsgInType3": 1, - "IcmpMsgOutType3": 5, - "IcmpOutAddrMaskReps": 0, - "IcmpOutAddrMasks": 0, - "IcmpOutDestUnreachs": 5, - "IcmpOutEchoReps": 0, - "IcmpOutEchos": 0, - "IcmpOutErrors": 0, - "IcmpOutMsgs": 5, - "IcmpOutParmProbs": 0, - "IcmpOutRedirects": 0, - "IcmpOutSrcQuenchs": 0, - "IcmpOutTimeExcds": 0, - "IcmpOutTimestampReps": 0, - "IcmpOutTimestamps": 0, - "IpDefaultTTL": 64, - "IpForwDatagrams": 0, - "IpForwarding": 2, - "IpFragCreates": 0, - "IpFragFails": 0, - "IpFragOKs": 0, - "IpInAddrErrors": 0, - "IpInDelivers": 132, - "IpInDiscards": 0, - "IpInHdrErrors": 0, - "IpInReceives": 132, - "IpInUnknownProtos": 0, - "IpOutDiscards": 0, - "IpOutNoRoutes": 40, - "IpOutRequests": 134, - "IpReasmFails": 0, - "IpReasmOKs": 0, - "IpReasmReqds": 0, - "IpReasmTimeout": 0, - "TcpActiveOpens": 12, - "TcpAttemptFails": 12, - "TcpCurrEstab": 0, - "TcpEstabResets": 0, - "TcpInErrs": 0, - "TcpInSegs": 24, - "TcpMaxConn": -1, - "TcpOutRsts": 12, - "TcpOutSegs": 24, - "TcpPassiveOpens": 0, - "TcpRetransSegs": 0, - "TcpRtoAlgorithm": 1, - "TcpRtoMax": 120000, - "TcpRtoMin": 200, - "UdpInDatagrams": 101, - "UdpInErrors": 0, - "UdpLiteInDatagrams": 0, - "UdpLiteInErrors": 0, - "UdpLiteNoPorts": 0, - "UdpLiteOutDatagrams": 0, - "UdpLiteRcvbufErrors": 0, - "UdpLiteSndbufErrors": 0, - "UdpNoPorts": 5, - "UdpOutDatagrams": 109, - "UdpRcvbufErrors": 0, - "UdpSndbufErrors": 0 - }, - "name": "nstat", - "tags": { - "host": "panshi-gsl", - "name": "snmp" - }, - "timestamp": 1536750390000 - }, - { - "fields": { - "blocked": 0, - "dead": 0, - "idle": 0, - "paging": 0, - "running": 1, - "sleeping": 181, - "stopped": 0, - "total": 182, - "total_threads": 280, - "unknown": 0, - "zombies": 0 - }, - "name": "processes", - "tags": { - "host": "panshi-gsl" - }, - "timestamp": 1536750390000 - }] -} \ No newline at end of file diff --git a/tests/script/general/http/telegraf.sim b/tests/script/general/http/telegraf.sim deleted file mode 100644 index 9fc153b2329bac70efe2506814af4a60b89966ae..0000000000000000000000000000000000000000 --- a/tests/script/general/http/telegraf.sim +++ /dev/null @@ -1,292 +0,0 @@ -system sh/stop_dnodes.sh -sleep 2000 -system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 -system sh/cfg.sh -n dnode1 -c telegrafUseFieldNum -v 0 -system sh/exec.sh -n dnode1 -s start - -sleep 2000 -sql connect - -print ============================ dnode1 start - -print =============== step1 - parse -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/ -print $system_content - -if $system_content != @{"status":"error","code":4448,"desc":"database name can not be null"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_admin' -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/ -print $system_content - -if $system_content != @{"status":"error","code":4448,"desc":"database name can not be null"}@ then - return -1 -endi - -system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_admin' -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/d123456789012345678901234567890123456 -print $system_content - -if $system_content != @{"status":"error","code":4449,"desc":"database name too long"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '[]' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4453,"desc":"metric name not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4453,"desc":"metric name not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '[{}]' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4453,"desc":"metric name not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"metrics": []}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4451,"desc":"metrics size is 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"metrics": [{}]}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4453,"desc":"metric name not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"metrics": 12}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4451,"desc":"metrics size is 0"}@ then - return -1 -endi - -#system_content curl -u root:taosdata -d '{"metrics": [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -#print $system_content - -#if $system_content != @{"status":"error","code":4452,"desc":"metrics size can not more than 50"}@ then -# return -1 -#endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4453,"desc":"metric name not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":111,"tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4454,"desc":"metric name type should be string"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4455,"desc":"metric name length is 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234a1234567890123456789012345678901234","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4456,"desc":"metric name length too long"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"}}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4457,"desc":"timestamp not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":""}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4458,"desc":"timestamp type should be integer"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":-1}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4459,"desc":"timestamp value smaller than 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4460,"desc":"tags not find"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4461,"desc":"tags size is 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":"","timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4461,"desc":"tags size is 0"}@ then - return -1 -endi - -#system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor","host":"windows","instance":"1","objectname":"Processor","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata -#print $system_content - -#if $system_content != @{"status":"error","code":4461,"desc":"tags size too long"}@ then -# return -1 -#endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4461,"desc":"tags size is 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"":"windows"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4464,"desc":"tag name is null"}@ then - return -1 -endi - -#system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host111111111111222222222222222222222":""},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -#print $system_content - -#if $system_content != @{"status":"error","code":4465,"desc":"tag name length too long"}@ then -# return -1 -#endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":true},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4466,"desc":"tag value type should be number or string"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":""},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4467,"desc":"tag value is null"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"5022":"111"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4468,"desc":"table is null"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222host111111111111222222222222222222222"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4469,"desc":"table name length too long"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4471,"desc":"fields size is 0"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4474,"desc":"field name is null"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":"","Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4477,"desc":"field value is null"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":true,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1535784122}' 127.0.0.1:7111/telegraf/db/root/taosdata1 -print $system_content - -if $system_content != @{"status":"error","code":4476,"desc":"field value type should be number or string"}@ then - return -1 -endi - -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1564641722000}' 127.0.0.1:7111/telegraf/db - -print $system_content - -if $system_content != @{"metrics":[{"metric":"win_cpu","stable":"win_cpu","table":"win_cpu_windows_1_Processor","timestamp":"1564641722000","affected_rows":1,"status":"succ"}]}@ then - return -1 -endi - -sleep 2000 - -print =============== step2 - insert single data -system_content curl -u root:taosdata -d '{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"windows","instance":"1","objectname":"Processor"},"timestamp":1564641722000}' 127.0.0.1:7111/telegraf/db/ - -print $system_content - -#if $system_content != @{"metrics":[{"metric":"win_cpu","stable":"win_cpu","table":"win_cpu_windows_1_Processor","timestamp":"1564641722000","affected_rows":1,"status":"succ"}]}@ then -# return -1 -#endi - -system_content curl -u root:taosdata -d 'select * from db.win_cpu_windows_1_Processor' 127.0.0.1:7111/rest/sql/ - -print $system_content - -#if $system_content != @{"status":"succ","head":["ts","f_percent_dpc_time","f_percent_idle_time","f_percent_interrupt_time","f_percent_privileged_time","f_percent_processor_time","f_percent_user_time"],"data":[["2019-08-01 06:42:02.000",0.000000000,95.598305000,0.000000000,0.000000000,0.000000000,0.000000000]],"rows":1}@ then -# return -1 -#endi - -print =============== step3 - multi-query data -system_content curl -u root:taosdata -d '{"metrics": [{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"window1","instance":"1","objectname":"Processor"},"timestamp":1564641723000},{"fields":{"Percent_DPC_Time":0,"Percent_Idle_Time":95.59830474853516,"Percent_Interrupt_Time":0,"Percent_Privileged_Time":0,"Percent_Processor_Time":0,"Percent_User_Time":0},"name":"win_cpu","tags":{"host":"window2","instance":"1","objectname":"Processor"},"timestamp":1564641723000}]}' 127.0.0.1:7111/telegraf/db/ - -print $system_content - -if $system_content != @{"metrics":[{"metric":"win_cpu","stable":"win_cpu","table":"win_cpu_window1_1_Processor","timestamp":"1564641723000","affected_rows":1,"status":"succ"},{"metric":"win_cpu","stable":"win_cpu","table":"win_cpu_window2_1_Processor","timestamp":"1564641723000","affected_rows":1,"status":"succ"}]}@ then - return -1 -endi - -system_content curl -u root:taosdata -d 'select * from db.win_cpu_window1_1_Processor' 127.0.0.1:7111/rest/sql/ - -print $system_content - -#if $system_content != @{"status":"succ","head":["ts","f_percent_dpc_time","f_percent_idle_time","f_percent_interrupt_time","f_percent_privileged_time","f_percent_processor_time","f_percent_user_time"],"data":[["2019-08-01 14:42:03.000",0.000000000,95.598305000,0.000000000,0.000000000,0.000000000,0.000000000]],"rows":1}@ then -# return -1 -#endi - -system_content curl -u root:taosdata -d 'select count(*) from db.win_cpu' 127.0.0.1:7111/rest/sql/ - -print $system_content - -if $system_content != @{"status":"succ","head":["count(*)"],"column_meta":[["count(*)",5,8]],"data":[[3]],"rows":1}@ then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/http/telegrafTest.go b/tests/script/general/http/telegrafTest.go deleted file mode 100644 index caa6493c82be41a46f7e36959fe50d4cf2d0e03c..0000000000000000000000000000000000000000 --- a/tests/script/general/http/telegrafTest.go +++ /dev/null @@ -1,238 +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 . - */ - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "io/ioutil" - "net/http" - "os" - "sync" - "sync/atomic" - "time" - "flag" -) - -var ( - token string - url string - config Config - request int64 - period int64 - errorNum int64 - template string -) - -type Config struct { - HostIp string `json:"hostIp"` - MachineNum int `json:"machineNum"` - LoopNum int `json:"loopNum"` - DbName string `json:"dbName"` - DataBegin int64 `json:"dataBegin"` -} - -type TokenResult struct { - Status string `json:"status"` - Code int `json:"code"` - Desc string `json:"desc"` -} - -type JsonResult struct { - Status string `json:"status"` - Code int `json:"code"` -} - -func readConf(filename string) { - file, err := os.Open(filename) - if err != nil { - println("%s not found", filename) - panic(err) - } - defer file.Close() - - dec := json.NewDecoder(file) - err = dec.Decode(&config) - if err != nil { - println("%s parse error", filename) - panic(err) - } - - request = 0 - period = 0 - errorNum = 0 - - fmt.Println("================config parameters======================") - fmt.Println("HostIp:", config.HostIp) - fmt.Println("MachineNum:", config.MachineNum) - fmt.Println("LoopNum:", config.LoopNum) - fmt.Println("dbName:", config.DbName) - fmt.Println("dataBegin:", config.DataBegin) - - fmt.Println("================http token=============================") - token, err = getToken() - url = fmt.Sprintf("http://%s:%d/telegraf/%s", config.HostIp, 6020, config.DbName) - - fmt.Println("httpToken:", token) - fmt.Println("httpUrl:", url) - - if err != nil { - panic(err) - } -} - -func readReq(filename string) { - file, err := os.Open(filename) - if err != nil { - println("%s not found", filename) - panic(err) - } - defer file.Close() - - data, _ := ioutil.ReadAll(file) - - template = string(data[:]) - - //fmt.Println(template) -} - -func getToken() (string, error) { - resp, err := http.Get(fmt.Sprintf("http://%s:%d/rest/login/%s/%s", config.HostIp, 6020, "root", "taosdata")) - if err != nil { - return "", err - } - - defer resp.Body.Close() - - var tokenResult TokenResult - - data, err := ioutil.ReadAll(resp.Body) - - if err != nil { - return "", err - } - - err = json.Unmarshal(data, &tokenResult) - if err != nil { - return "", err - } - - if tokenResult.Status != "succ" { - fmt.Println("get http token failed") - fmt.Println(tokenResult) - return "", err - } - - return tokenResult.Desc, nil -} - -func exec(client *http.Client, sql string) { - for times := 0; times < 10; times++ { - - req, err1 := http.NewRequest("POST", url, bytes.NewReader([]byte(sql))) - if err1 != nil { - continue - } - req.Header.Add("Authorization", "Taosd "+token) - - begin := time.Now() - resp, err := client.Do(req) - - if err != nil { - continue - } - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println(data) - resp.Body.Close() - continue - } - - spend := (time.Since(begin).Nanoseconds()) - - var jsonResult JsonResult - err = json.Unmarshal(data, &jsonResult) - if err != nil { - fmt.Println("parse json error: ", string(data[:])) - resp.Body.Close() - continue - } - - - atomic.AddInt64(&request, 1) - atomic.AddInt64(&period, spend) - - if request%1000 == 0 && request != 0 { - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.MachineNum) - dps := qps * float64(22) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) - } - return - } - //fmt.Println("xxxx>sql:", sql, ", retryTimes:", 10) - fmt.Println("exec sql failed") - errorNum++ -} - -func writeData(wg *sync.WaitGroup, tbIndex int) { - defer wg.Done() - client := &http.Client{} - - tbName := fmt.Sprintf("t%d", tbIndex) - - for j := 0; j < config.LoopNum; j++ { - tmVal := fmt.Sprintf("%d", int64(j)*int64(10000) + config.DataBegin) - //fmt.Println(tmVal) - - req1 := strings.Replace(template, "panshi-gsl", tbName, -1) - req2 := strings.Replace(req1, "1536750390000", tmVal, -1) - - //fmt.Println(req2) - exec(client, req2) - } -} - -func main() { - filename := flag.String("config", "telegraf.json", "config file name") - - flag.Parse() - - readReq("telegraf.req") - - readConf(*filename) - - fmt.Println("\n================telegraf test start======================") - - var wg sync.WaitGroup - - for i := 0; i < config.MachineNum; i++ { - wg.Add(1) - go writeData(&wg, i) - } - - wg.Wait() - - fmt.Println("\n================telegraf test stop ======================") - - requestAvg := float64(period) / float64(1000000) / float64(request) - qps := float64(1000) / float64(requestAvg) * float64(config.MachineNum) - dps := qps * float64(22) - fmt.Println("====== req:", request, ", error:", errorNum, ", qps:", int64(qps), ", wait:", int64(requestAvg), "ms", ", data per second:", int64(dps)) -} diff --git a/tests/script/general/http/telegraf_help.txt b/tests/script/general/http/telegraf_help.txt deleted file mode 100644 index a2e6d6e49c9348b8aa257f0362c0baf0875ada01..0000000000000000000000000000000000000000 --- a/tests/script/general/http/telegraf_help.txt +++ /dev/null @@ -1,24 +0,0 @@ -1.编译 -将main.go编译成可执行文件,telegrafTest -2.执行 -./telegrafTest -3.参数 telegraf.json的配置文件 - hostIp TDengine机器IP地址 - machineNum 模拟的机器数量 - loopNum 每个机器发送请求的次数 - dbName 创建的数据库名称 - dataBegin 生成模拟数据的开始时间戳 -4.telegraf.req(通常不变) - 1)替换panshi-gsl和1536750380000这两个字符串,生成http请求 - 2)通过http发送给TDengine -5.注意 - 1)修改配置文件/etc/taos/taos.cfg - httpDebugFlag 设置为131(131-httpDebug,135-httpDebug) - httpMaxThreads 按照机器情况设置,设置范围为(1-cpu cores) - httpCacheSessions 设置为可能的http连接的2倍 - maxVnodeConnections 设置为100000 - maxMeterConnections 设置为100000 - maxShellConns 设置为100000 - maxMgmtConnections 设置为100000 - 2)设置linux参数,例如 - ulimit -n 600000 \ No newline at end of file diff --git a/tests/script/general/http/testSuite.sim b/tests/script/general/http/testSuite.sim deleted file mode 100644 index f35362bf070a11e2fa2f1dd870acfe2074c0cbf5..0000000000000000000000000000000000000000 --- a/tests/script/general/http/testSuite.sim +++ /dev/null @@ -1,10 +0,0 @@ -run general/http/autocreate.sim -run general/http/chunked.sim -run general/http/restful.sim -run general/http/restful_insert.sim -run general/http/restful_limit.sim -run general/http/restful_full.sim -run general/http/prepare.sim -run general/http/telegraf.sim -run general/http/grafana_bug.sim -run general/http/grafana.sim diff --git a/tests/script/general/table/basic1.sim b/tests/script/general/table/basic1.sim index c26c3c33e4102723805925cccb61c63d01c866b8..f2341a84ce3bffb71a8789bd73b1010e20a3c485 100644 --- a/tests/script/general/table/basic1.sim +++ b/tests/script/general/table/basic1.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start -sleep 2000 sql connect print =============== create database @@ -13,29 +12,43 @@ endi print $data00 $data01 $data02 -print =============== create normal table -sql create table d1.n1 (ts timestamp, i int) -sql show d1.tables +sql use d1 + +print =============== create super table +sql create table st (ts timestamp, i int) tags (j int) +sql show stables if $rows != 1 then return -1 endi print $data00 $data01 $data02 -print =============== create super table -sql create table d1.st (ts timestamp, i int) tags (j int) -sql show d1.stables +sql create table st2 (ts timestamp, i float) tags (j int) +sql show stables +if $rows != 2 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data12 + +sql drop table st2 + +sql show stables if $rows != 1 then return -1 endi print $data00 $data01 $data02 +print $data10 $data11 $data12 print =============== create child table -sql create table d1.c1 using d1.st tags(1) -sql create table d1.c2 using d1.st tags(2) -sql show d1.tables -if $rows != 3 then +sql create table c1 using st tags(1) +sql create table c2 using st tags(2) + +return +sql show tables +if $rows != 2 then return -1 endi @@ -44,12 +57,12 @@ print $data10 $data11 $data22 print $data20 $data11 $data22 print =============== insert data -sql insert into d1.n1 values(now+1s, 1) -sql insert into d1.n1 values(now+2s, 2) -sql insert into d1.n1 values(now+3s, 3) +sql insert into c1 values(now+1s, 1) +sql insert into c1 values(now+2s, 2) +sql insert into c1 values(now+3s, 3) print =============== query data -sql select * from d1.n1 +sql select * from c1 if $rows != 3 then return -1 endi diff --git a/tests/script/general/user/testSuite.sim b/tests/script/general/user/testSuite.sim deleted file mode 100644 index b4bf52cfd1dfd13e99306110a63a19e6dc8bb230..0000000000000000000000000000000000000000 --- a/tests/script/general/user/testSuite.sim +++ /dev/null @@ -1,6 +0,0 @@ -run general/user/basic1.sim -run general/user/monitor.sim -run general/user/pass_alter.sim -run general/user/pass_len.sim -run general/user/user_create.sim -run general/user/user_len.sim \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2408faefa0418b83ab7e1fb715e81ee4fa6a4caf..f960abb4e02021e05a6767a5ebe8e89278dcdc0c 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -1,7 +1,16 @@ #======================b1-start=============== +# ---- user ./test.sh -f general/user/basic1.sim +# ---- db +./test.sh -f general/db/basic1.sim + +# ---- table +./test.sh -f general/table/basic1.sim + +# ---- dnode +./test.sh -f unique/dnode/basic1.sim #======================b1-end=============== diff --git a/tests/script/jenkins/simple.txt b/tests/script/jenkins/simple.txt deleted file mode 100644 index 88ff4d660131bea5dee2f5ccd0dad9d81c7bed5f..0000000000000000000000000000000000000000 --- a/tests/script/jenkins/simple.txt +++ /dev/null @@ -1,231 +0,0 @@ -cd ../../../debug; cmake .. -cd ../../../debug; make - -#./test.sh -f general/alter/cached_schema_after_alter.sim -./test.sh -f general/alter/count.sim -./test.sh -f general/alter/import.sim -#./test.sh -f general/alter/insert1.sim -./test.sh -f general/alter/insert2.sim -./test.sh -f general/alter/metrics.sim -./test.sh -f general/alter/table.sim - -./test.sh -f general/cache/new_metrics.sim -./test.sh -f general/cache/restart_metrics.sim -./test.sh -f general/cache/restart_table.sim - -./test.sh -f general/connection/connection.sim - -./test.sh -f general/column/commit.sim -./test.sh -f general/column/metrics.sim -./test.sh -f general/column/table.sim - -./test.sh -f general/compress/commitlog.sim -./test.sh -f general/compress/compress.sim -./test.sh -f general/compress/compress2.sim -./test.sh -f general/compress/uncompress.sim - -./test.sh -f general/compute/avg.sim -./test.sh -f general/compute/bottom.sim -./test.sh -f general/compute/count.sim -./test.sh -f general/compute/diff.sim -./test.sh -f general/compute/diff2.sim -./test.sh -f general/compute/first.sim -./test.sh -f general/compute/interval.sim -./test.sh -f general/compute/last.sim -./test.sh -f general/compute/leastsquare.sim -./test.sh -f general/compute/max.sim -./test.sh -f general/compute/min.sim -./test.sh -f general/compute/null.sim -./test.sh -f general/compute/percentile.sim -./test.sh -f general/compute/stddev.sim -./test.sh -f general/compute/sum.sim -./test.sh -f general/compute/top.sim - -./test.sh -f general/db/alter_option.sim -./test.sh -f general/db/alter_tables_d2.sim -./test.sh -f general/db/alter_tables_v1.sim -./test.sh -f general/db/alter_tables_v4.sim -./test.sh -f general/db/alter_vgroups.sim -./test.sh -f general/db/basic.sim -./test.sh -f general/db/basic1.sim -./test.sh -f general/db/basic2.sim -./test.sh -f general/db/basic3.sim -./test.sh -f general/db/basic4.sim -./test.sh -f general/db/basic5.sim -./test.sh -f general/db/delete_reuse1.sim -./test.sh -f general/db/delete_reuse2.sim -./test.sh -f general/db/delete_reusevnode.sim -./test.sh -f general/db/delete_reusevnode2.sim -./test.sh -f general/db/delete_writing1.sim -./test.sh -f general/db/delete_writing2.sim -./test.sh -f general/db/delete.sim -./test.sh -f general/db/len.sim -./test.sh -f general/db/repeat.sim -./test.sh -f general/db/tables.sim -./test.sh -f general/db/vnodes.sim - -./test.sh -f general/field/2.sim -./test.sh -f general/field/3.sim -./test.sh -f general/field/4.sim -./test.sh -f general/field/5.sim -./test.sh -f general/field/6.sim -./test.sh -f general/field/bigint.sim -./test.sh -f general/field/binary.sim -./test.sh -f general/field/bool.sim -./test.sh -f general/field/single.sim -./test.sh -f general/field/smallint.sim -./test.sh -f general/field/tinyint.sim - -./test.sh -f general/http/restful.sim -./test.sh -f general/http/restful_insert.sim -./test.sh -f general/http/restful_limit.sim -./test.sh -f general/http/restful_full.sim -./test.sh -f general/http/prepare.sim -./test.sh -f general/http/telegraf.sim -./test.sh -f general/http/grafana_bug.sim -./test.sh -f general/http/grafana.sim - -./test.sh -f general/import/basic.sim -./test.sh -f general/import/commit.sim -./test.sh -f general/import/large.sim -./test.sh -f general/import/replica1.sim - -./test.sh -f general/insert/basic.sim -./test.sh -f general/insert/insert_drop.sim -./test.sh -f general/insert/query_block1_memory.sim -./test.sh -f general/insert/query_block2_memory.sim -./test.sh -f general/insert/query_block1_file.sim -./test.sh -f general/insert/query_block2_file.sim -./test.sh -f general/insert/query_file_memory.sim -./test.sh -f general/insert/query_multi_file.sim -./test.sh -f general/insert/tcp.sim - -./test.sh -f general/parser/alter.sim -./test.sh -f general/parser/alter1.sim -./test.sh -f general/parser/alter_stable.sim -./test.sh -f general/parser/auto_create_tb.sim -./test.sh -f general/parser/auto_create_tb_drop_tb.sim -./test.sh -f general/parser/col_arithmetic_operation.sim -./test.sh -f general/parser/columnValue.sim -./test.sh -f general/parser/commit.sim -./test.sh -f general/parser/create_db.sim -./test.sh -f general/parser/create_mt.sim -./test.sh -f general/parser/create_tb.sim -./test.sh -f general/parser/dbtbnameValidate.sim -./test.sh -f general/parser/import_commit1.sim -./test.sh -f general/parser/import_commit2.sim -./test.sh -f general/parser/import_commit3.sim -./test.sh -f general/parser/insert_tb.sim -./test.sh -f general/parser/first_last.sim -#./test.sh -f general/parser/import_file.sim -./test.sh -f general/parser/lastrow.sim -./test.sh -f general/parser/nchar.sim -./test.sh -f general/parser/null_char.sim -./test.sh -f general/parser/single_row_in_tb.sim -./test.sh -f general/parser/select_from_cache_disk.sim -./test.sh -f general/parser/mixed_blocks.sim -./test.sh -f general/parser/selectResNum.sim -./test.sh -f general/parser/limit.sim -./test.sh -f general/parser/limit1.sim -./test.sh -f general/parser/limit1_tblocks100.sim -./test.sh -f general/parser/select_across_vnodes.sim -./test.sh -f general/parser/slimit1.sim -./test.sh -f general/parser/tbnameIn.sim -./test.sh -f general/parser/projection_limit_offset.sim -./test.sh -f general/parser/limit2.sim -./test.sh -f general/parser/fill.sim -./test.sh -f general/parser/fill_stb.sim -./test.sh -f general/parser/where.sim -./test.sh -f general/parser/slimit.sim -./test.sh -f general/parser/select_with_tags.sim -./test.sh -f general/parser/interp.sim -./test.sh -f general/parser/tags_dynamically_specifiy.sim -./test.sh -f general/parser/groupby.sim -./test.sh -f general/parser/set_tag_vals.sim -#./test.sh -f general/parser/slimit_alter_tags.sim -./test.sh -f general/parser/join.sim -./test.sh -f general/parser/join_multivnode.sim -./test.sh -f general/parser/binary_escapeCharacter.sim -./test.sh -f general/parser/bug.sim -./test.sh -f general/parser/repeatAlter.sim - -./test.sh -f general/stable/disk.sim -./test.sh -f general/stable/dnode3.sim -./test.sh -f general/stable/metrics.sim -./test.sh -f general/stable/refcount.sim -./test.sh -f general/stable/show.sim -./test.sh -f general/stable/values.sim -./test.sh -f general/stable/vnode3.sim - -./test.sh -f general/table/autocreate.sim -./test.sh -f general/table/basic1.sim -./test.sh -f general/table/basic2.sim -./test.sh -f general/table/basic3.sim -./test.sh -f general/table/bigint.sim -./test.sh -f general/table/binary.sim -./test.sh -f general/table/bool.sim -./test.sh -f general/table/column_name.sim -./test.sh -f general/table/column_num.sim -./test.sh -f general/table/column_value.sim -./test.sh -f general/table/column2.sim -./test.sh -f general/table/date.sim -./test.sh -f general/table/db.table.sim -./test.sh -f general/table/delete_reuse1.sim -./test.sh -f general/table/delete_reuse2.sim -./test.sh -f general/table/delete_writing.sim -./test.sh -f general/table/describe.sim -./test.sh -f general/table/double.sim -./test.sh -f general/table/fill.sim -./test.sh -f general/table/float.sim -./test.sh -f general/table/int.sim -./test.sh -f general/table/limit.sim -./test.sh -f general/table/smallint.sim -./test.sh -f general/table/table_len.sim -./test.sh -f general/table/table.sim -./test.sh -f general/table/tinyint.sim -./test.sh -f general/table/vgroup.sim - -./test.sh -f general/tag/3.sim -./test.sh -f general/tag/4.sim -./test.sh -f general/tag/5.sim -./test.sh -f general/tag/6.sim -./test.sh -f general/tag/add.sim -./test.sh -f general/tag/bigint.sim -./test.sh -f general/tag/binary_binary.sim -./test.sh -f general/tag/binary.sim -./test.sh -f general/tag/bool_binary.sim -./test.sh -f general/tag/bool_int.sim -./test.sh -f general/tag/bool.sim -./test.sh -f general/tag/change.sim -./test.sh -f general/tag/column.sim -#./test.sh -f general/tag/commit.sim -./test.sh -f general/tag/create.sim -./test.sh -f general/tag/delete.sim -./test.sh -f general/tag/double.sim -./test.sh -f general/tag/filter.sim -./test.sh -f general/tag/float.sim -./test.sh -f general/tag/int_binary.sim -./test.sh -f general/tag/int_float.sim -./test.sh -f general/tag/int.sim -./test.sh -f general/tag/set.sim -./test.sh -f general/tag/smallint.sim -./test.sh -f general/tag/tinyint.sim - -./test.sh -f general/user/authority.sim -./test.sh -f general/user/monitor.sim -./test.sh -f general/user/pass_alter.sim -./test.sh -f general/user/pass_len.sim -./test.sh -f general/user/user_create.sim -./test.sh -f general/user/user_len.sim - -./test.sh -f general/vector/metrics_field.sim -./test.sh -f general/vector/metrics_mix.sim -./test.sh -f general/vector/metrics_query.sim -./test.sh -f general/vector/metrics_tag.sim -./test.sh -f general/vector/metrics_time.sim -./test.sh -f general/vector/multi.sim -./test.sh -f general/vector/single.sim -./test.sh -f general/vector/table_field.sim -./test.sh -f general/vector/table_mix.sim -./test.sh -f general/vector/table_query.sim -./test.sh -f general/vector/table_time.sim diff --git a/tests/script/jenkins/unique.txt b/tests/script/jenkins/unique.txt deleted file mode 100644 index 372bdc9d9d55635de6f36a0629b2f9c2aca5df07..0000000000000000000000000000000000000000 --- a/tests/script/jenkins/unique.txt +++ /dev/null @@ -1,127 +0,0 @@ -cd ../../../debug; cmake .. -cd ../../../debug; make - -./test.sh -f unique/big/balance.sim -./test.sh -f unique/big/maxvnodes.sim -./test.sh -f unique/big/tcp.sim - -./test.sh -f unique/cluster/alter.sim -./test.sh -f unique/cluster/balance1.sim -./test.sh -f unique/cluster/balance2.sim -./test.sh -f unique/cluster/balance3.sim -./test.sh -f unique/cluster/cache.sim -./test.sh -f unique/cluster/vgroup100.sim - -./test.sh -f unique/column/replica3.sim - -./test.sh -f unique/db/commit.sim -./test.sh -f unique/db/delete.sim -./test.sh -f unique/db/delete_part.sim -./test.sh -f unique/db/replica_add12.sim -./test.sh -f unique/db/replica_add13.sim -./test.sh -f unique/db/replica_add23.sim -./test.sh -f unique/db/replica_reduce21.sim -./test.sh -f unique/db/replica_reduce32.sim -./test.sh -f unique/db/replica_reduce31.sim -./test.sh -f unique/db/replica_part.sim - -./test.sh -f unique/dnode/alternativeRole.sim -./test.sh -f unique/dnode/monitor.sim -./test.sh -f unique/dnode/monitor_bug.sim -./test.sh -f unique/dnode/simple.sim -./test.sh -f unique/dnode/balance1.sim -./test.sh -f unique/dnode/balance2.sim -./test.sh -f unique/dnode/balance3.sim -./test.sh -f unique/dnode/balancex.sim -./test.sh -f unique/dnode/data1.sim -./test.sh -f unique/dnode/m2.sim -./test.sh -f unique/dnode/m3.sim -./test.sh -f unique/dnode/lossdata.sim -./test.sh -f unique/dnode/offline1.sim -./test.sh -f unique/dnode/offline2.sim -./test.sh -f unique/dnode/offline3.sim -./test.sh -f unique/dnode/reason.sim -./test.sh -f unique/dnode/remove1.sim -./test.sh -f unique/dnode/remove2.sim -./test.sh -f unique/dnode/vnode_clean.sim - -./test.sh -f unique/http/admin.sim -./test.sh -f unique/http/opentsdb.sim - -./test.sh -f unique/import/replica2.sim -./test.sh -f unique/import/replica3.sim - -./test.sh -f unique/stable/balance_replica1.sim -./test.sh -f unique/stable/dnode2_stop.sim -./test.sh -f unique/stable/dnode2.sim -./test.sh -f unique/stable/dnode3.sim -./test.sh -f unique/stable/replica2_dnode4.sim -./test.sh -f unique/stable/replica2_vnode3.sim -./test.sh -f unique/stable/replica3_dnode6.sim -./test.sh -f unique/stable/replica3_vnode3.sim - -./test.sh -f unique/mnode/mgmt20.sim -./test.sh -f unique/mnode/mgmt21.sim -./test.sh -f unique/mnode/mgmt22.sim -./test.sh -f unique/mnode/mgmt23.sim -./test.sh -f unique/mnode/mgmt24.sim -./test.sh -f unique/mnode/mgmt25.sim -./test.sh -f unique/mnode/mgmt26.sim -./test.sh -f unique/mnode/mgmt30.sim -./test.sh -f unique/mnode/mgmt33.sim -./test.sh -f unique/mnode/mgmt34.sim -./test.sh -f unique/mnode/mgmtr2.sim - -./test.sh -f unique/vnode/many.sim -./test.sh -f unique/vnode/replica2_basic2.sim -./test.sh -f unique/vnode/replica2_repeat.sim -./test.sh -f unique/vnode/replica3_basic.sim -./test.sh -f unique/vnode/replica3_repeat.sim -./test.sh -f unique/vnode/replica3_vgroup.sim - -./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim -#./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim -./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim -./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim -#./test.sh -f unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim -#./test.sh -f unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim -./test.sh -f unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim -./test.sh -f unique/arbitrator/dn3_mn1_replica_change.sim -#./test.sh -f unique/arbitrator/dn3_mn1_stopDnode_timeout.sim -# lower the priority while file corruption -#./test.sh -f unique/arbitrator/dn3_mn1_vnode_change.sim -#./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim -#./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim -#./test.sh -f unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim -./test.sh -f unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim -./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim -./test.sh -f unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim -./test.sh -f unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim -./test.sh -f unique/arbitrator/dn3_mn1_vnode_nomaster.sim -./test.sh -f unique/arbitrator/dn3_mn2_killDnode.sim -./test.sh -f unique/arbitrator/insert_duplicationTs.sim -./test.sh -f unique/arbitrator/offline_replica2_alterTable_online.sim -./test.sh -f unique/arbitrator/offline_replica2_alterTag_online.sim -./test.sh -f unique/arbitrator/offline_replica2_createTable_online.sim -./test.sh -f unique/arbitrator/offline_replica2_dropDb_online.sim -./test.sh -f unique/arbitrator/offline_replica2_dropTable_online.sim -./test.sh -f unique/arbitrator/offline_replica3_alterTable_online.sim -./test.sh -f unique/arbitrator/offline_replica3_alterTag_online.sim -./test.sh -f unique/arbitrator/offline_replica3_createTable_online.sim -./test.sh -f unique/arbitrator/offline_replica3_dropDb_online.sim -./test.sh -f unique/arbitrator/offline_replica3_dropTable_online.sim -./test.sh -f unique/arbitrator/replica_changeWithArbitrator.sim -./test.sh -f unique/arbitrator/sync_replica2_alterTable_add.sim -./test.sh -f unique/arbitrator/sync_replica2_alterTable_drop.sim - -./test.sh -f unique/arbitrator/sync_replica2_dropDb.sim -./test.sh -f unique/arbitrator/sync_replica2_dropTable.sim -./test.sh -f unique/arbitrator/sync_replica3_alterTable_add.sim -./test.sh -f unique/arbitrator/sync_replica3_alterTable_drop.sim -./test.sh -f unique/arbitrator/sync_replica3_dropDb.sim -./test.sh -f unique/arbitrator/sync_replica3_dropTable.sim - -./test.sh -f unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim -./test.sh -f unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim -./test.sh -f unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim -./test.sh -f unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim diff --git a/tests/script/jenkins/wbasic.txt b/tests/script/jenkins/wbasic.txt deleted file mode 100644 index 984b15fc5a4e49a5e730667782b41afb8bdb6bb8..0000000000000000000000000000000000000000 --- a/tests/script/jenkins/wbasic.txt +++ /dev/null @@ -1,393 +0,0 @@ -wtest.bat -f issue/TD-2677.sim -wtest.bat -f issue/TD-2680.sim -wtest.bat -f issue/TD-2713.sim - -wtest.bat -f general/alter/cached_schema_after_alter.sim -wtest.bat -f general/alter/count.sim -wtest.bat -f general/alter/dnode.sim -wtest.bat -f general/alter/import.sim -wtest.bat -f general/alter/insert1.sim -wtest.bat -f general/alter/insert2.sim -wtest.bat -f general/alter/metrics.sim -wtest.bat -f general/alter/table.sim - -wtest.bat -f general/cache/new_metrics.sim -wtest.bat -f general/cache/restart_metrics.sim -wtest.bat -f general/cache/restart_table.sim - -wtest.bat -f general/connection/connection.sim - -wtest.bat -f general/column/commit.sim -wtest.bat -f general/column/metrics.sim -wtest.bat -f general/column/table.sim - -wtest.bat -f general/compress/commitlog.sim -wtest.bat -f general/compress/compress.sim -wtest.bat -f general/compress/compress2.sim -wtest.bat -f general/compress/uncompress.sim - -wtest.bat -f general/compute/avg.sim -wtest.bat -f general/compute/bottom.sim -wtest.bat -f general/compute/count.sim -wtest.bat -f general/compute/diff.sim -wtest.bat -f general/compute/diff2.sim -wtest.bat -f general/compute/first.sim -wtest.bat -f general/compute/interval.sim -wtest.bat -f general/compute/last.sim -wtest.bat -f general/compute/leastsquare.sim -wtest.bat -f general/compute/max.sim -wtest.bat -f general/compute/min.sim -wtest.bat -f general/compute/null.sim -wtest.bat -f general/compute/percentile.sim -wtest.bat -f general/compute/stddev.sim -wtest.bat -f general/compute/sum.sim -wtest.bat -f general/compute/top.sim - -wtest.bat -f general/db/alter_option.sim -wtest.bat -f general/db/alter_tables_d2.sim -wtest.bat -f general/db/alter_tables_v1.sim -wtest.bat -f general/db/alter_tables_v4.sim -wtest.bat -f general/db/alter_vgroups.sim -wtest.bat -f general/db/basic.sim -wtest.bat -f general/db/basic1.sim -wtest.bat -f general/db/basic2.sim -wtest.bat -f general/db/basic3.sim -wtest.bat -f general/db/basic4.sim -wtest.bat -f general/db/basic5.sim -wtest.bat -f general/db/delete_reuse1.sim -wtest.bat -f general/db/delete_reuse2.sim -wtest.bat -f general/db/delete_reusevnode.sim -wtest.bat -f general/db/delete_reusevnode2.sim -wtest.bat -f general/db/delete_writing1.sim -wtest.bat -f general/db/delete_writing2.sim -wtest.bat -f general/db/delete.sim -wtest.bat -f general/db/len.sim -wtest.bat -f general/db/repeat.sim -wtest.bat -f general/db/tables.sim -wtest.bat -f general/db/vnodes.sim -wtest.bat -f general/db/nosuchfile.sim - -wtest.bat -f general/field/2.sim -wtest.bat -f general/field/3.sim -wtest.bat -f general/field/4.sim -wtest.bat -f general/field/5.sim -wtest.bat -f general/field/6.sim -wtest.bat -f general/field/bigint.sim -wtest.bat -f general/field/binary.sim -wtest.bat -f general/field/bool.sim -wtest.bat -f general/field/single.sim -wtest.bat -f general/field/smallint.sim -wtest.bat -f general/field/tinyint.sim - -wtest.bat -f general/http/autocreate.sim -wtest.bat -f general/http/chunked.sim -wtest.bat -f general/http/gzip.sim -wtest.bat -f general/http/restful.sim -wtest.bat -f general/http/restful_insert.sim -wtest.bat -f general/http/restful_limit.sim -wtest.bat -f general/http/restful_full.sim -wtest.bat -f general/http/prepare.sim -wtest.bat -f general/http/telegraf.sim -wtest.bat -f general/http/grafana_bug.sim -wtest.bat -f general/http/grafana.sim - -wtest.bat -f general/import/basic.sim -wtest.bat -f general/import/commit.sim -wtest.bat -f general/import/large.sim -wtest.bat -f general/import/replica1.sim - -wtest.bat -f general/insert/basic.sim -wtest.bat -f general/insert/insert_drop.sim -wtest.bat -f general/insert/query_block1_memory.sim -wtest.bat -f general/insert/query_block2_memory.sim -wtest.bat -f general/insert/query_block1_file.sim -wtest.bat -f general/insert/query_block2_file.sim -wtest.bat -f general/insert/query_file_memory.sim -wtest.bat -f general/insert/query_multi_file.sim -wtest.bat -f general/insert/tcp.sim - -wtest.bat -f general/parser/alter.sim -wtest.bat -f general/parser/alter1.sim -wtest.bat -f general/parser/alter_stable.sim -wtest.bat -f general/parser/auto_create_tb.sim -wtest.bat -f general/parser/auto_create_tb_drop_tb.sim -wtest.bat -f general/parser/col_arithmetic_operation.sim -wtest.bat -f general/parser/columnValue.sim -wtest.bat -f general/parser/commit.sim -wtest.bat -f general/parser/create_db.sim -wtest.bat -f general/parser/create_mt.sim -wtest.bat -f general/parser/create_tb.sim -wtest.bat -f general/parser/dbtbnameValidate.sim -wtest.bat -f general/parser/import_commit1.sim -wtest.bat -f general/parser/import_commit2.sim -wtest.bat -f general/parser/import_commit3.sim -wtest.bat -f general/parser/insert_tb.sim -wtest.bat -f general/parser/first_last.sim -wtest.bat -f general/parser/lastrow.sim -wtest.bat -f general/parser/nchar.sim -wtest.bat -f general/parser/null_char.sim -wtest.bat -f general/parser/single_row_in_tb.sim -wtest.bat -f general/parser/select_from_cache_disk.sim -wtest.bat -f general/parser/mixed_blocks.sim -wtest.bat -f general/parser/selectResNum.sim -wtest.bat -f general/parser/limit.sim -wtest.bat -f general/parser/limit1.sim -wtest.bat -f general/parser/limit1_tblocks100.sim -wtest.bat -f general/parser/select_across_vnodes.sim -wtest.bat -f general/parser/slimit1.sim -wtest.bat -f general/parser/tbnameIn.sim -wtest.bat -f general/parser/projection_limit_offset.sim -wtest.bat -f general/parser/limit2.sim -wtest.bat -f general/parser/fill.sim -wtest.bat -f general/parser/fill_stb.sim -wtest.bat -f general/parser/where.sim -wtest.bat -f general/parser/slimit.sim -wtest.bat -f general/parser/select_with_tags.sim -wtest.bat -f general/parser/interp.sim -wtest.bat -f general/parser/tags_dynamically_specifiy.sim -wtest.bat -f general/parser/groupby.sim -wtest.bat -f general/parser/set_tag_vals.sim -wtest.bat -f general/parser/tags_filter.sim -wtest.bat -f general/parser/slimit_alter_tags.sim -wtest.bat -f general/parser/join.sim -wtest.bat -f general/parser/join_multivnode.sim -wtest.bat -f general/parser/binary_escapeCharacter.sim -wtest.bat -f general/parser/repeatAlter.sim -wtest.bat -f general/parser/union.sim -wtest.bat -f general/parser/topbot.sim -wtest.bat -f general/parser/function.sim - -wtest.bat -f general/stable/disk.sim -wtest.bat -f general/stable/dnode3.sim -wtest.bat -f general/stable/metrics.sim -wtest.bat -f general/stable/refcount.sim -wtest.bat -f general/stable/show.sim -wtest.bat -f general/stable/values.sim -wtest.bat -f general/stable/vnode3.sim - -wtest.bat -f general/table/autocreate.sim -wtest.bat -f general/table/basic1.sim -wtest.bat -f general/table/basic2.sim -wtest.bat -f general/table/basic3.sim -wtest.bat -f general/table/bigint.sim -wtest.bat -f general/table/binary.sim -wtest.bat -f general/table/bool.sim -wtest.bat -f general/table/column_name.sim -wtest.bat -f general/table/column_num.sim -wtest.bat -f general/table/column_value.sim -wtest.bat -f general/table/column2.sim -wtest.bat -f general/table/date.sim -wtest.bat -f general/table/db.table.sim -wtest.bat -f general/table/delete_reuse1.sim -wtest.bat -f general/table/delete_reuse2.sim -wtest.bat -f general/table/delete_writing.sim -wtest.bat -f general/table/describe.sim -wtest.bat -f general/table/double.sim -wtest.bat -f general/table/fill.sim -wtest.bat -f general/table/float.sim -wtest.bat -f general/table/int.sim -wtest.bat -f general/table/limit.sim -wtest.bat -f general/table/smallint.sim -wtest.bat -f general/table/table_len.sim -wtest.bat -f general/table/table.sim -wtest.bat -f general/table/tinyint.sim -wtest.bat -f general/table/vgroup.sim - -wtest.bat -f general/tag/3.sim -wtest.bat -f general/tag/4.sim -wtest.bat -f general/tag/5.sim -wtest.bat -f general/tag/6.sim -wtest.bat -f general/tag/add.sim -wtest.bat -f general/tag/bigint.sim -wtest.bat -f general/tag/binary_binary.sim -wtest.bat -f general/tag/binary.sim -wtest.bat -f general/tag/bool_binary.sim -wtest.bat -f general/tag/bool_int.sim -wtest.bat -f general/tag/bool.sim -wtest.bat -f general/tag/change.sim -wtest.bat -f general/tag/column.sim -wtest.bat -f general/tag/commit.sim -wtest.bat -f general/tag/create.sim -wtest.bat -f general/tag/delete.sim -wtest.bat -f general/tag/double.sim -wtest.bat -f general/tag/filter.sim -wtest.bat -f general/tag/float.sim -wtest.bat -f general/tag/int_binary.sim -wtest.bat -f general/tag/int_float.sim -wtest.bat -f general/tag/int.sim -wtest.bat -f general/tag/set.sim -wtest.bat -f general/tag/smallint.sim -wtest.bat -f general/tag/tinyint.sim - -wtest.bat -f general/user/authority.sim -wtest.bat -f general/user/monitor.sim -wtest.bat -f general/user/pass_alter.sim -wtest.bat -f general/user/pass_len.sim -wtest.bat -f general/user/user_create.sim -wtest.bat -f general/user/user_len.sim - -wtest.bat -f general/vector/metrics_field.sim -wtest.bat -f general/vector/metrics_mix.sim -wtest.bat -f general/vector/metrics_query.sim -wtest.bat -f general/vector/metrics_tag.sim -wtest.bat -f general/vector/metrics_time.sim -wtest.bat -f general/vector/multi.sim -wtest.bat -f general/vector/single.sim -wtest.bat -f general/vector/table_field.sim -wtest.bat -f general/vector/table_mix.sim -wtest.bat -f general/vector/table_query.sim -wtest.bat -f general/vector/table_time.sim - -wtest.bat -f general/wal/sync.sim -wtest.bat -f general/wal/kill.sim -wtest.bat -f general/wal/maxtables.sim - -wtest.bat -f unique/account/account_create.sim -wtest.bat -f unique/account/account_delete.sim -wtest.bat -f unique/account/account_len.sim -wtest.bat -f unique/account/authority.sim -wtest.bat -f unique/account/basic.sim -wtest.bat -f unique/account/paras.sim -wtest.bat -f unique/account/pass_alter.sim -wtest.bat -f unique/account/pass_len.sim -wtest.bat -f unique/account/usage.sim -wtest.bat -f unique/account/user_create.sim -wtest.bat -f unique/account/user_len.sim - -wtest.bat -f unique/big/balance.sim -wtest.bat -f unique/big/maxvnodes.sim -wtest.bat -f unique/big/tcp.sim - -wtest.bat -f unique/cluster/alter.sim -wtest.bat -f unique/cluster/balance1.sim -wtest.bat -f unique/cluster/balance2.sim -wtest.bat -f unique/cluster/balance3.sim -wtest.bat -f unique/cluster/cache.sim -wtest.bat -f unique/cluster/vgroup100.sim - -wtest.bat -f unique/column/replica3.sim - -wtest.bat -f unique/db/commit.sim -wtest.bat -f unique/db/delete.sim -wtest.bat -f unique/db/delete_part.sim -wtest.bat -f unique/db/replica_add12.sim -wtest.bat -f unique/db/replica_add13.sim -wtest.bat -f unique/db/replica_add23.sim -wtest.bat -f unique/db/replica_reduce21.sim -wtest.bat -f unique/db/replica_reduce32.sim -wtest.bat -f unique/db/replica_reduce31.sim -wtest.bat -f unique/db/replica_part.sim - -wtest.bat -f unique/dnode/alternativeRole.sim -wtest.bat -f unique/dnode/monitor.sim -wtest.bat -f unique/dnode/monitor_bug.sim -wtest.bat -f unique/dnode/simple.sim -wtest.bat -f unique/dnode/balance1.sim -wtest.bat -f unique/dnode/balance2.sim -wtest.bat -f unique/dnode/balance3.sim -wtest.bat -f unique/dnode/balancex.sim -wtest.bat -f unique/dnode/data1.sim -wtest.bat -f unique/dnode/m2.sim -wtest.bat -f unique/dnode/m3.sim -wtest.bat -f unique/dnode/lossdata.sim -wtest.bat -f unique/dnode/offline1.sim -wtest.bat -f unique/dnode/offline2.sim -wtest.bat -f unique/dnode/offline3.sim -wtest.bat -f unique/dnode/reason.sim -wtest.bat -f unique/dnode/remove1.sim -wtest.bat -f unique/dnode/remove2.sim -wtest.bat -f unique/dnode/vnode_clean.sim - -wtest.bat -f unique/http/admin.sim -wtest.bat -f unique/http/opentsdb.sim - -wtest.bat -f unique/import/replica2.sim -wtest.bat -f unique/import/replica3.sim - -wtest.bat -f unique/stable/balance_replica1.sim -wtest.bat -f unique/stable/dnode2_stop.sim -wtest.bat -f unique/stable/dnode2.sim -wtest.bat -f unique/stable/dnode3.sim -wtest.bat -f unique/stable/replica2_dnode4.sim -wtest.bat -f unique/stable/replica2_vnode3.sim -wtest.bat -f unique/stable/replica3_dnode6.sim -wtest.bat -f unique/stable/replica3_vnode3.sim - -wtest.bat -f unique/mnode/mgmt20.sim -wtest.bat -f unique/mnode/mgmt21.sim -wtest.bat -f unique/mnode/mgmt22.sim -wtest.bat -f unique/mnode/mgmt23.sim -wtest.bat -f unique/mnode/mgmt24.sim -wtest.bat -f unique/mnode/mgmt25.sim -wtest.bat -f unique/mnode/mgmt26.sim -wtest.bat -f unique/mnode/mgmt30.sim -wtest.bat -f unique/mnode/mgmt33.sim -wtest.bat -f unique/mnode/mgmt34.sim -wtest.bat -f unique/mnode/mgmtr2.sim - -wtest.bat -f unique/vnode/many.sim -wtest.bat -f unique/vnode/replica2_basic2.sim -wtest.bat -f unique/vnode/replica2_repeat.sim -wtest.bat -f unique/vnode/replica3_basic.sim -wtest.bat -f unique/vnode/replica3_repeat.sim -wtest.bat -f unique/vnode/replica3_vgroup.sim - -wtest.bat -f general/stream/metrics_del.sim -wtest.bat -f general/stream/metrics_replica1_vnoden.sim -wtest.bat -f general/stream/restart_stream.sim -wtest.bat -f general/stream/stream_3.sim -wtest.bat -f general/stream/stream_restart.sim -wtest.bat -f general/stream/table_del.sim -wtest.bat -f general/stream/table_replica1_vnoden.sim - -wtest.bat -f unique/arbitrator/check_cluster_cfg_para.sim -#wtest.bat -f unique/arbitrator/dn2_mn1_cache_file_sync.sim -wtest.bat -f unique/arbitrator/dn3_mn1_full_createTableFail.sim -wtest.bat -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim -wtest.bat -f unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim -wtest.bat -f unique/arbitrator/dn3_mn1_replica_change.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_stopDnode_timeout.sim -# lower the priority while file corruption -#wtest.bat -f unique/arbitrator/dn3_mn1_vnode_change.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim -#wtest.bat -f unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim -wtest.bat -f unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim -wtest.bat -f unique/arbitrator/dn3_mn1_vnode_delDir.sim -wtest.bat -f unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim -wtest.bat -f unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim -wtest.bat -f unique/arbitrator/dn3_mn1_vnode_nomaster.sim -wtest.bat -f unique/arbitrator/dn3_mn2_killDnode.sim -wtest.bat -f unique/arbitrator/insert_duplicationTs.sim -wtest.bat -f unique/arbitrator/offline_replica2_alterTable_online.sim -wtest.bat -f unique/arbitrator/offline_replica2_alterTag_online.sim -wtest.bat -f unique/arbitrator/offline_replica2_createTable_online.sim -wtest.bat -f unique/arbitrator/offline_replica2_dropDb_online.sim -wtest.bat -f unique/arbitrator/offline_replica2_dropTable_online.sim -wtest.bat -f unique/arbitrator/offline_replica3_alterTable_online.sim -wtest.bat -f unique/arbitrator/offline_replica3_alterTag_online.sim -wtest.bat -f unique/arbitrator/offline_replica3_createTable_online.sim -wtest.bat -f unique/arbitrator/offline_replica3_dropDb_online.sim -wtest.bat -f unique/arbitrator/offline_replica3_dropTable_online.sim -wtest.bat -f unique/arbitrator/replica_changeWithArbitrator.sim -wtest.bat -f unique/arbitrator/sync_replica2_alterTable_add.sim -wtest.bat -f unique/arbitrator/sync_replica2_alterTable_drop.sim - -wtest.bat -f unique/arbitrator/sync_replica2_dropDb.sim -wtest.bat -f unique/arbitrator/sync_replica2_dropTable.sim -wtest.bat -f unique/arbitrator/sync_replica3_alterTable_add.sim -wtest.bat -f unique/arbitrator/sync_replica3_alterTable_drop.sim -wtest.bat -f unique/arbitrator/sync_replica3_dropDb.sim -wtest.bat -f unique/arbitrator/sync_replica3_dropTable.sim - -wtest.bat -f unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim -wtest.bat -f unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim -wtest.bat -f unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim -wtest.bat -f unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim - -wtest.bat -f general/connection/test_old_data.sim -wtest.bat -f unique/dnode/datatrans_3node.sim -wtest.bat -f unique/dnode/datatrans_3node_2.sim - diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 03ce1c28885d158213c38a01363546675f46ae0a..fcc11ca2136df3b57aa64247a5d0452afa87e0c0 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -118,49 +118,31 @@ fi echo " " >> $TAOS_CFG echo "firstEp ${HOSTNAME}:7100" >> $TAOS_CFG echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG +echo "fqdn ${HOSTNAME}" >> $TAOS_CFG echo "serverPort ${NODE}" >> $TAOS_CFG +echo "supportVnodes 16" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG echo "mDebugFlag 143" >> $TAOS_CFG -echo "sdbDebugFlag 143" >> $TAOS_CFG echo "dDebugFlag 143" >> $TAOS_CFG echo "vDebugFlag 143" >> $TAOS_CFG echo "tsdbDebugFlag 143" >> $TAOS_CFG echo "cDebugFlag 143" >> $TAOS_CFG echo "jnidebugFlag 143" >> $TAOS_CFG -echo "odbcdebugFlag 143" >> $TAOS_CFG -echo "httpDebugFlag 143" >> $TAOS_CFG -echo "monDebugFlag 143" >> $TAOS_CFG -echo "mqttDebugFlag 143" >> $TAOS_CFG echo "qdebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "udebugFlag 143" >> $TAOS_CFG echo "sdebugFlag 143" >> $TAOS_CFG echo "wdebugFlag 143" >> $TAOS_CFG -echo "cqdebugFlag 143" >> $TAOS_CFG -echo "monitor 0" >> $TAOS_CFG -echo "monitorInterval 1" >> $TAOS_CFG -echo "http 0" >> $TAOS_CFG echo "slaveQuery 0" >> $TAOS_CFG echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG echo "defaultPass taosdata" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG -echo "mnodeEqualVnodeNum 0" >> $TAOS_CFG -echo "balanceInterval 1" >> $TAOS_CFG -echo "clog 2" >> $TAOS_CFG -#echo "cache 1" >> $TAOS_CFG -echo "days 10" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG -echo "maxVgroupsPerDb 4" >> $TAOS_CFG -echo "minTablesPerVnode 4" >> $TAOS_CFG -echo "maxTablesPerVnode 1000" >> $TAOS_CFG -echo "tableIncStepPerVnode 10000" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG -echo "numOfMnodes 1" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo "fsync 0" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG echo " " >> $TAOS_CFG - diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index d1572bb513c533d9a0d0465a03aeeebe6b85f6e6..2e95a740d082dd06e5fe89ca02fe04698a22969e 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -17,7 +17,7 @@ OS_TYPE=`$UNAME_BIN` NODE_NAME= EXEC_OPTON= CLEAR_OPTION="false" -while getopts "n:s:u:x:ct" arg +while getopts "n:s:u:x:cv" arg do case $arg in n) @@ -29,7 +29,7 @@ do c) CLEAR_OPTION="clear" ;; - t) + v) SHELL_OPTION="true" ;; u) diff --git a/tests/script/tmp/182.sim b/tests/script/tmp/182.sim deleted file mode 100644 index a178282cf835b236a202c71f1ef5a595e784324c..0000000000000000000000000000000000000000 --- a/tests/script/tmp/182.sim +++ /dev/null @@ -1,41 +0,0 @@ -system sh/stop_dnodes.sh - -system sh/deploy.sh -n dnode1 -i 1 -system sh/deploy.sh -n dnode2 -i 2 -system sh/deploy.sh -n dnode3 -i 3 -system sh/deploy.sh -n dnode4 -i 4 - -system sh/cfg.sh -n dnode1 -c walLevel -v 2 -system sh/cfg.sh -n dnode2 -c walLevel -v 2 -system sh/cfg.sh -n dnode3 -c walLevel -v 2 -system sh/cfg.sh -n dnode4 -c walLevel -v 2 - -system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 - -system sh/cfg.sh -n dnode1 -c activeCode -v eglxDLzRpslJWl7OxrPZ2K3sQ5631AP9SVpezsaz2dhJWl7OxrPZ2ElaXs7Gs9nYSVpezsaz2djGIj5StnQ3ZvLHcsE8cwcN - -system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4 - -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 100000 - -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode2 -c http -v 1 -system sh/cfg.sh -n dnode3 -c http -v 1 -system sh/cfg.sh -n dnode4 -c http -v 1 - -system sh/cfg.sh -n dnode1 -c httpMaxThreads -v 4 - -system sh/cfg.sh -n dnode1 -c firstEp -v 127.0.0.1:6030 -system sh/cfg.sh -n dnode1 -c secondEp -v 127.0.0.1:6030 -system sh/cfg.sh -n dnode1 -c serverPort -v 6030 -system sh/cfg.sh -n dnode1 -c fqdn -v 127.0.0.1 -system sh/exec.sh -n dnode1 -s start diff --git a/tests/script/tmp/dnodes.sim b/tests/script/tmp/dnodes.sim new file mode 100644 index 0000000000000000000000000000000000000000..a3f9a0c17385773698e2d8ab1cadbf56c5cf343d --- /dev/null +++ b/tests/script/tmp/dnodes.sim @@ -0,0 +1,105 @@ +############## config parameter ##################### +$node1 = 192.168.0.201 +$node2 = 192.168.0.202 +$node3 = 192.168.0.203 +$node4 = 192.168.0.204 + +$self = $node1 +$num = 25 + +#deploy = 0, start = 1, stop = 2 +$option = 0 +print =============== option:$option + + +############### stop dnodes ##################### +if $option == 0 then + system sh/stop_dnodes.sh +endi + +############### process firstEp ##################### + +$firstEp = $node1 . :7100 +$firstPort = 7100 +if $self == $node1 then + if $option == 1 then + system sh/exec.sh -n dnode1 -s start + endi + + if $option == 2 then + system sh/exec.sh -n dnode1 -s stop -x SIGINT + endi + + if $option == 0 then + system sh/deploy.sh -n dnode1 -i 1 + system sh/cfg.sh -n dnode1 -c firstEp -v $firstEp + system sh/cfg.sh -n dnode1 -c secondEp -v $firstEp + system sh/cfg.sh -n dnode1 -c fqdn -v $node1 + system sh/cfg.sh -n dnode1 -c serverPort -v $firstPort + system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 + + system sh/exec.sh -n dnode1 -s start + sql connect + + $i = 0 + while $i < $num + $port = $i * 100 + $port = $port + 8100 + $i = $i + 1 + sql create dnode $node1 port $port + endw + + $i = 0 + while $i < $num + $port = $i * 100 + $port = $port + 8100 + $i = $i + 1 + sql create dnode $node2 port $port + endw + + $i = 0 + while $i < $num + $port = $i * 100 + $port = $port + 8100 + $i = $i + 1 + sql create dnode $node3 port $port + endw + + $i = 0 + while $i < $num + $port = $i * 100 + $port = $port + 8100 + $i = $i + 1 + sql create dnode $node4 port $port + endw + endi +endi + +############### process nodes ##################### + +$i = 0 +while $i < $num + $index = $i + 80 + $port = $i * 100 + $port = $port + 8100 + $dnodename = dnode . $index + $i = $i + 1 + + if $option == 1 then + system sh/exec.sh -n $dnodename -s start + endi + + if $option == 2 then + system sh/exec.sh -n $dnodename -s stop -x SIGINT + endi + + if $option == 0 then + system sh/deploy.sh -n $dnodename -i 1 + system sh/cfg.sh -n $dnodename -c firstEp -v $firstEp + system sh/cfg.sh -n $dnodename -c secondEp -v $firstEp + system sh/cfg.sh -n $dnodename -c fqdn -v $self + system sh/cfg.sh -n $dnodename -c serverPort -v $port + + system sh/exec.sh -n $dnodename -s start + endi +endw diff --git a/tests/script/tmp/http.sim b/tests/script/tmp/http.sim deleted file mode 100644 index a5212905aed8558bb47983227e16ac6341fd8945..0000000000000000000000000000000000000000 --- a/tests/script/tmp/http.sim +++ /dev/null @@ -1,35 +0,0 @@ -system sh/stop_dnodes.sh - -system sh/deploy.sh -n dnode1 -i 1 -system sh/deploy.sh -n dnode2 -i 2 -system sh/deploy.sh -n dnode3 -i 3 -system sh/deploy.sh -n dnode4 -i 4 - -system sh/cfg.sh -n dnode1 -c walLevel -v 2 -system sh/cfg.sh -n dnode2 -c walLevel -v 2 -system sh/cfg.sh -n dnode3 -c walLevel -v 2 -system sh/cfg.sh -n dnode4 -c walLevel -v 2 - -system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 - -system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4 - -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode2 -c http -v 1 -system sh/cfg.sh -n dnode3 -c http -v 1 - -system sh/cfg.sh -n dnode1 -c monitor -v 1 -system sh/cfg.sh -n dnode2 -c monitor -v 1 -system sh/cfg.sh -n dnode3 -c monitor -v 1 - -system sh/cfg.sh -n dnode1 -c monitorInterval -v 1 -system sh/cfg.sh -n dnode2 -c monitorInterval -v 1 -system sh/cfg.sh -n dnode3 -c monitorInterval -v 1 - -system sh/exec.sh -n dnode1 -s start \ No newline at end of file diff --git a/tests/script/tmp/mnodes.sim b/tests/script/tmp/mnodes.sim deleted file mode 100644 index 8bca76c38b627ac6a6aa9eaae07a9126a9b19057..0000000000000000000000000000000000000000 --- a/tests/script/tmp/mnodes.sim +++ /dev/null @@ -1,115 +0,0 @@ -system sh/stop_dnodes.sh - -system sh/deploy.sh -n dnode1 -i 1 -system sh/deploy.sh -n dnode2 -i 2 -system sh/deploy.sh -n dnode3 -i 3 - -system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3 -system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3 -system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 - -system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 - -system sh/cfg.sh -n dnode1 -c http -v 0 -system sh/cfg.sh -n dnode2 -c http -v 0 -system sh/cfg.sh -n dnode3 -c http -v 0 - -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20000 -system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 20000 -system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 20000 - -system sh/cfg.sh -n dnode1 -c minTablesPerVnode -v 1000 -system sh/cfg.sh -n dnode2 -c minTablesPerVnode -v 1000 -system sh/cfg.sh -n dnode3 -c minTablesPerVnode -v 1000 - -system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 20 -system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 20 -system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 20 - -system sh/cfg.sh -n dnode1 -c replica -v 3 -system sh/cfg.sh -n dnode2 -c replica -v 3 -system sh/cfg.sh -n dnode3 -c replica -v 3 - -print ============== deploy - -system sh/exec.sh -n dnode1 -s start -sql connect - -sql create dnode $hostname2 -sql create dnode $hostname3 -system sh/exec.sh -n dnode2 -s start -system sh/exec.sh -n dnode3 -s start - -print =============== step1 -$x = 0 -step1: - $x = $x + 1 - sleep 1000 - if $x == 10 then - return -1 - endi - -sql show dnodes -print dnode1 $data4_1 -print dnode2 $data4_2 -print dnode3 $data4_3 - -if $data4_1 != ready then - goto step1 -endi -if $data4_2 != ready then - goto step1 -endi -if $data4_3 != ready then - goto step1 -endi - -sql show mnodes -$mnode1Role = $data2_1 -print mnode1Role $mnode1Role -$mnode2Role = $data2_2 -print mnode2Role $mnode2Role -$mnode3Role = $data2_3 -print mnode3Role $mnode3Role - -if $mnode1Role != master then - goto step1 -endi -if $mnode2Role != slave then - goto step1 -endi -if $mnode3Role != slave then - goto step1 -endi - -$x = 1 -show2: - -print =============== step $x -sql show mnodes -print $data0_1 $data2_1 - -sql show dnodes -print dnode1 $data4_1 -print dnode2 $data4_2 -print dnode3 $data4_3 - -if $data4_1 != ready then - goto step1 -endi -if $data4_2 != ready then - goto step1 -endi -if $data4_3 != ready then - goto step1 -endi - -$x = $x + 1 -sleep 3000 -if $x == 100000 then - return -1 -endi - -goto show2 diff --git a/tests/script/tmp/prepare.sim b/tests/script/tmp/prepare.sim index 343c422e9ff772c10f22539fb012fbf38241f91d..28675be808b84e4380c5c43e20666170607844e6 100644 --- a/tests/script/tmp/prepare.sim +++ b/tests/script/tmp/prepare.sim @@ -9,41 +9,3 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 system sh/cfg.sh -n dnode3 -c walLevel -v 2 system sh/cfg.sh -n dnode4 -c walLevel -v 2 - -system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 - -system sh/cfg.sh -n dnode1 -c activeCode -v eglxDLzRpslJWl7OxrPZ2K3sQ5631AP9SVpezsaz2dhJWl7OxrPZ2ElaXs7Gs9nYSVpezsaz2djGIj5StnQ3ZvLHcsE8cwcN - -system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4 - -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 100000 -system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 100000 - -system sh/cfg.sh -n dnode1 -c http -v 1 -system sh/cfg.sh -n dnode2 -c http -v 1 -system sh/cfg.sh -n dnode3 -c http -v 1 -system sh/cfg.sh -n dnode4 -c http -v 1 - -return -# for crash_gen -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 10 -system sh/cfg.sh -n dnode1 -c rpcMaxTime -v 101 -system sh/cfg.sh -n dnode1 -c cache -v 2 -system sh/cfg.sh -n dnode1 -c keep -v 36500 -system sh/cfg.sh -n dnode1 -c walLevel -v 1 - - -# for windows - -system sh/cfg.sh -n dnode1 -c firstEp -v 152.136.17.116:6030 -system sh/cfg.sh -n dnode1 -c secondEp -v 152.136.17.116:6030 -system sh/cfg.sh -n dnode1 -c serverPort -v 6030 -system sh/cfg.sh -n dnode1 -c fqdn -v 152.136.17.116 diff --git a/tests/script/unique/dnode/basic1.sim b/tests/script/unique/dnode/basic1.sim index 5382e88e536596682636496e9e3f66bc121b1561..49b29a4ac8de800a05b70f2d8c278d2e06c3d8d3 100644 --- a/tests/script/unique/dnode/basic1.sim +++ b/tests/script/unique/dnode/basic1.sim @@ -15,7 +15,7 @@ if $data00 != 1 then return -1 endi -if $data01 != 192.168.0.1 then +if $data02 != 0 then return -1 endi @@ -28,12 +28,14 @@ if $data00 != 1 then return -1 endi -if $data01 != 192.168.0.1 then +if $data02 != master then return -1 endi print =============== create dnodes -sql create dnode $hostname2 +sql create dnode $hostname port 7200 +sleep 2000 + sql show dnodes; if $rows != 2 then return -1 @@ -43,15 +45,23 @@ if $data00 != 1 then return -1 endi -if $data01 != 192.168.0.1 then +if $data10 != 2 then return -1 endi -if $data10 != 2 then +if $data02 != 0 then + return -1 +endi + +if $data12 != 0 then return -1 endi -if $data11 != 192.168.0.2 then +if $data04 != ready then + return -1 +endi + +if $data14 != ready then return -1 endi @@ -64,27 +74,36 @@ if $data00 != 1 then return -1 endi -if $data01 != 192.168.0.1 then +if $data02 != master then return -1 endi print =============== create table sql create database d1; sql create database d2; -sql create database d3; -sql create database d4; -sql create database d5; -sql create table d1.t1 (ts timestamp, i int); -sql create table d2.t1 (ts timestamp, i int); -sql create table d3.t1 (ts timestamp, i int); -sql create table d4.t1 (ts timestamp, i int); +sql show databases +if $rows != 2 then + return -1 +endi + +sql use d1 +sql show vgroups; + +if $rows != 2 then + return -1 +endi +print =============== drop dnode +sql drop dnode 2; sql show dnodes; -if $data05 != 2 then +if $rows != 1 then return -1 endi -if $data15 != 2 then +if $data00 != 1 then return -1 endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index cb61e6b81454fc1828105081b9d646f4159c8564..016b6500ed381c06bb5b155d165518acccc5bcf6 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -42,41 +42,7 @@ char *simParseArbitratorName(char *varName) { char *simParseHostName(char *varName) { static char hostName[140]; - - int32_t index = atoi(varName + 8); - int32_t port = 7100; - switch (index) { - case 1: - port = 7100; - break; - case 2: - port = 7200; - break; - case 3: - port = 7300; - break; - case 4: - port = 7400; - break; - case 5: - port = 7500; - break; - case 6: - port = 7600; - break; - case 7: - port = 7700; - break; - case 8: - port = 7800; - break; - case 9: - port = 7900; - break; - } - - sprintf(hostName, "'%s:%d'", simHostName, port); - // simInfo("hostName:%s", hostName); + sprintf(hostName, "%s", simHostName); return hostName; } diff --git a/tools/shell/src/backup/tnettest.c b/tools/shell/src/backup/tnettest.c index c8a6b36fc721b6ac9c107fa0fa7fea82ec65d79f..d6904ddc04f67f3c271cbe8cc817ee32505ecbe3 100644 --- a/tools/shell/src/backup/tnettest.c +++ b/tools/shell/src/backup/tnettest.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosdef.h" -#include "taosmsg.h" +#include "tmsg.h" #include "taoserror.h" #include "tulog.h" #include "tglobal.h" @@ -358,7 +358,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p epSet.port[0] = port; strcpy(epSet.fqdn[0], serverFqdn); - reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; + reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pktLen); reqMsg.contLen = pktLen; reqMsg.code = 0; @@ -368,7 +368,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); - if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) { + if ((rspMsg.code != 0) || (rspMsg.msgType != TDMT_DND_NETWORK_TEST + 1)) { uDebug("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); return rspMsg.code; } @@ -602,7 +602,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, epSet.port[0] = port; strcpy(epSet.fqdn[0], host); - reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; + reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pkgLen); reqMsg.contLen = pkgLen; reqMsg.code = 0; @@ -613,7 +613,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); int code = 0; - if ((rspMsg.code != 0) || (rspMsg.msgType != TSDB_MSG_TYPE_NETWORK_TEST + 1)) { + if ((rspMsg.code != 0) || (rspMsg.msgType != TDMT_DND_NETWORK_TEST + 1)) { uError("ret code 0x%x %s", rspMsg.code, tstrerror(rspMsg.code)); code = -1; }else{