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

taosdata / TDengine / #3571

31 Dec 2024 08:57AM UTC coverage: 63.276% (+0.3%) from 62.94%
#3571

push

travis-ci

web-flow
Merge pull request #29434 from taosdata/enh/3.0/TD-33266-2

Fix(cover):fix some review errors in pr 29417.

140094 of 284342 branches covered (49.27%)

Branch coverage included in aggregate %.

217978 of 281543 relevant lines covered (77.42%)

20036556.91 hits per line

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

64.19
/source/dnode/vnode/src/vnd/vnodeSync.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 "sync.h"
18
#include "tq.h"
19
#include "tqCommon.h"
20
#include "tsdb.h"
21
#include "vnd.h"
22

23
#define BATCH_ENABLE 0
24

25
static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; }
10,447,647✔
26

27
static inline void vnodeWaitBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) {
2,288✔
28
  const STraceId *trace = &pMsg->info.traceId;
2,288✔
29
  vGTrace("vgId:%d, msg:%p wait block, type:%s sec:%d seq:%" PRId64, pVnode->config.vgId, pMsg,
2,288!
30
          TMSG_INFO(pMsg->msgType), pVnode->blockSec, pVnode->blockSeq);
31
  if (tsem_wait(&pVnode->syncSem) != 0) {
2,288!
32
    vError("vgId:%d, failed to wait sem", pVnode->config.vgId);
×
33
  }
34
}
2,288✔
35

36
static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) {
2,952,695✔
37
  if (vnodeIsMsgBlock(pMsg->msgType)) {
2,952,695✔
38
    const STraceId *trace = &pMsg->info.traceId;
18,736✔
39
    (void)taosThreadMutexLock(&pVnode->lock);
18,736✔
40
    if (pVnode->blocked) {
18,737✔
41
      vGTrace("vgId:%d, msg:%p post block, type:%s sec:%d seq:%" PRId64, pVnode->config.vgId, pMsg,
2,257!
42
              TMSG_INFO(pMsg->msgType), pVnode->blockSec, pVnode->blockSeq);
43
      pVnode->blocked = false;
2,257✔
44
      pVnode->blockSec = 0;
2,257✔
45
      pVnode->blockSeq = 0;
2,257✔
46
      if (tsem_post(&pVnode->syncSem) != 0) {
2,257!
47
        vError("vgId:%d, failed to post sem", pVnode->config.vgId);
×
48
      }
49
    }
50
    (void)taosThreadMutexUnlock(&pVnode->lock);
18,737✔
51
  }
52
}
2,952,707✔
53

54
void vnodeRedirectRpcMsg(SVnode *pVnode, SRpcMsg *pMsg, int32_t code) {
40,316✔
55
  SEpSet newEpSet = {0};
40,316✔
56
  syncGetRetryEpSet(pVnode->sync, &newEpSet);
40,316✔
57

58
  const STraceId *trace = &pMsg->info.traceId;
40,316✔
59
  vGTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", pVnode->config.vgId, pMsg,
40,316!
60
          newEpSet.numOfEps, newEpSet.inUse);
61
  for (int32_t i = 0; i < newEpSet.numOfEps; ++i) {
154,005✔
62
    vGTrace("vgId:%d, msg:%p redirect:%d ep:%s:%u", pVnode->config.vgId, pMsg, i, newEpSet.eps[i].fqdn,
113,689!
63
            newEpSet.eps[i].port);
64
  }
65
  pMsg->info.hasEpSet = 1;
40,316✔
66

67
  if (code == 0) code = TSDB_CODE_SYN_NOT_LEADER;
40,316!
68

69
  SRpcMsg rsp = {.code = code, .info = pMsg->info, .msgType = pMsg->msgType + 1};
40,316✔
70
  int32_t contLen = tSerializeSEpSet(NULL, 0, &newEpSet);
40,316✔
71

72
  rsp.pCont = rpcMallocCont(contLen);
40,316✔
73
  if (rsp.pCont == NULL) {
40,316!
74
    pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
×
75
  } else {
76
    if (tSerializeSEpSet(rsp.pCont, contLen, &newEpSet) < 0) {
40,316!
77
      vError("vgId:%d, failed to serialize ep set", pVnode->config.vgId);
×
78
    }
79
    rsp.contLen = contLen;
40,316✔
80
  }
81

82
  tmsgSendRsp(&rsp);
40,316✔
83
}
40,316✔
84

85
static void inline vnodeHandleWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
10,188,546✔
86
  SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info};
10,188,546✔
87
  if (vnodeProcessWriteMsg(pVnode, pMsg, pMsg->info.conn.applyIndex, &rsp) < 0) {
10,188,546✔
88
    rsp.code = terrno;
568✔
89
    const STraceId *trace = &pMsg->info.traceId;
554✔
90
    vGError("vgId:%d, msg:%p failed to apply right now since %s", pVnode->config.vgId, pMsg, terrstr());
554!
91
  }
92
  if (rsp.info.handle != NULL) {
10,188,690✔
93
    tmsgSendRsp(&rsp);
10,152,594✔
94
  } else {
95
    if (rsp.pCont) {
36,096✔
96
      rpcFreeCont(rsp.pCont);
26,020✔
97
    }
98
  }
99
}
10,188,880✔
100

