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

taosdata / TDengine / #3647

13 Mar 2025 05:26AM UTC coverage: 25.9% (-2.5%) from 28.375%
#3647

push

travis-ci

web-flow
Merge pull request #30158 from taosdata/docs/anchor-caps-30

docs: lowercase anchors for 3.0

53974 of 285572 branches covered (18.9%)

Branch coverage included in aggregate %.

92870 of 281392 relevant lines covered (33.0%)

617448.64 hits per line

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

31.89
/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http:www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "vmInt.h"
18
#include "vnodeInt.h"
19

20
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
36✔
21
  if (pMsg->info.handle == NULL) return;
36!
22
  SRpcMsg rsp = {
36✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
36✔
25
      .contLen = pMsg->info.rspLen,
36✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
36✔
29
}
30

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

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

43
  if (IsReq(pMsg)) {
20!
44
    if (code != 0) {
20!
45
      if (terrno != 0) code = terrno;
×
46
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
×
47
    }
48
    vmSendRsp(pMsg, code);
20✔
49
  }
50

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

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

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

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

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

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

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

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

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

140
static void vmProcessStreamCtrlQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
×
141
  SVnodeObj *pVnode = pInfo->ahandle;
×
142
  void      *pItem = NULL;
×
143
  int32_t    code = 0;
×
144

145
  while (1) {
×
146
    if (taosGetQitem(pQall, &pItem) == 0) {
×
147
      break;
×
148
    }
149

150
    SRpcMsg        *pMsg = pItem;
×
151
    const STraceId *trace = &pMsg->info.traceId;
×
152

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

162
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
163
    rpcFreeCont(pMsg->pCont);
×
164
    taosFreeQitem(pMsg);
×
165
  }
166
}
×
167

168
static void vmProcessStreamChkptQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
×
169
  SVnodeObj *pVnode = pInfo->ahandle;
×
170
  void      *pItem = NULL;
×
171
  int32_t    code = 0;
×
172

173
  while (1) {
×
174
    if (taosGetQitem(pQall, &pItem) == 0) {
×
175
      break;
×
176
    }
177

178
    SRpcMsg        *pMsg = pItem;
×
179
    const STraceId *trace = &pMsg->info.traceId;
×
180

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

190
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
191
    rpcFreeCont(pMsg->pCont);
×
192
    taosFreeQitem(pMsg);
×
193
  }
194
}
×
195

196
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
×
197
  SVnodeObj      *pVnode = pInfo->ahandle;
×
198
  const STraceId *trace = &pMsg->info.traceId;
×
199
  int32_t         code = 0;
×
200

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

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

211
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
212
  rpcFreeCont(pMsg->pCont);
×
213
  taosFreeQitem(pMsg);
×
214
}
×
215

216
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
×
217
  SVnodeObj *pVnode = pInfo->ahandle;
×
218
  SRpcMsg   *pMsg = NULL;
×
219

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

225
    terrno = 0;
×
226
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
×
227
    if (code != 0) {
×
228
      if (code == -1 && terrno != 0) {
×
229
        code = terrno;
×
230
      }
231

232
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
×
233
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
234
      } else {
235
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
236
      }
237

238
      vmSendRsp(pMsg, code);
×
239
    }
240

241
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
242
    rpcFreeCont(pMsg->pCont);
×
243
    taosFreeQitem(pMsg);
×
244
  }
245
}
×
246

247
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
×
248
  SVnodeObj *pVnode = pInfo->ahandle;
×
249
  SRpcMsg   *pMsg = NULL;
×
250

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

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

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

272
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
57✔
273
  STfs *pTfs = pVnode->pImpl->pTfs;
57✔
274
  if (pTfs) {
57!
275
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
57✔
276
  } else {
277
    return osDataSpaceSufficient();
×
278
  }
279
}
280

281
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
114✔
282
  *pNode = vmAcquireVnode(pMgt, vgId);
114✔
283
  if (*pNode == NULL) {
114✔
284
    return terrno;
17✔
285
  }
286
  return 0;
97✔
287
}
288
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
114✔
289
  int32_t         code = 0;
114✔
290
  const STraceId *trace = &pMsg->info.traceId;
