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

taosdata / TDengine / #3911

24 Apr 2025 11:36PM UTC coverage: 53.735% (-1.6%) from 55.295%
#3911

push

travis-ci

happyguoxy
Sync branches at 2025-04-25 07:35

170049 of 316459 relevant lines covered (53.73%)

1192430.54 hits per line

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

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

29
  pEntry->bytes = bytes;
72,627✔
30
  pEntry->dataLen = dataLen;
72,627✔
31
  pEntry->rid = -1;
72,627✔
32

33
  return pEntry;
72,627✔
34
}
35

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

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

49
  return pEntry;
31,829✔
50
}
51

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

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

65
  return pEntry;
37,456✔
66
}
67

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

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

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

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

97
  return pEntry;
540✔
98
}
99

100
void syncEntryDestroy(SSyncRaftEntry* pEntry) {
333,006✔
101
  if (pEntry != NULL) {
333,006✔
102
    sTrace("free entry:%p", pEntry);
132,602✔
103
    taosMemoryFree(pEntry);
132,602✔
104
  }
105
}
333,005✔
106

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

116
  return 0;
94,647✔
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