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

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 hits per line

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

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

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

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

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

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

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

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
1,500!
62
  switch (pMsg->msgType) {
1,500!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
63✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
63✔
68
      break;
63✔
69
    case TDMT_VND_ALTER_REPLICA:
405✔
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
405✔
71
      break;
405✔
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;
×
78
    case TDMT_DND_ALTER_VNODE_TYPE:
1,032✔
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,032✔
80
      break;
1,032✔
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)) {
1,500!
93
    if (code != 0) {
1,500✔
94
      if (terrno != 0) code = terrno;
991!
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
991!
96
    }
97
    vmSendRsp(pMsg, code);
1,500✔
98
  }
99

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

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

109
  dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
33,092!
110
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
33,092✔
111
  if (code != 0) {
33,081!
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

117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
33,081!
118
  rpcFreeCont(pMsg->pCont);
33,081✔
119
  taosFreeQitem(pMsg);
33,090✔
120
}
33,091✔
121

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

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

135
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,012!
136
  rpcFreeCont(pMsg->pCont);
1,012✔
137
  taosFreeQitem(pMsg);
1,012✔
138
}
1,012✔
139

140
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
68,391✔
141
  SVnodeObj *pVnode = pInfo->ahandle;
68,391✔
142
  SRpcMsg   *pMsg = NULL;
68,391✔
143

144
  for (int32_t i = 0; i < numOfMsgs; ++i) {
143,381✔
145
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
74,866!
146
    const STraceId *trace = &pMsg->info.traceId;
74,966✔
147
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
74,966!
148

149
    terrno = 0;
74,966✔
150
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
74,853✔
151
    if (code != 0) {
74,890!
UNCOV
152
      if (code == -1 && terrno != 0) {
×
153
        code = terrno;
×
154
      }
155

UNCOV
156
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
×
157
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
158
      } else {
UNCOV
159
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
160
      }
161

UNCOV
162
      vmSendRsp(pMsg, code);
×
163
    }
164

165
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
74,890!
166
    rpcFreeCont(pMsg->pCont);
74,890✔
167
    taosFreeQitem(pMsg);
74,996✔
168
  }
169
}
68,515✔
170

171
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
74,794✔
172
  SVnodeObj *pVnode = pInfo->ahandle;
74,794✔
173
  SRpcMsg   *pMsg = NULL;
74,794✔
174

175
  for (int32_t i = 0; i < numOfMsgs; ++i) {
169,596✔
176
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
94,808!
177
    const STraceId *trace = &pMsg->info.traceId;
94,808✔
178
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
94,808!
179

180
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
94,808✔
181
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
94,807!
182
    rpcFreeCont(pMsg->pCont);
94,807✔
183
    taosFreeQitem(pMsg);
94,801✔
184
  }
185
}
74,788✔
186

187
static void vmSendResponse(SRpcMsg *pMsg) {
×
188
  if (pMsg->info.handle) {
×
189
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
190
    if (rpcSendResponse(&rsp) != 0) {
×
191
      dError("failed to send response since %s", terrstr());
×
192
    }
193
  }
194
}
×
195

196
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
35,788✔
197
  STfs *pTfs = pVnode->pImpl->pTfs;
35,788✔
198
  if (pTfs) {
35,788!
199
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
35,788✔
200
  } else {
201
    return osDataSpaceSufficient();
×
202
  }
203
}
204

205
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
336,598✔
206
  *pNode = vmAcquireVnode(pMgt, vgId);
336,598✔
207
  if (*pNode == NULL) {
337,263✔
208
    return terrno;
381✔
209
  }
210
  return 0;
336,882✔
211
}
212
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
336,612✔
213
  int32_t         code = 0;
336,612✔
214
  const STraceId *trace = &pMsg->info.traceId;
336,612✔
215
  if (pMsg->contLen < sizeof(SMsgHead)) {
336,612!
216
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
217
            pMsg->contLen);
218
    return TSDB_CODE_INVALID_MSG;
×
219
  }
220

221
  SMsgHead *pHead = pMsg->pCont;
336,612✔
222

223
  pHead->contLen = ntohl(pHead->contLen);
336,612✔
224
  pHead->vgId = ntohl(pHead->vgId);
336,612✔
225

226
  SVnodeObj *pVnode = NULL;
336,612✔
227
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
336,612✔
228
  if (code != 0) {
337,245✔
229
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
374!
230
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
231
    return code;
374✔
232
  }
233

234
  switch (qtype) {
336,871✔
235
    case QUERY_QUEUE:
33,024✔
236
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
33,024✔
237
      if (code) {
33,031!
UNCOV
238
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
239
      } else {
240
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
33,031!
241
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
33,031✔
242
      }
243
      break;
33,070✔
244
    case STREAM_QUEUE:
1,012✔
245
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
1,012!
246
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
1,012✔
247
      break;
1,012✔
248
    case FETCH_QUEUE:
74,487✔
249
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
74,487!
250
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
74,487✔
251
      break;
74,890✔
252
    case WRITE_QUEUE:
35,788✔
253
      if (!vmDataSpaceSufficient(pVnode)) {
35,788!
254
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
255
        dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
256
        break;
×
257
      }
258
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
35,788!
259
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
260
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
261
        break;
×
262
      }
263
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
35,788!
UNCOV
264
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
×
UNCOV
265
        code = TSDB_CODE_VND_STOPPED;
×
UNCOV
266
        break;
×
267
      }
268
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
35,788!
269
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
35,788✔
270
      break;
35,788✔
271
    case SYNC_QUEUE:
90,612✔
272
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
90,612!
273
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
90,612✔
274
      break;
90,612✔
275
    case SYNC_RD_QUEUE:
4,188✔
276
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
4,188!
277
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
4,188✔
278
      break;
4,188✔
279
    case APPLY_QUEUE:
97,253✔
280
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
97,253!
281
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
97,253✔
282
      break;
97,253✔
283
    default:
507✔
284
      code = TSDB_CODE_INVALID_MSG;
507✔
285
      break;
507✔
286
  }
287

288
  vmReleaseVnode(pMgmt, pVnode);
337,320✔
289
  return code;
336,871✔
290
}
291

292
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
4,224✔
293

294
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
70,288✔
295

296
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
35,655✔
297

298
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
32,777✔
299

300
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
74,456✔
301

UNCOV
302
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
×
303

304
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
101✔
305
  const STraceId *trace = &pMsg->info.traceId;
101✔
306
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
101!
307
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
101✔
308
}
309

310
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
1,500✔
311
  const STraceId *trace = &pMsg->info.traceId;
1,500✔
312
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
1,500!
313
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
1,500✔
314
}
315

316
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
119,278✔
317
  int32_t code;
318
  if (pRpc->contLen < sizeof(SMsgHead)) {
119,278!
319
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
320
           pRpc->contLen);
321
    rpcFreeCont(pRpc->pCont);
×
322
    pRpc->pCont = NULL;
×
323
    return TSDB_CODE_INVALID_MSG;
×
324
  }
325

326
  EQItype  itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
119,278✔
327
  SRpcMsg *pMsg;
328
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
119,278✔
329
  if (code) {
119,274!
330
    rpcFreeCont(pRpc->pCont);
×
331
    pRpc->pCont = NULL;
×
332
    return code;
×
333
  }
334

335
  SMsgHead *pHead = pRpc->pCont;
119,274✔
336
  dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
119,274!
337

338
  pHead->contLen = htonl(pHead->contLen);
119,274✔
339
  pHead->vgId = htonl(pHead->vgId);
119,274✔
340
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
119,274✔
341
  pRpc->pCont = NULL;
119,274✔
342

343
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
119,274✔
344
  if (code != 0) {
119,277✔
345
    dTrace("msg:%p, is freed", pMsg);
311✔
346
    rpcFreeCont(pMsg->pCont);
311✔
347
    taosFreeQitem(pMsg);
311✔
348
  }
349

350
  return code;
119,277✔
351
}
352

353
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
6,981✔
354
  int32_t    size = -1;
6,981✔
355
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
6,981✔
356
  if (pVnode != NULL) {
6,980✔
357
    switch (qtype) {
5,901!
358
      case WRITE_QUEUE:
×
359
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
360
        break;
×
361
      case SYNC_QUEUE:
×
362
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
363
        break;
×
364
      case APPLY_QUEUE:
5,901✔
365
        size = taosQueueItemSize(pVnode->pApplyW.queue);
5,901✔
366
        break;
5,901✔
367
      case QUERY_QUEUE:
×
368
        size = taosQueueItemSize(pVnode->pQueryQ);
×
369
        break;
×
370
      case FETCH_QUEUE:
×
371
        size = taosQueueItemSize(pVnode->pFetchQ);
×
372
        break;
×
373
      case STREAM_QUEUE:
×
374
        size = taosQueueItemSize(pVnode->pStreamQ);
×
375
        break;
×
376
      default:
×
377
        break;
×
378
    }
379
  }
380
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
6,980✔
381
  if (size < 0) {
6,980✔
382
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
1,079!
383
    size = 0;
1,079✔
384
  }
385
  return size;
6,980✔
386
}
387

388
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
556✔
389
  int32_t         code = 0;
556✔
390
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
556✔
391
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
556✔
392
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
556✔
393
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
556✔
394
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
556✔
395
  if (code) {
556!
396
    return code;
×
397
  }
398
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
556✔
399
  if (code) {
556!
400
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
401
    return code;
×
402
  }
403
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
556✔
404
  if (code) {
556!
405
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
406
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
407
    return code;
×
408
  }
409
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
556✔
410
  if (code) {
556!
411
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
412
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
413
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
414
    return code;
×
415
  }
416

417
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
556✔
418
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
556✔
419
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
556✔
420

421
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
556!
422
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
556!
423
    return TSDB_CODE_OUT_OF_MEMORY;
×
424
  }
425

426
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
556!
427
        taosQueueGetThreadId(pVnode->pWriteW.queue));
428
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
556!
429
        taosQueueGetThreadId(pVnode->pSyncW.queue));
430
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
556!
431
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
432
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
556!
433
        taosQueueGetThreadId(pVnode->pApplyW.queue));
434
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
556!
435
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
556!
436
        taosQueueGetThreadId(pVnode->pFetchQ));
437
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
556!
438
  return 0;
556✔
439
}
440

441
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
556✔
442
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
556✔
443
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
556✔
444
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
556✔
445
  pVnode->pQueryQ = NULL;
556✔
446
  pVnode->pStreamQ = NULL;
556✔
447
  pVnode->pFetchQ = NULL;
556✔
448
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
556✔
449
}
556✔
450

451
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
40✔
452
  int32_t                code = 0;
40✔
453
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
40✔
454
  pQPool->name = "vnode-query";
40✔
455
  pQPool->min = tsNumOfVnodeQueryThreads;
40✔
456
  pQPool->max = tsNumOfVnodeQueryThreads;
40✔
457
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
40!
458

459
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
40✔
460

461
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
40✔
462
  pStreamPool->name = "vnode-stream";
40✔
463
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
40✔
464
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
40!
465

466
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
40✔
467
  pFPool->name = "vnode-fetch";
40✔
468
  pFPool->max = tsNumOfVnodeFetchThreads;
40✔
469
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
40!
470

471
  SSingleWorkerCfg mgmtCfg = {
40✔
472
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
473

474
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
40!
475

476
  int32_t threadNum = 0;
40✔
477
  if (tsNumOfCores == 1) {
40!
478
    threadNum = 2;
×
479
  } else {
480
    threadNum = tsNumOfCores;
40✔
481
  }
482
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
40✔
483
                                   .max = threadNum,
484
                                   .name = "vnode-multi-mgmt",
485
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
486
                                   .param = pMgmt};
487

488
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
40!
489

490
  dDebug("vnode workers are initialized");
40✔
491
  return 0;
40✔
492
}
493

494
void vmStopWorker(SVnodeMgmt *pMgmt) {
40✔
495
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
40✔
496
  tAutoQWorkerCleanup(&pMgmt->streamPool);
40✔
497
  tWWorkerCleanup(&pMgmt->fetchPool);
40✔
498
  dDebug("vnode workers are closed");
40✔
499
}
40✔
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