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

taosdata / TDengine / #3543

29 Nov 2024 02:58AM UTC coverage: 60.842% (+0.02%) from 60.819%
#3543

push

travis-ci

web-flow
Merge pull request #28973 from taosdata/merge/mainto3.0

merge: from main to 3.0

120460 of 253224 branches covered (47.57%)

Branch coverage included in aggregate %.

706 of 908 new or added lines in 18 files covered. (77.75%)

2401 existing lines in 137 files now uncovered.

201633 of 276172 relevant lines covered (73.01%)

19045673.23 hits per line

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

46.53
/source/libs/sync/src/syncIndexMgr.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 "syncIndexMgr.h"
18
#include "syncUtil.h"
19

20
SSyncIndexMgr *syncIndexMgrCreate(SSyncNode *pNode) {
31,815✔
21
  SSyncIndexMgr *pIndexMgr = taosMemoryCalloc(1, sizeof(SSyncIndexMgr));
31,815✔
22
  if (pIndexMgr == NULL) {
31,816!
23
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
24
    return NULL;
×
25
  }
26

27
  pIndexMgr->replicas = &pNode->replicasId;
31,816✔
28
  pIndexMgr->replicaNum = pNode->replicaNum;
31,816✔
29
  pIndexMgr->totalReplicaNum = pNode->totalReplicaNum;
31,816✔
30
  pIndexMgr->pNode = pNode;
31,816✔
31
  syncIndexMgrClear(pIndexMgr);
31,816✔
32

33
  return pIndexMgr;
31,816✔
34
}
35

36
void syncIndexMgrUpdate(SSyncIndexMgr *pIndexMgr, SSyncNode *pNode) {
582✔
37
  pIndexMgr->replicas = &pNode->replicasId;
582✔
38
  pIndexMgr->replicaNum = pNode->replicaNum;
582✔
39
  pIndexMgr->totalReplicaNum = pNode->totalReplicaNum;
582✔
40
  pIndexMgr->pNode = pNode;
582✔
41
  syncIndexMgrClear(pIndexMgr);
582✔
42
}
582✔
43

44
void syncIndexMgrDestroy(SSyncIndexMgr *pIndexMgr) {
31,813✔
45
  if (pIndexMgr != NULL) {
31,813!
46
    taosMemoryFree(pIndexMgr);
31,813✔
47
  }
48
}
31,813✔
49

50
void syncIndexMgrClear(SSyncIndexMgr *pIndexMgr) {
32,398✔
51
  memset(pIndexMgr->index, 0, sizeof(pIndexMgr->index));
32,398✔
52
  memset(pIndexMgr->privateTerm, 0, sizeof(pIndexMgr->privateTerm));
32,398✔
53

54
  int64_t timeNow = taosGetTimestampMs();
32,398✔
55
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
79,942✔
56
    pIndexMgr->startTimeArr[i] = 0;
47,544✔
57
    pIndexMgr->recvTimeArr[i] = timeNow;
47,544✔
58
  }
59
}
32,398✔
60

61
void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncIndex index) {
15,646,792✔
62
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
20,950,272!
63
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
20,950,595✔
64
      (pIndexMgr->index)[i] = index;
15,647,314✔
65
      return;
15,647,314✔
66
    }
67
  }
68

69
  sError("vgId:%d, indexmgr set index:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, index,
×
70
         DID(pRaftId), CID(pRaftId));
71
}
72

73
void syncIndexMgrCopyIfExist(SSyncIndexMgr * pNewIndex, SSyncIndexMgr * pOldIndex, SRaftId *oldReplicasId){
×
74
  for(int j = 0; j < pOldIndex->totalReplicaNum; ++j){
×
75
    sDebug("old Index j:%d, index:%"PRId64, j, pOldIndex->index[j]);
×
76
  }
77
  
78
  for (int i = 0; i < pNewIndex->totalReplicaNum; ++i) {
×
79
    for(int j = 0; j < pOldIndex->totalReplicaNum; ++j){
×
80
      if (syncUtilSameId(/*(const SRaftId*)*/&((oldReplicasId[j])), &((*(pNewIndex->replicas))[i]))) {
×
81
        pNewIndex->index[i] = pOldIndex->index[j];
×
82
        pNewIndex->privateTerm[i] = pOldIndex->privateTerm[j];
×
83
        pNewIndex->startTimeArr[i] = pOldIndex->startTimeArr[j];
×
84
        pNewIndex->recvTimeArr[i] = pOldIndex->recvTimeArr[j];   
×
85
      }
86
    }
87
  }
88

89
  for (int i = 0; i < pNewIndex->totalReplicaNum; ++i){
×
90
    sDebug("new index i:%d, index:%"PRId64, i, pNewIndex->index[i]);
×
91
  }
92
}
×
93

