• 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

31.89
/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) {
36✔
21
  if (pMsg->info.handle == NULL) return;
36!
22
  SRpcMsg rsp = {
36✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
36✔
25
      .contLen = pMsg->info.rspLen,
36✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
36✔
29
}
30

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

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

43
  if (IsReq(pMsg)) {
20!
44
    if (code != 0) {
20!
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);
20✔
49
  }
50

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

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

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
16!
62
  switch (pMsg->msgType) {
16!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
16✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
16✔
68
      break;
16✔
UNCOV
69
    case TDMT_VND_ALTER_REPLICA:
×
UNCOV
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
×
UNCOV
71
      break;
×
UNCOV
72
    case TDMT_VND_DISABLE_WRITE:
×
UNCOV
73
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
×
UNCOV
74
      break;
×
UNCOV
75
    case TDMT_VND_ALTER_HASHRANGE:
×
UNCOV
76
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
×
UNCOV
77
      break;
×
UNCOV
78
    case TDMT_DND_ALTER_VNODE_TYPE:
×
UNCOV
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
×
UNCOV
80
      break;
×
81
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
82
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
83
      break;
×
UNCOV
84
    case TDMT_VND_ARB_HEARTBEAT:
×
UNCOV
85
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
×
UNCOV
86
      break;
×
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)) {
16!
93
    if (code != 0) {
16!
UNCOV
94
      if (terrno != 0) code = terrno;
×
UNCOV
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
×
96
    }
97
    vmSendRsp(pMsg, code);
16✔
98
  }
99

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

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

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

UNCOV
117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
UNCOV
118
  rpcFreeCont(pMsg->pCont);
×
UNCOV
119
  taosFreeQitem(pMsg);
×
UNCOV
120
}
×
121

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

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

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

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

UNCOV
148
  while (1) {
×
UNCOV
149
    if (taosGetQitem(pQall, &pItem) == 0) {
×
UNCOV
150
      break;
×
151
    }
152

UNCOV
153
    SRpcMsg        *pMsg = pItem;
×
UNCOV
154
    const STraceId *trace = &pMsg->info.traceId;
×
155

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

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

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

UNCOV
177
  while (1) {
×
UNCOV
178
    if (taosGetQitem(pQall, &pItem) == 0) {
×
UNCOV
179
      break;
×
180
    }
181

UNCOV
182
    SRpcMsg        *pMsg = pItem;
×
UNCOV
183
    const STraceId *trace = &pMsg->info.traceId;
×
184

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

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

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

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

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

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

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

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

229
    terrno = 0;
×
UNCOV
230
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
×
UNCOV
231
    if (code != 0) {
×
UNCOV
232
      if (code == -1 && terrno != 0) {
×
233
        code = terrno;
×
234
      }
235

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

UNCOV
242
      vmSendRsp(pMsg, code);
×
243
    }
244

UNCOV
245
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
UNCOV
246
    rpcFreeCont(pMsg->pCont);
×
UNCOV
247
    taosFreeQitem(pMsg);
×
248
  }
UNCOV
249
}
×
250

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

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

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

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

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

285
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
112✔
286
  *pNode = vmAcquireVnode(pMgt, vgId);
112✔
287
  if (*pNode == NULL) {
112✔
288
    return terrno;
16✔
289
  }
290
  return 0;
96✔
291
}
292
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
112✔
293
  int32_t         code = 0;
112✔
294
  const STraceId *trace = &pMsg->info.traceId;
112✔
295
  if (pMsg->contLen < sizeof(SMsgHead)) {
112!
UNCOV
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);
UNCOV
298
    return TSDB_CODE_INVALID_MSG;
×
299
  }
300

301
  SMsgHead *pHead = pMsg->pCont;
112✔
302

303
  pHead->contLen = ntohl(pHead->contLen);
112✔
304
  pHead->vgId = ntohl(pHead->vgId);
112✔
305

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

