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

taosdata / TDengine / #4335

20 Jun 2025 05:45AM UTC coverage: 60.571% (-2.3%) from 62.916%
#4335

push

travis-ci

web-flow
fix: compatibility ci problems. (#31430)

149119 of 315107 branches covered (47.32%)

Branch coverage included in aggregate %.

231167 of 312731 relevant lines covered (73.92%)

6342953.77 hits per line

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

81.0
/source/libs/sync/src/syncRaftEntry.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 "syncRaftEntry.h"
18
#include "syncUtil.h"
19
#include "tref.h"
20

21
SSyncRaftEntry* syncEntryBuild(int32_t dataLen) {
3,149,382✔
22
  int32_t         bytes = sizeof(SSyncRaftEntry) + dataLen;
3,149,382✔
23
  SSyncRaftEntry* pEntry = taosMemoryCalloc(1, bytes);
3,149,382!
24
  if (pEntry == NULL) {
3,149,641!
25
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
26
    return NULL;
×
27
  }
28

29
  pEntry->bytes = bytes;
3,149,641✔
30
  pEntry->dataLen = dataLen;
3,149,641✔
31
  pEntry->rid = -1;
3,149,641✔
32

33
  return pEntry;
3,149,641✔
34
}
35

36
SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index, const STraceId *traceId) {
297,780✔
37
  SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen);
297,780✔
38
  if (pEntry == NULL) return NULL;
297,785!
39

40
  pEntry->msgType = pMsg->msgType;
297,785✔
41
  pEntry->originalRpcType = pMsg->originalRpcType;
297,785✔
42
  pEntry->originRpcTraceId = *traceId;
297,785✔
43
  pEntry->seqNum = pMsg->seqNum;
297,785✔
44
  pEntry->isWeak = pMsg->isWeak;
297,785✔
45
  pEntry->term = term;
297,785✔
46
  pEntry->index = index;
297,785✔
47
  memcpy(pEntry->data, pMsg->data, pMsg->dataLen);
297,785✔
48

49
  return pEntry;
297,785✔
50
}
51

52
SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index) {
2,102,272✔
53
  SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->contLen);
2,102,272✔
54
  if (pEntry == NULL) return NULL;
2,102,603!
55

56
  pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
2,102,603✔
57
  pEntry->originalRpcType = pMsg->msgType;
2,102,603✔
58
  pEntry->originRpcTraceId = pMsg->info.traceId;
2,102,603✔
59
  pEntry->seqNum = 0;
2,102,603✔
60
  pEntry->isWeak = 0;
2,102,603✔
61
  pEntry->term = term;
2,102,603✔
62
  pEntry->index = index;
2,102,603✔
63
  memcpy(pEntry->data, pMsg->pCont, pMsg->contLen);
2,102,603✔
64

65
  return pEntry;
2,102,603✔
66
}
67

68
SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg) {
474,598✔
69
  SSyncRaftEntry* pEntry = taosMemoryMalloc(pMsg->dataLen);
474,598!
70
  if (pEntry == NULL) {
474,600!
71
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
72
    return NULL;
×
73
  }
74
  memcpy(pEntry, pMsg->data, pMsg->dataLen);
474,600✔
75
  if (pEntry->bytes != pMsg->dataLen) {
474,600!
76
    terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
×
77
    return NULL;
×
78
  }
79
  return pEntry;
474,600✔
80
}
81

82
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) {
29,160✔
83
  SSyncRaftEntry* pEntry = syncEntryBuild(sizeof(SMsgHead));
29,160✔
84
  if (pEntry == NULL) return NULL;
29,161!
85

86
  pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
29,161✔
87
  pEntry->originalRpcType = TDMT_SYNC_NOOP;
29,161✔
88
  pEntry->seqNum = 0;
29,161✔
89
  pEntry->isWeak = 0;
29,161✔
90
  pEntry->term = term;
29,161✔
91
  pEntry->index = index;
29,161✔
92

93
  SMsgHead* pHead = (SMsgHead*)pEntry->data;
29,161✔
94
  pHead->vgId = vgId;
29,161✔
95
  pHead->contLen = sizeof(SMsgHead);
29,161✔
96

97
  return pEntry;
29,161✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
7,213,809✔
101
  if (pEntry != NULL) {
7,213,809✔
102
    sTrace("free entry:%p", pEntry);
3,614,965✔
103
    taosMemoryFree(pEntry);
3,614,965!
104
  }
105
}
7,212,236✔
106

107
int32_t syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) {
1,180,472✔
108
  pRpcMsg->msgType = pEntry->originalRpcType;
1,180,472✔
109
  pRpcMsg->contLen = (int32_t)(pEntry->dataLen);
1,180,472✔
110
  pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
1,180,472✔
111
  if (pRpcMsg->pCont == NULL) {
1,180,469!
112
    return terrno;
×
113
  }
114
  memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen);
1,180,489✔
115

116
  return 0;
1,180,489✔
117
}
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