refactor: adjust sync header file
This commit is contained in:
parent
dbaa74462e
commit
0f9cd43027
|
@ -20,17 +20,23 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tmsgcb.h"
|
#include "tmsgcb.h"
|
||||||
|
|
||||||
|
#define SYNC_INDEX_BEGIN 0
|
||||||
|
#define SYNC_INDEX_INVALID -1
|
||||||
|
|
||||||
typedef uint64_t SyncNodeId;
|
typedef uint64_t SyncNodeId;
|
||||||
typedef int32_t SyncGroupId;
|
typedef int32_t SyncGroupId;
|
||||||
typedef int64_t SyncIndex;
|
typedef int64_t SyncIndex;
|
||||||
typedef uint64_t SyncTerm;
|
typedef uint64_t SyncTerm;
|
||||||
|
|
||||||
|
typedef struct SSyncNode SSyncNode;
|
||||||
|
typedef struct SSyncBuffer SSyncBuffer;
|
||||||
|
typedef struct SWal SWal;
|
||||||
|
typedef struct SSyncRaftEntry SSyncRaftEntry;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TAOS_SYNC_STATE_FOLLOWER = 100,
|
TAOS_SYNC_STATE_FOLLOWER = 100,
|
||||||
TAOS_SYNC_STATE_CANDIDATE = 101,
|
TAOS_SYNC_STATE_CANDIDATE = 101,
|
||||||
|
@ -38,6 +44,17 @@ typedef enum {
|
||||||
TAOS_SYNC_STATE_ERROR = 103,
|
TAOS_SYNC_STATE_ERROR = 103,
|
||||||
} ESyncState;
|
} ESyncState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TAOS_SYNC_PROPOSE_SUCCESS = 0,
|
||||||
|
TAOS_SYNC_PROPOSE_NOT_LEADER = 1,
|
||||||
|
TAOS_SYNC_PROPOSE_OTHER_ERROR = 2,
|
||||||
|
} ESyncProposeCode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TAOS_SYNC_FSM_CB_SUCCESS = 0,
|
||||||
|
TAOS_SYNC_FSM_CB_OTHER_ERROR = 1,
|
||||||
|
} ESyncFsmCbCode;
|
||||||
|
|
||||||
typedef struct SNodeInfo {
|
typedef struct SNodeInfo {
|
||||||
uint16_t nodePort;
|
uint16_t nodePort;
|
||||||
char nodeFqdn[TSDB_FQDN_LEN];
|
char nodeFqdn[TSDB_FQDN_LEN];
|
||||||
|
@ -55,11 +72,6 @@ typedef struct SSnapshot {
|
||||||
SyncTerm lastApplyTerm;
|
SyncTerm lastApplyTerm;
|
||||||
} SSnapshot;
|
} SSnapshot;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TAOS_SYNC_FSM_CB_SUCCESS = 0,
|
|
||||||
TAOS_SYNC_FSM_CB_OTHER_ERROR,
|
|
||||||
} ESyncFsmCbCode;
|
|
||||||
|
|
||||||
typedef struct SFsmCbMeta {
|
typedef struct SFsmCbMeta {
|
||||||
SyncIndex index;
|
SyncIndex index;
|
||||||
bool isWeak;
|
bool isWeak;
|
||||||
|
@ -68,27 +80,15 @@ typedef struct SFsmCbMeta {
|
||||||
uint64_t seqNum;
|
uint64_t seqNum;
|
||||||
} SFsmCbMeta;
|
} SFsmCbMeta;
|
||||||
|
|
||||||
struct SRpcMsg;
|
|
||||||
typedef struct SRpcMsg SRpcMsg;
|
|
||||||
|
|
||||||
typedef struct SSyncFSM {
|
typedef struct SSyncFSM {
|
||||||
void* data;
|
void* data;
|
||||||
|
|
||||||
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||||
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||||
|
|
||||||
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||||
int32_t (*FpRestoreSnapshot)(struct SSyncFSM* pFsm, const SSnapshot* snapshot);
|
int32_t (*FpRestoreSnapshot)(struct SSyncFSM* pFsm, const SSnapshot* snapshot);
|
||||||
|
|
||||||
} SSyncFSM;
|
} SSyncFSM;
|
||||||
|
|
||||||
struct SSyncRaftEntry;
|
|
||||||
typedef struct SSyncRaftEntry SSyncRaftEntry;
|
|
||||||
|
|
||||||
#define SYNC_INDEX_BEGIN 0
|
|
||||||
#define SYNC_INDEX_INVALID -1
|
|
||||||
|
|
||||||
// abstract definition of log store in raft
|
// abstract definition of log store in raft
|
||||||
// SWal implements it
|
// SWal implements it
|
||||||
typedef struct SSyncLogStore {
|
typedef struct SSyncLogStore {
|
||||||
|
@ -117,11 +117,6 @@ typedef struct SSyncLogStore {
|
||||||
|
|
||||||
} SSyncLogStore;
|
} SSyncLogStore;
|
||||||
|
|
||||||
struct SWal;
|
|
||||||
typedef struct SWal SWal;
|
|
||||||
|
|
||||||
struct SEpSet;
|
|
||||||
typedef struct SEpSet SEpSet;
|
|
||||||
|
|
||||||
typedef struct SSyncInfo {
|
typedef struct SSyncInfo {
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
|
@ -130,10 +125,8 @@ typedef struct SSyncInfo {
|
||||||
SWal* pWal;
|
SWal* pWal;
|
||||||
SSyncFSM* pFsm;
|
SSyncFSM* pFsm;
|
||||||
SMsgCb* msgcb;
|
SMsgCb* msgcb;
|
||||||
|
|
||||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
int32_t syncInit();
|
int32_t syncInit();
|
||||||
|
@ -148,27 +141,8 @@ const char* syncGetMyRoleStr(int64_t rid);
|
||||||
SyncTerm syncGetMyTerm(int64_t rid);
|
SyncTerm syncGetMyTerm(int64_t rid);
|
||||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
||||||
int32_t syncGetVgId(int64_t rid);
|
int32_t syncGetVgId(int64_t rid);
|
||||||
|
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
||||||
typedef enum {
|
bool syncEnvIsStart();
|
||||||
TAOS_SYNC_PROPOSE_SUCCESS = 0,
|
|
||||||
TAOS_SYNC_PROPOSE_NOT_LEADER,
|
|
||||||
TAOS_SYNC_PROPOSE_OTHER_ERROR,
|
|
||||||
} ESyncProposeCode;
|
|
||||||
|
|
||||||
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
|
||||||
|
|
||||||
bool syncEnvIsStart();
|
|
||||||
|
|
||||||
extern int32_t sDebugFlag;
|
|
||||||
|
|
||||||
//-----------------------------------------
|
|
||||||
struct SSyncNode;
|
|
||||||
typedef struct SSyncNode SSyncNode;
|
|
||||||
|
|
||||||
struct SSyncBuffer;
|
|
||||||
typedef struct SSyncBuffer SSyncBuffer;
|
|
||||||
//-----------------------------------------
|
|
||||||
|
|
||||||
const char* syncStr(ESyncState state);
|
const char* syncStr(ESyncState state);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -20,9 +20,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#include "cJSON.h"
|
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
// ------------------ ds -------------------
|
// ------------------ ds -------------------
|
||||||
|
@ -32,9 +29,6 @@ typedef struct SRaftId {
|
||||||
} SRaftId;
|
} SRaftId;
|
||||||
|
|
||||||
// ------------------ control -------------------
|
// ------------------ control -------------------
|
||||||
struct SSyncNode;
|
|
||||||
typedef struct SSyncNode SSyncNode;
|
|
||||||
|
|
||||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||||
void syncNodeRelease(SSyncNode* pNode);
|
void syncNodeRelease(SSyncNode* pNode);
|
||||||
|
|
||||||
|
|
|
@ -20,135 +20,41 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "cJSON.h"
|
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "syncTools.h"
|
#include "syncTools.h"
|
||||||
#include "taosdef.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
|
||||||
#define sFatal(...) \
|
// clang-format off
|
||||||
{ \
|
#define sFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||||
if (sDebugFlag & DEBUG_FATAL) { \
|
#define sError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||||
taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
#define sWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||||
} \
|
#define sInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||||
}
|
#define sDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define sError(...) \
|
#define sTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
{ \
|
#define sFatalLong(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||||
if (sDebugFlag & DEBUG_ERROR) { \
|
#define sErrorLong(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||||
taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
#define sWarnLong(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||||
} \
|
#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||||
}
|
#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define sWarn(...) \
|
#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
{ \
|
// clang-format on
|
||||||
if (sDebugFlag & DEBUG_WARN) { \
|
|
||||||
taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sInfo(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_INFO) { \
|
|
||||||
taosPrintLog("SYN INFO ", DEBUG_INFO, 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sDebug(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_DEBUG) { \
|
|
||||||
taosPrintLog("SYN DEBUG ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sTrace(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_TRACE) { \
|
|
||||||
taosPrintLog("SYN TRACE ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define sFatalLong(...) \
|
typedef struct SyncTimeout SyncTimeout;
|
||||||
{ \
|
typedef struct SyncClientRequest SyncClientRequest;
|
||||||
if (sDebugFlag & DEBUG_FATAL) { \
|
typedef struct SyncPing SyncPing;
|
||||||
taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
typedef struct SyncPingReply SyncPingReply;
|
||||||
} \
|
typedef struct SyncRequestVote SyncRequestVote;
|
||||||
}
|
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
||||||
#define sErrorLong(...) \
|
typedef struct SyncAppendEntries SyncAppendEntries;
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_ERROR) { \
|
|
||||||
taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sWarnLong(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_WARN) { \
|
|
||||||
taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sInfoLong(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_INFO) { \
|
|
||||||
taosPrintLongString("SYN INFO ", DEBUG_INFO, 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sDebugLong(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_DEBUG) { \
|
|
||||||
taosPrintLongString("SYN DEBUG ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define sTraceLong(...) \
|
|
||||||
{ \
|
|
||||||
if (sDebugFlag & DEBUG_TRACE) { \
|
|
||||||
taosPrintLongString("SYN TRACE ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SyncTimeout;
|
|
||||||
typedef struct SyncTimeout SyncTimeout;
|
|
||||||
|
|
||||||
struct SyncClientRequest;
|
|
||||||
typedef struct SyncClientRequest SyncClientRequest;
|
|
||||||
|
|
||||||
struct SyncPing;
|
|
||||||
typedef struct SyncPing SyncPing;
|
|
||||||
|
|
||||||
struct SyncPingReply;
|
|
||||||
typedef struct SyncPingReply SyncPingReply;
|
|
||||||
|
|
||||||
struct SyncRequestVote;
|
|
||||||
typedef struct SyncRequestVote SyncRequestVote;
|
|
||||||
|
|
||||||
struct SyncRequestVoteReply;
|
|
||||||
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
|
||||||
|
|
||||||
struct SyncAppendEntries;
|
|
||||||
typedef struct SyncAppendEntries SyncAppendEntries;
|
|
||||||
|
|
||||||
struct SyncAppendEntriesReply;
|
|
||||||
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
||||||
|
typedef struct SSyncEnv SSyncEnv;
|
||||||
struct SSyncEnv;
|
typedef struct SRaftStore SRaftStore;
|
||||||
typedef struct SSyncEnv SSyncEnv;
|
typedef struct SVotesGranted SVotesGranted;
|
||||||
|
typedef struct SVotesRespond SVotesRespond;
|
||||||
struct SRaftStore;
|
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
||||||
typedef struct SRaftStore SRaftStore;
|
typedef struct SRaftCfg SRaftCfg;
|
||||||
|
typedef struct SSyncRespMgr SSyncRespMgr;
|
||||||
struct SVotesGranted;
|
|
||||||
typedef struct SVotesGranted SVotesGranted;
|
|
||||||
|
|
||||||
struct SVotesRespond;
|
|
||||||
typedef struct SVotesRespond SVotesRespond;
|
|
||||||
|
|
||||||
struct SSyncIndexMgr;
|
|
||||||
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
|
||||||
|
|
||||||
struct SRaftCfg;
|
|
||||||
typedef struct SRaftCfg SRaftCfg;
|
|
||||||
|
|
||||||
struct SSyncRespMgr;
|
|
||||||
typedef struct SSyncRespMgr SSyncRespMgr;
|
|
||||||
|
|
||||||
typedef struct SSyncNode {
|
typedef struct SSyncNode {
|
||||||
// init by SSyncInfo
|
// init by SSyncInfo
|
||||||
|
|
Loading…
Reference in New Issue