314
  switch (qtype) {
96!
UNCOV
315
    case QUERY_QUEUE:
×
UNCOV
316
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
×
UNCOV
317
      if (code) {
×
UNCOV
318
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
319
      } else {
UNCOV
320
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
×
UNCOV
321
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
×
322
      }
UNCOV
323
      break;
×
324
    case STREAM_QUEUE:
20✔
325
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
20!
326
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
20✔
327
      break;
20✔
UNCOV
328
    case STREAM_CTRL_QUEUE:
×
UNCOV
329
      dGTrace("vgId:%d, msg:%p put into vnode-stream-ctrl queue", pVnode->vgId, pMsg);
×
UNCOV
330
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
×
UNCOV
331
      break;
×
UNCOV
332
    case STREAM_LONG_EXEC_QUEUE:
×
UNCOV
333
      dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
×
UNCOV
334
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
×
UNCOV
335
      break;
×
UNCOV
336
    case STREAM_CHKPT_QUEUE:
×
UNCOV
337
      dGTrace("vgId:%d, msg:%p put into vnode-stream-chkpt queue", pVnode->vgId, pMsg);
×
UNCOV
338
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
×
UNCOV
339
      break;
×
UNCOV
340
    case FETCH_QUEUE:
×
UNCOV
341
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
×
342
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
×
343
      break;
×
344
    case WRITE_QUEUE:
56✔
345
      if (!vmDataSpaceSufficient(pVnode)) {
56!
UNCOV
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)) {
56!
UNCOV
351
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
UNCOV
352
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
UNCOV
353
        break;
×
354
      }
355
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
56!
UNCOV
356
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
×
UNCOV
357
        code = TSDB_CODE_VND_STOPPED;
×
UNCOV
358
        break;
×
359
      }
360
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
56!
361
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
56✔
362
      break;
56✔
UNCOV
363
    case SYNC_QUEUE:
×
UNCOV
364
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
×
UNCOV
365
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
×
UNCOV
366
      break;
×
UNCOV
367
    case SYNC_RD_QUEUE:
×
UNCOV
368
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
×
UNCOV
369
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
×
UNCOV
370
      break;
×
371
    case APPLY_QUEUE:
20✔
372
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
20!
373
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
20✔
374
      break;
20✔
UNCOV
375
    default:
×
UNCOV
376
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
377
      break;
×
378
  }
379

380
  vmReleaseVnode(pMgmt, pVnode);
96✔
381
  return code;
96✔
382
}
383

UNCOV
384
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
×
385

UNCOV
386
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
×
387

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

UNCOV
390
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
×
391

UNCOV
392
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
×
393

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

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

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

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

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

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

414
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
58✔
415
  int32_t code;
416
  if (pRpc->contLen < sizeof(SMsgHead)) {
58!
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);
UNCOV
419
    rpcFreeCont(pRpc->pCont);
×
UNCOV
420
    pRpc->pCont = NULL;
×
UNCOV
421
    return TSDB_CODE_INVALID_MSG;
×
422
  }
423

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

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

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

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

448
  return code;
58✔
449
}
450

UNCOV
451
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
×
452
  int32_t    size = -1;
×
453
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
×
454
  if (pVnode != NULL) {
×
455
    switch (qtype) {
×
456
      case WRITE_QUEUE:
×
457
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
UNCOV
458
        break;
×
UNCOV
459
      case SYNC_QUEUE:
×
UNCOV
460
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
461
        break;
×
462
      case APPLY_QUEUE:
×
463
        size = taosQueueItemSize(pVnode->pApplyW.queue);
×
464
        break;
×
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;
×
UNCOV
480
      case STREAM_CHKPT_QUEUE:
×
UNCOV
481
        size = taosQueueItemSize(pVnode->pStreamChkQ);
×
UNCOV
482
      default:
×
UNCOV
483
        break;
×
484
    }
485
  }
UNCOV
486
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
×
UNCOV
487
  if (size < 0) {
×
UNCOV
488
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
×
UNCOV
489
    size = 0;
×
490
  }
UNCOV
491
  return size;
×
492
}
493

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

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

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

532
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
20!
533
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
20!
534
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
20!
UNCOV
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,
20!
539
        taosQueueGetThreadId(pVnode->pWriteW.queue));
540
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
20!
541
        taosQueueGetThreadId(pVnode->pSyncW.queue));
542
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
20!
543
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
544
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
20!
545
        taosQueueGetThreadId(pVnode->pApplyW.queue));
546
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
20!
547
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
20!
548
        taosQueueGetThreadId(pVnode->pFetchQ));
549
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
20!
550
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
20!
551
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
20!
552
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
553
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
20!
554
        taosQueueGetThreadId(pVnode->pStreamChkQ));
555
  return 0;
20✔
556
}
557

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

568
  pVnode->pStreamQ = NULL;
20✔
569
  pVnode->pStreamCtrlQ = NULL;
20✔
570
  pVnode->pStreamLongExecQ = NULL;
20✔
571

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

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

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

586
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
8✔
587

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

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

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

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

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

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

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

618
  int32_t threadNum = 0;
8✔
619
  if (tsNumOfCores == 1) {
8!
UNCOV
620
    threadNum = 2;
×
621
  } else {
622
    threadNum = tsNumOfCores;
8✔
623
  }
624
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
8✔
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;
8!
631

632
  dDebug("vnode workers are initialized");
8!
633
  return 0;
8✔
634
}
635

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