fix(sync): add detail log flag

This commit is contained in:
Minghao Li 2022-06-09 11:18:48 +08:00
parent 89e2c2d47a
commit d81f5e9f77
5 changed files with 97 additions and 58 deletions

View File

@ -497,30 +497,39 @@ static int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry) {
// prevLogIndex == -1 // prevLogIndex == -1
static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries* pMsg) { static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries* pMsg) {
if (pMsg->prevLogIndex == SYNC_INDEX_INVALID) { if (pMsg->prevLogIndex == SYNC_INDEX_INVALID) {
if (gRaftDetailLog) {
sTrace("syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld", pMsg->prevLogIndex); sTrace("syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld", pMsg->prevLogIndex);
}
return true; return true;
} }
SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode);
if (pMsg->prevLogIndex > myLastIndex) { if (pMsg->prevLogIndex > myLastIndex) {
if (gRaftDetailLog) {
sTrace("syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld", pMsg->prevLogIndex, sTrace("syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld", pMsg->prevLogIndex,
myLastIndex); myLastIndex);
}
return false; return false;
} }
SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1);
if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) { if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) {
if (gRaftDetailLog) {
sTrace( sTrace(
"syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, " "syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, "
"myPreLogTerm:%lu", "myPreLogTerm:%lu",
pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm); pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm);
}
return true; return true;
} }
if (gRaftDetailLog) {
sTrace( sTrace(
"syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, " "syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, "
"myPreLogTerm:%lu", "myPreLogTerm:%lu",
pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm); pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm);
}
return false; return false;
} }

View File

