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

taosdata / TDengine / #5015

03 Apr 2026 03:59PM UTC coverage: 72.289% (+0.03%) from 72.256%
#5015

push

travis-ci

web-flow
merge: from main to 3.0 branch #35067

4055 of 5985 new or added lines in 68 files covered. (67.75%)

13044 existing lines in 149 files now uncovered.

257390 of 356056 relevant lines covered (72.29%)

130247228.09 hits per line

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

80.32
/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
#include "ttime.h"
26

27
#define FQDNRETRYTIMES 100
28

29
static void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
23,678,252✔
30
  int32_t len = snprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
23,678,252✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
72,244,105✔
32
    len += snprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
48,567,911✔
33
    if (i < pCfg->replicaNum - 1) {
48,566,809✔
34
      len += snprintf(buf + len, bufLen - len, "%s", ", ");
24,888,951✔
35
    }
36
  }
37
  len += snprintf(buf + len, bufLen - len, "%s", "]}");
23,677,656✔
38
}
23,677,533✔
39

40
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
3,194,939✔
41
  pEpSet->inUse = 0;
3,194,939✔
42
  pEpSet->numOfEps = 1;
3,194,939✔
43
  pEpSet->eps[0].port = pInfo->nodePort;
3,194,939✔
44
  tstrncpy(pEpSet->eps[0].fqdn, pInfo->nodeFqdn, TSDB_FQDN_LEN);
3,194,939✔
45
}
3,194,939✔
46

47
bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) {
8,258,511✔
48
  SIpAddr addr = {0};
8,258,511✔
49
  sDebug("vgId:%d, resolve sync addr from fqdn, ep:%s:%u", vgId, pInfo->nodeFqdn, pInfo->nodePort);
8,258,905✔
50

51
  int32_t code = 0;
8,258,718✔
52
  for (int32_t i = 0; i < FQDNRETRYTIMES; i++) {
8,258,718✔
53
    code = taosGetIpFromFqdn(tsEnableIpv6, pInfo->nodeFqdn, &addr);
8,258,905✔
54
    if (code) {
8,258,905✔
55
      sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s, retry", vgId, pInfo->nodeId, pInfo->nodeFqdn);
×
56
      taosSsleep(1);
×
57
    } else {
58
      break;
8,258,905✔
59
    }
60
  }
61

62
  if (code != 0) {
8,258,718✔
63
    sError("vgId:%d, failed to resolve sync addr, dnode:%d fqdn:%s", vgId, pInfo->nodeId, pInfo->nodeFqdn);
×
64
    terrno = TSDB_CODE_TSC_INVALID_FQDN;
×
65
    return false;
×
66
  }
67

68
  raftId->addr = SYNC_ADDR(pInfo);
8,258,718✔
69
  raftId->vgId = vgId;
8,258,905✔
70

71
  sInfo("vgId:%d, sync addr:0x%" PRIx64 " is resolved, ep:%s:%u ip:%s dnode:%d cluster:%" PRId64, vgId, raftId->addr,
8,258,905✔
72
        pInfo->nodeFqdn, pInfo->nodePort, IP_ADDR_STR(&addr), pInfo->nodeId, pInfo->clusterId);
73
  return true;
8,258,905✔
74
}
75

76
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
2,147,483,647✔
77
  if (pId1->addr == pId2->addr && pId1->vgId == pId2->vgId) {
2,147,483,647✔
78
    return true;
2,071,681,789✔
79
  }
80

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
1,576,136,074✔
82
    return true;
32,636✔
83
  }
84

85
  return false;
1,576,126,811✔
86
}
87

88
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
1,503,669✔
89

90
static inline int32_t syncUtilRand(int32_t max) {
123,639,079✔
91
#ifdef WINDOWS
92
  unsigned int number;
93
  uint32_t     err;
94

95
  err = taosRandR(&number);
96
  if (err != 0) {
97
    sError("failed to get random number, err:%u", err);
98
    return max / 2;
99
  }
100
  return number % max;
101
#else
102
  return taosRand() % max;
123,639,079✔
103
#endif
104
}
105

106
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
123,639,079✔
107
  int32_t rdm = min + syncUtilRand(max - min);
123,639,079✔
108

109
  // sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm);
110
  return rdm;
123,640,126✔
111
}
112

113
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
4,931,757✔
114

115
void syncUtilMsgHtoN(void* msg) {
259,726,781✔
116
  SMsgHead* pHead = msg;
259,726,781✔
117
  pHead->contLen = htonl(pHead->contLen);
259,726,781✔
118
  pHead->vgId = htonl(pHead->vgId);
259,727,260✔
119
}
259,729,826✔
120

121
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf) {
4,881,645✔
122
  (void)memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
4,881,645✔
123
  int32_t randVal = taosSafeRand() % 1000;
4,881,645✔
124
  int64_t currentMs = taosGetTimestampMs();
4,881,645✔
125
  (void)snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, groupId, currentMs, randVal);
4,881,645✔
126
}
4,881,645✔
127

128
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
141,820,622✔
129
  if (formatTime) {
141,820,622✔
130
    char pBuf[TD_TIME_STR_LEN] = {0};
141,821,729✔
131
    if (tsMs > 0) {
141,822,635✔
132
      if (formatTimestampLocal(pBuf, sizeof(pBuf), tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
99,904,314✔
133
        pBuf[0] = '\0';
×
134
      }
135
    }
136
    (*len) += snprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
141,824,962✔
137
  } else {
138
    (*len) += snprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
139
  }
140
}
141,823,133✔
141

142
// for leader
143
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
22,826,321✔
144
  int32_t len = 0;
22,826,321✔
145
  len += snprintf(buf + len, bufLen - len, "%s", "{");
22,828,087✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
70,103,532✔
147
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
47,273,787✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
47,273,464✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
47,270,567✔
150
    if (i < pSyncNode->replicaNum - 1) {
47,274,475✔
151
      len += snprintf(buf + len, bufLen - len, "%s", ",");
24,445,738✔
152
    }
153
  }
154
  len += snprintf(buf + len, bufLen - len, "%s", "}");
22,829,681✔
155
}
22,828,514✔
156

157
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
22,829,263✔
158
  int32_t len = 0;
22,829,263✔
159
  len += snprintf(buf + len, bufLen - len, "%s", "{");
22,829,748✔
160
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
70,100,959✔
161
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
47,274,910✔
162
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
47,271,377✔
163
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
47,274,700✔
164
    if (i < pSyncNode->replicaNum - 1) {
47,275,089✔
165
      len += snprintf(buf + len, bufLen - len, "%s", ",");
24,445,738✔
166
    }
167
  }
168
  len += snprintf(buf + len, bufLen - len, "%s", "}");
22,827,997✔
169
}
22,827,363✔
170

171
// for follower
172
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
22,828,514✔
173
  int32_t len = 0;
22,828,514✔
174
  len += snprintf(buf + len, bufLen - len, "%s", "{");
22,829,615✔
175
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
70,104,707✔
176
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
47,273,895✔
177
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
47,273,656✔
178
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
47,274,502✔
179
    if (i < pSyncNode->replicaNum - 1) {
47,275,662✔
180
      len += snprintf(buf + len, bufLen - len, "%s", ",");
24,445,392✔
181
    }
182
  }
183
  len += snprintf(buf + len, bufLen - len, "%s", "}");
22,830,287✔
184
}
22,828,830✔
185

186
static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
22,829,076✔
187
  SSyncLogBuffer* pBuf = pSyncNode->pLogBuf;
22,829,076✔
188
  if (pBuf == NULL) {
22,828,838✔
189
    return;
×
190
  }
191
  int32_t len = 0;
22,828,838✔
192
  len += snprintf(buf + len, bufLen - len, "[%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pBuf->startIndex,
22,828,838✔
193
                  pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
194
}
195

196
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
22,827,976✔
197
  int32_t len = 0;
22,827,976✔
198
  len += snprintf(buf + len, bufLen - len, "%s", "{");
22,827,976✔
199
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
70,104,302✔
200
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
47,274,056✔
201
    if (pMgr == NULL) break;
47,274,754✔
202
    len += snprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
47,274,754✔
203
                    pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
204
    len += snprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
47,273,755✔
205
    if (i + 1 < pSyncNode->replicaNum) {
47,273,036✔
206
      len += snprintf(buf + len, bufLen - len, "%s", ", ");
24,444,451✔
207
    }
208
  }
209
  len += snprintf(buf + len, bufLen - len, "%s", "}");
22,829,617✔
210
}
22,829,029✔
211

212
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
848,527✔
213
  int32_t len = 0;
848,527✔
214
  len += snprintf(buf + len, bufLen - len, "%s", "{");
848,527✔
215
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
2,117,992✔
216
    SPeerState* pState = syncNodeGetPeerState(pSyncNode, &(pSyncNode->replicasId[i]));
1,269,465✔
217
    if (pState == NULL) break;
1,269,465✔
218
    len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 "%s", i, pState->lastSendIndex,
1,269,465✔
219
                    pState->lastSendTime, (i < pSyncNode->replicaNum - 1) ? ", " : "");
1,269,465✔
220
  }
221
  len += snprintf(buf + len, bufLen - len, "%s", "}");
848,527✔
222
}
848,527✔
223

224
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, bool formatTime, SSyncNode* pNode,
20,879,356✔
225
                      const char* format, ...) {
226
  if (pNode == NULL || pNode->pLogStore == NULL) return;
20,879,356✔
227
  int64_t currentTerm = raftStoreGetTerm(pNode);
20,880,622✔
228

229
  // save error code, otherwise it will be overwritten
230
  int32_t errCode = terrno;
20,880,835✔
231

232
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
20,880,835✔
233
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
20,880,835✔
234
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);  // vnodeSyncGetSnapshotInfo
20,880,214✔
235
  }
236

237
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
20,881,311✔
238
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
20,881,311✔
239
  if (pNode->pLogStore != NULL) {
20,881,311✔
240
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
20,880,722✔
241
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
20,880,459✔
242
  }
243

244
  int32_t cacheHit = pNode->pLogStore->cacheHit;
20,880,835✔
245
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
20,880,835✔
246

247
  char cfgStr[1024] = "";
20,880,777✔
248
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
20,880,777✔
249

250
  char replMgrStatesStr[1024] = "";
20,879,811✔
251
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
20,880,296✔
252

253
  char bufferStatesStr[256] = "";
20,880,039✔
254
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
20,880,578✔
255

256
  char hbrTimeStr[256] = "";
20,879,624✔
257
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
20,879,811✔
258

259
  char hbTimeStr[256] = "";
20,879,500✔
260
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
20,879,710✔
261

262
  char sentHbTimeStr[512] = "";
20,879,378✔
263
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
20,880,402✔
264

265
  char    eventLog[512];  // {0};
20,875,564✔
266
  va_list argpointer;
20,875,564✔
267
  va_start(argpointer, format);
20,879,360✔
268
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
20,879,360✔
269
  va_end(argpointer);
20,879,360✔
270

271
  int32_t aqItems = 0;
20,879,360✔
272
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
20,879,360✔
273
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);  // vnodeApplyQueueItems
20,879,981✔
274
  }
275

276
  // restore error code
277
  terrno = errCode;
20,876,603✔
278
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
20,877,741✔
279

