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

taosdata / TDengine / #4938

23 Jan 2026 09:40AM UTC coverage: 66.8% (+0.006%) from 66.794%
#4938

push

travis-ci

web-flow
fix: case failuer caused by the modification of the error description (#34391)

204187 of 305671 relevant lines covered (66.8%)

124015580.65 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) {
21,135,526✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
21,135,526✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
66,142,829✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
45,010,952✔
33
    if (i < pCfg->replicaNum - 1) {
45,009,976✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
23,874,783✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
21,134,793✔
38
}
21,135,228✔
39

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

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

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

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

68
  raftId->addr = SYNC_ADDR(pInfo);
7,336,559✔
69
  raftId->vgId = vgId;
7,336,559✔
70

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

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
1,453,846,052✔
82
    return true;
30,096✔
83
  }
84

85
  return false;
1,453,876,199✔
86
}
87

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

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
113,077,435✔
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
113,077,435✔
93
  int32_t rdm = min + syncUtilRand(max - min);
113,077,435✔
94

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

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

101
void syncUtilMsgHtoN(void* msg) {
238,704,418✔
102
  SMsgHead* pHead = msg;
238,704,418✔
103
  pHead->contLen = htonl(pHead->contLen);
238,704,418✔
104
  pHead->vgId = htonl(pHead->vgId);
238,705,749✔
105
}
238,706,221✔
106

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

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
132,075,964✔
115
  if (formatTime) {
132,075,964✔
116
    char pBuf[TD_TIME_STR_LEN] = {0};
132,077,801✔
117
    if (tsMs > 0) {
132,078,572✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
92,720,963✔
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
132,086,380✔
123
  } else {
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
132,082,594✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,560,631✔
130
  int32_t len = 0;
20,560,631✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,559,964✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,582,916✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
44,026,512✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
44,021,056✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
44,023,195✔
136
    if (i < pSyncNode->replicaNum - 1) {
44,020,764✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,462,683✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,558,077✔
141
}
20,563,819✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,563,434✔
144
  int32_t len = 0;
20,563,434✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,564,325✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,586,846✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
44,026,989✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
44,022,976✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
44,024,318✔
150
    if (i < pSyncNode->replicaNum - 1) {
44,027,100✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,462,819✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,559,588✔
155
}
20,563,694✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,558,559✔
159
  int32_t len = 0;
20,558,559✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,560,263✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,591,016✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
44,026,376✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
44,027,163✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
44,027,634✔
165
    if (i < pSyncNode->replicaNum - 1) {
44,028,425✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,463,087✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,564,768✔
170
}
20,565,487✔
171

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

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
20,563,619✔
183
  int32_t len = 0;
20,563,619✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,563,619✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
64,587,613✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
44,027,251✔
187
    if (pMgr == NULL) break;
44,024,254✔
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
44,024,254✔
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
44,025,126✔
191
    if (i + 1 < pSyncNode->replicaNum) {
44,025,625✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
23,462,571✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,561,525✔
196
}
20,562,774✔
197

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

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

215
  // save error code, otherwise it will be overwritten
216
  int32_t errCode = terrno;
18,816,423✔
217

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

223
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
18,816,266✔
224
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
18,816,266✔
225
  if (pNode->pLogStore != NULL) {
18,816,266✔
226
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
18,816,266✔
227
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
18,815,993✔
228
  }
229

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
18,815,074✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
18,815,294✔
232

233
  char cfgStr[1024] = "";
18,814,864✔
234
  syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
18,815,273✔
235

236
  char replMgrStatesStr[1024] = "";
18,815,045✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
18,815,956✔
238

239
  char bufferStatesStr[256] = "";
18,813,424✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
18,814,165✔
241

242
  char hbrTimeStr[256] = "";
18,814,912✔
243
  syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr), formatTime);
18,814,912✔
244

245
  char hbTimeStr[256] = "";
18,814,873✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
18,815,354✔
247

248
  char sentHbTimeStr[512] = "";
18,814,273✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
18,815,378✔
250

251
  char    eventLog[512];  // {0};
18,800,061✔
252
  va_list argpointer;
18,800,505✔
253
  va_start(argpointer, format);
18,815,370✔
254
  int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
18,815,370✔
255
  va_end(argpointer);
18,815,370✔
256

257
  int32_t aqItems = 0;
18,815,370✔
258
  if (pNode != NULL && pNode->pFsm != NULL && pNode->pFsm->FpApplyQueueItems != NULL) {
18,815,370✔
259
    aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);  // vnodeApplyQueueItems
18,813,506✔
260
  }
261

262
  // restore error code
263
  terrno = errCode;
18,806,209✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
18,812,173✔
265

