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

taosdata / TDengine / #3655

14 Mar 2025 08:10AM UTC coverage: 59.532% (+22.6%) from 36.951%
#3655

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.

139898 of 302527 branches covered (46.24%)

Branch coverage included in aggregate %.

71 of 99 new or added lines in 12 files covered. (71.72%)

2746 existing lines in 57 files now uncovered.

220499 of 302857 relevant lines covered (72.81%)

5509252.7 hits per line

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

68.8
/source/dnode/mgmt/mgmt_vnode/src/vmWorker.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 "vmInt.h"
18
#include "vnodeInt.h"
19

20
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
362,944✔
21
  if (pMsg->info.handle == NULL) return;
362,944✔
22
  SRpcMsg rsp = {
362,878✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
362,878✔
25
      .contLen = pMsg->info.rspLen,
362,878✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
362,878✔
29
}
30

31
static void vmProcessMultiMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
8,559✔
32
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
8,559✔
33
  int32_t         code = -1;
8,559✔
34
  const STraceId *trace = &pMsg->info.traceId;
8,559✔
35

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
8,559!
37
  switch (pMsg->msgType) {
8,559!
38
    case TDMT_DND_CREATE_VNODE:
8,719✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
8,719✔
40
      break;
8,724✔
41
  }
42

43
  if (IsReq(pMsg)) {
8,564!
44
    if (code != 0) {
8,724!
45
      if (terrno != 0) code = terrno;
×
46
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
×
47
    }
48
    vmSendRsp(pMsg, code);
8,724✔
49
  }
50

51
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
8,564!
52
  rpcFreeCont(pMsg->pCont);
8,564✔
53
  taosFreeQitem(pMsg);
8,724✔
54
}
8,724✔
55

56
static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
8,407✔
57
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
8,407✔
58
  int32_t         code = -1;
8,407✔
59
  const STraceId *trace = &pMsg->info.traceId;
8,407✔
60

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
8,407!
62
  switch (pMsg->msgType) {
8,407!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
3,433✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
3,433✔
68
      break;
3,433✔
69
    case TDMT_VND_ALTER_REPLICA:
1,073✔
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
1,073✔
71
      break;
1,073✔
72
    case TDMT_VND_DISABLE_WRITE:
30✔
73
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
30✔
74
      break;
30✔
75
    case TDMT_VND_ALTER_HASHRANGE:
30✔
76
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
30✔
77
      break;
30✔
78
    case TDMT_DND_ALTER_VNODE_TYPE:
3,745✔
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
3,745✔
80
      break;
3,745✔
81
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
82
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
83
      break;
×
84
    case TDMT_VND_ARB_HEARTBEAT:
96✔
85
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
96✔
86
      break;
96✔
87
    default:
×
88
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
89
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
90
  }
91

92
  if (IsReq(pMsg)) {
8,407!
93
    if (code != 0) {
8,407✔
94
      if (terrno != 0) code = terrno;
3,588!
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
3,588!
96
    }
97
    vmSendRsp(pMsg, code);
8,407✔
98
  }
99

100
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
8,407!
101
  rpcFreeCont(pMsg->pCont);
8,407✔
102
  taosFreeQitem(pMsg);
8,407✔
103
}
8,407✔
104

105
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
5,077,465✔
106
  SVnodeObj      *pVnode = pInfo->ahandle;
5,077,465✔
107
  const STraceId *trace = &pMsg->info.traceId;
5,077,465✔
108

109
  dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
5,077,465!
110
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
5,077,465✔
111
  if (code != 0) {
5,076,836✔
112
    if (terrno != 0) code = terrno;
345,155✔
113
    dGError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
345,154!
114
    vmSendRsp(pMsg, code);
345,157✔
115
  }
116

117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
5,076,828!
118
  rpcFreeCont(pMsg->pCont);
5,076,828✔
119
  taosFreeQitem(pMsg);
5,077,420✔
120
}
5,077,429✔
121