280
  if (pNode != NULL) {
20,877,978✔
281
    taosPrintLog(
62,624,715✔
282
        flags, level, dflag,
283
        "vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64
284
        ", applied-index:%" PRId64 ", first-ver:%" PRId64 ", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
285
        ", snap-term:%" PRIu64
286
        ", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
287
        "aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
288
        ", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
289
        ", buffer:%s, repl-mgrs:%s, members:%s, send hb:%s, recv hb:%s, recv hb-reply:%s, arb-token:%s, "
290
        "msg[sent:%" PRId64 ", recv:%" PRId64 ", slow-recv:%" PRId64 "]",
291
        pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
292
        appliedIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
293
        snapshot.lastApplyTerm, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
294
        pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex,
295
        pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish,
20,878,952✔
296
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
297
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
20,877,409✔
298
        pNode->recvCount, pNode->slowCount);
299
  }
300
}
301

302
void syncPrintHbLog(const char* flags, ELogLevel level, int32_t dflag, bool formatTime, SSyncNode* pNode,
1,949,452✔
303
                    const char* format, ...) {
304
  if (pNode == NULL || pNode->pLogStore == NULL) return;
1,949,452✔
305
  int64_t currentTerm = raftStoreTryGetTerm(pNode);
1,949,452✔
306

307
  // save error code, otherwise it will be overwritten
308
  int32_t errCode = terrno;
1,949,452✔
309

310
  int32_t cacheHit = pNode->pLogStore->cacheHit;
1,949,452✔
311
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
1,949,452✔
312

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

316
  char replMgrStatesStr[1024] = "";
1,949,452✔
317
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
1,949,452✔
318

319
  char bufferStatesStr[256] = "";
1,949,452✔
320
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
1,949,452✔
321

322
  char hbrTimeStr[256] = "";
1,949,452✔
323
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
1,949,452✔
324

325
  char hbTimeStr[256] = "";
1,949,452✔
326
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
1,949,452✔
327

328
  char sentHbTimeStr[512] = "";
1,949,452✔
329
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
1,949,452✔
330

331
  char    eventLog[512];  // {0};
1,949,357✔
332
  va_list argpointer;
1,949,357✔
333
  va_start(argpointer, format);
1,949,452✔
334
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
1,949,452✔
335
  va_end(argpointer);
1,949,452✔
336

337
  terrno = errCode;
1,949,452✔
338

339
  if (pNode != NULL) {
1,949,452✔
340
    taosPrintLog(
5,848,166✔
341
        flags, level, dflag,
342
        "vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64 ", min:%" PRId64
343
        ", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
344
        ", snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
345
        ", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
346
        ", buffer:%s, repl-mgrs:%s, members:%s, send hb:%s, recv hb:%s, recv hb-reply:%s, arb-token:%s, "
347
        "msg[sent:%" PRId64 ", recv:%" PRId64 ", slow-recv:%" PRId64 "]",
348
        pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
349
        pNode->minMatchIndex, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
350
        pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, pNode->snapshottingIndex, pNode->replicaNum,
351
        pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
1,949,452✔
352
        pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr, replMgrStatesStr, cfgStr,
353
        sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount, pNode->recvCount, pNode->slowCount);
1,949,452✔
354
  }
355
}
356

357
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
613,008✔
358
                                const char* format, ...) {
359
  SSyncNode* pNode = pSender->pSyncNode;
613,008✔
360
  if (pNode == NULL || pNode->pLogStore == NULL) return;
613,008✔
361

362
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
612,899✔
363
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
612,899✔
364
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
612,899✔
365
  }
366

367
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
612,899✔
368
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
612,899✔
369
  if (pNode->pLogStore != NULL) {
612,899✔
370
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
612,899✔
371
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
612,899✔
372
  }
373

374
  char cfgStr[1024] = "";
612,899✔
375
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
612,899✔
376

377
  char peerStr[1024] = "";
612,899✔
378
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
612,899✔
379

380
  char    eventLog[512];  // {0};
612,899✔
381
  va_list argpointer;
612,899✔
382
  va_start(argpointer, format);
612,899✔
383
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
612,899✔
384
  va_end(argpointer);
612,899✔
385

386
  taosPrintLog(flags, level, dflag,
4,290,293✔
387
               "vgId:%d, %s, sync:%s, snap-sender:%p signature:(%" PRId64 ", %" PRId64 "), {start:%" PRId64
388
               " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRId64 " last-cfg:%" PRId64
389
               ", seq:%d, ack:%d, "
390
               " buf:[%" PRId64 " %" PRId64 ", %" PRId64
391
               "], finish:%d, as:%d, to-dnode:%d}"
392
               ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64
393
               ", min-match:%" PRId64 ", snap:{last-index:%" PRId64 ", term:%" PRIu64
394
               "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
395
               ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
396
               pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->term, pSender->senderStartTime,
397
               pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
398
               pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
399
               pSender->pSndBuf->start, pSender->pSndBuf->cursor, pSender->pSndBuf->end, pSender->finish,
1,838,697✔
400
               pSender->replicaIndex, DID(&pNode->replicasId[pSender->replicaIndex]), raftStoreGetTerm(pNode),
612,899✔
401
               pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
402
               snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize, pNode->replicaNum,
612,899✔
403
               pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr, cfgStr);
612,899✔
404
}
405

406
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
235,628✔
407
                                  const char* format, ...) {
408
  SSyncNode* pNode = pReceiver->pSyncNode;
235,628✔
409
  if (pNode == NULL || pNode->pLogStore == NULL) return;
235,628✔
410

411
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
235,628✔
412
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
235,628✔
413
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
235,628✔
414
  }
415

416
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
235,628✔
417
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
235,628✔
418
  if (pNode->pLogStore != NULL) {
235,628✔
419
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
235,628✔
420
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
235,628✔
421
  }
422

423
  char cfgStr[1024] = "";
235,628✔
424
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
235,628✔
425

426
  char peerStr[1024] = "";
235,628✔
427
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
235,628✔
428

429
  char    eventLog[512];  // {0};
235,628✔
430
  va_list argpointer;
235,628✔
431
  va_start(argpointer, format);
235,628✔
432
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
235,628✔
433
  va_end(argpointer);
235,628✔
434

435
  taosPrintLog(
1,649,396✔
436
      flags, level, dflag,
437
      "vgId:%d, %s, sync:%s,"
438
      " snap-receiver:%p signature:(%" PRId64 ", %" PRId64 "), {start:%d ack:%d buf:[%" PRId64 " %" PRId64 ", %" PRId64
439
      ")"
440
      " from-dnode:%d, start:%" PRId64 " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRIu64 " last-cfg:%" PRId64
441
      "}"
442
      ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64 ", min-match:%" PRId64
443
      ", snap:{last-index:%" PRId64 ", last-term:%" PRIu64 "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
444
      ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
445
      pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->term, pReceiver->receiverStartTime,
446
      pReceiver->start, pReceiver->ack, pReceiver->pRcvBuf->start, pReceiver->pRcvBuf->cursor, pReceiver->pRcvBuf->end,
942,512✔
447
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
235,628✔
448
      pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex,
449
      raftStoreGetTerm(pNode), pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex,
450
      snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize,
235,628✔
451
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
235,628✔
452
      cfgStr);
453
}
454

455
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const STraceId* trace) {
35,277,220✔
456
  if (!(sDebugFlag & DEBUG_TRACE)) return;
35,277,220✔
457

458
  int64_t tsNow = taosGetTimestampMs();
21,867✔
459
  int64_t timeDIff = tsNow - pMsg->timeStamp;
21,867✔
460
  sNTrace(pSyncNode,
21,867✔
461
          "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, ts:%" PRId64 ", elapsed:%" PRId64
462
          ", data:%p}, QID:0x%" PRIx64 ":0x%" PRIx64,
463
          syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->timeStamp, timeDIff, pMsg->data,
464
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
465
}
466

467
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const STraceId* trace) {
25,045,546✔
468
  sNTrace(pSyncNode,
25,045,546✔
469
          "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, QID:0x%" PRIx64
470
          ":0x%" PRIx64,
471
          pMsg->cmd, syncLocalCmdGetStr(pMsg->cmd), pMsg->currentTerm, pMsg->commitIndex, trace ? trace->rootId : 0,
472
          trace ? trace->msgId : 0);
473
}
25,045,546✔
474

475
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s,
×
476
                                   const STraceId* trace) {
477
  sNTrace(pSyncNode,
×
478
          "send sync-append-entries-reply to dnode:%d, {term:%" PRId64 ", pterm:%" PRId64
479
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
480
          DID(&pMsg->destId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s,
481
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
482
}
×
483

UNCOV
484
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s,
×
485
                                   const STraceId* trace) {
UNCOV
486
  sNTrace(pSyncNode,
×
487
          "recv sync-append-entries-reply from dnode:%d {term:%" PRId64 ", pterm:%" PRId64
488
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
489
          DID(&pMsg->srcId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s,
490
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
UNCOV
491
}
×
492

493
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
26,854,432✔
494
                          int64_t execTime, const STraceId* trace) {
495
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
26,854,432✔
496
    char pBuf[TD_TIME_STR_LEN] = {0};
16,668✔
497
    if (pMsg->timeStamp > 0) {
16,668✔
498
      if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
16,668✔
499
        pBuf[0] = '\0';
×
500
      }
501
    }
502
    if (printX) {
16,668✔
503
      sHError(pSyncNode,
×
504
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
505
              ", ts:%s}, x, QID:0x%" PRIx64 ":0x%" PRIx64,
506
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, trace ? trace->rootId : 0, 
507
              trace ? trace->msgId : 0);
508
    } else {
509
      sHError(pSyncNode,
16,668✔
510
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
511
              ", ts:%s}, slow timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
512
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
513
              trace ? trace->rootId : 0, trace ? trace->msgId : 0);
514
    }
515
  } else {
516
    if (printX) {
26,837,764✔
517
      char pBuf[TD_TIME_STR_LEN] = {0};
1,011,840✔
518
      if (pMsg->timeStamp > 0) {
1,011,840✔
519
        if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
1,011,840✔
520
          pBuf[0] = '\0';
×
521
        }
522
      }
523
      sHTrace(pSyncNode,
1,011,840✔
524
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
525
              ", ts:%s}, x, QID:0x%" PRIx64 ":0x%" PRIx64,
526
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, trace ? trace->rootId : 0, 
527
              trace ? trace->msgId : 0);
528
    } else {
529
      if (tsSyncLogHeartbeat) {
25,825,924✔
530
        char pBuf[TD_TIME_STR_LEN] = {0};
×
531
        if (pMsg->timeStamp > 0) {
×
532
          if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
533
            pBuf[0] = '\0';
×
534
          }
535
        }
536
        sHInfo(pSyncNode,
×
537
               "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
538
               ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
539
               DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
540
               trace ? trace->rootId : 0, trace ? trace->msgId : 0);
541
      } else {
542
        if (sDebugFlag & DEBUG_TRACE) {
25,825,924✔
543
          char pBuf[TD_TIME_STR_LEN] = {0};
×
544
          if (pMsg->timeStamp > 0) {
×
545
            if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
546
              pBuf[0] = '\0';
×
547
            }
548
          }
549
          sHTrace(pSyncNode,
×
550
                  "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
551
                  ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
552
                  DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
553
                  trace ? trace->rootId : 0, trace ? trace->msgId : 0);
554
        }
555
      }
556
    }
557
  }
558
}
26,854,432✔
559

560
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
25,142,539✔
561
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
562
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
25,142,539✔
563
    pSyncNode->hbSlowNum++;
903,020✔
564

565
    char pBuf[TD_TIME_STR_LEN] = {0};
903,020✔
566
    if (pMsg->timeStamp > 0) {
903,020✔
567
      if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
903,020✔
568
        pBuf[0] = '\0';
×
569
      }
