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

taosdata / TDengine / #3527

12 Nov 2024 08:50PM UTC coverage: 60.819% (+0.6%) from 60.225%
#3527

push

travis-ci

GitHub
Merge pull request #28730 from taosdata/doc/analysis

118574 of 249004 branches covered (47.62%)

Branch coverage included in aggregate %.

199137 of 273386 relevant lines covered (72.84%)

15792295.89 hits per line

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

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

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

33
  return pEntry;
13,252,829✔
34
}
35

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

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

48
  return pEntry;
247,999✔
49
}
50

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

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

63
  return pEntry;
10,117,634✔
64
}
65

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

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

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

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

95
  return pEntry;
28,672✔
96
}
97

98
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
36,725,780✔
99
  if (pEntry != NULL) {
36,725,780✔
100
    sTrace("free entry:%p", pEntry);
16,052,981✔
101
    taosMemoryFree(pEntry);
16,052,984✔
102
  }
103
}
36,724,613✔
104

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

114
  return 0;
3,333,458✔
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