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

taosdata / TDengine / #3929

25 Apr 2025 11:21AM UTC coverage: 62.507% (+0.1%) from 62.362%
#3929

push

travis-ci

web-flow
docs: jdbc tmq supports database subscription. [TS-6222] (#30819)

* docs: jdbc tmq supports database subscription. [TS-6222]

* Update docs/zh/07-develop/07-tmq.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update 07-tmq.md

---------

Co-authored-by: haoranchen <haoran920c@163.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

155520 of 317319 branches covered (49.01%)

Branch coverage included in aggregate %.

240651 of 316482 relevant lines covered (76.04%)

6469891.78 hits per line

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

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

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

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

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

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

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

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
9,085!
62
  switch (pMsg->msgType) {
9,085!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
3,884✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
3,884✔
68
      break;
3,884✔
69
    case TDMT_VND_ALTER_REPLICA:
1,117✔
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
1,117✔
71
      break;
1,117✔
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,957✔
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
3,957✔
80
      break;
3,957✔
81
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
82
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
83
      break;
×
84
    case TDMT_VND_ARB_HEARTBEAT:
67✔
85
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
67✔
86
      break;
67✔
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)) {
9,085!
93
    if (code != 0) {
9,085✔
94
      if (terrno != 0) code = terrno;
3,789!
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
3,789!
96
    }
97
    vmSendRsp(pMsg, code);
9,085✔
98
  }
99

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

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

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

117
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
5,005,144!
118
  rpcFreeCont(pMsg->pCont);
5,005,144✔
119
  taosFreeQitem(pMsg);
5,006,434✔
120
}
5,006,610✔
121

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

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

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

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

148
  while (1) {
57,136✔
149
    if (taosGetQitem(pQall, &pItem) == 0) {
107,579✔
150
      break;
50,454✔
151
    }
152

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

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

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

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

177
  while (1) {
3,206✔
178
    if (taosGetQitem(pQall, &pItem) == 0) {
6,120✔
179
      break;
2,914✔
180
    }
181

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

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

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

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

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

207
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
940✔
208
  if (code != 0) {
940✔
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);
940!
216
  rpcFreeCont(pMsg->pCont);
940✔
217
  taosFreeQitem(pMsg);
940✔
218
}
940✔
219

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

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

229
    terrno = 0;
4,348,043✔
230
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
4,345,643✔
231
    if (code != 0) {
4,346,705✔
232
      if (code == -1 && terrno != 0) {
1,579!
233
        code = terrno;
×
234
      }
235

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

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

245
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
4,346,705!
246
    rpcFreeCont(pMsg->pCont);
4,346,705✔
247
    taosFreeQitem(pMsg);
4,348,697✔
248
  }
249
}
4,270,566✔
250

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

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

260
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
958,160✔
261
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
958,095!
262
    rpcFreeCont(pMsg->pCont);
958,095✔
263
    taosFreeQitem(pMsg);
958,023✔
264
  }
265
}
814,551✔
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,991,522✔
277
  STfs *pTfs = pVnode->pImpl->pTfs;
1,991,522✔
278
  if (pTfs) {
1,991,522!
279
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
1,991,599✔
280
  } else {
281
    return osDataSpaceSufficient();
×
282
  }
283
}
284

285
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
13,870,692✔
286
  *pNode = vmAcquireVnode(pMgt, vgId);
13,870,692✔
287
  if (*pNode == NULL) {
13,885,140✔
288
    return terrno;
676,442✔
289
  }
290
  return 0;
13,208,698✔
291
}
292
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
13,870,690✔
293
  int32_t         code = 0;
13,870,690✔
294
  const STraceId *trace = &pMsg->info.traceId;
13,870,690✔
295
  if (pMsg->contLen < sizeof(SMsgHead)) {
13,870,690!
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;
13,870,690✔
302

303
  pHead->contLen = ntohl(pHead->contLen);
13,870,690✔
304
  pHead->vgId = ntohl(pHead->vgId);
13,870,690✔
305

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

314
  switch (qtype) {
13,208,413✔
315
    case QUERY_QUEUE:
5,004,739✔
316
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
5,004,739✔
317
      if (code) {
5,004,798✔
318
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
17!
319
      } else {
320
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
5,004,781!
321
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
5,004,781✔
322
      }
323
      break;
5,005,652✔
324
    case STREAM_QUEUE:
97,859✔
325
      dGTrace("vgId:%d, msg:%p, put into vnode-stream queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
97,859!
326
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
97,859✔
327
      break;
97,860✔
328
    case STREAM_CTRL_QUEUE:
57,133✔
329
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-ctrl queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
57,133!
330
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
57,133✔
331
      break;
57,135✔
332
    case STREAM_LONG_EXEC_QUEUE:
940✔
333
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-long-exec queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
940!
334
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
940✔
335
      break;
940✔
336
    case STREAM_CHKPT_QUEUE:
3,206✔
337
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-chkpt queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
3,206!
338
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
3,206✔
339
      break;
3,206✔
340
    case FETCH_QUEUE:
4,341,143✔
341
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
4,341,143!
342
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
4,341,143✔
343
      break;
4,346,242✔
344
    case WRITE_QUEUE:
1,991,529✔
345
      if (!vmDataSpaceSufficient(pVnode)) {
1,991,529!
346
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
347
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
348
               tstrerror(code), TMSG_INFO(pMsg->msgType));
349
        break;
×
350
      }
351
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
1,991,556!
352
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
353
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
354
               tstrerror(code), TMSG_INFO(pMsg->msgType));
355
        break;
×
356
      }
