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

taosdata / TDengine / #5072

17 May 2026 01:15AM UTC coverage: 73.298% (+10.2%) from 63.054%
#5072

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281314 of 383795 relevant lines covered (73.3%)

139475194.87 hits per line

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

83.11
/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) {
16,474,925✔
21
  if (pMsg->info.handle == NULL) return;
16,474,925✔
22
  SRpcMsg rsp = {
32,939,168✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
16,474,368✔
25
      .contLen = pMsg->info.rspLen,
16,473,570✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
16,474,188✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
3,675,706✔
37
  switch (pMsg->msgType) {
3,675,706✔
38
    case TDMT_DND_CREATE_VNODE:
3,672,095✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
3,672,095✔
40
      break;
3,673,579✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
1,208✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
1,208✔
44
      break;
1,208✔
45
    case TDMT_DND_MOUNT_VNODE:
1,376✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,376✔
47
      break;
1,376✔
48
#endif
49
  }
50

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,668,749✔
60
  rpcFreeCont(pMsg->pCont);
3,668,749✔
61
  taosFreeQitem(pMsg);
3,667,387✔
62
}
3,672,252✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
5,454,072✔
70
  switch (pMsg->msgType) {
5,454,072✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,937,111✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,937,111✔
76
      break;
1,937,111✔
77
    case TDMT_VND_ALTER_REPLICA:
767,603✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
767,603✔
79
      break;
767,603✔
80
    case TDMT_VND_DISABLE_WRITE:
30,190✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
30,190✔
82
      break;
30,190✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,837✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,837✔
85
      break;
3,837✔
86
    case TDMT_VND_ALTER_HASHRANGE:
29,393✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
29,393✔
88
      break;
29,393✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
2,393,624✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
2,393,624✔
91
      break;
2,393,624✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
122,426✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
122,426✔
97
      break;
122,426✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
29,956✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
29,956✔
100
      break;
29,956✔
101
    case TDMT_DND_QUERY_COMPACT_PROGRESS:
139,932✔
102
      code = vmProcessDnodeQueryCompactProgressReq(pMgmt, pMsg);
139,932✔
103
      break;
139,932✔
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)) {
5,454,072✔
110
    if (code != 0) {
5,454,072✔
111
      if (terrno != 0) code = terrno;
2,282,560✔
112
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
2,282,560✔
113
    }
114
    vmSendRsp(pMsg, code);
5,454,072✔
115
  }
116

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

122
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
821,144,670✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
821,144,670✔
124
  const STraceId *trace = &pMsg->info.traceId;
821,166,614✔
125

126
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
821,173,748✔
127
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
821,174,789✔
128
  if (code != 0) {
821,017,182✔
129
    if (terrno != 0) code = terrno;
6,486,868✔
130
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
6,486,868✔
131
    vmSendRsp(pMsg, code);
6,487,602✔
132
  }
133

134
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
821,015,745✔
135
  rpcFreeCont(pMsg->pCont);
821,015,745✔
136
  taosFreeQitem(pMsg);
821,044,769✔
137
}
821,003,753✔
138

139
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
1,249,422,594✔
140
  SVnodeObj *pVnode = pInfo->ahandle;
1,249,422,594✔
141
  SRpcMsg   *pMsg = NULL;
1,249,475,468✔
142

143
  for (int32_t i = 0; i < numOfMsgs; ++i) {
2,147,483,647✔
144
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,264,605,606✔
145
    const STraceId *trace = &pMsg->info.traceId;
1,264,461,585✔
146
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
1,264,706,431✔
147

148
    terrno = 0;
1,264,709,312✔
149
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
1,264,773,563✔
150
    if (code != 0) {
1,264,715,641✔
151
      if (code == -1 && terrno != 0) {
857,139✔
152
        code = terrno;
×
153
      }
154

155
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
857,139✔
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());
857,139✔
159
      }
160

161
      vmSendRsp(pMsg, code);
857,139✔
162
    }
163

164
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
1,264,715,641✔
165
    rpcFreeCont(pMsg->pCont);
1,264,715,641✔
166
    taosFreeQitem(pMsg);
1,264,728,666✔
167
  }
168
}
1,249,631,773✔
169

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

175
  terrno = 0;
68,331,003✔
176
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg, pInfo);
68,331,735✔
177
  if (code != 0) {
68,324,541✔
178
    if (code == -1 && terrno != 0) {
156,914✔
179
      code = terrno;
×
180
    }
181

182
    if (code == 0) {
156,914✔
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());
156,914✔
186
    }
187
  }
188

189
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
68,324,541✔
190
  rpcFreeCont(pMsg->pCont);
68,324,541✔
191
  taosFreeQitem(pMsg);
68,324,021✔
192
}
68,327,379✔
193

194
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
738,851,372✔
195
  SVnodeObj *pVnode = pInfo->ahandle;
738,851,372✔
196
  SRpcMsg   *pMsg = NULL;
738,854,621✔
197

