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

taosdata / TDengine / #3530

16 Nov 2024 07:44AM UTC coverage: 60.219% (-0.7%) from 60.888%
#3530

push

travis-ci

web-flow
Update 03-ad.md

118417 of 252124 branches covered (46.97%)

Branch coverage included in aggregate %.

198982 of 274951 relevant lines covered (72.37%)

6072359.98 hits per line

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

76.41
/source/libs/sync/src/syncUtil.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 "syncUtil.h"
18
#include "syncIndexMgr.h"
19
#include "syncMessage.h"
20
#include "syncPipeline.h"
21
#include "syncRaftCfg.h"
22
#include "syncRaftStore.h"
23
#include "syncSnapshot.h"
24
#include "tglobal.h"
25

26
static void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
244,924✔
27
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
244,924✔
28
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
540,621✔
29
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
295,698✔
30
    if (i < pCfg->replicaNum - 1) {
295,704✔
31
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
50,782✔
32
    }
33
  }
34
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
244,923✔
35
}
244,923✔
36

37
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
7,224✔
38
  pEpSet->inUse = 0;
7,224✔
39
  pEpSet->numOfEps = 1;
7,224✔
40
  pEpSet->eps[0].port = pInfo->nodePort;
7,224✔
41
  tstrncpy(pEpSet->eps[0].fqdn, pInfo->nodeFqdn, TSDB_FQDN_LEN);
7,224✔
42
}
7,224✔
43

44
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
22,449✔
45
  uint32_t ipv4 = 0xFFFFFFFF;
22,449✔
46
  sDebug("vgId:%d, resolve sync addr from fqdn, ep:%s:%u", vgId, pInfo->nodeFqdn, pInfo->nodePort);
22,449✔
47
  for (int32_t i = 0; i < tsResolveFQDNRetryTime; i++) {
22,461!
48
    int32_t code = taosGetIpv4FromFqdn(pInfo->nodeFqdn, &ipv4);
22,461✔
49
    if (code) {
22,460!
50
      sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
×
51
      taosSsleep(1);
×
52
    } else {
53
      break;
22,460✔
54
    }
55
  }
56

57
  if (ipv4 == 0xFFFFFFFF || ipv4 == 1) {
22,460!
58
    sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s", vgId, pInfo->nodeId, pInfo->nodeFqdn);
×
59
    terrno = TSDB_CODE_TSC_INVALID_FQDN;
×
60
    return false;
×
61
  }
62

63
  char ipbuf[TD_IP_LEN] = {0};
22,461✔
64
  tinet_ntoa(ipbuf, ipv4);
22,461✔
65
  raftId->addr = SYNC_ADDR(pInfo);
22,461✔
66
  raftId->vgId = vgId;
22,461✔
67

68
  sInfo("vgId:%d, sync addr:%" PRIu64 " is resolved, ep:%s:%u ip:%s ipv4:%u dnode:%d cluster:%" PRId64, vgId,
22,461!
69
        raftId->addr, pInfo->nodeFqdn, pInfo->nodePort, ipbuf, ipv4, pInfo->nodeId, pInfo->clusterId);
70
  return true;
22,462✔
71
}
72

73
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
8,976,555✔
74
  if (pId1->addr == pId2->addr && pId1->vgId == pId2->vgId) {
8,976,555!
75
    return true;
5,431,346✔
76
  }
77

78
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
3,545,209!
79
    return true;
184✔
80
  }
81

82
  return false;
3,545,025✔
83
}
84

85
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
3,159!
86

87
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
397,524✔
88

89
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
397,524✔
90
  int32_t rdm = min + syncUtilRand(max - min);
397,524✔
91

92
  // sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm);
93
  return rdm;
397,525✔
94
}
95

96
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
14,507✔
97

98
void syncUtilMsgHtoN(void* msg) {
825,153✔
99
  SMsgHead* pHead = msg;
825,153✔
100
  pHead->contLen = htonl(pHead->contLen);
825,153✔
101
  pHead->vgId = htonl(pHead->vgId);
825,153✔
102
}
825,153✔
103

104
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf) {
14,228✔
105
  (void)memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
14,228✔
106
  int32_t randVal = taosSafeRand() % 1000;
14,228✔
107
  int64_t currentMs = taosGetTimestampMs();
14,228✔
108
  (void)snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, groupId, currentMs, randVal);
14,228✔
109
}
14,228✔
110

111
// for leader
112
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
226,007✔
113
  int32_t len = 0;
226,007✔
114
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
226,007✔
115
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
501,550✔
116
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
275,529✔
117
    len += tsnprintf(buf + len, bufLen - len, "%d:%" PRId64, i, tsMs);
275,530✔
118
    if (i < pSyncNode->replicaNum - 1) {
275,531✔
119
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
49,513✔
120
    }
121
  }
122
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
226,021✔
123
}
226,021✔
124

125
// for follower
126
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
226,014✔
127
  int32_t len = 0;
226,014✔
128
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
226,014✔
129
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
501,561✔
130
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
275,527✔
131
    len += tsnprintf(buf + len, bufLen - len, "%d:%" PRId64, i, tsMs);
275,535✔
132
    if (i < pSyncNode->replicaNum - 1) {
275,536✔
133
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
49,513✔
134
    }
135
  }
136
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
226,034✔
137
}
226,023✔
138

139
static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
226,008✔
140
  SSyncLogBuffer* pBuf = pSyncNode->pLogBuf;
226,008✔
141
  if (pBuf == NULL) {
226,008!
142
    return;
×
143
  }
144
  int32_t len = 0;
226,008✔
145
  len += tsnprintf(buf + len, bufLen - len, "[%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pBuf->startIndex,
226,008✔
146
                  pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
147
}
148

149
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
226,017✔
150
  int32_t len = 0;
226,017✔
151
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
226,017✔
152
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
501,524✔
153
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
275,531✔
154
    if (pMgr == NULL) break;
275,531✔
155
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "]", i, pMgr->restored,
275,504✔
156
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
157
    if (i + 1 < pSyncNode->replicaNum) {
275,500✔
158
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
49,507✔
159
    }
160
  }
161
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
226,020✔
162
}
226,023✔
163

164
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
18,902✔
165
  int32_t len = 0;
18,902✔
166
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
18,902✔
167
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
38,947✔
168
    SPeerState* pState = syncNodeGetPeerState(pSyncNode, &(pSyncNode->replicasId[i]));
20,047✔
169
    if (pState == NULL) break;
20,048!
170
    len += tsnprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 "%s", i, pState->lastSendIndex,
20,048✔
171
                    pState->lastSendTime, (i < pSyncNode->replicaNum - 1) ? ", " : "");
20,048✔
172
  }
173
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
18,900✔
174
}
18,901✔
175

176
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
226,020✔
177
  if (pNode == NULL || pNode->pLogStore == NULL) return;
226,020!
178
  int64_t currentTerm = raftStoreGetTerm(pNode);
226,023✔
179

180
  // save error code, otherwise it will be overwritten
181
  int32_t errCode = terrno;
226,024✔
182

183
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
226,025✔
184
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
226,025!
185
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
226,023✔
186
  }
187

188
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
226,026✔
189
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
226,026✔
190
  if (pNode->pLogStore != NULL) {
226,026✔
191
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
226,024✔
192
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
226,020✔
193
  }
194

195
  int32_t cacheHit = pNode->pLogStore->cacheHit;
226,021✔
196
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
226,021✔
197

198
  char cfgStr[1024] = "";
226,021✔
199
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
226,021✔
200

201
  char replMgrStatesStr[1024] = "";
226,021✔
202
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
226,021✔
203

204
  char bufferStatesStr[256] = "";
226,023✔
205
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
226,023✔
206

207
  char hbrTimeStr[256] = "";
226,020✔
208
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr));
226,020✔
209

210
  char hbTimeStr[256] = "";
226,020✔
211
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr));
226,020✔
212

213
  char    eventLog[512];  // {0};
214
  va_list argpointer;
215
  va_start(argpointer, format);
226,020✔
216
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
226,020✔
217
  va_end(argpointer);
226,020✔
218

219
  int32_t aqItems = 0;
226,020✔
220
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
226,020!
221
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);
226,020✔
222
  }
223

224
  // restore error code
225
  terrno = errCode;
226,021✔
226
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);
226,020✔
227

228
  if (pNode != NULL) {
226,022!
229
    taosPrintLog(
226,019✔
230
        flags, level, dflag,
231
        "vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64
232
        ", applied-index:%" PRId64 ", first-ver:%" PRId64 ", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
233
        ", snap-term:%" PRIu64
234
        ", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
235
        "aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
236
        ", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
237
        ", buffer:%s, repl-mgrs:%s, members:%s, hb:%s, hb-reply:%s, arb-token:%s",
238
        pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
239
        appliedIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
240
        snapshot.lastApplyTerm, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
241
        pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex,
242
        pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish,
226,019✔
243
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
244
        replMgrStatesStr, cfgStr, hbTimeStr, hbrTimeStr, pNode->arbToken);
226,022✔
245
  }
246
}
247

248
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
17,205✔
249
                                const char* format, ...) {
250
  SSyncNode* pNode = pSender->pSyncNode;
17,205✔
251
  if (pNode == NULL || pNode->pLogStore == NULL) return;
17,205!
252

253
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
17,205✔
254
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
17,205!
255
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
17,206✔
256
  }
257

258
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
17,206✔
259
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
17,206✔
260
  if (pNode->pLogStore != NULL) {
17,206!
261
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
17,207✔
262
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
17,207✔
263
  }
264

265
  char cfgStr[1024] = "";
17,205✔
266
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
17,205✔
267

268
  char peerStr[1024] = "";
17,207✔
269
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
17,207✔
270

271
  char    eventLog[512];  // {0};
272
  va_list argpointer;
273
  va_start(argpointer, format);
17,206✔
274
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
17,206✔
275
  va_end(argpointer);
17,206✔
276

277
  taosPrintLog(flags, level, dflag,
17,207✔
278
               "vgId:%d, %s, sync:%s, snap-sender:%p signature:(%" PRId64 ", %" PRId64 "), {start:%" PRId64
279
               " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRId64 " last-cfg:%" PRId64
280
               ", seq:%d, ack:%d, "
281
               " buf:[%" PRId64 " %" PRId64 ", %" PRId64
282
               "], finish:%d, as:%d, to-dnode:%d}"
283
               ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64
284
               ", min-match:%" PRId64 ", snap:{last-index:%" PRId64 ", term:%" PRIu64
285
               "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
286
               ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
287
               pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->term, pSender->startTime,
288
               pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
289
               pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
290
               pSender->pSndBuf->start, pSender->pSndBuf->cursor, pSender->pSndBuf->end, pSender->finish,
17,207✔
291
               pSender->replicaIndex, DID(&pNode->replicasId[pSender->replicaIndex]), raftStoreGetTerm(pNode),
17,207✔
292
               pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
293
               snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize, pNode->replicaNum,
17,206✔
294
               pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr, cfgStr);
17,206✔
295
}
296

297
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
1,695✔
298
                                  const char* format, ...) {
299
  SSyncNode* pNode = pReceiver->pSyncNode;
1,695✔
300
  if (pNode == NULL || pNode->pLogStore == NULL) return;
1,695!
301

302
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
1,695✔
303
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
1,695!
304
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
1,695✔
305
  }
306

307
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
1,695✔
308
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
1,695✔
309
  if (pNode->pLogStore != NULL) {
1,695!
310
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
1,695✔
311
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
1,695✔
312
  }
313

314
  char cfgStr[1024] = "";
1,695✔
315
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
1,695✔
316

317
  char peerStr[1024] = "";
1,695✔
318
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
1,695✔
319

320
  char    eventLog[512];  // {0};
321
  va_list argpointer;
322
  va_start(argpointer, format);
1,695✔
323
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
1,695✔
324
  va_end(argpointer);
1,695✔
325

326
  taosPrintLog(
1,695✔
327
      flags, level, dflag,
328
      "vgId:%d, %s, sync:%s,"
329
      " snap-receiver:%p signature:(%" PRId64 ", %" PRId64 "), {start:%d ack:%d buf:[%" PRId64 " %" PRId64 ", %" PRId64
330
      ")"
331
      " from-dnode:%d, start:%" PRId64 " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRIu64 " last-cfg:%" PRId64
332
      "}"
333
      ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64 ", min-match:%" PRId64
334
      ", snap:{last-index:%" PRId64 ", last-term:%" PRIu64 "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
335
      ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
336
      pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->term, pReceiver->startTime, pReceiver->start,
1,695✔
337
      pReceiver->ack, pReceiver->pRcvBuf->start, pReceiver->pRcvBuf->cursor, pReceiver->pRcvBuf->end,
1,695✔
338
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
1,695✔
339
      pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex,
340
      raftStoreGetTerm(pNode), pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex,
341
      snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize,
1,695✔
342
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
1,695✔
343
      cfgStr);
344
}
345

346
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
47,426✔
347
  if (!(sDebugFlag & DEBUG_TRACE)) return;
47,426✔
348

349
  int64_t tsNow = taosGetTimestampMs();
4,165✔
350
  int64_t timeDIff = tsNow - pMsg->timeStamp;
4,165✔
351
  sNTrace(
4,165!
352
      pSyncNode, "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, ts:%" PRId64 ", elapsed:%" PRId64 ", data:%p}, %s",
353
      syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->timeStamp, timeDIff, pMsg->data, s);
354
}
355

356
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
42,341✔
357
  sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
42,341!
358
          syncLocalCmdGetStr(pMsg->cmd), pMsg->currentTerm, pMsg->commitIndex, s);
359
}
42,341✔
360

361
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
×
362
  sNTrace(pSyncNode,
×
363
          "send sync-append-entries-reply to dnode:%d, {term:%" PRId64 ", pterm:%" PRId64
364
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
365
          DID(&pMsg->destId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
366
}
×
367

368
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
×
369
  sNTrace(pSyncNode,
×
370
          "recv sync-append-entries-reply from dnode:%d {term:%" PRId64 ", pterm:%" PRId64
371
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
372
          DID(&pMsg->srcId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s);
373
}
×
374

375
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
45,708✔
376
                          int64_t execTime) {
377
  if (printX) {
45,708✔
378
    sNTrace(pSyncNode,
2,099!
379
            "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
380
            ", ts:%" PRId64 "}, x",
381
            DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp);
382
  } else {
383
    sNTrace(pSyncNode,
43,609!
384
            "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
385
            ", ts:%" PRId64 "}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
386
            DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, timerElapsed,
387
            execTime);
388
  }
389
}
45,708✔
390

391
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t timeDiff, const char* s) {
42,429✔
392
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
42,429!
393
    pSyncNode->hbSlowNum++;
×
394

395
    sNTrace(pSyncNode,
×
396
            "recv sync-heartbeat from dnode:%d slow {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
397
            ", ts:%" PRId64 "}, QID:%s, net elapsed:%" PRId64,
398
            DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
399
  }
400

401
  sNTrace(pSyncNode,
42,429!
402
          "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
403
          ", ts:%" PRId64 "}, QID:%s, net elapsed:%" PRId64,
404
          DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->timeStamp, s, timeDiff);
405
}
42,429✔
406

407
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
×
408
  sNTrace(pSyncNode, "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s",
×
409
          DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s);
410
}
×
411

412
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t timeDiff, const char* s) {
42,263✔
413
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
42,263✔
414
    pSyncNode->hbrSlowNum++;
520✔
415

416
    sNTrace(pSyncNode,
520!
417
            "recv sync-heartbeat-reply from dnode:%d slow {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
418
            DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, s, timeDiff);
419
  }
420

421
  sNTrace(pSyncNode,
42,263!
422
          "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, net elapsed:%" PRId64,
423
          DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, s, timeDiff);
424
}
42,263✔
425

426
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
×
427
  sNDebug(pSyncNode,
×
428
          "send sync-snapshot-send to dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
429
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64,
430
          DID(&pMsg->destId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
431
          pMsg->startTime);
432
}
×
433

434
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
×
435
  sNDebug(pSyncNode,
×
436
          "recv sync-snapshot-send from dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
437
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", data-len:%u",
438
          DID(&pMsg->srcId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
439
          pMsg->startTime, pMsg->dataLen);
440
}
×
441

442
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
84✔
443
  sNDebug(pSyncNode,
84!
444
          "send sync-snapshot-rsp to dnode:%d, %s, acked:%d, term:%" PRId64 ", begin-index:%" PRId64
445
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64,
446
          DID(&pMsg->destId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
447
          pMsg->startTime);
448
}
84✔
449

450
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
×
451
  sNDebug(pSyncNode,
×
452
          "recv sync-snapshot-rsp from dnode:%d, %s, ack:%d, term:%" PRId64 ", begin-index:%" PRId64
453
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64,
454
          DID(&pMsg->srcId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
455
          pMsg->startTime);
456
}
×
457

458
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
1✔
459
  sNTrace(pSyncNode,
1!
460
          "recv sync-append-entries from dnode:%d {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
461
          "}, commit-index:%" PRId64 ", datalen:%d}, %s",
462
          DID(&pMsg->srcId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->dataLen, s);
463
}
1✔
464

465
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
×
466
  sNTrace(pSyncNode,
×
467
          "send sync-append-entries to dnode:%d, {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
468
          "}, index:%" PRId64 ", commit-index:%" PRId64 ", datalen:%d}, %s",
469
          DID(&pMsg->destId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1),
470
          pMsg->commitIndex, pMsg->dataLen, s);
471
}
×
472

473
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, int32_t voteGranted, const char* errmsg,
4,298✔
474
                            const char* opt) {
475
  char statusMsg[64];
476
  snprintf(statusMsg, sizeof(statusMsg), "granted:%d", voteGranted);
4,298✔
477
  sNInfo(pSyncNode,
4,298!
478
         "%s sync-request-vote from dnode:%d, {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64 "}, %s",
479
         opt, DID(&pMsg->srcId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm,
480
         (voteGranted != -1) ? statusMsg : errmsg);
481
}
4,298✔
482

483
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s) {
×
484
  sNInfo(pNode,
×
485
         "send sync-request-vote to dnode:%d {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64 "}, %s",
486
         DID(&pMsg->destId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
487
}
×
488

489
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
2,078✔
490
  sNInfo(pSyncNode, "recv sync-request-vote-reply from dnode:%d {term:%" PRId64 ", grant:%d}, %s", DID(&pMsg->srcId),
2,078!
491
         pMsg->term, pMsg->voteGranted, s);
492
}
2,078✔
493

494
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
2,148✔
495
  sNInfo(pSyncNode, "send sync-request-vote-reply to dnode:%d {term:%" PRId64 ", grant:%d}, %s", DID(&pMsg->destId),
2,148!
496
         pMsg->term, pMsg->voteGranted, s);
497
}
2,148✔
498

499
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) {
170✔
500
  void* data = taosMemoryRealloc(pSnap->data, size);
170✔
501
  if (data == NULL) {
170!
502
    return terrno;
×
503
  }
504
  pSnap->data = data;
170✔
505
  return 0;
170✔
506
}
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