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

taosdata / TDengine / #4800

16 Oct 2025 09:19AM UTC coverage: 53.935% (-7.1%) from 61.083%
#4800

push

travis-ci

web-flow
Merge b32e3a393 into a190048d5

134724 of 323629 branches covered (41.63%)

Branch coverage included in aggregate %.

184803 of 268802 relevant lines covered (68.75%)

69058627.2 hits per line

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

57.95
/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) {
7,298,622✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
7,298,622✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
22,729,336✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
15,430,998✔
33
    if (i < pCfg->replicaNum - 1) {
15,431,546✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
8,132,784✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
7,298,198✔
38
}
7,298,762✔
39

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

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

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

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

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

76
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
640,962,944✔
77
  if (pId1->addr == pId2->addr && pId1->vgId == pId2->vgId) {
640,962,944✔
78
    return true;
429,008,404✔
79
  }
80

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
211,980,669!
82
    return true;
5,280✔
83
  }
84

85
  return false;
211,966,915✔
86
}
87

88
bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); }
512,043!
89

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
11,695,688!
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
11,695,688✔
93
  int32_t rdm = min + syncUtilRand(max - min);
11,695,688✔
94

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

99
int32_t syncUtilQuorum(int32_t replicaNum) { return replicaNum / 2 + 1; }
1,667,317✔
100

101
void syncUtilMsgHtoN(void* msg) {
21,291,352✔
102
  SMsgHead* pHead = msg;
21,291,352✔
103
  pHead->contLen = htonl(pHead->contLen);
21,291,352✔
104
  pHead->vgId = htonl(pHead->vgId);
21,291,698✔
105
}
21,291,990✔
106

107
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf) {
1,658,847✔
108
  (void)memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
1,658,847!
109
  int32_t randVal = taosSafeRand() % 1000;
1,658,847✔
110
  int64_t currentMs = taosGetTimestampMs();
1,658,390✔
111
  (void)snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, groupId, currentMs, randVal);
1,658,390✔
112
}
1,658,390✔
113

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
46,068,928✔
115
  if (formatTime) {
46,068,928!
116
    char pBuf[TD_TIME_STR_LEN] = {0};
46,069,900✔
117
    if (tsMs > 0) {
46,070,895✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
32,531,035!
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
46,074,117✔
123
  } else {
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
46,070,292✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
7,244,999✔
130
  int32_t len = 0;
7,244,999✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
7,245,407✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
22,602,193✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
15,356,949✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
15,357,089✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
15,354,872✔
136
    if (i < pSyncNode->replicaNum - 1) {
15,356,665✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
8,111,118✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
7,245,090✔
141
}
7,245,971✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
7,245,971✔
144
  int32_t len = 0;
7,245,971✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
7,245,971✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
22,603,060✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
15,357,089✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
15,357,042✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
15,356,163✔
150
    if (i < pSyncNode->replicaNum - 1) {
15,357,089✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
8,111,118✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
7,245,971✔
155
}
7,245,971✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
7,245,547✔
159
  int32_t len = 0;
7,245,547✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
7,245,514✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
22,603,013✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
15,357,089✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
15,356,596✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
15,356,658✔
165
    if (i < pSyncNode->replicaNum - 1) {
15,357,089✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
8,111,118✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
7,245,924✔
170
}
7,245,971✔
171

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

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
7,244,969✔
183
  int32_t len = 0;
7,244,969✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
7,244,969✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
22,601,202✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
15,355,829✔
187
    if (pMgr == NULL) break;
15,355,386!
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
15,355,386!
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
15,356,661✔
191
    if (i + 1 < pSyncNode->replicaNum) {
15,355,729✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
8,110,690✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
7,245,233✔
196
}
7,245,493✔
197

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

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

215
  // save error code, otherwise it will be overwritten
216
  int32_t errCode = terrno;
6,523,618✔
217

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

223
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
6,523,618✔
224
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
6,523,618✔
225
  if (pNode->pLogStore != NULL) {
6,523,618!
226
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
6,523,618✔
227
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
6,523,618✔
228
  }
229

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
6,523,618✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
6,523,618✔
232

233
  char cfgStr[1024] = "";
6,523,477✔
234
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
6,523,478✔
235

236
  char replMgrStatesStr[1024] = "";
6,523,054✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
6,523,194✔
238

239
  char bufferStatesStr[256] = "";
6,523,140✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
6,523,140✔
241

242
  char hbrTimeStr[256] = "";
6,523,194✔
243
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
6,523,194✔
244

245
  char hbTimeStr[256] = "";
6,523,161✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
6,523,161✔
247

248
  char sentHbTimeStr[512] = "";
6,523,618✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
6,523,618✔
250

251
  char    eventLog[512];  // {0};
6,522,603✔
252
  va_list argpointer;
6,522,603✔
253
  va_start(argpointer, format);
6,523,618✔
254
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
6,523,618!
255
  va_end(argpointer);
6,523,618✔
256

257
  int32_t aqItems = 0;
6,523,618✔
258
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
6,523,618!
259
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);  // vnodeApplyQueueItems
6,523,618✔
260
  }
261

262
  // restore error code
263
  terrno = errCode;
6,522,770✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
6,523,157✔
265

266
  if (pNode != NULL) {
6,522,761!
267
    taosPrintLog(
19,564,953✔
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,
6,523,141!
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
6,522,592✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

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

293
  // save error code, otherwise it will be overwritten
294
  int32_t errCode = terrno;
722,353✔
295

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
722,353✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
722,353✔
298

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

302
  char replMgrStatesStr[1024] = "";
722,353✔
303
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
722,353✔
304

305
  char bufferStatesStr[256] = "";
722,353✔
306
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
722,353✔
307

308
  char hbrTimeStr[256] = "";
722,353✔
309
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
722,353✔
310

311
  char hbTimeStr[256] = "";
722,353✔
312
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
722,353✔
313

314
  char sentHbTimeStr[512] = "";
722,353✔
315
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
722,353✔
316

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

323
  terrno = errCode;
722,353✔
324

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

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

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

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

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

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

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

372
  taosPrintLog(flags, level, dflag,
306,047✔
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->startTime,
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,
131,163!
386
               pSender->replicaIndex, DID(&pNode->replicasId[pSender->replicaIndex]), raftStoreGetTerm(pNode),
43,721✔
387
               pNode->commitIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
388
               snapshot.lastApplyTerm, pNode->raftCfg.isStandBy, pNode->raftCfg.batchSize, pNode->replicaNum,
43,721✔
389
               pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr, cfgStr);
43,721!
390
}
391

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

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

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

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

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

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

421
  taosPrintLog(
63,490✔
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->startTime, pReceiver->start,
9,070✔
432
      pReceiver->ack, pReceiver->pRcvBuf->start, pReceiver->pRcvBuf->cursor, pReceiver->pRcvBuf->end,
27,210✔
433
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
9,070✔
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,
9,070✔
437
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
9,070!
438
      cfgStr);
439
}
440

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

444
  int64_t tsNow = taosGetTimestampMs();
×
445
  int64_t timeDIff = tsNow - pMsg->timeStamp;
×
446
  sNTrace(pSyncNode,
×
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) {
3,909,413✔
454
  sNTrace(pSyncNode,
3,909,413!
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
}
3,909,413✔
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

470
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s,
×
471
                                   const STraceId* trace) {
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);
477
}
×
478

479
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
4,275,142✔
480
                          int64_t execTime, const STraceId* trace) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
4,275,142✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
144✔
483
    if (pMsg->timeStamp > 0) {
144!
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
144!
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
144!
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,
144!
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) {
4,274,998✔
503
      char pBuf[TD_TIME_STR_LEN] = {0};
373,128✔
504
      if (pMsg->timeStamp > 0) {
373,128!
505
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
373,128!
506
          pBuf[0] = '\0';
×
507
        }
508
      }
509
      sHTrace(pSyncNode,
373,128!
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) {
3,901,870!
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) {
3,901,870!
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
}
4,275,142✔
545

546
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
3,919,286✔
547
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
548
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
3,919,286✔
549
    pSyncNode->hbSlowNum++;
342,023✔
550

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

558
    sHWarn(pSyncNode,
342,023!
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) {
3,577,263!
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) {
3,577,263!
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
}
3,919,286✔
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,
3,837,240✔
613
                               const STraceId* trace, int64_t timeDiff) {
614
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
3,837,240✔
615
    pSyncNode->hbrSlowNum++;
380,186✔
616

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

624
    sHError(pSyncNode,
380,186!
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){
3,457,054!
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) {
3,457,054!
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
}
3,837,240✔
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->startTime, 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->startTime, pMsg->dataLen, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
678
}
×
679

680
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s,
962✔
681
                                const STraceId* trace) {
682
  sNDebug(pSyncNode,
962!
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
}
962✔
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,
685,550✔
717
                            const char* opt, const STraceId* trace) {
718
  char statusMsg[64];
685,550✔
719
  snprintf(statusMsg, sizeof(statusMsg), "granted:%d", voteGranted);
685,550!
720
  sNInfo(pSyncNode,
685,550!
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
}
685,550✔
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,
343,994✔
736
                                 const STraceId* trace) {
737
  sNInfo(pSyncNode,
343,994!
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
}
343,994✔
741

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

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