101
static void vnodeHandleProposeError(SVnode *pVnode, SRpcMsg *pMsg, int32_t code) {
130,061✔
102
  if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_RESTORING) {
130,061✔
103
    vnodeRedirectRpcMsg(pVnode, pMsg, code);
32,004✔
104
  } else if (code == TSDB_CODE_MSG_PREPROCESSED) {
98,057✔
105
    SRpcMsg rsp = {.code = TSDB_CODE_SUCCESS, .info = pMsg->info};
95,905✔
106
    if (rsp.info.handle != NULL) {
95,905!
107
      tmsgSendRsp(&rsp);
96,082✔
108
    }
109
  } else {
110
    const STraceId *trace = &pMsg->info.traceId;
2,152✔
111
    vGError("vgId:%d, msg:%p failed to propose since %s, code:0x%x", pVnode->config.vgId, pMsg, tstrerror(code), code);
2,152!
112
    SRpcMsg rsp = {.code = code, .info = pMsg->info};
2,152✔
113
    if (rsp.info.handle != NULL) {
2,152✔
114
      tmsgSendRsp(&rsp);
1,699✔
115
    }
116
  }
117
}
130,361✔
118

119
static int32_t inline vnodeProposeMsg(SVnode *pVnode, SRpcMsg *pMsg, bool isWeak) {
10,329,273✔
120
  int64_t seq = 0;
10,329,273✔
121

122
  (void)taosThreadMutexLock(&pVnode->lock);
10,329,273✔
123
  int32_t code = syncPropose(pVnode->sync, pMsg, isWeak, &seq);
10,329,665✔
124
  bool    wait = (code == 0 && vnodeIsMsgBlock(pMsg->msgType));
10,329,319✔
125
  if (wait) {
10,329,319✔
126
    if (pVnode->blocked) {
2,288!
127
      return TSDB_CODE_INTERNAL_ERROR;
×
128
    }
129
    pVnode->blocked = true;
2,288✔
130
    pVnode->blockSec = taosGetTimestampSec();
2,288✔
131
    pVnode->blockSeq = seq;
2,288✔
132
  }
133
  (void)taosThreadMutexUnlock(&pVnode->lock);
10,329,319✔
134

135
  if (code > 0) {
10,329,600✔
136
    vnodeHandleWriteMsg(pVnode, pMsg);
10,188,868✔
137
  } else if (code < 0) {
140,732✔
138
    if (terrno != 0) code = terrno;
11,398!
139
    vnodeHandleProposeError(pVnode, pMsg, code);
11,398✔
140
  }
141

142
  if (wait) vnodeWaitBlockMsg(pVnode, pMsg);
10,329,592✔
143
  return code;
10,329,609✔
144
}
145

146
void vnodeProposeCommitOnNeed(SVnode *pVnode, bool atExit) {
10,436,392✔
147
  if (!vnodeShouldCommit(pVnode, atExit)) {
10,436,392✔
148
    return;
10,428,980✔
149
  }
150

151
  int32_t   contLen = sizeof(SMsgHead);
8,218✔
152
  SMsgHead *pHead = rpcMallocCont(contLen);
8,218✔
153
  pHead->contLen = contLen;
8,224✔
154
  pHead->vgId = pVnode->config.vgId;
8,224✔
155

156
  SRpcMsg rpcMsg = {0};
8,224✔
157
  rpcMsg.msgType = TDMT_VND_COMMIT;
8,224✔
158
  rpcMsg.contLen = contLen;
8,224✔
159
  rpcMsg.pCont = pHead;
8,224✔
160
  rpcMsg.info.noResp = 1;
8,224✔
161

162
  vInfo("vgId:%d, propose vnode commit", pVnode->config.vgId);
8,224✔
163
  bool isWeak = false;
8,224✔
164

165
  if (!atExit) {
8,224✔
166
    if (vnodeProposeMsg(pVnode, &rpcMsg, isWeak) < 0) {
737!
167
      vTrace("vgId:%d, failed to propose vnode commit since %s", pVnode->config.vgId, terrstr());
×
168
    }
169
    rpcFreeCont(rpcMsg.pCont);
737✔
170
    rpcMsg.pCont = NULL;
737✔
171
  } else {
172
    if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
7,487✔
173
      vTrace("vgId:%d, failed to put vnode commit to queue since %s", pVnode->config.vgId, terrstr());
3,428✔
174
    }
175
  }
176
}
177

178
#if BATCH_ENABLE
179

180
static void inline vnodeProposeBatchMsg(SVnode *pVnode, SRpcMsg **pMsgArr, bool *pIsWeakArr, int32_t *arrSize) {
181
  if (*arrSize <= 0) return;
182
  SRpcMsg *pLastMsg = pMsgArr[*arrSize - 1];
183

184
  (void)taosThreadMutexLock(&pVnode->lock);
185
  int32_t code = syncProposeBatch(pVnode->sync, pMsgArr, pIsWeakArr, *arrSize);
186
  bool    wait = (code == 0 && vnodeIsBlockMsg(pLastMsg->msgType));
187
  if (wait) {
188
    pVnode->blocked = true;
189
  }
190
  (void)taosThreadMutexUnlock(&pVnode->lock);
191

192
  if (code > 0) {
193
    for (int32_t i = 0; i < *arrSize; ++i) {
194
      vnodeHandleWriteMsg(pVnode, pMsgArr[i]);
195
    }
196
  } else if (code < 0) {
197
    if (terrno != 0) code = terrno;
198
    for (int32_t i = 0; i < *arrSize; ++i) {
199
      vnodeHandleProposeError(pVnode, pMsgArr[i], code);
200
    }
201
  }
202

203
  if (wait) vnodeWaitBlockMsg(pVnode, pLastMsg);
204
  pLastMsg = NULL;
205

206
  for (int32_t i = 0; i < *arrSize; ++i) {
207
    SRpcMsg        *pMsg = pMsgArr[i];
208
    const STraceId *trace = &pMsg->info.traceId;
209
    vGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->config.vgId, pMsg, code);
210
    rpcFreeCont(pMsg->pCont);
211
    taosFreeQitem(pMsg);
212
  }
213

214
  *arrSize = 0;
