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

taosdata / TDengine / #4949

05 Feb 2026 06:58AM UTC coverage: 66.973% (+0.1%) from 66.866%
#4949

push

travis-ci

web-flow
enh: [6690002267] Enh virtual super table scan. (#34481)

50 of 59 new or added lines in 3 files covered. (84.75%)

3548 existing lines in 127 files now uncovered.

205730 of 307182 relevant lines covered (66.97%)

125825389.62 hits per line

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

76.62
/source/dnode/vnode/src/tsdb/tsdbRetentionMonitor.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
#include "tsdb.h"
17
#include "tsdbInt.h"
18
#include "vnd.h"
19

20
bool tsdbRetentionMonHasTask(STsdb *tsdb) { return (TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr) > 0); }
×
21

22
int32_t tsdbOpenRetentionMonitor(STsdb *tsdb) {
3,768,243✔
23
  tsdb->pRetentionMonitor = (SRetentionMonitor *)taosMemoryCalloc(1, sizeof(SRetentionMonitor));
3,768,243✔
24
  if (tsdb->pRetentionMonitor == NULL) {
3,789,753✔
25
    return TSDB_CODE_OUT_OF_MEMORY;
×
26
  }
27
  return 0;
3,789,753✔
28
}
29

30
void tsdbCloseRetentionMonitor(STsdb *tsdb) {
3,789,201✔
31
  if (tsdb->pRetentionMonitor) {
3,789,201✔
32
    TARRAY2_DESTROY(&tsdb->pRetentionMonitor->stateArr, NULL);
3,789,201✔
33
    taosMemoryFreeClear(tsdb->pRetentionMonitor);
3,789,201✔
34
  }
35
}
3,789,534✔
36

37
int32_t tsdbAddRetentionMonitorTask(STsdb *tsdb, int32_t fid, SVATaskID *taskId, int64_t fileSize) {
121,393✔
38
  if (TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr) == 0) {
121,393✔
39
    tsdb->pRetentionMonitor->startTimeSec = taosGetTimestampSec();
40,436✔
40
    tsdb->pRetentionMonitor->totalTasks = 0;
40,436✔
41
    tsdb->pRetentionMonitor->totalSize = 0;
40,436✔
42
    tsdb->pRetentionMonitor->finishedSize = 0;
40,436✔
43
    tsdb->pRetentionMonitor->lastUpdateFinishedSizeTime = tsdb->pRetentionMonitor->startTimeSec;
40,436✔
44
    tsdb->pRetentionMonitor->killed = 0;
40,436✔
45
  }
46

47
  SRetentionState state = {
121,393✔
48
      .fid = fid,
49
      .taskId = *taskId,
50
      .fileSize = fileSize,
51
  };
52

53
  int32_t code = TARRAY2_APPEND(&tsdb->pRetentionMonitor->stateArr, state);
121,393✔
54
  if (code) return code;
121,393✔
55
  tsdb->pRetentionMonitor->totalTasks++;
121,393✔
56
  tsdb->pRetentionMonitor->totalSize += fileSize;
121,393✔
57
  tsdbDebug("vid:%d, fid:%d, taskId:%" PRId64 " is added to retention monitor, number of tasks:%d", TD_VID(tsdb->pVnode),
121,393✔
58
            fid, taskId->id, TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr));
59
  return 0;
121,133✔
60
}
61

62
int32_t tsdbUpdateRetentionMonitorTask(STsdb *tsdb, int32_t fid, SVATaskID *taskId, int64_t fileSize) {
×
63
  for (int32_t i = 0; i < TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr); i++) {
×
64
    SRetentionState *state = TARRAY2_GET_PTR(&tsdb->pRetentionMonitor->stateArr, i);
×
65
    if (state->fid == fid) {
×
66
      tsdb->pRetentionMonitor->totalSize -= state->fileSize;
×
67
      tsdb->pRetentionMonitor->totalSize += fileSize;
×
68
      state->fileSize = fileSize;
×
69
      tsdbDebug("vid:%d, fid:%d, taskId:%" PRId64 " is updated in retention monitor, number of tasks:%d",
×
70
                TD_VID(tsdb->pVnode), fid, taskId->id, TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr));
71
      return 0;
×
72
    }
73
  }
74
  return 0;
×
75
}
76

77
void tsdbRemoveRetentionMonitorTask(STsdb *tsdb, SVATaskID *taskId) {
121,393✔
78
  (void)taosThreadMutexLock(&tsdb->mutex);
121,393✔
79

80
  for (int32_t i = 0; i < TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr); i++) {
121,393✔
81
    SRetentionState *state = TARRAY2_GET_PTR(&tsdb->pRetentionMonitor->stateArr, i);
121,393✔
82
    if (state->taskId.async == taskId->async && state->taskId.id == taskId->id) {
121,393✔
83
      tsdbInfo("vid:%d, fid:%d, taskId:%" PRId64 " is removed from retention monitor, number of tasks:%d",
121,393✔
84
               TD_VID(tsdb->pVnode), state->fid, taskId->id, TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr));
85
      tsdb->pRetentionMonitor->finishedSize += state->fileSize;
121,393✔
86
      tsdb->pRetentionMonitor->lastUpdateFinishedSizeTime = taosGetTimestampSec();
121,393✔
87
      TARRAY2_REMOVE(&tsdb->pRetentionMonitor->stateArr, i, NULL);
121,393✔
88
      break;
121,393✔
89
    }
90
  }
91

92
  (void)taosThreadMutexUnlock(&tsdb->mutex);
121,393✔
93
}
121,393✔
94

95
void tsdbStopAllRetentionTask(STsdb *tsdb) {
3,815,286✔
96
  int32_t i;
97

98
  (void)taosThreadMutexLock(&tsdb->mutex);
3,815,286✔
99

100
  if (tsdb->pRetentionMonitor == NULL) {
3,818,249✔
101
    (void)taosThreadMutexUnlock(&tsdb->mutex);
×
102
    return;
×
103
  }
104

105
  atomic_store_8(&tsdb->pRetentionMonitor->killed, 1);
3,818,088✔
106

107
  i = 0;
3,817,752✔
108
  while (i < TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr)) {
3,817,752✔
UNCOV
109
    SRetentionState *state = TARRAY2_GET_PTR(&tsdb->pRetentionMonitor->stateArr, i);
×
UNCOV
110
    if (vnodeACancel(&state->taskId) == 0) {
×
111
      TARRAY2_REMOVE(&tsdb->pRetentionMonitor->stateArr, i, NULL);
×
112
    } else {
UNCOV
113
      i++;
×
114
    }
115
  }
116

117
  (void)taosThreadMutexUnlock(&tsdb->mutex);
3,817,248✔
118
  return;
3,817,960✔
119
}
120

121
int32_t tsdbRetentionMonitorGetInfo(STsdb *tsdb, SQueryCompactProgressRsp *rsp) {
108,748✔
122
  (void)taosThreadMutexLock(&tsdb->mutex);
108,748✔
123
  rsp->compactId = 0;  // TODO
109,840✔
124
  rsp->vgId = TD_VID(tsdb->pVnode);
109,840✔
125
  rsp->numberFileset = tsdb->pRetentionMonitor->totalTasks;
109,840✔
126
  rsp->finished = rsp->numberFileset - TARRAY2_SIZE(&tsdb->pRetentionMonitor->stateArr);
109,840✔
127
  // calculate progress
128
  if (tsdb->pRetentionMonitor->totalSize > 0) {
109,318✔
129
    rsp->progress = tsdb->pRetentionMonitor->finishedSize * 100 / tsdb->pRetentionMonitor->totalSize;
68,682✔
130
  } else {
131
    rsp->progress = 0;
40,636✔
132
  }
133
  // calculate estimated remaining time
134
  int64_t elapsed = tsdb->pRetentionMonitor->lastUpdateFinishedSizeTime - tsdb->pRetentionMonitor->startTimeSec;
109,318✔
135
  if (rsp->progress > 0 && elapsed > 0) {
109,840✔
136
    rsp->remainingTime = elapsed * (100 - rsp->progress) / rsp->progress;
694✔
137
  } else {
138
    rsp->remainingTime = tsdb->pRetentionMonitor->totalSize / (20 * 1024 * 1024);  // suppose 20MB/s
109,146✔
139
  }
140
  (void)taosThreadMutexUnlock(&tsdb->mutex);
109,318✔
141
  return 0;
109,840✔
142
}
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