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

taosdata / TDengine / #5038

29 Apr 2026 11:44AM UTC coverage: 73.151% (-0.008%) from 73.159%
#5038

push

travis-ci

web-flow
feat(statewindow): support multi columns (#35136)

1554 of 1828 new or added lines in 18 files covered. (85.01%)

7333 existing lines in 152 files now uncovered.

277490 of 379338 relevant lines covered (73.15%)

134410214.73 hits per line

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

82.07
/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) {
13,095,844✔
21
  if (pMsg->info.handle == NULL) return;
13,095,844✔
22
  SRpcMsg rsp = {
26,187,916✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
13,098,282✔
25
      .contLen = pMsg->info.rspLen,
13,098,447✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
13,098,447✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
3,382,250✔
37
  switch (pMsg->msgType) {
3,382,250✔
38
    case TDMT_DND_CREATE_VNODE:
3,380,473✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
3,380,473✔
40
      break;
3,380,142✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
1,030✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
1,030✔
44
      break;
1,030✔
45
    case TDMT_DND_MOUNT_VNODE:
1,176✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,176✔
47
      break;
1,176✔
48
#endif
49
  }
50

51
  if (IsReq(pMsg)) {
3,381,919✔
52
    if (code != 0) {
3,382,679✔
53
      if (terrno != 0) code = terrno;
736✔
54
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
736✔
55
    }
56
    vmSendRsp(pMsg, code);
3,382,679✔
57
  }
58

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,382,155✔
60
  rpcFreeCont(pMsg->pCont);
3,382,155✔
61
  taosFreeQitem(pMsg);
3,381,401✔
62
}
3,382,470✔
63

64
static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
4,942,844✔
65
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
4,942,844✔
66
  int32_t         code = -1;
4,942,844✔
67
  const STraceId *trace = &pMsg->info.traceId;
4,942,844✔
68

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,942,844✔
70
  switch (pMsg->msgType) {
4,942,844✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,788,642✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,788,642✔
76
      break;
1,788,642✔
77
    case TDMT_VND_ALTER_REPLICA:
705,317✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
705,317✔
79
      break;
705,317✔
80
    case TDMT_VND_DISABLE_WRITE:
27,195✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
27,195✔
82
      break;
27,195✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,609✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,609✔
85
      break;
3,609✔
86
    case TDMT_VND_ALTER_HASHRANGE:
26,434✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
26,434✔
88
      break;
26,434✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
2,114,261✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
2,114,261✔
91
      break;
2,114,261✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
125,321✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
125,321✔
97
      break;
125,321✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
27,398✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
27,398✔
100
      break;
27,398✔
101
    case TDMT_DND_QUERY_COMPACT_PROGRESS:
124,667✔
102
      code = vmProcessDnodeQueryCompactProgressReq(pMgmt, pMsg);
124,667✔
103
      break;
124,667✔
104
    default:
×
105
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
106
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
107
  }
108

109
  if (IsReq(pMsg)) {
4,942,844✔
110
    if (code != 0) {
4,942,844✔
111
      if (terrno != 0) code = terrno;
2,012,532✔
112
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
2,012,532✔
113
    }
114
    vmSendRsp(pMsg, code);
4,942,844✔
115
  }
116

117
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
4,942,844✔
118
  rpcFreeCont(pMsg->pCont);
4,942,844✔
119
  taosFreeQitem(pMsg);
4,942,844✔
120
}
4,942,844✔
121

122
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
731,295,798✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
731,295,798✔
124
  const STraceId *trace = &pMsg->info.traceId;
731,304,474✔
125

126
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
731,304,672✔
127
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
731,304,672✔
128
  if (code != 0) {
731,236,823✔
129
    if (terrno != 0) code = terrno;
3,963,662✔
130
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
3,963,326✔
131
    vmSendRsp(pMsg, code);
3,964,318✔
132
  }
133

134
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
731,236,483✔
135
  rpcFreeCont(pMsg->pCont);
731,236,483✔
136
  taosFreeQitem(pMsg);
731,233,340✔
137
}
731,237,462✔
138

139
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
1,072,988,494✔
140
  SVnodeObj *pVnode = pInfo->ahandle;
1,072,988,494✔
141
  SRpcMsg   *pMsg = NULL;
1,073,006,540✔
142

