Merge pull request #17626 from taosdata/feature/sync2-merge
fix(sync): fix coverity scan issues
This commit is contained in:
commit
011843d8f4
|
@ -45,6 +45,11 @@
|
||||||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||||
//
|
//
|
||||||
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
sError("pSyncNode is NULL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
||||||
return;
|
return;
|
||||||
|
@ -172,6 +177,7 @@ static inline int64_t syncNodeAbs64(int64_t a, int64_t b) {
|
||||||
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
||||||
return pSyncNode->quorum;
|
return pSyncNode->quorum;
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t quorum = 1; // self
|
int32_t quorum = 1; // self
|
||||||
|
|
||||||
int64_t timeNow = taosGetTimestampMs();
|
int64_t timeNow = taosGetTimestampMs();
|
||||||
|
@ -228,6 +234,7 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return quorum;
|
return quorum;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -835,7 +835,9 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
sInfo("vgId:%d, sync get retry epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn,
|
sInfo("vgId:%d, sync get retry epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn,
|
||||||
pEpSet->eps[i].port);
|
pEpSet->eps[i].port);
|
||||||
}
|
}
|
||||||
|
if (pEpSet->numOfEps > 0) {
|
||||||
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
||||||
|
}
|
||||||
sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
||||||
|
|
||||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||||
|
@ -1438,12 +1440,13 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeClose(SSyncNode* pSyncNode) {
|
void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
syncNodeEventLog(pSyncNode, "sync close");
|
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
|
||||||
|
syncNodeEventLog(pSyncNode, "sync close");
|
||||||
|
|
||||||
ret = raftStoreClose(pSyncNode->pRaftStore);
|
ret = raftStoreClose(pSyncNode->pRaftStore);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
@ -1879,6 +1882,10 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||||
|
@ -1954,6 +1961,10 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
|
inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t userStrLen = strlen(str);
|
int32_t userStrLen = strlen(str);
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
|
@ -2937,6 +2948,7 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) {
|
||||||
sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL");
|
sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
@ -3010,6 +3022,7 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||||
|
syncPingReplyDestroy(pMsgReply);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3058,6 +3071,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
||||||
|
|
||||||
// reply
|
// reply
|
||||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||||
|
syncHeartbeatReplyDestroy(pMsgReply);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3329,6 +3343,11 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ths == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ths->pFsm != NULL && ths->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
// advance commit index to sanpshot first
|
// advance commit index to sanpshot first
|
||||||
SSnapshot snapshot = {0};
|
SSnapshot snapshot = {0};
|
||||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||||
|
@ -3341,6 +3360,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
// update begin index
|
// update begin index
|
||||||
beginIndex = snapshot.lastApplyIndex + 1;
|
beginIndex = snapshot.lastApplyIndex + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
ESyncState state = flag;
|
ESyncState state = flag;
|
||||||
|
@ -3413,9 +3433,11 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
|
|
||||||
// config change finish
|
// config change finish
|
||||||
if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) {
|
if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) {
|
||||||
|
if (rpcMsg.pCont != NULL) {
|
||||||
code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry);
|
code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry);
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// execute in pre-commit
|
// execute in pre-commit
|
||||||
|
@ -3528,7 +3550,7 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->peersId)[i]);
|
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->peersId)[i]);
|
||||||
if (pSender->start) {
|
if (pSender != NULL && pSender->start) {
|
||||||
sError("sync cannot change3");
|
sError("sync cannot change3");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,32 +411,40 @@ SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen) {
|
||||||
pMsg->bytes = bytes;
|
pMsg->bytes = bytes;
|
||||||
|
|
||||||
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char* data = NULL;
|
char* data = NULL;
|
||||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ASSERT(len = pMsg->dataLen);
|
ASSERT(len == pMsg->dataLen);
|
||||||
memcpy(pMsg->data, data, len);
|
memcpy(pMsg->data, data, len);
|
||||||
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
@ -673,32 +681,40 @@ SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen) {
|
||||||
pMsg->bytes = bytes;
|
pMsg->bytes = bytes;
|
||||||
|
|
||||||
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char* data = NULL;
|
char* data = NULL;
|
||||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ASSERT(len = pMsg->dataLen);
|
ASSERT(len == pMsg->dataLen);
|
||||||
memcpy(pMsg->data, data, len);
|
memcpy(pMsg->data, data, len);
|
||||||
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
|
@ -532,7 +532,7 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index,
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
int32_t code = raftEntryCacheGetEntryP(pCache, index, &pEntry);
|
int32_t code = raftEntryCacheGetEntryP(pCache, index, &pEntry);
|
||||||
if (code == 1) {
|
if (code == 1) {
|
||||||
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
*ppEntry = taosMemoryMalloc((int64_t)(pEntry->bytes));
|
||||||
memcpy(*ppEntry, pEntry, pEntry->bytes);
|
memcpy(*ppEntry, pEntry, pEntry->bytes);
|
||||||
(*ppEntry)->rid = -1;
|
(*ppEntry)->rid = -1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -209,7 +209,8 @@ bool syncUtilCanPrint(char c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* syncUtilprintBin(char* ptr, uint32_t len) {
|
char* syncUtilprintBin(char* ptr, uint32_t len) {
|
||||||
char* s = taosMemoryMalloc(len + 1);
|
int64_t memLen = (int64_t)(len + 1);
|
||||||
|
char* s = taosMemoryMalloc(memLen);
|
||||||
ASSERT(s != NULL);
|
ASSERT(s != NULL);
|
||||||
memset(s, 0, len + 1);
|
memset(s, 0, len + 1);
|
||||||
memcpy(s, ptr, len);
|
memcpy(s, ptr, len);
|
||||||
|
|
Loading…
Reference in New Issue