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

taosdata / TDengine / #4791

13 Oct 2025 06:50AM UTC coverage: 57.628% (-0.8%) from 58.476%
#4791

push

travis-ci

web-flow
Merge pull request #33213 from taosdata/fix/huoh/timemoe_model_directory

fix: fix tdgpt timemoe model directory

136628 of 303332 branches covered (45.04%)

Branch coverage included in aggregate %.

208121 of 294900 relevant lines covered (70.57%)

4250784.02 hits per line

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

69.23
/source/libs/sync/src/syncMessage.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 "syncMessage.h"
18
#include "syncRaftEntry.h"
19
#include "syncRaftStore.h"
20

21
int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS,
55,997✔
22
                         SSyncNode* pNode) {
23
  int32_t bytes = sizeof(SyncTimeout);
55,997✔
24
  pMsg->pCont = rpcMallocCont(bytes);
55,997✔
25
  pMsg->msgType = (timeoutType == SYNC_TIMEOUT_ELECTION) ? TDMT_SYNC_TIMEOUT_ELECTION : TDMT_SYNC_TIMEOUT;
55,997✔
26
  pMsg->contLen = bytes;
55,997✔
27
  if (pMsg->pCont == NULL) {
55,997!
28
    return terrno;
×
29
  }
30

31
  SyncTimeout* pTimeout = pMsg->pCont;
55,997✔
32
  pTimeout->bytes = bytes;
55,997✔
33
  pTimeout->msgType = pMsg->msgType;
55,997✔
34
  pTimeout->vgId = pNode->vgId;
55,997✔
35
  pTimeout->timeoutType = timeoutType;
55,997✔
36
  pTimeout->logicClock = logicClock;
55,997✔
37
  pTimeout->timerMS = timerMS;
55,997✔
38
  pTimeout->timeStamp = taosGetTimestampMs();
55,997✔
39
  pTimeout->data = pNode;
55,997✔
40
  return 0;
55,997✔
41
}
42

43
int32_t syncBuildClientRequest(SRpcMsg* pMsg, const SRpcMsg* pOriginal, uint64_t seqNum, bool isWeak, int32_t vgId) {
167,422✔
44
  int32_t bytes = sizeof(SyncClientRequest) + pOriginal->contLen;
167,422✔
45

46
  pMsg->pCont = rpcMallocCont(bytes);
167,422✔
47
  if (pMsg->pCont == NULL) {
167,422!
48
    return terrno;
×
49
  }
50
  pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
167,422✔
51
  pMsg->contLen = bytes;
167,422✔
52

53
  SyncClientRequest* pClientRequest = pMsg->pCont;
167,422✔
54
  pClientRequest->bytes = bytes;
167,422✔
55
  pClientRequest->vgId = vgId;
167,422✔
56
  pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
167,422✔
57
  pClientRequest->originalRpcType = pOriginal->msgType;
167,422✔
58
  pClientRequest->seqNum = seqNum;
167,422✔
59
  pClientRequest->isWeak = isWeak;
167,422✔
60
  pClientRequest->dataLen = pOriginal->contLen;
167,422✔
61
  memcpy(pClientRequest->data, (char*)pOriginal->pCont, pOriginal->contLen);
167,422✔
62

63
  return 0;
167,422✔
64
}
65

66
int32_t syncBuildClientRequestFromNoopEntry(SRpcMsg* pMsg, const SSyncRaftEntry* pEntry, int32_t vgId) {
×
67
  int32_t bytes = sizeof(SyncClientRequest) + pEntry->bytes;
×
68
  pMsg->pCont = rpcMallocCont(bytes);
×
69
  pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
×
70
  pMsg->contLen = bytes;
×
71
  if (pMsg->pCont == NULL) {
×
72
    return terrno;
×
73
  }
74

75
  SyncClientRequest* pClientRequest = pMsg->pCont;
×
76
  pClientRequest->bytes = bytes;
×
77
  pClientRequest->vgId = vgId;
×
78
  pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
×
79
  pClientRequest->originalRpcType = TDMT_SYNC_NOOP;
×
80
  pClientRequest->dataLen = pEntry->bytes;
×
81
  memcpy(pClientRequest->data, (char*)pEntry, pEntry->bytes);
×
82

83
  return 0;
×
84
}
85

