syncVoteMgr.h 2.4 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
/*
 * 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_VOTG_MGR_H
#define _TD_LIBS_SYNC_VOTG_MGR_H

#ifdef __cplusplus
extern "C" {
#endif

#include "syncInt.h"

M
syncInt  
Minghao Li 已提交
25
typedef struct SVotesGranted {
M
Minghao Li 已提交
26 27
  SRaftId (*replicas)[TSDB_MAX_REPLICA];
  bool       isGranted[TSDB_MAX_REPLICA];
M
Minghao Li 已提交
28
  int32_t    replicaNum;
M
Minghao Li 已提交
29
  int32_t    votes;
M
Minghao Li 已提交
30 31 32 33
  SyncTerm   term;
  int32_t    quorum;
  bool       toLeader;
  SSyncNode *pSyncNode;
M
syncInt  
Minghao Li 已提交
34 35
} SVotesGranted;

M
Minghao Li 已提交
36 37
SVotesGranted *voteGrantedCreate(SSyncNode *pSyncNode);
void           voteGrantedDestroy(SVotesGranted *pVotesGranted);
M
Minghao Li 已提交
38
void           voteGrantedUpdate(SVotesGranted *pVotesGranted, SSyncNode *pSyncNode);
M
Minghao Li 已提交
39 40 41
bool           voteGrantedMajority(SVotesGranted *pVotesGranted);
void           voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg);
void           voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term);
H
Hongze Cheng 已提交
42 43
cJSON         *voteGranted2Json(SVotesGranted *pVotesGranted);
char          *voteGranted2Str(SVotesGranted *pVotesGranted);
M
Minghao Li 已提交
44 45 46 47 48 49 50 51 52 53

typedef struct SVotesRespond {
  SRaftId (*replicas)[TSDB_MAX_REPLICA];
  bool       isRespond[TSDB_MAX_REPLICA];
  int32_t    replicaNum;
  SyncTerm   term;
  SSyncNode *pSyncNode;
} SVotesRespond;

SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode);
M
Minghao Li 已提交
54
void           votesRespondDestory(SVotesRespond *pVotesRespond);
M
Minghao Li 已提交
55
void           votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pSyncNode);
M
Minghao Li 已提交
56 57
bool           votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId);
void           votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg);
M
Minghao Li 已提交
58
void           votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term);
H
Hongze Cheng 已提交
59 60
cJSON         *votesRespond2Json(SVotesRespond *pVotesRespond);
char          *votesRespond2Str(SVotesRespond *pVotesRespond);
M
syncInt  
Minghao Li 已提交
61

M
Minghao Li 已提交
62 63 64 65 66
#ifdef __cplusplus
}
#endif

#endif /*_TD_LIBS_SYNC_VOTG_MGR_H*/