122
static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
114,537✔
123
#ifdef USE_STREAM
124
  SVnodeObj      *pVnode = pInfo->ahandle;
114,537✔
125
  const STraceId *trace = &pMsg->info.traceId;
114,537✔
126

127
  dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
114,537!
128
  int32_t code = vnodeProcessStreamMsg(pVnode->pImpl, pMsg, pInfo);
114,537✔
129
  if (code != 0) {
114,539✔
130
    terrno = code;
1✔
131
    dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
1!
132
            tstrerror(code));
133
    vmSendRsp(pMsg, code);
1✔
134
  }
135

136
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
114,539!
137
  rpcFreeCont(pMsg->pCont);
114,539✔
138
  taosFreeQitem(pMsg);
114,539✔
139
#endif
140
}
114,539✔
141

142
static void vmProcessStreamCtrlQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
61,448✔
143
#ifdef USE_STREAM
144
  SVnodeObj *pVnode = pInfo->ahandle;
61,448✔
145
  void      *pItem = NULL;
61,448✔
146
  int32_t    code = 0;
61,448✔
147

148
  while (1) {
82,665✔
149
    if (taosGetQitem(pQall, &pItem) == 0) {
144,113✔
150
      break;
61,448✔
151
    }
152

153
    SRpcMsg        *pMsg = pItem;
82,665✔
154
    const STraceId *trace = &pMsg->info.traceId;
82,665✔
155

156
    dGTrace("vgId:%d, msg:%p get from vnode-stream-ctrl queue", pVnode->vgId, pMsg);
82,665!
157
    code = vnodeProcessStreamCtrlMsg(pVnode->pImpl, pMsg, pInfo);
82,665✔
158
    if (code != 0) {
82,665✔
159
      terrno = code;
53✔
160
      dGError("vgId:%d, msg:%p failed to process stream ctrl msg %s since %s", pVnode->vgId, pMsg,
53!
161
              TMSG_INFO(pMsg->msgType), tstrerror(code));
162
      vmSendRsp(pMsg, code);
53✔
163
    }
164

165
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
82,665!
166
    rpcFreeCont(pMsg->pCont);
82,665✔
167
    taosFreeQitem(pMsg);
82,665✔
168
  }
169
#endif
170
}
61,448✔
171

172
static void vmProcessStreamChkptQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
5,042✔
173
  SVnodeObj *pVnode = pInfo->ahandle;
5,042✔
174
  void      *pItem = NULL;
5,042✔
175
  int32_t    code = 0;
5,042✔
176

177
  while (1) {
5,642✔
178
    if (taosGetQitem(pQall, &pItem) == 0) {
10,684✔
179
      break;
5,042✔
180
    }
181

182
    SRpcMsg        *pMsg = pItem;
5,642✔
183
    const STraceId *trace = &pMsg->info.traceId;
5,642✔
184

185
    dGTrace("vgId:%d, msg:%p get from vnode-stream-chkpt queue", pVnode->vgId, pMsg);
5,642!
186
    code = vnodeProcessStreamChkptMsg(pVnode->pImpl, pMsg, pInfo);
5,642✔
187
    if (code != 0) {
5,642✔
188
      terrno = code;
12✔
189
      dGError("vgId:%d, msg:%p failed to process stream chkpt msg %s since %s", pVnode->vgId, pMsg,
12!
190
              TMSG_INFO(pMsg->msgType), tstrerror(code));
191
      vmSendRsp(pMsg, code);
12✔
192
    }
193

194
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
5,642!
195
    rpcFreeCont(pMsg->pCont);
5,642✔
196
    taosFreeQitem(pMsg);
5,642✔
197
  }
198
}
5,042✔
199

200
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
1,587✔
201
  SVnodeObj      *pVnode = pInfo->ahandle;
1,587✔
202
  const STraceId *trace = &pMsg->info.traceId;
1,587✔
203
  int32_t         code = 0;
1,587✔
204

205
  dGTrace("vgId:%d, msg:%p get from vnode-stream long-exec queue", pVnode->vgId, pMsg);
1,587!
206

207
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
1,587✔
208
  if (code != 0) {
1,587✔
209
    terrno = code;
1✔
210
    dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
1!
211
            tstrerror(code));
212
    vmSendRsp(pMsg, code);
1✔
213
  }
214

215
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,587!
216
  rpcFreeCont(pMsg->pCont);
1,587✔
217
  taosFreeQitem(pMsg);
1,587✔
218
}
1,587✔
219

220
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,376,861✔
221
  SVnodeObj *pVnode = pInfo->ahandle;
3,376,861✔
222
  SRpcMsg   *pMsg = NULL;
3,376,861✔
223

224
  for (int32_t i = 0; i < numOfMsgs; ++i) {
6,844,318✔
225
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,465,075!
226
    const STraceId *trace = &pMsg->info.traceId;
3,466,960✔
227
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
3,466,960!
228

229
    terrno = 0;
3,466,960✔
230
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
3,464,934✔
231
    if (code != 0) {
3,466,707✔
232
      if (code == -1 && terrno != 0) {
590!
233
        code = terrno;
×
234
      }
235

236
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
590!
237
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
238
      } else {
239
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
590!
240
      }
241

242
      vmSendRsp(pMsg, code);
590✔
243
    }
244

245
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
3,466,707!
246
    rpcFreeCont(pMsg->pCont);
3,466,707✔
247
    taosFreeQitem(pMsg);
3,467,479✔
248
  }
249
}
3,379,243✔
250

251
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
775,857✔
252
  SVnodeObj *pVnode = pInfo->ahandle;
775,857✔
253
  SRpcMsg   *pMsg = NULL;
775,857✔
254

255
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,689,970✔
256
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
914,018!
257
    const STraceId *trace = &pMsg->info.traceId;
914,199✔
258
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
914,199!
259

260
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
914,199✔
261
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
914,071!
262
    rpcFreeCont(pMsg->pCont);
914,071✔
263
    taosFreeQitem(pMsg);
914,046✔
264
  }
265
}
775,952✔
266

267
static void vmSendResponse(SRpcMsg *pMsg) {
×
268
  if (pMsg->info.handle) {
×
269
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
270
    if (rpcSendResponse(&rsp) != 0) {
×
271
      dError("failed to send response since %s", terrstr());
×
272
    }
273
  }
274
}
×
275

276
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
1,798,802✔
277
  STfs *pTfs = pVnode->pImpl->pTfs;
1,798,802✔
278
  if (pTfs) {
1,798,802!
279
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
1,798,868✔
280
  } else {
UNCOV
281
    return osDataSpaceSufficient();
×
282
  }
283
}
284

285
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
12,727,767✔
286
  *pNode = vmAcquireVnode(pMgt, vgId);
12,727,767✔
287
  if (*pNode == NULL) {
12,741,101✔
288
    return terrno;
553,332✔
289
  }
290
  return 0;
12,187,769✔
291
}
292
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
12,726,980✔
293
  int32_t         code = 0;
12,726,980✔
294
  const STraceId *trace = &pMsg->info.traceId;
12,726,980✔
295
  if (pMsg->contLen < sizeof(SMsgHead)) {
12,726,980!
296
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
297
            pMsg->contLen);
298
    return TSDB_CODE_INVALID_MSG;
×
299
  }
300

301
  SMsgHead *pHead = pMsg->pCont;
12,726,980✔
302

303
  pHead->contLen = ntohl(pHead->contLen);
12,726,980✔
304
  pHead->vgId = ntohl(pHead->vgId);
12,726,980✔
305

306
  SVnodeObj *pVnode = NULL;
12,726,980✔
307
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
12,726,980✔
308
  if (code != 0) {
12,740,828✔
309
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
553,362!
310
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
311
    return code;
553,362✔
312
  }
313

