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

taosdata / TDengine / #4914

06 Jan 2026 01:30AM UTC coverage: 64.876% (-0.008%) from 64.884%
#4914

push

travis-ci

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

180 of 319 new or added lines in 14 files covered. (56.43%)

3475 existing lines in 124 files now uncovered.

194993 of 300563 relevant lines covered (64.88%)

116239151.85 hits per line

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

80.27
/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) {
19,695,904✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
19,695,904✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
61,359,591✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
41,664,722✔
33
    if (i < pCfg->replicaNum - 1) {
41,665,219✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
21,969,256✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
19,695,978✔
38
}
19,695,977✔
39

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

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

51
  int32_t code = 0;
7,005,947✔
52
  for (int32_t i = 0; i < FQDNRETRYTIMES; i++) {
7,005,947✔
53
    code = taosGetIpFromFqdn(tsEnableIpv6, pInfo->nodeFqdn, &addr);
7,005,947✔
54
    if (code) {
7,005,947✔
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;
7,005,947✔
59
    }
60
  }
61

62
  if (code != 0) {
7,005,947✔
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);
7,005,947✔
69
  raftId->vgId = vgId;
7,005,947✔
70

71
  sInfo("vgId:%d, sync addr:0x%" PRIx64 " is resolved, ep:%s:%u ip:%s dnode:%d cluster:%" PRId64, vgId, raftId->addr,
7,005,947✔
72
        pInfo->nodeFqdn, pInfo->nodePort, IP_ADDR_STR(&addr), pInfo->nodeId, pInfo->clusterId);
73
  return true;
7,005,947✔
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;
1,931,211,739✔
79
  }
80

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
1,428,098,243✔
82
    return true;
24,828✔
83
  }
84

85
  return false;
1,428,097,838✔
86
}
87

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

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
115,796,896✔
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
115,796,896✔
93
  int32_t rdm = min + syncUtilRand(max - min);
115,796,896✔
94

95
  // sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm);
96
  return rdm;
115,796,896✔
97
}
98

99
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
4,080,996✔
100

101
void syncUtilMsgHtoN(void* msg) {
239,851,569✔
102
  SMsgHead* pHead = msg;
239,851,569✔
103
  pHead->contLen = htonl(pHead->contLen);
239,851,569✔
104
  pHead->vgId = htonl(pHead->vgId);
239,848,247✔
105
}
239,854,220✔
106

107
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf) {
4,043,017✔
108
  (void)memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
4,043,017✔
109
  int32_t randVal = taosSafeRand() % 1000;
4,043,017✔
110
  int64_t currentMs = taosGetTimestampMs();
4,042,630✔
111
  (void)snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, groupId, currentMs, randVal);
4,042,630✔
112
}
4,042,630✔
113

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
122,150,496✔
115
  if (formatTime) {
122,150,496✔
116
    char pBuf[TD_TIME_STR_LEN] = {0};
122,151,317✔
117
    if (tsMs > 0) {
122,153,255✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
86,199,881✔
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
122,156,933✔
123
  } else {
UNCOV
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
122,151,630✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
19,161,122✔
130
  int32_t len = 0;
19,161,122✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
19,160,905✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
59,876,432✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
40,718,584✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
40,716,024✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
40,715,451✔
136
    if (i < pSyncNode->replicaNum - 1) {
40,715,754✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
21,557,266✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
19,159,269✔
141
}
19,159,685✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
19,159,954✔
144
  int32_t len = 0;
19,159,954✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
19,159,954✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
59,878,305✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
40,718,586✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
40,717,203✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
40,716,835✔
150
    if (i < pSyncNode->replicaNum - 1) {
40,718,901✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
21,557,649✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
19,160,012✔
155
}
19,160,983✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
19,158,942✔
159
  int32_t len = 0;
19,158,942✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
19,158,942✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
59,878,244✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
40,717,947✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
40,715,773✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
40,715,957✔
165
    if (i < pSyncNode->replicaNum - 1) {
40,718,048✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
21,556,794✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
19,161,486✔
170
}
19,161,486✔
171

172
static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
19,160,449✔
173
  SSyncLogBuffer* pBuf = pSyncNode->pLogBuf;
19,160,449✔
174
  if (pBuf == NULL) {
19,161,188✔
175
    return;
×
176
  }
177
  int32_t len = 0;
19,161,188✔
178
  len += tsnprintf(buf + len, bufLen - len, "[%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pBuf->startIndex,
19,161,188✔
179
                   pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
180
}
181

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
19,160,707✔
183
  int32_t len = 0;
19,160,707✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
19,160,707✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
59,879,545✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
40,717,839✔
187
    if (pMgr == NULL) break;
40,718,132✔
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
40,718,132✔
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
40,717,700✔
191
    if (i + 1 < pSyncNode->replicaNum) {
40,717,893✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
21,557,290✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
19,161,274✔
196
}
19,161,307✔
197

198
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
534,573✔
199
  int32_t len = 0;
534,573✔
200
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
534,573✔
201
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
1,462,889✔
202
    SPeerState* pState = syncNodeGetPeerState(pSyncNode, &(pSyncNode->replicasId[i]));
928,316✔
203
    if (pState == NULL) break;
928,316✔
204
    len += tsnprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 "%s", i, pState->lastSendIndex,
928,316✔
205
                     pState->lastSendTime, (i < pSyncNode->replicaNum - 1) ? ", " : "");
928,316✔
206
  }
207
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
534,573✔
208
}
534,573✔
209

210
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, bool formatTime, SSyncNode* pNode,
17,464,552✔
211
                      const char* format, ...) {
212
  if (pNode == NULL || pNode->pLogStore == NULL) return;
17,464,552✔
213
  int64_t currentTerm = raftStoreGetTerm(pNode);
17,464,557✔
214

215
  // save error code, otherwise it will be overwritten
216
  int32_t errCode = terrno;
17,464,951✔
217

218
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
17,464,951✔
219
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
17,464,951✔
220
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);  // vnodeSyncGetSnapshotInfo
17,464,734✔
221
  }
222

223
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
17,465,150✔
224
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
17,465,150✔
225
  if (pNode->pLogStore != NULL) {
17,465,150✔
226
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
17,464,951✔
227
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
17,464,499✔
228
  }
229

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
17,464,572✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
17,464,346✔
232

233
  char cfgStr[1024] = "";
17,464,308✔
234
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
17,464,355✔
235

236
  char replMgrStatesStr[1024] = "";
17,464,951✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
17,464,951✔
238

239
  char bufferStatesStr[256] = "";
17,464,772✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
17,464,772✔
241

242
  char hbrTimeStr[256] = "";
17,464,716✔
243
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
17,464,716✔
244

245
  char hbTimeStr[256] = "";
17,463,732✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
17,464,096✔
247

248
  char sentHbTimeStr[512] = "";
17,464,050✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
17,464,050✔
250

251
  char    eventLog[512];  // {0};
17,461,447✔
252
  va_list argpointer;
17,462,522✔
253
  va_start(argpointer, format);
17,464,271✔
254
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
17,464,271✔
255
  va_end(argpointer);
17,464,271✔
256

257
  int32_t aqItems = 0;
17,464,271✔
258
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
17,464,271✔
259
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);  // vnodeApplyQueueItems
17,464,564✔
260
  }
261

262
  // restore error code
263
  terrno = errCode;
17,458,542✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
17,462,678✔
265

266
  if (pNode != NULL) {
17,461,901✔
267
    taosPrintLog(
52,375,817✔
268
        flags, level, dflag,
269
        "vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64
270
        ", applied-index:%" PRId64 ", first-ver:%" PRId64 ", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
271
        ", snap-term:%" PRIu64
272
        ", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
273
        "aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
274
        ", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
275
        ", buffer:%s, repl-mgrs:%s, members:%s, send hb:%s, recv hb:%s, recv hb-reply:%s, arb-token:%s, "
276
        "msg[sent:%" PRId64 ", recv:%" PRId64 ", slow-recv:%" PRId64 "]",
277
        pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
278
        appliedIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
279
        snapshot.lastApplyTerm, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
280
        pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex,
281
        pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish,
17,461,172✔
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
17,460,905✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

288
void syncPrintHbLog(const char* flags, ELogLevel level, int32_t dflag, bool formatTime, SSyncNode* pNode,
1,696,535✔
289
                    const char* format, ...) {
290
  if (pNode == NULL || pNode->pLogStore == NULL) return;
1,696,535✔
291
  int64_t currentTerm = raftStoreTryGetTerm(pNode);
1,696,535✔
292

293
  // save error code, otherwise it will be overwritten
294
  int32_t errCode = terrno;
1,696,535✔
295

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
1,696,535✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
1,696,535✔
298

299
  char cfgStr[1024] = "";
1,696,535✔
300
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
1,696,535✔
301

302
  char replMgrStatesStr[1024] = "";
1,696,453✔
303
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
1,696,453✔
304

305
  char bufferStatesStr[256] = "";
1,696,535✔
306
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
1,696,535✔
307

308
  char hbrTimeStr[256] = "";
1,696,535✔
309
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
1,696,535✔
310

311
  char hbTimeStr[256] = "";
1,696,535✔
312
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
1,696,535✔
313

314
  char sentHbTimeStr[512] = "";
1,696,535✔
315
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
1,696,535✔
316

317
  char    eventLog[512];  // {0};
1,696,407✔
318
  va_list argpointer;
1,696,407✔
319
  va_start(argpointer, format);
1,696,535✔
320
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
1,696,535✔
321
  va_end(argpointer);
1,696,535✔
322

323
  terrno = errCode;
1,696,535✔
324

325
  if (pNode != NULL) {
1,696,535✔
326
    taosPrintLog(
5,089,349✔
327
        flags, level, dflag,
328
        "vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64 ", min:%" PRId64
329
        ", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
330
        ", snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
331
        ", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
332
        ", buffer:%s, repl-mgrs:%s, members:%s, send hb:%s, recv hb:%s, recv hb-reply:%s, arb-token:%s, "
333
        "msg[sent:%" PRId64 ", recv:%" PRId64 ", slow-recv:%" PRId64 "]",
334
        pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
335
        pNode->minMatchIndex, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
336
        pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, pNode->snapshottingIndex, pNode->replicaNum,
337
        pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
1,696,535✔
338
        pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr, replMgrStatesStr, cfgStr,
339
        sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount, pNode->recvCount, pNode->slowCount);
1,696,535✔
340
  }
341
}
342

343
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
333,163✔
344
                                const char* format, ...) {
345
  SSyncNode* pNode = pSender->pSyncNode;
333,163✔
346
  if (pNode == NULL || pNode->pLogStore == NULL) return;
333,163✔
347

348
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
333,066✔
349
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
333,066✔
350
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
333,066✔
351
  }
352

353
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
333,066✔
354
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
333,066✔
355
  if (pNode->pLogStore != NULL) {
333,066✔
356
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
333,066✔
357
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
333,066✔
358
  }
359

360
  char cfgStr[1024] = "";
333,066✔
361
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
333,066✔
362

363
  char peerStr[1024] = "";
333,066✔
364
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
333,066✔
365

366
  char    eventLog[512];  // {0};
333,066✔
367
  va_list argpointer;
333,066✔
368
  va_start(argpointer, format);
333,066✔
369
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
333,066✔
370
  va_end(argpointer);
333,066✔
371

372
  taosPrintLog(flags, level, dflag,
2,331,462✔
373
               "vgId:%d, %s, sync:%s, snap-sender:%p signature:(%" PRId64 ", %" PRId64 "), {start:%" PRId64
374
               " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRId64 " last-cfg:%" PRId64
375
               ", seq:%d, ack:%d, "
376
               " buf:[%" PRId64 " %" PRId64 ", %" PRId64
377
               "], finish:%d, as:%d, to-dnode:%d}"
378
               ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64
379
               ", min-match:%" PRId64 ", snap:{last-index:%" PRId64 ", term:%" PRIu64
380
               "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
381
               ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
382
               pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->term, pSender->senderStartTime,
383
               pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
384
               pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
385
               pSender->pSndBuf->start, pSender->pSndBuf->cursor, pSender->pSndBuf->end, pSender->finish,
999,198✔
386
               pSender->replicaIndex, DID(&pNode->replicasId[pSender->replicaIndex]), raftStoreGetTerm(pNode),
333,066✔
387
               pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
388
               snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize, pNode->replicaNum,
333,066✔
389
               pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr, cfgStr);
333,066✔
390
}
391

