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

taosdata / TDengine / #4905

29 Dec 2025 02:08PM UTC coverage: 65.423% (-0.3%) from 65.734%
#4905

push

travis-ci

web-flow
enh: sign connect request (#34067)

23 of 29 new or added lines in 4 files covered. (79.31%)

11614 existing lines in 186 files now uncovered.

193476 of 295730 relevant lines covered (65.42%)

115752566.53 hits per line

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

75.0
/source/dnode/mnode/impl/src/mndRetentionDetail.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
#include "mndRetentionDetail.h"
16
#include "mndCompactDetail.h"
17
#include "mndDb.h"
18
#include "mndShow.h"
19
#include "mndTrans.h"
20

21
#define MND_RETENTION_DETAIL_VER_NUMBER 1
22

23
static int32_t mndRetrieveRetentionDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
24
static void    mndCancelRetrieveRetentionDetail(SMnode *pMnode, void *pIter);
25

26
int32_t mndInitRetentionDetail(SMnode *pMnode) {
385,708✔
27
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_RETENTION_DETAIL, mndRetrieveRetentionDetail);
385,708✔
28
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_RETENTION_DETAIL, mndCancelRetrieveRetentionDetail);
385,708✔
29

30
  SSdbTable table = {
385,708✔
31
      .sdbType = SDB_RETENTION_DETAIL,
32
      .keyType = SDB_KEY_INT64,
33
      .encodeFp = (SdbEncodeFp)mndRetentionDetailActionEncode,
34
      .decodeFp = (SdbDecodeFp)mndRetentionDetailActionDecode,
35
      .insertFp = (SdbInsertFp)mndRetentionDetailActionInsert,
36
      .updateFp = (SdbUpdateFp)mndRetentionDetailActionUpdate,
37
      .deleteFp = (SdbDeleteFp)mndRetentionDetailActionDelete,
38
  };
39

40
  return sdbSetTable(pMnode->pSdb, table);
385,708✔
41
}
42

43
void mndCleanupRetentionDetail(SMnode *pMnode) { mDebug("mnd retention detail cleanup"); }
385,645✔
44

45
int32_t mndRetrieveRetentionDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
2,112✔
46
  SMnode              *pMnode = pReq->info.node;
2,112✔
47
  SSdb                *pSdb = pMnode->pSdb;
2,112✔
48
  int32_t              numOfRows = 0;
2,112✔
49
  int32_t              code = 0, lino = 0;
2,112✔
50
  SRetentionDetailObj *pDetail = NULL;
2,112✔
51

52
  while (numOfRows < rows) {
6,336✔
53
    pShow->pIter = sdbFetch(pSdb, SDB_RETENTION_DETAIL, pShow->pIter, (void **)&pDetail);
6,336✔
54
    if (pShow->pIter == NULL) break;
6,336✔
55

56
    SColumnInfoData *pColInfo = NULL;
4,224✔
57
    int32_t          cols = 0;
4,224✔
58

59
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
60
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->id, false, pDetail, pShow->pIter, _exit);
4,224✔
61

62
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
63
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->vgId, false, pDetail, pShow->pIter, _exit);
4,224✔
64

65
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
66
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->dnodeId, false, pDetail, pShow->pIter, _exit);
4,224✔
67

68
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
69
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->numberFileset, false, pDetail, pShow->pIter, _exit);
4,224✔
70

71
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
72
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->finished, false, pDetail, pShow->pIter, _exit);
4,224✔
73

74
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
75
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->startTime, false, pDetail, pShow->pIter, _exit);
4,224✔
76

77
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
78
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->progress, false, pDetail, pShow->pIter, _exit);
4,224✔
79

80
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
4,224✔
81
    COL_DATA_SET_VAL_GOTO((const char *)&pDetail->remainingTime, false, pDetail, pShow->pIter, _exit);
4,224✔
82

83
    numOfRows++;
4,224✔
84
    sdbRelease(pSdb, pDetail);
4,224✔
85
  }
86
_exit:
2,112✔
87
  pShow->numOfRows += numOfRows;
2,112✔
88
  return numOfRows;
2,112✔
89
}
90

UNCOV
91
static void mndCancelRetrieveRetentionDetail(SMnode *pMnode, void *pIter) {
×
UNCOV
92
  SSdb *pSdb = pMnode->pSdb;
×
UNCOV
93
  sdbCancelFetchByType(pSdb, pIter, SDB_RETENTION_DETAIL);
×
UNCOV
94
}
×
95

96
void tFreeRetentionDetailObj(SRetentionDetailObj *pObj) {}
74,368✔
97

98
SSdbRaw *mndRetentionDetailActionEncode(SRetentionDetailObj *pObj) {
77,200✔
99
  int32_t code = 0;
77,200✔
100
  int32_t lino = 0;
77,200✔
101
  terrno = TSDB_CODE_SUCCESS;
77,200✔
102

103
  void    *buf = NULL;
77,200✔
104
  SSdbRaw *pRaw = NULL;
77,200✔
105

106
  int32_t tlen = tSerializeSCompactDetailObj(NULL, 0, pObj);
77,200✔
107
  if (tlen < 0) {
77,200✔
UNCOV
108
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
109
    goto OVER;
×
110
  }
111

112
  int32_t size = sizeof(int32_t) + tlen;
77,200✔
113
  pRaw = sdbAllocRaw(SDB_RETENTION_DETAIL, MND_RETENTION_DETAIL_VER_NUMBER, size);
77,200✔
114
  if (pRaw == NULL) {
77,200✔
UNCOV
115
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
116
    goto OVER;
×
117
  }
118

119
  buf = taosMemoryMalloc(tlen);
77,200✔
120
  if (buf == NULL) {
77,200✔
UNCOV
121
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
122
    goto OVER;
×
123
  }
124

125
  tlen = tSerializeSCompactDetailObj(buf, tlen, pObj);
77,200✔
126
  if (tlen < 0) {
77,200✔
UNCOV
127
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
128
    goto OVER;
×
129
  }
130

131
  int32_t dataPos = 0;
77,200✔
132
  SDB_SET_INT32(pRaw, dataPos, tlen, OVER);
77,200✔
133
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER);
77,200✔
134
  SDB_SET_DATALEN(pRaw, dataPos, OVER);
77,200✔
135

136
OVER:
77,200✔
137
  taosMemoryFreeClear(buf);
