fix: allow the ip resolved by fqdn different between dnodes
This commit is contained in:
parent
b05c65cd47
commit
c2323db00d
|
@ -39,6 +39,7 @@ typedef enum {
|
||||||
QUEUE_MAX,
|
QUEUE_MAX,
|
||||||
} EQueueType;
|
} EQueueType;
|
||||||
|
|
||||||
|
typedef int32_t (*UpdateDnodeInfoFp)(void* pData, int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port);
|
||||||
typedef int32_t (*PutToQueueFp)(void* pMgmt, EQueueType qtype, SRpcMsg* pMsg);
|
typedef int32_t (*PutToQueueFp)(void* pMgmt, EQueueType qtype, SRpcMsg* pMsg);
|
||||||
typedef int32_t (*GetQueueSizeFp)(void* pMgmt, int32_t vgId, EQueueType qtype);
|
typedef int32_t (*GetQueueSizeFp)(void* pMgmt, int32_t vgId, EQueueType qtype);
|
||||||
typedef int32_t (*SendReqFp)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
typedef int32_t (*SendReqFp)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
|
@ -48,6 +49,7 @@ typedef void (*ReleaseHandleFp)(SRpcHandleInfo* pHandle, int8_t type);
|
||||||
typedef void (*ReportStartup)(const char* name, const char* desc);
|
typedef void (*ReportStartup)(const char* name, const char* desc);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
void* data;
|
||||||
void* mgmt;
|
void* mgmt;
|
||||||
void* clientRpc;
|
void* clientRpc;
|
||||||
PutToQueueFp putToQueueFp;
|
PutToQueueFp putToQueueFp;
|
||||||
|
@ -57,6 +59,7 @@ typedef struct {
|
||||||
RegisterBrokenLinkArgFp registerBrokenLinkArgFp;
|
RegisterBrokenLinkArgFp registerBrokenLinkArgFp;
|
||||||
ReleaseHandleFp releaseHandleFp;
|
ReleaseHandleFp releaseHandleFp;
|
||||||
ReportStartup reportStartupFp;
|
ReportStartup reportStartupFp;
|
||||||
|
UpdateDnodeInfoFp updateDnodeInfoFp;
|
||||||
} SMsgCb;
|
} SMsgCb;
|
||||||
|
|
||||||
void tmsgSetDefault(const SMsgCb* msgcb);
|
void tmsgSetDefault(const SMsgCb* msgcb);
|
||||||
|
@ -67,6 +70,7 @@ void tmsgSendRsp(SRpcMsg* pMsg);
|
||||||
void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg);
|
void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg);
|
||||||
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type);
|
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type);
|
||||||
void tmsgReportStartup(const char* name, const char* desc);
|
void tmsgReportStartup(const char* name, const char* desc);
|
||||||
|
int32_t tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,8 @@ typedef enum {
|
||||||
} ESyncState;
|
} ESyncState;
|
||||||
|
|
||||||
typedef struct SNodeInfo {
|
typedef struct SNodeInfo {
|
||||||
|
int64_t clusterId;
|
||||||
|
int32_t nodeId;
|
||||||
uint16_t nodePort;
|
uint16_t nodePort;
|
||||||
char nodeFqdn[TSDB_FQDN_LEN];
|
char nodeFqdn[TSDB_FQDN_LEN];
|
||||||
} SNodeInfo;
|
} SNodeInfo;
|
||||||
|
|
|
@ -180,6 +180,6 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("successed to write %s, deployed:%d", realfile, pOption->deploy);
|
dDebug("succeed to write %s, deployed:%d", realfile, pOption->deploy);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,6 @@ _OVER:
|
||||||
|
|
||||||
if (code != 0) return -1;
|
if (code != 0) return -1;
|
||||||
|
|
||||||
dDebug("successed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
|
dDebug("succeed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
|
||||||
return taosRenameFile(file, realfile);
|
return taosRenameFile(file, realfile);
|
||||||
}
|
}
|
|
@ -134,8 +134,10 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||||
memset(&pCfg->syncCfg.nodeInfo, 0, sizeof(pCfg->syncCfg.nodeInfo));
|
memset(&pCfg->syncCfg.nodeInfo, 0, sizeof(pCfg->syncCfg.nodeInfo));
|
||||||
for (int i = 0; i < pCreate->replica; ++i) {
|
for (int i = 0; i < pCreate->replica; ++i) {
|
||||||
SNodeInfo *pNode = &pCfg->syncCfg.nodeInfo[i];
|
SNodeInfo *pNode = &pCfg->syncCfg.nodeInfo[i];
|
||||||
|
pNode->nodeId = pCreate->replicas[i].id;
|
||||||
pNode->nodePort = pCreate->replicas[i].port;
|
pNode->nodePort = pCreate->replicas[i].port;
|
||||||
tstrncpy(pNode->nodeFqdn, pCreate->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
tstrncpy(pNode->nodeFqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||||
|
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +190,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix,
|
req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix,
|
||||||
req.hashSuffix, req.replica, req.selfIndex, req.strict);
|
req.hashSuffix, req.replica, req.selfIndex, req.strict);
|
||||||
for (int32_t i = 0; i < req.replica; ++i) {
|
for (int32_t i = 0; i < req.replica; ++i) {
|
||||||
dInfo("vgId:%d, replica:%d id:%d fqdn:%s port:%u", req.vgId, i, req.replicas[i].id, req.replicas[i].fqdn,
|
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", req.vgId, i, req.replicas[i].fqdn, req.replicas[i].port,
|
||||||
req.replicas[i].port);
|
req.replicas[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
SReplica *pReplica = &req.replicas[req.selfIndex];
|
SReplica *pReplica = &req.replicas[req.selfIndex];
|
||||||
|
|
|
@ -345,6 +345,8 @@ SMsgCb dmGetMsgcb(SDnode *pDnode) {
|
||||||
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
|
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
|
||||||
.releaseHandleFp = dmReleaseHandle,
|
.releaseHandleFp = dmReleaseHandle,
|
||||||
.reportStartupFp = dmReportStartup,
|
.reportStartupFp = dmReportStartup,
|
||||||
|
.updateDnodeInfoFp = dmUpdateDnodeInfo,
|
||||||
|
.data = &pDnode->data,
|
||||||
};
|
};
|
||||||
return msgCb;
|
return msgCb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,7 @@ void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
|
||||||
void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||||
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
|
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||||
|
int32_t dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,22 +182,25 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmWriteEps(SDnodeData *pData) {
|
int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
|
int32_t code = -1;
|
||||||
|
char *content = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
|
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
dError("failed to write %s since %s", file, strerror(errno));
|
dError("failed to open %s since %s", file, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
int32_t maxLen = 256 * 1024;
|
int32_t maxLen = 256 * 1024;
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
content = taosMemoryCalloc(1, maxLen + 1);
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
len += snprintf(content + len, maxLen - len, "{\n");
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
||||||
|
@ -221,20 +224,39 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
taosWriteFile(pFile, content, len);
|
if (taosWriteFile(pFile, content, len) != len) {
|
||||||
taosFsyncFile(pFile);
|
dError("failed to write %s since %s", file, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
dError("failed to fsync %s since %s", file, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
taosMemoryFree(content);
|
taosMemoryFreeClear(content);
|
||||||
|
|
||||||
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());
|
||||||
return -1;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
dDebug("successed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
dInfo("succeed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||||
return 0;
|
|
||||||
|
_OVER:
|
||||||
|
if (content != NULL) taosMemoryFreeClear(content);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to write file %s since %s", realfile, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
||||||
|
@ -332,3 +354,41 @@ void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) {
|
||||||
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t dmUpdateDnodeInfo(void *data, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port) {
|
||||||
|
SDnodeData *pData = data;
|
||||||
|
int32_t ret = -1;
|
||||||
|
taosThreadRwlockRdlock(&pData->lock);
|
||||||
|
if (*dnodeId <= 0) {
|
||||||
|
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pData->dnodeEps); ++i) {
|
||||||
|
SDnodeEp *pDnodeEp = taosArrayGet(pData->dnodeEps, i);
|
||||||
|
if (strcmp(pDnodeEp->ep.fqdn, fqdn) == 0 && pDnodeEp->ep.port == *port) {
|
||||||
|
dInfo("dnode:%s:%u, update dnodeId from %d to %d", fqdn, port, *dnodeId, pDnodeEp->id);
|
||||||
|
*dnodeId = pDnodeEp->id;
|
||||||
|
*clusterId = pData->clusterId;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret != 0) {
|
||||||
|
dInfo("dnode:%s:%u, failed to update dnodeId:%d", fqdn, port, *dnodeId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SDnodeEp *pDnodeEp = taosHashGet(pData->dnodeHash, dnodeId, sizeof(int32_t));
|
||||||
|
if (pDnodeEp) {
|
||||||
|
if (strcmp(pDnodeEp->ep.fqdn, fqdn) != 0) {
|
||||||
|
dInfo("dnode:%d, update port from %s to %s", *dnodeId, fqdn, pDnodeEp->ep.fqdn);
|
||||||
|
tstrncpy(fqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
|
||||||
|
}
|
||||||
|
if (pDnodeEp->ep.port != *port) {
|
||||||
|
dInfo("dnode:%d, update port from %u to %u", *dnodeId, *port, pDnodeEp->ep.port);
|
||||||
|
*port = pDnodeEp->ep.port;
|
||||||
|
}
|
||||||
|
*clusterId = pData->clusterId;
|
||||||
|
ret = 0;
|
||||||
|
} else {
|
||||||
|
dInfo("dnode:%d, failed to update dnode info", *dnodeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosThreadRwlockUnlock(&pData->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -105,7 +105,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("successed to write %s, deployed:%d", realfile, deployed);
|
dInfo("succeed to write %s, deployed:%d", realfile, deployed);
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "tmisce.h"
|
#include "tmisce.h"
|
||||||
|
#include "mndCluster.h"
|
||||||
|
|
||||||
#define MNODE_VER_NUMBER 1
|
#define MNODE_VER_NUMBER 1
|
||||||
#define MNODE_RESERVE_SIZE 64
|
#define MNODE_RESERVE_SIZE 64
|
||||||
|
@ -743,8 +744,12 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
||||||
|
|
||||||
if (objStatus == SDB_STATUS_READY || objStatus == SDB_STATUS_CREATING) {
|
if (objStatus == SDB_STATUS_READY || objStatus == SDB_STATUS_CREATING) {
|
||||||
SNodeInfo *pNode = &cfg.nodeInfo[cfg.replicaNum];
|
SNodeInfo *pNode = &cfg.nodeInfo[cfg.replicaNum];
|
||||||
tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, sizeof(pNode->nodeFqdn));
|
pNode->nodeId = pObj->pDnode->id;
|
||||||
|
pNode->clusterId = mndGetClusterId(pMnode);
|
||||||
pNode->nodePort = pObj->pDnode->port;
|
pNode->nodePort = pObj->pDnode->port;
|
||||||
|
tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||||
|
mInfo("vgId:1, ep:%s:%u dnode:%d", pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
||||||
if (pObj->pDnode->id == pMnode->selfDnodeId) {
|
if (pObj->pDnode->id == pMnode->selfDnodeId) {
|
||||||
cfg.myIndex = cfg.replicaNum;
|
cfg.myIndex = cfg.replicaNum;
|
||||||
}
|
}
|
||||||
|
@ -775,7 +780,8 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
||||||
mInfo("vgId:1, mnode sync reconfig, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex);
|
mInfo("vgId:1, mnode sync reconfig, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex);
|
||||||
for (int32_t i = 0; i < cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < cfg.replicaNum; ++i) {
|
||||||
SNodeInfo *pNode = &cfg.nodeInfo[i];
|
SNodeInfo *pNode = &cfg.nodeInfo[i];
|
||||||
mInfo("vgId:1, index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort);
|
mInfo("vgId:1, index:%d, ep:%s:%u dnode:%d cluster:%" PRId64, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId,
|
||||||
|
pNode->clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
|
#include "mndCluster.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||||
|
@ -297,9 +298,12 @@ int32_t mndInitSync(SMnode *pMnode) {
|
||||||
pCfg->myIndex = pMgmt->selfIndex;
|
pCfg->myIndex = pMgmt->selfIndex;
|
||||||
for (int32_t i = 0; i < pMgmt->numOfReplicas; ++i) {
|
for (int32_t i = 0; i < pMgmt->numOfReplicas; ++i) {
|
||||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||||
tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
pNode->nodeId = pMgmt->replicas[i].id;
|
||||||
pNode->nodePort = pMgmt->replicas[i].port;
|
pNode->nodePort = pMgmt->replicas[i].port;
|
||||||
mInfo("vgId:1, index:%d ep:%s:%u", i, pNode->nodeFqdn, pNode->nodePort);
|
tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||||
|
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||||
|
mInfo("vgId:1, index:%d ep:%s:%u dnode:%d cluster:" PRId64, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId,
|
||||||
|
pNode->clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsem_init(&pMgmt->syncSem, 0, 0);
|
tsem_init(&pMgmt->syncSem, 0, 0);
|
||||||
|
|
|
@ -125,13 +125,17 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
||||||
if (tjsonAddIntegerToObject(pJson, "vndStats.timeseries", pCfg->vndStats.numOfTimeSeries) < 0) return -1;
|
if (tjsonAddIntegerToObject(pJson, "vndStats.timeseries", pCfg->vndStats.numOfTimeSeries) < 0) return -1;
|
||||||
if (tjsonAddIntegerToObject(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries) < 0) return -1;
|
if (tjsonAddIntegerToObject(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries) < 0) return -1;
|
||||||
|
|
||||||
SJson *pNodeInfoArr = tjsonCreateArray();
|
SJson *nodeInfo = tjsonCreateArray();
|
||||||
tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", pNodeInfoArr);
|
if (nodeInfo == NULL) return -1;
|
||||||
|
if (tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", nodeInfo) < 0) return -1;
|
||||||
for (int i = 0; i < pCfg->syncCfg.replicaNum; ++i) {
|
for (int i = 0; i < pCfg->syncCfg.replicaNum; ++i) {
|
||||||
SJson *pNodeInfo = tjsonCreateObject();
|
SJson *info = tjsonCreateObject();
|
||||||
tjsonAddIntegerToObject(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort);
|
if (info == NULL) return -1;
|
||||||
tjsonAddStringToObject(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
|
if (tjsonAddIntegerToObject(info, "nodePort", pCfg->syncCfg.nodeInfo[i].nodePort) < 0) return -1;
|
||||||
tjsonAddItemToArray(pNodeInfoArr, pNodeInfo);
|
if (tjsonAddStringToObject(info, "nodeFqdn", pCfg->syncCfg.nodeInfo[i].nodeFqdn) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(info, "nodeId", pCfg->syncCfg.nodeInfo[i].nodeId) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(info, "clusterId", pCfg->syncCfg.nodeInfo[i].clusterId) < 0) return -1;
|
||||||
|
if (tjsonAddItemToArray(nodeInfo, info) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -240,15 +244,19 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
||||||
tjsonGetNumberValue(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries, code);
|
tjsonGetNumberValue(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
|
|
||||||
SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
SJson *nodeInfo = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
||||||
int arraySize = tjsonGetArraySize(pNodeInfoArr);
|
int arraySize = tjsonGetArraySize(nodeInfo);
|
||||||
assert(arraySize == pCfg->syncCfg.replicaNum);
|
if (arraySize != pCfg->syncCfg.replicaNum) return -1;
|
||||||
|
|
||||||
for (int i = 0; i < arraySize; ++i) {
|
for (int i = 0; i < arraySize; ++i) {
|
||||||
SJson *pNodeInfo = tjsonGetArrayItem(pNodeInfoArr, i);
|
SJson *info = tjsonGetArrayItem(nodeInfo, i);
|
||||||
assert(pNodeInfo != NULL);
|
if (info == NULL) return -1;
|
||||||
tjsonGetNumberValue(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort, code);
|
tjsonGetNumberValue(info, "nodePort", pCfg->syncCfg.nodeInfo[i].nodePort, code);
|
||||||
tjsonGetStringValue(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
|
if (code < 0) return -1;
|
||||||
|
tjsonGetStringValue(info, "nodeFqdn", pCfg->syncCfg.nodeInfo[i].nodeFqdn);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(info, "nodeId", pCfg->syncCfg.nodeInfo[i].nodeId, code);
|
||||||
|
tjsonGetNumberValue(info, "clusterId", pCfg->syncCfg.nodeInfo[i].clusterId, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
tjsonGetNumberValue(pJson, "tsdbPageSize", pCfg->tsdbPageSize, code);
|
tjsonGetNumberValue(pJson, "tsdbPageSize", pCfg->tsdbPageSize, code);
|
||||||
|
|
|
@ -82,8 +82,10 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
|
||||||
vInfo("vgId:%d, save config, replicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum, pCfg->myIndex);
|
vInfo("vgId:%d, save config, replicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||||
for (int i = 0; i < pReq->replica; ++i) {
|
for (int i = 0; i < pReq->replica; ++i) {
|
||||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||||
|
pNode->nodeId = pReq->replicas[i].id;
|
||||||
pNode->nodePort = pReq->replicas[i].port;
|
pNode->nodePort = pReq->replicas[i].port;
|
||||||
tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||||
|
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||||
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -578,7 +578,8 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||||
vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
|
vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||||
vInfo("vgId:%d, index:%d ep:%s:%u", pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
vInfo("vgId:%d, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort,
|
||||||
|
pNode->nodeId, pNode->clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
pVnode->sync = syncOpen(&syncInfo);
|
pVnode->sync = syncOpen(&syncInfo);
|
||||||
|
|
|
@ -53,6 +53,18 @@ typedef struct SyncPreSnapshot SyncPreSnapshot;
|
||||||
typedef struct SSyncLogBuffer SSyncLogBuffer;
|
typedef struct SSyncLogBuffer SSyncLogBuffer;
|
||||||
typedef struct SSyncLogReplMgr SSyncLogReplMgr;
|
typedef struct SSyncLogReplMgr SSyncLogReplMgr;
|
||||||
|
|
||||||
|
#define MAX_CONFIG_INDEX_COUNT 256
|
||||||
|
|
||||||
|
typedef struct SRaftCfg {
|
||||||
|
SSyncCfg cfg;
|
||||||
|
int32_t batchSize;
|
||||||
|
int8_t isStandBy;
|
||||||
|
int8_t snapshotStrategy;
|
||||||
|
SyncIndex lastConfigIndex;
|
||||||
|
int32_t configIndexCount;
|
||||||
|
SyncIndex configIndexArr[MAX_CONFIG_INDEX_COUNT];
|
||||||
|
} SRaftCfg;
|
||||||
|
|
||||||
typedef struct SRaftId {
|
typedef struct SRaftId {
|
||||||
SyncNodeId addr;
|
SyncNodeId addr;
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
|
@ -93,7 +105,7 @@ typedef struct SPeerState {
|
||||||
typedef struct SSyncNode {
|
typedef struct SSyncNode {
|
||||||
// init by SSyncInfo
|
// init by SSyncInfo
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
SRaftCfg* pRaftCfg;
|
SRaftCfg raftCfg;
|
||||||
char path[TSDB_FILENAME_LEN];
|
char path[TSDB_FILENAME_LEN];
|
||||||
char raftStorePath[TSDB_FILENAME_LEN * 2];
|
char raftStorePath[TSDB_FILENAME_LEN * 2];
|
||||||
char configPath[TSDB_FILENAME_LEN * 2];
|
char configPath[TSDB_FILENAME_LEN * 2];
|
||||||
|
@ -112,6 +124,7 @@ typedef struct SSyncNode {
|
||||||
|
|
||||||
int32_t peersNum;
|
int32_t peersNum;
|
||||||
SNodeInfo peersNodeInfo[TSDB_MAX_REPLICA];
|
SNodeInfo peersNodeInfo[TSDB_MAX_REPLICA];
|
||||||
|
SEpSet peersEpset[TSDB_MAX_REPLICA];
|
||||||
SRaftId peersId[TSDB_MAX_REPLICA];
|
SRaftId peersId[TSDB_MAX_REPLICA];
|
||||||
|
|
||||||
int32_t replicaNum;
|
int32_t replicaNum;
|
||||||
|
@ -245,7 +258,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
// utils --------------
|
// utils --------------
|
||||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
|
||||||
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
|
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
|
||||||
int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHandle** h);
|
int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHandle** h);
|
||||||
bool syncNodeHeartbeatReplyTimeout(SSyncNode* pSyncNode);
|
bool syncNodeHeartbeatReplyTimeout(SSyncNode* pSyncNode);
|
||||||
|
|
|
@ -22,64 +22,9 @@ extern "C" {
|
||||||
|
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
|
|
||||||
#define CONFIG_FILE_LEN 2048
|
int32_t syncWriteCfgFile(SSyncNode *pNode);
|
||||||
#define MAX_CONFIG_INDEX_COUNT 256
|
int32_t syncReadCfgFile(SSyncNode *pNode);
|
||||||
|
int32_t syncAddCfgIndex(SSyncNode *pNode, SyncIndex cfgIndex);
|
||||||
typedef struct SRaftCfgIndex {
|
|
||||||
TdFilePtr pFile;
|
|
||||||
char path[TSDB_FILENAME_LEN * 2];
|
|
||||||
|
|
||||||
SyncIndex configIndexArr[MAX_CONFIG_INDEX_COUNT];
|
|
||||||
int32_t configIndexCount;
|
|
||||||
} SRaftCfgIndex;
|
|
||||||
|
|
||||||
SRaftCfgIndex *raftCfgIndexOpen(const char *path);
|
|
||||||
int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex);
|
|
||||||
|
|
||||||
cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex);
|
|
||||||
int32_t raftCfgIndexCreateFile(const char *path);
|
|
||||||
|
|
||||||
typedef struct SRaftCfg {
|
|
||||||
SSyncCfg cfg;
|
|
||||||
TdFilePtr pFile;
|
|
||||||
char path[TSDB_FILENAME_LEN * 2];
|
|
||||||
int8_t isStandBy;
|
|
||||||
int32_t batchSize;
|
|
||||||
int8_t snapshotStrategy;
|
|
||||||
SyncIndex lastConfigIndex;
|
|
||||||
|
|
||||||
SyncIndex configIndexArr[MAX_CONFIG_INDEX_COUNT];
|
|
||||||
int32_t configIndexCount;
|
|
||||||
|
|
||||||
} SRaftCfg;
|
|
||||||
|
|
||||||
SRaftCfg *raftCfgOpen(const char *path);
|
|
||||||
int32_t raftCfgClose(SRaftCfg *pRaftCfg);
|
|
||||||
int32_t raftCfgPersist(SRaftCfg *pRaftCfg);
|
|
||||||
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex);
|
|
||||||
|
|
||||||
void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *str, int32_t bufLen);
|
|
||||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
|
||||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
|
||||||
|
|
||||||
cJSON *raftCfg2Json(SRaftCfg *pRaftCfg);
|
|
||||||
char *raftCfg2Str(SRaftCfg *pRaftCfg);
|
|
||||||
int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg);
|
|
||||||
int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
|
|
||||||
|
|
||||||
typedef struct SRaftCfgMeta {
|
|
||||||
int8_t isStandBy;
|
|
||||||
int32_t batchSize;
|
|
||||||
int8_t snapshotStrategy;
|
|
||||||
SyncIndex lastConfigIndex;
|
|
||||||
} SRaftCfgMeta;
|
|
||||||
|
|
||||||
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,22 +62,19 @@ extern "C" {
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port);
|
#define CID(pRaftId) (int32_t)(((pRaftId)->addr) >> 32)
|
||||||
void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port);
|
#define DID(pRaftId) (int32_t)((pRaftId)->addr)
|
||||||
|
#define SYNC_ADDR(pInfo) (int64_t)(((pInfo)->clusterId << 32) | (pInfo)->nodeId)
|
||||||
|
|
||||||
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet);
|
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet);
|
||||||
void syncUtilRaftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet);
|
|
||||||
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId);
|
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId);
|
||||||
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2);
|
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2);
|
||||||
bool syncUtilEmptyId(const SRaftId* pId);
|
bool syncUtilEmptyId(const SRaftId* pId);
|
||||||
|
|
||||||
int32_t syncUtilElectRandomMS(int32_t min, int32_t max);
|
int32_t syncUtilElectRandomMS(int32_t min, int32_t max);
|
||||||
int32_t syncUtilQuorum(int32_t replicaNum);
|
int32_t syncUtilQuorum(int32_t replicaNum);
|
||||||
cJSON* syncUtilRaftId2Json(const SRaftId* p);
|
|
||||||
const char* syncStr(ESyncState state);
|
const char* syncStr(ESyncState state);
|
||||||
char* syncUtilPrintBin(char* ptr, uint32_t len);
|
|
||||||
char* syncUtilPrintBin2(char* ptr, uint32_t len);
|
|
||||||
void syncUtilMsgHtoN(void* msg);
|
void syncUtilMsgHtoN(void* msg);
|
||||||
void syncUtilMsgNtoH(void* msg);
|
|
||||||
bool syncUtilUserPreCommit(tmsg_t msgType);
|
bool syncUtilUserPreCommit(tmsg_t msgType);
|
||||||
bool syncUtilUserRollback(tmsg_t msgType);
|
bool syncUtilUserRollback(tmsg_t msgType);
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode);
|
voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode);
|
||||||
votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode);
|
votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode);
|
||||||
|
|
||||||
pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum);
|
pSyncNode->quorum = syncUtilQuorum(pSyncNode->raftCfg.cfg.replicaNum);
|
||||||
|
|
||||||
syncNodeCandidate2Leader(pSyncNode);
|
syncNodeCandidate2Leader(pSyncNode);
|
||||||
pSyncNode->pVotesGranted->toLeader = true;
|
pSyncNode->pVotesGranted->toLeader = true;
|
||||||
|
|
|
@ -115,7 +115,7 @@ void syncHbTimerDataRemove(int64_t rid) { taosRemoveRef(gHbDataRefId, rid); }
|
||||||
SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) {
|
SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) {
|
||||||
SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid);
|
SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
sError("failed to acquire hb-timer-data from refId:%" PRId64, rid);
|
sInfo("failed to acquire hb-timer-data from refId:%" PRId64, rid);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,8 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, Sync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr set index:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, index,
|
||||||
uint16_t port;
|
DID(pRaftId), CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr set index:%" PRId64 " for %s:%d failed", pIndexMgr->pNode->vgId, index, host, port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
|
SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
|
||||||
|
@ -77,10 +75,7 @@ SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr get replmgr from dnode:%d cluster:%d failed", pNode->vgId, DID(pRaftId), CID(pRaftId));
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr get replmgr from %s:%d failed", pNode->vgId, host, port);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +87,8 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr get index from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
|
||||||
uint16_t port;
|
CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr get index from %s:%d failed", pIndexMgr->pNode->vgId, host, port);
|
|
||||||
return SYNC_INDEX_INVALID;
|
return SYNC_INDEX_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,11 +100,8 @@ void syncIndexMgrSetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr set start-time:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId,
|
||||||
uint16_t port;
|
startTime, DID(pRaftId), CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr set start-time:%" PRId64 " for %s:%d failed", pIndexMgr->pNode->vgId, startTime, host,
|
|
||||||
port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
||||||
|
@ -122,10 +112,8 @@ int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr get start-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
|
||||||
uint16_t port;
|
CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr get start-time from %s:%d failed", pIndexMgr->pNode->vgId, host, port);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,10 +125,8 @@ void syncIndexMgrSetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr set recv-time:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, recvTime,
|
||||||
uint16_t port;
|
DID(pRaftId), CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr set recv-time:%" PRId64 " for %s:%d failed", pIndexMgr->pNode->vgId, recvTime, host, port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
||||||
|
@ -151,10 +137,8 @@ int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr get recv-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
|
||||||
uint16_t port;
|
CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr get recv-time from %s:%d failed", pIndexMgr->pNode->vgId, host, port);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,10 +150,8 @@ void syncIndexMgrSetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr set term:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, term,
|
||||||
uint16_t port;
|
DID(pRaftId), CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr set term:%" PRId64 " for %s:%d failed", pIndexMgr->pNode->vgId, term, host, port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
||||||
|
@ -180,9 +162,7 @@ SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[128];
|
sError("vgId:%d, indexmgr get term from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
|
||||||
uint16_t port;
|
CID(pRaftId));
|
||||||
syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, indexmgr get term from %s:%d failed", pIndexMgr->pNode->vgId, host, port);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,15 +306,10 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
||||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
int64_t matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[i]));
|
int64_t matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[i]));
|
||||||
if (lastApplyIndex > matchIndex) {
|
if (lastApplyIndex > matchIndex) {
|
||||||
do {
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64
|
"new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64
|
||||||
" of %s:%d, do not delete wal",
|
" of dnode:%d, do not delete wal",
|
||||||
lastApplyIndex, matchIndex, host, port);
|
lastApplyIndex, matchIndex, DID(&pSyncNode->peersId[i]));
|
||||||
} while (0);
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -556,7 +551,7 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
|
||||||
(void)syncBuildLeaderTransfer(&rpcMsg, pSyncNode->vgId);
|
(void)syncBuildLeaderTransfer(&rpcMsg, pSyncNode->vgId);
|
||||||
|
|
||||||
SyncLeaderTransfer* pMsg = rpcMsg.pCont;
|
SyncLeaderTransfer* pMsg = rpcMsg.pCont;
|
||||||
pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort);
|
pMsg->newLeaderId.addr = SYNC_ADDR(&newLeader);
|
||||||
pMsg->newLeaderId.vgId = pSyncNode->vgId;
|
pMsg->newLeaderId.vgId = pSyncNode->vgId;
|
||||||
pMsg->newNodeInfo = newLeader;
|
pMsg->newNodeInfo = newLeader;
|
||||||
|
|
||||||
|
@ -622,9 +617,9 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ASSERT(rid == pSyncNode->rid);
|
ASSERT(rid == pSyncNode->rid);
|
||||||
sMeta->lastConfigIndex = pSyncNode->pRaftCfg->lastConfigIndex;
|
sMeta->lastConfigIndex = pSyncNode->raftCfg.lastConfigIndex;
|
||||||
|
|
||||||
sTrace("vgId:%d, get snapshot meta, lastConfigIndex:%" PRId64, pSyncNode->vgId, pSyncNode->pRaftCfg->lastConfigIndex);
|
sTrace("vgId:%d, get snapshot meta, lastConfigIndex:%" PRId64, pSyncNode->vgId, pSyncNode->raftCfg.lastConfigIndex);
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -637,13 +632,13 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct
|
||||||
}
|
}
|
||||||
ASSERT(rid == pSyncNode->rid);
|
ASSERT(rid == pSyncNode->rid);
|
||||||
|
|
||||||
ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1);
|
ASSERT(pSyncNode->raftCfg.configIndexCount >= 1);
|
||||||
SyncIndex lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[0];
|
SyncIndex lastIndex = (pSyncNode->raftCfg.configIndexArr)[0];
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.configIndexCount; ++i) {
|
||||||
if ((pSyncNode->pRaftCfg->configIndexArr)[i] > lastIndex &&
|
if ((pSyncNode->raftCfg.configIndexArr)[i] > lastIndex &&
|
||||||
(pSyncNode->pRaftCfg->configIndexArr)[i] <= snapshotIndex) {
|
(pSyncNode->raftCfg.configIndexArr)[i] <= snapshotIndex) {
|
||||||
lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i];
|
lastIndex = (pSyncNode->raftCfg.configIndexArr)[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sMeta->lastConfigIndex = lastIndex;
|
sMeta->lastConfigIndex = lastIndex;
|
||||||
|
@ -656,13 +651,13 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) {
|
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) {
|
||||||
ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1);
|
ASSERT(pSyncNode->raftCfg.configIndexCount >= 1);
|
||||||
SyncIndex lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[0];
|
SyncIndex lastIndex = (pSyncNode->raftCfg.configIndexArr)[0];
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.configIndexCount; ++i) {
|
||||||
if ((pSyncNode->pRaftCfg->configIndexArr)[i] > lastIndex &&
|
if ((pSyncNode->raftCfg.configIndexArr)[i] > lastIndex &&
|
||||||
(pSyncNode->pRaftCfg->configIndexArr)[i] <= snapshotLastApplyIndex) {
|
(pSyncNode->raftCfg.configIndexArr)[i] <= snapshotLastApplyIndex) {
|
||||||
lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i];
|
lastIndex = (pSyncNode->raftCfg.configIndexArr)[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sTrace("vgId:%d, sync get last config index, index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId,
|
sTrace("vgId:%d, sync get last config index, index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId,
|
||||||
|
@ -677,15 +672,15 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) return;
|
if (pSyncNode == NULL) return;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
SEp* pEp = &pEpSet->eps[i];
|
SEp* pEp = &pEpSet->eps[i];
|
||||||
tstrncpy(pEp->fqdn, pSyncNode->pRaftCfg->cfg.nodeInfo[i].nodeFqdn, TSDB_FQDN_LEN);
|
tstrncpy(pEp->fqdn, pSyncNode->raftCfg.cfg.nodeInfo[i].nodeFqdn, TSDB_FQDN_LEN);
|
||||||
pEp->port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort;
|
pEp->port = (pSyncNode->raftCfg.cfg.nodeInfo)[i].nodePort;
|
||||||
pEpSet->numOfEps++;
|
pEpSet->numOfEps++;
|
||||||
sDebug("vgId:%d, sync get retry epset, index:%d %s:%d", pSyncNode->vgId, i, pEp->fqdn, pEp->port);
|
sDebug("vgId:%d, sync get retry epset, index:%d %s:%d", pSyncNode->vgId, i, pEp->fqdn, pEp->port);
|
||||||
}
|
}
|
||||||
if (pEpSet->numOfEps > 0) {
|
if (pEpSet->numOfEps > 0) {
|
||||||
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
pEpSet->inUse = (pSyncNode->raftCfg.cfg.myIndex + 1) % pEpSet->numOfEps;
|
||||||
}
|
}
|
||||||
|
|
||||||
sInfo("vgId:%d, sync get retry epset numOfEps:%d inUse:%d", pSyncNode->vgId, pEpSet->numOfEps, pEpSet->inUse);
|
sInfo("vgId:%d, sync get retry epset numOfEps:%d inUse:%d", pSyncNode->vgId, pEpSet->numOfEps, pEpSet->inUse);
|
||||||
|
@ -849,44 +844,43 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path));
|
||||||
|
snprintf(pSyncNode->raftStorePath, sizeof(pSyncNode->raftStorePath), "%s%sraft_store.json", pSyncInfo->path,
|
||||||
|
TD_DIRSEP);
|
||||||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s%sraft_config.json", pSyncInfo->path, TD_DIRSEP);
|
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s%sraft_config.json", pSyncInfo->path, TD_DIRSEP);
|
||||||
|
|
||||||
if (!taosCheckExistFile(pSyncNode->configPath)) {
|
if (!taosCheckExistFile(pSyncNode->configPath)) {
|
||||||
// create a new raft config file
|
// create a new raft config file
|
||||||
SRaftCfgMeta meta = {0};
|
pSyncNode->raftCfg.isStandBy = pSyncInfo->isStandBy;
|
||||||
meta.isStandBy = pSyncInfo->isStandBy;
|
pSyncNode->raftCfg.snapshotStrategy = pSyncInfo->snapshotStrategy;
|
||||||
meta.snapshotStrategy = pSyncInfo->snapshotStrategy;
|
pSyncNode->raftCfg.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||||
meta.lastConfigIndex = SYNC_INDEX_INVALID;
|
pSyncNode->raftCfg.batchSize = pSyncInfo->batchSize;
|
||||||
meta.batchSize = pSyncInfo->batchSize;
|
pSyncNode->raftCfg.cfg = pSyncInfo->syncCfg;
|
||||||
if (raftCfgCreateFile(&pSyncInfo->syncCfg, meta, pSyncNode->configPath) != 0) {
|
pSyncNode->raftCfg.configIndexCount = 1;
|
||||||
sError("vgId:%d, failed to create raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
pSyncNode->raftCfg.configIndexArr[0] = -1;
|
||||||
|
|
||||||
|
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||||
|
sError("vgId:%d, failed to create sync cfg file", pSyncNode->vgId);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
if (pSyncInfo->syncCfg.replicaNum == 0) {
|
|
||||||
sInfo("vgId:%d, sync config not input", pSyncNode->vgId);
|
|
||||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// update syncCfg by raft_config.json
|
// update syncCfg by raft_config.json
|
||||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
if (syncReadCfgFile(pSyncNode) != 0) {
|
||||||
if (pSyncNode->pRaftCfg == NULL) {
|
sError("vgId:%d, failed to read sync cfg file", pSyncNode->vgId);
|
||||||
sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncInfo->syncCfg.replicaNum > 0 && syncIsConfigChanged(&pSyncNode->pRaftCfg->cfg, &pSyncInfo->syncCfg)) {
|
if (pSyncInfo->syncCfg.replicaNum > 0 && syncIsConfigChanged(&pSyncNode->raftCfg.cfg, &pSyncInfo->syncCfg)) {
|
||||||
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
||||||
pSyncNode->pRaftCfg->cfg = pSyncInfo->syncCfg;
|
pSyncNode->raftCfg.cfg = pSyncInfo->syncCfg;
|
||||||
if (raftCfgPersist(pSyncNode->pRaftCfg) != 0) {
|
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||||
sError("vgId:%d, failed to persist raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
sError("vgId:%d, failed to write sync cfg file", pSyncNode->vgId);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sInfo("vgId:%d, use sync config from raft cfg file", pSyncNode->vgId);
|
sInfo("vgId:%d, use sync config from sync cfg file", pSyncNode->vgId);
|
||||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
pSyncInfo->syncCfg = pSyncNode->raftCfg.cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
raftCfgClose(pSyncNode->pRaftCfg);
|
|
||||||
pSyncNode->pRaftCfg = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init by SSyncInfo
|
// init by SSyncInfo
|
||||||
|
@ -895,13 +889,10 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
sInfo("vgId:%d, start to open sync node, replica:%d selfIndex:%d", pSyncNode->vgId, pCfg->replicaNum, pCfg->myIndex);
|
sInfo("vgId:%d, start to open sync node, replica:%d selfIndex:%d", pSyncNode->vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
SNodeInfo* pNode = &pCfg->nodeInfo[i];
|
SNodeInfo* pNode = &pCfg->nodeInfo[i];
|
||||||
sInfo("vgId:%d, index:%d ep:%s:%u", pSyncNode->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
sInfo("vgId:%d, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, pSyncNode->vgId, i, pNode->nodeFqdn, pNode->nodePort,
|
||||||
|
pNode->nodeId, pNode->clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path));
|
|
||||||
snprintf(pSyncNode->raftStorePath, sizeof(pSyncNode->raftStorePath), "%s%sraft_store.json", pSyncInfo->path,
|
|
||||||
TD_DIRSEP);
|
|
||||||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s%sraft_config.json", pSyncInfo->path, TD_DIRSEP);
|
|
||||||
|
|
||||||
pSyncNode->pWal = pSyncInfo->pWal;
|
pSyncNode->pWal = pSyncInfo->pWal;
|
||||||
pSyncNode->msgcb = pSyncInfo->msgcb;
|
pSyncNode->msgcb = pSyncInfo->msgcb;
|
||||||
|
@ -916,26 +907,20 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// init raft config
|
|
||||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
|
||||||
if (pSyncNode->pRaftCfg == NULL) {
|
|
||||||
sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex];
|
pSyncNode->myNodeInfo = pSyncNode->raftCfg.cfg.nodeInfo[pSyncNode->raftCfg.cfg.myIndex];
|
||||||
if (!syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId)) {
|
if (!syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId)) {
|
||||||
sError("vgId:%d, failed to determine my raft member id", pSyncNode->vgId);
|
sError("vgId:%d, failed to determine my raft member id", pSyncNode->vgId);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// init peersNum, peers, peersId
|
// init peersNum, peers, peersId
|
||||||
pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1;
|
pSyncNode->peersNum = pSyncNode->raftCfg.cfg.replicaNum - 1;
|
||||||
int32_t j = 0;
|
int32_t j = 0;
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
if (i != pSyncNode->pRaftCfg->cfg.myIndex) {
|
if (i != pSyncNode->raftCfg.cfg.myIndex) {
|
||||||
pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i];
|
pSyncNode->peersNodeInfo[j] = pSyncNode->raftCfg.cfg.nodeInfo[i];
|
||||||
|
syncUtilNodeInfo2EpSet(&pSyncNode->peersNodeInfo[j], &pSyncNode->peersEpset[j]);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -947,9 +932,9 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// init replicaNum, replicasId
|
// init replicaNum, replicasId
|
||||||
pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum;
|
pSyncNode->replicaNum = pSyncNode->raftCfg.cfg.replicaNum;
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
if (!syncUtilNodeInfo2RaftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) {
|
if (!syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) {
|
||||||
sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i);
|
sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
@ -958,7 +943,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
// init raft algorithm
|
// init raft algorithm
|
||||||
pSyncNode->pFsm = pSyncInfo->pFsm;
|
pSyncNode->pFsm = pSyncInfo->pFsm;
|
||||||
pSyncInfo->pFsm = NULL;
|
pSyncInfo->pFsm = NULL;
|
||||||
pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum);
|
pSyncNode->quorum = syncUtilQuorum(pSyncNode->raftCfg.cfg.replicaNum);
|
||||||
pSyncNode->leaderCache = EMPTY_RAFT_ID;
|
pSyncNode->leaderCache = EMPTY_RAFT_ID;
|
||||||
|
|
||||||
// init life cycle outside
|
// init life cycle outside
|
||||||
|
@ -1293,8 +1278,6 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
pSyncNode->pLogStore = NULL;
|
pSyncNode->pLogStore = NULL;
|
||||||
syncLogBufferDestroy(pSyncNode->pLogBuf);
|
syncLogBufferDestroy(pSyncNode->pLogBuf);
|
||||||
pSyncNode->pLogBuf = NULL;
|
pSyncNode->pLogBuf = NULL;
|
||||||
raftCfgClose(pSyncNode->pRaftCfg);
|
|
||||||
pSyncNode->pRaftCfg = NULL;
|
|
||||||
|
|
||||||
syncNodeStopPingTimer(pSyncNode);
|
syncNodeStopPingTimer(pSyncNode);
|
||||||
syncNodeStopElectTimer(pSyncNode);
|
syncNodeStopElectTimer(pSyncNode);
|
||||||
|
@ -1330,7 +1313,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
taosMemoryFree(pSyncNode);
|
taosMemoryFree(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; }
|
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->raftCfg.snapshotStrategy; }
|
||||||
|
|
||||||
// timer control --------------
|
// timer control --------------
|
||||||
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
||||||
|
@ -1392,7 +1375,7 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms) {
|
||||||
void syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
void syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
||||||
int32_t electMS;
|
int32_t electMS;
|
||||||
|
|
||||||
if (pSyncNode->pRaftCfg->isStandBy) {
|
if (pSyncNode->raftCfg.isStandBy) {
|
||||||
electMS = TIMER_MAX_MS;
|
electMS = TIMER_MAX_MS;
|
||||||
} else {
|
} else {
|
||||||
electMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
electMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
||||||
|
@ -1461,55 +1444,46 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pNode, SRpcMsg* pMsg) {
|
||||||
SEpSet epSet;
|
SEpSet* epSet = NULL;
|
||||||
syncUtilRaftId2EpSet(destRaftId, &epSet);
|
for (int32_t i = 0; i < pNode->peersNum; ++i) {
|
||||||
|
if (destRaftId->addr == pNode->peersId[i].addr) {
|
||||||
|
epSet = &pNode->peersEpset[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pSyncNode->syncSendMSg != NULL) {
|
if (pNode->syncSendMSg != NULL && epSet != NULL) {
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
syncUtilMsgHtoN(pMsg->pCont);
|
||||||
pMsg->info.noResp = 1;
|
pMsg->info.noResp = 1;
|
||||||
return pSyncNode->syncSendMSg(&epSet, pMsg);
|
return pNode->syncSendMSg(epSet, pMsg);
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
sError("vgId:%d, sync send msg by id error, fp:%p epset:%p", pNode->vgId, pNode->syncSendMSg, epSet);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
inline bool syncNodeInConfig(SSyncNode* pNode, const SSyncCfg* pCfg) {
|
||||||
SEpSet epSet;
|
|
||||||
syncUtilNodeInfo2EpSet(nodeInfo, &epSet);
|
|
||||||
if (pSyncNode->syncSendMSg != NULL) {
|
|
||||||
// htonl
|
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
|
||||||
|
|
||||||
pMsg->info.noResp = 1;
|
|
||||||
pSyncNode->syncSendMSg(&epSet, pMsg);
|
|
||||||
} else {
|
|
||||||
sError("vgId:%d, sync send msg by info error, fp-send-msg is null", pSyncNode->vgId);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) {
|
|
||||||
bool b1 = false;
|
bool b1 = false;
|
||||||
bool b2 = false;
|
bool b2 = false;
|
||||||
|
|
||||||
for (int32_t i = 0; i < config->replicaNum; ++i) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
if (strcmp((config->nodeInfo)[i].nodeFqdn, pSyncNode->myNodeInfo.nodeFqdn) == 0 &&
|
if (strcmp(pCfg->nodeInfo[i].nodeFqdn, pNode->myNodeInfo.nodeFqdn) == 0 &&
|
||||||
(config->nodeInfo)[i].nodePort == pSyncNode->myNodeInfo.nodePort) {
|
pCfg->nodeInfo[i].nodePort == pNode->myNodeInfo.nodePort) {
|
||||||
b1 = true;
|
b1 = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < config->replicaNum; ++i) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
SRaftId raftId;
|
SRaftId raftId = {
|
||||||
raftId.addr = syncUtilAddr2U64((config->nodeInfo)[i].nodeFqdn, (config->nodeInfo)[i].nodePort);
|
.addr = SYNC_ADDR(&pCfg->nodeInfo[i]),
|
||||||
raftId.vgId = pSyncNode->vgId;
|
.vgId = pNode->vgId,
|
||||||
|
};
|
||||||
|
|
||||||
if (syncUtilSameId(&raftId, &(pSyncNode->myRaftId))) {
|
if (syncUtilSameId(&raftId, &pNode->myRaftId)) {
|
||||||
b2 = true;
|
b2 = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1533,14 +1507,14 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) {
|
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) {
|
||||||
SSyncCfg oldConfig = pSyncNode->pRaftCfg->cfg;
|
SSyncCfg oldConfig = pSyncNode->raftCfg.cfg;
|
||||||
if (!syncIsConfigChanged(&oldConfig, pNewConfig)) {
|
if (!syncIsConfigChanged(&oldConfig, pNewConfig)) {
|
||||||
sInfo("vgId:1, sync not reconfig since not changed");
|
sInfo("vgId:1, sync not reconfig since not changed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSyncNode->pRaftCfg->cfg = *pNewConfig;
|
pSyncNode->raftCfg.cfg = *pNewConfig;
|
||||||
pSyncNode->pRaftCfg->lastConfigIndex = lastConfigChangeIndex;
|
pSyncNode->raftCfg.lastConfigIndex = lastConfigChangeIndex;
|
||||||
|
|
||||||
pSyncNode->configChangeNum++;
|
pSyncNode->configChangeNum++;
|
||||||
|
|
||||||
|
@ -1563,21 +1537,18 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
}
|
}
|
||||||
|
|
||||||
// log begin config change
|
// log begin config change
|
||||||
char oldCfgStr[1024] = {0};
|
sNInfo(pSyncNode, "begin do config change, from %d to %d", pSyncNode->vgId, oldConfig.replicaNum,
|
||||||
char newCfgStr[1024] = {0};
|
pNewConfig->replicaNum);
|
||||||
syncCfg2SimpleStr(&oldConfig, oldCfgStr, sizeof(oldCfgStr));
|
|
||||||
syncCfg2SimpleStr(pNewConfig, oldCfgStr, sizeof(oldCfgStr));
|
|
||||||
sNInfo(pSyncNode, "begin do config change, from %s to %s", oldCfgStr, oldCfgStr);
|
|
||||||
|
|
||||||
if (IamInNew) {
|
if (IamInNew) {
|
||||||
pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal
|
pSyncNode->raftCfg.isStandBy = 0; // change isStandBy to normal
|
||||||
}
|
}
|
||||||
if (isDrop) {
|
if (isDrop) {
|
||||||
pSyncNode->pRaftCfg->isStandBy = 1; // set standby
|
pSyncNode->raftCfg.isStandBy = 1; // set standby
|
||||||
}
|
}
|
||||||
|
|
||||||
// add last config index
|
// add last config index
|
||||||
raftCfgAddConfigIndex(pSyncNode->pRaftCfg, lastConfigChangeIndex);
|
syncAddCfgIndex(pSyncNode, lastConfigChangeIndex);
|
||||||
|
|
||||||
if (IamInNew) {
|
if (IamInNew) {
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
@ -1594,15 +1565,16 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
}
|
}
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex];
|
pSyncNode->myNodeInfo = pSyncNode->raftCfg.cfg.nodeInfo[pSyncNode->raftCfg.cfg.myIndex];
|
||||||
syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId);
|
syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId);
|
||||||
|
|
||||||
// init peersNum, peers, peersId
|
// init peersNum, peers, peersId
|
||||||
pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1;
|
pSyncNode->peersNum = pSyncNode->raftCfg.cfg.replicaNum - 1;
|
||||||
int32_t j = 0;
|
int32_t j = 0;
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
if (i != pSyncNode->pRaftCfg->cfg.myIndex) {
|
if (i != pSyncNode->raftCfg.cfg.myIndex) {
|
||||||
pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i];
|
pSyncNode->peersNodeInfo[j] = pSyncNode->raftCfg.cfg.nodeInfo[i];
|
||||||
|
syncUtilNodeInfo2EpSet(&pSyncNode->peersNodeInfo[j], &pSyncNode->peersEpset[j]);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1611,13 +1583,13 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
}
|
}
|
||||||
|
|
||||||
// init replicaNum, replicasId
|
// init replicaNum, replicasId
|
||||||
pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum;
|
pSyncNode->replicaNum = pSyncNode->raftCfg.cfg.replicaNum;
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
syncUtilNodeInfo2RaftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]);
|
syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update quorum first
|
// update quorum first
|
||||||
pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum);
|
pSyncNode->quorum = syncUtilQuorum(pSyncNode->raftCfg.cfg.replicaNum);
|
||||||
|
|
||||||
syncIndexMgrUpdate(pSyncNode->pNextIndex, pSyncNode);
|
syncIndexMgrUpdate(pSyncNode->pNextIndex, pSyncNode);
|
||||||
syncIndexMgrUpdate(pSyncNode->pMatchIndex, pSyncNode);
|
syncIndexMgrUpdate(pSyncNode->pMatchIndex, pSyncNode);
|
||||||
|
@ -1637,11 +1609,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
bool reset = false;
|
bool reset = false;
|
||||||
for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
|
for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
|
||||||
if (syncUtilSameId(&(pSyncNode->replicasId)[i], &oldReplicasId[j]) && oldSenders[j] != NULL) {
|
if (syncUtilSameId(&(pSyncNode->replicasId)[i], &oldReplicasId[j]) && oldSenders[j] != NULL) {
|
||||||
char host[128];
|
sNTrace(pSyncNode, "snapshot sender reset for:%" PRId64 ", newIndex:%d, dnode:%d, %p",
|
||||||
uint16_t port;
|
(pSyncNode->replicasId)[i].addr, i, DID(&pSyncNode->replicasId[i]), oldSenders[j]);
|
||||||
syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode, "snapshot sender reset for: %" PRId64 ", newIndex:%d, %s:%d, %p",
|
|
||||||
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
|
|
||||||
|
|
||||||
pSyncNode->senders[i] = oldSenders[j];
|
pSyncNode->senders[i] = oldSenders[j];
|
||||||
oldSenders[j] = NULL;
|
oldSenders[j] = NULL;
|
||||||
|
@ -1651,8 +1620,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
int32_t oldreplicaIndex = pSyncNode->senders[i]->replicaIndex;
|
int32_t oldreplicaIndex = pSyncNode->senders[i]->replicaIndex;
|
||||||
pSyncNode->senders[i]->replicaIndex = i;
|
pSyncNode->senders[i]->replicaIndex = i;
|
||||||
|
|
||||||
sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex,
|
sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, dnode:%d, %p, reset:%d",
|
||||||
i, host, port, pSyncNode->senders[i], reset);
|
oldreplicaIndex, i, DID(&pSyncNode->replicasId[i]), pSyncNode->senders[i], reset);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1684,33 +1653,30 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
}
|
}
|
||||||
|
|
||||||
// persist cfg
|
// persist cfg
|
||||||
raftCfgPersist(pSyncNode->pRaftCfg);
|
syncWriteCfgFile(pSyncNode);
|
||||||
|
|
||||||
char tmpbuf[1024] = {0};
|
|
||||||
snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s",
|
|
||||||
oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr);
|
|
||||||
|
|
||||||
// change isStandBy to normal (election timeout)
|
// change isStandBy to normal (election timeout)
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
syncNodeBecomeLeader(pSyncNode, tmpbuf);
|
syncNodeBecomeLeader(pSyncNode, "");
|
||||||
|
|
||||||
// Raft 3.6.2 Committing entries from previous terms
|
// Raft 3.6.2 Committing entries from previous terms
|
||||||
syncNodeAppendNoop(pSyncNode);
|
syncNodeAppendNoop(pSyncNode);
|
||||||
// syncMaybeAdvanceCommitIndex(pSyncNode);
|
// syncMaybeAdvanceCommitIndex(pSyncNode);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
syncNodeBecomeFollower(pSyncNode, tmpbuf);
|
syncNodeBecomeFollower(pSyncNode, "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// persist cfg
|
// persist cfg
|
||||||
raftCfgPersist(pSyncNode->pRaftCfg);
|
syncWriteCfgFile(pSyncNode);
|
||||||
sNInfo(pSyncNode, "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", oldConfig.replicaNum,
|
sNInfo(pSyncNode, "do not config change from %d to %d", oldConfig.replicaNum, pNewConfig->replicaNum);
|
||||||
pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_END:
|
_END:
|
||||||
// log end config change
|
// log end config change
|
||||||
sNInfo(pSyncNode, "end do config change, from %s to %s", oldCfgStr, newCfgStr);
|
sNInfo(pSyncNode, "end do config change, from %d to %d", pSyncNode->vgId, oldConfig.replicaNum,
|
||||||
|
pNewConfig->replicaNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
// raft state change --------------
|
// raft state change --------------
|
||||||
|
@ -2889,9 +2855,10 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
|
|
||||||
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) {
|
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) {
|
||||||
for (int32_t i = 0; i < pNewCfg->replicaNum; ++i) {
|
for (int32_t i = 0; i < pNewCfg->replicaNum; ++i) {
|
||||||
SRaftId raftId;
|
SRaftId raftId = {
|
||||||
raftId.addr = syncUtilAddr2U64((pNewCfg->nodeInfo)[i].nodeFqdn, (pNewCfg->nodeInfo)[i].nodePort);
|
.addr = SYNC_ADDR(&pNewCfg->nodeInfo[i]),
|
||||||
raftId.vgId = ths->vgId;
|
.vgId = ths->vgId,
|
||||||
|
};
|
||||||
|
|
||||||
if (syncUtilSameId(&(ths->myRaftId), &raftId)) {
|
if (syncUtilSameId(&(ths->myRaftId), &raftId)) {
|
||||||
pNewCfg->myIndex = i;
|
pNewCfg->myIndex = i;
|
||||||
|
|
|
@ -652,18 +652,15 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
SRaftId destId = pMsg->srcId;
|
SRaftId destId = pMsg->srcId;
|
||||||
ASSERT(pMgr->restored == false);
|
ASSERT(pMgr->restored == false);
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
if (pMgr->endIndex == 0) {
|
if (pMgr->endIndex == 0) {
|
||||||
ASSERT(pMgr->startIndex == 0);
|
ASSERT(pMgr->startIndex == 0);
|
||||||
ASSERT(pMgr->matchIndex == 0);
|
ASSERT(pMgr->matchIndex == 0);
|
||||||
if (pMsg->matchIndex < 0) {
|
if (pMsg->matchIndex < 0) {
|
||||||
pMgr->restored = true;
|
pMgr->restored = true;
|
||||||
sInfo("vgId:%d, sync log repl mgr restored. peer: %s:%d (%" PRIx64 "), mgr: rs(%d) [%" PRId64 " %" PRId64
|
sInfo("vgId:%d, sync log repl mgr restored. peer: dnode:%d (%" PRIx64 "), mgr: rs(%d) [%" PRId64 " %" PRId64
|
||||||
", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
||||||
pNode->vgId, host, port, destId.addr, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
pNode->vgId, DID(&destId), destId.addr, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
||||||
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -678,21 +675,21 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
|
||||||
if (pMsg->success && pMsg->matchIndex == pMsg->lastSendIndex) {
|
if (pMsg->success && pMsg->matchIndex == pMsg->lastSendIndex) {
|
||||||
pMgr->matchIndex = pMsg->matchIndex;
|
pMgr->matchIndex = pMsg->matchIndex;
|
||||||
pMgr->restored = true;
|
pMgr->restored = true;
|
||||||
sInfo("vgId:%d, sync log repl mgr restored. peer: %s:%d (%" PRIx64 "), mgr: rs(%d) [%" PRId64 " %" PRId64
|
sInfo("vgId:%d, sync log repl mgr restored. peer: dnode:%d (%" PRIx64 "), mgr: rs(%d) [%" PRId64 " %" PRId64
|
||||||
", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
||||||
pNode->vgId, host, port, destId.addr, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
pNode->vgId, DID(&destId), destId.addr, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
||||||
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->success == false && pMsg->matchIndex >= pMsg->lastSendIndex) {
|
if (pMsg->success == false && pMsg->matchIndex >= pMsg->lastSendIndex) {
|
||||||
sWarn("vgId:%d, failed to rollback match index. peer: %s:%d, match index: %" PRId64 ", last sent: %" PRId64,
|
sWarn("vgId:%d, failed to rollback match index. peer: dnode:%d, match index: %" PRId64 ", last sent: %" PRId64,
|
||||||
pNode->vgId, host, port, pMsg->matchIndex, pMsg->lastSendIndex);
|
pNode->vgId, DID(&destId), pMsg->matchIndex, pMsg->lastSendIndex);
|
||||||
if (syncNodeStartSnapshot(pNode, &destId) < 0) {
|
if (syncNodeStartSnapshot(pNode, &destId) < 0) {
|
||||||
sError("vgId:%d, failed to start snapshot for peer %s:%d", pNode->vgId, host, port);
|
sError("vgId:%d, failed to start snapshot for peer dnode:%d", pNode->vgId, DID(&destId));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sInfo("vgId:%d, snapshot replication to peer %s:%d", pNode->vgId, host, port);
|
sInfo("vgId:%d, snapshot replication to peer dnode:%d", pNode->vgId, DID(&destId));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -707,10 +704,10 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
|
||||||
if (term < 0 || (term != pMsg->lastMatchTerm && (index + 1 == firstVer || index == firstVer))) {
|
if (term < 0 || (term != pMsg->lastMatchTerm && (index + 1 == firstVer || index == firstVer))) {
|
||||||
ASSERT(term >= 0 || terrno == TSDB_CODE_WAL_LOG_NOT_EXIST);
|
ASSERT(term >= 0 || terrno == TSDB_CODE_WAL_LOG_NOT_EXIST);
|
||||||
if (syncNodeStartSnapshot(pNode, &destId) < 0) {
|
if (syncNodeStartSnapshot(pNode, &destId) < 0) {
|
||||||
sError("vgId:%d, failed to start snapshot for peer %s:%d", pNode->vgId, host, port);
|
sError("vgId:%d, failed to start snapshot for peer %s:%d", pNode->vgId, DID(&destId));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sInfo("vgId:%d, snapshot replication to peer %s:%d", pNode->vgId, host, port);
|
sInfo("vgId:%d, snapshot replication to peer %s:%d", pNode->vgId, DID(&destId));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,382 +16,226 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "syncRaftCfg.h"
|
#include "syncRaftCfg.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
// file must already exist!
|
static int32_t syncEncodeSyncCfg(const void *pObj, SJson *pJson) {
|
||||||
SRaftCfgIndex *raftCfgIndexOpen(const char *path) {
|
SSyncCfg *pCfg = (SSyncCfg *)pObj;
|
||||||
SRaftCfgIndex *pRaftCfgIndex = taosMemoryMalloc(sizeof(SRaftCfg));
|
if (tjsonAddIntegerToObject(pJson, "replicaNum", pCfg->replicaNum) < 0) return -1;
|
||||||
snprintf(pRaftCfgIndex->path, sizeof(pRaftCfgIndex->path), "%s", path);
|
if (tjsonAddIntegerToObject(pJson, "myIndex", pCfg->myIndex) < 0) return -1;
|
||||||
|
|
||||||
pRaftCfgIndex->pFile = taosOpenFile(pRaftCfgIndex->path, TD_FILE_READ | TD_FILE_WRITE);
|
SJson *nodeInfo = tjsonCreateArray();
|
||||||
ASSERT(pRaftCfgIndex->pFile != NULL);
|
if (nodeInfo == NULL) return -1;
|
||||||
|
if (tjsonAddItemToObject(pJson, "nodeInfo", nodeInfo) < 0) return -1;
|
||||||
taosLSeekFile(pRaftCfgIndex->pFile, 0, SEEK_SET);
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
|
SJson *info = tjsonCreateObject();
|
||||||
int32_t bufLen = MAX_CONFIG_INDEX_COUNT * 16;
|
if (info == NULL) return -1;
|
||||||
char *pBuf = taosMemoryMalloc(bufLen);
|
if (tjsonAddIntegerToObject(info, "nodePort", pCfg->nodeInfo[i].nodePort) < 0) return -1;
|
||||||
memset(pBuf, 0, bufLen);
|
if (tjsonAddStringToObject(info, "nodeFqdn", pCfg->nodeInfo[i].nodeFqdn) < 0) return -1;
|
||||||
int64_t len = taosReadFile(pRaftCfgIndex->pFile, pBuf, bufLen);
|
if (tjsonAddIntegerToObject(info, "nodeId", pCfg->nodeInfo[i].nodeId) < 0) return -1;
|
||||||
ASSERT(len > 0);
|
if (tjsonAddIntegerToObject(info, "clusterId", pCfg->nodeInfo[i].clusterId) < 0) return -1;
|
||||||
|
if (tjsonAddItemToArray(nodeInfo, info) < 0) return -1;
|
||||||
int32_t ret = raftCfgIndexFromStr(pBuf, pRaftCfgIndex);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
taosMemoryFree(pBuf);
|
|
||||||
|
|
||||||
return pRaftCfgIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex) {
|
|
||||||
if (pRaftCfgIndex != NULL) {
|
|
||||||
int64_t ret = taosCloseFile(&(pRaftCfgIndex->pFile));
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
taosMemoryFree(pRaftCfgIndex);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex) {
|
|
||||||
ASSERT(pRaftCfgIndex != NULL);
|
|
||||||
|
|
||||||
char *s = raftCfgIndex2Str(pRaftCfgIndex);
|
|
||||||
taosLSeekFile(pRaftCfgIndex->pFile, 0, SEEK_SET);
|
|
||||||
|
|
||||||
int64_t ret = taosWriteFile(pRaftCfgIndex->pFile, s, strlen(s) + 1);
|
|
||||||
ASSERT(ret == strlen(s) + 1);
|
|
||||||
|
|
||||||
taosMemoryFree(s);
|
|
||||||
taosFsyncFile(pRaftCfgIndex->pFile);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex) {
|
|
||||||
ASSERT(pRaftCfgIndex->configIndexCount <= MAX_CONFIG_INDEX_COUNT);
|
|
||||||
(pRaftCfgIndex->configIndexArr)[pRaftCfgIndex->configIndexCount] = configIndex;
|
|
||||||
++(pRaftCfgIndex->configIndexCount);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex) {
|
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "configIndexCount", pRaftCfgIndex->configIndexCount);
|
|
||||||
cJSON *pIndexArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "configIndexArr", pIndexArr);
|
|
||||||
for (int i = 0; i < pRaftCfgIndex->configIndexCount; ++i) {
|
|
||||||
char buf64[128];
|
|
||||||
snprintf(buf64, sizeof(buf64), "%" PRId64, (pRaftCfgIndex->configIndexArr)[i]);
|
|
||||||
cJSON *pIndexObj = cJSON_CreateObject();
|
|
||||||
cJSON_AddStringToObject(pIndexObj, "index", buf64);
|
|
||||||
cJSON_AddItemToArray(pIndexArr, pIndexObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SRaftCfgIndex", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex) {
|
|
||||||
cJSON *pJson = raftCfgIndex2Json(pRaftCfgIndex);
|
|
||||||
char *serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex) {
|
|
||||||
cJSON *pJson = cJSON_GetObjectItem(pRoot, "SRaftCfgIndex");
|
|
||||||
|
|
||||||
cJSON *pJsonConfigIndexCount = cJSON_GetObjectItem(pJson, "configIndexCount");
|
|
||||||
pRaftCfgIndex->configIndexCount = cJSON_GetNumberValue(pJsonConfigIndexCount);
|
|
||||||
|
|
||||||
cJSON *pIndexArr = cJSON_GetObjectItem(pJson, "configIndexArr");
|
|
||||||
int arraySize = cJSON_GetArraySize(pIndexArr);
|
|
||||||
ASSERT(arraySize == pRaftCfgIndex->configIndexCount);
|
|
||||||
|
|
||||||
memset(pRaftCfgIndex->configIndexArr, 0, sizeof(pRaftCfgIndex->configIndexArr));
|
|
||||||
for (int i = 0; i < arraySize; ++i) {
|
|
||||||
cJSON *pIndexObj = cJSON_GetArrayItem(pIndexArr, i);
|
|
||||||
ASSERT(pIndexObj != NULL);
|
|
||||||
|
|
||||||
cJSON *pIndex = cJSON_GetObjectItem(pIndexObj, "index");
|
|
||||||
ASSERT(cJSON_IsString(pIndex));
|
|
||||||
(pRaftCfgIndex->configIndexArr)[i] = atoll(pIndex->valuestring);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex) {
|
static int32_t syncEncodeRaftCfg(const void *pObj, SJson *pJson) {
|
||||||
cJSON *pRoot = cJSON_Parse(s);
|
SRaftCfg *pCfg = (SRaftCfg *)pObj;
|
||||||
ASSERT(pRoot != NULL);
|
if (tjsonAddObject(pJson, "SSyncCfg", syncEncodeSyncCfg, (void *)&pCfg->cfg) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "isStandBy", pCfg->isStandBy) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "snapshotStrategy", pCfg->snapshotStrategy) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "batchSize", pCfg->batchSize) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "lastConfigIndex", pCfg->lastConfigIndex) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "configIndexCount", pCfg->configIndexCount) < 0) return -1;
|
||||||
|
|
||||||
int32_t ret = raftCfgIndexFromJson(pRoot, pRaftCfgIndex);
|
SJson *configIndexArr = tjsonCreateArray();
|
||||||
ASSERT(ret == 0);
|
if (configIndexArr == NULL) return -1;
|
||||||
|
if (tjsonAddItemToObject(pJson, "configIndexArr", configIndexArr) < 0) return -1;
|
||||||
|
for (int32_t i = 0; i < pCfg->configIndexCount; ++i) {
|
||||||
|
SJson *configIndex = tjsonCreateObject();
|
||||||
|
if (configIndex == NULL) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(configIndex, "index", pCfg->configIndexArr[i]) < 0) return -1;
|
||||||
|
if (tjsonAddItemToArray(configIndexArr, configIndex) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCfgIndexCreateFile(const char *path) {
|
int32_t syncWriteCfgFile(SSyncNode *pNode) {
|
||||||
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
int32_t code = -1;
|
||||||
|
char *buffer = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
const char *realfile = pNode->configPath;
|
||||||
|
SRaftCfg *pCfg = &pNode->raftCfg;
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
snprintf(file, sizeof(file), "%s.bak", realfile);
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
int32_t err = terrno;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
const char *errStr = tstrerror(err);
|
sError("failed to open sync cfg file:%s since %s", pNode->vgId, realfile, terrstr());
|
||||||
int32_t sysErr = errno;
|
goto _OVER;
|
||||||
const char *sysErrStr = strerror(errno);
|
|
||||||
sError("create raft cfg index file error, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", err, err, errStr, sysErr,
|
|
||||||
sysErrStr);
|
|
||||||
ASSERT(0);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SRaftCfgIndex raftCfgIndex;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
memset(raftCfgIndex.configIndexArr, 0, sizeof(raftCfgIndex.configIndexArr));
|
pJson = tjsonCreateObject();
|
||||||
raftCfgIndex.configIndexCount = 1;
|
if (pJson == NULL) goto _OVER;
|
||||||
raftCfgIndex.configIndexArr[0] = -1;
|
if (tjsonAddObject(pJson, "RaftCfg", syncEncodeRaftCfg, pCfg) < 0) goto _OVER;
|
||||||
|
|
||||||
char *s = raftCfgIndex2Str(&raftCfgIndex);
|
buffer = tjsonToString(pJson);
|
||||||
int64_t ret = taosWriteFile(pFile, s, strlen(s) + 1);
|
if (buffer == NULL) goto _OVER;
|
||||||
ASSERT(ret == strlen(s) + 1);
|
|
||||||
|
|
||||||
taosMemoryFree(s);
|
int32_t len = strlen(buffer);
|
||||||
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return 0;
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to rename sync cfg file:%s to %s since %s", pNode->vgId, file, realfile, terrstr());
|
||||||
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------
|
code = 0;
|
||||||
// file must already exist!
|
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d", pNode->vgId, realfile, len);
|
||||||
SRaftCfg *raftCfgOpen(const char *path) {
|
|
||||||
SRaftCfg *pCfg = taosMemoryMalloc(sizeof(SRaftCfg));
|
|
||||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s", path);
|
|
||||||
|
|
||||||
pCfg->pFile = taosOpenFile(pCfg->path, TD_FILE_READ | TD_FILE_WRITE);
|
_OVER:
|
||||||
ASSERT(pCfg->pFile != NULL);
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
taosLSeekFile(pCfg->pFile, 0, SEEK_SET);
|
if (code != 0) {
|
||||||
|
sError("failed to write sync cfg file:%s since %s", pNode->vgId, realfile, terrstr());
|
||||||
char buf[CONFIG_FILE_LEN] = {0};
|
|
||||||
int len = taosReadFile(pCfg->pFile, buf, sizeof(buf));
|
|
||||||
ASSERT(len > 0);
|
|
||||||
|
|
||||||
int32_t ret = raftCfgFromStr(buf, pCfg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
return pCfg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCfgClose(SRaftCfg *pRaftCfg) {
|
|
||||||
int64_t ret = taosCloseFile(&(pRaftCfg->pFile));
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
taosMemoryFree(pRaftCfg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgPersist(SRaftCfg *pRaftCfg) {
|
|
||||||
ASSERT(pRaftCfg != NULL);
|
|
||||||
|
|
||||||
char *s = raftCfg2Str(pRaftCfg);
|
|
||||||
taosLSeekFile(pRaftCfg->pFile, 0, SEEK_SET);
|
|
||||||
|
|
||||||
char buf[CONFIG_FILE_LEN] = {0};
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
|
|
||||||
if (strlen(s) + 1 > CONFIG_FILE_LEN) {
|
|
||||||
sError("too long config str:%s", s);
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s", s);
|
|
||||||
int64_t ret = taosWriteFile(pRaftCfg->pFile, buf, sizeof(buf));
|
|
||||||
ASSERT(ret == sizeof(buf));
|
|
||||||
|
|
||||||
// int64_t ret = taosWriteFile(pRaftCfg->pFile, s, strlen(s) + 1);
|
|
||||||
// ASSERT(ret == strlen(s) + 1);
|
|
||||||
|
|
||||||
taosMemoryFree(s);
|
|
||||||
taosFsyncFile(pRaftCfg->pFile);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex) {
|
|
||||||
ASSERT(pRaftCfg->configIndexCount <= MAX_CONFIG_INDEX_COUNT);
|
|
||||||
(pRaftCfg->configIndexArr)[pRaftCfg->configIndexCount] = configIndex;
|
|
||||||
++(pRaftCfg->configIndexCount);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pSyncCfg != NULL) {
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncCfg->replicaNum);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "myIndex", pSyncCfg->myIndex);
|
|
||||||
|
|
||||||
cJSON *pNodeInfoArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "nodeInfo", pNodeInfoArr);
|
|
||||||
for (int i = 0; i < pSyncCfg->replicaNum; ++i) {
|
|
||||||
cJSON *pNodeInfo = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pNodeInfo, "nodePort", ((pSyncCfg->nodeInfo)[i]).nodePort);
|
|
||||||
cJSON_AddStringToObject(pNodeInfo, "nodeFqdn", ((pSyncCfg->nodeInfo)[i]).nodeFqdn);
|
|
||||||
cJSON_AddItemToArray(pNodeInfoArr, pNodeInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) {
|
|
||||||
memset(pSyncCfg, 0, sizeof(SSyncCfg));
|
|
||||||
// cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg");
|
|
||||||
const cJSON *pJson = pRoot;
|
|
||||||
|
|
||||||
cJSON *pReplicaNum = cJSON_GetObjectItem(pJson, "replicaNum");
|
|
||||||
ASSERT(cJSON_IsNumber(pReplicaNum));
|
|
||||||
pSyncCfg->replicaNum = cJSON_GetNumberValue(pReplicaNum);
|
|
||||||
|
|
||||||
cJSON *pMyIndex = cJSON_GetObjectItem(pJson, "myIndex");
|
|
||||||
ASSERT(cJSON_IsNumber(pMyIndex));
|
|
||||||
pSyncCfg->myIndex = cJSON_GetNumberValue(pMyIndex);
|
|
||||||
|
|
||||||
cJSON *pNodeInfoArr = cJSON_GetObjectItem(pJson, "nodeInfo");
|
|
||||||
int arraySize = cJSON_GetArraySize(pNodeInfoArr);
|
|
||||||
ASSERT(arraySize == pSyncCfg->replicaNum);
|
|
||||||
|
|
||||||
for (int i = 0; i < arraySize; ++i) {
|
|
||||||
cJSON *pNodeInfo = cJSON_GetArrayItem(pNodeInfoArr, i);
|
|
||||||
ASSERT(pNodeInfo != NULL);
|
|
||||||
|
|
||||||
cJSON *pNodePort = cJSON_GetObjectItem(pNodeInfo, "nodePort");
|
|
||||||
ASSERT(cJSON_IsNumber(pNodePort));
|
|
||||||
((pSyncCfg->nodeInfo)[i]).nodePort = cJSON_GetNumberValue(pNodePort);
|
|
||||||
|
|
||||||
cJSON *pNodeFqdn = cJSON_GetObjectItem(pNodeInfo, "nodeFqdn");
|
|
||||||
ASSERT(cJSON_IsString(pNodeFqdn));
|
|
||||||
snprintf(((pSyncCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pSyncCfg->nodeInfo)[i]).nodeFqdn), "%s",
|
|
||||||
pNodeFqdn->valuestring);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
|
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pRoot, "SSyncCfg", syncCfg2Json(&(pRaftCfg->cfg)));
|
|
||||||
cJSON_AddNumberToObject(pRoot, "isStandBy", pRaftCfg->isStandBy);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "snapshotStrategy", pRaftCfg->snapshotStrategy);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "batchSize", pRaftCfg->batchSize);
|
|
||||||
|
|
||||||
char buf64[128];
|
|
||||||
snprintf(buf64, sizeof(buf64), "%" PRId64, pRaftCfg->lastConfigIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastConfigIndex", buf64);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "configIndexCount", pRaftCfg->configIndexCount);
|
|
||||||
cJSON *pIndexArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "configIndexArr", pIndexArr);
|
|
||||||
for (int i = 0; i < pRaftCfg->configIndexCount; ++i) {
|
|
||||||
snprintf(buf64, sizeof(buf64), "%" PRId64, (pRaftCfg->configIndexArr)[i]);
|
|
||||||
cJSON *pIndexObj = cJSON_CreateObject();
|
|
||||||
cJSON_AddStringToObject(pIndexObj, "index", buf64);
|
|
||||||
cJSON_AddItemToArray(pIndexArr, pIndexObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "RaftCfg", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *raftCfg2Str(SRaftCfg *pRaftCfg) {
|
|
||||||
cJSON *pJson = raftCfg2Json(pRaftCfg);
|
|
||||||
char *serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
|
|
||||||
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
int32_t err = terrno;
|
|
||||||
const char *errStr = tstrerror(err);
|
|
||||||
int32_t sysErr = errno;
|
|
||||||
const char *sysErrStr = strerror(errno);
|
|
||||||
sError("create raft cfg file error, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", err, err, errStr, sysErr, sysErrStr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SRaftCfg raftCfg;
|
|
||||||
raftCfg.cfg = *pCfg;
|
|
||||||
raftCfg.isStandBy = meta.isStandBy;
|
|
||||||
raftCfg.batchSize = meta.batchSize;
|
|
||||||
raftCfg.snapshotStrategy = meta.snapshotStrategy;
|
|
||||||
raftCfg.lastConfigIndex = meta.lastConfigIndex;
|
|
||||||
raftCfg.configIndexCount = 1;
|
|
||||||
memset(raftCfg.configIndexArr, 0, sizeof(raftCfg.configIndexArr));
|
|
||||||
raftCfg.configIndexArr[0] = -1;
|
|
||||||
char *s = raftCfg2Str(&raftCfg);
|
|
||||||
|
|
||||||
char buf[CONFIG_FILE_LEN] = {0};
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
ASSERT(strlen(s) + 1 <= CONFIG_FILE_LEN);
|
|
||||||
snprintf(buf, sizeof(buf), "%s", s);
|
|
||||||
int64_t ret = taosWriteFile(pFile, buf, sizeof(buf));
|
|
||||||
ASSERT(ret == sizeof(buf));
|
|
||||||
|
|
||||||
// int64_t ret = taosWriteFile(pFile, s, strlen(s) + 1);
|
|
||||||
// ASSERT(ret == strlen(s) + 1);
|
|
||||||
|
|
||||||
taosMemoryFree(s);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
|
|
||||||
// memset(pRaftCfg, 0, sizeof(SRaftCfg));
|
|
||||||
cJSON *pJson = cJSON_GetObjectItem(pRoot, "RaftCfg");
|
|
||||||
|
|
||||||
cJSON *pJsonIsStandBy = cJSON_GetObjectItem(pJson, "isStandBy");
|
|
||||||
pRaftCfg->isStandBy = cJSON_GetNumberValue(pJsonIsStandBy);
|
|
||||||
|
|
||||||
cJSON *pJsonBatchSize = cJSON_GetObjectItem(pJson, "batchSize");
|
|
||||||
pRaftCfg->batchSize = cJSON_GetNumberValue(pJsonBatchSize);
|
|
||||||
|
|
||||||
cJSON *pJsonSnapshotStrategy = cJSON_GetObjectItem(pJson, "snapshotStrategy");
|
|
||||||
pRaftCfg->snapshotStrategy = cJSON_GetNumberValue(pJsonSnapshotStrategy);
|
|
||||||
|
|
||||||
cJSON *pJsonLastConfigIndex = cJSON_GetObjectItem(pJson, "lastConfigIndex");
|
|
||||||
pRaftCfg->lastConfigIndex = atoll(cJSON_GetStringValue(pJsonLastConfigIndex));
|
|
||||||
|
|
||||||
cJSON *pJsonConfigIndexCount = cJSON_GetObjectItem(pJson, "configIndexCount");
|
|
||||||
pRaftCfg->configIndexCount = cJSON_GetNumberValue(pJsonConfigIndexCount);
|
|
||||||
|
|
||||||
cJSON *pIndexArr = cJSON_GetObjectItem(pJson, "configIndexArr");
|
|
||||||
int arraySize = cJSON_GetArraySize(pIndexArr);
|
|
||||||
ASSERT(arraySize == pRaftCfg->configIndexCount);
|
|
||||||
|
|
||||||
memset(pRaftCfg->configIndexArr, 0, sizeof(pRaftCfg->configIndexArr));
|
|
||||||
for (int i = 0; i < arraySize; ++i) {
|
|
||||||
cJSON *pIndexObj = cJSON_GetArrayItem(pIndexArr, i);
|
|
||||||
ASSERT(pIndexObj != NULL);
|
|
||||||
|
|
||||||
cJSON *pIndex = cJSON_GetObjectItem(pIndexObj, "index");
|
|
||||||
ASSERT(cJSON_IsString(pIndex));
|
|
||||||
(pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg");
|
|
||||||
int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg));
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) {
|
static int32_t syncDecodeSyncCfg(const SJson *pJson, void *pObj) {
|
||||||
cJSON *pRoot = cJSON_Parse(s);
|
SSyncCfg *pCfg = (SSyncCfg *)pObj;
|
||||||
ASSERT(pRoot != NULL);
|
int32_t code = 0;
|
||||||
|
|
||||||
int32_t ret = raftCfgFromJson(pRoot, pRaftCfg);
|
tjsonGetNumberValue(pJson, "replicaNum", pCfg->replicaNum, code);
|
||||||
ASSERT(ret == 0);
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(pJson, "myIndex", pCfg->myIndex, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
|
||||||
|
SJson *nodeInfo = tjsonGetObjectItem(pJson, "nodeInfo");
|
||||||
|
if (nodeInfo == NULL) return -1;
|
||||||
|
pCfg->replicaNum = tjsonGetArraySize(nodeInfo);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
|
SJson *info = tjsonGetArrayItem(nodeInfo, i);
|
||||||
|
if (info == NULL) return -1;
|
||||||
|
tjsonGetNumberValue(info, "nodePort", pCfg->nodeInfo[i].nodePort, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetStringValue(info, "nodeFqdn", pCfg->nodeInfo[i].nodeFqdn);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(info, "nodeId", pCfg->nodeInfo[i].nodeId, code);
|
||||||
|
tjsonGetNumberValue(info, "clusterId", pCfg->nodeInfo[i].clusterId, code);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t syncDecodeRaftCfg(const SJson *pJson, void *pObj) {
|
||||||
|
SRaftCfg *pCfg = (SRaftCfg *)pObj;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
if (tjsonToObject(pJson, "SSyncCfg", syncDecodeSyncCfg, (void *)&pCfg->cfg) < 0) return -1;
|
||||||
|
|
||||||
|
tjsonGetNumberValue(pJson, "isStandBy", pCfg->isStandBy, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(pJson, "snapshotStrategy", pCfg->snapshotStrategy, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(pJson, "batchSize", pCfg->batchSize, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(pJson, "lastConfigIndex", pCfg->lastConfigIndex, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetNumberValue(pJson, "configIndexCount", pCfg->configIndexCount, code);
|
||||||
|
|
||||||
|
SJson *configIndexArr = tjsonGetObjectItem(pJson, "configIndexArr");
|
||||||
|
if (configIndexArr == NULL) return -1;
|
||||||
|
|
||||||
|
pCfg->configIndexCount = tjsonGetArraySize(configIndexArr);
|
||||||
|
for (int32_t i = 0; i < pCfg->configIndexCount; ++i) {
|
||||||
|
SJson *configIndex = tjsonGetArrayItem(configIndexArr, i);
|
||||||
|
if (configIndex == NULL) return -1;
|
||||||
|
tjsonGetNumberValue(configIndex, "index", pCfg->configIndexArr[i], code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncReadCfgFile(SSyncNode *pNode) {
|
||||||
|
int32_t code = -1;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
char *pData = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
const char *file = pNode->configPath;
|
||||||
|
SRaftCfg *pCfg = &pNode->raftCfg;
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to open sync cfg file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t size = 0;
|
||||||
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to fstat sync cfg file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
pData = taosMemoryMalloc(size + 1);
|
||||||
|
if (pData == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
pData[size] = '\0';
|
||||||
|
|
||||||
|
pJson = tjsonParse(pData);
|
||||||
|
if (pJson == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tjsonToObject(pJson, "RaftCfg", syncDecodeRaftCfg, (void *)pCfg) < 0) {
|
||||||
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
sInfo("vgId:%d, succceed to read sync cfg file %s", pNode->vgId, file);
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pData != NULL) taosMemoryFree(pData);
|
||||||
|
if (pJson != NULL) cJSON_Delete(pJson);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncAddCfgIndex(SSyncNode *pNode, SyncIndex cfgIndex) {
|
||||||
|
SRaftCfg *pCfg = &pNode->raftCfg;
|
||||||
|
if (pCfg->configIndexCount <= MAX_CONFIG_INDEX_COUNT) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCfg->configIndexArr[pCfg->configIndexCount] = cfgIndex;
|
||||||
|
pCfg->configIndexCount++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -112,13 +112,6 @@ int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
|
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
|
||||||
|
|
||||||
uint64_t u64 = pRaftStore->voteFor.addr;
|
|
||||||
char host[128] = {0};
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pRoot, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "addr_port", port);
|
|
||||||
|
|
||||||
char *serialized = cJSON_Print(pRoot);
|
char *serialized = cJSON_Print(pRoot);
|
||||||
int len2 = strlen(serialized);
|
int len2 = strlen(serialized);
|
||||||
ASSERT(len2 < len);
|
ASSERT(len2 < len);
|
||||||
|
|
|
@ -107,10 +107,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
|
||||||
|
|
||||||
pMsg = rpcMsg.pCont;
|
pMsg = rpcMsg.pCont;
|
||||||
} else {
|
} else {
|
||||||
char host[64];
|
sNError(pSyncNode, "replicate to dnode:%d error, next-index:%" PRId64, DID(pDestId), nextIndex);
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
sNError(pSyncNode, "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,10 +168,7 @@ int32_t syncNodeReplicateOld(SSyncNode* pSyncNode) {
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
||||||
ret = syncNodeReplicateOne(pSyncNode, pDestId, true);
|
ret = syncNodeReplicateOne(pSyncNode, pDestId, true);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
char host[64];
|
sError("vgId:%d, do append entries error for %s:%d", pSyncNode->vgId, DID(pDestId));
|
||||||
int16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
sError("vgId:%d, do append entries error for %s:%d", pSyncNode->vgId, host, port);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +177,6 @@ int32_t syncNodeReplicateOld(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
|
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
|
||||||
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
||||||
int32_t ret = 0;
|
|
||||||
pMsg->destId = *destRaftId;
|
pMsg->destId = *destRaftId;
|
||||||
syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg);
|
syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -229,11 +222,7 @@ int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* dest
|
||||||
if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
|
if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
|
||||||
ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pRpcMsg);
|
ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pRpcMsg);
|
||||||
} else {
|
} else {
|
||||||
char logBuf[128];
|
sNTrace(pSyncNode, "do not repcate to dnode:%d for index:%" PRId64, DID(destRaftId), pMsg->prevLogIndex + 1);
|
||||||
char host[64];
|
|
||||||
int16_t port;
|
|
||||||
syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode, "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1);
|
|
||||||
rpcFreeCont(pRpcMsg->pCont);
|
rpcFreeCont(pRpcMsg->pCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,33 +24,35 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
|
||||||
static void syncNodeCleanConfigIndex(SSyncNode* ths) {
|
static void syncNodeCleanConfigIndex(SSyncNode* ths) {
|
||||||
|
#if 0
|
||||||
int32_t newArrIndex = 0;
|
int32_t newArrIndex = 0;
|
||||||
SyncIndex newConfigIndexArr[MAX_CONFIG_INDEX_COUNT] = {0};
|
SyncIndex newConfigIndexArr[MAX_CONFIG_INDEX_COUNT] = {0};
|
||||||
SSnapshot snapshot = {0};
|
SSnapshot snapshot = {0};
|
||||||
|
|
||||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||||
if (snapshot.lastApplyIndex != SYNC_INDEX_INVALID) {
|
if (snapshot.lastApplyIndex != SYNC_INDEX_INVALID) {
|
||||||
for (int32_t i = 0; i < ths->pRaftCfg->configIndexCount; ++i) {
|
for (int32_t i = 0; i < ths->raftCfg.configIndexCount; ++i) {
|
||||||
if (ths->pRaftCfg->configIndexArr[i] < snapshot.lastConfigIndex) {
|
if (ths->raftCfg.configIndexArr[i] < snapshot.lastConfigIndex) {
|
||||||
// pass
|
// pass
|
||||||
} else {
|
} else {
|
||||||
// save
|
// save
|
||||||
newConfigIndexArr[newArrIndex] = ths->pRaftCfg->configIndexArr[i];
|
newConfigIndexArr[newArrIndex] = ths->raftCfg.configIndexArr[i];
|
||||||
++newArrIndex;
|
++newArrIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t oldCnt = ths->pRaftCfg->configIndexCount;
|
int32_t oldCnt = ths->raftCfg.configIndexCount;
|
||||||
ths->pRaftCfg->configIndexCount = newArrIndex;
|
ths->raftCfg.configIndexCount = newArrIndex;
|
||||||
memcpy(ths->pRaftCfg->configIndexArr, newConfigIndexArr, sizeof(newConfigIndexArr));
|
memcpy(ths->raftCfg.configIndexArr, newConfigIndexArr, sizeof(newConfigIndexArr));
|
||||||
|
|
||||||
int32_t code = raftCfgPersist(ths->pRaftCfg);
|
int32_t code = syncWriteCfgFile(ths);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sNFatal(ths, "failed to persist cfg");
|
sNFatal(ths, "failed to persist cfg");
|
||||||
} else {
|
} else {
|
||||||
sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->pRaftCfg->configIndexCount);
|
sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->raftCfg.configIndexCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
||||||
|
|
|
@ -21,42 +21,23 @@
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncSnapshot.h"
|
#include "syncSnapshot.h"
|
||||||
|
|
||||||
extern void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
|
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
||||||
|
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
||||||
|
|
||||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
uint32_t hostU32 = taosGetIpv4FromFqdn(host);
|
if (i < pCfg->replicaNum - 1) {
|
||||||
if (hostU32 == (uint32_t)-1) {
|
len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
||||||
sError("failed to resolve ipv4 addr, host:%s", host);
|
} else {
|
||||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16);
|
|
||||||
return u64;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port) {
|
|
||||||
uint32_t hostU32 = (uint32_t)((u64 >> 32) & 0x00000000FFFFFFFF);
|
|
||||||
|
|
||||||
struct in_addr addr = {.s_addr = hostU32};
|
|
||||||
taosInetNtoa(addr, host, len);
|
|
||||||
*port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
|
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
|
||||||
pEpSet->inUse = 0;
|
pEpSet->inUse = 0;
|
||||||
pEpSet->numOfEps = 0;
|
pEpSet->numOfEps = 1;
|
||||||
addEpIntoEpSet(pEpSet, pInfo->nodeFqdn, pInfo->nodePort);
|
pEpSet->eps[0].port = pInfo->nodePort;
|
||||||
}
|
tstrncpy(pEpSet->eps[0].fqdn, pInfo->nodeFqdn, TSDB_FQDN_LEN);
|
||||||
|
|
||||||
void syncUtilRaftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) {
|
|
||||||
char host[TSDB_FQDN_LEN] = {0};
|
|
||||||
uint16_t port = 0;
|
|
||||||
|
|
||||||
syncUtilU642Addr(raftId->addr, host, sizeof(host), &port);
|
|
||||||
pEpSet->inUse = 0;
|
|
||||||
pEpSet->numOfEps = 0;
|
|
||||||
addEpIntoEpSet(pEpSet, host, port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
|
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
|
||||||
|
@ -69,13 +50,18 @@ bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId*
|
||||||
|
|
||||||
char ipbuf[128] = {0};
|
char ipbuf[128] = {0};
|
||||||
tinet_ntoa(ipbuf, ipv4);
|
tinet_ntoa(ipbuf, ipv4);
|
||||||
raftId->addr = syncUtilAddr2U64(ipbuf, pInfo->nodePort);
|
raftId->addr = SYNC_ADDR(pInfo);
|
||||||
raftId->vgId = vgId;
|
raftId->vgId = vgId;
|
||||||
|
|
||||||
|
sInfo("vgId:%d, sync addr:%" PRIu64 ", dnode:%d cluster:%" PRId64 " fqdn:%s ip:%s port:%u ipv4:%u", vgId,
|
||||||
|
raftId->addr, pInfo->nodeId, pInfo->clusterId, pInfo->nodeFqdn, ipbuf, pInfo->nodePort, ipv4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
|
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
|
||||||
return pId1->addr == pId2->addr && pId1->vgId == pId2->vgId;
|
if (pId1->addr == pId2->addr && pId1->vgId == pId2->vgId) return true;
|
||||||
|
if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
|
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
|
||||||
|
@ -91,89 +77,16 @@ int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
|
||||||
|
|
||||||
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
|
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
|
||||||
|
|
||||||
cJSON* syncUtilRaftId2Json(const SRaftId* p) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", p->addr);
|
|
||||||
cJSON_AddStringToObject(pRoot, "addr", u64buf);
|
|
||||||
char host[128] = {0};
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(p->addr, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pRoot, "host", host);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "port", port);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", p->vgId);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SRaftId", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool syncUtilCanPrint(char c) {
|
|
||||||
if (c >= 32 && c <= 126) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncUtilPrintBin(char* ptr, uint32_t len) {
|
|
||||||
int64_t memLen = (int64_t)(len + 1);
|
|
||||||
char* s = taosMemoryMalloc(memLen);
|
|
||||||
ASSERT(s != NULL);
|
|
||||||
memset(s, 0, len + 1);
|
|
||||||
memcpy(s, ptr, len);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < len; ++i) {
|
|
||||||
if (!syncUtilCanPrint(s[i])) {
|
|
||||||
s[i] = '.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncUtilPrintBin2(char* ptr, uint32_t len) {
|
|
||||||
uint32_t len2 = len * 4 + 1;
|
|
||||||
char* s = taosMemoryMalloc(len2);
|
|
||||||
ASSERT(s != NULL);
|
|
||||||
memset(s, 0, len2);
|
|
||||||
|
|
||||||
char* p = s;
|
|
||||||
for (int32_t i = 0; i < len; ++i) {
|
|
||||||
int32_t n = sprintf(p, "%d,", ptr[i]);
|
|
||||||
p += n;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncUtilMsgHtoN(void* msg) {
|
void syncUtilMsgHtoN(void* msg) {
|
||||||
SMsgHead* pHead = msg;
|
SMsgHead* pHead = msg;
|
||||||
pHead->contLen = htonl(pHead->contLen);
|
pHead->contLen = htonl(pHead->contLen);
|
||||||
pHead->vgId = htonl(pHead->vgId);
|
pHead->vgId = htonl(pHead->vgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilMsgNtoH(void* msg) {
|
|
||||||
SMsgHead* pHead = msg;
|
|
||||||
pHead->contLen = ntohl(pHead->contLen);
|
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool syncUtilUserPreCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
bool syncUtilUserPreCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||||
|
|
||||||
bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||||
|
|
||||||
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
|
||||||
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
|
||||||
if (i < pCfg->replicaNum - 1) {
|
|
||||||
len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
|
||||||
} else {
|
|
||||||
len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for leader
|
// for leader
|
||||||
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
int32_t len = 5;
|
int32_t len = 5;
|
||||||
|
@ -222,7 +135,7 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
||||||
if (pNode == NULL || pNode->pRaftCfg == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
int64_t currentTerm = pNode->pRaftStore->currentTerm;
|
int64_t currentTerm = pNode->pRaftStore->currentTerm;
|
||||||
|
|
||||||
// save error code, otherwise it will be overwritten
|
// save error code, otherwise it will be overwritten
|
||||||
|
@ -244,11 +157,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
int32_t cacheMiss = pNode->pLogStore->cacheMiss;
|
int32_t cacheMiss = pNode->pLogStore->cacheMiss;
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024];
|
||||||
if (pNode->pRaftCfg != NULL) {
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char peerStr[1024] = "{";
|
||||||
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
||||||
|
@ -259,8 +168,6 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
char hbTimeStr[256] = "hb:{";
|
char hbTimeStr[256] = "hb:{";
|
||||||
syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr));
|
syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr));
|
||||||
|
|
||||||
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
|
||||||
|
|
||||||
char eventLog[512]; // {0};
|
char eventLog[512]; // {0};
|
||||||
va_list argpointer;
|
va_list argpointer;
|
||||||
va_start(argpointer, format);
|
va_start(argpointer, format);
|
||||||
|
@ -275,7 +182,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
// restore error code
|
// restore error code
|
||||||
terrno = errCode;
|
terrno = errCode;
|
||||||
|
|
||||||
if (pNode != NULL && pNode->pRaftCfg != NULL) {
|
if (pNode != NULL) {
|
||||||
taosPrintLog(flags, level, dflag,
|
taosPrintLog(flags, level, dflag,
|
||||||
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", first-ver:%" PRId64
|
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", first-ver:%" PRId64
|
||||||
", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 ", snap-term:%" PRIu64
|
", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 ", snap-term:%" PRIu64
|
||||||
|
@ -286,7 +193,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->electNum,
|
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->electNum,
|
||||||
pNode->becomeLeaderNum, pNode->configChangeNum, cacheHit, cacheMiss, pNode->hbSlowNum,
|
pNode->becomeLeaderNum, pNode->configChangeNum, cacheHit, cacheMiss, pNode->hbSlowNum,
|
||||||
pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex, pNode->replicaNum,
|
pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex, pNode->replicaNum,
|
||||||
pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
||||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr, hbTimeStr,
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr, hbTimeStr,
|
||||||
hbrTimeStr);
|
hbrTimeStr);
|
||||||
}
|
}
|
||||||
|
@ -295,7 +202,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||||
const char* format, ...) {
|
const char* format, ...) {
|
||||||
SSyncNode* pNode = pSender->pSyncNode;
|
SSyncNode* pNode = pSender->pSyncNode;
|
||||||
if (pNode == NULL || pNode->pRaftCfg == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
@ -310,17 +217,11 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
||||||
}
|
}
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024];
|
||||||
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char peerStr[1024] = "{";
|
||||||
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
||||||
|
|
||||||
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
|
||||||
SRaftId destId = pNode->replicasId[pSender->replicaIndex];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
char eventLog[512]; // {0};
|
char eventLog[512]; // {0};
|
||||||
va_list argpointer;
|
va_list argpointer;
|
||||||
va_start(argpointer, format);
|
va_start(argpointer, format);
|
||||||
|
@ -330,24 +231,24 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
||||||
taosPrintLog(flags, level, dflag,
|
taosPrintLog(flags, level, dflag,
|
||||||
"vgId:%d, %s, sync:%s, {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64
|
"vgId:%d, %s, sync:%s, {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64
|
||||||
" lcindex:%" PRId64
|
" lcindex:%" PRId64
|
||||||
" seq:%d ack:%d finish:%d replica-index:%d %s:%d}"
|
" seq:%d ack:%d finish:%d replica-index:%d dnode:%d}"
|
||||||
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->snapshotParam.start,
|
pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->snapshotParam.start,
|
||||||
pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
||||||
pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex,
|
pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex,
|
||||||
host, port, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex, logLastIndex,
|
DID(&pNode->replicasId[pSender->replicaIndex]), pNode->pRaftStore->currentTerm, pNode->commitIndex,
|
||||||
pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->pRaftCfg->isStandBy,
|
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize, pNode->replicaNum,
|
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
||||||
pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
||||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||||
const char* format, ...) {
|
const char* format, ...) {
|
||||||
SSyncNode* pNode = pReceiver->pSyncNode;
|
SSyncNode* pNode = pReceiver->pSyncNode;
|
||||||
if (pNode == NULL || pNode->pRaftCfg == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
@ -362,17 +263,11 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df
|
||||||
}
|
}
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024];
|
||||||
syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char peerStr[1024] = "{";
|
||||||
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
||||||
|
|
||||||
int32_t quorum = syncNodeDynamicQuorum(pNode);
|
|
||||||
SRaftId fromId = pReceiver->fromId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(fromId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
char eventLog[512]; // {0};
|
char eventLog[512]; // {0};
|
||||||
va_list argpointer;
|
va_list argpointer;
|
||||||
va_start(argpointer, format);
|
va_start(argpointer, format);
|
||||||
|
@ -381,19 +276,19 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df
|
||||||
|
|
||||||
taosPrintLog(flags, level, dflag,
|
taosPrintLog(flags, level, dflag,
|
||||||
"vgId:%d, %s, sync:%s,"
|
"vgId:%d, %s, sync:%s,"
|
||||||
" {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from:%s:%d s-param:%" PRId64
|
" {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from dnode:%d s-param:%" PRId64
|
||||||
" e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
" e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
||||||
"}"
|
"}"
|
||||||
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->start, pReceiver->ack,
|
pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->start, pReceiver->ack,
|
||||||
pReceiver->term, pReceiver->startTime, host, port, pReceiver->snapshotParam.start,
|
pReceiver->term, pReceiver->startTime, DID(&pReceiver->fromId), pReceiver->snapshotParam.start,
|
||||||
pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm,
|
pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm,
|
||||||
pReceiver->snapshot.lastConfigIndex, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex,
|
pReceiver->snapshot.lastConfigIndex, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex,
|
||||||
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
pNode->pRaftCfg->isStandBy, pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize,
|
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
||||||
pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
||||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,56 +303,37 @@ void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char*
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
||||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-append-entries-reply to %s:%d, {term:%" PRId64 ", pterm:%" PRId64
|
"send sync-append-entries-reply to dnode:%d, {term:%" PRId64 ", pterm:%" PRId64
|
||||||
", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
|
", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
|
||||||
host, port, pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
|
DID(&pMsg->destId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-append-entries-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64
|
"recv sync-append-entries-reply from dnode:%d {term:%" PRId64 ", pterm:%" PRId64
|
||||||
", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
|
", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
|
||||||
host, port, pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
|
DID(&pMsg->srcId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
|
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
|
||||||
int64_t execTime) {
|
int64_t execTime) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
if (printX) {
|
if (printX) {
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
"send sync-heartbeat to dnode:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
||||||
"}, x",
|
"}, x",
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp);
|
DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp);
|
||||||
} else {
|
} else {
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
"send sync-heartbeat to dnode:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
||||||
"}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
|
"}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, timerElapsed, execTime);
|
DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, timerElapsed,
|
||||||
|
execTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,183 +341,109 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64
|
||||||
if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
|
if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
|
||||||
pSyncNode->hbSlowNum++;
|
pSyncNode->hbSlowNum++;
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
sNInfo(pSyncNode,
|
sNInfo(pSyncNode,
|
||||||
"recv sync-heartbeat from %s:%d slow {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
"recv sync-heartbeat from dnode:%d slow {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64
|
||||||
"}, %s, net elapsed:%" PRId64,
|
", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
|
DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-heartbeat from %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
"recv sync-heartbeat from dnode:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", ts:%" PRId64
|
||||||
"}, %s, net elapsed:%" PRId64,
|
"}, %s, net elapsed:%" PRId64,
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
|
DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
sNTrace(pSyncNode, "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s",
|
||||||
|
DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s);
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s", host, port,
|
|
||||||
pMsg->term, pMsg->timeStamp, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t timeDiff, const char* s) {
|
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t timeDiff, const char* s) {
|
||||||
if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
|
if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
|
||||||
pSyncNode->hbrSlowNum++;
|
pSyncNode->hbrSlowNum++;
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-heartbeat-reply from %s:%d slow {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
|
"recv sync-heartbeat-reply from dnode:%d slow {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
|
||||||
host, port, pMsg->term, pMsg->timeStamp, s, timeDiff);
|
DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, s, timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-heartbeat-reply from %s:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64, host,
|
"recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
|
||||||
port, pMsg->term, pMsg->timeStamp, s, timeDiff);
|
DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, s, timeDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_DEBUG)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNDebug(pSyncNode,
|
sNDebug(pSyncNode,
|
||||||
"send sync-snapshot-send to %s:%u, %s, seq:%d, term:%" PRId64 ", begin:%" PRId64 ", end:%" PRId64
|
"send sync-snapshot-send to dnode:%d, %s, seq:%d, term:%" PRId64 ", begin:%" PRId64 ", end:%" PRId64
|
||||||
", lterm:%" PRId64 ", stime:%" PRId64,
|
", lterm:%" PRId64 ", stime:%" PRId64,
|
||||||
host, port, s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime);
|
DID(&pMsg->destId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
|
||||||
|
pMsg->startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_DEBUG)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNDebug(pSyncNode,
|
sNDebug(pSyncNode,
|
||||||
"recv sync-snapshot-send from %s:%u, %s, seq:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
"recv sync-snapshot-send from dnode:%d, %s, seq:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
||||||
", lterm:%" PRId64 ", stime:%" PRId64 ", len:%u",
|
", lterm:%" PRId64 ", stime:%" PRId64 ", len:%u",
|
||||||
host, port, s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime,
|
DID(&pMsg->srcId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
|
||||||
pMsg->dataLen);
|
pMsg->startTime, pMsg->dataLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_DEBUG)) return;
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNDebug(pSyncNode,
|
sNDebug(pSyncNode,
|
||||||
"send sync-snapshot-rsp to %s:%u, %s, ack:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
"send sync-snapshot-rsp to dnode:%d, %s, ack:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
||||||
", lterm:%" PRId64 ", stime:%" PRId64,
|
", lterm:%" PRId64 ", stime:%" PRId64,
|
||||||
host, port, s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime);
|
DID(&pMsg->destId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
|
||||||
|
pMsg->startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_DEBUG)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNDebug(pSyncNode,
|
sNDebug(pSyncNode,
|
||||||
"recv sync-snapshot-rsp from %s:%u, %s, ack:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
"recv sync-snapshot-rsp from dnode:%d, %s, ack:%d, term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64
|
||||||
", lterm:%" PRId64 ", stime:%" PRId64,
|
", lterm:%" PRId64 ", stime:%" PRId64,
|
||||||
host, port, s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime);
|
DID(&pMsg->srcId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
|
||||||
|
pMsg->startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-append-entries from %s:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
"recv sync-append-entries from dnode:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s",
|
", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
DID(&pMsg->srcId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
||||||
pMsg->dataLen, s);
|
pMsg->dataLen, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||||
if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-append-entries to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
"send sync-append-entries to dnode:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", lsend-index:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
", lsend-index:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1), pMsg->commitIndex,
|
DID(&pMsg->destId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1),
|
||||||
pMsg->dataLen, s);
|
pMsg->commitIndex, pMsg->dataLen, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, int32_t voteGranted, const char* s) {
|
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, int32_t voteGranted, const char* s) {
|
||||||
// if (!(sDebugFlag & DEBUG_TRACE)) return;
|
|
||||||
|
|
||||||
char logBuf[256];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
if (voteGranted == -1) {
|
if (voteGranted == -1) {
|
||||||
sNInfo(pSyncNode,
|
sNInfo(pSyncNode,
|
||||||
"recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s", host,
|
"recv sync-request-vote from dnode:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||||
port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
DID(&pMsg->srcId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||||
} else {
|
} else {
|
||||||
sNInfo(pSyncNode,
|
sNInfo(pSyncNode,
|
||||||
"recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, granted:%d",
|
"recv sync-request-vote from dnode:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64
|
||||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, voteGranted);
|
"}, granted:%d",
|
||||||
|
DID(&pMsg->srcId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, voteGranted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s) {
|
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s) {
|
||||||
// if (!(sDebugFlag & DEBUG_TRACE)) return;
|
sNInfo(pNode, "send sync-request-vote to dnode:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||||
|
DID(&pMsg->destId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
sNInfo(pNode, "send sync-request-vote to %s:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s", host,
|
|
||||||
port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||||
// if (!(sDebugFlag & DEBUG_TRACE)) return;
|
sNInfo(pSyncNode, "recv sync-request-vote-reply from dnode:%d {term:%" PRId64 ", grant:%d}, %s", DID(&pMsg->srcId),
|
||||||
|
pMsg->term, pMsg->voteGranted, s);
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
sNInfo(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
|
||||||
pMsg->voteGranted, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||||
// if (!(sDebugFlag & DEBUG_TRACE)) return;
|
sNInfo(pSyncNode, "send sync-request-vote-reply to dnode:%d {term:%" PRId64 ", grant:%d}, %s", DID(&pMsg->destId),
|
||||||
|
pMsg->term, pMsg->voteGranted, s);
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
|
||||||
sNInfo(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
|
||||||
pMsg->voteGranted, s);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,3 +70,47 @@ int main(int argc, char** argv) {
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool syncUtilCanPrint(char c) {
|
||||||
|
if (c >= 32 && c <= 126) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncUtilPrintBin(char* ptr, uint32_t len) {
|
||||||
|
int64_t memLen = (int64_t)(len + 1);
|
||||||
|
char* s = taosMemoryMalloc(memLen);
|
||||||
|
ASSERT(s != NULL);
|
||||||
|
memset(s, 0, len + 1);
|
||||||
|
memcpy(s, ptr, len);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < len; ++i) {
|
||||||
|
if (!syncUtilCanPrint(s[i])) {
|
||||||
|
s[i] = '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncUtilPrintBin2(char* ptr, uint32_t len) {
|
||||||
|
uint32_t len2 = len * 4 + 1;
|
||||||
|
char* s = taosMemoryMalloc(len2);
|
||||||
|
ASSERT(s != NULL);
|
||||||
|
memset(s, 0, len2);
|
||||||
|
|
||||||
|
char* p = s;
|
||||||
|
for (int32_t i = 0; i < len; ++i) {
|
||||||
|
int32_t n = sprintf(p, "%d,", ptr[i]);
|
||||||
|
p += n;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncUtilMsgNtoH(void* msg) {
|
||||||
|
SMsgHead* pHead = msg;
|
||||||
|
pHead->contLen = ntohl(pHead->contLen);
|
||||||
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
|
}
|
||||||
|
|
|
@ -200,8 +200,8 @@ inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
||||||
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
||||||
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum,
|
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->raftCfg.isStandBy, pSyncNode->replicaNum,
|
||||||
pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
pSyncNode->raftCfg.lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
int32_t syncNodePingAll(SSyncNode* pSyncNode) {
|
int32_t syncNodePingAll(SSyncNode* pSyncNode) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.replicaNum; ++i) {
|
||||||
SRaftId* destId = &(pSyncNode->replicasId[i]);
|
SRaftId* destId = &(pSyncNode->replicasId[i]);
|
||||||
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
||||||
ret = syncNodePing(pSyncNode, destId, pMsg);
|
ret = syncNodePing(pSyncNode, destId, pMsg);
|
||||||
|
|
|
@ -24,7 +24,6 @@ static SMsgCb defaultMsgCb;
|
||||||
void tmsgSetDefault(const SMsgCb* msgcb) { defaultMsgCb = *msgcb; }
|
void tmsgSetDefault(const SMsgCb* msgcb) { defaultMsgCb = *msgcb; }
|
||||||
|
|
||||||
int32_t tmsgPutToQueue(const SMsgCb* msgcb, EQueueType qtype, SRpcMsg* pMsg) {
|
int32_t tmsgPutToQueue(const SMsgCb* msgcb, EQueueType qtype, SRpcMsg* pMsg) {
|
||||||
ASSERT(msgcb != NULL);
|
|
||||||
int32_t code = (*msgcb->putToQueueFp)(msgcb->mgmt, qtype, pMsg);
|
int32_t code = (*msgcb->putToQueueFp)(msgcb->mgmt, qtype, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
@ -59,3 +58,7 @@ void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg) { (*defaultMsgCb.registerBrokenLin
|
||||||
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type) { (*defaultMsgCb.releaseHandleFp)(pHandle, type); }
|
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type) { (*defaultMsgCb.releaseHandleFp)(pHandle, type); }
|
||||||
|
|
||||||
void tmsgReportStartup(const char* name, const char* desc) { (*defaultMsgCb.reportStartupFp)(name, desc); }
|
void tmsgReportStartup(const char* name, const char* desc) { (*defaultMsgCb.reportStartupFp)(name, desc); }
|
||||||
|
|
||||||
|
int32_t tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port) {
|
||||||
|
return (*defaultMsgCb.updateDnodeInfoFp)(defaultMsgCb.data, dnodeId, clusterId, fqdn, port);
|
||||||
|
}
|
||||||
|
|
|
@ -640,7 +640,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
|
|
||||||
int32_t taosFsyncFile(TdFilePtr pFile) {
|
int32_t taosFsyncFile(TdFilePtr pFile) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this implementation is WRONG
|
// this implementation is WRONG
|
||||||
|
|
|
@ -181,7 +181,7 @@ typedef struct _script_t {
|
||||||
extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
extern SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
||||||
extern SCommand simCmdList[];
|
extern SCommand simCmdList[];
|
||||||
extern int32_t simScriptPos;
|
extern int32_t simScriptPos;
|
||||||
extern int32_t simScriptSucced;
|
extern int32_t simScriptSucceed;
|
||||||
extern int32_t simDebugFlag;
|
extern int32_t simDebugFlag;
|
||||||
extern char simScriptDir[];
|
extern char simScriptDir[];
|
||||||
extern bool abortExecution;
|
extern bool abortExecution;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
|
||||||
SCommand simCmdList[SIM_CMD_END];
|
SCommand simCmdList[SIM_CMD_END];
|
||||||
int32_t simScriptPos = -1;
|
int32_t simScriptPos = -1;
|
||||||
int32_t simScriptSucced = 0;
|
int32_t simScriptSucceed = 0;
|
||||||
int32_t simDebugFlag = 143;
|
int32_t simDebugFlag = 143;
|
||||||
void simCloseTaosdConnect(SScript *script);
|
void simCloseTaosdConnect(SScript *script);
|
||||||
char simScriptDir[PATH_MAX] = {0};
|
char simScriptDir[PATH_MAX] = {0};
|
||||||
|
@ -88,13 +88,13 @@ SScript *simProcessCallOver(SScript *script) {
|
||||||
}
|
}
|
||||||
|
|
||||||
simCloseTaosdConnect(script);
|
simCloseTaosdConnect(script);
|
||||||
simScriptSucced++;
|
simScriptSucceed++;
|
||||||
simScriptPos--;
|
simScriptPos--;
|
||||||
simFreeScript(script);
|
simFreeScript(script);
|
||||||
|
|
||||||
if (simScriptPos == -1 && simExecSuccess) {
|
if (simScriptPos == -1 && simExecSuccess) {
|
||||||
simInfo("----------------------------------------------------------------------");
|
simInfo("----------------------------------------------------------------------");
|
||||||
simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced);
|
simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucceed);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue