syncSnapshot.h 3.1 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
  bool           finish;
M
Minghao Li 已提交
48 49 50 51

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

M
Minghao Li 已提交
54
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex);
M
Minghao Li 已提交
55
void                 snapshotSenderDestroy(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
56
bool                 snapshotSenderIsStart(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
57
int32_t              snapshotSenderStart(SSyncSnapshotSender *pSender);
58
int32_t              snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
M
Minghao Li 已提交
59 60
int32_t              snapshotSend(SSyncSnapshotSender *pSender);
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 83
int32_t                snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg);
int32_t                snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver);
bool                   snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
84
void                   snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver);
85 86

// on message
87
int32_t syncNodeOnSnapshot(SSyncNode *ths, const SRpcMsg *pMsg);
M
Minghao Li 已提交
88 89
int32_t syncNodeOnSnapshotReply(SSyncNode *ths, SyncSnapshotRsp *pMsg);

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

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

#endif /*_TD_LIBS_SYNC_SNAPSHOT_H*/