• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4894

22 Dec 2025 09:33AM UTC coverage: 65.72% (+0.2%) from 65.57%
#4894

push

travis-ci

web-flow
Update README.md (#34007)

* Update README.md

* docs: update table of contents and improve installation instructions in README

* docs: adjust words

---------

Signed-off-by: WANG Xu <feici02@outlook.com>
Co-authored-by: WANG Xu <feici02@outlook.com>

184394 of 280577 relevant lines covered (65.72%)

111859687.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.0
/source/libs/sync/src/syncVoteMgr.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "syncVoteMgr.h"
18
#include "syncMessage.h"
19
#include "syncUtil.h"
20

21
static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) {
5,588,525✔
22
  (void)memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted));
5,588,525✔
23
  pVotesGranted->votes = 0;
5,589,081✔
24
}
5,589,081✔
25

26
SVotesGranted *voteGrantedCreate(SSyncNode *pNode) {
4,798,131✔
27
  SVotesGranted *pVotesGranted = taosMemoryCalloc(1, sizeof(SVotesGranted));
4,798,131✔
28
  if (pVotesGranted == NULL) {
4,800,027✔
29
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
30
    return NULL;
×
31
  }
32

33
  pVotesGranted->replicas = (void*)&pNode->replicasId;
4,800,027✔
34
  pVotesGranted->replicaNum = pNode->replicaNum;
4,799,471✔
35
  voteGrantedClearVotes(pVotesGranted);
4,800,027✔
36

37
  pVotesGranted->term = 0;
4,799,299✔
38
  pVotesGranted->quorum = pNode->quorum;
4,799,299✔
39
  pVotesGranted->toLeader = false;
4,799,764✔
40
  pVotesGranted->pNode = pNode;
4,799,471✔
41

42
  return pVotesGranted;
4,799,471✔
43
}
44

45
void voteGrantedDestroy(SVotesGranted *pVotesGranted) {
4,778,151✔
46
  if (pVotesGranted != NULL) {
4,778,151✔
47
    taosMemoryFree(pVotesGranted);
4,778,644✔
48
  }
49
}
4,777,399✔
50

51
void voteGrantedUpdate(SVotesGranted *pVotesGranted, SSyncNode *pNode) {
98,417✔
52
  pVotesGranted->replicas = (void*)&pNode->replicasId;
98,417✔
53
  pVotesGranted->replicaNum = pNode->replicaNum;
98,417✔
54
  voteGrantedClearVotes(pVotesGranted);
98,417✔
55

56
  pVotesGranted->term = 0;
98,417✔
57
  pVotesGranted->quorum = pNode->quorum;
98,417✔
58
  pVotesGranted->toLeader = false;
98,417✔
59
  pVotesGranted->pNode = pNode;
98,417✔
60
}
98,417✔
61

62
bool voteGrantedMajority(SVotesGranted *pVotesGranted) { return pVotesGranted->votes >= pVotesGranted->quorum; }
1,821,699✔
63

