From fd152f00ece7b192a9c826f799f3085ca95c3461 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 11 Nov 2022 14:35:16 +0800 Subject: [PATCH] refact: adjust head file and sync log --- source/libs/sync/inc/syncInt.h | 25 ++++++++++++++++++- .../sync/inc/{syncTools.h => syncMessage.h} | 22 +++------------- source/libs/sync/src/syncAppendEntries.c | 1 + source/libs/sync/src/syncAppendEntriesReply.c | 1 + source/libs/sync/src/syncElection.c | 3 ++- source/libs/sync/src/syncMessage.c | 1 + source/libs/sync/src/syncRequestVote.c | 1 + source/libs/sync/src/syncRequestVoteReply.c | 1 + source/libs/sync/src/syncVoteMgr.c | 1 + 9 files changed, 36 insertions(+), 20 deletions(-) rename source/libs/sync/inc/{syncTools.h => syncMessage.h} (97%) diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 8a951ba38d..46bbb14421 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -21,7 +21,6 @@ extern "C" { #endif #include "sync.h" -#include "syncTools.h" #include "taosdef.h" #include "tlog.h" #include "trpc.h" @@ -85,9 +84,33 @@ typedef struct SSyncSnapshotSender SSyncSnapshotSender; typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver; typedef struct SSyncTimer SSyncTimer; typedef struct SSyncHbTimerData SSyncHbTimerData; +typedef struct SyncSnapshotSend SyncSnapshotSend; +typedef struct SyncSnapshotRsp SyncSnapshotRsp; +typedef struct SyncLocalCmd SyncLocalCmd; +typedef struct SyncAppendEntriesBatch SyncAppendEntriesBatch; +typedef struct SyncPreSnapshotReply SyncPreSnapshotReply; +typedef struct SyncHeartbeatReply SyncHeartbeatReply; +typedef struct SyncHeartbeat SyncHeartbeat; +typedef struct SyncPreSnapshot SyncPreSnapshot; + +typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg); +typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg); +typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex); +typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg); +typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg); +typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg); +typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg); +typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg); +typedef int32_t (*FpOnSnapshotCb)(SSyncNode* ths, SyncSnapshotSend* pMsg); +typedef int32_t (*FpOnSnapshotReplyCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg); extern bool gRaftDetailLog; +typedef struct SRaftId { + SyncNodeId addr; + SyncGroupId vgId; +} SRaftId; + typedef struct SSyncHbTimerData { SSyncNode* pSyncNode; SSyncTimer* pTimer; diff --git a/source/libs/sync/inc/syncTools.h b/source/libs/sync/inc/syncMessage.h similarity index 97% rename from source/libs/sync/inc/syncTools.h rename to source/libs/sync/inc/syncMessage.h index 3fb4a5ba0c..93a674e170 100644 --- a/source/libs/sync/inc/syncTools.h +++ b/source/libs/sync/inc/syncMessage.h @@ -13,18 +13,14 @@ * along with this program. If not, see . */ -#ifndef _TD_LIBS_SYNC_TOOLS_H -#define _TD_LIBS_SYNC_TOOLS_H +#ifndef _TD_LIBS_SYNC_MESSAGE_H +#define _TD_LIBS_SYNC_MESSAGE_H #ifdef __cplusplus extern "C" { #endif -// ------------------ ds ------------------- -typedef struct SRaftId { - SyncNodeId addr; - SyncGroupId vgId; -} SRaftId; +#include "syncInt.h" // ------------------ for debug ------------------- void syncRpcMsgPrint(SRpcMsg* pMsg); @@ -731,16 +727,6 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg); // ----------------------------------------- -typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg); -typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg); -typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex); -typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg); -typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg); -typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg); -typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg); -typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg); -typedef int32_t (*FpOnSnapshotCb)(SSyncNode* ths, SyncSnapshotSend* pMsg); -typedef int32_t (*FpOnSnapshotReplyCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg); // option ---------------------------------- bool syncNodeSnapshotEnable(SSyncNode* pSyncNode); @@ -752,4 +738,4 @@ ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode); } #endif -#endif /*_TD_LIBS_SYNC_TOOLS_H*/ +#endif /*_TD_LIBS_SYNC_MESSAGE_H*/ diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 2dbe157c16..c9c1baa4bc 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "syncAppendEntries.h" +#include "syncMessage.h" #include "syncRaftLog.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 89661987a8..53d6b5d92f 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "syncAppendEntriesReply.h" +#include "syncMessage.h" #include "syncCommit.h" #include "syncIndexMgr.h" #include "syncRaftStore.h" diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 95f7a638f6..123ce5b581 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -15,10 +15,11 @@ #define _DEFAULT_SOURCE #include "syncElection.h" +#include "syncMessage.h" #include "syncRaftCfg.h" #include "syncRaftStore.h" -#include "syncVoteMgr.h" #include "syncUtil.h" +#include "syncVoteMgr.h" // TLA+ Spec // RequestVote(i, j) == diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 3fcb563f3b..e3434aba73 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncMessage.h" #include "syncRaftCfg.h" #include "syncRaftEntry.h" diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index f2b75def6b..bf44341acd 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "syncRequestVote.h" +#include "syncMessage.h" #include "syncRaftCfg.h" #include "syncRaftStore.h" #include "syncUtil.h" diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 02b9bb40ac..1acf16507a 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "syncRequestVoteReply.h" +#include "syncMessage.h" #include "syncRaftStore.h" #include "syncVoteMgr.h" diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 4ca4e26bec..8a0a35ce33 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "syncVoteMgr.h" +#include "syncMessage.h" #include "syncUtil.h" static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) { -- GitLab