94
SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
5,535,172✔
95
  for (int i = 0; i < pNode->totalReplicaNum; i++) {
11,125,883✔
96
    if (syncUtilSameId(&pNode->replicasId[i], pRaftId)) {
11,125,879✔
97
      return pNode->logReplMgrs[i];
5,535,169✔
98
    }
99
  }
100

101
  terrno = TSDB_CODE_SYN_INVALID_ID;
4✔
102
  sError("vgId:%d, indexmgr get replmgr from dnode:%d cluster:%d failed", pNode->vgId, DID(pRaftId), CID(pRaftId));
2!
103
  return NULL;
2✔
104
}
105

106
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
2,640,126✔
107
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
5,306,751✔
108
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
5,306,750✔
109
      SyncIndex idx = (pIndexMgr->index)[i];
2,640,126✔
110
      return idx;
2,640,126✔
111
    }
112
  }
113

114
  terrno = TSDB_CODE_SYN_INVALID_ID;
1✔
115
  sError("vgId:%d, indexmgr get index from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
116
         CID(pRaftId));
117
  return SYNC_INDEX_INVALID;
×
118
}
119

120
void syncIndexMgrSetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, int64_t startTime) {
×
121
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
122
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
123
      (pIndexMgr->startTimeArr)[i] = startTime;
×
124
      return;
×
125
    }
126
  }
127

128
  sError("vgId:%d, indexmgr set start-time:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId,
×
129
         startTime, DID(pRaftId), CID(pRaftId));
130
}
131

132
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
×
133
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
134
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
135
      int64_t startTime = (pIndexMgr->startTimeArr)[i];
×
136
      return startTime;
×
137
    }
138
  }
139

140
  sError("vgId:%d, indexmgr get start-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
141
         CID(pRaftId));
142
  return TSDB_CODE_SYN_INVALID_ID;
×
143
  ;
144
}
145

146
void syncIndexMgrSetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, int64_t recvTime) {
89,744✔
147
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
174,449!
148
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
174,449✔
149
      (pIndexMgr->recvTimeArr)[i] = recvTime;
89,744✔
150
      return;
89,744✔
151
    }
152
  }
153

UNCOV
154
  sError("vgId:%d, indexmgr set recv-time:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, recvTime,
×
155
         DID(pRaftId), CID(pRaftId));
156
}
157

158
void syncIndexMgrSetSentTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, int64_t sentTime) {
48,321✔
159
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
101,016!
160
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
101,016✔
161
      (pIndexMgr->sentTimeArr)[i] = sentTime;
48,321✔
162
      return;
48,321✔
163
    }
164
  }
165

166
  sError("vgId:%d, indexmgr set sent-time:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, sentTime,
×
167
         DID(pRaftId), CID(pRaftId));
168
}
169

170
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
878,840✔
171
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
1,347,876!
172
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
1,347,881✔
173
      int64_t recvTime = (pIndexMgr->recvTimeArr)[i];
878,842✔
174
      return recvTime;
878,842✔
175
    }
176
  }
177

178
  sError("vgId:%d, indexmgr get recv-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
179
         CID(pRaftId));
180
  return TSDB_CODE_SYN_INVALID_ID;
×
181
}
182

183
int64_t syncIndexMgrGetSentTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
288,300✔
184
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
373,839!
185
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
373,839✔
186
      int64_t recvTime = (pIndexMgr->sentTimeArr)[i];
288,295✔
187
      return recvTime;
288,295✔
188
    }
189
  }
190

191
  sError("vgId:%d, indexmgr get sent-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
192
         CID(pRaftId));
193
  return TSDB_CODE_SYN_INVALID_ID;
×
194
}
195

196
void syncIndexMgrSetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncTerm term) {
×
197
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
198
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
199
      (pIndexMgr->privateTerm)[i] = term;
×
200
      return;
×
201
    }
202
  }
203

204
  sError("vgId:%d, indexmgr set term:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, term,
×
205
         DID(pRaftId), CID(pRaftId));
206
}
207

208
SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
×
209
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
210
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
211
      SyncTerm term = (pIndexMgr->privateTerm)[i];
×
212
      return term;
×
213
    }
214
  }
215

216
  sError("vgId:%d, indexmgr get term from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
217
         CID(pRaftId));
218
  return TSDB_CODE_SYN_INVALID_ID;
×
219
}
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