64
void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg) {
1,284,526✔
65
  if (!pMsg->voteGranted) {
1,284,526✔
66
    sNFatal(pVotesGranted->pNode, "vote granted should be true");
×
67
    return;
×
68
  }
69

70
  if (pMsg->term != pVotesGranted->term) {
1,284,526✔
71
    sNTrace(pVotesGranted->pNode, "vote grant term:%" PRId64 " not matched with msg term:%" PRId64, pVotesGranted->term,
×
72
            pMsg->term);
73
    return;
×
74
  }
75

76
  if (!syncUtilSameId(&pVotesGranted->pNode->myRaftId, &pMsg->destId)) {
1,284,526✔
77
    sNFatal(pVotesGranted->pNode, "vote granted raftId not matched with msg");
×
78
    return;
×
79
  }
80

81
  int32_t j = -1;
1,284,526✔
82
  for (int32_t i = 0; i < pVotesGranted->replicaNum; ++i) {
2,473,211✔
83
    if (syncUtilSameId(&((*(pVotesGranted->replicas))[i]), &(pMsg->srcId))) {
2,473,211✔
84
      j = i;
1,284,526✔
85
      break;
1,284,526✔
86
    }
87
  }
88
  if ((j == -1) || !(j >= 0 && j < pVotesGranted->replicaNum)) {
1,284,526✔
89
    sNFatal(pVotesGranted->pNode, "invalid msg srcId, index:%d", j);
×
90
    return;
×
91
  }
92

93
  if (pVotesGranted->isGranted[j] != true) {
1,284,526✔
94
    ++(pVotesGranted->votes);
1,284,526✔
95
    pVotesGranted->isGranted[j] = true;
1,284,526✔
96
  }
97

98
  if (pVotesGranted->votes > pVotesGranted->replicaNum) {
1,284,526✔
99
    sNFatal(pVotesGranted->pNode, "votes:%d not matched with replicaNum:%d", pVotesGranted->votes,
×
100
            pVotesGranted->replicaNum);
101
    return;
×
102
  }
103
}
104

105
void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term) {
690,637✔
106
  pVotesGranted->term = term;
690,637✔
107
  voteGrantedClearVotes(pVotesGranted);
690,637✔
108
  pVotesGranted->toLeader = false;
690,637✔
109
}
690,637✔
110

111
SVotesRespond *votesRespondCreate(SSyncNode *pNode) {
4,799,176✔
112
  SVotesRespond *pVotesRespond = taosMemoryCalloc(1, sizeof(SVotesRespond));
4,799,176✔
113
  if (pVotesRespond == NULL) {
4,800,027✔
114
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
115
    return NULL;
×
116
  }
117

118
  pVotesRespond->replicas = (void*)&pNode->replicasId;
4,800,027✔
119
  pVotesRespond->replicaNum = pNode->replicaNum;
4,799,471✔
120
  pVotesRespond->term = 0;
4,799,471✔
121
  pVotesRespond->pNode = pNode;
4,799,550✔
122

123
  return pVotesRespond;
4,798,917✔
124
}
125

126
void votesRespondDestory(SVotesRespond *pVotesRespond) {
4,778,151✔
127
  if (pVotesRespond != NULL) {
4,778,151✔
128
    taosMemoryFree(pVotesRespond);
4,778,151✔
129
  }
130
}
4,778,660✔
131

132
void votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pNode) {
98,417✔
133
  pVotesRespond->replicas = (void*)&pNode->replicasId;
98,417✔
134
  pVotesRespond->replicaNum = pNode->replicaNum;
98,417✔
135
  pVotesRespond->term = 0;
98,417✔
136
  pVotesRespond->pNode = pNode;
98,417✔
137
}
98,417✔
138

139
bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId) {
×
140
  bool ret = false;
×
141
  for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) {
×
142
    if (syncUtilSameId(&(*pVotesRespond->replicas)[i], pRaftId) && pVotesRespond->isRespond[i]) {
×
143
      ret = true;
×
144
      break;
×
145
    }
146
  }
147
  return ret;
×
148
}
149

150
void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg) {
1,347,510✔
151
  if (pVotesRespond->term != pMsg->term) {
1,347,510✔
152
    sNTrace(pVotesRespond->pNode, "vote respond add error");
×
153
    return;
×
154
  }
155

156
  for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) {
2,560,586✔
157
    if (syncUtilSameId(&((*(pVotesRespond->replicas))[i]), &pMsg->srcId)) {
2,560,586✔
158
      pVotesRespond->isRespond[i] = true;
1,347,510✔
159
      return;
1,347,510✔
160
    }
161
  }
162

163
  sNFatal(pVotesRespond->pNode, "votes respond not found");
×
164
}
165

166
void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term) {
690,637✔
167
  pVotesRespond->term = term;
690,637✔
168
  (void)memset(pVotesRespond->isRespond, 0, sizeof(pVotesRespond->isRespond));
690,637✔
169
}
690,637✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc