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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

14.53
/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

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

UNCOV
56
  TAOS_RETURN(TSDB_CODE_SUCCESS);
×
57
}
58

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

65
  TAOS_RETURN(ret);
2✔
66
}
67

68
int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
300✔
69
  if ((pNode->state != TAOS_SYNC_STATE_LEADER && pNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) ||
300!
70
      pNode->raftCfg.cfg.totalReplicaNum == 1) {
300!
71
    TAOS_RETURN(TSDB_CODE_SUCCESS);
300✔
72
  }
UNCOV
73
  for (int32_t i = 0; i < pNode->totalReplicaNum; i++) {
×
UNCOV
74
    if (syncUtilSameId(&pNode->replicasId[i], &pNode->myRaftId)) {
×
UNCOV
75
      continue;
×
76
    }
UNCOV
77
    SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
×
UNCOV
78
    int32_t          ret = 0;
×
UNCOV
79
    if ((ret = syncLogReplStart(pMgr, pNode)) != 0) {
×
UNCOV
80
      sWarn("vgId:%d, failed to start log replication to dnode:%d since %s", pNode->vgId, DID(&(pNode->replicasId[i])),
×
81
            tstrerror(ret));
82
    }
83
  }
84

UNCOV
85
  TAOS_RETURN(TSDB_CODE_SUCCESS);
×
86
}
87

UNCOV
88
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
×
UNCOV
89
  SyncAppendEntries* pMsg = pRpcMsg->pCont;
×
UNCOV
90
  pMsg->destId = *destRaftId;
×
UNCOV
91
  TAOS_CHECK_RETURN(syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg));
×
92

UNCOV
93
  int32_t nRef = 0;
×
UNCOV
94
  if (pSyncNode != NULL) {
×
UNCOV
95
    nRef = atomic_add_fetch_32(&pSyncNode->sendCount, 1);
×
UNCOV
96
    if (nRef <= 0) {
×
97
      sError("vgId:%d, send count is %d", pSyncNode->vgId, nRef);
×
98
    }
99
  }
100

UNCOV
101
  SSyncLogReplMgr* mgr = syncNodeGetLogReplMgr(pSyncNode, (SRaftId*)destRaftId);
×
UNCOV
102
  if (mgr != NULL) {
×
UNCOV
103
    nRef = atomic_add_fetch_32(&mgr->sendCount, 1);
×
UNCOV
104
    if (nRef <= 0) {
×
105
      sError("vgId:%d, send count is %d", pSyncNode->vgId, nRef);
×
106
    }
107
  }
108

UNCOV
109
  TAOS_RETURN(TSDB_CODE_SUCCESS);
×
110
}
111

UNCOV
112
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcMsg* pMsg) {
×
UNCOV
113
  SRaftId destIdTmp = *destId;
×
UNCOV
114
  TAOS_CHECK_RETURN(syncNodeSendMsgById(destId, pSyncNode, pMsg));
×
115

UNCOV
116
  int64_t tsMs = taosGetTimestampMs();
×
UNCOV
117
  syncIndexMgrSetSentTime(pSyncNode->pMatchIndex, &destIdTmp, tsMs);
×
118

UNCOV
119
  return TSDB_CODE_SUCCESS;
×
120
}
121

122
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
28✔
123
  int64_t ts = taosGetTimestampMs();
28✔
124
  for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
28!
UNCOV
125
    SRpcMsg rpcMsg = {0};
×
UNCOV
126
    if (syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId) != 0) {
×
127
      sError("vgId:%d, build sync-heartbeat error", pSyncNode->vgId);
×
128
      continue;
×
129
    }
130

UNCOV
131
    SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
×
UNCOV
132
    pSyncMsg->srcId = pSyncNode->myRaftId;
×
UNCOV
133
    pSyncMsg->destId = pSyncNode->peersId[i];
×
UNCOV
134
    pSyncMsg->term = raftStoreGetTerm(pSyncNode);
×
UNCOV
135
    pSyncMsg->commitIndex = pSyncNode->commitIndex;
×
UNCOV
136
    pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
×
UNCOV
137
    pSyncMsg->privateTerm = 0;
×
UNCOV
138
    pSyncMsg->timeStamp = ts;
×
139

140
    // send msg
UNCOV
141
    TRACE_SET_MSGID(&(rpcMsg.info.traceId), tGenIdPI64());
×
UNCOV
142
    STraceId* trace = &(rpcMsg.info.traceId);
×
UNCOV
143
    sGTrace("vgId:%d, send sync-heartbeat to dnode:%d", pSyncNode->vgId, DID(&(pSyncMsg->destId)));
×
UNCOV
144
    syncLogSendHeartbeat(pSyncNode, pSyncMsg, true, 0, 0);
×
UNCOV
145
    int32_t ret = syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg);
×
UNCOV
146
    if (ret != 0) {
×
147
      sError("vgId:%d, failed to send sync-heartbeat since %s", pSyncNode->vgId, tstrerror(ret));
×
148
    }
149
  }
150

151
  TAOS_RETURN(TSDB_CODE_SUCCESS);
28✔
152
}
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