syncSnapshot.h 3.0 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
/*
 * 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_SNAPSHOT_H
#define _TD_LIBS_SYNC_SNAPSHOT_H

#ifdef __cplusplus
extern "C" {
#endif

M
Minghao Li 已提交
23
#include "syncInt.h"
M
Minghao Li 已提交
24

M
Minghao Li 已提交
25 26 27 28 29
#define SYNC_SNAPSHOT_SEQ_INVALID      -2
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE  -3
#define SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT -1
#define SYNC_SNAPSHOT_SEQ_BEGIN        0
#define SYNC_SNAPSHOT_SEQ_END          0x7FFFFFFF
M
Minghao Li 已提交
30

M
Minghao Li 已提交
31 32
#define SYNC_SNAPSHOT_RETRY_MS 5000

M
Minghao Li 已提交
33
typedef struct SSyncSnapshotSender {
34 35 36
  bool           start;
  int32_t        seq;
  int32_t        ack;
M
Minghao Li 已提交
37 38
  void          *pReader;
  void          *pCurrentBlock;
39 40 41 42 43 44
  int32_t        blockLen;
  SSnapshotParam snapshotParam;
  SSnapshot      snapshot;
  SSyncCfg       lastConfig;
  int64_t        sendingMS;
  SyncTerm       term;
45
  int64_t        startTime;
M
Minghao Li 已提交
46
  int64_t        endTime;
47
  int64_t        lastSendTime;
48
  bool           finish;
M
Minghao Li 已提交
49 50 51 52

  // init when create
  SSyncNode *pSyncNode;
  int32_t    replicaIndex;
M
Minghao Li 已提交
53 54
} SSyncSnapshotSender;

M
Minghao Li 已提交
55
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex);
M
Minghao Li 已提交
56
void                 snapshotSenderDestroy(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
57
bool                 snapshotSenderIsStart(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
58
int32_t              snapshotSenderStart(SSyncSnapshotSender *pSender);
59
void                 snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
M
Minghao Li 已提交
60
int32_t              snapshotReSend(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
61

62
typedef struct SSyncSnapshotReceiver {
M
Minghao Li 已提交
63 64 65 66 67 68 69 70
  // update when pre snapshot
  bool     start;
  int32_t  ack;
  SyncTerm term;
  SRaftId  fromId;
  int64_t  startTime;

  // update when begin
M
Minghao Li 已提交
71
  void          *pWriter;
72 73
  SSnapshotParam snapshotParam;
  SSnapshot      snapshot;
M
Minghao Li 已提交
74 75 76

  // init when create
  SSyncNode *pSyncNode;
M
Minghao Li 已提交
77 78
} SSyncSnapshotReceiver;

79
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId);
M
Minghao Li 已提交
80
void                   snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver);
81 82
void                   snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg);
void                   snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver);
83
bool                   snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
84 85

// on message
86
int32_t syncNodeOnSnapshot(SSyncNode *ths, const SRpcMsg *pMsg);
S
Shengliang Guan 已提交
87
int32_t syncNodeOnSnapshotRsp(SSyncNode *ths, const SRpcMsg *pMsg);
M
Minghao Li 已提交
88

89 90
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode *pSyncNode, SyncIndex snapshotLastApplyIndex);

M
Minghao Li 已提交
91
// start
M
Minghao Li 已提交
92

M
Minghao Li 已提交
93 94 95 96 97
#ifdef __cplusplus
}
#endif

#endif /*_TD_LIBS_SYNC_SNAPSHOT_H*/