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

taosdata / TDengine / #4847

11 Nov 2025 05:50AM UTC coverage: 62.651% (+0.3%) from 62.306%
#4847

push

travis-ci

web-flow
Merge e78cd6509 into 47a2ea7a0

542 of 650 new or added lines in 16 files covered. (83.38%)

1515 existing lines in 91 files now uncovered.

113826 of 181682 relevant lines covered (62.65%)

113230552.12 hits per line

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

79.51
/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,219,144✔
30
  int32_t len = tsnprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
21,219,144✔
31
  for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
65,793,161✔
32
    len += tsnprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
44,574,390✔
33
    if (i < pCfg->replicaNum - 1) {
44,575,886✔
34
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
23,355,939✔
35
    }
36
  }
37
  len += tsnprintf(buf + len, bufLen - len, "%s", "]}");
21,218,789✔
38
}
21,220,569✔
39

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

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

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

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

68
  raftId->addr = SYNC_ADDR(pInfo);
8,256,382✔
69
  raftId->vgId = vgId;
8,256,382✔
70

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

81
  if ((CID(pId1) == 0 || CID(pId2) == 0) && (DID(pId1) == DID(pId2)) && pId1->vgId == pId2->vgId) {
1,167,490,554✔
82
    return true;
58,060✔
83
  }
84

85
  return false;
1,167,459,777✔
86
}
87

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

90
static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
86,974,623✔
91

92
int32_t syncUtilElectRandomMS(int32_t min, int32_t max) {
86,974,575✔
93
  int32_t rdm = min + syncUtilRand(max - min);
86,974,575✔
94

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

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

101
void syncUtilMsgHtoN(void* msg) {
175,306,043✔
102
  SMsgHead* pHead = msg;
175,306,043✔
103
  pHead->contLen = htonl(pHead->contLen);
175,306,043✔
104
  pHead->vgId = htonl(pHead->vgId);
175,303,195✔
105
}
175,304,095✔
106

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

114
static void syncPrintTime(bool formatTime, int32_t* len, int64_t tsMs, int32_t i, char* buf, int32_t bufLen, int64_t count) {
131,572,407✔
115
  if (formatTime) {
131,572,407✔
116
    char pBuf[TD_TIME_STR_LEN] = {0};
131,574,170✔
117
    if (tsMs > 0) {
131,575,533✔
118
      if (formatTimestampLocal(pBuf, tsMs, TSDB_TIME_PRECISION_MILLI) == NULL) {
93,057,583✔
119
        pBuf[0] = '\0';
×
120
      }
121
    }
122
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%s:%" PRId64, i, pBuf, count);
131,582,473✔
123
  } else {
124
    (*len) += tsnprintf(buf + (*len), bufLen - (*len), "%d:%" PRId64, i, tsMs);
×
125
  }
126
}
131,573,093✔
127

128
// for leader
129
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,839,672✔
130
  int32_t len = 0;
20,839,672✔
131
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,840,826✔
132
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,697,255✔
133
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
43,858,750✔
134
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
43,855,327✔
135
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
43,853,481✔
136
    if (i < pSyncNode->replicaNum - 1) {
43,855,521✔
137
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,015,828✔
138
    }
139
  }
140
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,841,247✔
141
}
20,842,402✔
142

143
static void syncSentHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,842,898✔
144
  int32_t len = 0;
20,842,898✔
145
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,842,898✔
146
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,701,250✔
147
    int64_t tsMs = syncIndexMgrGetSentTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
43,859,063✔
148
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
43,859,063✔
149
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
43,859,063✔
150
    if (i < pSyncNode->replicaNum - 1) {
43,858,769✔
151
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,016,135✔
152
    }
153
  }
154
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,842,898✔
155
}
20,842,898✔
156

157
// for follower
158
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen, bool formatTime) {
20,840,968✔
159
  int32_t len = 0;
20,840,968✔
160
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,842,898✔
161
  for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
64,700,409✔
162
    int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
43,855,949✔
163
    int64_t count = syncIndexMgrGetRecvCount(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
43,856,412✔
164
    syncPrintTime(formatTime, &len, tsMs, i, buf, bufLen, count);
43,857,283✔
165
    if (i < pSyncNode->replicaNum - 1) {
43,858,722✔
166
      len += tsnprintf(buf + len, bufLen - len, "%s", ",");
23,016,429✔
167
    }
168
  }
169
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,842,898✔
170
}
20,842,898✔
171

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

182
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
20,841,110✔
183
  int32_t len = 0;
20,841,110✔
184
  len += tsnprintf(buf + len, bufLen - len, "%s", "{");
20,841,110✔
185
  for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
64,694,950✔
186
    SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
43,857,007✔
187
    if (pMgr == NULL) break;
43,855,408✔
188
    len += tsnprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] ", i, pMgr->restored,
43,855,408✔
189
                     pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
190
    len += tsnprintf(buf + len, bufLen - len, "%" PRId64, pMgr->sendCount);
43,857,897✔
191
    if (i + 1 < pSyncNode->replicaNum) {
43,853,268✔
192
      len += tsnprintf(buf + len, bufLen - len, "%s", ", ");
23,014,528✔
193
    }
194
  }
195
  len += tsnprintf(buf + len, bufLen - len, "%s", "}");
20,838,414✔
196
}
20,838,953✔
197

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

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

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

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

223
  SyncIndex logLastIndex = SYNC_INDEX_INVALID;
18,791,514✔
224
  SyncIndex logBeginIndex = SYNC_INDEX_INVALID;
18,791,514✔
225
  if (pNode->pLogStore != NULL) {
18,791,514✔
226
    logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore);
18,791,457✔
227
    logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
18,792,050✔
228
  }
229

230
  int32_t cacheHit = pNode->pLogStore->cacheHit;
18,792,797✔
231
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
18,792,797✔
232

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

236
  char replMgrStatesStr[1024] = "";
18,792,797✔
237
  syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
18,792,797✔
238

239
  char bufferStatesStr[256] = "";
18,788,891✔
240
  syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
18,788,891✔
241

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

245
  char hbTimeStr[256] = "";
18,790,371✔
246
  syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr), formatTime);
18,791,526✔
247

248
  char sentHbTimeStr[512] = "";
18,792,797✔
249
  syncSentHearbeatTime2Str(pNode, sentHbTimeStr, sizeof(sentHbTimeStr), formatTime);
18,792,797✔
250

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

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

262
  // restore error code
263
  terrno = errCode;
18,791,234✔
264
  SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);  // vnodeSyncAppliedIndex
18,791,219✔
265

266
  if (pNode != NULL) {
18,790,473✔
267
    taosPrintLog(
56,311,769✔
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,790,192✔
282
        syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
283
        replMgrStatesStr, cfgStr, sentHbTimeStr, hbTimeStr, hbrTimeStr, pNode->arbToken, pNode->sendCount,
18,791,276✔
284
        pNode->recvCount, pNode->slowCount);
285
  }
286
}
287

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

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

296
  int32_t cacheHit = pNode->pLogStore->cacheHit;
2,050,101✔
297
  int32_t cacheMiss = pNode->pLogStore->cacheMiss;
2,050,101✔
298

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

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

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

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

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

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

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

323
  terrno = errCode;
2,050,101✔
324

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

441
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const STraceId* trace) {
28,564,172✔
442
  if (!(sDebugFlag & DEBUG_TRACE)) return;
28,564,172✔
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) {
29,204,446✔
454
  sNTrace(pSyncNode,
29,204,446✔
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
}
29,204,446✔
460

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

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

479
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, bool printX, int64_t timerElapsed,
32,389,546✔
480
                          int64_t execTime, const STraceId* trace) {
481
  if (timerElapsed > SYNC_HEARTBEAT_SLOW_MS) {
32,389,546✔
482
    char pBuf[TD_TIME_STR_LEN] = {0};
38,744✔
483
    if (pMsg->timeStamp > 0) {
38,744✔
484
      if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
38,744✔
485
        pBuf[0] = '\0';
×
486
      }
487
    }
488
    if (printX) {
38,744✔
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,
38,744✔
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) {
32,350,802✔
503
      char pBuf[TD_TIME_STR_LEN] = {0};
1,028,025✔
504
      if (pMsg->timeStamp > 0) {
1,028,025✔
505
        if (formatTimestampLocal(pBuf, pMsg->timeStamp, TSDB_TIME_PRECISION_MILLI) == NULL) {
1,028,025✔
506
          pBuf[0] = '\0';
×
507
        }
508
      }
509
      sHTrace(pSyncNode,
1,028,025✔
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) {
31,322,777✔
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) {
31,322,777✔
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
}
32,389,546✔
545

546
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, int64_t netElapsed, const STraceId* trace,
29,387,710✔
547
                          int64_t timeDiff, const SRpcMsg* pRpcMsg) {
548
  if (timeDiff > SYNC_HEARTBEAT_SLOW_MS) {
29,387,710✔
549
    pSyncNode->hbSlowNum++;
901,551✔
550

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

558
    sHWarn(pSyncNode,
901,551✔
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) {
28,486,159✔
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) {
28,486,159✔
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
}
29,387,710✔
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,
29,410,592✔
613
                               const STraceId* trace, int64_t timeDiff) {
614
  if (timeDiff > SYNC_HEARTBEAT_REPLY_SLOW_MS) {
29,410,592✔
615
    pSyncNode->hbrSlowNum++;
1,109,806✔
616

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

624
    sHError(pSyncNode,
1,109,806✔
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){
28,300,786✔
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) {
28,300,786✔
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
}
29,410,592✔
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,
20,606✔
681
                                const STraceId* trace) {
682
  sNDebug(pSyncNode,
20,606✔
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
}
20,606✔
688

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

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

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

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

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

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