syncSnapshot.h 3.2 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
int32_t              snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
M
Minghao Li 已提交
60 61
int32_t              snapshotSend(SSyncSnapshotSender *pSender);
int32_t              snapshotReSend(SSyncSnapshotSender *pSender);
M
Minghao Li 已提交
62

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

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

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

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

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

91 92
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode *pSyncNode, SyncIndex snapshotLastApplyIndex);

M
Minghao Li 已提交
93
// start
M
Minghao Li 已提交
94

M
Minghao Li 已提交
95 96 97 98 99
#ifdef __cplusplus
}
#endif

#endif /*_TD_LIBS_SYNC_SNAPSHOT_H*/