2021-12-24 01:41:09 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-08 06:01:01 +00:00
|
|
|
#include "vnodeInt.h"
|
2021-12-24 01:41:09 +00:00
|
|
|
|
2022-01-21 10:19:40 +00:00
|
|
|
int vnodeQueryOpen(SVnode *pVnode) {
|
2022-04-16 07:50:05 +00:00
|
|
|
return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), NULL, (void **)&pVnode->pQuery, &pVnode->msgCb);
|
2022-01-21 10:19:40 +00:00
|
|
|
}
|
2021-12-24 01:41:09 +00:00
|
|
|
|
2022-03-18 08:39:51 +00:00
|
|
|
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
|
2022-03-09 08:13:46 +00:00
|
|
|
|
2022-04-14 08:42:50 +00:00
|
|
|
int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
2022-03-08 09:22:21 +00:00
|
|
|
STbCfg *pTbCfg = NULL;
|
|
|
|
|
STbCfg *pStbCfg = NULL;
|
2021-12-30 07:05:49 +00:00
|
|
|
tb_uid_t uid;
|
|
|
|
|
int32_t nCols;
|
|
|
|
|
int32_t nTagCols;
|
2022-01-25 05:42:33 +00:00
|
|
|
SSchemaWrapper *pSW = NULL;
|
|
|
|
|
STableMetaRsp *pTbMetaMsg = NULL;
|
2022-02-15 08:46:21 +00:00
|
|
|
STableMetaRsp metaRsp = {0};
|
|
|
|
|
SSchema *pTagSchema;
|
2021-12-31 06:02:48 +00:00
|
|
|
SRpcMsg rpcMsg;
|
2021-12-31 06:43:13 +00:00
|
|
|
int msgLen = 0;
|
2022-03-11 10:21:28 +00:00
|
|
|
int32_t code = 0;
|
2022-03-11 07:59:28 +00:00
|
|
|
char tableFName[TSDB_TABLE_FNAME_LEN];
|
2022-03-11 10:21:28 +00:00
|
|
|
int32_t rspLen = 0;
|
|
|
|
|
void *pRsp = NULL;
|
2021-12-28 05:58:53 +00:00
|
|
|
|
2022-02-15 08:46:21 +00:00
|
|
|
STableInfoReq infoReq = {0};
|
|
|
|
|
if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
|
2022-03-11 10:21:28 +00:00
|
|
|
code = TSDB_CODE_INVALID_MSG;
|
2022-02-15 08:46:21 +00:00
|
|
|
goto _exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 07:59:28 +00:00
|
|
|
metaRsp.dbId = pVnode->config.dbId;
|
|
|
|
|
memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
|
|
|
|
|
strcpy(metaRsp.tbName, infoReq.tbName);
|
|
|
|
|
|
|
|
|
|
sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
|
|
|
|
|
code = vnodeValidateTableHash(&pVnode->config, tableFName);
|
|
|
|
|
if (code) {
|
|
|
|
|
goto _exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-15 08:46:21 +00:00
|
|
|
pTbCfg = metaGetTbInfoByName(pVnode->pMeta, infoReq.tbName, &uid);
|
2021-12-30 07:05:49 +00:00
|
|
|
if (pTbCfg == NULL) {
|
2022-01-12 07:51:34 +00:00
|
|
|
code = TSDB_CODE_VND_TB_NOT_EXIST;
|
2021-12-31 06:02:48 +00:00
|
|
|
goto _exit;
|
2021-12-30 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
|
|
|
|
pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid);
|
|
|
|
|
if (pStbCfg == NULL) {
|
2022-02-11 11:52:07 +00:00
|
|
|
code = TSDB_CODE_VND_TB_NOT_EXIST;
|
2021-12-31 06:02:48 +00:00
|
|
|
goto _exit;
|
2021-12-30 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pSW = metaGetTableSchema(pVnode->pMeta, pTbCfg->ctbCfg.suid, 0, true);
|
|
|
|
|
} else {
|
|
|
|
|
pSW = metaGetTableSchema(pVnode->pMeta, uid, 0, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nCols = pSW->nCols;
|
|
|
|
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
2022-04-20 08:50:45 +00:00
|
|
|
// nTagCols = pTbCfg->stbCfg.nTagCols;
|
|
|
|
|
// pTagSchema = pTbCfg->stbCfg.pTagSchema;
|
2022-01-04 07:39:08 +00:00
|
|
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
2022-04-20 08:50:45 +00:00
|
|
|
// nTagCols = pStbCfg->stbCfg.nTagCols;
|
|
|
|
|
// pTagSchema = pStbCfg->stbCfg.pTagSchema;
|
2021-12-30 07:05:49 +00:00
|
|
|
} else {
|
|
|
|
|
nTagCols = 0;
|
|
|
|
|
pTagSchema = NULL;
|
2021-12-28 05:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 16:29:53 +00:00
|
|
|
metaRsp.pSchemas = taosMemoryCalloc(nCols + nTagCols, sizeof(SSchema));
|
2022-02-15 07:24:27 +00:00
|
|
|
if (metaRsp.pSchemas == NULL) {
|
2022-02-11 11:52:07 +00:00
|
|
|
code = TSDB_CODE_VND_OUT_OF_MEMORY;
|
2021-12-31 06:02:48 +00:00
|
|
|
goto _exit;
|
2021-12-28 05:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-30 07:05:49 +00:00
|
|
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
2022-02-15 07:24:27 +00:00
|
|
|
strcpy(metaRsp.stbName, pStbCfg->name);
|
|
|
|
|
metaRsp.suid = pTbCfg->ctbCfg.suid;
|
2022-01-07 01:56:11 +00:00
|
|
|
} else if (pTbCfg->type == META_SUPER_TABLE) {
|
2022-02-15 07:24:27 +00:00
|
|
|
strcpy(metaRsp.stbName, pTbCfg->name);
|
|
|
|
|
metaRsp.suid = uid;
|
2021-12-30 07:05:49 +00:00
|
|
|
}
|
2022-02-15 07:24:27 +00:00
|
|
|
metaRsp.numOfTags = nTagCols;
|
|
|
|
|
metaRsp.numOfColumns = nCols;
|
|
|
|
|
metaRsp.tableType = pTbCfg->type;
|
|
|
|
|
metaRsp.tuid = uid;
|
2022-04-16 07:50:05 +00:00
|
|
|
metaRsp.vgId = TD_VID(pVnode);
|
2021-12-30 07:05:49 +00:00
|
|
|
|
2022-02-15 07:24:27 +00:00
|
|
|
memcpy(metaRsp.pSchemas, pSW->pSchema, sizeof(SSchema) * pSW->nCols);
|
2021-12-30 07:05:49 +00:00
|
|
|
if (nTagCols) {
|
2022-02-15 07:24:27 +00:00
|
|
|
memcpy(POINTER_SHIFT(metaRsp.pSchemas, sizeof(SSchema) * pSW->nCols), pTagSchema, sizeof(SSchema) * nTagCols);
|
2021-12-30 07:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-11 10:21:28 +00:00
|
|
|
_exit:
|
|
|
|
|
|
|
|
|
|
rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
|
2022-02-15 07:24:27 +00:00
|
|
|
if (rspLen < 0) {
|
|
|
|
|
code = TSDB_CODE_INVALID_MSG;
|
|
|
|
|
goto _exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 10:21:28 +00:00
|
|
|
pRsp = rpcMallocCont(rspLen);
|
2022-02-15 07:24:27 +00:00
|
|
|
if (pRsp == NULL) {
|
|
|
|
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
goto _exit;
|
2021-12-30 07:05:49 +00:00
|
|
|
}
|
2022-02-15 08:46:21 +00:00
|
|
|
tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
|
2021-12-28 05:58:53 +00:00
|
|
|
|
2022-02-15 07:24:27 +00:00
|
|
|
tFreeSTableMetaRsp(&metaRsp);
|
2022-01-25 05:42:33 +00:00
|
|
|
if (pSW != NULL) {
|
2022-03-25 16:29:53 +00:00
|
|
|
taosMemoryFreeClear(pSW->pSchema);
|
|
|
|
|
taosMemoryFreeClear(pSW);
|
2022-01-24 06:44:19 +00:00
|
|
|
}
|
2022-01-25 05:42:33 +00:00
|
|
|
|
|
|
|
|
if (pTbCfg) {
|
2022-03-25 16:29:53 +00:00
|
|
|
taosMemoryFreeClear(pTbCfg->name);
|
2022-01-25 05:42:33 +00:00
|
|
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
2022-04-20 08:50:45 +00:00
|
|
|
// taosMemoryFree(pTbCfg->stbCfg.pTagSchema);
|
2022-01-25 05:42:33 +00:00
|
|
|
} else if (pTbCfg->type == META_SUPER_TABLE) {
|
|
|
|
|
kvRowFree(pTbCfg->ctbCfg.pTag);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 16:29:53 +00:00
|
|
|
taosMemoryFreeClear(pTbCfg);
|
2022-01-25 05:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 06:43:13 +00:00
|
|
|
rpcMsg.handle = pMsg->handle;
|
|
|
|
|
rpcMsg.ahandle = pMsg->ahandle;
|
2022-02-15 07:24:27 +00:00
|
|
|
rpcMsg.pCont = pRsp;
|
|
|
|
|
rpcMsg.contLen = rspLen;
|
2021-12-31 06:43:13 +00:00
|
|
|
rpcMsg.code = code;
|
2021-12-31 05:34:38 +00:00
|
|
|
|
2022-03-29 09:15:48 +00:00
|
|
|
tmsgSendRsp(&rpcMsg);
|
2022-03-21 08:43:27 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
2021-12-30 09:13:02 +00:00
|
|
|
}
|
2022-04-14 08:42:50 +00:00
|
|
|
|
|
|
|
|
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
2022-04-16 07:50:05 +00:00
|
|
|
pLoad->vgId = TD_VID(pVnode);
|
2022-04-19 13:39:42 +00:00
|
|
|
pLoad->syncState = TAOS_SYNC_STATE_LEADER;
|
2022-04-14 08:42:50 +00:00
|
|
|
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
|
|
|
|
pLoad->numOfTimeSeries = 400;
|
|
|
|
|
pLoad->totalStorage = 300;
|
|
|
|
|
pLoad->compStorage = 200;
|
|
|
|
|
pLoad->pointsWritten = 100;
|
|
|
|
|
pLoad->numOfSelectReqs = 1;
|
|
|
|
|
pLoad->numOfInsertReqs = 3;
|
|
|
|
|
pLoad->numOfInsertSuccessReqs = 2;
|
|
|
|
|
pLoad->numOfBatchInsertReqs = 5;
|
|
|
|
|
pLoad->numOfBatchInsertSuccessReqs = 4;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|