TDengine/source/dnode/vnode/src/vnd/vnodeQuery.c

151 lines
4.4 KiB
C
Raw Normal View History

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-26 11:04:26 +00:00
#include "vnd.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-04-24 05:24:55 +00:00
STableInfoReq infoReq = {0};
STableMetaRsp metaRsp = {0};
SMetaReader mer1 = {0};
SMetaReader mer2 = {0};
char tableFName[TSDB_TABLE_FNAME_LEN];
SRpcMsg rpcMsg;
int32_t code = 0;
int32_t rspLen = 0;
void *pRsp = NULL;
SSchemaWrapper schema = {0};
SSchemaWrapper schemaTag = {0};
2022-04-22 05:30:15 +00:00
// decode req
if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
code = TSDB_CODE_INVALID_MSG;
goto _exit;
}
2022-04-24 02:50:08 +00:00
metaRsp.dbId = pVnode->config.dbId;
2022-03-11 07:59:28 +00:00
strcpy(metaRsp.tbName, infoReq.tbName);
2022-04-22 06:25:59 +00:00
memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
2022-04-24 02:50:08 +00:00
2022-03-11 07:59:28 +00:00
sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
2022-04-23 10:50:26 +00:00
code = vnodeValidateTableHash(pVnode, tableFName);
2022-03-11 07:59:28 +00:00
if (code) {
goto _exit;
}
2022-04-22 06:25:59 +00:00
// query meta
2022-04-26 11:04:26 +00:00
metaReaderInit(&mer1, pVnode->pMeta, 0);
2021-12-28 05:58:53 +00:00
2022-04-24 05:24:55 +00:00
if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
2022-04-26 13:51:01 +00:00
code = terrno;
2021-12-31 06:02:48 +00:00
goto _exit;
2021-12-28 05:58:53 +00:00
}
2022-04-24 02:50:08 +00:00
metaRsp.tableType = mer1.me.type;
2022-04-22 06:25:59 +00:00
metaRsp.vgId = TD_VID(pVnode);
2022-04-24 02:50:08 +00:00
metaRsp.tuid = mer1.me.uid;
if (mer1.me.type == TSDB_SUPER_TABLE) {
2022-04-25 11:38:05 +00:00
strcpy(metaRsp.stbName, mer1.me.name);
2022-05-26 08:29:52 +00:00
schema = mer1.me.stbEntry.schemaRow;
2022-04-24 02:50:08 +00:00
schemaTag = mer1.me.stbEntry.schemaTag;
metaRsp.suid = mer1.me.uid;
} else if (mer1.me.type == TSDB_CHILD_TABLE) {
2022-04-26 11:04:26 +00:00
metaReaderInit(&mer2, pVnode->pMeta, 0);
2022-04-24 05:24:55 +00:00
if (metaGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
2022-04-24 02:50:08 +00:00
2022-04-25 11:38:05 +00:00
strcpy(metaRsp.stbName, mer2.me.name);
2022-04-24 02:50:08 +00:00
metaRsp.suid = mer2.me.uid;
2022-05-26 08:29:52 +00:00
schema = mer2.me.stbEntry.schemaRow;
2022-04-24 02:50:08 +00:00
schemaTag = mer2.me.stbEntry.schemaTag;
} else if (mer1.me.type == TSDB_NORMAL_TABLE) {
2022-05-26 08:29:52 +00:00
schema = mer1.me.ntbEntry.schemaRow;
2022-04-22 06:25:59 +00:00
} else {
ASSERT(0);
2021-12-30 07:05:49 +00:00
}
2022-04-24 02:50:08 +00:00
metaRsp.numOfTags = schemaTag.nCols;
metaRsp.numOfColumns = schema.nCols;
metaRsp.precision = pVnode->config.tsdbCfg.precision;
2022-05-26 08:29:52 +00:00
metaRsp.sversion = schema.version;
2022-04-24 02:50:08 +00:00
metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));
memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
if (schemaTag.nCols) {
memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
}
2022-04-22 06:25:59 +00:00
// encode and send response
2022-03-11 10:21:28 +00:00
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-04-26 13:51:01 +00:00
_exit:
2022-05-16 08:13:51 +00:00
rpcMsg.info = pMsg->info;
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-06-10 09:07:24 +00:00
if (code) {
qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code));
}
2022-03-29 09:15:48 +00:00
tmsgSendRsp(&rpcMsg);
2022-04-22 06:25:59 +00:00
2022-04-24 02:50:08 +00:00
taosMemoryFree(metaRsp.pSchemas);
2022-04-24 05:38:56 +00:00
metaReaderClear(&mer2);
metaReaderClear(&mer1);
2022-05-11 03:44:09 +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-05-08 14:22:47 +00:00
pLoad->syncState = syncGetMyRole(pVnode->sync);
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;
}
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
if (dbname) {
*dbname = pVnode->config.dbname;
}
if (vgId) {
*vgId = TD_VID(pVnode);
}
}