refactor: update config when there's one locally
This commit is contained in:
parent
9fc7536a0b
commit
81d0798f5f
|
@ -349,7 +349,9 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
|||
}
|
||||
|
||||
// open/close --------------
|
||||
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
|
||||
SSyncInfo* pSyncInfo = (SSyncInfo*)pOldSyncInfo;
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode));
|
||||
assert(pSyncNode != NULL);
|
||||
memset(pSyncNode, 0, sizeof(SSyncNode));
|
||||
|
@ -361,11 +363,25 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
|||
sError("failed to create dir:%s since %s", pSyncInfo->path, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s/raft_config.json", pSyncInfo->path);
|
||||
if (!taosCheckExistFile(pSyncNode->configPath)) {
|
||||
// create raft config file
|
||||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s/raft_config.json", pSyncInfo->path);
|
||||
ret = syncCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), pSyncNode->configPath);
|
||||
assert(ret == 0);
|
||||
|
||||
} else {
|
||||
// update syncCfg by raft_config.json
|
||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
||||
assert(pSyncNode->pRaftCfg != NULL);
|
||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
||||
|
||||
char *seralized = raftCfg2Str(pSyncNode->pRaftCfg);
|
||||
sInfo("syncNodeOpen update config :%s", seralized);
|
||||
taosMemoryFree(seralized);
|
||||
|
||||
raftCfgClose(pSyncNode->pRaftCfg);
|
||||
}
|
||||
|
||||
// init by SSyncInfo
|
||||
|
|
|
@ -49,7 +49,7 @@ void test4() {
|
|||
logTest((char*)__FUNCTION__);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
// taosInitLog("tmp/syncTest.log", 100);
|
||||
tsAsyncLog = 0;
|
||||
|
||||
|
@ -58,6 +58,14 @@ int main() {
|
|||
test3();
|
||||
test4();
|
||||
|
||||
if (argc == 2) {
|
||||
bool bTaosDirExist = taosDirExist(argv[1]);
|
||||
printf("%s bTaosDirExist:%d \n", argv[1], bTaosDirExist);
|
||||
|
||||
bool bTaosCheckExistFile = taosCheckExistFile(argv[1]);
|
||||
printf("%s bTaosCheckExistFile:%d \n", argv[1], bTaosCheckExistFile);
|
||||
}
|
||||
|
||||
// taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue