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

taosdata / TDengine / #4113

17 May 2025 06:43AM UTC coverage: 62.054% (-0.8%) from 62.857%
#4113

push

travis-ci

web-flow
Merge pull request #31115 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

154737 of 318088 branches covered (48.65%)

Branch coverage included in aggregate %.

175 of 225 new or added lines in 20 files covered. (77.78%)

5853 existing lines in 216 files now uncovered.

239453 of 317147 relevant lines covered (75.5%)

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

29
  pEntry->bytes = bytes;
12,302,912✔
30
  pEntry->dataLen = dataLen;
12,302,912✔
31
  pEntry->rid = -1;
12,302,912✔
32

33
  return pEntry;
12,302,912✔
34
}
35

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

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

49
  return pEntry;
245,444✔
50
}
51

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

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

65
  return pEntry;
10,434,554✔
66
}
67

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

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

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

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

97
  return pEntry;
28,820✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
28,785,724✔
101
  if (pEntry != NULL) {
28,785,724✔
102
    sTrace("free entry:%p", pEntry);
13,605,321✔
103
    taosMemoryFree(pEntry);
13,605,322!
104
  }
105
}
28,783,974✔
106

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

116
  return 0;
1,893,749✔
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