未验证 提交 011843d8 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17626 from taosdata/feature/sync2-merge

fix(sync): fix coverity scan issues
...@@ -45,6 +45,11 @@ ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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);
...@@ -3007,9 +3019,10 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { ...@@ -3007,9 +3019,10 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
SMsgHead* pHead = rpcMsg.pCont; SMsgHead* pHead = rpcMsg.pCont;
pHead->contLen = htonl(pHead->contLen); pHead->contLen = htonl(pHead->contLen);
pHead->vgId = htonl(pHead->vgId); pHead->vgId = htonl(pHead->vgId);
*/ */
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) { ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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, ...@@ -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) { ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册