86
int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId) {
2,721✔
87
  int32_t bytes = sizeof(SyncRequestVote);
2,721✔
88
  pMsg->pCont = rpcMallocCont(bytes);
2,721✔
89
  pMsg->msgType = TDMT_SYNC_REQUEST_VOTE;
2,721✔
90
  pMsg->contLen = bytes;
2,721✔
91
  if (pMsg->pCont == NULL) {
2,721!
92
    return terrno;
×
93
  }
94

95
  SyncRequestVote* pRequestVote = pMsg->pCont;
2,721✔
96
  pRequestVote->bytes = bytes;
2,721✔
97
  pRequestVote->msgType = TDMT_SYNC_REQUEST_VOTE;
2,721✔
98
  pRequestVote->vgId = vgId;
2,721✔
99
  return 0;
2,721✔
100
}
101

102
int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId) {
3,966✔
103
  int32_t bytes = sizeof(SyncRequestVoteReply);
3,966✔
104
  pMsg->pCont = rpcMallocCont(bytes);
3,966✔
105
  pMsg->msgType = TDMT_SYNC_REQUEST_VOTE_REPLY;
3,966✔
106
  pMsg->contLen = bytes;
3,966✔
107
  if (pMsg->pCont == NULL) {
3,966!
108
    return terrno;
×
109
  }
110

111
  SyncRequestVoteReply* pRequestVoteReply = pMsg->pCont;
3,966✔
112
  pRequestVoteReply->bytes = bytes;
3,966✔
113
  pRequestVoteReply->msgType = TDMT_SYNC_REQUEST_VOTE_REPLY;
3,966✔
114
  pRequestVoteReply->vgId = vgId;
3,966✔
115
  return 0;
3,966✔
116
}
117

118
int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
×
119
  int32_t bytes = sizeof(SyncAppendEntries) + dataLen;
×
120
  pMsg->pCont = rpcMallocCont(bytes);
×
121
  pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES;
×
122
  pMsg->contLen = bytes;
×
123
  if (pMsg->pCont == NULL) {
×
124
    return terrno;
×
125
  }
126

127
  SyncAppendEntries* pAppendEntries = pMsg->pCont;
×
128
  pAppendEntries->bytes = bytes;
×
129
  pAppendEntries->vgId = vgId;
×
130
  pAppendEntries->msgType = TDMT_SYNC_APPEND_ENTRIES;
×
131
  pAppendEntries->dataLen = dataLen;
×
132
  return 0;
×
133
}
134

135
int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId) {
226,194✔
136
  int32_t bytes = sizeof(SyncAppendEntriesReply);
226,194✔
137
  pMsg->pCont = rpcMallocCont(bytes);
226,194✔
138
  pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
226,194✔
139
  pMsg->contLen = bytes;
226,194✔
140
  if (pMsg->pCont == NULL) {
226,194!
141
    return terrno;
×
142
  }
143

144
  SyncAppendEntriesReply* pAppendEntriesReply = pMsg->pCont;
226,194✔
145
  pAppendEntriesReply->bytes = bytes;
226,194✔
146
  pAppendEntriesReply->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
226,194✔
147
  pAppendEntriesReply->vgId = vgId;
226,194✔
148
  return 0;
226,194✔
149
}
150