114✔
291
  if (pMsg->contLen < sizeof(SMsgHead)) {
114!
292
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
293
            pMsg->contLen);
294
    return TSDB_CODE_INVALID_MSG;
×
295
  }
296

297
  SMsgHead *pHead = pMsg->pCont;
114✔
298

299
  pHead->contLen = ntohl(pHead->contLen);
114✔
300
  pHead->vgId = ntohl(pHead->vgId);
114✔
301

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

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

376
  vmReleaseVnode(pMgmt, pVnode);
97✔
377
  return code;
97✔
378
}
379

380
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
×
381

382
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
×
383

384
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
56✔
385

386
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
×
387

388
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
×
389

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

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

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

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

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

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

410
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
58✔
411
  int32_t code;
412
  if (pRpc->contLen < sizeof(SMsgHead)) {
58!
413
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
414
           pRpc->contLen);
415
    rpcFreeCont(pRpc->pCont);
×
416
    pRpc->pCont = NULL;
×
417
    return TSDB_CODE_INVALID_MSG;
×
418
  }
419

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

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

432
  pHead->contLen = htonl(pHead->contLen);
58✔
433
  pHead->vgId = htonl(pHead->vgId);
58✔
434
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
58✔
435
  pRpc->pCont = NULL;
58✔
436

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

444
  return code;
58✔
445
}
446

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

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

519
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
20✔
520
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
20✔
521

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

528
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
20!
529
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
20!
530
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
20!
531
    return TSDB_CODE_OUT_OF_MEMORY;
×
532
  }
533

534
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
20!
535
        taosQueueGetThreadId(pVnode->pWriteW.queue));
536
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
20!
537
        taosQueueGetThreadId(pVnode->pSyncW.queue));
538
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
20!
539
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
540
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
20!
541
        taosQueueGetThreadId(pVnode->pApplyW.queue));
542
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
20!
543
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
20!
544
        taosQueueGetThreadId(pVnode->pFetchQ));
545
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
20!
546
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
20!
547
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
20!
548
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
549
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
20!
550
        taosQueueGetThreadId(pVnode->pStreamChkQ));
551
  return 0;
20✔
552
}
553

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

564
  pVnode->pStreamQ = NULL;
20✔
565
  pVnode->pStreamCtrlQ = NULL;
20✔
566
  pVnode->pStreamLongExecQ = NULL;
20✔
567

568
  pVnode->pStreamChkQ = NULL;
20✔
569
  pVnode->pFetchQ = NULL;
20✔
570
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
20!
571
}
20✔
572

573
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
8✔
574
  int32_t code = 0;
8✔
575

576
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
8✔
577
  pQPool->name = "vnode-query";
8✔
578
  pQPool->min = tsNumOfVnodeQueryThreads;
8✔
579
  pQPool->max = tsNumOfVnodeQueryThreads;
8✔
580
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
8!
581

582
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
8✔
583

584
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
8✔
585
  pStreamPool->name = "vnode-stream";
8✔
586
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
8✔
587
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
8!
588

589
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
8✔
590
  pLongExecPool->name = "vnode-stream-long-exec";
8✔
591
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
8✔
592
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
8!
593

594
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
8✔
595
  pStreamCtrlPool->name = "vnode-stream-ctrl";
8✔
596
  pStreamCtrlPool->max = 1;
8✔
597
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
8!
598

599
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
8✔
600
  pStreamChkPool->name = "vnode-stream-chkpt";
8✔
601
  pStreamChkPool->max = 1;
8✔
602
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
8!
603

604
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
8✔
605
  pFPool->name = "vnode-fetch";
8✔
606
  pFPool->max = tsNumOfVnodeFetchThreads;
8✔
607
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
8!
608

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

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

614
  int32_t threadNum = 0;
8✔
615
  if (tsNumOfCores == 1) {
8!
616
    threadNum = 2;
×
617
  } else {
618
    threadNum = tsNumOfCores;
8✔
619
  }
620
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
8✔
621
                                   .max = threadNum,
622
                                   .name = "vnode-multi-mgmt",
623
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
624
                                   .param = pMgmt};
625

626
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
8!
627

628
  dDebug("vnode workers are initialized");
8!
629
  return 0;
8✔
630
}
631

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