570
    }
571

572
    sHWarn(pSyncNode,
903,020✔
573
           "recv sync-heartbeat from dnode:%d slow(%d ms) {term:%" PRId64 ", commit-index:%" PRId64
574
           ", min-match:%" PRId64 ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64
575
           ":0x%" PRIx64,
576
           DID(&pMsg->srcId), SYNC_HEARTBEAT_SLOW_MS, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf,
577
           netElapsed, timeDiff, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
578
  } else {
579
    if (tsSyncLogHeartbeat) {
24,239,519✔
580
      char pBuf[TD_TIME_STR_LEN] = {0};
×
581
      if (pMsg->timeStamp > 0) {
×
582
        if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
583
          pBuf[0] = '\0';
×
584
        }
585
      }
586
      sHInfo(pSyncNode,
×
587
             "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
588
             ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64 ":0x%" PRIx64 ", rpc msg:%p",
589
             DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
590
             trace->rootId, trace->msgId, pRpcMsg);
591
    } else {
592
      if (sDebugFlag & DEBUG_TRACE) {
24,239,519✔
593
        char pBuf[TD_TIME_STR_LEN] = {0};
×
594
        if (pMsg->timeStamp > 0) {
×
595
          if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
596
            pBuf[0] = '\0';
×
597
          }
598
        }
599

600
        sHTrace(pSyncNode,
×
601
                "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
602
                ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64 ":0x%" PRIx64,
603
                DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
604
                trace->rootId, trace->msgId);
605
      }
606
    }
607
  }
608
}
25,142,539✔
609

610
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s,
×
611
                               const STraceId* trace) {
612
  if(tsSyncLogHeartbeat){
×
613
    sHInfo(pSyncNode,
×
614
          "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, QID:0x%" PRIx64
615
          ":0x%" PRIx64,
616
          DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
617
  }
618
  else{
619
    sHTrace(pSyncNode,
×
620
          "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, QID:0x%" PRIx64
621
          ":0x%" PRIx64,
622
          DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
623
  }
624
}
×
625

626
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t netElapse,
25,131,768✔
627
                               const STraceId* trace, int64_t timeDiff) {
628
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
25,131,768✔
629
    pSyncNode->hbrSlowNum++;
1,029,764✔
630

631
    char pBuf[TD_TIME_STR_LEN] = {0};
1,029,764✔
632
    if (pMsg->timeStamp > 0) {
1,029,764✔
633
      if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
1,029,764✔
634
        pBuf[0] = '\0';
×
635
      }
636
    }
637

638
    sHWarn(pSyncNode,
1,029,764✔
639
           "recv sync-heartbeat-reply from dnode:%d slow(%d ms) {term:%" PRId64 ", ts:%s}, net elapsed:%" PRId64
640
           ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
641
           DID(&pMsg->srcId), SYNC_HEARTBEAT_REPLY_SLOW_MS, pMsg->term, pBuf, netElapse, timeDiff, trace->rootId,
642
           trace->msgId);
643
  } else {
644
    if(tsSyncLogHeartbeat){
24,102,004✔
645
      char pBuf[TD_TIME_STR_LEN] = {0};
×
646
      if (pMsg->timeStamp > 0) {
×
647
        if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
648
          pBuf[0] = '\0';
×
649
        }
650
      }
651
      sHInfo(pSyncNode,
×
652
              "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
653
              ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
654
              DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
655
              trace ? trace->msgId : 0);
656
    }
657
    else{
658
      if (sDebugFlag & DEBUG_TRACE) {
24,102,004✔
659
        char pBuf[TD_TIME_STR_LEN] = {0};
×
660
        if (pMsg->timeStamp > 0) {
×
661
          if (formatTimestampLocal(pBuf, sizeof(pBuf), pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
662
            pBuf[0] = '\0';
×
663
          }
664
        }
665
        sHTrace(pSyncNode,
×
666
                "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
667
                ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
668
                DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
669
                trace ? trace->msgId : 0);
670
      }
671
    }   
672
  }