215
}
216

217
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
218
  SVnode   *pVnode = pInfo->ahandle;
219
  int32_t   vgId = pVnode->config.vgId;
220
  int32_t   code = 0;
221
  SRpcMsg  *pMsg = NULL;
222
  int32_t   arrayPos = 0;
223
  SRpcMsg **pMsgArr = taosMemoryCalloc(numOfMsgs, sizeof(SRpcMsg *));
224
  bool     *pIsWeakArr = taosMemoryCalloc(numOfMsgs, sizeof(bool));
225
  vTrace("vgId:%d, get %d msgs from vnode-write queue", vgId, numOfMsgs);
226

227
  for (int32_t msg = 0; msg < numOfMsgs; msg++) {
228
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
229
    bool isWeak = vnodeIsMsgWeak(pMsg->msgType);
230
    bool isBlock = vnodeIsMsgBlock(pMsg->msgType);
231

232
    const STraceId *trace = &pMsg->info.traceId;
233
    vGTrace("vgId:%d, msg:%p get from vnode-write queue, weak:%d block:%d msg:%d:%d pos:%d, handle:%p", vgId, pMsg,
234
            isWeak, isBlock, msg, numOfMsgs, arrayPos, pMsg->info.handle);
235

236
    if (!pVnode->restored) {
237
      vGWarn("vgId:%d, msg:%p failed to process since restore not finished, type:%s", vgId, pMsg,
238
             TMSG_INFO(pMsg->msgType));
239
      terrno = TSDB_CODE_SYN_RESTORING;
240
      vnodeHandleProposeError(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
241
      rpcFreeCont(pMsg->pCont);
242
      taosFreeQitem(pMsg);
243
      continue;
244
    }
245

246
    if (pMsgArr == NULL || pIsWeakArr == NULL) {
247
      vGError("vgId:%d, msg:%p failed to process since out of memory, type:%s", vgId, pMsg, TMSG_INFO(pMsg->msgType));
248
      terrno = TSDB_CODE_OUT_OF_MEMORY;
249
      vnodeHandleProposeError(pVnode, pMsg, terrno);
250
      rpcFreeCont(pMsg->pCont);
251
      taosFreeQitem(pMsg);
252
      continue;
253
    }
254

255
    bool atExit = false;
256
    vnodeProposeCommitOnNeed(pVnode, atExit);
257

258
    code = vnodePreProcessWriteMsg(pVnode, pMsg);
259
    if (code != 0) {
260
      vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr());
261
      rpcFreeCont(pMsg->pCont);
262
      taosFreeQitem(pMsg);
263
      continue;
264
    }
265

266
    if (isBlock) {
267
      vnodeProposeBatchMsg(pVnode, pMsgArr, pIsWeakArr, &arrayPos);
268
    }
269

270
    pMsgArr[arrayPos] = pMsg;
271
    pIsWeakArr[arrayPos] = isWeak;
272
    arrayPos++;
273

274
    if (isBlock || msg == numOfMsgs - 1) {
275
      vnodeProposeBatchMsg(pVnode, pMsgArr, pIsWeakArr, &arrayPos);
276
    }
277
  }
278

279
  taosMemoryFree(pMsgArr);
280
  taosMemoryFree(pIsWeakArr);
281
}
282

283
#else
284

285
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
9,031,081✔
286
  SVnode  *pVnode = pInfo->ahandle;
9,031,081✔
287
  int32_t  vgId = pVnode->config.vgId;
9,031,081✔
288
  int32_t  code = 0;
9,031,081✔
289
  SRpcMsg *pMsg = NULL;
9,031,081✔
290
  vTrace("vgId:%d, get %d msgs from vnode-write queue", vgId, numOfMsgs);
9,031,081✔
291

292
  for (int32_t msg = 0; msg < numOfMsgs; msg++) {
19,479,401✔
293
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
10,447,960!
294
    bool isWeak = vnodeIsMsgWeak(pMsg->msgType);
10,447,875✔
295

296
    const STraceId *trace = &pMsg->info.traceId;
10,447,660✔
297
    vGTrace("vgId:%d, msg:%p get from vnode-write queue, weak:%d block:%d msg:%d:%d, handle:%p", vgId, pMsg, isWeak,
10,447,660!
298
            vnodeIsMsgBlock(pMsg->msgType), msg, numOfMsgs, pMsg->info.handle);
299

300
    if (!pVnode->restored) {
10,447,660✔
301
      vGWarn("vgId:%d, msg:%p failed to process since restore not finished, type:%s", vgId, pMsg,
21,135!
302
             TMSG_INFO(pMsg->msgType));
303
      vnodeHandleProposeError(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
21,135✔
304
      rpcFreeCont(pMsg->pCont);
21,135✔
305
      taosFreeQitem(pMsg);
21,135✔
306
      continue;
21,135✔
307
    }
308

309
    bool atExit = false;
10,426,525✔
310
    vnodeProposeCommitOnNeed(pVnode, atExit);
10,426,525✔
311

312
    code = vnodePreProcessWriteMsg(pVnode, pMsg);
10,426,869✔
313
    if (code != 0) {
10,426,091✔
314
      if (code != TSDB_CODE_MSG_PREPROCESSED) {
97,562✔
315
        vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, tstrerror(code));
1,698!
316
      }
317
      vnodeHandleProposeError(pVnode, pMsg, code);
97,562✔
318
      rpcFreeCont(pMsg->pCont);
97,789✔
319
      taosFreeQitem(pMsg);
97,915✔
320
      continue;
97,916✔
321
    }
322

323
    code = vnodeProposeMsg(pVnode, pMsg, isWeak);
10,328,529✔
324

325
    vGTrace("vgId:%d, msg:%p is freed, code:0x%x", vgId, pMsg, code);
10,328,851!
326
    rpcFreeCont(pMsg->pCont);
10,328,851✔
327
    taosFreeQitem(pMsg);
10,328,942✔
328
  }
329
}
9,031,441✔
330

331
#endif
332

333
void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
2,012,933✔
334
  SVnode  *pVnode = pInfo->ahandle;
2,012,933✔
335
  int32_t  vgId = pVnode->config.vgId;
2,012,933✔
336
  int32_t  code = 0;
2,012,933✔
337
  SRpcMsg *pMsg = NULL;
2,012,933✔
338

339
  for (int32_t i = 0; i < numOfMsgs; ++i) {
4,965,889✔
340
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
2,952,934!
341
    const STraceId *trace = &pMsg->info.traceId;
2,952,924✔
342

343
    if (vnodeIsMsgBlock(pMsg->msgType)) {
2,952,924✔
344
      vGTrace("vgId:%d, msg:%p get from vnode-apply queue, type:%s handle:%p index:%" PRId64
18,738!
345
              ", blocking msg obtained sec:%d seq:%" PRId64,
346
              vgId, pMsg, TMSG_INFO(pMsg->msgType), pMsg->info.handle, pMsg->info.conn.applyIndex, pVnode->blockSec,
347
              pVnode->blockSeq);
348
    } else {
349
      vGTrace("vgId:%d, msg:%p get from vnode-apply queue, type:%s handle:%p index:%" PRId64, vgId, pMsg,
2,934,162!
350
              TMSG_INFO(pMsg->msgType), pMsg->info.handle, pMsg->info.conn.applyIndex);
351
    }
352

353
    SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info};
2,952,900✔
354
    if (rsp.code == 0) {
2,952,900✔
355
      if (vnodeProcessWriteMsg(pVnode, pMsg, pMsg->info.conn.applyIndex, &rsp) < 0) {
2,952,846!
356
        rsp.code = terrno;
×
357
        vGError("vgId:%d, msg:%p failed to apply since %s, index:%" PRId64, vgId, pMsg, terrstr(),
×
358
                pMsg->info.conn.applyIndex);
359
      }
360
    }
361

362
    vnodePostBlockMsg(pVnode, pMsg);
2,952,914✔
363
    if (rsp.info.handle != NULL) {
2,952,707✔
364
      tmsgSendRsp(&rsp);
129,301✔
365
    } else {
366
      if (rsp.pCont) {
2,823,406✔
367
        rpcFreeCont(rsp.pCont);
2,773,522✔
368
      }
369
    }
370

371
    vGTrace("vgId:%d, msg:%p is freed, code:0x%x index:%" PRId64, vgId, pMsg, rsp.code, pMsg->info.conn.applyIndex);
2,952,921!
372
    rpcFreeCont(pMsg->pCont);
2,952,921✔
373
    taosFreeQitem(pMsg);
2,952,820✔
374
  }
375
}
2,012,955✔
376

377
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
5,637,766✔
378
  const STraceId *trace = &pMsg->info.traceId;
5,637,766✔
379
  vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
5,637,766!
380

381
  int32_t code = syncProcessMsg(pVnode->sync, pMsg);
5,637,766✔
382
  if (code != 0) {
5,637,837✔
383
    vGError("vgId:%d, failed to process sync msg:%p type:%s, reason: %s", pVnode->config.vgId, pMsg,
10!
384
            TMSG_INFO(pMsg->msgType), tstrerror(code));
385
  }
386

387
  return code;
5,637,837✔
388
}
389

390
static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
×
391
  if (pMsg == NULL || pMsg->pCont == NULL) {
×
392
    return TSDB_CODE_INVALID_PARA;
×
393
  }
394

395
  if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
×
396
    rpcFreeCont(pMsg->pCont);
×
397
    pMsg->pCont = NULL;
×
398
    return TSDB_CODE_INVALID_PARA;
×
399
  }
400

401
  int32_t code = tmsgPutToQueue(msgcb, SYNC_RD_QUEUE, pMsg);
×
402
  if (code != 0) {
×
403
    rpcFreeCont(pMsg->pCont);
×
404
    pMsg->pCont = NULL;
×
405
  }
406
  return code;
×
407
}
408

409
static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
360,435✔
410
  if (pMsg == NULL || pMsg->pCont == NULL) {
360,435!
411
    return TSDB_CODE_INVALID_PARA;
×
412
  }
413

414
  if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
360,436!
415
    rpcFreeCont(pMsg->pCont);
×
416
    pMsg->pCont = NULL;
×
417
    return TSDB_CODE_INVALID_PARA;
×
418
  }
419

420
  int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg);
360,436✔
421
  if (code != 0) {
360,437✔
422
    rpcFreeCont(pMsg->pCont);
1,313✔
423
    pMsg->pCont = NULL;
1,312✔
424
  }
425
  return code;
360,436✔
426
}
427

428
static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
5,297,506✔
429
  int32_t code = tmsgSendSyncReq(pEpSet, pMsg);
5,297,506✔
430
  if (code != 0) {
5,297,528!
431
    rpcFreeCont(pMsg->pCont);
×
432
    pMsg->pCont = NULL;
×
433
  }
434
  return code;
5,297,529✔
435
}
436

437
static int32_t vnodeSyncGetSnapshotInfo(const SSyncFSM *pFsm, SSnapshot *pSnapshot) {
442,952✔
438
  return vnodeGetSnapshot(pFsm->data, pSnapshot);
442,952✔
439
}
440

441
static int32_t vnodeSyncApplyMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
2,953,535✔
442
  SVnode *pVnode = pFsm->data;
2,953,535✔
443
  pMsg->info.conn.applyIndex = pMeta->index;
