refact(cluster): node mgmt
This commit is contained in:
parent
d812206eda
commit
c57b157461
|
@ -45,7 +45,7 @@ int32_t dmReadEps(SDnode *pDnode) {
|
||||||
int32_t maxLen = 256 * 1024;
|
int32_t maxLen = 256 * 1024;
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||||
cJSON *root = NULL;
|
cJSON *root = NULL;
|
||||||
char file[PATH_MAX];
|
char file[PATH_MAX] = {0};
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
||||||
|
@ -54,7 +54,7 @@ int32_t dmReadEps(SDnode *pDnode) {
|
||||||
goto PRASE_DNODE_OVER;
|
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);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
// dDebug("file %s not exist", file);
|
// dDebug("file %s not exist", file);
|
||||||
|
@ -175,8 +175,10 @@ PRASE_DNODE_OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmWriteEps(SDnode *pDnode) {
|
int32_t dmWriteEps(SDnode *pDnode) {
|
||||||
char file[PATH_MAX];
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.dataDir, TD_DIRSEP);
|
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);
|
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
|
@ -215,9 +217,6 @@ int32_t dmWriteEps(SDnode *pDnode) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
taosMemoryFree(content);
|
taosMemoryFree(content);
|
||||||
|
|
||||||
char realfile[PATH_MAX];
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP);
|
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to rename %s since %s", file, terrstr());
|
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 len = 0;
|
||||||
int32_t maxLen = 4096;
|
int32_t maxLen = 4096;
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
if (pReq != NULL) {
|
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
|
||||||
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
|
|
||||||
for (int32_t i = 0; i < pReq->replica; ++i) {
|
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||||
SReplica *pReplica = &pReq->replicas[i];
|
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, " \"id\": %d,\n", pReplica->id);
|
||||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
||||||
len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
|
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");
|
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||||
} else {
|
} else {
|
||||||
len += snprintf(content + len, maxLen - len, " }],\n");
|
len += snprintf(content + len, maxLen - len, " }],\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,18 @@ int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) {
|
||||||
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
||||||
return -1;
|
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) {
|
static void mmClose(SMgmtWrapper *pWrapper) {
|
||||||
|
@ -172,6 +183,14 @@ static int32_t mmOpen(SMgmtWrapper *pWrapper) {
|
||||||
return -1;
|
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");
|
dInfo("mnode-mgmt is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue