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

taosdata / TDengine / #4872

04 Dec 2025 01:55AM UTC coverage: 64.678% (+0.02%) from 64.654%
#4872

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

880 of 2219 new or added lines in 36 files covered. (39.66%)

6146 existing lines in 122 files now uncovered.

159679 of 246882 relevant lines covered (64.68%)

110947965.82 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) {
27,517,385✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
27,517,385✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
89,506,301✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
61,989,360✔
33
    if (i < pCfg->replicaNum - 1) {
61,990,833✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
34,473,306✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
27,516,937✔
38
}
27,516,887✔
39

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

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

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

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

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

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
1,357,931,868✔
82
    return true;
58,524✔
83
  }
84

85
  return false;
1,357,892,171✔
86
}
87

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

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
95,944,866✔
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
95,945,584✔
93
  int32_t rdm = min + syncUtilRand(max - min);
95,945,584✔
94

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

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

101
void syncUtilMsgHtoN(void* msg) {
193,186,127✔
102
  SMsgHead* pHead = msg;
193,186,127✔
103
  pHead->contLen = htonl(pHead->contLen);
193,186,127✔
104
  pHead->vgId = htonl(pHead->vgId);
193,187,191✔
105
}
193,185,813✔
106

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

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
182,271,962✔
115
  if (formatTime) {
182,271,962✔
116
    char pBuf[TD_TIME_STR_LEN] = {0};
182,272,805✔
117
    if (tsMs > 0) {
182,273,464✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
127,231,978✔
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
182,279,339✔
123
  } else {
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
182,273,766✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
26,841,726✔
130
  int32_t len = 0;
26,841,726✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
26,842,513✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
87,601,465✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
60,758,335✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
60,758,951✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
60,756,553✔
136
    if (i < pSyncNode->replicaNum - 1) {
60,756,408✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
33,914,548✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
26,844,068✔
141
}
26,844,497✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
26,845,357✔
144
  int32_t len = 0;
26,845,357✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
26,845,357✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
87,604,650✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
60,759,673✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
60,759,216✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
60,759,314✔
150
    if (i < pSyncNode->replicaNum - 1) {
60,759,314✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
33,914,217✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
26,845,284✔
155
}
26,845,284✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
26,842,517✔
159
  int32_t len = 0;
26,842,517✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
26,843,783✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
87,604,504✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
60,758,281✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
60,759,289✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
60,758,909✔
165
    if (i < pSyncNode->replicaNum - 1) {
60,759,673✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
33,914,576✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
26,845,357✔
170
}
26,845,284✔
171

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

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
26,843,596✔
183
  int32_t len = 0;
26,843,596✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
26,843,596✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
87,600,261✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
60,758,356✔
187
    if (pMgr == NULL) break;
60,758,190✔
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
60,758,190✔
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
60,758,624✔
191
    if (i + 1 < pSyncNode->replicaNum) {
60,756,777✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
33,914,520✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
26,843,983✔
196
}
26,843,037✔
197

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

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

215
  // save error code, otherwise it will be overwritten
216
  int32_t errCode = terrno;
24,670,484✔
217

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

223
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
24,669,982✔
224
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
24,669,982✔
225
  if (pNode->pLogStore != NULL) {
24,669,982✔
226
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
24,670,986✔
227
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
24,670,484✔
228
  }
229

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
24,670,842✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
24,670,842✔
232

233
  char cfgStr[1024] = "";
24,670,312✔
234
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
24,670,986✔
235

236
  char replMgrStatesStr[1024] = "";
24,669,514✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
24,669,514✔
238

239
  char bufferStatesStr[256] = "";
24,668,666✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
24,669,168✔
241

242
  char hbrTimeStr[256] = "";
24,668,680✔
243
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
24,669,467✔
244

245
  char hbTimeStr[256] = "";
24,668,671✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
24,668,671✔
247

248
  char sentHbTimeStr[512] = "";
24,670,986✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
24,670,986✔
250

251
  char    eventLog[512];  // {0};
24,625,222✔
252
  va_list argpointer;
24,625,222✔
253
  va_start(argpointer, format);
24,670,913✔
254
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
24,670,913✔
255
  va_end(argpointer);
24,670,913✔
256

257
  int32_t aqItems = 0;
24,670,913✔
258
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
24,670,913✔
259
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);  // vnodeApplyQueueItems
24,670,986✔
260
  }
261

262
  // restore error code
263
  terrno = errCode;
24,670,986✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
24,670,222✔
265

266
  if (pNode != NULL) {
24,667,516✔
267
    taosPrintLog(
73,911,107✔
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,
24,666,569✔
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
24,668,200✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

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

293
  // save error code, otherwise it will be overwritten
294
  int32_t errCode = terrno;
2,174,371✔
295

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
2,174,371✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
2,174,371✔
298

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

302
  char replMgrStatesStr[1024] = "";
2,174,371✔
303
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
2,174,371✔
304

305
  char bufferStatesStr[256] = "";
2,174,371✔
306
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
2,174,371✔
307

308
  char hbrTimeStr[256] = "";
2,174,371✔
309
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
2,174,371✔
310

311
  char hbTimeStr[256] = "";
2,174,371✔
312
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
2,174,371✔
313

314
  char sentHbTimeStr[512] = "";
2,174,371✔
315
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
2,174,371✔
316

317
  char    eventLog[512];  // {0};
2,172,841✔
318
  va_list argpointer;
2,172,841✔
319
  va_start(argpointer, format);
2,174,371✔
320
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
2,174,371✔
321
  va_end(argpointer);
2,174,371✔
322

323
  terrno = errCode;
2,174,371✔
324

325
  if (pNode != NULL) {
2,174,371✔
326
    taosPrintLog(
6,520,053✔
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),
2,174,371✔
338
        pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr, replMgrStatesStr, cfgStr,
339
        sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount, pNode->recvCount, pNode->slowCount);
2,174,371✔
340
  }
341
}
342

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

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

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

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

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

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

372
  taosPrintLog(flags, level, dflag,
2,970,597✔
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,
1,273,113✔
386
               pSender->replicaIndex, DID(&pNode->replicasId[pSender->replicaIndex]), raftStoreGetTerm(pNode),
424,371✔
387
               pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
388
               snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize, pNode->replicaNum,
424,371✔
389
               pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr, cfgStr);
424,371✔
390
}
391

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

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

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

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

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

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

421
  taosPrintLog(
1,738,317✔
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,
993,324✔
433
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
248,331✔
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,
248,331✔
437
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
248,331✔
438
      cfgStr);
439
}
440

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

444
  int64_t tsNow = taosGetTimestampMs();
2,406✔
445
  int64_t timeDIff = tsNow - pMsg->timeStamp;
2,406✔
446
  sNTrace(pSyncNode,
2,406✔
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) {
33,954,937✔
454
  sNTrace(pSyncNode,
33,954,937✔
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
}
33,954,937✔
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,
37,551,259✔
480
                          int64_t execTime, const STraceId* trace) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
37,551,259✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
17,226✔
483
    if (pMsg->timeStamp > 0) {
17,226✔
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
17,226✔
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
17,226✔
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,
17,226✔
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) {
37,534,033✔
503
      char pBuf[TD_TIME_STR_LEN] = {0};
1,123,609✔
504
      if (pMsg->timeStamp > 0) {
1,123,609✔
505
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
1,123,609✔
506
          pBuf[0] = '\0';
×
507
        }
508
      }
509
      sHTrace(pSyncNode,
1,123,609✔
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) {
36,410,424✔
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) {
36,410,424✔
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
}
37,551,259✔
545

546
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
34,176,054✔
547
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
548
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
34,176,054✔
549
    pSyncNode->hbSlowNum++;
964,311✔
550

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

558
    sHWarn(pSyncNode,
964,311✔
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) {
33,211,743✔
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) {
33,211,743✔
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
}
34,176,054✔
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,
34,146,011✔
613
                               const STraceId* trace, int64_t timeDiff) {
614
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
34,146,011✔
615
    pSyncNode->hbrSlowNum++;
1,192,834✔
616

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

624
    sHWarn(pSyncNode,
1,192,834✔
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){
32,953,177✔
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) {
32,953,177✔
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
}
34,146,011✔
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,
33,309✔
681
                                const STraceId* trace) {
682
  sNDebug(pSyncNode,
33,309✔
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
}
33,309✔
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,
2,132,570✔
717
                            const char* opt, const STraceId* trace) {
718
  char statusMsg[64];
2,131,556✔
719
  snprintf(statusMsg, sizeof(statusMsg), "granted:%d", voteGranted);
2,132,570✔
720
  sNInfo(pSyncNode,
2,132,570✔
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
}
2,132,570✔
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,
1,022,596✔
736
                                 const STraceId* trace) {
737
  sNInfo(pSyncNode,
1,022,596✔
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
}
1,022,596✔
741

742
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
1,066,285✔
743
                                 const STraceId* trace) {
744
  sNInfo(pSyncNode,
1,066,285✔
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
}
1,066,285✔
748

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