refactor code

This commit is contained in:
yihaoDeng 2024-12-02 18:42:01 +08:00
parent e495d39220
commit 411a476b91
6 changed files with 47 additions and 52 deletions

View File

@ -78,7 +78,6 @@ typedef enum EScanType {
SCAN_TYPE_BLOCK_INFO, SCAN_TYPE_BLOCK_INFO,
SCAN_TYPE_LAST_ROW, SCAN_TYPE_LAST_ROW,
SCAN_TYPE_TABLE_COUNT, SCAN_TYPE_TABLE_COUNT,
SCAN_TYPE_DB_DISK_USAGE,
} EScanType; } EScanType;
typedef struct SScanLogicNode { typedef struct SScanLogicNode {
@ -205,15 +204,15 @@ typedef struct SStreamNodeOption {
} SStreamNodeOption; } SStreamNodeOption;
typedef struct SInterpFuncLogicNode { typedef struct SInterpFuncLogicNode {
SLogicNode node; SLogicNode node;
SNodeList* pFuncs; SNodeList* pFuncs;
STimeWindow timeRange; STimeWindow timeRange;
int64_t interval; int64_t interval;
int8_t intervalUnit; int8_t intervalUnit;
int8_t precision; int8_t precision;
EFillMode fillMode; EFillMode fillMode;
SNode* pFillValues; // SNodeListNode SNode* pFillValues; // SNodeListNode
SNode* pTimeSeries; // SColumnNode SNode* pTimeSeries; // SColumnNode
SStreamNodeOption streamNodeOption; SStreamNodeOption streamNodeOption;
} SInterpFuncLogicNode; } SInterpFuncLogicNode;
@ -518,16 +517,16 @@ typedef struct SIndefRowsFuncPhysiNode {
} SIndefRowsFuncPhysiNode; } SIndefRowsFuncPhysiNode;
typedef struct SInterpFuncPhysiNode { typedef struct SInterpFuncPhysiNode {
SPhysiNode node; SPhysiNode node;
SNodeList* pExprs; SNodeList* pExprs;
SNodeList* pFuncs; SNodeList* pFuncs;
STimeWindow timeRange; STimeWindow timeRange;
int64_t interval; int64_t interval;
int8_t intervalUnit; int8_t intervalUnit;
int8_t precision; int8_t precision;
EFillMode fillMode; EFillMode fillMode;
SNode* pFillValues; // SNodeListNode SNode* pFillValues; // SNodeListNode
SNode* pTimeSeries; // SColumnNode SNode* pTimeSeries; // SColumnNode
SStreamNodeOption streamNodeOption; SStreamNodeOption streamNodeOption;
} SInterpFuncPhysiNode; } SInterpFuncPhysiNode;

View File

@ -529,7 +529,7 @@ static const SSysDbTableSchema consumerSchema[] = {
{.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, {.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, {.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, {.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "parameters", .bytes = 64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, {.name = "parameters", .bytes = 128 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false},
}; };
static const SSysDbTableSchema offsetSchema[] = { static const SSysDbTableSchema offsetSchema[] = {

View File

@ -97,6 +97,11 @@ typedef struct SBlockDistInfo {
uint64_t uid; // table uid uint64_t uid; // table uid
} SBlockDistInfo; } SBlockDistInfo;
typedef struct {
int8_t type;
tb_uid_t uid;
} STableId;
static int32_t sysChkFilter__Comm(SNode* pNode); static int32_t sysChkFilter__Comm(SNode* pNode);
static int32_t sysChkFilter__DBName(SNode* pNode); static int32_t sysChkFilter__DBName(SNode* pNode);
static int32_t sysChkFilter__VgroupId(SNode* pNode); static int32_t sysChkFilter__VgroupId(SNode* pNode);
@ -766,7 +771,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
SMetaReader smrChildTable = {0}; SMetaReader smrChildTable = {0};
pAPI->metaReaderFn.initReader(&smrChildTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); pAPI->metaReaderFn.initReader(&smrChildTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn);
int32_t code = pAPI->metaReaderFn.getTableEntryByName(&smrChildTable, condTableName); code = pAPI->metaReaderFn.getTableEntryByName(&smrChildTable, condTableName);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
// terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly
pAPI->metaReaderFn.clearReader(&smrChildTable); pAPI->metaReaderFn.clearReader(&smrChildTable);
@ -1958,11 +1963,12 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
SSysTableScanInfo* pInfo = pOperator->info; SSysTableScanInfo* pInfo = pOperator->info;
SDbSizeStatisInfo staticsInfo = {0}; SDbSizeStatisInfo staticsInfo = {0};
char* buf = NULL;
SSDataBlock* p = NULL; SSDataBlock* p = NULL;
int32_t numOfRows = 0;
const char* db = NULL; const char* db = NULL;
int32_t numOfCols = 0; int32_t numOfCols = 0;
int32_t numOfRows = 0;
// the retrieve is executed on the mnode, so return tables that belongs to the information schema database. // the retrieve is executed on the mnode, so return tables that belongs to the information schema database.
if (pInfo->readHandle.mnd != NULL) { if (pInfo->readHandle.mnd != NULL) {
@ -1971,7 +1977,12 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
} }
if (pInfo->pCur == NULL) { if (pInfo->pCur == NULL) {
pInfo->pCur = pAPI->metaFn.openTableMetaCursor(pInfo->readHandle.vnode); pInfo->pCur = pAPI->metaFn.openTableMetaCursor(pInfo->readHandle.vnode);
if (pInfo->pCur == NULL) {
code = terrno;
QUERY_CHECK_CODE(code, lino, _end);
}
} }
SSDataBlock* pBlock = pInfo->pRes; SSDataBlock* pBlock = pInfo->pRes;
code = buildVgDiskUsage(pOperator, &staticsInfo); code = buildVgDiskUsage(pOperator, &staticsInfo);
@ -1986,26 +1997,25 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
usageInfo.walInDiskSize = staticsInfo.walSize; usageInfo.walInDiskSize = staticsInfo.walSize;
usageInfo.rawDataSize = staticsInfo.rawDataSize; usageInfo.rawDataSize = staticsInfo.rawDataSize;
char* p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE); buf = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE);
QUERY_CHECK_NULL(p, code, lino, _end, terrno); QUERY_CHECK_NULL(buf, code, lino, _end, terrno);
int32_t tempRes = tSerializeBlockDbUsage(varDataVal(p), len, &usageInfo); int32_t tempRes = tSerializeBlockDbUsage(varDataVal(p), len, &usageInfo);
if (tempRes != len) { if (tempRes != len) {
taosMemoryFree(p); QUERY_CHECK_CODE(TSDB_CODE_INVALID_MSG, lino, _end);
QUERY_CHECK_CODE(code, lino, _end);
} }
varDataSetLen(p, len);
varDataSetLen(buf, len);
int32_t slotId = 1; int32_t slotId = 1;
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 1); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 1);
QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno); QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
code = colDataSetVal(pColInfo, 0, p, false); code = colDataSetVal(pColInfo, 0, buf, false);
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
taosMemoryFree(p); taosMemoryFreeClear(buf);
if (slotId != 0) { if (slotId != 0) {
SColumnInfoData* p1 = taosArrayGet(pBlock->pDataBlock, 0); SColumnInfoData* p1 = taosArrayGet(pBlock->pDataBlock, 0);
QUERY_CHECK_NULL(p1, code, lino, _end, terrno); QUERY_CHECK_NULL(p1, code, lino, _end, terrno);
int64_t v = 0;
// colDataSetInt64(p1, 0, &v);
} }
pBlock->info.rows = 1; pBlock->info.rows = 1;
@ -2069,8 +2079,6 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.rawDataSize, false); // estimate_size code = colDataSetVal(pColInfoData, numOfRows, (char*)&staticsInfo.rawDataSize, false); // estimate_size
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
numOfRows += 1; numOfRows += 1;
pAPI->metaFn.closeTableMetaCursor(pInfo->pCur);
pInfo->pCur = NULL;
if (numOfRows > 0) { if (numOfRows > 0) {
p->info.rows = numOfRows; p->info.rows = numOfRows;
@ -2081,7 +2089,6 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL);
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
numOfRows = 0;
} }
blockDataDestroy(p); blockDataDestroy(p);
@ -2091,6 +2098,11 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
setOperatorCompleted(pOperator); setOperatorCompleted(pOperator);
} }
_end: _end:
taosMemoryFree(buf);
if (pInfo->pCur) {
pAPI->metaFn.closeTableMetaCursor(pInfo->pCur);
pInfo->pCur = NULL;
}
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
blockDataDestroy(p); blockDataDestroy(p);
@ -2162,11 +2174,6 @@ _end:
} }
return NULL; return NULL;
} }
static SSDataBlock* sysTableScanUsageRewrite(SOperatorInfo* pOperator) {
int32_t code = TSDB_CODE_SUCCESS;
return NULL;
}
static SSDataBlock* sysTableScanUsage(SOperatorInfo* pOperator) { static SSDataBlock* sysTableScanUsage(SOperatorInfo* pOperator) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0; int32_t lino = 0;
@ -3170,16 +3177,6 @@ _error:
return code; return code;
} }
static int32_t vnodeGetEstimateRawSize(void* arg, int64_t* size) {
int32_t code = TSDB_CODE_SUCCESS;
return code;
}
typedef struct {
int8_t type;
tb_uid_t uid;
} STableId;
static int32_t buildTableListInfo(SOperatorInfo* pOperator, STableId* id, STableListInfo** ppTableListInfo) { static int32_t buildTableListInfo(SOperatorInfo* pOperator, STableId* id, STableListInfo** ppTableListInfo) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t line = 0; int32_t line = 0;

View File

@ -1092,7 +1092,6 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt); return collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt);
case QUERY_NODE_SHOW_USAGE_STMT: case QUERY_NODE_SHOW_USAGE_STMT:
return collectMetaKeyFromShowUsage(pCxt, (SShowStmt*)pStmt); return collectMetaKeyFromShowUsage(pCxt, (SShowStmt*)pStmt);
return 0;
case QUERY_NODE_DELETE_STMT: case QUERY_NODE_DELETE_STMT:
return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt); return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt);
case QUERY_NODE_INSERT_STMT: case QUERY_NODE_INSERT_STMT:

View File

@ -632,7 +632,6 @@ static ENodeType getScanOperatorType(EScanType scanType) {
return QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; return QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN;
case SCAN_TYPE_TABLE_COUNT: case SCAN_TYPE_TABLE_COUNT:
return QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN; return QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN;
case SCAN_TYPE_DB_DISK_USAGE:
default: default:
break; break;
} }

View File

@ -603,6 +603,7 @@ int taosGetDirSize(const char *path, int64_t *size) {
} }
nBytes = snprintf(fullPath, sizeof(fullPath), "%s%s%s", path, TD_DIRSEP, name); nBytes = snprintf(fullPath, sizeof(fullPath), "%s%s%s", path, TD_DIRSEP, name);
if (nBytes <= 0 || nBytes >= sizeof(fullPath)) { if (nBytes <= 0 || nBytes >= sizeof(fullPath)) {
TAOS_UNUSED(taosCloseDir(&pDir));
return TSDB_CODE_OUT_OF_RANGE; return TSDB_CODE_OUT_OF_RANGE;
} }