392
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
201,507✔
393
                                  const char* format, ...) {
394
  SSyncNode* pNode = pReceiver->pSyncNode;
201,507✔
395
  if (pNode == NULL || pNode->pLogStore == NULL) return;
201,507✔
396

397
  SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
201,507✔
398
  if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
201,507✔
399
    (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
201,507✔
400
  }
401

402
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
201,507✔
403
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
201,507✔
404
  if (pNode->pLogStore != NULL) {
201,507✔
405
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
201,507✔
406
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
201,507✔
407
  }
408

409
  char cfgStr[1024] = "";
201,507✔
410
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
201,507✔
411

412
  char peerStr[1024] = "";
201,507✔
413
  syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
201,507✔
414

415
  char    eventLog[512];  // {0};
201,507✔
416
  va_list argpointer;
201,507✔
417
  va_start(argpointer, format);
201,507✔
418
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
201,507✔
419
  va_end(argpointer);
201,507✔
420

421
  taosPrintLog(
1,410,549✔
422
      flags, level, dflag,
423
      "vgId:%d, %s, sync:%s,"
424
      " snap-receiver:%p signature:(%" PRId64 ", %" PRId64 "), {start:%d ack:%d buf:[%" PRId64 " %" PRId64 ", %" PRId64
425
      ")"
426
      " from-dnode:%d, start:%" PRId64 " end:%" PRId64 " last-index:%" PRId64 " last-term:%" PRIu64 " last-cfg:%" PRId64
427
      "}"
428
      ", term:%" PRIu64 ", commit-index:%" PRId64 ", firstver:%" PRId64 ", lastver:%" PRId64 ", min-match:%" PRId64
429
      ", snap:{last-index:%" PRId64 ", last-term:%" PRIu64 "}, standby:%d, batch-sz:%d, replicas:%d, last-cfg:%" PRId64
430
      ", chging:%d, restore:%d, quorum:%d, peer:%s, cfg:%s",
431
      pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->term, pReceiver->receiverStartTime,
432
      pReceiver->start, pReceiver->ack, pReceiver->pRcvBuf->start, pReceiver->pRcvBuf->cursor, pReceiver->pRcvBuf->end,
806,028✔
433
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
201,507✔
434
      pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex,
435
      raftStoreGetTerm(pNode), pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex,
436
      snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize,
201,507✔
437
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
201,507✔
438
      cfgStr);
439
}
440

441
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const STraceId* trace) {
26,365,183✔
442
  if (!(sDebugFlag & DEBUG_TRACE)) return;
26,365,183✔
443

444
  int64_t tsNow = taosGetTimestampMs();
1,212✔
445
  int64_t timeDIff = tsNow - pMsg->timeStamp;
1,212✔
446
  sNTrace(pSyncNode,
1,212✔
447
          "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, ts:%" PRId64 ", elapsed:%" PRId64
448
          ", data:%p}, QID:0x%" PRIx64 ":0x%" PRIx64,
449
          syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->timeStamp, timeDIff, pMsg->data,
450
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
451
}
452

453
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const STraceId* trace) {
23,085,872✔
454
  sNTrace(pSyncNode,
23,085,872✔
455
          "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, QID:0x%" PRIx64
456
          ":0x%" PRIx64,
457
          pMsg->cmd, syncLocalCmdGetStr(pMsg->cmd), pMsg->currentTerm, pMsg->commitIndex, trace ? trace->rootId : 0,
458
          trace ? trace->msgId : 0);
459
}
23,085,872✔
460

461
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s,
×
462
                                   const STraceId* trace) {
463
  sNTrace(pSyncNode,
×
464
          "send sync-append-entries-reply to dnode:%d, {term:%" PRId64 ", pterm:%" PRId64
465
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
466
          DID(&pMsg->destId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s,
467
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
468
}
×
469

UNCOV
470
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s,
×
471
                                   const STraceId* trace) {
UNCOV
472
  sNTrace(pSyncNode,
×
473
          "recv sync-append-entries-reply from dnode:%d {term:%" PRId64 ", pterm:%" PRId64
474
          ", success:%d, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
475
          DID(&pMsg->srcId), pMsg->term, pMsg->lastMatchTerm, pMsg->success, pMsg->lastSendIndex, pMsg->matchIndex, s,
476
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
UNCOV
477
}
×
478

479
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
24,578,707✔
480
                          int64_t execTime, const STraceId* trace) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
24,578,707✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
9,142✔
483
    if (pMsg->timeStamp > 0) {
9,142✔
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
9,142✔
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
9,142✔
489
      sHError(pSyncNode,
×
490
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
491
              ", ts:%s}, x, QID:0x%" PRIx64 ":0x%" PRIx64,
492
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, trace ? trace->rootId : 0, 
493
              trace ? trace->msgId : 0);
494
    } else {
495
      sHError(pSyncNode,
9,142✔
496
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
497
              ", ts:%s}, slow timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
498
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
499
              trace ? trace->rootId : 0, trace ? trace->msgId : 0);
500
    }
501
  } else {
502
    if (printX) {
24,569,565✔
503
      char pBuf[TD_TIME_STR_LEN] = {0};
884,417✔
504
      if (pMsg->timeStamp > 0) {
884,417✔
505
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
884,417✔
506
          pBuf[0] = '\0';
×
507
        }
508
      }
509
      sHTrace(pSyncNode,
884,417✔
510
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
511
              ", ts:%s}, x, QID:0x%" PRIx64 ":0x%" PRIx64,
512
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, trace ? trace->rootId : 0, 
513
              trace ? trace->msgId : 0);
514
    } else {
515
      if (tsSyncLogHeartbeat) {
23,685,148✔
516
        char pBuf[TD_TIME_STR_LEN] = {0};
×
517
        if (pMsg->timeStamp > 0) {
×
518
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
519
            pBuf[0] = '\0';
×
520
          }
521
        }
522
        sHInfo(pSyncNode,
×
523
               "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
524
               ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
525
               DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
526
               trace ? trace->rootId : 0, trace ? trace->msgId : 0);
527
      } else {
528
        if (sDebugFlag & DEBUG_TRACE) {
23,685,148✔
529
          char pBuf[TD_TIME_STR_LEN] = {0};
×
530
          if (pMsg->timeStamp > 0) {
×
531
            if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
532
              pBuf[0] = '\0';
×
533
            }
534
          }
535
          sHTrace(pSyncNode,
×
536
                  "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
537
                  ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
538
                  DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
539
                  trace ? trace->rootId : 0, trace ? trace->msgId : 0);
540
        }
541
      }
542
    }
543
  }
544
}
24,578,707✔
545

546
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
23,164,737✔
547
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
548
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
23,164,737✔
549
    pSyncNode->hbSlowNum++;
794,441✔
550

551
    char pBuf[TD_TIME_STR_LEN] = {0};
794,441✔
552
    if (pMsg->timeStamp > 0) {
794,441✔
553
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
794,441✔
554
        pBuf[0] = '\0';
×
555
      }
556
    }
557

558
    sHWarn(pSyncNode,
794,441✔
559
           "recv sync-heartbeat from dnode:%d slow(%d ms) {term:%" PRId64 ", commit-index:%" PRId64
560
           ", min-match:%" PRId64 ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64
561
           ":0x%" PRIx64,
562
           DID(&pMsg->srcId), SYNC_HEARTBEAT_SLOW_MS, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf,
563
           netElapsed, timeDiff, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
564
  } else {
565
    if (tsSyncLogHeartbeat) {
22,370,296✔
566
      char pBuf[TD_TIME_STR_LEN] = {0};
×
567
      if (pMsg->timeStamp > 0) {
×
568
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
569
          pBuf[0] = '\0';
×
570
        }
571
      }
572
      sHInfo(pSyncNode,
×
573
             "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
574
             ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64 ":0x%" PRIx64 ", rpc msg:%p",
575
             DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
576
             trace->rootId, trace->msgId, pRpcMsg);
577
    } else {
578
      if (sDebugFlag & DEBUG_TRACE) {
22,370,296✔
579
        char pBuf[TD_TIME_STR_LEN] = {0};
×
580
        if (pMsg->timeStamp > 0) {
×
581
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
582
            pBuf[0] = '\0';
×
583
          }
584
        }
585

586
        sHTrace(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,
589
                DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
590
                trace->rootId, trace->msgId);
591
      }
592
    }
593
  }
594
}
23,164,737✔
595

596
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s,
×
597
                               const STraceId* trace) {
598
  if(tsSyncLogHeartbeat){
×
599
    sHInfo(pSyncNode,
×
600
          "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, QID:0x%" PRIx64
601
          ":0x%" PRIx64,
602
          DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
603
  }
604
  else{
605
    sHTrace(pSyncNode,
×
606
          "send sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, %s, QID:0x%" PRIx64
607
          ":0x%" PRIx64,
608
          DID(&pMsg->destId), pMsg->term, pMsg->timeStamp, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
609
  }
610
}
×
611

612
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t netElapse,
22,958,402✔
613
                               const STraceId* trace, int64_t timeDiff) {
614
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
22,958,402✔
615
    pSyncNode->hbrSlowNum++;
892,952✔
616

617
    char pBuf[TD_TIME_STR_LEN] = {0};
892,952✔
618
    if (pMsg->timeStamp > 0) {
892,952✔
619
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
892,952✔
620
        pBuf[0] = '\0';
×
621
      }
622
    }
623

624
    sHWarn(pSyncNode,
892,952✔
625
           "recv sync-heartbeat-reply from dnode:%d slow(%d ms) {term:%" PRId64 ", ts:%s}, net elapsed:%" PRId64
626
           ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
627
           DID(&pMsg->srcId), SYNC_HEARTBEAT_REPLY_SLOW_MS, pMsg->term, pBuf, netElapse, timeDiff, trace->rootId,
628
           trace->msgId);
629
  } else {
630
    if(tsSyncLogHeartbeat){
22,065,450✔
631
      char pBuf[TD_TIME_STR_LEN] = {0};
×
632
      if (pMsg->timeStamp > 0) {
×
633
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
634
          pBuf[0] = '\0';
×
635
        }
636
      }
637
      sHInfo(pSyncNode,
×
638
              "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
639
              ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
640
              DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
641
              trace ? trace->msgId : 0);
642
    }
643
    else{
644
      if (sDebugFlag & DEBUG_TRACE) {
22,065,450✔
645
        char pBuf[TD_TIME_STR_LEN] = {0};
×
646
        if (pMsg->timeStamp > 0) {
×
647
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
648
            pBuf[0] = '\0';
×
649
          }
650
        }
651
        sHTrace(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
    }   
658
  }
659
}
22,958,402✔
660

