Merge branch '3.0' of https://github.com/taosdata/TDengine into feature/3.0_mhli
This commit is contained in:
commit
3f463d85d0
|
@ -86,5 +86,6 @@ SpacesInSquareBrackets: false
|
|||
Standard: Auto
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
AlignConsecutiveDeclarations: true
|
||||
...
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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[];
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
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 during query processing
|
||||
extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked
|
||||
extern int8_t tsKeepOriginalColumnName;
|
||||
// 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;
|
||||
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];
|
||||
|
|
|
@ -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 type
|
||||
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
|
||||
#define TD_MSG_NUMBER_
|
||||
#undef TD_MSG_DICT_
|
||||
#undef TD_MSG_INFO_
|
||||
#undef TD_MSG_SEG_CODE_
|
||||
#include "tmsgdef.h"
|
||||
|
||||
#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
|
||||
#undef TD_MSG_NUMBER_
|
||||
#undef TD_MSG_DICT_
|
||||
#undef TD_MSG_INFO_
|
||||
#define TD_MSG_SEG_CODE_
|
||||
#include "tmsgdef.h"
|
||||
|
||||
// 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" )
|
||||
#undef TD_MSG_NUMBER_
|
||||
#undef TD_MSG_DICT_
|
||||
#undef TD_MSG_INFO_
|
||||
#undef TD_MSG_SEG_CODE_
|
||||
#include "tmsgdef.h"
|
||||
|
||||
// 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" )
|
||||
extern char* tMsgInfo[];
|
||||
extern int tMsgDict[];
|
||||
|
||||
// message from vnode to vnode
|
||||
// message from vnode to mnode
|
||||
// message from vnode to qnode
|
||||
// message from vnode to dnode
|
||||
#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))
|
||||
|
||||
// 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
|
||||
typedef uint16_t tmsg_t;
|
||||
|
||||
/* ------------------------ ENCODE/DECODE FUNCTIONS AND MACROS ------------------------ */
|
||||
struct SMEListNode {
|
||||
TD_SLIST_NODE(SMEListNode);
|
||||
SEncoder coder;
|
||||
};
|
||||
|
||||
typedef struct SMsgEncoder {
|
||||
SEncoder coder;
|
||||
TD_SLIST(SMEListNode) eStack; // encode stack
|
||||
} SMsgEncoder;
|
||||
|
||||
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_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)
|
||||
|
||||
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;
|
||||
} SDropMnodeInMsg;
|
||||
} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} 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)
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
};
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -13,205 +13,199 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
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;
|
||||
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 {
|
||||
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.
|
||||
*/
|
||||
int32_t qnodeStart();
|
||||
|
||||
/**
|
||||
* Stop Qnode in Dnode.
|
||||
* @brief Start one Qnode in Dnode.
|
||||
*
|
||||
* @param qnodeId Qnode ID to stop, -1 for all Qnodes.
|
||||
* @param pOption Option of the qnode.
|
||||
* @return SQnode* The qnode object.
|
||||
*/
|
||||
void qnodeStop(int64_t qnodeId);
|
||||
|
||||
SQnode *qndOpen(const SQnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* Get the statistical information of Qnode
|
||||
* @brief Stop Qnode in Dnode.
|
||||
*
|
||||
* @param qnodeId Qnode ID to get statistics, -1 for all
|
||||
* @param stat Statistical information.
|
||||
* @return Error Code.
|
||||
* @param pQnode The qnode object to close.
|
||||
*/
|
||||
int32_t qnodeGetStatistics(int64_t qnodeId, SQnodeStat *stat);
|
||||
void qndClose(SQnode *pQnode);
|
||||
|
||||
/**
|
||||
* Interface for processing Qnode messages.
|
||||
* @brief Get the statistical information of Qnode
|
||||
*
|
||||
* @param pMsg Message to be processed.
|
||||
* @return Error code
|
||||
* @param pQnode The qnode object.
|
||||
* @param pLoad Statistics of the qnode.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
void qnodeProcessReq(SRpcMsg *pMsg);
|
||||
|
||||
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
int32_t qndProcessMsg(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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*<SArray*<SSubplan*>>. 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,6 +166,9 @@ void qDestroySubplan(SSubplan* pSubplan);
|
|||
*/
|
||||
void qDestroyQueryDag(SQueryDag* pDag);
|
||||
|
||||
char* qDagToString(const SQueryDag* pDag);
|
||||
SQueryDag* qStringToDag(const char* pStr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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,15 +74,15 @@ 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;
|
||||
|
||||
|
@ -93,7 +94,22 @@ typedef struct STableMetaOutput {
|
|||
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)
|
||||
|
|
|
@ -42,21 +42,24 @@ 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);
|
||||
|
||||
int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
||||
int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -22,43 +22,43 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
extern char tsOsName[];
|
||||
extern char tsDnodeDir[];
|
||||
extern char tsDataDir[];
|
||||
extern char tsLogDir[];
|
||||
extern char tsScriptDir[];
|
||||
|
|
|
@ -0,0 +1,476 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -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")
|
||||
|
|
|
@ -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 );
|
||||
#define tbufInitWriter(Allocator, Endian) \
|
||||
{ .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) }
|
||||
|
||||
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 );
|
||||
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 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 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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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 clientReqRefPool;
|
||||
extern int32_t clientConnRefPool;
|
||||
|
||||
extern SAppInfo appInfo;
|
||||
extern int32_t tscReqRef;
|
||||
extern int32_t tscConnRef;
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <catalog.h>
|
||||
#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();
|
||||
|
|
|
@ -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,6 +122,153 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst);
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen);
|
||||
(*pRequest)->sqlstr[sqlLen] = 0;
|
||||
(*pRequest)->sqlLen = sqlLen;
|
||||
|
||||
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), .pTransporter = pTscObj->pTransporter},
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = pRequest->sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(pSendMsg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
|
||||
//temporary disabled until planner ready
|
||||
#if 0
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
|
||||
//TODO: check sql valid
|
||||
|
||||
CHECK_CODE_GOTO(qCreateQueryDag(pQuery, &pDag), _return);
|
||||
|
||||
dagStr = qDagToString(pDag);
|
||||
if(dagStr == NULL) {
|
||||
//TODO
|
||||
}
|
||||
#endif
|
||||
|
||||
SCMCreateTopicReq req = {
|
||||
.name = (char*)name,
|
||||
.igExists = 0,
|
||||
/*.physicalPlan = dagStr,*/
|
||||
.physicalPlan = (char*)sql,
|
||||
.logicalPlan = "",
|
||||
};
|
||||
|
||||
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);*/
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen };
|
||||
|
||||
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) {
|
||||
|
@ -123,99 +279,35 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
|
||||
nPrintTsc("%s", sql)
|
||||
|
||||
SRequestObj* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
strntolower(pRequest->sqlstr, sql, (int32_t)sqlLen);
|
||||
pRequest->sqlstr[sqlLen] = 0;
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr);
|
||||
|
||||
SParseContext cxt = {
|
||||
.ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)},
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE
|
||||
};
|
||||
SRequestObj* pRequest = NULL;
|
||||
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};
|
||||
SQueryDag* pDag = NULL;
|
||||
void* pJob = NULL;
|
||||
|
||||
SRequestMsgBody body = buildRequestMsgImpl(pRequest);
|
||||
SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
|
||||
|
||||
if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) {
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
|
||||
char buf[12] = {0};
|
||||
sprintf(buf, "%d", pTscObj->pAppInfo->clusterId);
|
||||
code = catalogGetHandle(buf, &pCatalog);
|
||||
if (code != 0) {
|
||||
pRequest->code = code;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
SCreateTableMsg* pMsg = body.msgInfo.pMsg;
|
||||
|
||||
SName t = {0};
|
||||
tNameFromString(&t, pMsg->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE);
|
||||
|
||||
char db[TSDB_DB_NAME_LEN + TS_PATH_DELIMITER_LEN + TSDB_ACCT_ID_LEN] = {0};
|
||||
tNameGetFullDbName(&t, db);
|
||||
|
||||
SVgroupInfo info = {0};
|
||||
catalogGetTableHashVgroup(pCatalog, pTscObj->pTransporter, pEpSet, db, tNameGetTableName(&t), &info);
|
||||
|
||||
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]));
|
||||
}
|
||||
|
||||
sendMsgToServer(pTscObj->pTransporter, &ep, &body, &transporterId);
|
||||
} else {
|
||||
int64_t transporterId = 0;
|
||||
sendMsgToServer(pTscObj->pTransporter, pEpSet, &body, &transporterId);
|
||||
}
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroyRequestMsgBody(&body);
|
||||
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);
|
||||
}
|
||||
|
||||
tfree(cxt.ctx.db);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
return pRequest;
|
||||
_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;
|
||||
}
|
||||
if (pSendInfo->requestObjRefId != 0) {
|
||||
SRequestObj *pRequest = (SRequestObj *)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
||||
assert(pRequest->self == pSendInfo->requestObjRefId);
|
||||
|
||||
assert(pRequest->self == requestRefId);
|
||||
pRequest->metric.rsp = taosGetTimestampMs();
|
||||
pRequest->metric.rsp = taosGetTimestampMs();
|
||||
pRequest->code = pMsg->code;
|
||||
|
||||
pRequest->code = pMsg->code;
|
||||
|
||||
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);
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
if (pEpSet) {
|
||||
if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, pEpSet)) {
|
||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, pEpSet);
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
|
||||
/*
|
||||
* 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,
|
||||
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);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscReqRef, requestRefId);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
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 {
|
||||
memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
|
||||
}
|
||||
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
pConnect->pid = htonl(appInfo.pid);
|
||||
pConnect->startTime = htobe64(appInfo.startTime);
|
||||
tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app));
|
||||
|
||||
pMsgBody->msgInfo.pMsg = pConnect;
|
||||
return 0;
|
||||
static void setErrno(SRequestObj* pRequest, int32_t code) {
|
||||
pRequest->code = code;
|
||||
terrno = code;
|
||||
}
|
||||
|
||||
int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj* pRequest = param;
|
||||
setErrno(pRequest, code);
|
||||
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
||||
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;
|
||||
SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) {
|
||||
SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo));
|
||||
|
||||
SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
|
||||
if (pRetrieveMsg == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||
pMsgSendInfo->requestId = pRequest->requestId;
|
||||
pMsgSendInfo->param = pRequest;
|
||||
pMsgSendInfo->msgType = pRequest->type;
|
||||
|
||||
pRetrieveMsg->showId = htonl(pRequest->body.execId);
|
||||
pMsgBody->msgInfo.pMsg = pRetrieveMsg;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest) {
|
||||
if (pRequest->type == TSDB_MSG_TYPE_SHOW_RETRIEVE) {
|
||||
SRequestMsgBody body = {0};
|
||||
buildRetrieveMnodeMsg(pRequest, &body);
|
||||
return body;
|
||||
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);
|
||||
SRequestMsgBody body = {
|
||||
.requestObjRefId = pRequest->self,
|
||||
.msgInfo = pRequest->body.requestMsg,
|
||||
.msgType = pRequest->type,
|
||||
.requestId = pRequest->requestId,
|
||||
};
|
||||
return body;
|
||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||
}
|
||||
|
||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||
return pMsgSendInfo;
|
||||
}
|
||||
|
||||
int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
SShowRsp* pShow = (SShowRsp *)pMsg;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg;
|
||||
assert(pMsg->len >= sizeof(SRetrieveTableRsp));
|
||||
|
||||
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) {
|
||||
// todo rsp with the vnode id list
|
||||
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 processUseDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg;
|
||||
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(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;
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
#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, "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);
|
||||
// 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,11 +161,55 @@ 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, create_dnode_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
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);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
ASSERT_EQ(numOfFields, 0);
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, use_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, "use abc1");
|
||||
|
@ -182,24 +227,182 @@ TEST(testCase, use_db_test) {
|
|||
}
|
||||
|
||||
TEST(testCase, drop_db_test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// showDB(pConn);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// showDB(pConn);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("create to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_stable_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, "create database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
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("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
}
|
||||
|
||||
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("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, "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);
|
||||
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);
|
||||
|
||||
showDB(pConn);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
// TEST(testCase, create_stable_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
TEST(testCase, drop_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 creating 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 using db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop stable st1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
#endif
|
||||
|
||||
//TEST(testCase, create_topic_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
|
@ -226,29 +429,26 @@ TEST(testCase, drop_db_test) {
|
|||
// 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, create_table_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_ctable_Test) {}
|
||||
|
||||
TEST(testCase, show_stable_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
TEST(testCase, show_table_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");
|
||||
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);
|
||||
|
@ -261,44 +461,5 @@ TEST(testCase, show_stable_Test) {
|
|||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_stable_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in creating 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 using db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop stable st1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, show_table_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "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");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,17 +15,18 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
#include "ulog.h"
|
||||
#include "tlog.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tcompare.h"
|
||||
#include "tutil.h"
|
||||
#include "ttimezone.h"
|
||||
#include "tlocale.h"
|
||||
#include "tconfig.h"
|
||||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlocale.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
|
||||
// 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.
|
||||
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 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
|
||||
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;
|
||||
|
@ -200,7 +186,6 @@ void taosSetAllDebugFlag() {
|
|||
dDebugFlag = debugFlag;
|
||||
vDebugFlag = debugFlag;
|
||||
jniDebugFlag = debugFlag;
|
||||
odbcDebugFlag = debugFlag;
|
||||
qDebugFlag = debugFlag;
|
||||
rpcDebugFlag = debugFlag;
|
||||
uDebugFlag = 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,7 +216,7 @@ 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);
|
||||
|
@ -262,7 +247,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
|
|||
return 0;
|
||||
}
|
||||
if (strncasecmp(cfg->option, "debugFlag", olen) == 0) {
|
||||
taosSetAllDebugFlag();
|
||||
taosSetAllDebugFlag();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -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,17 +1073,14 @@ 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) {
|
||||
|
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "taos.h"
|
||||
#include "taosdef.h"
|
||||
#include "thash.h"
|
||||
#include "ttime.h"
|
||||
#include "ttokendef.h"
|
||||
#include "ttypes.h"
|
||||
|
|
|
@ -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)
|
|
@ -0,0 +1,11 @@
|
|||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(mgmt)
|
|
@ -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
|
||||
)
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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) {}
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
taos_queue pMgmtQ;
|
||||
SWorkerPool mgmtPool;
|
||||
} SDnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
int32_t refCount;
|
||||
int8_t deployed;
|
||||
int8_t dropped;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
char *file;
|
||||
SMnode *pMnode;
|
||||
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;
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_*/
|
|
@ -0,0 +1,379 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -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 (pMsg->pCont != NULL && pMsg->contLen != 0) {
|
||||
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
dndUpdateDnodeCfg(pDnode, pCfg);
|
||||
|
||||
if (pCfg->dropped) {
|
||||
pMgmt->statusSent = 0;
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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_NETWORK_TEST:
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
case TDMT_DND_CREATE_MNODE:
|
||||
code = dndProcessCreateMnodeReq(pDnode, pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_CONFIG_DNODE_IN:
|
||||
dndProcessConfigDnodeReq(pDnode, pMsg);
|
||||
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 TDMT_MND_STATUS_RSP:
|
||||
dndProcessStatusRsp(pDnode, pMsg);
|
||||
break;
|
||||
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 req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
|
||||
void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_STATUS_RSP:
|
||||
dndProcessStatusRsp(pDnode, pMsg, pEpSet);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_AUTH_RSP:
|
||||
dndProcessAuthRsp(pDnode, pMsg, pEpSet);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_GRANT_RSP:
|
||||
dndProcessGrantRsp(pDnode, pMsg, pEpSet);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
while (pMgmt->refCount > 1) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
dndCleanupMnodeReadWorker(pDnode);
|
||||
dndCleanupMnodeWriteWorker(pDnode);
|
||||
dndCleanupMnodeSyncWorker(pDnode);
|
||||
|
||||
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,23 +444,28 @@ 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);
|
||||
}
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAlterMnode(pDnode, &option) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndWriteMnodeFile(pDnode);
|
||||
}
|
||||
|
||||
static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDropMnodeInMsg *pMsg = pRpcMsg->pCont;
|
||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
|
@ -541,39 +476,12 @@ static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessReadMsg(pMsg);
|
||||
mndProcessMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
|
@ -582,306 +490,43 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
|||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeWriteQueue(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) {
|
||||
mndProcessWriteMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
code = dndWriteMsgToWorker(pWorker, pMsg, 0);
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
}
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessApplyMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (taosWriteQitem(pQueue, pMsg) != 0) {
|
||||
mndCleanupMsg(pMsg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,358 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
)
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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);
|
||||
// }
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue