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

taosdata / TDengine / #3831

02 Apr 2025 01:14AM UTC coverage: 34.081% (-0.02%) from 34.097%
#3831

push

travis-ci

happyguoxy
test:alter gcda dir

148596 of 599532 branches covered (24.79%)

Branch coverage included in aggregate %.

222550 of 489473 relevant lines covered (45.47%)

1589752.67 hits per line

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

80.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) {
229,983✔
22
  int32_t         bytes = sizeof(SSyncRaftEntry) + dataLen;
229,983✔
23
  SSyncRaftEntry* pEntry = taosMemoryCalloc(1, bytes);
229,983!
24
  if (pEntry == NULL) {
229,995!
25
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
26
    return NULL;
×
27
  }
28

29
  pEntry->bytes = bytes;
229,995✔
30
  pEntry->dataLen = dataLen;
229,995✔
31
  pEntry->rid = -1;
229,995✔
32

33
  return pEntry;
229,995✔
34
}
35

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

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

49
  return pEntry;
106,170✔
50
}
51

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

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

65
  return pEntry;
113,562✔
66
}
67

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

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

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

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

97
  return pEntry;
1,866✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
1,082,796✔
101
  if (pEntry != NULL) {
1,082,796✔
102
    sTrace("free entry:%p", pEntry);
429,357✔
103
    taosMemoryFree(pEntry);
429,357!
104
  }
105
}
1,082,796✔
106

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

116
  return 0;
314,175✔
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