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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

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

29
  pEntry->bytes = bytes;
13,319,825✔
30
  pEntry->dataLen = dataLen;
13,319,825✔
31
  pEntry->rid = -1;
13,319,825✔
32

33
  return pEntry;
13,319,825✔
34
}
35

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

40
  pEntry->msgType = pMsg->msgType;
202,403✔
41
  pEntry->originalRpcType = pMsg->originalRpcType;
202,403✔
42
  pEntry->seqNum = pMsg->seqNum;
202,403✔
43
  pEntry->isWeak = pMsg->isWeak;
202,403✔
44
  pEntry->term = term;
202,403✔
45
  pEntry->index = index;
202,403✔
46
  memcpy(pEntry->data, pMsg->data, pMsg->dataLen);
202,403✔
47

48
  return pEntry;
202,403✔
49
}
50

51
SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index) {
10,123,377✔
52
  SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->contLen);
10,123,377✔
53
  if (pEntry == NULL) return NULL;
10,123,481!
54

55
  pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
10,123,481✔
56
  pEntry->originalRpcType = pMsg->msgType;
10,123,481✔
57
  pEntry->seqNum = 0;
10,123,481✔
58
  pEntry->isWeak = 0;
10,123,481✔
59
  pEntry->term = term;
10,123,481✔
60
  pEntry->index = index;
10,123,481✔
61
  memcpy(pEntry->data, pMsg->pCont, pMsg->contLen);
10,123,481✔
62

63
  return pEntry;
10,123,481✔
64
}
65

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

80
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) {
24,683✔
81
  SSyncRaftEntry* pEntry = syncEntryBuild(sizeof(SMsgHead));
24,683✔
82
  if (pEntry == NULL) return NULL;
24,683!
83

84
  pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
24,683✔
85
  pEntry->originalRpcType = TDMT_SYNC_NOOP;
24,683✔
86
  pEntry->seqNum = 0;
24,683✔
87
  pEntry->isWeak = 0;
24,683✔
88
  pEntry->term = term;
24,683✔
89
  pEntry->index = index;
24,683✔
90

91
  SMsgHead* pHead = (SMsgHead*)pEntry->data;
24,683✔
92
  pHead->vgId = vgId;
24,683✔
93
  pHead->contLen = sizeof(SMsgHead);
24,683✔
94

95
  return pEntry;
24,683✔
96
}
97

98
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
36,954,853✔
99
  if (pEntry != NULL) {
36,954,853✔
100
    sTrace("free entry:%p", pEntry);
16,148,300✔
101
    taosMemoryFree(pEntry);
16,148,301✔
102
  }
103
}
36,954,669✔
104

105
int32_t syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) {
3,326,982✔
106
  pRpcMsg->msgType = pEntry->originalRpcType;
3,326,982✔
107
  pRpcMsg->contLen = (int32_t)(pEntry->dataLen);
3,326,982✔
108
  pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
3,326,982✔
109
  if (pRpcMsg->pCont == NULL) {
3,327,041!
110
    return terrno;
×
111
  }
112
  memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen);
3,327,089✔
113

114
  return 0;
3,327,089✔
115
}
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