提交 8fc5ce2e 编写于 作者: S Shengliang Guan

refactor: node mgmt

上级 5257e812
......@@ -20,9 +20,9 @@
static SMsgCb tsDefaultMsgCb;
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb) {
if (tsDefaultMsgCb.pWrapper == NULL) {
tsDefaultMsgCb = *pMsgCb;
}
// if (tsDefaultMsgCb.pWrapper == NULL) {
tsDefaultMsgCb = *pMsgCb;
//}
}
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq) {
......
......@@ -84,6 +84,7 @@ TEST_F(DndTestBnode, 01_Create_Bnode) {
}
TEST_F(DndTestBnode, 02_Drop_Bnode) {
#if 0
{
SDDropBnodeReq dropReq = {0};
dropReq.dnodeId = 2;
......@@ -96,7 +97,7 @@ TEST_F(DndTestBnode, 02_Drop_Bnode) {
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
}
#endif
{
SDDropBnodeReq dropReq = {0};
dropReq.dnodeId = 1;
......
......@@ -82,6 +82,7 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
}
TEST_F(DndTestQnode, 02_Drop_Qnode) {
#if 0
{
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
......@@ -94,6 +95,7 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
}
#endif
{
SDDropQnodeReq dropReq = {0};
......
......@@ -82,6 +82,7 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
}
TEST_F(DndTestSnode, 01_Drop_Snode) {
#if 0
{
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
......@@ -94,6 +95,7 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
}
#endif
{
SDDropSnodeReq dropReq = {0};
......
......@@ -87,13 +87,11 @@ typedef struct {
typedef struct SMnode {
int32_t selfId;
int64_t clusterId;
TdThread thread;
bool stopped;
int8_t replica;
int8_t selfIndex;
SReplica replicas[TSDB_MAX_REPLICA];
tmr_h timer;
tmr_h transTimer;
tmr_h mqTimer;
tmr_h telemTimer;
char *path;
int64_t checkTime;
SSdb *pSdb;
......
......@@ -56,82 +56,75 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
return pReq;
}
static void mndPullupTrans(void *param, void *tmrId) {
SMnode *pMnode = param;
if (mndIsMaster(pMnode)) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
}
taosTmrReset(mndPullupTrans, tsTransPullupInterval * 1000, pMnode, pMnode->timer, &pMnode->transTimer);
static void mndPullupTrans(SMnode *pMnode) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
}
static void mndCalMqRebalance(void *param, void *tmrId) {
SMnode *pMnode = param;
if (mndIsMaster(pMnode)) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {
.msgType = TDMT_MND_MQ_TIMER,
.pCont = pReq,
.contLen = contLen,
};
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
}
static void mndCalMqRebalance(SMnode *pMnode) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {
.msgType = TDMT_MND_MQ_TIMER,
.pCont = pReq,
.contLen = contLen,
};
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
}
taosTmrReset(mndCalMqRebalance, tsMqRebalanceInterval * 1000, pMnode, pMnode->timer, &pMnode->mqTimer);
static void mndPullupTelem(SMnode *pMnode) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
}
static void mndPullupTelem(void *param, void *tmrId) {
static void *mndThreadFp(void *param) {
SMnode *pMnode = param;
if (mndIsMaster(pMnode)) {
int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
}
int64_t lastTime = 0;
setThreadName("mnode-timer");
taosTmrReset(mndPullupTelem, tsTelemInterval * 1000, pMnode, pMnode->timer, &pMnode->telemTimer);
}
while (1) {
lastTime++;
taosMsleep(100);
if (pMnode->stopped) break;
if (!mndIsMaster(pMnode)) continue;
static int32_t mndInitTimer(SMnode *pMnode) {
pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND");
if (pMnode->timer == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (lastTime % (tsTransPullupInterval * 10) == 0) {
mndPullupTrans(pMnode);
}
if (taosTmrReset(mndPullupTrans, tsTransPullupInterval * 1000, pMnode, pMnode->timer, &pMnode->transTimer)) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (lastTime % (tsMqRebalanceInterval * 10) == 0) {
mndCalMqRebalance(pMnode);
}
if (taosTmrReset(mndCalMqRebalance, tsMqRebalanceInterval * 1000, pMnode, pMnode->timer, &pMnode->mqTimer)) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
if (lastTime % (tsTelemInterval * 10) == 0) {
mndPullupTelem(pMnode);
}
}
int32_t interval = tsTelemInterval < 10 ? tsTelemInterval : 10;
if (taosTmrReset(mndPullupTelem, interval * 1000, pMnode, pMnode->timer, &pMnode->telemTimer)) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
static int32_t mndInitTimer(SMnode *pMnode) {
TdThreadAttr thAttr;
taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (taosThreadCreate(&pMnode->thread, &thAttr, mndThreadFp, pMnode) != 0) {
mError("failed to create timer thread since %s", strerror(errno));
return -1;
}
taosThreadAttrDestroy(&thAttr);
tmsgReportStartup("mnode-timer", "initialized");
return 0;
}
static void mndCleanupTimer(SMnode *pMnode) {
if (pMnode->timer != NULL) {
taosTmrStop(pMnode->transTimer);
pMnode->transTimer = NULL;
taosTmrStop(pMnode->mqTimer);
pMnode->mqTimer = NULL;
taosTmrStop(pMnode->telemTimer);
pMnode->telemTimer = NULL;
taosTmrCleanUp(pMnode->timer);
pMnode->timer = NULL;
pMnode->stopped = true;
if (taosCheckPthreadValid(pMnode->thread)) {
taosThreadJoin(pMnode->thread, NULL);
}
}
......
......@@ -5,7 +5,7 @@ add_subdirectory(bnode)
add_subdirectory(db)
add_subdirectory(dnode)
add_subdirectory(func)
add_subdirectory(mnode)
#add_subdirectory(mnode)
add_subdirectory(profile)
add_subdirectory(qnode)
add_subdirectory(sdb)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册