syncRaftEntry.h 1.9 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

M
Minghao Li 已提交
16 17
#ifndef _TD_LIBS_SYNC_RAFT_ENTRY_H
#define _TD_LIBS_SYNC_RAFT_ENTRY_H
M
Minghao Li 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

M
Minghao Li 已提交
23
#include "syncInt.h"
M
Minghao Li 已提交
24
#include "syncMessage.h"
25
#include "tskiplist.h"
M
Minghao Li 已提交
26 27

typedef struct SSyncRaftEntry {
M
Minghao Li 已提交
28
  uint32_t  bytes;
29 30
  uint32_t  msgType;          // TDMT_SYNC_CLIENT_REQUEST
  uint32_t  originalRpcType;  // origin RpcMsg msgType
M
Minghao Li 已提交
31 32
  uint64_t  seqNum;
  bool      isWeak;
M
Minghao Li 已提交
33 34
  SyncTerm  term;
  SyncIndex index;
35
  int64_t   rid;
36 37
  uint32_t  dataLen;  // origin RpcMsg.contLen
  char      data[];   // origin RpcMsg.pCont
M
Minghao Li 已提交
38 39
} SSyncRaftEntry;

40 41 42 43
SSyncRaftEntry* syncEntryBuild(int32_t dataLen);
SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index);
SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index);
SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg);
M
Minghao Li 已提交
44
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId);
B
Benguang Zhao 已提交
45
void            syncEntryDestroy(SSyncRaftEntry* pEntry);
M
Minghao Li 已提交
46
void            syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg);  // step 7
M
Minghao Li 已提交
47

48
static FORCE_INLINE bool syncLogReplBarrier(SSyncRaftEntry* pEntry) {
49 50
  return pEntry->originalRpcType == TDMT_SYNC_NOOP;
}
M
Minghao Li 已提交
51

M
Minghao Li 已提交
52 53 54 55
#ifdef __cplusplus
}
#endif

M
Minghao Li 已提交
56
#endif /*_TD_LIBS_SYNC_RAFT_ENTRY_H*/