77,200✔
138
  if (terrno != TSDB_CODE_SUCCESS) {
77,200✔
UNCOV
139
    mError("retention detail:%" PRId32 ", failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
×
UNCOV
140
    sdbFreeRaw(pRaw);
×
UNCOV
141
    return NULL;
×
142
  }
143

144
  mTrace("retention detail:%" PRId32 ", encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
77,200✔
145
  return pRaw;
77,200✔
146
}
147

148
SSdbRow *mndRetentionDetailActionDecode(SSdbRaw *pRaw) {
74,368✔
149
  int32_t              code = 0;
74,368✔
150
  int32_t              lino = 0;
74,368✔
151
  SSdbRow             *pRow = NULL;
74,368✔
152
  SRetentionDetailObj *pObj = NULL;
74,368✔
153
  void                *buf = NULL;
74,368✔
154
  terrno = TSDB_CODE_SUCCESS;
74,368✔
155

156
  int8_t sver = 0;
74,368✔
157
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
74,368✔
UNCOV
158
    goto OVER;
×
159
  }
160

161
  if (sver != MND_RETENTION_DETAIL_VER_NUMBER) {
74,368✔
UNCOV
162
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
UNCOV
163
    mError("retention detail read invalid ver, data ver: %d, curr ver: %d", sver, MND_RETENTION_DETAIL_VER_NUMBER);
×
UNCOV
164
    goto OVER;
×
165
  }
166

167
  pRow = sdbAllocRow(sizeof(SRetentionDetailObj));
74,368✔
168
  if (pRow == NULL) {
74,368✔
UNCOV
169
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
170
    goto OVER;
×
171
  }
172

173
  pObj = sdbGetRowObj(pRow);
74,368✔
174
  if (pObj == NULL) {
74,368✔
175
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
176
    goto OVER;
×
177
  }
178

179
  int32_t tlen;
74,368✔
180
  int32_t dataPos = 0;
74,368✔
181
  SDB_GET_INT32(pRaw, dataPos, &tlen, OVER);
74,368✔
182
  buf = taosMemoryMalloc(tlen + 1);
74,368✔
183
  if (buf == NULL) {
74,368✔
UNCOV
184
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
185
    goto OVER;
×
186
  }
187
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
74,368✔
188

189
  if ((terrno = tDeserializeSCompactDetailObj(buf, tlen, pObj)) < 0) {
74,368✔
UNCOV
190
    goto OVER;
×
191
  }
192

193
OVER:
74,368✔
194
  taosMemoryFreeClear(buf);
74,368✔
195
  if (terrno != TSDB_CODE_SUCCESS) {
74,368✔
UNCOV
196
    mError("retention detail:%" PRId32 ", failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
×
UNCOV
197
    taosMemoryFreeClear(pRow);
×
UNCOV
198
    return NULL;
×
199
  }
200

201
  mTrace("retention detail:%" PRId32 ", decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
74,368✔
202
  return pRow;
74,368✔
203
}
204

205
int32_t mndRetentionDetailActionInsert(SSdb *pSdb, SRetentionDetailObj *pObj) {
38,600✔
206
  mTrace("retention detail:%" PRId32 ", perform insert action", pObj->id);
38,600✔
207
  return 0;
38,600✔
208
}
209

210
int32_t mndRetentionDetailActionDelete(SSdb *pSdb, SRetentionDetailObj *pObj) {
74,368✔
211
  mTrace("retention detail:%" PRId32 ", perform insert action", pObj->id);
74,368✔
212
  tFreeRetentionDetailObj(pObj);
74,368✔
213
  return 0;
74,368✔
214
}
215

UNCOV
216
int32_t mndRetentionDetailActionUpdate(SSdb *pSdb, SRetentionDetailObj *pOldObj, SRetentionDetailObj *pNewObj) {
×
UNCOV
217
  mTrace("retention detail:%" PRId32 ", perform update action, old row:%p new row:%p", pOldObj->id, pOldObj, pNewObj);
×
218

UNCOV
219
  pOldObj->numberFileset = pNewObj->numberFileset;
×
UNCOV
220
  pOldObj->finished = pNewObj->finished;
×
221

UNCOV
222
  return 0;
×
223
}
224

225
int32_t mndAddRetentionDetailToTrans(SMnode *pMnode, STrans *pTrans, SRetentionObj *pObj, SVgObj *pVgroup,
38,600✔
226
                                     SVnodeGid *pVgid, int32_t index) {
227
  int32_t             code = 0;
38,600✔
228
  SRetentionDetailObj detail = {0};
38,600✔
229
  detail.detailId = index;
38,600✔
230
  detail.id = pObj->id;
38,600✔
231
  detail.vgId = pVgroup->vgId;
38,600✔
232
  detail.dnodeId = pVgid->dnodeId;
38,600✔
233
  detail.startTime = taosGetTimestampMs();
38,600✔
234
  detail.numberFileset = -1;
38,600✔
235
  detail.finished = -1;
38,600✔
236
  detail.newNumberFileset = -1;
38,600✔
237
  detail.newFinished = -1;
38,600✔
238

239
  mInfo("retention:%d, add retention detail to trans, index:%d, vgId:%d, dnodeId:%d", detail.id, detail.detailId,
38,600✔
240
        detail.vgId, detail.dnodeId);
241

242
  SSdbRaw *pVgRaw = mndRetentionDetailActionEncode(&detail);
38,600✔
243
  if (pVgRaw == NULL) return -1;
38,600✔
244
  if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) {
38,600✔
UNCOV
245
    sdbFreeRaw(pVgRaw);
×
UNCOV
246
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
UNCOV
247
    if (terrno != 0) code = terrno;
×
UNCOV
248
    TAOS_RETURN(code);
×
249
  }
250
  code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
38,600✔
251

252
  TAOS_RETURN(code);
38,600✔
253
}
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