143
  for (int32_t i = 0; i < numOfMsgs; ++i) {
2,147,483,647✔
144
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,114,279,248✔
145
    const STraceId *trace = &pMsg->info.traceId;
1,114,332,491✔
146
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
1,114,377,152✔
147

148
    terrno = 0;
1,114,379,446✔
149
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
1,114,377,232✔
150
    if (code != 0) {
1,114,431,688✔
151
      if (code == -1 && terrno != 0) {
809,262✔
152
        code = terrno;
×
153
      }
154

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

161
      vmSendRsp(pMsg, code);
809,262✔
162
    }
163

164
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
1,114,431,688✔
165
    rpcFreeCont(pMsg->pCont);
1,114,431,688✔
166
    taosFreeQitem(pMsg);
1,114,415,849✔
167
  }
168
}
1,073,016,068✔
169

170
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
56,591,351✔
171
  SVnodeObj *pVnode = pInfo->ahandle;
56,591,351✔
172
  const STraceId *trace = &pMsg->info.traceId;
56,591,582✔
173
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
56,591,161✔
174

175
  terrno = 0;
56,591,161✔
176
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg, pInfo);
56,591,409✔
177
  if (code != 0) {
56,588,708✔
178
    if (code == -1 && terrno != 0) {
135,220✔
179
      code = terrno;
×
180
    }
181

182
    if (code == 0) {
135,220✔
183
      dGDebug("vgId:%d, msg:%p, success to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
×
184
    } else {
185
      dGError("vgId:%d, msg:%p, failed to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
135,220✔
186
    }
187
  }
188

189
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
56,588,708✔
190
  rpcFreeCont(pMsg->pCont);
56,589,232✔
191
  taosFreeQitem(pMsg);
56,588,395✔
192
}
56,588,231✔
193

194
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
559,274,965✔
195
  SVnodeObj *pVnode = pInfo->ahandle;
559,274,965✔
196
  SRpcMsg   *pMsg = NULL;
559,276,704✔
197

198
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,664,165,453✔
199
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,104,890,755✔
200
    const STraceId *trace = &pMsg->info.traceId;
1,104,885,537✔
201
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
1,104,886,929✔
202

203
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
1,104,887,365✔
204
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,104,882,808✔
205
    rpcFreeCont(pMsg->pCont);
1,104,884,223✔
206
    taosFreeQitem(pMsg);
1,104,860,907✔
207
  }
208
}
559,279,859✔
209

210
static void vmSendResponse(SRpcMsg *pMsg) {
×
211
  if (pMsg->info.handle) {
×
212
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
213
    if (rpcSendResponse(&rsp) != 0) {
×
214
      dError("failed to send response since %s", terrstr());
×
215
    }
216
  }
217
}
×
218

219
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
784,689,033✔
220
  STfs *pTfs = pVnode->pImpl->pTfs;
784,689,033✔
221
  if (pTfs) {
784,705,312✔
222
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
784,705,312✔
223
  } else {
224
    return osDataSpaceSufficient();
×
225
  }
226
}
227

228
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
2,147,483,647✔
229
  *pNode = vmAcquireVnode(pMgt, vgId);
2,147,483,647✔
230
  if (*pNode == NULL) {
2,147,483,647✔
231
    return terrno;
12,904,985✔
232
  }
233
  return 0;
2,147,483,647✔
234
}
235
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
2,147,483,647✔
236
  int32_t         code = 0;
2,147,483,647✔
237
  SMsgHead *      pHead = pMsg->pCont;
2,147,483,647✔
238
  SVnodeObj *     pVnode = NULL;
2,147,483,647✔
239
  const STraceId *trace = &pMsg->info.traceId;
2,147,483,647✔
240

241
  if (pMsg->contLen < sizeof(SMsgHead)) {
2,147,483,647✔
242
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
243
            pMsg->contLen);
244
    return TSDB_CODE_INVALID_MSG;
×
245
  }
246

247
  pHead->contLen = ntohl(pHead->contLen);
2,147,483,647✔
248
  pHead->vgId = ntohl(pHead->vgId);
2,147,483,647✔
249
  
250
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
2,147,483,647✔
251
  if (code != 0) {
2,147,483,647✔
252
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
12,904,985✔
253
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
254
    return code;
12,904,985✔
255
  }
256

