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

refact(cluster): node mgmt

上级 d812206e
......@@ -45,7 +45,7 @@ int32_t dmReadEps(SDnode *pDnode) {
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;
pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
......@@ -54,7 +54,7 @@ int32_t dmReadEps(SDnode *pDnode) {
goto PRASE_DNODE_OVER;
}
snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.dataDir, 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);
......@@ -175,8 +175,10 @@ PRASE_DNODE_OVER:
}
int32_t dmWriteEps(SDnode *pDnode) {
char file[PATH_MAX];
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.dataDir, TD_DIRSEP);
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) {
......@@ -215,9 +217,6 @@ int32_t dmWriteEps(SDnode *pDnode) {
taosCloseFile(&pFile);
taosMemoryFree(content);
char realfile[PATH_MAX];
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP);
if (taosRenameFile(file, realfile) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to rename %s since %s", file, terrstr());
......
......@@ -121,22 +121,29 @@ int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deploye
int32_t len = 0;
int32_t maxLen = 4096;
char *content = taosMemoryCalloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n");
if (pReq != NULL) {
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
for (int32_t i = 0; i < pReq->replica; ++i) {
SReplica *pReplica = &pReq->replicas[i];
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\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 < pReq->replica - 1) {
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");
......
......@@ -103,7 +103,18 @@ int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) {
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
return -1;
}
return mndAlter(pMgmt->pMnode, &option);
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;
}
return 0;
}
static void mmClose(SMgmtWrapper *pWrapper) {
......@@ -172,6 +183,14 @@ static int32_t mmOpen(SMgmtWrapper *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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册