314
  switch (qtype) {
12,187,466✔
315
    case QUERY_QUEUE:
5,075,327✔
316
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
5,075,327✔
317
      if (code) {
5,075,384✔
318
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
11!
319
      } else {
320
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
5,075,373!
321
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
5,075,373✔
322
      }
323
      break;
5,076,751✔
324
    case STREAM_QUEUE:
114,538✔
325
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
114,538!
326
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
114,538✔
327
      break;
114,539✔
328
    case STREAM_CTRL_QUEUE:
82,663✔
329
      dGTrace("vgId:%d, msg:%p put into vnode-stream-ctrl queue", pVnode->vgId, pMsg);
82,663!
330
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
82,663✔
331
      break;
82,660✔
332
    case STREAM_LONG_EXEC_QUEUE:
1,587✔
333
      dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
1,587!
334
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
1,587✔
335
      break;
1,587✔
336
    case STREAM_CHKPT_QUEUE:
5,642✔
337
      dGTrace("vgId:%d, msg:%p put into vnode-stream-chkpt queue", pVnode->vgId, pMsg);
5,642!
338
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
5,642✔
339
      break;
5,642✔
340
    case FETCH_QUEUE:
3,459,988✔
341
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
3,459,988!
342
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
3,459,989✔
343
      break;
3,465,631✔
344
    case WRITE_QUEUE:
1,798,814✔
345
      if (!vmDataSpaceSufficient(pVnode)) {
1,798,814!
346
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
347
        dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
348
        break;
×
349
      }
350
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
1,798,814!
351
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
352
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
353
        break;
×
354
      }
355
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
1,798,811✔
356
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
217!
357
        code = TSDB_CODE_VND_STOPPED;
217✔
358
        break;
217✔
359
      }
360
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
1,798,594!
361
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,798,594✔
362
      break;
1,798,622✔
363
    case SYNC_QUEUE:
849,041✔
364
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
849,041!
365
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
849,042✔
366
      break;
849,048✔
367
    case SYNC_RD_QUEUE:
65,141✔
368
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
65,141!
369
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
65,141✔
370
      break;
65,131✔
371
    case APPLY_QUEUE:
725,906✔
372
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
725,906!
373
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
725,906✔
374
      break;
725,909✔
375
    default:
8,819✔
376
      code = TSDB_CODE_INVALID_MSG;
8,819✔
377
      break;
8,819✔
378
  }
379

380
  vmReleaseVnode(pMgmt, pVnode);
12,194,556✔
381
  return code;
12,186,399✔
382
}
383

384
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
65,476✔
385

386
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
639,485✔
387

388
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
1,782,211✔
389

390
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
5,555,907✔
391

392
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
3,459,912✔
393

394
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
846✔
395

396
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
82,676✔
397

398
int32_t vmPutMsgToStreamLongExecQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_LONG_EXEC_QUEUE); }
×
399

400
int32_t vmPutMsgToStreamChkQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CHKPT_QUEUE); }
×
401

402
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,716✔
403
  const STraceId *trace = &pMsg->info.traceId;
8,716✔
404
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
8,716!
405
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
8,716✔
406
}
407

408
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,399✔
409
  const STraceId *trace = &pMsg->info.traceId;
8,399✔
410
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
8,399!
411
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
8,399✔
412
}
413

414
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
1,143,666✔
415
  int32_t code;
416
  if (pRpc->contLen < sizeof(SMsgHead)) {
1,143,666!
417
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
418
           pRpc->contLen);
419
    rpcFreeCont(pRpc->pCont);
×
420
    pRpc->pCont = NULL;
×
421
    return TSDB_CODE_INVALID_MSG;
×
422
  }
423

424
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
1,143,666✔
425
  SRpcMsg *pMsg;
426
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
1,143,666✔
427
  if (code) {
1,143,630!
428
    rpcFreeCont(pRpc->pCont);
×
429
    pRpc->pCont = NULL;
×
430
    return code;
×
431
  }
432

