• 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

30.69
/source/libs/sync/src/syncTimeout.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 "syncTimeout.h"
18
#include "syncElection.h"
19
#include "syncRaftCfg.h"
20
#include "syncRaftLog.h"
21
#include "syncReplication.h"
22
#include "syncRespMgr.h"
23
#include "syncSnapshot.h"
24
#include "syncUtil.h"
25

26
static void syncNodeCleanConfigIndex(SSyncNode* ths) {
2✔
27
#if 0
28
  int32_t   newArrIndex = 0;
29
  SyncIndex newConfigIndexArr[MAX_CONFIG_INDEX_COUNT] = {0};
30
  SSnapshot snapshot = {0};
31

32
  ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
33
  if (snapshot.lastApplyIndex != SYNC_INDEX_INVALID) {
34
    for (int32_t i = 0; i < ths->raftCfg.configIndexCount; ++i) {
35
      if (ths->raftCfg.configIndexArr[i] < snapshot.lastConfigIndex) {
36
        // pass
37
      } else {
38
        // save
39
        newConfigIndexArr[newArrIndex] = ths->raftCfg.configIndexArr[i];
40
        ++newArrIndex;
41
      }
42
    }
43

44
    int32_t oldCnt = ths->raftCfg.configIndexCount;
45
    ths->raftCfg.configIndexCount = newArrIndex;
46
    memcpy(ths->raftCfg.configIndexArr, newConfigIndexArr, sizeof(newConfigIndexArr));
47

48
    int32_t code = syncWriteCfgFile(ths);
49
    if (code != 0) {
50
      sNFatal(ths, "failed to persist cfg");
51
    } else {
52
      sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->raftCfg.configIndexCount);
53
    }
54
  }
55
#endif
56
}
2✔
57

58
static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
2✔
59
  ths->tmrRoutineNum++;
2✔
60

61
  if (ths->tmrRoutineNum % 60 == 0 && ths->totalReplicaNum > 1) {
2!
62
    sNInfo(ths, "timer routines");
×
63
  } else {
64
    sNTrace(ths, "timer routines");
2!
65
  }
66

67
  // timer replicate
68
  TAOS_CHECK_RETURN(syncNodeReplicate(ths));
2!
69

70
  // clean mnode index
71
  if (syncNodeIsMnode(ths)) {
2!
72
    syncNodeCleanConfigIndex(ths);
2✔
73
  }
74

75
  int64_t timeNow = taosGetTimestampMs();
2✔
76

77
  for (int i = 0; i < ths->peersNum; ++i) {
2!
UNCOV
78
    SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(ths->peersId[i]));
×
UNCOV
79
    if (pSender != NULL) {
×
UNCOV
80
      if (ths->isStart && (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) &&
×
UNCOV
81
          pSender->start) {
×
UNCOV
82
        int64_t elapsedMs = timeNow - pSender->lastSendTime;
×
UNCOV
83
        if (elapsedMs < SYNC_SNAP_RESEND_MS) {
×
UNCOV
84
          continue;
×
85
        }
86

87
        if (elapsedMs > SYNC_SNAP_TIMEOUT_MS) {
×
88
          sSError(pSender, "snap replication timeout, terminate.");
×
89
          snapshotSenderStop(pSender, false);
×
90
        } else {
91
          sSWarn(pSender, "snap replication resend.");
×
92
          TAOS_CHECK_RETURN(snapshotReSend(pSender));
×
93
        }
94
      }
95
    }
96
  }
97

98
  if (!syncNodeIsMnode(ths)) {
2!
UNCOV
99
    syncRespClean(ths->pSyncRespMgr);
×
100
  }
101

102
  return 0;
2✔
103
}
104

105
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pRpc) {
2✔
106
  int32_t      ret = 0;
2✔
107
  SyncTimeout* pMsg = pRpc->pCont;
2✔
108

109
  syncLogRecvTimer(ths, pMsg, "");
2✔
110

111
  if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
2!
112
    if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
2!
113
      ++(ths->pingTimerCounter);
2✔
114

115
      TAOS_CHECK_RETURN(syncNodeTimerRoutine(ths));
2!
116
    }
117

UNCOV
118
  } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
×
UNCOV
119
    if (atomic_load_64(&ths->electTimerLogicClock) <= pMsg->logicClock) {
×
UNCOV
120
      ++(ths->electTimerCounter);
×
121

UNCOV
122
      TAOS_CHECK_RETURN(syncNodeElect(ths));
×
123
    }
124

125
  } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) {
×
126
    if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) {
×
127
      ++(ths->heartbeatTimerCounter);
×
128
      sTrace("vgId:%d, sync timer, type:replicate count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId,
×
129
             ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser);
130
    }
131

132
  } else {
133
    sError("vgId:%d, recv unknown timer-type:%d", ths->vgId, pMsg->timeoutType);
×
134
  }
135

136
  return ret;
2✔
137
}
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