266
  if (pNode != NULL) {
18,809,472✔
267
    taosPrintLog(
56,400,777✔
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,
18,812,646✔
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
18,810,477✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

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

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

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
1,749,064✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
1,749,064✔
298

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

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

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

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

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

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

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

323
  terrno = errCode;
1,749,064✔
324

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

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

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

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

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

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

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

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

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

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

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

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

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

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

421
  taosPrintLog(
1,439,382✔
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,
822,504✔
433
      DID(&pReceiver->fromId), pReceiver->snapshotParam.start, pReceiver->snapshotParam.end,
205,626✔
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,
205,626✔
437
      pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, pNode->quorum, peerStr,
205,626✔
438
      cfgStr);
439
}
440

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

444
  int64_t tsNow = taosGetTimestampMs();
856✔
445
  int64_t timeDIff = tsNow - pMsg->timeStamp;
856✔
446
  sNTrace(pSyncNode,
856✔
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) {
22,288,894✔
454
  sNTrace(pSyncNode,
22,288,894✔
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
}
22,288,894✔
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,
24,176,665✔
480
                          int64_t execTime, const STraceId* trace) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
24,176,665✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
6,673✔
483
    if (pMsg->timeStamp > 0) {
6,673✔
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
6,673✔
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
6,673✔
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,
6,673✔
496
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
497
              ", ts:%s}, slow timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
498
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
499
              trace ? trace->rootId : 0, trace ? trace->msgId : 0);
500
    }
501
  } else {
502
    if (printX) {
24,169,992✔
503
      char pBuf[TD_TIME_STR_LEN] = {0};
915,311✔
504
      if (pMsg->timeStamp > 0) {
915,311✔
505
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
915,311✔
506
          pBuf[0] = '\0';
×
507
        }
508
      }
509
      sHTrace(pSyncNode,
915,311✔
510
              "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
511
              ", ts:%s}, x, QID:0x%" PRIx64 ":0x%" PRIx64,
512
              DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, trace ? trace->rootId : 0, 
513
              trace ? trace->msgId : 0);
514
    } else {
515
      if (tsSyncLogHeartbeat) {
23,254,681✔
516
        char pBuf[TD_TIME_STR_LEN] = {0};
×
517
        if (pMsg->timeStamp > 0) {
×
518
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
519
            pBuf[0] = '\0';
×
520
          }
521
        }
522
        sHInfo(pSyncNode,
×
523
               "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
524
               ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
525
               DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
526
               trace ? trace->rootId : 0, trace ? trace->msgId : 0);
527
      } else {
528
        if (sDebugFlag & DEBUG_TRACE) {
23,254,681✔
529
          char pBuf[TD_TIME_STR_LEN] = {0};
×
530
          if (pMsg->timeStamp > 0) {
×
531
            if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
532
              pBuf[0] = '\0';
×
533
            }
534
          }
535
          sHTrace(pSyncNode,
×
536
                  "send sync-heartbeat to dnode:%d {term:%" PRId64 ", commit-index:%" PRId64 ", min-match:%" PRId64
537
                  ", ts:%s}, timer-elapsed:%" PRId64 ", next-exec:%" PRId64 ", QID:0x%" PRIx64 ":0x%" PRIx64,
538
                  DID(&pMsg->destId), pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pBuf, timerElapsed, execTime, 
539
                  trace ? trace->rootId : 0, trace ? trace->msgId : 0);
540
        }
541
      }
542
    }
543
  }
544
}
24,176,665✔
545

546
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
22,358,509✔
547
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
548
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
22,358,509✔
549
    pSyncNode->hbSlowNum++;
816,559✔
550

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

558
    sHWarn(pSyncNode,
816,559✔
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) {
21,541,950✔
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) {
21,541,950✔
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
}
22,358,509✔
595

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

612
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, int64_t netElapse,
22,460,910✔
613
                               const STraceId* trace, int64_t timeDiff) {
614
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
22,460,910✔
615
    pSyncNode->hbrSlowNum++;
925,832✔
616

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

624
    sHWarn(pSyncNode,
925,832✔
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){
21,535,078✔
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) {
21,535,078✔
645
        char pBuf[TD_TIME_STR_LEN] = {0};
×
646
        if (pMsg->timeStamp > 0) {
×
647
          if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
×
648
            pBuf[0] = '\0';
×
649
          }
650
        }
651
        sHTrace(pSyncNode,
×
652
                "recv sync-heartbeat-reply from dnode:%d {term:%" PRId64 ", ts:%" PRId64 "}, net elapsed:%" PRId64
653
                ", timeDiff:%" PRId64 " QID:0x%" PRIx64 ":0x%" PRIx64,
654
                DID(&pMsg->srcId), pMsg->term, pMsg->timeStamp, netElapse, timeDiff, trace ? trace->rootId : 0,
655
                trace ? trace->msgId : 0);
656
      }
657
    }   
658
  }
659
}
22,460,910✔
660

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

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

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

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

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

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

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

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

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