TDengine/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c

427 lines
15 KiB
C
Raw Normal View History

2022-03-14 05:24:15 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http:www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
2022-03-16 11:39:43 +00:00
#include "vmInt.h"
#include "vnodeInt.h"
2022-03-14 05:24:15 +00:00
2022-05-16 07:17:11 +00:00
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
2022-06-09 01:46:01 +00:00
if (pMsg->info.handle == NULL) return;
2022-05-08 14:20:53 +00:00
SRpcMsg rsp = {
.code = code,
2022-05-16 07:17:11 +00:00
.pCont = pMsg->info.rsp,
.contLen = pMsg->info.rspLen,
2022-05-20 04:48:15 +00:00
.info = pMsg->info,
2022-05-08 14:20:53 +00:00
};
2022-04-02 09:22:19 +00:00
tmsgSendRsp(&rsp);
2022-03-21 07:13:30 +00:00
}
2022-06-02 09:43:03 +00:00
static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2022-06-22 01:50:53 +00:00
SVnodeMgmt *pMgmt = pInfo->ahandle;
int32_t code = -1;
const STraceId *trace = &pMsg->info.traceId;
2022-03-22 08:10:26 +00:00
2022-06-18 09:23:55 +00:00
dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
2022-05-20 04:48:15 +00:00
switch (pMsg->msgType) {
2022-03-21 06:12:20 +00:00
case TDMT_DND_CREATE_VNODE:
code = vmProcessCreateVnodeReq(pMgmt, pMsg);
break;
case TDMT_DND_DROP_VNODE:
code = vmProcessDropVnodeReq(pMgmt, pMsg);
break;
2022-10-20 08:47:03 +00:00
case TDMT_VND_ALTER_REPLICA:
2023-01-30 08:33:17 +00:00
code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
2022-10-20 08:47:03 +00:00
break;
2023-01-30 05:54:15 +00:00
case TDMT_VND_DISABLE_WRITE:
code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
break;
2023-01-30 08:33:17 +00:00
case TDMT_VND_ALTER_HASHRANGE:
code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
break;
2023-04-18 11:03:45 +00:00
case TDMT_DND_ALTER_VNODE_TYPE:
code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
break;
2023-07-18 08:09:38 +00:00
case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
break;
case TDMT_VND_ARB_HEARTBEAT:
code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
break;
2022-03-21 06:12:20 +00:00
default:
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
2022-06-22 01:50:53 +00:00
dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
2022-03-21 06:12:20 +00:00
}
2022-05-20 04:48:15 +00:00
if (IsReq(pMsg)) {
2022-06-08 06:44:42 +00:00
if (code != 0) {
if (terrno != 0) code = terrno;
2023-05-05 10:57:15 +00:00
dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
2022-06-02 09:43:03 +00:00
}
2022-05-08 14:20:53 +00:00
vmSendRsp(pMsg, code);
2022-03-21 06:12:20 +00:00
}
2022-06-22 01:50:53 +00:00
dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
2022-05-16 07:17:11 +00:00
rpcFreeCont(pMsg->pCont);
2022-03-21 06:12:20 +00:00
taosFreeQitem(pMsg);
}
2022-05-16 07:17:11 +00:00
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2022-06-22 01:50:53 +00:00
SVnodeObj *pVnode = pInfo->ahandle;
const STraceId *trace = &pMsg->info.traceId;
2022-03-22 08:10:26 +00:00
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
2022-05-16 07:17:11 +00:00
int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg);
2022-03-21 07:13:30 +00:00
if (code != 0) {
2022-05-08 14:20:53 +00:00
if (terrno != 0) code = terrno;
2023-05-20 04:20:54 +00:00
dGError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
2022-05-08 14:20:53 +00:00
vmSendRsp(pMsg, code);
2022-03-21 07:13:30 +00:00
}
2022-06-02 09:43:03 +00:00
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2022-05-20 07:58:25 +00:00
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
2022-03-18 11:43:09 +00:00
}
2022-03-16 02:48:22 +00:00
2022-07-13 08:26:22 +00:00
static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2022-06-22 01:50:53 +00:00
SVnodeObj *pVnode = pInfo->ahandle;
const STraceId *trace = &pMsg->info.traceId;
2022-03-22 08:10:26 +00:00
2022-07-13 08:26:22 +00:00
dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
int32_t code = vnodeProcessStreamMsg(pVnode->pImpl, pMsg, pInfo);
2022-03-21 07:13:30 +00:00
if (code != 0) {
2022-05-08 14:20:53 +00:00
if (terrno != 0) code = terrno;
2023-01-03 03:18:48 +00:00
dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
terrstr(code));
2022-05-08 14:20:53 +00:00
vmSendRsp(pMsg, code);
2022-03-21 07:13:30 +00:00
}
2022-06-02 09:43:03 +00:00
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2022-05-20 07:58:25 +00:00
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
2022-03-21 06:39:35 +00:00
}
2022-07-11 09:52:30 +00:00
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SVnodeObj *pVnode = pInfo->ahandle;
SRpcMsg *pMsg = NULL;
2022-03-22 08:10:26 +00:00
2022-07-11 09:52:30 +00:00
for (int32_t i = 0; i < numOfMsgs; ++i) {
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
const STraceId *trace = &pMsg->info.traceId;
dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
2022-06-02 09:43:03 +00:00
2023-08-07 03:29:54 +00:00
terrno = 0;
2022-07-11 09:52:30 +00:00
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
if (code != 0) {
2023-08-07 03:29:54 +00:00
if (code == -1 && terrno != 0) {
2023-04-26 09:58:23 +00:00
code = terrno;
}
if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
} else {
dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
}
2022-07-11 09:52:30 +00:00
vmSendRsp(pMsg, code);
}
dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2022-07-11 09:52:30 +00:00
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
}
2022-03-21 06:39:35 +00:00
}
2022-03-22 08:10:26 +00:00
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SVnodeObj *pVnode = pInfo->ahandle;
2022-06-20 11:53:48 +00:00
SRpcMsg *pMsg = NULL;
2022-03-16 02:48:22 +00:00
for (int32_t i = 0; i < numOfMsgs; ++i) {
2022-06-02 09:43:03 +00:00
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
2022-06-22 01:50:53 +00:00
const STraceId *trace = &pMsg->info.traceId;
dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
2022-03-16 02:48:22 +00:00
2022-07-05 11:22:01 +00:00
int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL); // no response here
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2022-05-16 07:17:11 +00:00
rpcFreeCont(pMsg->pCont);
2022-05-09 07:17:33 +00:00
taosFreeQitem(pMsg);
2022-03-16 02:48:22 +00:00
}
}
static void vmSendResponse(SRpcMsg *pMsg) {
if (pMsg->info.handle) {
SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
rpcSendResponse(&rsp);
}
}
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
STfs *pTfs = pVnode->pImpl->pTfs;
if (pTfs) {
return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
} else {
return osDataSpaceSufficient();
}
}
2022-06-02 09:43:03 +00:00
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
2022-06-22 01:50:53 +00:00
const STraceId *trace = &pMsg->info.traceId;
if (pMsg->contLen < sizeof(SMsgHead)) {
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
pMsg->contLen);
return -1;
}
2023-01-03 03:18:48 +00:00
SMsgHead *pHead = pMsg->pCont;
int32_t code = 0;
2022-05-08 14:20:53 +00:00
2022-03-24 06:37:53 +00:00
pHead->contLen = ntohl(pHead->contLen);
pHead->vgId = ntohl(pHead->vgId);
2022-03-16 02:48:22 +00:00
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
if (pVnode == NULL) {
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
terrno = (terrno != 0) ? terrno : -1;
return terrno;
2022-03-16 02:48:22 +00:00
}
2022-03-21 06:12:20 +00:00
switch (qtype) {
2022-03-21 11:49:20 +00:00
case QUERY_QUEUE:
code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
if (code) {
dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, terrstr(code));
} else {
dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pQueryQ, pMsg);
}
2022-03-21 06:12:20 +00:00
break;
2022-07-13 08:26:22 +00:00
case STREAM_QUEUE:
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pStreamQ, pMsg);
2022-07-13 08:26:22 +00:00
break;
2022-03-21 11:49:20 +00:00
case FETCH_QUEUE:
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
2022-03-28 09:25:12 +00:00
taosWriteQitem(pVnode->pFetchQ, pMsg);
2022-03-21 06:12:20 +00:00
break;
2022-03-21 11:49:20 +00:00
case WRITE_QUEUE:
if (!vmDataSpaceSufficient(pVnode)) {
terrno = TSDB_CODE_NO_ENOUGH_DISKSPACE;
2022-08-03 12:17:53 +00:00
code = terrno;
2022-08-11 03:14:31 +00:00
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code));
2023-01-30 05:54:15 +00:00
break;
}
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
2022-07-18 05:22:21 +00:00
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
code = terrno;
2022-08-11 03:14:31 +00:00
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code));
2023-01-30 05:54:15 +00:00
break;
}
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
terrno = TSDB_CODE_VND_STOPPED;
code = terrno;
2023-01-30 05:54:15 +00:00
break;
2022-07-18 05:22:21 +00:00
}
2023-01-30 05:54:15 +00:00
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pWriteW.queue, pMsg);
2022-03-21 11:49:20 +00:00
break;
case SYNC_QUEUE:
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pSyncW.queue, pMsg);
2022-03-21 11:49:20 +00:00
break;
case SYNC_RD_QUEUE:
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
break;
2022-06-02 09:43:03 +00:00
case APPLY_QUEUE:
2022-06-22 01:50:53 +00:00
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pApplyW.queue, pMsg);
2022-06-02 09:43:03 +00:00
break;
2022-03-21 06:12:20 +00:00
default:
2022-03-28 09:25:12 +00:00
code = -1;
2022-03-21 06:12:20 +00:00
terrno = TSDB_CODE_INVALID_PARA;
break;
}
2022-03-18 11:43:09 +00:00
vmReleaseVnode(pMgmt, pVnode);
return code;
2022-03-16 02:48:22 +00:00
}
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
2022-03-18 11:43:09 +00:00
2022-06-02 09:43:03 +00:00
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
2022-06-02 09:43:03 +00:00
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
2022-03-16 02:48:22 +00:00
2022-06-02 09:43:03 +00:00
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
2022-03-16 02:48:22 +00:00
2022-06-02 09:43:03 +00:00
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
2022-03-18 11:43:09 +00:00
2022-07-13 08:26:22 +00:00
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
2022-06-02 09:43:03 +00:00
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
2022-06-22 01:50:53 +00:00
const STraceId *trace = &pMsg->info.traceId;
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
2022-06-02 09:43:03 +00:00
taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
2022-03-28 09:25:12 +00:00
return 0;
2022-03-16 02:48:22 +00:00
}
2022-06-02 10:26:29 +00:00
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
if (pRpc->contLen < sizeof(SMsgHead)) {
dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
pRpc->contLen);
rpcFreeCont(pRpc->pCont);
pRpc->pCont = NULL;
return -1;
}
2022-12-10 06:02:57 +00:00
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
2022-07-05 09:38:21 +00:00
if (pMsg == NULL) {
2022-09-23 11:55:46 +00:00
rpcFreeCont(pRpc->pCont);
2022-07-05 09:38:21 +00:00
pRpc->pCont = NULL;
return -1;
}
2022-05-08 14:20:53 +00:00
2022-06-02 09:43:03 +00:00
SMsgHead *pHead = pRpc->pCont;
2022-12-10 07:09:55 +00:00
dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
2022-06-02 11:12:52 +00:00
2022-06-02 09:43:03 +00:00
pHead->contLen = htonl(pHead->contLen);
pHead->vgId = htonl(pHead->vgId);
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
pRpc->pCont = NULL;
2022-07-05 09:38:21 +00:00
int32_t code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
if (code != 0) {
dTrace("msg:%p, is freed", pMsg);
rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg);
2022-07-05 09:38:21 +00:00
}
return code;
2022-03-16 02:48:22 +00:00
}
2022-05-11 10:23:08 +00:00
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
2022-03-22 07:53:29 +00:00
int32_t size = -1;
2022-05-11 10:23:08 +00:00
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
if (pVnode != NULL) {
2022-03-22 07:53:29 +00:00
switch (qtype) {
case WRITE_QUEUE:
size = taosQueueItemSize(pVnode->pWriteW.queue);
2022-03-22 07:53:29 +00:00
break;
case SYNC_QUEUE:
size = taosQueueItemSize(pVnode->pSyncW.queue);
2022-03-22 07:53:29 +00:00
break;
case APPLY_QUEUE:
size = taosQueueItemSize(pVnode->pApplyW.queue);
2022-03-22 07:53:29 +00:00
break;
2022-05-08 14:20:53 +00:00
case QUERY_QUEUE:
size = taosQueueItemSize(pVnode->pQueryQ);
2022-05-08 14:20:53 +00:00
break;
case FETCH_QUEUE:
size = taosQueueItemSize(pVnode->pFetchQ);
2022-05-08 14:20:53 +00:00
break;
2022-07-13 08:26:22 +00:00
case STREAM_QUEUE:
size = taosQueueItemSize(pVnode->pStreamQ);
break;
2022-03-22 07:53:29 +00:00
default:
break;
}
}
if (pVnode) vmReleaseVnode(pMgmt, pVnode);
2022-10-25 07:55:19 +00:00
if (size < 0) {
2022-11-16 07:45:40 +00:00
dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
2022-10-25 07:55:19 +00:00
size = 0;
}
2022-03-22 07:53:29 +00:00
return size;
}
2022-05-11 10:23:08 +00:00
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
(void)tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
(void)tMultiWorkerInit(&pVnode->pSyncW, &scfg);
(void)tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
(void)tMultiWorkerInit(&pVnode->pApplyW, &acfg);
2022-03-16 06:32:02 +00:00
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
2022-07-11 09:52:30 +00:00
pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
2022-03-16 02:48:22 +00:00
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
2022-03-16 02:48:22 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
2024-02-27 08:27:59 +00:00
taosQueueGetThreadId(pVnode->pWriteW.queue));
dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
2024-02-27 08:27:59 +00:00
taosQueueGetThreadId(pVnode->pSyncW.queue));
dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
2024-02-27 08:27:59 +00:00
taosQueueGetThreadId(pVnode->pSyncRdW.queue));
dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
2024-02-27 08:27:59 +00:00
taosQueueGetThreadId(pVnode->pApplyW.queue));
2022-11-04 02:27:36 +00:00
dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
2024-02-27 08:27:59 +00:00
taosQueueGetThreadId(pVnode->pFetchQ));
2022-11-04 02:27:36 +00:00
dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
2022-03-16 02:48:22 +00:00
return 0;
}
2022-05-11 10:23:08 +00:00
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
2022-05-08 14:20:53 +00:00
tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
2022-07-11 09:52:30 +00:00
tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
2022-03-16 02:48:22 +00:00
pVnode->pQueryQ = NULL;
2022-07-13 08:26:22 +00:00
pVnode->pStreamQ = NULL;
2022-05-08 14:20:53 +00:00
pVnode->pFetchQ = NULL;
2022-05-20 03:47:08 +00:00
dDebug("vgId:%d, queue is freed", pVnode->vgId);
2022-03-16 10:20:57 +00:00
}
2022-05-11 10:23:08 +00:00
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
2022-03-16 02:48:22 +00:00
SQWorkerPool *pQPool = &pMgmt->queryPool;
pQPool->name = "vnode-query";
2022-04-07 07:43:47 +00:00
pQPool->min = tsNumOfVnodeQueryThreads;
pQPool->max = tsNumOfVnodeQueryThreads;
2022-03-16 02:48:22 +00:00
if (tQWorkerInit(pQPool) != 0) return -1;
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
2022-07-13 08:26:22 +00:00
pStreamPool->name = "vnode-stream";
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
2022-07-13 08:26:22 +00:00
2022-07-11 09:52:30 +00:00
SWWorkerPool *pFPool = &pMgmt->fetchPool;
2022-03-16 02:48:22 +00:00
pFPool->name = "vnode-fetch";
2022-04-07 07:43:47 +00:00
pFPool->max = tsNumOfVnodeFetchThreads;
2022-07-11 09:52:30 +00:00
if (tWWorkerInit(pFPool) != 0) return -1;
2022-03-16 02:48:22 +00:00
2022-06-02 09:43:03 +00:00
SSingleWorkerCfg mgmtCfg = {
2024-01-11 03:50:52 +00:00
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
2022-06-02 09:43:03 +00:00
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
2022-03-16 10:20:57 +00:00
2022-03-24 11:59:37 +00:00
dDebug("vnode workers are initialized");
2022-03-16 02:48:22 +00:00
return 0;
}
2022-05-11 10:23:08 +00:00
void vmStopWorker(SVnodeMgmt *pMgmt) {
2022-05-08 14:20:53 +00:00
tQWorkerCleanup(&pMgmt->queryPool);
tAutoQWorkerCleanup(&pMgmt->streamPool);
2022-07-11 09:52:30 +00:00
tWWorkerCleanup(&pMgmt->fetchPool);
2022-03-24 11:59:37 +00:00
dDebug("vnode workers are closed");
2022-03-16 02:48:22 +00:00
}