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

taosdata / TDengine / #3531

19 Nov 2024 10:42AM UTC coverage: 60.213% (-0.006%) from 60.219%
#3531

push

travis-ci

web-flow
Merge pull request #28777 from taosdata/fix/3.0/TD-32366

fix:TD-32366/stmt add geometry datatype check

118529 of 252344 branches covered (46.97%)

Branch coverage included in aggregate %.

7 of 48 new or added lines in 3 files covered. (14.58%)

2282 existing lines in 115 files now uncovered.

199096 of 275161 relevant lines covered (72.36%)

6067577.83 hits per line

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

79.09
/source/libs/sync/src/syncReplication.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 "syncReplication.h"
18
#include "syncIndexMgr.h"
19
#include "syncPipeline.h"
20
#include "syncRaftEntry.h"
21
#include "syncRaftStore.h"
22
#include "syncUtil.h"
23

24
// TLA+ Spec
25
// AppendEntries(i, j) ==
26
//    /\ i /= j
27
//    /\ state[i] = Leader
28
//    /\ LET prevLogIndex == nextIndex[i][j] - 1
29
//           prevLogTerm == IF prevLogIndex > 0 THEN
30
//                              log[i][prevLogIndex].term
31
//                          ELSE
32
//                              0
33
//           \* Send up to 1 entry, constrained by the end of the log.
34
//           lastEntry == Min({Len(log[i]), nextIndex[i][j]})
35
//           entries == SubSeq(log[i], nextIndex[i][j], lastEntry)
36
//       IN Send([mtype          |-> AppendEntriesRequest,
37
//                mterm          |-> currentTerm[i],
38
//                mprevLogIndex  |-> prevLogIndex,
39
//                mprevLogTerm   |-> prevLogTerm,
40
//                mentries       |-> entries,
41
//                \* mlog is used as a history variable for the proof.
42
//                \* It would not exist in a real implementation.
43
//                mlog           |-> log[i],
44
//                mcommitIndex   |-> Min({commitIndex[i], lastEntry}),
45
//                msource        |-> i,
46
//                mdest          |-> j])
47
//    /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
48

49
int32_t syncNodeReplicateReset(SSyncNode* pNode, SRaftId* pDestId) {
85✔
50
  SSyncLogBuffer* pBuf = pNode->pLogBuf;
85✔
51
  (void)taosThreadMutexLock(&pBuf->mutex);
85✔
52
  SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(pNode, pDestId);
85✔
53
  syncLogReplReset(pMgr);
85✔
54
  (void)taosThreadMutexUnlock(&pBuf->mutex);
85✔
55

56
  TAOS_RETURN(TSDB_CODE_SUCCESS);
85✔
57
}
58

59
int32_t syncNodeReplicate(SSyncNode* pNode) {
44,994✔
60
  SSyncLogBuffer* pBuf = pNode->pLogBuf;
44,994✔
61
  (void)taosThreadMutexLock(&pBuf->mutex);
44,994✔
62
  int32_t ret = syncNodeReplicateWithoutLock(pNode);
45,098✔
63
  (void)taosThreadMutexUnlock(&pBuf->mutex);
45,059✔
64

65
  TAOS_RETURN(ret);
45,094✔
66
}
67

68
int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
2,361,759✔
69
  if ((pNode->state != TAOS_SYNC_STATE_LEADER && pNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) ||
2,361,759!
70
      pNode->raftCfg.cfg.totalReplicaNum == 1) {
2,009,373✔
71
    TAOS_RETURN(TSDB_CODE_SUCCESS);
2,198,846✔
72
  }
73
  for (int32_t i = 0; i < pNode->totalReplicaNum; i++) {
647,587✔
74
    if (syncUtilSameId(&pNode->replicasId[i], &pNode->myRaftId)) {
484,669✔
75
      continue;
162,911✔
76
    }
77
    SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
321,756✔
78
    if (syncLogReplStart(pMgr, pNode) != 0) {
321,756✔
79
      sError("vgId:%d, failed to start log replication to dnode:%d", pNode->vgId, DID(&(pNode->replicasId[i])));
70!
80
    }
81
  }
82

83
  TAOS_RETURN(TSDB_CODE_SUCCESS);
162,918✔
84
}
85

86
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
366,848✔
87
  SyncAppendEntries* pMsg = pRpcMsg->pCont;
366,848✔
88
  pMsg->destId = *destRaftId;
366,848✔
89
  TAOS_CHECK_RETURN(syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg));
366,848!
90

91
  int32_t nRef = 0;
366,861✔
92
  if (pSyncNode != NULL) {
366,861!
93
    nRef = atomic_fetch_add_32(&pSyncNode->sendCount, 1);
366,861✔
94
    if (nRef <= 0) {
366,861✔
95
      sError("vgId:%d, send count is %d", pSyncNode->vgId, nRef);
1,132!
96
    }
97
  }
98

99
  SSyncLogReplMgr* mgr = syncNodeGetLogReplMgr(pSyncNode, (SRaftId*)destRaftId);
366,861✔
100
  if (mgr != NULL) {
366,860!
101
    nRef = atomic_fetch_add_32(&mgr->sendCount, 1);
366,860✔
102
    if (nRef <= 0) {
366,861✔
103
      sError("vgId:%d, send count is %d", pSyncNode->vgId, nRef);
2,173!
104
    }
105
  }
106

107
  TAOS_RETURN(TSDB_CODE_SUCCESS);
366,861✔
108
}
109

110
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcMsg* pMsg) {
44,562✔
111
  return syncNodeSendMsgById(destId, pSyncNode, pMsg);
44,562✔
112
}
113

114
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
11,941✔
115
  int64_t ts = taosGetTimestampMs();
11,941✔
116
  for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
14,039✔
117
    SRpcMsg rpcMsg = {0};
2,098✔
118
    if (syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId) != 0) {
2,098!
UNCOV
119
      sError("vgId:%d, build sync-heartbeat error", pSyncNode->vgId);
×
UNCOV
120
      continue;
×
121
    }
122

123
    SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
2,098✔
124
    pSyncMsg->srcId = pSyncNode->myRaftId;
2,098✔
125
    pSyncMsg->destId = pSyncNode->peersId[i];
2,098✔
126
    pSyncMsg->term = raftStoreGetTerm(pSyncNode);
2,098✔
127
    pSyncMsg->commitIndex = pSyncNode->commitIndex;
2,098✔
128
    pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
2,098✔
129
    pSyncMsg->privateTerm = 0;
2,098✔
130
    pSyncMsg->timeStamp = ts;
2,098✔
131

132
    // send msg
133
    TRACE_SET_MSGID(&(rpcMsg.info.traceId), tGenIdPI64());
2,098✔
134
    STraceId* trace = &(rpcMsg.info.traceId);
2,098✔
135
    sGTrace("vgId:%d, send sync-heartbeat to dnode:%d", pSyncNode->vgId, DID(&(pSyncMsg->destId)));
2,098!
136
    syncLogSendHeartbeat(pSyncNode, pSyncMsg, true, 0, 0);
2,098✔
137
    int32_t ret = syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg);
2,098✔
138
    if (ret != 0) {
2,098!
UNCOV
139
      sError("vgId:%d, failed to send sync-heartbeat since %s", pSyncNode->vgId, tstrerror(ret));
×
140
    }
141
  }
142

143
  TAOS_RETURN(TSDB_CODE_SUCCESS);
11,941✔
144
}
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