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

taosdata / TDengine / #3522

07 Nov 2024 05:59AM UTC coverage: 58.216% (+1.3%) from 56.943%
#3522

push

travis-ci

web-flow
Merge pull request #28663 from taosdata/fix/3_liaohj

fix(stream): stop the underlying scan operations for stream

111884 of 248391 branches covered (45.04%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 1 file covered. (75.0%)

1164 existing lines in 134 files now uncovered.

191720 of 273118 relevant lines covered (70.2%)

13088725.13 hits per line

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

42.94
/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) {
12,880✔
21
  SSyncIndexMgr *pIndexMgr = taosMemoryCalloc(1, sizeof(SSyncIndexMgr));
12,880✔
22
  if (pIndexMgr == NULL) {
12,889!
23
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
24
    return NULL;
×
25
  }
26

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

33
  return pIndexMgr;
12,889✔
34
}
35

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

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

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

54
  int64_t timeNow = taosGetTimestampMs();
13,267✔
55
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
34,428✔
56
    pIndexMgr->startTimeArr[i] = 0;
21,161✔
57
    pIndexMgr->recvTimeArr[i] = timeNow;
21,161✔
58
  }
59
}
13,267✔
60

61
void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncIndex index) {
13,870,012✔
62
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
18,735,628!
63
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
18,735,815✔
64
      (pIndexMgr->index)[i] = index;
13,870,324✔
65
      return;
13,870,324✔
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) {
2,570,521✔
95
  for (int i = 0; i < pNode->totalReplicaNum; i++) {
5,141,797✔
96
    if (syncUtilSameId(&pNode->replicasId[i], pRaftId)) {
5,141,795✔
97
      return pNode->logReplMgrs[i];
2,570,519✔
98
    }
99
  }
100

101
  terrno = TSDB_CODE_SYN_INVALID_ID;
2✔
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,447,464✔
107
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
4,896,755!
108
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
4,896,755✔
109
      SyncIndex idx = (pIndexMgr->index)[i];
2,447,464✔
110
      return idx;
2,447,464✔
111
    }
112
  }
113

UNCOV
114
  terrno = TSDB_CODE_SYN_INVALID_ID;
×
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) {
18,075✔
147
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
35,251!
148
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
35,251✔
149
      (pIndexMgr->recvTimeArr)[i] = recvTime;
18,075✔
150
      return;
18,075✔
151
    }
152
  }
153

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
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
221,721✔
159
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
411,823!
160
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
411,825✔
161
      int64_t recvTime = (pIndexMgr->recvTimeArr)[i];
221,718✔
162
      return recvTime;
221,718✔
163
    }
164
  }
165

UNCOV
166
  sError("vgId:%d, indexmgr get recv-time from dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, DID(pRaftId),
×
167
         CID(pRaftId));
168
  return TSDB_CODE_SYN_INVALID_ID;
×
169
}
170

171
void syncIndexMgrSetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncTerm term) {
×
172
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
173
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
174
      (pIndexMgr->privateTerm)[i] = term;
×
175
      return;
×
176
    }
177
  }
178

179
  sError("vgId:%d, indexmgr set term:%" PRId64 " for dnode:%d cluster:%d failed", pIndexMgr->pNode->vgId, term,
×
180
         DID(pRaftId), CID(pRaftId));
181
}
182

183
SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
×
184
  for (int i = 0; i < pIndexMgr->totalReplicaNum; ++i) {
×
185
    if (syncUtilSameId(&((*(pIndexMgr->replicas))[i]), pRaftId)) {
×
186
      SyncTerm term = (pIndexMgr->privateTerm)[i];
×
187
      return term;
×
188
    }
189
  }
190

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