Merge branch '3.0' of https://github.com/taosdata/TDengine into feature/vnode_refact
This commit is contained in:
commit
0c84f347fe
|
@ -203,11 +203,10 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows);
|
|||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||
|
||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
||||
int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n);
|
||||
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData);
|
||||
|
||||
void blockDebugShowData(const SArray* dataBlocks);
|
||||
|
||||
|
|
|
@ -747,8 +747,8 @@ typedef struct {
|
|||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
int32_t sver; // software version
|
||||
int64_t dver; // dnode table version in sdb
|
||||
int32_t sver; // software version
|
||||
int64_t dnodeVer; // dnode table version in sdb
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
int64_t rebootTime;
|
||||
|
@ -762,6 +762,7 @@ typedef struct {
|
|||
|
||||
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
|
||||
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
|
||||
void tFreeSStatusReq(SStatusReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
|
@ -775,7 +776,7 @@ typedef struct {
|
|||
} SDnodeEp;
|
||||
|
||||
typedef struct {
|
||||
int64_t dver;
|
||||
int64_t dnodeVer;
|
||||
SDnodeCfg dnodeCfg;
|
||||
SArray* pDnodeEps; // Array of SDnodeEp
|
||||
} SStatusRsp;
|
||||
|
|
|
@ -30,12 +30,12 @@ typedef struct SDnode SDnode;
|
|||
*
|
||||
* @return int32_t 0 for success and -1 for failure
|
||||
*/
|
||||
int32_t dndInit();
|
||||
int32_t dmInit();
|
||||
|
||||
/**
|
||||
* @brief Clear the environment
|
||||
*/
|
||||
void dndCleanup();
|
||||
void dmCleanup();
|
||||
|
||||
/* ------------------------ SDnode ----------------------- */
|
||||
typedef struct {
|
||||
|
@ -51,7 +51,7 @@ typedef struct {
|
|||
int8_t ntype;
|
||||
} 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.
|
||||
|
@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
|
|||
* @param pOption Option of the dnode.
|
||||
* @return SDnode* The dnode object.
|
||||
*/
|
||||
SDnode *dndCreate(const SDnodeOpt *pOption);
|
||||
SDnode *dmCreate(const SDnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* @brief Stop and cleanup the dnode.
|
||||
*
|
||||
* @param pDnode The dnode object to close.
|
||||
*/
|
||||
void dndClose(SDnode *pDnode);
|
||||
void dmClose(SDnode *pDnode);
|
||||
|
||||
/**
|
||||
* @brief Run dnode until specific event is receive.
|
||||
*
|
||||
* @param pDnode The dnode object to run.
|
||||
*/
|
||||
int32_t dndRun(SDnode *pDnode);
|
||||
int32_t dmRun(SDnode *pDnode);
|
||||
|
||||
/**
|
||||
* @brief Handle event in the dnode.
|
||||
|
@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode);
|
|||
* @param pDnode The dnode object to close.
|
||||
* @param event The event to handle.
|
||||
*/
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
|
|||
* @param pMnode The mnode object.
|
||||
*/
|
||||
int32_t mndStart(SMnode *pMnode);
|
||||
void mndStop(SMnode *pMnode);
|
||||
|
||||
/**
|
||||
* @brief Get mnode monitor info.
|
||||
|
@ -102,6 +103,12 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha
|
|||
*/
|
||||
int32_t mndProcessMsg(SNodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Generate machine code
|
||||
*
|
||||
*/
|
||||
void mndGenerateMachineCode();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
extern "C" {
|
||||
#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 void *(*ProcMallocFp)(int32_t contLen);
|
||||
typedef void *(*ProcFreeFp)(void *pCont);
|
||||
typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
EProcFuncType ftype);
|
||||
|
||||
typedef struct {
|
||||
ProcConsumeFp childConsumeFp;
|
||||
|
@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc);
|
|||
void taosProcStop(SProcObj *pProc);
|
||||
|
||||
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 taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle));
|
||||
void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
EProcFuncType ftype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -460,14 +460,14 @@ function install_service_on_systemd() {
|
|||
}
|
||||
|
||||
function install_service() {
|
||||
if ((${service_mod}==0)); then
|
||||
install_service_on_systemd
|
||||
elif ((${service_mod}==1)); then
|
||||
install_service_on_sysvinit
|
||||
else
|
||||
# must manual stop taosd
|
||||
# if ((${service_mod}==0)); then
|
||||
# install_service_on_systemd
|
||||
# elif ((${service_mod}==1)); then
|
||||
# install_service_on_sysvinit
|
||||
# else
|
||||
# # must manual stop taosd
|
||||
kill_process taosd
|
||||
fi
|
||||
# fi
|
||||
}
|
||||
|
||||
function install_TDengine() {
|
||||
|
|
|
@ -596,12 +596,15 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
|
|||
pResultInfo->row[i] = varDataVal(pStart);
|
||||
} else {
|
||||
pResultInfo->row[i] = NULL;
|
||||
pResultInfo->length[i] = 0;
|
||||
}
|
||||
} else {
|
||||
if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) {
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current;
|
||||
pResultInfo->length[i] = bytes;
|
||||
} else {
|
||||
pResultInfo->row[i] = NULL;
|
||||
pResultInfo->length[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -410,7 +410,11 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
|||
}
|
||||
|
||||
SResultColumn *pCol = &pResultInfo->pCol[col];
|
||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||
if (IS_VAR_DATA_TYPE(pResultInfo->fields[col].type)) {
|
||||
return (pCol->offset[row] == -1);
|
||||
} else {
|
||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||
}
|
||||
}
|
||||
|
||||
bool taos_is_update_query(TAOS_RES *res) { return taos_num_fields(res) == 0; }
|
||||
|
@ -463,25 +467,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
doFetchRows(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
|
||||
if (pResultInfo == NULL) return -1;
|
||||
|
||||
|
@ -489,11 +475,24 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
doFetchRows(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
|
|
|
@ -459,11 +459,10 @@ TEST(testCase, create_multiple_tables) {
|
|||
|
||||
taos_free_result(pRes);
|
||||
|
||||
for (int32_t i = 0; i < 25000; ++i) {
|
||||
for (int32_t i = 0; i < 500; i += 2) {
|
||||
char sql[512] = {0};
|
||||
snprintf(sql, tListLen(sql),
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5) t_x_%d using st1 tags(911)", i,
|
||||
(i + 1) * 30, (i + 2) * 40);
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5)", i, i + 1);
|
||||
TAOS_RES* pres = taos_query(pConn, sql);
|
||||
if (taos_errno(pres) != 0) {
|
||||
printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
|
@ -653,6 +652,7 @@ TEST(testCase, projection_query_stables) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST(testCase, agg_query_tables) {
|
||||
|
@ -662,7 +662,7 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "select length('abc') from tu");
|
||||
pRes = taos_query(pConn, "select * from test_block_raw.all_type");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
@ -673,6 +673,10 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
int32_t n = 0;
|
||||
void* data = NULL;
|
||||
int32_t code = taos_fetch_raw_block(pRes, &n, &data);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t* length = taos_fetch_lengths(pRes);
|
||||
|
|
|
@ -1149,10 +1149,11 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
||||
if(pDataBlock == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t numOfCols = pDataBlock->info.numOfCols;
|
||||
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
|
@ -1160,6 +1161,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
|||
|
||||
pBlock->info.numOfCols = numOfCols;
|
||||
pBlock->info.hasVarCol = pDataBlock->info.hasVarCol;
|
||||
pBlock->info.rowSize = pDataBlock->info.rows;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
|
@ -1168,6 +1170,23 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
|||
taosArrayPush(pBlock->pDataBlock, &colInfo);
|
||||
}
|
||||
|
||||
if (copyData) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
|
||||
SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
|
||||
int32_t code = colInfoDataEnsureCapacity(pDst, pDataBlock->info.rows);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
colDataAssign(pDst, pSrc, pDataBlock->info.rows);
|
||||
}
|
||||
|
||||
pBlock->info.rows = pDataBlock->info.rows;
|
||||
pBlock->info.capacity = pDataBlock->info.rows;
|
||||
}
|
||||
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
|||
tsDiskCfgNum = 1;
|
||||
taosAddDataDir(0, pItem->str, 0, 1);
|
||||
tstrncpy(tsDataDir, pItem->str, PATH_MAX);
|
||||
if (taosMkDir(tsDataDir) != 0) {
|
||||
if (taosMulMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
|||
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
|
||||
if (pCfg->level == 0 && pCfg->primary == 1) {
|
||||
tstrncpy(tsDataDir, pCfg->dir, PATH_MAX);
|
||||
if (taosMkDir(tsDataDir) != 0) {
|
||||
if (taosMulMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (taosMkDir(pCfg->dir) != 0) {
|
||||
if (taosMulMkDir(pCfg->dir) != 0) {
|
||||
uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
|
||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
||||
if (taosMkDir(tsTempDir) != 0) {
|
||||
if (taosMulMkDir(tsTempDir) != 0) {
|
||||
uError("failed to create tempDir:%s since %s", tsTempDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -870,7 +870,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
|
||||
// status
|
||||
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 (tEncodeI64(&encoder, pReq->clusterId) < 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) {
|
|||
|
||||
// status
|
||||
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 (tDecodeI64(&decoder, &pReq->clusterId) < 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) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); }
|
||||
|
||||
int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
@ -967,7 +969,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
|||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
|
||||
// status
|
||||
if (tEncodeI64(&encoder, pRsp->dver) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1;
|
||||
|
||||
// dnode cfg
|
||||
if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1;
|
||||
|
@ -998,7 +1000,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
|||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
|
||||
// status
|
||||
if (tDecodeI64(&decoder, &pRsp->dver) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1;
|
||||
|
||||
// cluster cfg
|
||||
if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1;
|
||||
|
|
|
@ -1,29 +1,16 @@
|
|||
aux_source_directory(dm DNODE_SRC)
|
||||
aux_source_directory(qm DNODE_SRC)
|
||||
aux_source_directory(bm DNODE_SRC)
|
||||
aux_source_directory(sm DNODE_SRC)
|
||||
aux_source_directory(vm DNODE_SRC)
|
||||
aux_source_directory(mm DNODE_SRC)
|
||||
aux_source_directory(main DNODE_SRC)
|
||||
add_library(dnode STATIC ${DNODE_SRC})
|
||||
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"
|
||||
)
|
||||
add_subdirectory(interface)
|
||||
add_subdirectory(implement)
|
||||
add_subdirectory(mgmt_bnode)
|
||||
add_subdirectory(mgmt_mnode)
|
||||
add_subdirectory(mgmt_qnode)
|
||||
add_subdirectory(mgmt_snode)
|
||||
add_subdirectory(mgmt_vnode)
|
||||
add_subdirectory(test)
|
||||
|
||||
aux_source_directory(exe EXEC_SRC)
|
||||
add_executable(taosd ${EXEC_SRC})
|
||||
target_include_directories(
|
||||
taosd
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/dnode/mnode/impl/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc"
|
||||
)
|
||||
target_link_libraries(taosd dnode)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -1,216 +0,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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SStatusReq req = {0};
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
req.sver = tsVersion;
|
||||
req.dver = pMgmt->dver;
|
||||
req.dnodeId = pDnode->dnodeId;
|
||||
req.clusterId = pDnode->clusterId;
|
||||
req.rebootTime = pDnode->rebootTime;
|
||||
req.updateTime = pMgmt->updateTime;
|
||||
req.numOfCores = tsNumOfCores;
|
||||
req.numOfSupportVnodes = pDnode->numOfSupportVnodes;
|
||||
tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN);
|
||||
|
||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES);
|
||||
if (pWrapper != NULL) {
|
||||
SMonVloadInfo info = {0};
|
||||
dmGetVnodeLoads(pWrapper, &info);
|
||||
req.pVloads = info.pVloads;
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
taosArrayDestroy(req.pVloads);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
|
||||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pMgmt, &epSet);
|
||||
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) {
|
||||
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;
|
||||
dError("auth rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
dError("config req is received, but not supported yet");
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper != NULL) {
|
||||
dndReleaseWrapper(pWrapper);
|
||||
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper = &pDnode->wrappers[ntype];
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
pWrapper->deployed = false;
|
||||
|
||||
int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
pWrapper->deployed = true;
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
pWrapper->deployed = false;
|
||||
dDebug("node:%s, has been dropped", pWrapper->name);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
switch (pMsg->rpcMsg.msgType) {
|
||||
case TDMT_DND_CREATE_MNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg);
|
||||
case TDMT_DND_DROP_MNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, MNODE, pMsg);
|
||||
case TDMT_DND_CREATE_QNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg);
|
||||
case TDMT_DND_DROP_QNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, QNODE, pMsg);
|
||||
case TDMT_DND_CREATE_SNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg);
|
||||
case TDMT_DND_DROP_SNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, SNODE, pMsg);
|
||||
case TDMT_DND_CREATE_BNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg);
|
||||
case TDMT_DND_DROP_BNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, BNODE, pMsg);
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void dmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
// Requests handled by DNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
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
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -1,171 +0,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/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
|
@ -1,142 +0,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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
static void *dmThreadRoutine(void *param) {
|
||||
SDnodeMgmt *pMgmt = param;
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
int64_t lastStatusTime = taosGetTimestampMs();
|
||||
int64_t lastMonitorTime = lastStatusTime;
|
||||
|
||||
setThreadName("dnode-hb");
|
||||
|
||||
while (true) {
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float statusInterval = (curTime - lastStatusTime) / 1000.0f;
|
||||
if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) {
|
||||
dmSendStatusReq(pMgmt);
|
||||
lastStatusTime = curTime;
|
||||
}
|
||||
|
||||
float monitorInterval = (curTime - lastMonitorTime) / 1000.0f;
|
||||
if (monitorInterval >= tsMonitorInterval) {
|
||||
dmSendMonitorReport(pDnode);
|
||||
lastMonitorTime = curTime;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t dmStartThread(SDnodeMgmt *pMgmt) {
|
||||
pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt);
|
||||
if (pMgmt->threadId == NULL) {
|
||||
dError("failed to init dnode thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
||||
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
dTrace("msg:%p, will be processed in dnode queue", pMsg);
|
||||
|
||||
switch (pRpc->msgType) {
|
||||
case TDMT_DND_CONFIG_DNODE:
|
||||
code = dmProcessConfigReq(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_STATUS_RSP:
|
||||
code = dmProcessStatusRsp(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_AUTH_RSP:
|
||||
code = dmProcessAuthRsp(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_GRANT_RSP:
|
||||
code = dmProcessGrantRsp(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pRpc->msgType & 1u) {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
|
||||
SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt};
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
dDebug("dnode workers are initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopWorker(SDnodeMgmt *pMgmt) {
|
||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->monitorWorker);
|
||||
|
||||
if (pMgmt->threadId != NULL) {
|
||||
taosDestoryThread(pMgmt->threadId);
|
||||
pMgmt->threadId = NULL;
|
||||
}
|
||||
dDebug("dnode workers are closed");
|
||||
}
|
||||
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
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);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
|
@ -14,47 +14,46 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmImp.h"
|
||||
#include "tconfig.h"
|
||||
#include "mndGrant.h"
|
||||
|
||||
static struct {
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
SArray *pArgs; // SConfigPair
|
||||
SDnode *pDnode;
|
||||
EDndType ntype;
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
SArray *pArgs; // SConfigPair
|
||||
SDnode *pDnode;
|
||||
EDndNodeType ntype;
|
||||
} 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);
|
||||
if (pDnode != NULL) {
|
||||
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
||||
dmSetEvent(pDnode, DND_EVENT_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dndStopDnode);
|
||||
taosSetSignal(SIGHUP, dndStopDnode);
|
||||
taosSetSignal(SIGINT, dndStopDnode);
|
||||
taosSetSignal(SIGTSTP, dndStopDnode);
|
||||
taosSetSignal(SIGABRT, dndStopDnode);
|
||||
taosSetSignal(SIGBREAK, dndStopDnode);
|
||||
taosSetSignal(SIGQUIT, dndStopDnode);
|
||||
static void dmSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dmStopDnode);
|
||||
taosSetSignal(SIGHUP, dmStopDnode);
|
||||
taosSetSignal(SIGINT, dmStopDnode);
|
||||
taosSetSignal(SIGTSTP, dmStopDnode);
|
||||
taosSetSignal(SIGABRT, dmStopDnode);
|
||||
taosSetSignal(SIGBREAK, dmStopDnode);
|
||||
taosSetSignal(SIGQUIT, dmStopDnode);
|
||||
|
||||
if (!tsMultiProcess) {
|
||||
} else if (global.ntype == DNODE || global.ntype == NODE_MAX) {
|
||||
} else if (global.ntype == DNODE || global.ntype == NODE_END) {
|
||||
taosIgnSignal(SIGCHLD);
|
||||
} else {
|
||||
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) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
|
@ -73,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
|||
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
global.ntype = atoi(argv[++i]);
|
||||
if (global.ntype <= DNODE || global.ntype > NODE_MAX) {
|
||||
printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1);
|
||||
if (global.ntype <= DNODE || global.ntype > NODE_END) {
|
||||
printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
|
@ -90,11 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndGenerateGrant() {
|
||||
parseGrantParameter();
|
||||
}
|
||||
static void dmGenerateGrant() { mndGenerateMachineCode(); }
|
||||
|
||||
static void dndPrintVersion() {
|
||||
static void dmPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
|
@ -105,12 +102,12 @@ static void dndPrintVersion() {
|
|||
printf("buildInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
static void dndDumpCfg() {
|
||||
static void dmDumpCfg() {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
cfgDumpCfg(pCfg, 0, 1);
|
||||
}
|
||||
|
||||
static SDnodeOpt dndGetOpt() {
|
||||
static SDnodeOpt dmGetOpt() {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
SDnodeOpt option = {0};
|
||||
|
||||
|
@ -127,43 +124,43 @@ static SDnodeOpt dndGetOpt() {
|
|||
return option;
|
||||
}
|
||||
|
||||
static int32_t dndInitLog() {
|
||||
static int32_t dmInitLog() {
|
||||
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);
|
||||
}
|
||||
|
||||
static void dndSetProcInfo(int32_t argc, char **argv) {
|
||||
static void dmSetProcInfo(int32_t argc, char **argv) {
|
||||
taosSetProcPath(argc, argv);
|
||||
if (global.ntype != DNODE && global.ntype != NODE_MAX) {
|
||||
const char *name = dndNodeProcStr(global.ntype);
|
||||
if (global.ntype != DNODE && global.ntype != NODE_END) {
|
||||
const char *name = dmProcName(global.ntype);
|
||||
taosSetProcName(argc, argv, name);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndRunDnode() {
|
||||
if (dndInit() != 0) {
|
||||
static int32_t dmRunDnode() {
|
||||
if (dmInit() != 0) {
|
||||
dError("failed to init environment since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeOpt option = dndGetOpt();
|
||||
SDnode *pDnode = dndCreate(&option);
|
||||
SDnodeOpt option = dmGetOpt();
|
||||
SDnode *pDnode = dmCreate(&option);
|
||||
if (pDnode == NULL) {
|
||||
dError("failed to to create dnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
global.pDnode = pDnode;
|
||||
dndSetSignalHandle();
|
||||
dmSetSignalHandle();
|
||||
}
|
||||
|
||||
dInfo("start the service");
|
||||
int32_t code = dndRun(pDnode);
|
||||
int32_t code = dmRun(pDnode);
|
||||
dInfo("start shutting down the service");
|
||||
|
||||
global.pDnode = NULL;
|
||||
dndClose(pDnode);
|
||||
dndCleanup();
|
||||
dmClose(pDnode);
|
||||
dmCleanup();
|
||||
taosCloseLog();
|
||||
taosCleanupCfg();
|
||||
return code;
|
||||
|
@ -175,22 +172,22 @@ int main(int argc, char const *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndParseArgs(argc, argv) != 0) {
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
printf("failed to start since parse args error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (global.generateGrant) {
|
||||
dndGenerateGrant();
|
||||
dmGenerateGrant();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (global.printVersion) {
|
||||
dndPrintVersion();
|
||||
dmPrintVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dndInitLog() != 0) {
|
||||
if (dmInitLog() != 0) {
|
||||
printf("failed to start since init log error\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -201,12 +198,12 @@ int main(int argc, char const *argv[]) {
|
|||
}
|
||||
|
||||
if (global.dumpConfig) {
|
||||
dndDumpCfg();
|
||||
dmDumpCfg();
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
dndSetProcInfo(argc, (char **)argv);
|
||||
return dndRunDnode();
|
||||
dmSetProcInfo(argc, (char **)argv);
|
||||
return dmRunDnode();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
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 ()
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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_*/
|
|
@ -14,32 +14,50 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
static void dmPrintDnodes(SDnodeMgmt *pMgmt);
|
||||
static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep);
|
||||
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps);
|
||||
static void dmPrintEps(SDnode *pDnode);
|
||||
static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep);
|
||||
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 len = 0;
|
||||
int32_t maxLen = 256 * 1024;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
char file[PATH_MAX];
|
||||
char file[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
pMgmt->dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
||||
if (pMgmt->dnodeEps == NULL) {
|
||||
pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
||||
if (pDnode->data.dnodeEps == NULL) {
|
||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||
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);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
@ -62,21 +80,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
|||
dError("failed to read %s since dnodeId not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->dnodeId = dnodeId->valueint;
|
||||
pDnode->data.dnodeId = dnodeId->valueint;
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->clusterId = atoll(clusterId->valuestring);
|
||||
pDnode->data.clusterId = atoll(clusterId->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->dropped = dropped->valueint;
|
||||
pDnode->data.dropped = dropped->valueint;
|
||||
|
||||
cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes");
|
||||
if (!dnodes || dnodes->type != cJSON_Array) {
|
||||
|
@ -126,41 +144,41 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
dnodeEp.isMnode = isMnode->valueint;
|
||||
|
||||
taosArrayPush(pMgmt->dnodeEps, &dnodeEp);
|
||||
taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dDebug("succcessed to read file %s", file);
|
||||
dmPrintDnodes(pMgmt);
|
||||
dmPrintEps(pDnode);
|
||||
|
||||
PRASE_DNODE_OVER:
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (dmIsEpChanged(pMgmt, pDnode->dnodeId, pDnode->localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->localEp, file);
|
||||
if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pMgmt->dnodeEps) == 0) {
|
||||
if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) {
|
||||
SDnodeEp dnodeEp = {0};
|
||||
dnodeEp.isMnode = 1;
|
||||
taosGetFqdnPortFromEp(pDnode->firstEp, &dnodeEp.ep);
|
||||
taosArrayPush(pMgmt->dnodeEps, &dnodeEp);
|
||||
taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep);
|
||||
taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
dmResetDnodes(pMgmt, pMgmt->dnodeEps);
|
||||
dmResetEps(pDnode, pDnode->data.dnodeEps);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
int32_t dmWriteEps(SDnode *pDnode) {
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->wrappers[DNODE].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);
|
||||
if (pFile == NULL) {
|
||||
|
@ -174,14 +192,14 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
|||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->data.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->data.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped);
|
||||
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) {
|
||||
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, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port);
|
||||
|
@ -199,50 +217,47 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
|||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMgmt->updateTime = taosGetTimestampMs();
|
||||
pDnode->data.updateTime = taosGetTimestampMs();
|
||||
dDebug("successed to write %s", realfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
||||
int32_t numOfEps = taosArrayGetSize(dnodeEps);
|
||||
void dmUpdateEps(SDnode *pDnode, SArray *eps) {
|
||||
int32_t numOfEps = taosArrayGetSize(eps);
|
||||
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) {
|
||||
dmResetDnodes(pMgmt, dnodeEps);
|
||||
dmWriteFile(pMgmt);
|
||||
dmResetEps(pDnode, eps);
|
||||
dmWriteEps(pDnode);
|
||||
} else {
|
||||
int32_t size = numOfEps * sizeof(SDnodeEp);
|
||||
if (memcmp(pMgmt->dnodeEps->pData, dnodeEps->pData, size) != 0) {
|
||||
dmResetDnodes(pMgmt, dnodeEps);
|
||||
dmWriteFile(pMgmt);
|
||||
if (memcmp(pDnode->data.dnodeEps->pData, eps->pData, size) != 0) {
|
||||
dmResetEps(pDnode, eps);
|
||||
dmWriteEps(pDnode);
|
||||
}
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
||||
if (pMgmt->dnodeEps != dnodeEps) {
|
||||
SArray *tmp = pMgmt->dnodeEps;
|
||||
pMgmt->dnodeEps = taosArrayDup(dnodeEps);
|
||||
static void dmResetEps(SDnode *pDnode, SArray *dnodeEps) {
|
||||
if (pDnode->data.dnodeEps != dnodeEps) {
|
||||
SArray *tmp = pDnode->data.dnodeEps;
|
||||
pDnode->data.dnodeEps = taosArrayDup(dnodeEps);
|
||||
taosArrayDestroy(tmp);
|
||||
}
|
||||
|
||||
pMgmt->mnodeEpSet.inUse = 0;
|
||||
pMgmt->mnodeEpSet.numOfEps = 0;
|
||||
pDnode->data.mnodeEps.inUse = 0;
|
||||
pDnode->data.mnodeEps.numOfEps = 0;
|
||||
|
||||
int32_t mIndex = 0;
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps);
|
||||
|
@ -251,40 +266,40 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
|||
SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i);
|
||||
if (!pDnodeEp->isMnode) 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++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfEps; 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) {
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps);
|
||||
static void dmPrintEps(SDnode *pDnode) {
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
|
||||
dDebug("print dnode ep list, num:%d", numOfEps);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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) {
|
||||
char epstr[TSDB_EP_LEN + 1];
|
||||
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
|
||||
changed = strcmp(ep, epstr) != 0;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
return changed;
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* 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 bool dmRequireNode(SMgmtWrapper *pWrapper) {
|
||||
bool required = false;
|
||||
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
if (!required) {
|
||||
dDebug("node:%s, does not require startup", pWrapper->name);
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) {
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (pWrapper->ntype == VNODE) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (pWrapper->ntype == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (pWrapper->ntype == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (pWrapper->ntype == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (pWrapper->ntype == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dmGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = DND_PROC_PARENT;
|
||||
pWrapper->procObj = taosProcInit(&cfg);
|
||||
if (pWrapper->procObj == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
args[1] = "-c";
|
||||
args[2] = configDir;
|
||||
args[3] = "-n";
|
||||
args[4] = tstr;
|
||||
args[5] = NULL;
|
||||
|
||||
int32_t pid = taosNewProc(args);
|
||||
if (pid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->procId = pid;
|
||||
dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->ntype == NODE_END) {
|
||||
dInfo("node:%s, should be started manually in child process", pWrapper->name);
|
||||
} else {
|
||||
if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (taosProcRun(pWrapper->procObj) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType == DND_PROC_SINGLE || pWrapper->procType == DND_PROC_CHILD) {
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
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);
|
||||
pWrapper->deployed = true;
|
||||
} else {
|
||||
if (dmInitParentProc(pWrapper) != 0) return -1;
|
||||
if (dmWriteShmFile(pWrapper) != 0) return -1;
|
||||
if (dmRunParentProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dInfo("node:%s, not start in parent process", pWrapper->name);
|
||||
} else if (pWrapper->procType == DND_PROC_CHILD) {
|
||||
dInfo("node:%s, start in child process", pWrapper->name);
|
||||
if (pWrapper->ntype != DNODE) {
|
||||
if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
void dmStopNode(SMgmtWrapper *pWrapper) {
|
||||
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;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCleanup(pWrapper->procObj);
|
||||
pWrapper->procObj = NULL;
|
||||
}
|
||||
|
||||
dInfo("node:%s, has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||
if (pDnode->ptype == DND_PROC_CHILD) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
pWrapper->required = dmRequireNode(pWrapper);
|
||||
if (!pWrapper->required) {
|
||||
dError("dnode:%s, failed to open since not required", pWrapper->name);
|
||||
}
|
||||
|
||||
pWrapper->procType = DND_PROC_CHILD;
|
||||
|
||||
SMsgCb msgCb = pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pWrapper;
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
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];
|
||||
pWrapper->required = dmRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (pDnode->ptype == DND_PROC_PARENT && n != DNODE) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dmSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmStartNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dmStartNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dmReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmStopNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dmStopNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmCloseNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dmCloseNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmProcessProcHandle(void *handle) {
|
||||
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 void dmWatchNodes(SDnode *pDnode) {
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
if (pDnode->ptype == DND_PROC_PARENT) {
|
||||
for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->procType != DND_PROC_PARENT) continue;
|
||||
if (pDnode->ntype == NODE_END) continue;
|
||||
|
||||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle);
|
||||
}
|
||||
dmNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
}
|
||||
|
||||
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];
|
||||
dInfo("%s run in child process", pWrapper->name);
|
||||
}
|
||||
|
||||
if (dmOpenNodes(pDnode) != 0) {
|
||||
dError("failed to open nodes since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmStartNodes(pDnode) != 0) {
|
||||
dError("failed to start nodes since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
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;
|
||||
} else {
|
||||
dmWatchNodes(pDnode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* 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 void dmUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||
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};
|
||||
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
req.sver = tsVersion;
|
||||
req.dnodeVer = pDnode->data.dnodeVer;
|
||||
req.dnodeId = pDnode->data.dnodeId;
|
||||
req.clusterId = pDnode->data.clusterId;
|
||||
req.rebootTime = pDnode->data.rebootTime;
|
||||
req.updateTime = pDnode->data.updateTime;
|
||||
req.numOfCores = tsNumOfCores;
|
||||
req.numOfSupportVnodes = pDnode->data.supportVnodes;
|
||||
tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN);
|
||||
|
||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
|
||||
SMonVloadInfo info = {0};
|
||||
dmGetVnodeLoads(pDnode, &info);
|
||||
req.pVloads = info.pVloads;
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
tFreeSStatusReq(&req);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
|
||||
dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
dmProcessStatusRsp(pDnode, &rpcRsp);
|
||||
}
|
||||
|
||||
int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("auth rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
dError("config req is received, but not supported yet");
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper != NULL) {
|
||||
dmReleaseWrapper(pWrapper);
|
||||
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
pWrapper = &pDnode->wrappers[ntype];
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been created", pWrapper->name);
|
||||
pWrapper->required = true;
|
||||
pWrapper->deployed = true;
|
||||
pWrapper->procType = pDnode->ptype;
|
||||
(void)dmOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
|
||||
int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been dropped", pWrapper->name);
|
||||
}
|
||||
|
||||
dmReleaseWrapper(pWrapper);
|
||||
|
||||
if (code == 0) {
|
||||
dmCloseNode(pWrapper);
|
||||
pWrapper->required = false;
|
||||
pWrapper->deployed = false;
|
||||
taosRemoveDir(pWrapper->path);
|
||||
}
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
// Requests handled by DNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
}
|
||||
|
||||
static int32_t dmStartMgmt(SMgmtWrapper *pWrapper) {
|
||||
if (dmStartStatusThread(pWrapper->pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (dmStartMonitorThread(pWrapper->pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmStopMgmt(SMgmtWrapper *pWrapper) {
|
||||
dmStopMonitorThread(pWrapper->pDnode);
|
||||
dmStopStatusThread(pWrapper->pDnode);
|
||||
}
|
||||
|
||||
static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
|
||||
dInfo("dnode-mgmt start to init");
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
|
||||
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 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
|
||||
pInfo->protocol = 1;
|
||||
pInfo->dnode_id = pDnode->dnodeId;
|
||||
pInfo->cluster_id = pDnode->clusterId;
|
||||
pInfo->dnode_id = pDnode->data.dnodeId;
|
||||
pInfo->cluster_id = pDnode->data.clusterId;
|
||||
tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
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_qnode = pDnode->wrappers[QNODE].required;
|
||||
pInfo->has_snode = pDnode->wrappers[SNODE].required;
|
||||
|
@ -55,7 +55,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
SRpcMsg req = {0};
|
||||
SRpcMsg rsp;
|
||||
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;
|
||||
|
||||
SMgmtWrapper *pWrapper = NULL;
|
||||
|
@ -64,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
bool getFromAPI = !tsMultiProcess;
|
||||
pWrapper = &pDnode->wrappers[MNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_MM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo);
|
||||
}
|
||||
|
@ -79,16 +79,16 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
pWrapper = &pDnode->wrappers[VNODES];
|
||||
pWrapper = &pDnode->wrappers[VNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
vmGetMonitorInfo(pWrapper, &vmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_VM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo);
|
||||
}
|
||||
|
@ -98,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[QNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
qmGetMonitorInfo(pWrapper, &qmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_QM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo);
|
||||
}
|
||||
|
@ -115,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[SNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
smGetMonitorInfo(pWrapper, &smInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_SM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo);
|
||||
}
|
||||
|
@ -132,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[BNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
bmGetMonitorInfo(pWrapper, &bmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_BM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo);
|
||||
}
|
||||
|
@ -161,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
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;
|
||||
if (getFromAPI) {
|
||||
vmGetVnodeLoads(pWrapper, pInfo);
|
||||
|
@ -169,26 +172,14 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) {
|
|||
SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD};
|
||||
SRpcMsg rsp = {0};
|
||||
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;
|
||||
|
||||
dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo);
|
||||
}
|
||||
rpcFreeCont(rsp.pCont);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* 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,18 +14,31 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
#define INTERNAL_USER "_dnd"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_SECRET "_pwd"
|
||||
|
||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE];
|
||||
dmUpdateMnodeEpSet(pWrapper->pMgmt, pEpSet);
|
||||
static void dmGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
*pEpSet = pDnode->data.mnodeEps;
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
||||
static void dmSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse);
|
||||
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
pDnode->data.mnodeEps = *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(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static inline NodeMsgFp dmGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
if (msgFp == NULL) {
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
|
@ -34,7 +47,7 @@ static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
|||
return msgFp;
|
||||
}
|
||||
|
||||
static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
||||
static inline int32_t dmBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if ((pRpc->msgType & 1U) && rpcGetConnInfo(pRpc->handle, &connInfo) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
|
@ -49,28 +62,29 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
int32_t code = -1;
|
||||
SNodeMsg *pMsg = NULL;
|
||||
NodeMsgFp msgFp = NULL;
|
||||
uint16_t msgType = pRpc->msgType;
|
||||
uint16_t msgType = pRpc->msgType;
|
||||
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
dmSetMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
}
|
||||
|
||||
if (dndMarkWrapper(pWrapper) != 0) goto _OVER;
|
||||
if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER;
|
||||
if (dmMarkWrapper(pWrapper) != 0) goto _OVER;
|
||||
if ((msgFp = dmGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER;
|
||||
if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER;
|
||||
if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
|
||||
if (pWrapper->procType == PROC_SINGLE) {
|
||||
dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
if (pWrapper->procType == DND_PROC_SINGLE) {
|
||||
dTrace("msg:%p, is created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user);
|
||||
code = (*msgFp)(pWrapper, pMsg);
|
||||
} else if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle,
|
||||
PROC_REQ);
|
||||
} else if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and put into child queue, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType),
|
||||
pRpc->handle, pMsg->user);
|
||||
code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle,
|
||||
PROC_FUNC_REQ);
|
||||
} else {
|
||||
dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
ASSERT(1);
|
||||
|
@ -78,13 +92,13 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS
|
|||
|
||||
_OVER:
|
||||
if (code == 0) {
|
||||
if (pWrapper->procType == PROC_PARENT) {
|
||||
if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dTrace("msg:%p, is freed in parent process", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
}
|
||||
} else {
|
||||
dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr());
|
||||
dError("msg:%p, type:%s failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), code & 0XFFFF, terrstr());
|
||||
if (msgType & 1U) {
|
||||
if (terrno != 0) code = terrno;
|
||||
if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) {
|
||||
|
@ -101,23 +115,23 @@ _OVER:
|
|||
rpcFreeCont(pRpc->pCont);
|
||||
}
|
||||
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
||||
static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
bool isReq = msgType & 1u;
|
||||
SMsgHandle *pHandle = &pMgmt->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMgmtWrapper *pWrapper = pHandle->pWrapper;
|
||||
SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMgmtWrapper *pWrapper = pHandle->pNdWrapper;
|
||||
|
||||
if (msgType == TDMT_DND_NETWORK_TEST) {
|
||||
dTrace("network test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
dmProcessStartupReq(pDnode, pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING) {
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
dError("msg:%s ignored since dnode not running, handle:%p app:%p", TMSG_INFO(msgType), pMsg->handle, pMsg->ahandle);
|
||||
if (isReq) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY, .ahandle = pMsg->ahandle};
|
||||
|
@ -141,6 +155,7 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pHandle->pMndWrapper != NULL || pHandle->pQndWrapper != NULL) {
|
||||
|
@ -155,17 +170,215 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
}
|
||||
|
||||
dTrace("msg:%s will be processed by %s, app:%p", TMSG_INFO(msgType), pWrapper->name, pMsg->ahandle);
|
||||
dndProcessRpcMsg(pWrapper, pMsg, pEpSet);
|
||||
dmProcessRpcMsg(pWrapper, pMsg, pEpSet);
|
||||
}
|
||||
|
||||
static int32_t dndInitClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
int32_t dmInitMsgHandle(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
|
||||
for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[msgIndex];
|
||||
int8_t vgId = pWrapper->msgVgIds[msgIndex];
|
||||
if (msgFp == NULL) continue;
|
||||
|
||||
SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex];
|
||||
if (vgId == QNODE_HANDLE) {
|
||||
if (pHandle->pQndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pQndWrapper = pWrapper;
|
||||
} else if (vgId == MNODE_HANDLE) {
|
||||
if (pHandle->pMndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pMndWrapper = pWrapper;
|
||||
} else {
|
||||
if (pHandle->pNdWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pNdWrapper = pWrapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int32_t dmSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pDnode->trans.clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) {
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pDnode, &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->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.eps[i].port = htons(epSet.eps[i].port);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pReq->handle, &epSet);
|
||||
}
|
||||
|
||||
static inline void dmSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_NODE_REDIRECT) {
|
||||
dmSendRpcRedirectRsp(pDnode, pRsp);
|
||||
} else {
|
||||
rpcSendResponse(pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pDnode, &epSet);
|
||||
rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
static inline int32_t dmSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pWrapper->pDnode->status != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
return dmSendRpcReq(pWrapper->pDnode, pEpSet, pReq);
|
||||
} else {
|
||||
char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet));
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pHead, pReq, sizeof(SRpcMsg));
|
||||
memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet));
|
||||
taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen,
|
||||
PROC_FUNC_REQ);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
dmSendRpcRsp(pWrapper->pDnode, pRsp);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_FUNC_RSP);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_FUNC_REGIST);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
rpcReleaseHandle(handle, type);
|
||||
} else {
|
||||
SRpcMsg msg = {.handle = handle, .code = type};
|
||||
taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_FUNC_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
EProcFuncType ftype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
pRpc->pCont = pCont;
|
||||
dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle);
|
||||
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
int32_t code = (*msgFp)(pWrapper, pMsg);
|
||||
|
||||
if (code != 0) {
|
||||
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
if (pRpc->msgType & 1U) {
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
||||
dmSendRsp(pWrapper, &rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
EProcFuncType ftype) {
|
||||
pMsg->pCont = pCont;
|
||||
dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle,
|
||||
pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle);
|
||||
|
||||
switch (ftype) {
|
||||
case PROC_FUNC_REGIST:
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
break;
|
||||
case PROC_FUNC_RELEASE:
|
||||
taosProcRemoveHandle(pWrapper->procObj, pMsg->handle);
|
||||
rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code);
|
||||
rpcFreeCont(pCont);
|
||||
break;
|
||||
case PROC_FUNC_REQ:
|
||||
dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
break;
|
||||
case PROC_FUNC_RSP:
|
||||
taosProcRemoveHandle(pWrapper->procObj, pMsg->handle);
|
||||
dmSendRpcRsp(pWrapper->pDnode, pMsg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
taosMemoryFree(pMsg);
|
||||
}
|
||||
|
||||
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->procShm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static int32_t dmInitClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = (RpcCfp)dndProcessMsg;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessMsg;
|
||||
rpcInit.sessions = 1024;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
|
@ -178,8 +391,8 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
rpcInit.secret = pass;
|
||||
|
||||
pMgmt->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
pTrans->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->clientRpc == NULL) {
|
||||
dError("failed to init dnode rpc client");
|
||||
return -1;
|
||||
}
|
||||
|
@ -188,24 +401,17 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
if (pMgmt->clientRpc) {
|
||||
rpcClose(pMgmt->clientRpc);
|
||||
pMgmt->clientRpc = NULL;
|
||||
static void dmCleanupClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->clientRpc) {
|
||||
rpcClose(pTrans->clientRpc);
|
||||
pTrans->clientRpc = NULL;
|
||||
dDebug("dnode rpc client is closed");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
SEpSet epSet = {0};
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE];
|
||||
dmGetMnodeEpSet(pWrapper->pMgmt, &epSet);
|
||||
rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
static inline int32_t dmGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
int32_t code = 0;
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
|
||||
|
@ -227,8 +433,9 @@ static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (dndGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
if (dmGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||
return 0;
|
||||
}
|
||||
|
@ -242,7 +449,7 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch
|
|||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, authReq.spi, authReq.encrypt);
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
if (rpcRsp.code != 0) {
|
||||
terrno = rpcRsp.code;
|
||||
|
@ -262,23 +469,22 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch
|
|||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t dndInitServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
static int32_t dmInitServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = pDnode->serverPort;
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.localPort = pDnode->data.serverPort;
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.numOfThreads = tsNumOfRpcThreads;
|
||||
rpcInit.cfp = (RpcCfp)dndProcessMsg;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessMsg;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = (RpcAfp)dndRetrieveUserAuthInfo;
|
||||
rpcInit.afp = (RpcAfp)dmRetrieveUserAuthInfo;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
pMgmt->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->serverRpc == NULL) {
|
||||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->serverRpc == NULL) {
|
||||
dError("failed to init dnode rpc server");
|
||||
return -1;
|
||||
}
|
||||
|
@ -287,209 +493,33 @@ static int32_t dndInitServer(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
if (pMgmt->serverRpc) {
|
||||
rpcClose(pMgmt->serverRpc);
|
||||
pMgmt->serverRpc = NULL;
|
||||
static void dmCleanupServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->serverRpc) {
|
||||
rpcClose(pTrans->serverRpc);
|
||||
pTrans->serverRpc = NULL;
|
||||
dDebug("dnode rpc server is closed");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndInitTrans(SDnode *pDnode) {
|
||||
if (dndInitServer(pDnode) != 0) return -1;
|
||||
if (dndInitClient(pDnode) != 0) return -1;
|
||||
int32_t dmInitTrans(SDnode *pDnode) {
|
||||
if (dmInitServer(pDnode) != 0) return -1;
|
||||
if (dmInitClient(pDnode) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupTrans(SDnode *pDnode) {
|
||||
dndCleanupServer(pDnode);
|
||||
dndCleanupClient(pDnode);
|
||||
void dmCleanupTrans(SDnode *pDnode) {
|
||||
dmCleanupServer(pDnode);
|
||||
dmCleanupClient(pDnode);
|
||||
}
|
||||
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
|
||||
for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[msgIndex];
|
||||
int8_t vgId = pWrapper->msgVgIds[msgIndex];
|
||||
if (msgFp == NULL) continue;
|
||||
|
||||
SMsgHandle *pHandle = &pMgmt->msgHandles[msgIndex];
|
||||
if (vgId == QNODE_HANDLE) {
|
||||
if (pHandle->pQndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pQndWrapper = pWrapper;
|
||||
} else if (vgId == MNODE_HANDLE) {
|
||||
if (pHandle->pMndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pMndWrapper = pWrapper;
|
||||
} else {
|
||||
if (pHandle->pWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pWrapper = pWrapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_NODE_REDIRECT) {
|
||||
dmSendRedirectRsp(pWrapper->pMgmt, pRsp);
|
||||
} else {
|
||||
rpcSendResponse(pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
return dndSendRpcReq(&pWrapper->pDnode->trans, pEpSet, pReq);
|
||||
} else {
|
||||
char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet));
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pHead, pReq, sizeof(SRpcMsg));
|
||||
memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet));
|
||||
taosProcPutToParentQ(pWrapper->pProc, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen,
|
||||
PROC_REQ);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
dndSendRpcRsp(pWrapper, pRsp);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
rpcReleaseHandle(handle, type);
|
||||
} else {
|
||||
SRpcMsg msg = {.handle = handle, .code = type};
|
||||
taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) {
|
||||
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) {
|
||||
SMsgCb msgCb = {
|
||||
.sendReqFp = dmSendReq,
|
||||
.sendRspFp = dmSendRsp,
|
||||
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
|
||||
.releaseHandleFp = dmReleaseHandle,
|
||||
.pWrapper = pWrapper,
|
||||
.sendReqFp = dndSendReq,
|
||||
.sendRspFp = dndSendRsp,
|
||||
.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg,
|
||||
.releaseHandleFp = dndReleaseHandle,
|
||||
};
|
||||
return msgCb;
|
||||
}
|
||||
|
||||
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
ProcFuncType ftype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
pRpc->pCont = pCont;
|
||||
dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle);
|
||||
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
int32_t code = (*msgFp)(pWrapper, pMsg);
|
||||
|
||||
if (code != 0) {
|
||||
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
if (pRpc->msgType & 1U) {
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
||||
dndSendRsp(pWrapper, &rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
ProcFuncType ftype) {
|
||||
pMsg->pCont = pCont;
|
||||
dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle,
|
||||
pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle);
|
||||
|
||||
switch (ftype) {
|
||||
case PROC_REGIST:
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
break;
|
||||
case PROC_RELEASE:
|
||||
taosProcRemoveHandle(pWrapper->pProc, pMsg->handle);
|
||||
rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code);
|
||||
rpcFreeCont(pCont);
|
||||
break;
|
||||
case PROC_REQ:
|
||||
dndSendRpcReq(&pWrapper->pDnode->trans, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
break;
|
||||
case PROC_RSP:
|
||||
taosProcRemoveHandle(pWrapper->pProc, pMsg->handle);
|
||||
dndSendRpcRsp(pWrapper, pMsg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
taosMemoryFree(pMsg);
|
||||
}
|
||||
|
||||
SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->shm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp);
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* 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 void *dmStatusThreadFp(void *param) {
|
||||
SDnode *pDnode = param;
|
||||
int64_t lastTime = taosGetTimestampMs();
|
||||
|
||||
setThreadName("dnode-status");
|
||||
|
||||
while (1) {
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
|
||||
if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsStatusInterval) {
|
||||
dmSendStatusReq(pDnode);
|
||||
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;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsMonitorInterval) {
|
||||
dmSendMonitorReport(pDnode);
|
||||
lastTime = curTime;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t dmStartStatusThread(SDnode *pDnode) {
|
||||
pDnode->data.statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode);
|
||||
if (pDnode->data.statusThreadId == NULL) {
|
||||
dError("failed to init dnode status thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopStatusThread(SDnode *pDnode) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
int32_t code = -1;
|
||||
dTrace("msg:%p, will be processed in dnode-mgmt queue", pMsg);
|
||||
|
||||
switch (pRpc->msgType) {
|
||||
case TDMT_DND_CONFIG_DNODE:
|
||||
code = dmProcessConfigReq(pDnode, pMsg);
|
||||
break;
|
||||
case TDMT_MND_AUTH_RSP:
|
||||
code = dmProcessAuthRsp(pDnode, pMsg);
|
||||
break;
|
||||
case TDMT_MND_GRANT_RSP:
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pRpc->msgType & 1u) {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
int32_t dmStartWorker(SDnode *pDnode) {
|
||||
SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pDnode};
|
||||
if (tSingleWorkerInit(&pDnode->data.mgmtWorker, &cfg) != 0) {
|
||||
dError("failed to start dnode-mgmt worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode workers are initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopWorker(SDnode *pDnode) {
|
||||
tSingleWorkerCleanup(&pDnode->data.mgmtWorker);
|
||||
dDebug("dnode workers are closed");
|
||||
}
|
||||
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SSingleWorker *pWorker = &pWrapper->pDnode->data.mgmtWorker;
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
|
@ -1,71 +0,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_*/
|
|
@ -1,199 +0,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_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_*/
|
|
@ -0,0 +1,10 @@
|
|||
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
|
||||
)
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* 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_*/
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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_INT_H_
|
||||
#define _TD_DM_INT_H_
|
||||
|
||||
#include "dmDef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// dmInt.c
|
||||
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
const char *dmStatName(EDndRunStatus stat);
|
||||
const char *dmLogName(EDndNodeType ntype);
|
||||
const char *dmProcName(EDndNodeType ntype);
|
||||
const char *dmEventName(EDndEvent ev);
|
||||
|
||||
void dmSetStatus(SDnode *pDnode, EDndRunStatus stat);
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event);
|
||||
void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
|
||||
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||
void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
|
||||
|
||||
// dmFile.c
|
||||
int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
||||
int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
||||
int32_t dmReadShmFile(SMgmtWrapper *pWrapper);
|
||||
int32_t dmWriteShmFile(SMgmtWrapper *pWrapper);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DM_INT_H_*/
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DM_LOG_H_
|
||||
#define _TD_DM_LOG_H_
|
||||
|
||||
#include "tlog.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__); }}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DM_LOG_H_*/
|
|
@ -14,12 +14,12 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
#include "wal.h"
|
||||
|
||||
static int8_t once = DND_ENV_INIT;
|
||||
|
||||
int32_t dndInit() {
|
||||
int32_t dmInit() {
|
||||
dDebug("start to init dnode env");
|
||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||
terrno = TSDB_CODE_REPEAT_INIT;
|
||||
|
@ -45,7 +45,7 @@ int32_t dndInit() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanup() {
|
||||
void dmCleanup() {
|
||||
dDebug("start to cleanup dnode env");
|
||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
|
||||
dError("dnode env is already cleaned up");
|
||||
|
@ -57,63 +57,3 @@ void dndCleanup() {
|
|||
taosStopCacheRefreshWorker();
|
||||
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";
|
||||
}
|
||||
}
|
|
@ -14,22 +14,22 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#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;
|
||||
int64_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
cJSON *root = NULL;
|
||||
char file[PATH_MAX];
|
||||
char file[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||
int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||
int32_t code = -1;
|
||||
int32_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -117,7 +117,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
TdFilePtr dndCheckRunning(const char *dataDir) {
|
||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
||||
|
@ -140,18 +140,17 @@ TdFilePtr dndCheckRunning(const char *dataDir) {
|
|||
return pFile;
|
||||
}
|
||||
|
||||
int32_t dndReadShmFile(SDnode *pDnode) {
|
||||
int32_t dmReadShmFile(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = -1;
|
||||
char itemName[24] = {0};
|
||||
char content[MAXLEN + 1] = {0};
|
||||
char file[PATH_MAX] = {0};
|
||||
cJSON *root = 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);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("node:%s, file %s not exist", pWrapper->name, file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -160,44 +159,36 @@ int32_t dndReadShmFile(SDnode *pDnode) {
|
|||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||
snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype));
|
||||
cJSON *shmid = cJSON_GetObjectItem(root, itemName);
|
||||
if (shmid && shmid->type == cJSON_Number) {
|
||||
pDnode->wrappers[ntype].shm.id = shmid->valueint;
|
||||
}
|
||||
cJSON *shmid = cJSON_GetObjectItem(root, "shmid");
|
||||
if (shmid && shmid->type == cJSON_Number) {
|
||||
pWrapper->procShm.id = shmid->valueint;
|
||||
}
|
||||
|
||||
snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype));
|
||||
cJSON *shmsize = cJSON_GetObjectItem(root, itemName);
|
||||
if (shmsize && shmsize->type == cJSON_Number) {
|
||||
pDnode->wrappers[ntype].shm.size = shmsize->valueint;
|
||||
}
|
||||
cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize");
|
||||
if (shmsize && shmsize->type == cJSON_Number) {
|
||||
pWrapper->procShm.size = shmsize->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
for (EDndType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
if (pWrapper->shm.id >= 0) {
|
||||
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||
taosDropShm(&pWrapper->shm);
|
||||
}
|
||||
if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) {
|
||||
if (pWrapper->procShm.id >= 0) {
|
||||
dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
|
||||
taosDropShm(&pWrapper->procShm);
|
||||
}
|
||||
} else {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
if (taosAttachShm(&pWrapper->shm) != 0) {
|
||||
if (taosAttachShm(&pWrapper->procShm) != 0) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
_OVER:
|
||||
|
@ -207,7 +198,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteShmFile(SDnode *pDnode) {
|
||||
int32_t dmWriteShmFile(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = -1;
|
||||
int32_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -215,37 +206,30 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
|
|||
char realfile[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(file, sizeof(file), "%s%sshmfile.bak", pWrapper->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sshmfile", pWrapper->path, TD_DIRSEP);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
len += snprintf(content + len, MAXLEN - len, "{\n");
|
||||
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
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, " \"shmid\":%d,\n", pWrapper->procShm.id);
|
||||
len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pWrapper->procShm.size);
|
||||
len += snprintf(content + len, MAXLEN - len, "}\n");
|
||||
|
||||
if (taosWriteFile(pFile, content, len) != len) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (taosFsyncFile(pFile) != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -253,11 +237,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
|
|||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", realfile);
|
||||
dInfo("node:%s, successed to write %s", pWrapper->name, realfile);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
const char *dmStatName(EDndRunStatus 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 *dmLogName(EDndNodeType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODE:
|
||||
return "vnode";
|
||||
case QNODE:
|
||||
return "qnode";
|
||||
case SNODE:
|
||||
return "snode";
|
||||
case MNODE:
|
||||
return "mnode";
|
||||
case BNODE:
|
||||
return "bnode";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmProcName(EDndNodeType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODE:
|
||||
return "taosv";
|
||||
case QNODE:
|
||||
return "taosq";
|
||||
case SNODE:
|
||||
return "taoss";
|
||||
case MNODE:
|
||||
return "taosm";
|
||||
case BNODE:
|
||||
return "taosb";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmEventName(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";
|
||||
}
|
||||
}
|
||||
|
||||
void dmSetStatus(SDnode *pDnode, EDndRunStatus status) {
|
||||
if (pDnode->status != status) {
|
||||
dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status));
|
||||
pDnode->status = status;
|
||||
}
|
||||
}
|
||||
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event) {
|
||||
if (event == DND_EVENT_STOP) {
|
||||
pDnode->event = event;
|
||||
}
|
||||
}
|
||||
|
||||
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 *pRetWrapper = pWrapper;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
pRetWrapper = NULL;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return pRetWrapper;
|
||||
}
|
||||
|
||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
code = -1;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1);
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount);
|
||||
}
|
||||
|
||||
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
|
||||
SStartupReq *pStartup = &pDnode->startup;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
static void dmGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||
pStartup->finished = (pDnode->status == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
||||
dmGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||
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);
|
||||
}
|
|
@ -1,357 +0,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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
||||
bool required = false;
|
||||
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
if (!required) {
|
||||
dDebug("node:%s, does not require startup", pWrapper->name);
|
||||
} else {
|
||||
dDebug("node:%s, needs to be started", pWrapper->name);
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) {
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (pWrapper->ntype == VNODES) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (pWrapper->ntype == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (pWrapper->ntype == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (pWrapper->ntype == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (pWrapper->ntype == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCreateShm(&pWrapper->shm, pWrapper->ntype, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
args[1] = "-c";
|
||||
args[2] = configDir;
|
||||
args[3] = "-n";
|
||||
args[4] = tstr;
|
||||
args[5] = NULL;
|
||||
|
||||
int32_t pid = taosNewProc(args);
|
||||
if (pid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->procId = pid;
|
||||
dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->ntype == NODE_MAX) {
|
||||
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||
} else {
|
||||
if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) {
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
if (pDnode->procType == PROC_SINGLE) {
|
||||
return dndOpenNodeImp(pWrapper);
|
||||
} else if (pDnode->procType == PROC_PARENT) {
|
||||
if (dndInitNodeProc(pWrapper) != 0) return -1;
|
||||
if (dndWriteShmFile(pDnode) != 0) return -1;
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCloseNodeImp(SMgmtWrapper *pWrapper) {
|
||||
dDebug("node:%s, mgmt start to close", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->pProc) {
|
||||
taosProcCleanup(pWrapper->pProc);
|
||||
pWrapper->pProc = NULL;
|
||||
}
|
||||
dDebug("node:%s, mgmt has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->procType == 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);
|
||||
}
|
||||
}
|
||||
dndCloseNodeImp(pWrapper);
|
||||
}
|
||||
|
||||
static void dndProcessProcHandle(void *handle) {
|
||||
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) {
|
||||
dInfo("dnode run in single process");
|
||||
pDnode->procType = PROC_SINGLE;
|
||||
|
||||
for (EDndType n = DNODE; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->fp.startFp == NULL) continue;
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
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);
|
||||
break;
|
||||
}
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in parent process");
|
||||
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];
|
||||
pWrapper->required = dndRequireNode(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) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
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)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle);
|
||||
dndNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
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);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
pWrapper->procType = PROC_CHILD;
|
||||
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = true;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
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) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("%s is about to stop", pWrapper->name);
|
||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
break;
|
||||
}
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
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 {
|
||||
return dndRunInChildProcess(pDnode);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,229 +0,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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes;
|
||||
pDnode->serverPort = pOption->serverPort;
|
||||
pDnode->dataDir = strdup(pOption->dataDir);
|
||||
pDnode->localEp = strdup(pOption->localEp);
|
||||
pDnode->localFqdn = strdup(pOption->localFqdn);
|
||||
pDnode->firstEp = strdup(pOption->firstEp);
|
||||
pDnode->secondEp = strdup(pOption->secondEp);
|
||||
pDnode->disks = pOption->disks;
|
||||
pDnode->numOfDisks = pOption->numOfDisks;
|
||||
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) {
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||
taosMemoryFreeClear(pMgmt->path);
|
||||
}
|
||||
if (pDnode->lockfile != NULL) {
|
||||
taosUnLockFile(pDnode->lockfile);
|
||||
taosCloseFile(&pDnode->lockfile);
|
||||
pDnode->lockfile = NULL;
|
||||
}
|
||||
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) {
|
||||
dDebug("start to create dnode object");
|
||||
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 (dndInitVars(pDnode, pOption) != 0) {
|
||||
dError("failed to init variables since %s", terrstr());
|
||||
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;
|
||||
taosInitRWLatch(&pWrapper->latch);
|
||||
}
|
||||
|
||||
if (dndInitMsgHandle(pDnode) != 0) {
|
||||
dError("failed to init msg handles since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndReadShmFile(pDnode) != 0) {
|
||||
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) {
|
||||
if (pDnode == NULL) return;
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dndCloseNode(pWrapper);
|
||||
}
|
||||
|
||||
dndClearVars(pDnode);
|
||||
dInfo("dnode is closed, data:%p", pDnode);
|
||||
}
|
||||
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event) {
|
||||
if (event == DND_EVENT_STOP) {
|
||||
pDnode->event = event;
|
||||
}
|
||||
}
|
||||
|
||||
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
SMgmtWrapper *pRetWrapper = pWrapper;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
pRetWrapper = NULL;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return pRetWrapper;
|
||||
}
|
||||
|
||||
int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
code = -1;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dndReleaseWrapper(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1);
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount);
|
||||
}
|
||||
|
||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
|
||||
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;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
||||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
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
|
||||
)
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef _TD_DND_BNODE_INT_H_
|
||||
#define _TD_DND_BNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "bnode.h"
|
||||
|
||||
|
@ -33,10 +33,6 @@ typedef struct SBnodeMgmt {
|
|||
SSingleWorker monitorWorker;
|
||||
} SBnodeMgmt;
|
||||
|
||||
// bmInt.c
|
||||
int32_t bmOpen(SMgmtWrapper *pWrapper);
|
||||
int32_t bmDrop(SMgmtWrapper *pWrapper);
|
||||
|
||||
// bmHandle.c
|
||||
void bmInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
|
@ -53,13 +53,19 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.dnodeId != pDnode->dnodeId) {
|
||||
if (createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
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;
|
||||
} 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) {
|
||||
|
@ -72,16 +78,21 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
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) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -16,70 +16,25 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#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) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
||||
static int32_t bmOpenImp(SBnodeMgmt *pMgmt) {
|
||||
SBnodeOpt option = {0};
|
||||
bmInitOption(pMgmt, &option);
|
||||
|
||||
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) {
|
||||
if (pMgmt->pBnode != NULL) {
|
||||
bmStopWorker(pMgmt);
|
||||
bndClose(pMgmt->pBnode);
|
||||
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);
|
||||
if (pMgmt->pBnode != NULL) {
|
||||
bmStopWorker(pMgmt);
|
||||
bndClose(pMgmt->pBnode);
|
||||
pMgmt->pBnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("bnode-mgmt is cleaned up");
|
||||
|
@ -98,23 +53,30 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = bmOpenImp(pMgmt);
|
||||
if (code != 0) {
|
||||
dError("failed to init bnode-mgmt since %s", terrstr());
|
||||
SBnodeOpt option = {0};
|
||||
bmInitOption(pMgmt, &option);
|
||||
pMgmt->pBnode = bndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pBnode == NULL) {
|
||||
dError("failed to open bnode since %s", terrstr());
|
||||
bmClose(pWrapper);
|
||||
} else {
|
||||
dInfo("bnode-mgmt is initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = bmOpen;
|
||||
mgmtFp.closeFp = bmClose;
|
||||
mgmtFp.createMsgFp = bmProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = bmProcessDropReq;
|
||||
mgmtFp.createFp = bmProcessCreateReq;
|
||||
mgmtFp.dropFp = bmProcessDropReq;
|
||||
mgmtFp.requiredFp = bmRequire;
|
||||
|
||||
bmInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
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
|
||||
)
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TD_DND_MNODE_INT_H_
|
||||
#define _TD_DND_MNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "mnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -40,11 +41,9 @@ typedef struct SMnodeMgmt {
|
|||
|
||||
// mmFile.c
|
||||
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
|
||||
int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq);
|
||||
int32_t mmDrop(SMgmtWrapper *pWrapper);
|
||||
int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq);
|
||||
|
||||
// mmHandle.c
|
|
@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) {
|
|||
snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
@ -105,9 +105,11 @@ PRASE_MNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
||||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed) {
|
||||
char file[PATH_MAX] = {0};
|
||||
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);
|
||||
if (pFile == NULL) {
|
||||
|
@ -119,21 +121,30 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
|||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
|
||||
|
||||
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");
|
||||
for (int32_t i = 0; i < pMgmt->replica; ++i) {
|
||||
SReplica *pReplica = &pMgmt->replicas[i];
|
||||
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, " \"port\": %u\n", pReplica->port);
|
||||
if (i < pMgmt->replica - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
|
||||
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];
|
||||
if (pReq != NULL) {
|
||||
pReplica = &pReq->replicas[i];
|
||||
}
|
||||
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, " \"port\": %u\n", pReplica->port);
|
||||
if (i < replica - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }],\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
taosWriteFile(pFile, content, len);
|
||||
|
@ -141,9 +152,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
|||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s since %s", file, terrstr());
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* 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 "mmInt.h"
|
||||
|
||||
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant);
|
||||
}
|
||||
|
||||
int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) {
|
||||
SMonMmInfo mmInfo = {0};
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dmGetMonitorSysInfo(&mmInfo.sys);
|
||||
monGetLogs(&mmInfo.log);
|
||||
|
||||
int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo);
|
||||
if (rspLen < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo);
|
||||
pReq->pRsp = pRsp;
|
||||
pReq->rspLen = rspLen;
|
||||
tFreeSMonMmInfo(&mmInfo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.replica <= 1 || createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pWrapper, &createReq, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (mmWriteFile(pWrapper, NULL, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alterReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->data.dnodeId, alterReq.dnodeId);
|
||||
return -1;
|
||||
} else {
|
||||
return mmAlter(pMgmt, &alterReq);
|
||||
}
|
||||
}
|
||||
|
||||
void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by DNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
}
|
|
@ -18,9 +18,9 @@
|
|||
#include "wal.h"
|
||||
|
||||
static bool mmDeployRequired(SDnode *pDnode) {
|
||||
if (pDnode->dnodeId > 0) return false;
|
||||
if (pDnode->clusterId > 0) return false;
|
||||
if (strcmp(pDnode->localEp, pDnode->firstEp) != 0) return false;
|
||||
if (pDnode->data.dnodeId > 0) return false;
|
||||
if (pDnode->data.clusterId > 0) return false;
|
||||
if (strcmp(pDnode->data.localEp, pDnode->data.firstEp) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,8 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
|||
}
|
||||
|
||||
static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue;
|
||||
msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue;
|
||||
|
@ -53,8 +54,8 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
|||
pOption->selfIndex = 0;
|
||||
SReplica *pReplica = &pOption->replicas[0];
|
||||
pReplica->id = 1;
|
||||
pReplica->port = pMgmt->pDnode->serverPort;
|
||||
tstrncpy(pReplica->fqdn, pMgmt->pDnode->localFqdn, TSDB_FQDN_LEN);
|
||||
pReplica->port = pMgmt->pDnode->data.serverPort;
|
||||
tstrncpy(pReplica->fqdn, pMgmt->pDnode->data.localFqdn, TSDB_FQDN_LEN);
|
||||
pOption->deploy = true;
|
||||
|
||||
pMgmt->selfIndex = pOption->selfIndex;
|
||||
|
@ -80,7 +81,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre
|
|||
pReplica->id = pCreate->replicas[i].id;
|
||||
pReplica->port = pCreate->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
if (pReplica->id == pMgmt->pDnode->dnodeId) {
|
||||
if (pReplica->id == pMgmt->pDnode->data.dnodeId) {
|
||||
pOption->selfIndex = i;
|
||||
}
|
||||
}
|
||||
|
@ -97,83 +98,22 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) {
|
||||
SMnodeOpt option = {0};
|
||||
if (pReq != NULL) {
|
||||
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
bool deployed = false;
|
||||
if (mmReadFile(pMgmt, &deployed) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!deployed) {
|
||||
dInfo("mnode start to deploy");
|
||||
if (pMgmt->pWrapper->procType == PROC_CHILD) {
|
||||
pMgmt->pDnode->dnodeId = 1;
|
||||
}
|
||||
mmBuildOptionForDeploy(pMgmt, &option);
|
||||
} else {
|
||||
dInfo("mnode start to open");
|
||||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
}
|
||||
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pMgmt, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mmCloseImp(SMnodeMgmt *pMgmt) {
|
||||
if (pMgmt->pMnode != NULL) {
|
||||
mmStopWorker(pMgmt);
|
||||
mndClose(pMgmt->pMnode);
|
||||
pMgmt->pMnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) {
|
||||
SMnodeOpt option = {0};
|
||||
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return mndAlter(pMgmt->pMnode, &option);
|
||||
}
|
||||
|
||||
int32_t mmDrop(SMgmtWrapper *pWrapper) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return 0;
|
||||
|
||||
dInfo("mnode-mgmt start to drop");
|
||||
bool deployed = false;
|
||||
if (mmWriteFile(pMgmt, deployed) != 0) {
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
if (mndAlter(pMgmt->pMnode, &option) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pMgmt->pWrapper, pReq, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmCloseImp(pMgmt);
|
||||
taosRemoveDir(pMgmt->path);
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("mnode-mgmt is dropped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -182,13 +122,18 @@ static void mmClose(SMgmtWrapper *pWrapper) {
|
|||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("mnode-mgmt start to cleanup");
|
||||
mmCloseImp(pMgmt);
|
||||
if (pMgmt->pMnode != NULL) {
|
||||
mmStopWorker(pMgmt);
|
||||
mndClose(pMgmt->pMnode);
|
||||
pMgmt->pMnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("mnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) {
|
||||
static int32_t mmOpen(SMgmtWrapper *pWrapper) {
|
||||
dInfo("mnode-mgmt start to init");
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
|
@ -206,18 +151,49 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = mmOpenImp(pMgmt, pReq);
|
||||
if (code != 0) {
|
||||
dError("failed to init mnode-mgmt since %s", terrstr());
|
||||
bool deployed = false;
|
||||
if (mmReadFile(pMgmt, &deployed) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
} else {
|
||||
dInfo("mnode-mgmt is initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
SMnodeOpt option = {0};
|
||||
if (!deployed) {
|
||||
dInfo("mnode start to deploy");
|
||||
if (pWrapper->procType == DND_PROC_CHILD) {
|
||||
pWrapper->pDnode->data.dnodeId = 1;
|
||||
}
|
||||
mmBuildOptionForDeploy(pMgmt, &option);
|
||||
} else {
|
||||
dInfo("mnode start to open");
|
||||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
|
||||
static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); }
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!deployed) {
|
||||
deployed = true;
|
||||
if (mmWriteFile(pWrapper, NULL, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("mnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mmStart(SMgmtWrapper *pWrapper) {
|
||||
dDebug("mnode-mgmt start to run");
|
||||
|
@ -225,13 +201,22 @@ static int32_t mmStart(SMgmtWrapper *pWrapper) {
|
|||
return mndStart(pMgmt->pMnode);
|
||||
}
|
||||
|
||||
static void mmStop(SMgmtWrapper *pWrapper) {
|
||||
dDebug("mnode-mgmt start to stop");
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt != NULL) {
|
||||
mndStop(pMgmt->pMnode);
|
||||
}
|
||||
}
|
||||
|
||||
void mmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = mmOpen;
|
||||
mgmtFp.closeFp = mmClose;
|
||||
mgmtFp.startFp = mmStart;
|
||||
mgmtFp.createMsgFp = mmProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = mmProcessDropReq;
|
||||
mgmtFp.stopFp = mmStop;
|
||||
mgmtFp.createFp = mmProcessCreateReq;
|
||||
mgmtFp.dropFp = mmProcessDropReq;
|
||||
mgmtFp.requiredFp = mmRequire;
|
||||
|
||||
mmInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
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
|
||||
)
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TD_DND_QNODE_INT_H_
|
||||
#define _TD_DND_QNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "qnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -33,10 +34,6 @@ typedef struct SQnodeMgmt {
|
|||
SSingleWorker monitorWorker;
|
||||
} SQnodeMgmt;
|
||||
|
||||
// qmInt.c
|
||||
int32_t qmOpen(SMgmtWrapper *pWrapper);
|
||||
int32_t qmDrop(SMgmtWrapper *pWrapper);
|
||||
|
||||
// qmHandle.c
|
||||
void qmInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
|
@ -53,13 +53,19 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.dnodeId != pDnode->dnodeId) {
|
||||
if (createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
|
@ -72,27 +78,32 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return qmDrop(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
}
|
|
@ -16,79 +16,34 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "qmInt.h"
|
||||
|
||||
static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); }
|
||||
static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); }
|
||||
|
||||
static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue;
|
||||
msgCb.qsizeFp = qmGetQueueSize;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
||||
static int32_t qmOpenImp(SQnodeMgmt *pMgmt) {
|
||||
SQnodeOpt option = {0};
|
||||
qmInitOption(pMgmt, &option);
|
||||
|
||||
pMgmt->pQnode = qndOpen(&option);
|
||||
if (pMgmt->pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start qnode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void qmCloseImp(SQnodeMgmt *pMgmt) {
|
||||
if (pMgmt->pQnode != NULL) {
|
||||
qmStopWorker(pMgmt);
|
||||
qndClose(pMgmt->pQnode);
|
||||
pMgmt->pQnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t qmDrop(SMgmtWrapper *pWrapper) {
|
||||
SQnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return 0;
|
||||
|
||||
dInfo("qnode-mgmt start to drop");
|
||||
bool deployed = false;
|
||||
if (dndWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
qmCloseImp(pMgmt);
|
||||
taosRemoveDir(pMgmt->path);
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("qnode-mgmt is dropped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void qmClose(SMgmtWrapper *pWrapper) {
|
||||
SQnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("qnode-mgmt start to cleanup");
|
||||
qmCloseImp(pMgmt);
|
||||
if (pMgmt->pQnode != NULL) {
|
||||
qmStopWorker(pMgmt);
|
||||
qndClose(pMgmt->pQnode);
|
||||
pMgmt->pQnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("qnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
int32_t qmOpen(SMgmtWrapper *pWrapper) {
|
||||
static int32_t qmOpen(SMgmtWrapper *pWrapper) {
|
||||
dInfo("qnode-mgmt start to init");
|
||||
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
|
@ -101,23 +56,31 @@ int32_t qmOpen(SMgmtWrapper *pWrapper) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = qmOpenImp(pMgmt);
|
||||
if (code != 0) {
|
||||
dError("failed to init qnode-mgmt since %s", terrstr());
|
||||
SQnodeOpt option = {0};
|
||||
qmInitOption(pMgmt, &option);
|
||||
pMgmt->pQnode = qndOpen(&option);
|
||||
if (pMgmt->pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
qmClose(pWrapper);
|
||||
} else {
|
||||
dInfo("qnode-mgmt is initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return code;
|
||||
if (qmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start qnode worker since %s", terrstr());
|
||||
qmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("qnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = qmOpen;
|
||||
mgmtFp.closeFp = qmClose;
|
||||
mgmtFp.createMsgFp = qmProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = qmProcessDropReq;
|
||||
mgmtFp.createFp = qmProcessCreateReq;
|
||||
mgmtFp.dropFp = qmProcessDropReq;
|
||||
mgmtFp.requiredFp = qmRequire;
|
||||
|
||||
qmInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
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
|
||||
)
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TD_DND_SNODE_INT_H_
|
||||
#define _TD_DND_SNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "snode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -35,10 +36,6 @@ typedef struct SSnodeMgmt {
|
|||
SSingleWorker monitorWorker;
|
||||
} SSnodeMgmt;
|
||||
|
||||
// smInt.c
|
||||
int32_t smOpen(SMgmtWrapper *pWrapper);
|
||||
int32_t smDrop(SMgmtWrapper *pWrapper);
|
||||
|
||||
// smHandle.c
|
||||
void smInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
|
@ -53,13 +53,19 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.dnodeId != pDnode->dnodeId) {
|
||||
if (createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
|
@ -72,20 +78,25 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return smDrop(pWrapper);
|
||||
// return dndCloseNode(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void smInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by SNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -16,70 +16,25 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "smInt.h"
|
||||
|
||||
static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); }
|
||||
static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); }
|
||||
|
||||
static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
||||
static int32_t smOpenImp(SSnodeMgmt *pMgmt) {
|
||||
SSnodeOpt option = {0};
|
||||
smInitOption(pMgmt, &option);
|
||||
|
||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (smStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start snode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void smCloseImp(SSnodeMgmt *pMgmt) {
|
||||
if (pMgmt->pSnode != NULL) {
|
||||
smStopWorker(pMgmt);
|
||||
sndClose(pMgmt->pSnode);
|
||||
pMgmt->pSnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t smDrop(SMgmtWrapper *pWrapper) {
|
||||
SSnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return 0;
|
||||
|
||||
dInfo("snode-mgmt start to drop");
|
||||
bool deployed = false;
|
||||
if (dndWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
smCloseImp(pMgmt);
|
||||
taosRemoveDir(pMgmt->path);
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("snode-mgmt is dropped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void smClose(SMgmtWrapper *pWrapper) {
|
||||
SSnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("snode-mgmt start to cleanup");
|
||||
smCloseImp(pMgmt);
|
||||
if (pMgmt->pSnode != NULL) {
|
||||
smStopWorker(pMgmt);
|
||||
sndClose(pMgmt->pSnode);
|
||||
pMgmt->pSnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("snode-mgmt is cleaned up");
|
||||
|
@ -98,23 +53,28 @@ int32_t smOpen(SMgmtWrapper *pWrapper) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = smOpenImp(pMgmt);
|
||||
if (code != 0) {
|
||||
dError("failed to init snode-mgmt since %s", terrstr());
|
||||
smClose(pWrapper);
|
||||
} else {
|
||||
dInfo("snode-mgmt is initialized");
|
||||
SSnodeOpt option = {0};
|
||||
smInitOption(pMgmt, &option);
|
||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return code;
|
||||
if (smStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start snode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void smSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = smOpen;
|
||||
mgmtFp.closeFp = smClose;
|
||||
mgmtFp.createMsgFp = smProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = smProcessDropReq;
|
||||
mgmtFp.createFp = smProcessCreateReq;
|
||||
mgmtFp.dropFp = smProcessDropReq;
|
||||
mgmtFp.requiredFp = smRequire;
|
||||
|
||||
smInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
aux_source_directory(src MGMT_VNODE)
|
||||
add_library(mgmt_vnode STATIC ${MGMT_VNODE})
|
||||
target_include_directories(
|
||||
mgmt_vnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mgmt_vnode dnode_interface
|
||||
)
|
|
@ -16,8 +16,9 @@
|
|||
#ifndef _TD_DND_VNODES_INT_H_
|
||||
#define _TD_DND_VNODES_INT_H_
|
||||
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "sync.h"
|
||||
#include "dndInt.h"
|
||||
#include "vnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -95,6 +96,7 @@ int32_t vmProcessSyncVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq);
|
|||
int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq);
|
||||
int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq);
|
||||
int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq);
|
||||
void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
|
||||
|
||||
// vmFile.c
|
||||
int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
|
@ -143,7 +143,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue;
|
||||
|
@ -304,52 +304,51 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
void vmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -126,9 +126,9 @@ static void *vmOpenVnodeFunc(void *param) {
|
|||
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pCfg->vgId,
|
||||
pMgmt->state.openVnodes, pMgmt->state.totalVnodes);
|
||||
dndReportStartup(pDnode, "open-vnodes", stepDesc);
|
||||
dmReportStartup(pDnode, "open-vnodes", stepDesc);
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue;
|
||||
|
@ -278,11 +278,11 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
|||
taosInitRWLatch(&pMgmt->latch);
|
||||
|
||||
SDiskCfg dCfg = {0};
|
||||
tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN);
|
||||
tstrncpy(dCfg.dir, pDnode->data.dataDir, TSDB_FILENAME_LEN);
|
||||
dCfg.level = 0;
|
||||
dCfg.primary = 1;
|
||||
SDiskCfg *pDisks = pDnode->disks;
|
||||
int32_t numOfDisks = pDnode->numOfDisks;
|
||||
SDiskCfg *pDisks = pDnode->data.disks;
|
||||
int32_t numOfDisks = pDnode->data.numOfDisks;
|
||||
if (numOfDisks <= 0 || pDisks == NULL) {
|
||||
pDisks = &dCfg;
|
||||
numOfDisks = 1;
|
||||
|
@ -329,7 +329,7 @@ _OVER:
|
|||
|
||||
static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
*required = pDnode->numOfSupportVnodes > 0;
|
||||
*required = pDnode->data.supportVnodes > 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,199 +0,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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mmInt.h"
|
||||
|
||||
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant);
|
||||
}
|
||||
|
||||
int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) {
|
||||
SMonMmInfo mmInfo = {0};
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dmGetMonitorSysInfo(&mmInfo.sys);
|
||||
monGetLogs(&mmInfo.log);
|
||||
|
||||
int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo);
|
||||
if (rspLen < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo);
|
||||
pReq->pRsp = pRsp;
|
||||
pReq->rspLen = rspLen;
|
||||
tFreeSMonMmInfo(&mmInfo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return mmOpenFromMsg(pWrapper, &createReq);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return mmDrop(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alterReq.dnodeId != pDnode->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->dnodeId, alterReq.dnodeId);
|
||||
return -1;
|
||||
} else {
|
||||
return mmAlter(pMgmt, &alterReq);
|
||||
}
|
||||
}
|
||||
|
||||
void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by DNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
enable_testing()
|
||||
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(sut)
|
||||
if(${BUILD_TEST})
|
||||
enable_testing()
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(sut)
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
aux_source_directory(. BQTEST_SRC)
|
||||
add_executable(dbnodeTest ${BQTEST_SRC})
|
||||
aux_source_directory(. DND_BNODE_TEST_SRC)
|
||||
add_executable(dbnodeTest ${DND_BNODE_TEST_SRC})
|
||||
target_link_libraries(
|
||||
dbnodeTest
|
||||
PUBLIC sut
|
||||
dbnodeTest sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
aux_source_directory(. DMTEST_SRC)
|
||||
add_executable(dmnodeTest ${DMTEST_SRC})
|
||||
aux_source_directory(. DND_MNODE_TEST_SRC)
|
||||
add_executable(dmnodeTest ${DND_MNODE_TEST_SRC})
|
||||
target_link_libraries(
|
||||
dmnodeTest
|
||||
PUBLIC sut
|
||||
dmnodeTest sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. DQTEST_SRC)
|
||||
add_executable(dqnodeTest ${DQTEST_SRC})
|
||||
aux_source_directory(. DND_QNODE_TEST_SRC)
|
||||
add_executable(dqnodeTest ${DND_QNODE_TEST_SRC})
|
||||
target_link_libraries(
|
||||
dqnodeTest
|
||||
PUBLIC sut
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. SQTEST_SRC)
|
||||
add_executable(dsnodeTest ${SQTEST_SRC})
|
||||
aux_source_directory(. DND_SNODE_TEST_SRC)
|
||||
add_executable(dsnodeTest ${DND_SNODE_TEST_SRC})
|
||||
target_link_libraries(
|
||||
dsnodeTest
|
||||
PUBLIC sut
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
aux_source_directory(src SUT_SRC)
|
||||
add_library(sut STATIC STATIC ${SUT_SRC})
|
||||
target_link_libraries(
|
||||
sut
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
aux_source_directory(src DND_SUT_SRC)
|
||||
add_library(sut STATIC STATIC ${DND_SUT_SRC})
|
||||
target_include_directories(
|
||||
sut
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
sut dnode gtest_main
|
||||
)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
void* serverLoop(void* param) {
|
||||
SDnode* pDnode = (SDnode*)param;
|
||||
dndRun(pDnode);
|
||||
dmRun(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ bool TestServer::DoStart() {
|
|||
SDnodeOpt option = BuildOption(path, fqdn, port, firstEp);
|
||||
taosMkDir(path);
|
||||
|
||||
pDnode = dndCreate(&option);
|
||||
pDnode = dmCreate(&option);
|
||||
if (pDnode == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
@ -68,11 +68,11 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const
|
|||
}
|
||||
|
||||
void TestServer::Stop() {
|
||||
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
||||
dmSetEvent(pDnode, DND_EVENT_STOP);
|
||||
taosThreadJoin(threadId, NULL);
|
||||
|
||||
if (pDnode != NULL) {
|
||||
dndClose(pDnode);
|
||||
dmClose(pDnode);
|
||||
pDnode = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) {
|
|||
}
|
||||
|
||||
void Testbase::Init(const char* path, int16_t port) {
|
||||
dndInit();
|
||||
dmInit();
|
||||
|
||||
char fqdn[] = "localhost";
|
||||
char firstEp[TSDB_EP_LEN] = {0};
|
||||
|
@ -62,7 +62,7 @@ void Testbase::Cleanup() {
|
|||
client.Cleanup();
|
||||
taosMsleep(10);
|
||||
server.Stop();
|
||||
dndCleanup();
|
||||
dmCleanup();
|
||||
}
|
||||
|
||||
void Testbase::Restart() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. VNODE_SRC)
|
||||
add_executable(dvnodeTest ${VNODE_SRC})
|
||||
aux_source_directory(. DND_VNODE_TEST_SRC)
|
||||
add_executable(dvnodeTest ${DND_VNODE_TEST_SRC})
|
||||
target_link_libraries(
|
||||
dvnodeTest
|
||||
PUBLIC sut
|
||||
|
|
|
@ -44,7 +44,6 @@ void grantReset(EGrantType grant, uint64_t value);
|
|||
void grantAdd(EGrantType grant, uint64_t value);
|
||||
void grantRestore(EGrantType grant, uint64_t value);
|
||||
|
||||
void parseGrantParameter();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -354,7 +354,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) {
|
|||
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
bool dnodeChanged = (statusReq.dver != sdbGetTableVer(pMnode->pSdb, SDB_DNODE));
|
||||
bool dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE));
|
||||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||
bool needCheck = !online || dnodeChanged || reboot;
|
||||
|
||||
|
@ -405,7 +405,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) {
|
|||
pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
|
||||
|
||||
SStatusRsp statusRsp = {0};
|
||||
statusRsp.dver = sdbGetTableVer(pMnode->pSdb, SDB_DNODE);
|
||||
statusRsp.dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE);
|
||||
statusRsp.dnodeCfg.dnodeId = pDnode->id;
|
||||
statusRsp.dnodeCfg.clusterId = pMnode->clusterId;
|
||||
statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp));
|
||||
|
|
|
@ -18,10 +18,15 @@
|
|||
#include "taoserror.h"
|
||||
#include "mndGrant.h"
|
||||
#include "mndInt.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
#ifndef _GRANT
|
||||
static int32_t mndRetrieveGrant(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { return TSDB_CODE_OPS_NOT_SUPPORT; }
|
||||
|
||||
int32_t mndInitGrant(SMnode *pMnode) { return TSDB_CODE_SUCCESS; }
|
||||
int32_t mndInitGrant(SMnode *pMnode) {
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_GRANTS, mndRetrieveGrant);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
void mndCleanupGrant() {}
|
||||
void grantParseParameter() { mError("can't parsed parameter k"); }
|
||||
int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
|
@ -31,4 +36,4 @@ void grantRestore(EGrantType grant, uint64_t value) {}
|
|||
|
||||
#endif
|
||||
|
||||
void parseGrantParameter() { grantParseParameter(); }
|
||||
void mndGenerateMachineCode() { grantParseParameter(); }
|
||||
|
|
|
@ -222,7 +222,6 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) {
|
|||
if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -348,6 +347,8 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) {
|
|||
|
||||
int32_t mndStart(SMnode *pMnode) { return mndInitTimer(pMnode); }
|
||||
|
||||
void mndStop(SMnode *pMnode) { return mndCleanupTimer(pMnode); }
|
||||
|
||||
int32_t mndProcessMsg(SNodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pNode;
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
|
|
|
@ -48,8 +48,6 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
|
|||
|
||||
#define GET_TABLEGROUP(q, _index) ((SArray*)taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
|
||||
|
||||
#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL ? 0 : ((_r)->outputBuf)->info.rows)
|
||||
|
||||
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0)
|
||||
|
||||
enum {
|
||||
|
@ -84,21 +82,6 @@ typedef struct SResultInfo { // TODO refactor
|
|||
int32_t threshold; // result size threshold in rows.
|
||||
} SResultInfo;
|
||||
|
||||
typedef struct SColumnFilterElem {
|
||||
int16_t bytes; // column length
|
||||
__filter_func_t fp;
|
||||
SColumnFilterInfo filterInfo;
|
||||
void* q;
|
||||
} SColumnFilterElem;
|
||||
|
||||
typedef struct SSingleColumnFilterInfo {
|
||||
void* pData;
|
||||
void* pData2; // used for nchar column
|
||||
int32_t numOfFilters;
|
||||
SColumnInfo info;
|
||||
SColumnFilterElem* pFilters;
|
||||
} SSingleColumnFilterInfo;
|
||||
|
||||
typedef struct STableQueryInfo {
|
||||
TSKEY lastKey; // last check ts
|
||||
uint64_t uid; // table uid
|
||||
|
@ -169,66 +152,36 @@ typedef struct SOperatorCostInfo {
|
|||
uint64_t totalCost;
|
||||
} SOperatorCostInfo;
|
||||
|
||||
typedef struct SOrder {
|
||||
uint32_t order;
|
||||
SColumn col;
|
||||
} SOrder;
|
||||
|
||||
// The basic query information extracted from the SQueryInfo tree to support the
|
||||
// execution of query in a data node.
|
||||
typedef struct STaskAttr {
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool diffQuery; // is diff query
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
int32_t havingNum; // having expr number
|
||||
int16_t numOfCols;
|
||||
int16_t numOfTags;
|
||||
STimeWindow window;
|
||||
SInterval interval;
|
||||
int16_t precision;
|
||||
int16_t numOfOutput;
|
||||
int16_t fillType;
|
||||
int32_t resultRowSize;
|
||||
int32_t tagLen; // tag value length of current query
|
||||
|
||||
// todo comment it
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool queryBlockDist; // if query data block distribution
|
||||
bool stabledev; // super table stddev query
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool diffQuery; // is diff query
|
||||
bool simpleAgg;
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
bool needReverseScan; // need reverse scan
|
||||
bool distinct; // distinct query or not
|
||||
bool stateWindow; // window State on sub/normal table
|
||||
bool createFilterOperator; // if filter operator is needed
|
||||
bool multigroupResult; // multigroup result can exist in one SSDataBlock
|
||||
int32_t interBufSize; // intermediate buffer sizse
|
||||
|
||||
int32_t havingNum; // having expr number
|
||||
|
||||
SOrder order;
|
||||
int16_t numOfCols;
|
||||
int16_t numOfTags;
|
||||
|
||||
STimeWindow window;
|
||||
SInterval interval;
|
||||
int16_t precision;
|
||||
int16_t numOfOutput;
|
||||
int16_t fillType;
|
||||
|
||||
int32_t srcRowSize; // todo extract struct
|
||||
int32_t resultRowSize;
|
||||
int32_t intermediateResultRowSize; // intermediate result row size, in case of top-k query.
|
||||
int32_t maxTableColumnWidth;
|
||||
int32_t tagLen; // tag value length of current query
|
||||
|
||||
SExprInfo* pExpr1;
|
||||
|
||||
SColumnInfo* tableCols;
|
||||
SColumnInfo* tagColList;
|
||||
int32_t numOfFilterCols;
|
||||
int64_t* fillVal;
|
||||
|
||||
SSingleColumnFilterInfo* pFilterInfo;
|
||||
SExprInfo *pExpr1;
|
||||
SColumnInfo* tagColList;
|
||||
int32_t numOfFilterCols;
|
||||
int64_t* fillVal;
|
||||
void* tsdb;
|
||||
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
||||
int32_t vgId;
|
||||
SArray* pUdfInfo; // no need to free
|
||||
} STaskAttr;
|
||||
|
||||
struct SOperatorInfo;
|
||||
|
@ -252,7 +205,6 @@ typedef struct STaskIdInfo {
|
|||
|
||||
typedef struct SExecTaskInfo {
|
||||
STaskIdInfo id;
|
||||
char* content;
|
||||
uint32_t status;
|
||||
STimeWindow window;
|
||||
STaskCostInfo cost;
|
||||
|
@ -262,7 +214,7 @@ typedef struct SExecTaskInfo {
|
|||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
char* sql; // query sql string
|
||||
jmp_buf env; // jump to this position when error happens.
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
struct SOperatorInfo* pRoot;
|
||||
} SExecTaskInfo;
|
||||
|
||||
|
@ -297,7 +249,7 @@ typedef struct STaskRuntimeEnv {
|
|||
int64_t currentOffset; // dynamic offset value
|
||||
|
||||
STableQueryInfo* current;
|
||||
SResultInfo resultInfo;
|
||||
SResultInfo resultInfo;
|
||||
SHashObj* pTableRetrieveTsMap;
|
||||
struct SUdfInfo* pUdfInfo;
|
||||
} STaskRuntimeEnv;
|
||||
|
@ -339,25 +291,6 @@ typedef struct {
|
|||
SColumnInfo* colList;
|
||||
} SQueriedTableInfo;
|
||||
|
||||
typedef struct SQInfo {
|
||||
void* signature;
|
||||
uint64_t qId;
|
||||
int32_t code; // error code to returned to client
|
||||
int64_t owner; // if it is in execution
|
||||
|
||||
STaskRuntimeEnv runtimeEnv;
|
||||
STaskAttr query;
|
||||
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
|
||||
|
||||
TdThreadMutex lock; // used to synchronize the rsp/query threads
|
||||
tsem_t ready;
|
||||
int32_t dataReady; // denote if query result is ready or not
|
||||
void* rspContext; // response context
|
||||
int64_t startExecTs; // start to exec timestamp
|
||||
char* sql; // query sql string
|
||||
STaskCostInfo summary;
|
||||
} SQInfo;
|
||||
|
||||
typedef enum {
|
||||
EX_SOURCE_DATA_NOT_READY = 0x1,
|
||||
EX_SOURCE_DATA_READY = 0x2,
|
||||
|
@ -523,24 +456,6 @@ typedef struct SProjectOperatorInfo {
|
|||
int64_t curOutput;
|
||||
} SProjectOperatorInfo;
|
||||
|
||||
typedef struct SSLimitOperatorInfo {
|
||||
int64_t groupTotal;
|
||||
int64_t currentGroupOffset;
|
||||
int64_t rowsTotal;
|
||||
int64_t currentOffset;
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
char** prevRow;
|
||||
SArray* orderColumnList;
|
||||
bool hasPrev;
|
||||
bool ignoreCurrentGroup;
|
||||
bool multigroupResult;
|
||||
SSDataBlock* pRes; // result buffer
|
||||
SSDataBlock* pPrevBlock;
|
||||
int64_t capacity;
|
||||
int64_t threshold;
|
||||
} SSLimitOperatorInfo;
|
||||
|
||||
typedef struct SFillOperatorInfo {
|
||||
struct SFillInfo* pFillInfo;
|
||||
SSDataBlock* pRes;
|
||||
|
@ -553,10 +468,10 @@ typedef struct SFillOperatorInfo {
|
|||
} SFillOperatorInfo;
|
||||
|
||||
typedef struct {
|
||||
char *pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
char *pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
} SGroupKeys, SStateKeys;
|
||||
|
||||
typedef struct SGroupbyOperatorInfo {
|
||||
|
@ -582,19 +497,19 @@ typedef struct SDataGroupInfo {
|
|||
|
||||
// The sort in partition may be needed later.
|
||||
typedef struct SPartitionOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SHashObj* pGroupSet; // quick locate the window object for each result
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SHashObj* pGroupSet; // quick locate the window object for each result
|
||||
|
||||
SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t rowCapacity; // maximum number of rows for each buffer page
|
||||
int32_t* columnOffset; // start position for each column data
|
||||
SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t rowCapacity; // maximum number of rows for each buffer page
|
||||
int32_t* columnOffset; // start position for each column data
|
||||
|
||||
void* pGroupIter; // group iterator
|
||||
int32_t pageIndex; // page index of current group
|
||||
void* pGroupIter; // group iterator
|
||||
int32_t pageIndex; // page index of current group
|
||||
} SPartitionOperatorInfo;
|
||||
|
||||
typedef struct SWindowRowsSup {
|
||||
|
@ -633,26 +548,21 @@ typedef struct SStateWindowOperatorInfo {
|
|||
} SStateWindowOperatorInfo;
|
||||
|
||||
typedef struct SSortedMergeOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
bool hasVarCol;
|
||||
SOptrBasicInfo binfo;
|
||||
bool hasVarCol;
|
||||
|
||||
SArray* pSortInfo;
|
||||
int32_t numOfSources;
|
||||
|
||||
SSortHandle *pSortHandle;
|
||||
|
||||
int32_t bufPageSize;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
|
||||
int32_t resultRowFactor;
|
||||
bool hasGroupVal;
|
||||
|
||||
SDiskbasedBuf *pTupleStore; // keep the final results
|
||||
int32_t numOfResPerPage;
|
||||
|
||||
char** groupVal;
|
||||
SArray *groupInfo;
|
||||
SAggSupporter aggSup;
|
||||
SArray* pSortInfo;
|
||||
int32_t numOfSources;
|
||||
SSortHandle *pSortHandle;
|
||||
int32_t bufPageSize;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
int32_t resultRowFactor;
|
||||
bool hasGroupVal;
|
||||
SDiskbasedBuf *pTupleStore; // keep the final results
|
||||
int32_t numOfResPerPage;
|
||||
char** groupVal;
|
||||
SArray *groupInfo;
|
||||
SAggSupporter aggSup;
|
||||
} SSortedMergeOperatorInfo;
|
||||
|
||||
typedef struct SSortOperatorInfo {
|
||||
|
@ -680,8 +590,7 @@ int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInf
|
|||
void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, int32_t* rowCellOffset);
|
||||
void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset);
|
||||
void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order);
|
||||
int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type,
|
||||
int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup);
|
||||
int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup);
|
||||
void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput);
|
||||
int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows,
|
||||
char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs,
|
||||
|
@ -748,7 +657,6 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo);
|
|||
void publishOperatorProfEvent(SOperatorInfo* operatorInfo, EQueryProfEventType eventType);
|
||||
void publishQueryAbortEvent(SExecTaskInfo* pTaskInfo, int32_t code);
|
||||
|
||||
void calculateOperatorProfResults(SQInfo* pQInfo);
|
||||
void queryCostStatis(SExecTaskInfo* pTaskInfo);
|
||||
|
||||
void doDestroyTask(SExecTaskInfo* pTaskInfo);
|
||||
|
|
|
@ -337,11 +337,11 @@ int32_t tsDescOrder(const void* p1, const void* p2) {
|
|||
|
||||
void orderTheResultRows(STaskRuntimeEnv* pRuntimeEnv) {
|
||||
__compar_fn_t fn = NULL;
|
||||
if (pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_ASC) {
|
||||
fn = tsAscOrder;
|
||||
} else {
|
||||
fn = tsDescOrder;
|
||||
}
|
||||
// if (pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_ASC) {
|
||||
// fn = tsAscOrder;
|
||||
// } else {
|
||||
// fn = tsDescOrder;
|
||||
// }
|
||||
|
||||
taosArraySort(pRuntimeEnv->pResultRowArrayList, fn);
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupRe
|
|||
|
||||
static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList,
|
||||
int32_t* rowCellInfoOffset) {
|
||||
bool ascQuery = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQueryAttr);
|
||||
bool ascQuery = true;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -413,7 +413,8 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
|
|||
goto _end;
|
||||
}
|
||||
|
||||
SCompSupporter cs = {pTableQueryInfoList, posList, pRuntimeEnv->pQueryAttr->order.order};
|
||||
int32_t order = TSDB_ORDER_ASC;
|
||||
SCompSupporter cs = {pTableQueryInfoList, posList, order};
|
||||
|
||||
int32_t ret = tMergeTreeCreate(&pTree, numOfTables, &cs, tableResultComparFn);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -52,7 +52,7 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
|||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
||||
|
||||
SSDataBlock* p = createOneDataBlock(pDataBlock);
|
||||
SSDataBlock* p = createOneDataBlock(pDataBlock, false);
|
||||
p->info = pDataBlock->info;
|
||||
|
||||
taosArrayClear(p->pDataBlock);
|
||||
|
|
|
@ -990,7 +990,8 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext,
|
|||
|
||||
static FORCE_INLINE TSKEY reviseWindowEkey(STaskAttr* pQueryAttr, STimeWindow* pWindow) {
|
||||
TSKEY ekey = -1;
|
||||
if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
|
||||
int32_t order = TSDB_ORDER_ASC;
|
||||
if (order == TSDB_ORDER_ASC) {
|
||||
ekey = pWindow->ekey;
|
||||
if (ekey > pQueryAttr->window.ekey) {
|
||||
ekey = pQueryAttr->window.ekey;
|
||||
|
@ -1700,9 +1701,8 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type,
|
||||
int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo,
|
||||
SAggSupporter* pAggSup) {
|
||||
int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes,
|
||||
int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup) {
|
||||
SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo;
|
||||
SqlFunctionCtx* pCtx = binfo->pCtx;
|
||||
|
||||
|
@ -1961,7 +1961,8 @@ static bool isCachedLastQuery(STaskAttr* pQueryAttr) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pQueryAttr->order.order != TSDB_ORDER_DESC || !TSWINDOW_IS_EQUAL(pQueryAttr->window, TSWINDOW_DESC_INITIALIZER)) {
|
||||
int32_t order = TSDB_ORDER_ASC;
|
||||
if (order != TSDB_ORDER_DESC || !TSWINDOW_IS_EQUAL(pQueryAttr->window, TSWINDOW_DESC_INITIALIZER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2187,7 +2188,7 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI
|
|||
TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
|
||||
if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
|
||||
if (true) {
|
||||
// getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w);
|
||||
assert(w.ekey >= pBlockInfo->window.skey);
|
||||
|
||||
|
@ -2257,57 +2258,6 @@ static int32_t doTSJoinFilter(STaskRuntimeEnv* pRuntimeEnv, TSKEY key, bool ascQ
|
|||
return TS_JOIN_TS_EQUAL;
|
||||
}
|
||||
|
||||
bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t numOfRows, int8_t* p) {
|
||||
bool all = true;
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
bool qualified = false;
|
||||
|
||||
for (int32_t k = 0; k < numOfFilterCols; ++k) {
|
||||
char* pElem = (char*)pFilterInfo[k].pData + pFilterInfo[k].info.bytes * i;
|
||||
|
||||
qualified = false;
|
||||
for (int32_t j = 0; j < pFilterInfo[k].numOfFilters; ++j) {
|
||||
SColumnFilterElem* pFilterElem = NULL;
|
||||
// SColumnFilterElem* pFilterElem = &pFilterInfo[k].pFilters[j];
|
||||
|
||||
bool isnull = isNull(pElem, pFilterInfo[k].info.type);
|
||||
if (isnull) {
|
||||
// if (pFilterElem->fp == isNullOperator) {
|
||||
// qualified = true;
|
||||
// break;
|
||||
// } else {
|
||||
// continue;
|
||||
// }
|
||||
} else {
|
||||
// if (pFilterElem->fp == notNullOperator) {
|
||||
// qualified = true;
|
||||
// break;
|
||||
// } else if (pFilterElem->fp == isNullOperator) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
|
||||
if (pFilterElem->fp(pFilterElem, pElem, pElem, pFilterInfo[k].info.type)) {
|
||||
qualified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!qualified) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p[i] = qualified ? 1 : 0;
|
||||
if (!qualified) {
|
||||
all = false;
|
||||
}
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) {
|
||||
int32_t len = 0;
|
||||
int32_t start = 0;
|
||||
|
@ -2357,49 +2307,6 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) {
|
|||
}
|
||||
}
|
||||
|
||||
void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols,
|
||||
SSDataBlock* pBlock, bool ascQuery) {
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
|
||||
int8_t* p = taosMemoryCalloc(numOfRows, sizeof(int8_t));
|
||||
bool all = true;
|
||||
#if 0
|
||||
if (pRuntimeEnv->pTsBuf != NULL) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
|
||||
TSKEY* k = (TSKEY*) pColInfoData->pData;
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
int32_t offset = ascQuery? i:(numOfRows - i - 1);
|
||||
int32_t ret = doTSJoinFilter(pRuntimeEnv, k[offset], ascQuery);
|
||||
if (ret == TS_JOIN_TAG_NOT_EQUALS) {
|
||||
break;
|
||||
} else if (ret == TS_JOIN_TS_NOT_EQUALS) {
|
||||
all = false;
|
||||
continue;
|
||||
} else {
|
||||
assert(ret == TS_JOIN_TS_EQUAL);
|
||||
p[offset] = true;
|
||||
}
|
||||
|
||||
if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// save the cursor status
|
||||
pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf);
|
||||
} else {
|
||||
all = doFilterDataBlock(pFilterInfo, numOfFilterCols, numOfRows, p);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!all) {
|
||||
doCompactSDataBlock(pBlock, numOfRows, p);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(p);
|
||||
}
|
||||
|
||||
void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, bool ascQuery) {
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
|
||||
|
@ -3131,7 +3038,7 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) {
|
|||
bool keep = filterExecute(filter, pBlock, &rowRes, NULL, param1.numOfCols);
|
||||
filterFreeInfo(filter);
|
||||
|
||||
SSDataBlock* px = createOneDataBlock(pBlock);
|
||||
SSDataBlock* px = createOneDataBlock(pBlock, false);
|
||||
blockDataEnsureCapacity(px, pBlock->info.rows);
|
||||
|
||||
// todo extract method
|
||||
|
@ -3509,22 +3416,22 @@ static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* ev
|
|||
}
|
||||
}
|
||||
|
||||
void calculateOperatorProfResults(SQInfo* pQInfo) {
|
||||
if (pQInfo->summary.queryProfEvents == NULL) {
|
||||
// qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pQInfo->summary.operatorProfResults == NULL) {
|
||||
// qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId);
|
||||
return;
|
||||
}
|
||||
void calculateOperatorProfResults(void) {
|
||||
// if (pQInfo->summary.queryProfEvents == NULL) {
|
||||
// // qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (pQInfo->summary.operatorProfResults == NULL) {
|
||||
// // qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId);
|
||||
// return;
|
||||
// }
|
||||
|
||||
SArray* opStack = taosArrayInit(32, sizeof(SOperatorStackItem));
|
||||
if (opStack == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
size_t size = taosArrayGetSize(pQInfo->summary.queryProfEvents);
|
||||
SHashObj* profResults = pQInfo->summary.operatorProfResults;
|
||||
|
||||
|
@ -3547,7 +3454,7 @@ void calculateOperatorProfResults(SQInfo* pQInfo) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
taosArrayDestroy(opStack);
|
||||
}
|
||||
|
||||
|
@ -4507,13 +4414,6 @@ static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
cleanupAggSup(&pInfo->aggSup);
|
||||
}
|
||||
|
||||
static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SSLimitOperatorInfo* pInfo = (SSLimitOperatorInfo*)param;
|
||||
taosArrayDestroy(pInfo->orderColumnList);
|
||||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
taosMemoryFreeClear(pInfo->prevRow);
|
||||
}
|
||||
|
||||
static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) {
|
||||
assert(dst != NULL && src != NULL);
|
||||
|
||||
|
@ -4713,7 +4613,7 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) {
|
|||
SSortedMergeOperatorInfo* pInfo = pOperator->info;
|
||||
SSortHandle* pHandle = pInfo->pSortHandle;
|
||||
|
||||
SSDataBlock* pDataBlock = createOneDataBlock(pInfo->binfo.pRes);
|
||||
SSDataBlock* pDataBlock = createOneDataBlock(pInfo->binfo.pRes, false);
|
||||
blockDataEnsureCapacity(pDataBlock, pInfo->binfo.capacity);
|
||||
|
||||
while (1) {
|
||||
|
@ -5546,8 +5446,6 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup
|
|||
}
|
||||
|
||||
STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr;
|
||||
int32_t order = pQueryAttr->order.order;
|
||||
|
||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
|
||||
while (1) {
|
||||
|
@ -5563,14 +5461,13 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup
|
|||
STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current;
|
||||
|
||||
// setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
|
||||
setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order);
|
||||
setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, TSDB_ORDER_ASC);
|
||||
setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey);
|
||||
|
||||
hashIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex);
|
||||
}
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
pQueryAttr->order.order = order; // TODO : restore the order
|
||||
doCloseAllTimeWindow(pRuntimeEnv);
|
||||
setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
|
||||
int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
int32_t ret = setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
if (num > 0) {
|
||||
len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
|
||||
int32_t ret =
|
||||
setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len,
|
||||
setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len,
|
||||
0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR);
|
||||
|
|
|
@ -258,16 +258,14 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
return pOperator;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) {
|
||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) {
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
|
||||
pInfo->dataReader = pTsdbReadHandle;
|
||||
pInfo->times = 1;
|
||||
pInfo->reverseTimes = 0;
|
||||
pInfo->order = pRuntimeEnv->pQueryAttr->order.order;
|
||||
pInfo->current = 0;
|
||||
pInfo->prevGroupId = -1;
|
||||
pRuntimeEnv->enableGroupData = true;
|
||||
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
pOperator->name = "TableSeqScanOperator";
|
||||
|
@ -275,8 +273,6 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim
|
|||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->getNextFn = doTableScanImpl;
|
||||
|
||||
return pOperator;
|
||||
|
@ -594,7 +590,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) {
|
|||
bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols);
|
||||
filterFreeInfo(filter);
|
||||
|
||||
SSDataBlock* px = createOneDataBlock(pInfo->pRes);
|
||||
SSDataBlock* px = createOneDataBlock(pInfo->pRes, false);
|
||||
blockDataEnsureCapacity(px, pInfo->pRes->info.rows);
|
||||
|
||||
// TODO refactor
|
||||
|
@ -683,71 +679,70 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
while (1) {
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
|
||||
_retry:
|
||||
pInfo->req.type = pInfo->type;
|
||||
strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb));
|
||||
if (pInfo->showRewrite) {
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
getDBNameFromCondition(pInfo->pCondition, dbName);
|
||||
sprintf(pInfo->req.db, "%d.%s", pInfo->accountId, dbName);
|
||||
pInfo->req.type = pInfo->type;
|
||||
strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb));
|
||||
|
||||
if (pInfo->showRewrite) {
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
getDBNameFromCondition(pInfo->pCondition, dbName);
|
||||
sprintf(pInfo->req.db, "%d.%s", pInfo->accountId, dbName);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req);
|
||||
char* buf1 = taosMemoryCalloc(1, contLen);
|
||||
tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req);
|
||||
|
||||
// send the fetch remote task result reques
|
||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo));
|
||||
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMsgSendInfo->param = pOperator;
|
||||
pMsgSendInfo->msgInfo.pData = buf1;
|
||||
pMsgSendInfo->msgInfo.len = contLen;
|
||||
pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE;
|
||||
pMsgSendInfo->fp = loadSysTableContentCb;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
tsem_wait(&pInfo->ready);
|
||||
|
||||
if (pTaskInfo->code) {
|
||||
qDebug("%s load meta data from mnode failed, totalRows:%" PRIu64 ", code:%s", GET_TASKID(pTaskInfo),
|
||||
pInfo->loadInfo.totalRows, tstrerror(pTaskInfo->code));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRetrieveMetaTableRsp* pRsp = pInfo->pRsp;
|
||||
pInfo->req.showId = pRsp->handle;
|
||||
|
||||
if (pRsp->numOfRows == 0 || pRsp->completed) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
qDebug("%s load meta data from mnode completed, rowsOfSource:%d, totalRows:%" PRIu64 " ", GET_TASKID(pTaskInfo),
|
||||
pRsp->numOfRows, pInfo->loadInfo.totalRows);
|
||||
|
||||
if (pRsp->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp;
|
||||
setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data,
|
||||
pTableRsp->compLen, pOperator->numOfOutput, startTs, NULL, pInfo->scanCols);
|
||||
|
||||
// todo log the filter info
|
||||
doFilterResult(pInfo);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
return pInfo->pRes;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req);
|
||||
char* buf1 = taosMemoryCalloc(1, contLen);
|
||||
tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req);
|
||||
|
||||
// send the fetch remote task result reques
|
||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo));
|
||||
pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMsgSendInfo->param = pOperator;
|
||||
pMsgSendInfo->msgInfo.pData = buf1;
|
||||
pMsgSendInfo->msgInfo.len = contLen;
|
||||
pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE;
|
||||
pMsgSendInfo->fp = loadSysTableContentCb;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
tsem_wait(&pInfo->ready);
|
||||
|
||||
if (pTaskInfo->code) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRetrieveMetaTableRsp* pRsp = pInfo->pRsp;
|
||||
pInfo->req.showId = pRsp->handle;
|
||||
|
||||
if (pRsp->numOfRows == 0 || pRsp->completed) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
||||
if (pRsp->numOfRows == 0) {
|
||||
// qDebug("%s vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64"
|
||||
// try next",
|
||||
// GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pExchangeInfo->current + 1,
|
||||
// pDataInfo->totalRows, pExchangeInfo->totalRows);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp;
|
||||
setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, pTableRsp->compLen,
|
||||
pOperator->numOfOutput, startTs, NULL, pInfo->scanCols);
|
||||
|
||||
doFilterResult(pInfo);
|
||||
if (pInfo->pRes->info.rows == 0) {
|
||||
goto _retry;
|
||||
}
|
||||
|
||||
return pInfo->pRes;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName,
|
||||
|
|
|
@ -99,7 +99,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t
|
|||
pSortHandle->numOfPages = numOfPages;
|
||||
pSortHandle->pSortInfo = pSortInfo;
|
||||
pSortHandle->pIndexMap = pIndexMap;
|
||||
pSortHandle->pDataBlock = createOneDataBlock(pBlock);
|
||||
pSortHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
|
||||
pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES);
|
||||
pSortHandle->cmpParam.orderInfo = pSortInfo;
|
||||
|
@ -206,7 +206,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) {
|
|||
|
||||
blockDataCleanup(pDataBlock);
|
||||
|
||||
SSDataBlock* pBlock = createOneDataBlock(pDataBlock);
|
||||
SSDataBlock* pBlock = createOneDataBlock(pDataBlock, false);
|
||||
return doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId);
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
|||
tMergeTreeDestroy(pHandle->pMergeTree);
|
||||
pHandle->numOfCompletedSources = 0;
|
||||
|
||||
SSDataBlock* pBlock = createOneDataBlock(pHandle->pDataBlock);
|
||||
SSDataBlock* pBlock = createOneDataBlock(pHandle->pDataBlock, false);
|
||||
code = doAddNewExternalMemSource(pHandle->pBuf, pResList, pBlock, &pHandle->sourceId);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
|
@ -531,7 +531,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
}
|
||||
|
||||
if (pHandle->pDataBlock == NULL) {
|
||||
pHandle->pDataBlock = createOneDataBlock(pBlock);
|
||||
pHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
}
|
||||
|
||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap);
|
||||
|
|
|
@ -331,6 +331,19 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNcharCo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t numOfRows) {
|
||||
int32_t numOfNulls = 0;
|
||||
if (!pColumnInfoData->hasNull) {
|
||||
return numOfNulls;
|
||||
}
|
||||
for (int i = 0; i < numOfRows; ++i) {
|
||||
if (pColumnInfoData->varmeta.offset[i] == -1) {
|
||||
numOfNulls++;
|
||||
}
|
||||
}
|
||||
return numOfNulls;
|
||||
}
|
||||
|
||||
int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum < 2 || inputNum > 8) { // concat accpet 2-8 input strings
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -363,10 +376,12 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
factor = TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows);
|
||||
if (pInput[i].numOfRows == 1) {
|
||||
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * factor * numOfRows;
|
||||
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * factor * (numOfRows - numOfNulls);
|
||||
} else {
|
||||
inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE;
|
||||
inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,13 +459,15 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
factor = TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows);
|
||||
if (i == 0) {
|
||||
// calculate required separator space
|
||||
inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows * (inputNum - 2) * factor;
|
||||
inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor;
|
||||
} else if (pInput[i].numOfRows == 1) {
|
||||
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows * factor;
|
||||
inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor;
|
||||
} else {
|
||||
inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE;
|
||||
inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1100,6 +1100,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
|
|||
SSubmitRsp *rsp = (SSubmitRsp *)msg;
|
||||
SCH_ERR_JRET(rsp->code);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(rspCode);
|
||||
|
||||
SSubmitRsp *rsp = (SSubmitRsp *)msg;
|
||||
|
@ -1298,7 +1299,6 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in
|
|||
SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode));
|
||||
|
||||
_return:
|
||||
|
||||
if (pJob) {
|
||||
schReleaseJob(pParam->refId);
|
||||
}
|
||||
|
|
|
@ -147,8 +147,8 @@ static void (*transAsyncHandle[])(SSrvMsg* msg, SWorkThrdObj* thrd) = {uvHandleR
|
|||
static void uvDestroyConn(uv_handle_t* handle);
|
||||
|
||||
// server and worker thread
|
||||
static void* workerThread(void* arg);
|
||||
static void* acceptThread(void* arg);
|
||||
static void* transWorkerThread(void* arg);
|
||||
static void* transAcceptThread(void* arg);
|
||||
|
||||
// add handle loop
|
||||
static bool addHandleToWorkloop(void* arg);
|
||||
|
@ -538,7 +538,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
|||
}
|
||||
}
|
||||
|
||||
void* acceptThread(void* arg) {
|
||||
void* transAcceptThread(void* arg) {
|
||||
// opt
|
||||
setThreadName("trans-accept");
|
||||
SServerObj* srv = (SServerObj*)arg;
|
||||
|
@ -596,7 +596,7 @@ static bool addHandleToAcceptloop(void* arg) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
void* workerThread(void* arg) {
|
||||
void* transWorkerThread(void* arg) {
|
||||
setThreadName("trans-worker");
|
||||
SWorkThrdObj* pThrd = (SWorkThrdObj*)arg;
|
||||
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
||||
|
@ -686,7 +686,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
if (false == addHandleToWorkloop(thrd)) {
|
||||
goto End;
|
||||
}
|
||||
int err = taosThreadCreate(&(thrd->thread), NULL, workerThread, (void*)(thrd));
|
||||
int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd));
|
||||
if (err == 0) {
|
||||
tDebug("sucess to create worker-thread %d", i);
|
||||
// printf("thread %d create\n", i);
|
||||
|
@ -698,7 +698,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
if (false == addHandleToAcceptloop(srv)) {
|
||||
goto End;
|
||||
}
|
||||
int err = taosThreadCreate(&srv->thread, NULL, acceptThread, (void*)srv);
|
||||
int err = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv);
|
||||
if (err == 0) {
|
||||
tDebug("success to create accept-thread");
|
||||
} else {
|
||||
|
|
|
@ -154,7 +154,7 @@ static void taosProcCleanupQueue(SProcQueue *pQueue) {
|
|||
}
|
||||
|
||||
static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen,
|
||||
const char *pBody, int32_t rawBodyLen, int64_t handle, ProcFuncType ftype) {
|
||||
const char *pBody, int32_t rawBodyLen, int64_t handle, EProcFuncType ftype) {
|
||||
if (rawHeadLen == 0 || pHead == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
|
@ -171,7 +171,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (handle != 0 && ftype == PROC_REQ) {
|
||||
if (handle != 0 && ftype == PROC_FUNC_REQ) {
|
||||
if (taosHashPut(pProc->hash, &handle, sizeof(int64_t), &handle, sizeof(int64_t)) != 0) {
|
||||
taosThreadMutexUnlock(&pQueue->mutex);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -232,7 +232,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char
|
|||
}
|
||||
|
||||
static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen,
|
||||
ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp,
|
||||
EProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp,
|
||||
ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) {
|
||||
tsem_wait(&pQueue->sem);
|
||||
|
||||
|
@ -309,7 +309,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea
|
|||
*ppBody = pBody;
|
||||
*pHeadLen = rawHeadLen;
|
||||
*pBodyLen = rawBodyLen;
|
||||
*pFuncType = (ProcFuncType)ftype;
|
||||
*pFuncType = (EProcFuncType)ftype;
|
||||
|
||||
uTrace("proc:%s, pop msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype,
|
||||
pQueue->items, rawHeadLen, pHead, rawBodyLen, pBody);
|
||||
|
@ -364,7 +364,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) {
|
|||
static void taosProcThreadLoop(SProcObj *pProc) {
|
||||
void *pHead, *pBody;
|
||||
int16_t headLen;
|
||||
ProcFuncType ftype;
|
||||
EProcFuncType ftype;
|
||||
int32_t bodyLen;
|
||||
SProcQueue *pQueue;
|
||||
ProcConsumeFp consumeFp;
|
||||
|
@ -454,8 +454,8 @@ void taosProcCleanup(SProcObj *pProc) {
|
|||
}
|
||||
|
||||
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
void *handle, ProcFuncType ftype) {
|
||||
if (ftype != PROC_REQ) {
|
||||
void *handle, EProcFuncType ftype) {
|
||||
if (ftype != PROC_FUNC_REQ) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
|
@ -482,7 +482,7 @@ void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)) {
|
|||
}
|
||||
|
||||
void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype) {
|
||||
EProcFuncType ftype) {
|
||||
int32_t retry = 0;
|
||||
while (taosProcQueuePush(pProc, pProc->pParentQueue, pHead, headLen, pBody, bodyLen, 0, ftype) != 0) {
|
||||
uWarn("proc:%s, failed to put to queue:%p since %s, retry:%d", pProc->name, pProc->pParentQueue, terrstr(), retry);
|
||||
|
|
|
@ -89,7 +89,7 @@ TEST_F(UtilTesProc, 00_Init_Cleanup) {
|
|||
taosDropShm(&shm);
|
||||
}
|
||||
|
||||
void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) {
|
||||
void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
|
||||
STestMsg msg;
|
||||
memcpy(&msg, pHead, headLen);
|
||||
char body[2000] = {0};
|
||||
|
@ -120,20 +120,20 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) {
|
|||
SProcObj *cproc = taosProcInit(&cfg);
|
||||
ASSERT_NE(cproc, nullptr);
|
||||
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RSP), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REGIST), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RELEASE), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RSP), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REGIST), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RELEASE), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_FUNC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_FUNC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_FUNC_REQ), 0);
|
||||
|
||||
for (int32_t j = 0; j < 1000; j++) {
|
||||
int32_t i = 0;
|
||||
for (i = 0; i < 20; ++i) {
|
||||
ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0);
|
||||
ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0);
|
||||
}
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0);
|
||||
ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0);
|
||||
|
||||
cfg.isChild = true;
|
||||
cfg.name = "1235_p";
|
||||
|
@ -147,7 +147,7 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) {
|
|||
taosDropShm(&shm);
|
||||
}
|
||||
|
||||
void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) {
|
||||
void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
|
||||
STestMsg msg;
|
||||
memcpy(&msg, pHead, headLen);
|
||||
char body[2000] = {0};
|
||||
|
@ -186,7 +186,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) {
|
|||
for (int32_t j = 0; j < 1000; j++) {
|
||||
int32_t i = 0;
|
||||
for (i = 0; i < 20; ++i) {
|
||||
taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_REQ);
|
||||
taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_FUNC_REQ);
|
||||
}
|
||||
|
||||
taosProcRun(cproc);
|
||||
|
@ -198,7 +198,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) {
|
|||
taosDropShm(&shm);
|
||||
}
|
||||
|
||||
void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) {
|
||||
void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
|
||||
STestMsg msg;
|
||||
memcpy(&msg, pHead, headLen);
|
||||
char body[2000] = {0};
|
||||
|
@ -236,7 +236,7 @@ TEST_F(UtilTesProc, 03_Handle) {
|
|||
int32_t i = 0;
|
||||
for (i = 0; i < 20; ++i) {
|
||||
head.handle = (void *)((int64_t)i);
|
||||
ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_REQ), 0);
|
||||
ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_FUNC_REQ), 0);
|
||||
}
|
||||
|
||||
cfg.isChild = true;
|
||||
|
|
|
@ -35,11 +35,11 @@ CURR_DIR=`pwd`
|
|||
IN_TDINTERNAL="community"
|
||||
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
TAOS_DIR=$CURR_DIR/../../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
|
||||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
fi
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ CURR_DIR=`pwd`
|
|||
IN_TDINTERNAL="community"
|
||||
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
TAOS_DIR=$CURR_DIR/../../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
|
||||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
fi
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ CURR_DIR=`pwd`
|
|||
IN_TDINTERNAL="community"
|
||||
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
TAOS_DIR=$CURR_DIR/../../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
|
||||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
fi
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
|||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
fi
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
export PYTHONPATH=$(pwd)/../../src/connector/python
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR
|
||||
|
|
|
@ -81,7 +81,8 @@
|
|||
# --- for multi process mode
|
||||
./test.sh -f tsim/user/basic1.sim -m
|
||||
./test.sh -f tsim/db/basic3.sim -m
|
||||
./test.sh -f tsim/insert/backquote.sim
|
||||
./test.sh -f tsim/db/error1.sim -m
|
||||
./test.sh -f tsim/insert/backquote.sim -m
|
||||
./test.sh -f tsim/parser/fourArithmetic-basic.sim -m
|
||||
./test.sh -f tsim/query/interval-offset.sim -m
|
||||
./test.sh -f tsim/tmq/basic.sim -m
|
||||
|
|
|
@ -43,7 +43,7 @@ else
|
|||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1`
|
||||
|
||||
if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
cut_opt="--field="
|
||||
|
@ -52,9 +52,9 @@ else
|
|||
fi
|
||||
|
||||
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
else
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2`
|
||||
fi
|
||||
|
||||
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
|
||||
|
|
|
@ -46,7 +46,7 @@ else
|
|||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1`
|
||||
|
||||
if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
cut_opt="--field="
|
||||
|
@ -55,9 +55,9 @@ else
|
|||
fi
|
||||
|
||||
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
else
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2`
|
||||
fi
|
||||
|
||||
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
|
||||
|
|
|
@ -41,7 +41,7 @@ else
|
|||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1`
|
||||
|
||||
if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
cut_opt="--field="
|
||||
|
|
|
@ -52,7 +52,7 @@ else
|
|||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1`
|
||||
|
||||
if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
cut_opt="--field="
|
||||
|
@ -61,9 +61,9 @@ else
|
|||
fi
|
||||
|
||||
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
else
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2`
|
||||
fi
|
||||
|
||||
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
|
||||
|
|
|
@ -52,7 +52,7 @@ else
|
|||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||
TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1`
|
||||
|
||||
if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
cut_opt="--field="
|
||||
|
@ -61,9 +61,9 @@ else
|
|||
fi
|
||||
|
||||
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3`
|
||||
else
|
||||
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2`
|
||||
BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2`
|
||||
fi
|
||||
|
||||
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue