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

taosdata / TDengine / #3720

26 Mar 2025 06:20AM UTC coverage: 30.242% (-31.7%) from 61.936%
#3720

push

travis-ci

web-flow
feat(taosBenchmark): supports decimal data type (#30456)

* feat: taosBenchmark supports decimal data type

* build: decimal script not use pytest.sh

* fix: fix typo for decimal script

* test: insertBasic.py debug

71234 of 313946 branches covered (22.69%)

Branch coverage included in aggregate %.

38 of 423 new or added lines in 8 files covered. (8.98%)

120240 existing lines in 447 files now uncovered.

118188 of 312400 relevant lines covered (37.83%)

1450220.33 hits per line

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

57.09
/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,
1,449✔
22
                         SSyncNode* pNode) {
23
  int32_t bytes = sizeof(SyncTimeout);
1,449✔
24
  pMsg->pCont = rpcMallocCont(bytes);
1,449✔
25
  pMsg->msgType = (timeoutType == SYNC_TIMEOUT_ELECTION) ? TDMT_SYNC_TIMEOUT_ELECTION : TDMT_SYNC_TIMEOUT;
1,449✔
26
  pMsg->contLen = bytes;
1,449✔
27
  if (pMsg->pCont == NULL) {
1,449!
28
    return terrno;
×
29
  }
30

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

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

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

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

63
  return 0;
1,759✔
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) {
333✔
87
  int32_t bytes = sizeof(SyncRequestVote);
333✔
88
  pMsg->pCont = rpcMallocCont(bytes);
333✔
89
  pMsg->msgType = TDMT_SYNC_REQUEST_VOTE;
333✔
90
  pMsg->contLen = bytes;
333✔
91
  if (pMsg->pCont == NULL) {
333!
92
    return terrno;
×
93
  }
94

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

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

111
  SyncRequestVoteReply* pRequestVoteReply = pMsg->pCont;
477✔
112
  pRequestVoteReply->bytes = bytes;
477✔
113
  pRequestVoteReply->msgType = TDMT_SYNC_REQUEST_VOTE_REPLY;
477✔
114
  pRequestVoteReply->vgId = vgId;
477✔
115
  return 0;
477✔
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) {
2,416✔
136
  int32_t bytes = sizeof(SyncAppendEntriesReply);
2,416✔
137
  pMsg->pCont = rpcMallocCont(bytes);
2,416✔
138
  pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
2,416✔
139
  pMsg->contLen = bytes;
2,416✔
140
  if (pMsg->pCont == NULL) {
2,416!
141
    return terrno;
×
142
  }
143

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

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

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

167
  (void)memcpy(pMsg->data, pEntry, dataLen);
798,462✔
168

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

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

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

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

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

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

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

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

UNCOV
237
  SyncSnapshotRsp* pPreSnapshotRsp = pMsg->pCont;
×
UNCOV
238
  pPreSnapshotRsp->bytes = bytes;
×
UNCOV
239
  pPreSnapshotRsp->msgType = TDMT_SYNC_SNAPSHOT_RSP;
×
UNCOV
240
  pPreSnapshotRsp->vgId = vgId;
×
UNCOV
241
  return 0;
×
242
}
243

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

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

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

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

UNCOV
276
const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
×
UNCOV
277
  switch (timerType) {
×
UNCOV
278
    case SYNC_TIMEOUT_PING:
×
UNCOV
279
      return "ping";
×
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