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

taosdata / TDengine / #4962

09 Feb 2026 01:16AM UTC coverage: 66.872% (+0.07%) from 66.798%
#4962

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205763 of 307696 relevant lines covered (66.87%)

127640448.9 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) {
4,962,628✔
22
  (void)memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted));
4,962,628✔
23
  pVotesGranted->votes = 0;
4,962,977✔
24
}
4,962,229✔
25

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

33
  pVotesGranted->replicas = (void*)&pNode->replicasId;
4,404,773✔
34
  pVotesGranted->replicaNum = pNode->replicaNum;
4,404,773✔
35
  voteGrantedClearVotes(pVotesGranted);
4,405,521✔
36

37
  pVotesGranted->term = 0;
4,404,773✔
38
  pVotesGranted->quorum = pNode->quorum;
4,404,773✔
39
  pVotesGranted->toLeader = false;
4,405,521✔
40
  pVotesGranted->pNode = pNode;
4,404,424✔
41

42
  return pVotesGranted;
4,403,734✔
43
}
44

45
void voteGrantedDestroy(SVotesGranted *pVotesGranted) {
4,393,508✔
46
  if (pVotesGranted != NULL) {
4,393,508✔
47
    taosMemoryFree(pVotesGranted);
4,393,508✔
48
  }
49
}
4,393,508✔
50

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

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

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

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

70
  if (pMsg->term != pVotesGranted->term) {
1,003,623✔
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,003,623✔
77
    sNFatal(pVotesGranted->pNode, "vote granted raftId not matched with msg");
×
78
    return;
×
79
  }
80

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

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

98
  if (pVotesGranted->votes > pVotesGranted->replicaNum) {
1,003,623✔
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) {
511,378✔
106
  pVotesGranted->term = term;
511,378✔
107
  voteGrantedClearVotes(pVotesGranted);
511,378✔
108
  pVotesGranted->toLeader = false;
511,378✔
109
}
511,378✔
110

111
SVotesRespond *votesRespondCreate(SSyncNode *pNode) {
4,403,734✔
112
  SVotesRespond *pVotesRespond = taosMemoryCalloc(1, sizeof(SVotesRespond));
4,403,734✔
113
  if (pVotesRespond == NULL) {
4,405,172✔
114
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
115
    return NULL;
×
116
  }
117

118
  pVotesRespond->replicas = (void*)&pNode->replicasId;
4,405,172✔
119
  pVotesRespond->replicaNum = pNode->replicaNum;
4,405,172✔
120
  pVotesRespond->term = 0;
4,403,734✔
121
  pVotesRespond->pNode = pNode;
4,404,424✔
122

123
  return pVotesRespond;
4,404,773✔
124
}
125

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

132
void votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pNode) {
46,078✔
133
  pVotesRespond->replicas = (void*)&pNode->replicasId;
46,078✔
134
  pVotesRespond->replicaNum = pNode->replicaNum;
46,078✔
135
  pVotesRespond->term = 0;
46,078✔
136
  pVotesRespond->pNode = pNode;
46,078✔
137
}
46,078✔
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,063,128✔
151
  if (pVotesRespond->term != pMsg->term) {
1,063,128✔
152
    sNTrace(pVotesRespond->pNode, "vote respond add error");
×
153
    return;
×
154
  }
155

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

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

166
void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term) {
511,378✔
167
  pVotesRespond->term = term;
511,378✔
168
  (void)memset(pVotesRespond->isRespond, 0, sizeof(pVotesRespond->isRespond));
511,378✔
169
}
511,378✔
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