198
  for (int32_t i = 0; i < numOfMsgs; ++i) {
2,147,483,647✔
199
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,489,687,228✔
200
    const STraceId *trace = &pMsg->info.traceId;
1,489,679,038✔
201
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
1,489,687,551✔
202

203
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
1,489,687,551✔
204
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,489,680,638✔
205
    rpcFreeCont(pMsg->pCont);
1,489,680,638✔
206
    taosFreeQitem(pMsg);
1,489,635,480✔
207
  }
208
}
738,824,409✔
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) {
924,544,613✔
220
  STfs *pTfs = pVnode->pImpl->pTfs;
924,544,613✔
221
  if (pTfs) {
924,580,059✔
222
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
924,580,059✔
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;
16,752,113✔
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,
16,752,113✔
253
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
254
    return code;
16,751,924✔
255
  }
256

257
  switch (qtype) {
2,147,483,647✔
258
    case QUERY_QUEUE:
820,845,729✔
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);
820,845,729✔
262
      if (code) {
820,869,476✔
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));
820,869,476✔
266
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
820,869,671✔
267
      }
268
      break;
821,039,243✔
269
    case FETCH_QUEUE:
1,263,927,234✔
270
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,263,927,234✔
271
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
1,263,927,234✔
272
      break;
1,264,743,117✔
273
    case WRITE_QUEUE:
924,523,171✔
274
      if (!vmDataSpaceSufficient(pVnode)) {
924,523,171✔
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) {
924,538,989✔
289
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
139,131✔
290
               TMSG_INFO(pMsg->msgType));
291
        code = TSDB_CODE_VND_STOPPED;
139,131✔
292
        break;
139,131✔
293
      }
294
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
924,378,520✔
295
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
924,380,937✔
296
      break;
924,443,022✔
297
    case SYNC_QUEUE:
1,444,845,210✔
298
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,444,845,210✔
299
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
1,444,845,210✔
300
      break;
1,444,963,322✔
301
    case SYNC_RD_QUEUE:
44,709,370✔
302
      if(tsSyncLogHeartbeat){
44,709,370✔
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));
44,709,370✔
307
      }
308
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
44,709,370✔
309
      break;
44,726,717✔
310
    case APPLY_QUEUE:
826,776,219✔
311
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
826,776,219✔
312
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
826,776,392✔
313
      break;
826,783,822✔
314
    case STREAM_READER_QUEUE:
68,308,213✔
315
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
68,308,213✔
316
              TMSG_INFO(pMsg->msgType));
317
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
68,312,443✔
318
      break;
68,327,926✔
319
    default:
13✔
320
      code = TSDB_CODE_INVALID_MSG;
13✔
321
      break;
13✔
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); }
44,940,374✔
329

330
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
1,227,694,679✔
331

332
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
923,340,561✔
333

334
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
756,235,731✔
335

336
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
1,264,429,174✔
337

338
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
68,349,221✔
339

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

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

352
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
1,126,419,562✔
353
  int32_t code;
354
  if (pRpc->contLen < sizeof(SMsgHead)) {
1,126,419,562✔
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;
1,126,440,335✔
363
  SRpcMsg *pMsg;
1,126,428,649✔
364
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
1,126,442,183✔
365
  if (code) {
1,126,355,924✔
366
    rpcFreeCont(pRpc->pCont);
×
367
    pRpc->pCont = NULL;
×
368
    return code;
×
369
  }
370

371
  SMsgHead *pHead = pRpc->pCont;
1,126,355,924✔
372
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
1,126,363,696✔
373

374
  pHead->contLen = htonl(pHead->contLen);
1,126,363,696✔
375
  pHead->vgId = htonl(pHead->vgId);
1,126,368,880✔
376
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
1,126,365,487✔
377
  pRpc->pCont = NULL;
1,126,365,487✔
378

379
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
1,126,434,694✔
380
  if (code != 0) {
1,126,442,462✔
381
    dTrace("msg:%p, is freed", pMsg);
1,728,128✔
382
    rpcFreeCont(pMsg->pCont);
1,728,128✔
383
    taosFreeQitem(pMsg);
1,728,128✔
384
  }
385

386
  return code;
1,126,433,673✔
387
}
388

389
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
21,624,870✔
390
  int32_t    size = -1;
21,624,870✔
391
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
21,624,870✔
392
  if (pVnode != NULL) {
21,653,770✔
393
    switch (qtype) {
11,742,190✔
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:
11,742,190✔
401
        size = taosQueueItemSize(pVnode->pApplyW.queue);
11,742,190✔
402
        break;
11,744,616✔
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);
21,656,196✔
417
  if (size < 0) {
21,633,882✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
9,884,987✔
419
    size = 0;
9,882,560✔
420
  }
421
  return size;
21,631,455✔
422
}
423

424
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,952,631✔
425
  int32_t         code = 0;
4,952,631✔
426
  SMultiWorkerCfg wcfg = {.max = 1,
4,952,631✔
427
                          .name = "vnode-write",
428
                          .fp = (FItems)vnodeProposeWriteMsg,
429
                          .param = pVnode->pImpl,
4,952,631✔
430
                          .threadCategory = THREAD_CAT_WRITE};