151
int32_t syncBuildAppendEntriesFromRaftEntry(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
227,751✔
152
                                            SRpcMsg* pRpcMsg) {
153
  uint32_t dataLen = pEntry->bytes;
227,751✔
154
  uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
227,751✔
155
  pRpcMsg->info.traceId = pEntry->originRpcTraceId;
227,751✔
156
  pRpcMsg->contLen = bytes;
227,751✔
157
  pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
227,751✔
158
  if (pRpcMsg->pCont == NULL) {
227,749!
159
    return terrno;
×
160
  }
161

162
  SyncAppendEntries* pMsg = pRpcMsg->pCont;
227,749✔
163
  pMsg->bytes = pRpcMsg->contLen;
227,749✔
164
  pMsg->msgType = pRpcMsg->msgType = TDMT_SYNC_APPEND_ENTRIES;
227,749✔
165
  pMsg->dataLen = dataLen;
227,749✔
166

167
  (void)memcpy(pMsg->data, pEntry, dataLen);
227,749✔
168

169
  pMsg->prevLogIndex = pEntry->index - 1;
227,749✔
170
  pMsg->prevLogTerm = prevLogTerm;
227,749✔
171
  pMsg->vgId = pNode->vgId;
227,749✔
172
  pMsg->srcId = pNode->myRaftId;
227,749✔
173
  pMsg->term = raftStoreGetTerm(pNode);
227,749✔
174
  pMsg->commitIndex = pNode->commitIndex;
227,752✔
175
  pMsg->privateTerm = 0;
227,752✔
176
  return 0;
227,752✔
177
}
178

179
int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId) {
85,061✔
180
  int32_t bytes = sizeof(SyncHeartbeat);
85,061✔
181
  pMsg->pCont = rpcMallocCont(bytes);
85,061✔
182
  pMsg->msgType = TDMT_SYNC_HEARTBEAT;
85,061✔
183
  pMsg->contLen = bytes;
85,061✔
184
  if (pMsg->pCont == NULL) {
85,061!
185
    return terrno;
×
186
  }
187

188
  SyncHeartbeat* pHeartbeat = pMsg->pCont;
85,061✔
189
  pHeartbeat->bytes = bytes;
85,061✔
190
  pHeartbeat->msgType = TDMT_SYNC_HEARTBEAT;
85,061✔
191
  pHeartbeat->vgId = vgId;
85,061✔
192
  return 0;
85,061✔
193
}
194

195
int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId) {
78,730✔
196
  int32_t bytes = sizeof(SyncHeartbeatReply);
78,730✔
197
  pMsg->pCont = rpcMallocCont(bytes);
78,730✔
198
  pMsg->msgType = TDMT_SYNC_HEARTBEAT_REPLY;
78,729✔
199
  pMsg->contLen = bytes;
78,729✔
200
  if (pMsg->pCont == NULL) {
78,729!
201
    return terrno;
×
202
  }
203

204
  SyncHeartbeatReply* pHeartbeatReply = pMsg->pCont;
78,729✔
205
  pHeartbeatReply->bytes = bytes;
78,729✔
206
  pHeartbeatReply->msgType = TDMT_SYNC_HEARTBEAT_REPLY;
78,729✔
207
  pHeartbeatReply->vgId = vgId;
78,729✔
208
  return 0;
78,729✔
209
}
210

211
int32_t syncBuildSnapshotSend(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
1,543✔
212
  int32_t bytes = sizeof(SyncSnapshotSend) + dataLen;
1,543✔
213
  pMsg->pCont = rpcMallocCont(bytes);
1,543✔
214
  pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND;
1,543✔
215
  pMsg->contLen = bytes;
1,543✔
216
  if (pMsg->pCont == NULL) {
1,543!
217
    return terrno;
×
218
  }
219

220
  SyncSnapshotSend* pSnapshotSend = pMsg->pCont;
1,543✔
221
  pSnapshotSend->bytes = bytes;
1,543✔
222
  pSnapshotSend->vgId = vgId;
1,543✔
223
  pSnapshotSend->msgType = TDMT_SYNC_SNAPSHOT_SEND;
1,543✔
224
  pSnapshotSend->dataLen = dataLen;
1,543✔
225
  return 0;
1,543✔
226
}
227

228
int32_t syncBuildSnapshotSendRsp(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
1,496✔
229
  int32_t bytes = sizeof(SyncSnapshotRsp) + dataLen;
1,496✔
230
  pMsg->pCont = rpcMallocCont(bytes);
1,496✔
231
  pMsg->msgType = TDMT_SYNC_SNAPSHOT_RSP;
1,496✔
232
  pMsg->contLen = bytes;
1,496✔
233
  if (pMsg->pCont == NULL) {
1,496!
234
    return terrno;
×
235
  }
236

237
  SyncSnapshotRsp* pPreSnapshotRsp = pMsg->pCont;
1,496✔
238
  pPreSnapshotRsp->bytes = bytes;
1,496✔
239
  pPreSnapshotRsp->msgType = TDMT_SYNC_SNAPSHOT_RSP;
1,496✔
240
  pPreSnapshotRsp->vgId = vgId;
1,496✔
241
  return 0;
1,496✔
242
}
243

244
int32_t syncBuildLeaderTransfer(SRpcMsg* pMsg, int32_t vgId) {
1,202✔
245
  int32_t bytes = sizeof(SyncLeaderTransfer);
1,202✔
246
  pMsg->pCont = rpcMallocCont(bytes);
1,202✔
247
  pMsg->msgType = TDMT_SYNC_LEADER_TRANSFER;
1,202✔
248
  pMsg->contLen = bytes;
1,202✔
249
  if (pMsg->pCont == NULL) {
1,202!
250
    return terrno;
×
251
  }
252

253
  SyncLeaderTransfer* pLeaderTransfer = pMsg->pCont;
1,202✔
254
  pLeaderTransfer->bytes = bytes;
1,202✔
255
  pLeaderTransfer->msgType = TDMT_SYNC_LEADER_TRANSFER;
1,202✔
256
  pLeaderTransfer->vgId = vgId;
1,202✔
257
  return 0;
1,202✔
258
}
259

260
int32_t syncBuildLocalCmd(SRpcMsg* pMsg, int32_t vgId) {
78,575✔
261
  int32_t bytes = sizeof(SyncLocalCmd);
78,575✔
262
  pMsg->pCont = rpcMallocCont(bytes);
78,575✔
263
  pMsg->msgType = TDMT_SYNC_LOCAL_CMD;
78,575✔
264
  pMsg->contLen = bytes;
78,575✔
265
  if (pMsg->pCont == NULL) {
78,575!
266
    return terrno;
×
267
  }
268

269
  SyncLocalCmd* pLocalCmd = pMsg->pCont;
78,575✔
270
  pLocalCmd->bytes = bytes;
78,575✔
271
  pLocalCmd->msgType = TDMT_SYNC_LOCAL_CMD;
78,575✔
272
  pLocalCmd->vgId = vgId;
78,575✔
273
  return 0;
78,575✔
274
}
275

276
const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
143✔
277
  switch (timerType) {
143!
278
    case SYNC_TIMEOUT_PING:
143✔
279
      return "ping";
143✔
280
    case SYNC_TIMEOUT_ELECTION:
×
281
      return "elect";
×
282
    case SYNC_TIMEOUT_HEARTBEAT:
×
283
      return "heartbeat";
×
284
    default:
×
285
      return "unknown";
×
286
  }
287
}
288

289
const char* syncLocalCmdGetStr(ESyncLocalCmd cmd) {
×
290
  switch (cmd) {
×
291
    case SYNC_LOCAL_CMD_STEP_DOWN:
×
292
      return "step-down";
×
293
    case SYNC_LOCAL_CMD_FOLLOWER_CMT:
×
294
      return "follower-commit";
×
295
    default:
×
296
      return "unknown-local-cmd";
×
297
  }
298
}
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