661
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s,
×
662
                                 const STraceId* trace) {
663
  sNDebug(pSyncNode,
×
664
          "send sync-snapshot-send to dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
665
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
666
          DID(&pMsg->destId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
667
          pMsg->snapStartTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
668
}
×
669

670
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s,
×
671
                                 const STraceId* trace) {
672
  sNDebug(pSyncNode,
×
673
          "recv sync-snapshot-send from dnode:%d, %s, seq:%d, term:%" PRId64 ", begin-index:%" PRId64
674
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", data-len:%u, QID:0x%" PRIx64
675
          ":0x%" PRIx64,
676
          DID(&pMsg->srcId), s, pMsg->seq, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm,
677
          pMsg->snapStartTime, pMsg->dataLen, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
678
}
×
679

680
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s,
27,661✔
681
                                const STraceId* trace) {
682
  sNDebug(pSyncNode,
27,661✔
683
          "send sync-snapshot-rsp to dnode:%d, %s, acked:%d, term:%" PRId64 ", begin-index:%" PRId64
684
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
685
          DID(&pMsg->destId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
686
          pMsg->startTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
687
}
27,661✔
688

689
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s,
×
690
                                const STraceId* trace) {
691
  sNDebug(pSyncNode,
×
692
          "recv sync-snapshot-rsp from dnode:%d, %s, ack:%d, term:%" PRId64 ", begin-index:%" PRId64
693
          ", last-index:%" PRId64 ", last-term:%" PRId64 ", start-time:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
694
          DID(&pMsg->srcId), s, pMsg->ack, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm,
695
          pMsg->startTime, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
696
}
×
697

698
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s,
×
699
                              const STraceId* trace) {
700
  sNTrace(pSyncNode,
×
701
          "recv sync-append-entries from dnode:%d {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
702
          "}, commit-index:%" PRId64 ", datalen:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
703
          DID(&pMsg->srcId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->dataLen, s,
704
          trace ? trace->rootId : 0, trace ? trace->msgId : 0);
705
}
×
706

707
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s,
×
708
                              const STraceId* trace) {
709
  sNTrace(pSyncNode,
×
710
          "send sync-append-entries to dnode:%d, {term:%" PRId64 ", prev-log:{index:%" PRId64 ", term:%" PRId64
711
          "}, index:%" PRId64 ", commit-index:%" PRId64 ", datalen:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
712
          DID(&pMsg->destId), pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1),
713
          pMsg->commitIndex, pMsg->dataLen, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
714
}
×
715

716
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, int32_t voteGranted, const char* errmsg,
1,658,942✔
717
                            const char* opt, const STraceId* trace) {
718
  char statusMsg[64];
1,658,878✔
719
  snprintf(statusMsg, sizeof(statusMsg), "granted:%d", voteGranted);
1,658,942✔
720
  sNInfo(pSyncNode,
1,658,942✔
721
         "%s sync-request-vote from dnode:%d, {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64
722
         "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
723
         opt, DID(&pMsg->srcId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm,
724
         (voteGranted != -1) ? statusMsg : errmsg, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
725
}
1,658,942✔
726

727
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s, const STraceId* trace) {
×
728
  sNInfo(pNode,
×
729
         "send sync-request-vote to dnode:%d {term:%" PRId64 ", last-index:%" PRId64 ", last-term:%" PRId64
730
         "}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
731
         DID(&pMsg->destId), pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s, trace ? trace->rootId : 0,
732
         trace ? trace->msgId : 0);
733
}
×
734

735
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
813,068✔
736
                                 const STraceId* trace) {
737
  sNInfo(pSyncNode,
813,068✔
738
         "recv sync-request-vote-reply from dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
739
         DID(&pMsg->srcId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
740
}
813,068✔
741

742
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
829,471✔
743
                                 const STraceId* trace) {
744
  sNInfo(pSyncNode,
829,471✔
745
         "send sync-request-vote-reply to dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
746
         DID(&pMsg->destId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
747
}
829,471✔
748

749
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) {
55,516✔
750
  void* data = taosMemoryRealloc(pSnap->data, size);
55,516✔
751
  if (data == NULL) {
55,516✔
752
    return terrno;
×
753
  }
754
  pSnap->data = data;
55,516✔
755
  return 0;
55,516✔
756
}
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