357
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
1,991,551✔
358
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
249!
359
               TMSG_INFO(pMsg->msgType));
360
        code = TSDB_CODE_VND_STOPPED;
249✔
361
        break;
249✔
362
      }
363
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,991,302!
364
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,991,312✔
365
      break;
1,991,316✔
366
    case SYNC_QUEUE:
885,014✔
367
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
885,014!
368
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
885,017✔
369
      break;
885,004✔
370
    case SYNC_RD_QUEUE:
73,184✔
371
      dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
73,184!
372
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
73,184✔
373
      break;
73,189✔
374
    case APPLY_QUEUE:
744,577✔
375
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
744,577!
376
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
744,575✔
377
      break;
744,573✔
378
    default:
9,089✔
379
      code = TSDB_CODE_INVALID_MSG;
9,089✔
380
      break;
9,089✔
381
  }
382

383
  vmReleaseVnode(pMgmt, pVnode);
13,214,455✔
384
  return code;
13,207,494✔
385
}
386

387
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
73,554✔
388

389
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
665,252✔
390

391
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
1,976,739✔
392

393
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
5,617,162✔
394

395
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
4,341,110✔
396

397
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
826✔
398

399
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
57,139✔
400

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

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

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

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

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

427
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
1,142,045✔
428
  SRpcMsg *pMsg;
429
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
1,142,045✔
430
  if (code) {
1,142,052!
431
    rpcFreeCont(pRpc->pCont);
×
432
    pRpc->pCont = NULL;
×
433
    return code;
×
434
  }
435

436
  SMsgHead *pHead = pRpc->pCont;
1,142,052✔
437
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
1,142,052!
438

439
  pHead->contLen = htonl(pHead->contLen);
1,142,053✔
440
  pHead->vgId = htonl(pHead->vgId);
1,142,053✔
441
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
1,142,053✔
442
  pRpc->pCont = NULL;
1,142,053✔
443

444
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
1,142,053✔
445
  if (code != 0) {
1,142,056✔
446
    dTrace("msg:%p, is freed", pMsg);
4,105✔
447
    rpcFreeCont(pMsg->pCont);
4,105✔
448
    taosFreeQitem(pMsg);
4,107✔
449
  }
450

451
  return code;
1,142,059✔
452
}
453

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

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

526
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
12,277✔
527
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
12,277✔
528

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

535
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
12,277!
536
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
12,277!
537
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
12,277!
538
    return TSDB_CODE_OUT_OF_MEMORY;
×
539
  }
540

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

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

571
  pVnode->pStreamQ = NULL;
12,277✔
572
  pVnode->pStreamCtrlQ = NULL;
12,277✔
573
  pVnode->pStreamLongExecQ = NULL;
12,277✔
574

575
  pVnode->pStreamChkQ = NULL;
12,277✔
576
  pVnode->pFetchQ = NULL;
12,277✔
577
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
12,277✔
578
}
12,277✔
579

580
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
2,407✔
581
  int32_t code = 0;
2,407✔
582

583
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
2,407✔
584
  pQPool->name = "vnode-query";
2,407✔
585
  pQPool->min = tsNumOfVnodeQueryThreads;
2,407✔
586
  pQPool->max = tsNumOfVnodeQueryThreads;
2,407✔
587
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
2,407!
588

589
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,407✔
590

591
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
2,407✔
592
  pStreamPool->name = "vnode-stream";
2,407✔
593
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
2,407✔
594
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
2,407!
595

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

601
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
2,407✔
602
  pStreamCtrlPool->name = "vnode-stream-ctrl";
2,407✔
603
  pStreamCtrlPool->max = 4;
2,407✔
604
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
2,407!
605

606
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
2,407✔
607
  pStreamChkPool->name = "vnode-stream-chkpt";
2,407✔
608
  pStreamChkPool->max = 1;
2,407✔
609
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
2,407!
610

611
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
2,407✔
612
  pFPool->name = "vnode-fetch";
2,407✔
613
  pFPool->max = tsNumOfVnodeFetchThreads;
2,407✔
614
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
2,407!
615

616
  SSingleWorkerCfg mgmtCfg = {
2,407✔
617
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
618

619
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,407!
620

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

633
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
2,407!
634

635
  dDebug("vnode workers are initialized");
2,407✔
636
  return 0;
2,407✔
637
}
638

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