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

taosdata / TDengine / #3546

03 Dec 2024 10:02AM UTC coverage: 60.691% (-0.1%) from 60.839%
#3546

push

travis-ci

web-flow
Merge pull request #29015 from taosdata/fix/TS-5668

[TS-5668] fix(keeper): fix endpoint value too long for column/tag and eliminate warnings

120577 of 253823 branches covered (47.5%)

Branch coverage included in aggregate %.

201666 of 277134 relevant lines covered (72.77%)

18719900.08 hits per line

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

61.69
/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) {
17,525✔
22
  (void)memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted));
17,525✔
23
  pVotesGranted->votes = 0;
17,525✔
24
}
17,525✔
25

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

33
  pVotesGranted->replicas = (void*)&pNode->replicasId;
15,906✔
34
  pVotesGranted->replicaNum = pNode->replicaNum;
15,906✔
35
  voteGrantedClearVotes(pVotesGranted);
15,906✔
36

37
  pVotesGranted->term = 0;
15,906✔
38
  pVotesGranted->quorum = pNode->quorum;
15,906✔
39
  pVotesGranted->toLeader = false;
15,906✔
40
  pVotesGranted->pNode = pNode;
15,906✔
41

42
  return pVotesGranted;
15,906✔
43
}
44

45
void voteGrantedDestroy(SVotesGranted *pVotesGranted) {
15,903✔
46
  if (pVotesGranted != NULL) {
15,903!
47
    taosMemoryFree(pVotesGranted);
15,904✔
48
  }
49
}
15,904✔
50

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

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

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

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

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

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

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

98
  if (pVotesGranted->votes > pVotesGranted->replicaNum) {
2,462!
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) {
1,329✔
106
  pVotesGranted->term = term;
1,329✔
107
  voteGrantedClearVotes(pVotesGranted);
1,329✔
108
  pVotesGranted->toLeader = false;
1,329✔
109
}
1,329✔
110

111
SVotesRespond *votesRespondCreate(SSyncNode *pNode) {
15,906✔
112
  SVotesRespond *pVotesRespond = taosMemoryCalloc(1, sizeof(SVotesRespond));
15,906✔
113
  if (pVotesRespond == NULL) {
15,906!
114
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
115
    return NULL;
×
116
  }
117

118
  pVotesRespond->replicas = (void*)&pNode->replicasId;
15,906✔
119
  pVotesRespond->replicaNum = pNode->replicaNum;
15,906✔
120
  pVotesRespond->term = 0;
15,906✔
121
  pVotesRespond->pNode = pNode;
15,906✔
122

123
  return pVotesRespond;
15,906✔
124
}
125

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

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

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

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

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