2,953,535✔
444
  pMsg->info.conn.applyTerm = pMeta->term;
2,953,535✔
445

446
  const STraceId *trace = &pMsg->info.traceId;
2,953,535✔
447
  vGTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64
2,953,535!
448
          ", weak:%d, code:%d, state:%d %s, type:%s code:0x%x",
449
          pVnode->config.vgId, pFsm, pMeta->index, pMeta->term, pMsg->info.conn.applyIndex, pMeta->isWeak, pMeta->code,
450
          pMeta->state, syncStr(pMeta->state), TMSG_INFO(pMsg->msgType), pMsg->code);
451

452
  return tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, pMsg);
2,953,535✔
453
}
454

455
static int32_t vnodeSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
2,953,537✔
456
  if (pMsg->code == 0) {
2,953,537!
457
    return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
2,953,538✔
458
  }
459

460
  const STraceId *trace = &pMsg->info.traceId;
×
461
  SVnode         *pVnode = pFsm->data;
×
462
  vnodePostBlockMsg(pVnode, pMsg);
×
463

464
  SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info};
×
465
  if (rsp.info.handle != NULL) {
×
466
    tmsgSendRsp(&rsp);
×
467
  }
468

469
  vGTrace("vgId:%d, msg:%p is freed, code:0x%x index:%" PRId64, TD_VID(pVnode), pMsg, rsp.code, pMeta->index);
×
470
  rpcFreeCont(pMsg->pCont);
×
471
  pMsg->pCont = NULL;
×
472
  return 0;
×
473
}
474

475
static int32_t vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
×
476
  if (pMeta->isWeak == 1) {
×
477
    return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
×
478
  }
479
  return 0;
×
480
}
481

482
static SyncIndex vnodeSyncAppliedIndex(const SSyncFSM *pFSM) {
10,513,067✔
483
  SVnode *pVnode = pFSM->data;
10,513,067✔
484
  return atomic_load_64(&pVnode->state.applied);
10,513,067✔
485
}
486

487
static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
×
488
  SVnode *pVnode = pFsm->data;
×
489
  vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
×
490
         pVnode->config.vgId, pFsm, pMeta->index, pMeta->isWeak, pMeta->code, pMeta->state, syncStr(pMeta->state),
491
         TMSG_INFO(pMsg->msgType));
492
}
×
493

494
static int32_t vnodeSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) {
72✔
495
  SVnode *pVnode = pFsm->data;
72✔
496
  return vnodeSnapReaderOpen(pVnode, (SSnapshotParam *)pParam, (SVSnapReader **)ppReader);
72✔
497
}
498

499
static void vnodeSnapshotStopRead(const SSyncFSM *pFsm, void *pReader) {
72✔
500
  SVnode *pVnode = pFsm->data;
72✔
501
  vnodeSnapReaderClose(pReader);
72✔
502
}
72✔
503

504
static int32_t vnodeSnapshotDoRead(const SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) {
57,858✔
505
  SVnode *pVnode = pFsm->data;
57,858✔
506
  return vnodeSnapRead(pReader, (uint8_t **)ppBuf, len);
57,858✔
507
}
508

509
static int32_t vnodeSnapshotStartWrite(const SSyncFSM *pFsm, void *pParam, void **ppWriter) {
70✔
510
  SVnode *pVnode = pFsm->data;
70✔
511

512
  do {
×
513
    int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
70✔
514
    if (itemSize == 0) {
70!
515
      vInfo("vgId:%d, start write vnode snapshot since apply queue is empty", pVnode->config.vgId);
70!
516
      break;
70✔
517
    } else {
518
      vInfo("vgId:%d, write vnode snapshot later since %d items in apply queue", pVnode->config.vgId, itemSize);
×
519
      taosMsleep(10);
×
520
    }
521
  } while (true);
522

523
  return vnodeSnapWriterOpen(pVnode, (SSnapshotParam *)pParam, (SVSnapWriter **)ppWriter);
70✔
524
}
525

526
static int32_t vnodeSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) {
70✔
527
  SVnode *pVnode = pFsm->data;
70✔
528
  vInfo("vgId:%d, stop write vnode snapshot, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64,
70!
529
        pVnode->config.vgId, isApply, pSnapshot->lastApplyIndex, pSnapshot->lastApplyTerm, pSnapshot->lastConfigIndex);
530

531
  int32_t code = vnodeSnapWriterClose(pWriter, !isApply, pSnapshot);
70✔
532
  if (code != 0) {
70!
533
    vError("vgId:%d, failed to finish applying vnode snapshot since %s, code:0x%x", pVnode->config.vgId, terrstr(),
×
534
           code);
535
  }
536
  return code;
70✔
537
}
538

539
static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
57,728✔
540
  SVnode *pVnode = pFsm->data;
57,728✔
541
  vDebug("vgId:%d, continue write vnode snapshot, blockLen:%d", pVnode->config.vgId, len);
57,728!
542
  int32_t code = vnodeSnapWrite(pWriter, pBuf, len);
57,728✔
543
  vDebug("vgId:%d, continue write vnode snapshot finished, blockLen:%d", pVnode->config.vgId, len);
57,728!
544
  return code;
57,728✔
545
}
546

