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

704 lines
20 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
#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType, tags) \
do { \
int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal)); \
ASSERT(newVal >= 0); \
if (newVal < 0) { \
vWarn("vgId:%d, %s, abnormal val:%" PRIi64 ", old val:%" PRIi64, TD_VID(pVnode), tags, newVal, (oVal)); \
} \
2022-10-11 09:47:23 +00:00
} while (0)
2022-01-21 10:19:40 +00:00
int vnodeQueryOpen(SVnode *pVnode) {
2022-09-05 05:56:42 +00:00
return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), (void **)&pVnode->pQuery, &pVnode->msgCb);
2022-01-21 10:19:40 +00:00
}
2021-12-24 01:41:09 +00:00
2022-11-11 10:44:59 +00:00
void vnodeQueryPreClose(SVnode *pVnode) { qWorkerStopAllTasks((void *)pVnode->pQuery); }
2022-11-11 09:13:55 +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-07-26 10:00:50 +00:00
int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
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];
2022-07-04 12:03:20 +00:00
SRpcMsg rpcMsg = {0};
2022-04-24 05:24:55 +00:00
int32_t code = 0;
int32_t rspLen = 0;
void *pRsp = NULL;
2022-04-24 05:24:55 +00:00
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
metaReaderDoInit(&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) {
metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
if (metaReaderGetTableEntryByUid(&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;
2023-01-30 10:26:42 +00:00
metaRsp.tversion = schemaTag.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-07-26 10:00:50 +00:00
if (direct) {
pRsp = rpcMallocCont(rspLen);
} else {
pRsp = taosMemoryCalloc(1, 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;
2022-07-04 12:03:20 +00:00
rpcMsg.msgType = pMsg->msgType;
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-07-26 10:00:50 +00:00
if (direct) {
tmsgSendRsp(&rpcMsg);
} else {
*pMsg = rpcMsg;
2022-07-26 10:00:50 +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
2022-07-26 10:00:50 +00:00
int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
2022-06-20 05:32:21 +00:00
STableCfgReq cfgReq = {0};
STableCfgRsp cfgRsp = {0};
SMetaReader mer1 = {0};
SMetaReader mer2 = {0};
char tableFName[TSDB_TABLE_FNAME_LEN];
2022-07-04 12:03:20 +00:00
SRpcMsg rpcMsg = {0};
2022-06-20 05:32:21 +00:00
int32_t code = 0;
int32_t rspLen = 0;
void *pRsp = NULL;
2022-06-20 05:32:21 +00:00
SSchemaWrapper schema = {0};
SSchemaWrapper schemaTag = {0};
// decode req
if (tDeserializeSTableCfgReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
code = TSDB_CODE_INVALID_MSG;
goto _exit;
}
strcpy(cfgRsp.tbName, cfgReq.tbName);
memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
sprintf(tableFName, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
code = vnodeValidateTableHash(pVnode, tableFName);
if (code) {
goto _exit;
}
// query meta
metaReaderDoInit(&mer1, pVnode->pMeta, 0);
2022-06-20 05:32:21 +00:00
if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
code = terrno;
goto _exit;
}
cfgRsp.tableType = mer1.me.type;
if (mer1.me.type == TSDB_SUPER_TABLE) {
2022-06-20 12:58:36 +00:00
code = TSDB_CODE_VND_HASH_MISMATCH;
goto _exit;
2022-06-20 05:32:21 +00:00
} else if (mer1.me.type == TSDB_CHILD_TABLE) {
metaReaderDoInit(&mer2, pVnode->pMeta, 0);
if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
2022-06-20 05:32:21 +00:00
strcpy(cfgRsp.stbName, mer2.me.name);
schema = mer2.me.stbEntry.schemaRow;
schemaTag = mer2.me.stbEntry.schemaTag;
2022-06-20 12:58:36 +00:00
cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
if (mer1.me.ctbEntry.commentLen > 0) {
cfgRsp.pComment = taosStrdup(mer1.me.ctbEntry.comment);
2022-06-20 12:58:36 +00:00
}
STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
cfgRsp.tagsLen = pTag->len;
cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
2022-06-20 05:32:21 +00:00
} else if (mer1.me.type == TSDB_NORMAL_TABLE) {
schema = mer1.me.ntbEntry.schemaRow;
2022-06-20 12:58:36 +00:00
cfgRsp.ttl = mer1.me.ntbEntry.ttlDays;
cfgRsp.commentLen = mer1.me.ntbEntry.commentLen;
if (mer1.me.ntbEntry.commentLen > 0) {
cfgRsp.pComment = taosStrdup(mer1.me.ntbEntry.comment);
2022-06-20 12:58:36 +00:00
}
2022-06-20 05:32:21 +00:00
} else {
ASSERT(0);
}
cfgRsp.numOfTags = schemaTag.nCols;
cfgRsp.numOfColumns = schema.nCols;
cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
2022-06-20 05:32:21 +00:00
memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
if (schemaTag.nCols) {
memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
}
// encode and send response
rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
if (rspLen < 0) {
code = TSDB_CODE_INVALID_MSG;
goto _exit;
}
2022-07-26 10:00:50 +00:00
if (direct) {
pRsp = rpcMallocCont(rspLen);
} else {
pRsp = taosMemoryCalloc(1, rspLen);
}
2022-06-20 05:32:21 +00:00
if (pRsp == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
_exit:
rpcMsg.info = pMsg->info;
rpcMsg.pCont = pRsp;
rpcMsg.contLen = rspLen;
rpcMsg.code = code;
2022-07-04 12:03:20 +00:00
rpcMsg.msgType = pMsg->msgType;
2022-06-20 05:32:21 +00:00
if (code) {
qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
}
2022-07-26 10:00:50 +00:00
if (direct) {
tmsgSendRsp(&rpcMsg);
} else {
*pMsg = rpcMsg;
2022-07-26 10:00:50 +00:00
}
2022-06-20 12:58:36 +00:00
tFreeSTableCfgRsp(&cfgRsp);
2022-06-20 05:32:21 +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
2023-01-30 10:26:42 +00:00
static FORCE_INLINE void vnodeFreeSBatchRspMsg(void *p) {
2022-11-17 02:35:25 +00:00
if (NULL == p) {
return;
}
2023-01-30 10:26:42 +00:00
SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
2022-11-17 02:35:25 +00:00
rpcFreeCont(pRsp->msg);
}
2022-07-26 10:00:50 +00:00
int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
2023-01-30 10:26:42 +00:00
int32_t code = 0;
int32_t rspSize = 0;
SBatchReq batchReq = {0};
SBatchMsg *req = NULL;
2022-11-17 02:35:25 +00:00
SBatchRspMsg rsp = {0};
2023-01-30 10:26:42 +00:00
SBatchRsp batchRsp = {0};
SRpcMsg reqMsg = *pMsg;
SRpcMsg rspMsg = {0};
void *pRsp = NULL;
2022-07-26 10:00:50 +00:00
2022-11-17 02:35:25 +00:00
if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
code = TSDB_CODE_OUT_OF_MEMORY;
qError("tDeserializeSBatchReq failed");
goto _exit;
}
2023-01-30 10:26:42 +00:00
int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
2022-10-17 11:48:36 +00:00
if (msgNum >= MAX_META_MSG_IN_BATCH) {
code = TSDB_CODE_INVALID_MSG;
qError("too many msgs %d in vnode batch meta req", msgNum);
goto _exit;
}
2022-11-17 02:35:25 +00:00
batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
if (NULL == batchRsp.pRsps) {
2022-07-26 10:00:50 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
2022-11-17 06:09:15 +00:00
qError("taosArrayInit %d SBatchRspMsg failed", msgNum);
2022-07-26 10:00:50 +00:00
goto _exit;
}
2022-07-26 10:00:50 +00:00
for (int32_t i = 0; i < msgNum; ++i) {
2022-11-17 02:35:25 +00:00
req = taosArrayGet(batchReq.pMsgs, i);
reqMsg.msgType = req->msgType;
reqMsg.pCont = req->msg;
reqMsg.contLen = req->msgLen;
switch (req->msgType) {
2022-07-26 10:00:50 +00:00
case TDMT_VND_TABLE_META:
vnodeGetTableMeta(pVnode, &reqMsg, false);
break;
case TDMT_VND_TABLE_CFG:
vnodeGetTableCfg(pVnode, &reqMsg, false);
break;
default:
2022-11-17 02:35:25 +00:00
qError("invalid req msgType %d", req->msgType);
2022-07-26 10:00:50 +00:00
reqMsg.code = TSDB_CODE_INVALID_MSG;
reqMsg.pCont = NULL;
reqMsg.contLen = 0;
break;
}
2022-11-17 02:35:25 +00:00
rsp.msgIdx = req->msgIdx;
2022-07-26 10:00:50 +00:00
rsp.reqType = reqMsg.msgType;
rsp.msgLen = reqMsg.contLen;
rsp.rspCode = reqMsg.code;
rsp.msg = reqMsg.pCont;
2022-11-17 02:35:25 +00:00
taosArrayPush(batchRsp.pRsps, &rsp);
2022-07-26 10:00:50 +00:00
}
2022-11-17 02:35:25 +00:00
rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
if (rspSize < 0) {
2022-11-17 06:09:15 +00:00
qError("tSerializeSBatchRsp failed");
2022-11-17 02:35:25 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
2022-10-18 08:33:27 +00:00
goto _exit;
}
2022-07-26 10:00:50 +00:00
pRsp = rpcMallocCont(rspSize);
if (pRsp == NULL) {
2022-11-17 06:09:15 +00:00
qError("rpcMallocCont %d failed", rspSize);
2022-07-26 10:00:50 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
2022-11-17 06:09:15 +00:00
if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
qError("tSerializeSBatchRsp %d failed", rspSize);
2022-11-17 02:35:25 +00:00
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
2022-07-26 10:00:50 +00:00
}
_exit:
rspMsg.info = pMsg->info;
rspMsg.pCont = pRsp;
rspMsg.contLen = rspSize;
rspMsg.code = code;
rspMsg.msgType = pMsg->msgType;
if (code) {
2022-07-27 06:02:05 +00:00
qError("vnd get batch meta failed cause of %s", tstrerror(code));
2022-07-26 10:00:50 +00:00
}
2022-11-17 08:31:22 +00:00
taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
2022-11-17 06:09:15 +00:00
taosArrayDestroyEx(batchRsp.pRsps, tFreeSBatchRspMsg);
2022-07-26 10:00:50 +00:00
tmsgSendRsp(&rspMsg);
2022-07-27 06:02:05 +00:00
return code;
2022-07-26 10:00:50 +00:00
}
2022-10-11 10:22:29 +00:00
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
2022-11-02 02:24:55 +00:00
SSyncState state = syncGetState(pVnode->sync);
2022-10-11 09:47:23 +00:00
pLoad->vgId = TD_VID(pVnode);
2022-11-02 02:24:55 +00:00
pLoad->syncState = state.state;
pLoad->syncRestore = state.restored;
2023-08-15 02:10:06 +00:00
pLoad->syncTerm = state.term;
pLoad->roleTimeMs = state.roleTimeMs;
pLoad->startTimeMs = state.startTimeMs;
pLoad->syncCanRead = state.canRead;
2023-07-18 08:09:38 +00:00
pLoad->learnerProgress = state.progress;
2022-10-11 09:47:23 +00:00
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
2023-03-22 08:08:16 +00:00
pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
2022-10-11 09:47:23 +00:00
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
2023-09-19 00:29:51 +00:00
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
2022-10-11 09:47:23 +00:00
pLoad->totalStorage = (int64_t)3 * 1073741824;
pLoad->compStorage = (int64_t)2 * 1073741824;
pLoad->pointsWritten = 100;
pLoad->numOfSelectReqs = 1;
pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
pLoad->numOfInsertSuccessReqs = atomic_load_64(&pVnode->statis.nInsertSuccess);
pLoad->numOfBatchInsertReqs = atomic_load_64(&pVnode->statis.nBatchInsert);
pLoad->numOfBatchInsertSuccessReqs = atomic_load_64(&pVnode->statis.nBatchInsertSuccess);
return 0;
}
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
SSyncState syncState = syncGetState(pVnode->sync);
if (syncState.state == TAOS_SYNC_STATE_LEADER) {
pLoad->vgId = TD_VID(pVnode);
pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
return 0;
}
return -1;
}
2022-10-11 10:22:29 +00:00
/**
* @brief Reset the statistics value by monitor interval
*
* @param pVnode
* @param pLoad
*/
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
2023-01-30 10:26:42 +00:00
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64,
"nBatchInsertSuccess");
2022-10-11 10:22:29 +00:00
}
2023-07-10 11:55:01 +00:00
void vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId, int64_t* numOfTables, int64_t* numOfNormalTables) {
SVnode* pVnodeObj = pVnode;
SVnodeCfg* pConf = &pVnodeObj->config;
if (dbname) {
*dbname = pConf->dbname;
}
if (vgId) {
*vgId = TD_VID(pVnodeObj);
}
if (numOfTables) {
*numOfTables = pConf->vndStats.numOfNTables + pConf->vndStats.numOfCTables;
}
if (numOfNormalTables) {
*numOfNormalTables = pConf->vndStats.numOfNTables;
}
2022-06-20 02:38:08 +00:00
}
2023-07-10 11:55:01 +00:00
int32_t vnodeGetTableList(void* pVnode, int8_t type, SArray* pList) {
2023-05-25 09:51:03 +00:00
if (type == TSDB_SUPER_TABLE) {
return vnodeGetStbIdList(pVnode, 0, pList);
} else {
return TSDB_CODE_INVALID_PARA;
}
}
2022-06-20 02:38:08 +00:00
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
2023-08-11 09:52:52 +00:00
SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
2022-06-20 02:38:08 +00:00
while (1) {
tb_uid_t id = metaCtbCursorNext(pCur);
if (id == 0) {
break;
}
STableKeyInfo info = {uid = id};
2022-06-20 02:38:08 +00:00
taosArrayPush(list, &info);
}
metaCloseCtbCursor(pCur);
2022-06-20 02:38:08 +00:00
return TSDB_CODE_SUCCESS;
}
2022-09-28 14:07:16 +00:00
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg) {
return 0;
}
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
SVnode *pVnodeObj = pVnode;
2023-08-11 09:52:52 +00:00
SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
2022-06-20 02:38:08 +00:00
while (1) {
tb_uid_t id = metaCtbCursorNext(pCur);
if (id == 0) {
break;
}
taosArrayPush(list, &id);
}
metaCloseCtbCursor(pCur);
2022-06-20 02:38:08 +00:00
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
2022-08-12 13:00:48 +00:00
if (!pCur) {
return TSDB_CODE_FAILED;
}
while (1) {
tb_uid_t id = metaStbCursorNext(pCur);
if (id == 0) {
break;
}
taosArrayPush(list, &id);
}
metaCloseStbCursor(pCur);
return TSDB_CODE_SUCCESS;
}
2023-07-09 13:49:37 +00:00
int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg, void *arg1),
void *arg) {
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
if (!pCur) {
return TSDB_CODE_FAILED;
}
while (1) {
tb_uid_t id = metaStbCursorNext(pCur);
if (id == 0) {
break;
}
if ((*filter) && (*filter)(arg, &id)) {
continue;
}
taosArrayPush(list, &id);
}
metaCloseStbCursor(pCur);
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
2023-08-11 09:52:52 +00:00
SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0);
if (!pCur) {
return TSDB_CODE_FAILED;
}
*num = 0;
while (1) {
tb_uid_t id = metaCtbCursorNext(pCur);
if (id == 0) {
break;
}
++(*num);
}
metaCloseCtbCursor(pCur);
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
2023-09-23 23:52:27 +00:00
SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0);
if (pSW) {
*num = pSW->nCols;
tDeleteSchemaWrapper(pSW);
} else {
*num = 2;
}
return TSDB_CODE_SUCCESS;
}
2023-07-10 11:55:01 +00:00
#ifdef TD_ENTERPRISE
const char *tkLogStb[TK_LOG_STB_NUM] = {"cluster_info",
"data_dir",
"dnodes_info",
"d_info",
"grants_info",
"keeper_monitor",
"logs",
"log_dir",
"log_summary",
"m_info",
"taosadapter_restful_http_request_fail",
"taosadapter_restful_http_request_in_flight",
"taosadapter_restful_http_request_summary_milliseconds",
"taosadapter_restful_http_request_total",
"taosadapter_system_cpu_percent",
"taosadapter_system_mem_percent",
"temp_dir",
"vgroups_info",
2023-10-05 13:35:57 +00:00
"vnodes_role"};
const char *tkAuditStb[TK_AUDIT_STB_NUM] = {"operations"};
// exclude stbs of taoskeeper log
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode) {
int32_t tbSize = 0;
int32_t tbNum = 0;
const char **pTbArr = NULL;
const char *dbName = NULL;
if (!(dbName = strchr(((SVnode *)pVnode)->config.dbname, '.'))) return 0;
if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
tbNum = TK_LOG_STB_NUM;
pTbArr = (const char **)&tkLogStb;
2023-10-05 13:35:57 +00:00
} else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
tbNum = TK_AUDIT_STB_NUM;
pTbArr = (const char **)&tkAuditStb;
}
if (tbNum && pTbArr) {
tbSize = metaSizeOfTbFilterCache(pVnode, 0);
if (tbSize < tbNum) {
for (int32_t i = 0; i < tbNum; ++i) {
tb_uid_t suid = metaGetTableEntryUidByName(pVnode->pMeta, pTbArr[i]);
2023-10-05 13:35:57 +00:00
if (suid != 0) {
metaPutTbToFilterCache(pVnode, &suid, 0);
}
}
tbSize = metaSizeOfTbFilterCache(pVnode, 0);
}
}
return tbSize;
}
2023-10-05 15:48:52 +00:00
#endif
2023-10-05 15:30:30 +00:00
2023-07-10 12:01:50 +00:00
static bool vnodeTimeSeriesFilter(void *arg1, void *arg2) {
2023-07-09 13:49:37 +00:00
SVnode *pVnode = (SVnode *)arg1;
2023-09-28 02:15:34 +00:00
if (metaTbInFilterCache(pVnode, arg2, 0)) {
2023-07-09 13:49:37 +00:00
return true;
}
return false;
}
int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
SArray *suidList = NULL;
if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
2023-07-09 13:49:37 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_FAILED;
}
int32_t tbFilterSize = 0;
2023-10-05 15:48:52 +00:00
#ifdef TD_ENTERPRISE
tbFilterSize = vnodeGetTimeSeriesBlackList(pVnode);
2023-10-05 15:48:52 +00:00
#endif
if ((!tbFilterSize && vnodeGetStbIdList(pVnode, 0, suidList) < 0) ||
2023-07-10 12:01:50 +00:00
(tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) {
2023-07-09 13:49:37 +00:00
qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr());
taosArrayDestroy(suidList);
return TSDB_CODE_FAILED;
}
*num = 0;
int64_t arrSize = taosArrayGetSize(suidList);
for (int64_t i = 0; i < arrSize; ++i) {
2023-07-09 13:49:37 +00:00
tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
2023-07-09 13:49:37 +00:00
int64_t ctbNum = 0;
int32_t numOfCols = 0;
metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols);
2023-07-09 13:49:37 +00:00
*num += ctbNum * (numOfCols - 1);
}
taosArrayDestroy(suidList);
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
if (!pCur) {
2023-07-09 13:49:37 +00:00
return TSDB_CODE_FAILED;
}
*num = 0;
while (1) {
2023-07-09 13:49:37 +00:00
tb_uid_t id = metaStbCursorNext(pCur);
if (id == 0) {
break;
}
2023-07-09 13:49:37 +00:00
int64_t ctbNum = 0;
vnodeGetCtbNum(pVnode, id, &ctbNum);
2023-07-09 13:49:37 +00:00
*num += ctbNum;
}
metaCloseStbCursor(pCur);
return TSDB_CODE_SUCCESS;
}
void *vnodeGetIdx(void *pVnode) {
2022-06-20 02:38:08 +00:00
if (pVnode == NULL) {
2023-07-09 13:49:37 +00:00
return NULL;
2022-06-20 02:38:08 +00:00
}
2023-07-10 11:55:01 +00:00
return metaGetIdx(((SVnode*)pVnode)->pMeta);
2022-06-20 02:38:08 +00:00
}
void *vnodeGetIvtIdx(void *pVnode) {
2022-06-20 02:38:08 +00:00
if (pVnode == NULL) {
2023-07-09 13:49:37 +00:00
return NULL;
2022-06-20 02:38:08 +00:00
}
2023-07-10 11:55:01 +00:00
return metaGetIvtIdx(((SVnode*)pVnode)->pMeta);
2022-06-20 02:38:08 +00:00
}