提交 2b2c2ad5 编写于 作者: H Haojun Liao

Merge remote-tracking branch 'origin/3.0' into feature/3.0_liaohj

...@@ -46,16 +46,20 @@ IF (TD_WINDOWS) ...@@ -46,16 +46,20 @@ IF (TD_WINDOWS)
ENDIF () ENDIF ()
ELSE () ELSE ()
IF (${SANITIZER} MATCHES "true")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
MESSAGE(STATUS "Will compile with Address Sanitizer!")
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") ENDIF ()
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
ADD_DEFINITIONS("-D_TD_ARM_") ADD_DEFINITIONS("-D_TD_ARM_")
ELSE () ELSE ()
ADD_DEFINITIONS("-msse4.2 -mfma") ADD_DEFINITIONS("-msse4.2 -mfma")
ENDIF () ENDIF ()
ENDIF () ENDIF ()
...@@ -65,22 +65,32 @@ static void prepare_data(TAOS* taos) { ...@@ -65,22 +65,32 @@ static void prepare_data(TAOS* taos) {
usleep(100000); usleep(100000);
taos_select_db(taos, "test"); taos_select_db(taos, "test");
res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20)) tags(area int, localtion binary(20));"); res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20), c nchar(20)) tags(area int, city binary(20), dist nchar(20));");
taos_free_result(res); taos_free_result(res);
char command[1024] = {0}; char command[1024] = {0};
for (int64_t i = 0; i < g_num_of_tb; i ++) { for (int64_t i = 0; i < g_num_of_tb; i ++) {
sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s');", // sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');",
i, i, (i%2)?"beijing":"shanghai"); // i, i, (i%2)?"beijing":"shanghai", (i%2)?"朝阳区":"黄浦区");
sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');",
i, i, (i%2)?"beijing":"shanghai", (i%2)?"chaoyang":"huangpu");
res = taos_query(taos, command); res = taos_query(taos, command);
if ((res) && (0 == taos_errno(res))) {
okPrint("t%" PRId64 " created\n", i);
} else {
errorPrint("%s() LN%d: %s\n",
__func__, __LINE__, taos_errstr(res));
}
taos_free_result(res); taos_free_result(res);
int64_t j = 0; int64_t j = 0;
int64_t total = 0; int64_t total = 0;
int64_t affected; int64_t affected;
for (; j < g_num_of_rec -1; j ++) { for (; j < g_num_of_rec -1; j ++) {
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", %f, %"PRId64", '%c%d')", sprintf(command, "insert into t%"PRId64" "
i, 1650000000000+j, (float)j, j, 'a'+(int)j%10, rand()); "values(%" PRId64 ", %f, %"PRId64", '%c%d', '%c%d')",
i, 1650000000000+j, (float)j, j, 'a'+(int)j%25, rand(),
'z' - (int)j%25, rand());
res = taos_query(taos, command); res = taos_query(taos, command);
if ((res) && (0 == taos_errno(res))) { if ((res) && (0 == taos_errno(res))) {
affected = taos_affected_rows(res); affected = taos_affected_rows(res);
...@@ -91,7 +101,7 @@ static void prepare_data(TAOS* taos) { ...@@ -91,7 +101,7 @@ static void prepare_data(TAOS* taos) {
} }
taos_free_result(res); taos_free_result(res);
} }
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL)", sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL, NULL)",
i, 1650000000000+j+1); i, 1650000000000+j+1);
res = taos_query(taos, command); res = taos_query(taos, command);
if ((res) && (0 == taos_errno(res))) { if ((res) && (0 == taos_errno(res))) {
...@@ -107,12 +117,16 @@ static void prepare_data(TAOS* taos) { ...@@ -107,12 +117,16 @@ static void prepare_data(TAOS* taos) {
} }
} }
static int print_result(TAOS_RES* res, int block) { static int print_result(char *tbname, TAOS_RES* res, int block) {
int64_t num_rows = 0; int64_t num_rows = 0;
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
int num_fields = taos_num_fields(res); int num_fields = taos_num_fields(res);
TAOS_FIELD* fields = taos_fetch_fields(res); TAOS_FIELD* fields = taos_fetch_fields(res);
for (int f = 0; f < num_fields; f++) {
printf("fields[%d].name=%s, fields[%d].type=%d, fields[%d].bytes=%d\n",
f, fields[f].name, f, fields[f].type, f, fields[f].bytes);
}
if (block) { if (block) {
warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__); warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__);
int rows = 0; int rows = 0;
...@@ -126,6 +140,16 @@ static int print_result(TAOS_RES* res, int block) { ...@@ -126,6 +140,16 @@ static int print_result(TAOS_RES* res, int block) {
taos_print_row(temp, row, fields, num_fields); taos_print_row(temp, row, fields, num_fields);
puts(temp); puts(temp);
num_rows ++; num_rows ++;
int* lengths = taos_fetch_lengths(res);
if (lengths) {
for (int c = 0; c < num_fields; c++) {
printf("length of column %d is %d\n", c, lengths[c]);
}
} else {
errorPrint("%s() LN%d: %s's lengths is NULL\n",
__func__, __LINE__, tbname);
}
} }
} }
...@@ -134,27 +158,20 @@ static int print_result(TAOS_RES* res, int block) { ...@@ -134,27 +158,20 @@ static int print_result(TAOS_RES* res, int block) {
static void verify_query(TAOS* taos) { static void verify_query(TAOS* taos) {
// TODO: select count(tbname) from stable once stable query work // TODO: select count(tbname) from stable once stable query work
//
char tbname[193] = {0};
char command[1024] = {0}; char command[1024] = {0};
for (int64_t i = 0; i < g_num_of_tb; i++) { for (int64_t i = 0; i < g_num_of_tb; i++) {
sprintf(command, "select * from t%"PRId64"", i); sprintf(tbname, "t%"PRId64"", i);
sprintf(command, "select * from %s", tbname);
TAOS_RES* res = taos_query(taos, command); TAOS_RES* res = taos_query(taos, command);
if (res) { if (res) {
if (0 == taos_errno(res)) { if (0 == taos_errno(res)) {
int field_count = taos_field_count(res); int field_count = taos_field_count(res);
printf("field_count: %d\n", field_count); printf("field_count: %d\n", field_count);
int* lengths = taos_fetch_lengths(res); int64_t rows = print_result(tbname, res, i % 2);
if (lengths) {
for (int c = 0; c < field_count; c++) {
printf("length of column %d is %d\n", c, lengths[c]);
}
} else {
errorPrint("%s() LN%d: t%"PRId64"'s lengths is NULL\n",
__func__, __LINE__, i);
}
int64_t rows = print_result(res, i % 2);
printf("rows is: %"PRId64"\n", rows); printf("rows is: %"PRId64"\n", rows);
} else { } else {
......
...@@ -86,30 +86,31 @@ enum { ...@@ -86,30 +86,31 @@ enum {
typedef enum _mgmt_table { typedef enum _mgmt_table {
TSDB_MGMT_TABLE_START, TSDB_MGMT_TABLE_START,
TSDB_MGMT_TABLE_ACCT,
TSDB_MGMT_TABLE_USER,
TSDB_MGMT_TABLE_DB,
TSDB_MGMT_TABLE_TABLE,
TSDB_MGMT_TABLE_DNODE, TSDB_MGMT_TABLE_DNODE,
TSDB_MGMT_TABLE_MNODE, TSDB_MGMT_TABLE_MNODE,
TSDB_MGMT_TABLE_MODULE,
TSDB_MGMT_TABLE_QNODE, TSDB_MGMT_TABLE_QNODE,
TSDB_MGMT_TABLE_SNODE, TSDB_MGMT_TABLE_SNODE,
TSDB_MGMT_TABLE_BNODE, TSDB_MGMT_TABLE_BNODE,
TSDB_MGMT_TABLE_VGROUP, TSDB_MGMT_TABLE_CLUSTER,
TSDB_MGMT_TABLE_DB,
TSDB_MGMT_TABLE_FUNC,
TSDB_MGMT_TABLE_INDEX,
TSDB_MGMT_TABLE_STB, TSDB_MGMT_TABLE_STB,
TSDB_MGMT_TABLE_MODULE,
TSDB_MGMT_TABLE_QUERIES,
TSDB_MGMT_TABLE_STREAMS, TSDB_MGMT_TABLE_STREAMS,
TSDB_MGMT_TABLE_VARIABLES, TSDB_MGMT_TABLE_TABLE,
TSDB_MGMT_TABLE_CONNS, TSDB_MGMT_TABLE_USER,
TSDB_MGMT_TABLE_TRANS,
TSDB_MGMT_TABLE_GRANTS, TSDB_MGMT_TABLE_GRANTS,
TSDB_MGMT_TABLE_VGROUP,
TSDB_MGMT_TABLE_TOPICS,
TSDB_MGMT_TABLE_CONSUMERS,
TSDB_MGMT_TABLE_SUBSCRIBES,
TSDB_MGMT_TABLE_TRANS,
TSDB_MGMT_TABLE_SMAS,
TSDB_MGMT_TABLE_CONFIGS,
TSDB_MGMT_TABLE_CONNS,
TSDB_MGMT_TABLE_QUERIES,
TSDB_MGMT_TABLE_VNODES, TSDB_MGMT_TABLE_VNODES,
TSDB_MGMT_TABLE_CLUSTER,
TSDB_MGMT_TABLE_STREAMTABLES,
TSDB_MGMT_TABLE_TP,
TSDB_MGMT_TABLE_FUNC,
TSDB_MGMT_TABLE_INDEX,
TSDB_MGMT_TABLE_MAX, TSDB_MGMT_TABLE_MAX,
} EShowType; } EShowType;
...@@ -363,7 +364,7 @@ typedef struct { ...@@ -363,7 +364,7 @@ typedef struct {
int32_t maxTimeSeries; int32_t maxTimeSeries;
int32_t maxStreams; int32_t maxStreams;
int32_t accessState; // Configured only by command int32_t accessState; // Configured only by command
int64_t maxStorage; // In unit of GB int64_t maxStorage;
} SCreateAcctReq, SAlterAcctReq; } SCreateAcctReq, SAlterAcctReq;
int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq); int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
...@@ -748,7 +749,7 @@ typedef struct { ...@@ -748,7 +749,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t sver; // software version int32_t sver; // software version
int64_t dver; // dnode table version in sdb int64_t dnodeVer; // dnode table version in sdb
int32_t dnodeId; int32_t dnodeId;
int64_t clusterId; int64_t clusterId;
int64_t rebootTime; int64_t rebootTime;
...@@ -762,6 +763,7 @@ typedef struct { ...@@ -762,6 +763,7 @@ typedef struct {
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
void tFreeSStatusReq(SStatusReq* pReq);
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
...@@ -775,7 +777,7 @@ typedef struct { ...@@ -775,7 +777,7 @@ typedef struct {
} SDnodeEp; } SDnodeEp;
typedef struct { typedef struct {
int64_t dver; int64_t dnodeVer;
SDnodeCfg dnodeCfg; SDnodeCfg dnodeCfg;
SArray* pDnodeEps; // Array of SDnodeEp SArray* pDnodeEps; // Array of SDnodeEp
} SStatusRsp; } SStatusRsp;
...@@ -1883,7 +1885,6 @@ typedef struct { ...@@ -1883,7 +1885,6 @@ typedef struct {
char topicName[TSDB_TOPIC_FNAME_LEN]; char topicName[TSDB_TOPIC_FNAME_LEN];
char cgroup[TSDB_CGROUP_LEN]; char cgroup[TSDB_CGROUP_LEN];
char* sql; char* sql;
char* logicalPlan;
char* physicalPlan; char* physicalPlan;
char* qmsg; char* qmsg;
} SMqSetCVgReq; } SMqSetCVgReq;
...@@ -1897,7 +1898,6 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq* ...@@ -1897,7 +1898,6 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq*
tlen += taosEncodeString(buf, pReq->topicName); tlen += taosEncodeString(buf, pReq->topicName);
tlen += taosEncodeString(buf, pReq->cgroup); tlen += taosEncodeString(buf, pReq->cgroup);
tlen += taosEncodeString(buf, pReq->sql); tlen += taosEncodeString(buf, pReq->sql);
tlen += taosEncodeString(buf, pReq->logicalPlan);
tlen += taosEncodeString(buf, pReq->physicalPlan); tlen += taosEncodeString(buf, pReq->physicalPlan);
tlen += taosEncodeString(buf, pReq->qmsg); tlen += taosEncodeString(buf, pReq->qmsg);
return tlen; return tlen;
...@@ -1911,7 +1911,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) { ...@@ -1911,7 +1911,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
buf = taosDecodeStringTo(buf, pReq->topicName); buf = taosDecodeStringTo(buf, pReq->topicName);
buf = taosDecodeStringTo(buf, pReq->cgroup); buf = taosDecodeStringTo(buf, pReq->cgroup);
buf = taosDecodeString(buf, &pReq->sql); buf = taosDecodeString(buf, &pReq->sql);
buf = taosDecodeString(buf, &pReq->logicalPlan);
buf = taosDecodeString(buf, &pReq->physicalPlan); buf = taosDecodeString(buf, &pReq->physicalPlan);
buf = taosDecodeString(buf, &pReq->qmsg); buf = taosDecodeString(buf, &pReq->qmsg);
return buf; return buf;
......
...@@ -181,49 +181,50 @@ ...@@ -181,49 +181,50 @@
#define TK_NULL 163 #define TK_NULL 163
#define TK_FIRST 164 #define TK_FIRST 164
#define TK_LAST 165 #define TK_LAST 165
#define TK_NOW 166 #define TK_CAST 166
#define TK_TODAY 167 #define TK_NOW 167
#define TK_ROWTS 168 #define TK_TODAY 168
#define TK_TBNAME 169 #define TK_ROWTS 169
#define TK_QSTARTTS 170 #define TK_TBNAME 170
#define TK_QENDTS 171 #define TK_QSTARTTS 171
#define TK_WSTARTTS 172 #define TK_QENDTS 172
#define TK_WENDTS 173 #define TK_WSTARTTS 173
#define TK_WDURATION 174 #define TK_WENDTS 174
#define TK_BETWEEN 175 #define TK_WDURATION 175
#define TK_IS 176 #define TK_BETWEEN 176
#define TK_NK_LT 177 #define TK_IS 177
#define TK_NK_GT 178 #define TK_NK_LT 178
#define TK_NK_LE 179 #define TK_NK_GT 179
#define TK_NK_GE 180 #define TK_NK_LE 180
#define TK_NK_NE 181 #define TK_NK_GE 181
#define TK_MATCH 182 #define TK_NK_NE 182
#define TK_NMATCH 183 #define TK_MATCH 183
#define TK_JOIN 184 #define TK_NMATCH 184
#define TK_INNER 185 #define TK_JOIN 185
#define TK_SELECT 186 #define TK_INNER 186
#define TK_DISTINCT 187 #define TK_SELECT 187
#define TK_WHERE 188 #define TK_DISTINCT 188
#define TK_PARTITION 189 #define TK_WHERE 189
#define TK_BY 190 #define TK_PARTITION 190
#define TK_SESSION 191 #define TK_BY 191
#define TK_STATE_WINDOW 192 #define TK_SESSION 192
#define TK_SLIDING 193 #define TK_STATE_WINDOW 193
#define TK_FILL 194 #define TK_SLIDING 194
#define TK_VALUE 195 #define TK_FILL 195
#define TK_NONE 196 #define TK_VALUE 196
#define TK_PREV 197 #define TK_NONE 197
#define TK_LINEAR 198 #define TK_PREV 198
#define TK_NEXT 199 #define TK_LINEAR 199
#define TK_GROUP 200 #define TK_NEXT 200
#define TK_HAVING 201 #define TK_GROUP 201
#define TK_ORDER 202 #define TK_HAVING 202
#define TK_SLIMIT 203 #define TK_ORDER 203
#define TK_SOFFSET 204 #define TK_SLIMIT 204
#define TK_LIMIT 205 #define TK_SOFFSET 205
#define TK_OFFSET 206 #define TK_LIMIT 206
#define TK_ASC 207 #define TK_OFFSET 207
#define TK_NULLS 208 #define TK_ASC 208
#define TK_NULLS 209
#define TK_NK_SPACE 300 #define TK_NK_SPACE 300
#define TK_NK_COMMENT 301 #define TK_NK_COMMENT 301
......
...@@ -181,6 +181,7 @@ typedef struct { ...@@ -181,6 +181,7 @@ typedef struct {
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) #define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) #define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) #define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
#define IS_INTEGER_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)))
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t))) #define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
#define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP)) #define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
......
...@@ -30,12 +30,12 @@ typedef struct SDnode SDnode; ...@@ -30,12 +30,12 @@ typedef struct SDnode SDnode;
* *
* @return int32_t 0 for success and -1 for failure * @return int32_t 0 for success and -1 for failure
*/ */
int32_t dndInit(); int32_t dmInit();
/** /**
* @brief Clear the environment * @brief Clear the environment
*/ */
void dndCleanup(); void dmCleanup();
/* ------------------------ SDnode ----------------------- */ /* ------------------------ SDnode ----------------------- */
typedef struct { typedef struct {
...@@ -51,7 +51,7 @@ typedef struct { ...@@ -51,7 +51,7 @@ typedef struct {
int8_t ntype; int8_t ntype;
} SDnodeOpt; } SDnodeOpt;
typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent;
/** /**
* @brief Initialize and start the dnode. * @brief Initialize and start the dnode.
...@@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; ...@@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
* @param pOption Option of the dnode. * @param pOption Option of the dnode.
* @return SDnode* The dnode object. * @return SDnode* The dnode object.
*/ */
SDnode *dndCreate(const SDnodeOpt *pOption); SDnode *dmCreate(const SDnodeOpt *pOption);
/** /**
* @brief Stop and cleanup the dnode. * @brief Stop and cleanup the dnode.
* *
* @param pDnode The dnode object to close. * @param pDnode The dnode object to close.
*/ */
void dndClose(SDnode *pDnode); void dmClose(SDnode *pDnode);
/** /**
* @brief Run dnode until specific event is receive. * @brief Run dnode until specific event is receive.
* *
* @param pDnode The dnode object to run. * @param pDnode The dnode object to run.
*/ */
int32_t dndRun(SDnode *pDnode); int32_t dmRun(SDnode *pDnode);
/** /**
* @brief Handle event in the dnode. * @brief Handle event in the dnode.
...@@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode); ...@@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode);
* @param pDnode The dnode object to close. * @param pDnode The dnode object to close.
* @param event The event to handle. * @param event The event to handle.
*/ */
void dndHandleEvent(SDnode *pDnode, EDndEvent event); void dmSetEvent(SDnode *pDnode, EDndEvent event);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -68,31 +68,18 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); ...@@ -68,31 +68,18 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
* @param pMnode The mnode object. * @param pMnode The mnode object.
*/ */
int32_t mndStart(SMnode *pMnode); int32_t mndStart(SMnode *pMnode);
void mndStop(SMnode *pMnode);
/** /**
* @brief Get mnode monitor info. * @brief Get mnode monitor info.
* *
* @param pMnode The mnode object. * @param pMnode The mnode object.
* @param pClusterInfo * @param pCluster
* @param pVgroupInfo * @param pVgroup
* @param pGrantInfo * @param pGrant
* @return int32_t 0 for success, -1 for failure. * @return int32_t 0 for success, -1 for failure.
*/ */
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
SMonGrantInfo *pGrantInfo);
/**
* @brief Get user authentication info.
*
* @param pMnode The mnode object.
* @param user
* @param spi
* @param encrypt
* @param secret
* @param ckey
* @return int32_t 0 for success, -1 for failure.
*/
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
/** /**
* @brief Process the read, write, sync request. * @brief Process the read, write, sync request.
...@@ -102,6 +89,11 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha ...@@ -102,6 +89,11 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha
*/ */
int32_t mndProcessMsg(SNodeMsg *pMsg); int32_t mndProcessMsg(SNodeMsg *pMsg);
/**
* @brief Generate machine code
*/
void mndGenerateMachineCode();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -123,7 +123,7 @@ void fmFuncMgtDestroy(); ...@@ -123,7 +123,7 @@ void fmFuncMgtDestroy();
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
int32_t fmGetFuncResultType(SFunctionNode* pFunc); int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
bool fmIsAggFunc(int32_t funcId); bool fmIsAggFunc(int32_t funcId);
bool fmIsScalarFunc(int32_t funcId); bool fmIsScalarFunc(int32_t funcId);
......
...@@ -267,6 +267,11 @@ typedef struct SDescribeStmt { ...@@ -267,6 +267,11 @@ typedef struct SDescribeStmt {
STableMeta* pMeta; STableMeta* pMeta;
} SDescribeStmt; } SDescribeStmt;
typedef struct SKillStmt {
ENodeType type;
int32_t targetId;
} SKillStmt;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -52,7 +52,8 @@ extern "C" { ...@@ -52,7 +52,8 @@ extern "C" {
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext)
typedef enum ENodeType { typedef enum ENodeType {
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on. // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
// VALUE, OPERATOR, FUNCTION and so on.
QUERY_NODE_COLUMN = 1, QUERY_NODE_COLUMN = 1,
QUERY_NODE_VALUE, QUERY_NODE_VALUE,
QUERY_NODE_OPERATOR, QUERY_NODE_OPERATOR,
...@@ -126,30 +127,30 @@ typedef enum ENodeType { ...@@ -126,30 +127,30 @@ typedef enum ENodeType {
QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
QUERY_NODE_SPLIT_VGROUP_STMT, QUERY_NODE_SPLIT_VGROUP_STMT,
QUERY_NODE_SYNCDB_STMT, QUERY_NODE_SYNCDB_STMT,
QUERY_NODE_SHOW_DATABASES_STMT,
QUERY_NODE_SHOW_TABLES_STMT,
QUERY_NODE_SHOW_STABLES_STMT,
QUERY_NODE_SHOW_USERS_STMT,
QUERY_NODE_SHOW_DNODES_STMT, QUERY_NODE_SHOW_DNODES_STMT,
QUERY_NODE_SHOW_VGROUPS_STMT,
QUERY_NODE_SHOW_MNODES_STMT, QUERY_NODE_SHOW_MNODES_STMT,
QUERY_NODE_SHOW_MODULES_STMT, QUERY_NODE_SHOW_MODULES_STMT,
QUERY_NODE_SHOW_QNODES_STMT, QUERY_NODE_SHOW_QNODES_STMT,
QUERY_NODE_SHOW_SNODES_STMT,
QUERY_NODE_SHOW_BNODES_STMT,
QUERY_NODE_SHOW_DATABASES_STMT,
QUERY_NODE_SHOW_FUNCTIONS_STMT, QUERY_NODE_SHOW_FUNCTIONS_STMT,
QUERY_NODE_SHOW_INDEXES_STMT, QUERY_NODE_SHOW_INDEXES_STMT,
QUERY_NODE_SHOW_STABLES_STMT,
QUERY_NODE_SHOW_STREAMS_STMT, QUERY_NODE_SHOW_STREAMS_STMT,
QUERY_NODE_SHOW_APPS_STMT, QUERY_NODE_SHOW_TABLES_STMT,
QUERY_NODE_SHOW_CONNECTIONS_STMT, QUERY_NODE_SHOW_USERS_STMT,
QUERY_NODE_SHOW_LICENCE_STMT, QUERY_NODE_SHOW_LICENCE_STMT,
QUERY_NODE_SHOW_CREATE_DATABASE_STMT, QUERY_NODE_SHOW_VGROUPS_STMT,
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
QUERY_NODE_SHOW_QUERIES_STMT,
QUERY_NODE_SHOW_SCORES_STMT,
QUERY_NODE_SHOW_TOPICS_STMT, QUERY_NODE_SHOW_TOPICS_STMT,
QUERY_NODE_SHOW_VARIABLE_STMT, QUERY_NODE_SHOW_CONSUMERS_STMT,
QUERY_NODE_SHOW_BNODES_STMT, QUERY_NODE_SHOW_SUBSCRIBES_STMT,
QUERY_NODE_SHOW_SNODES_STMT, QUERY_NODE_SHOW_TRANS_STMT,
QUERY_NODE_SHOW_SMAS_STMT,
QUERY_NODE_SHOW_CONFIGS_STMT,
QUERY_NODE_SHOW_CONNECTIONS_STMT,
QUERY_NODE_SHOW_QUERIES_STMT,
QUERY_NODE_SHOW_VNODES_STMT,
QUERY_NODE_KILL_CONNECTION_STMT, QUERY_NODE_KILL_CONNECTION_STMT,
QUERY_NODE_KILL_QUERY_STMT, QUERY_NODE_KILL_QUERY_STMT,
......
...@@ -566,8 +566,6 @@ int32_t* taosGetErrno(); ...@@ -566,8 +566,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603) #define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604) #define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605) #define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
#define TSDB_CODE_PAR_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2606)
#define TSDB_CODE_PAR_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2607)
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
...@@ -603,6 +601,11 @@ int32_t* taosGetErrno(); ...@@ -603,6 +601,11 @@ int32_t* taosGetErrno();
//planner //planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
//function
#define TSDB_CODE_FUNC_FUNTION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2800)
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -106,6 +106,7 @@ extern const int32_t TYPE_BYTES[15]; ...@@ -106,6 +106,7 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_INS_TABLE_MODULES "modules" #define TSDB_INS_TABLE_MODULES "modules"
#define TSDB_INS_TABLE_QNODES "qnodes" #define TSDB_INS_TABLE_QNODES "qnodes"
#define TSDB_INS_TABLE_BNODES "bnodes" #define TSDB_INS_TABLE_BNODES "bnodes"
#define TSDB_INS_TABLE_SNODES "snodes"
#define TSDB_INS_TABLE_CLUSTER "cluster" #define TSDB_INS_TABLE_CLUSTER "cluster"
#define TSDB_INS_TABLE_USER_DATABASES "user_databases" #define TSDB_INS_TABLE_USER_DATABASES "user_databases"
#define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions" #define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions"
...@@ -115,10 +116,17 @@ extern const int32_t TYPE_BYTES[15]; ...@@ -115,10 +116,17 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_INS_TABLE_USER_TABLES "user_tables" #define TSDB_INS_TABLE_USER_TABLES "user_tables"
#define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed" #define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed"
#define TSDB_INS_TABLE_USER_USERS "user_users" #define TSDB_INS_TABLE_USER_USERS "user_users"
#define TSDB_INS_TABLE_VGROUPS "vgroups"
#define TSDB_INS_TABLE_BNODES "bnodes"
#define TSDB_INS_TABLE_SNODES "snodes"
#define TSDB_INS_TABLE_LICENCES "grants" #define TSDB_INS_TABLE_LICENCES "grants"
#define TSDB_INS_TABLE_VGROUPS "vgroups"
#define TSDB_INS_TABLE_TOPICS "topics"
#define TSDB_INS_TABLE_CONSUMERS "consumers"
#define TSDB_INS_TABLE_SUBSCRIBES "subscribes"
#define TSDB_INS_TABLE_TRANS "trans"
#define TSDB_INS_TABLE_SMAS "smas"
#define TSDB_INS_TABLE_CONFIGS "configs"
#define TSDB_INS_TABLE_CONNS "connections"
#define TSDB_INS_TABLE_QUERIES "queries"
#define TSDB_INS_TABLE_VNODES "vnodes"
#define TSDB_INDEX_TYPE_SMA "SMA" #define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT" #define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
...@@ -498,6 +506,15 @@ enum { ...@@ -498,6 +506,15 @@ enum {
#define QNODE_HANDLE 1 #define QNODE_HANDLE 1
#define DEFAULT_HANDLE 0 #define DEFAULT_HANDLE 0
#define TSDB_CONFIG_OPTION_LEN 16
#define TSDB_CONIIG_VALUE_LEN 48
#define TSDB_CONFIG_NUMBER 8
#define QUERY_ID_SIZE 20
#define QUERY_OBJ_ID_SIZE 18
#define SUBQUERY_INFO_SIZE 6
#define QUERY_SAVE_SIZE 20
#define MAX_NUM_STR_SIZE 40 #define MAX_NUM_STR_SIZE 40
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "tcoding.h" #include "tcoding.h"
#include "tfreelist.h" #include "tfreelist.h"
#include "tmacro.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
extern "C" { extern "C" {
#endif #endif
typedef enum { PROC_REQ = 1, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType; typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType;
typedef struct SProcObj SProcObj; typedef struct SProcObj SProcObj;
typedef void *(*ProcMallocFp)(int32_t contLen); typedef void *(*ProcMallocFp)(int32_t contLen);
typedef void *(*ProcFreeFp)(void *pCont); typedef void *(*ProcFreeFp)(void *pCont);
typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen,
ProcFuncType ftype); EProcFuncType ftype);
typedef struct { typedef struct {
ProcConsumeFp childConsumeFp; ProcConsumeFp childConsumeFp;
...@@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc); ...@@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc);
void taosProcStop(SProcObj *pProc); void taosProcStop(SProcObj *pProc);
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
void *handle, ProcFuncType ftype); void *handle, EProcFuncType ftype);
void taosProcRemoveHandle(SProcObj *pProc, void *handle); void taosProcRemoveHandle(SProcObj *pProc, void *handle);
void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)); void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle));
void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
ProcFuncType ftype); EProcFuncType ftype);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -469,7 +469,10 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { ...@@ -469,7 +469,10 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
} }
if (TD_RES_TMQ(res)) { if (TD_RES_TMQ(res)) {
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
if (pResultInfo == NULL) return -1; if (pResultInfo == NULL) {
(*numOfRows) = 0;
return 0;
}
pResultInfo->current = pResultInfo->numOfRows; pResultInfo->current = pResultInfo->numOfRows;
(*numOfRows) = pResultInfo->numOfRows; (*numOfRows) = pResultInfo->numOfRows;
......
...@@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { ...@@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
tsDiskCfgNum = 1; tsDiskCfgNum = 1;
taosAddDataDir(0, pItem->str, 0, 1); taosAddDataDir(0, pItem->str, 0, 1);
tstrncpy(tsDataDir, pItem->str, PATH_MAX); tstrncpy(tsDataDir, pItem->str, PATH_MAX);
if (taosMkDir(tsDataDir) != 0) { if (taosMulMkDir(tsDataDir) != 0) {
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
return -1; return -1;
} }
...@@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { ...@@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg)); memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
if (pCfg->level == 0 && pCfg->primary == 1) { if (pCfg->level == 0 && pCfg->primary == 1) {
tstrncpy(tsDataDir, pCfg->dir, PATH_MAX); tstrncpy(tsDataDir, pCfg->dir, PATH_MAX);
if (taosMkDir(tsDataDir) != 0) { if (taosMulMkDir(tsDataDir) != 0) {
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
return -1; return -1;
} }
} }
if (taosMkDir(pCfg->dir) != 0) { if (taosMulMkDir(pCfg->dir) != 0) {
uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr()); uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr());
return -1; return -1;
} }
...@@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { ...@@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
if (taosMkDir(tsTempDir) != 0) { if (taosMulMkDir(tsTempDir) != 0) {
uError("failed to create tempDir:%s since %s", tsTempDir, terrstr()); uError("failed to create tempDir:%s since %s", tsTempDir, terrstr());
return -1; return -1;
} }
...@@ -495,7 +495,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { ...@@ -495,7 +495,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
tsRpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32; tsRpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32;
tsRpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32; tsRpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32;
tsRpcForceTcp = cfgGetItem(pCfg, "rpcForceTcp")->i32; tsRpcForceTcp = cfgGetItem(pCfg, "rpcForceTcp")->i32;
tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->bval; tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32;
tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32; tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32;
tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32;
tsMaxWildCardsLen = cfgGetItem(pCfg, "maxWildCardsLength")->i32; tsMaxWildCardsLen = cfgGetItem(pCfg, "maxWildCardsLength")->i32;
......
...@@ -870,7 +870,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { ...@@ -870,7 +870,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
// status // status
if (tEncodeI32(&encoder, pReq->sver) < 0) return -1; if (tEncodeI32(&encoder, pReq->sver) < 0) return -1;
if (tEncodeI64(&encoder, pReq->dver) < 0) return -1; if (tEncodeI64(&encoder, pReq->dnodeVer) < 0) return -1;
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1; if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1;
if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1; if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1;
...@@ -915,7 +915,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { ...@@ -915,7 +915,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
// status // status
if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1; if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->dver) < 0) return -1; if (tDecodeI64(&decoder, &pReq->dnodeVer) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1; if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1;
...@@ -960,6 +960,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { ...@@ -960,6 +960,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
return 0; return 0;
} }
void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); }
int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
SCoder encoder = {0}; SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
...@@ -967,7 +969,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { ...@@ -967,7 +969,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
if (tStartEncode(&encoder) < 0) return -1; if (tStartEncode(&encoder) < 0) return -1;
// status // status
if (tEncodeI64(&encoder, pRsp->dver) < 0) return -1; if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1;
// dnode cfg // dnode cfg
if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1; if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1;
...@@ -998,7 +1000,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { ...@@ -998,7 +1000,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
if (tStartDecode(&decoder) < 0) return -1; if (tStartDecode(&decoder) < 0) return -1;
// status // status
if (tDecodeI64(&decoder, &pRsp->dver) < 0) return -1; if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1;
// cluster cfg // cluster cfg
if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1;
...@@ -2182,7 +2184,6 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq ...@@ -2182,7 +2184,6 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq
if (tStartEncode(&encoder) < 0) return -1; if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI64(&encoder, pReq->showId) < 0) return -1; if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
if (tEncodeI32(&encoder, pReq->type) < 0) return -1; if (tEncodeI32(&encoder, pReq->type) < 0) return -1;
// if (tEncodeI8(&encoder, pReq->free) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1; if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1;
tEndEncode(&encoder); tEndEncode(&encoder);
...@@ -2199,7 +2200,6 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR ...@@ -2199,7 +2200,6 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR
if (tStartDecode(&decoder) < 0) return -1; if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->type) < 0) return -1; if (tDecodeI32(&decoder, &pReq->type) < 0) return -1;
// if (tDecodeI8(&decoder, &pReq->free) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1;
tEndDecode(&decoder); tEndDecode(&decoder);
......
aux_source_directory(dm DNODE_SRC) add_subdirectory(interface)
aux_source_directory(qm DNODE_SRC) add_subdirectory(implement)
aux_source_directory(bm DNODE_SRC) add_subdirectory(mgmt_bnode)
aux_source_directory(sm DNODE_SRC) add_subdirectory(mgmt_mnode)
aux_source_directory(vm DNODE_SRC) add_subdirectory(mgmt_qnode)
aux_source_directory(mm DNODE_SRC) add_subdirectory(mgmt_snode)
aux_source_directory(main DNODE_SRC) add_subdirectory(mgmt_vnode)
add_library(dnode STATIC ${DNODE_SRC}) add_subdirectory(test)
target_link_libraries(
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
)
target_include_directories(
dnode
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
aux_source_directory(exe EXEC_SRC) aux_source_directory(exe EXEC_SRC)
add_executable(taosd ${EXEC_SRC}) add_executable(taosd ${EXEC_SRC})
target_include_directories( target_include_directories(
taosd taosd
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc"
PRIVATE "${TD_SOURCE_DIR}/source/dnode/mnode/impl/inc"
) )
target_link_libraries(taosd dnode) target_link_libraries(taosd dnode)
if(${BUILD_TEST})
add_subdirectory(test)
endif(${BUILD_TEST})
/*
* 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 "dmInt.h"
void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) {
taosRLockLatch(&pMgmt->latch);
*pEpSet = pMgmt->mnodeEpSet;
taosRUnLockLatch(&pMgmt->latch);
}
void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) {
dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse);
taosWLockLatch(&pMgmt->latch);
pMgmt->mnodeEpSet = *pEpSet;
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
}
taosWUnLockLatch(&pMgmt->latch);
}
void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
taosRLockLatch(&pMgmt->latch);
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
if (pDnodeEp != NULL) {
if (pPort != NULL) {
*pPort = pDnodeEp->ep.port;
}
if (pFqdn != NULL) {
tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
}
if (pEp != NULL) {
snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
}
}
taosRUnLockLatch(&pMgmt->latch);
}
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) {
SDnode *pDnode = pMgmt->pDnode;
SEpSet epSet = {0};
dmGetMnodeEpSet(pMgmt, &epSet);
dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse);
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port);
if (strcmp(epSet.eps[i].fqdn, pDnode->localFqdn) == 0 && epSet.eps[i].port == pDnode->serverPort) {
epSet.inUse = (i + 1) % epSet.numOfEps;
}
epSet.eps[i].port = htons(epSet.eps[i].port);
}
rpcSendRedirectRsp(pReq->handle, &epSet);
}
static int32_t dmStart(SMgmtWrapper *pWrapper) {
dDebug("dnode-mgmt start to run");
return dmStartThread(pWrapper->pMgmt);
}
static int32_t dmInit(SMgmtWrapper *pWrapper) {
SDnode *pDnode = pWrapper->pDnode;
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
dInfo("dnode-mgmt start to init");
pDnode->dnodeId = 0;
pDnode->dropped = 0;
pDnode->clusterId = 0;
pMgmt->path = pWrapper->path;
pMgmt->pDnode = pDnode;
pMgmt->pWrapper = pWrapper;
taosInitRWLatch(&pMgmt->latch);
pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
if (pMgmt->dnodeHash == NULL) {
dError("failed to init dnode hash");
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (dmReadFile(pMgmt) != 0) {
dError("failed to read file since %s", terrstr());
return -1;
}
if (pDnode->dropped) {
dError("dnode will not start since its already dropped");
return -1;
}
if (dmStartWorker(pMgmt) != 0) {
return -1;
}
if (dndInitTrans(pDnode) != 0) {
dError("failed to init transport since %s", terrstr());
return -1;
}
pWrapper->pMgmt = pMgmt;
pMgmt->msgCb = dndCreateMsgcb(pWrapper);
dInfo("dnode-mgmt is initialized");
return 0;
}
static void dmCleanup(SMgmtWrapper *pWrapper) {
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
if (pMgmt == NULL) return;
dInfo("dnode-mgmt start to clean up");
SDnode *pDnode = pMgmt->pDnode;
dmStopWorker(pMgmt);
taosWLockLatch(&pMgmt->latch);
if (pMgmt->dnodeEps != NULL) {
taosArrayDestroy(pMgmt->dnodeEps);
pMgmt->dnodeEps = NULL;
}
if (pMgmt->dnodeHash != NULL) {
taosHashCleanup(pMgmt->dnodeHash);
pMgmt->dnodeHash = NULL;
}
taosWUnLockLatch(&pMgmt->latch);
taosMemoryFree(pMgmt);
pWrapper->pMgmt = NULL;
dndCleanupTrans(pDnode);
dInfo("dnode-mgmt is cleaned up");
}
static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) {
*required = true;
return 0;
}
void dmSetMgmtFp(SMgmtWrapper *pWrapper) {
SMgmtFp mgmtFp = {0};
mgmtFp.openFp = dmInit;
mgmtFp.closeFp = dmCleanup;
mgmtFp.startFp = dmStart;
mgmtFp.requiredFp = dmRequire;
dmInitMsgHandle(pWrapper);
pWrapper->name = "dnode";
pWrapper->fp = mgmtFp;
}
...@@ -14,9 +14,8 @@ ...@@ -14,9 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dmImp.h"
#include "tconfig.h" #include "tconfig.h"
#include "mndGrant.h"
static struct { static struct {
bool dumpConfig; bool dumpConfig;
...@@ -27,34 +26,34 @@ static struct { ...@@ -27,34 +26,34 @@ static struct {
char apolloUrl[PATH_MAX]; char apolloUrl[PATH_MAX];
SArray *pArgs; // SConfigPair SArray *pArgs; // SConfigPair
SDnode *pDnode; SDnode *pDnode;
EDndType ntype; EDndNodeType ntype;
} global = {0}; } global = {0};
static void dndStopDnode(int signum, void *info, void *ctx) { static void dmStopDnode(int signum, void *info, void *ctx) {
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
if (pDnode != NULL) { if (pDnode != NULL) {
dndHandleEvent(pDnode, DND_EVENT_STOP); dmSetEvent(pDnode, DND_EVENT_STOP);
} }
} }
static void dndSetSignalHandle() { static void dmSetSignalHandle() {
taosSetSignal(SIGTERM, dndStopDnode); taosSetSignal(SIGTERM, dmStopDnode);
taosSetSignal(SIGHUP, dndStopDnode); taosSetSignal(SIGHUP, dmStopDnode);
taosSetSignal(SIGINT, dndStopDnode); taosSetSignal(SIGINT, dmStopDnode);
taosSetSignal(SIGTSTP, dndStopDnode); taosSetSignal(SIGTSTP, dmStopDnode);
taosSetSignal(SIGABRT, dndStopDnode); taosSetSignal(SIGABRT, dmStopDnode);
taosSetSignal(SIGBREAK, dndStopDnode); taosSetSignal(SIGBREAK, dmStopDnode);
taosSetSignal(SIGQUIT, dndStopDnode); taosSetSignal(SIGQUIT, dmStopDnode);
if (!tsMultiProcess) { if (!tsMultiProcess) {
} else if (global.ntype == DNODE || global.ntype == NODE_MAX) { } else if (global.ntype == DNODE || global.ntype == NODE_END) {
taosIgnSignal(SIGCHLD); taosIgnSignal(SIGCHLD);
} else { } else {
taosKillChildOnParentStopped(); taosKillChildOnParentStopped();
} }
} }
static int32_t dndParseArgs(int32_t argc, char const *argv[]) { static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
for (int32_t i = 1; i < argc; ++i) { for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0) { if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
...@@ -73,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { ...@@ -73,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
tstrncpy(global.envFile, argv[++i], PATH_MAX); tstrncpy(global.envFile, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-n") == 0) { } else if (strcmp(argv[i], "-n") == 0) {
global.ntype = atoi(argv[++i]); global.ntype = atoi(argv[++i]);
if (global.ntype <= DNODE || global.ntype > NODE_MAX) { if (global.ntype <= DNODE || global.ntype > NODE_END) {
printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1); printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1);
return -1; return -1;
} }
} else if (strcmp(argv[i], "-k") == 0) { } else if (strcmp(argv[i], "-k") == 0) {
...@@ -90,11 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { ...@@ -90,11 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
return 0; return 0;
} }
static void dndGenerateGrant() { static void dmGenerateGrant() { mndGenerateMachineCode(); }
parseGrantParameter();
}
static void dndPrintVersion() { static void dmPrintVersion() {
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
char *releaseName = "enterprise"; char *releaseName = "enterprise";
#else #else
...@@ -105,12 +102,12 @@ static void dndPrintVersion() { ...@@ -105,12 +102,12 @@ static void dndPrintVersion() {
printf("buildInfo: %s\n", buildinfo); printf("buildInfo: %s\n", buildinfo);
} }
static void dndDumpCfg() { static void dmDumpCfg() {
SConfig *pCfg = taosGetCfg(); SConfig *pCfg = taosGetCfg();
cfgDumpCfg(pCfg, 0, 1); cfgDumpCfg(pCfg, 0, 1);
} }
static SDnodeOpt dndGetOpt() { static SDnodeOpt dmGetOpt() {
SConfig *pCfg = taosGetCfg(); SConfig *pCfg = taosGetCfg();
SDnodeOpt option = {0}; SDnodeOpt option = {0};
...@@ -127,43 +124,43 @@ static SDnodeOpt dndGetOpt() { ...@@ -127,43 +124,43 @@ static SDnodeOpt dndGetOpt() {
return option; return option;
} }
static int32_t dndInitLog() { static int32_t dmInitLog() {
char logName[12] = {0}; char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
} }
static void dndSetProcInfo(int32_t argc, char **argv) { static void dmSetProcInfo(int32_t argc, char **argv) {
taosSetProcPath(argc, argv); taosSetProcPath(argc, argv);
if (global.ntype != DNODE && global.ntype != NODE_MAX) { if (global.ntype != DNODE && global.ntype != NODE_END) {
const char *name = dndNodeProcStr(global.ntype); const char *name = dmProcName(global.ntype);
taosSetProcName(argc, argv, name); taosSetProcName(argc, argv, name);
} }
} }
static int32_t dndRunDnode() { static int32_t dmRunDnode() {
if (dndInit() != 0) { if (dmInit() != 0) {
dError("failed to init environment since %s", terrstr()); dError("failed to init environment since %s", terrstr());
return -1; return -1;
} }
SDnodeOpt option = dndGetOpt(); SDnodeOpt option = dmGetOpt();
SDnode *pDnode = dndCreate(&option); SDnode *pDnode = dmCreate(&option);
if (pDnode == NULL) { if (pDnode == NULL) {
dError("failed to to create dnode since %s", terrstr()); dError("failed to to create dnode since %s", terrstr());
return -1; return -1;
} else { } else {
global.pDnode = pDnode; global.pDnode = pDnode;
dndSetSignalHandle(); dmSetSignalHandle();
} }
dInfo("start the service"); dInfo("start the service");
int32_t code = dndRun(pDnode); int32_t code = dmRun(pDnode);
dInfo("start shutting down the service"); dInfo("start shutting down the service");
global.pDnode = NULL; global.pDnode = NULL;
dndClose(pDnode); dmClose(pDnode);
dndCleanup(); dmCleanup();
taosCloseLog(); taosCloseLog();
taosCleanupCfg(); taosCleanupCfg();
return code; return code;
...@@ -175,22 +172,22 @@ int main(int argc, char const *argv[]) { ...@@ -175,22 +172,22 @@ int main(int argc, char const *argv[]) {
return -1; return -1;
} }
if (dndParseArgs(argc, argv) != 0) { if (dmParseArgs(argc, argv) != 0) {
printf("failed to start since parse args error\n"); printf("failed to start since parse args error\n");
return -1; return -1;
} }
if (global.generateGrant) { if (global.generateGrant) {
dndGenerateGrant(); dmGenerateGrant();
return 0; return 0;
} }
if (global.printVersion) { if (global.printVersion) {
dndPrintVersion(); dmPrintVersion();
return 0; return 0;
} }
if (dndInitLog() != 0) { if (dmInitLog() != 0) {
printf("failed to start since init log error\n"); printf("failed to start since init log error\n");
return -1; return -1;
} }
...@@ -201,12 +198,12 @@ int main(int argc, char const *argv[]) { ...@@ -201,12 +198,12 @@ int main(int argc, char const *argv[]) {
} }
if (global.dumpConfig) { if (global.dumpConfig) {
dndDumpCfg(); dmDumpCfg();
taosCleanupCfg(); taosCleanupCfg();
taosCloseLog(); taosCloseLog();
return 0; return 0;
} }
dndSetProcInfo(argc, (char **)argv); dmSetProcInfo(argc, (char **)argv);
return dndRunDnode(); return dmRunDnode();
} }
aux_source_directory(src IMPLEMENT_SRC)
add_library(dnode STATIC ${IMPLEMENT_SRC})
target_link_libraries(
dnode mgmt_bnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode
)
target_include_directories(
dnode
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
IF (TD_GRANT)
TARGET_LINK_LIBRARIES(dnode grant)
ENDIF ()
IF (TD_USB_DONGLE)
TARGET_LINK_LIBRARIES(dnode usb_dongle)
else()
ENDIF ()
\ No newline at end of file
/*
* 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_IMP_H_
#define _TD_DND_IMP_H_
#include "dmInt.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t dmOpenNode(SMgmtWrapper *pWrapper);
void dmCloseNode(SMgmtWrapper *pWrapper);
// dmTransport.c
int32_t dmInitTrans(SDnode *pDnode);
void dmCleanupTrans(SDnode *pDnode);
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper);
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper);
int32_t dmInitMsgHandle(SDnode *pDnode);
void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp);
// dmEps.c
int32_t dmReadEps(SDnode *pDnode);
int32_t dmWriteEps(SDnode *pDnode);
void dmUpdateEps(SDnode *pDnode, SArray *pDnodeEps);
// dmHandle.c
void dmSendStatusReq(SDnode *pDnode);
int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg);
int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg);
int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg);
int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
// dmMonitor.c
void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo);
void dmSendMonitorReport(SDnode *pDnode);
// dmWorker.c
int32_t dmStartStatusThread(SDnode *pDnode);
void dmStopStatusThread(SDnode *pDnode);
int32_t dmStartMonitorThread(SDnode *pDnode);
void dmStopMonitorThread(SDnode *pDnode);
int32_t dmStartWorker(SDnode *pDnode);
void dmStopWorker(SDnode *pDnode);
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
// mgmt nodes
void dmSetMgmtFp(SMgmtWrapper *pWrapper);
void bmSetMgmtFp(SMgmtWrapper *pWrapper);
void qmSetMgmtFp(SMgmtWrapper *pWrapper);
void smSetMgmtFp(SMgmtWrapper *pWrapper);
void vmSetMgmtFp(SMgmtWrapper *pWrapper);
void mmSetMgmtFp(SMgmtWrapper *pWrapper);
void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo);
void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo);
void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo);
void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo);
void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo);
#ifdef __cplusplus
}
#endif
#endif /*_TD_DND_IMP_H_*/
\ No newline at end of file
...@@ -14,32 +14,50 @@ ...@@ -14,32 +14,50 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmInt.h" #include "dmImp.h"
static void dmPrintDnodes(SDnodeMgmt *pMgmt); static void dmPrintEps(SDnode *pDnode);
static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep); static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep);
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps); static void dmResetEps(SDnode *pDnode, SArray *dnodeEps);
int32_t dmReadFile(SDnodeMgmt *pMgmt) { static void dmGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
taosRLockLatch(&pDnode->data.latch);
SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t));
if (pDnodeEp != NULL) {
if (pPort != NULL) {
*pPort = pDnodeEp->ep.port;
}
if (pFqdn != NULL) {
tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
}
if (pEp != NULL) {
snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
}
}
taosRUnLockLatch(&pDnode->data.latch);
}
int32_t dmReadEps(SDnode *pDnode) {
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 256 * 1024; int32_t maxLen = 256 * 1024;
char *content = taosMemoryCalloc(1, maxLen + 1); char *content = taosMemoryCalloc(1, maxLen + 1);
cJSON *root = NULL; cJSON *root = NULL;
char file[PATH_MAX]; char file[PATH_MAX] = {0};
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
SDnode *pDnode = pMgmt->pDnode;
pMgmt->dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
if (pMgmt->dnodeEps == NULL) { if (pDnode->data.dnodeEps == NULL) {
dError("failed to calloc dnodeEp array since %s", strerror(errno)); dError("failed to calloc dnodeEp array since %s", strerror(errno));
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
snprintf(file, sizeof(file), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
dDebug("file %s not exist", file); // dDebug("file %s not exist", file);
code = 0; code = 0;
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
...@@ -62,21 +80,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { ...@@ -62,21 +80,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
dError("failed to read %s since dnodeId not found", file); dError("failed to read %s since dnodeId not found", file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pDnode->dnodeId = dnodeId->valueint; pDnode->data.dnodeId = dnodeId->valueint;
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
if (!clusterId || clusterId->type != cJSON_String) { if (!clusterId || clusterId->type != cJSON_String) {
dError("failed to read %s since clusterId not found", file); dError("failed to read %s since clusterId not found", file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pDnode->clusterId = atoll(clusterId->valuestring); pDnode->data.clusterId = atoll(clusterId->valuestring);
cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
if (!dropped || dropped->type != cJSON_Number) { if (!dropped || dropped->type != cJSON_Number) {
dError("failed to read %s since dropped not found", file); dError("failed to read %s since dropped not found", file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pDnode->dropped = dropped->valueint; pDnode->data.dropped = dropped->valueint;
cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes"); cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes");
if (!dnodes || dnodes->type != cJSON_Array) { if (!dnodes || dnodes->type != cJSON_Array) {
...@@ -126,41 +144,41 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { ...@@ -126,41 +144,41 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
} }
dnodeEp.isMnode = isMnode->valueint; dnodeEp.isMnode = isMnode->valueint;
taosArrayPush(pMgmt->dnodeEps, &dnodeEp); taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
} }
code = 0; code = 0;
dDebug("succcessed to read file %s", file); dDebug("succcessed to read file %s", file);
dmPrintDnodes(pMgmt); dmPrintEps(pDnode);
PRASE_DNODE_OVER: PRASE_DNODE_OVER:
if (content != NULL) taosMemoryFree(content); if (content != NULL) taosMemoryFree(content);
if (root != NULL) cJSON_Delete(root); if (root != NULL) cJSON_Delete(root);
if (pFile != NULL) taosCloseFile(&pFile); if (pFile != NULL) taosCloseFile(&pFile);
if (dmIsEpChanged(pMgmt, pDnode->dnodeId, pDnode->localEp)) { if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) {
dError("localEp %s different with %s and need reconfigured", pDnode->localEp, file); dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file);
return -1; return -1;
} }
if (taosArrayGetSize(pMgmt->dnodeEps) == 0) { if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) {
SDnodeEp dnodeEp = {0}; SDnodeEp dnodeEp = {0};
dnodeEp.isMnode = 1; dnodeEp.isMnode = 1;
taosGetFqdnPortFromEp(pDnode->firstEp, &dnodeEp.ep); taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep);
taosArrayPush(pMgmt->dnodeEps, &dnodeEp); taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
} }
dmResetDnodes(pMgmt, pMgmt->dnodeEps); dmResetEps(pDnode, pDnode->data.dnodeEps);
terrno = code; terrno = code;
return code; return code;
} }
int32_t dmWriteFile(SDnodeMgmt *pMgmt) { int32_t dmWriteEps(SDnode *pDnode) {
SDnode *pDnode = pMgmt->pDnode; char file[PATH_MAX] = {0};
char realfile[PATH_MAX];
char file[PATH_MAX]; snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->wrappers[DNODE].path, TD_DIRSEP);
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP); snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP);
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
...@@ -174,14 +192,14 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { ...@@ -174,14 +192,14 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
char *content = taosMemoryCalloc(1, maxLen + 1); char *content = taosMemoryCalloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->data.dnodeId);
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId); len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->data.clusterId);
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->dropped); len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped);
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n"); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
for (int32_t i = 0; i < numOfEps; ++i) { for (int32_t i = 0; i < numOfEps; ++i) {
SDnodeEp *pDnodeEp = taosArrayGet(pMgmt->dnodeEps, i); SDnodeEp *pDnodeEp = taosArrayGet(pDnode->data.dnodeEps, i);
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id);
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn);
len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port); len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port);
...@@ -199,50 +217,47 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { ...@@ -199,50 +217,47 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
taosMemoryFree(content); taosMemoryFree(content);
char realfile[PATH_MAX];
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP);
if (taosRenameFile(file, realfile) != 0) { if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s since %s", file, terrstr()); dError("failed to rename %s since %s", file, terrstr());
return -1; return -1;
} }
pMgmt->updateTime = taosGetTimestampMs(); pDnode->data.updateTime = taosGetTimestampMs();
dDebug("successed to write %s", realfile); dDebug("successed to write %s", realfile);
return 0; return 0;
} }
void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) { void dmUpdateEps(SDnode *pDnode, SArray *eps) {
int32_t numOfEps = taosArrayGetSize(dnodeEps); int32_t numOfEps = taosArrayGetSize(eps);
if (numOfEps <= 0) return; if (numOfEps <= 0) return;
taosWLockLatch(&pMgmt->latch); taosWLockLatch(&pDnode->data.latch);
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
if (numOfEps != numOfEpsOld) { if (numOfEps != numOfEpsOld) {
dmResetDnodes(pMgmt, dnodeEps); dmResetEps(pDnode, eps);
dmWriteFile(pMgmt); dmWriteEps(pDnode);
} else { } else {
int32_t size = numOfEps * sizeof(SDnodeEp); int32_t size = numOfEps * sizeof(SDnodeEp);
if (memcmp(pMgmt->dnodeEps->pData, dnodeEps->pData, size) != 0) { if (memcmp(pDnode->data.dnodeEps->pData, eps->pData, size) != 0) {
dmResetDnodes(pMgmt, dnodeEps); dmResetEps(pDnode, eps);
dmWriteFile(pMgmt); dmWriteEps(pDnode);
} }
} }
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pDnode->data.latch);
} }
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { static void dmResetEps(SDnode *pDnode, SArray *dnodeEps) {
if (pMgmt->dnodeEps != dnodeEps) { if (pDnode->data.dnodeEps != dnodeEps) {
SArray *tmp = pMgmt->dnodeEps; SArray *tmp = pDnode->data.dnodeEps;
pMgmt->dnodeEps = taosArrayDup(dnodeEps); pDnode->data.dnodeEps = taosArrayDup(dnodeEps);
taosArrayDestroy(tmp); taosArrayDestroy(tmp);
} }
pMgmt->mnodeEpSet.inUse = 0; pDnode->data.mnodeEps.inUse = 0;
pMgmt->mnodeEpSet.numOfEps = 0; pDnode->data.mnodeEps.numOfEps = 0;
int32_t mIndex = 0; int32_t mIndex = 0;
int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps); int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps);
...@@ -251,40 +266,40 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { ...@@ -251,40 +266,40 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i);
if (!pDnodeEp->isMnode) continue; if (!pDnodeEp->isMnode) continue;
if (mIndex >= TSDB_MAX_REPLICA) continue; if (mIndex >= TSDB_MAX_REPLICA) continue;
pMgmt->mnodeEpSet.numOfEps++; pDnode->data.mnodeEps.numOfEps++;
pMgmt->mnodeEpSet.eps[mIndex] = pDnodeEp->ep; pDnode->data.mnodeEps.eps[mIndex] = pDnodeEp->ep;
mIndex++; mIndex++;
} }
for (int32_t i = 0; i < numOfEps; i++) { for (int32_t i = 0; i < numOfEps; i++) {
SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i);
taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); taosHashPut(pDnode->data.dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp));
} }
dmPrintDnodes(pMgmt); dmPrintEps(pDnode);
} }
static void dmPrintDnodes(SDnodeMgmt *pMgmt) { static void dmPrintEps(SDnode *pDnode) {
int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
dDebug("print dnode ep list, num:%d", numOfEps); dDebug("print dnode ep list, num:%d", numOfEps);
for (int32_t i = 0; i < numOfEps; i++) { for (int32_t i = 0; i < numOfEps; i++) {
SDnodeEp *pEp = taosArrayGet(pMgmt->dnodeEps, i); SDnodeEp *pEp = taosArrayGet(pDnode->data.dnodeEps, i);
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode); dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode);
} }
} }
static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep) { static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep) {
bool changed = false; bool changed = false;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pDnode->data.latch);
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t));
if (pDnodeEp != NULL) { if (pDnodeEp != NULL) {
char epstr[TSDB_EP_LEN + 1]; char epstr[TSDB_EP_LEN + 1];
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
changed = strcmp(ep, epstr) != 0; changed = strcmp(ep, epstr) != 0;
} }
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pDnode->data.latch);
return changed; return changed;
} }
...@@ -14,22 +14,20 @@ ...@@ -14,22 +14,20 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dmImp.h"
static bool dndRequireNode(SMgmtWrapper *pWrapper) { static bool dmRequireNode(SMgmtWrapper *pWrapper) {
bool required = false; bool required = false;
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
if (!required) { if (!required) {
dDebug("node:%s, does not require startup", pWrapper->name); dDebug("node:%s, does not require startup", pWrapper->name);
} else {
dDebug("node:%s, needs to be started", pWrapper->name);
} }
return required; return required;
} }
static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) {
int32_t shmsize = tsMnodeShmSize; int32_t shmsize = tsMnodeShmSize;
if (pWrapper->ntype == VNODES) { if (pWrapper->ntype == VNODE) {
shmsize = tsVnodeShmSize; shmsize = tsVnodeShmSize;
} else if (pWrapper->ntype == QNODE) { } else if (pWrapper->ntype == QNODE) {
shmsize = tsQnodeShmSize; shmsize = tsQnodeShmSize;
...@@ -43,18 +41,18 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { ...@@ -43,18 +41,18 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) {
return -1; return -1;
} }
if (taosCreateShm(&pWrapper->shm, pWrapper->ntype, shmsize) != 0) { if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) {
terrno = TAOS_SYSTEM_ERROR(terrno); terrno = TAOS_SYSTEM_ERROR(terrno);
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
return -1; return -1;
} }
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize); dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize);
SProcCfg cfg = dndGenProcCfg(pWrapper); SProcCfg cfg = dmGenProcCfg(pWrapper);
cfg.isChild = false; cfg.isChild = false;
pWrapper->procType = PROC_PARENT; pWrapper->procType = DND_PROC_PARENT;
pWrapper->pProc = taosProcInit(&cfg); pWrapper->procObj = taosProcInit(&cfg);
if (pWrapper->pProc == NULL) { if (pWrapper->procObj == NULL) {
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
...@@ -62,7 +60,7 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { ...@@ -62,7 +60,7 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) {
return 0; return 0;
} }
static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) { static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) {
char tstr[8] = {0}; char tstr[8] = {0};
char *args[6] = {0}; char *args[6] = {0};
snprintf(tstr, sizeof(tstr), "%d", n); snprintf(tstr, sizeof(tstr), "%d", n);
...@@ -84,54 +82,108 @@ static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) { ...@@ -84,54 +82,108 @@ static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) {
return 0; return 0;
} }
static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) {
if (pWrapper->pDnode->ntype == NODE_MAX) { if (pWrapper->pDnode->ntype == NODE_END) {
dInfo("node:%s, should be started manually", pWrapper->name); dInfo("node:%s, should be started manually in child process", pWrapper->name);
} else { } else {
if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) { if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
return -1; return -1;
} }
} }
if (taosProcRun(pWrapper->procObj) != 0) {
if (taosProcRun(pWrapper->pProc) != 0) {
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
return 0;
}
static int32_t dmInitChildProc(SMgmtWrapper *pWrapper) {
SProcCfg cfg = dmGenProcCfg(pWrapper);
cfg.isChild = true;
pWrapper->procObj = taosProcInit(&cfg);
if (pWrapper->procObj == NULL) {
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
return -1;
}
return 0; return 0;
} }
static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) { static int32_t dmRunChildProc(SMgmtWrapper *pWrapper) {
if (taosProcRun(pWrapper->procObj) != 0) {
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
return -1;
}
return 0;
}
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
if (taosMkDir(pWrapper->path) != 0) { if (taosMkDir(pWrapper->path) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
return -1; return -1;
} }
if (pWrapper->procType == DND_PROC_SINGLE || pWrapper->procType == DND_PROC_CHILD) {
if ((*pWrapper->fp.openFp)(pWrapper) != 0) { if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
if (pWrapper->procType == DND_PROC_CHILD) {
if (dmInitChildProc(pWrapper) != 0) return -1;
if (dmRunChildProc(pWrapper) != 0) return -1;
}
dDebug("node:%s, has been opened", pWrapper->name); dDebug("node:%s, has been opened", pWrapper->name);
pWrapper->deployed = true; pWrapper->deployed = true;
} else {
if (dmInitParentProc(pWrapper) != 0) return -1;
if (dmWriteShmFile(pWrapper) != 0) return -1;
if (dmRunParentProc(pWrapper) != 0) return -1;
}
return 0; return 0;
} }
int32_t dndOpenNode(SMgmtWrapper *pWrapper) { int32_t dmStartNode(SMgmtWrapper *pWrapper) {
SDnode *pDnode = pWrapper->pDnode; if (pWrapper->procType == DND_PROC_PARENT) {
if (pDnode->procType == PROC_SINGLE) { dInfo("node:%s, not start in parent process", pWrapper->name);
return dndOpenNodeImp(pWrapper); } else if (pWrapper->procType == DND_PROC_CHILD) {
} else if (pDnode->procType == PROC_PARENT) { dInfo("node:%s, start in child process", pWrapper->name);
if (dndInitNodeProc(pWrapper) != 0) return -1; if (pWrapper->ntype != DNODE) {
if (dndWriteShmFile(pDnode) != 0) return -1; if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
if (dndRunNodeProc(pWrapper) != 0) return -1; dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1;
}
}
} else {
if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1;
}
} }
return 0; return 0;
} }
static void dndCloseNodeImp(SMgmtWrapper *pWrapper) { void dmStopNode(SMgmtWrapper *pWrapper) {
dDebug("node:%s, mgmt start to close", pWrapper->name); if (pWrapper->fp.stopFp != NULL) {
(*pWrapper->fp.stopFp)(pWrapper);
}
}
void dmCloseNode(SMgmtWrapper *pWrapper) {
dInfo("node:%s, start to close", pWrapper->name);
if (pWrapper->procType == DND_PROC_PARENT) {
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
taosKillProc(pWrapper->procId);
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
taosWaitProc(pWrapper->procId);
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
}
}
dmStopNode(pWrapper);
pWrapper->required = false; pWrapper->required = false;
taosWLockLatch(&pWrapper->latch); taosWLockLatch(&pWrapper->latch);
if (pWrapper->deployed) { if (pWrapper->deployed) {
...@@ -144,214 +196,144 @@ static void dndCloseNodeImp(SMgmtWrapper *pWrapper) { ...@@ -144,214 +196,144 @@ static void dndCloseNodeImp(SMgmtWrapper *pWrapper) {
taosMsleep(10); taosMsleep(10);
} }
if (pWrapper->pProc) { if (pWrapper->procObj) {
taosProcCleanup(pWrapper->pProc); taosProcCleanup(pWrapper->procObj);
pWrapper->pProc = NULL; pWrapper->procObj = NULL;
} }
dDebug("node:%s, mgmt has been closed", pWrapper->name);
dInfo("node:%s, has been closed", pWrapper->name);
} }
void dndCloseNode(SMgmtWrapper *pWrapper) { static int32_t dmOpenNodes(SDnode *pDnode) {
if (pWrapper->pDnode->procType == PROC_PARENT) { if (pDnode->ptype == DND_PROC_CHILD) {
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); pWrapper->required = dmRequireNode(pWrapper);
taosKillProc(pWrapper->procId); if (!pWrapper->required) {
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); dError("dnode:%s, failed to open since not required", pWrapper->name);
taosWaitProc(pWrapper->procId);
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
}
} }
dndCloseNodeImp(pWrapper);
}
static void dndProcessProcHandle(void *handle) { pWrapper->procType = DND_PROC_CHILD;
dWarn("handle:%p, the child process dies and send an offline rsp", handle);
SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE};
rpcSendResponse(&rpcMsg);
}
static int32_t dndRunInSingleProcess(SDnode *pDnode) { SMsgCb msgCb = pDnode->data.msgCb;
dInfo("dnode run in single process"); msgCb.pWrapper = pWrapper;
pDnode->procType = PROC_SINGLE; tmsgSetDefaultMsgCb(&msgCb);
for (EDndType n = DNODE; n < NODE_MAX; ++n) { if (dmOpenNode(pWrapper) != 0) {
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
return -1;
}
} else {
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
pWrapper->required = dndRequireNode(pWrapper); pWrapper->required = dmRequireNode(pWrapper);
if (!pWrapper->required) continue; if (!pWrapper->required) continue;
if (dndOpenNodeImp(pWrapper) != 0) { if (pDnode->ptype == DND_PROC_PARENT && n != DNODE) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); pWrapper->procType = DND_PROC_PARENT;
} else {
pWrapper->procType = DND_PROC_SINGLE;
}
if (dmOpenNode(pWrapper) != 0) {
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
} }
}
dndSetStatus(pDnode, DND_STAT_RUNNING); dmSetStatus(pDnode, DND_STAT_RUNNING);
return 0;
}
for (EDndType n = 0; n < NODE_MAX; ++n) { static int32_t dmStartNodes(SDnode *pDnode) {
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue; if (!pWrapper->required) continue;
if (pWrapper->fp.startFp == NULL) continue; if (dmStartNode(pWrapper) != 0) {
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
} }
dInfo("TDengine initialized successfully"); dInfo("TDengine initialized successfully");
dndReportStartup(pDnode, "TDengine", "initialized successfully"); dmReportStartup(pDnode, "TDengine", "initialized successfully");
while (1) {
if (pDnode->event == DND_EVENT_STOP) {
dInfo("dnode is about to stop");
dndSetStatus(pDnode, DND_STAT_STOPPED);
break;
}
taosMsleep(100);
}
return 0; return 0;
} }
static int32_t dndRunInParentProcess(SDnode *pDnode) { static void dmStopNodes(SDnode *pDnode) {
dInfo("dnode run in parent process"); for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
pDnode->procType = PROC_PARENT;
SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
if (dndOpenNodeImp(pDWrapper) != 0) {
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
return -1;
}
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
pWrapper->required = dndRequireNode(pWrapper); dmStopNode(pWrapper);
if (!pWrapper->required) continue;
if (dndInitNodeProc(pWrapper) != 0) return -1;
}
if (dndWriteShmFile(pDnode) != 0) {
dError("failed to write runtime file since %s", terrstr());
return -1;
} }
}
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { static void dmCloseNodes(SDnode *pDnode) {
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue; dmCloseNode(pWrapper);
if (dndRunNodeProc(pWrapper) != 0) return -1;
} }
}
dndSetStatus(pDnode, DND_STAT_RUNNING); static void dmProcessProcHandle(void *handle) {
dWarn("handle:%p, the child process dies and send an offline rsp", handle);
if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) { SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE};
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); rpcSendResponse(&rpcMsg);
return -1; }
}
dInfo("TDengine initialized successfully");
dndReportStartup(pDnode, "TDengine", "initialized successfully");
while (1) {
if (pDnode->event == DND_EVENT_STOP) {
dInfo("dnode is about to stop");
dndSetStatus(pDnode, DND_STAT_STOPPED);
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue;
if (pDnode->ntype == NODE_MAX) continue;
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { static void dmWatchNodes(SDnode *pDnode) {
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); taosThreadMutexLock(&pDnode->mutex);
taosKillProc(pWrapper->procId); if (pDnode->ptype == DND_PROC_PARENT) {
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) {
taosWaitProc(pWrapper->procId);
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
}
}
break;
} else {
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue; if (!pWrapper->required) continue;
if (pDnode->ntype == NODE_MAX) continue; if (pWrapper->procType != DND_PROC_PARENT) continue;
if (pDnode->ntype == NODE_END) continue;
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle); if (pWrapper->procObj) {
dndNewNodeProc(pWrapper, n); taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle);
} }
dmNewNodeProc(pWrapper, n);
} }
} }
taosMsleep(100);
} }
taosThreadMutexUnlock(&pDnode->mutex);
return 0;
} }
static int32_t dndRunInChildProcess(SDnode *pDnode) { int32_t dmRun(SDnode *pDnode) {
if (!tsMultiProcess) {
pDnode->ptype = DND_PROC_SINGLE;
dInfo("dnode run in single process");
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_END) {
pDnode->ptype = DND_PROC_PARENT;
dInfo("dnode run in parent process");
} else {
pDnode->ptype = DND_PROC_CHILD;
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
dInfo("%s run in child process", pWrapper->name); dInfo("%s run in child process", pWrapper->name);
pDnode->procType = PROC_CHILD;
pWrapper->required = dndRequireNode(pWrapper);
if (!pWrapper->required) {
dError("%s does not require startup", pWrapper->name);
return -1;
} }
SMsgCb msgCb = dndCreateMsgcb(pWrapper); if (dmOpenNodes(pDnode) != 0) {
tmsgSetDefaultMsgCb(&msgCb); dError("failed to open nodes since %s", terrstr());
pWrapper->procType = PROC_CHILD;
if (dndOpenNodeImp(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
SProcCfg cfg = dndGenProcCfg(pWrapper); if (dmStartNodes(pDnode) != 0) {
cfg.isChild = true; dError("failed to start nodes since %s", terrstr());
pWrapper->pProc = taosProcInit(&cfg);
if (pWrapper->pProc == NULL) {
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
return -1; return -1;
} }
if (pWrapper->fp.startFp != NULL) {
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
return -1;
}
}
dndSetStatus(pDnode, DND_STAT_RUNNING);
if (taosProcRun(pWrapper->pProc) != 0) {
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
return -1;
}
dInfo("TDengine initialized successfully");
dndReportStartup(pDnode, "TDengine", "initialized successfully");
while (1) { while (1) {
if (pDnode->event == DND_EVENT_STOP) {
dInfo("%s is about to stop", pWrapper->name);
dndSetStatus(pDnode, DND_STAT_STOPPED);
break;
}
taosMsleep(100); taosMsleep(100);
} if (pDnode->event & DND_EVENT_STOP) {
dInfo("dnode is about to stop");
dmSetStatus(pDnode, DND_STAT_STOPPED);
dmStopNodes(pDnode);
dmCloseNodes(pDnode);
return 0; return 0;
}
int32_t dndRun(SDnode *pDnode) {
if (!tsMultiProcess) {
return dndRunInSingleProcess(pDnode);
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
return dndRunInParentProcess(pDnode);
} else { } else {
return dndRunInChildProcess(pDnode); dmWatchNodes(pDnode);
}
} }
return 0;
} }
...@@ -14,22 +14,53 @@ ...@@ -14,22 +14,53 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmInt.h" #include "dmImp.h"
void dmSendStatusReq(SDnodeMgmt *pMgmt) { static void dmUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
SDnode *pDnode = pMgmt->pDnode; if (pDnode->data.dnodeId == 0) {
dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
taosWLockLatch(&pDnode->data.latch);
pDnode->data.dnodeId = pCfg->dnodeId;
pDnode->data.clusterId = pCfg->clusterId;
dmWriteEps(pDnode);
taosWUnLockLatch(&pDnode->data.latch);
}
}
static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) {
if (pRsp->code != TSDB_CODE_SUCCESS) {
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) {
dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId);
pDnode->data.dropped = 1;
dmWriteEps(pDnode);
}
} else {
SStatusRsp statusRsp = {0};
if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
pDnode->data.dnodeVer = statusRsp.dnodeVer;
dmUpdateDnodeCfg(pDnode, &statusRsp.dnodeCfg);
dmUpdateEps(pDnode, statusRsp.pDnodeEps);
}
tFreeSStatusRsp(&statusRsp);
}
return TSDB_CODE_SUCCESS;
}
void dmSendStatusReq(SDnode *pDnode) {
SStatusReq req = {0}; SStatusReq req = {0};
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pDnode->data.latch);
req.sver = tsVersion; req.sver = tsVersion;
req.dver = pMgmt->dver; req.dnodeVer = pDnode->data.dnodeVer;
req.dnodeId = pDnode->dnodeId; req.dnodeId = pDnode->data.dnodeId;
req.clusterId = pDnode->clusterId; req.clusterId = pDnode->data.clusterId;
req.rebootTime = pDnode->rebootTime; req.rebootTime = pDnode->data.rebootTime;
req.updateTime = pMgmt->updateTime; req.updateTime = pDnode->data.updateTime;
req.numOfCores = tsNumOfCores; req.numOfCores = tsNumOfCores;
req.numOfSupportVnodes = pDnode->numOfSupportVnodes; req.numOfSupportVnodes = pDnode->data.supportVnodes;
tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN); tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN);
req.clusterCfg.statusInterval = tsStatusInterval; req.clusterCfg.statusInterval = tsStatusInterval;
req.clusterCfg.checkTime = 0; req.clusterCfg.checkTime = 0;
...@@ -38,96 +69,54 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { ...@@ -38,96 +69,54 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pDnode->data.latch);
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES);
if (pWrapper != NULL) {
SMonVloadInfo info = {0}; SMonVloadInfo info = {0};
dmGetVnodeLoads(pWrapper, &info); dmGetVnodeLoads(pDnode, &info);
req.pVloads = info.pVloads; req.pVloads = info.pVloads;
dndReleaseWrapper(pWrapper);
}
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
void *pHead = rpcMallocCont(contLen); void *pHead = rpcMallocCont(contLen);
tSerializeSStatusReq(pHead, contLen, &req); tSerializeSStatusReq(pHead, contLen, &req);
taosArrayDestroy(req.pVloads); tFreeSStatusReq(&req);
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
pMgmt->statusSent = 1; SRpcMsg rpcRsp = {0};
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
SEpSet epSet = {0}; dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
dmGetMnodeEpSet(pMgmt, &epSet); dmProcessStatusRsp(pDnode, &rpcRsp);
tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg);
}
static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) {
SDnode *pDnode = pMgmt->pDnode;
if (pDnode->dnodeId == 0) {
dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
taosWLockLatch(&pMgmt->latch);
pDnode->dnodeId = pCfg->dnodeId;
pDnode->clusterId = pCfg->clusterId;
dmWriteFile(pMgmt);
taosWUnLockLatch(&pMgmt->latch);
}
} }
int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg) {
SDnode *pDnode = pMgmt->pDnode;
SRpcMsg *pRsp = &pMsg->rpcMsg;
if (pRsp->code != TSDB_CODE_SUCCESS) {
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->dropped && pDnode->dnodeId > 0) {
dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->dnodeId);
pDnode->dropped = 1;
dmWriteFile(pMgmt);
}
} else {
SStatusRsp statusRsp = {0};
if (pRsp->pCont != NULL && pRsp->contLen != 0 &&
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
pMgmt->dver = statusRsp.dver;
dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps);
}
tFreeSStatusRsp(&statusRsp);
}
pMgmt->statusSent = 0;
return TSDB_CODE_SUCCESS;
}
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
SRpcMsg *pRsp = &pMsg->rpcMsg; SRpcMsg *pRsp = &pMsg->rpcMsg;
dError("auth rsp is received, but not supported yet"); dError("auth rsp is received, but not supported yet");
return 0; return 0;
} }
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) {
SRpcMsg *pRsp = &pMsg->rpcMsg; SRpcMsg *pRsp = &pMsg->rpcMsg;
dError("grant rsp is received, but not supported yet"); dError("grant rsp is received, but not supported yet");
return 0; return 0;
} }
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg) {
SRpcMsg *pReq = &pMsg->rpcMsg; SRpcMsg *pReq = &pMsg->rpcMsg;
SDCfgDnodeReq *pCfg = pReq->pCont; SDCfgDnodeReq *pCfg = pReq->pCont;
dError("config req is received, but not supported yet"); dError("config req is received, but not supported yet");
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_OPS_NOT_SUPPORT;
} }
static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
if (pWrapper != NULL) { if (pWrapper != NULL) {
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED; terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
dError("failed to create node since %s", terrstr()); dError("failed to create node since %s", terrstr());
return -1; return -1;
} }
taosThreadMutexLock(&pDnode->mutex);
pWrapper = &pDnode->wrappers[ntype]; pWrapper = &pDnode->wrappers[ntype];
if (taosMkDir(pWrapper->path) != 0) { if (taosMkDir(pWrapper->path) != 0) {
...@@ -136,81 +125,150 @@ static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg * ...@@ -136,81 +125,150 @@ static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *
return -1; return -1;
} }
int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg); int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg);
if (code != 0) { if (code != 0) {
dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
} else { } else {
dDebug("node:%s, has been opened", pWrapper->name); dDebug("node:%s, has been created", pWrapper->name);
pWrapper->required = true;
pWrapper->deployed = true; pWrapper->deployed = true;
pWrapper->procType = pDnode->ptype;
(void)dmOpenNode(pWrapper);
} }
taosThreadMutexUnlock(&pDnode->mutex);
return code; return code;
} }
static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
if (pWrapper == NULL) { if (pWrapper == NULL) {
terrno = TSDB_CODE_NODE_NOT_DEPLOYED; terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
dError("failed to drop node since %s", terrstr()); dError("failed to drop node since %s", terrstr());
return -1; return -1;
} }
taosWLockLatch(&pWrapper->latch); taosThreadMutexLock(&pDnode->mutex);
pWrapper->deployed = false;
int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg); int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg);
if (code != 0) { if (code != 0) {
pWrapper->deployed = true;
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
} else { } else {
pWrapper->deployed = false;
dDebug("node:%s, has been dropped", pWrapper->name); dDebug("node:%s, has been dropped", pWrapper->name);
} }
taosWUnLockLatch(&pWrapper->latch); dmReleaseWrapper(pWrapper);
dndReleaseWrapper(pWrapper);
if (code == 0) {
dmCloseNode(pWrapper);
pWrapper->required = false;
pWrapper->deployed = false;
taosRemoveDir(pWrapper->path);
}
taosThreadMutexUnlock(&pDnode->mutex);
return code; return code;
} }
int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) { static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) {
switch (pMsg->rpcMsg.msgType) { // Requests handled by DNODE
case TDMT_DND_CREATE_MNODE: dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg); dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
case TDMT_DND_DROP_MNODE: dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessDropNodeMsg(pDnode, MNODE, pMsg); dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
case TDMT_DND_CREATE_QNODE: dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg); dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
case TDMT_DND_DROP_QNODE: dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessDropNodeMsg(pDnode, QNODE, pMsg); dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
case TDMT_DND_CREATE_SNODE: dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg);
case TDMT_DND_DROP_SNODE: // Requests handled by MNODE
return dmProcessDropNodeMsg(pDnode, SNODE, pMsg); dmSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
case TDMT_DND_CREATE_BNODE: dmSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg); }
case TDMT_DND_DROP_BNODE:
return dmProcessDropNodeMsg(pDnode, BNODE, pMsg); static int32_t dmStartMgmt(SMgmtWrapper *pWrapper) {
default: if (dmStartStatusThread(pWrapper->pDnode) != 0) {
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
return -1; return -1;
} }
if (dmStartMonitorThread(pWrapper->pDnode) != 0) {
return -1;
}
return 0;
} }
void dmInitMsgHandle(SMgmtWrapper *pWrapper) { static void dmStopMgmt(SMgmtWrapper *pWrapper) {
// Requests handled by DNODE dmStopMonitorThread(pWrapper->pDnode);
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); dmStopStatusThread(pWrapper->pDnode);
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); }
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE);
// Requests handled by MNODE static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); dInfo("dnode-mgmt start to init");
dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); SDnode *pDnode = pWrapper->pDnode;
dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
pDnode->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
if (pDnode->data.dnodeHash == NULL) {
dError("failed to init dnode hash");
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (dmReadEps(pDnode) != 0) {
dError("failed to read file since %s", terrstr());
return -1;
}
if (pDnode->data.dropped) {
dError("dnode will not start since its already dropped");
return -1;
}
if (dmStartWorker(pDnode) != 0) {
return -1;
}
if (dmInitTrans(pDnode) != 0) {
dError("failed to init transport since %s", terrstr());
return -1;
}
dInfo("dnode-mgmt is initialized");
return 0;
}
static void dmCleanupMgmt(SMgmtWrapper *pWrapper) {
dInfo("dnode-mgmt start to clean up");
SDnode *pDnode = pWrapper->pDnode;
dmStopWorker(pDnode);
taosWLockLatch(&pDnode->data.latch);
if (pDnode->data.dnodeEps != NULL) {
taosArrayDestroy(pDnode->data.dnodeEps);
pDnode->data.dnodeEps = NULL;
}
if (pDnode->data.dnodeHash != NULL) {
taosHashCleanup(pDnode->data.dnodeHash);
pDnode->data.dnodeHash = NULL;
}
taosWUnLockLatch(&pDnode->data.latch);
dmCleanupTrans(pDnode);
dInfo("dnode-mgmt is cleaned up");
}
static int32_t dmRequireMgmt(SMgmtWrapper *pWrapper, bool *required) {
*required = true;
return 0;
}
void dmSetMgmtFp(SMgmtWrapper *pWrapper) {
SMgmtFp mgmtFp = {0};
mgmtFp.openFp = dmInitMgmt;
mgmtFp.closeFp = dmCleanupMgmt;
mgmtFp.startFp = dmStartMgmt;
mgmtFp.stopFp = dmStopMgmt;
mgmtFp.requiredFp = dmRequireMgmt;
dmSetMgmtMsgHandle(pWrapper);
pWrapper->name = "dnode";
pWrapper->fp = mgmtFp;
} }
...@@ -14,17 +14,17 @@ ...@@ -14,17 +14,17 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmInt.h" #include "dmImp.h"
static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
pInfo->protocol = 1; pInfo->protocol = 1;
pInfo->dnode_id = pDnode->dnodeId; pInfo->dnode_id = pDnode->data.dnodeId;
pInfo->cluster_id = pDnode->clusterId; pInfo->cluster_id = pDnode->data.clusterId;
tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN); tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
} }
static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f); pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f);
pInfo->has_mnode = pDnode->wrappers[MNODE].required; pInfo->has_mnode = pDnode->wrappers[MNODE].required;
pInfo->has_qnode = pDnode->wrappers[QNODE].required; pInfo->has_qnode = pDnode->wrappers[QNODE].required;
pInfo->has_snode = pDnode->wrappers[SNODE].required; pInfo->has_snode = pDnode->wrappers[SNODE].required;
...@@ -55,7 +55,7 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -55,7 +55,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
SRpcMsg req = {0}; SRpcMsg req = {0};
SRpcMsg rsp; SRpcMsg rsp;
SEpSet epset = {.inUse = 0, .numOfEps = 1}; SEpSet epset = {.inUse = 0, .numOfEps = 1};
tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN);
epset.eps[0].port = tsServerPort; epset.eps[0].port = tsServerPort;
SMgmtWrapper *pWrapper = NULL; SMgmtWrapper *pWrapper = NULL;
...@@ -64,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -64,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
bool getFromAPI = !tsMultiProcess; bool getFromAPI = !tsMultiProcess;
pWrapper = &pDnode->wrappers[MNODE]; pWrapper = &pDnode->wrappers[MNODE];
if (getFromAPI) { if (getFromAPI) {
if (dndMarkWrapper(pWrapper) == 0) { if (dmMarkWrapper(pWrapper) == 0) {
mmGetMonitorInfo(pWrapper, &mmInfo); mmGetMonitorInfo(pWrapper, &mmInfo);
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
} }
} else { } else {
if (pWrapper->required) { if (pWrapper->required) {
req.msgType = TDMT_MON_MM_INFO; req.msgType = TDMT_MON_MM_INFO;
dndSendRecv(pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo);
} }
...@@ -79,16 +79,16 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -79,16 +79,16 @@ void dmSendMonitorReport(SDnode *pDnode) {
} }
} }
pWrapper = &pDnode->wrappers[VNODES]; pWrapper = &pDnode->wrappers[VNODE];
if (getFromAPI) { if (getFromAPI) {
if (dndMarkWrapper(pWrapper) == 0) { if (dmMarkWrapper(pWrapper) == 0) {
vmGetMonitorInfo(pWrapper, &vmInfo); vmGetMonitorInfo(pWrapper, &vmInfo);
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
} }
} else { } else {
if (pWrapper->required) { if (pWrapper->required) {
req.msgType = TDMT_MON_VM_INFO; req.msgType = TDMT_MON_VM_INFO;
dndSendRecv(pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo);
} }
...@@ -98,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -98,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
pWrapper = &pDnode->wrappers[QNODE]; pWrapper = &pDnode->wrappers[QNODE];
if (getFromAPI) { if (getFromAPI) {
if (dndMarkWrapper(pWrapper) == 0) { if (dmMarkWrapper(pWrapper) == 0) {
qmGetMonitorInfo(pWrapper, &qmInfo); qmGetMonitorInfo(pWrapper, &qmInfo);
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
} }
} else { } else {
if (pWrapper->required) { if (pWrapper->required) {
req.msgType = TDMT_MON_QM_INFO; req.msgType = TDMT_MON_QM_INFO;
dndSendRecv(pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo);
} }
...@@ -115,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -115,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
pWrapper = &pDnode->wrappers[SNODE]; pWrapper = &pDnode->wrappers[SNODE];
if (getFromAPI) { if (getFromAPI) {
if (dndMarkWrapper(pWrapper) == 0) { if (dmMarkWrapper(pWrapper) == 0) {
smGetMonitorInfo(pWrapper, &smInfo); smGetMonitorInfo(pWrapper, &smInfo);
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
} }
} else { } else {
if (pWrapper->required) { if (pWrapper->required) {
req.msgType = TDMT_MON_SM_INFO; req.msgType = TDMT_MON_SM_INFO;
dndSendRecv(pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo);
} }
...@@ -132,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -132,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
pWrapper = &pDnode->wrappers[BNODE]; pWrapper = &pDnode->wrappers[BNODE];
if (getFromAPI) { if (getFromAPI) {
if (dndMarkWrapper(pWrapper) == 0) { if (dmMarkWrapper(pWrapper) == 0) {
bmGetMonitorInfo(pWrapper, &bmInfo); bmGetMonitorInfo(pWrapper, &bmInfo);
dndReleaseWrapper(pWrapper); dmReleaseWrapper(pWrapper);
} }
} else { } else {
if (pWrapper->required) { if (pWrapper->required) {
req.msgType = TDMT_MON_BM_INFO; req.msgType = TDMT_MON_BM_INFO;
dndSendRecv(pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo);
} }
...@@ -161,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) { ...@@ -161,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) {
monSendReport(); monSendReport();
} }
void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo) {
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, VNODE);
if (pWrapper == NULL) return;
bool getFromAPI = !tsMultiProcess; bool getFromAPI = !tsMultiProcess;
if (getFromAPI) { if (getFromAPI) {
vmGetVnodeLoads(pWrapper, pInfo); vmGetVnodeLoads(pWrapper, pInfo);
...@@ -169,26 +172,14 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { ...@@ -169,26 +172,14 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) {
SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD}; SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD};
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
SEpSet epset = {.inUse = 0, .numOfEps = 1}; SEpSet epset = {.inUse = 0, .numOfEps = 1};
tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN);
epset.eps[0].port = tsServerPort; epset.eps[0].port = tsServerPort;
dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp); dmSendRecv(pDnode, &epset, &req, &rsp);
if (rsp.code == 0 && rsp.contLen > 0) { if (rsp.code == 0 && rsp.contLen > 0) {
tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo); tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo);
} }
rpcFreeCont(rsp.pCont); rpcFreeCont(rsp.pCont);
} }
} dmReleaseWrapper(pWrapper);
void dmGetMonitorSysInfo(SMonSysInfo *pInfo) {
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
taosGetCpuCores(&pInfo->cpu_cores);
taosGetProcMemory(&pInfo->mem_engine);
taosGetSysMemory(&pInfo->mem_system);
pInfo->mem_total = tsTotalMemoryKB;
pInfo->disk_engine = 0;
pInfo->disk_used = tsDataSpace.size.used;
pInfo->disk_total = tsDataSpace.size.total;
taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
} }
/*
* 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 "dmImp.h"
static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
pDnode->data.dnodeId = 0;
pDnode->data.clusterId = 0;
pDnode->data.dnodeVer = 0;
pDnode->data.updateTime = 0;
pDnode->data.rebootTime = taosGetTimestampMs();
pDnode->data.dropped = 0;
pDnode->data.localEp = strdup(pOption->localEp);
pDnode->data.localFqdn = strdup(pOption->localFqdn);
pDnode->data.firstEp = strdup(pOption->firstEp);
pDnode->data.secondEp = strdup(pOption->secondEp);
pDnode->data.dataDir = strdup(pOption->dataDir);
pDnode->data.disks = pOption->disks;
pDnode->data.numOfDisks = pOption->numOfDisks;
pDnode->data.supportVnodes = pOption->numOfSupportVnodes;
pDnode->data.serverPort = pOption->serverPort;
pDnode->ntype = pOption->ntype;
if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL ||
pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_END) {
pDnode->data.lockfile = dmCheckRunning(pDnode->data.dataDir);
if (pDnode->data.lockfile == NULL) {
return -1;
}
}
taosInitRWLatch(&pDnode->data.latch);
taosThreadMutexInit(&pDnode->mutex, NULL);
return 0;
}
static void dmClearVars(SDnode *pDnode) {
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
taosMemoryFreeClear(pMgmt->path);
}
if (pDnode->data.lockfile != NULL) {
taosUnLockFile(pDnode->data.lockfile);
taosCloseFile(&pDnode->data.lockfile);
pDnode->data.lockfile = NULL;
}
taosMemoryFreeClear(pDnode->data.localEp);
taosMemoryFreeClear(pDnode->data.localFqdn);
taosMemoryFreeClear(pDnode->data.firstEp);
taosMemoryFreeClear(pDnode->data.secondEp);
taosMemoryFreeClear(pDnode->data.dataDir);
taosThreadMutexDestroy(&pDnode->mutex);
memset(&pDnode->mutex, 0, sizeof(pDnode->mutex));
taosMemoryFree(pDnode);
dDebug("dnode memory is cleared, data:%p", pDnode);
}
SDnode *dmCreate(const SDnodeOpt *pOption) {
dDebug("start to create dnode");
int32_t code = -1;
char path[PATH_MAX] = {0};
SDnode *pDnode = NULL;
pDnode = taosMemoryCalloc(1, sizeof(SDnode));
if (pDnode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
if (dmInitVars(pDnode, pOption) != 0) {
dError("failed to init variables since %s", terrstr());
goto _OVER;
}
dmSetStatus(pDnode, DND_STAT_INIT);
dmSetMgmtFp(&pDnode->wrappers[DNODE]);
mmSetMgmtFp(&pDnode->wrappers[MNODE]);
vmSetMgmtFp(&pDnode->wrappers[VNODE]);
qmSetMgmtFp(&pDnode->wrappers[QNODE]);
smSetMgmtFp(&pDnode->wrappers[SNODE]);
bmSetMgmtFp(&pDnode->wrappers[BNODE]);
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
snprintf(path, sizeof(path), "%s%s%s", pDnode->data.dataDir, TD_DIRSEP, pWrapper->name);
pWrapper->path = strdup(path);
pWrapper->procShm.id = -1;
pWrapper->pDnode = pDnode;
pWrapper->ntype = n;
pWrapper->procType = DND_PROC_SINGLE;
taosInitRWLatch(&pWrapper->latch);
if (pWrapper->path == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
if (n != DNODE && dmReadShmFile(pWrapper) != 0) {
dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr());
goto _OVER;
}
}
if (dmInitMsgHandle(pDnode) != 0) {
dError("failed to init msg handles since %s", terrstr());
goto _OVER;
}
pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]);
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
dInfo("dnode is created, data:%p", pDnode);
code = 0;
_OVER:
if (code != 0 && pDnode) {
dmClearVars(pDnode);
pDnode = NULL;
dError("failed to create dnode since %s", terrstr());
}
return pDnode;
}
void dmClose(SDnode *pDnode) {
if (pDnode == NULL) return;
dmClearVars(pDnode);
dInfo("dnode is closed, data:%p", pDnode);
}
...@@ -14,43 +14,62 @@ ...@@ -14,43 +14,62 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmInt.h" #include "dmImp.h"
static void *dmThreadRoutine(void *param) { static void *dmStatusThreadFp(void *param) {
SDnodeMgmt *pMgmt = param; SDnode *pDnode = param;
SDnode *pDnode = pMgmt->pDnode; int64_t lastTime = taosGetTimestampMs();
int64_t lastStatusTime = taosGetTimestampMs();
int64_t lastMonitorTime = lastStatusTime;
setThreadName("dnode-hb"); setThreadName("dnode-status");
while (true) { while (1) {
taosThreadTestCancel(); taosThreadTestCancel();
taosMsleep(200); taosMsleep(200);
if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) {
if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) {
continue; continue;
} }
int64_t curTime = taosGetTimestampMs(); int64_t curTime = taosGetTimestampMs();
float statusInterval = (curTime - lastStatusTime) / 1000.0f; float interval = (curTime - lastTime) / 1000.0f;
if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) { if (interval >= tsStatusInterval) {
dmSendStatusReq(pMgmt); dmSendStatusReq(pDnode);
lastStatusTime = curTime; lastTime = curTime;
}
}
return NULL;
}
static void *dmMonitorThreadFp(void *param) {
SDnode *pDnode = param;
int64_t lastTime = taosGetTimestampMs();
setThreadName("dnode-monitor");
while (1) {
taosThreadTestCancel();
taosMsleep(200);
if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) {
continue;
} }
float monitorInterval = (curTime - lastMonitorTime) / 1000.0f; int64_t curTime = taosGetTimestampMs();
if (monitorInterval >= tsMonitorInterval) { float interval = (curTime - lastTime) / 1000.0f;
if (interval >= tsMonitorInterval) {
dmSendMonitorReport(pDnode); dmSendMonitorReport(pDnode);
lastMonitorTime = curTime; lastTime = curTime;
} }
} }
return TSDB_CODE_SUCCESS;
return NULL;
} }
int32_t dmStartThread(SDnodeMgmt *pMgmt) { int32_t dmStartStatusThread(SDnode *pDnode) {
pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); pDnode->data.statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode);
if (pMgmt->threadId == NULL) { if (pDnode->data.statusThreadId == NULL) {
dError("failed to init dnode thread"); dError("failed to init dnode status thread");
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
...@@ -58,29 +77,72 @@ int32_t dmStartThread(SDnodeMgmt *pMgmt) { ...@@ -58,29 +77,72 @@ int32_t dmStartThread(SDnodeMgmt *pMgmt) {
return 0; return 0;
} }
static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { void dmStopStatusThread(SDnode *pDnode) {
SDnodeMgmt *pMgmt = pInfo->ahandle; if (pDnode->data.statusThreadId != NULL) {
taosDestoryThread(pDnode->data.statusThreadId);
pDnode->data.statusThreadId = NULL;
}
}
int32_t dmStartMonitorThread(SDnode *pDnode) {
pDnode->data.monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode);
if (pDnode->data.monitorThreadId == NULL) {
dError("failed to init dnode monitor thread");
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
return 0;
}
SDnode *pDnode = pMgmt->pDnode; void dmStopMonitorThread(SDnode *pDnode) {
if (pDnode->data.monitorThreadId != NULL) {
taosDestoryThread(pDnode->data.monitorThreadId);
pDnode->data.monitorThreadId = NULL;
}
}
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
SDnode *pDnode = pInfo->ahandle;
SRpcMsg *pRpc = &pMsg->rpcMsg; SRpcMsg *pRpc = &pMsg->rpcMsg;
int32_t code = -1; int32_t code = -1;
dTrace("msg:%p, will be processed in dnode queue", pMsg); dTrace("msg:%p, will be processed in dnode-mgmt queue", pMsg);
switch (pRpc->msgType) { switch (pRpc->msgType) {
case TDMT_DND_CONFIG_DNODE: case TDMT_DND_CONFIG_DNODE:
code = dmProcessConfigReq(pMgmt, pMsg); code = dmProcessConfigReq(pDnode, pMsg);
break;
case TDMT_MND_STATUS_RSP:
code = dmProcessStatusRsp(pMgmt, pMsg);
break; break;
case TDMT_MND_AUTH_RSP: case TDMT_MND_AUTH_RSP:
code = dmProcessAuthRsp(pMgmt, pMsg); code = dmProcessAuthRsp(pDnode, pMsg);
break; break;
case TDMT_MND_GRANT_RSP: case TDMT_MND_GRANT_RSP:
code = dmProcessGrantRsp(pMgmt, pMsg); code = dmProcessGrantRsp(pDnode, pMsg);
break;
case TDMT_DND_CREATE_MNODE:
code = dmProcessCreateNodeReq(pDnode, MNODE, pMsg);
break;
case TDMT_DND_DROP_MNODE:
code = dmProcessDropNodeReq(pDnode, MNODE, pMsg);
break;
case TDMT_DND_CREATE_QNODE:
code = dmProcessCreateNodeReq(pDnode, QNODE, pMsg);
break;
case TDMT_DND_DROP_QNODE:
code = dmProcessDropNodeReq(pDnode, QNODE, pMsg);
break;
case TDMT_DND_CREATE_SNODE:
code = dmProcessCreateNodeReq(pDnode, SNODE, pMsg);
break;
case TDMT_DND_DROP_SNODE:
code = dmProcessDropNodeReq(pDnode, SNODE, pMsg);
break;
case TDMT_DND_CREATE_BNODE:
code = dmProcessCreateNodeReq(pDnode, BNODE, pMsg);
break;
case TDMT_DND_DROP_BNODE:
code = dmProcessDropNodeReq(pDnode, BNODE, pMsg);
break; break;
default: default:
code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg);
break; break;
} }
...@@ -95,16 +157,10 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { ...@@ -95,16 +157,10 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
taosFreeQitem(pMsg); taosFreeQitem(pMsg);
} }
int32_t dmStartWorker(SDnodeMgmt *pMgmt) { int32_t dmStartWorker(SDnode *pDnode) {
SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pDnode};
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) { if (tSingleWorkerInit(&pDnode->data.mgmtWorker, &cfg) != 0) {
dError("failed to start dnode mgmt worker since %s", terrstr()); dError("failed to start dnode-mgmt worker since %s", terrstr());
return -1;
}
SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt};
if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) {
dError("failed to start dnode monitor worker since %s", terrstr());
return -1; return -1;
} }
...@@ -112,30 +168,13 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { ...@@ -112,30 +168,13 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
return 0; return 0;
} }
void dmStopWorker(SDnodeMgmt *pMgmt) { void dmStopWorker(SDnode *pDnode) {
tSingleWorkerCleanup(&pMgmt->mgmtWorker); tSingleWorkerCleanup(&pDnode->data.mgmtWorker);
tSingleWorkerCleanup(&pMgmt->monitorWorker);
if (pMgmt->threadId != NULL) {
taosDestoryThread(pMgmt->threadId);
pMgmt->threadId = NULL;
}
dDebug("dnode workers are closed"); dDebug("dnode workers are closed");
} }
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
SDnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pWrapper->pDnode->data.mgmtWorker;
SSingleWorker *pWorker = &pMgmt->mgmtWorker;
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
taosWriteQitem(pWorker->queue, pMsg);
return 0;
}
int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
SSingleWorker *pWorker = &pMgmt->monitorWorker;
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
taosWriteQitem(pWorker->queue, pMsg); taosWriteQitem(pWorker->queue, pMsg);
return 0; return 0;
......
/*
* 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_DNODE_INT_H_
#define _TD_DND_DNODE_INT_H_
#include "dndInt.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SDnodeMgmt {
int64_t dver;
int64_t updateTime;
int8_t statusSent;
SEpSet mnodeEpSet;
SHashObj *dnodeHash;
SArray *dnodeEps;
TdThread *threadId;
SRWLatch latch;
SSingleWorker mgmtWorker;
SSingleWorker monitorWorker;
SMsgCb msgCb;
const char *path;
SDnode *pDnode;
SMgmtWrapper *pWrapper;
} SDnodeMgmt;
// dmFile.c
int32_t dmReadFile(SDnodeMgmt *pMgmt);
int32_t dmWriteFile(SDnodeMgmt *pMgmt);
void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *pDnodeEps);
// dmHandle.c
void dmInitMsgHandle(SMgmtWrapper *pWrapper);
void dmSendStatusReq(SDnodeMgmt *pMgmt);
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg);
// dmMonitor.c
void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
void dmSendMonitorReport(SDnode *pDnode);
// dmWorker.c
int32_t dmStartThread(SDnodeMgmt *pMgmt);
int32_t dmStartWorker(SDnodeMgmt *pMgmt);
void dmStopWorker(SDnodeMgmt *pMgmt);
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
#ifdef __cplusplus
}
#endif
#endif /*_TD_DND_DNODE_INT_H_*/
\ No newline at end of file
/*
* 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_INT_H_
#define _TD_DND_INT_H_
#include "os.h"
#include "cJSON.h"
#include "tcache.h"
#include "tcrc32c.h"
#include "tdatablock.h"
#include "tglobal.h"
#include "thash.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tmsg.h"
#include "tmsgcb.h"
#include "tprocess.h"
#include "tqueue.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
#include "tworker.h"
#include "dnode.h"
#include "monitor.h"
#ifdef __cplusplus
extern "C" {
#endif
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } EDndType;
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus;
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStatus;
typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType;
typedef struct SMgmtFp SMgmtFp;
typedef struct SMgmtWrapper SMgmtWrapper;
typedef struct SMsgHandle SMsgHandle;
typedef struct SDnodeMgmt SDnodeMgmt;
typedef struct SVnodesMgmt SVnodesMgmt;
typedef struct SMnodeMgmt SMnodeMgmt;
typedef struct SQnodeMgmt SQnodeMgmt;
typedef struct SSnodeMgmt SSnodeMgmt;
typedef struct SBnodeMgmt SBnodeMgmt;
typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper);
typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper);
typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper);
typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required);
typedef struct SMsgHandle {
SMgmtWrapper *pQndWrapper;
SMgmtWrapper *pMndWrapper;
SMgmtWrapper *pWrapper;
} SMsgHandle;
typedef struct SMgmtFp {
OpenNodeFp openFp;
CloseNodeFp closeFp;
StartNodeFp startFp;
CreateNodeFp createMsgFp;
DropNodeFp dropMsgFp;
RequireNodeFp requiredFp;
} SMgmtFp;
typedef struct SMgmtWrapper {
const char *name;
char *path;
int32_t refCount;
SRWLatch latch;
EDndType ntype;
bool deployed;
bool required;
EProcType procType;
int32_t procId;
SProcObj *pProc;
SShm shm;
void *pMgmt;
SDnode *pDnode;
SMgmtFp fp;
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
NodeMsgFp msgFps[TDMT_MAX];
} SMgmtWrapper;
typedef struct {
void *serverRpc;
void *clientRpc;
SMsgHandle msgHandles[TDMT_MAX];
} STransMgmt;
typedef struct SDnode {
int64_t clusterId;
int32_t dnodeId;
int32_t numOfSupportVnodes;
int64_t rebootTime;
char *localEp;
char *localFqdn;
char *firstEp;
char *secondEp;
char *dataDir;
SDiskCfg *disks;
int32_t numOfDisks;
uint16_t serverPort;
bool dropped;
EProcType procType;
EDndType ntype;
EDndStatus status;
EDndEvent event;
SStartupReq startup;
TdFilePtr lockfile;
STransMgmt trans;
SMgmtWrapper wrappers[NODE_MAX];
} SDnode;
// dndEnv.c
const char *dndStatStr(EDndStatus stat);
const char *dndNodeLogStr(EDndType ntype);
const char *dndNodeProcStr(EDndType ntype);
const char *dndEventStr(EDndEvent ev);
// dndExec.c
int32_t dndOpenNode(SMgmtWrapper *pWrapper);
void dndCloseNode(SMgmtWrapper *pWrapper);
// dndFile.c
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
TdFilePtr dndCheckRunning(const char *dataDir);
int32_t dndReadShmFile(SDnode *pDnode);
int32_t dndWriteShmFile(SDnode *pDnode);
// dndInt.c
EDndStatus dndGetStatus(SDnode *pDnode);
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType nType);
int32_t dndMarkWrapper(SMgmtWrapper *pWrapper);
void dndReleaseWrapper(SMgmtWrapper *pWrapper);
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
// dndTransport.c
int32_t dndInitTrans(SDnode *pDnode);
void dndCleanupTrans(SDnode *pDnode);
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper);
int32_t dndInitMsgHandle(SDnode *pDnode);
void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
// mgmt
void dmSetMgmtFp(SMgmtWrapper *pWrapper);
void bmSetMgmtFp(SMgmtWrapper *pWrapper);
void qmSetMgmtFp(SMgmtWrapper *pMgmt);
void smSetMgmtFp(SMgmtWrapper *pWrapper);
void vmSetMgmtFp(SMgmtWrapper *pWrapper);
void mmSetMgmtFp(SMgmtWrapper *pMgmt);
void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg);
void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo);
void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo);
void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo);
void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo);
void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo);
#ifdef __cplusplus
}
#endif
#endif /*_TD_DND_INT_H_*/
\ No newline at end of file
aux_source_directory(src DNODE_INTERFACE)
add_library(dnode_interface STATIC ${DNODE_INTERFACE})
target_include_directories(
dnode_interface
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt"
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
)
\ No newline at end of file
/*
* 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_DM_DEF_H_
#define _TD_DM_DEF_H_
#include "dmLog.h"
#include "cJSON.h"
#include "tcache.h"
#include "tcrc32c.h"
#include "tdatablock.h"
#include "tglobal.h"
#include "thash.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tmsg.h"
#include "tmsgcb.h"
#include "tprocess.h"
#include "tqueue.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
#include "tworker.h"
#include "dnode.h"
#include "mnode.h"
#include "monitor.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { DNODE, VNODE, QNODE, SNODE, MNODE, BNODE, NODE_END } EDndNodeType;
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndRunStatus;
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EDndEnvStatus;
typedef enum { DND_PROC_SINGLE, DND_PROC_CHILD, DND_PROC_PARENT } EDndProcType;
typedef int32_t (*NodeMsgFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*OpenNodeFp)(struct SMgmtWrapper *pWrapper);
typedef void (*CloseNodeFp)(struct SMgmtWrapper *pWrapper);
typedef int32_t (*StartNodeFp)(struct SMgmtWrapper *pWrapper);
typedef void (*StopNodeFp)(struct SMgmtWrapper *pWrapper);
typedef int32_t (*CreateNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*DropNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*RequireNodeFp)(struct SMgmtWrapper *pWrapper, bool *required);
typedef struct {
SMgmtWrapper *pQndWrapper;
SMgmtWrapper *pMndWrapper;
SMgmtWrapper *pNdWrapper;
} SMsgHandle;
typedef struct {
OpenNodeFp openFp;
CloseNodeFp closeFp;
StartNodeFp startFp;
StopNodeFp stopFp;
CreateNodeFp createFp;
DropNodeFp dropFp;
RequireNodeFp requiredFp;
} SMgmtFp;
typedef struct SMgmtWrapper {
SDnode *pDnode;
struct {
const char *name;
char *path;
int32_t refCount;
SRWLatch latch;
EDndNodeType ntype;
bool deployed;
bool required;
SMgmtFp fp;
void *pMgmt;
};
struct {
EDndProcType procType;
int32_t procId;
SProcObj *procObj;
SShm procShm;
};
struct {
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
NodeMsgFp msgFps[TDMT_MAX];
};
} SMgmtWrapper;
typedef struct {
void *serverRpc;
void *clientRpc;
SMsgHandle msgHandles[TDMT_MAX];
} SDnodeTrans;
typedef struct {
int32_t dnodeId;
int64_t clusterId;
int64_t dnodeVer;
int64_t updateTime;
int64_t rebootTime;
bool dropped;
SEpSet mnodeEps;
SArray *dnodeEps;
SHashObj *dnodeHash;
TdThread *statusThreadId;
TdThread *monitorThreadId;
SRWLatch latch;
SSingleWorker mgmtWorker;
SMsgCb msgCb;
SDnode *pDnode;
TdFilePtr lockfile;
char *localEp;
char *localFqdn;
char *firstEp;
char *secondEp;
char *dataDir;
SDiskCfg *disks;
int32_t numOfDisks;
int32_t supportVnodes;
uint16_t serverPort;
} SDnodeData;
typedef struct SDnode {
EDndProcType ptype;
EDndNodeType ntype;
EDndRunStatus status;
EDndEvent event;
SStartupReq startup;
SDnodeTrans trans;
SDnodeData data;
TdThreadMutex mutex;
SMgmtWrapper wrappers[NODE_END];
} SDnode;
#ifdef __cplusplus
}
#endif
#endif /*_TD_DM_DEF_H_*/
\ No newline at end of file
...@@ -13,56 +13,40 @@ ...@@ -13,56 +13,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_VNODE_TSDB_SMA_H_ #ifndef _TD_DM_INT_H_
#define _TD_VNODE_TSDB_SMA_H_ #define _TD_DM_INT_H_
#include "tdbInt.h" #include "dmDef.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct SSmaKey SSmaKey; // dmInt.c
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
struct SSmaKey { int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
TSKEY skey; void dmReleaseWrapper(SMgmtWrapper *pWrapper);
int64_t groupId; const char *dmStatName(EDndRunStatus stat);
}; const char *dmLogName(EDndNodeType ntype);
const char *dmProcName(EDndNodeType ntype);
const char *dmEventName(EDndEvent ev);
typedef struct SDBFile SDBFile;
void dmSetStatus(SDnode *pDnode, EDndRunStatus stat);
struct SDBFile { void dmSetEvent(SDnode *pDnode, EDndEvent event);
int32_t fid; void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
TDB *pDB; void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
char *path; void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
}; void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
int32_t tsdbOpenDBEnv(TENV **ppEnv, const char *path); // dmFile.c
int32_t tsdbCloseDBEnv(TENV *pEnv); int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
int32_t tsdbOpenDBF(TENV *pEnv, SDBFile *pDBF); int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed);
int32_t tsdbCloseDBF(SDBFile *pDBF); TdFilePtr dmCheckRunning(const char *dataDir);
int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn); int32_t dmReadShmFile(SMgmtWrapper *pWrapper);
void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_t *valLen); int32_t dmWriteShmFile(SMgmtWrapper *pWrapper);
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv);
void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv);
#if 0
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
#endif
// internal func
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
int32_t len = 0;
len += taosEncodeFixedI64(pData, tsKey);
len += taosEncodeFixedI64(pData, groupId);
return len;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_VNODE_TSDB_SMA_H_*/ #endif /*_TD_DM_INT_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -13,28 +13,24 @@ ...@@ -13,28 +13,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_MACRO_H_ #ifndef _TD_DM_LOG_H_
#define _TD_UTIL_MACRO_H_ #define _TD_DM_LOG_H_
#include "os.h" #include "tlog.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// Module init/clear MACRO definitions #define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
#define TD_MOD_UNINITIALIZED 0 #define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
#define TD_MOD_INITIALIZED 1 #define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
typedef int8_t td_mode_flag_t; #define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED)
#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_INITIALIZED, TD_MOD_UNINITIALIZED)
#define TD_IS_NULL(PTR) ((PTR) == NULL)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_MACRO_H_*/ #endif /*_TD_DM_LOG_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dmInt.h"
#include "wal.h" #include "wal.h"
static int8_t once = DND_ENV_INIT; static int8_t once = DND_ENV_INIT;
int32_t dndInit() { int32_t dmInit() {
dDebug("start to init dnode env"); dDebug("start to init dnode env");
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
terrno = TSDB_CODE_REPEAT_INIT; terrno = TSDB_CODE_REPEAT_INIT;
...@@ -45,7 +45,7 @@ int32_t dndInit() { ...@@ -45,7 +45,7 @@ int32_t dndInit() {
return 0; return 0;
} }
void dndCleanup() { void dmCleanup() {
dDebug("start to cleanup dnode env"); dDebug("start to cleanup dnode env");
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
dError("dnode env is already cleaned up"); dError("dnode env is already cleaned up");
...@@ -57,63 +57,3 @@ void dndCleanup() { ...@@ -57,63 +57,3 @@ void dndCleanup() {
taosStopCacheRefreshWorker(); taosStopCacheRefreshWorker();
dInfo("dnode env is cleaned up"); dInfo("dnode env is cleaned up");
} }
const char *dndStatStr(EDndStatus status) {
switch (status) {
case DND_STAT_INIT:
return "init";
case DND_STAT_RUNNING:
return "running";
case DND_STAT_STOPPED:
return "stopped";
default:
return "UNKNOWN";
}
}
const char *dndNodeLogStr(EDndType ntype) {
switch (ntype) {
case VNODES:
return "vnode";
case QNODE:
return "qnode";
case SNODE:
return "snode";
case MNODE:
return "mnode";
case BNODE:
return "bnode";
default:
return "taosd";
}
}
const char *dndNodeProcStr(EDndType ntype) {
switch (ntype) {
case VNODES:
return "taosv";
case QNODE:
return "taosq";
case SNODE:
return "taoss";
case MNODE:
return "taosm";
case BNODE:
return "taosb";
default:
return "taosd";
}
}
const char *dndEventStr(EDndEvent ev) {
switch (ev) {
case DND_EVENT_START:
return "start";
case DND_EVENT_STOP:
return "stop";
case DND_EVENT_CHILD:
return "child";
default:
return "UNKNOWN";
}
}
\ No newline at end of file
...@@ -14,22 +14,22 @@ ...@@ -14,22 +14,22 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dmInt.h"
#define MAXLEN 1024 #define MAXLEN 1024
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
int64_t len = 0; int64_t len = 0;
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
cJSON *root = NULL; cJSON *root = NULL;
char file[PATH_MAX]; char file[PATH_MAX] = {0};
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
dDebug("file %s not exist", file); // dDebug("file %s not exist", file);
code = 0; code = 0;
goto _OVER; goto _OVER;
} }
...@@ -64,7 +64,7 @@ _OVER: ...@@ -64,7 +64,7 @@ _OVER:
return code; return code;
} }
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
int32_t code = -1; int32_t code = -1;
int32_t len = 0; int32_t len = 0;
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
...@@ -117,7 +117,7 @@ _OVER: ...@@ -117,7 +117,7 @@ _OVER:
return code; return code;
} }
TdFilePtr dndCheckRunning(const char *dataDir) { TdFilePtr dmCheckRunning(const char *dataDir) {
char filepath[PATH_MAX] = {0}; char filepath[PATH_MAX] = {0};
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP); snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
...@@ -140,18 +140,17 @@ TdFilePtr dndCheckRunning(const char *dataDir) { ...@@ -140,18 +140,17 @@ TdFilePtr dndCheckRunning(const char *dataDir) {
return pFile; return pFile;
} }
int32_t dndReadShmFile(SDnode *pDnode) { int32_t dmReadShmFile(SMgmtWrapper *pWrapper) {
int32_t code = -1; int32_t code = -1;
char itemName[24] = {0};
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
char file[PATH_MAX] = {0}; char file[PATH_MAX] = {0};
cJSON *root = NULL; cJSON *root = NULL;
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); snprintf(file, sizeof(file), "%s%sshmfile", pWrapper->path, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
dDebug("file %s not exist", file); // dDebug("node:%s, file %s not exist", pWrapper->name, file);
code = 0; code = 0;
goto _OVER; goto _OVER;
} }
...@@ -160,44 +159,36 @@ int32_t dndReadShmFile(SDnode *pDnode) { ...@@ -160,44 +159,36 @@ int32_t dndReadShmFile(SDnode *pDnode) {
root = cJSON_Parse(content); root = cJSON_Parse(content);
if (root == NULL) { if (root == NULL) {
terrno = TSDB_CODE_INVALID_JSON_FORMAT; terrno = TSDB_CODE_INVALID_JSON_FORMAT;
dError("failed to read %s since invalid json format", file); dError("node:%s, failed to read %s since invalid json format", pWrapper->name, file);
goto _OVER; goto _OVER;
} }
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { cJSON *shmid = cJSON_GetObjectItem(root, "shmid");
snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype));
cJSON *shmid = cJSON_GetObjectItem(root, itemName);
if (shmid && shmid->type == cJSON_Number) { if (shmid && shmid->type == cJSON_Number) {
pDnode->wrappers[ntype].shm.id = shmid->valueint; pWrapper->procShm.id = shmid->valueint;
} }
snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize");
cJSON *shmsize = cJSON_GetObjectItem(root, itemName);
if (shmsize && shmsize->type == cJSON_Number) { if (shmsize && shmsize->type == cJSON_Number) {
pDnode->wrappers[ntype].shm.size = shmsize->valueint; pWrapper->procShm.size = shmsize->valueint;
}
} }
} }
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) {
for (EDndType ntype = DNODE; ntype < NODE_MAX; ++ntype) { if (pWrapper->procShm.id >= 0) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
if (pWrapper->shm.id >= 0) { taosDropShm(&pWrapper->procShm);
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
taosDropShm(&pWrapper->shm);
}
} }
} else { } else {
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; if (taosAttachShm(&pWrapper->procShm) != 0) {
if (taosAttachShm(&pWrapper->shm) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); dError("shmid:%d, failed to attach shm since %s", pWrapper->procShm.id, terrstr());
goto _OVER; goto _OVER;
} }
dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size); dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
} }
dDebug("successed to load %s", file); dDebug("node:%s, successed to load %s", pWrapper->name, file);
code = 0; code = 0;
_OVER: _OVER:
...@@ -207,7 +198,7 @@ _OVER: ...@@ -207,7 +198,7 @@ _OVER:
return code; return code;
} }
int32_t dndWriteShmFile(SDnode *pDnode) { int32_t dmWriteShmFile(SMgmtWrapper *pWrapper) {
int32_t code = -1; int32_t code = -1;
int32_t len = 0; int32_t len = 0;
char content[MAXLEN + 1] = {0}; char content[MAXLEN + 1] = {0};
...@@ -215,37 +206,30 @@ int32_t dndWriteShmFile(SDnode *pDnode) { ...@@ -215,37 +206,30 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
char realfile[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0};
TdFilePtr pFile = NULL; TdFilePtr pFile = NULL;
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP); snprintf(file, sizeof(file), "%s%sshmfile.bak", pWrapper->path, TD_DIRSEP);
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); snprintf(realfile, sizeof(realfile), "%s%sshmfile", pWrapper->path, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to open file:%s since %s", file, terrstr()); dError("node:%s, failed to open file:%s since %s", pWrapper->name, file, terrstr());
goto _OVER; goto _OVER;
} }
len += snprintf(content + len, MAXLEN - len, "{\n"); len += snprintf(content + len, MAXLEN - len, "{\n");
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pWrapper->procShm.id);
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pWrapper->procShm.size);
len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id);
if (ntype == NODE_MAX - 1) {
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size);
} else {
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size);
}
}
len += snprintf(content + len, MAXLEN - len, "}\n"); len += snprintf(content + len, MAXLEN - len, "}\n");
if (taosWriteFile(pFile, content, len) != len) { if (taosWriteFile(pFile, content, len) != len) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to write file:%s since %s", file, terrstr()); dError("node:%s, failed to write file:%s since %s", pWrapper->name, file, terrstr());
goto _OVER; goto _OVER;
} }
if (taosFsyncFile(pFile) != 0) { if (taosFsyncFile(pFile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to fsync file:%s since %s", file, terrstr()); dError("node:%s, failed to fsync file:%s since %s", pWrapper->name, file, terrstr());
goto _OVER; goto _OVER;
} }
...@@ -253,11 +237,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) { ...@@ -253,11 +237,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
if (taosRenameFile(file, realfile) != 0) { if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s to %s since %s", file, realfile, terrstr()); dError("node:%s, failed to rename %s to %s since %s", pWrapper->name, file, realfile, terrstr());
return -1; return -1;
} }
dInfo("successed to write %s", realfile); dInfo("node:%s, successed to write %s", pWrapper->name, realfile);
code = 0; code = 0;
_OVER: _OVER:
......
...@@ -14,142 +14,87 @@ ...@@ -14,142 +14,87 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndInt.h" #include "dmInt.h"
static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { const char *dmStatName(EDndRunStatus status) {
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; switch (status) {
pDnode->serverPort = pOption->serverPort; case DND_STAT_INIT:
pDnode->dataDir = strdup(pOption->dataDir); return "init";
pDnode->localEp = strdup(pOption->localEp); case DND_STAT_RUNNING:
pDnode->localFqdn = strdup(pOption->localFqdn); return "running";
pDnode->firstEp = strdup(pOption->firstEp); case DND_STAT_STOPPED:
pDnode->secondEp = strdup(pOption->secondEp); return "stopped";
pDnode->disks = pOption->disks; default:
pDnode->numOfDisks = pOption->numOfDisks; return "UNKNOWN";
pDnode->ntype = pOption->ntype;
pDnode->rebootTime = taosGetTimestampMs();
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
pDnode->secondEp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
} }
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
pDnode->lockfile = dndCheckRunning(pDnode->dataDir);
if (pDnode->lockfile == NULL) {
return -1;
}
}
return 0;
} }
static void dndClearVars(SDnode *pDnode) { const char *dmLogName(EDndNodeType ntype) {
for (EDndType n = 0; n < NODE_MAX; ++n) { switch (ntype) {
SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; case VNODE:
taosMemoryFreeClear(pMgmt->path); return "vnode";
} case QNODE:
if (pDnode->lockfile != NULL) { return "qnode";
taosUnLockFile(pDnode->lockfile); case SNODE:
taosCloseFile(&pDnode->lockfile); return "snode";
pDnode->lockfile = NULL; case MNODE:
return "mnode";
case BNODE:
return "bnode";
default:
return "taosd";
} }
taosMemoryFreeClear(pDnode->localEp);
taosMemoryFreeClear(pDnode->localFqdn);
taosMemoryFreeClear(pDnode->firstEp);
taosMemoryFreeClear(pDnode->secondEp);
taosMemoryFreeClear(pDnode->dataDir);
taosMemoryFree(pDnode);
dDebug("dnode memory is cleared, data:%p", pDnode);
} }
SDnode *dndCreate(const SDnodeOpt *pOption) { const char *dmProcName(EDndNodeType ntype) {
dDebug("start to create dnode object"); switch (ntype) {
int32_t code = -1; case VNODE:
char path[PATH_MAX] = {0}; return "taosv";
SDnode *pDnode = NULL; case QNODE:
return "taosq";
pDnode = taosMemoryCalloc(1, sizeof(SDnode)); case SNODE:
if (pDnode == NULL) { return "taoss";
terrno = TSDB_CODE_OUT_OF_MEMORY; case MNODE:
goto _OVER; return "taosm";
} case BNODE:
return "taosb";
if (dndInitVars(pDnode, pOption) != 0) { default:
dError("failed to init variables since %s", terrstr()); return "taosd";
goto _OVER;
}
dndSetStatus(pDnode, DND_STAT_INIT);
dmSetMgmtFp(&pDnode->wrappers[DNODE]);
mmSetMgmtFp(&pDnode->wrappers[MNODE]);
vmSetMgmtFp(&pDnode->wrappers[VNODES]);
qmSetMgmtFp(&pDnode->wrappers[QNODE]);
smSetMgmtFp(&pDnode->wrappers[SNODE]);
bmSetMgmtFp(&pDnode->wrappers[BNODE]);
for (EDndType n = 0; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
pWrapper->path = strdup(path);
pWrapper->shm.id = -1;
pWrapper->pDnode = pDnode;
pWrapper->ntype = n;
if (pWrapper->path == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
} }
}
pWrapper->procType = PROC_SINGLE; const char *dmEventName(EDndEvent ev) {
taosInitRWLatch(&pWrapper->latch); switch (ev) {
} case DND_EVENT_START:
return "start";
if (dndInitMsgHandle(pDnode) != 0) { case DND_EVENT_STOP:
dError("failed to init msg handles since %s", terrstr()); return "stop";
goto _OVER; case DND_EVENT_CHILD:
} return "child";
default:
if (dndReadShmFile(pDnode) != 0) { return "UNKNOWN";
dError("failed to read shm file since %s", terrstr());
goto _OVER;
}
SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]);
tmsgSetDefaultMsgCb(&msgCb);
dInfo("dnode is created, data:%p", pDnode);
code = 0;
_OVER:
if (code != 0 && pDnode) {
dndClearVars(pDnode);
pDnode = NULL;
dError("failed to create dnode since %s", terrstr());
} }
return pDnode;
} }
void dndClose(SDnode *pDnode) { void dmSetStatus(SDnode *pDnode, EDndRunStatus status) {
if (pDnode == NULL) return; if (pDnode->status != status) {
dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status));
for (EDndType n = 0; n < NODE_MAX; ++n) { pDnode->status = status;
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
dndCloseNode(pWrapper);
} }
dndClearVars(pDnode);
dInfo("dnode is closed, data:%p", pDnode);
} }
void dndHandleEvent(SDnode *pDnode, EDndEvent event) { void dmSetEvent(SDnode *pDnode, EDndEvent event) {
if (event == DND_EVENT_STOP) { if (event == DND_EVENT_STOP) {
pDnode->event = event; pDnode->event = event;
} }
} }
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
}
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
SMgmtWrapper *pRetWrapper = pWrapper; SMgmtWrapper *pRetWrapper = pWrapper;
...@@ -166,11 +111,11 @@ SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { ...@@ -166,11 +111,11 @@ SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) {
return pRetWrapper; return pRetWrapper;
} }
int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
int32_t code = 0; int32_t code = 0;
taosRLockLatch(&pWrapper->latch); taosRLockLatch(&pWrapper->latch);
if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) {
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
} else { } else {
...@@ -182,7 +127,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { ...@@ -182,7 +127,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) {
return code; return code;
} }
void dndReleaseWrapper(SMgmtWrapper *pWrapper) { void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
if (pWrapper == NULL) return; if (pWrapper == NULL) return;
taosRLockLatch(&pWrapper->latch); taosRLockLatch(&pWrapper->latch);
...@@ -191,39 +136,38 @@ void dndReleaseWrapper(SMgmtWrapper *pWrapper) { ...@@ -191,39 +136,38 @@ void dndReleaseWrapper(SMgmtWrapper *pWrapper) {
dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount);
} }
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
}
EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; }
void dndSetStatus(SDnode *pDnode, EDndStatus status) {
if (pDnode->status != status) {
dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status));
pDnode->status = status;
}
}
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
SStartupReq *pStartup = &pDnode->startup; SStartupReq *pStartup = &pDnode->startup;
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
pStartup->finished = 0; pStartup->finished = 0;
} }
static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { static void dmGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); pStartup->finished = (pDnode->status == DND_STAT_RUNNING);
} }
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
dDebug("startup req is received"); dDebug("startup req is received");
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
dndGetStartup(pDnode, pStartup); dmGetStartup(pDnode, pStartup);
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
void dmGetMonitorSysInfo(SMonSysInfo *pInfo) {
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
taosGetCpuCores(&pInfo->cpu_cores);
taosGetProcMemory(&pInfo->mem_engine);
taosGetSysMemory(&pInfo->mem_system);
pInfo->mem_total = tsTotalMemoryKB;
pInfo->disk_engine = 0;
pInfo->disk_used = tsDataSpace.size.used;
pInfo->disk_total = tsDataSpace.size.total;
taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
}
aux_source_directory(src MGMT_BNODE)
add_library(mgmt_bnode STATIC ${MGMT_BNODE})
target_include_directories(
mgmt_bnode
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
mgmt_bnode dnode_interface
)
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_DND_BNODE_INT_H_ #ifndef _TD_DND_BNODE_INT_H_
#define _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_
#include "dndInt.h" #include "dmInt.h"
#include "bnode.h" #include "bnode.h"
...@@ -33,10 +33,6 @@ typedef struct SBnodeMgmt { ...@@ -33,10 +33,6 @@ typedef struct SBnodeMgmt {
SSingleWorker monitorWorker; SSingleWorker monitorWorker;
} SBnodeMgmt; } SBnodeMgmt;
// bmInt.c
int32_t bmOpen(SMgmtWrapper *pWrapper);
int32_t bmDrop(SMgmtWrapper *pWrapper);
// bmHandle.c // bmHandle.c
void bmInitMsgHandle(SMgmtWrapper *pWrapper); void bmInitMsgHandle(SMgmtWrapper *pWrapper);
int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
......
...@@ -53,13 +53,19 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { ...@@ -53,13 +53,19 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
return -1; return -1;
} }
if (createReq.dnodeId != pDnode->dnodeId) { if (createReq.dnodeId != pDnode->data.dnodeId) {
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_INVALID_OPTION;
dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->dnodeId); dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId);
return -1; return -1;
} else {
return dndOpenNode(pWrapper);
} }
bool deployed = true;
if (dmWriteFile(pWrapper, deployed) != 0) {
dError("failed to write bnode file since %s", terrstr());
return -1;
}
return 0;
} }
int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
...@@ -72,16 +78,21 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { ...@@ -72,16 +78,21 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
return -1; return -1;
} }
if (dropReq.dnodeId != pDnode->dnodeId) { if (dropReq.dnodeId != pDnode->data.dnodeId) {
terrno = TSDB_CODE_INVALID_OPTION; terrno = TSDB_CODE_INVALID_OPTION;
dError("failed to drop bnode since %s", terrstr()); dError("failed to drop bnode since %s", terrstr());
return -1; return -1;
} else {
// dndCloseNode(pWrapper);
return bmDrop(pWrapper);
} }
bool deployed = false;
if (dmWriteFile(pWrapper, deployed) != 0) {
dError("failed to write bnode file since %s", terrstr());
return -1;
}
return 0;
} }
void bmInitMsgHandle(SMgmtWrapper *pWrapper) { void bmInitMsgHandle(SMgmtWrapper *pWrapper) {
dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE);
} }
...@@ -16,70 +16,25 @@ ...@@ -16,70 +16,25 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "bmInt.h" #include "bmInt.h"
static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); }
static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) {
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
msgCb.pWrapper = pMgmt->pWrapper;
pOption->msgCb = msgCb; pOption->msgCb = msgCb;
} }
static int32_t bmOpenImp(SBnodeMgmt *pMgmt) { static void bmClose(SMgmtWrapper *pWrapper) {
SBnodeOpt option = {0}; SBnodeMgmt *pMgmt = pWrapper->pMgmt;
bmInitOption(pMgmt, &option); if (pMgmt == NULL) return;
pMgmt->pBnode = bndOpen(pMgmt->path, &option);
if (pMgmt->pBnode == NULL) {
dError("failed to open bnode since %s", terrstr());
return -1;
}
if (bmStartWorker(pMgmt) != 0) {
dError("failed to start bnode worker since %s", terrstr());
return -1;
}
bool deployed = true;
if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) {
dError("failed to write bnode file since %s", terrstr());
return -1;
}
return 0;
}
static void bmCloseImp(SBnodeMgmt *pMgmt) { dInfo("bnode-mgmt start to cleanup");
if (pMgmt->pBnode != NULL) { if (pMgmt->pBnode != NULL) {
bmStopWorker(pMgmt); bmStopWorker(pMgmt);
bndClose(pMgmt->pBnode); bndClose(pMgmt->pBnode);
pMgmt->pBnode = NULL; pMgmt->pBnode = NULL;
} }
}
int32_t bmDrop(SMgmtWrapper *pWrapper) {
SBnodeMgmt *pMgmt = pWrapper->pMgmt;
if (pMgmt == NULL) return 0;
dInfo("bnode-mgmt start to drop");
bool deployed = false;
if (dndWriteFile(pWrapper, deployed) != 0) {
dError("failed to drop bnode since %s", terrstr());
return -1;
}
bmCloseImp(pMgmt);
taosRemoveDir(pMgmt->path);
pWrapper->pMgmt = NULL;
taosMemoryFree(pMgmt);
dInfo("bnode-mgmt is dropped");
return 0;
}
static void bmClose(SMgmtWrapper *pWrapper) {
SBnodeMgmt *pMgmt = pWrapper->pMgmt;
if (pMgmt == NULL) return;
dInfo("bnode-mgmt start to cleanup");
bmCloseImp(pMgmt);
pWrapper->pMgmt = NULL; pWrapper->pMgmt = NULL;
taosMemoryFree(pMgmt); taosMemoryFree(pMgmt);
dInfo("bnode-mgmt is cleaned up"); dInfo("bnode-mgmt is cleaned up");
...@@ -98,23 +53,30 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) { ...@@ -98,23 +53,30 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) {
pMgmt->pWrapper = pWrapper; pMgmt->pWrapper = pWrapper;
pWrapper->pMgmt = pMgmt; pWrapper->pMgmt = pMgmt;
int32_t code = bmOpenImp(pMgmt); SBnodeOpt option = {0};
if (code != 0) { bmInitOption(pMgmt, &option);
dError("failed to init bnode-mgmt since %s", terrstr()); pMgmt->pBnode = bndOpen(pMgmt->path, &option);
if (pMgmt->pBnode == NULL) {
dError("failed to open bnode since %s", terrstr());
bmClose(pWrapper); bmClose(pWrapper);
} else { return -1;
dInfo("bnode-mgmt is initialized");
} }
return code; if (bmStartWorker(pMgmt) != 0) {
dError("failed to start bnode worker since %s", terrstr());
bmClose(pWrapper);
return -1;
}
return 0;
} }
void bmSetMgmtFp(SMgmtWrapper *pWrapper) { void bmSetMgmtFp(SMgmtWrapper *pWrapper) {
SMgmtFp mgmtFp = {0}; SMgmtFp mgmtFp = {0};
mgmtFp.openFp = bmOpen; mgmtFp.openFp = bmOpen;
mgmtFp.closeFp = bmClose; mgmtFp.closeFp = bmClose;
mgmtFp.createMsgFp = bmProcessCreateReq; mgmtFp.createFp = bmProcessCreateReq;
mgmtFp.dropMsgFp = bmProcessDropReq; mgmtFp.dropFp = bmProcessDropReq;
mgmtFp.requiredFp = bmRequire; mgmtFp.requiredFp = bmRequire;
bmInitMsgHandle(pWrapper); bmInitMsgHandle(pWrapper);
......
aux_source_directory(src MGMT_MNODE)
add_library(mgmt_mnode STATIC ${MGMT_MNODE})
target_include_directories(
mgmt_mnode
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
mgmt_mnode dnode_interface
)
\ No newline at end of file
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#ifndef _TD_DND_MNODE_INT_H_ #ifndef _TD_DND_MNODE_INT_H_
#define _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_
#include "dndInt.h" #include "dmInt.h"
#include "mnode.h" #include "mnode.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -40,11 +41,9 @@ typedef struct SMnodeMgmt { ...@@ -40,11 +41,9 @@ typedef struct SMnodeMgmt {
// mmFile.c // mmFile.c
int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed); int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed);
int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed); int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed);
// mmInt.c // mmInt.c
int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq);
int32_t mmDrop(SMgmtWrapper *pWrapper);
int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq); int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq);
// mmHandle.c // mmHandle.c
......
...@@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) { ...@@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) {
snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP); snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
dDebug("file %s not exist", file); // dDebug("file %s not exist", file);
code = 0; code = 0;
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
...@@ -105,9 +105,11 @@ PRASE_MNODE_OVER: ...@@ -105,9 +105,11 @@ PRASE_MNODE_OVER:
return code; return code;
} }
int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed) {
char file[PATH_MAX]; char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP); char realfile[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%smnode.json.bak", pWrapper->path, TD_DIRSEP);
snprintf(realfile, sizeof(realfile), "%s%smnode.json", pWrapper->path, TD_DIRSEP);
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
...@@ -121,19 +123,28 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { ...@@ -121,19 +123,28 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
char *content = taosMemoryCalloc(1, maxLen + 1); char *content = taosMemoryCalloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", deployed);
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
for (int32_t i = 0; i < pMgmt->replica; ++i) {
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
if (pReq != NULL || pMgmt != NULL) {
int8_t replica = (pReq != NULL ? pReq->replica : pMgmt->replica);
for (int32_t i = 0; i < replica; ++i) {
SReplica *pReplica = &pMgmt->replicas[i]; SReplica *pReplica = &pMgmt->replicas[i];
if (pReq != NULL) {
pReplica = &pReq->replicas[i];
}
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id);
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
if (i < pMgmt->replica - 1) { if (i < replica - 1) {
len += snprintf(content + len, maxLen - len, " },{\n"); len += snprintf(content + len, maxLen - len, " },{\n");
} else { } else {
len += snprintf(content + len, maxLen - len, " }]\n"); len += snprintf(content + len, maxLen - len, " }],\n");
} }
} }
}
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
len += snprintf(content + len, maxLen - len, "}\n"); len += snprintf(content + len, maxLen - len, "}\n");
taosWriteFile(pFile, content, len); taosWriteFile(pFile, content, len);
...@@ -141,9 +152,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { ...@@ -141,9 +152,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
taosMemoryFree(content); taosMemoryFree(content);
char realfile[PATH_MAX];
snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
if (taosRenameFile(file, realfile) != 0) { if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s since %s", file, terrstr()); dError("failed to rename %s since %s", file, terrstr());
......
aux_source_directory(src MGMT_QNODE)
add_library(mgmt_qnode STATIC ${MGMT_QNODE})
target_include_directories(
mgmt_qnode
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
mgmt_qnode dnode_interface
)
\ No newline at end of file
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#ifndef _TD_DND_QNODE_INT_H_ #ifndef _TD_DND_QNODE_INT_H_
#define _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_
#include "dndInt.h" #include "dmInt.h"
#include "qnode.h" #include "qnode.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -33,10 +34,6 @@ typedef struct SQnodeMgmt { ...@@ -33,10 +34,6 @@ typedef struct SQnodeMgmt {
SSingleWorker monitorWorker; SSingleWorker monitorWorker;
} SQnodeMgmt; } SQnodeMgmt;
// qmInt.c
int32_t qmOpen(SMgmtWrapper *pWrapper);
int32_t qmDrop(SMgmtWrapper *pWrapper);
// qmHandle.c // qmHandle.c
void qmInitMsgHandle(SMgmtWrapper *pWrapper); void qmInitMsgHandle(SMgmtWrapper *pWrapper);
int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
......
aux_source_directory(src MGMT_SNODE)
add_library(mgmt_snode STATIC ${MGMT_SNODE})
target_include_directories(
mgmt_snode
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
mgmt_snode dnode_interface
)
\ No newline at end of file
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#ifndef _TD_DND_SNODE_INT_H_ #ifndef _TD_DND_SNODE_INT_H_
#define _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_
#include "dndInt.h" #include "dmInt.h"
#include "snode.h" #include "snode.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -35,10 +36,6 @@ typedef struct SSnodeMgmt { ...@@ -35,10 +36,6 @@ typedef struct SSnodeMgmt {
SSingleWorker monitorWorker; SSingleWorker monitorWorker;
} SSnodeMgmt; } SSnodeMgmt;
// smInt.c
int32_t smOpen(SMgmtWrapper *pWrapper);
int32_t smDrop(SMgmtWrapper *pWrapper);
// smHandle.c // smHandle.c
void smInitMsgHandle(SMgmtWrapper *pWrapper); void smInitMsgHandle(SMgmtWrapper *pWrapper);
int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册