547
static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) {
12,157✔
548
  SVnode   *pVnode = pFsm->data;
12,157✔
549
  int32_t   vgId = pVnode->config.vgId;
12,157✔
550
  SyncIndex appliedIdx = -1;
12,157✔
551

552
  do {
553
    appliedIdx = vnodeSyncAppliedIndex(pFsm);
24,712✔
554
    if (appliedIdx > commitIdx) {
24,717!
555
      vError("vgId:%d, restore failed since applied-index:%" PRId64 " is larger than commit-index:%" PRId64, vgId,
×
556
             appliedIdx, commitIdx);
557
      break;
×
558
    }
559
    if (appliedIdx == commitIdx) {
24,717✔
560
      vInfo("vgId:%d, no items to be applied, restore finish", pVnode->config.vgId);
12,157✔
561
      break;
12,157✔
562
    } else {
563
      vInfo("vgId:%d, restore not finish since %" PRId64 " items to be applied. commit-index:%" PRId64
12,560✔
564
            ", applied-index:%" PRId64,
565
            vgId, commitIdx - appliedIdx, commitIdx, appliedIdx);
566
      taosMsleep(10);
12,560✔
567
    }
568
  } while (true);
569

570
  walApplyVer(pVnode->pWal, commitIdx);
12,157✔
571
  pVnode->restored = true;
12,157✔
572

573
  SStreamMeta *pMeta = pVnode->pTq->pStreamMeta;
12,157✔
574
  streamMetaWLock(pMeta);
12,157✔
575

576
  if (pMeta->startInfo.tasksWillRestart) {
12,157!
577
    vInfo("vgId:%d, sync restore finished, stream tasks will be launched by other thread", vgId);
×
578
    streamMetaWUnLock(pMeta);
×
579
    return;
×
580
  }
581

582
  if (vnodeIsRoleLeader(pVnode)) {
12,157✔
583
    // start to restore all stream tasks
584
    if (tsDisableStream) {
10,282!
585
      vInfo("vgId:%d, sync restore finished, not launch stream tasks, since stream tasks are disabled", vgId);
×
586
    } else {
587
      vInfo("vgId:%d sync restore finished, start to launch stream task(s)", vgId);
10,282✔
588
      if (pMeta->startInfo.startAllTasks == 1) {
10,283✔
589
        pMeta->startInfo.restartCount += 1;
5✔
590
        vDebug("vgId:%d in start tasks procedure, inc restartCounter by 1, remaining restart:%d", vgId,
5✔
591
               pMeta->startInfo.restartCount);
592
      } else {
593
        pMeta->startInfo.startAllTasks = 1;
10,278✔
594
        streamMetaWUnLock(pMeta);
10,278✔
595

596
        tqInfo("vgId:%d stream task already loaded, start them", vgId);
10,278!
597
        int32_t code = streamTaskSchedTask(&pVnode->msgCb, TD_VID(pVnode), 0, 0, STREAM_EXEC_T_START_ALL_TASKS);
10,278✔
598
        if (code != 0) {
10,278!
599
          tqError("vgId:%d failed to sched stream task, code:%s", vgId, tstrerror(code));
×
600
        }
601
        return;
10,278✔
602
      }
603
    }
604
  } else {
605
    vInfo("vgId:%d, sync restore finished, not launch stream tasks since not leader", vgId);
1,874!
606
  }
607

608
  streamMetaWUnLock(pMeta);
1,879✔
609
}
610

611
static void vnodeBecomeFollower(const SSyncFSM *pFsm) {
4,672✔
612
  SVnode *pVnode = pFsm->data;
4,672✔
613
  vInfo("vgId:%d, become follower", pVnode->config.vgId);
4,672!
614

615
  (void)taosThreadMutexLock(&pVnode->lock);
4,672✔
616
  if (pVnode->blocked) {
4,672!
617
    pVnode->blocked = false;
×
618
    vDebug("vgId:%d, become follower and post block", pVnode->config.vgId);
×
619
    if (tsem_post(&pVnode->syncSem) != 0) {
×
620
      vError("vgId:%d, failed to post sync semaphore", pVnode->config.vgId);
×
621
    }
622
  }
623
  (void)taosThreadMutexUnlock(&pVnode->lock);
4,672✔
624

625
  if (pVnode->pTq) {
4,672!
626
    tqUpdateNodeStage(pVnode->pTq, false);
4,672✔
627
    if (tqStopStreamTasksAsync(pVnode->pTq) != 0) {
4,672!
628
      vError("vgId:%d, failed to stop stream tasks", pVnode->config.vgId);
×
629
    }
630
  }
631
}
4,672✔
632

633
static void vnodeBecomeLearner(const SSyncFSM *pFsm) {
177✔
634
  SVnode *pVnode = pFsm->data;
177✔
635
  vInfo("vgId:%d, become learner", pVnode->config.vgId);
177!
636

637
  (void)taosThreadMutexLock(&pVnode->lock);
177✔
638
  if (pVnode->blocked) {
177!
639
    pVnode->blocked = false;
×
640
    vDebug("vgId:%d, become learner and post block", pVnode->config.vgId);
×
641
    if (tsem_post(&pVnode->syncSem) != 0) {
×
642
      vError("vgId:%d, failed to post sync semaphore", pVnode->config.vgId);
×
643
    }
644
  }
645
  (void)taosThreadMutexUnlock(&pVnode->lock);
177✔
646
}
177✔
647

648
static void vnodeBecomeLeader(const SSyncFSM *pFsm) {
10,283✔
649
  SVnode *pVnode = pFsm->data;
10,283✔
650
  vDebug("vgId:%d, become leader", pVnode->config.vgId);
10,283✔
651
  if (pVnode->pTq) {
10,283!
652
    tqUpdateNodeStage(pVnode->pTq, true);
10,283✔
653
  }
654
}
10,283✔
655

656
static void vnodeBecomeAssignedLeader(const SSyncFSM *pFsm) {
×
657
  SVnode *pVnode = pFsm->data;
×
658
  vDebug("vgId:%d, become assigned leader", pVnode->config.vgId);
×
659
  if (pVnode->pTq) {
×
660
    tqUpdateNodeStage(pVnode->pTq, true);
×
661
  }
662
}
×
663

