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

taosdata / TDengine / #3565

25 Dec 2024 05:34AM UTC coverage: 51.098% (-11.1%) from 62.21%
#3565

push

travis-ci

web-flow
Merge pull request #29316 from taosdata/enh/3.0/TD-33266

enh(ut):Add wal & config UT.

111558 of 284773 branches covered (39.17%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 2 files covered. (50.0%)

39015 existing lines in 102 files now uncovered.

177882 of 281666 relevant lines covered (63.15%)

15090998.35 hits per line

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

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

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

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

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

51
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
18!
52
  rpcFreeCont(pMsg->pCont);
18✔
53
  taosFreeQitem(pMsg);
18✔
54
}
18✔
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) {
18✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
18✔
124
  const STraceId *trace = &pMsg->info.traceId;
18✔
125

126
  dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
18!
127
  int32_t code = vnodeProcessStreamMsg(pVnode->pImpl, pMsg, pInfo);
18✔
128
  if (code != 0) {
18!
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);
18!
136
  rpcFreeCont(pMsg->pCont);
18✔
137
  taosFreeQitem(pMsg);
18✔
138
}
18✔
139

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

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

UNCOV
149
    terrno = 0;
×
UNCOV
150
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
×
UNCOV
151
    if (code != 0) {
×
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

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

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

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

UNCOV
180
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
×
UNCOV
181
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
UNCOV
182
    rpcFreeCont(pMsg->pCont);
×
UNCOV
183
    taosFreeQitem(pMsg);
×
184
  }
UNCOV
185
}
×
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) {
40✔
197
  STfs *pTfs = pVnode->pImpl->pTfs;
40✔
198
  if (pTfs) {
40!
199
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
40✔
200
  } else {
201
    return osDataSpaceSufficient();
×
202
  }
203
}
204

205
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
92✔
206
  *pNode = vmAcquireVnode(pMgt, vgId);
92✔
207
  if (*pNode == NULL) {
92✔
208
    return terrno;
16✔
209
  }
210
  return 0;
76✔
211
}
212
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
92✔
213
  int32_t         code = 0;
92✔
214
  const STraceId *trace = &pMsg->info.traceId;
92✔
215
  if (pMsg->contLen < sizeof(SMsgHead)) {
92!
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;
92✔
222

223
  pHead->contLen = ntohl(pHead->contLen);
92✔
224
  pHead->vgId = ntohl(pHead->vgId);
92✔
225

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

234
  switch (qtype) {
76!
UNCOV
235
    case QUERY_QUEUE:
×
UNCOV
236
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
×
UNCOV
237
      if (code) {
×
UNCOV
238
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
239
      } else {
UNCOV
240
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
×
UNCOV
241
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
×
242
      }
UNCOV
243
      break;
×
244
    case STREAM_QUEUE:
18✔
245
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
18!
246
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
18✔
247
      break;
18✔
UNCOV
248
    case FETCH_QUEUE:
×
UNCOV
249
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
×
UNCOV
250
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
×
UNCOV
251
      break;
×
252
    case WRITE_QUEUE:
40✔
253
      if (!vmDataSpaceSufficient(pVnode)) {
40!
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)) {
40!
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) {
40!
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);
40!
269
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
40✔
270
      break;
40✔
UNCOV
271
    case SYNC_QUEUE:
×
UNCOV
272
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
×
UNCOV
273
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
×
UNCOV
274
      break;
×
UNCOV
275
    case SYNC_RD_QUEUE:
×
UNCOV
276
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
×
UNCOV
277
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
×
UNCOV
278
      break;
×
279
    case APPLY_QUEUE:
18✔
280
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
18!
281
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
18✔
282
      break;
18✔
UNCOV
283
    default:
×
UNCOV
284
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
285
      break;
×
286
  }
287

288
  vmReleaseVnode(pMgmt, pVnode);
76✔
289
  return code;
76✔
290
}
291

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

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

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

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

UNCOV
300
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
×
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) {
18✔
305
  const STraceId *trace = &pMsg->info.traceId;
18✔
306
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
18!
307
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
18✔
308
}
309

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

316
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
54✔
317
  int32_t code;
318
  if (pRpc->contLen < sizeof(SMsgHead)) {
54!
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;
54✔
327
  SRpcMsg *pMsg;
328
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
54✔
329
  if (code) {
54!
330
    rpcFreeCont(pRpc->pCont);
×
331
    pRpc->pCont = NULL;
×
332
    return code;
×
333
  }
334

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

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

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

350
  return code;
54✔
351
}
352

UNCOV
353
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
×
UNCOV
354
  int32_t    size = -1;
×
UNCOV
355
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
×
UNCOV
356
  if (pVnode != NULL) {
×
UNCOV
357
    switch (qtype) {
×
358
      case WRITE_QUEUE:
×
359
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
360
        break;
×
361
      case SYNC_QUEUE:
×
362
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
363
        break;
×
UNCOV
364
      case APPLY_QUEUE:
×
UNCOV
365
        size = taosQueueItemSize(pVnode->pApplyW.queue);
×
UNCOV
366
        break;
×
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
  }
UNCOV
380
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
×
UNCOV
381
  if (size < 0) {
×
UNCOV
382
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
×
UNCOV
383
    size = 0;
×
384
  }
UNCOV
385
  return size;
×
386
}
387

388
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
18✔
389
  int32_t         code = 0;
18✔
390
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
18✔
391
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
18✔
392
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
18✔
393
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
18✔
394
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
18✔
395
  if (code) {
18!
396
    return code;
×
397
  }
398
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
18✔
399
  if (code) {
18!
400
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
401
    return code;
×
402
  }
403
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
18✔
404
  if (code) {
18!
405
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
406
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
407
    return code;
×
408
  }
409
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
18✔
410
  if (code) {
18!
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);
18✔
418
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
18✔
419
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
18✔
420

421
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
18!
422
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
18!
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,
18!
427
        taosQueueGetThreadId(pVnode->pWriteW.queue));
428
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
18!
429
        taosQueueGetThreadId(pVnode->pSyncW.queue));
430
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
18!
431
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
432
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
18!
433
        taosQueueGetThreadId(pVnode->pApplyW.queue));
434
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
18!
435
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
18!
436
        taosQueueGetThreadId(pVnode->pFetchQ));
437
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
18!
438
  return 0;
18✔
439
}
440

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

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

459
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
8✔
460

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

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

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

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

476
  int32_t threadNum = 0;
8✔
477
  if (tsNumOfCores == 1) {
8!
478
    threadNum = 2;
×
479
  } else {
480
    threadNum = tsNumOfCores;
8✔
481
  }
482
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
8✔
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;
8!
489

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

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