257
  switch (qtype) {
2,147,483,647✔
258
    case QUERY_QUEUE:
731,217,874✔
259
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
260
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
261
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
731,217,874✔
262
      if (code) {
731,166,474✔
263
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
264
      } else {
265
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
731,166,474✔
266
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
731,166,601✔
267
      }
268
      break;
731,215,831✔
269
    case FETCH_QUEUE:
1,114,239,226✔
270
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,114,239,226✔
271
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
1,114,239,226✔
272
      break;
1,114,450,948✔
273
    case WRITE_QUEUE:
784,683,896✔
274
      if (!vmDataSpaceSufficient(pVnode)) {
784,683,896✔
275
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
276
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
277
               tstrerror(code), TMSG_INFO(pMsg->msgType));
278
        break;
×
279
      }
280
#if 0
281
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
282
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
284
               tstrerror(code), TMSG_INFO(pMsg->msgType));
285
        break;
286
      }
287
#endif
288
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
784,682,466✔
289
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
171,798✔
290
               TMSG_INFO(pMsg->msgType));
291
        code = TSDB_CODE_VND_STOPPED;
171,798✔
292
        break;
171,798✔
293
      }
294
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
784,496,162✔
295
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
784,496,789✔
296
      break;
784,544,584✔
297
    case SYNC_QUEUE:
1,054,113,955✔
298
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,054,113,955✔
299
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
1,054,113,955✔
300
      break;
1,054,211,593✔
301
    case SYNC_RD_QUEUE:
50,669,822✔
302
      if(tsSyncLogHeartbeat){
50,669,822✔
303
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
304
      }
305
      else{
306
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
50,669,822✔
307
      }
308
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
50,669,822✔
309
      break;
50,679,681✔
310
    case APPLY_QUEUE:
612,181,277✔
311
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
612,181,277✔
312
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
612,181,277✔
313
      break;
612,181,048✔
314
    case STREAM_READER_QUEUE:
56,585,402✔
315
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
56,585,402✔
316
              TMSG_INFO(pMsg->msgType));
317
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
56,586,440✔
318
      break;
56,587,454✔
UNCOV
319
    default:
×
UNCOV
320
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
321
      break;
×
322
  }
323

324
  vmReleaseVnode(pMgmt, pVnode);
2,147,483,647✔
325
  return code;
2,147,483,647✔
326
}
327

328
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
51,023,643✔
329

330
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
863,987,713✔
331

332
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
783,651,305✔
333

334
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
686,497,876✔
335

336
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
1,114,395,462✔
337

338
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
56,611,617✔
339

340
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
3,382,264✔
341
  const STraceId *trace = &pMsg->info.traceId;
3,382,264✔
342
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
3,382,679✔
343
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
3,382,679✔
344
}
345

346
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
4,941,415✔
347
  const STraceId *trace = &pMsg->info.traceId;
4,941,415✔
348
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
4,942,844✔
349
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
4,942,844✔
350
}
351

352
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
860,573,891✔
353
  int32_t code;
354
  if (pRpc->contLen < sizeof(SMsgHead)) {
860,573,891✔
355
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
356
           pRpc->contLen);
357
    rpcFreeCont(pRpc->pCont);
×
358
    pRpc->pCont = NULL;
×
359
    return TSDB_CODE_INVALID_MSG;
×
360
  }
361

362
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
860,583,074✔
363
  SRpcMsg *pMsg;
860,571,497✔
364
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
860,582,260✔
365
  if (code) {
860,567,486✔
366
    rpcFreeCont(pRpc->pCont);
×
367
    pRpc->pCont = NULL;
×
368
    return code;
×
369
  }
370

371
  SMsgHead *pHead = pRpc->pCont;
860,567,486✔
372
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
860,568,179✔
373

374
  pHead->contLen = htonl(pHead->contLen);
860,568,179✔
375
  pHead->vgId = htonl(pHead->vgId);
860,564,724✔
376
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
860,568,710✔
377
  pRpc->pCont = NULL;
860,568,710✔
378

379
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
860,583,524✔
380
  if (code != 0) {
860,579,207✔
381
    dTrace("msg:%p, is freed", pMsg);
1,763,706✔
382
    rpcFreeCont(pMsg->pCont);
1,763,706✔
383
    taosFreeQitem(pMsg);
1,763,706✔
384
  }
385

386
  return code;
860,583,351✔
387
}
388

389
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
20,018,467✔
390
  int32_t    size = -1;