664
static bool vnodeApplyQueueEmpty(const SSyncFSM *pFsm) {
×
665
  SVnode *pVnode = pFsm->data;
×
666

667
  if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) {
×
668
    int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
×
669
    return (itemSize == 0);
×
670
  } else {
671
    return true;
×
672
  }
673
}
674

675
static int32_t vnodeApplyQueueItems(const SSyncFSM *pFsm) {
160,110✔
676
  SVnode *pVnode = pFsm->data;
160,110✔
677

678
  if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) {
160,110!
679
    int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
160,124✔
680
    return itemSize;
160,125✔
681
  } else {
682
    return TSDB_CODE_INVALID_PARA;
×
683
  }
684
}
685

686
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
12,281✔
687
  SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM));
12,281!
688
  if (pFsm == NULL) {
12,281!
689
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
690
    return NULL;
×
691
  }
692
  pFsm->data = pVnode;
12,281✔
693
  pFsm->FpCommitCb = vnodeSyncCommitMsg;
12,281✔
694
  pFsm->FpAppliedIndexCb = vnodeSyncAppliedIndex;
12,281✔
695
  pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg;
12,281✔
696
  pFsm->FpRollBackCb = vnodeSyncRollBackMsg;
12,281✔
697
  pFsm->FpGetSnapshot = NULL;
12,281✔
698
  pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshotInfo;
12,281✔
699
  pFsm->FpRestoreFinishCb = vnodeRestoreFinish;
12,281✔
700
  pFsm->FpLeaderTransferCb = NULL;
12,281✔
701
  pFsm->FpApplyQueueEmptyCb = vnodeApplyQueueEmpty;
12,281✔
702
  pFsm->FpApplyQueueItems = vnodeApplyQueueItems;
12,281✔
703
  pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
12,281✔
704
  pFsm->FpBecomeAssignedLeaderCb = vnodeBecomeAssignedLeader;
12,281✔
705
  pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
12,281✔
706
  pFsm->FpBecomeLearnerCb = vnodeBecomeLearner;
12,281✔
707
  pFsm->FpReConfigCb = NULL;
12,281✔
708
  pFsm->FpSnapshotStartRead = vnodeSnapshotStartRead;
12,281✔
709
  pFsm->FpSnapshotStopRead = vnodeSnapshotStopRead;
12,281✔
710
  pFsm->FpSnapshotDoRead = vnodeSnapshotDoRead;
12,281✔
711
  pFsm->FpSnapshotStartWrite = vnodeSnapshotStartWrite;
12,281✔
712
  pFsm->FpSnapshotStopWrite = vnodeSnapshotStopWrite;
12,281✔
713
  pFsm->FpSnapshotDoWrite = vnodeSnapshotDoWrite;
12,281✔
714

715
  return pFsm;
12,281✔
716
}
717

718
int32_t vnodeSyncOpen(SVnode *pVnode, char *path, int32_t vnodeVersion) {
12,281✔
719
  SSyncInfo syncInfo = {
12,281✔
720
      .snapshotStrategy = SYNC_STRATEGY_WAL_FIRST,
721
      .batchSize = 1,
722
      .vgId = pVnode->config.vgId,
12,281✔
723
      .syncCfg = pVnode->config.syncCfg,
724
      .pWal = pVnode->pWal,
12,281✔
725
      .msgcb = &pVnode->msgCb,
12,281✔
726
      .syncSendMSg = vnodeSyncSendMsg,
727
      .syncEqMsg = vnodeSyncEqMsg,
728
      .syncEqCtrlMsg = vnodeSyncEqCtrlMsg,
729
      .pingMs = 5000,
730
      .electMs = 4000,
731
      .heartbeatMs = 700,
732
  };
733

734
  snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
12,281✔
735
  syncInfo.pFsm = vnodeSyncMakeFsm(pVnode);
12,281✔
736

737
  SSyncCfg *pCfg = &syncInfo.syncCfg;
12,281✔
738
  vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
12,281✔
739
  for (int32_t i = 0; i < pCfg->totalReplicaNum; ++i) {
30,755✔
740
    SNodeInfo *pNode = &pCfg->nodeInfo[i];
18,473✔
741
    vInfo("vgId:%d, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, pVnode->config.vgId, i, pNode->nodeFqdn,
18,473✔
742
          pNode->nodePort, pNode->nodeId, pNode->clusterId);
743
  }
744

745
  pVnode->sync = syncOpen(&syncInfo, vnodeVersion);
12,282✔
746
  if (pVnode->sync <= 0) {
12,281!
747
    vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
×
748
    return terrno;
×
749
  }
750

751
  return 0;
12,281✔
752
}
753

754
int32_t vnodeSyncStart(SVnode *pVnode) {
12,280✔
755
  vInfo("vgId:%d, start sync", pVnode->config.vgId);
12,280✔
756
  int32_t code = syncStart(pVnode->sync);
12,281✔
757
  if (code) {
12,281!
758
    vError("vgId:%d, failed to start sync subsystem since %s", pVnode->config.vgId, tstrerror(code));
×
759
    return code;
×
760
  }
761
  return 0;
12,281✔
762
}
763

764
void vnodeSyncPreClose(SVnode *pVnode) {
12,281✔
765
  vInfo("vgId:%d, sync pre close", pVnode->config.vgId);
12,281✔
766
  int32_t code = syncLeaderTransfer(pVnode->sync);
12,281✔
767
  if (code) {
12,281✔
768
    vError("vgId:%d, failed to transfer leader since %s", pVnode->config.vgId, tstrerror(code));
900!
769
  }
770
  syncPreStop(pVnode->sync);
12,281✔
771

772
  (void)taosThreadMutexLock(&pVnode->lock);
12,279✔
773
  if (pVnode->blocked) {
12,281✔
774
    vInfo("vgId:%d, post block after close sync", pVnode->config.vgId);
31!
775
    pVnode->blocked = false;
31✔
776
    if (tsem_post(&pVnode->syncSem) != 0) {
31!
777
      vError("vgId:%d, failed to post block", pVnode->config.vgId);
×
778
    }
779
  }
780
  (void)taosThreadMutexUnlock(&pVnode->lock);
12,281✔
781
}
12,281✔
782

