enh: save dnodeVer in dnodeEps.json
This commit is contained in:
parent
d702cb1486
commit
3fc793dbe0
|
@ -38,9 +38,13 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
|
||||||
SStatusRsp statusRsp = {0};
|
SStatusRsp statusRsp = {0};
|
||||||
if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
|
if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
|
||||||
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
|
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
|
||||||
pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
|
dTrace("status msg received from mnode, dnodeVer:%" PRId64 " saved:%" PRId64, statusRsp.dnodeVer,
|
||||||
dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
|
pMgmt->pData->dnodeVer);
|
||||||
dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
|
if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) {
|
||||||
|
pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
|
||||||
|
dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
|
||||||
|
dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rpcFreeCont(pRsp->pCont);
|
rpcFreeCont(pRsp->pCont);
|
||||||
tFreeSStatusRsp(&statusRsp);
|
tFreeSStatusRsp(&statusRsp);
|
||||||
|
@ -89,7 +93,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .info.ahandle = (void *)0x9527};
|
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .info.ahandle = (void *)0x9527};
|
||||||
SRpcMsg rpcRsp = {0};
|
SRpcMsg rpcRsp = {0};
|
||||||
|
|
||||||
dTrace("send status msg to mnode");
|
dTrace("send status msg to mnode, dnodeVer:%" PRId64, req.dnodeVer);
|
||||||
|
|
||||||
SEpSet epSet = {0};
|
SEpSet epSet = {0};
|
||||||
dmGetMnodeEpSet(pMgmt->pData, &epSet);
|
dmGetMnodeEpSet(pMgmt->pData, &epSet);
|
||||||
|
|
|
@ -81,6 +81,13 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
pData->dnodeId = dnodeId->valueint;
|
pData->dnodeId = dnodeId->valueint;
|
||||||
|
|
||||||
|
cJSON *dnodeVer = cJSON_GetObjectItem(root, "dnodeVer");
|
||||||
|
if (!dnodeVer || dnodeVer->type != cJSON_String) {
|
||||||
|
dError("failed to read %s since dnodeVer not found", file);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
pData->dnodeVer = atoll(dnodeVer->valuestring);
|
||||||
|
|
||||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||||
if (!clusterId || clusterId->type != cJSON_String) {
|
if (!clusterId || clusterId->type != cJSON_String) {
|
||||||
dError("failed to read %s since clusterId not found", file);
|
dError("failed to read %s since clusterId not found", file);
|
||||||
|
@ -193,6 +200,7 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"dnodeVer\": \"%" PRId64 "\",\n", pData->dnodeVer);
|
||||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pData->clusterId);
|
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pData->clusterId);
|
||||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pData->dropped);
|
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pData->dropped);
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
|
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
|
||||||
|
@ -224,30 +232,15 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
dDebug("successed to write %s", realfile);
|
dDebug("successed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
||||||
int32_t numOfEps = taosArrayGetSize(eps);
|
|
||||||
if (numOfEps <= 0) return;
|
|
||||||
|
|
||||||
taosThreadRwlockWrlock(&pData->lock);
|
taosThreadRwlockWrlock(&pData->lock);
|
||||||
|
dDebug("new dnode list get from mnode, dnodeVer:%" PRId64, pData->dnodeVer);
|
||||||
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pData->dnodeEps);
|
dmResetEps(pData, eps);
|
||||||
if (numOfEps != numOfEpsOld) {
|
dmWriteEps(pData);
|
||||||
dDebug("new dnode list get from mnode");
|
|
||||||
dmResetEps(pData, eps);
|
|
||||||
dmWriteEps(pData);
|
|
||||||
} else {
|
|
||||||
int32_t size = numOfEps * sizeof(SDnodeEp);
|
|
||||||
if (memcmp(pData->dnodeEps->pData, eps->pData, size) != 0) {
|
|
||||||
dDebug("new dnode list get from mnode");
|
|
||||||
dmResetEps(pData, eps);
|
|
||||||
dmWriteEps(pData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
taosThreadRwlockUnlock(&pData->lock);
|
taosThreadRwlockUnlock(&pData->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
|
int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
|
||||||
int64_t curMs = taosGetTimestampMs();
|
int64_t curMs = taosGetTimestampMs();
|
||||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||||
bool dnodeChanged = (statusReq.dnodeVer != dnodeVer);
|
bool dnodeChanged = (statusReq.dnodeVer == 0) || (statusReq.dnodeVer != dnodeVer);
|
||||||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||||
bool needCheck = !online || dnodeChanged || reboot;
|
bool needCheck = !online || dnodeChanged || reboot;
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
if (!online) {
|
if (!online) {
|
||||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
mInfo("dnode:%d, from offline to online", pDnode->id);
|
||||||
} else {
|
} else {
|
||||||
mDebug("dnode:%d, send dnode epset, online:%d dnode_ver:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
mDebug("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
||||||
statusReq.dnodeVer, dnodeVer, reboot);
|
statusReq.dnodeVer, dnodeVer, reboot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue