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

taosdata / TDengine / #3530

16 Nov 2024 07:44AM UTC coverage: 60.219% (-0.7%) from 60.888%
#3530

push

travis-ci

web-flow
Update 03-ad.md

118417 of 252124 branches covered (46.97%)

Branch coverage included in aggregate %.

198982 of 274951 relevant lines covered (72.37%)

6072359.98 hits per line

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

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

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

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

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

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

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

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

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

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

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

117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,640,655!
118
  rpcFreeCont(pMsg->pCont);
1,640,655✔
119
  taosFreeQitem(pMsg);
1,641,202✔
120
}
1,641,198✔
121

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

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

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

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

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

149
    terrno = 0;
4,072,855✔
150
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
4,070,899✔
151
    if (code != 0) {
4,072,662✔
152
      if (code == -1 && terrno != 0) {
1,573!
153
        code = terrno;
×
154
      }
155

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

162
      vmSendRsp(pMsg, code);
1,573✔
163
    }
164

165
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
4,072,662!
166
    rpcFreeCont(pMsg->pCont);
4,072,662✔
167
    taosFreeQitem(pMsg);
4,073,479✔
168
  }
169
}
3,947,474✔
170

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

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

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

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

223
  pHead->contLen = ntohl(pHead->contLen);
9,589,950✔
224
  pHead->vgId = ntohl(pHead->vgId);
9,589,950✔
225

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

234
  switch (qtype) {
9,592,481✔
235
    case QUERY_QUEUE:
1,639,419✔
236
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
1,639,419✔
237
      if (code) {
1,638,814✔
238
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
30!
239
      } else {
240
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
1,638,784!
241
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
1,638,784✔
242
      }
243
      break;
1,640,524✔
244
    case STREAM_QUEUE:
191,344✔
245
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
191,344!
246
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
191,345✔
247
      break;
191,348✔
248
    case FETCH_QUEUE:
4,066,595✔
249
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
4,066,595!
250
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
4,066,595✔
251
      break;
4,071,676✔
252
    case WRITE_QUEUE:
1,931,726✔
253
      if (!vmDataSpaceSufficient(pVnode)) {
1,931,726!
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)) {
1,931,741!
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) {
1,931,740✔
264
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
391!
265
        code = TSDB_CODE_VND_STOPPED;
391✔
266
        break;
391✔
267
      }
268
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
1,931,349!
269
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,931,349✔
270
      break;
1,931,360✔
271
    case SYNC_QUEUE:
933,392✔
272
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
933,392!
273
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
933,392✔
274
      break;
933,363✔
275
    case SYNC_RD_QUEUE:
77,824✔
276
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
77,824!
277
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
77,824✔
278
      break;
77,823✔
279
    case APPLY_QUEUE:
744,678✔
280
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
744,678!
281
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
744,678✔
282
      break;
744,680✔
283
    default:
7,503✔
284
      code = TSDB_CODE_INVALID_MSG;
7,503✔
285
      break;
7,503✔
286
  }
287

288
  vmReleaseVnode(pMgmt, pVnode);
9,598,668✔
289
  return code;
9,593,567✔
290
}
291

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

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

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

298
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
1,569,860✔
299

300
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
4,066,943✔
301

302
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
83,070✔
303

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

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

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

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

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

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

350
  return code;
1,177,706✔
351
}
352

353
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
184,499✔
354
  int32_t    size = -1;
184,499✔
355
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
184,499✔
356
  if (pVnode != NULL) {
184,512✔
357
    switch (qtype) {
159,447!
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:
159,447✔
365
        size = taosQueueItemSize(pVnode->pApplyW.queue);
159,447✔
366
        break;
159,445✔
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);
184,510✔
381
  if (size < 0) {
184,510✔
382
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
25,061✔
383
    size = 0;
25,061✔
384
  }
385
  return size;
184,510✔
386
}
387

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

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

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

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

459
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
2,336✔
460
  pStreamPool->name = "vnode-stream";
2,336✔
461
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
2,336✔
462
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
2,336!
463

464
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
2,336✔
465
  pFPool->name = "vnode-fetch";
2,336✔
466
  pFPool->max = tsNumOfVnodeFetchThreads;
2,336✔
467
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
2,336!
468

469
  SSingleWorkerCfg mgmtCfg = {
2,336✔
470
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
471

472
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,336!
473

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

486
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
2,336!
487

488
  dDebug("vnode workers are initialized");
2,336✔
489
  return 0;
2,336✔
490
}
491

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