20,018,467✔
391
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
20,018,467✔
392
  if (pVnode != NULL) {
20,020,594✔
393
    switch (qtype) {
10,956,160✔
394
      case WRITE_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
396
        break;
×
397
      case SYNC_QUEUE:
×
398
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
399
        break;
×
400
      case APPLY_QUEUE:
10,956,160✔
401
        size = taosQueueItemSize(pVnode->pApplyW.queue);
10,956,160✔
402
        break;
10,955,629✔
403
      case QUERY_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pQueryQ);
×
405
        break;
×
406
      case FETCH_QUEUE:
×
407
        size = taosQueueItemSize(pVnode->pFetchQ);
×
408
        break;
×
409
      case STREAM_READER_QUEUE:
×
410
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
411
        break;
×
412
      default:
×
413
        break;
×
414
    }
415
  }
416
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
20,020,063✔
417
  if (size < 0) {
20,018,913✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
9,059,536✔
419
    size = 0;
9,059,204✔
420
  }
421
  return size;
20,018,581✔
422
}
423

424
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,536,813✔
425
  int32_t         code = 0;
4,536,813✔
426
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
4,536,813✔
427
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
4,536,813✔
428
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
4,537,572✔
429
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
4,536,346✔
430
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
4,537,105✔
431
  if (code) {
4,538,948✔
432
    return code;
×
433
  }
434
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
4,538,948✔
435
  if (code) {
4,538,948✔
436
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
437
    return code;
×
438
  }
439
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
4,538,948✔
440
  if (code) {
4,538,948✔
441
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
442
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
443
    return code;
×
444
  }
445
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
4,538,948✔
446
  if (code) {
4,538,849✔
447
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
448
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
449
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
450
    return code;
×
451
  }
452

453
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
4,538,849✔
454
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
4,538,948✔
455
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
4,538,948✔
456

457
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
4,538,948✔
458
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
4,538,948✔
459
    return TSDB_CODE_OUT_OF_MEMORY;
×
460
  }
461

462
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
4,538,948✔
463
        taosQueueGetThreadId(pVnode->pWriteW.queue));
464
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
4,538,948✔
465
        taosQueueGetThreadId(pVnode->pSyncW.queue));
466
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
4,538,948✔
467
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
468
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
4,538,948✔
469
        taosQueueGetThreadId(pVnode->pApplyW.queue));
470
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
4,538,948✔
471
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
4,538,948✔
472
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
4,538,948✔
473
        taosQueueGetThreadId(pVnode->pFetchQ));
474
  return 0;
4,538,948✔
475
}
476

477
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,538,645✔
478
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
4,538,645✔
479
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
4,538,948✔
480
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
4,538,948✔
481

482
  pVnode->pQueryQ = NULL;
4,538,948✔
483
  pVnode->pFetchQ = NULL;
4,538,948✔
484
  pVnode->pStreamReaderQ = NULL;
4,538,948✔
485
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
4,538,948✔
486
}
4,538,948✔
487

488
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
662,044✔
489
  int32_t code = 0;
662,044✔
490

491
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
662,044✔
492
  pQPool->name = "vnode-query";
662,044✔
493
  pQPool->min = tsNumOfVnodeQueryThreads;
662,044✔
494
  pQPool->max = tsNumOfVnodeQueryThreads;
662,044✔
495
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
662,044✔
496

497
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
662,044✔
498
  pSPool->name = "vnode-st-reader";
662,044✔
499
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
662,044✔
500
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
662,044✔
501
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
662,044✔
502

503
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
662,044✔
504

505
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
662,044✔
506
  pFPool->name = "vnode-fetch";
662,044✔
507
  pFPool->max = tsNumOfVnodeFetchThreads;
662,044✔
508
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
662,044✔
509

510
  SSingleWorkerCfg mgmtCfg = {
662,044✔
511
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
512

513
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
662,044✔
514

515
  int32_t threadNum = 0;
662,044✔
516
  if (tsNumOfCores == 1) {
662,044✔
517
    threadNum = 2;
×
518
  } else {
519
    threadNum = tsNumOfCores;
662,044✔
520
  }
521
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
662,044✔
522
                                   .max = threadNum,
523
                                   .name = "vnode-multi-mgmt",
524
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
525
                                   .param = pMgmt};
526

527
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
662,044✔
528
  dDebug("vnode workers are initialized");
662,044✔
529
  return 0;
662,044✔
530
}
531

532
void vmStopWorker(SVnodeMgmt *pMgmt) {
662,044✔
533
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
662,044✔
534
  tWWorkerCleanup(&pMgmt->fetchPool);
662,044✔
535
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
662,044✔
536
  dDebug("vnode workers are closed");
662,044✔
537
}
662,044✔
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