syncMessage.h 2.8 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * 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/>.
 */

#ifndef _TD_LIBS_SYNC_MESSAGE_H
#define _TD_LIBS_SYNC_MESSAGE_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
M
Minghao Li 已提交
26
#include "sync.h"
M
Minghao Li 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "syncRaftEntry.h"
#include "taosdef.h"

typedef enum ESyncMessageType {
  SYNC_PING = 0,
  SYNC_PING_REPLY,
  SYNC_CLIENT_REQUEST,
  SYNC_CLIENT_REQUEST_REPLY,
  SYNC_REQUEST_VOTE,
  SYNC_REQUEST_VOTE_REPLY,
  SYNC_APPEND_ENTRIES,
  SYNC_APPEND_ENTRIES_REPLY,
} ESyncMessageType;

typedef struct SyncPing {
  ESyncMessageType   msgType;
  const SSyncBuffer *pData;
M
Minghao Li 已提交
44 45
} SyncPing, RaftPing;

M
Minghao Li 已提交
46 47 48
typedef struct SyncPingReply {
  ESyncMessageType   msgType;
  const SSyncBuffer *pData;
M
Minghao Li 已提交
49
} SyncPingReply, RaftPingReply;
M
Minghao Li 已提交
50 51 52 53 54 55

typedef struct SyncClientRequest {
  ESyncMessageType   msgType;
  const SSyncBuffer *pData;
  int64_t            seqNum;
  bool               isWeak;
M
Minghao Li 已提交
56
} SyncClientRequest, RaftClientRequest;
M
Minghao Li 已提交
57 58 59 60 61 62

typedef struct SyncClientRequestReply {
  ESyncMessageType   msgType;
  int32_t            errCode;
  const SSyncBuffer *pErrMsg;
  const SSyncBuffer *pLeaderHint;
M
Minghao Li 已提交
63 64
} SyncClientRequestReply, RaftClientRequestReply;

M
Minghao Li 已提交
65 66 67 68 69 70 71
typedef struct SyncRequestVote {
  ESyncMessageType msgType;
  SyncTerm         currentTerm;
  SyncNodeId       nodeId;
  SyncGroupId      vgId;
  SyncIndex        lastLogIndex;
  SyncTerm         lastLogTerm;
M
Minghao Li 已提交
72
} SyncRequestVote, RaftRequestVote;
M
Minghao Li 已提交
73 74 75 76 77 78 79

typedef struct SyncRequestVoteReply {
  ESyncMessageType msgType;
  SyncTerm         currentTerm;
  SyncNodeId       nodeId;
  SyncGroupId      vgId;
  bool             voteGranted;
M
Minghao Li 已提交
80
} SyncRequestVoteReply, RaftRequestVoteReply;
M
Minghao Li 已提交
81 82 83 84 85 86 87 88 89 90

typedef struct SyncAppendEntries {
  ESyncMessageType msgType;
  SyncTerm         currentTerm;
  SyncNodeId       nodeId;
  SyncIndex        prevLogIndex;
  SyncTerm         prevLogTerm;
  int32_t          entryCount;
  SSyncRaftEntry * logEntries;
  SyncIndex        commitIndex;
M
Minghao Li 已提交
91
} SyncAppendEntries, RaftAppendEntries;
M
Minghao Li 已提交
92 93 94 95 96 97 98

typedef struct SyncAppendEntriesReply {
  ESyncMessageType msgType;
  SyncTerm         currentTerm;
  SyncNodeId       nodeId;
  bool             success;
  SyncIndex        matchIndex;
M
Minghao Li 已提交
99
} SyncAppendEntriesReply, RaftAppendEntriesReply;
M
Minghao Li 已提交
100 101 102 103 104 105

#ifdef __cplusplus
}
#endif

#endif /*_TD_LIBS_SYNC_MESSAGE_H*/