673
}
25,131,768✔
674

675
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s,
×
676
                                 const STraceId* trace) {
677
  sNDebug(pSyncNode,
×
678
          "send sync-snapshot-send to dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
679
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
680
          DID(&pMsg->destId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
681
          pMsg->snapStartTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
682
}
×
683

684
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s,
×
685
                                 const STraceId* trace) {
686
  sNDebug(pSyncNode,
×
687
          "recv sync-snapshot-send from dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
688
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", data-len:%u, QID:0x%" PRIx64
689
          ":0x%" PRIx64,
690
          DID(&pMsg->srcId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
691
          pMsg->snapStartTime, pMsg->dataLen, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
692
}
×
693

694
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s,
30,059✔
695
                                const STraceId* trace) {
696
  sNDebug(pSyncNode,
30,059✔
697
          "send sync-snapshot-rsp to dnode:%d, %s, acked:%d, term:%" PRId64 ", begin-index:%" PRId64
698
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
699
          DID(&pMsg->destId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
700
          pMsg->startTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
701
}
30,059✔
702

703
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s,
×
704
                                const STraceId* trace) {
705
  sNDebug(pSyncNode,
×
706
          "recv sync-snapshot-rsp from dnode:%d, %s, ack:%d, term:%" PRId64 ", begin-index:%" PRId64
707
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
708
          DID(&pMsg->srcId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
709
          pMsg->startTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
710
}
×
711

712
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s,
×
713
                              const STraceId* trace) {
714
  sNTrace(pSyncNode,
×
715
          "recv sync-append-entries from dnode:%d {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
716
          "}, commit-index:%" PRId64 ", datalen:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
717
          DID(&pMsg->srcId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->dataLen, s,
718
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
719
}
×
720

721
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s,
×
722
                              const STraceId* trace) {
723
  sNTrace(pSyncNode,
×
724
          "send sync-append-entries to dnode:%d, {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
725
          "}, index:%" PRId64 ", commit-index:%" PRId64 ", datalen:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
726
          DID(&pMsg->destId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1),
727
          pMsg->commitIndex, pMsg->dataLen, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
728
}
×
729

730
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, int32_t voteGranted, const char* errmsg,
1,897,426✔
731
                            const char* opt, const STraceId* trace) {
732
  char statusMsg[64];
1,897,350✔
733
  snprintf(statusMsg, sizeof(statusMsg), "granted:%d", voteGranted);
1,897,426✔
734
  sNInfo(pSyncNode,
1,897,426✔
735
         "%s sync-request-vote from dnode:%d, {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64
736
         "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
737
         opt, DID(&pMsg->srcId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm,
738
         (voteGranted != -1) ? statusMsg : errmsg, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
739
}
1,897,426✔
740

741
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s, const STraceId* trace) {
×
742
  sNInfo(pNode,
×
743
         "send sync-request-vote to dnode:%d {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64
744
         "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
745
         DID(&pMsg->destId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s, trace ? trace->rootId : 0,
746
         trace ? trace->msgId : 0);
747
}
×
748

749
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
930,275✔
750
                                 const STraceId* trace) {
751
  sNInfo(pSyncNode,
930,275✔
752
         "recv sync-request-vote-reply from dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
753
         DID(&pMsg->srcId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
754
}
930,275✔
755

756
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
948,713✔
757
                                 const STraceId* trace) {
758
  sNInfo(pSyncNode,
948,713✔
759
         "send sync-request-vote-reply to dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
760
         DID(&pMsg->destId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
761
}
948,713✔
762

763
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) {
60,357✔
764
  void* data = taosMemoryRealloc(pSnap->data, size);
60,357✔
765
  if (data == NULL) {
60,357✔
766
    return terrno;
×
767
  }
768
  pSnap->data = data;
60,357✔
769
  return 0;
60,357✔
770
}
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