diff --git a/source/dnode/vnode/src/inc/vnodeSync.h b/source/dnode/vnode/src/inc/vnodeSync.h index 6bbdc4ae72fe7557906e8be870a25ecb32b27037..fea94c46077e08465519bab4faed2d6ffa61e0f2 100644 --- a/source/dnode/vnode/src/inc/vnodeSync.h +++ b/source/dnode/vnode/src/inc/vnodeSync.h @@ -20,7 +20,7 @@ extern "C" { #endif -int32_t vnodeSyncOpen(SVnode *pVnode); +int32_t vnodeSyncOpen(SVnode *pVnode, char *path); int32_t vnodeSyncStart(SVnode *pVnode); void vnodeSyncClose(SVnode *pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 625a2b3aedf1e5415e2451293061c35d9c092495..0f8bab7856370d7a367adff87b4e53bc036f6083 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -82,6 +82,18 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1; + // sync integration + if (tjsonAddIntegerToObject(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1; + SJson *pNodeInfoArr = tjsonCreateArray(); + tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", pNodeInfoArr); + for (int i = 0; i < pCfg->syncCfg.replicaNum; ++i) { + SJson *pNodeInfo = tjsonCreateObject(); + tjsonAddIntegerToObject(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort); + tjsonAddStringToObject(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn); + tjsonAddItemToArray(pNodeInfoArr, pNodeInfo); + } + return 0; } @@ -120,6 +132,21 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1; if (tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1; + // sync integration + if (tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1; + if (tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1; + + SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo"); + int arraySize = tjsonGetArraySize(pNodeInfoArr); + assert(arraySize == pCfg->syncCfg.replicaNum); + + for (int i = 0; i < arraySize; ++i) { + cJSON *pNodeInfo = tjsonGetArrayItem(pNodeInfoArr, i); + assert(pNodeInfo != NULL); + tjsonGetNumberValue(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort); + tjsonGetStringValue(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn); + } + return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index ae5c99ff03e46f47edb2afaf68edf2ef92536dcf..30eb9e2a42bf132d4740680834790e2e68b4c85c 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -126,7 +126,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { // sync integration // open sync - if (vnodeSyncOpen(pVnode)) { + if (vnodeSyncOpen(pVnode, dir)) { goto _err; } diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index e0e421b95c145cca80af0a63a73916d6114443d0..4db483851ec9b04112b0d9555a663c3bf71cc645 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -20,7 +20,7 @@ // sync integration -int32_t vnodeSyncOpen(SVnode *pVnode) { +int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { SSyncInfo syncInfo; syncInfo.vgId = pVnode->config.vgId; SSyncCfg *pCfg = &(syncInfo.syncCfg); @@ -28,7 +28,7 @@ int32_t vnodeSyncOpen(SVnode *pVnode) { pCfg->myIndex = pVnode->config.syncCfg.myIndex; memcpy(pCfg->nodeInfo, pVnode->config.syncCfg.nodeInfo, sizeof(pCfg->nodeInfo)); - snprintf(syncInfo.path, sizeof(syncInfo.path), "%s/sync", pVnode->path); + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s/sync", path); syncInfo.pWal = pVnode->pWal; syncInfo.pFsm = syncVnodeMakeFsm(pVnode);