• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

taosdata / TDengine / #5096

17 May 2026 01:15AM UTC coverage: 73.276% (-0.006%) from 73.282%
#5096

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281228 of 383795 relevant lines covered (73.28%)

132339998.33 hits per line

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

79.25
/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) {
8,037,184✔
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
}
8,037,184✔
57

58
static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
44,724,225✔
59
  ths->tmrRoutineNum++;
44,724,225✔
60

61
  sDebug("vgId:%d, timer routine, status report", ths->vgId);
44,725,398✔
62
  if (ths->tmrRoutineNum % (tsRoutineReportInterval / (ths->pingTimerMS / 1000)) == 0) {
44,725,398✔
63
    sNInfo(ths, "timer routines");
229,156✔
64
  } else {
65
    sNTrace(ths, "timer routines");
44,486,311✔
66
  }
67

68
  // timer replicate
69
  sDebug("vgId:%d, timer routine, node replicate", ths->vgId);
44,715,467✔
70
  int32_t ret = 0;
44,715,467✔
71
  if((ret = syncNodeReplicate(ths)) != 0){
44,715,467✔
72
    sWarn("vgId:%d, failed to replicate node since %s", ths->vgId, tstrerror(ret));
45,147✔
73
  }
74

75
  // clean mnode index
76
  sDebug("vgId:%d, timer routine, clean config index", ths->vgId);
44,719,419✔
77
  if (syncNodeIsMnode(ths)) {
44,719,419✔
78
    syncNodeCleanConfigIndex(ths);
8,037,184✔
79
  }
80

81
  sDebug("vgId:%d, timer routine, snapshot resend", ths->vgId);
44,720,381✔
82
  int64_t timeNow = taosGetTimestampMs();
44,714,871✔
83

84
  for (int i = 0; i < ths->peersNum; ++i) {
65,826,915✔
85
    SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(ths->peersId[i]));
21,112,291✔
86
    if (pSender != NULL) {
21,112,774✔
87
      if (ths->isStart && (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) &&
21,112,774✔
88
          pSender->start) {
6,678,995✔
89
        int64_t elapsedMs = timeNow - pSender->lastSendTime;
278✔
90
        if (elapsedMs < SYNC_SNAP_RESEND_MS) {
278✔
91
          continue;
278✔
92
        }
93

94
        if (elapsedMs > SYNC_SNAP_TIMEOUT_MS) {
×
95
          sSError(pSender, "snap replication timeout, terminate.");
×
96
          snapshotSenderStop(pSender, false);
×
97
        } else {
98
          sSWarn(pSender, "snap replication resend.");
×
99
          if((ret = snapshotReSend(pSender)) != 0){
×
100
            sWarn("vgId:%d, failed to snapshot resend in timer routine since %s", ths->vgId, tstrerror(ret));
×
101
          }
102
        }
103
      }
104
    }
105
  }
106

107
  sDebug("vgId:%d, timer routine, resp clean", ths->vgId);
44,718,599✔
108
  if (!syncNodeIsMnode(ths)) {
44,718,599✔
109
    syncRespClean(ths->pSyncRespMgr);
36,676,191✔
110
  }
111

112
  return 0;
44,718,863✔
113
}
114

115
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pRpc) {
45,341,070✔
116
  int32_t      ret = 0;
45,341,070✔
117
  SyncTimeout* pMsg = pRpc->pCont;
45,341,070✔
118

119
  syncLogRecvTimer(ths, pMsg, &pRpc->info.traceId);
45,343,202✔
120

121
  if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
45,331,693✔
122
    if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
44,726,409✔
123
      ++(ths->pingTimerCounter);
44,725,382✔
124

125
      TAOS_CHECK_RETURN(syncNodeTimerRoutine(ths));
44,725,000✔
126
    }
127

128
  } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
614,609✔
129
    if (atomic_load_64(&ths->electTimerLogicClock) <= pMsg->logicClock) {
614,609✔
130
      ++(ths->electTimerCounter);
612,274✔
131

132
      TAOS_CHECK_RETURN(syncNodeElect(ths));
612,274✔
133
    }
134

135
  } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) {
×
136
    if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) {
×
137
      ++(ths->heartbeatTimerCounter);
×
138
      sTrace("vgId:%d, sync timer, type:replicate count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId,
×
139
             ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser);
140
    }
141

142
  } else {
143
    sError("vgId:%d, recv unknown timer-type:%d", ths->vgId, pMsg->timeoutType);
×
144
  }
145

146
  return ret;
45,321,743✔
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc