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

1477 lines
46 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/>.
*/
#include "tsdb.h"
#include "tutil.h"
#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)); \
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
2024-03-13 08:03:43 +00:00
int32_t fillTableColCmpr(SMetaReader *reader, SSchemaExt *pExt, int32_t numOfCol) {
int8_t tblType = reader->me.type;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (withExtSchema(tblType)) {
2024-03-13 08:03:43 +00:00
SColCmprWrapper *p = &(reader->me.colCmpr);
2024-08-20 11:35:35 +00:00
if (numOfCol != p->nCols) {
vError("fillTableColCmpr table type:%d, col num:%d, col cmpr num:%d mismatch", tblType, numOfCol, p->nCols);
return TSDB_CODE_APP_ERROR;
2024-08-20 11:35:35 +00:00
}
2024-03-13 08:03:43 +00:00
for (int i = 0; i < p->nCols; i++) {
SColCmpr *pCmpr = &p->pColCmpr[i];
pExt[i].colId = pCmpr->id;
pExt[i].compress = pCmpr->alg;
}
}
return 0;
}
2025-02-27 07:06:49 +00:00
void vnodePrintTableMeta(STableMetaRsp *pMeta) {
2025-01-23 08:12:54 +00:00
if (!(qDebugFlag & DEBUG_DEBUG)) {
return;
}
qDebug("tbName:%s", pMeta->tbName);
qDebug("stbName:%s", pMeta->stbName);
qDebug("dbFName:%s", pMeta->dbFName);
qDebug("dbId:%" PRId64, pMeta->dbId);
qDebug("numOfTags:%d", pMeta->numOfTags);
qDebug("numOfColumns:%d", pMeta->numOfColumns);
qDebug("precision:%d", pMeta->precision);
qDebug("tableType:%d", pMeta->tableType);
qDebug("sversion:%d", pMeta->sversion);
qDebug("tversion:%d", pMeta->tversion);
qDebug("suid:%" PRIu64, pMeta->suid);
qDebug("tuid:%" PRIu64, pMeta->tuid);
qDebug("vgId:%d", pMeta->vgId);
qDebug("sysInfo:%d", pMeta->sysInfo);
if (pMeta->pSchemas) {
for (int32_t i = 0; i < (pMeta->numOfColumns + pMeta->numOfTags); ++i) {
2025-02-27 07:06:49 +00:00
SSchema *pSchema = pMeta->pSchemas + i;
qDebug("%d col/tag: type:%d, flags:%d, colId:%d, bytes:%d, name:%s", i, pSchema->type, pSchema->flags,
pSchema->colId, pSchema->bytes, pSchema->name);
2025-01-23 08:12:54 +00:00
}
}
}
int32_t fillTableColRef(SMetaReader *reader, SColRef *pRef, int32_t numOfCol) {
int8_t tblType = reader->me.type;
if (hasRefCol(tblType)) {
SColRefWrapper *p = &(reader->me.colRef);
if (numOfCol != p->nCols) {
vError("fillTableColRef table type:%d, col num:%d, col cmpr num:%d mismatch", tblType, numOfCol, p->nCols);
return TSDB_CODE_APP_ERROR;
}
for (int i = 0; i < p->nCols; i++) {
SColRef *pColRef = &p->pColRef[i];
pRef[i].hasRef = pColRef->hasRef;
pRef[i].id = pColRef->id;
if(pRef[i].hasRef) {
tstrncpy(pRef[i].refDbName, pColRef->refDbName, TSDB_DB_NAME_LEN);
tstrncpy(pRef[i].refTableName, pColRef->refTableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pRef[i].refColName, pColRef->refColName, TSDB_COL_NAME_LEN);
}
}
}
return 0;
}
int32_t 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];
2024-09-19 11:03:06 +00:00
bool reqTbUid = false;
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};
uint8_t autoCreateCtb = 0;
2022-04-22 05:30:15 +00:00
// decode req
if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
2024-07-23 06:34:43 +00:00
code = terrno;
goto _exit4;
2022-04-22 05:30:15 +00:00
}
autoCreateCtb = infoReq.autoCreateCtb;
2022-04-22 05:30:15 +00:00
2024-09-19 11:03:06 +00:00
if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true;
2022-04-24 02:50:08 +00:00
metaRsp.dbId = pVnode->config.dbId;
2024-12-13 07:03:01 +00:00
tstrncpy(metaRsp.tbName, infoReq.tbName, TSDB_TABLE_NAME_LEN);
(void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
2022-04-24 02:50:08 +00:00
2024-09-19 11:03:06 +00:00
if (!reqTbUid) {
2024-12-13 12:59:39 +00:00
(void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
2025-07-12 07:39:29 +00:00
if (pVnode->mounted) tTrimMountPrefix(tableFName);
2024-09-16 03:39:11 +00:00
code = vnodeValidateTableHash(pVnode, tableFName);
if (code) {
goto _exit4;
}
2022-03-11 07:59:28 +00:00
}
2022-04-22 06:25:59 +00:00
// query meta
2024-03-16 14:42:49 +00:00
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
2024-09-19 11:03:06 +00:00
if (reqTbUid) {
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
SET_ERRNO(0);
2024-09-16 03:39:11 +00:00
uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
if (ERRNO == ERANGE || tbUid == 0) {
2024-09-18 11:38:57 +00:00
code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
2024-09-16 03:39:11 +00:00
goto _exit3;
}
SMetaReader mr3 = {0};
metaReaderDoInit(&mr3, ((SVnode *)pVnode)->pMeta, META_READER_NOLOCK);
if ((code = metaReaderGetTableEntryByUid(&mr3, tbUid)) < 0) {
metaReaderClear(&mr3);
TAOS_CHECK_GOTO(code, NULL, _exit3);
}
tstrncpy(metaRsp.tbName, mr3.me.name, TSDB_TABLE_NAME_LEN);
metaReaderClear(&mr3);
TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, metaRsp.tbName), NULL, _exit3);
2024-09-16 03:39:11 +00:00
} else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
2022-04-26 13:51:01 +00:00
code = terrno;
goto _exit3;
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;
switch (mer1.me.type) {
case TSDB_SUPER_TABLE: {
(void)strcpy(metaRsp.stbName, mer1.me.name);
schema = mer1.me.stbEntry.schemaRow;
schemaTag = mer1.me.stbEntry.schemaTag;
metaRsp.suid = mer1.me.uid;
break;
}
case TSDB_CHILD_TABLE:
case TSDB_VIRTUAL_CHILD_TABLE:{
metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
(void)strcpy(metaRsp.stbName, mer2.me.name);
metaRsp.suid = mer2.me.uid;
schema = mer2.me.stbEntry.schemaRow;
schemaTag = mer2.me.stbEntry.schemaTag;
break;
}
case TSDB_NORMAL_TABLE:
case TSDB_VIRTUAL_NORMAL_TABLE: {
schema = mer1.me.ntbEntry.schemaRow;
break;
}
default: {
vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type);
goto _exit3;
}
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));
2024-03-13 08:03:43 +00:00
metaRsp.pSchemaExt = (SSchemaExt *)taosMemoryCalloc(metaRsp.numOfColumns, sizeof(SSchemaExt));
if (NULL == metaRsp.pSchemas || NULL == metaRsp.pSchemaExt) {
code = terrno;
goto _exit;
}
(void)memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
2022-04-24 02:50:08 +00:00
if (schemaTag.nCols) {
(void)memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
2022-04-24 02:50:08 +00:00
}
2024-03-13 08:03:43 +00:00
if (metaRsp.pSchemaExt) {
2024-06-13 02:11:41 +00:00
SMetaReader *pReader = mer1.me.type == TSDB_CHILD_TABLE ? &mer2 : &mer1;
code = fillTableColCmpr(pReader, metaRsp.pSchemaExt, metaRsp.numOfColumns);
2024-03-13 08:03:43 +00:00
if (code < 0) {
goto _exit;
}
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
for (int32_t i = 0; i < metaRsp.numOfColumns && pReader->me.pExtSchemas; i++) {
metaRsp.pSchemaExt[i].typeMod = pReader->me.pExtSchemas[i].typeMod;
}
2024-03-13 08:03:43 +00:00
} else {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
if (hasRefCol(mer1.me.type)) {
metaRsp.rversion = mer1.me.colRef.version;
metaRsp.pColRefs = (SColRef*)taosMemoryMalloc(sizeof(SColRef) * metaRsp.numOfColumns);
if (metaRsp.pColRefs) {
code = fillTableColRef(&mer1, metaRsp.pColRefs, metaRsp.numOfColumns);
if (code < 0) {
goto _exit;
}
}
metaRsp.numOfColRefs = metaRsp.numOfColumns;
} else {
metaRsp.pColRefs = NULL;
metaRsp.numOfColRefs = 0;
}
2022-04-24 02:50:08 +00:00
2025-01-23 08:12:54 +00:00
vnodePrintTableMeta(&metaRsp);
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) {
2024-07-23 06:34:43 +00:00
code = terrno;
2022-02-15 07:24:27 +00:00
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 = terrno;
2022-02-15 07:24:27 +00:00
goto _exit;
2021-12-30 07:05:49 +00:00
}
rspLen = tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
if (rspLen < 0) {
2024-07-23 06:34:43 +00:00
code = terrno;
goto _exit;
}
2021-12-28 05:58:53 +00:00
2022-04-26 13:51:01 +00:00
_exit:
taosMemoryFree(metaRsp.pColRefs);
taosMemoryFree(metaRsp.pSchemas);
2024-03-13 08:03:43 +00:00
taosMemoryFree(metaRsp.pSchemaExt);
_exit2:
metaReaderClear(&mer2);
_exit3:
metaReaderClear(&mer1);
_exit4:
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
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST && autoCreateCtb == 1) {
code = TSDB_CODE_SUCCESS;
}
2022-06-10 09:07:24 +00:00
if (code) {
2024-09-16 03:39:11 +00:00
qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
2022-06-10 09:07:24 +00:00
}
2022-07-26 10:00:50 +00:00
if (direct) {
tmsgSendRsp(&rpcMsg);
} else {
*pMsg = rpcMsg;
2022-07-26 10:00:50 +00:00
}
return code;
2021-12-30 09:13:02 +00:00
}
2022-04-14 08:42:50 +00:00
int32_t 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) {
2024-07-23 06:34:43 +00:00
code = terrno;
2022-06-20 05:32:21 +00:00
goto _exit;
}
2024-12-13 07:03:01 +00:00
tstrncpy(cfgRsp.tbName, cfgReq.tbName, TSDB_TABLE_NAME_LEN);
(void)memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
2022-06-20 05:32:21 +00:00
2024-12-13 12:59:39 +00:00
(void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
2025-07-12 07:39:29 +00:00
if (pVnode->mounted) tTrimMountPrefix(tableFName);
2022-06-20 05:32:21 +00:00
code = vnodeValidateTableHash(pVnode, tableFName);
if (code) {
goto _exit;
}
// query meta
2024-03-16 14:42:49 +00:00
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
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;
} else if (mer1.me.type == TSDB_CHILD_TABLE || mer1.me.type == TSDB_VIRTUAL_CHILD_TABLE) {
2024-12-25 11:14:52 +00:00
metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
2022-06-20 05:32:21 +00:00
2024-12-13 07:03:01 +00:00
tstrncpy(cfgRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
2022-06-20 05:32:21 +00:00
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);
if (NULL == cfgRsp.pComment) {
2024-10-09 07:37:00 +00:00
code = terrno;
goto _exit;
}
2022-06-20 12:58:36 +00:00
}
STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
cfgRsp.tagsLen = pTag->len;
cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
if (NULL == cfgRsp.pTags) {
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
(void)memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
} else if (mer1.me.type == TSDB_NORMAL_TABLE || mer1.me.type == TSDB_VIRTUAL_NORMAL_TABLE) {
2022-06-20 05:32:21 +00:00
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);
if (NULL == cfgRsp.pComment) {
2024-10-09 07:37:00 +00:00
code = terrno;
goto _exit;
}
2022-06-20 12:58:36 +00:00
}
2022-06-20 05:32:21 +00:00
} else {
vError("vnodeGetTableCfg get invalid table type:%d", mer1.me.type);
2024-12-25 11:14:52 +00:00
code = TSDB_CODE_APP_ERROR;
goto _exit;
2022-06-20 05:32:21 +00:00
}
cfgRsp.numOfTags = schemaTag.nCols;
cfgRsp.numOfColumns = schema.nCols;
cfgRsp.virtualStb = false; // vnode don't have super table, so it's always false
cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
2024-03-13 09:54:14 +00:00
cfgRsp.pSchemaExt = (SSchemaExt *)taosMemoryMalloc(cfgRsp.numOfColumns * sizeof(SSchemaExt));
cfgRsp.pColRefs = (SColRef *)taosMemoryMalloc(sizeof(SColRef) * cfgRsp.numOfColumns);
2022-06-20 05:32:21 +00:00
if (NULL == cfgRsp.pSchemas || NULL == cfgRsp.pSchemaExt || NULL == cfgRsp.pColRefs) {
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
(void)memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
2022-06-20 05:32:21 +00:00
if (schemaTag.nCols) {
(void)memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
2022-06-20 05:32:21 +00:00
}
SMetaReader *pReader = (mer1.me.type == TSDB_CHILD_TABLE || mer1.me.type == TSDB_VIRTUAL_CHILD_TABLE) ? &mer2 : &mer1;
2024-06-13 02:11:41 +00:00
SColCmprWrapper *pColCmpr = &pReader->me.colCmpr;
SColRefWrapper *pColRef = &mer1.me.colRef;
if (withExtSchema(cfgRsp.tableType)) {
for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
SColCmpr *pCmpr = &pColCmpr->pColCmpr[i];
SSchemaExt *pSchExt = cfgRsp.pSchemaExt + i;
pSchExt->colId = pCmpr->id;
pSchExt->compress = pCmpr->alg;
if (pReader->me.pExtSchemas)
pSchExt->typeMod = pReader->me.pExtSchemas[i].typeMod;
else
pSchExt->typeMod = 0;
}
}
2024-06-13 02:11:41 +00:00
cfgRsp.virtualStb = false;
if (hasRefCol(cfgRsp.tableType)) {
for (int32_t i = 0; i < cfgRsp.numOfColumns; i++) {
SColRef *pRef = &pColRef->pColRef[i];
cfgRsp.pColRefs[i].hasRef = pRef->hasRef;
cfgRsp.pColRefs[i].id = pRef->id;
if (cfgRsp.pColRefs[i].hasRef) {
tstrncpy(cfgRsp.pColRefs[i].refDbName, pRef->refDbName, TSDB_DB_NAME_LEN);
tstrncpy(cfgRsp.pColRefs[i].refTableName, pRef->refTableName, TSDB_TABLE_NAME_LEN);
tstrncpy(cfgRsp.pColRefs[i].refColName, pRef->refColName, TSDB_COL_NAME_LEN);
}
}
}
2024-03-13 09:54:14 +00:00
2022-06-20 05:32:21 +00:00
// encode and send response
rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
if (rspLen < 0) {
2024-07-23 06:34:43 +00:00
code = terrno;
2022-06-20 05:32:21 +00:00
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 = terrno;
2022-06-20 05:32:21 +00:00
goto _exit;
}
rspLen = tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);
if (rspLen < 0) {
2024-07-23 06:34:43 +00:00
code = terrno;
goto _exit;
}
2022-06-20 05:32:21 +00:00
_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);
return code;
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)) {
2024-07-23 06:34:43 +00:00
code = terrno;
2022-11-17 02:35:25 +00:00
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) {
2024-09-20 00:56:46 +00:00
code = terrno;
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);
if (req == NULL) {
2024-10-09 07:37:00 +00:00
code = terrno;
goto _exit;
}
2022-11-17 02:35:25 +00:00
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:
// error code has been set into reqMsg, no need to handle it here.
2024-09-05 01:57:45 +00:00
if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
}
2022-07-26 10:00:50 +00:00
break;
2024-09-17 07:41:10 +00:00
case TDMT_VND_TABLE_NAME:
// error code has been set into reqMsg, no need to handle it here.
if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) {
qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType);
}
break;
2022-07-26 10:00:50 +00:00
case TDMT_VND_TABLE_CFG:
// error code has been set into reqMsg, no need to handle it here.
2024-09-05 01:57:45 +00:00
if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) {
qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType);
}
2022-07-26 10:00:50 +00:00
break;
2025-03-20 01:52:03 +00:00
case TDMT_VND_VSUBTABLES_META:
// error code has been set into reqMsg, no need to handle it here.
if (TSDB_CODE_SUCCESS != vnodeGetVSubtablesMeta(pVnode, &reqMsg)) {
qWarn("vnodeGetVSubtablesMeta failed, msgType:%d", req->msgType);
}
break;
case TDMT_VND_VSTB_REF_DBS:
// error code has been set into reqMsg, no need to handle it here.
if (TSDB_CODE_SUCCESS != vnodeGetVStbRefDbs(pVnode, &reqMsg)) {
qWarn("vnodeGetVStbRefDbs failed, msgType:%d", req->msgType);
}
break;
2022-07-26 10:00:50 +00:00
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;
if (NULL == taosArrayPush(batchRsp.pRsps, &rsp)) {
qError("taosArrayPush failed");
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
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");
2024-07-23 06:34:43 +00:00
code = terrno;
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);
2024-07-23 06:34:43 +00:00
code = terrno;
2022-07-26 10:00:50 +00:00
goto _exit;
}
2022-11-17 06:09:15 +00:00
if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
qError("tSerializeSBatchRsp %d failed", rspSize);
2024-07-23 06:34:43 +00:00
code = terrno;
2022-11-17 02:35:25 +00:00
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
}
2025-02-27 07:06:49 +00:00
#define VNODE_DO_META_QUERY(pVnode, cmd) \
do { \
(void)taosThreadRwlockRdlock(&(pVnode)->metaRWLock); \
cmd; \
(void)taosThreadRwlockUnlock(&(pVnode)->metaRWLock); \
} while (0)
int32_t vnodeReadVSubtables(SReadHandle* pHandle, int64_t suid, SArray** ppRes) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t line = 0;
SMetaReader mr = {0};
bool readerInit = false;
SVCTableRefCols* pTb = NULL;
int32_t refColsNum = 0;
char tbFName[TSDB_TABLE_FNAME_LEN];
SSHashObj* pSrcTbls = NULL;
2025-03-17 06:51:11 +00:00
SArray *pList = taosArrayInit(10, sizeof(uint64_t));
QUERY_CHECK_NULL(pList, code, line, _return, terrno);
2025-03-17 06:51:11 +00:00
QUERY_CHECK_CODE(pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList), line, _return);
size_t num = taosArrayGetSize(pList);
*ppRes = taosArrayInit(num, POINTER_BYTES);
QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno);
pSrcTbls = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
QUERY_CHECK_NULL(pSrcTbls, code, line, _return, terrno);
for (int32_t i = 0; i < num; ++i) {
uint64_t* id = taosArrayGet(pList, i);
QUERY_CHECK_NULL(id, code, line, _return, terrno);
pHandle->api.metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pHandle->api.metaFn);
QUERY_CHECK_CODE(pHandle->api.metaReaderFn.getTableEntryByUid(&mr, *id), line, _return);
readerInit = true;
refColsNum = 0;
for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
if (mr.me.colRef.pColRef[j].hasRef) {
refColsNum++;
}
}
if (refColsNum <= 0) {
pHandle->api.metaReaderFn.clearReader(&mr);
readerInit = false;
continue;
}
pTb = taosMemoryCalloc(1, refColsNum * sizeof(SRefColInfo) + sizeof(*pTb));
QUERY_CHECK_NULL(pTb, code, line, _return, terrno);
pTb->uid = mr.me.uid;
pTb->numOfColRefs = refColsNum;
pTb->refCols = (SRefColInfo*)(pTb + 1);
2025-03-17 06:51:11 +00:00
refColsNum = 0;
tSimpleHashClear(pSrcTbls);
for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
if (!mr.me.colRef.pColRef[j].hasRef) {
continue;
}
pTb->refCols[refColsNum].colId = mr.me.colRef.pColRef[j].id;
tstrncpy(pTb->refCols[refColsNum].refColName, mr.me.colRef.pColRef[j].refColName, TSDB_COL_NAME_LEN);
tstrncpy(pTb->refCols[refColsNum].refTableName, mr.me.colRef.pColRef[j].refTableName, TSDB_TABLE_NAME_LEN);
tstrncpy(pTb->refCols[refColsNum].refDbName, mr.me.colRef.pColRef[j].refDbName, TSDB_DB_NAME_LEN);
snprintf(tbFName, sizeof(tbFName), "%s.%s", pTb->refCols[refColsNum].refDbName, pTb->refCols[refColsNum].refTableName);
if (NULL == tSimpleHashGet(pSrcTbls, tbFName, strlen(tbFName))) {
QUERY_CHECK_CODE(tSimpleHashPut(pSrcTbls, tbFName, strlen(tbFName), &code, sizeof(code)), line, _return);
}
2025-03-17 06:51:11 +00:00
refColsNum++;
}
pTb->numOfSrcTbls = tSimpleHashGetSize(pSrcTbls);
QUERY_CHECK_NULL(taosArrayPush(*ppRes, &pTb), code, line, _return, terrno);
pTb = NULL;
2025-03-17 06:51:11 +00:00
pHandle->api.metaReaderFn.clearReader(&mr);
readerInit = false;
}
_return:
if (readerInit) {
pHandle->api.metaReaderFn.clearReader(&mr);
}
taosArrayDestroy(pList);
taosMemoryFree(pTb);
tSimpleHashCleanup(pSrcTbls);
2025-03-17 06:51:11 +00:00
if (code) {
qError("%s failed since %s", __func__, tstrerror(code));
}
return code;
}
int32_t vnodeReadVStbRefDbs(SReadHandle* pHandle, int64_t suid, SArray** ppRes) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t line = 0;
SMetaReader mr = {0};
bool readerInit = false;
SSHashObj* pDbNameHash = NULL;
SArray* pList = NULL;
pList = taosArrayInit(10, sizeof(uint64_t));
QUERY_CHECK_NULL(pList, code, line, _return, terrno);
*ppRes = taosArrayInit(10, POINTER_BYTES);
QUERY_CHECK_NULL(*ppRes, code, line, _return, terrno)
// lookup in cache
code = pHandle->api.metaFn.metaGetCachedRefDbs(pHandle->vnode, suid, *ppRes);
QUERY_CHECK_CODE(code, line, _return);
if (taosArrayGetSize(*ppRes) > 0) {
// found in cache
goto _return;
} else {
code = pHandle->api.metaFn.getChildTableList(pHandle->vnode, suid, pList);
QUERY_CHECK_CODE(code, line, _return);
size_t num = taosArrayGetSize(pList);
pDbNameHash = tSimpleHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
QUERY_CHECK_NULL(pDbNameHash, code, line, _return, terrno);
for (int32_t i = 0; i < num; ++i) {
uint64_t* id = taosArrayGet(pList, i);
QUERY_CHECK_NULL(id, code, line, _return, terrno);
pHandle->api.metaReaderFn.initReader(&mr, pHandle->vnode, META_READER_LOCK, &pHandle->api.metaFn);
readerInit = true;
code = pHandle->api.metaReaderFn.getTableEntryByUid(&mr, *id);
QUERY_CHECK_CODE(code, line, _return);
for (int32_t j = 0; j < mr.me.colRef.nCols; j++) {
if (mr.me.colRef.pColRef[j].hasRef) {
if (NULL == tSimpleHashGet(pDbNameHash, mr.me.colRef.pColRef[j].refDbName, strlen(mr.me.colRef.pColRef[j].refDbName))) {
char *refDbName = taosStrdup(mr.me.colRef.pColRef[j].refDbName);
QUERY_CHECK_NULL(refDbName, code, line, _return, terrno);
QUERY_CHECK_NULL(taosArrayPush(*ppRes, &refDbName), code, line, _return, terrno);
code = tSimpleHashPut(pDbNameHash, refDbName, strlen(refDbName), NULL, 0);
QUERY_CHECK_CODE(code, line, _return);
}
}
}
pHandle->api.metaReaderFn.clearReader(&mr);
readerInit = false;
}
code = pHandle->api.metaFn.metaPutRefDbsToCache(pHandle->vnode, suid, *ppRes);
QUERY_CHECK_CODE(code, line, _return);
}
_return:
if (readerInit) {
pHandle->api.metaReaderFn.clearReader(&mr);
}
taosArrayDestroy(pList);
tSimpleHashCleanup(pDbNameHash);
if (code) {
qError("%s failed since %s", __func__, tstrerror(code));
}
return code;
}
int32_t vnodeGetVSubtablesMeta(SVnode *pVnode, SRpcMsg *pMsg) {
int32_t code = 0;
int32_t rspSize = 0;
SVSubTablesReq req = {0};
SVSubTablesRsp rsp = {0};
SRpcMsg rspMsg = {0};
void *pRsp = NULL;
int32_t line = 0;
if (tDeserializeSVSubTablesReq(pMsg->pCont, pMsg->contLen, &req)) {
code = terrno;
qError("tDeserializeSVSubTablesReq failed");
goto _return;
}
SReadHandle handle = {0};
handle.vnode = pVnode;
initStorageAPI(&handle.api);
QUERY_CHECK_CODE(vnodeReadVSubtables(&handle, req.suid, &rsp.pTables), line, _return);
rsp.vgId = TD_VID(pVnode);
rspSize = tSerializeSVSubTablesRsp(NULL, 0, &rsp);
if (rspSize < 0) {
code = rspSize;
qError("tSerializeSVSubTablesRsp failed, error:%d", rspSize);
goto _return;
}
2025-03-20 01:52:03 +00:00
pRsp = taosMemoryCalloc(1, rspSize);
if (pRsp == NULL) {
code = terrno;
qError("rpcMallocCont %d failed, error:%d", rspSize, terrno);
goto _return;
}
rspSize = tSerializeSVSubTablesRsp(pRsp, rspSize, &rsp);
if (rspSize < 0) {
code = rspSize;
qError("tSerializeSVSubTablesRsp failed, error:%d", rspSize);
goto _return;
}
_return:
rspMsg.info = pMsg->info;
rspMsg.pCont = pRsp;
rspMsg.contLen = rspSize;
rspMsg.code = code;
rspMsg.msgType = pMsg->msgType;
if (code) {
qError("vnd get virtual subtables failed cause of %s", tstrerror(code));
}
2025-03-20 01:52:03 +00:00
*pMsg = rspMsg;
tDestroySVSubTablesRsp(&rsp);
2025-03-20 01:52:03 +00:00
//tmsgSendRsp(&rspMsg);
return code;
}
int32_t vnodeGetVStbRefDbs(SVnode *pVnode, SRpcMsg *pMsg) {
int32_t code = 0;
int32_t rspSize = 0;
SVStbRefDbsReq req = {0};
SVStbRefDbsRsp rsp = {0};
SRpcMsg rspMsg = {0};
void *pRsp = NULL;
int32_t line = 0;
if (tDeserializeSVStbRefDbsReq(pMsg->pCont, pMsg->contLen, &req)) {
code = terrno;
qError("tDeserializeSVSubTablesReq failed");
goto _return;
}
SReadHandle handle = {0};
handle.vnode = pVnode;
initStorageAPI(&handle.api);
code = vnodeReadVStbRefDbs(&handle, req.suid, &rsp.pDbs);
QUERY_CHECK_CODE(code, line, _return);
rsp.vgId = TD_VID(pVnode);
rspSize = tSerializeSVStbRefDbsRsp(NULL, 0, &rsp);
if (rspSize < 0) {
code = rspSize;
qError("tSerializeSVStbRefDbsRsp failed, error:%d", rspSize);
goto _return;
}
pRsp = taosMemoryCalloc(1, rspSize);
if (pRsp == NULL) {
code = terrno;
qError("rpcMallocCont %d failed, error:%d", rspSize, terrno);
goto _return;
}
rspSize = tSerializeSVStbRefDbsRsp(pRsp, rspSize, &rsp);
if (rspSize < 0) {
code = rspSize;
qError("tSerializeSVStbRefDbsRsp failed, error:%d", rspSize);
goto _return;
}
_return:
rspMsg.info = pMsg->info;
rspMsg.pCont = pRsp;
rspMsg.contLen = rspSize;
rspMsg.code = code;
rspMsg.msgType = pMsg->msgType;
if (code) {
qError("vnd get virtual stb ref db failed cause of %s", tstrerror(code));
}
*pMsg = rspMsg;
tDestroySVStbRefDbsRsp(&rsp);
return code;
}
static int32_t vnodeGetCompStorage(SVnode *pVnode, int64_t *output) {
int32_t code = 0;
#ifdef TD_ENTERPRISE
int32_t now = taosGetTimestampSec();
if (llabs(now - pVnode->config.vndStats.storageLastUpd) >= 30) {
pVnode->config.vndStats.storageLastUpd = now;
SDbSizeStatisInfo info = {0};
if (0 == (code = vnodeGetDBSize(pVnode, &info))) {
int64_t compSize =
feat[ts-6107]: shared storage (#31552) * add API to use s3 as shared storage * support using local file system as shared storage * upload file to shared storage * support read, compact and drop * finish basic mnode & vnode msg processing * follower sync migration state * implement mnode transaction, and improve log * send migration progress msg to dnode to avoid deadlock * implement following migration * remove mcount * avoid redo migration on startup * avoid follower deadlock when leader is down * trigger migrate by timer, avoid compact after migration * comment out the usage of 'tcs' functions in stream * change config item prefix from s3 to ss * change db option prefix from s3 to ss * rename s3 data struct, function, file to ss * rename s3 macro to ss * update s3 sql to ss * rename remaining s3 items to ss * check ss configruation, improve s3 retry * grant object storage -> shared storage, check ssEnabled * fix memory leaks * update build options * omit sensitive information when dump config * fix backward compatibility issue * fix issues found in ci-checks * fix some failed test cases * avoid follower timeout and improve log * fix: follower timeout because migration status not updated * refuse migration if there's an in progress one * fix ss test case * remove garbage files and other minor improvement * fix failed test cases * update unit test * fix failed test case * fix failed test case * update document * update document and fix failed test cases * fix minor issues in code, test and document * check new commit after migration task is scheduled * fix several issus 1. migrate information cannot be dropped sometimes because progress response was put into read queue. 2. memory leak in rare cases 3. data corruption in rare cases 4. failed test case * add shared storage upgrade tool * fix compile error
2025-07-14 08:33:53 +00:00
info.l1Size + info.l2Size + info.l3Size + info.cacheSize + info.walSize + info.metaSize + +info.ssSize;
if (compSize >= 0) {
pVnode->config.vndStats.compStorage = compSize;
} else {
vError("vnode get comp storage failed since compSize is negative:%" PRIi64, compSize);
code = TSDB_CODE_APP_ERROR;
}
} else {
vWarn("vnode get comp storage failed since %s", tstrerror(code));
}
}
if (output) *output = pVnode->config.vndStats.compStorage;
#endif
return code;
}
static void vnodeGetBufferInfo(SVnode *pVnode, int64_t *bufferSegmentUsed, int64_t *bufferSegmentSize) {
*bufferSegmentUsed = 0;
*bufferSegmentSize = 0;
if (pVnode) {
(void)taosThreadMutexLock(&pVnode->mutex);
if (pVnode->inUse) {
*bufferSegmentUsed = pVnode->inUse->size;
}
*bufferSegmentSize = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
(void)taosThreadMutexUnlock(&pVnode->mutex);
}
}
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);
pLoad->syncAppliedIndex = pVnode->state.applied;
syncGetCommitIndex(pVnode->sync, &pLoad->syncCommitIndex);
2022-11-02 02:24:55 +00:00
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);
2025-02-27 07:06:49 +00:00
VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
pLoad->totalStorage = (int64_t)3 * 1073741824; // TODO
(void)vnodeGetCompStorage(pVnode, &pLoad->compStorage);
2022-10-11 09:47:23 +00:00
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);
vnodeGetBufferInfo(pVnode, &pLoad->bufferSegmentUsed, &pLoad->bufferSegmentSize);
2022-10-11 09:47:23 +00:00
return 0;
}
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
SSyncState syncState = syncGetState(pVnode->sync);
if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_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-12-08 09:26:44 +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-12-08 09:26:44 +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) {
2024-08-20 11:35:35 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2023-08-11 09:52:52 +00:00
SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1);
if (NULL == pCur) {
qError("vnode get all table list failed");
2024-08-14 09:50:20 +00:00
return terrno;
}
2022-06-20 02:38:08 +00:00
while (1) {
tb_uid_t id = metaCtbCursorNext(pCur);
if (id == 0) {
break;
}
STableKeyInfo info = {uid = id};
if (NULL == taosArrayPush(list, &info)) {
qError("taosArrayPush failed");
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
2022-06-20 02:38:08 +00:00
}
_exit:
metaCloseCtbCursor(pCur);
return code;
2022-06-20 02:38:08 +00:00
}
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) {
2024-08-20 11:35:35 +00:00
int32_t code = TSDB_CODE_SUCCESS;
SVnode *pVnodeObj = pVnode;
2023-08-11 09:52:52 +00:00
SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1);
if (NULL == pCur) {
qError("vnode get all table list failed");
2024-08-14 09:50:20 +00:00
return terrno;
}
2022-06-20 02:38:08 +00:00
while (1) {
tb_uid_t id = metaCtbCursorNext(pCur);
if (id == 0) {
break;
}
2024-08-20 11:35:35 +00:00
if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed");
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
2022-06-20 02:38:08 +00:00
}
_exit:
metaCloseCtbCursor(pCur);
return code;
2022-06-20 02:38:08 +00:00
}
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
2024-08-20 11:35:35 +00:00
int32_t code = TSDB_CODE_SUCCESS;
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
2022-08-12 13:00:48 +00:00
if (!pCur) {
2024-07-24 02:09:24 +00:00
return TSDB_CODE_OUT_OF_MEMORY;
2022-08-12 13:00:48 +00:00
}
while (1) {
tb_uid_t id = metaStbCursorNext(pCur);
if (id == 0) {
break;
}
2024-08-20 11:35:35 +00:00
if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed");
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
2022-08-12 13:00:48 +00:00
}
_exit:
2022-08-12 13:00:48 +00:00
metaCloseStbCursor(pCur);
return code;
2022-08-12 13:00:48 +00:00
}
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) {
2024-08-20 11:35:35 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2023-07-09 13:49:37 +00:00
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
if (!pCur) {
2024-08-14 09:50:20 +00:00
return terrno;
2023-07-09 13:49:37 +00:00
}
while (1) {
tb_uid_t id = metaStbCursorNext(pCur);
if (id == 0) {
break;
}
if ((*filter) && (*filter)(arg, &id)) {
continue;
}
2024-08-20 11:35:35 +00:00
if (NULL == taosArrayPush(list, &id)) {
qError("taosArrayPush failed");
2024-09-20 00:56:46 +00:00
code = terrno;
goto _exit;
}
2023-07-09 13:49:37 +00:00
}
_exit:
2023-07-09 13:49:37 +00:00
metaCloseStbCursor(pCur);
return code;
2023-07-09 13:49:37 +00:00
}
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) {
2024-08-14 09:50:20 +00:00
return terrno;
}
*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) {
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
SSchemaWrapper *pSW = metaGetTableSchema(pVnode->pMeta, suid, -1, 0, NULL);
if (pSW) {
*num = pSW->nCols;
tDeleteSchemaWrapper(pSW);
} else {
*num = 2;
}
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetStbInfo(SVnode *pVnode, tb_uid_t suid, int64_t *keep, int8_t *flags) {
SMetaReader mr = {0};
metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK);
int32_t code = metaReaderGetTableEntryByUid(&mr, suid);
if (code == TSDB_CODE_SUCCESS) {
if (keep) *keep = mr.me.stbEntry.keep;
if (flags) *flags = mr.me.flags;
} else {
if (keep) *keep = 0;
if (flags) *flags = 0;
}
metaReaderClear(&mr);
return TSDB_CODE_SUCCESS;
}
2023-07-10 11:55:01 +00:00
#ifdef TD_ENTERPRISE
const char *tkLogStb[] = {"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",
"vnodes_role"};
const char *tkAuditStb[] = {"operations"};
const int tkLogStbNum = ARRAY_SIZE(tkLogStb);
const int tkAuditStbNum = ARRAY_SIZE(tkAuditStb);
// exclude stbs of taoskeeper log
2024-07-28 10:29:51 +00:00
static int32_t vnodeGetTimeSeriesBlackList(SVnode *pVnode, int32_t *tbSize) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t tbNum = 0;
const char **pTbArr = NULL;
const char *dbName = NULL;
2024-07-28 10:29:51 +00:00
*tbSize = 0;
2023-10-07 01:30:32 +00:00
if (!(dbName = strchr(pVnode->config.dbname, '.'))) return 0;
if (0 == strncmp(++dbName, "log", TSDB_DB_NAME_LEN)) {
tbNum = tkLogStbNum;
pTbArr = (const char **)&tkLogStb;
2023-10-05 13:35:57 +00:00
} else if (0 == strncmp(dbName, "audit", TSDB_DB_NAME_LEN)) {
tbNum = tkAuditStbNum;
pTbArr = (const char **)&tkAuditStb;
}
if (tbNum && pTbArr) {
2024-07-28 10:29:51 +00:00
*tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 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) {
2024-07-28 10:29:51 +00:00
code = metaPutTbToFilterCache(pVnode->pMeta, &suid, 0);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
2023-10-05 13:35:57 +00:00
}
}
2024-07-28 10:29:51 +00:00
*tbSize = metaSizeOfTbFilterCache(pVnode->pMeta, 0);
2023-10-05 13:35:57 +00:00
}
}
2024-07-28 10:29:51 +00:00
return code;
}
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-10-07 01:30:32 +00:00
if (metaTbInFilterCache(pVnode->pMeta, 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)))) {
2024-09-20 00:56:46 +00:00
return terrno;
}
int32_t tbFilterSize = 0;
2024-07-28 10:29:51 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2023-10-05 15:48:52 +00:00
#ifdef TD_ENTERPRISE
2024-07-28 10:29:51 +00:00
code = vnodeGetTimeSeriesBlackList(pVnode, &tbFilterSize);
if (TSDB_CODE_SUCCESS != code) {
goto _exit;
}
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);
2024-08-14 09:50:20 +00:00
return terrno;
2023-07-09 13:49:37 +00:00
}
*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;
int8_t flags = 0;
code = metaGetStbStats(pVnode, suid, &ctbNum, &numOfCols, &flags);
if (TSDB_CODE_SUCCESS != code) {
goto _exit;
}
if (!TABLE_IS_VIRTUAL(flags)) {
*num += ctbNum * (numOfCols - 1);
}
}
_exit:
taosArrayDestroy(suidList);
return TSDB_CODE_SUCCESS;
}
int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
if (!pCur) {
2024-08-14 09:50:20 +00:00
return terrno;
}
*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;
int32_t code = vnodeGetCtbNum(pVnode, id, &ctbNum);
if (TSDB_CODE_SUCCESS != code) {
metaCloseStbCursor(pCur);
return code;
}
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-12-08 09:26:44 +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-12-08 09:26:44 +00:00
return metaGetIvtIdx(((SVnode *)pVnode)->pMeta);
2022-06-20 02:38:08 +00:00
}
2025-04-25 10:05:12 +00:00
int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid, SSchemaWrapper **pTagSchema) {
return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid, pTagSchema);
}
2024-02-07 03:40:47 +00:00
static FORCE_INLINE int32_t vnodeGetDBPrimaryInfo(SVnode *pVnode, SDbSizeStatisInfo *pInfo) {
2024-11-05 11:57:13 +00:00
int32_t code = 0;
char path[TSDB_FILENAME_LEN] = {0};
2024-11-06 07:25:50 +00:00
char *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
int64_t dirSize[4];
2024-11-05 11:57:13 +00:00
2025-07-12 07:39:29 +00:00
vnodeGetPrimaryPath(pVnode, false, path, TSDB_FILENAME_LEN);
2024-11-05 11:57:13 +00:00
int32_t offset = strlen(path);
for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
2024-11-06 07:25:50 +00:00
int64_t size = {0};
2024-11-05 11:57:13 +00:00
(void)snprintf(path + offset, TSDB_FILENAME_LEN, "%s%s", TD_DIRSEP, dirName[i]);
2024-11-06 07:25:50 +00:00
code = taosGetDirSize(path, &size);
2024-11-05 11:57:13 +00:00
if (code != 0) {
return code;
}
path[offset] = 0;
2024-11-06 07:25:50 +00:00
dirSize[i] = size;
2024-11-05 11:57:13 +00:00
}
pInfo->l1Size = 0;
2024-11-06 07:25:50 +00:00
pInfo->walSize = dirSize[1];
pInfo->metaSize = dirSize[2];
2024-11-06 13:22:26 +00:00
pInfo->cacheSize = dirSize[3];
return code;
}
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
int32_t code = 0;
int32_t lino = 0;
SVnode *pVnodeObj = pVnode;
if (pVnodeObj == NULL) {
return TSDB_CODE_VND_NOT_EXIST;
}
code = vnodeGetDBPrimaryInfo(pVnode, pInfo);
if (code != 0) goto _exit;
2024-11-06 07:25:50 +00:00
code = tsdbGetFsSize(pVnodeObj->pTsdb, pInfo);
_exit:
2024-11-07 09:09:57 +00:00
return code;
2024-11-05 11:57:13 +00:00
}
2025-06-30 02:33:34 +00:00
/*
* Get raw write metrics for a vnode
*/
int32_t vnodeGetRawWriteMetrics(void *pVnode, SRawWriteMetrics *pRawMetrics) {
if (pVnode == NULL || pRawMetrics == NULL) {
return TSDB_CODE_INVALID_PARA;
}
SVnode *pVnode1 = (SVnode *)pVnode;
SSyncMetrics syncMetrics = syncGetMetrics(pVnode1->sync);
// Copy values following SRawWriteMetrics structure order
pRawMetrics->total_requests = atomic_load_64(&pVnode1->writeMetrics.total_requests);
pRawMetrics->total_rows = atomic_load_64(&pVnode1->writeMetrics.total_rows);
pRawMetrics->total_bytes = atomic_load_64(&pVnode1->writeMetrics.total_bytes);
pRawMetrics->fetch_batch_meta_time = atomic_load_64(&pVnode1->writeMetrics.fetch_batch_meta_time);
pRawMetrics->fetch_batch_meta_count = atomic_load_64(&pVnode1->writeMetrics.fetch_batch_meta_count);
pRawMetrics->preprocess_time = atomic_load_64(&pVnode1->writeMetrics.preprocess_time);
pRawMetrics->wal_write_bytes = atomic_load_64(&syncMetrics.wal_write_bytes);
pRawMetrics->wal_write_time = atomic_load_64(&syncMetrics.wal_write_time);
pRawMetrics->apply_bytes = atomic_load_64(&pVnode1->writeMetrics.apply_bytes);
pRawMetrics->apply_time = atomic_load_64(&pVnode1->writeMetrics.apply_time);
pRawMetrics->commit_count = atomic_load_64(&pVnode1->writeMetrics.commit_count);
pRawMetrics->commit_time = atomic_load_64(&pVnode1->writeMetrics.commit_time);
pRawMetrics->memtable_wait_time = atomic_load_64(&pVnode1->writeMetrics.memtable_wait_time);
pRawMetrics->blocked_commit_count = atomic_load_64(&pVnode1->writeMetrics.blocked_commit_count);
pRawMetrics->blocked_commit_time = atomic_load_64(&pVnode1->writeMetrics.block_commit_time);
pRawMetrics->merge_count = atomic_load_64(&pVnode1->writeMetrics.merge_count);
pRawMetrics->merge_time = atomic_load_64(&pVnode1->writeMetrics.merge_time);
pRawMetrics->last_cache_commit_time = atomic_load_64(&pVnode1->writeMetrics.last_cache_commit_time);
pRawMetrics->last_cache_commit_count = atomic_load_64(&pVnode1->writeMetrics.last_cache_commit_count);
return 0;
}
/*
* Reset raw write metrics for a vnode by subtracting old values
*/
int32_t vnodeResetRawWriteMetrics(void *pVnode, const SRawWriteMetrics *pOldMetrics) {
if (pVnode == NULL || pOldMetrics == NULL) {
return TSDB_CODE_INVALID_PARA;
}
SVnode *pVnode1 = (SVnode *)pVnode;
// Reset vnode write metrics using atomic operations to subtract old values
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_requests, pOldMetrics->total_requests);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_rows, pOldMetrics->total_rows);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.total_bytes, pOldMetrics->total_bytes);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.fetch_batch_meta_time, pOldMetrics->fetch_batch_meta_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.fetch_batch_meta_count, pOldMetrics->fetch_batch_meta_count);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.preprocess_time, pOldMetrics->preprocess_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.apply_bytes, pOldMetrics->apply_bytes);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.apply_time, pOldMetrics->apply_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.commit_count, pOldMetrics->commit_count);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.commit_time, pOldMetrics->commit_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.merge_time, pOldMetrics->merge_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.memtable_wait_time, pOldMetrics->memtable_wait_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.blocked_commit_count, pOldMetrics->blocked_commit_count);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.block_commit_time, pOldMetrics->blocked_commit_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.merge_count, pOldMetrics->merge_count);
// Reset new cache metrics
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.last_cache_commit_time, pOldMetrics->last_cache_commit_time);
(void)atomic_sub_fetch_64(&pVnode1->writeMetrics.last_cache_commit_count, pOldMetrics->last_cache_commit_count);
// Reset sync metrics
SSyncMetrics syncMetrics = {
.wal_write_bytes = pOldMetrics->wal_write_bytes,
.wal_write_time = pOldMetrics->wal_write_time,
};
syncResetMetrics(pVnode1->sync, &syncMetrics);
return 0;
}