提交 da6722d3 编写于 作者: S Shengliang Guan

enh: update epset on dnode info changed

上级 b09b67ac
......@@ -84,6 +84,9 @@ static void dmClearVars(SDnode *pDnode) {
pData->dnodeEps = NULL;
}
if (pData->oldDnodeEps != NULL) {
if (dmWriteEps(pData) == 0) {
dmRemoveDnodePairs(pData);
}
taosArrayDestroy(pData->oldDnodeEps);
pData->oldDnodeEps = NULL;
}
......
......@@ -169,6 +169,7 @@ void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
void dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
void dmRemoveDnodePairs(SDnodeData *pData);
#ifdef __cplusplus
}
......
......@@ -155,6 +155,7 @@ _OVER:
if (code != 0) {
dError("failed to read dnode file:%s since %s", file, terrstr());
return code;
}
if (taosArrayGetSize(pData->dnodeEps) == 0) {
......@@ -164,6 +165,10 @@ _OVER:
taosArrayPush(pData->dnodeEps, &dnodeEp);
}
if (dmReadDnodePairs(pData) != 0) {
return -1;
}
dDebug("reset dnode list on startup");
dmResetEps(pData, pData->dnodeEps);
......@@ -416,6 +421,13 @@ static int32_t dmDecodeEpPairs(SJson *pJson, SDnodeData *pData) {
return code;
}
void dmRemoveDnodePairs(SDnodeData *pData) {
char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
dInfo("dnode file:%s is removed", file);
(void)taosRemoveFile(file);
}
static int32_t dmReadDnodePairs(SDnodeData *pData) {
int32_t code = -1;
TdFilePtr pFile = NULL;
......@@ -424,12 +436,6 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
char file[PATH_MAX] = {0};
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
if (pData->oldDnodeEps == NULL) {
dError("failed to calloc dnodeEp array since %s", strerror(errno));
goto _OVER;
}
if (taosStatFile(file, NULL, NULL) < 0) {
dDebug("dnode file:%s not exist", file);
code = 0;
......@@ -470,7 +476,15 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
goto _OVER;
}
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
if (pData->oldDnodeEps == NULL) {
dError("failed to calloc dnodeEp array since %s", strerror(errno));
goto _OVER;
}
if (dmDecodeEpPairs(pJson, pData) < 0) {
taosArrayDestroy(pData->oldDnodeEps);
pData->oldDnodeEps = NULL;
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
goto _OVER;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册