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

taosdata / TDengine / #4488

12 Jul 2025 07:47AM UTC coverage: 62.207% (-0.7%) from 62.948%
#4488

push

travis-ci

web-flow
docs: update stream docs (#31822)

157961 of 324087 branches covered (48.74%)

Branch coverage included in aggregate %.

244465 of 322830 relevant lines covered (75.73%)

6561668.76 hits per line

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

61.69
/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) {
204,284✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
204,284✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
533,834✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
329,555✔
33
    if (i < pCfg->replicaNum - 1) {
329,554✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
125,278✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
204,279✔
38
}
204,280✔
39

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

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

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

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

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

76
bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) {
14,296,609✔
77
  if (pId1->addr == pId2->addr && pId1->vgId == pId2->vgId) {
14,296,609!
78
    return true;
8,291,893✔
79
  }
80

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
6,004,716!
82
    return true;
228✔
83
  }
84

85
  return false;
6,004,488✔
86
}
87

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

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
490,415✔
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
490,415✔
93
  int32_t rdm = min + syncUtilRand(max - min);
490,415✔
94

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

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

101
void syncUtilMsgHtoN(void* msg) {
1,035,840✔
102
  SMsgHead* pHead = msg;
1,035,840✔
103
  pHead->contLen = htonl(pHead->contLen);
1,035,840✔
104
  pHead->vgId = htonl(pHead->vgId);
1,035,840✔
105
}
1,035,840✔
106

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

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
596,462✔
115
  if (formatTime) {
596,462!
116
    char pBuf[TD_TIME_STR_LEN] = {0};
596,462✔
117
    if (tsMs > 0) {
596,462✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
413,866!
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
596,458✔
123
  } else {
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
596,476✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
117,239✔
130
  int32_t len = 0;
117,239✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
117,239✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
316,071✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
198,834✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
198,837✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
198,836✔
136
    if (i < pSyncNode->replicaNum - 1) {
198,831✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
81,596✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
117,237✔
141
}
117,240✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
117,243✔
144
  int32_t len = 0;
117,243✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
117,243✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
316,079✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
198,835✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
198,834✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
198,833✔
150
    if (i < pSyncNode->replicaNum - 1) {
198,839✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
81,596✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
117,244✔
155
}
117,243✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
117,226✔
159
  int32_t len = 0;
117,226✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
117,226✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
316,073✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
198,819✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
198,836✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
198,836✔
165
    if (i < pSyncNode->replicaNum - 1) {
198,836✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
81,595✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
117,254✔
170
}
117,242✔
171

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

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
117,240✔
183
  int32_t len = 0;
117,240✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
117,240✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
316,077✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
198,835✔
187
    if (pMgr == NULL) break;
198,835!
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
198,835✔
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
198,833✔
191
    if (i + 1 < pSyncNode->replicaNum) {
198,835✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
81,595✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
117,242✔
196
}
117,242✔
197

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

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

215
  // save error code, otherwise it will be overwritten
216
  int32_t errCode = terrno;
111,428✔
217

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

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

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
111,429✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
111,429✔
232

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

236
  char replMgrStatesStr[1024] = "";
111,426✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
111,426✔
238

239
  char bufferStatesStr[256] = "";
111,427✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
111,427✔
241

242
  char hbrTimeStr[256] = "";
111,426✔
243
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
111,426✔
244

245
  char hbTimeStr[256] = "";
111,422✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
111,422✔
247

248
  char sentHbTimeStr[512] = "";
111,427✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
111,427✔
250

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

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

262
  // restore error code
263
  terrno = errCode;
111,420✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
111,423✔
265

266
  if (pNode != NULL) {
111,425!
267
    taosPrintLog(
111,418✔
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,
111,417✔
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
111,425✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

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

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

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
5,815✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
5,815✔
298

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

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

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

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

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

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

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

323
  terrno = errCode;
5,815✔
324

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

444
  int64_t tsNow = taosGetTimestampMs();
4,795✔
445
  int64_t timeDIff = tsNow - pMsg->timeStamp;
4,795✔
446
  sNTrace(pSyncNode,
4,795!
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) {
52,237✔
454
  sNTrace(pSyncNode,
52,237!
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
}
52,237✔
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,
61,145✔
480
                          int64_t execTime) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
61,145✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
14✔
483
    if (pMsg->timeStamp > 0) {
14!
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
14!
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
14!
489
      sHError(pSyncNode,
×
490
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
491
              ", ts:%s}, x",
492
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf);
493
    } else {
494
      sHError(pSyncNode,
14!
495
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
496
              ", ts:%s}, slow timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
497
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime);
498
    }
499
  } else {
500
    if (printX) {
61,131✔
501
      char pBuf[TD_TIME_STR_LEN] = {0};
3,134✔
502
      if (pMsg->timeStamp > 0) {
3,134!
503
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
3,134!
504
          pBuf[0] = '\0';
×
505
        }
506
      }
507
      sHTrace(pSyncNode,
3,134!
508
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
509
              ", ts:%s}, x",
510
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf);
511
    } else {
512
      if (tsSyncLogHeartbeat) {
57,997!
513
        char pBuf[TD_TIME_STR_LEN] = {0};
×
514
        if (pMsg->timeStamp > 0) {
×
515
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
516
            pBuf[0] = '\0';
×
517
          }
518
        }
519
        sHInfo(pSyncNode,
×
520
               "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
521
               ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
522
               DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime);
523
      } else {
524
        if (sDebugFlag & DEBUG_TRACE) {
57,997!
525
          char pBuf[TD_TIME_STR_LEN] = {0};
×
526
          if (pMsg->timeStamp > 0) {
×
527
            if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
528
              pBuf[0] = '\0';
×
529
            }
530
          }
531
          sHTrace(pSyncNode,
×
532
                  "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
533
                  ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64,
534
                  DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime);
535
        }
536
      }
537
    }
538
  }
539
}
61,145✔
540

541
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
52,787✔
542
                          int64_t timeDiff) {
543
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
52,787✔
544
    pSyncNode->hbSlowNum++;
2,680✔
545

546
    char pBuf[TD_TIME_STR_LEN] = {0};
2,680✔
547
    if (pMsg->timeStamp > 0) {
2,680!
548
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
2,680!
549
        pBuf[0] = '\0';
×
550
      }
551
    }
552

553
    sHWarn(pSyncNode,
2,680!
554
           "recv sync-heartbeat from dnode:%d slow(%d ms) {term:%" PRId64 ", commit-index:%" PRId64
555
           ", min-match:%" PRId64 ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64
556
           ":0x%" PRIx64,
557
           DID(&pMsg->srcId), SYNC_HEARTBEAT_SLOW_MS, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf,
558
           netElapsed, timeDiff, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
559
  } else {
560
    if (tsSyncLogHeartbeat) {
50,107!
561
      char pBuf[TD_TIME_STR_LEN] = {0};
×
562
      if (pMsg->timeStamp > 0) {
×
563
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
564
          pBuf[0] = '\0';
×
565
        }
566
      }
567
      sHInfo(pSyncNode,
×
568
             "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
569
             ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64 ":0x%" PRIx64,
570
             DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
571
             trace->rootId, trace->msgId);
572
    } else {
573
      if (sDebugFlag & DEBUG_TRACE) {
50,107!
574
        char pBuf[TD_TIME_STR_LEN] = {0};
×
575
        if (pMsg->timeStamp > 0) {
×
576
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
577
            pBuf[0] = '\0';
×
578
          }
579
        }
580

581
        sHTrace(pSyncNode,
×
582
                "recv sync-heartbeat from dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
583
                ", ts:%s}, net elapsed:%" PRId64 "ms, timeDiff:%" PRId64 "ms, QID:0x%" PRIx64 ":0x%" PRIx64,
584
                DID(&pMsg->srcId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, netElapsed, timeDiff,
585
                trace->rootId, trace->msgId);
586
      }
587
    }
588
  }
589
}
52,787✔
590

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

607
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t netElapse,
50,867✔
608
                               const STraceId* trace, int64_t timeDiff) {
609
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
50,867✔
610
    pSyncNode->hbrSlowNum++;
3,121✔
611

612
    char pBuf[TD_TIME_STR_LEN] = {0};
3,121✔
613
    if (pMsg->timeStamp > 0) {
3,121!
614
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
3,121!
615
        pBuf[0] = '\0';
×
616
      }
617
    }
618

619
    sHError(pSyncNode,
3,121!
620
            "recv sync-heartbeat-reply from dnode:%d slow(%d ms) {term:%" PRId64 ", ts:%s}, net elapsed:%" PRId64
621
            ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
622
            DID(&pMsg->srcId), SYNC_HEARTBEAT_REPLY_SLOW_MS, pMsg->term, pBuf, netElapse, timeDiff, trace->rootId,
623
            trace->msgId);
624
  } else {
625
    if(tsSyncLogHeartbeat){
47,746!
626
      char pBuf[TD_TIME_STR_LEN] = {0};
×
627
      if (pMsg->timeStamp > 0) {
×
628
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
629
          pBuf[0] = '\0';
×
630
        }
631
      }
632
      sHInfo(pSyncNode,
×
633
              "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
634
              ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
635
              DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
636
              trace ? trace->msgId : 0);
637
    }
638
    else{
639
      if (sDebugFlag & DEBUG_TRACE) {
47,746!
640
        char pBuf[TD_TIME_STR_LEN] = {0};
×
641
        if (pMsg->timeStamp > 0) {
×
642
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
643
            pBuf[0] = '\0';
×
644
          }
645
        }
646
        sHTrace(pSyncNode,
×
647
                "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
648
                ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
649
                DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
650
                trace ? trace->msgId : 0);
651
      }
652
    }   
653
  }
654
}
50,867✔
655

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

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

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

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

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

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

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

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

730
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
2,791✔
731
                                 const STraceId* trace) {
732
  sNInfo(pSyncNode,
2,791!
733
         "recv sync-request-vote-reply from dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
734
         DID(&pMsg->srcId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
735
}
2,791✔
736

737
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s,
3,098✔
738
                                 const STraceId* trace) {
739
  sNInfo(pSyncNode,
3,098!
740
         "send sync-request-vote-reply to dnode:%d {term:%" PRId64 ", grant:%d}, %s, QID:0x%" PRIx64 ":0x%" PRIx64,
741
         DID(&pMsg->destId), pMsg->term, pMsg->voteGranted, s, trace ? trace->rootId : 0, trace ? trace->msgId : 0);
742
}
3,098✔
743

744
int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) {
107✔
745
  void* data = taosMemoryRealloc(pSnap->data, size);
107!
746
  if (data == NULL) {
107!
747
    return terrno;
×
748
  }
749
  pSnap->data = data;
107✔
750
  return 0;
107✔
751
}
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