433
  SMsgHead *pHead = pRpc->pCont;
1,143,630✔
434
  dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
1,143,630!
435

436
  pHead->contLen = htonl(pHead->contLen);
1,143,630✔
437
  pHead->vgId = htonl(pHead->vgId);
1,143,630✔
438
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
1,143,630✔
439
  pRpc->pCont = NULL;
1,143,630✔
440

441
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
1,143,630✔
442
  if (code != 0) {
1,143,688✔
443
    dTrace("msg:%p, is freed", pMsg);
3,906✔
444
    rpcFreeCont(pMsg->pCont);
3,906✔
445
    taosFreeQitem(pMsg);
3,907✔
446
  }
447

448
  return code;
1,143,687✔
449
}
450

451
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
152,622✔
452
  int32_t    size = -1;
152,622✔
453
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
152,622✔
454
  if (pVnode != NULL) {
152,634✔
455
    switch (qtype) {
130,728!
456
      case WRITE_QUEUE:
×
457
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
458
        break;
×
459
      case SYNC_QUEUE:
×
460
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
461
        break;
×
462
      case APPLY_QUEUE:
130,728✔
463
        size = taosQueueItemSize(pVnode->pApplyW.queue);
130,728✔
464
        break;
130,728✔
465
      case QUERY_QUEUE:
×
466
        size = taosQueueItemSize(pVnode->pQueryQ);
×
467
        break;
×
468
      case FETCH_QUEUE:
×
469
        size = taosQueueItemSize(pVnode->pFetchQ);
×
470
        break;
×
471
      case STREAM_QUEUE:
×
472
        size = taosQueueItemSize(pVnode->pStreamQ);
×
473
        break;
×
474
      case STREAM_CTRL_QUEUE:
×
475
        size = taosQueueItemSize(pVnode->pStreamCtrlQ);
×
476
        break;
×
477
      case STREAM_LONG_EXEC_QUEUE:
×
478
        size = taosQueueItemSize(pVnode->pStreamLongExecQ);
×
479
        break;
×
480
      case STREAM_CHKPT_QUEUE:
×
481
        size = taosQueueItemSize(pVnode->pStreamChkQ);
×
482
      default:
×
483
        break;
×
484
    }
485
  }
486
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
152,634✔
487
  if (size < 0) {
152,628✔
488
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
21,895✔
489
    size = 0;
21,895✔
490
  }
491
  return size;
152,628✔
492
}
493

494
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
10,765✔
495
  int32_t         code = 0;
10,765✔
496
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
10,765✔
497
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
10,765✔
498
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
10,765✔
499
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
10,765✔
500
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
10,765✔
501
  if (code) {
10,765!
502
    return code;
×
503
  }
504
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
10,765✔
505
  if (code) {
10,765!
506
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
507
    return code;
×
508
  }
509
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
10,765✔
510
  if (code) {
10,765!
511
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
512
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
513
    return code;
×
514
  }
515
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
10,765✔
516
  if (code) {
10,765!
517
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
518
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
519
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
520
    return code;
×
521
  }
522

523
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
10,765✔
524
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
10,765✔
525

526
  // init stream msg processing queue family
527
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue, 2);
10,765✔
528
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
10,765✔
529
  pVnode->pStreamLongExecQ = tAutoQWorkerAllocQueue(&pMgmt->streamLongExecPool, pVnode, (FItem)vmProcessStreamLongExecQueue, 1);
10,765✔
530
  pVnode->pStreamChkQ = tWWorkerAllocQueue(&pMgmt->streamChkPool, pVnode, (FItems)vmProcessStreamChkptQueue);
10,765✔
531

532
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
10,765!
533
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
10,765!
534
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
10,765!
535
    return TSDB_CODE_OUT_OF_MEMORY;
×
536
  }
537

538
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
10,765!
539
        taosQueueGetThreadId(pVnode->pWriteW.queue));
540
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
10,765!
541
        taosQueueGetThreadId(pVnode->pSyncW.queue));
542
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
10,765!
543
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
544
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
10,765!
545
        taosQueueGetThreadId(pVnode->pApplyW.queue));
546
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
10,765!
547
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
10,765!
548
        taosQueueGetThreadId(pVnode->pFetchQ));
549
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
10,765!
550
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
10,765!
551
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
10,765!
552
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
553
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
10,765!
554
        taosQueueGetThreadId(pVnode->pStreamChkQ));
555
  return 0;
10,765✔
556
}
557

558
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
10,765✔
559
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
10,765✔
560
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
10,765✔
561
  tAutoQWorkerFreeQueue(&pMgmt->streamLongExecPool, pVnode->pStreamLongExecQ);
10,765✔
562
  tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
10,764✔
563
  tWWorkerFreeQueue(&pMgmt->streamChkPool, pVnode->pStreamChkQ);
10,765✔
564
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
10,765✔
565
  pVnode->pQueryQ = NULL;
10,763✔
566
  pVnode->pFetchQ = NULL;
10,763✔
567

568
  pVnode->pStreamQ = NULL;
10,763✔
569
  pVnode->pStreamCtrlQ = NULL;
10,763✔
570
  pVnode->pStreamLongExecQ = NULL;
10,763✔
571

572
  pVnode->pStreamChkQ = NULL;
10,763✔
573
  pVnode->pFetchQ = NULL;
10,763✔
574
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
10,763✔
575
}
10,763✔
576

577
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
2,127✔
578
  int32_t code = 0;
2,127✔
579

580
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
2,127✔
581
  pQPool->name = "vnode-query";
2,127✔
582
  pQPool->min = tsNumOfVnodeQueryThreads;
2,127✔
583
  pQPool->max = tsNumOfVnodeQueryThreads;
2,127✔
584
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
2,127!
585

586
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,127✔
587

588
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
2,127✔
589
  pStreamPool->name = "vnode-stream";
2,127✔
590
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
2,127✔
591
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
2,127!
592

593
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
2,127✔
594
  pLongExecPool->name = "vnode-stream-long-exec";
2,127✔
595
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
2,127✔
596
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
2,127!
597

598
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
2,127✔
599
  pStreamCtrlPool->name = "vnode-stream-ctrl";
2,127✔
600
  pStreamCtrlPool->max = 1;
2,127✔
601
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
2,127!
602

603
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
2,127✔
604
  pStreamChkPool->name = "vnode-stream-chkpt";
2,127✔
605
  pStreamChkPool->max = 1;
2,127✔
606
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
2,127!
607

608
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
2,127✔
609
  pFPool->name = "vnode-fetch";
2,127✔
610
  pFPool->max = tsNumOfVnodeFetchThreads;
2,127✔
611
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
2,127!
612

613
  SSingleWorkerCfg mgmtCfg = {
2,127✔
614
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
615

616
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,127!
617

618
  int32_t threadNum = 0;
2,127✔
619
  if (tsNumOfCores == 1) {
2,127!
620
    threadNum = 2;
×
621
  } else {
622
    threadNum = tsNumOfCores;
2,127✔
623
  }
624
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
2,127✔
625
                                   .max = threadNum,
626
                                   .name = "vnode-multi-mgmt",
627
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
628
                                   .param = pMgmt};
629

630
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
2,127!
631

632
  dDebug("vnode workers are initialized");
2,127✔
633
  return 0;
2,127✔
634
}
635

636
void vmStopWorker(SVnodeMgmt *pMgmt) {
2,127✔
637
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
2,127✔
638
  tAutoQWorkerCleanup(&pMgmt->streamPool);
2,127✔
639
  tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
2,127✔
640
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
2,127✔
641
  tWWorkerCleanup(&pMgmt->streamChkPool);
2,127✔
642
  tWWorkerCleanup(&pMgmt->fetchPool);
2,127✔
643
  dDebug("vnode workers are closed");
2,127✔
644
}
2,127✔
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