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

taosdata / TDengine / #3818

01 Apr 2025 07:46AM UTC coverage: 34.065% (-0.02%) from 34.08%
#3818

push

travis-ci

happyguoxy
test:alter gcda dir

148531 of 599532 branches covered (24.77%)

Branch coverage included in aggregate %.

222425 of 489446 relevant lines covered (45.44%)

762721.74 hits per line

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

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

29
  pEntry->bytes = bytes;
75,943✔
30
  pEntry->dataLen = dataLen;
75,943✔
31
  pEntry->rid = -1;
75,943✔
32

33
  return pEntry;
75,943✔
34
}
35

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

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

49
  return pEntry;
35,234✔
50
}
51

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

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

65
  return pEntry;
37,266✔
66
}
67

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

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

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

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

97
  return pEntry;
622✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
358,085✔
101
  if (pEntry != NULL) {
358,085✔
102
    sTrace("free entry:%p", pEntry);
142,036✔
103
    taosMemoryFree(pEntry);
142,036!
104
  }
105
}
358,071✔
106

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

116
  return 0;
104,272✔
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