TDengine/source/libs/sync/inc/syncVoteMgr.h

63 lines
2.1 KiB
C
Raw Normal View History

2022-02-26 18:24:50 +00:00
/*
* 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"
2022-03-03 09:28:00 +00:00
typedef struct SVotesGranted {
2022-03-08 09:07:29 +00:00
SRaftId (*replicas)[TSDB_MAX_REPLICA];
bool isGranted[TSDB_MAX_REPLICA];
2022-03-09 02:15:40 +00:00
int32_t replicaNum;
2022-03-08 09:07:29 +00:00
int32_t votes;
2022-03-05 07:03:49 +00:00
SyncTerm term;
int32_t quorum;
bool toLeader;
2022-12-29 03:17:36 +00:00
SSyncNode *pNode;
2022-03-03 09:28:00 +00:00
} SVotesGranted;
2022-12-29 03:17:36 +00:00
SVotesGranted *voteGrantedCreate(SSyncNode *pNode);
2022-03-05 07:03:49 +00:00
void voteGrantedDestroy(SVotesGranted *pVotesGranted);
2022-12-29 03:17:36 +00:00
void voteGrantedUpdate(SVotesGranted *pVotesGranted, SSyncNode *pNode);
2022-03-05 07:03:49 +00:00
bool voteGrantedMajority(SVotesGranted *pVotesGranted);
void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg);
void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term);
typedef struct SVotesRespond {
SRaftId (*replicas)[TSDB_MAX_REPLICA];
bool isRespond[TSDB_MAX_REPLICA];
int32_t replicaNum;
SyncTerm term;
2022-12-29 03:17:36 +00:00
SSyncNode *pNode;
2022-03-05 07:03:49 +00:00
} SVotesRespond;
2022-12-29 03:17:36 +00:00
SVotesRespond *votesRespondCreate(SSyncNode *pNode);
2022-03-08 09:07:29 +00:00
void votesRespondDestory(SVotesRespond *pVotesRespond);
2022-12-29 03:17:36 +00:00
void votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pNode);
2022-03-05 07:03:49 +00:00
bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId);
void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg);
2022-03-09 02:15:40 +00:00
void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term);
2022-03-03 09:28:00 +00:00
2022-02-26 18:24:50 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_LIBS_SYNC_VOTG_MGR_H*/