431
  SMultiWorkerCfg scfg = {.max = 1,
4,950,204✔
432
                          .name = "vnode-sync",
433
                          .fp = (FItems)vmProcessSyncQueue,
434
                          .param = pVnode,
435
                          .threadCategory = THREAD_CAT_WRITE};
436
  SMultiWorkerCfg sccfg = {.max = 1,
4,948,483✔
437
                           .name = "vnode-sync-rd",
438
                           .fp = (FItems)vmProcessSyncQueue,
439
                           .param = pVnode,
440
                           .threadCategory = THREAD_CAT_WRITE};
441
  SMultiWorkerCfg acfg = {.max = 1,
4,945,468✔
442
                          .name = "vnode-apply",
443
                          .fp = (FItems)vnodeApplyWriteMsg,
444
                          .param = pVnode->pImpl,
4,946,039✔
445
                          .threadCategory = THREAD_CAT_WRITE};
446
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
4,948,624✔
447
  if (code) {
4,956,549✔
448
    return code;
×
449
  }
450
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
4,956,549✔
451
  if (code) {
4,956,549✔
452
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
453
    return code;
×
454
  }
455
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
4,956,549✔
456
  if (code) {
4,956,549✔
457
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
458
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
459
    return code;
×
460
  }
461
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
4,956,549✔
462
  if (code) {
4,956,549✔
463
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
464
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
465
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
466
    return code;
×
467
  }
468

469
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
4,956,549✔
470
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
4,956,209✔
471
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
4,956,549✔
472

473
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
4,956,549✔
474
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
4,956,549✔
475
    return TSDB_CODE_OUT_OF_MEMORY;
×
476
  }
477

478
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
4,956,549✔
479
        taosQueueGetThreadId(pVnode->pWriteW.queue));
480
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
4,956,549✔
481
        taosQueueGetThreadId(pVnode->pSyncW.queue));
482
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
4,956,549✔
483
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
484
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
4,956,549✔
485
        taosQueueGetThreadId(pVnode->pApplyW.queue));
486
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
4,956,549✔
487
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
4,956,549✔
488
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
4,956,549✔
489
        taosQueueGetThreadId(pVnode->pFetchQ));
490
  return 0;
4,956,549✔
491
}
492

493
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,956,157✔
494
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
4,956,157✔
495
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
4,956,549✔
496
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
4,956,549✔
497

498
  pVnode->pQueryQ = NULL;
4,956,330✔
499
  pVnode->pFetchQ = NULL;
4,956,549✔
500
  pVnode->pStreamReaderQ = NULL;
4,956,330✔
501
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
4,955,516✔
502
}
4,955,516✔
503

504
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
724,244✔
505
  int32_t code = 0;
724,244✔
506

507
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
724,244✔
508
  pQPool->name = "vnode-query";
724,244✔
509
  pQPool->min = tsNumOfVnodeQueryThreads;
724,244✔
510
  pQPool->max = tsNumOfVnodeQueryThreads;
724,244✔
511
  pQPool->threadCategory = THREAD_CAT_READ;
724,244✔
512
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
724,244✔
513

514
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
724,244✔
515
  pSPool->name = "vnode-st-reader";
724,244✔
516
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
724,244✔
517
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
724,244✔
518
  pSPool->threadCategory = THREAD_CAT_READ;
724,244✔
519
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
724,244✔
520

521
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
724,244✔
522

523
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
724,244✔
524
  pFPool->name = "vnode-fetch";
724,244✔
525
  pFPool->max = tsNumOfVnodeFetchThreads;
724,244✔
526
  pFPool->threadCategory = THREAD_CAT_READ;
724,244✔
527
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
724,244✔
528

529
  SSingleWorkerCfg mgmtCfg = {.min = 1,
724,244✔
530
                              .max = 1,
531
                              .name = "vnode-mgmt",
532
                              .fp = (FItem)vmProcessMgmtQueue,
533
                              .param = pMgmt,
534
                              .threadCategory = THREAD_CAT_WRITE};
535

536
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
724,244✔
537

538
  int32_t threadNum = 0;
724,244✔
539
  if (tsNumOfCores == 1) {
724,244✔
540
    threadNum = 2;
×
541
  } else {
542
    threadNum = tsNumOfCores;
724,244✔
543
  }
544
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
724,244✔
545
                                   .max = threadNum,
546
                                   .name = "vnode-multi-mgmt",
547
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
548
                                   .param = pMgmt,
549
                                   .threadCategory = THREAD_CAT_WRITE};
550

551
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
724,244✔
552
  dDebug("vnode workers are initialized");
724,244✔
553
  return 0;
724,244✔
554
}
555

556
void vmStopWorker(SVnodeMgmt *pMgmt) {
724,244✔
557
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
724,244✔
558
  tWWorkerCleanup(&pMgmt->fetchPool);
724,244✔
559
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
724,244✔
560
  dDebug("vnode workers are closed");
724,244✔
561
}
724,244✔
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