TDengine/source/libs/sync/inc/syncMessage.h

283 lines
7.1 KiB
C
Raw Normal View History

2022-04-18 13:50:56 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-11-11 06:35:16 +00:00
#ifndef _TD_LIBS_SYNC_MESSAGE_H
#define _TD_LIBS_SYNC_MESSAGE_H
2022-04-18 13:50:56 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-11-11 06:35:16 +00:00
#include "syncInt.h"
2022-04-19 03:51:51 +00:00
2022-04-18 13:50:56 +00:00
typedef enum ESyncTimeoutType {
SYNC_TIMEOUT_PING = 100,
SYNC_TIMEOUT_ELECTION,
SYNC_TIMEOUT_HEARTBEAT,
} ESyncTimeoutType;
typedef struct SyncTimeout {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
ESyncTimeoutType timeoutType;
uint64_t logicClock;
int32_t timerMS;
2022-11-25 10:19:25 +00:00
int64_t timeStamp;
2022-04-18 13:50:56 +00:00
void* data; // need optimized
} SyncTimeout;
typedef struct SyncClientRequest {
uint32_t bytes;
int32_t vgId;
uint32_t msgType; // TDMT_SYNC_CLIENT_REQUEST
uint32_t originalRpcType; // origin RpcMsg msgType
2022-04-18 13:50:56 +00:00
uint64_t seqNum;
bool isWeak;
int16_t reserved;
uint32_t dataLen; // origin RpcMsg.contLen
char data[]; // origin RpcMsg.pCont
2022-04-18 13:50:56 +00:00
} SyncClientRequest;
typedef struct SyncClientRequestReply {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
int32_t errCode;
SRaftId leaderHint;
int16_t reserved;
2022-04-18 13:50:56 +00:00
} SyncClientRequestReply;
typedef struct SyncRequestVote {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
SyncIndex lastLogIndex;
SyncTerm lastLogTerm;
int16_t reserved;
2022-04-18 13:50:56 +00:00
} SyncRequestVote;
typedef struct SyncRequestVoteReply {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
bool voteGranted;
int16_t reserved;
2022-04-18 13:50:56 +00:00
} SyncRequestVoteReply;
typedef struct SyncAppendEntries {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
2022-04-18 13:50:56 +00:00
// private data
SyncTerm term;
SyncIndex prevLogIndex;
SyncTerm prevLogTerm;
SyncIndex commitIndex;
SyncTerm privateTerm;
int16_t reserved;
2022-04-18 13:50:56 +00:00
uint32_t dataLen;
char data[];
} SyncAppendEntries;
typedef struct SyncAppendEntriesReply {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
SyncTerm lastMatchTerm;
2022-04-18 13:50:56 +00:00
bool success;
SyncIndex matchIndex;
2022-10-16 04:07:02 +00:00
SyncIndex lastSendIndex;
int64_t startTime;
int16_t fsmState;
2022-04-18 13:50:56 +00:00
} SyncAppendEntriesReply;
2022-09-07 07:29:04 +00:00
typedef struct SyncHeartbeat {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
SyncIndex commitIndex;
SyncTerm privateTerm;
2022-10-20 06:53:03 +00:00
SyncTerm minMatchIndex;
int64_t timeStamp;
int16_t reserved;
2022-09-07 07:29:04 +00:00
} SyncHeartbeat;
typedef struct SyncHeartbeatReply {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
SyncTerm privateTerm;
int64_t startTime;
int64_t timeStamp;
int16_t reserved;
2022-09-07 07:29:04 +00:00
} SyncHeartbeatReply;
2022-11-01 02:25:31 +00:00
typedef struct SyncPreSnapshot {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
int16_t reserved;
2022-11-01 02:25:31 +00:00
} SyncPreSnapshot;
2022-11-01 02:47:19 +00:00
typedef struct SyncPreSnapshotReply {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
// private data
SyncTerm term;
SyncIndex snapStart;
int16_t reserved;
2022-11-01 02:47:19 +00:00
} SyncPreSnapshotReply;
2022-04-20 03:51:00 +00:00
typedef struct SyncApplyMsg {
uint32_t bytes;
int32_t vgId;
uint32_t msgType; // user SyncApplyMsg msgType
uint32_t originalRpcType; // user RpcMsg msgType
SFsmCbMeta fsmMeta;
uint32_t dataLen; // user RpcMsg.contLen
char data[]; // user RpcMsg.pCont
} SyncApplyMsg;
typedef struct SyncSnapshotSend {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
SyncTerm term;
SyncIndex beginIndex; // snapshot.beginIndex
SyncIndex lastIndex; // snapshot.lastIndex
SyncTerm lastTerm; // snapshot.lastTerm
SyncIndex lastConfigIndex; // snapshot.lastConfigIndex
2022-06-11 05:52:17 +00:00
SSyncCfg lastConfig;
2022-11-02 07:25:26 +00:00
int64_t startTime;
int32_t seq;
int16_t payloadType;
uint32_t dataLen;
char data[];
} SyncSnapshotSend;
typedef struct SyncSnapshotRsp {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
SyncTerm term;
SyncIndex lastIndex;
SyncTerm lastTerm;
2022-11-02 07:25:26 +00:00
int64_t startTime;
int32_t ack;
int32_t code;
2022-11-02 07:25:26 +00:00
SyncIndex snapBeginIndex; // when ack = SYNC_SNAPSHOT_SEQ_BEGIN, it's valid
int16_t payloadType;
char data[];
} SyncSnapshotRsp;
2022-06-11 04:44:58 +00:00
typedef struct SyncLeaderTransfer {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
/*
SRaftId srcId;
SRaftId destId;
*/
2022-06-13 07:47:43 +00:00
SNodeInfo newNodeInfo;
SRaftId newLeaderId;
2022-06-11 04:44:58 +00:00
} SyncLeaderTransfer;
2022-10-27 09:16:46 +00:00
typedef enum {
2022-10-27 09:59:16 +00:00
SYNC_LOCAL_CMD_STEP_DOWN = 100,
SYNC_LOCAL_CMD_FOLLOWER_CMT,
2023-04-18 11:03:45 +00:00
SYNC_LOCAL_CMD_LEARNER_CMT,
2022-10-27 09:16:46 +00:00
} ESyncLocalCmd;
2022-10-27 08:21:54 +00:00
typedef struct SyncLocalCmd {
uint32_t bytes;
int32_t vgId;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
2022-11-12 02:08:28 +00:00
int32_t cmd;
SyncTerm currentTerm; // step down new term
SyncIndex commitIndex; // follower commit index
2022-10-27 08:21:54 +00:00
} SyncLocalCmd;
2022-11-12 12:29:49 +00:00
int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType ttype, uint64_t logicClock, int32_t ms, SSyncNode* pNode);
2022-11-13 08:11:49 +00:00
int32_t syncBuildClientRequest(SRpcMsg* pMsg, const SRpcMsg* pOriginal, uint64_t seq, bool isWeak, int32_t vgId);
2022-11-12 12:29:49 +00:00
int32_t syncBuildClientRequestFromNoopEntry(SRpcMsg* pMsg, const SSyncRaftEntry* pEntry, int32_t vgId);
2022-11-12 04:58:08 +00:00
int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId);
2022-11-12 05:17:56 +00:00
int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId);
2022-11-12 08:40:09 +00:00
int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
2022-11-12 10:21:58 +00:00
int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId);
int32_t syncBuildAppendEntriesFromRaftEntry(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
SRpcMsg* pRpcMsg);
2022-11-12 12:37:15 +00:00
int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId);
2022-11-12 13:31:01 +00:00
int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId);
2022-11-13 08:03:45 +00:00
int32_t syncBuildPreSnapshot(SRpcMsg* pMsg, int32_t vgId);
int32_t syncBuildPreSnapshotReply(SRpcMsg* pMsg, int32_t vgId);
2022-11-13 08:11:49 +00:00
int32_t syncBuildApplyMsg(SRpcMsg* pMsg, const SRpcMsg* pOriginal, int32_t vgId, SFsmCbMeta* pMeta);
2022-11-13 08:39:21 +00:00
int32_t syncBuildSnapshotSend(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
int32_t syncBuildSnapshotSendRsp(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
2022-11-13 09:00:47 +00:00
int32_t syncBuildLeaderTransfer(SRpcMsg* pMsg, int32_t vgId);
2022-11-13 09:14:03 +00:00
int32_t syncBuildLocalCmd(SRpcMsg* pMsg, int32_t vgId);
2022-11-12 04:58:08 +00:00
2022-11-13 09:21:30 +00:00
const char* syncTimerTypeStr(ESyncTimeoutType timerType);
const char* syncLocalCmdGetStr(ESyncLocalCmd cmd);
2022-04-18 13:50:56 +00:00
#ifdef __cplusplus
}
#endif
2022-11-11 06:35:16 +00:00
#endif /*_TD_LIBS_SYNC_MESSAGE_H*/