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

taosdata / TDengine / #4143

24 May 2025 03:30AM UTC coverage: 32.868% (-29.4%) from 62.238%
#4143

push

travis-ci

web-flow
test: migrate stream cases (#31164)

76401 of 312956 branches covered (24.41%)

Branch coverage included in aggregate %.

128686 of 311012 relevant lines covered (41.38%)

579734.08 hits per line

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

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

29
  pEntry->bytes = bytes;
26,734✔
30
  pEntry->dataLen = dataLen;
26,734✔
31
  pEntry->rid = -1;
26,734✔
32

33
  return pEntry;
26,734✔
34
}
35

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

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

49
  return pEntry;
472✔
50
}
51

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

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

65
  return pEntry;
26,111✔
66
}
67

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

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

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

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

97
  return pEntry;
136✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
53,506✔
101
  if (pEntry != NULL) {
53,506✔
102
    sTrace("free entry:%p", pEntry);
26,734!
103
    taosMemoryFree(pEntry);
26,734!
104
  }
105
}
53,506✔
106

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

116
  return 0;
540✔
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