783
void vnodeSyncPostClose(SVnode *pVnode) {
12,281✔
784
  vInfo("vgId:%d, sync post close", pVnode->config.vgId);
12,281✔
785
  syncPostStop(pVnode->sync);
12,281✔
786
}
12,280✔
787

788
void vnodeSyncClose(SVnode *pVnode) {
12,281✔
789
  vInfo("vgId:%d, close sync", pVnode->config.vgId);
12,281✔
790
  syncStop(pVnode->sync);
12,281✔
791
}
12,279✔
792

793
void vnodeSyncCheckTimeout(SVnode *pVnode) {
31,871✔
794
  vTrace("vgId:%d, check sync timeout msg", pVnode->config.vgId);
31,871✔
795
  (void)taosThreadMutexLock(&pVnode->lock);
31,871✔
796
  if (pVnode->blocked) {
31,871!
797
    int32_t curSec = taosGetTimestampSec();
×
798
    int32_t delta = curSec - pVnode->blockSec;
×
799
    if (delta > VNODE_TIMEOUT_SEC) {
×
800
      vError("vgId:%d, failed to propose since timeout and post block, start:%d cur:%d delta:%d seq:%" PRId64,
×
801
             pVnode->config.vgId, pVnode->blockSec, curSec, delta, pVnode->blockSeq);
802
      if (syncSendTimeoutRsp(pVnode->sync, pVnode->blockSeq) != 0) {
×
803
#if 0
804
        SRpcMsg rpcMsg = {.code = TSDB_CODE_SYN_TIMEOUT, .info = pVnode->blockInfo};
805
        vError("send timeout response since its applyed, seq:%" PRId64 " handle:%p ahandle:%p", pVnode->blockSeq,
806
              rpcMsg.info.handle, rpcMsg.info.ahandle);
807
        rpcSendResponse(&rpcMsg);
808
#endif
809
      }
810
      pVnode->blocked = false;
×
811
      pVnode->blockSec = 0;
×
812
      pVnode->blockSeq = 0;
×
813
      if (tsem_post(&pVnode->syncSem) != 0) {
×
814
        vError("vgId:%d, failed to post block", pVnode->config.vgId);
×
815
      }
816
    }
817
  }
818
  (void)taosThreadMutexUnlock(&pVnode->lock);
31,871✔
819
}
31,871✔
820

821
bool vnodeIsRoleLeader(SVnode *pVnode) {
675,869✔
822
  SSyncState state = syncGetState(pVnode->sync);
675,869✔
823
  return state.state == TAOS_SYNC_STATE_LEADER;
676,063✔
824
}
825

826
bool vnodeIsLeader(SVnode *pVnode) {
16,352✔
827
  terrno = 0;
16,352✔
828
  SSyncState state = syncGetState(pVnode->sync);
16,353✔
829

830
  if (terrno != 0) {
16,363✔
831
    vInfo("vgId:%d, vnode is stopping", pVnode->config.vgId);
2,128!
832
    return false;
2,128✔
833
  }
834

835
  if (state.state != TAOS_SYNC_STATE_LEADER) {
14,235!
836
    terrno = TSDB_CODE_SYN_NOT_LEADER;
×
837
    vInfo("vgId:%d, vnode not leader, state:%s", pVnode->config.vgId, syncStr(state.state));
×
838
    return false;
×
839
  }
840

841
  if (!state.restored || !pVnode->restored) {
14,235!
842
    terrno = TSDB_CODE_SYN_RESTORING;
×
843
    vInfo("vgId:%d, vnode not restored:%d:%d", pVnode->config.vgId, state.restored, pVnode->restored);
×
844
    return false;
×
845
  }
846

847
  return true;
14,235✔
848
}
849

850
int64_t vnodeClusterId(SVnode *pVnode) {
×
851
  SSyncCfg *syncCfg = &pVnode->config.syncCfg;
×
852
  return syncCfg->nodeInfo[syncCfg->myIndex].clusterId;
×
853
}
854

855
int32_t vnodeNodeId(SVnode *pVnode) {
468,243✔
856
  SSyncCfg *syncCfg = &pVnode->config.syncCfg;
468,243✔
857
  return syncCfg->nodeInfo[syncCfg->myIndex].nodeId;
468,243✔
858
}
859

860
int32_t vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnap) {
443,017✔
861
  int code = 0;
443,017✔
862
  pSnap->lastApplyIndex = pVnode->state.committed;
443,017✔
863
  pSnap->lastApplyTerm = pVnode->state.commitTerm;
443,017✔
864
  pSnap->lastConfigIndex = -1;
443,017✔
865
  pSnap->state = SYNC_FSM_STATE_COMPLETE;
443,017✔
866

867
  if (tsdbSnapGetFsState(pVnode) != TSDB_FS_STATE_NORMAL) {
443,017!
868
    pSnap->state = SYNC_FSM_STATE_INCOMPLETE;
×
869
  }
870

871
  if (pSnap->type == TDMT_SYNC_PREP_SNAPSHOT || pSnap->type == TDMT_SYNC_PREP_SNAPSHOT_REPLY) {
443,013✔
872
    code = tsdbSnapPrepDescription(pVnode, pSnap);
140✔
873
  }
874
  return code;
443,015✔
875
}
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