@ -146,10 +146,12 @@ void syncIndexMgrLog(SSyncIndexMgr *pObj) {
} }
void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) { void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) {
if (gRaftDetailLog) {
char *serialized = syncIndexMgr2Str(pObj); char *serialized = syncIndexMgr2Str(pObj);
sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term) { void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term) {
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {

View File

@ -852,10 +852,12 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRp
SEpSet epSet; SEpSet epSet;
syncUtilraftId2EpSet(destRaftId, &epSet); syncUtilraftId2EpSet(destRaftId, &epSet);
if (pSyncNode->FpSendMsg != NULL) { if (pSyncNode->FpSendMsg != NULL) {
if (gRaftDetailLog) {
char* JsonStr = syncRpcMsg2Str(pMsg); char* JsonStr = syncRpcMsg2Str(pMsg);
syncUtilJson2Line(JsonStr); syncUtilJson2Line(JsonStr);
sTrace("sync send msg, vgId:%d, type:%d, msg:%s", pSyncNode->vgId, pMsg->msgType, JsonStr); sTrace("sync send msg, vgId:%d, type:%d, msg:%s", pSyncNode->vgId, pMsg->msgType, JsonStr);
taosMemoryFree(JsonStr); taosMemoryFree(JsonStr);
}
// htonl // htonl
syncUtilMsgHtoN(pMsg->pCont); syncUtilMsgHtoN(pMsg->pCont);

View File

@ -145,10 +145,12 @@ void syncRpcMsgLog(SRpcMsg* pMsg) {
} }
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncRpcMsg2Str(pMsg); char* serialized = syncRpcMsg2Str(pMsg);
sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncTimeout---- // ---- message process SyncTimeout----
SyncTimeout* syncTimeoutBuild() { SyncTimeout* syncTimeoutBuild() {
@ -274,10 +276,12 @@ void syncTimeoutLog(const SyncTimeout* pMsg) {
} }
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) { void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncTimeout2Str(pMsg); char* serialized = syncTimeout2Str(pMsg);
sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncPing---- // ---- message process SyncPing----
SyncPing* syncPingBuild(uint32_t dataLen) { SyncPing* syncPingBuild(uint32_t dataLen) {
@ -534,10 +538,12 @@ void syncPingLog(const SyncPing* pMsg) {
} }
void syncPingLog2(char* s, const SyncPing* pMsg) { void syncPingLog2(char* s, const SyncPing* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncPing2Str(pMsg); char* serialized = syncPing2Str(pMsg);
sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncPingReply---- // ---- message process SyncPingReply----
SyncPingReply* syncPingReplyBuild(uint32_t dataLen) { SyncPingReply* syncPingReplyBuild(uint32_t dataLen) {
@ -794,10 +800,12 @@ void syncPingReplyLog(const SyncPingReply* pMsg) {
} }
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) { void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncPingReply2Str(pMsg); char* serialized = syncPingReply2Str(pMsg);
sTrace("syncPingReplyLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized); sTrace("syncPingReplyLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncClientRequest---- // ---- message process SyncClientRequest----
SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) { SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) {
@ -935,10 +943,12 @@ void syncClientRequestLog(const SyncClientRequest* pMsg) {
} }
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncClientRequest2Str(pMsg); char* serialized = syncClientRequest2Str(pMsg);
sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncRequestVote---- // ---- message process SyncRequestVote----
SyncRequestVote* syncRequestVoteBuild(int32_t vgId) { SyncRequestVote* syncRequestVoteBuild(int32_t vgId) {
@ -1084,10 +1094,12 @@ void syncRequestVoteLog(const SyncRequestVote* pMsg) {
} }
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) { void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncRequestVote2Str(pMsg); char* serialized = syncRequestVote2Str(pMsg);
sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncRequestVoteReply---- // ---- message process SyncRequestVoteReply----
SyncRequestVoteReply* syncRequestVoteReplyBuild(int32_t vgId) { SyncRequestVoteReply* syncRequestVoteReplyBuild(int32_t vgId) {
@ -1230,10 +1242,12 @@ void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) {
} }
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) { void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncRequestVoteReply2Str(pMsg); char* serialized = syncRequestVoteReply2Str(pMsg);
sTrace("syncRequestVoteReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncRequestVoteReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncAppendEntries---- // ---- message process SyncAppendEntries----
SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen, int32_t vgId) { SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen, int32_t vgId) {
@ -1399,10 +1413,12 @@ void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
} }
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) { void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncAppendEntries2Str(pMsg); char* serialized = syncAppendEntries2Str(pMsg);
sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncAppendEntriesReply---- // ---- message process SyncAppendEntriesReply----
SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) { SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) {
@ -1551,10 +1567,12 @@ void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
} }
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) { void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncAppendEntriesReply2Str(pMsg); char* serialized = syncAppendEntriesReply2Str(pMsg);
sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// ---- message process SyncApplyMsg---- // ---- message process SyncApplyMsg----
SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) { SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) {
@ -1702,10 +1720,12 @@ void syncApplyMsgLog(const SyncApplyMsg* pMsg) {
} }
void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) { void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncApplyMsg2Str(pMsg); char* serialized = syncApplyMsg2Str(pMsg);
sTrace("syncApplyMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncApplyMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// --------------------------------------------- // ---------------------------------------------
SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) { SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) {
@ -1870,10 +1890,12 @@ void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) {
} }
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) { void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncSnapshotSend2Str(pMsg); char* serialized = syncSnapshotSend2Str(pMsg);
sTrace("syncSnapshotSendLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncSnapshotSendLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}
// --------------------------------------------- // ---------------------------------------------
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) { SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) {
@ -2028,7 +2050,9 @@ void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) {
} }
void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) { void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
if (gRaftDetailLog) {
char* serialized = syncSnapshotRsp2Str(pMsg); char* serialized = syncSnapshotRsp2Str(pMsg);
sTrace("syncSnapshotRspLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("syncSnapshotRspLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}

View File

@ -583,7 +583,9 @@ void logStoreSimpleLog(SSyncLogStore* pLogStore) {
} }
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) {
if (gRaftDetailLog) {
char* serialized = logStoreSimple2Str(pLogStore); char* serialized = logStoreSimple2Str(pLogStore);
sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
taosMemoryFree(serialized); taosMemoryFree(serialized);
} }
}