Merge remote-tracking branch 'origin/develop' into feature/python-test-no-sudo
This commit is contained in:
commit
73b41cb437
|
@ -33,6 +33,7 @@ Target/
|
|||
*.failed
|
||||
*.sql
|
||||
sim/
|
||||
*DS_Store
|
||||
|
||||
# Doxygen Generated files
|
||||
html/
|
||||
|
|
21
.travis.yml
21
.travis.yml
|
@ -26,10 +26,6 @@ matrix:
|
|||
- python3-setuptools
|
||||
- valgrind
|
||||
|
||||
before_install:
|
||||
- sudo apt update -y -qq
|
||||
- sudo apt install -y net-tools python-pip python-setuptools python3-pip python3-setuptools valgrind
|
||||
|
||||
before_script:
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
- mkdir debug
|
||||
|
@ -44,7 +40,7 @@ matrix:
|
|||
case $TRAVIS_OS_NAME in
|
||||
linux)
|
||||
cd ${TRAVIS_BUILD_DIR}/debug
|
||||
sudo make install || travis_terminate $?
|
||||
make install || travis_terminate $?
|
||||
|
||||
pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
|
||||
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
|
||||
|
@ -63,11 +59,14 @@ matrix:
|
|||
GREEN_UNDERLINE='\033[4;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
tail -10 mem-error-out.txt
|
||||
defiMemError=`grep -m 1 'definitely lost' mem-error-out.txt | awk '{print $7}'`
|
||||
memError=`grep -m 1 'ERROR SUMMARY' mem-error-out.txt | awk '{print $4}'`
|
||||
|
||||
if [ -n "$memError" ]; then
|
||||
if [ "$memError" -gt 23 ]; then
|
||||
echo -e "${RED} ## Memory errors number valgrind reports is $memError. More than our threshold! ## ${NC} "
|
||||
if [ "$memError" -gt 16 ] || [ "$defiMemError" -gt 0 ]; then
|
||||
echo -e "${RED} ## Memory errors number valgrind reports is $memError.\
|
||||
Definitely lost is $defiMemError. More than our threshold! ## ${NC}"
|
||||
travis_terminate $memError
|
||||
fi
|
||||
fi
|
||||
|
@ -131,10 +130,6 @@ matrix:
|
|||
- python3-setuptools
|
||||
- lcov
|
||||
|
||||
before_install:
|
||||
- sudo apt update -y -qq
|
||||
- sudo apt install -y net-tools python-pip python-setuptools python3-pip python3-setuptools lcov
|
||||
|
||||
before_script:
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
- mkdir debug
|
||||
|
@ -149,7 +144,7 @@ matrix:
|
|||
case $TRAVIS_OS_NAME in
|
||||
linux)
|
||||
cd ${TRAVIS_BUILD_DIR}/debug
|
||||
sudo make install || travis_terminate $?
|
||||
make install || travis_terminate $?
|
||||
|
||||
pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
|
||||
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
|
||||
|
@ -162,7 +157,7 @@ matrix:
|
|||
travis_terminate $?
|
||||
fi
|
||||
|
||||
sudo pkill taosd
|
||||
pkill taosd
|
||||
sleep 1
|
||||
|
||||
cd ${TRAVIS_BUILD_DIR}
|
||||
|
|
|
@ -43,7 +43,7 @@ lib_files="${build_dir}/lib/libtaos.so.${version}"
|
|||
header_files="${code_dir}/inc/taos.h ${code_dir}/inc/taoserror.h"
|
||||
cfg_dir="${top_dir}/packaging/cfg"
|
||||
install_files="${script_dir}/install.sh"
|
||||
nginx_dir="${code_dir}/../../enterprise/src/modules/web"
|
||||
nginx_dir="${code_dir}/../../enterprise/src/plugins/web"
|
||||
|
||||
# Init file
|
||||
#init_dir=${script_dir}/deb
|
||||
|
|
|
@ -15,4 +15,4 @@ ADD_SUBDIRECTORY(vnode)
|
|||
ADD_SUBDIRECTORY(tsdb)
|
||||
ADD_SUBDIRECTORY(wal)
|
||||
ADD_SUBDIRECTORY(dnode)
|
||||
#ADD_SUBDIRECTORY(connector/jdbc)
|
||||
ADD_SUBDIRECTORY(connector/jdbc)
|
||||
|
|
|
@ -57,8 +57,8 @@ typedef struct SJoinSubquerySupporter {
|
|||
int64_t interval; // interval time
|
||||
SLimitVal limit; // limit info
|
||||
uint64_t uid; // query meter uid
|
||||
SColumnBaseInfo colList; // previous query information
|
||||
SSqlExprInfo exprsInfo;
|
||||
SArray* colList; // previous query information
|
||||
SArray* exprsInfo;
|
||||
SFieldInfo fieldsInfo;
|
||||
STagCond tagCond;
|
||||
SSqlGroupbyExpr groupbyExpr;
|
||||
|
@ -69,8 +69,9 @@ typedef struct SJoinSubquerySupporter {
|
|||
|
||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
||||
STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
||||
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
|
||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||
void tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf);
|
||||
|
||||
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes,
|
||||
uint32_t offset);
|
||||
|
@ -85,8 +86,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
|
|||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||
STableDataBlocks** dataBlocks);
|
||||
|
||||
SVnodeSidList* tscGetVnodeSidList(SSuperTableMeta* pMetricmeta, int32_t vnodeIdx);
|
||||
STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
|
||||
UNUSED_FUNC STableIdInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -106,69 +106,68 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
|||
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo);
|
||||
|
||||
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
||||
bool tscQueryOnSTable(SSqlCmd* pCmd);
|
||||
bool tscQueryTags(SQueryInfo* pQueryInfo);
|
||||
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
||||
|
||||
void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex, int16_t functionId, SColumnIndex* pIndex,
|
||||
SSchema* pColSchema, int16_t isTag);
|
||||
|
||||
void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex);
|
||||
//void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex);
|
||||
void addRequiredTagColumn(STableMetaInfo* pTableMetaInfo, SColumnIndex* index);
|
||||
|
||||
int32_t setMeterID(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
||||
int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
||||
void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
||||
|
||||
bool tscIsInsertOrImportData(char* sqlstr);
|
||||
|
||||
/* use for keep current db info temporarily, for handle table with db prefix */
|
||||
// todo remove it
|
||||
void tscGetDBInfoFromMeterId(char* tableId, char* db);
|
||||
|
||||
int tscAllocPayload(SSqlCmd* pCmd, int size);
|
||||
|
||||
void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema);
|
||||
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField);
|
||||
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes);
|
||||
void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible);
|
||||
void tscFieldInfoSetExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlExpr* pExpr);
|
||||
void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionExpr* pExpr);
|
||||
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes);
|
||||
|
||||
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo);
|
||||
void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList, int32_t size);
|
||||
void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src);
|
||||
SFieldSupInfo* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField);
|
||||
SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field);
|
||||
|
||||
SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index);
|
||||
TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index);
|
||||
|
||||
void tscFieldInfoUpdateOffset(SQueryInfo* pQueryInfo);
|
||||
void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src);
|
||||
void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo);
|
||||
|
||||
TAOS_FIELD* tscFieldInfoGetField(SQueryInfo* pQueryInfo, int32_t index);
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||
int32_t tscGetResRowLength(SQueryInfo* pQueryInfo);
|
||||
void tscClearFieldInfo(SFieldInfo* pFieldInfo);
|
||||
int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index);
|
||||
void tscFieldInfoClear(SFieldInfo* pFieldInfo);
|
||||
int32_t tscNumOfFields(SQueryInfo* pQueryInfo);
|
||||
int32_t tscFieldInfoCompare(SFieldInfo* pFieldInfo1, SFieldInfo* pFieldInfo2);
|
||||
int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2);
|
||||
|
||||
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex);
|
||||
|
||||
int32_t tscGetResRowLength(SArray* pExprList);
|
||||
|
||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t interSize);
|
||||
SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId);
|
||||
int16_t size, int16_t interSize, bool isTagCol);
|
||||
|
||||
SSqlExpr* tscSqlExprAppend(SQueryInfo* pQueryInfo, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
|
||||
int16_t size, int16_t interSize, bool isTagCol);
|
||||
|
||||
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
|
||||
int16_t size);
|
||||
int32_t tscSqlExprNumOfExprs(SQueryInfo* pQueryInfo);
|
||||
|
||||
SSqlExpr* tscSqlExprGet(SQueryInfo* pQueryInfo, int32_t index);
|
||||
void tscSqlExprCopy(SSqlExprInfo* dst, const SSqlExprInfo* src, uint64_t uid, bool deepcopy);
|
||||
void* tscSqlExprDestroy(SSqlExpr* pExpr);
|
||||
void tscSqlExprInfoDestroy(SSqlExprInfo* pExprInfo);
|
||||
SArray* tscSqlExprCopy(const SArray* src, uint64_t uid, bool deepcopy);
|
||||
void tscSqlExprInfoDestroy(SArray* pExprInfo);
|
||||
|
||||
SColumnBase* tscColumnBaseInfoInsert(SQueryInfo* pQueryInfo, SColumnIndex* colIndex);
|
||||
void tscColumnFilterInfoCopy(SColumnFilterInfo* dst, const SColumnFilterInfo* src);
|
||||
void tscColumnBaseCopy(SColumnBase* dst, const SColumnBase* src);
|
||||
SColumn* tscColumnClone(const SColumn* src);
|
||||
SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex);
|
||||
void tscColumnListCopy(SArray* dst, const SArray* src, int16_t tableIndex);
|
||||
void tscColumnListDestroy(SArray* pColList);
|
||||
|
||||
void tscColumnBaseInfoCopy(SColumnBaseInfo* dst, const SColumnBaseInfo* src, int16_t tableIndex);
|
||||
SColumnBase* tscColumnBaseInfoGet(SColumnBaseInfo* pColumnBaseInfo, int32_t index);
|
||||
void tscColumnBaseInfoUpdateTableIndex(SColumnBaseInfo* pColList, int16_t tableIndex);
|
||||
|
||||
void tscColumnBaseInfoReserve(SColumnBaseInfo* pColumnBaseInfo, int32_t size);
|
||||
void tscColumnBaseInfoDestroy(SColumnBaseInfo* pColumnBaseInfo);
|
||||
SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters);
|
||||
|
||||
int32_t tscValidateName(SSQLToken* pToken);
|
||||
|
||||
|
@ -188,27 +187,25 @@ void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo);
|
|||
void tscSetFreeHeatBeat(STscObj* pObj);
|
||||
bool tscShouldFreeHeatBeat(SSqlObj* pHb);
|
||||
void tscCleanSqlCmd(SSqlCmd* pCmd);
|
||||
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
|
||||
bool tscShouldBeFreed(SSqlObj* pSql);
|
||||
|
||||
void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||
void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
|
||||
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||
|
||||
SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||
int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo);
|
||||
|
||||
STableMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index);
|
||||
void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache);
|
||||
void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache);
|
||||
|
||||
STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta,
|
||||
SVgroupsInfo* vgroupList, int16_t numOfTags, int16_t* tags);
|
||||
SVgroupsInfo* vgroupList, SArray* pTagCols);
|
||||
|
||||
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo);
|
||||
int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
|
||||
void tscFreeSubqueryInfo(SSqlCmd* pCmd);
|
||||
void tscFreeQueryInfo(SSqlCmd* pCmd);
|
||||
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
||||
|
||||
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* keyStr, uint64_t uid);
|
||||
int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex);
|
||||
int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
|
||||
int tscGetMeterMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists);
|
||||
|
@ -242,11 +239,6 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex);
|
|||
|
||||
int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid);
|
||||
|
||||
TAOS* taos_connect_a(char* ip, char* user, char* pass, char* db, uint16_t port, void (*fp)(void*, TAOS_RES*, int),
|
||||
void* param, void** taos);
|
||||
|
||||
void sortRemoveDuplicates(STableDataBlocks* dataBuf);
|
||||
|
||||
void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex);
|
||||
|
||||
bool hasMoreVnodesToTry(SSqlObj *pSql);
|
||||
|
|
|
@ -22,33 +22,31 @@ extern "C" {
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "qsqlparser.h"
|
||||
#include "qsqltype.h"
|
||||
#include "qtsbuf.h"
|
||||
#include "taos.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "tglobal.h"
|
||||
#include "trpc.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
|
||||
#include "qsqlparser.h"
|
||||
#include "qsqltype.h"
|
||||
#include "qtsbuf.h"
|
||||
#include "queryExecutor.h"
|
||||
|
||||
// forward declaration
|
||||
struct SSqlInfo;
|
||||
struct SLocalReducer;
|
||||
|
||||
// data source from sql string or from file
|
||||
enum {
|
||||
DATA_FROM_SQL_STRING = 1,
|
||||
DATA_FROM_DATA_FILE = 2,
|
||||
};
|
||||
|
||||
typedef SCMSTableVgroupRspMsg SVgroupsInfo;
|
||||
|
||||
typedef struct SSqlGroupbyExpr {
|
||||
int16_t tableIndex;
|
||||
int16_t numOfGroupCols;
|
||||
SColIndex columnInfo[TSDB_MAX_TAGS]; // group by columns information
|
||||
int16_t orderIndex; // order by column index
|
||||
int16_t orderType; // order by type: asc/desc
|
||||
} SSqlGroupbyExpr;
|
||||
|
||||
typedef struct STableComInfo {
|
||||
uint8_t numOfTags;
|
||||
uint8_t precision;
|
||||
|
@ -57,42 +55,44 @@ typedef struct STableComInfo {
|
|||
} STableComInfo;
|
||||
|
||||
typedef struct STableMeta {
|
||||
//super table if it is created according to super table, otherwise, tableInfo is used
|
||||
union { struct STableMeta* pSTable; STableComInfo tableInfo; };
|
||||
uint8_t tableType;
|
||||
int16_t sversion;
|
||||
// super table if it is created according to super table, otherwise, tableInfo is used
|
||||
union {
|
||||
struct STableMeta *pSTable;
|
||||
STableComInfo tableInfo;
|
||||
};
|
||||
uint8_t tableType;
|
||||
int16_t sversion;
|
||||
SCMVgroupInfo vgroupInfo;
|
||||
int32_t sid; // the index of one table in a virtual node
|
||||
uint64_t uid; // unique id of a table
|
||||
SSchema schema[]; // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
|
||||
int32_t sid; // the index of one table in a virtual node
|
||||
uint64_t uid; // unique id of a table
|
||||
SSchema schema[]; // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
|
||||
} STableMeta;
|
||||
|
||||
typedef struct STableMetaInfo {
|
||||
STableMeta * pTableMeta; // table meta, cached in client side and acquried by name
|
||||
SVgroupsInfo* vgroupList;
|
||||
|
||||
STableMeta * pTableMeta; // table meta, cached in client side and acquried by name
|
||||
SVgroupsInfo *vgroupList;
|
||||
|
||||
/*
|
||||
* 1. keep the vnode index during the multi-vnode super table projection query
|
||||
* 2. keep the vnode index for multi-vnode insertion
|
||||
*/
|
||||
int32_t vgroupIndex;
|
||||
char name[TSDB_TABLE_ID_LEN]; // (super) table name
|
||||
int16_t numOfTags; // total required tags in query, including groupby tags
|
||||
int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection
|
||||
SArray* tagColList; // SArray<SColumn*>, involved tag columns
|
||||
} STableMetaInfo;
|
||||
|
||||
/* the structure for sql function in select clause */
|
||||
typedef struct SSqlExpr {
|
||||
char aliasName[TSDB_COL_NAME_LEN]; // as aliasName
|
||||
SColIndex colInfo;
|
||||
int64_t uid; // refactor use the pointer
|
||||
int16_t functionId; // function id in aAgg array
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
int16_t interResBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
int32_t offset; // sub result column value of arithmetic expression.
|
||||
char aliasName[TSDB_COL_NAME_LEN]; // as aliasName
|
||||
SColIndex colInfo;
|
||||
int64_t uid; // refactor use the pointer
|
||||
int16_t functionId; // function id in aAgg array
|
||||
int16_t resType; // return value type
|
||||
int16_t resBytes; // length of return value
|
||||
int16_t interResBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
tVariant param[3]; // parameters are not more than 3
|
||||
int32_t offset; // sub result column value of arithmetic expression.
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
|
@ -100,46 +100,27 @@ typedef struct SColumnIndex {
|
|||
int16_t columnIndex;
|
||||
} SColumnIndex;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutputCols; // number of column in result
|
||||
int16_t numOfAlloc; // allocated size
|
||||
TAOS_FIELD *pFields;
|
||||
typedef struct SFieldSupInfo {
|
||||
bool visible;
|
||||
SArithExprInfo *pArithExprInfo;
|
||||
SSqlExpr * pSqlExpr;
|
||||
} SFieldSupInfo;
|
||||
|
||||
/*
|
||||
* define if this column is belong to the queried result, it may be add by parser to faciliate
|
||||
* the query process
|
||||
*
|
||||
* NOTE: these hidden columns always locate at the end of the output columns
|
||||
*/
|
||||
bool * pVisibleCols;
|
||||
int32_t numOfHiddenCols; // the number of column not belongs to the queried result columns
|
||||
SSqlFunctionExpr** pExpr; // used for aggregation arithmetic express,such as count(*)+count(*)
|
||||
SSqlExpr** pSqlExpr;
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SArray *pFields; // SArray<TAOS_FIELD>
|
||||
SArray *pSupportInfo; // SArray<SFieldSupInfo>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SSqlExprInfo {
|
||||
int16_t numOfAlloc;
|
||||
int16_t numOfExprs;
|
||||
SSqlExpr** pExprs;
|
||||
} SSqlExprInfo;
|
||||
|
||||
typedef struct SColumnBase {
|
||||
typedef struct SColumn {
|
||||
SColumnIndex colIndex;
|
||||
int32_t numOfFilters;
|
||||
SColumnFilterInfo *filterInfo;
|
||||
} SColumnBase;
|
||||
|
||||
typedef struct SColumnBaseInfo {
|
||||
int16_t numOfAlloc;
|
||||
int16_t numOfCols;
|
||||
SColumnBase *pColList;
|
||||
} SColumnBaseInfo;
|
||||
|
||||
struct SLocalReducer;
|
||||
} SColumn;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
int32_t len; // length of tag query condition data
|
||||
char * cond;
|
||||
} SCond;
|
||||
|
||||
|
@ -166,7 +147,7 @@ typedef struct STagCond {
|
|||
SJoinInfo joinInfo;
|
||||
|
||||
// for different table, the query condition must be seperated
|
||||
SArray* pCond;
|
||||
SArray *pCond;
|
||||
} STagCond;
|
||||
|
||||
typedef struct SParamInfo {
|
||||
|
@ -207,7 +188,7 @@ typedef struct STableDataBlocks {
|
|||
SParamInfo *params;
|
||||
} STableDataBlocks;
|
||||
|
||||
typedef struct SDataBlockList {
|
||||
typedef struct SDataBlockList { // todo remove
|
||||
uint32_t nSize;
|
||||
uint32_t nAlloc;
|
||||
STableDataBlocks **pData;
|
||||
|
@ -218,14 +199,14 @@ typedef struct SQueryInfo {
|
|||
uint16_t type; // query/insert/import type
|
||||
char slidingTimeUnit;
|
||||
|
||||
int64_t etime, stime;
|
||||
STimeWindow window;
|
||||
int64_t intervalTime; // aggregation time interval
|
||||
int64_t slidingTime; // sliding window in mseconds
|
||||
SSqlGroupbyExpr groupbyExpr; // group by tags info
|
||||
|
||||
SColumnBaseInfo colList;
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SSqlExprInfo exprsInfo;
|
||||
SArray * exprsInfo; // SArray<SSqlExpr*>
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
STagCond tagCond;
|
||||
|
@ -239,22 +220,16 @@ typedef struct SQueryInfo {
|
|||
int64_t clauseLimit; // limit for current sub clause
|
||||
|
||||
// offset value in the original sql expression, NOT sent to virtual node, only applied at client side
|
||||
int64_t prjOffset;
|
||||
int64_t prjOffset;
|
||||
} SQueryInfo;
|
||||
|
||||
// data source from sql string or from file
|
||||
enum {
|
||||
DATA_FROM_SQL_STRING = 1,
|
||||
DATA_FROM_DATA_FILE = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int command;
|
||||
uint8_t msgType;
|
||||
|
||||
union {
|
||||
bool existsCheck; // check if the table exists or not
|
||||
bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta
|
||||
bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta
|
||||
int8_t dataSourceType; // load data from file or not
|
||||
};
|
||||
|
||||
|
@ -271,11 +246,11 @@ typedef struct {
|
|||
int32_t payloadLen;
|
||||
SQueryInfo **pQueryInfo;
|
||||
int32_t numOfClause;
|
||||
|
||||
SDataBlockList *pDataBlocks; // submit data blocks after parsing sql
|
||||
char * curSql; // current sql, resume position of sql after parsing paused
|
||||
void * pTableList; // referred table involved in sql
|
||||
|
||||
|
||||
SDataBlockList *pDataBlocks; // submit data blocks after parsing sql
|
||||
char * curSql; // current sql, resume position of sql after parsing paused
|
||||
void * pTableList; // referred table involved in sql
|
||||
|
||||
// for parameter ('?') binding and batch processing
|
||||
int32_t batchSize;
|
||||
int32_t numOfParams;
|
||||
|
@ -286,50 +261,49 @@ typedef struct SResRec {
|
|||
int numOfTotal;
|
||||
} SResRec;
|
||||
|
||||
struct STSBuf;
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfRows; // num of results in current retrieved
|
||||
int64_t numOfTotal; // num of total results
|
||||
int64_t numOfTotalInCurrentClause; // num of total result in current subclause
|
||||
char * pRsp;
|
||||
int32_t rspType;
|
||||
int32_t rspLen;
|
||||
uint64_t qhandle;
|
||||
int64_t uid;
|
||||
int64_t useconds;
|
||||
int64_t offset; // offset value from vnode during projection query of stable
|
||||
int32_t row;
|
||||
int16_t numOfCols;
|
||||
int16_t precision;
|
||||
bool completed;
|
||||
int32_t code;
|
||||
int32_t numOfGroups;
|
||||
SResRec * pGroupRec;
|
||||
char * data;
|
||||
void ** tsrow;
|
||||
char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t)
|
||||
SColumnIndex *pColumnIndex;
|
||||
int64_t numOfRows; // num of results in current retrieved
|
||||
int64_t numOfTotal; // num of total results
|
||||
int64_t numOfTotalInCurrentClause; // num of total result in current subclause
|
||||
char * pRsp;
|
||||
int32_t rspType;
|
||||
int32_t rspLen;
|
||||
uint64_t qhandle;
|
||||
int64_t uid;
|
||||
int64_t useconds;
|
||||
int64_t offset; // offset value from vnode during projection query of stable
|
||||
int32_t row;
|
||||
int16_t numOfCols;
|
||||
int16_t precision;
|
||||
bool completed;
|
||||
int32_t code;
|
||||
int32_t numOfGroups;
|
||||
SResRec * pGroupRec;
|
||||
char * data;
|
||||
void ** tsrow;
|
||||
char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t)
|
||||
SColumnIndex * pColumnIndex;
|
||||
struct SLocalReducer *pLocalReducer;
|
||||
} SSqlRes;
|
||||
|
||||
typedef struct STscObj {
|
||||
void * signature;
|
||||
void * pTimer;
|
||||
char mgmtIp[TSDB_USER_LEN];
|
||||
uint16_t mgmtPort;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acctId[TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_TABLE_ID_LEN];
|
||||
char sversion[TSDB_VERSION_LEN];
|
||||
char writeAuth : 1;
|
||||
char superAuth : 1;
|
||||
struct SSqlObj *pSql;
|
||||
struct SSqlObj *pHb;
|
||||
struct SSqlObj *sqlList;
|
||||
void * signature;
|
||||
void * pTimer;
|
||||
char mgmtIp[TSDB_USER_LEN];
|
||||
uint16_t mgmtPort;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acctId[TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_TABLE_ID_LEN];
|
||||
char sversion[TSDB_VERSION_LEN];
|
||||
char writeAuth : 1;
|
||||
char superAuth : 1;
|
||||
void* pMgmtConn;
|
||||
struct SSqlObj * pSql;
|
||||
struct SSqlObj * pHb;
|
||||
struct SSqlObj * sqlList;
|
||||
struct SSqlStream *streamList;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutex_t mutex;
|
||||
} STscObj;
|
||||
|
||||
typedef struct SSqlObj {
|
||||
|
@ -337,23 +311,23 @@ typedef struct SSqlObj {
|
|||
STscObj *pTscObj;
|
||||
void (*fp)();
|
||||
void (*fetchFp)();
|
||||
void * param;
|
||||
uint32_t ip;
|
||||
short vnode;
|
||||
int64_t stime;
|
||||
uint32_t queryId;
|
||||
void * pStream;
|
||||
void * pSubscription;
|
||||
char * sqlstr;
|
||||
char retry;
|
||||
char maxRetry;
|
||||
SRpcIpSet ipList;
|
||||
char freed : 4;
|
||||
char listed : 4;
|
||||
tsem_t rspSem;
|
||||
SSqlCmd cmd;
|
||||
SSqlRes res;
|
||||
uint8_t numOfSubs;
|
||||
void * param;
|
||||
uint32_t ip;
|
||||
short vnode;
|
||||
int64_t stime;
|
||||
uint32_t queryId;
|
||||
void * pStream;
|
||||
void * pSubscription;
|
||||
char * sqlstr;
|
||||
char retry;
|
||||
char maxRetry;
|
||||
SRpcIpSet ipList;
|
||||
char freed : 4;
|
||||
char listed : 4;
|
||||
tsem_t rspSem;
|
||||
SSqlCmd cmd;
|
||||
SSqlRes res;
|
||||
uint8_t numOfSubs;
|
||||
struct SSqlObj **pSubs;
|
||||
struct SSqlObj * prev, *next;
|
||||
} SSqlObj;
|
||||
|
@ -386,14 +360,11 @@ typedef struct SSqlStream {
|
|||
struct SSqlStream *prev, *next;
|
||||
} SSqlStream;
|
||||
|
||||
int32_t tscInitRpc(const char *user, const char *secret);
|
||||
int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn);
|
||||
void tscInitMsgsFp();
|
||||
|
||||
// tscSql API
|
||||
int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
|
||||
|
||||
void tscInitMsgsFp();
|
||||
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
|
||||
|
||||
void tscProcessMsgFromServer(SRpcMsg *rpcMsg);
|
||||
int tscProcessSql(SSqlObj *pSql);
|
||||
|
||||
|
@ -406,12 +377,8 @@ int tscProcessLocalCmd(SSqlObj *pSql);
|
|||
int tscCfgDynamicOptions(char *msg);
|
||||
int taos_retrieve(TAOS_RES *res);
|
||||
|
||||
/*
|
||||
* transfer function for metric query in stream computing, the function need to be change
|
||||
* before send query message to vnode
|
||||
*/
|
||||
int32_t tscTansformSQLFunctionForSTableQuery(SQueryInfo *pQueryInfo);
|
||||
void tscRestoreSQLFunctionForMetricQuery(SQueryInfo *pQueryInfo);
|
||||
int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo *pQueryInfo);
|
||||
void tscRestoreSQLFuncForSTableQuery(SQueryInfo *pQueryInfo);
|
||||
|
||||
int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo);
|
||||
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
||||
|
@ -441,10 +408,13 @@ void tscFreeSqlObj(SSqlObj *pObj);
|
|||
|
||||
void tscCloseTscObj(STscObj *pObj);
|
||||
|
||||
void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const char* sqlstr, size_t sqlLen);
|
||||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, void **taos);
|
||||
|
||||
void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, void (*fp)(), void *param, const char *sqlstr, size_t sqlLen);
|
||||
|
||||
void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql);
|
||||
void tscKillMetricQuery(SSqlObj *pSql);
|
||||
void tscKillSTableQuery(SSqlObj *pSql);
|
||||
void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen);
|
||||
bool tscIsUpdateQuery(STscObj *pObj);
|
||||
bool tscHasReachLimitation(SQueryInfo *pQueryInfo, SSqlRes *pRes);
|
||||
|
@ -453,19 +423,20 @@ char *tscGetErrorMsgPayload(SSqlCmd *pCmd);
|
|||
|
||||
int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *sql);
|
||||
|
||||
void tscQueueAsyncFreeResult(SSqlObj *pSql);
|
||||
int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
||||
void tscQueueAsyncFreeResult(SSqlObj *pSql);
|
||||
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
|
||||
char * tscGetResultColumnChr(SSqlRes *pRes, SQueryInfo *pQueryInfo, int32_t column);
|
||||
|
||||
extern void * pVnodeConn;
|
||||
extern void * pTscMgmtConn;
|
||||
extern void * tscCacheHandle;
|
||||
extern int slaveIndex;
|
||||
extern void * tscTmr;
|
||||
extern void * tscQhandle;
|
||||
extern int tscKeepConn[];
|
||||
extern int tsInsertHeadSize;
|
||||
extern int tscNumOfThreads;
|
||||
extern SRpcIpSet tscMgmtIpSet;
|
||||
extern void * pVnodeConn;
|
||||
extern void * tscCacheHandle;
|
||||
extern void * tscTmr;
|
||||
extern void * tscQhandle;
|
||||
extern int tscKeepConn[];
|
||||
extern int tsInsertHeadSize;
|
||||
extern int tscNumOfThreads;
|
||||
extern SRpcIpSet tscMgmtIpSet;
|
||||
|
||||
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
|
||||
|
||||
typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
|
|
|
@ -281,7 +281,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
|
|||
|
||||
int code = taos_query(tscon, dst);
|
||||
if (code != 0) {
|
||||
jniError("jobj:%p, conn:%p, code:%d, msg:%s", jobj, tscon, code, taos_errstr(tscon));
|
||||
jniError("jobj:%p, conn:%p, code:%s, msg:%s", jobj, tscon, tstrerror(code), taos_errstr(tscon));
|
||||
free(dst);
|
||||
return JNI_TDENGINE_ERROR;
|
||||
} else {
|
||||
|
@ -290,9 +290,9 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
|
|||
|
||||
if (pSql->cmd.command == TSDB_SQL_INSERT) {
|
||||
affectRows = taos_affected_rows(tscon);
|
||||
jniTrace("jobj:%p, conn:%p, code:%d, affect rows:%d", jobj, tscon, code, affectRows);
|
||||
jniTrace("jobj:%p, conn:%p, code:%s, affect rows:%d", jobj, tscon, tstrerror(code), affectRows);
|
||||
} else {
|
||||
jniTrace("jobj:%p, conn:%p, code:%d", jobj, tscon, code);
|
||||
jniTrace("jobj:%p, conn:%p, code:%s", jobj, tscon, tstrerror(code));
|
||||
}
|
||||
|
||||
free(dst);
|
||||
|
|
|
@ -46,7 +46,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const
|
|||
pSql->signature = pSql;
|
||||
pSql->param = param;
|
||||
pSql->pTscObj = pObj;
|
||||
pSql->maxRetry = 1;
|
||||
pSql->maxRetry = TSDB_MAX_REPLICA_NUM;
|
||||
pSql->fp = fp;
|
||||
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
|
||||
|
@ -287,9 +287,9 @@ void tscAsyncFetchSingleRowProxy(void *param, TAOS_RES *tres, int numOfRows) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i){
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
if (pExpr != NULL) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
// pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pSup->pSqlExpr->resBytes * pRes->row;
|
||||
} else {
|
||||
//todo add
|
||||
}
|
||||
|
@ -308,11 +308,12 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols; ++i) {
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
if (pExpr != NULL) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pSup = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
|
||||
if (pSup->pSqlExpr != NULL) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i);
|
||||
} else {
|
||||
//todo add
|
||||
// todo add
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +333,7 @@ void tscProcessAsyncRes(SSchedMsg *pMsg) {
|
|||
int code = pRes->code;
|
||||
|
||||
// in case of async insert, restore the user specified callback function
|
||||
bool shouldFree = tscShouldFreeAsyncSqlObj(pSql);
|
||||
bool shouldFree = tscShouldBeFreed(pSql);
|
||||
|
||||
if (cmd == TSDB_SQL_INSERT) {
|
||||
assert(pSql->fp != NULL);
|
||||
|
@ -487,7 +488,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
*/
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
tscTansformSQLFunctionForSTableQuery(pQueryInfo);
|
||||
tscTansformSQLFuncForSTableQuery(pQueryInfo);
|
||||
tscIncStreamExecutionCount(pSql->pStream);
|
||||
} else {
|
||||
tscTrace("%p get tableMeta successfully", pSql);
|
||||
|
|
|
@ -2940,7 +2940,7 @@ static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
char *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
|
||||
|
||||
pCtx->aOutputBuf += pCtx->inputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/;
|
||||
pCtx->aOutputBuf += pCtx->inputBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3294,29 +3294,26 @@ static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
}
|
||||
}
|
||||
|
||||
char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
|
||||
char *getArithColumnData(void *param, const char* name, int32_t colId) {
|
||||
SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
|
||||
|
||||
SSqlFunctionExpr *pExpr = pSupport->pExpr;
|
||||
int32_t colIndex = -1;
|
||||
|
||||
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||
if (colId == pExpr->binExprInfo.pReqColumns[i].colId) {
|
||||
colIndex = pExpr->binExprInfo.pReqColumns[i].colIndex;
|
||||
int32_t index = -1;
|
||||
for (int32_t i = 0; i < pSupport->numOfCols; ++i) {
|
||||
if (colId == pSupport->colList[i].colId) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(colIndex >= 0 && colId >= 0);
|
||||
return pSupport->data[colIndex] + pSupport->offset * pSupport->elemSize[colIndex];
|
||||
assert(index >= 0 && colId >= 0);
|
||||
return pSupport->data[index] + pSupport->offset * pSupport->colList[index].bytes;
|
||||
}
|
||||
|
||||
static void arithmetic_function(SQLFunctionCtx *pCtx) {
|
||||
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
|
||||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
arithmetic_callback_function);
|
||||
tExprTreeCalcTraverse(sas->pArithExpr->pExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order, getArithColumnData);
|
||||
|
||||
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size;
|
||||
pCtx->param[1].pz = NULL;
|
||||
|
@ -3327,10 +3324,9 @@ static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||
|
||||
sas->offset = index;
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
|
||||
arithmetic_callback_function);
|
||||
tExprTreeCalcTraverse(sas->pArithExpr->pExpr, 1, pCtx->aOutputBuf, sas, pCtx->order, getArithColumnData);
|
||||
|
||||
pCtx->aOutputBuf += pCtx->outputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/;
|
||||
pCtx->aOutputBuf += pCtx->outputBytes;
|
||||
}
|
||||
|
||||
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
|
||||
|
|
|
@ -130,13 +130,13 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
SSchema *pSchema = tscGetTableSchema(pMeta);
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
||||
TSDB_COL_NAME_LEN);
|
||||
|
||||
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
||||
|
||||
int32_t bytes = pSchema[i].bytes;
|
||||
|
@ -144,10 +144,10 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
bytes = bytes / TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 2);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2);
|
||||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
|
||||
if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) {
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i, "tag",
|
||||
strlen("tag") + 1);
|
||||
|
@ -162,18 +162,18 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
char *pTagValue = tsGetTagsValue(pMeta);
|
||||
for (int32_t i = numOfRows; i < totalNumOfRows; ++i) {
|
||||
// field name
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i, pSchema[i].name,
|
||||
TSDB_COL_NAME_LEN);
|
||||
|
||||
// type name
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 1);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
|
||||
char *type = tDataTypeDesc[pSchema[i].type].aName;
|
||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i, type, pField->bytes);
|
||||
|
||||
// type length
|
||||
int32_t bytes = pSchema[i].bytes;
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 2);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 2);
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
bytes = bytes / TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||
|
||||
// tag value
|
||||
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3);
|
||||
char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i;
|
||||
|
||||
if (isNull(pTagValue, pSchema[i].type)) {
|
||||
|
@ -236,31 +236,51 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
|||
static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, int32_t typeColLength,
|
||||
int32_t noteColLength) {
|
||||
int32_t rowLen = 0;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
pCmd->numOfCols = numOfCols;
|
||||
SColumnIndex index = {0};
|
||||
|
||||
pSql->cmd.numOfCols = numOfCols;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, "Field", TSDB_COL_NAME_LEN);
|
||||
TAOS_FIELD f = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_COL_NAME_LEN};
|
||||
strncpy(f.name, "Field", TSDB_COL_NAME_LEN);
|
||||
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, TSDB_COL_NAME_LEN,
|
||||
TSDB_COL_NAME_LEN, false);
|
||||
|
||||
rowLen += TSDB_COL_NAME_LEN;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 1, TSDB_DATA_TYPE_BINARY, "Type", typeColLength);
|
||||
f.bytes = typeColLength;
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
strncpy(f.name, "Type", TSDB_COL_NAME_LEN);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength,
|
||||
typeColLength, false);
|
||||
|
||||
rowLen += typeColLength;
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 2, TSDB_DATA_TYPE_INT, "Length", sizeof(int32_t));
|
||||
f.bytes = sizeof(int32_t);
|
||||
f.type = TSDB_DATA_TYPE_INT;
|
||||
strncpy(f.name, "Length", TSDB_COL_NAME_LEN);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t),
|
||||
sizeof(int32_t), false);
|
||||
|
||||
rowLen += sizeof(int32_t);
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 3, TSDB_DATA_TYPE_BINARY, "Note", noteColLength);
|
||||
rowLen += noteColLength;
|
||||
f.bytes = noteColLength;
|
||||
f.type = TSDB_DATA_TYPE_BINARY;
|
||||
strncpy(f.name, "Note", TSDB_COL_NAME_LEN);
|
||||
|
||||
//set the sqlexpr part
|
||||
SColumnIndex index = {0};
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[0] = tscSqlExprInsert(pQueryInfo, 0, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, TSDB_COL_NAME_LEN, TSDB_COL_NAME_LEN);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[1] = tscSqlExprInsert(pQueryInfo, 1, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength, typeColLength);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[2] = tscSqlExprInsert(pQueryInfo, 2, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_INT, sizeof(int32_t), sizeof(int32_t));
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[3] = tscSqlExprInsert(pQueryInfo, 3, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength, noteColLength);
|
||||
|
||||
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength,
|
||||
noteColLength, false);
|
||||
|
||||
rowLen += noteColLength;
|
||||
return rowLen;
|
||||
}
|
||||
|
||||
|
@ -280,7 +300,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
|||
|
||||
int32_t rowLen =
|
||||
tscBuildMeterSchemaResultFields(pSql, NUM_OF_DESCRIBE_TABLE_COLUMNS, TYPE_COLUMN_LENGTH, note_field_length);
|
||||
tscFieldInfoCalOffset(pQueryInfo);
|
||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||
return tscSetValueToResObj(pSql, rowLen);
|
||||
}
|
||||
|
||||
|
@ -310,7 +330,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
int32_t totalNumOfResults = pMetricMeta->numOfTables;
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
|
||||
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
||||
|
||||
|
@ -321,7 +341,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
for (int32_t j = 0; j < pSidList->numOfSids; ++j) {
|
||||
STableIdInfo *pSidExt = tscGetMeterSidInfo(pSidList, j);
|
||||
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
|
||||
SColIndex *pColIndex = &tscSqlExprGet(pQueryInfo, k)->colInfo;
|
||||
int16_t offsetId = pColIndex->colIdx;
|
||||
|
||||
|
@ -329,7 +349,7 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
|||
assert(0);
|
||||
|
||||
char * val = NULL;//pSidExt->tags + vOffset[offsetId];
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
|
||||
|
||||
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, k) * totalNumOfResults + pField->bytes * rowIdx, val,
|
||||
(size_t)pField->bytes);
|
||||
|
@ -350,17 +370,17 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
|||
#if 0
|
||||
SSuperTableMeta *pMetricMeta = tscGetMetaInfo(pQueryInfo, 0)->pMetricMeta;
|
||||
int32_t totalNumOfResults = 1; // count function only produce one result
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowLen = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
|
||||
tscInitResObjForLocalQuery(pSql, totalNumOfResults, rowLen);
|
||||
|
||||
int32_t rowIdx = 0;
|
||||
for (int32_t i = 0; i < totalNumOfResults; ++i) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutputCols; ++k) {
|
||||
for (int32_t k = 0; k < pQueryInfo->fieldsInfo.numOfOutput; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
if (pExpr->colInfo.colIdx == -1 && pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, k);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, k);
|
||||
|
||||
memcpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, i) * totalNumOfResults + pField->bytes * rowIdx,
|
||||
&pMetricMeta->numOfTables, sizeof(pMetricMeta->numOfTables));
|
||||
|
@ -388,7 +408,7 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
|||
return pSql->res.code;
|
||||
}
|
||||
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr *pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
if (pExpr->functionId == TSDB_FUNC_COUNT) {
|
||||
return tscBuildMetricTagSqlFunctionResult(pSql);
|
||||
} else {
|
||||
|
@ -399,7 +419,7 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
|||
static void tscProcessCurrentUser(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
|
@ -414,7 +434,7 @@ static void tscProcessCurrentDB(SSqlObj *pSql) {
|
|||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN);
|
||||
}
|
||||
|
||||
|
@ -422,14 +442,14 @@ static void tscProcessServerVer(SSqlObj *pSql) {
|
|||
const char* v = pSql->pTscObj->sversion;
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, tListLen(pSql->pTscObj->sversion));
|
||||
}
|
||||
|
||||
static void tscProcessClientVer(SSqlObj *pSql) {
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version));
|
||||
}
|
||||
|
||||
|
@ -449,7 +469,7 @@ static void tscProcessServStatus(SSqlObj *pSql) {
|
|||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2);
|
||||
}
|
||||
|
||||
|
@ -462,13 +482,16 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
|||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||
|
||||
tscClearFieldInfo(&pQueryInfo->fieldsInfo);
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||
|
||||
tscFieldInfoSetValue(&pQueryInfo->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength);
|
||||
tscInitResObjForLocalQuery(pSql, 1, valueLength);
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[0] = pQueryInfo->exprsInfo.pExprs[0];
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
|
||||
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprsInfo, 0);
|
||||
|
||||
strncpy(pRes->data, val, pField->bytes);
|
||||
}
|
||||
|
|
|
@ -613,7 +613,7 @@ static void tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, in
|
|||
}
|
||||
|
||||
// data block is disordered, sort it in ascending order
|
||||
void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
|
||||
void tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf) {
|
||||
SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData;
|
||||
|
||||
// size is less than the total size, since duplicated rows may be removed yet.
|
||||
|
@ -779,7 +779,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
STableMetaInfo *pSTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX);
|
||||
setMeterID(pSTableMeterMetaInfo, &sToken, pSql);
|
||||
tscSetTableId(pSTableMeterMetaInfo, &sToken, pSql);
|
||||
|
||||
strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
|
||||
code = tscGetTableMeta(pSql, pSTableMeterMetaInfo);
|
||||
|
@ -922,7 +922,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
return tscInvalidSQLErrMsg(pCmd->payload, "invalid table name", *sqlstr);
|
||||
}
|
||||
|
||||
int32_t ret = setMeterID(pTableMetaInfo, &tableToken, pSql);
|
||||
int32_t ret = tscSetTableId(pTableMetaInfo, &tableToken, pSql);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1059,7 +1059,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
|||
goto _error_clean;
|
||||
}
|
||||
|
||||
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tscSetTableId(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,15 +209,15 @@ void tscKillStream(STscObj *pObj, uint32_t killId) {
|
|||
}
|
||||
|
||||
char *tscBuildQueryStreamDesc(char *pMsg, STscObj *pObj) {
|
||||
SQqueryList *pQList = (SQqueryList *)pMsg;
|
||||
char * pMax = pMsg + TSDB_PAYLOAD_SIZE - 256;
|
||||
|
||||
SQueryDesc *pQdesc = pQList->qdesc;
|
||||
|
||||
SQqueryList *pQList = (SQqueryList *)pMsg;
|
||||
pQList->numOfQueries = 0;
|
||||
|
||||
SQueryDesc *pQdesc = (SQueryDesc*)(pMsg + sizeof(SQqueryList));
|
||||
|
||||
// We extract the lock to tscBuildHeartBeatMsg function.
|
||||
/* pthread_mutex_lock (&pObj->mutex); */
|
||||
|
||||
pMsg += sizeof(SQqueryList);
|
||||
SSqlObj *pSql = pObj->sqlList;
|
||||
while (pSql) {
|
||||
|
@ -244,8 +244,9 @@ char *tscBuildQueryStreamDesc(char *pMsg, STscObj *pObj) {
|
|||
}
|
||||
|
||||
SStreamList *pSList = (SStreamList *)pMsg;
|
||||
SStreamDesc *pSdesc = pSList->sdesc;
|
||||
pSList->numOfStreams = 0;
|
||||
|
||||
SStreamDesc *pSdesc = (SStreamDesc*) (pMsg + sizeof(SStreamList));
|
||||
|
||||
pMsg += sizeof(SStreamList);
|
||||
SSqlStream *pStream = pObj->streamList;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -161,9 +161,9 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
|||
pTableMeta->tableType = pTableMetaMsg->tableType;
|
||||
|
||||
pTableMeta->tableInfo = (STableComInfo) {
|
||||
.numOfTags = pTableMetaMsg->numOfTags,
|
||||
.numOfTags = pTableMetaMsg->numOfTags,
|
||||
.precision = pTableMetaMsg->precision,
|
||||
.numOfColumns = pTableMetaMsg->numOfColumns,
|
||||
.precision = pTableMetaMsg->precision
|
||||
};
|
||||
|
||||
pTableMeta->sid = pTableMetaMsg->sid;
|
||||
|
@ -172,7 +172,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
|||
|
||||
memcpy(pTableMeta->schema, pTableMetaMsg->schema, schemaSize);
|
||||
|
||||
int32_t numOfTotalCols = pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags;
|
||||
int32_t numOfTotalCols = pTableMeta->tableInfo.numOfColumns;
|
||||
for(int32_t i = 0; i < numOfTotalCols; ++i) {
|
||||
pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,9 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
|
|||
* merge requirement. So, the final result in pRes structure is formatted in accordance with the pCmd object.
|
||||
*/
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pReducer->pCtx[i];
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
|
@ -108,10 +110,10 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SSqlRes *pRes, SLocalReducer *pRedu
|
|||
|
||||
int16_t n = 0;
|
||||
int16_t tagLen = 0;
|
||||
SQLFunctionCtx **pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutputCols, POINTER_BYTES);
|
||||
SQLFunctionCtx **pTagCtx = calloc(pQueryInfo->fieldsInfo.numOfOutput, POINTER_BYTES);
|
||||
|
||||
SQLFunctionCtx *pCtx = NULL;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAG_DUMMY || pExpr->functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
tagLen += pExpr->resBytes;
|
||||
|
@ -254,12 +256,13 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
// the input data format follows the old format, but output in a new format.
|
||||
// so, all the input must be parsed as old format
|
||||
pReducer->pCtx = (SQLFunctionCtx *)calloc(pQueryInfo->exprsInfo.numOfExprs, sizeof(SQLFunctionCtx));
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
pReducer->pCtx = (SQLFunctionCtx *)calloc(size, sizeof(SQLFunctionCtx));
|
||||
pReducer->rowSize = pMemBuffer[0]->nElemSize;
|
||||
|
||||
tscRestoreSQLFunctionForMetricQuery(pQueryInfo);
|
||||
tscFieldInfoCalOffset(pQueryInfo);
|
||||
tscRestoreSQLFuncForSTableQuery(pQueryInfo);
|
||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||
|
||||
if (pReducer->rowSize > pMemBuffer[0]->pageSize) {
|
||||
assert(false); // todo fixed row size is larger than the minimum page size;
|
||||
|
@ -279,7 +282,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16;
|
||||
pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage));
|
||||
|
||||
int32_t finalRowLength = tscGetResRowLength(pQueryInfo);
|
||||
int32_t finalRowLength = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
pReducer->resColModel = finalmodel;
|
||||
pReducer->resColModel->capacity = pReducer->nResultBufSize / finalRowLength;
|
||||
assert(finalRowLength <= pReducer->rowSize);
|
||||
|
@ -301,7 +304,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
}
|
||||
|
||||
pReducer->pTempBuffer->numOfElems = 0;
|
||||
pReducer->pResInfo = calloc((size_t)pQueryInfo->exprsInfo.numOfExprs, sizeof(SResultInfo));
|
||||
pReducer->pResInfo = calloc(size, sizeof(SResultInfo));
|
||||
|
||||
tscCreateResPointerInfo(pRes, pQueryInfo);
|
||||
tscInitSqlContext(pCmd, pRes, pReducer, pDesc);
|
||||
|
@ -324,7 +327,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||
|
||||
int16_t prec = tinfo.precision;
|
||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||
int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey;
|
||||
int64_t revisedSTime =
|
||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, prec);
|
||||
|
||||
|
@ -332,7 +335,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||
pReducer->rowSize);
|
||||
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) {
|
||||
pInterpoInfo->pTags[0] = (char *)pInterpoInfo->pTags + POINTER_BYTES * pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
@ -462,7 +465,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
taosDestoryInterpoInfo(&pLocalReducer->interpolationInfo);
|
||||
|
||||
if (pLocalReducer->pCtx != NULL) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[i];
|
||||
|
||||
tVariantDestroy(&pCtx->tag);
|
||||
|
@ -480,7 +483,7 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
|
|||
tfree(pLocalReducer->pResultBuf);
|
||||
|
||||
if (pLocalReducer->pResInfo != NULL) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pLocalReducer->pResInfo[i].interResultBuf);
|
||||
}
|
||||
|
||||
|
@ -532,7 +535,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm
|
|||
}
|
||||
|
||||
if (numOfGroupByCols > 0) {
|
||||
int32_t startCols = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startCols = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
// tags value locate at the last columns
|
||||
for (int32_t i = 0; i < pQueryInfo->groupbyExpr.numOfGroupCols; ++i) {
|
||||
|
@ -612,8 +615,10 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * pQueryInfo->exprsInfo.numOfExprs);
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size);
|
||||
if (pSchema == NULL) {
|
||||
tscError("%p failed to allocate memory", pSql);
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
|
@ -621,7 +626,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
}
|
||||
|
||||
int32_t rlen = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
pSchema[i].bytes = pExpr->resBytes;
|
||||
|
@ -634,8 +639,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
if (rlen != 0) {
|
||||
capacity = nBufferSizes / rlen;
|
||||
}
|
||||
|
||||
pModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
||||
|
||||
pModel = createColumnModel(pSchema, size, capacity);
|
||||
|
||||
size_t numOfSubs = pTableMetaInfo->vgroupList->numOfVgroups;
|
||||
for (int32_t i = 0; i < numOfSubs; ++i) {
|
||||
|
@ -649,8 +654,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
}
|
||||
|
||||
// final result depends on the fields number
|
||||
memset(pSchema, 0, sizeof(SSchema) * pQueryInfo->exprsInfo.numOfExprs);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
memset(pSchema, 0, sizeof(SSchema) * size);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
SSchema *p1 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex);
|
||||
|
@ -683,8 +688,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
|||
pSchema[i].bytes = bytes;
|
||||
strcpy(pSchema[i].name, pModel->pFields[i].field.name);
|
||||
}
|
||||
|
||||
*pFinalModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
||||
|
||||
*pFinalModel = createColumnModel(pSchema, size, capacity);
|
||||
tfree(pSchema);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -782,7 +787,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
|||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||
|
||||
int16_t prec = tinfo.precision;
|
||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||
int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey;
|
||||
int64_t revisedSTime =
|
||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, prec);
|
||||
|
||||
|
@ -800,7 +805,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
|||
// static void reversedCopyResultToDstBuf(SQueryInfo* pQueryInfo, SSqlRes *pRes, tFilePage *pFinalDataPage) {
|
||||
//
|
||||
// for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
// TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
// TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
//
|
||||
// int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
// char * src = pFinalDataPage->data + (pRes->numOfRows - 1) * pField->bytes + pRes->numOfRows * offset;
|
||||
|
@ -817,8 +822,10 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
|||
static void reversedCopyFromInterpolationToDstBuf(SQueryInfo *pQueryInfo, SSqlRes *pRes, tFilePage **pResPages,
|
||||
SLocalReducer *pLocalReducer) {
|
||||
assert(0);
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
int32_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
assert(offset == getColumnModelOffset(pLocalReducer->resColModel, i));
|
||||
|
@ -894,7 +901,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, &pLocalReducer->interpolationInfo);
|
||||
}
|
||||
|
||||
int32_t rowSize = tscGetResRowLength(pQueryInfo);
|
||||
int32_t rowSize = tscGetResRowLength(pQueryInfo->exprsInfo);
|
||||
memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize);
|
||||
|
||||
pFinalDataPage->numOfElems = 0;
|
||||
|
@ -905,18 +912,18 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
|
||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
|
||||
int64_t actualETime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||
int64_t actualETime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.ekey : pQueryInfo->window.skey;
|
||||
|
||||
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
tFilePage **pResPages = malloc(POINTER_BYTES * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
pResPages[i] = calloc(1, sizeof(tFilePage) + pField->bytes * pLocalReducer->resColModel->capacity);
|
||||
}
|
||||
|
||||
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
int32_t *functions = (int32_t *)((char *)srcData + pQueryInfo->fieldsInfo.numOfOutputCols * sizeof(void *));
|
||||
char ** srcData = (char **)malloc((POINTER_BYTES + sizeof(int32_t)) * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
int32_t *functions = (int32_t *)((char *)srcData + pQueryInfo->fieldsInfo.numOfOutput * sizeof(void *));
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
srcData[i] =
|
||||
pLocalReducer->pBufForInterpo + tscFieldInfoGetOffset(pQueryInfo, i) * pInterpoInfo->numOfRawDataInRows;
|
||||
functions[i] = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
|
@ -943,8 +950,8 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
newRows -= pQueryInfo->limit.offset;
|
||||
|
||||
if (pQueryInfo->limit.offset > 0) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
memmove(pResPages[i]->data, pResPages[i]->data + pField->bytes * pQueryInfo->limit.offset,
|
||||
newRows * pField->bytes);
|
||||
}
|
||||
|
@ -992,8 +999,8 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
}
|
||||
|
||||
if (pQueryInfo->order.order == TSDB_ORDER_ASC) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
int16_t offset = getColumnModelOffset(pLocalReducer->resColModel, i);
|
||||
memcpy(pRes->data + offset * pRes->numOfRows, pResPages[i]->data, pField->bytes * pRes->numOfRows);
|
||||
}
|
||||
|
@ -1003,7 +1010,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
|||
}
|
||||
|
||||
pFinalDataPage->numOfElems = 0;
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
tfree(pResPages[i]);
|
||||
}
|
||||
tfree(pResPages);
|
||||
|
@ -1030,8 +1037,9 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer)
|
|||
static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, bool needInit) {
|
||||
// the tag columns need to be set before all functions execution
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, j);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j];
|
||||
|
||||
|
@ -1051,7 +1059,7 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer,
|
|||
}
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
int32_t functionId = tscSqlExprGet(pQueryInfo, j)->functionId;
|
||||
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
|
||||
continue;
|
||||
|
@ -1071,8 +1079,9 @@ static void handleUnprocessedRow(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, tF
|
|||
|
||||
static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx) {
|
||||
int64_t maxOutput = 0;
|
||||
|
||||
for (int32_t j = 0; j < pQueryInfo->exprsInfo.numOfExprs; ++j) {
|
||||
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for (int32_t j = 0; j < size; ++j) {
|
||||
// SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[j];
|
||||
// if (pExpr == NULL) {
|
||||
// assert(pQueryInfo->fieldsInfo.pExpr[j] != NULL);
|
||||
|
@ -1107,7 +1116,9 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
|
|||
*/
|
||||
static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLocalReducer *pLocalReducer) {
|
||||
int32_t maxBufSize = 0; // find the max tags column length to prepare the buffer
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
if (maxBufSize < pExpr->resBytes && pExpr->functionId == TSDB_FUNC_TAG) {
|
||||
maxBufSize = pExpr->resBytes;
|
||||
|
@ -1117,7 +1128,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
|
|||
assert(maxBufSize >= 0);
|
||||
|
||||
char *buf = malloc((size_t)maxBufSize);
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG) {
|
||||
continue;
|
||||
|
@ -1139,7 +1150,9 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo
|
|||
}
|
||||
|
||||
int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) {
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]);
|
||||
}
|
||||
|
@ -1242,7 +1255,7 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
#endif
|
||||
|
||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutputCols - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
int32_t startIndex = pQueryInfo->fieldsInfo.numOfOutput - pQueryInfo->groupbyExpr.numOfGroupCols;
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->groupbyExpr.numOfGroupCols; ++i) {
|
||||
int16_t offset = getColumnModelOffset(pModel, startIndex + i);
|
||||
|
@ -1258,7 +1271,7 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no
|
|||
}
|
||||
|
||||
void resetOutputBuf(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) { // reset output buffer to the beginning
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
pLocalReducer->pCtx[i].aOutputBuf =
|
||||
pLocalReducer->pResultBuf->data + tscFieldInfoGetOffset(pQueryInfo, i) * pLocalReducer->resColModel->capacity;
|
||||
}
|
||||
|
@ -1282,7 +1295,7 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
|
|||
|
||||
// for group result interpolation, do not return if not data is generated
|
||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||
int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey;
|
||||
int64_t newTime =
|
||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, precision);
|
||||
|
||||
|
@ -1348,7 +1361,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
|
|||
prevGroupCompleted) {
|
||||
// if interpoType == TSDB_INTERPO_NONE, return directly
|
||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||
int64_t etime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||
int64_t etime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.ekey : pQueryInfo->window.skey;
|
||||
|
||||
etime = taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->intervalTime,
|
||||
pQueryInfo->slidingTimeUnit, precision);
|
||||
|
@ -1386,8 +1399,9 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) {
|
|||
|
||||
SLocalReducer *pLocalReducer = pRes->pLocalReducer;
|
||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
size_t size = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
for (int32_t k = 0; k < size; ++k) {
|
||||
SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k];
|
||||
|
||||
|
|
|
@ -163,11 +163,13 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
|
|||
tscGetQueryInfoDetailSafely(&pSql->cmd, 0, &pQueryInfo);
|
||||
pQueryInfo->command = TSDB_SQL_HB;
|
||||
|
||||
pSql->cmd.command = TSDB_SQL_HB;
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(&(pSql->cmd), TSDB_DEFAULT_PAYLOAD_SIZE)) {
|
||||
tfree(pSql);
|
||||
return;
|
||||
}
|
||||
|
||||
pSql->cmd.command = TSDB_SQL_HB;
|
||||
pSql->param = pObj;
|
||||
pSql->pTscObj = pObj;
|
||||
pSql->signature = pSql;
|
||||
|
@ -188,6 +190,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
|
|||
}
|
||||
|
||||
int tscSendMsgToServer(SSqlObj *pSql) {
|
||||
STscObj* pObj = pSql->pTscObj;
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
||||
char *pMsg = rpcMallocCont(pCmd->payloadLen);
|
||||
|
@ -221,7 +224,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
|
|||
.handle = pSql,
|
||||
.code = 0
|
||||
};
|
||||
rpcSendRequest(pTscMgmtConn, &pSql->ipList, &rpcMsg);
|
||||
rpcSendRequest(pObj->pMgmtConn, &pSql->ipList, &rpcMsg);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -359,13 +362,13 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
|
|||
|
||||
/*
|
||||
* Whether to free sqlObj or not should be decided before call the user defined function, since this SqlObj
|
||||
* may be freed in UDF, and reused by other threads before tscShouldFreeAsyncSqlObj called, in which case
|
||||
* tscShouldFreeAsyncSqlObj checks an object which is actually allocated by other threads.
|
||||
* may be freed in UDF, and reused by other threads before tscShouldBeFreed called, in which case
|
||||
* tscShouldBeFreed checks an object which is actually allocated by other threads.
|
||||
*
|
||||
* If this block of memory is re-allocated for an insert thread, in which tscKeepConn[command] equals to 0,
|
||||
* the tscShouldFreeAsyncSqlObj will success and tscFreeSqlObj free it immediately.
|
||||
* the tscShouldBeFreed will success and tscFreeSqlObj free it immediately.
|
||||
*/
|
||||
bool shouldFree = tscShouldFreeAsyncSqlObj(pSql);
|
||||
bool shouldFree = tscShouldBeFreed(pSql);
|
||||
(*pSql->fp)(pSql->param, taosres, rpcMsg->code);
|
||||
|
||||
if (shouldFree) {
|
||||
|
@ -380,7 +383,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
|
|||
int doProcessSql(SSqlObj *pSql) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pCmd->command == TSDB_SQL_SELECT ||
|
||||
pCmd->command == TSDB_SQL_FETCH ||
|
||||
pCmd->command == TSDB_SQL_RETRIEVE ||
|
||||
|
@ -389,10 +393,15 @@ int doProcessSql(SSqlObj *pSql) {
|
|||
pCmd->command == TSDB_SQL_HB ||
|
||||
pCmd->command == TSDB_SQL_META ||
|
||||
pCmd->command == TSDB_SQL_STABLEVGROUP) {
|
||||
tscBuildMsg[pCmd->command](pSql, NULL);
|
||||
pRes->code = tscBuildMsg[pCmd->command](pSql, NULL);
|
||||
}
|
||||
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
tscQueueAsyncRes(pSql);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
int32_t code = tscSendMsgToServer(pSql);
|
||||
code = tscSendMsgToServer(pSql);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRes->code = code;
|
||||
tscQueueAsyncRes(pSql);
|
||||
|
@ -458,7 +467,7 @@ int tscProcessSql(SSqlObj *pSql) {
|
|||
return doProcessSql(pSql);
|
||||
}
|
||||
|
||||
void tscKillMetricQuery(SSqlObj *pSql) {
|
||||
void tscKillSTableQuery(SSqlObj *pSql) {
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
@ -572,9 +581,11 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
|
|||
const static int32_t MIN_QUERY_MSG_PKT_SIZE = TSDB_MAX_BYTES_PER_ROW * 5;
|
||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||
|
||||
int32_t srcColListSize = pQueryInfo->colList.numOfCols * sizeof(SColumnInfo);
|
||||
|
||||
int32_t exprSize = sizeof(SSqlFuncExprMsg) * pQueryInfo->exprsInfo.numOfExprs;
|
||||
int32_t srcColListSize = taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo);
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
int32_t exprSize = sizeof(SSqlFuncMsg) * numOfExprs;
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
// meter query without tags values
|
||||
|
@ -583,20 +594,6 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) {
|
|||
}
|
||||
|
||||
int32_t size = 4096;
|
||||
|
||||
#if 0
|
||||
SSuperTableMeta *pMetricMeta = pTableMetaInfo->pMetricMeta;
|
||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vgroupIndex);
|
||||
|
||||
int32_t meterInfoSize = (pMetricMeta->tagLen + sizeof(STableIdInfo)) * pVnodeSidList->numOfSids;
|
||||
int32_t outputColumnSize = pQueryInfo->exprsInfo.numOfExprs * sizeof(SSqlFuncExprMsg);
|
||||
|
||||
int32_t size = meterInfoSize + outputColumnSize + srcColListSize + exprSize + MIN_QUERY_MSG_PKT_SIZE;
|
||||
if (pQueryInfo->tsBuf != NULL) {
|
||||
size += pQueryInfo->tsBuf->fileSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -629,7 +626,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
|
||||
if (pQueryInfo->colList.numOfCols <= 0) {
|
||||
if (taosArrayGetSize(pQueryInfo->colList) <= 0) {
|
||||
tscError("%p illegal value of numOfCols in query msg: %d", pSql, tscGetNumOfColumns(pTableMeta));
|
||||
return -1;
|
||||
}
|
||||
|
@ -648,8 +645,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pStart;
|
||||
|
||||
int32_t msgLen = 0;
|
||||
int32_t msgLen = 0;
|
||||
int32_t numOfTables = 0;
|
||||
int32_t numOfTags = taosArrayGetSize(pTableMetaInfo->tagColList);
|
||||
|
||||
if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) {
|
||||
numOfTables = 1;
|
||||
|
@ -658,7 +656,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
tscTrace("%p queried tables:%d, table id: %s", pSql, 1, pTableMetaInfo->name);
|
||||
} else { // query super table
|
||||
int32_t index = pTableMetaInfo->vgroupIndex;
|
||||
|
||||
if (index < 0) {
|
||||
tscError("%p error vgroupIndex:%d", pSql, index);
|
||||
return -1;
|
||||
|
@ -674,17 +671,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pSql->ipList.ip[i] = pVgroupInfo->ipAddr[i].ip;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pTableMetaInfo->vgroupIndex);
|
||||
uint32_t vnodeId = pVnodeSidList->vpeerDesc[pVnodeSidList->index].vnode;
|
||||
|
||||
numOfTables = pVnodeSidList->numOfSids;
|
||||
if (numOfTables <= 0) {
|
||||
tscError("%p vid:%d,error numOfTables in query message:%d", pSql, vnodeId, numOfTables);
|
||||
return -1; // error
|
||||
}
|
||||
#endif
|
||||
|
||||
tscTrace("%p query on super table, numOfVgroup:%d, vgroupIndex:%d", pSql, pTableMetaInfo->vgroupList->numOfVgroups, index);
|
||||
|
||||
pQueryMsg->head.vgId = htonl(pVgroupInfo->vgId);
|
||||
|
@ -692,11 +678,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (pQueryInfo->order.order == TSDB_ORDER_ASC) {
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->stime);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->etime);
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->window.skey);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.ekey);
|
||||
} else {
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->etime);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->stime);
|
||||
pQueryMsg->window.skey = htobe64(pQueryInfo->window.ekey);
|
||||
pQueryMsg->window.ekey = htobe64(pQueryInfo->window.skey);
|
||||
}
|
||||
|
||||
pQueryMsg->numOfTables = htonl(numOfTables);
|
||||
|
@ -705,37 +691,39 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pQueryMsg->interpoType = htons(pQueryInfo->interpoType);
|
||||
pQueryMsg->limit = htobe64(pQueryInfo->limit.limit);
|
||||
pQueryMsg->offset = htobe64(pQueryInfo->limit.offset);
|
||||
pQueryMsg->numOfCols = htons(pQueryInfo->colList.numOfCols);
|
||||
pQueryMsg->numOfCols = htons(taosArrayGetSize(pQueryInfo->colList));
|
||||
pQueryMsg->intervalTime = htobe64(pQueryInfo->intervalTime);
|
||||
pQueryMsg->slidingTime = htobe64(pQueryInfo->slidingTime);
|
||||
pQueryMsg->slidingTimeUnit = pQueryInfo->slidingTimeUnit;
|
||||
pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols);
|
||||
|
||||
pQueryMsg->queryType = htons(pQueryInfo->type);
|
||||
pQueryMsg->numOfOutputCols = htons(pQueryInfo->exprsInfo.numOfExprs);
|
||||
|
||||
int32_t numOfOutput = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pQueryMsg->numOfTags = htonl(numOfTags);
|
||||
pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType);
|
||||
pQueryMsg->queryType = htons(pQueryInfo->type);
|
||||
|
||||
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
pQueryMsg->numOfOutput = htons(numOfOutput);
|
||||
if (numOfOutput < 0) {
|
||||
tscError("%p illegal value of number of output columns in query msg: %d", pSql, numOfOutput);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// set column list ids
|
||||
char *pMsg = (char *)(pQueryMsg->colList) + pQueryInfo->colList.numOfCols * sizeof(SColumnInfo);
|
||||
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
|
||||
char *pMsg = (char *)(pQueryMsg->colList) + numOfCols * sizeof(SColumnInfo);
|
||||
SSchema *pSchema = tscGetTableSchema(pTableMeta);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
|
||||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->colList.numOfCols; ++i) {
|
||||
SColumnBase *pCol = tscColumnBaseInfoGet(&pQueryInfo->colList, i);
|
||||
SSchema * pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL ||
|
||||
pColSchema->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
tscError("%p sid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s",
|
||||
pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex,
|
||||
pColSchema->name);
|
||||
|
||||
// if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL ||
|
||||
// pColSchema->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
// tscError("%p vid:%d sid:%d id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s", pSql,
|
||||
// htons(pQueryMsg->vnode), pTableMeta->sid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex,
|
||||
// pColSchema->name);
|
||||
//
|
||||
// return -1; // 0 means build msg failed
|
||||
// }
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
pQueryMsg->colList[i].colId = htons(pColSchema->colId);
|
||||
pQueryMsg->colList[i].bytes = htons(pColSchema->bytes);
|
||||
|
@ -747,11 +735,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SColumnFilterInfo *pColFilter = &pCol->filterInfo[f];
|
||||
|
||||
SColumnFilterInfo *pFilterMsg = (SColumnFilterInfo *)pMsg;
|
||||
pFilterMsg->filterOnBinary = htons(pColFilter->filterOnBinary);
|
||||
pFilterMsg->filterstr = htons(pColFilter->filterstr);
|
||||
|
||||
pMsg += sizeof(SColumnFilterInfo);
|
||||
|
||||
if (pColFilter->filterOnBinary) {
|
||||
if (pColFilter->filterstr) {
|
||||
pFilterMsg->len = htobe64(pColFilter->len);
|
||||
memcpy(pMsg, (void *)pColFilter->pz, pColFilter->len + 1);
|
||||
pMsg += (pColFilter->len + 1); // append the additional filter binary info
|
||||
|
@ -770,18 +758,12 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
bool hasArithmeticFunction = false;
|
||||
|
||||
SSqlFuncExprMsg *pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg;
|
||||
SSqlFuncMsg *pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
for (int32_t i = 0; i < tscSqlExprNumOfExprs(pQueryInfo); ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
if (pExpr->functionId == TSDB_FUNC_ARITHM) {
|
||||
hasArithmeticFunction = true;
|
||||
}
|
||||
|
||||
if (!tscValidateColumnId(pTableMetaInfo, pExpr->colInfo.colId)) {
|
||||
/* column id is not valid according to the cached metermeta, the table meta is expired */
|
||||
/* column id is not valid according to the cached table meta, the table meta is expired */
|
||||
tscError("%p table schema is not matched with parsed sql", pSql);
|
||||
return -1;
|
||||
}
|
||||
|
@ -792,7 +774,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
pSqlFuncExpr->functionId = htons(pExpr->functionId);
|
||||
pSqlFuncExpr->numOfParams = htons(pExpr->numOfParams);
|
||||
pMsg += sizeof(SSqlFuncExprMsg);
|
||||
pMsg += sizeof(SSqlFuncMsg);
|
||||
|
||||
for (int32_t j = 0; j < pExpr->numOfParams; ++j) {
|
||||
pSqlFuncExpr->arg[j].argType = htons((uint16_t)pExpr->param[j].nType);
|
||||
|
@ -800,33 +782,15 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
|
||||
|
||||
// by plus one char to make the string null-terminated
|
||||
pMsg += pExpr->param[j].nLen + 1;
|
||||
pMsg += pExpr->param[j].nLen;
|
||||
} else {
|
||||
pSqlFuncExpr->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64Key);
|
||||
}
|
||||
}
|
||||
|
||||
pSqlFuncExpr = (SSqlFuncExprMsg *)pMsg;
|
||||
pSqlFuncExpr = (SSqlFuncMsg *)pMsg;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
if (hasArithmeticFunction) {
|
||||
SColumnBase *pColBase = pQueryInfo->colList.pColList;
|
||||
for (int32_t i = 0; i < pQueryInfo->colList.numOfCols; ++i) {
|
||||
char * name = pSchema[pColBase[i].colIndex.columnIndex].name;
|
||||
int32_t lenx = strlen(name);
|
||||
memcpy(pMsg, name, lenx);
|
||||
*(pMsg + lenx) = ',';
|
||||
|
||||
len += (lenx + 1); // one for comma
|
||||
pMsg += (lenx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
pQueryMsg->colNameLen = htonl(len);
|
||||
|
||||
// serialize the table info (sid, uid, tags)
|
||||
pMsg = doSerializeTableInfo(pSql, htons(pQueryMsg->head.vgId), pMsg);
|
||||
|
||||
|
@ -836,8 +800,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pQueryMsg->orderType = htons(pGroupbyExpr->orderType);
|
||||
|
||||
for (int32_t j = 0; j < pGroupbyExpr->numOfGroupCols; ++j) {
|
||||
SColIndex *pCol = &pGroupbyExpr->columnInfo[j];
|
||||
|
||||
SColIndex* pCol = taosArrayGet(pGroupbyExpr->columnInfo, j);
|
||||
|
||||
*((int16_t *)pMsg) = pCol->colId;
|
||||
pMsg += sizeof(pCol->colId);
|
||||
|
||||
|
@ -853,11 +817,42 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
*((int64_t *)pMsg) = htobe64(pQueryInfo->defaultVal[i]);
|
||||
pMsg += sizeof(pQueryInfo->defaultVal[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfTags != 0) {
|
||||
int32_t numOfColumns = tscGetNumOfColumns(pTableMeta);
|
||||
int32_t numOfTagColumns = tscGetNumOfTags(pTableMeta);
|
||||
int32_t total = numOfTagColumns + numOfColumns;
|
||||
|
||||
pSchema = tscGetTableTagSchema(pTableMeta);
|
||||
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
|
||||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
|
||||
if ((pCol->colIndex.columnIndex >= numOfTagColumns || pCol->colIndex.columnIndex < -1) ||
|
||||
(pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR)) {
|
||||
tscError("%p sid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s",
|
||||
pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns,
|
||||
pCol->colIndex, pColSchema->name);
|
||||
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
SColumnInfo* pTagCol = (SColumnInfo*) pMsg;
|
||||
|
||||
pTagCol->colId = htons(pColSchema->colId);
|
||||
pTagCol->bytes = htons(pColSchema->bytes);
|
||||
pTagCol->type = htons(pColSchema->type);
|
||||
pTagCol->numOfFilters = 0;
|
||||
|
||||
pMsg += sizeof(SColumnInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// compressed ts block
|
||||
pQueryMsg->tsOffset = htonl(pMsg - pStart);
|
||||
|
@ -896,6 +891,14 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pQueryInfo->tagCond.tbnameCond.cond == NULL) {
|
||||
*pMsg = 0;
|
||||
pMsg++;
|
||||
} else {
|
||||
strcpy(pMsg, pQueryInfo->tagCond.tbnameCond.cond);
|
||||
pMsg += strlen(pQueryInfo->tagCond.tbnameCond.cond) + 1;
|
||||
}
|
||||
|
||||
// tbname in/like query expression should be sent to mgmt node
|
||||
msgLen = pMsg - pStart;
|
||||
|
||||
|
@ -1258,7 +1261,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pSchema = (SSchema *)pCreateTableMsg->schema;
|
||||
|
||||
for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
pSchema->type = pField->type;
|
||||
strcpy(pSchema->name, pField->name);
|
||||
|
@ -1277,7 +1280,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
tscClearFieldInfo(&pQueryInfo->fieldsInfo);
|
||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||
|
||||
msgLen = pMsg - (char*)pCreateTableMsg;
|
||||
pCreateTableMsg->contLen = htonl(msgLen);
|
||||
|
@ -1320,12 +1323,12 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
strcpy(pAlterTableMsg->tableId, pTableMetaInfo->name);
|
||||
pAlterTableMsg->type = htons(pAlterInfo->type);
|
||||
|
||||
pAlterTableMsg->numOfCols = htons(tscNumOfFields(pQueryInfo));
|
||||
pAlterTableMsg->numOfCols = tscNumOfFields(pQueryInfo);
|
||||
memcpy(pAlterTableMsg->tagVal, pAlterInfo->tagData.data, TSDB_MAX_TAGS_LEN);
|
||||
|
||||
SSchema *pSchema = pAlterTableMsg->schema;
|
||||
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
for (int i = 0; i < pAlterTableMsg->numOfCols; ++i) {
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
pSchema->type = pField->type;
|
||||
strcpy(pSchema->name, pField->name);
|
||||
|
@ -1349,11 +1352,6 @@ int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pCmd->payloadLen = sizeof(SCMAlterDbMsg);
|
||||
pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_DB;
|
||||
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||
tscError("%p failed to malloc for query msg", pSql);
|
||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SCMAlterDbMsg *pAlterDbMsg = (SCMAlterDbMsg*)pCmd->payload;
|
||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
strcpy(pAlterDbMsg->db, pTableMetaInfo->name);
|
||||
|
@ -1384,9 +1382,9 @@ static int tscSetResultPointer(SQueryInfo *pQueryInfo, SSqlRes *pRes) {
|
|||
return pRes->code;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
pRes->tsrow[i] = (pRes->data + offset * pRes->numOfRows);
|
||||
pRes->tsrow[i] = ((char*) pRes->data + offset * pRes->numOfRows);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1828,7 +1826,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
pCmd->msgType = TSDB_MSG_TYPE_CM_HEARTBEAT;
|
||||
|
||||
assert(msgLen + minMsgSize() <= size);
|
||||
return msgLen;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int tscProcessTableMetaRsp(SSqlObj *pSql) {
|
||||
|
@ -2190,28 +2188,35 @@ int tscProcessShowRsp(SSqlObj *pSql) {
|
|||
strcpy(key + 1, "showlist");
|
||||
|
||||
taosCacheRelease(tscCacheHandle, (void *)&(pTableMetaInfo->pTableMeta), false);
|
||||
|
||||
size_t size = 0;
|
||||
STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg, &size);
|
||||
|
||||
pTableMetaInfo->pTableMeta =
|
||||
(STableMeta *)taosCachePut(tscCacheHandle, key, (char *)pTableMeta, size, tsMeterMetaKeepTimer);
|
||||
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
pTableMetaInfo->pTableMeta = taosCachePut(tscCacheHandle, key, (char *)pTableMeta, size, tsMeterMetaKeepTimer);
|
||||
SSchema *pTableSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||
|
||||
tscColumnBaseInfoReserve(&pQueryInfo->colList, pMetaMsg->numOfColumns);
|
||||
SColumnIndex index = {0};
|
||||
|
||||
for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
index.columnIndex = i;
|
||||
tscColumnBaseInfoInsert(pQueryInfo, &index);
|
||||
tscFieldInfoSetValFromSchema(&pQueryInfo->fieldsInfo, i, &pTableSchema[i]);
|
||||
|
||||
pQueryInfo->fieldsInfo.pSqlExpr[i] = tscSqlExprInsert(pQueryInfo, i, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pTableSchema[i].type, pTableSchema[i].bytes, pTableSchema[i].bytes);
|
||||
if (pQueryInfo->colList == NULL) {
|
||||
pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES);
|
||||
}
|
||||
|
||||
tscFieldInfoCalOffset(pQueryInfo);
|
||||
|
||||
SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo;
|
||||
|
||||
SColumnIndex index = {0};
|
||||
pSchema = pMetaMsg->schema;
|
||||
|
||||
for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i, ++pSchema) {
|
||||
index.columnIndex = i;
|
||||
tscColumnListInsert(pQueryInfo->colList, &index);
|
||||
|
||||
TAOS_FIELD f = tscCreateField(pSchema->type, pSchema->name, pSchema->bytes);
|
||||
SFieldSupInfo* pInfo = tscFieldInfoAppend(pFieldInfo, &f);
|
||||
|
||||
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index,
|
||||
pTableSchema[i].type, pTableSchema[i].bytes, pTableSchema[i].bytes, false);
|
||||
}
|
||||
|
||||
pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||
|
||||
tfree(pTableMeta);
|
||||
return 0;
|
||||
|
@ -2322,7 +2327,7 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
||||
int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
|
@ -2339,9 +2344,9 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
|||
tscSetResultPointer(pQueryInfo, pRes);
|
||||
|
||||
if (pSql->pSubscription != NULL) {
|
||||
int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutputCols;
|
||||
int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput;
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, numOfCols - 1);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1);
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1);
|
||||
|
||||
char* p = pRes->data + (pField->bytes + offset) * pRes->numOfRows;
|
||||
|
@ -2479,7 +2484,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) {
|
|||
* 1. only update the metermeta in force model metricmeta is not updated
|
||||
* 2. if get metermeta failed, still get the metermeta
|
||||
*/
|
||||
if (pTableMetaInfo->pTableMeta == NULL || !tscQueryOnMetric(pCmd)) {
|
||||
if (pTableMetaInfo->pTableMeta == NULL || !tscQueryOnSTable(pCmd)) {
|
||||
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
if (pTableMetaInfo->pTableMeta) {
|
||||
tscTrace("%p update table meta, old: numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
|
||||
|
@ -2550,7 +2555,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
STableMetaInfo *pMMInfo = tscGetMetaInfo(pQueryInfo, i);
|
||||
|
||||
STableMeta *pTableMeta = taosCacheAcquireByName(tscCacheHandle, pMMInfo->name);
|
||||
tscAddTableMetaInfo(pNewQueryInfo, pMMInfo->name, pTableMeta, NULL, pMMInfo->numOfTags, pMMInfo->tagColumnIndex);
|
||||
tscAddTableMetaInfo(pNewQueryInfo, pMMInfo->name, pTableMeta, NULL, pMMInfo->tagColList);
|
||||
}
|
||||
|
||||
if ((code = tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2573,7 +2578,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
|
||||
// if (pSql->fp != NULL && pSql->pStream == NULL) {
|
||||
// pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||
// tscFreeSubqueryInfo(pCmd);
|
||||
// tscFreeQueryInfo(pCmd);
|
||||
// }
|
||||
|
||||
tscTrace("%p allocate new pSqlObj:%p to get stable vgroupInfo", pSql, pNew);
|
||||
|
@ -2624,7 +2629,7 @@ void tscInitMsgsFp() {
|
|||
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromVnode;
|
||||
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromNode;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_DB] = tscProcessDropDbRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_TABLE] = tscProcessDropTableRsp;
|
||||
|
@ -2635,7 +2640,7 @@ void tscInitMsgsFp() {
|
|||
tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp;
|
||||
|
|
|
@ -66,7 +66,8 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (tscInitRpc(user, pass) != 0) {
|
||||
void* pMgmtConn = NULL;
|
||||
if (tscInitRpc(user, pass, &pMgmtConn) != 0) {
|
||||
terrno = TSDB_CODE_NETWORK_UNAVAIL;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -118,6 +119,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
|
|||
strtolower(pObj->db, tmp);
|
||||
}
|
||||
|
||||
pObj->pMgmtConn = pMgmtConn;
|
||||
pthread_mutex_init(&pObj->mutex, NULL);
|
||||
|
||||
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||
|
@ -129,7 +131,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
|
|||
|
||||
pSql->pTscObj = pObj;
|
||||
pSql->signature = pSql;
|
||||
pSql->maxRetry = TSDB_REPLICA_MAX_NUM;
|
||||
pSql->maxRetry = TSDB_MAX_REPLICA_NUM;
|
||||
|
||||
tsem_init(&pSql->rspSem, 0, 0);
|
||||
|
||||
|
@ -326,16 +328,21 @@ int taos_num_fields(TAOS_RES *res) {
|
|||
SSqlObj *pSql = (SSqlObj *)res;
|
||||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
int32_t num = 0;
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
if (pQueryInfo == NULL) {
|
||||
return 0;
|
||||
return num;
|
||||
}
|
||||
|
||||
SFieldInfo *pFieldsInfo = &pQueryInfo->fieldsInfo;
|
||||
if (pFieldsInfo)
|
||||
return (pFieldsInfo->numOfOutputCols - pFieldsInfo->numOfHiddenCols);
|
||||
else
|
||||
return 0;
|
||||
size_t numOfCols = tscNumOfFields(pQueryInfo);
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SFieldSupInfo* pInfo = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
|
||||
if (pInfo->visible) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS *taos) {
|
||||
|
@ -357,11 +364,16 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
|
||||
if (pQueryInfo)
|
||||
return pQueryInfo->fieldsInfo.pFields;
|
||||
else
|
||||
if (pQueryInfo == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t numOfCols = tscNumOfFields(pQueryInfo);
|
||||
if (numOfCols == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pQueryInfo->fieldsInfo.pFields->pData;
|
||||
}
|
||||
|
||||
int taos_retrieve(TAOS_RES *res) {
|
||||
|
@ -414,8 +426,8 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
if (pQueryInfo == NULL)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i);
|
||||
for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i);
|
||||
}
|
||||
|
||||
*rows = pRes->tsrow;
|
||||
|
@ -446,20 +458,21 @@ static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pF
|
|||
}
|
||||
}
|
||||
|
||||
static char *getArithemicInputSrc(void *param, char *name, int32_t colId) {
|
||||
SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
|
||||
SSqlFunctionExpr * pExpr = pSupport->pExpr;
|
||||
static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) {
|
||||
// SArithmeticSupport *pSupport = (SArithmeticSupport *)param;
|
||||
// SArithExprInfo * pExpr = pSupport->pArithExpr;
|
||||
|
||||
int32_t index = -1;
|
||||
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||
if (strcmp(name, pExpr->binExprInfo.pReqColumns[i].name) == 0) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(index >= 0 && index < pExpr->binExprInfo.numOfCols);
|
||||
return pSupport->data[index] + pSupport->offset * pSupport->elemSize[index];
|
||||
// int32_t index = -1;
|
||||
// for (int32_t i = 0; i < pExpr->numOfCols; ++i) {
|
||||
// if (strcmp(name, pExpr->colList[i].name) == 0) {
|
||||
// index = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// assert(index >= 0 && index < pExpr->numOfCols);
|
||||
// return pSupport->data[index] + pSupport->offset * pSupport->elemSize[index];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void **doSetResultRowData(SSqlObj *pSql) {
|
||||
|
@ -476,7 +489,8 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
//todo refactor move away
|
||||
for(int32_t k = 0; k < pQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
for(int32_t k = 0; k < numOfExprs; ++k) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k);
|
||||
|
||||
if (k > 0) {
|
||||
|
@ -487,9 +501,9 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
|
||||
int32_t num = 0;
|
||||
for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) {
|
||||
if (pQueryInfo->fieldsInfo.pSqlExpr[i] != NULL) {
|
||||
SSqlExpr* pExpr = pQueryInfo->fieldsInfo.pSqlExpr[i];
|
||||
pRes->tsrow[i] = TSC_GET_RESPTR_BASE(pRes, pQueryInfo, i) + pExpr->resBytes * pRes->row;
|
||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i);
|
||||
if (pInfo->pSqlExpr != NULL) {
|
||||
pRes->tsrow[i] = tscGetResultColumnChr(pRes, pQueryInfo, i) + pInfo->pSqlExpr->resBytes * pRes->row;
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -499,37 +513,37 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
|||
continue;
|
||||
}
|
||||
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
transferNcharData(pSql, i, pField);
|
||||
|
||||
// calculate the result from serveral other columns
|
||||
if (pQueryInfo->fieldsInfo.pExpr != NULL && pQueryInfo->fieldsInfo.pExpr[i] != NULL) {
|
||||
// calculate the result from several other columns
|
||||
if (pInfo->pArithExprInfo != NULL) {
|
||||
SArithmeticSupport *sas = (SArithmeticSupport *)calloc(1, sizeof(SArithmeticSupport));
|
||||
sas->offset = 0;
|
||||
sas->pExpr = pQueryInfo->fieldsInfo.pExpr[i];
|
||||
sas->pArithExpr = pInfo->pArithExprInfo;
|
||||
|
||||
sas->numOfCols = sas->pExpr->binExprInfo.numOfCols;
|
||||
// sas->numOfCols = sas->pArithExpr->numOfCols;
|
||||
|
||||
if (pRes->buffer[i] == NULL) {
|
||||
pRes->buffer[i] = malloc(tscFieldInfoGetField(pQueryInfo, i)->bytes);
|
||||
pRes->buffer[i] = malloc(tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i)->bytes);
|
||||
}
|
||||
|
||||
for(int32_t k = 0; k < sas->numOfCols; ++k) {
|
||||
int32_t columnIndex = sas->pExpr->binExprInfo.pReqColumns[k].colIndex;
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
|
||||
|
||||
sas->elemSize[k] = pExpr->resBytes;
|
||||
sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
|
||||
// int32_t columnIndex = sas->pArithExpr->colList[k].colIndex;
|
||||
// SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
|
||||
//
|
||||
// sas->elemSize[k] = pExpr->resBytes;
|
||||
// sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
|
||||
}
|
||||
|
||||
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSDB_ORDER_ASC, getArithemicInputSrc);
|
||||
tExprTreeCalcTraverse(sas->pArithExpr->pExpr, 1, pRes->buffer[i], sas, TSDB_ORDER_ASC, getArithemicInputSrc);
|
||||
pRes->tsrow[i] = pRes->buffer[i];
|
||||
|
||||
free(sas); //todo optimization
|
||||
}
|
||||
}
|
||||
|
||||
assert(num <= pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
assert(num <= pQueryInfo->fieldsInfo.numOfOutput);
|
||||
|
||||
pRes->row++; // index increase one-step
|
||||
return pRes->tsrow;
|
||||
|
@ -591,11 +605,13 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
|
|||
|
||||
static UNUSED_FUNC void **tscBuildResFromSubqueries(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
|
||||
while (1) {
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
if (pRes->tsrow == NULL) {
|
||||
pRes->tsrow = calloc(pQueryInfo->exprsInfo.numOfExprs, POINTER_BYTES);
|
||||
pRes->tsrow = calloc(numOfExprs, POINTER_BYTES);
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
@ -619,7 +635,7 @@ static UNUSED_FUNC void **tscBuildResFromSubqueries(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
if (success) { // current row of final output has been built, return to app
|
||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
int32_t tableIndex = pRes->pColumnIndex[i].tableIndex;
|
||||
int32_t columnIndex = pRes->pColumnIndex[i].columnIndex;
|
||||
|
||||
|
@ -949,7 +965,7 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
tscKillMetricQuery(pSql);
|
||||
tscKillSTableQuery(pSql);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1142,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
|||
return code;
|
||||
}
|
||||
|
||||
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
if ((code = tscSetTableId(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static int64_t getDelayValueAfterTimewindowClosed(SSqlStream* pStream, int64_t l
|
|||
}
|
||||
|
||||
static bool isProjectStream(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_PRJ) {
|
||||
return false;
|
||||
|
@ -86,7 +86,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
|||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||
}
|
||||
|
||||
tscTansformSQLFunctionForSTableQuery(pQueryInfo);
|
||||
tscTansformSQLFuncForSTableQuery(pQueryInfo);
|
||||
|
||||
// failed to get meter/metric meta, retry in 10sec.
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -116,18 +116,18 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
|||
|
||||
if (isProjectStream(pQueryInfo)) {
|
||||
/*
|
||||
* pQueryInfo->etime, which is the start time, does not change in case of
|
||||
* pQueryInfo->window.ekey, which is the start time, does not change in case of
|
||||
* repeat first execution, once the first execution failed.
|
||||
*/
|
||||
pQueryInfo->stime = pStream->stime; // start time
|
||||
pQueryInfo->window.skey = pStream->stime; // start time
|
||||
|
||||
pQueryInfo->etime = taosGetTimestamp(pStream->precision); // end time
|
||||
if (pQueryInfo->etime > pStream->etime) {
|
||||
pQueryInfo->etime = pStream->etime;
|
||||
pQueryInfo->window.ekey = taosGetTimestamp(pStream->precision); // end time
|
||||
if (pQueryInfo->window.ekey > pStream->etime) {
|
||||
pQueryInfo->window.ekey = pStream->etime;
|
||||
}
|
||||
} else {
|
||||
pQueryInfo->stime = pStream->stime - pStream->interval;
|
||||
pQueryInfo->etime = pStream->stime - 1;
|
||||
pQueryInfo->window.skey = pStream->stime - pStream->interval;
|
||||
pQueryInfo->window.ekey = pStream->stime - 1;
|
||||
}
|
||||
|
||||
// launch stream computing in a new thread
|
||||
|
@ -147,7 +147,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
|||
retryDelay);
|
||||
|
||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||
tscClearMeterMetaInfo(pTableMetaInfo, true);
|
||||
tscClearTableMetaInfo(pTableMetaInfo, true);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
||||
return;
|
||||
|
@ -177,7 +177,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
if (pSql == NULL || numOfRows < 0) {
|
||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
|
||||
tscClearMeterMetaInfo(pTableMetaInfo, true);
|
||||
tscClearTableMetaInfo(pTableMetaInfo, true);
|
||||
|
||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
||||
return;
|
||||
|
@ -219,9 +219,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
void *oldPtr = pSql->res.data;
|
||||
pSql->res.data = tmpRes;
|
||||
|
||||
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, i);
|
||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||
|
||||
assignVal(pSql->res.data + offset, (char *)(&pQueryInfo->defaultVal[i]), pField->bytes, pField->type);
|
||||
row[i] = pSql->res.data + offset;
|
||||
|
@ -231,7 +231,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
row[0] = pRes->data;
|
||||
|
||||
// char result[512] = {0};
|
||||
// taos_print_row(result, row, pQueryInfo->fieldsInfo.pFields, pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
// taos_print_row(result, row, pQueryInfo->fieldsInfo.pFields, pQueryInfo->fieldsInfo.numOfOutput);
|
||||
// tscPrint("%p stream:%p query result: %s", pSql, pStream, result);
|
||||
tscTrace("%p stream:%p fetch result", pSql, pStream);
|
||||
|
||||
|
@ -259,7 +259,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
|||
pStream->numOfRes);
|
||||
|
||||
// release the metric/meter meta information reference, so data in cache can be updated
|
||||
tscClearMeterMetaInfo(pTableMetaInfo, false);
|
||||
tscClearTableMetaInfo(pTableMetaInfo, false);
|
||||
tscSetNextLaunchTimer(pStream, pSql);
|
||||
}
|
||||
}
|
||||
|
@ -425,10 +425,10 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
|
|||
pStream->slidingTime = tsProjectExecInterval;
|
||||
|
||||
if (stime != 0) { // first projection start from the latest event timestamp
|
||||
assert(stime >= pQueryInfo->stime);
|
||||
assert(stime >= pQueryInfo->window.skey);
|
||||
stime += 1; // exclude the last records from table
|
||||
} else {
|
||||
stime = pQueryInfo->stime;
|
||||
stime = pQueryInfo->window.skey;
|
||||
}
|
||||
} else { // timewindow based aggregation stream
|
||||
if (stime == 0) { // no data in meter till now
|
||||
|
@ -548,7 +548,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
|||
pStream->precision = tinfo.precision;
|
||||
|
||||
pStream->ctime = taosGetTimestamp(pStream->precision);
|
||||
pStream->etime = pQueryInfo->etime;
|
||||
pStream->etime = pQueryInfo->window.ekey;
|
||||
|
||||
pSql->pStream = pStream;
|
||||
tscAddIntoStreamList(pStream);
|
||||
|
|
|
@ -190,10 +190,10 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
|
|||
return;
|
||||
}
|
||||
|
||||
tscSqlExprInfoDestroy(&pSupporter->exprsInfo);
|
||||
tscColumnBaseInfoDestroy(&pSupporter->colList);
|
||||
tscSqlExprInfoDestroy(pSupporter->exprsInfo);
|
||||
tscColumnListDestroy(pSupporter->colList);
|
||||
|
||||
tscClearFieldInfo(&pSupporter->fieldsInfo);
|
||||
tscFieldInfoClear(&pSupporter->fieldsInfo);
|
||||
|
||||
if (pSupporter->f != NULL) {
|
||||
fclose(pSupporter->f);
|
||||
|
@ -211,9 +211,11 @@ void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
|
|||
*
|
||||
*/
|
||||
bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
|
||||
for (int32_t i = 0; i < pQueryInfo->colList.numOfCols; ++i) {
|
||||
SColumnBase* pBase = tscColumnBaseInfoGet(&pQueryInfo->colList, i);
|
||||
if (pBase->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumn* base = taosArrayGet(pQueryInfo->colList, i);
|
||||
if (base->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +238,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
|
||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
||||
pSupporter = pSql->pSubs[i]->param;
|
||||
if (pSupporter->exprsInfo.numOfExprs > 0) {
|
||||
if (taosArrayGetSize(pSupporter->exprsInfo) > 0) {
|
||||
++numOfSub;
|
||||
}
|
||||
}
|
||||
|
@ -262,7 +264,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
|
||||
pSupporter = pPrevSub->param;
|
||||
|
||||
if (pSupporter->exprsInfo.numOfExprs == 0) {
|
||||
if (taosArrayGetSize(pSupporter->exprsInfo) == 0) {
|
||||
tscTrace("%p subIndex: %d, not need to launch query, ignore it", pSql, i);
|
||||
|
||||
tscDestroyJoinSupporter(pSupporter);
|
||||
|
@ -277,7 +279,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
pSubQueryInfo->tsBuf = NULL;
|
||||
|
||||
// free result for async object will also free sqlObj
|
||||
assert(pSubQueryInfo->exprsInfo.numOfExprs == 1); // ts_comp query only requires one resutl columns
|
||||
assert(tscSqlExprNumOfExprs(pSubQueryInfo) == 1); // ts_comp query only requires one resutl columns
|
||||
taos_free_result(pPrevSub);
|
||||
|
||||
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL);
|
||||
|
@ -299,27 +301,27 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
pQueryInfo->intervalTime = pSupporter->interval;
|
||||
pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
|
||||
|
||||
tscColumnBaseInfoCopy(&pQueryInfo->colList, &pSupporter->colList, 0);
|
||||
tscColumnListCopy(pQueryInfo->colList, pSupporter->colList, 0);
|
||||
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
|
||||
|
||||
tscSqlExprCopy(&pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopyAll(&pQueryInfo->fieldsInfo, &pSupporter->fieldsInfo);
|
||||
pQueryInfo->exprsInfo = tscSqlExprCopy(pSupporter->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopy(&pQueryInfo->fieldsInfo, &pSupporter->fieldsInfo);
|
||||
|
||||
pSupporter->exprsInfo.numOfExprs = 0;
|
||||
pSupporter->fieldsInfo.numOfOutputCols = 0;
|
||||
pSupporter->fieldsInfo.numOfOutput = 0;
|
||||
|
||||
/*
|
||||
* if the first column of the secondary query is not ts function, add this function.
|
||||
* Because this column is required to filter with timestamp after intersecting.
|
||||
*/
|
||||
if (pSupporter->exprsInfo.pExprs[0]->functionId != TSDB_FUNC_TS) {
|
||||
SSqlExpr* pExpr = taosArrayGet(pSupporter->exprsInfo, 0);
|
||||
if (pExpr->functionId != TSDB_FUNC_TS) {
|
||||
tscAddTimestampColumn(pQueryInfo, TSDB_FUNC_TS, 0);
|
||||
}
|
||||
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
||||
assert(pNew->numOfSubs == 0 && pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1);
|
||||
|
||||
tscFieldInfoCalOffset(pNewQueryInfo);
|
||||
tscFieldInfoUpdateOffset(pNewQueryInfo);
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pNewQueryInfo, 0);
|
||||
|
||||
|
@ -342,10 +344,11 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|||
|
||||
tscPrintSelectClause(pNew, 0);
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
|
||||
tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
||||
pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
|
||||
pNewQueryInfo->exprsInfo.numOfExprs, pNewQueryInfo->colList.numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
taosArrayGetSize(pNewQueryInfo->exprsInfo), numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
}
|
||||
|
||||
//prepare the subqueries object failed, abort
|
||||
|
@ -413,10 +416,10 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter
|
|||
|
||||
// update the query time range according to the join results on timestamp
|
||||
static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et) {
|
||||
assert(pQueryInfo->stime <= st && pQueryInfo->etime >= et);
|
||||
assert(pQueryInfo->window.skey <= st && pQueryInfo->window.ekey >= et);
|
||||
|
||||
pQueryInfo->stime = st;
|
||||
pQueryInfo->etime = et;
|
||||
pQueryInfo->window.skey = st;
|
||||
pQueryInfo->window.ekey = et;
|
||||
}
|
||||
|
||||
static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
|
||||
|
@ -688,9 +691,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
|||
}
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pQueryInfo->fieldsInfo.numOfOutput);
|
||||
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
|
||||
int32_t tableIndexOfSub = -1;
|
||||
|
@ -707,7 +710,8 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
|||
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
|
||||
SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0);
|
||||
|
||||
for (int32_t k = 0; k < pSubQueryInfo->exprsInfo.numOfExprs; ++k) {
|
||||
size_t numOfExprs = taosArrayGetSize(pSubQueryInfo->exprsInfo);
|
||||
for (int32_t k = 0; k < numOfExprs; ++k) {
|
||||
SSqlExpr* pSubExpr = tscSqlExprGet(pSubQueryInfo, k);
|
||||
if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) {
|
||||
pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k};
|
||||
|
@ -723,11 +727,6 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
|
||||
// int32_t idx = pSql->cmd.vnodeIdx;
|
||||
|
||||
// SVnodeSidList *vnodeInfo = NULL;
|
||||
// if (pTableMetaInfo->pMetricMeta != NULL) {
|
||||
// vnodeInfo = tscGetVnodeSidList(pTableMetaInfo->pMetricMeta, idx - 1);
|
||||
// }
|
||||
|
||||
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
|
||||
|
||||
// if (atomic_add_fetch_32(pSupporter->numOfComplete, 1) >=
|
||||
|
@ -850,11 +849,17 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
||||
assert(pNewQueryInfo != NULL);
|
||||
|
||||
tscColumnBaseInfoUpdateTableIndex(&pNewQueryInfo->colList, 0);
|
||||
tscColumnBaseInfoCopy(&pSupporter->colList, &pNewQueryInfo->colList, 0);
|
||||
// update the table index
|
||||
size_t num = taosArrayGetSize(pNewQueryInfo->colList);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SColumn* pCol = taosArrayGetP(pNewQueryInfo->colList, i);
|
||||
pCol->colIndex.tableIndex = 0;
|
||||
}
|
||||
|
||||
tscSqlExprCopy(&pSupporter->exprsInfo, &pNewQueryInfo->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopyAll(&pSupporter->fieldsInfo, &pNewQueryInfo->fieldsInfo);
|
||||
tscColumnListCopy(pSupporter->colList, pNewQueryInfo->colList, 0);
|
||||
|
||||
pSupporter->exprsInfo = tscSqlExprCopy(pNewQueryInfo->exprsInfo, pSupporter->uid, false);
|
||||
tscFieldInfoCopy(&pSupporter->fieldsInfo, &pNewQueryInfo->fieldsInfo);
|
||||
|
||||
tscTagCondCopy(&pSupporter->tagCond, &pNewQueryInfo->tagCond);
|
||||
|
||||
|
@ -867,8 +872,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
memset(&pNewQueryInfo->groupbyExpr, 0, sizeof(SSqlGroupbyExpr));
|
||||
|
||||
// this data needs to be transfer to support struct
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols = 0;
|
||||
pNewQueryInfo->exprsInfo.numOfExprs = 0;
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput = 0;
|
||||
|
||||
// set the ts,tags that involved in join, as the output column of intermediate result
|
||||
tscClearSubqueryInfo(&pNew->cmd);
|
||||
|
@ -888,27 +892,26 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
|
|||
pExpr->numOfParams = 1;
|
||||
|
||||
// add the filter tag column
|
||||
for (int32_t i = 0; i < pSupporter->colList.numOfCols; ++i) {
|
||||
SColumnBase *pColBase = &pSupporter->colList.pColList[i];
|
||||
if (pColBase->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered.
|
||||
tscColumnBaseCopy(&pNewQueryInfo->colList.pColList[pNewQueryInfo->colList.numOfCols], pColBase);
|
||||
pNewQueryInfo->colList.numOfCols++;
|
||||
size_t s = taosArrayGetSize(pSupporter->colList);
|
||||
|
||||
for (int32_t i = 0; i < s; ++i) {
|
||||
SColumn *pCol = taosArrayGetP(pSupporter->colList, i);
|
||||
|
||||
if (pCol->numOfFilters > 0) { // copy to the pNew->cmd.colList if it is filtered.
|
||||
SColumn* p = tscColumnClone(pCol);
|
||||
taosArrayPush(pNewQueryInfo->colList, &p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
|
||||
|
||||
tscTrace("%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
|
||||
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
||||
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
|
||||
pNewQueryInfo->exprsInfo.numOfExprs, pNewQueryInfo->colList.numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
tscPrintSelectClause(pNew, 0);
|
||||
|
||||
tscTrace("%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
|
||||
"exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
||||
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type,
|
||||
pNewQueryInfo->exprsInfo.numOfExprs, pNewQueryInfo->colList.numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols,
|
||||
pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
|
||||
tscPrintSelectClause(pNew, 0);
|
||||
|
||||
} else {
|
||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
||||
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY;
|
||||
|
@ -1352,7 +1355,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
|
|||
}
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
printf("received data from vnode: %d rows\n", pRes->numOfRows);
|
||||
printf("received data from vnode: %"PRIu64" rows\n", pRes->numOfRows);
|
||||
SSrcColumnInfo colInfo[256] = {0};
|
||||
|
||||
tscGetSrcColumnInfo(colInfo, pQueryInfo);
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "trpc.h"
|
||||
#include "taosdef.h"
|
||||
#include "tsocket.h"
|
||||
#include "tsystem.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
|
@ -33,16 +31,11 @@
|
|||
|
||||
// global, not configurable
|
||||
void * pVnodeConn;
|
||||
void * pVMeterConn;
|
||||
void * pTscMgmtConn;
|
||||
void * pSlaveConn;
|
||||
void * tscCacheHandle;
|
||||
int slaveIndex;
|
||||
void * tscTmr;
|
||||
void * tscQhandle;
|
||||
void * tscCheckDiskUsageTmr;
|
||||
int tsInsertHeadSize;
|
||||
char tsLastUser[TSDB_USER_LEN + 1];
|
||||
|
||||
int tscNumOfThreads;
|
||||
|
||||
|
@ -50,12 +43,12 @@ static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
|||
void taosInitNote(int numOfNoteLines, int maxNotes, char* lable);
|
||||
void tscUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet);
|
||||
|
||||
void tscCheckDiskUsage(void *para, void *unused) {
|
||||
void tscCheckDiskUsage(void *UNUSED_PARAM(para), void* UNUSED_PARAM(param)) {
|
||||
taosGetDisk();
|
||||
taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr);
|
||||
}
|
||||
|
||||
int32_t tscInitRpc(const char *user, const char *secret) {
|
||||
int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) {
|
||||
SRpcInit rpcInit;
|
||||
char secretEncrypt[32] = {0};
|
||||
taosEncryptPass((uint8_t *)secret, strlen(secret), secretEncrypt);
|
||||
|
@ -67,7 +60,6 @@ int32_t tscInitRpc(const char *user, const char *secret) {
|
|||
rpcInit.label = "TSC-vnode";
|
||||
rpcInit.numOfThreads = tscNumOfThreads;
|
||||
rpcInit.cfp = tscProcessMsgFromServer;
|
||||
rpcInit.ufp = tscUpdateIpSet;
|
||||
rpcInit.sessions = tsMaxVnodeConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.user = (char*)user;
|
||||
|
@ -82,30 +74,24 @@ int32_t tscInitRpc(const char *user, const char *secret) {
|
|||
}
|
||||
}
|
||||
|
||||
// not stop service, switch users
|
||||
if (strcmp(tsLastUser, user) != 0 && pTscMgmtConn != NULL) {
|
||||
tscTrace("switch user from %s to %s", user, tsLastUser);
|
||||
rpcClose(pTscMgmtConn);
|
||||
pTscMgmtConn = NULL;
|
||||
}
|
||||
|
||||
if (pTscMgmtConn == NULL) {
|
||||
if (*pMgmtConn == NULL) {
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localIp = tsLocalIp;
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "TSC-mgmt";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = tscProcessMsgFromServer;
|
||||
rpcInit.ufp = tscUpdateIpSet;
|
||||
rpcInit.sessions = tsMaxMgmtConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = 2000;
|
||||
rpcInit.user = (char*)user;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = secretEncrypt;
|
||||
strcpy(tsLastUser, user);
|
||||
|
||||
pTscMgmtConn = rpcOpen(&rpcInit);
|
||||
if (pTscMgmtConn == NULL) {
|
||||
*pMgmtConn = rpcOpen(&rpcInit);
|
||||
if (*pMgmtConn == NULL) {
|
||||
tscError("failed to init connection to mgmt");
|
||||
return -1;
|
||||
}
|
||||
|
@ -167,7 +153,6 @@ void taos_init_imp() {
|
|||
}
|
||||
|
||||
tscInitMsgsFp();
|
||||
slaveIndex = rand();
|
||||
int queueSize = tsMaxVnodeConnections + tsMaxMeterConnections + tsMaxMgmtConnections + tsMaxMgmtConnections;
|
||||
|
||||
if (tscEmbedded == 0) {
|
||||
|
@ -219,11 +204,6 @@ void taos_cleanup() {
|
|||
pVnodeConn = NULL;
|
||||
}
|
||||
|
||||
if (pTscMgmtConn != NULL) {
|
||||
rpcClose(pTscMgmtConn);
|
||||
pTscMgmtConn = NULL;
|
||||
}
|
||||
|
||||
taosTmrCleanUp(tscTmr);
|
||||
}
|
||||
|
||||
|
@ -395,7 +375,6 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,11 +48,9 @@ extern int32_t tsEnableCoreFile;
|
|||
extern int32_t tsTotalMemoryMB;
|
||||
extern int32_t tsVersion;
|
||||
|
||||
extern int tscEmbedded;
|
||||
|
||||
extern int32_t tscEmbedded;
|
||||
extern int64_t tsMsPerDay[2];
|
||||
|
||||
|
||||
extern char tsMasterIp[];
|
||||
extern char tsSecondIp[];
|
||||
extern uint16_t tsMnodeDnodePort;
|
||||
|
@ -61,94 +59,90 @@ extern uint16_t tsDnodeShellPort;
|
|||
extern uint16_t tsDnodeMnodePort;
|
||||
extern uint16_t tsSyncPort;
|
||||
|
||||
extern int tsStatusInterval;
|
||||
extern int tsShellActivityTimer;
|
||||
extern int tsVnodePeerHBTimer;
|
||||
extern int tsMgmtPeerHBTimer;
|
||||
extern int tsMeterMetaKeepTimer;
|
||||
extern int tsMetricMetaKeepTimer;
|
||||
extern int32_t tsStatusInterval;
|
||||
extern int32_t tsShellActivityTimer;
|
||||
extern int32_t tsVnodePeerHBTimer;
|
||||
extern int32_t tsMgmtPeerHBTimer;
|
||||
extern int32_t tsMeterMetaKeepTimer;
|
||||
extern int32_t tsMetricMetaKeepTimer;
|
||||
|
||||
extern float tsNumOfThreadsPerCore;
|
||||
extern float tsRatioOfQueryThreads;
|
||||
extern char tsPublicIp[];
|
||||
extern char tsPrivateIp[];
|
||||
extern short tsNumOfVnodesPerCore;
|
||||
extern short tsNumOfTotalVnodes;
|
||||
extern short tsCheckHeaderFile;
|
||||
extern float tsNumOfThreadsPerCore;
|
||||
extern float tsRatioOfQueryThreads;
|
||||
extern char tsPublicIp[];
|
||||
extern char tsPrivateIp[];
|
||||
extern int16_t tsNumOfVnodesPerCore;
|
||||
extern int16_t tsNumOfTotalVnodes;
|
||||
extern uint32_t tsPublicIpInt;
|
||||
extern short tsAffectedRowsMod;
|
||||
|
||||
extern int tsSessionsPerVnode;
|
||||
extern int tsAverageCacheBlocks;
|
||||
extern int tsCacheBlockSize;
|
||||
extern int32_t tsCacheBlockSize;
|
||||
extern int32_t tsTotalBlocks;
|
||||
extern int32_t tsTablesPerVnode;
|
||||
extern int16_t tsDaysPerFile;
|
||||
extern int32_t tsDaysToKeep;
|
||||
extern int32_t tsMinRowsInFileBlock;
|
||||
extern int32_t tsMaxRowsInFileBlock;
|
||||
extern int16_t tsCommitTime; // seconds
|
||||
extern int32_t tsTimePrecision;
|
||||
extern int16_t tsCompression;
|
||||
extern int16_t tsCommitLog;
|
||||
extern int32_t tsReplications;
|
||||
|
||||
extern int tsRowsInFileBlock;
|
||||
extern float tsFileBlockMinPercent;
|
||||
|
||||
extern short tsNumOfBlocksPerMeter;
|
||||
extern short tsCommitTime; // seconds
|
||||
extern short tsCommitLog;
|
||||
extern short tsAsyncLog;
|
||||
extern short tsCompression;
|
||||
extern short tsDaysPerFile;
|
||||
extern int tsDaysToKeep;
|
||||
extern int tsReplications;
|
||||
|
||||
extern int tsNumOfMPeers;
|
||||
extern int tsMaxShellConns;
|
||||
extern int tsMaxTables;
|
||||
extern int16_t tsAffectedRowsMod;
|
||||
extern int32_t tsNumOfMPeers;
|
||||
extern int32_t tsMaxShellConns;
|
||||
extern int32_t tsMaxTables;
|
||||
|
||||
extern char tsLocalIp[];
|
||||
extern char tsDefaultDB[];
|
||||
extern char tsDefaultUser[];
|
||||
extern char tsDefaultPass[];
|
||||
extern int tsMaxMeterConnections;
|
||||
extern int tsMaxVnodeConnections;
|
||||
extern int tsMaxMgmtConnections;
|
||||
extern int32_t tsMaxMeterConnections;
|
||||
extern int32_t tsMaxVnodeConnections;
|
||||
extern int32_t tsMaxMgmtConnections;
|
||||
|
||||
extern int tsBalanceMonitorInterval;
|
||||
extern int tsBalanceStartInterval;
|
||||
extern int tsBalancePolicy;
|
||||
extern int tsOfflineThreshold;
|
||||
extern int tsMgmtEqualVnodeNum;
|
||||
extern int32_t tsBalanceMonitorInterval;
|
||||
extern int32_t tsBalanceStartInterval;
|
||||
extern int32_t tsOfflineThreshold;
|
||||
extern int32_t tsMgmtEqualVnodeNum;
|
||||
|
||||
extern int tsEnableHttpModule;
|
||||
extern int tsEnableMonitorModule;
|
||||
extern int tsRestRowLimit;
|
||||
extern int tsCompressMsgSize;
|
||||
extern int tsMaxSQLStringLen;
|
||||
extern int tsMaxNumOfOrderedResults;
|
||||
extern int32_t tsEnableHttpModule;
|
||||
extern int32_t tsEnableMonitorModule;
|
||||
|
||||
extern int32_t tsRestRowLimit;
|
||||
extern int32_t tsMaxSQLStringLen;
|
||||
extern int32_t tsCompressMsgSize;
|
||||
extern int32_t tsMaxNumOfOrderedResults;
|
||||
|
||||
extern char tsSocketType[4];
|
||||
|
||||
extern int tsTimePrecision;
|
||||
extern int tsMinSlidingTime;
|
||||
extern int tsMinIntervalTime;
|
||||
extern int tsMaxStreamComputDelay;
|
||||
extern int tsStreamCompStartDelay;
|
||||
extern int tsStreamCompRetryDelay;
|
||||
extern int32_t tsMinSlidingTime;
|
||||
extern int32_t tsMinIntervalTime;
|
||||
extern int32_t tsMaxStreamComputDelay;
|
||||
extern int32_t tsStreamCompStartDelay;
|
||||
extern int32_t tsStreamCompRetryDelay;
|
||||
extern float tsStreamComputDelayRatio; // the delayed computing ration of the whole time window
|
||||
|
||||
extern int tsProjectExecInterval;
|
||||
extern int64_t tsMaxRetentWindow;
|
||||
|
||||
extern char tsHttpIp[];
|
||||
extern char tsHttpIp[];
|
||||
extern uint16_t tsHttpPort;
|
||||
extern int tsHttpCacheSessions;
|
||||
extern int tsHttpSessionExpire;
|
||||
extern int tsHttpMaxThreads;
|
||||
extern int tsHttpEnableCompress;
|
||||
extern int tsHttpEnableRecordSql;
|
||||
extern int tsTelegrafUseFieldNum;
|
||||
extern int32_t tsHttpCacheSessions;
|
||||
extern int32_t tsHttpSessionExpire;
|
||||
extern int32_t tsHttpMaxThreads;
|
||||
extern int32_t tsHttpEnableCompress;
|
||||
extern int32_t tsHttpEnableRecordSql;
|
||||
extern int32_t tsTelegrafUseFieldNum;
|
||||
|
||||
extern int tsTscEnableRecordSql;
|
||||
extern int tsAnyIp;
|
||||
extern int32_t tsTscEnableRecordSql;
|
||||
extern int32_t tsAnyIp;
|
||||
|
||||
extern char tsMonitorDbName[];
|
||||
extern char tsInternalPass[];
|
||||
extern int tsMonitorInterval;
|
||||
extern char tsMonitorDbName[];
|
||||
extern char tsInternalPass[];
|
||||
extern int32_t tsMonitorInterval;
|
||||
|
||||
extern int tsNumOfLogLines;
|
||||
extern int32_t tsAsyncLog;
|
||||
extern int32_t tsNumOfLogLines;
|
||||
extern int32_t ddebugFlag;
|
||||
extern int32_t mdebugFlag;
|
||||
extern int32_t cdebugFlag;
|
||||
|
|
|
@ -74,43 +74,40 @@ int32_t tsVnodePeerHBTimer = 1; // second
|
|||
int32_t tsMgmtPeerHBTimer = 1; // second
|
||||
int32_t tsMeterMetaKeepTimer = 7200; // second
|
||||
int32_t tsMetricMetaKeepTimer = 600; // second
|
||||
int tsRpcTimer = 300;
|
||||
int tsRpcMaxTime = 600; // seconds;
|
||||
int32_t tsRpcTimer = 300;
|
||||
int32_t tsRpcMaxTime = 600; // seconds;
|
||||
|
||||
float tsNumOfThreadsPerCore = 1.0;
|
||||
float tsRatioOfQueryThreads = 0.5;
|
||||
char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0};
|
||||
char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0};
|
||||
float tsNumOfThreadsPerCore = 1.0;
|
||||
float tsRatioOfQueryThreads = 0.5;
|
||||
char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0};
|
||||
char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0};
|
||||
int16_t tsNumOfVnodesPerCore = 8;
|
||||
int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM;
|
||||
int16_t tsCheckHeaderFile = 0;
|
||||
|
||||
#ifdef _TD_ARM_32_
|
||||
int32_t tsSessionsPerVnode = 100;
|
||||
int32_t tsTablesPerVnode = 100;
|
||||
#else
|
||||
int32_t tsSessionsPerVnode = 1000;
|
||||
int32_t tsTablesPerVnode = TSDB_DEFAULT_TABLES;
|
||||
#endif
|
||||
|
||||
int32_t tsCacheBlockSize = 16384; // 256 columns
|
||||
int32_t tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS;
|
||||
int32_t tsCacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||
int32_t tsTotalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
|
||||
int16_t tsDaysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
|
||||
int32_t tsDaysToKeep = TSDB_DEFAULT_KEEP;
|
||||
int32_t tsMinRowsInFileBlock = TSDB_DEFAULT_MIN_ROW_FBLOCK;
|
||||
int32_t tsMaxRowsInFileBlock = TSDB_DEFAULT_MAX_ROW_FBLOCK;
|
||||
int16_t tsCommitTime = TSDB_DEFAULT_COMMIT_TIME; // seconds
|
||||
int32_t tsTimePrecision = TSDB_DEFAULT_PRECISION;
|
||||
int16_t tsCompression = TSDB_DEFAULT_COMP_LEVEL;
|
||||
int16_t tsCommitLog = TSDB_DEFAULT_CLOG_LEVEL;
|
||||
int32_t tsReplications = TSDB_DEFAULT_REPLICA_NUM;
|
||||
|
||||
/**
|
||||
* Change the meaning of affected rows:
|
||||
* 0: affected rows not include those duplicate records
|
||||
* 1: affected rows include those duplicate records
|
||||
*/
|
||||
int16_t tsAffectedRowsMod = 0;
|
||||
|
||||
int32_t tsRowsInFileBlock = 4096;
|
||||
float tsFileBlockMinPercent = 0.05;
|
||||
|
||||
int16_t tsNumOfBlocksPerMeter = 100;
|
||||
int16_t tsCommitTime = 3600; // seconds
|
||||
int16_t tsCommitLog = 1;
|
||||
int16_t tsCompression = TSDB_MAX_COMPRESSION_LEVEL;
|
||||
int16_t tsDaysPerFile = 10;
|
||||
int32_t tsDaysToKeep = 3650;
|
||||
int32_t tsReplications = TSDB_REPLICA_MIN_NUM;
|
||||
|
||||
int32_t tsNumOfMPeers = 3;
|
||||
int32_t tsMaxShellConns = 2000;
|
||||
int32_t tsMaxTables = 100000;
|
||||
|
@ -125,15 +122,16 @@ int32_t tsMaxVnodeConnections = 10000;
|
|||
|
||||
int32_t tsBalanceMonitorInterval = 2; // seconds
|
||||
int32_t tsBalanceStartInterval = 300; // seconds
|
||||
int32_t tsBalancePolicy = 0; // 1-use sys.montor
|
||||
int32_t tsOfflineThreshold = 864000; // seconds 10days
|
||||
int32_t tsMgmtEqualVnodeNum = 4;
|
||||
|
||||
int32_t tsEnableHttpModule = 1;
|
||||
int32_t tsEnableMonitorModule = 0;
|
||||
|
||||
int32_t tsRestRowLimit = 10240;
|
||||
int32_t tsMaxSQLStringLen = TSDB_MAX_SQL_LEN;
|
||||
|
||||
int32_t tsNumOfLogLines = 10000000;
|
||||
int32_t mdebugFlag = 135;
|
||||
int32_t sdbDebugFlag = 135;
|
||||
int32_t ddebugFlag = 131;
|
||||
|
@ -146,7 +144,6 @@ int32_t qdebugFlag = 131;
|
|||
int32_t rpcDebugFlag = 131;
|
||||
int32_t uDebugFlag = 131;
|
||||
int32_t debugFlag = 131;
|
||||
int tsNumOfLogLines = 10000000;
|
||||
|
||||
// the maximum number of results for projection query on super table that are returned from
|
||||
// one virtual node, to order according to timestamp
|
||||
|
@ -165,9 +162,6 @@ int32_t tsCompressMsgSize = -1;
|
|||
// use UDP by default[option: udp, tcp]
|
||||
char tsSocketType[4] = "udp";
|
||||
|
||||
// time precision, millisecond by default
|
||||
int32_t tsTimePrecision = TSDB_TIME_PRECISION_MILLI;
|
||||
|
||||
// 10 ms for sliding time, the value will changed in case of time precision changed
|
||||
int32_t tsMinSlidingTime = 10;
|
||||
|
||||
|
@ -575,16 +569,6 @@ static void doInitGlobalConfig() {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "ctime";
|
||||
cfg.ptr = &tsCommitTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 30;
|
||||
cfg.maxValue = 40960;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "statusInterval";
|
||||
cfg.ptr = &tsStatusInterval;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
|
@ -686,62 +670,12 @@ static void doInitGlobalConfig() {
|
|||
taosInitConfigOption(cfg);
|
||||
|
||||
// database configs
|
||||
cfg.option = "clog";
|
||||
cfg.ptr = &tsCommitLog;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 2;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "comp";
|
||||
cfg.ptr = &tsCompression;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 2;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "days";
|
||||
cfg.ptr = &tsDaysPerFile;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 365;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "keep";
|
||||
cfg.ptr = &tsDaysToKeep;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 365000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "replica";
|
||||
cfg.ptr = &tsReplications;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 3;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "tables";
|
||||
cfg.ptr = &tsSessionsPerVnode;
|
||||
cfg.ptr = &tsTablesPerVnode;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_TABLES_PER_VNODE;
|
||||
cfg.maxValue = TSDB_MAX_TABLES_PER_VNODE;
|
||||
cfg.minValue = TSDB_MIN_TABLES;
|
||||
cfg.maxValue = TSDB_MAX_TABLES;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
@ -750,48 +684,98 @@ static void doInitGlobalConfig() {
|
|||
cfg.ptr = &tsCacheBlockSize;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 100;
|
||||
cfg.maxValue = 1048576;
|
||||
cfg.minValue = TSDB_MIN_CACHE_BLOCK_SIZE;
|
||||
cfg.maxValue = TSDB_MAX_CACHE_BLOCK_SIZE;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "rows";
|
||||
cfg.ptr = &tsRowsInFileBlock;
|
||||
cfg.option = "blocks";
|
||||
cfg.ptr = &tsTotalBlocks;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 200;
|
||||
cfg.maxValue = 1048576;
|
||||
cfg.minValue = TSDB_MIN_TOTAL_BLOCKS;
|
||||
cfg.maxValue = TSDB_MAX_TOTAL_BLOCKS;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "fileBlockMinPercent";
|
||||
cfg.ptr = &tsFileBlockMinPercent;
|
||||
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1.0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "ablocks";
|
||||
cfg.ptr = &tsAverageCacheBlocks;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_AVG_BLOCKS;
|
||||
cfg.maxValue = TSDB_MAX_AVG_BLOCKS;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "tblocks";
|
||||
cfg.ptr = &tsNumOfBlocksPerMeter;
|
||||
cfg.option = "days";
|
||||
cfg.ptr = &tsDaysPerFile;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 32;
|
||||
cfg.maxValue = 4096;
|
||||
cfg.minValue = TSDB_MIN_DAYS_PER_FILE;
|
||||
cfg.maxValue = TSDB_MAX_DAYS_PER_FILE;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "keep";
|
||||
cfg.ptr = &tsDaysToKeep;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_KEEP;
|
||||
cfg.maxValue = TSDB_MAX_KEEP;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "minRows";
|
||||
cfg.ptr = &tsMinRowsInFileBlock;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_MIN_ROW_FBLOCK;
|
||||
cfg.maxValue = TSDB_MAX_MIN_ROW_FBLOCK;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxRows";
|
||||
cfg.ptr = &tsMaxRowsInFileBlock;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_MAX_ROW_FBLOCK;
|
||||
cfg.maxValue = TSDB_MAX_MAX_ROW_FBLOCK;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "ctime";
|
||||
cfg.ptr = &tsCommitTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_COMMIT_TIME;
|
||||
cfg.maxValue = TSDB_MAX_COMMIT_TIME;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "comp";
|
||||
cfg.ptr = &tsCompression;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_COMP_LEVEL;
|
||||
cfg.maxValue = TSDB_MAX_COMP_LEVEL;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "clog";
|
||||
cfg.ptr = &tsCommitLog;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_CLOG_LEVEL;
|
||||
cfg.maxValue = TSDB_MAX_CLOG_LEVEL;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "replica";
|
||||
cfg.ptr = &tsReplications;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_REPLICA_NUM;
|
||||
cfg.maxValue = TSDB_MAX_REPLICA_NUM;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
|
|
@ -316,6 +316,9 @@ class CTaosInterface(object):
|
|||
blocks = [None] * len(fields)
|
||||
for i in range(len(fields)):
|
||||
data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
|
||||
if data == None:
|
||||
blocks[i] = [None] * num_of_rows
|
||||
continue
|
||||
|
||||
if fields[i]['type'] not in _CONVERT_FUNC:
|
||||
raise DatabaseError("Invalid data type returned from database")
|
||||
|
|
|
@ -316,6 +316,9 @@ class CTaosInterface(object):
|
|||
blocks = [None] * len(fields)
|
||||
for i in range(len(fields)):
|
||||
data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
|
||||
if data == None:
|
||||
blocks[i] = [None] * num_of_rows
|
||||
continue
|
||||
|
||||
if fields[i]['type'] not in _CONVERT_FUNC:
|
||||
raise DatabaseError("Invalid data type returned from database")
|
||||
|
|
|
@ -316,6 +316,9 @@ class CTaosInterface(object):
|
|||
blocks = [None] * len(fields)
|
||||
for i in range(len(fields)):
|
||||
data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
|
||||
if data == None:
|
||||
blocks[i] = [None] * num_of_rows
|
||||
continue
|
||||
|
||||
if fields[i]['type'] not in _CONVERT_FUNC:
|
||||
raise DatabaseError("Invalid data type returned from database")
|
||||
|
|
|
@ -316,6 +316,9 @@ class CTaosInterface(object):
|
|||
blocks = [None] * len(fields)
|
||||
for i in range(len(fields)):
|
||||
data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
|
||||
if data == None:
|
||||
blocks[i] = [None] * num_of_rows
|
||||
continue
|
||||
|
||||
if fields[i]['type'] not in _CONVERT_FUNC:
|
||||
raise DatabaseError("Invalid data type returned from database")
|
||||
|
|
|
@ -39,10 +39,6 @@ extern int32_t ddebugFlag;
|
|||
#define dPrint(...) \
|
||||
{ taosPrintLog("DND ", 255, __VA_ARGS__); }
|
||||
|
||||
#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__)
|
||||
#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__)
|
||||
#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -59,6 +59,19 @@ void dnodeUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) {
|
|||
tsMnodeIpSet = *pIpSet;
|
||||
}
|
||||
|
||||
void dnodeGetMnodeIpSet(void *ipSetRaw, bool usePublicIp) {
|
||||
SRpcIpSet *ipSet = ipSetRaw;
|
||||
ipSet->numOfIps = tsMnodeInfos.nodeNum;
|
||||
ipSet->inUse = tsMnodeInfos.inUse;
|
||||
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; ++i) {
|
||||
if (usePublicIp) {
|
||||
ipSet->ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp;
|
||||
} else {
|
||||
ipSet->ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitMClient() {
|
||||
dnodeReadDnodeCfg();
|
||||
tsRebootTime = taosGetTimestampSec();
|
||||
|
@ -138,7 +151,9 @@ static void dnodeProcessRspFromMnode(SRpcMsg *pMsg) {
|
|||
if (tsDnodeProcessMgmtRspFp[pMsg->msgType]) {
|
||||
(*tsDnodeProcessMgmtRspFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
dError("%s is not processed in mnode rpc client", taosMsg[pMsg->msgType]);
|
||||
dError("%s is not processed in dnode mclient", taosMsg[pMsg->msgType]);
|
||||
SRpcMsg rpcRsp = {.pCont = 0, .contLen = 0, .code = TSDB_CODE_OPS_NOT_SUPPORT, .handle = pMsg->handle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -128,14 +128,16 @@ static void dnodeCloseVnodes() {
|
|||
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||
SMDCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||
pCreate->cfg.vgId = htonl(pCreate->cfg.vgId);
|
||||
pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion);
|
||||
pCreate->cfg.maxTables = htonl(pCreate->cfg.maxTables);
|
||||
pCreate->cfg.maxCacheSize = htobe64(pCreate->cfg.maxCacheSize);
|
||||
pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock);
|
||||
pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock);
|
||||
pCreate->cfg.cacheBlockSize = htonl(pCreate->cfg.cacheBlockSize);
|
||||
pCreate->cfg.totalBlocks = htonl(pCreate->cfg.totalBlocks);
|
||||
pCreate->cfg.daysPerFile = htonl(pCreate->cfg.daysPerFile);
|
||||
pCreate->cfg.daysToKeep1 = htonl(pCreate->cfg.daysToKeep1);
|
||||
pCreate->cfg.daysToKeep2 = htonl(pCreate->cfg.daysToKeep2);
|
||||
pCreate->cfg.daysToKeep = htonl(pCreate->cfg.daysToKeep);
|
||||
pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock);
|
||||
pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock);
|
||||
pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime);
|
||||
pCreate->cfg.arbitratorIp = htonl(pCreate->cfg.arbitratorIp);
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ static void dnodeProcessMsgFromMnode(SRpcMsg *pMsg) {
|
|||
if (dnodeProcessMgmtMsgFp[pMsg->msgType]) {
|
||||
(*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
dError("%s is not processed in mserver", taosMsg[pMsg->msgType]);
|
||||
dError("%s is not processed in dnode mserver", taosMsg[pMsg->msgType]);
|
||||
rspMsg.code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -90,7 +90,7 @@ void dnodeCleanUpModules() {
|
|||
int32_t dnodeInitModules() {
|
||||
dnodeAllocModules();
|
||||
|
||||
for (int32_t module = 0; module < TSDB_MOD_MAX; ++module) {
|
||||
for (EModuleType module = 0; module < TSDB_MOD_MAX; ++module) {
|
||||
if (tsModule[module].initFp) {
|
||||
if ((*tsModule[module].initFp)() != 0) {
|
||||
dError("failed to init module:%s", tsModule[module].name);
|
||||
|
@ -103,7 +103,7 @@ int32_t dnodeInitModules() {
|
|||
}
|
||||
|
||||
void dnodeStartModules() {
|
||||
for (int32_t module = 1; module < TSDB_MOD_MAX; ++module) {
|
||||
for (EModuleType module = 1; module < TSDB_MOD_MAX; ++module) {
|
||||
if (tsModule[module].enable && tsModule[module].startFp) {
|
||||
if ((*tsModule[module].startFp)() != 0) {
|
||||
dError("failed to start module:%s", tsModule[module].name);
|
||||
|
|
|
@ -20,16 +20,17 @@
|
|||
#include "taosmsg.h"
|
||||
#include "trpc.h"
|
||||
#include "tglobal.h"
|
||||
#include "http.h"
|
||||
#include "dnode.h"
|
||||
#include "dnodeLog.h"
|
||||
#include "dnodeRead.h"
|
||||
#include "dnodeWrite.h"
|
||||
#include "dnodeShell.h"
|
||||
|
||||
static void (*dnodeProcessShellMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
static void dnodeProcessMsgFromShell(SRpcMsg *pMsg);
|
||||
static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
static void *tsDnodeShellRpc = NULL;
|
||||
static void (*dnodeProcessShellMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
static void dnodeProcessMsgFromShell(SRpcMsg *pMsg);
|
||||
static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
static void * tsDnodeShellRpc = NULL;
|
||||
static int32_t tsDnodeQueryReqNum = 0;
|
||||
static int32_t tsDnodeSubmitReqNum = 0;
|
||||
|
||||
|
@ -110,7 +111,7 @@ static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char
|
|||
SDnodeStatisInfo dnodeGetStatisInfo() {
|
||||
SDnodeStatisInfo info = {0};
|
||||
if (dnodeGetRunStatus() == TSDB_DNODE_RUN_STATUS_RUNING) {
|
||||
//info.httpReqNum = httpGetReqCount();
|
||||
info.httpReqNum = httpGetReqCount();
|
||||
info.queryReqNum = atomic_exchange_32(&tsDnodeQueryReqNum, 0);
|
||||
info.submitReqNum = atomic_exchange_32(&tsDnodeSubmitReqNum, 0);
|
||||
}
|
||||
|
|
|
@ -41,8 +41,9 @@ void *dnodeAllocateRqueue(void *pVnode);
|
|||
void dnodeFreeRqueue(void *rqueue);
|
||||
void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code);
|
||||
|
||||
bool dnodeIsFirstDeploy();
|
||||
bool dnodeIsFirstDeploy();
|
||||
uint32_t dnodeGetMnodeMasteIp();
|
||||
void dnodeGetMnodeIpSet(void *ipSet, bool usePublicIp);
|
||||
void * dnodeGetMnodeInfos();
|
||||
int32_t dnodeGetDnodeId();
|
||||
|
||||
|
|
|
@ -22,10 +22,38 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
char * acctId;
|
||||
int64_t currentPointsPerSecond;
|
||||
int64_t maxPointsPerSecond;
|
||||
int64_t totalTimeSeries;
|
||||
int64_t maxTimeSeries;
|
||||
int64_t totalStorage;
|
||||
int64_t maxStorage;
|
||||
int64_t totalQueryTime;
|
||||
int64_t maxQueryTime;
|
||||
int64_t totalInbound;
|
||||
int64_t maxInbound;
|
||||
int64_t totalOutbound;
|
||||
int64_t maxOutbound;
|
||||
int64_t totalDbs;
|
||||
int64_t maxDbs;
|
||||
int64_t totalUsers;
|
||||
int64_t maxUsers;
|
||||
int64_t totalStreams;
|
||||
int64_t maxStreams;
|
||||
int64_t totalConns;
|
||||
int64_t maxConns;
|
||||
int8_t accessState;
|
||||
} SAcctMonitorObj;
|
||||
|
||||
int32_t monitorInitSystem();
|
||||
int32_t monitorStartSystem();
|
||||
void monitorStopSystem();
|
||||
void monitorCleanUpSystem();
|
||||
void monitorStopSystem();
|
||||
void monitorCleanUpSystem();
|
||||
void monitorSaveAcctLog(SAcctMonitorObj *pMonObj);
|
||||
void monitorSaveLog(int32_t level, const char *const format, ...);
|
||||
void monitorExecuteSQL(char *sql);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ extern "C" {
|
|||
#define TSKEY int64_t
|
||||
#endif
|
||||
|
||||
// this data type is internally used only in 'in' query to hold the values
|
||||
#define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1)
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[11];
|
||||
// TODO: replace and remove code below
|
||||
|
@ -141,16 +144,17 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
|||
#define TSDB_RELATION_GREATER_EQUAL 5
|
||||
#define TSDB_RELATION_NOT_EQUAL 6
|
||||
#define TSDB_RELATION_LIKE 7
|
||||
#define TSDB_RELATION_IN 8
|
||||
|
||||
#define TSDB_RELATION_AND 8
|
||||
#define TSDB_RELATION_OR 9
|
||||
#define TSDB_RELATION_NOT 10
|
||||
#define TSDB_RELATION_AND 9
|
||||
#define TSDB_RELATION_OR 10
|
||||
#define TSDB_RELATION_NOT 11
|
||||
|
||||
#define TSDB_BINARY_OP_ADD 11
|
||||
#define TSDB_BINARY_OP_SUBTRACT 12
|
||||
#define TSDB_BINARY_OP_MULTIPLY 13
|
||||
#define TSDB_BINARY_OP_DIVIDE 14
|
||||
#define TSDB_BINARY_OP_REMAINDER 15
|
||||
#define TSDB_BINARY_OP_ADD 12
|
||||
#define TSDB_BINARY_OP_SUBTRACT 13
|
||||
#define TSDB_BINARY_OP_MULTIPLY 14
|
||||
#define TSDB_BINARY_OP_DIVIDE 15
|
||||
#define TSDB_BINARY_OP_REMAINDER 16
|
||||
#define TSDB_USERID_LEN 9
|
||||
#define TS_PATH_DELIMITER_LEN 1
|
||||
|
||||
|
@ -217,47 +221,56 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
|||
#define TSDB_MAX_MPEERS 5
|
||||
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1)
|
||||
|
||||
#define TSDB_REPLICA_MIN_NUM 1
|
||||
/*
|
||||
* this is defined in CMakeList.txt
|
||||
*/
|
||||
#define TSDB_REPLICA_MAX_NUM 3
|
||||
|
||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
|
||||
|
||||
//default value == 10
|
||||
#define TSDB_FILE_MIN_PARTITION_RANGE 1 //minimum partition range of vnode file in days
|
||||
#define TSDB_FILE_MAX_PARTITION_RANGE 3650 //max partition range of vnode file in days
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 1000000
|
||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
||||
|
||||
#define TSDB_DATA_MIN_RESERVE_DAY 1 // data in db to be reserved.
|
||||
#define TSDB_DATA_DEFAULT_RESERVE_DAY 3650 // ten years
|
||||
#define TSDB_MIN_TOTAL_BLOCKS 2
|
||||
#define TSDB_MAX_TOTAL_BLOCKS 10000
|
||||
#define TSDB_DEFAULT_TOTAL_BLOCKS 2
|
||||
|
||||
#define TSDB_MIN_COMPRESSION_LEVEL 0
|
||||
#define TSDB_MAX_COMPRESSION_LEVEL 2
|
||||
#define TSDB_MIN_TABLES 4
|
||||
#define TSDB_MAX_TABLES 200000
|
||||
#define TSDB_DEFAULT_TABLES 1000
|
||||
|
||||
#define TSDB_MIN_COMMIT_TIME_INTERVAL 30
|
||||
#define TSDB_MAX_COMMIT_TIME_INTERVAL 40960
|
||||
#define TSDB_MIN_DAYS_PER_FILE 1
|
||||
#define TSDB_MAX_DAYS_PER_FILE 3650
|
||||
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
||||
|
||||
#define TSDB_MIN_ROWS_IN_FILEBLOCK 200
|
||||
#define TSDB_MAX_ROWS_IN_FILEBLOCK 500000
|
||||
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
|
||||
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
|
||||
#define TSDB_DEFAULT_KEEP 3650 // ten years
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 100
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 104857600
|
||||
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
||||
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
||||
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCKS 100
|
||||
#define TSDB_MAX_CACHE_BLOCKS 409600
|
||||
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
||||
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
||||
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
||||
|
||||
#define TSDB_MIN_AVG_BLOCKS 2
|
||||
#define TSDB_MAX_AVG_BLOCKS 2048
|
||||
#define TSDB_DEFAULT_AVG_BLOCKS 4
|
||||
#define TSDB_MIN_COMMIT_TIME 30
|
||||
#define TSDB_MAX_COMMIT_TIME 40960
|
||||
#define TSDB_DEFAULT_COMMIT_TIME 3600
|
||||
|
||||
/*
|
||||
* There is a bug in function taosAllocateId.
|
||||
* When "create database tables 1" is executed, the wrong sid is assigned, so the minimum value is set to 2.
|
||||
*/
|
||||
#define TSDB_MIN_TABLES_PER_VNODE 2
|
||||
#define TSDB_MAX_TABLES_PER_VNODE 220000
|
||||
#define TSDB_MIN_PRECISION TSDB_PRECISION_MILLI
|
||||
#define TSDB_MAX_PRECISION TSDB_PRECISION_NANO
|
||||
#define TSDB_DEFAULT_PRECISION TSDB_PRECISION_MILLI
|
||||
|
||||
#define TSDB_MIN_COMP_LEVEL 0
|
||||
#define TSDB_MAX_COMP_LEVEL 2
|
||||
#define TSDB_DEFAULT_COMP_LEVEL 2
|
||||
|
||||
#define TSDB_MIN_CLOG_LEVEL 0
|
||||
#define TSDB_MAX_CLOG_LEVEL 2
|
||||
#define TSDB_DEFAULT_CLOG_LEVEL 2
|
||||
|
||||
#define TSDB_MIN_REPLICA_NUM 1
|
||||
#define TSDB_MAX_REPLICA_NUM 3
|
||||
#define TSDB_DEFAULT_REPLICA_NUM 1
|
||||
|
||||
#define TSDB_MAX_JOIN_TABLE_NUM 5
|
||||
#define TSDB_MAX_UNION_CLAUSE 5
|
||||
|
|
|
@ -97,73 +97,80 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE, 0, 203, "invalid table n
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUPER_TABLE, 0, 204, "no super table") // operation only available for super table
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_TABLE, 0, 205, "not active table")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ID_MISMATCH, 0, 206, "table id mismatch")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TAG_ALREAY_EXIST, 0, 207, "tag already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TAG_NOT_EXIST, 0, 208, "tag not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_ALREAY_EXIST, 0, 209, "field already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_NOT_EXIST, 0, 210, "field not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_COL_NAME_TOO_LONG, 0, 211, "column name too long")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TAGS, 0, 211, "too many tags")
|
||||
|
||||
|
||||
// dnode & mnode
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 300, "no enough dnodes")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 301, "dnode already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 302, "dnode not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 303, "no master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 304, "no remove master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 305, "invalid query id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 306, "invalid stream id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 307, "invalid connection")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 308, "sdb error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 250, "no enough dnodes")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 251, "dnode already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 252, "dnode not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 253, "no master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 254, "no remove master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 255, "invalid query id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 256, "invalid stream id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 257, "invalid connection")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 258, "sdb error")
|
||||
|
||||
// acct
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 400, "accounts already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 401, "invalid account")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 402, "invalid account parameter")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 403, "too many accounts")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 404, "too many users")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 405, "too many tables")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 406, "too many databases")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 407, "not enough time series")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 300, "accounts already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 301, "invalid account")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 302, "invalid account parameter")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 303, "too many accounts")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 304, "too many users")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 305, "too many tables")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 306, "too many databases")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 307, "not enough time series")
|
||||
|
||||
// grant
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 400, "auth failure")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 401, "no rights")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 402, "no write access")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 403, "no read access")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 404, "grant expired")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 405, "grant dnode limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 406, "grant account limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 407, "grant timeseries limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 408, "grant db limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 409, "grant user limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 410, "grant conn limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 411, "grant stream limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 412, "grant speed limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 413, "grant storage limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 414, "grant query time limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 415, "grant cpu limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 350, "auth failure")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 351, "no rights")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 352, "no write access")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 353, "no read access")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 354, "grant expired")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 355, "grant dnode limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 356, "grant account limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 357, "grant timeseries limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 358, "grant db limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 359, "grant user limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 360, "grant conn limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 361, "grant stream limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 362, "grant speed limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 363, "grant storage limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 364, "grant query time limited")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 365, "grant cpu limited")
|
||||
|
||||
// server
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 500, "invalid vgroup id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VNODE_ID, 0, 501, "invalid vnode id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_VNODE, 0, 502, "not active vnode")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 503, "vg init failed")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 504, "server no diskspace")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 505, "server out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 506, "no disk permissions")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 507, "file corrupted")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 508, "memory corrupted")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 400, "invalid vgroup id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VNODE_ID, 0, 401, "invalid vnode id")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_VNODE, 0, 402, "not active vnode")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 403, "vg init failed")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 404, "server no diskspace")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 405, "server out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 406, "no disk permissions")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 407, "file corrupted")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 408, "memory corrupted")
|
||||
|
||||
// client
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 601, "invalid client version")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 602, "client out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 603, "client no disk space")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 604, "invalid timestamp")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 605, "invalid sql")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 606, "query cache erased")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 607, "invalid query message") // failed to validate the sql expression msg by vnode
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 608, "sorted res too many") // too many result for ordered super table projection query
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 609, "invalid handle")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 610, "query cancelled")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 611, "invalid ie")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 612, "invalid value")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 451, "invalid client version")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 452, "client out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 453, "client no disk space")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 454, "invalid timestamp")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 455, "invalid sql")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 456, "query cache erased")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 457, "invalid query message") // failed to validate the sql expression msg by vnode
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 458, "sorted res too many") // too many result for ordered super table projection query
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 459, "invalid handle")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 460, "query cancelled")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 461, "invalid ie")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 462, "invalid value")
|
||||
|
||||
// others
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 700, "invalid file format")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 500, "invalid file format")
|
||||
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
|
|
|
@ -238,7 +238,7 @@ typedef struct {
|
|||
|
||||
typedef struct SSchema {
|
||||
uint8_t type;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
char name[TSDB_COL_NAME_LEN + 1];
|
||||
int16_t colId;
|
||||
int16_t bytes;
|
||||
} SSchema;
|
||||
|
@ -256,14 +256,14 @@ typedef struct {
|
|||
uint64_t uid;
|
||||
uint64_t superTableUid;
|
||||
uint64_t createdTime;
|
||||
char tableId[TSDB_TABLE_ID_LEN];
|
||||
char superTableId[TSDB_TABLE_ID_LEN];
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char superTableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char data[];
|
||||
} SMDCreateTableMsg;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char db[TSDB_DB_NAME_LEN + 1];
|
||||
int8_t igExists;
|
||||
int16_t numOfTags;
|
||||
int16_t numOfColumns;
|
||||
|
@ -274,13 +274,13 @@ typedef struct {
|
|||
} SCMCreateTableMsg;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN];
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
int8_t igNotExists;
|
||||
} SCMDropTableMsg;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char db[TSDB_DB_NAME_LEN + 1];
|
||||
int16_t type; /* operation type */
|
||||
char tagVal[TSDB_MAX_BYTES_PER_ROW];
|
||||
int8_t numOfCols; /* number of schema */
|
||||
|
@ -345,7 +345,6 @@ typedef struct {
|
|||
} SMDDropTableMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t contLen;
|
||||
int32_t vgId;
|
||||
int64_t uid;
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
|
@ -356,23 +355,15 @@ typedef struct {
|
|||
} SMDDropVnodeMsg;
|
||||
|
||||
typedef struct SColIndex {
|
||||
int16_t colId;
|
||||
/*
|
||||
* colIdx is the index of column in latest schema of table
|
||||
* it is available in the client side. Also used to determine
|
||||
* whether current table schema is up-to-date.
|
||||
*
|
||||
* colIdxInBuf is used to denote the index of column in pQuery->colList,
|
||||
* this value is invalid in client side, as well as in cache block of vnode either.
|
||||
*/
|
||||
int16_t colIndex;
|
||||
uint16_t flag; // denote if it is a tag or not
|
||||
int16_t colId; // column id
|
||||
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
|
||||
uint16_t flag; // denote if it is a tag or a normal column
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
} SColIndex;
|
||||
|
||||
/* sql function msg, to describe the message to vnode about sql function
|
||||
* operations in select clause */
|
||||
typedef struct SSqlFuncExprMsg {
|
||||
typedef struct SSqlFuncMsg {
|
||||
int16_t functionId;
|
||||
int16_t numOfParams;
|
||||
|
||||
|
@ -386,26 +377,20 @@ typedef struct SSqlFuncExprMsg {
|
|||
char * pz;
|
||||
} argValue;
|
||||
} arg[3];
|
||||
} SSqlFuncExprMsg;
|
||||
} SSqlFuncMsg;
|
||||
|
||||
typedef struct SSqlBinaryExprInfo {
|
||||
struct tExprNode *pBinExpr; /* for binary expression */
|
||||
int32_t numOfCols; /* binary expression involves the readed number of columns*/
|
||||
SColIndex * pReqColumns; /* source column list */
|
||||
} SSqlBinaryExprInfo;
|
||||
|
||||
typedef struct SSqlFunctionExpr {
|
||||
SSqlFuncExprMsg pBase;
|
||||
SSqlBinaryExprInfo binExprInfo;
|
||||
int16_t resBytes;
|
||||
int16_t resType;
|
||||
int16_t interResBytes;
|
||||
} SSqlFunctionExpr;
|
||||
typedef struct SArithExprInfo {
|
||||
SSqlFuncMsg base;
|
||||
struct tExprNode* pExpr;
|
||||
int16_t bytes;
|
||||
int16_t type;
|
||||
int16_t interResBytes;
|
||||
} SArithExprInfo;
|
||||
|
||||
typedef struct SColumnFilterInfo {
|
||||
int16_t lowerRelOptr;
|
||||
int16_t upperRelOptr;
|
||||
int16_t filterOnBinary; /* denote if current column is binary */
|
||||
int16_t filterstr; // denote if current column is char(binary/nchar)
|
||||
|
||||
union {
|
||||
struct {
|
||||
|
@ -469,16 +454,18 @@ typedef struct {
|
|||
int64_t limit;
|
||||
int64_t offset;
|
||||
uint16_t queryType; // denote another query process
|
||||
int16_t numOfOutputCols; // final output columns numbers
|
||||
int16_t numOfOutput; // final output columns numbers
|
||||
int16_t tagNameRelType; // relation of tag criteria and tbname criteria
|
||||
int16_t interpoType; // interpolate type
|
||||
uint64_t defaultVal; // default value array list
|
||||
|
||||
int32_t colNameLen;
|
||||
int64_t colNameList;
|
||||
// int32_t colNameLen;
|
||||
// int64_t colNameList;
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
int32_t numOfTags; // number of tags columns involved
|
||||
SColumnInfo colList[];
|
||||
} SQueryTableMsg;
|
||||
|
||||
|
@ -504,12 +491,12 @@ typedef struct SRetrieveTableRsp {
|
|||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t cfgVersion;
|
||||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
uint8_t status;
|
||||
uint8_t role;
|
||||
uint8_t accessState;
|
||||
uint8_t replica;
|
||||
uint8_t reserved[5];
|
||||
} SVnodeLoad;
|
||||
|
@ -517,28 +504,22 @@ typedef struct {
|
|||
typedef struct {
|
||||
char acct[TSDB_USER_LEN + 1];
|
||||
char db[TSDB_DB_NAME_LEN + 1];
|
||||
uint32_t vgId;
|
||||
int32_t maxSessions;
|
||||
int32_t cacheBlockSize;
|
||||
union {
|
||||
int32_t totalBlocks;
|
||||
float fraction;
|
||||
} cacheNumOfBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t daysToKeep;
|
||||
int32_t commitTime;
|
||||
int32_t rowsInFileBlock;
|
||||
int16_t blocksPerTable;
|
||||
int8_t compression;
|
||||
int8_t commitLog;
|
||||
int8_t replications;
|
||||
int8_t repStrategy;
|
||||
int8_t loadLatest; // load into mem or not
|
||||
uint8_t precision; // time resolution
|
||||
int8_t reserved[16];
|
||||
} SDbCfg, SCMCreateDbMsg, SCMAlterDbMsg;
|
||||
int32_t cacheBlockSize; //MB
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t daysToKeep;
|
||||
int32_t commitTime;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int8_t compression;
|
||||
int8_t commitLog;
|
||||
int8_t replications;
|
||||
uint8_t precision; // time resolution
|
||||
int8_t ignoreExist;
|
||||
} SCMCreateDbMsg, SCMAlterDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_ID_LEN + 1];
|
||||
|
@ -605,20 +586,22 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t vgId;
|
||||
int32_t cfgVersion;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables;
|
||||
int64_t maxCacheSize;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t commitTime;
|
||||
uint8_t precision; // time resolution
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t wals;
|
||||
int8_t commitLog;
|
||||
int8_t replications;
|
||||
int8_t wals;
|
||||
int8_t quorum;
|
||||
uint32_t arbitratorIp;
|
||||
int8_t reserved[16];
|
||||
|
@ -653,7 +636,7 @@ typedef struct SCMSTableVgroupMsg {
|
|||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t numOfIps;
|
||||
SIpAddr ipAddr[TSDB_REPLICA_MAX_NUM];
|
||||
SIpAddr ipAddr[TSDB_MAX_REPLICA_NUM];
|
||||
} SCMVgroupInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -697,7 +680,7 @@ typedef struct {
|
|||
} SVnodeDesc;
|
||||
|
||||
typedef struct {
|
||||
SVnodeDesc vpeerDesc[TSDB_REPLICA_MAX_NUM];
|
||||
SVnodeDesc vpeerDesc[TSDB_MAX_REPLICA_NUM];
|
||||
int16_t index; // used locally
|
||||
int32_t vgId;
|
||||
int32_t numOfSids;
|
||||
|
@ -713,8 +696,8 @@ typedef struct {
|
|||
|
||||
typedef struct STableMetaMsg {
|
||||
int32_t contLen;
|
||||
char tableId[TSDB_TABLE_ID_LEN]; // table id
|
||||
char stableId[TSDB_TABLE_ID_LEN]; // stable name if it is created according to super table
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1]; // table id
|
||||
char stableId[TSDB_TABLE_ID_LEN + 1]; // stable name if it is created according to super table
|
||||
uint8_t numOfTags;
|
||||
uint8_t precision;
|
||||
uint8_t tableType;
|
||||
|
@ -775,14 +758,14 @@ typedef struct {
|
|||
} SMDCfgDnodeMsg, SCMCfgDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
char sql[TSDB_SHOW_SQL_LEN + 1];
|
||||
char sql[TSDB_SHOW_SQL_LEN];
|
||||
uint32_t queryId;
|
||||
int64_t useconds;
|
||||
int64_t stime;
|
||||
} SQueryDesc;
|
||||
|
||||
typedef struct {
|
||||
char sql[TSDB_SHOW_SQL_LEN + 1];
|
||||
char sql[TSDB_SHOW_SQL_LEN];
|
||||
uint32_t streamId;
|
||||
int64_t num; // number of computing/cycles
|
||||
int64_t useconds;
|
||||
|
@ -794,12 +777,10 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int32_t numOfQueries;
|
||||
SQueryDesc *qdesc;
|
||||
} SQqueryList;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfStreams;
|
||||
SStreamDesc *sdesc;
|
||||
} SStreamList;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -45,15 +45,19 @@ typedef struct {
|
|||
|
||||
// --------- TSDB REPOSITORY CONFIGURATION DEFINITION
|
||||
typedef struct {
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int32_t tsdbId;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables; // maximum number of tables this repository can have
|
||||
int32_t daysPerFile; // day per file sharding policy
|
||||
int32_t keep; // day of data to keep
|
||||
int32_t keep1;
|
||||
int32_t keep2;
|
||||
int32_t minRowsPerFileBlock; // minimum rows per file block
|
||||
int32_t maxRowsPerFileBlock; // maximum rows per file block
|
||||
int32_t keep; // day of data to keep
|
||||
int64_t maxCacheSize; // maximum cache size this TSDB can use
|
||||
int32_t commitTime;
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
} STsdbCfg;
|
||||
|
||||
void tsdbSetDefaultCfg(STsdbCfg *pCfg);
|
||||
|
@ -98,6 +102,7 @@ int tsdbTableSetSName(STableCfg *config, char *sname, bool dup);
|
|||
void tsdbClearTableCfg(STableCfg *config);
|
||||
|
||||
int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId id, int32_t col, int16_t *type, int16_t *bytes, char **val);
|
||||
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name);
|
||||
|
||||
int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg);
|
||||
int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId);
|
||||
|
@ -146,7 +151,7 @@ typedef struct STsdbQueryCond {
|
|||
STimeWindow twindow;
|
||||
int32_t order; // desc/asc order to iterate the data block
|
||||
int32_t numOfCols;
|
||||
SColumnInfoData *colList;
|
||||
SColumnInfo *colList;
|
||||
} STsdbQueryCond;
|
||||
|
||||
typedef struct SBlockInfo {
|
||||
|
@ -278,8 +283,17 @@ SArray *tsdbGetTableList(TsdbQueryHandleT *pQueryHandle);
|
|||
* @param pTagCond. tag query condition
|
||||
*
|
||||
*/
|
||||
int32_t tsdbQueryByTagsCond(TsdbRepoT *tsdb, int64_t uid, const char *pTagCond, size_t len, STableGroupInfo *pGroupList,
|
||||
SColIndex *pColIndex, int32_t numOfCols);
|
||||
int32_t tsdbQueryByTagsCond(
|
||||
TsdbRepoT *tsdb,
|
||||
int64_t uid,
|
||||
const char *pTagCond,
|
||||
size_t len,
|
||||
int16_t tagNameRelType,
|
||||
const char* tbnameCond,
|
||||
STableGroupInfo *pGroupList,
|
||||
SColIndex *pColIndex,
|
||||
int32_t numOfCols
|
||||
);
|
||||
|
||||
int32_t tsdbGetOneTableGroup(TsdbRepoT *tsdb, int64_t uid, STableGroupInfo *pGroupInfo);
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(shell)
|
||||
#ADD_SUBDIRECTORY(taosdemo)
|
||||
#ADD_SUBDIRECTORY(taosdump)
|
||||
ADD_SUBDIRECTORY(taosdemo)
|
||||
ADD_SUBDIRECTORY(taosdump)
|
||||
|
|
|
@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
#include "taos.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tsclient.h"
|
||||
#include "taosdef.h"
|
||||
#include "tutil.h"
|
||||
|
@ -360,7 +359,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
void taosFreeDbInfos() {
|
||||
if (dbInfos == NULL) return;
|
||||
for (int i = 0; i < tsMaxDbs; i++) tfree(dbInfos[i]);
|
||||
for (int i = 0; i < TSDB_MAX_DBS; i++) tfree(dbInfos[i]);
|
||||
tfree(dbInfos);
|
||||
}
|
||||
|
||||
|
@ -440,7 +439,7 @@ int taosDumpOut(struct arguments *arguments) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbInfos = (SDbInfo **)calloc(tsMaxDbs, sizeof(SDbInfo *));
|
||||
dbInfos = (SDbInfo **)calloc(TSDB_MAX_DBS, sizeof(SDbInfo *));
|
||||
if (dbInfos == NULL) {
|
||||
fprintf(stderr, "failed to allocate memory\n");
|
||||
goto _exit_failure;
|
||||
|
@ -1330,4 +1329,4 @@ _exit_no_charset:
|
|||
*fcharset = '\0';
|
||||
tfree(line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef struct SDnodeObj {
|
|||
int32_t refCount;
|
||||
uint32_t moduleStatus;
|
||||
uint32_t lastReboot; // time stamp for last reboot
|
||||
float score; // calc in balance function
|
||||
float score; // calc in balance function
|
||||
float diskAvailable; // from dnode status msg
|
||||
int16_t diskAvgUsage; // calc from sys.disk
|
||||
int16_t cpuAvgUsage; // calc from sys.cpu
|
||||
|
@ -142,12 +142,32 @@ typedef struct SVgObj {
|
|||
SChildTableObj **tableList;
|
||||
} SVgObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t commitTime;
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t commitLog;
|
||||
int8_t replications;
|
||||
int8_t reserved[16];
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
char name[TSDB_DB_NAME_LEN + 1];
|
||||
int8_t status;
|
||||
char acct[TSDB_USER_LEN + 1];
|
||||
int64_t createdTime;
|
||||
int32_t cfgVersion;
|
||||
SDbCfg cfg;
|
||||
int8_t reserved[15];
|
||||
int8_t status;
|
||||
int8_t reserved[14];
|
||||
int8_t updateEnd[1];
|
||||
int32_t refCount;
|
||||
int32_t numOfVgroups;
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "tlog.h"
|
||||
#include "monitor.h"
|
||||
|
||||
extern int32_t mdebugFlag;
|
||||
extern int32_t sdbDebugFlag;
|
||||
|
@ -41,9 +42,9 @@ extern int32_t sdbDebugFlag;
|
|||
#define mPrint(...) \
|
||||
{ taosPrintLog("MND ", 255, __VA_ARGS__); }
|
||||
|
||||
#define mLError(...) mError(__VA_ARGS__)
|
||||
#define mLWarn(...) mWarn(__VA_ARGS__)
|
||||
#define mLPrint(...) mPrint(__VA_ARGS__)
|
||||
#define mLError(...) monitorSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__)
|
||||
#define mLWarn(...) monitorSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__)
|
||||
#define mLPrint(...) monitorSaveLog(0, __VA_ARGS__); mPrint(__VA_ARGS__)
|
||||
|
||||
#define sdbError(...) \
|
||||
if (sdbDebugFlag & DEBUG_ERROR) { \
|
||||
|
@ -60,9 +61,9 @@ extern int32_t sdbDebugFlag;
|
|||
#define sdbPrint(...) \
|
||||
{ taosPrintLog("MND-SDB ", 255, __VA_ARGS__); }
|
||||
|
||||
#define sdbLError(...) sdbError(__VA_ARGS__)
|
||||
#define sdbLWarn(...) sdbWarn(__VA_ARGS__)
|
||||
#define sdbLPrint(...) sdbPrint(__VA_ARGS__)
|
||||
#define sdbLError(...) monitorSaveLog(2, __VA_ARGS__); sdbError(__VA_ARGS__)
|
||||
#define sdbLWarn(...) monitorSaveLog(1, __VA_ARGS__); sdbWarn(__VA_ARGS__)
|
||||
#define sdbLPrint(...) monitorSaveLog(0, __VA_ARGS__); sdbPrint(__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ static void mgmtProcessRspFromDnode(SRpcMsg *rpcMsg) {
|
|||
if (mgmtProcessDnodeRspFp[rpcMsg->msgType]) {
|
||||
(*mgmtProcessDnodeRspFp[rpcMsg->msgType])(rpcMsg);
|
||||
} else {
|
||||
mError("%s is not processed in dclient", taosMsg[rpcMsg->msgType]);
|
||||
mError("%s is not processed in mgmt dclient", taosMsg[rpcMsg->msgType]);
|
||||
SRpcMsg rpcRsp = {.pCont = 0, .contLen = 0, .code = TSDB_CODE_OPS_NOT_SUPPORT, .handle = rpcMsg->handle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
|
|
|
@ -108,8 +108,12 @@ static void mgmtProcessMsgFromDnode(SRpcMsg *rpcMsg) {
|
|||
bool usePublicIp = false;
|
||||
|
||||
SRpcIpSet ipSet = {0};
|
||||
mgmtGetMnodeIpSet(&ipSet, usePublicIp);
|
||||
mTrace("conn from dnode ip:%s redirect msg", taosIpStr(connInfo.clientIp));
|
||||
ipSet.port = tsMnodeDnodePort;
|
||||
dnodeGetMnodeIpSet(&ipSet, usePublicIp);
|
||||
mTrace("conn from dnode ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse);
|
||||
for (int32_t i = 0; i < ipSet.numOfIps; ++i) {
|
||||
mTrace("index:%d ip:%s", i, taosIpStr(ipSet.ip[i]));
|
||||
}
|
||||
rpcSendRedirectRsp(rpcMsg->handle, &ipSet);
|
||||
return;
|
||||
}
|
||||
|
@ -119,7 +123,8 @@ static void mgmtProcessMsgFromDnode(SRpcMsg *rpcMsg) {
|
|||
memcpy(pMsg, rpcMsg, sizeof(SRpcMsg));
|
||||
mgmtAddToDServerQueue(pMsg);
|
||||
} else {
|
||||
mError("%s is not processed in dserver", taosMsg[rpcMsg->msgType]);
|
||||
mError("%s is not processed in mgmt dserver", taosMsg[rpcMsg->msgType]);
|
||||
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#include "taoserror.h"
|
||||
#include "tutil.h"
|
||||
#include "tgrant.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
#include "tname.h"
|
||||
#include "tbalance.h"
|
||||
#include "mgmtDef.h"
|
||||
#include "mgmtLog.h"
|
||||
#include "mgmtAcct.h"
|
||||
|
@ -53,7 +55,7 @@ static int32_t mgmtDbActionDestroy(SSdbOper *pOper) {
|
|||
|
||||
static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
|
||||
SDbObj *pDb = pOper->pObj;
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
|
||||
pDb->pHead = NULL;
|
||||
pDb->pTail = NULL;
|
||||
|
@ -66,7 +68,7 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
|
|||
mgmtDecAcctRef(pAcct);
|
||||
}
|
||||
else {
|
||||
mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->cfg.acct);
|
||||
mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct);
|
||||
return TSDB_CODE_INVALID_ACCT;
|
||||
}
|
||||
|
||||
|
@ -75,7 +77,7 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) {
|
|||
|
||||
static int32_t mgmtDbActionDelete(SSdbOper *pOper) {
|
||||
SDbObj *pDb = pOper->pObj;
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
|
||||
mgmtDropDbFromAcct(pAcct, pDb);
|
||||
mgmtDropAllChildTables(pDb);
|
||||
|
@ -175,156 +177,156 @@ SDbObj *mgmtGetDbByTableId(char *tableId) {
|
|||
return (SDbObj *)sdbGetRow(tsDbSdb, db);
|
||||
}
|
||||
|
||||
static int32_t mgmtCheckDBParams(SCMCreateDbMsg *pCreate) {
|
||||
if (pCreate->commitLog < 0 || pCreate->commitLog > 2) {
|
||||
mError("invalid db option commitLog: %d, only 0-2 allowed", pCreate->commitLog);
|
||||
static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) {
|
||||
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||
mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE,
|
||||
TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) {
|
||||
mError("invalid db option totalBlocks:%d valid range: [%d, %d]", pCfg->totalBlocks, TSDB_MIN_TOTAL_BLOCKS,
|
||||
TSDB_MAX_TOTAL_BLOCKS);
|
||||
}
|
||||
|
||||
if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) {
|
||||
mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES, TSDB_MAX_TABLES);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) {
|
||||
mError("invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM,
|
||||
TSDB_REPLICA_MAX_NUM);
|
||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) {
|
||||
mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE,
|
||||
TSDB_MAX_DAYS_PER_FILE);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) {
|
||||
mError("invalid db option daysPerFile: %d valid range: [%d, %d]", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE,
|
||||
TSDB_FILE_MAX_PARTITION_RANGE);
|
||||
if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) {
|
||||
mError("invalid db option daysToKeep:%d", pCfg->daysToKeep);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) {
|
||||
mError("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1,
|
||||
pCreate->daysToKeep2, pCreate->daysToKeep);
|
||||
if (pCfg->daysToKeep < pCfg->daysPerFile) {
|
||||
mError("invalid db option daysToKeep:%d daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) {
|
||||
mError("invalid db option daystokeep: %d", pCreate->daysToKeep);
|
||||
if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) {
|
||||
mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock,
|
||||
TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) {
|
||||
mError("invalid db option rowsInFileBlock: %d valid range: [%d, %d]", pCreate->rowsInFileBlock,
|
||||
TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK);
|
||||
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) {
|
||||
mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock,
|
||||
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||
mError("invalid db option cacheBlockSize: %d valid range: [%d, %d]", pCreate->cacheBlockSize,
|
||||
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||
if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) {
|
||||
mError("invalid db option minRowsPerFileBlock:%d maxRowsPerFileBlock:%d", pCfg->minRowsPerFileBlock,
|
||||
pCfg->maxRowsPerFileBlock);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) {
|
||||
mError("invalid db option maxSessions: %d valid range: [%d, %d]", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE,
|
||||
TSDB_MAX_TABLES_PER_VNODE);
|
||||
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) {
|
||||
mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME,
|
||||
TSDB_MAX_COMMIT_TIME);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) {
|
||||
mError("invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI,
|
||||
TSDB_TIME_PRECISION_MICRO);
|
||||
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) {
|
||||
mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_MIN_PRECISION,
|
||||
TSDB_MAX_PRECISION);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) {
|
||||
mError("invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, 0, TSDB_MAX_AVG_BLOCKS);
|
||||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) {
|
||||
mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMP_LEVEL,
|
||||
TSDB_MAX_COMP_LEVEL);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) {
|
||||
mError("invalid db option commitTime: %d valid range: [%d, %d]", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL,
|
||||
TSDB_MAX_COMMIT_TIME_INTERVAL);
|
||||
if (pCfg->commitLog < TSDB_MIN_CLOG_LEVEL || pCfg->commitLog > TSDB_MAX_CLOG_LEVEL) {
|
||||
mError("invalid db option commitLog:%d, only 0-2 allowed", pCfg->commitLog);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) {
|
||||
mError("invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL,
|
||||
TSDB_MAX_COMPRESSION_LEVEL);
|
||||
if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) {
|
||||
mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM,
|
||||
TSDB_MAX_REPLICA_NUM);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mgmtCheckDbParams(SCMCreateDbMsg *pCreate) {
|
||||
// assign default parameters
|
||||
if (pCreate->maxSessions < 0) pCreate->maxSessions = tsSessionsPerVnode;
|
||||
if (pCreate->cacheBlockSize < 0) pCreate->cacheBlockSize = tsCacheBlockSize;
|
||||
if (pCreate->daysPerFile < 0) pCreate->daysPerFile = tsDaysPerFile;
|
||||
if (pCreate->daysToKeep < 0) pCreate->daysToKeep = tsDaysToKeep;
|
||||
if (pCreate->daysToKeep1 < 0) pCreate->daysToKeep1 = pCreate->daysToKeep;
|
||||
if (pCreate->daysToKeep2 < 0) pCreate->daysToKeep2 = pCreate->daysToKeep;
|
||||
if (pCreate->commitTime < 0) pCreate->commitTime = tsCommitTime;
|
||||
if (pCreate->compression < 0) pCreate->compression = tsCompression;
|
||||
if (pCreate->commitLog < 0) pCreate->commitLog = tsCommitLog;
|
||||
if (pCreate->replications < 0) pCreate->replications = tsReplications; //
|
||||
if (pCreate->rowsInFileBlock < 0) pCreate->rowsInFileBlock = tsRowsInFileBlock; //
|
||||
if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; //
|
||||
|
||||
if (mgmtCheckDBParams(pCreate) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions);
|
||||
|
||||
if (pCreate->cacheNumOfBlocks.totalBlocks > TSDB_MAX_CACHE_BLOCKS) {
|
||||
mTrace("invalid db option cacheNumOfBlocks: %d valid range: [%d, %d]", pCreate->cacheNumOfBlocks.totalBlocks,
|
||||
TSDB_MIN_CACHE_BLOCKS, TSDB_MAX_CACHE_BLOCKS);
|
||||
return TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
|
||||
// calculate the blocks per table
|
||||
if (pCreate->blocksPerTable < 0) {
|
||||
pCreate->blocksPerTable = pCreate->cacheNumOfBlocks.totalBlocks / 4;
|
||||
}
|
||||
|
||||
if (pCreate->blocksPerTable > pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4) {
|
||||
pCreate->blocksPerTable = pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4;
|
||||
}
|
||||
|
||||
if (pCreate->blocksPerTable < TSDB_MIN_AVG_BLOCKS) {
|
||||
pCreate->blocksPerTable = TSDB_MIN_AVG_BLOCKS;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) {
|
||||
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = tsCacheBlockSize;
|
||||
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = tsTotalBlocks;
|
||||
if (pCfg->maxTables < 0) pCfg->maxTables = tsTablesPerVnode;
|
||||
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = tsDaysPerFile;
|
||||
if (pCfg->daysToKeep < 0) pCfg->daysToKeep = tsDaysToKeep;
|
||||
if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep;
|
||||
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep;
|
||||
if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock;
|
||||
if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock;
|
||||
if (pCfg->commitTime < 0) pCfg->commitTime = tsCommitTime;
|
||||
if (pCfg->precision < 0) pCfg->precision = tsTimePrecision;
|
||||
if (pCfg->compression < 0) pCfg->compression = tsCompression;
|
||||
if (pCfg->commitLog < 0) pCfg->commitLog = tsCommitLog;
|
||||
if (pCfg->replications < 0) pCfg->replications = tsReplications;
|
||||
}
|
||||
|
||||
static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
|
||||
int32_t code = acctCheck(pAcct, ACCT_GRANT_DB);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
if (code != 0) return code;
|
||||
|
||||
SDbObj *pDb = mgmtGetDb(pCreate->db);
|
||||
if (pDb != NULL) {
|
||||
mgmtDecDbRef(pDb);
|
||||
return TSDB_CODE_DB_ALREADY_EXIST;
|
||||
mgmtDecDbRef(pDb);
|
||||
if (pCreate->ignoreExist) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
return TSDB_CODE_DB_ALREADY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
code = mgmtCheckDbParams(pCreate);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
|
||||
assert(pCreate->daysToKeep1 <= pCreate->daysToKeep2 && pCreate->daysToKeep2 <= pCreate->daysToKeep);
|
||||
|
||||
code = grantCheck(TSDB_GRANT_DB);
|
||||
if (code != 0) {
|
||||
if (code != 0) return code;
|
||||
|
||||
pDb = calloc(1, sizeof(SDbObj));
|
||||
strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN);
|
||||
strncpy(pDb->acct, pAcct->user, TSDB_USER_LEN);
|
||||
pDb->createdTime = taosGetTimestampMs();
|
||||
pDb->cfg = (SDbCfg) {
|
||||
.cacheBlockSize = pCreate->cacheBlockSize,
|
||||
.totalBlocks = pCreate->totalBlocks,
|
||||
.maxTables = pCreate->maxSessions,
|
||||
.daysPerFile = pCreate->daysPerFile,
|
||||
.daysToKeep = pCreate->daysToKeep,
|
||||
.daysToKeep1 = pCreate->daysToKeep1,
|
||||
.daysToKeep2 = pCreate->daysToKeep2,
|
||||
.minRowsPerFileBlock = pCreate->maxRowsPerFileBlock,
|
||||
.maxRowsPerFileBlock = pCreate->maxRowsPerFileBlock,
|
||||
.commitTime = pCreate->commitTime,
|
||||
.precision = pCreate->precision,
|
||||
.compression = pCreate->compression,
|
||||
.commitLog = pCreate->commitLog,
|
||||
.replications = pCreate->replications
|
||||
};
|
||||
|
||||
mgmtSetDefaultDbCfg(&pDb->cfg);
|
||||
|
||||
code = mgmtCheckDbCfg(&pDb->cfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tfree(pDb);
|
||||
return code;
|
||||
}
|
||||
|
||||
pDb = malloc(sizeof(SDbObj));
|
||||
memset(pDb, 0, sizeof(SDbObj));
|
||||
strcpy(pDb->name, pCreate->db);
|
||||
strcpy(pCreate->acct, pAcct->user);
|
||||
pDb->createdTime = taosGetTimestampMs();
|
||||
pDb->cfg = *pCreate;
|
||||
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsDbSdb,
|
||||
.pObj = pDb,
|
||||
.rowSize = sizeof(SDbObj)
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsDbSdb,
|
||||
.pObj = pDb,
|
||||
.rowSize = sizeof(SDbObj),
|
||||
};
|
||||
|
||||
code = sdbInsertRow(&oper);
|
||||
|
@ -463,25 +465,25 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
|
|||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "rows");
|
||||
strcpy(pSchema[cols].name, "cache(MB)");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "blocks");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "minrows");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "cache(b)");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_FLOAT;
|
||||
strcpy(pSchema[cols].name, "ablocks");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "tblocks");
|
||||
strcpy(pSchema[cols].name, "maxrows");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
|
@ -508,7 +510,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
|
|||
|
||||
pShow->bytes[cols] = 3;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "time precision");
|
||||
strcpy(pSchema[cols].name, "precision");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
|
@ -596,11 +598,7 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
|
|||
if (strcmp(pUser->user, "root") == 0) {
|
||||
#endif
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.maxSessions; // table num can be created should minus 1
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.rowsInFileBlock;
|
||||
*(int32_t *)pWrite = pDb->cfg.maxTables; // table num can be created should minus 1
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
@ -608,17 +606,17 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
#ifdef _TD_ARM_32_
|
||||
*(int32_t *)pWrite = (pDb->cfg.cacheNumOfBlocks.totalBlocks * 1.0 / (pDb->cfg.maxSessions));
|
||||
#else
|
||||
*(float *)pWrite = (pDb->cfg.cacheNumOfBlocks.totalBlocks * 1.0 / (pDb->cfg.maxSessions));
|
||||
#endif
|
||||
*(int32_t *)pWrite = pDb->cfg.totalBlocks;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pDb->cfg.blocksPerTable;
|
||||
*(int32_t *)pWrite = pDb->cfg.minRowsPerFileBlock;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.maxRowsPerFileBlock;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.commitTime;
|
||||
cols++;
|
||||
|
@ -692,14 +690,15 @@ static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg) {
|
|||
SCMCreateDbMsg *pCreate = pMsg->pCont;
|
||||
pCreate->maxSessions = htonl(pCreate->maxSessions);
|
||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
|
||||
pCreate->daysToKeep = htonl(pCreate->daysToKeep);
|
||||
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
||||
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
||||
pCreate->commitTime = htonl(pCreate->commitTime);
|
||||
pCreate->blocksPerTable = htons(pCreate->blocksPerTable);
|
||||
pCreate->rowsInFileBlock = htonl(pCreate->rowsInFileBlock);
|
||||
|
||||
pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
|
||||
pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
|
||||
|
||||
int32_t code;
|
||||
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_GRANT_EXPIRED;
|
||||
|
@ -716,37 +715,66 @@ static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg) {
|
|||
}
|
||||
|
||||
static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
||||
SDbCfg newCfg = pDb->cfg;
|
||||
int32_t daysToKeep = htonl(pAlter->daysToKeep);
|
||||
int32_t maxSessions = htonl(pAlter->maxSessions);
|
||||
SDbCfg newCfg = pDb->cfg;
|
||||
int32_t cacheBlockSize = htonl(pAlter->daysToKeep);
|
||||
int32_t totalBlocks = htonl(pAlter->totalBlocks);
|
||||
int32_t maxTables = htonl(pAlter->maxSessions);
|
||||
int32_t daysToKeep = htonl(pAlter->daysToKeep);
|
||||
int32_t daysToKeep1 = htonl(pAlter->daysToKeep1);
|
||||
int32_t daysToKeep2 = htonl(pAlter->daysToKeep2);
|
||||
int8_t compression = pAlter->compression;
|
||||
int8_t replications = pAlter->replications;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) {
|
||||
mTrace("db:%s, cache:%d change to %d", pDb->name, pDb->cfg.cacheBlockSize, cacheBlockSize);
|
||||
newCfg.cacheBlockSize = cacheBlockSize;
|
||||
}
|
||||
|
||||
if (totalBlocks > 0 && totalBlocks != pDb->cfg.totalBlocks) {
|
||||
mTrace("db:%s, blocks:%d change to %d", pDb->name, pDb->cfg.totalBlocks, totalBlocks);
|
||||
newCfg.totalBlocks = totalBlocks;
|
||||
}
|
||||
|
||||
if (maxTables > 0 && maxTables != pDb->cfg.maxTables) {
|
||||
mTrace("db:%s, tables:%d change to %d", pDb->name, pDb->cfg.maxTables, maxTables);
|
||||
newCfg.maxTables = maxTables;
|
||||
if (newCfg.maxTables < pDb->cfg.maxTables) {
|
||||
mTrace("db:%s, tables:%d should larger than origin:%d", pDb->name, newCfg.maxTables, pDb->cfg.maxTables);
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
}
|
||||
|
||||
if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) {
|
||||
mTrace("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep, daysToKeep);
|
||||
newCfg.daysToKeep = daysToKeep;
|
||||
} else if (replications > 0 && replications != pDb->cfg.replications) {
|
||||
mTrace("db:%s, replica:%d change to %d", pDb->name, pDb->cfg.replications, replications);
|
||||
if (replications < TSDB_REPLICA_MIN_NUM || replications > TSDB_REPLICA_MAX_NUM) {
|
||||
mError("invalid db option replica: %d valid range: %d--%d", replications, TSDB_REPLICA_MIN_NUM, TSDB_REPLICA_MAX_NUM);
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
newCfg.replications = replications;
|
||||
} else if (maxSessions > 0 && maxSessions != pDb->cfg.maxSessions) {
|
||||
mTrace("db:%s, tables:%d change to %d", pDb->name, pDb->cfg.maxSessions, maxSessions);
|
||||
if (maxSessions < TSDB_MIN_TABLES_PER_VNODE || maxSessions > TSDB_MAX_TABLES_PER_VNODE) {
|
||||
mError("invalid db option tables: %d valid range: %d--%d", maxSessions, TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE);
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
if (maxSessions < pDb->cfg.maxSessions) {
|
||||
mError("invalid db option tables: %d should larger than original:%d", maxSessions, pDb->cfg.maxSessions);
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
}
|
||||
newCfg.maxSessions = maxSessions;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (daysToKeep1 > 0 && daysToKeep1 != pDb->cfg.daysToKeep1) {
|
||||
mTrace("db:%s, daysToKeep1:%d change to %d", pDb->name, pDb->cfg.daysToKeep1, daysToKeep1);
|
||||
newCfg.daysToKeep1 = daysToKeep1;
|
||||
}
|
||||
|
||||
if (daysToKeep2 > 0 && daysToKeep2 != pDb->cfg.daysToKeep2) {
|
||||
mTrace("db:%s, daysToKeep2:%d change to %d", pDb->name, pDb->cfg.daysToKeep2, daysToKeep2);
|
||||
newCfg.daysToKeep2 = daysToKeep2;
|
||||
}
|
||||
|
||||
if (compression > 0 && compression != pDb->cfg.compression) {
|
||||
mTrace("db:%s, compression:%d change to %d", pDb->name, pDb->cfg.compression, compression);
|
||||
newCfg.compression = compression;
|
||||
}
|
||||
|
||||
if (replications > 0 && replications != pDb->cfg.replications) {
|
||||
mTrace("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications);
|
||||
newCfg.replications = replications;
|
||||
}
|
||||
if (replications > mgmtGetDnodesNum()) {
|
||||
mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications);
|
||||
terrno = TSDB_CODE_NO_ENOUGH_DNODES;
|
||||
}
|
||||
|
||||
return newCfg;
|
||||
}
|
||||
|
||||
|
@ -756,8 +784,16 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
int32_t code = mgmtCheckDbCfg(&newCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t oldReplica = pDb->cfg.replications;
|
||||
|
||||
if (memcmp(&newCfg, &pDb->cfg, sizeof(SDbCfg)) != 0) {
|
||||
pDb->cfg = newCfg;
|
||||
pDb->cfgVersion++;
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsDbSdb,
|
||||
|
@ -770,7 +806,20 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *pNode = NULL;
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pNode = mgmtGetNextVgroup(pNode, &pVgroup);
|
||||
if (pVgroup == NULL) break;
|
||||
mgmtSendCreateVgroupMsg(pVgroup, NULL);
|
||||
mgmtDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
if (oldReplica != pDb->cfg.replications) {
|
||||
balanceNotify();
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -798,16 +847,6 @@ static void mgmtProcessAlterDbMsg(SQueuedMsg *pMsg) {
|
|||
return;
|
||||
}
|
||||
|
||||
SVgObj *pVgroup = pDb->pHead;
|
||||
if (pVgroup != NULL) {
|
||||
mPrint("vgroup:%d, will be altered", pVgroup->vgId);
|
||||
SQueuedMsg *newMsg = mgmtCloneQueuedMsg(pMsg);
|
||||
newMsg->ahandle = pVgroup;
|
||||
newMsg->expected = pVgroup->numOfVnodes;
|
||||
mgmtAlterVgroup(pVgroup, newMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
mTrace("db:%s, all vgroups is altered", pDb->name);
|
||||
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
@ -884,6 +923,8 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
|
|||
SDbObj *pDb = NULL;
|
||||
void * pNode = NULL;
|
||||
|
||||
mPrint("acct:%s, all dbs will be dropped from sdb", pAcct->user);
|
||||
|
||||
while (1) {
|
||||
pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb);
|
||||
if (pDb == NULL) break;
|
||||
|
@ -902,5 +943,5 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
|
|||
mgmtDecDbRef(pDb);
|
||||
}
|
||||
|
||||
mTrace("acct:%s, all dbs is is dropped from sdb", pAcct->user, numOfDbs);
|
||||
mPrint("acct:%s, all dbs:%d is dropped from sdb", pAcct->user, numOfDbs);
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg) {
|
|||
}
|
||||
uint32_t dnodeIp = inet_addr(pCmCfgDnode->ip);
|
||||
|
||||
if (strcmp(pMsg->pUser->pAcct->user, "root") != 0) {
|
||||
if (strcmp(pMsg->pUser->user, "root") != 0) {
|
||||
rpcRsp.code = TSDB_CODE_NO_RIGHTS;
|
||||
} else {
|
||||
SRpcIpSet ipSet = mgmtGetIpSetFromIp(dnodeIp);
|
||||
|
@ -343,6 +343,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
|
|||
for (int32_t j = 0; j < openVnodes; ++j) {
|
||||
SVnodeLoad *pVload = &pStatus->load[j];
|
||||
pVload->vgId = htonl(pVload->vgId);
|
||||
pVload->cfgVersion = htonl(pVload->cfgVersion);
|
||||
|
||||
SVgObj *pVgroup = mgmtGetVgroup(pVload->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
|
@ -469,7 +470,7 @@ static void mgmtProcessCreateDnodeMsg(SQueuedMsg *pMsg) {
|
|||
|
||||
SCMCreateDnodeMsg *pCreate = pMsg->pCont;
|
||||
|
||||
if (strcmp(pMsg->pUser->pAcct->user, "root") != 0) {
|
||||
if (strcmp(pMsg->pUser->user, "root") != 0) {
|
||||
rpcRsp.code = TSDB_CODE_NO_RIGHTS;
|
||||
} else {
|
||||
uint32_t ip = inet_addr(pCreate->ip);
|
||||
|
@ -489,7 +490,7 @@ static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg) {
|
|||
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
|
||||
|
||||
SCMDropDnodeMsg *pDrop = pMsg->pCont;
|
||||
if (strcmp(pMsg->pUser->pAcct->user, "root") != 0) {
|
||||
if (strcmp(pMsg->pUser->user, "root") != 0) {
|
||||
rpcRsp.code = TSDB_CODE_NO_RIGHTS;
|
||||
} else {
|
||||
uint32_t ip = inet_addr(pDrop->ip);
|
||||
|
|
|
@ -400,6 +400,8 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
|
|||
|
||||
if (pTable->keyType == SDB_KEY_AUTO) {
|
||||
pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pOper->pObj));
|
||||
} else {
|
||||
pTable->autoIndex++;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pTable->mutex);
|
||||
|
|
|
@ -151,8 +151,13 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
|
|||
bool usePublicIp = (connInfo.serverIp == tsPublicIpInt);
|
||||
|
||||
SRpcIpSet ipSet = {0};
|
||||
mgmtGetMnodeIpSet(&ipSet, usePublicIp);
|
||||
mTrace("conn from ip:%s user:%s redirect msg", taosIpStr(connInfo.clientIp), connInfo.user);
|
||||
ipSet.port = tsMnodeShellPort;
|
||||
dnodeGetMnodeIpSet(&ipSet, usePublicIp);
|
||||
mTrace("conn from shell ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse);
|
||||
for (int32_t i = 0; i < ipSet.numOfIps; ++i) {
|
||||
mTrace("index:%d ip:%s", i, taosIpStr(ipSet.ip[i]));
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(rpcMsg->handle, &ipSet);
|
||||
return;
|
||||
}
|
||||
|
@ -359,7 +364,7 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
*spi = 0;
|
||||
*spi = 1;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
|
||||
|
@ -429,9 +434,9 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
|
|||
connect_over:
|
||||
rpcRsp.code = code;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mLError("user:%s login from %s, code:%d", connInfo.user, taosIpStr(connInfo.clientIp), code);
|
||||
mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
||||
} else {
|
||||
mLPrint("user:%s login from %s, code:%d", connInfo.user, taosIpStr(connInfo.clientIp), code);
|
||||
mLPrint("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code));
|
||||
rpcRsp.pCont = pConnectRsp;
|
||||
rpcRsp.contLen = sizeof(SCMConnectRsp);
|
||||
}
|
||||
|
@ -488,7 +493,7 @@ static bool mgmtCheckMsgReadOnly(SQueuedMsg *pMsg) {
|
|||
}
|
||||
|
||||
static void mgmtProcessUnSupportMsg(SRpcMsg *rpcMsg) {
|
||||
mError("%s is not processed in shell", taosMsg[rpcMsg->msgType]);
|
||||
mError("%s is not processed in mnode shell", taosMsg[rpcMsg->msgType]);
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = 0,
|
||||
.pCont = 0,
|
||||
|
|
|
@ -78,6 +78,8 @@ static void mgmtGetChildTableMeta(SQueuedMsg *pMsg);
|
|||
static void mgmtProcessAlterTableMsg(SQueuedMsg *queueMsg);
|
||||
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg);
|
||||
|
||||
static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName);
|
||||
|
||||
static void mgmtDestroyChildTable(SChildTableObj *pTable) {
|
||||
tfree(pTable->schema);
|
||||
tfree(pTable->sql);
|
||||
|
@ -106,9 +108,9 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) {
|
|||
}
|
||||
mgmtDecDbRef(pDb);
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct == NULL) {
|
||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->cfg.acct);
|
||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
|
||||
return TSDB_CODE_INVALID_ACCT;
|
||||
}
|
||||
mgmtDecAcctRef(pAcct);
|
||||
|
@ -148,9 +150,9 @@ static int32_t mgmtChildTableActionDelete(SSdbOper *pOper) {
|
|||
}
|
||||
mgmtDecDbRef(pDb);
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct == NULL) {
|
||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->cfg.acct);
|
||||
mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct);
|
||||
return TSDB_CODE_INVALID_ACCT;
|
||||
}
|
||||
mgmtDecAcctRef(pAcct);
|
||||
|
@ -364,7 +366,7 @@ static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCta
|
|||
|
||||
bool find = false;
|
||||
int32_t pos = 0;
|
||||
for (int pos = 0; pos < pStable->vgLen; ++pos) {
|
||||
for (pos = 0; pos < pStable->vgLen; ++pos) {
|
||||
if (pStable->vgList[pos] == 0) break;
|
||||
if (pStable->vgList[pos] == pCtable->vgId) {
|
||||
find = true;
|
||||
|
@ -730,6 +732,9 @@ static void mgmtProcessCreateSuperTableMsg(SQueuedMsg *pMsg) {
|
|||
SSchema *tschema = pStable->schema;
|
||||
tschema[col].colId = pStable->nextColId++;
|
||||
tschema[col].bytes = htons(tschema[col].bytes);
|
||||
|
||||
// todo 1. check the length of each column; 2. check the total length of all columns
|
||||
assert(tschema[col].type >= TSDB_DATA_TYPE_BOOL && tschema[col].type <= TSDB_DATA_TYPE_NCHAR);
|
||||
}
|
||||
|
||||
SSdbOper oper = {
|
||||
|
@ -753,8 +758,26 @@ static void mgmtProcessCreateSuperTableMsg(SQueuedMsg *pMsg) {
|
|||
static void mgmtProcessDropSuperTableMsg(SQueuedMsg *pMsg) {
|
||||
SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable;
|
||||
if (pStable->numOfTables != 0) {
|
||||
mError("stable:%s, numOfTables:%d not 0", pStable->info.tableId, pStable->numOfTables);
|
||||
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_OTHERS);
|
||||
mgmtDropAllChildTablesInStable(pStable);
|
||||
for (int32_t vg = 0; vg < pStable->vgLen; ++vg) {
|
||||
int32_t vgId = pStable->vgList[vg];
|
||||
if (vgId == 0) break;
|
||||
|
||||
SMDDropSTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropSTableMsg));
|
||||
pDrop->vgId = htonl(vgId);
|
||||
pDrop->uid = htobe64(pStable->uid);
|
||||
mgmtExtractTableName(pStable->info.tableId, pDrop->tableId);
|
||||
|
||||
SVgObj *pVgroup = mgmtGetVgroup(vgId);
|
||||
if (pVgroup != NULL) {
|
||||
SRpcIpSet ipSet = mgmtGetIpSetFromVgroup(pVgroup);
|
||||
SRpcMsg rpcMsg = {.pCont = pDrop, .contLen = sizeof(SMDDropSTableMsg), .msgType = TSDB_MSG_TYPE_MD_DROP_STABLE};
|
||||
mgmtSendMsgToDnode(&ipSet, &rpcMsg);
|
||||
mgmtDecVgroupRef(pVgroup);
|
||||
}
|
||||
}
|
||||
//mError("stable:%s, numOfTables:%d not 0", pStable->info.tableId, pStable->numOfTables);
|
||||
//mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_OTHERS);
|
||||
} else {
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
|
@ -780,31 +803,33 @@ static int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *t
|
|||
|
||||
static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) {
|
||||
if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
mError("stable:%s, add tag, too many tags", pStable->info.tableId);
|
||||
return TSDB_CODE_TOO_MANY_TAGS;
|
||||
}
|
||||
|
||||
// check if schemas have the same name
|
||||
for (int32_t i = 1; i < ntags; i++) {
|
||||
for (int32_t j = 0; j < i; j++) {
|
||||
if (strcasecmp(schema[i].name, schema[j].name) == 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
for (int32_t i = 0; i < ntags; i++) {
|
||||
if (mgmtFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
|
||||
mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name);
|
||||
return TSDB_CODE_TAG_ALREAY_EXIST;
|
||||
}
|
||||
|
||||
if (mgmtFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
|
||||
mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name);
|
||||
return TSDB_CODE_FIELD_ALREAY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
|
||||
pStable->schema = realloc(pStable->schema, schemaSize + sizeof(SSchema) * ntags);
|
||||
|
||||
memmove(pStable->schema + sizeof(SSchema) * (pStable->numOfColumns + ntags),
|
||||
pStable->schema + sizeof(SSchema) * pStable->numOfColumns, sizeof(SSchema) * pStable->numOfTags);
|
||||
memcpy(pStable->schema + sizeof(SSchema) * pStable->numOfColumns, schema, sizeof(SSchema) * ntags);
|
||||
memcpy(pStable->schema + pStable->numOfColumns + pStable->numOfTags, schema, sizeof(SSchema) * ntags);
|
||||
|
||||
SSchema *tschema = (SSchema *) (pStable->schema + sizeof(SSchema) * pStable->numOfColumns);
|
||||
SSchema *tschema = (SSchema *)(pStable->schema + pStable->numOfColumns + pStable->numOfTags);
|
||||
for (int32_t i = 0; i < ntags; i++) {
|
||||
tschema[i].colId = pStable->nextColId++;
|
||||
}
|
||||
|
||||
pStable->numOfColumns += ntags;
|
||||
pStable->numOfTags += ntags;
|
||||
pStable->sversion++;
|
||||
|
||||
SSdbOper oper = {
|
||||
|
@ -819,25 +844,22 @@ static int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], i
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to add tag %s", pStable->info.tableId, schema[0].name);
|
||||
mPrint("stable %s, succeed to add tag %s", pStable->info.tableId, schema[0].name);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
|
||||
int32_t col = mgmtFindSuperTableTagIndex(pStable, tagName);
|
||||
if (col <= 0 || col >= pStable->numOfTags) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
if (col < 0) {
|
||||
mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName);
|
||||
return TSDB_CODE_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
memmove(pStable->schema + sizeof(SSchema) * col, pStable->schema + sizeof(SSchema) * (col + 1),
|
||||
sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags - col - 1));
|
||||
|
||||
memmove(pStable->schema + pStable->numOfColumns + col, pStable->schema + pStable->numOfColumns + col + 1,
|
||||
sizeof(SSchema) * (pStable->numOfTags - col - 1));
|
||||
pStable->numOfTags--;
|
||||
pStable->sversion++;
|
||||
|
||||
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
|
||||
pStable->schema = realloc(pStable->schema, schemaSize);
|
||||
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsSuperTableSdb,
|
||||
|
@ -850,27 +872,29 @@ static int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to drop tag %s", pStable->info.tableId, tagName);
|
||||
mPrint("stable %s, succeed to drop tag %s", pStable->info.tableId, tagName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTagName, char *newTagName) {
|
||||
int32_t col = mgmtFindSuperTableTagIndex(pStable, oldTagName);
|
||||
if (col < 0) {
|
||||
// Tag name does not exist
|
||||
mError("table:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName);
|
||||
return TSDB_CODE_INVALID_MSG_TYPE;
|
||||
mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName);
|
||||
return TSDB_CODE_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
// int32_t rowSize = 0;
|
||||
uint32_t len = strlen(newTagName);
|
||||
if (len >= TSDB_COL_NAME_LEN) {
|
||||
return TSDB_CODE_COL_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
if (col >= pStable->numOfTags || len >= TSDB_COL_NAME_LEN || mgmtFindSuperTableTagIndex(pStable, newTagName) >= 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
if (mgmtFindSuperTableTagIndex(pStable, newTagName) >= 0) {
|
||||
return TSDB_CODE_TAG_ALREAY_EXIST;
|
||||
}
|
||||
|
||||
// update
|
||||
SSchema *schema = (SSchema *) (pStable->schema + (pStable->numOfColumns + col) * sizeof(SSchema));
|
||||
SSchema *schema = (SSchema *) (pStable->schema + pStable->numOfColumns + col);
|
||||
strncpy(schema->name, newTagName, TSDB_COL_NAME_LEN);
|
||||
|
||||
SSdbOper oper = {
|
||||
|
@ -885,15 +909,15 @@ static int32_t mgmtModifySuperTableTagName(SSuperTableObj *pStable, char *oldTag
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName);
|
||||
mPrint("stable %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName) {
|
||||
SSchema *schema = (SSchema *) pStable->schema;
|
||||
for (int32_t i = 0; i < pStable->numOfColumns; i++) {
|
||||
if (strcasecmp(schema[i].name, colName) == 0) {
|
||||
return i;
|
||||
for (int32_t col = 0; col < pStable->numOfColumns; col++) {
|
||||
if (strcasecmp(schema[col].name, colName) == 0) {
|
||||
return col;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,21 +926,28 @@ static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colN
|
|||
|
||||
static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) {
|
||||
if (ncols <= 0) {
|
||||
mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ncols; i++) {
|
||||
if (mgmtFindSuperTableColumnIndex(pStable, schema[i].name) > 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name);
|
||||
return TSDB_CODE_FIELD_ALREAY_EXIST;
|
||||
}
|
||||
|
||||
if (mgmtFindSuperTableTagIndex(pStable, schema[i].name) > 0) {
|
||||
mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name);
|
||||
return TSDB_CODE_TAG_ALREAY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
|
||||
pStable->schema = realloc(pStable->schema, schemaSize + sizeof(SSchema) * ncols);
|
||||
|
||||
memmove(pStable->schema + sizeof(SSchema) * (pStable->numOfColumns + ncols),
|
||||
pStable->schema + sizeof(SSchema) * pStable->numOfColumns, sizeof(SSchema) * pStable->numOfTags);
|
||||
memcpy(pStable->schema + sizeof(SSchema) * pStable->numOfColumns, schema, sizeof(SSchema) * ncols);
|
||||
memmove(pStable->schema + pStable->numOfColumns + ncols, pStable->schema + pStable->numOfColumns,
|
||||
sizeof(SSchema) * pStable->numOfTags);
|
||||
memcpy(pStable->schema + pStable->numOfColumns, schema, sizeof(SSchema) * ncols);
|
||||
|
||||
SSchema *tschema = (SSchema *) (pStable->schema + sizeof(SSchema) * pStable->numOfColumns);
|
||||
for (int32_t i = 0; i < ncols; i++) {
|
||||
|
@ -926,7 +957,7 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
|
|||
pStable->numOfColumns += ncols;
|
||||
pStable->sversion++;
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables);
|
||||
mgmtDecAcctRef(pAcct);
|
||||
|
@ -944,17 +975,18 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to add column", pStable->info.tableId);
|
||||
mPrint("stable %s, succeed to add column", pStable->info.tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, char *colName) {
|
||||
int32_t col = mgmtFindSuperTableColumnIndex(pStable, colName);
|
||||
if (col < 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
if (col <= 0) {
|
||||
mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName);
|
||||
return TSDB_CODE_FIELD_NOT_EXIST;
|
||||
}
|
||||
|
||||
memmove(pStable->schema + sizeof(SSchema) * col, pStable->schema + sizeof(SSchema) * (col + 1),
|
||||
memmove(pStable->schema + col, pStable->schema + col + 1,
|
||||
sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags - col - 1));
|
||||
|
||||
pStable->numOfColumns--;
|
||||
|
@ -963,7 +995,7 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
|
|||
int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns);
|
||||
pStable->schema = realloc(pStable->schema, schemaSize);
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables;
|
||||
mgmtDecAcctRef(pAcct);
|
||||
|
@ -981,7 +1013,7 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to delete column", pStable->info.tableId);
|
||||
mPrint("stable %s, succeed to delete column", pStable->info.tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1109,12 +1141,11 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
|
|||
int32_t dbNameLen = strlen(pDropDb->name);
|
||||
SSuperTableObj *pTable = NULL;
|
||||
|
||||
mPrint("db:%s, all super tables will be dropped from sdb", pDropDb->name);
|
||||
|
||||
while (1) {
|
||||
mgmtDecTableRef(pTable);
|
||||
pNode = sdbFetchRow(tsSuperTableSdb, pNode, (void **)&pTable);
|
||||
if (pTable == NULL) {
|
||||
break;
|
||||
}
|
||||
if (pTable == NULL) break;
|
||||
|
||||
if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) {
|
||||
SSdbOper oper = {
|
||||
|
@ -1125,16 +1156,18 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
|
|||
sdbDeleteRow(&oper);
|
||||
pNode = pLastNode;
|
||||
numOfTables ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
mgmtDecTableRef(pTable);
|
||||
}
|
||||
mTrace("db:%s, all super tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
|
||||
mPrint("db:%s, all super tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
}
|
||||
|
||||
static int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTable) {
|
||||
int32_t numOfCols = pTable->numOfColumns + pTable->numOfTags;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
strcpy(pSchema->name, pTable->schema[i].name);
|
||||
strncpy(pSchema->name, pTable->schema[i].name, TSDB_TABLE_ID_LEN);
|
||||
pSchema->type = pTable->schema[i].type;
|
||||
pSchema->bytes = htons(pTable->schema[i].bytes);
|
||||
pSchema->colId = htons(pTable->schema[i].colId);
|
||||
|
@ -1154,7 +1187,7 @@ static void mgmtGetSuperTableMeta(SQueuedMsg *pMsg) {
|
|||
pMeta->numOfColumns = htons((int16_t)pTable->numOfColumns);
|
||||
pMeta->tableType = pTable->info.type;
|
||||
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable);
|
||||
strcpy(pMeta->tableId, pTable->info.tableId);
|
||||
strncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN);
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pMsg->thandle,
|
||||
|
@ -1214,7 +1247,7 @@ static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) {
|
|||
}
|
||||
|
||||
static void mgmtProcessDropSuperTableRsp(SRpcMsg *rpcMsg) {
|
||||
mTrace("drop stable rsp received, handle:%p code:%d", rpcMsg->handle, rpcMsg->code);
|
||||
mTrace("drop stable rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code));
|
||||
}
|
||||
|
||||
static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableObj *pTable) {
|
||||
|
@ -1238,7 +1271,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb
|
|||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(pCreate->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN);
|
||||
mgmtExtractTableName(pTable->info.tableId, pCreate->tableId);
|
||||
pCreate->contLen = htonl(contLen);
|
||||
pCreate->vgId = htonl(pTable->vgId);
|
||||
pCreate->tableType = pTable->info.type;
|
||||
|
@ -1248,7 +1281,7 @@ static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableOb
|
|||
pCreate->uid = htobe64(pTable->uid);
|
||||
|
||||
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
||||
memcpy(pCreate->superTableId, pTable->superTable->info.tableId, TSDB_TABLE_ID_LEN + 1);
|
||||
mgmtExtractTableName(pTable->superTable->info.tableId, pCreate->superTableId);
|
||||
pCreate->numOfColumns = htons(pTable->superTable->numOfColumns);
|
||||
pCreate->numOfTags = htons(pTable->superTable->numOfTags);
|
||||
pCreate->sversion = htonl(pTable->superTable->sversion);
|
||||
|
@ -1468,9 +1501,9 @@ static int32_t mgmtModifyChildTableTagValue(SChildTableObj *pTable, char *tagNam
|
|||
|
||||
static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) {
|
||||
SSchema *schema = (SSchema *) pTable->schema;
|
||||
for (int32_t i = 0; i < pTable->numOfColumns; i++) {
|
||||
if (strcasecmp(schema[i].name, colName) == 0) {
|
||||
return i;
|
||||
for (int32_t col = 0; col < pTable->numOfColumns; col++) {
|
||||
if (strcasecmp(schema[col].name, colName) == 0) {
|
||||
return col;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1479,21 +1512,23 @@ static int32_t mgmtFindNormalTableColumnIndex(SChildTableObj *pTable, char *colN
|
|||
|
||||
static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) {
|
||||
if (ncols <= 0) {
|
||||
mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ncols; i++) {
|
||||
if (mgmtFindNormalTableColumnIndex(pTable, schema[i].name) > 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name);
|
||||
return TSDB_CODE_FIELD_ALREAY_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t schemaSize = pTable->numOfColumns * sizeof(SSchema);
|
||||
pTable->schema = realloc(pTable->schema, schemaSize + sizeof(SSchema) * ncols);
|
||||
|
||||
memcpy(pTable->schema + schemaSize, schema, sizeof(SSchema) * ncols);
|
||||
memcpy(pTable->schema + pTable->numOfColumns, schema, sizeof(SSchema) * ncols);
|
||||
|
||||
SSchema *tschema = (SSchema *) (pTable->schema + sizeof(SSchema) * pTable->numOfColumns);
|
||||
SSchema *tschema = (SSchema *) (pTable->schema + pTable->numOfColumns);
|
||||
for (int32_t i = 0; i < ncols; i++) {
|
||||
tschema[i].colId = pTable->nextColId++;
|
||||
}
|
||||
|
@ -1501,9 +1536,9 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
|
|||
pTable->numOfColumns += ncols;
|
||||
pTable->sversion++;
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries += ncols;
|
||||
pAcct->acctInfo.numOfTimeSeries += ncols;
|
||||
mgmtDecAcctRef(pAcct);
|
||||
}
|
||||
|
||||
|
@ -1525,17 +1560,16 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc
|
|||
|
||||
static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, char *colName) {
|
||||
int32_t col = mgmtFindNormalTableColumnIndex(pTable, colName);
|
||||
if (col < 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
if (col <= 0) {
|
||||
mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName);
|
||||
return TSDB_CODE_FIELD_NOT_EXIST;
|
||||
}
|
||||
|
||||
memmove(pTable->schema + sizeof(SSchema) * col, pTable->schema + sizeof(SSchema) * (col + 1),
|
||||
sizeof(SSchema) * (pTable->numOfColumns - col - 1));
|
||||
|
||||
memmove(pTable->schema + col, pTable->schema + col + 1, sizeof(SSchema) * (pTable->numOfColumns - col - 1));
|
||||
pTable->numOfColumns--;
|
||||
pTable->sversion++;
|
||||
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
SAcctObj *pAcct = mgmtGetAcct(pDb->acct);
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries--;
|
||||
mgmtDecAcctRef(pAcct);
|
||||
|
@ -1553,7 +1587,7 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch
|
|||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mPrint("table %s, succeed to add column %s", pTable->info.tableId, colName);
|
||||
mPrint("table %s, succeed to drop column %s", pTable->info.tableId, colName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1678,12 +1712,11 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
|
|||
int32_t dbNameLen = strlen(pDropDb->name);
|
||||
SChildTableObj *pTable = NULL;
|
||||
|
||||
mPrint("db:%s, all child tables will be dropped from sdb", pDropDb->name);
|
||||
|
||||
while (1) {
|
||||
mgmtDecTableRef(pTable);
|
||||
pNode = sdbFetchRow(tsChildTableSdb, pNode, (void **)&pTable);
|
||||
if (pTable == NULL) {
|
||||
break;
|
||||
}
|
||||
if (pTable == NULL) break;
|
||||
|
||||
if (strncmp(pDropDb->name, pTable->info.tableId, dbNameLen) == 0) {
|
||||
SSdbOper oper = {
|
||||
|
@ -1694,11 +1727,11 @@ void mgmtDropAllChildTables(SDbObj *pDropDb) {
|
|||
sdbDeleteRow(&oper);
|
||||
pNode = pLastNode;
|
||||
numOfTables++;
|
||||
continue;
|
||||
}
|
||||
mgmtDecTableRef(pTable);
|
||||
}
|
||||
|
||||
mTrace("db:%s, all child tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
mPrint("db:%s, all child tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
}
|
||||
|
||||
static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
|
||||
|
@ -1707,12 +1740,11 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
|
|||
int32_t numOfTables = 0;
|
||||
SChildTableObj *pTable = NULL;
|
||||
|
||||
mPrint("stable:%s, all child tables will dropped from sdb", pStable->info.tableId, numOfTables);
|
||||
|
||||
while (1) {
|
||||
mgmtDecTableRef(pTable);
|
||||
pNode = sdbFetchRow(tsChildTableSdb, pNode, (void **)&pTable);
|
||||
if (pTable == NULL) {
|
||||
break;
|
||||
}
|
||||
if (pTable == NULL) break;
|
||||
|
||||
if (pTable->superTable == pStable) {
|
||||
SSdbOper oper = {
|
||||
|
@ -1723,11 +1755,12 @@ static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable) {
|
|||
sdbDeleteRow(&oper);
|
||||
pNode = pLastNode;
|
||||
numOfTables++;
|
||||
continue;
|
||||
}
|
||||
|
||||
mgmtDecTableRef(pTable);
|
||||
}
|
||||
|
||||
mTrace("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables);
|
||||
mPrint("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables);
|
||||
}
|
||||
|
||||
static SChildTableObj* mgmtGetTableByPos(uint32_t dnodeId, int32_t vnode, int32_t sid) {
|
||||
|
@ -1873,7 +1906,7 @@ static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
|
|||
|
||||
// not implemented yet
|
||||
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg) {
|
||||
mTrace("alter table rsp received, handle:%p code:%d", rpcMsg->handle, rpcMsg->code);
|
||||
mTrace("alter table rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code));
|
||||
}
|
||||
|
||||
static void mgmtProcessMultiTableMetaMsg(SQueuedMsg *pMsg) {
|
||||
|
@ -2075,7 +2108,8 @@ static void mgmtProcessAlterTableMsg(SQueuedMsg *pMsg) {
|
|||
return;
|
||||
}
|
||||
|
||||
pAlter->numOfCols = htons(pAlter->numOfCols);
|
||||
pAlter->type = htons(pAlter->type);
|
||||
|
||||
if (pAlter->numOfCols > 2) {
|
||||
mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols);
|
||||
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_APP_ERROR);
|
||||
|
|
|
@ -353,6 +353,7 @@ static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg) {
|
|||
mLPrint("user:%s, is created by %s", pCreate->user, pOperUser->user);
|
||||
}
|
||||
} else {
|
||||
mError("user:%s, no rights to create user", pOperUser->user);
|
||||
code = TSDB_CODE_NO_RIGHTS;
|
||||
}
|
||||
|
||||
|
@ -398,6 +399,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
|
|||
code = mgmtUpdateUser(pUser);
|
||||
mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
|
||||
} else {
|
||||
mError("user:%s, no rights to ater user", pOperUser->user);
|
||||
code = TSDB_CODE_NO_RIGHTS;
|
||||
}
|
||||
|
||||
|
@ -440,11 +442,13 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
|
|||
code = mgmtUpdateUser(pUser);
|
||||
mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
|
||||
} else {
|
||||
mError("user:%s, no rights to ater user", pOperUser->user);
|
||||
code = TSDB_CODE_NO_RIGHTS;
|
||||
}
|
||||
|
||||
mgmtSendSimpleResp(pMsg->thandle, code);
|
||||
} else {
|
||||
mError("user:%s, no rights to ater user", pOperUser->user);
|
||||
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_NO_RIGHTS);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,14 +71,14 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) {
|
|||
pVgroup->prev = NULL;
|
||||
pVgroup->next = NULL;
|
||||
|
||||
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions;
|
||||
pVgroup->tableList = calloc(pDb->cfg.maxSessions, sizeof(SChildTableObj *));
|
||||
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
|
||||
pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *));
|
||||
if (pVgroup->tableList == NULL) {
|
||||
mError("vgroup:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVgroup->idPool = taosInitIdPool(pDb->cfg.maxSessions);
|
||||
pVgroup->idPool = taosInitIdPool(pDb->cfg.maxTables);
|
||||
if (pVgroup->idPool == NULL) {
|
||||
mError("vgroup:%d, failed to taosInitIdPool for vgroups", pVgroup->vgId);
|
||||
tfree(pVgroup->tableList);
|
||||
|
@ -146,15 +146,15 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
|
|||
int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool);
|
||||
SDbObj *pDb = pVgroup->pDb;
|
||||
if (pDb != NULL) {
|
||||
if (pDb->cfg.maxSessions != oldTables) {
|
||||
mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxSessions);
|
||||
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxSessions);
|
||||
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions;
|
||||
if (pDb->cfg.maxTables != oldTables) {
|
||||
mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables);
|
||||
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables);
|
||||
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
|
||||
pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size);
|
||||
}
|
||||
}
|
||||
|
||||
mTrace("vgroup:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxSessions, pVgroup->numOfVnodes);
|
||||
mTrace("vgroup:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxTables, pVgroup->numOfVnodes);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -272,8 +272,9 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
|
|||
pVgroup->pointsWritten = htobe64(pVload->pointsWritten);
|
||||
}
|
||||
|
||||
if (pVload->replica != pVgroup->numOfVnodes) {
|
||||
mError("dnode:%d, vgroup:%d replica:%d not match with mgmt:%d", pDnode->dnodeId, pVload->vgId, pVload->replica,
|
||||
if (pVload->cfgVersion != pVgroup->pDb->cfgVersion || pVload->replica != pVgroup->numOfVnodes) {
|
||||
mError("dnode:%d, vgroup:%d, vnode cfgVersion:%d repica:%d not match with mgmt cfgVersion:%d replica:%d",
|
||||
pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion,
|
||||
pVgroup->numOfVnodes);
|
||||
mgmtSendCreateVgroupMsg(pVgroup, NULL);
|
||||
}
|
||||
|
@ -511,7 +512,7 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
|
|||
pVgroup->numOfTables++;
|
||||
}
|
||||
|
||||
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxSessions)
|
||||
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables)
|
||||
mgmtAddVgroupIntoDbTail(pVgroup);
|
||||
}
|
||||
|
||||
|
@ -522,7 +523,7 @@ void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
|
|||
pVgroup->numOfTables--;
|
||||
}
|
||||
|
||||
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxSessions)
|
||||
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables)
|
||||
mgmtAddVgroupIntoDbTail(pVgroup);
|
||||
}
|
||||
|
||||
|
@ -535,23 +536,22 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
|
|||
|
||||
SMDVnodeCfg *pCfg = &pVnode->cfg;
|
||||
pCfg->vgId = htonl(pVgroup->vgId);
|
||||
pCfg->maxTables = htonl(pDb->cfg.maxSessions);
|
||||
pCfg->maxCacheSize = htobe64((int64_t)pDb->cfg.cacheBlockSize * pDb->cfg.cacheNumOfBlocks.totalBlocks);
|
||||
pCfg->maxCacheSize = htobe64(-1);
|
||||
pCfg->minRowsPerFileBlock = htonl(-1);
|
||||
pCfg->maxRowsPerFileBlock = htonl(-1);
|
||||
pCfg->cfgVersion = htonl(pDb->cfgVersion);
|
||||
pCfg->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize);
|
||||
pCfg->totalBlocks = htonl(pDb->cfg.totalBlocks);
|
||||
pCfg->maxTables = htonl(pDb->cfg.maxTables);
|
||||
pCfg->daysPerFile = htonl(pDb->cfg.daysPerFile);
|
||||
pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1);
|
||||
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
|
||||
pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep);
|
||||
pCfg->daysToKeep = htonl(-1);
|
||||
pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1);
|
||||
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
|
||||
pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock);
|
||||
pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock);
|
||||
pCfg->commitTime = htonl(pDb->cfg.commitTime);
|
||||
pCfg->precision = pDb->cfg.precision;
|
||||
pCfg->compression = pDb->cfg.compression;
|
||||
pCfg->compression = -1;
|
||||
pCfg->wals = 3;
|
||||
pCfg->commitLog = pDb->cfg.commitLog;
|
||||
pCfg->replications = (int8_t) pVgroup->numOfVnodes;
|
||||
pCfg->wals = 3;
|
||||
pCfg->quorum = 1;
|
||||
|
||||
SMDVnodeDesc *pNodes = pVnode->nodes;
|
||||
|
@ -744,12 +744,13 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) {
|
|||
void mgmtDropAllVgroups(SDbObj *pDropDb) {
|
||||
void *pNode = NULL;
|
||||
void *pLastNode = NULL;
|
||||
int32_t numOfTables = 0;
|
||||
int32_t numOfVgroups = 0;
|
||||
int32_t dbNameLen = strlen(pDropDb->name);
|
||||
SVgObj *pVgroup = NULL;
|
||||
|
||||
mPrint("db:%s, all vgroups will be dropped from sdb", pDropDb->name);
|
||||
|
||||
while (1) {
|
||||
mgmtDecVgroupRef(pVgroup);
|
||||
pNode = sdbFetchRow(tsVgroupSdb, pNode, (void **)&pVgroup);
|
||||
if (pVgroup == NULL) break;
|
||||
|
||||
|
@ -761,22 +762,12 @@ void mgmtDropAllVgroups(SDbObj *pDropDb) {
|
|||
};
|
||||
sdbDeleteRow(&oper);
|
||||
pNode = pLastNode;
|
||||
numOfTables++;
|
||||
continue;
|
||||
numOfVgroups++;
|
||||
}
|
||||
|
||||
mgmtSendDropVgroupMsg(pVgroup, NULL);
|
||||
mgmtDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
mTrace("db:%s, all vgroups is dropped from sdb", pDropDb->name, numOfTables);
|
||||
mPrint("db:%s, all vgroups:%d is dropped from sdb", pDropDb->name, numOfVgroups);
|
||||
}
|
||||
|
||||
void mgmtAlterVgroup(SVgObj *pVgroup, void *ahandle) {
|
||||
assert(ahandle != NULL);
|
||||
|
||||
if (pVgroup->numOfVnodes != pVgroup->pDb->cfg.replications) {
|
||||
// TODO:
|
||||
// mgmtSendAlterVgroupMsg(pVgroup, NULL);
|
||||
} else {
|
||||
mgmtAddToShellQueue(ahandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,4 @@ extern int32_t httpDebugFlag;
|
|||
#define httpPrint(...) \
|
||||
{ taosPrintLog("HTP ", 255, __VA_ARGS__); }
|
||||
|
||||
#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__)
|
||||
#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__)
|
||||
#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gcHandle.h"
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "cJSON.h"
|
||||
#include "httpLog.h"
|
||||
#include "gcHandle.h"
|
||||
#include "gcJson.h"
|
||||
#include "taosdef.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest};
|
||||
static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
|
|
|
@ -13,10 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "gcHandle.h"
|
||||
#include "gcJson.h"
|
||||
#include "httpJson.h"
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tkey.h"
|
||||
#include "tutil.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpHandle.h"
|
||||
#include "tkey.h"
|
||||
|
||||
#define KEY_DES_4 4971256377704625728L
|
||||
|
||||
bool httpParseBasicAuthToken(HttpContext *pContext, char *token, int len) {
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
|
||||
char* httpMsg[] = {
|
||||
"success", // 0
|
||||
"http server is not online", // 1
|
||||
|
|
|
@ -13,21 +13,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "http.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
#include "shash.h"
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taos.h"
|
||||
#include "tglobal.h"
|
||||
#include "tsocket.h"
|
||||
#include "ttimer.h"
|
||||
#include "shash.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
|
||||
void httpToLowerUrl(char* url) {
|
||||
/*ignore case */
|
||||
|
|
|
@ -13,20 +13,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "taoserror.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpJson.h"
|
||||
#include "httpResp.h"
|
||||
#include "taosmsg.h"
|
||||
#include "httpLog.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
#define MAX_NUM_STR_SZ 25
|
||||
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "httpResp.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "httpCode.h"
|
||||
#include "httpJson.h"
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
#include "httpLog.h"
|
||||
#include "taoserror.h"
|
||||
#include "httpResp.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpJson.h"
|
||||
|
||||
const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"};
|
||||
|
||||
|
@ -44,9 +44,8 @@ const char *httpRespTemplate[] = {
|
|||
"%s 200 OK\r\nAccess-Control-Allow-Origin:*\r\n%sAccess-Control-Allow-Methods:POST, GET, OPTIONS, DELETE, PUT\r\nAccess-Control-Allow-Headers:Accept, Content-Type\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: %d\r\n\r\n"
|
||||
};
|
||||
|
||||
void httpSendErrorRespImp(HttpContext *pContext, int httpCode, char *httpCodeStr, int errNo, char *desc) {
|
||||
httpError("context:%p, fd:%d, ip:%s, code:%d, error:%d:%s", pContext, pContext->fd, pContext->ipstr, httpCode, errNo,
|
||||
desc);
|
||||
static void httpSendErrorRespImp(HttpContext *pContext, int httpCode, char *httpCodeStr, int errNo, char *desc) {
|
||||
httpError("context:%p, fd:%d, ip:%s, code:%d, error:%s", pContext, pContext->fd, pContext->ipstr, httpCode, desc);
|
||||
|
||||
char head[512] = {0};
|
||||
char body[512] = {0};
|
||||
|
@ -184,7 +183,7 @@ void httpSendErrorResp(HttpContext *pContext, int errNo) { httpSendErrorRespWith
|
|||
|
||||
void httpSendTaosdErrorResp(HttpContext *pContext, int errCode) {
|
||||
int httpCode = 400;
|
||||
httpSendErrorRespImp(pContext, httpCode, "Bad Request", errCode, (char*)tstrerror(errCode));
|
||||
httpSendErrorRespImp(pContext, httpCode, "Bad Request", 1000, (char*)tstrerror(errCode));
|
||||
}
|
||||
|
||||
void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg) {
|
||||
|
@ -200,7 +199,7 @@ void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg) {
|
|||
} else {}
|
||||
}
|
||||
|
||||
httpSendErrorRespImp(pContext, httpCode, "Bad Request", TSDB_CODE_INVALID_SQL, temp);
|
||||
httpSendErrorRespImp(pContext, httpCode, "Bad Request", 1000, temp);
|
||||
}
|
||||
|
||||
void httpSendSuccResp(HttpContext *pContext, char *desc) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tsocket.h"
|
||||
|
|
|
@ -13,20 +13,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "http.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "shash.h"
|
||||
#include "taos.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
|
||||
|
||||
void httpAccessSession(HttpContext *pContext) {
|
||||
HttpServer *server = pContext->pThread->pServer;
|
||||
|
|
|
@ -13,15 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tnote.h"
|
||||
#include "taos.h"
|
||||
#include "tsclient.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
#include "taos.h"
|
||||
#include "tsclient.h"
|
||||
#include "tnote.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, void **taos);
|
||||
|
@ -55,8 +56,8 @@ void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numO
|
|||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, numOfRows, sql);
|
||||
|
||||
if (numOfRows < 0) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, retrieve failed code:%d, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -numOfRows, sql);
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, retrieve failed code:%s, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(numOfRows), sql);
|
||||
} else {
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
@ -79,21 +80,21 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) {
|
|||
HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos;
|
||||
char * sql = httpGetCmdsString(pContext, singleCmd->sql);
|
||||
|
||||
if (-code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%d:inprogress, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -code, sql);
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%s:inprogress, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code < 0) {
|
||||
if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : -code)) {
|
||||
singleCmd->code = -code;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%d, last sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, -code, sql);
|
||||
if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) {
|
||||
singleCmd->code = code;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql);
|
||||
} else {
|
||||
singleCmd->code = -code;
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, error code:%d, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -code, sql);
|
||||
singleCmd->code = code;
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, error code:%s, sql:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql);
|
||||
|
||||
if (singleCmd->cmdReturnType == HTTP_CMD_RETURN_TYPE_WITH_RETURN) {
|
||||
if (encode->startJsonFp) (encode->startJsonFp)(pContext, singleCmd, result);
|
||||
|
@ -209,8 +210,8 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num
|
|||
pContext->user, numOfRows);
|
||||
|
||||
if (numOfRows < 0) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, retrieve failed, code:%d", pContext, pContext->fd, pContext->ipstr,
|
||||
pContext->user, -numOfRows);
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, retrieve failed, code:%s", pContext, pContext->fd, pContext->ipstr,
|
||||
pContext->user, tstrerror(numOfRows));
|
||||
} else {
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
@ -229,22 +230,22 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) {
|
|||
|
||||
HttpEncodeMethod *encode = pContext->encodeMethod;
|
||||
|
||||
if (-code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d:inprogress, sqlObj:%p",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, (SSqlObj *)result);
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:inprogress, sqlObj:%p",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), (SSqlObj *)result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code < 0) {
|
||||
SSqlObj *pObj = (SSqlObj *)result;
|
||||
if (-code == TSDB_CODE_INVALID_SQL) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d:invalidsql, sqlObj:%p, error:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj, pObj->cmd.payload);
|
||||
if (code == TSDB_CODE_INVALID_SQL) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p, error:%s",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj, pObj->cmd.payload);
|
||||
httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload);
|
||||
} else {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d, sqlObj:%p",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj);
|
||||
httpSendTaosdErrorResp(pContext, -code);
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p",
|
||||
pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj);
|
||||
httpSendTaosdErrorResp(pContext, code);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -349,9 +350,9 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) {
|
|||
if (pContext == NULL || pContext->signature != pContext) return;
|
||||
|
||||
if (code < 0) {
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, login error, code:%d", pContext, pContext->fd, pContext->ipstr,
|
||||
pContext->user, -code);
|
||||
httpSendTaosdErrorResp(pContext, -code);
|
||||
httpError("context:%p, fd:%d, ip:%s, user:%s, login error, code:%s", pContext, pContext->fd, pContext->ipstr,
|
||||
pContext->user, tstrerror(code));
|
||||
httpSendTaosdErrorResp(pContext, code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,17 +15,17 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "shash.h"
|
||||
#include "taos.h"
|
||||
#include "tglobal.h"
|
||||
#include "tsocket.h"
|
||||
#include "ttimer.h"
|
||||
#include "tadmin.h"
|
||||
#include "http.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
#include "httpLog.h"
|
||||
#include "shash.h"
|
||||
#include "taos.h"
|
||||
#include "tglobal.h"
|
||||
#include "tsocket.h"
|
||||
#include "ttimer.h"
|
||||
#include "gcHandle.h"
|
||||
#include "httpHandle.h"
|
||||
#include "restHandle.h"
|
||||
|
|
|
@ -13,15 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tmd5.h"
|
||||
#include "shash.h"
|
||||
#include "taos.h"
|
||||
#include "http.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpCode.h"
|
||||
#include "httpHandle.h"
|
||||
#include "httpResp.h"
|
||||
#include "shash.h"
|
||||
#include "taos.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
bool httpCheckUsedbSql(char *sql) {
|
||||
if (strstr(sql, "use ") != NULL) {
|
||||
|
|
|
@ -13,9 +13,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "httpLog.h"
|
||||
#include "restHandle.h"
|
||||
#include "restJson.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest};
|
||||
static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest};
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "httpLog.h"
|
||||
|
|
|
@ -13,14 +13,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tgHandle.h"
|
||||
#include "shash.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tgJson.h"
|
||||
#include "taosdef.h"
|
||||
#include "httpLog.h"
|
||||
#include "tglobal.h"
|
||||
#include "shash.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tgHandle.h"
|
||||
#include "tgJson.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
/*
|
||||
* taos.telegraf.cfg formats like
|
||||
|
|
|
@ -13,13 +13,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "httpLog.h"
|
||||
#include "httpJson.h"
|
||||
#include "httpResp.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tgHandle.h"
|
||||
#include "tgJson.h"
|
||||
#include "httpLog.h"
|
||||
|
||||
void tgInitQueryJson(HttpContext *pContext) {
|
||||
JsonBuf *jsonBuf = httpMallocJsonBuf(pContext);
|
||||
|
@ -97,8 +98,8 @@ void tgBuildSqlAffectRowsJson(HttpContext *pContext, HttpSqlCmd *cmd, int affect
|
|||
|
||||
bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
|
||||
HttpSqlCmds *multiCmds = pContext->multiCmds;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, check telegraf command, code:%d, state:%d, type:%d, rettype:%d, tags:%d",
|
||||
pContext, pContext->fd, pContext->ipstr, code, cmd->cmdState, cmd->cmdType, cmd->cmdReturnType, cmd->tagNum);
|
||||
httpTrace("context:%p, fd:%d, ip:%s, check telegraf command, code:%s, state:%d, type:%d, rettype:%d, tags:%d",
|
||||
pContext, pContext->fd, pContext->ipstr, tstrerror(code), cmd->cmdState, cmd->cmdType, cmd->cmdReturnType, cmd->tagNum);
|
||||
|
||||
if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) {
|
||||
if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) {
|
||||
|
@ -124,11 +125,11 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
|
|||
}
|
||||
} else if (cmd->cmdType == HTTP_CMD_TYPE_CREATE_DB) {
|
||||
cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, code:%d, create database failed", pContext, pContext->fd, pContext->ipstr,
|
||||
code);
|
||||
httpTrace("context:%p, fd:%d, ip:%s, code:%s, create database failed", pContext, pContext->fd, pContext->ipstr,
|
||||
tstrerror(code));
|
||||
} else if (cmd->cmdType == HTTP_CMD_TYPE_CREATE_STBALE) {
|
||||
cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, code:%d, create stable failed", pContext, pContext->fd, pContext->ipstr, code);
|
||||
httpTrace("context:%p, fd:%d, ip:%s, code:%s, create stable failed", pContext, pContext->fd, pContext->ipstr, tstrerror(code));
|
||||
} else {
|
||||
}
|
||||
|
||||
|
@ -137,8 +138,8 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
|
|||
|
||||
void tgSetNextCmd(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) {
|
||||
HttpSqlCmds *multiCmds = pContext->multiCmds;
|
||||
httpTrace("context:%p, fd:%d, ip:%s, get telegraf next command, pos:%d, code:%d, state:%d, type:%d, rettype:%d, tags:%d",
|
||||
pContext, pContext->fd, pContext->ipstr, multiCmds->pos, code, cmd->cmdState, cmd->cmdType,
|
||||
httpTrace("context:%p, fd:%d, ip:%s, get telegraf next command, pos:%d, code:%s, state:%d, type:%d, rettype:%d, tags:%d",
|
||||
pContext, pContext->fd, pContext->ipstr, multiCmds->pos, tstrerror(code), cmd->cmdState, cmd->cmdType,
|
||||
cmd->cmdReturnType, cmd->tagNum);
|
||||
|
||||
if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MONITOR_SYSTEM_H
|
||||
#define TDENGINE_MONITOR_SYSTEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t monitorInitSystem();
|
||||
int32_t monitorStartSystem();
|
||||
void monitorStopSystem();
|
||||
void monitorCleanUpSystem();
|
||||
void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond,
|
||||
int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage,
|
||||
int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound,
|
||||
int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs,
|
||||
int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams,
|
||||
int64_t totalConns, int64_t maxConns, int8_t accessState);
|
||||
void monitorSaveLog(int level, const char *const format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,431 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "tsystem.h"
|
||||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
#include "dnode.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#define monitorError(...) \
|
||||
if (monitorDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLog("ERROR MON ", 255, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorWarn(...) \
|
||||
if (monitorDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLog("WARN MON ", monitorDebugFlag, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorTrace(...) \
|
||||
if (monitorDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorPrint(...) \
|
||||
{ taosPrintLog("MON ", 255, __VA_ARGS__); }
|
||||
|
||||
#define SQL_LENGTH 1024
|
||||
#define LOG_LEN_STR 80
|
||||
#define IP_LEN_STR 15
|
||||
#define CHECK_INTERVAL 1000
|
||||
|
||||
typedef enum {
|
||||
MONITOR_CMD_CREATE_DB,
|
||||
MONITOR_CMD_CREATE_TB_LOG,
|
||||
MONITOR_CMD_CREATE_MT_DN,
|
||||
MONITOR_CMD_CREATE_MT_ACCT,
|
||||
MONITOR_CMD_CREATE_TB_DN,
|
||||
MONITOR_CMD_CREATE_TB_ACCT_ROOT,
|
||||
MONITOR_CMD_CREATE_TB_SLOWQUERY,
|
||||
MONITOR_CMD_MAX
|
||||
} EMonitorCommand;
|
||||
|
||||
typedef enum {
|
||||
MONITOR_STATE_UN_INIT,
|
||||
MONITOR_STATE_INITIALIZING,
|
||||
MONITOR_STATE_INITIALIZED,
|
||||
MONITOR_STATE_STOPPED
|
||||
} EMonitorState;
|
||||
|
||||
typedef struct {
|
||||
void * conn;
|
||||
void * timer;
|
||||
char privateIpStr[TSDB_IPv4ADDR_LEN];
|
||||
int8_t cmdIndex;
|
||||
int8_t state;
|
||||
char sql[SQL_LENGTH];
|
||||
void * initTimer;
|
||||
void * diskTimer;
|
||||
} SMonitorConn;
|
||||
|
||||
static SMonitorConn tsMonitorConn;
|
||||
static void monitorInitConn(void *para, void *unused);
|
||||
static void monitorInitConnCb(void *param, TAOS_RES *result, int32_t code);
|
||||
static void monitorInitDatabase();
|
||||
static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code);
|
||||
static void monitorStartTimer();
|
||||
static void monitorSaveSystemInfo();
|
||||
|
||||
static void monitorCheckDiskUsage(void *para, void *unused) {
|
||||
taosGetDisk();
|
||||
taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &tsMonitorConn.diskTimer);
|
||||
}
|
||||
|
||||
int32_t monitorInitSystem() {
|
||||
taos_init();
|
||||
taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &tsMonitorConn.diskTimer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t monitorStartSystem() {
|
||||
monitorPrint("start monitor module");
|
||||
monitorInitSystem();
|
||||
taosTmrReset(monitorInitConn, 10, NULL, tscTmr, &tsMonitorConn.initTimer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void monitorStartSystemRetry() {
|
||||
if (tsMonitorConn.initTimer != NULL) {
|
||||
taosTmrReset(monitorInitConn, 3000, NULL, tscTmr, &tsMonitorConn.initTimer);
|
||||
}
|
||||
}
|
||||
|
||||
static void monitorInitConn(void *para, void *unused) {
|
||||
monitorPrint("starting to initialize monitor service ..");
|
||||
tsMonitorConn.state = MONITOR_STATE_INITIALIZING;
|
||||
|
||||
if (tsMonitorConn.privateIpStr[0] == 0) {
|
||||
strcpy(tsMonitorConn.privateIpStr, tsPrivateIp);
|
||||
for (int32_t i = 0; i < TSDB_IPv4ADDR_LEN; ++i) {
|
||||
if (tsMonitorConn.privateIpStr[i] == '.') {
|
||||
tsMonitorConn.privateIpStr[i] = '_';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tsMonitorConn.conn == NULL) {
|
||||
taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, monitorInitConnCb, &tsMonitorConn, &(tsMonitorConn.conn));
|
||||
} else {
|
||||
monitorInitDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
static void monitorInitConnCb(void *param, TAOS_RES *result, int32_t code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, connect to database failed, reason:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
taos_close(tsMonitorConn.conn);
|
||||
tsMonitorConn.conn = NULL;
|
||||
tsMonitorConn.state = MONITOR_STATE_UN_INIT;
|
||||
monitorStartSystemRetry();
|
||||
return;
|
||||
}
|
||||
|
||||
monitorTrace("monitor:%p, connect to database success, reason:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
monitorInitDatabase();
|
||||
}
|
||||
|
||||
static void dnodeBuildMonitorSql(char *sql, int32_t cmd) {
|
||||
memset(sql, 0, SQL_LENGTH);
|
||||
|
||||
if (cmd == MONITOR_CMD_CREATE_DB) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create database if not exists %s replica 1 days 10 keep 30 rows 1024 cache 2048 "
|
||||
"ablocks 2 tblocks 32 tables 32 precision 'us'",
|
||||
tsMonitorDbName);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_MT_DN) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.dn(ts timestamp"
|
||||
", cpu_taosd float, cpu_system float, cpu_cores int"
|
||||
", mem_taosd float, mem_system float, mem_total int"
|
||||
", disk_used float, disk_total int"
|
||||
", band_speed float"
|
||||
", io_read float, io_write float"
|
||||
", req_http int, req_select int, req_insert int"
|
||||
") tags (ipaddr binary(%d))",
|
||||
tsMonitorDbName, IP_LEN_STR + 1);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_DN) {
|
||||
snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn_%s using %s.dn tags('%s')", tsMonitorDbName,
|
||||
tsMonitorConn.privateIpStr, tsMonitorDbName, tsPrivateIp);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_MT_ACCT) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.acct(ts timestamp "
|
||||
", currentPointsPerSecond bigint, maxPointsPerSecond bigint"
|
||||
", totalTimeSeries bigint, maxTimeSeries bigint"
|
||||
", totalStorage bigint, maxStorage bigint"
|
||||
", totalQueryTime bigint, maxQueryTime bigint"
|
||||
", totalInbound bigint, maxInbound bigint"
|
||||
", totalOutbound bigint, maxOutbound bigint"
|
||||
", totalDbs smallint, maxDbs smallint"
|
||||
", totalUsers smallint, maxUsers smallint"
|
||||
", totalStreams smallint, maxStreams smallint"
|
||||
", totalConns smallint, maxConns smallint"
|
||||
", accessState smallint"
|
||||
") tags (acctId binary(%d))",
|
||||
tsMonitorDbName, TSDB_USER_LEN + 1);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_ACCT_ROOT) {
|
||||
snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct_%s using %s.acct tags('%s')", tsMonitorDbName, "root",
|
||||
tsMonitorDbName, "root");
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_SLOWQUERY) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.slowquery(ts timestamp, username "
|
||||
"binary(%d), created_time timestamp, time bigint, sql binary(%d))",
|
||||
tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SHOW_SQL_LEN);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_LOG) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.log(ts timestamp, level tinyint, "
|
||||
"content binary(%d), ipaddr binary(%d))",
|
||||
tsMonitorDbName, LOG_LEN_STR, IP_LEN_STR);
|
||||
}
|
||||
|
||||
sql[SQL_LENGTH] = 0;
|
||||
}
|
||||
|
||||
static void monitorInitDatabase() {
|
||||
if (tsMonitorConn.cmdIndex < MONITOR_CMD_MAX) {
|
||||
dnodeBuildMonitorSql(tsMonitorConn.sql, tsMonitorConn.cmdIndex);
|
||||
taos_query_a(tsMonitorConn.conn, tsMonitorConn.sql, monitorInitDatabaseCb, NULL);
|
||||
} else {
|
||||
tsMonitorConn.state = MONITOR_STATE_INITIALIZED;
|
||||
monitorPrint("monitor service init success");
|
||||
|
||||
monitorStartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) {
|
||||
if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) {
|
||||
monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
|
||||
if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) {
|
||||
monitorPrint("dnode:%s is started", tsPrivateIp);
|
||||
}
|
||||
tsMonitorConn.cmdIndex++;
|
||||
monitorInitDatabase();
|
||||
} else {
|
||||
monitorError("monitor:%p, sql failed, reason:%s, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
|
||||
tsMonitorConn.state = MONITOR_STATE_UN_INIT;
|
||||
monitorStartSystemRetry();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorStopSystem() {
|
||||
monitorPrint("monitor module is stopped");
|
||||
tsMonitorConn.state = MONITOR_STATE_STOPPED;
|
||||
if (tsMonitorConn.initTimer != NULL) {
|
||||
taosTmrStopA(&(tsMonitorConn.initTimer));
|
||||
}
|
||||
if (tsMonitorConn.timer != NULL) {
|
||||
taosTmrStopA(&(tsMonitorConn.timer));
|
||||
}
|
||||
}
|
||||
|
||||
void monitorCleanUpSystem() {
|
||||
monitorStopSystem();
|
||||
monitorPrint("monitor module cleanup");
|
||||
}
|
||||
|
||||
static void monitorStartTimer() {
|
||||
taosTmrReset(monitorSaveSystemInfo, tsMonitorInterval * 1000, NULL, tscTmr, &tsMonitorConn.timer);
|
||||
}
|
||||
|
||||
static void dnodeMontiorInsertAcctCallback(void *param, TAOS_RES *result, int32_t code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save account info failed, code:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save account info failed, affect rows:%d", tsMonitorConn.conn, code);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save account info success, code:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeMontiorInsertSysCallback(void *param, TAOS_RES *result, int32_t code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save system info failed, code:%s %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save system info failed, affect rows:%d %s", tsMonitorConn.conn, code, tsMonitorConn.sql);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save system info success, code:%s %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeMontiorInsertLogCallback(void *param, TAOS_RES *result, int32_t code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save log failed, code:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save log failed, affect rows:%d", tsMonitorConn.conn, code);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save log info success, code:%s", tsMonitorConn.conn, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
// unit is MB
|
||||
static int32_t monitorBuildMemorySql(char *sql) {
|
||||
float sysMemoryUsedMB = 0;
|
||||
bool suc = taosGetSysMemory(&sysMemoryUsedMB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get sys memory info failed.", tsMonitorConn.conn);
|
||||
}
|
||||
|
||||
float procMemoryUsedMB = 0;
|
||||
suc = taosGetProcMemory(&procMemoryUsedMB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get proc memory info failed.", tsMonitorConn.conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f, %d", procMemoryUsedMB, sysMemoryUsedMB, tsTotalMemoryMB);
|
||||
}
|
||||
|
||||
// unit is %
|
||||
static int32_t monitorBuildCpuSql(char *sql) {
|
||||
float sysCpuUsage = 0, procCpuUsage = 0;
|
||||
bool suc = taosGetCpuUsage(&sysCpuUsage, &procCpuUsage);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get cpu usage failed.", tsMonitorConn.conn);
|
||||
}
|
||||
|
||||
if (sysCpuUsage <= procCpuUsage) {
|
||||
sysCpuUsage = procCpuUsage + (float)0.1;
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f, %d", procCpuUsage, sysCpuUsage, tsNumOfCores);
|
||||
}
|
||||
|
||||
// unit is GB
|
||||
static int32_t monitorBuildDiskSql(char *sql) {
|
||||
return sprintf(sql, ", %f, %d", (tsTotalDataDirGB - tsAvailDataDirGB), (int32_t)tsTotalDataDirGB);
|
||||
}
|
||||
|
||||
// unit is Kb
|
||||
static int32_t monitorBuildBandSql(char *sql) {
|
||||
float bandSpeedKb = 0;
|
||||
bool suc = taosGetBandSpeed(&bandSpeedKb);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get bandwidth speed failed.", tsMonitorConn.conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f", bandSpeedKb);
|
||||
}
|
||||
|
||||
static int32_t monitorBuildReqSql(char *sql) {
|
||||
SDnodeStatisInfo info = dnodeGetStatisInfo();
|
||||
return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum);
|
||||
}
|
||||
|
||||
static int32_t monitorBuildIoSql(char *sql) {
|
||||
float readKB = 0, writeKB = 0;
|
||||
bool suc = taosGetProcIO(&readKB, &writeKB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get io info failed.", tsMonitorConn.conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f", readKB, writeKB);
|
||||
}
|
||||
|
||||
static void monitorSaveSystemInfo() {
|
||||
if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) {
|
||||
monitorStartTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t ts = taosGetTimestampUs();
|
||||
char * sql = tsMonitorConn.sql;
|
||||
int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%" PRId64, tsMonitorDbName, tsMonitorConn.privateIpStr, ts);
|
||||
|
||||
pos += monitorBuildCpuSql(sql + pos);
|
||||
pos += monitorBuildMemorySql(sql + pos);
|
||||
pos += monitorBuildDiskSql(sql + pos);
|
||||
pos += monitorBuildBandSql(sql + pos);
|
||||
pos += monitorBuildIoSql(sql + pos);
|
||||
pos += monitorBuildReqSql(sql + pos);
|
||||
|
||||
monitorTrace("monitor:%p, save system info, sql:%s", tsMonitorConn.conn, sql);
|
||||
taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertSysCallback, "log");
|
||||
|
||||
if (tsMonitorConn.timer != NULL && tsMonitorConn.state != MONITOR_STATE_STOPPED) {
|
||||
monitorStartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorSaveAcctLog(SAcctMonitorObj *pMon) {
|
||||
if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return;
|
||||
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into %s.acct_%s using %s.acct tags('%s') values(now"
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %d)",
|
||||
tsMonitorDbName, pMon->acctId, tsMonitorDbName, pMon->acctId,
|
||||
pMon->currentPointsPerSecond, pMon->maxPointsPerSecond,
|
||||
pMon->totalTimeSeries, pMon->maxTimeSeries,
|
||||
pMon->totalStorage, pMon->maxStorage,
|
||||
pMon->totalQueryTime, pMon->maxQueryTime,
|
||||
pMon->totalInbound, pMon->maxInbound,
|
||||
pMon->totalOutbound, pMon->maxOutbound,
|
||||
pMon->totalDbs, pMon->maxDbs,
|
||||
pMon->totalUsers, pMon->maxUsers,
|
||||
pMon->totalStreams, pMon->maxStreams,
|
||||
pMon->totalConns, pMon->maxConns,
|
||||
pMon->accessState);
|
||||
|
||||
monitorTrace("monitor:%p, save account info, sql %s", tsMonitorConn.conn, sql);
|
||||
taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertAcctCallback, "account");
|
||||
}
|
||||
|
||||
void monitorSaveLog(int32_t level, const char *const format, ...) {
|
||||
if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return;
|
||||
|
||||
va_list argpointer;
|
||||
char sql[SQL_LENGTH] = {0};
|
||||
int32_t max_length = SQL_LENGTH - 30;
|
||||
|
||||
if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return;
|
||||
|
||||
int32_t len = snprintf(sql, (size_t)max_length, "import into %s.log values(%" PRId64 ", %d,'", tsMonitorDbName,
|
||||
taosGetTimestampUs(), level);
|
||||
|
||||
va_start(argpointer, format);
|
||||
len += vsnprintf(sql + len, (size_t)(max_length - len), format, argpointer);
|
||||
va_end(argpointer);
|
||||
if (len > max_length) len = max_length;
|
||||
|
||||
len += sprintf(sql + len, "', '%s')", tsPrivateIp);
|
||||
sql[len++] = 0;
|
||||
|
||||
monitorTrace("monitor:%p, save log, sql: %s", tsMonitorConn.conn, sql);
|
||||
taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertLogCallback, "log");
|
||||
}
|
||||
|
||||
void monitorExecuteSQL(char *sql) {
|
||||
if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return;
|
||||
|
||||
monitorTrace("monitor:%p, execute sql: %s", tsMonitorConn.conn, sql);
|
||||
|
||||
// bug while insert binary
|
||||
// taos_query_a(tsMonitorConn.conn, sql, NULL, NULL);
|
||||
}
|
|
@ -1,461 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
#include "monitor.h"
|
||||
#include "dnode.h"
|
||||
#include "tsclient.h"
|
||||
#include "taosdef.h"
|
||||
#include "tsystem.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tutil.h"
|
||||
#include "monitorSystem.h"
|
||||
|
||||
#define monitorError(...) \
|
||||
if (monitorDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLog("ERROR MON ", 255, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorWarn(...) \
|
||||
if (monitorDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLog("WARN MON ", monitorDebugFlag, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorTrace(...) \
|
||||
if (monitorDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); \
|
||||
}
|
||||
#define monitorPrint(...) \
|
||||
{ taosPrintLog("MON ", 255, __VA_ARGS__); }
|
||||
|
||||
#define monitorLError(...) monitorError(__VA_ARGS__)
|
||||
#define monitorLWarn(...) monitorWarn(__VA_ARGS__)
|
||||
#define monitorLPrint(...) monitorPrint(__VA_ARGS__)
|
||||
|
||||
#define SQL_LENGTH 1024
|
||||
#define LOG_LEN_STR 80
|
||||
#define IP_LEN_STR 15
|
||||
#define CHECK_INTERVAL 1000
|
||||
|
||||
typedef enum {
|
||||
MONITOR_CMD_CREATE_DB,
|
||||
MONITOR_CMD_CREATE_TB_LOG,
|
||||
MONITOR_CMD_CREATE_MT_DN,
|
||||
MONITOR_CMD_CREATE_MT_ACCT,
|
||||
MONITOR_CMD_CREATE_TB_DN,
|
||||
MONITOR_CMD_CREATE_TB_ACCT_ROOT,
|
||||
MONITOR_CMD_CREATE_TB_SLOWQUERY,
|
||||
MONITOR_CMD_MAX
|
||||
} MonitorCommand;
|
||||
|
||||
typedef enum {
|
||||
MONITOR_STATE_UN_INIT,
|
||||
MONITOR_STATE_INITIALIZING,
|
||||
MONITOR_STATE_INITIALIZED,
|
||||
MONITOR_STATE_STOPPED
|
||||
} MonitorState;
|
||||
|
||||
typedef struct {
|
||||
void * conn;
|
||||
void * timer;
|
||||
char privateIpStr[TSDB_IPv4ADDR_LEN];
|
||||
int8_t cmdIndex;
|
||||
int8_t state;
|
||||
char sql[SQL_LENGTH];
|
||||
void * initTimer;
|
||||
void * diskTimer;
|
||||
} MonitorConn;
|
||||
|
||||
MonitorConn *monitor = NULL;
|
||||
|
||||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, void **taos);
|
||||
void monitorInitConn(void *para, void *unused);
|
||||
void monitorInitConnCb(void *param, TAOS_RES *result, int code);
|
||||
void monitorInitDatabase();
|
||||
void monitorInitDatabaseCb(void *param, TAOS_RES *result, int code);
|
||||
void monitorStartTimer();
|
||||
void monitorSaveSystemInfo();
|
||||
void monitorSaveLog(int level, const char *const format, ...);
|
||||
void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond,
|
||||
int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage,
|
||||
int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound,
|
||||
int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs,
|
||||
int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams,
|
||||
int64_t totalConns, int64_t maxConns, int8_t accessState);
|
||||
void (*mnodeCountRequestFp)(SDnodeStatisInfo *info) = NULL;
|
||||
void monitorExecuteSQL(char *sql);
|
||||
|
||||
void monitorCheckDiskUsage(void *para, void *unused) {
|
||||
taosGetDisk();
|
||||
taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &monitor->diskTimer);
|
||||
}
|
||||
|
||||
int monitorInitSystem() {
|
||||
monitor = (MonitorConn *)malloc(sizeof(MonitorConn));
|
||||
memset(monitor, 0, sizeof(MonitorConn));
|
||||
taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &monitor->diskTimer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int monitorStartSystem() {
|
||||
if (monitor == NULL) {
|
||||
monitorInitSystem();
|
||||
}
|
||||
taosTmrReset(monitorInitConn, 10, NULL, tscTmr, &monitor->initTimer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void monitorStartSystemRetry() {
|
||||
if (monitor->initTimer != NULL) {
|
||||
taosTmrReset(monitorInitConn, 3000, NULL, tscTmr, &monitor->initTimer);
|
||||
}
|
||||
}
|
||||
|
||||
void monitorInitConn(void *para, void *unused) {
|
||||
monitorPrint("starting to initialize monitor service ..");
|
||||
monitor->state = MONITOR_STATE_INITIALIZING;
|
||||
|
||||
if (monitor->privateIpStr[0] == 0) {
|
||||
strcpy(monitor->privateIpStr, tsPrivateIp);
|
||||
for (int i = 0; i < TSDB_IPv4ADDR_LEN; ++i) {
|
||||
if (monitor->privateIpStr[i] == '.') {
|
||||
monitor->privateIpStr[i] = '_';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor->conn == NULL) {
|
||||
taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, monitorInitConnCb, monitor, &(monitor->conn));
|
||||
} else {
|
||||
monitorInitDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorInitConnCb(void *param, TAOS_RES *result, int code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, connect to database failed, code:%d", monitor->conn, code);
|
||||
taos_close(monitor->conn);
|
||||
monitor->conn = NULL;
|
||||
monitor->state = MONITOR_STATE_UN_INIT;
|
||||
monitorStartSystemRetry();
|
||||
return;
|
||||
}
|
||||
|
||||
monitorTrace("monitor:%p, connect to database success, code:%d", monitor->conn, code);
|
||||
monitorInitDatabase();
|
||||
}
|
||||
|
||||
void dnodeBuildMonitorSql(char *sql, int cmd) {
|
||||
memset(sql, 0, SQL_LENGTH);
|
||||
|
||||
if (cmd == MONITOR_CMD_CREATE_DB) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create database if not exists %s replica 1 days 10 keep 30 rows 1024 cache 2048 "
|
||||
"ablocks 2 tblocks 32 tables 32 precision 'us'",
|
||||
tsMonitorDbName);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_MT_DN) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.dn(ts timestamp"
|
||||
", cpu_taosd float, cpu_system float, cpu_cores int"
|
||||
", mem_taosd float, mem_system float, mem_total int"
|
||||
", disk_used float, disk_total int"
|
||||
", band_speed float"
|
||||
", io_read float, io_write float"
|
||||
", req_http int, req_select int, req_insert int"
|
||||
") tags (ipaddr binary(%d))",
|
||||
tsMonitorDbName, IP_LEN_STR + 1);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_DN) {
|
||||
snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn_%s using %s.dn tags('%s')", tsMonitorDbName,
|
||||
monitor->privateIpStr, tsMonitorDbName, tsPrivateIp);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_MT_ACCT) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.acct(ts timestamp "
|
||||
", currentPointsPerSecond bigint, maxPointsPerSecond bigint"
|
||||
", totalTimeSeries bigint, maxTimeSeries bigint"
|
||||
", totalStorage bigint, maxStorage bigint"
|
||||
", totalQueryTime bigint, maxQueryTime bigint"
|
||||
", totalInbound bigint, maxInbound bigint"
|
||||
", totalOutbound bigint, maxOutbound bigint"
|
||||
", totalDbs smallint, maxDbs smallint"
|
||||
", totalUsers smallint, maxUsers smallint"
|
||||
", totalStreams smallint, maxStreams smallint"
|
||||
", totalConns smallint, maxConns smallint"
|
||||
", accessState smallint"
|
||||
") tags (acctId binary(%d))",
|
||||
tsMonitorDbName, TSDB_USER_LEN + 1);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_ACCT_ROOT) {
|
||||
snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct_%s using %s.acct tags('%s')", tsMonitorDbName, "root",
|
||||
tsMonitorDbName, "root");
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_SLOWQUERY) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.slowquery(ts timestamp, username "
|
||||
"binary(%d), created_time timestamp, time bigint, sql binary(%d))",
|
||||
tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SHOW_SQL_LEN);
|
||||
} else if (cmd == MONITOR_CMD_CREATE_TB_LOG) {
|
||||
snprintf(sql, SQL_LENGTH,
|
||||
"create table if not exists %s.log(ts timestamp, level tinyint, "
|
||||
"content binary(%d), ipaddr binary(%d))",
|
||||
tsMonitorDbName, LOG_LEN_STR, IP_LEN_STR);
|
||||
}
|
||||
|
||||
sql[SQL_LENGTH] = 0;
|
||||
}
|
||||
|
||||
void monitorInitDatabase() {
|
||||
if (monitor->cmdIndex < MONITOR_CMD_MAX) {
|
||||
dnodeBuildMonitorSql(monitor->sql, monitor->cmdIndex);
|
||||
taos_query_a(monitor->conn, monitor->sql, monitorInitDatabaseCb, NULL);
|
||||
} else {
|
||||
monitor->state = MONITOR_STATE_INITIALIZED;
|
||||
monitorPrint("monitor service init success");
|
||||
|
||||
monitorStartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorInitDatabaseCb(void *param, TAOS_RES *result, int code) {
|
||||
if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) {
|
||||
monitorTrace("monitor:%p, sql success, code:%d, %s", monitor->conn, code, monitor->sql);
|
||||
if (monitor->cmdIndex == MONITOR_CMD_CREATE_TB_LOG) {
|
||||
monitorLPrint("dnode:%s is started", tsPrivateIp);
|
||||
}
|
||||
monitor->cmdIndex++;
|
||||
monitorInitDatabase();
|
||||
} else {
|
||||
monitorError("monitor:%p, sql failed, code:%d, %s", monitor->conn, code, monitor->sql);
|
||||
monitor->state = MONITOR_STATE_UN_INIT;
|
||||
monitorStartSystemRetry();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorStopSystem() {
|
||||
if (monitor == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
monitorLPrint("dnode:%s monitor module is stopped", tsPrivateIp);
|
||||
monitor->state = MONITOR_STATE_STOPPED;
|
||||
// taosLogFp = NULL;
|
||||
if (monitor->initTimer != NULL) {
|
||||
taosTmrStopA(&(monitor->initTimer));
|
||||
}
|
||||
if (monitor->timer != NULL) {
|
||||
taosTmrStopA(&(monitor->timer));
|
||||
}
|
||||
}
|
||||
|
||||
void monitorCleanUpSystem() {
|
||||
monitorPrint("monitor service cleanup");
|
||||
monitorStopSystem();
|
||||
}
|
||||
|
||||
void monitorStartTimer() {
|
||||
taosTmrReset(monitorSaveSystemInfo, tsMonitorInterval * 1000, NULL, tscTmr, &monitor->timer);
|
||||
}
|
||||
|
||||
void dnodeMontiorInsertAcctCallback(void *param, TAOS_RES *result, int code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save account info failed, code:%d", monitor->conn, code);
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save account info failed, affect rows:%d", monitor->conn, code);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save account info success, code:%d", monitor->conn, code);
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeMontiorInsertSysCallback(void *param, TAOS_RES *result, int code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save system info failed, code:%d %s", monitor->conn, code, monitor->sql);
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save system info failed, affect rows:%d %s", monitor->conn, code, monitor->sql);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save system info success, code:%d %s", monitor->conn, code, monitor->sql);
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeMontiorInsertLogCallback(void *param, TAOS_RES *result, int code) {
|
||||
if (code < 0) {
|
||||
monitorError("monitor:%p, save log failed, code:%d", monitor->conn, code);
|
||||
} else if (code == 0) {
|
||||
monitorError("monitor:%p, save log failed, affect rows:%d", monitor->conn, code);
|
||||
} else {
|
||||
monitorTrace("monitor:%p, save log info success, code:%d", monitor->conn, code);
|
||||
}
|
||||
}
|
||||
|
||||
// unit is MB
|
||||
int monitorBuildMemorySql(char *sql) {
|
||||
float sysMemoryUsedMB = 0;
|
||||
bool suc = taosGetSysMemory(&sysMemoryUsedMB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get sys memory info failed.", monitor->conn);
|
||||
}
|
||||
|
||||
float procMemoryUsedMB = 0;
|
||||
suc = taosGetProcMemory(&procMemoryUsedMB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get proc memory info failed.", monitor->conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f, %d", procMemoryUsedMB, sysMemoryUsedMB, tsTotalMemoryMB);
|
||||
}
|
||||
|
||||
// unit is %
|
||||
int monitorBuildCpuSql(char *sql) {
|
||||
float sysCpuUsage = 0, procCpuUsage = 0;
|
||||
bool suc = taosGetCpuUsage(&sysCpuUsage, &procCpuUsage);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get cpu usage failed.", monitor->conn);
|
||||
}
|
||||
|
||||
if (sysCpuUsage <= procCpuUsage) {
|
||||
sysCpuUsage = procCpuUsage + (float)0.1;
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f, %d", procCpuUsage, sysCpuUsage, tsNumOfCores);
|
||||
}
|
||||
|
||||
// unit is GB
|
||||
int monitorBuildDiskSql(char *sql) {
|
||||
return sprintf(sql, ", %f, %d", (tsTotalDataDirGB - tsAvailDataDirGB), (int32_t)tsTotalDataDirGB);
|
||||
}
|
||||
|
||||
// unit is Kb
|
||||
int monitorBuildBandSql(char *sql) {
|
||||
float bandSpeedKb = 0;
|
||||
bool suc = taosGetBandSpeed(&bandSpeedKb);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get bandwidth speed failed.", monitor->conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f", bandSpeedKb);
|
||||
}
|
||||
|
||||
int monitorBuildReqSql(char *sql) {
|
||||
SDnodeStatisInfo info;
|
||||
info.httpReqNum = info.submitReqNum = info.queryReqNum = 0;
|
||||
(*mnodeCountRequestFp)(&info);
|
||||
|
||||
return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum);
|
||||
}
|
||||
|
||||
int monitorBuildIoSql(char *sql) {
|
||||
float readKB = 0, writeKB = 0;
|
||||
bool suc = taosGetProcIO(&readKB, &writeKB);
|
||||
if (!suc) {
|
||||
monitorError("monitor:%p, get io info failed.", monitor->conn);
|
||||
}
|
||||
|
||||
return sprintf(sql, ", %f, %f", readKB, writeKB);
|
||||
}
|
||||
|
||||
void monitorSaveSystemInfo() {
|
||||
if (monitor->state != MONITOR_STATE_INITIALIZED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mnodeCountRequestFp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t ts = taosGetTimestampUs();
|
||||
char * sql = monitor->sql;
|
||||
int pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%" PRId64, tsMonitorDbName, monitor->privateIpStr, ts);
|
||||
|
||||
pos += monitorBuildCpuSql(sql + pos);
|
||||
pos += monitorBuildMemorySql(sql + pos);
|
||||
pos += monitorBuildDiskSql(sql + pos);
|
||||
pos += monitorBuildBandSql(sql + pos);
|
||||
pos += monitorBuildIoSql(sql + pos);
|
||||
pos += monitorBuildReqSql(sql + pos);
|
||||
|
||||
monitorTrace("monitor:%p, save system info, sql:%s", monitor->conn, sql);
|
||||
taos_query_a(monitor->conn, sql, dnodeMontiorInsertSysCallback, "log");
|
||||
|
||||
if (monitor->timer != NULL && monitor->state != MONITOR_STATE_STOPPED) {
|
||||
monitorStartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond,
|
||||
int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage,
|
||||
int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound,
|
||||
int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs,
|
||||
int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams,
|
||||
int64_t totalConns, int64_t maxConns, int8_t accessState) {
|
||||
if (monitor == NULL) return;
|
||||
if (monitor->state != MONITOR_STATE_INITIALIZED) return;
|
||||
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into %s.acct_%s using %s.acct tags('%s') values(now"
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %" PRId64 ", %" PRId64
|
||||
", %d)",
|
||||
tsMonitorDbName, acctId, tsMonitorDbName, acctId,
|
||||
currentPointsPerSecond, maxPointsPerSecond,
|
||||
totalTimeSeries, maxTimeSeries,
|
||||
totalStorage, maxStorage,
|
||||
totalQueryTime, maxQueryTime,
|
||||
totalInbound, maxInbound,
|
||||
totalOutbound, maxOutbound,
|
||||
totalDbs, maxDbs,
|
||||
totalUsers, maxUsers,
|
||||
totalStreams, maxStreams,
|
||||
totalConns, maxConns,
|
||||
accessState);
|
||||
|
||||
monitorTrace("monitor:%p, save account info, sql %s", monitor->conn, sql);
|
||||
taos_query_a(monitor->conn, sql, dnodeMontiorInsertAcctCallback, "account");
|
||||
}
|
||||
|
||||
void monitorSaveLog(int level, const char *const format, ...) {
|
||||
va_list argpointer;
|
||||
char sql[SQL_LENGTH] = {0};
|
||||
int max_length = SQL_LENGTH - 30;
|
||||
|
||||
if (monitor->state != MONITOR_STATE_INITIALIZED) {
|
||||
return;
|
||||
}
|
||||
|
||||
int len = snprintf(sql, (size_t)max_length, "import into %s.log values(%" PRId64 ", %d,'", tsMonitorDbName,
|
||||
taosGetTimestampUs(), level);
|
||||
|
||||
va_start(argpointer, format);
|
||||
len += vsnprintf(sql + len, (size_t)(max_length - len), format, argpointer);
|
||||
va_end(argpointer);
|
||||
if (len > max_length) len = max_length;
|
||||
|
||||
len += sprintf(sql + len, "', '%s')", tsPrivateIp);
|
||||
sql[len++] = 0;
|
||||
|
||||
monitorTrace("monitor:%p, save log, sql: %s", monitor->conn, sql);
|
||||
taos_query_a(monitor->conn, sql, dnodeMontiorInsertLogCallback, "log");
|
||||
}
|
||||
|
||||
void monitorExecuteSQL(char *sql) {
|
||||
monitorTrace("monitor:%p, execute sql: %s", monitor->conn, sql);
|
||||
taos_query_a(monitor->conn, sql, NULL, NULL);
|
||||
}
|
|
@ -82,16 +82,18 @@ void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
|||
|
||||
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param);
|
||||
|
||||
void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, char *, int32_t));
|
||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*cb)(void *, const char*, int32_t));
|
||||
|
||||
void tSQLBinaryExprTrv(tExprNode *pExprs, int32_t *val, int16_t *ids);
|
||||
// todo refactor: remove it
|
||||
void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res);
|
||||
|
||||
uint8_t getBinaryExprOptr(SSQLToken *pToken);
|
||||
|
||||
SBuffer exprTreeToBinary(tExprNode* pExprTree);
|
||||
|
||||
int32_t exprTreeFromBinary(const void* pBuf, size_t size, tExprNode** pExprNode);
|
||||
tExprNode* exprTreeFromBinary(const void* pBuf, size_t size);
|
||||
tExprNode* exprTreeFromTableName(const char* tbnameCond);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -114,14 +114,13 @@ typedef struct SCreateDBInfo {
|
|||
int32_t tablesPerVnode;
|
||||
int32_t daysPerFile;
|
||||
int32_t rowPerFileBlock;
|
||||
|
||||
float numOfAvgCacheBlocks;
|
||||
int32_t numOfBlocksPerTable;
|
||||
|
||||
float numOfAvgCacheBlocks;
|
||||
int32_t numOfBlocksPerTable;
|
||||
int64_t commitTime;
|
||||
int32_t commitLog;
|
||||
int32_t compressionLevel;
|
||||
SSQLToken precision;
|
||||
bool ignoreExists;
|
||||
|
||||
tVariantList *keep;
|
||||
} SCreateDBInfo;
|
||||
|
|
|
@ -39,10 +39,10 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
|
|||
|
||||
typedef struct SSqlGroupbyExpr {
|
||||
int16_t tableIndex;
|
||||
SArray* columnInfo; // SArray<SColIndex>, group by columns information
|
||||
int16_t numOfGroupCols;
|
||||
SColIndex* columnInfo; // group by columns information
|
||||
int16_t orderIndex; // order by column index
|
||||
int16_t orderType; // order by type: asc/desc
|
||||
int16_t orderIndex; // order by column index
|
||||
int16_t orderType; // order by type: asc/desc
|
||||
} SSqlGroupbyExpr;
|
||||
|
||||
typedef struct SPosInfo {
|
||||
|
@ -90,7 +90,7 @@ typedef struct SColumnFilterElem {
|
|||
} SColumnFilterElem;
|
||||
|
||||
typedef struct SSingleColumnFilterInfo {
|
||||
SColumnInfoData info;
|
||||
SColumnInfo info;
|
||||
int32_t numOfFilters;
|
||||
SColumnFilterElem* pFilters;
|
||||
void* pData;
|
||||
|
@ -108,7 +108,7 @@ typedef struct STableQueryInfo {
|
|||
SWindowResInfo windowResInfo;
|
||||
} STableQueryInfo;
|
||||
|
||||
typedef struct STableDataInfo {
|
||||
typedef struct STableDataInfo { // todo merge with the STableQueryInfo struct
|
||||
int32_t tableIndex;
|
||||
int32_t groupIdx; // group id in table list
|
||||
STableQueryInfo* pTableQInfo;
|
||||
|
@ -116,27 +116,29 @@ typedef struct STableDataInfo {
|
|||
|
||||
typedef struct SQuery {
|
||||
int16_t numOfCols;
|
||||
int16_t numOfTags;
|
||||
|
||||
SOrderVal order;
|
||||
STimeWindow window;
|
||||
int64_t intervalTime;
|
||||
int64_t slidingTime; // sliding time for sliding window query
|
||||
char slidingTimeUnit; // interval data type, used for daytime revise
|
||||
int8_t precision;
|
||||
int16_t numOfOutputCols;
|
||||
int16_t numOfOutput;
|
||||
int16_t interpoType;
|
||||
int16_t checkBuffer; // check if the buffer is full during scan each block
|
||||
SLimitVal limit;
|
||||
int32_t rowSize;
|
||||
SSqlGroupbyExpr* pGroupbyExpr;
|
||||
SSqlFunctionExpr* pSelectExpr;
|
||||
SColumnInfoData* colList;
|
||||
SArithExprInfo* pSelectExpr;
|
||||
SColumnInfo* colList;
|
||||
SColumnInfo* tagColList;
|
||||
int32_t numOfFilterCols;
|
||||
int64_t* defaultVal;
|
||||
TSKEY lastKey;
|
||||
uint32_t status; // query status
|
||||
SResultRec rec;
|
||||
int32_t pos;
|
||||
int64_t pointsOffset; // the number of points offset to save read data
|
||||
SData** sdata;
|
||||
SSingleColumnFilterInfo* pFilterInfo;
|
||||
} SQuery;
|
||||
|
|
|
@ -38,4 +38,9 @@ void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTa
|
|||
|
||||
char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult);
|
||||
|
||||
__filter_func_t *getRangeFilterFuncArray(int32_t type);
|
||||
__filter_func_t *getValueFilterFuncArray(int32_t type);
|
||||
|
||||
bool supportPrefilter(int32_t type);
|
||||
|
||||
#endif // TDENGINE_QUERYUTIL_H
|
||||
|
|
|
@ -114,11 +114,11 @@ enum {
|
|||
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
|
||||
|
||||
typedef struct SArithmeticSupport {
|
||||
SSqlFunctionExpr *pExpr;
|
||||
int32_t elemSize[TSDB_MAX_COLUMNS];
|
||||
SArithExprInfo *pArithExpr;
|
||||
int32_t numOfCols;
|
||||
SColumnInfo* colList;
|
||||
int32_t offset;
|
||||
char * data[TSDB_MAX_COLUMNS];
|
||||
char** data;
|
||||
} SArithmeticSupport;
|
||||
|
||||
typedef struct SQLPreAggVal {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define TDENGINE_TVARIANT_H
|
||||
|
||||
#include "tstoken.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -31,6 +32,7 @@ typedef struct tVariant {
|
|||
double dKey;
|
||||
char * pz;
|
||||
wchar_t *wpz;
|
||||
SArray *arr; // only for 'in' query to hold value list, not value for a field
|
||||
};
|
||||
} tVariant;
|
||||
|
||||
|
@ -38,7 +40,7 @@ void tVariantCreate(tVariant *pVar, SSQLToken *token);
|
|||
|
||||
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
|
||||
void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32_t type);
|
||||
|
||||
void tVariantDestroy(tVariant *pV);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "tarray.h"
|
||||
#include "tskiplist.h"
|
||||
#include "queryLog.h"
|
||||
#include "tsdbMain.h"
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -521,38 +522,48 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) {
|
|||
if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL ||
|
||||
optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) {
|
||||
pCond->start = calloc(1, sizeof(tVariant));
|
||||
|
||||
tVariantAssign(&pCond->start->v, &queryColInfo->q);
|
||||
pCond->start->optr = queryColInfo->optr;
|
||||
|
||||
} else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) {
|
||||
pCond->end = calloc(1, sizeof(tVariant));
|
||||
|
||||
tVariantAssign(&pCond->end->v, &queryColInfo->q);
|
||||
pCond->end->optr = queryColInfo->optr;
|
||||
|
||||
} else if (optr == TSDB_RELATION_IN) {
|
||||
printf("relation is in\n");
|
||||
|
||||
} else if (optr == TSDB_RELATION_LIKE) {
|
||||
printf("relation is like\n");
|
||||
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void tQueryOnSkipList(SSkipList* pSkipList, SQueryCond* pCond, int32_t type, SArray* result) {
|
||||
static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) {
|
||||
SSkipListIterator* iter = NULL;
|
||||
|
||||
if (pCond->start != NULL) {
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &pCond->start->v.i64Key, type, TSDB_ORDER_ASC);
|
||||
int32_t type = pQueryInfo->q.nType;
|
||||
|
||||
SQueryCond cond = { 0 };
|
||||
setQueryCond(pQueryInfo, &cond);
|
||||
|
||||
if (cond.start != NULL) {
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.start->v.i64Key, type, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &pCond->end->v.i64Key, type, TSDB_ORDER_DESC);
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) &cond.end->v.i64Key, type, TSDB_ORDER_DESC);
|
||||
}
|
||||
|
||||
__compar_fn_t func = getComparFunc(pSkipList->keyInfo.type, type, 0);
|
||||
|
||||
if (pCond->start != NULL) {
|
||||
int32_t optr = pCond->start->optr;
|
||||
if (cond.start != NULL) {
|
||||
int32_t optr = cond.start->optr;
|
||||
|
||||
if (optr == TSDB_RELATION_EQUAL) {
|
||||
while(tSkipListIterNext(iter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(iter);
|
||||
|
||||
int32_t ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &pCond->start->v.i64Key);
|
||||
int32_t ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.start->v.i64Key);
|
||||
if (ret == 0) {
|
||||
taosArrayPush(result, SL_GET_NODE_DATA(pNode));
|
||||
} else {
|
||||
|
@ -567,7 +578,7 @@ static void tQueryOnSkipList(SSkipList* pSkipList, SQueryCond* pCond, int32_t ty
|
|||
SSkipListNode* pNode = tSkipListIterGet(iter);
|
||||
|
||||
if (comp) {
|
||||
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &pCond->start->v.i64Key);
|
||||
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.start->v.i64Key);
|
||||
assert(ret >= 0);
|
||||
}
|
||||
|
||||
|
@ -584,7 +595,7 @@ static void tQueryOnSkipList(SSkipList* pSkipList, SQueryCond* pCond, int32_t ty
|
|||
assert(0);
|
||||
}
|
||||
} else {
|
||||
int32_t optr = pCond->end->optr;
|
||||
int32_t optr = cond.end->optr;
|
||||
|
||||
if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) {
|
||||
bool comp = true;
|
||||
|
@ -594,7 +605,7 @@ static void tQueryOnSkipList(SSkipList* pSkipList, SQueryCond* pCond, int32_t ty
|
|||
SSkipListNode* pNode = tSkipListIterGet(iter);
|
||||
|
||||
if (comp) {
|
||||
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &pCond->end->v.i64Key);
|
||||
ret = func(SL_GET_NODE_KEY(pSkipList, pNode), &cond.end->v.i64Key);
|
||||
assert(ret <= 0);
|
||||
}
|
||||
|
||||
|
@ -609,17 +620,6 @@ static void tQueryOnSkipList(SSkipList* pSkipList, SQueryCond* pCond, int32_t ty
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* qsort comparator
|
||||
* sort the result to ensure meters with the same gid is grouped together
|
||||
*/
|
||||
//static int32_t compareByAddr(const void *pLeft, const void *pRight) {
|
||||
// int64_t p1 = (int64_t) * ((tSkipListNode **)pLeft);
|
||||
// int64_t p2 = (int64_t) * ((tSkipListNode **)pRight);
|
||||
//
|
||||
// DEFAULT_COMP(p1, p2);
|
||||
//}
|
||||
|
||||
int32_t merge(SArray *pLeft, SArray *pRight, SArray *pFinalRes) {
|
||||
// assert(pFinalRes->pRes == 0);
|
||||
//
|
||||
|
@ -770,19 +770,55 @@ static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SBinaryFilte
|
|||
taosArrayCopy(pResult, array);
|
||||
}
|
||||
|
||||
static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSkipList *pSkipList,
|
||||
SBinaryFilterSupp *param) {
|
||||
|
||||
static void tSQLBinaryTraverseOnSkipList(
|
||||
tExprNode *pExpr,
|
||||
SArray *pResult,
|
||||
SSkipList *pSkipList,
|
||||
SBinaryFilterSupp *param
|
||||
) {
|
||||
SSkipListIterator* iter = tSkipListCreateIter(pSkipList);
|
||||
|
||||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||
|
||||
if (filterItem(pExpr, pNode, param)) {
|
||||
taosArrayPush(pResult, SL_GET_NODE_DATA(pNode));
|
||||
}
|
||||
}
|
||||
tSkipListDestroyIter(iter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) {
|
||||
SSkipListIterator* iter = tSkipListCreateIter(pSkipList);
|
||||
|
||||
while (tSkipListIterNext(iter)) {
|
||||
bool addToResult = false;
|
||||
|
||||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||
STable* table = *(STable**) SL_GET_NODE_DATA(pNode);
|
||||
|
||||
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
if (pQueryInfo->optr == TSDB_RELATION_IN) {
|
||||
addToResult = pQueryInfo->compare(table->name, pQueryInfo->q.arr);
|
||||
} else if(pQueryInfo->optr == TSDB_RELATION_LIKE) {
|
||||
addToResult = !pQueryInfo->compare(table->name, pQueryInfo->q.pz);
|
||||
}
|
||||
} else {
|
||||
// TODO: other columns
|
||||
}
|
||||
|
||||
if (addToResult) {
|
||||
taosArrayPush(result, (void*)&table);
|
||||
}
|
||||
}
|
||||
|
||||
tSkipListDestroyIter(iter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// post-root order traverse syntax tree
|
||||
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param) {
|
||||
if (pExpr == NULL) {
|
||||
|
@ -792,97 +828,101 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
|||
tExprNode *pLeft = pExpr->_node.pLeft;
|
||||
tExprNode *pRight = pExpr->_node.pRight;
|
||||
|
||||
// recursive traverse left child branch
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK;
|
||||
|
||||
if (weight == 0 && taosArrayGetSize(result) > 0 && pSkipList == NULL) {
|
||||
/**
|
||||
* Perform the filter operation based on the initial filter result, which is obtained from filtering from index.
|
||||
* Since no index presented, the filter operation is done by scan all elements in the result set.
|
||||
*
|
||||
* if the query is a high selectivity filter, only small portion of meters are retrieved.
|
||||
*/
|
||||
exprTreeTraverseImpl(pExpr, result, param);
|
||||
} else if (weight == 0) {
|
||||
/**
|
||||
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
|
||||
*/
|
||||
assert(taosArrayGetSize(result) == 0);
|
||||
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
|
||||
} else if (weight == 2 || (weight == 1 && pExpr->_node.optr == TSDB_RELATION_OR)) {
|
||||
SArray* rLeft = taosArrayInit(10, POINTER_BYTES);
|
||||
SArray* rRight = taosArrayInit(10, POINTER_BYTES);
|
||||
|
||||
tExprTreeTraverse(pLeft, pSkipList, rLeft, param);
|
||||
tExprTreeTraverse(pRight, pSkipList, rRight, param);
|
||||
|
||||
if (pExpr->_node.optr == TSDB_RELATION_AND) { // CROSS
|
||||
intersect(rLeft, rRight, result);
|
||||
} else if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
|
||||
merge(rLeft, rRight, result);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
taosArrayDestroy(rLeft);
|
||||
taosArrayDestroy(rRight);
|
||||
} else {
|
||||
/*
|
||||
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
|
||||
*
|
||||
* first, we filter results based on the skiplist index, which is the initial filter stage,
|
||||
* then, we conduct the secondary filter operation based on the result from the initial filter stage.
|
||||
*/
|
||||
assert(pExpr->_node.optr == TSDB_RELATION_AND);
|
||||
|
||||
tExprNode *pFirst = NULL;
|
||||
tExprNode *pSecond = NULL;
|
||||
if (pLeft->_node.hasPK == 1) {
|
||||
pFirst = pLeft;
|
||||
pSecond = pRight;
|
||||
} else {
|
||||
pFirst = pRight;
|
||||
pSecond = pLeft;
|
||||
}
|
||||
|
||||
assert(pFirst != pSecond && pFirst != NULL && pSecond != NULL);
|
||||
|
||||
// we filter the result based on the skiplist index in the first place
|
||||
tExprTreeTraverse(pFirst, pSkipList, result, param);
|
||||
|
||||
/*
|
||||
* recursively perform the filter operation based on the initial results,
|
||||
* So, we do not set the skip list index as a parameter
|
||||
*/
|
||||
tExprTreeTraverse(pSecond, NULL, result, param);
|
||||
}
|
||||
} else { // column project
|
||||
// column project
|
||||
if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) {
|
||||
assert(pLeft->nodeType == TSQL_NODE_COL && pRight->nodeType == TSQL_NODE_VALUE);
|
||||
|
||||
param->setupInfoFn(pExpr, param->pExtInfo);
|
||||
if (pSkipList == NULL) {
|
||||
tSQLListTraverseOnResult(pExpr, param->fp, result);
|
||||
} else {
|
||||
tQueryInfo *pQueryInfo = pExpr->_node.info;
|
||||
|
||||
if (pQueryInfo->colIndex == 0 && pQueryInfo->optr != TSDB_RELATION_LIKE) {
|
||||
SQueryCond cond = {0};
|
||||
/*int32_t ret = */ setQueryCond(pQueryInfo, &cond);
|
||||
tQueryOnSkipList(pSkipList, &cond, pQueryInfo->q.nType, result);
|
||||
} else {
|
||||
/* Brutal force scan the whole skip list to find the appropriate result,
|
||||
* since the filter is not applied to indexed column.
|
||||
*/
|
||||
assert(0);
|
||||
// result->num = tSkipListIterateList(pSkipList, (tSkipListNode ***)&result->pRes, fp, queryColInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
tQueryInfo *pQueryInfo = pExpr->_node.info;
|
||||
if (pQueryInfo->colIndex == 0 && pQueryInfo->optr != TSDB_RELATION_LIKE) {
|
||||
tQueryIndexColumn(pSkipList, pQueryInfo, result);
|
||||
} else {
|
||||
tQueryIndexlessColumn(pSkipList, pQueryInfo, result);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// recursive traverse left child branch
|
||||
uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK;
|
||||
|
||||
if (weight == 0 ) {
|
||||
if (taosArrayGetSize(result) > 0 && pSkipList == NULL) {
|
||||
/**
|
||||
* Perform the filter operation based on the initial filter result, which is obtained from filtering from index.
|
||||
* Since no index presented, the filter operation is done by scan all elements in the result set.
|
||||
*
|
||||
* if the query is a high selectivity filter, only small portion of meters are retrieved.
|
||||
*/
|
||||
exprTreeTraverseImpl(pExpr, result, param);
|
||||
} else {
|
||||
/**
|
||||
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
|
||||
*/
|
||||
assert(taosArrayGetSize(result) == 0);
|
||||
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (weight == 2 || (weight == 1 && pExpr->_node.optr == TSDB_RELATION_OR)) {
|
||||
SArray* rLeft = taosArrayInit(10, POINTER_BYTES);
|
||||
SArray* rRight = taosArrayInit(10, POINTER_BYTES);
|
||||
|
||||
tExprTreeTraverse(pLeft, pSkipList, rLeft, param);
|
||||
tExprTreeTraverse(pRight, pSkipList, rRight, param);
|
||||
|
||||
if (pExpr->_node.optr == TSDB_RELATION_AND) { // CROSS
|
||||
intersect(rLeft, rRight, result);
|
||||
} else if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
|
||||
merge(rLeft, rRight, result);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
taosArrayDestroy(rLeft);
|
||||
taosArrayDestroy(rRight);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
|
||||
*
|
||||
* first, we filter results based on the skiplist index, which is the initial filter stage,
|
||||
* then, we conduct the secondary filter operation based on the result from the initial filter stage.
|
||||
*/
|
||||
assert(pExpr->_node.optr == TSDB_RELATION_AND);
|
||||
|
||||
tExprNode *pFirst = NULL;
|
||||
tExprNode *pSecond = NULL;
|
||||
if (pLeft->_node.hasPK == 1) {
|
||||
pFirst = pLeft;
|
||||
pSecond = pRight;
|
||||
} else {
|
||||
pFirst = pRight;
|
||||
pSecond = pLeft;
|
||||
}
|
||||
|
||||
assert(pFirst != pSecond && pFirst != NULL && pSecond != NULL);
|
||||
|
||||
// we filter the result based on the skiplist index in the first place
|
||||
tExprTreeTraverse(pFirst, pSkipList, result, param);
|
||||
|
||||
/*
|
||||
* recursively perform the filter operation based on the initial results,
|
||||
* So, we do not set the skip list index as a parameter
|
||||
*/
|
||||
tExprTreeTraverse(pSecond, NULL, result, param);
|
||||
}
|
||||
|
||||
void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*getSourceDataBlock)(void *, char *, int32_t)) {
|
||||
|
||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*getSourceDataBlock)(void *, const char*, int32_t)) {
|
||||
if (pExprs == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -893,13 +933,13 @@ void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOut
|
|||
/* the left output has result from the left child syntax tree */
|
||||
char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows);
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
||||
tSQLBinaryExprCalcTraverse(pLeft, numOfRows, pLeftOutput, param, order, getSourceDataBlock);
|
||||
tExprTreeCalcTraverse(pLeft, numOfRows, pLeftOutput, param, order, getSourceDataBlock);
|
||||
}
|
||||
|
||||
/* the right output has result from the right child syntax tree */
|
||||
char *pRightOutput = malloc(sizeof(int64_t) * numOfRows);
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
tSQLBinaryExprCalcTraverse(pRight, numOfRows, pRightOutput, param, order, getSourceDataBlock);
|
||||
tExprTreeCalcTraverse(pRight, numOfRows, pRightOutput, param, order, getSourceDataBlock);
|
||||
}
|
||||
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
||||
|
@ -961,7 +1001,7 @@ void tSQLBinaryExprCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOut
|
|||
free(pRightOutput);
|
||||
}
|
||||
|
||||
void tSQLBinaryExprTrv(tExprNode *pExprs, int32_t *val, int16_t *ids) {
|
||||
void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
|
||||
if (pExprs == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -971,17 +1011,15 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, int32_t *val, int16_t *ids) {
|
|||
|
||||
// recursive traverse left child branch
|
||||
if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
||||
tSQLBinaryExprTrv(pLeft, val, ids);
|
||||
tSQLBinaryExprTrv(pLeft, res);
|
||||
} else if (pLeft->nodeType == TSQL_NODE_COL) {
|
||||
ids[*val] = pLeft->pSchema->colId;
|
||||
(*val) += 1;
|
||||
taosArrayPush(res, &pLeft->pSchema->colId);
|
||||
}
|
||||
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
tSQLBinaryExprTrv(pRight, val, ids);
|
||||
tSQLBinaryExprTrv(pRight, res);
|
||||
} else if (pRight->nodeType == TSQL_NODE_COL) {
|
||||
ids[*val] = pRight->pSchema->colId;
|
||||
(*val) += 1;
|
||||
taosArrayPush(res, &pRight->pSchema->colId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1032,49 +1070,143 @@ SBuffer exprTreeToBinary(tExprNode* pExprTree) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void exprTreeFromBinaryImpl(tExprNode** pExprTree, SBuffer* pBuf) {
|
||||
static tExprNode* exprTreeFromBinaryImpl(SBuffer* pBuf) {
|
||||
tExprNode* pExpr = calloc(1, sizeof(tExprNode));
|
||||
tbufReadToBuffer(pBuf, &pExpr->nodeType, sizeof(pExpr->nodeType));
|
||||
pExpr->nodeType = tbufReadUint8(pBuf);
|
||||
|
||||
if (pExpr->nodeType == TSQL_NODE_VALUE) {
|
||||
tVariant* pVal = calloc(1, sizeof(tVariant));
|
||||
if (pVal == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
pExpr->pVal = pVal;
|
||||
|
||||
tbufReadToBuffer(pBuf, &pVal->nType, sizeof(pVal->nType));
|
||||
pVal->nType = tbufReadUint32(pBuf);
|
||||
if (pVal->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
tbufReadToBuffer(pBuf, &pVal->nLen, sizeof(pVal->nLen));
|
||||
pVal->pz = calloc(1, pVal->nLen + 1);
|
||||
tbufReadToBuffer(pBuf, pVal->pz, pVal->nLen);
|
||||
} else {
|
||||
tbufReadToBuffer(pBuf, &pVal->pz, sizeof(pVal->i64Key));
|
||||
pVal->i64Key = tbufReadInt64(pBuf);
|
||||
}
|
||||
|
||||
pExpr->pVal = pVal;
|
||||
} else if (pExpr->nodeType == TSQL_NODE_COL) {
|
||||
SSchema* pSchema = calloc(1, sizeof(SSchema));
|
||||
tbufReadToBuffer(pBuf, &pSchema->colId, sizeof(pSchema->colId));
|
||||
tbufReadToBuffer(pBuf, &pSchema->bytes, sizeof(pSchema->bytes));
|
||||
tbufReadToBuffer(pBuf, &pSchema->type, sizeof(pSchema->type));
|
||||
|
||||
if (pSchema == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
pExpr->pSchema = pSchema;
|
||||
|
||||
pSchema->colId = tbufReadInt16(pBuf);
|
||||
pSchema->bytes = tbufReadInt16(pBuf);
|
||||
pSchema->type = tbufReadUint8(pBuf);
|
||||
tbufReadToString(pBuf, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
|
||||
pExpr->pSchema = pSchema;
|
||||
} else if (pExpr->nodeType == TSQL_NODE_EXPR) {
|
||||
tbufReadToBuffer(pBuf, &pExpr->_node.optr, sizeof(pExpr->_node.optr));
|
||||
tbufReadToBuffer(pBuf, &pExpr->_node.hasPK, sizeof(pExpr->_node.hasPK));
|
||||
|
||||
exprTreeFromBinaryImpl(&pExpr->_node.pLeft, pBuf);
|
||||
exprTreeFromBinaryImpl(&pExpr->_node.pRight, pBuf);
|
||||
pExpr->_node.optr = tbufReadUint8(pBuf);
|
||||
pExpr->_node.hasPK = tbufReadUint8(pBuf);
|
||||
pExpr->_node.pLeft = exprTreeFromBinaryImpl(pBuf);
|
||||
pExpr->_node.pRight = exprTreeFromBinaryImpl(pBuf);
|
||||
|
||||
assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL);
|
||||
}
|
||||
|
||||
*pExprTree = pExpr;
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
int32_t exprTreeFromBinary(const void* pBuf, size_t size, tExprNode** pExprNode) {
|
||||
tExprNode* exprTreeFromBinary(const void* pBuf, size_t size) {
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
SBuffer rbuf = {0};
|
||||
/*int32_t code =*/ tbufBeginRead(&rbuf, pBuf, size);
|
||||
exprTreeFromBinaryImpl(pExprNode, &rbuf);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
tbufBeginRead(&rbuf, pBuf, size);
|
||||
return exprTreeFromBinaryImpl(&rbuf);
|
||||
}
|
||||
|
||||
tExprNode* exprTreeFromTableName(const char* tbnameCond) {
|
||||
if (!tbnameCond) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tExprNode* expr = calloc(1, sizeof(tExprNode));
|
||||
if (expr == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
expr->nodeType = TSQL_NODE_EXPR;
|
||||
|
||||
tExprNode* left = calloc(1, sizeof(tExprNode));
|
||||
if (left == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
expr->_node.pLeft = left;
|
||||
|
||||
left->nodeType = TSQL_NODE_COL;
|
||||
SSchema* pSchema = calloc(1, sizeof(SSchema));
|
||||
if (pSchema == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
left->pSchema = pSchema;
|
||||
|
||||
pSchema->type = TSDB_DATA_TYPE_BINARY;
|
||||
pSchema->bytes = TSDB_TABLE_NAME_LEN;
|
||||
strcpy(pSchema->name, TSQL_TBNAME_L);
|
||||
pSchema->colId = -1;
|
||||
|
||||
tExprNode* right = calloc(1, sizeof(tExprNode));
|
||||
if (right == NULL) {
|
||||
// TODO
|
||||
}
|
||||
expr->_node.pRight = right;
|
||||
|
||||
if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) {
|
||||
right->nodeType = TSQL_NODE_VALUE;
|
||||
expr->_node.optr = TSDB_RELATION_LIKE;
|
||||
tVariant* pVal = calloc(1, sizeof(tVariant));
|
||||
if (pVal == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
right->pVal = pVal;
|
||||
pVal->nType = TSDB_DATA_TYPE_BINARY;
|
||||
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1;
|
||||
pVal->pz = malloc(len);
|
||||
if (pVal->pz == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len);
|
||||
pVal->nLen = (int32_t)len;
|
||||
|
||||
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) {
|
||||
right->nodeType = TSQL_NODE_VALUE;
|
||||
expr->_node.optr = TSDB_RELATION_IN;
|
||||
tVariant* pVal = calloc(1, sizeof(tVariant));
|
||||
if (pVal == NULL) {
|
||||
// TODO:
|
||||
}
|
||||
right->pVal = pVal;
|
||||
pVal->nType = TSDB_DATA_TYPE_ARRAY;
|
||||
pVal->arr = taosArrayInit(2, sizeof(char*));
|
||||
|
||||
const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN;
|
||||
for (const char *e = cond; *e != 0; e++) {
|
||||
if (*e == TS_PATH_DELIMITER[0]) {
|
||||
cond = e + 1;
|
||||
} else if (*e == ',') {
|
||||
size_t len = e - cond + 1;
|
||||
char* p = malloc( len );
|
||||
memcpy(p, cond, len);
|
||||
p[len - 1] = 0;
|
||||
cond += len;
|
||||
taosArrayPush(pVal->arr, &p);
|
||||
}
|
||||
}
|
||||
|
||||
if (*cond != 0) {
|
||||
char* p = strdup( cond );
|
||||
taosArrayPush(pVal->arr, &p);
|
||||
}
|
||||
|
||||
taosArraySortString(pVal->arr);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
|
@ -815,8 +815,7 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI
|
|||
|
||||
pInfo->pDCLInfo->dbOpt = *pDB;
|
||||
pInfo->pDCLInfo->dbOpt.dbname = *pToken;
|
||||
|
||||
tTokenListAppend(pInfo->pDCLInfo, pIgExists);
|
||||
pInfo->pDCLInfo->dbOpt.ignoreExists = (pIgExists != NULL);
|
||||
}
|
||||
|
||||
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,558 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#include "taosmsg.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "queryExecutor.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
bool less_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval < pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool less_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval < pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool less_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval < pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool less_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval < pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool less_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval < pFilter->filterInfo.upperBndd);
|
||||
}
|
||||
|
||||
bool less_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval < pFilter->filterInfo.upperBndd);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
bool large_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool large_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool large_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool large_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool large_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)maxval > pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool large_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)maxval > pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool lessEqual_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval <= pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool lessEqual_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval <= pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool lessEqual_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval <= pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool lessEqual_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval <= pFilter->filterInfo.upperBndi);
|
||||
}
|
||||
|
||||
bool lessEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd);
|
||||
}
|
||||
|
||||
bool lessEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval <= pFilter->filterInfo.upperBndd);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool largeEqual_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool largeEqual_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool largeEqual_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool largeEqual_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool largeEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool largeEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool equal_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int8_t *)minval == *(int8_t *)maxval) {
|
||||
return (*(int8_t *)minval == pFilter->filterInfo.lowerBndi);
|
||||
} else { /* range filter */
|
||||
assert(*(int8_t *)minval < *(int8_t *)maxval);
|
||||
|
||||
return *(int8_t *)minval <= pFilter->filterInfo.lowerBndi && *(int8_t *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int16_t *)minval == *(int16_t *)maxval) {
|
||||
return (*(int16_t *)minval == pFilter->filterInfo.lowerBndi);
|
||||
} else { /* range filter */
|
||||
assert(*(int16_t *)minval < *(int16_t *)maxval);
|
||||
|
||||
return *(int16_t *)minval <= pFilter->filterInfo.lowerBndi && *(int16_t *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int32_t *)minval == *(int32_t *)maxval) {
|
||||
return (*(int32_t *)minval == pFilter->filterInfo.lowerBndi);
|
||||
} else { /* range filter */
|
||||
assert(*(int32_t *)minval < *(int32_t *)maxval);
|
||||
|
||||
return *(int32_t *)minval <= pFilter->filterInfo.lowerBndi && *(int32_t *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int64_t *)minval == *(int64_t *)maxval) {
|
||||
return (*(int64_t *)minval == pFilter->filterInfo.lowerBndi);
|
||||
} else { /* range filter */
|
||||
assert(*(int64_t *)minval < *(int64_t *)maxval);
|
||||
|
||||
return *(int64_t *)minval <= pFilter->filterInfo.lowerBndi && *(int64_t *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(float *)minval == *(float *)maxval) {
|
||||
return (fabs(*(float *)minval - pFilter->filterInfo.lowerBndd) <= FLT_EPSILON);
|
||||
} else { /* range filter */
|
||||
assert(*(float *)minval < *(float *)maxval);
|
||||
return *(float *)minval <= pFilter->filterInfo.lowerBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(double *)minval == *(double *)maxval) {
|
||||
return (*(double *)minval == pFilter->filterInfo.lowerBndd);
|
||||
} else { /* range filter */
|
||||
assert(*(double *)minval < *(double *)maxval);
|
||||
|
||||
return *(double *)minval <= pFilter->filterInfo.lowerBndi && *(double *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||
}
|
||||
}
|
||||
|
||||
bool equal_str(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
// query condition string is greater than the max length of string, not qualified data
|
||||
if (pFilter->filterInfo.len > pFilter->bytes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strncmp((char *)pFilter->filterInfo.pz, minval, pFilter->bytes) == 0;
|
||||
}
|
||||
|
||||
bool equal_nchar(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
// query condition string is greater than the max length of string, not qualified data
|
||||
if (pFilter->filterInfo.len > pFilter->bytes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return wcsncmp((wchar_t *)pFilter->filterInfo.pz, (wchar_t*) minval, pFilter->bytes/TSDB_NCHAR_SIZE) == 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
bool like_str(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
||||
|
||||
return patternMatch((char *)pFilter->filterInfo.pz, minval, pFilter->bytes, &info) == TSDB_PATTERN_MATCH;
|
||||
}
|
||||
|
||||
bool like_nchar(SColumnFilterElem* pFilter, char* minval, char *maxval) {
|
||||
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
||||
|
||||
return WCSPatternMatch((wchar_t*) pFilter->filterInfo.pz, (wchar_t*) minval, pFilter->bytes/TSDB_NCHAR_SIZE, &info) == TSDB_PATTERN_MATCH;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* If minval equals to maxval, it may serve as the one element filter,
|
||||
* or all elements of an array are identical during pref-filter stage.
|
||||
* Otherwise, it must be pre-filter of array list of elements.
|
||||
*
|
||||
* During pre-filter stage, if there is one element that locates in [minval, maxval],
|
||||
* the filter function will return true.
|
||||
*/
|
||||
bool nequal_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int8_t *)minval == *(int8_t *)maxval) {
|
||||
return (*(int8_t *)minval != pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int16_t *)minval == *(int16_t *)maxval) {
|
||||
return (*(int16_t *)minval != pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int32_t *)minval == *(int32_t *)maxval) {
|
||||
return (*(int32_t *)minval != pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(int64_t *)minval == *(int64_t *)maxval) {
|
||||
return (*(int64_t *)minval != pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(float *)minval == *(float *)maxval) {
|
||||
return (*(float *)minval != pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (*(double *)minval == *(double *)maxval) {
|
||||
return (*(double *)minval != pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nequal_str(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
if (pFilter->filterInfo.len > pFilter->bytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return strncmp((char *)pFilter->filterInfo.pz, minval, pFilter->bytes) != 0;
|
||||
}
|
||||
|
||||
bool nequal_nchar(SColumnFilterElem *pFilter, char* minval, char *maxval) {
|
||||
if (pFilter->filterInfo.len > pFilter->bytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return wcsncmp((wchar_t *)pFilter->filterInfo.pz, (wchar_t*)minval, pFilter->bytes/TSDB_NCHAR_SIZE) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
bool rangeFilter_i32_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval <= pFilter->filterInfo.upperBndi && *(int32_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i32_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval<pFilter->filterInfo.upperBndi &&*(int32_t *)maxval> pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i32_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval < pFilter->filterInfo.upperBndi && *(int32_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i32_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int32_t *)minval <= pFilter->filterInfo.upperBndi && *(int32_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool rangeFilter_i8_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval <= pFilter->filterInfo.upperBndi && *(int8_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i8_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval<pFilter->filterInfo.upperBndi &&*(int8_t *)maxval> pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i8_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval < pFilter->filterInfo.upperBndi && *(int8_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i8_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int8_t *)minval <= pFilter->filterInfo.upperBndi && *(int8_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
bool rangeFilter_i16_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval <= pFilter->filterInfo.upperBndi && *(int16_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i16_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval<pFilter->filterInfo.upperBndi &&*(int16_t *)maxval> pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i16_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval < pFilter->filterInfo.upperBndi && *(int16_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i16_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int16_t *)minval <= pFilter->filterInfo.upperBndi && *(int16_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
bool rangeFilter_i64_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval <= pFilter->filterInfo.upperBndi && *(int64_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i64_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval<pFilter->filterInfo.upperBndi &&*(int64_t *)maxval> pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i64_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval < pFilter->filterInfo.upperBndi && *(int64_t *)maxval >= pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
bool rangeFilter_i64_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(int64_t *)minval <= pFilter->filterInfo.upperBndi && *(int64_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
bool rangeFilter_ds_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_ds_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval<pFilter->filterInfo.upperBndd &&*(float *)maxval> pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_ds_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval < pFilter->filterInfo.upperBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_ds_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd && *(float *)maxval > pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool rangeFilter_dd_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval <= pFilter->filterInfo.upperBndd && *(double *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_dd_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval<pFilter->filterInfo.upperBndd &&*(double *)maxval> pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_dd_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval < pFilter->filterInfo.upperBndd && *(double *)maxval >= pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
bool rangeFilter_dd_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||
return (*(double *)minval <= pFilter->filterInfo.upperBndd && *(double *)maxval > pFilter->filterInfo.lowerBndd);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
bool (*filterFunc_i8[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_i8,
|
||||
large_i8,
|
||||
equal_i8,
|
||||
lessEqual_i8,
|
||||
largeEqual_i8,
|
||||
nequal_i8,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_i16[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_i16,
|
||||
large_i16,
|
||||
equal_i16,
|
||||
lessEqual_i16,
|
||||
largeEqual_i16,
|
||||
nequal_i16,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_i32[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_i32,
|
||||
large_i32,
|
||||
equal_i32,
|
||||
lessEqual_i32,
|
||||
largeEqual_i32,
|
||||
nequal_i32,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_i64[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_i64,
|
||||
large_i64,
|
||||
equal_i64,
|
||||
lessEqual_i64,
|
||||
largeEqual_i64,
|
||||
nequal_i64,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_ds[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_ds,
|
||||
large_ds,
|
||||
equal_ds,
|
||||
lessEqual_ds,
|
||||
largeEqual_ds,
|
||||
nequal_ds,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_dd[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
less_dd,
|
||||
large_dd,
|
||||
equal_dd,
|
||||
lessEqual_dd,
|
||||
largeEqual_dd,
|
||||
nequal_dd,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool (*filterFunc_str[])(SColumnFilterElem* pFilter, char* minval, char *maxval) = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
equal_str,
|
||||
NULL,
|
||||
NULL,
|
||||
nequal_str,
|
||||
like_str,
|
||||
};
|
||||
|
||||
bool (*filterFunc_nchar[])(SColumnFilterElem* pFitler, char* minval, char* maxval) = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
equal_nchar,
|
||||
NULL,
|
||||
NULL,
|
||||
nequal_nchar,
|
||||
like_nchar,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_i8[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_i8_ee,
|
||||
rangeFilter_i8_ie,
|
||||
rangeFilter_i8_ei,
|
||||
rangeFilter_i8_ii,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_i16[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_i16_ee,
|
||||
rangeFilter_i16_ie,
|
||||
rangeFilter_i16_ei,
|
||||
rangeFilter_i16_ii,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_i32[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_i32_ee,
|
||||
rangeFilter_i32_ie,
|
||||
rangeFilter_i32_ei,
|
||||
rangeFilter_i32_ii,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_i64[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_i64_ee,
|
||||
rangeFilter_i64_ie,
|
||||
rangeFilter_i64_ei,
|
||||
rangeFilter_i64_ii,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_ds[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_ds_ee,
|
||||
rangeFilter_ds_ie,
|
||||
rangeFilter_ds_ei,
|
||||
rangeFilter_ds_ii,
|
||||
};
|
||||
|
||||
bool (*rangeFilterFunc_dd[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||
NULL,
|
||||
rangeFilter_dd_ee,
|
||||
rangeFilter_dd_ie,
|
||||
rangeFilter_dd_ei,
|
||||
rangeFilter_dd_ii,
|
||||
};
|
||||
|
||||
__filter_func_t* getRangeFilterFuncArray(int32_t type) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_BOOL: return rangeFilterFunc_i8;
|
||||
case TSDB_DATA_TYPE_TINYINT: return rangeFilterFunc_i8;
|
||||
case TSDB_DATA_TYPE_SMALLINT: return rangeFilterFunc_i16;
|
||||
case TSDB_DATA_TYPE_INT: return rangeFilterFunc_i32;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: //timestamp uses bigint filter
|
||||
case TSDB_DATA_TYPE_BIGINT: return rangeFilterFunc_i64;
|
||||
case TSDB_DATA_TYPE_FLOAT: return rangeFilterFunc_ds;
|
||||
case TSDB_DATA_TYPE_DOUBLE: return rangeFilterFunc_dd;
|
||||
default:return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
__filter_func_t* getValueFilterFuncArray(int32_t type) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_BOOL: return filterFunc_i8;
|
||||
case TSDB_DATA_TYPE_TINYINT: return filterFunc_i8;
|
||||
case TSDB_DATA_TYPE_SMALLINT: return filterFunc_i16;
|
||||
case TSDB_DATA_TYPE_INT: return filterFunc_i32;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: //timestamp uses bigint filter
|
||||
case TSDB_DATA_TYPE_BIGINT: return filterFunc_i64;
|
||||
case TSDB_DATA_TYPE_FLOAT: return filterFunc_ds;
|
||||
case TSDB_DATA_TYPE_DOUBLE: return filterFunc_dd;
|
||||
case TSDB_DATA_TYPE_BINARY: return filterFunc_str;
|
||||
case TSDB_DATA_TYPE_NCHAR: return filterFunc_nchar;
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool supportPrefilter(int32_t type) { return type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR; }
|
|
@ -217,11 +217,11 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
|
|||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutputCols; ++i) {
|
||||
for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutput; ++i) {
|
||||
SResultInfo *pResultInfo = &pWindowRes->resultInfo[i];
|
||||
|
||||
char * s = getPosInResultPage(pRuntimeEnv, i, pWindowRes);
|
||||
size_t size = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes;
|
||||
size_t size = pRuntimeEnv->pQuery->pSelectExpr[i].bytes;
|
||||
memset(s, 0, size);
|
||||
|
||||
resetResultInfo(pResultInfo);
|
||||
|
@ -245,7 +245,7 @@ void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, con
|
|||
dst->window = src->window;
|
||||
dst->status = src->status;
|
||||
|
||||
int32_t nOutputCols = pRuntimeEnv->pQuery->numOfOutputCols;
|
||||
int32_t nOutputCols = pRuntimeEnv->pQuery->numOfOutput;
|
||||
|
||||
for (int32_t i = 0; i < nOutputCols; ++i) {
|
||||
SResultInfo *pDst = &dst->resultInfo[i];
|
||||
|
@ -261,7 +261,7 @@ void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, con
|
|||
// copy the output buffer data from src to dst, the position info keep unchanged
|
||||
char * dstBuf = getPosInResultPage(pRuntimeEnv, i, dst);
|
||||
char * srcBuf = getPosInResultPage(pRuntimeEnv, i, (SWindowResult *)src);
|
||||
size_t s = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes;
|
||||
size_t s = pRuntimeEnv->pQuery->pSelectExpr[i].bytes;
|
||||
|
||||
memcpy(dstBuf, srcBuf, s);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t t
|
|||
* @param len
|
||||
* @param type
|
||||
*/
|
||||
void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t type) {
|
||||
void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32_t type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
|
@ -109,10 +109,10 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t
|
|||
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
pVar->pz = strndup(pz, len);
|
||||
pVar->nLen = strdequote(pVar->pz);
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY: { // todo refactor, extract a method
|
||||
pVar->pz = calloc(len, sizeof(char));
|
||||
memcpy(pVar->pz, pz, len);
|
||||
pVar->nLen = len;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -130,6 +130,17 @@ void tVariantDestroy(tVariant *pVar) {
|
|||
tfree(pVar->pz);
|
||||
pVar->nLen = 0;
|
||||
}
|
||||
|
||||
// NOTE: this is only for string array
|
||||
if (pVar->nType == TSDB_DATA_TYPE_ARRAY) {
|
||||
size_t num = taosArrayGetSize(pVar->arr);
|
||||
for(size_t i = 0; i < num; i++) {
|
||||
void* p = taosArrayGetP(pVar->arr, i);
|
||||
free(p);
|
||||
}
|
||||
taosArrayDestroy(pVar->arr);
|
||||
pVar->arr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
|
||||
|
@ -145,6 +156,18 @@ void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
|
|||
|
||||
pDst->pz = calloc(1, len);
|
||||
memcpy(pDst->pz, pSrc->pz, len);
|
||||
return;
|
||||
}
|
||||
|
||||
// this is only for string array
|
||||
if (pSrc->nType == TSDB_DATA_TYPE_ARRAY) {
|
||||
size_t num = taosArrayGetSize(pSrc->arr);
|
||||
pDst->arr = taosArrayInit(num, sizeof(char*));
|
||||
for(size_t i = 0; i < num; i++) {
|
||||
char* p = (char*)taosArrayGetP(pSrc->arr, i);
|
||||
char* n = strdup(p);
|
||||
taosArrayPush(pDst->arr, &n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -556,8 +556,7 @@ void exprSerializeTest1() {
|
|||
ASSERT_TRUE(size > 0);
|
||||
char* b = tbufGetData(&buf, false);
|
||||
|
||||
tExprNode* p2 = NULL;
|
||||
exprTreeFromBinary(b, size, &p2);
|
||||
tExprNode* p2 = exprTreeFromBinary(b, size);
|
||||
ASSERT_EQ(p1->nodeType, p2->nodeType);
|
||||
|
||||
ASSERT_EQ(p2->_node.optr, p1->_node.optr);
|
||||
|
@ -593,8 +592,7 @@ void exprSerializeTest2() {
|
|||
ASSERT_TRUE(size > 0);
|
||||
char* b = tbufGetData(&buf, false);
|
||||
|
||||
tExprNode* p2 = NULL;
|
||||
exprTreeFromBinary(b, size, &p2);
|
||||
tExprNode* p2 = exprTreeFromBinary(b, size);
|
||||
ASSERT_EQ(p1->nodeType, p2->nodeType);
|
||||
|
||||
ASSERT_EQ(p2->_node.optr, p1->_node.optr);
|
||||
|
|
|
@ -58,7 +58,7 @@ TEST(testCase, patternMatchTest) {
|
|||
EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);
|
||||
|
||||
str = "abcdefgabcdeju";
|
||||
ret = patternMatch("abc%f_", str, 1, &info);
|
||||
ret = patternMatch("abc%f_", str, 1, &info); // pattern string is longe than the size
|
||||
EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);
|
||||
|
||||
str = "abcdefgabcdeju";
|
||||
|
@ -72,4 +72,8 @@ TEST(testCase, patternMatchTest) {
|
|||
str = "abcdefgabcdeju";
|
||||
ret = patternMatch("a__", str, 2, &info);
|
||||
EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);
|
||||
|
||||
str = "carzero";
|
||||
ret = patternMatch("%o", str, strlen(str), &info);
|
||||
EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
|
||||
}
|
||||
|
|
|
@ -74,9 +74,12 @@ typedef struct STable {
|
|||
void * pIndex; // For TSDB_SUPER_TABLE, it is the skiplist index
|
||||
void * eventHandler; // TODO
|
||||
void * streamHandler; // TODO
|
||||
TSKEY lastKey; // lastkey inserted in this table, initialized as 0, TODO: make a structure
|
||||
struct STable *next; // TODO: remove the next
|
||||
} STable;
|
||||
|
||||
#define TSDB_GET_TABLE_LAST_KEY(pTable) ((pTable)->lastKey)
|
||||
|
||||
void * tsdbEncodeTable(STable *pTable, int *contLen);
|
||||
STable *tsdbDecodeTable(void *cont, int contLen);
|
||||
void tsdbFreeEncode(void *cont);
|
||||
|
@ -129,9 +132,6 @@ STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
|
|||
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
|
||||
char * getTupleKey(const void *data);
|
||||
|
||||
// ------------------------------ TSDB CACHE INTERFACES ------------------------------
|
||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 * 1024 * 1024 /* 16M */
|
||||
|
||||
typedef struct {
|
||||
int blockId;
|
||||
int offset;
|
||||
|
@ -245,7 +245,7 @@ typedef struct {
|
|||
int32_t len;
|
||||
int32_t offset;
|
||||
int32_t hasLast : 1;
|
||||
int32_t numOfSuperBlocks : 31;
|
||||
int32_t numOfBlocks : 31;
|
||||
int32_t checksum;
|
||||
TSKEY maxKey;
|
||||
} SCompIdx; /* sizeof(SCompIdx) = 24 */
|
||||
|
|
|
@ -26,6 +26,9 @@ STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize, TsdbRepoT *pRepo) {
|
|||
if (pCache == NULL) return NULL;
|
||||
|
||||
if (cacheBlockSize < 0) cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||
cacheBlockSize *= (1024 * 1024);
|
||||
|
||||
if (maxBytes < 0) maxBytes = cacheBlockSize * TSDB_DEFAULT_TOTAL_BLOCKS;
|
||||
|
||||
pCache->maxBytes = maxBytes;
|
||||
pCache->cacheBlockSize = cacheBlockSize;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tulog.h"
|
||||
#include "talgo.h"
|
||||
#include "tsdb.h"
|
||||
|
@ -11,24 +12,6 @@
|
|||
#define IS_VALID_COMPRESSION(compression) (((compression) >= NO_COMPRESSION) && ((compression) <= TWO_STAGE_COMP))
|
||||
#define TSDB_MIN_ID 0
|
||||
#define TSDB_MAX_ID INT_MAX
|
||||
#define TSDB_MIN_TABLES 4
|
||||
#define TSDB_MAX_TABLES 100000
|
||||
#define TSDB_DEFAULT_TABLES 1000
|
||||
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
||||
#define TSDB_MIN_DAYS_PER_FILE 1
|
||||
#define TSDB_MAX_DAYS_PER_FILE 60
|
||||
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
||||
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
||||
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
||||
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
||||
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
||||
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
||||
#define TSDB_DEFAULT_KEEP 3650
|
||||
#define TSDB_MIN_KEEP 1
|
||||
#define TSDB_MAX_KEEP INT_MAX
|
||||
#define TSDB_DEFAULT_CACHE_SIZE (16 * 1024 * 1024) // 16M
|
||||
#define TSDB_MIN_CACHE_SIZE (4 * 1024 * 1024) // 4M
|
||||
#define TSDB_MAX_CACHE_SIZE (1024 * 1024 * 1024) // 1G
|
||||
|
||||
#define TSDB_CFG_FILE_NAME "CONFIG"
|
||||
#define TSDB_DATA_DIR_NAME "data"
|
||||
|
@ -70,7 +53,6 @@ void tsdbSetDefaultCfg(STsdbCfg *pCfg) {
|
|||
pCfg->minRowsPerFileBlock = -1;
|
||||
pCfg->maxRowsPerFileBlock = -1;
|
||||
pCfg->keep = -1;
|
||||
pCfg->maxCacheSize = -1;
|
||||
pCfg->compression = TWO_STAGE_COMP;
|
||||
}
|
||||
|
||||
|
@ -163,6 +145,34 @@ int32_t tsdbDropRepo(TsdbRepoT *repo) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tsdbRestoreInfo(STsdbRepo *pRepo) {
|
||||
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
||||
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||
SFileGroup *pFGroup = NULL;
|
||||
|
||||
SFileGroupIter iter;
|
||||
SRWHelper rhelper = {0};
|
||||
|
||||
if (tsdbInitReadHelper(&rhelper, pRepo) < 0) goto _err;
|
||||
tsdbInitFileGroupIter(pFileH, &iter, TSDB_ORDER_ASC);
|
||||
while ((pFGroup = tsdbGetFileGroupNext(&iter)) != NULL) {
|
||||
if (tsdbSetAndOpenHelperFile(&rhelper, pFGroup) < 0) goto _err;
|
||||
for (int i = 0; i < pRepo->config.maxTables; i++) {
|
||||
STable * pTable = pMeta->tables[i];
|
||||
SCompIdx *pIdx = &rhelper.pCompIdx[i];
|
||||
|
||||
if (pIdx->offset > 0 && pTable->lastKey < pIdx->maxKey) pTable->lastKey = pIdx->maxKey;
|
||||
}
|
||||
}
|
||||
|
||||
tsdbDestroyHelper(&rhelper);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tsdbDestroyHelper(&rhelper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an existing TSDB storage repository
|
||||
* @param tsdbDir the existing TSDB root directory
|
||||
|
@ -192,7 +202,7 @@ TsdbRepoT *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pRepo->tsdbCache = tsdbInitCache(pRepo->config.maxCacheSize, -1, (TsdbRepoT *)pRepo);
|
||||
pRepo->tsdbCache = tsdbInitCache(-1, -1, (TsdbRepoT *)pRepo);
|
||||
if (pRepo->tsdbCache == NULL) {
|
||||
tsdbFreeMeta(pRepo->tsdbMeta);
|
||||
free(pRepo->rootDir);
|
||||
|
@ -210,6 +220,16 @@ TsdbRepoT *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Restore key from file
|
||||
if (tsdbRestoreInfo(pRepo) < 0) {
|
||||
tsdbFreeCache(pRepo->tsdbCache);
|
||||
tsdbFreeMeta(pRepo->tsdbMeta);
|
||||
tsdbCloseFileH(pRepo->tsdbFileH);
|
||||
free(pRepo->rootDir);
|
||||
free(pRepo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRepo->state = TSDB_REPO_STATE_ACTIVE;
|
||||
|
||||
return (TsdbRepoT *)pRepo;
|
||||
|
@ -612,13 +632,6 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
|
|||
if (pCfg->keep < TSDB_MIN_KEEP || pCfg->keep > TSDB_MAX_KEEP) return -1;
|
||||
}
|
||||
|
||||
// Check maxCacheSize
|
||||
if (pCfg->maxCacheSize == -1) {
|
||||
pCfg->maxCacheSize = TSDB_DEFAULT_CACHE_SIZE;
|
||||
} else {
|
||||
if (pCfg->maxCacheSize < TSDB_MIN_CACHE_SIZE || pCfg->maxCacheSize > TSDB_MAX_CACHE_SIZE) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -755,6 +768,7 @@ static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable
|
|||
tSkipListPut(pTable->mem->pData, pNode);
|
||||
if (key > pTable->mem->keyLast) pTable->mem->keyLast = key;
|
||||
if (key < pTable->mem->keyFirst) pTable->mem->keyFirst = key;
|
||||
if (key > pTable->lastKey) pTable->lastKey = key;
|
||||
|
||||
pTable->mem->numOfPoints = tSkipListGetSize(pTable->mem->pData);
|
||||
|
||||
|
|
|
@ -251,6 +251,18 @@ int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId id, int32_t colId, int16_t*
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name) {
|
||||
STsdbMeta* pMeta = tsdbGetMeta(repo);
|
||||
STable* pTable = tsdbGetTableByUid(pMeta, id.uid);
|
||||
|
||||
*name = strndup(pTable->name, TSDB_TABLE_NAME_LEN);
|
||||
if (*name == NULL) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
|
||||
if (tsdbCheckTableCfg(pCfg) < 0) return -1;
|
||||
|
||||
|
@ -299,6 +311,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
|
|||
|
||||
table->tableId = pCfg->tableId;
|
||||
table->name = strdup(pCfg->name);
|
||||
table->lastKey = 0;
|
||||
if (IS_CREATE_STABLE(pCfg)) { // TSDB_CHILD_TABLE
|
||||
table->type = TSDB_CHILD_TABLE;
|
||||
table->superUid = pCfg->superUid;
|
||||
|
|
|
@ -322,12 +322,12 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
|
|||
|
||||
if (tsdbWriteBlockToFile(pHelper, pWFile, pDataCols, rowsToWrite, &compBlock, isLast, true) < 0) goto _err;
|
||||
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfSuperBlocks) < 0) goto _err;
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks) < 0) goto _err;
|
||||
} else { // (Has old data) AND ((has last block) OR (key overlap)), need to merge the block
|
||||
SCompBlock *pCompBlock = taosbsearch((void *)(&keyFirst), (void *)(pHelper->pCompInfo->blocks),
|
||||
pIdx->numOfSuperBlocks, sizeof(SCompBlock), compareKeyBlock, TD_GE);
|
||||
pIdx->numOfBlocks, sizeof(SCompBlock), compareKeyBlock, TD_GE);
|
||||
|
||||
int blkIdx = (pCompBlock == NULL) ? (pIdx->numOfSuperBlocks - 1) : (pCompBlock - pHelper->pCompInfo->blocks);
|
||||
int blkIdx = (pCompBlock == NULL) ? (pIdx->numOfBlocks - 1) : (pCompBlock - pHelper->pCompInfo->blocks);
|
||||
|
||||
if (pCompBlock == NULL) { // No key overlap, must has last block, just merge with the last block
|
||||
ASSERT(pIdx->hasLast && pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].last);
|
||||
|
@ -362,18 +362,18 @@ int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
|
|||
if ((pHelper->files.nLastF.fd > 0) && (pHelper->hasOldLastBlock)) {
|
||||
if (tsdbLoadCompInfo(pHelper, NULL) < 0) return -1;
|
||||
|
||||
SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + pIdx->numOfSuperBlocks - 1;
|
||||
SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + pIdx->numOfBlocks - 1;
|
||||
ASSERT(pCompBlock->last);
|
||||
|
||||
if (pCompBlock->numOfSubBlocks > 1) {
|
||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfSuperBlocks - 1), NULL) < 0) return -1;
|
||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfBlocks - 1), NULL) < 0) return -1;
|
||||
ASSERT(pHelper->pDataCols[0]->numOfPoints > 0 &&
|
||||
pHelper->pDataCols[0]->numOfPoints < pHelper->config.minRowsPerFileBlock);
|
||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0],
|
||||
pHelper->pDataCols[0]->numOfPoints, &compBlock, true, true) < 0)
|
||||
return -1;
|
||||
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfSuperBlocks - 1) < 0) return -1;
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
||||
|
||||
} else {
|
||||
if (lseek(pHelper->files.lastF.fd, pCompBlock->offset, SEEK_SET) < 0) return -1;
|
||||
|
@ -827,7 +827,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
|
|||
ASSERT(keyFirst <= blockAtIdx(pHelper, blkIdx)->keyLast);
|
||||
|
||||
TSKEY keyLimit =
|
||||
(blkIdx == pIdx->numOfSuperBlocks - 1) ? INT64_MAX : pHelper->pCompInfo->blocks[blkIdx + 1].keyFirst - 1;
|
||||
(blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : pHelper->pCompInfo->blocks[blkIdx + 1].keyFirst - 1;
|
||||
|
||||
// rows1: number of rows must merge in this block
|
||||
int rows1 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, blockAtIdx(pHelper, blkIdx)->keyLast);
|
||||
|
@ -969,7 +969,7 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
|||
if (tsdbAdjustInfoSizeIfNeeded(pHelper, pIdx->len + sizeof(SCompInfo)) < 0) goto _err;
|
||||
|
||||
// Change the offset
|
||||
for (int i = 0; i < pIdx->numOfSuperBlocks; i++) {
|
||||
for (int i = 0; i < pIdx->numOfBlocks; i++) {
|
||||
SCompBlock *pTCompBlock = &pHelper->pCompInfo->blocks[i];
|
||||
if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += sizeof(SCompBlock);
|
||||
}
|
||||
|
@ -984,13 +984,13 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
|||
}
|
||||
pHelper->pCompInfo->blocks[blkIdx] = *pCompBlock;
|
||||
|
||||
pIdx->numOfSuperBlocks++;
|
||||
pIdx->numOfBlocks++;
|
||||
pIdx->len += sizeof(SCompBlock);
|
||||
ASSERT(pIdx->len <= tsizeof(pHelper->pCompInfo));
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].last;
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last;
|
||||
|
||||
if (pIdx->numOfSuperBlocks > 1) {
|
||||
if (pIdx->numOfBlocks > 1) {
|
||||
ASSERT(pHelper->pCompInfo->blocks[0].keyLast < pHelper->pCompInfo->blocks[1].keyFirst);
|
||||
}
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
memmove((void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset + pSCompBlock->len + sizeof(SCompBlock)),
|
||||
(void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset + pSCompBlock->len), tsize);
|
||||
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfSuperBlocks; i++) {
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
||||
SCompBlock *pTCompBlock = &pHelper->pCompInfo->blocks[i];
|
||||
if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += sizeof(SCompBlock);
|
||||
}
|
||||
|
@ -1040,7 +1040,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
pIdx->len += sizeof(SCompBlock);
|
||||
} else { // Need to create two sub-blocks
|
||||
void *ptr = NULL;
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfSuperBlocks; i++) {
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
||||
SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i;
|
||||
if (pTCompBlock->numOfSubBlocks > 1) {
|
||||
ptr = (void *)((char *)(pHelper->pCompInfo) + pTCompBlock->offset + pTCompBlock->len);
|
||||
|
@ -1053,7 +1053,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
size_t tsize = pIdx->len - ((char *)ptr - (char *)(pHelper->pCompInfo));
|
||||
if (tsize > 0) {
|
||||
memmove((void *)((char *)ptr + sizeof(SCompBlock) * 2), ptr, tsize);
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfSuperBlocks; i++) {
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
||||
SCompBlock *pTCompBlock = pHelper->pCompInfo->blocks + i;
|
||||
if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset += (sizeof(SCompBlock) * 2);
|
||||
}
|
||||
|
@ -1074,8 +1074,8 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
pIdx->len += (sizeof(SCompBlock) * 2);
|
||||
}
|
||||
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].last;
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last;
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
|||
(void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset + pSCompBlock->len), tsize);
|
||||
}
|
||||
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfSuperBlocks; i++) {
|
||||
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
||||
SCompBlock *pTCompBlock = &pHelper->pCompInfo->blocks[i];
|
||||
if (pTCompBlock->numOfSubBlocks > 1) pTCompBlock->offset -= (sizeof(SCompBlock) * pSCompBlock->numOfSubBlocks);
|
||||
}
|
||||
|
@ -1112,8 +1112,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
|||
|
||||
*pSCompBlock = *pCompBlock;
|
||||
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfSuperBlocks - 1].last;
|
||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast;
|
||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -189,8 +189,8 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable
|
|||
for (int32_t i = 0; i < pCond->numOfCols; ++i) {
|
||||
SColumnInfoData pDest = {{0}, 0};
|
||||
|
||||
pDest.info = pCond->colList[i].info;
|
||||
pDest.pData = calloc(1, EXTRA_BYTES + bufferCapacity * pCond->colList[i].info.bytes);
|
||||
pDest.info = pCond->colList[i];
|
||||
pDest.pData = calloc(1, EXTRA_BYTES + bufferCapacity * pCond->colList[i].bytes);
|
||||
taosArrayPush(pQueryHandle->pColumns, &pDest);
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
|
|||
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
|
||||
|
||||
SCompIdx* compIndex = &pQueryHandle->rhelper.pCompIdx[pCheckInfo->tableId.tid];
|
||||
if (compIndex->len == 0 || compIndex->numOfSuperBlocks == 0) { // no data block in this file, try next file
|
||||
if (compIndex->len == 0 || compIndex->numOfBlocks == 0) { // no data block in this file, try next file
|
||||
continue;//no data blocks in the file belongs to pCheckInfo->pTable
|
||||
} else {
|
||||
if (pCheckInfo->compSize < compIndex->len) {
|
||||
|
@ -327,7 +327,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
|
|||
TSKEY e = MAX(pCheckInfo->lastKey, pQueryHandle->window.ekey);
|
||||
|
||||
// discard the unqualified data block based on the query time window
|
||||
int32_t start = binarySearchForBlockImpl(pCompInfo->blocks, compIndex->numOfSuperBlocks, s, TSDB_ORDER_ASC);
|
||||
int32_t start = binarySearchForBlockImpl(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC);
|
||||
int32_t end = start;
|
||||
|
||||
if (s > pCompInfo->blocks[start].keyLast) {
|
||||
|
@ -335,7 +335,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo
|
|||
}
|
||||
|
||||
// todo speedup the procedure of located end block
|
||||
while (end < compIndex->numOfSuperBlocks && (pCompInfo->blocks[end].keyFirst <= e)) {
|
||||
while (end < compIndex->numOfBlocks && (pCompInfo->blocks[end].keyFirst <= e)) {
|
||||
end += 1;
|
||||
}
|
||||
|
||||
|
@ -442,11 +442,13 @@ static bool loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock
|
|||
if (!doLoadFileDataBlock(pQueryHandle, pBlock, pCheckInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDataCols* pDataCols = pCheckInfo->pDataCols;
|
||||
|
||||
SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0];
|
||||
assert(pCols->numOfPoints == pBlock->numOfPoints);
|
||||
|
||||
if (pCheckInfo->lastKey > pBlock->keyFirst) {
|
||||
cur->pos =
|
||||
binarySearchForKey(pDataCols->cols[0].pData, pBlock->numOfPoints, pCheckInfo->lastKey, pQueryHandle->order);
|
||||
binarySearchForKey(pCols->cols[0].pData, pBlock->numOfPoints, pCheckInfo->lastKey, pQueryHandle->order);
|
||||
} else {
|
||||
cur->pos = 0;
|
||||
}
|
||||
|
@ -548,8 +550,9 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf
|
|||
SArray* sa) {
|
||||
SQueryFilePos* cur = &pQueryHandle->cur;
|
||||
SDataBlockInfo blockInfo = getTrueDataBlockInfo(pCheckInfo, pBlock);
|
||||
|
||||
SDataCols* pCols = pCheckInfo->pDataCols;
|
||||
|
||||
// pQueryHandle->rhelper.pDataCols[0]->cols[0];
|
||||
SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0];
|
||||
|
||||
int32_t endPos = cur->pos;
|
||||
if (ASCENDING_ORDER_TRAVERSE(pQueryHandle->order) && pQueryHandle->window.ekey > blockInfo.window.ekey) {
|
||||
|
@ -595,10 +598,8 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf
|
|||
SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, j);
|
||||
|
||||
if (pCol->info.colId == colId) {
|
||||
// SDataCol* pDataCol = &pCols->cols[i];
|
||||
// pCol->pData = pQueryHandle->rhelper.pDataCols[0]->cols[i].pData + pCol->info.bytes * start;
|
||||
memmove(pCol->pData, pQueryHandle->rhelper.pDataCols[0]->cols[i].pData + pCol->info.bytes * start,
|
||||
pQueryHandle->realNumOfRows * pCol->info.bytes);
|
||||
memmove(pCol->pData, pQueryHandle->rhelper.pDataCols[0]->cols[i].pData + pCol->info.bytes * start,
|
||||
pQueryHandle->realNumOfRows * pCol->info.bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1082,7 +1083,7 @@ SArray* tsdbRetrieveDataBlock(TsdbQueryHandleT* pQueryHandle, SArray* pIdList) {
|
|||
return pHandle->pColumns;
|
||||
} else {
|
||||
STableBlockInfo* pBlockInfoEx = &pHandle->pDataBlockInfo[pHandle->cur.slot];
|
||||
STableCheckInfo* pCheckInfo = pBlockInfoEx->pTableCheckInfo;
|
||||
STableCheckInfo* pCheckInfo = pBlockInfoEx->pTableCheckInfo;
|
||||
|
||||
SDataBlockInfo binfo = getTrueDataBlockInfo(pCheckInfo, pBlockInfoEx->pBlock.compBlock);
|
||||
assert(pHandle->realNumOfRows <= binfo.rows);
|
||||
|
@ -1132,6 +1133,7 @@ static int32_t getAllTableIdList(STsdbRepo* tsdb, int64_t uid, SArray* list) {
|
|||
taosArrayPush(list, &t);
|
||||
}
|
||||
|
||||
tSkipListDestroyIter(iter);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1211,7 +1213,9 @@ void filterPrepare(void* expr, void* param) {
|
|||
pInfo->compare = getComparFunc(pSchema->type, pCond->nType, pInfo->optr);
|
||||
|
||||
tVariantAssign(&pInfo->q, pCond);
|
||||
tVariantTypeSetType(&pInfo->q, pInfo->sch.type);
|
||||
if (pInfo->optr != TSDB_RELATION_IN) {
|
||||
tVariantTypeSetType(&pInfo->q, pInfo->sch.type);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
|
||||
|
@ -1325,22 +1329,15 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
|
|||
}
|
||||
|
||||
if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table
|
||||
size_t num = taosArrayGetSize(pTableList);
|
||||
|
||||
SArray* sa = taosArrayInit(num, sizeof(SPair));
|
||||
for(int32_t i = 0; i < num; ++i) {
|
||||
SArray* sa = taosArrayInit(size, sizeof(SPair));
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
STable* pTable = taosArrayGetP(pTableList, i);
|
||||
|
||||
SPair p = {.first = pTable};
|
||||
taosArrayPush(sa, &p);
|
||||
}
|
||||
|
||||
taosArrayPush(pTableGroup, &sa);
|
||||
uTrace("all %d tables belong to one group", size);
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
tSidSetDisplay(pTableGroup);
|
||||
#endif
|
||||
} else {
|
||||
STableGroupSupporter *pSupp = (STableGroupSupporter *) calloc(1, sizeof(STableGroupSupporter));
|
||||
pSupp->numOfCols = numOfOrderCols;
|
||||
|
@ -1349,10 +1346,6 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
|
|||
|
||||
taosqsort(pTableList->pData, size, POINTER_BYTES, pSupp, tableGroupComparFn);
|
||||
createTableGroupImpl(pTableGroup, pTableList->pData, size, pSupp, tableGroupComparFn);
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
tSidSetDisplay(pTableGroup);
|
||||
#endif
|
||||
tfree(pSupp);
|
||||
}
|
||||
|
||||
|
@ -1364,16 +1357,26 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
|
|||
|
||||
STable* pTable = *(STable**)(SL_GET_NODE_DATA((SSkipListNode*)pNode));
|
||||
|
||||
char* val = dataRowTuple(pTable->tagVal); // todo not only the first column
|
||||
char* val = NULL;
|
||||
int8_t type = pInfo->sch.type;
|
||||
|
||||
if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
val = pTable->name;
|
||||
type = TSDB_DATA_TYPE_BINARY;
|
||||
} else {
|
||||
val = dataRowTuple(pTable->tagVal); // todo not only the first column
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if (pInfo->q.nType == TSDB_DATA_TYPE_BINARY || pInfo->q.nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
ret = pInfo->compare(val, pInfo->q.pz);
|
||||
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pInfo->optr == TSDB_RELATION_IN) {
|
||||
ret = pInfo->compare(val, pInfo->q.arr);
|
||||
} else {
|
||||
ret = pInfo->compare(val, pInfo->q.pz);
|
||||
}
|
||||
} else {
|
||||
tVariant t = {0};
|
||||
tVariantCreateFromBinary(&t, val, (uint32_t)pInfo->sch.bytes, type);
|
||||
|
||||
ret = pInfo->compare(&t.i64Key, &pInfo->q.i64Key);
|
||||
}
|
||||
|
||||
|
@ -1399,6 +1402,9 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
|
|||
case TSDB_RELATION_LIKE: {
|
||||
return ret == 0;
|
||||
}
|
||||
case TSDB_RELATION_IN: {
|
||||
return ret == 1;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
|
@ -1406,6 +1412,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) {
|
||||
// query according to the binary expression
|
||||
STSchema* pSchema = pSTable->tagSchema;
|
||||
|
@ -1428,12 +1435,23 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr)
|
|||
tExprTreeDestroy(&pExpr, destroyHelper);
|
||||
|
||||
convertQueryResult(pRes, pTableList);
|
||||
taosArrayDestroy(pTableList);
|
||||
free(schema);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbQueryByTagsCond(TsdbRepoT* tsdb, int64_t uid, const char* pTagCond, size_t len, STableGroupInfo* pGroupInfo,
|
||||
SColIndex* pColIndex, int32_t numOfCols) {
|
||||
|
||||
|
||||
int32_t tsdbQueryByTagsCond(
|
||||
TsdbRepoT *tsdb,
|
||||
int64_t uid,
|
||||
const char *pTagCond,
|
||||
size_t len,
|
||||
int16_t tagNameRelType,
|
||||
const char* tbnameCond,
|
||||
STableGroupInfo *pGroupInfo,
|
||||
SColIndex *pColIndex,
|
||||
int32_t numOfCols
|
||||
) {
|
||||
STable* pSTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
|
||||
if (pSTable == NULL) {
|
||||
uError("failed to get stable, uid:%" PRIu64, uid);
|
||||
|
@ -1443,33 +1461,39 @@ int32_t tsdbQueryByTagsCond(TsdbRepoT* tsdb, int64_t uid, const char* pTagCond,
|
|||
SArray* res = taosArrayInit(8, POINTER_BYTES);
|
||||
STSchema* pTagSchema = tsdbGetTableTagSchema(tsdbGetMeta(tsdb), pSTable);
|
||||
|
||||
if (pTagCond == NULL || len == 0) { // no tags condition, all tables created according to this stable are involved
|
||||
// no tags and tbname condition, all child tables of this stable are involved
|
||||
if (tbnameCond == NULL && (pTagCond == NULL || len == 0)) {
|
||||
int32_t ret = getAllTableIdList(tsdb, uid, res);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(res);
|
||||
return ret;
|
||||
if (ret == TSDB_CODE_SUCCESS) {
|
||||
pGroupInfo->numOfTables = taosArrayGetSize(res);
|
||||
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols);
|
||||
}
|
||||
|
||||
pGroupInfo->numOfTables = taosArrayGetSize(res);
|
||||
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols);
|
||||
return ret;
|
||||
}
|
||||
|
||||
tExprNode* pExprNode = NULL;
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
// failed to build expression, no result, return immediately
|
||||
if ((ret = exprTreeFromBinary(pTagCond, len, &pExprNode) != TSDB_CODE_SUCCESS) || (pExprNode == NULL)) {
|
||||
uError("stable:%" PRIu64 ", failed to deserialize expression tree, error exists", uid);
|
||||
taosArrayDestroy(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
doQueryTableList(pSTable, res, pExprNode);
|
||||
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
tExprNode* expr = exprTreeFromTableName(tbnameCond);
|
||||
tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len);
|
||||
if (tagExpr != NULL) {
|
||||
if (expr == NULL) {
|
||||
expr = tagExpr;
|
||||
} else {
|
||||
tExprNode* tbnameExpr = expr;
|
||||
expr = calloc(1, sizeof(tExprNode));
|
||||
expr->nodeType = TSQL_NODE_EXPR;
|
||||
expr->_node.optr = tagNameRelType;
|
||||
expr->_node.pLeft = tagExpr;
|
||||
expr->_node.pRight = tbnameExpr;
|
||||
}
|
||||
}
|
||||
|
||||
doQueryTableList(pSTable, res, expr);
|
||||
pGroupInfo->numOfTables = taosArrayGetSize(res);
|
||||
pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols);
|
||||
|
||||
taosArrayDestroy(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1490,6 +1514,7 @@ int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, int64_t uid, STableGroupInfo* pGro
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
|
||||
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*)queryHandle;
|
||||
if (pQueryHandle == NULL) {
|
||||
|
@ -1523,5 +1548,6 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
|
|||
|
||||
tfree(pQueryHandle->pDataBlockInfo);
|
||||
tsdbDestroyHelper(&pQueryHandle->rhelper);
|
||||
|
||||
tfree(pQueryHandle);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ void* taosArrayPush(SArray* pArray, void* pData);
|
|||
*
|
||||
* @param pArray
|
||||
*/
|
||||
void taosArrayPop(SArray* pArray);
|
||||
void* taosArrayPop(SArray* pArray);
|
||||
|
||||
/**
|
||||
* get the data from array
|
||||
|
@ -61,7 +61,7 @@ void taosArrayPop(SArray* pArray);
|
|||
* @param index
|
||||
* @return
|
||||
*/
|
||||
void* taosArrayGet(SArray* pArray, size_t index);
|
||||
void* taosArrayGet(const SArray* pArray, size_t index);
|
||||
|
||||
/**
|
||||
* get the pointer data from the array
|
||||
|
@ -69,7 +69,7 @@ void* taosArrayGet(SArray* pArray, size_t index);
|
|||
* @param index
|
||||
* @return
|
||||
*/
|
||||
void* taosArrayGetP(SArray* pArray, size_t index);
|
||||
void* taosArrayGetP(const SArray* pArray, size_t index);
|
||||
|
||||
/**
|
||||
* return the size of array
|
||||
|
@ -112,6 +112,34 @@ SArray* taosArrayClone(SArray* pSrc);
|
|||
*/
|
||||
void taosArrayDestroy(SArray* pArray);
|
||||
|
||||
/**
|
||||
* sort the array
|
||||
* @param pArray
|
||||
* @param compar
|
||||
*/
|
||||
void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*));
|
||||
|
||||
/**
|
||||
* sort string array
|
||||
* @param pArray
|
||||
*/
|
||||
void taosArraySortString(SArray* pArray);
|
||||
|
||||
/**
|
||||
* search the array
|
||||
* @param pArray
|
||||
* @param compar
|
||||
* @param key
|
||||
*/
|
||||
void* taosArraySearch(const SArray* pArray, int (*compar)(const void*, const void*), const void* key);
|
||||
|
||||
/**
|
||||
* search the array
|
||||
* @param pArray
|
||||
* @param key
|
||||
*/
|
||||
char* taosArraySearchString(const SArray* pArray, const char* key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -120,7 +120,7 @@ void tbufWriteString(SBuffer* buf, const char* str);
|
|||
TBUFFER_DEFINE_FUNCTION(bool, Bool)
|
||||
TBUFFER_DEFINE_FUNCTION(char, Char)
|
||||
TBUFFER_DEFINE_FUNCTION(int8_t, Int8)
|
||||
TBUFFER_DEFINE_FUNCTION(uint8_t, Unt8)
|
||||
TBUFFER_DEFINE_FUNCTION(uint8_t, Uint8)
|
||||
TBUFFER_DEFINE_FUNCTION(int16_t, Int16)
|
||||
TBUFFER_DEFINE_FUNCTION(uint16_t, Uint16)
|
||||
TBUFFER_DEFINE_FUNCTION(int32_t, Int32)
|
||||
|
|
|
@ -42,9 +42,9 @@ static void median(void *src, size_t size, size_t s, size_t e, const void *param
|
|||
assert(comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) <= 0 && comparFn(elePtrAt(src, size, s), elePtrAt(src, size, e), param) <= 0);
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
tTagsPrints(src[s], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
tTagsPrints(src[mid], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
tTagsPrints(src[e], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
// tTagsPrints(src[s], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
// tTagsPrints(src[mid], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
// tTagsPrints(src[e], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ void* taosArrayInit(size_t size, size_t elemSize) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pArray->pData = calloc(size, elemSize * size);
|
||||
pArray->pData = calloc(size, elemSize);
|
||||
if (pArray->pData == NULL) {
|
||||
free(pArray);
|
||||
return NULL;
|
||||
|
@ -76,20 +76,22 @@ void* taosArrayPush(SArray* pArray, void* pData) {
|
|||
return dst;
|
||||
}
|
||||
|
||||
void taosArrayPop(SArray* pArray) {
|
||||
if (pArray == NULL || pArray->size == 0) {
|
||||
return;
|
||||
}
|
||||
void* taosArrayPop(SArray* pArray) {
|
||||
assert( pArray != NULL );
|
||||
|
||||
if (pArray->size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
pArray->size -= 1;
|
||||
return TARRAY_GET_ELEM(pArray, pArray->size);
|
||||
}
|
||||
|
||||
void* taosArrayGet(SArray* pArray, size_t index) {
|
||||
void* taosArrayGet(const SArray* pArray, size_t index) {
|
||||
assert(index < pArray->size);
|
||||
return TARRAY_GET_ELEM(pArray, index);
|
||||
}
|
||||
|
||||
void* taosArrayGetP(SArray* pArray, size_t index) {
|
||||
void* taosArrayGetP(const SArray* pArray, size_t index) {
|
||||
void* ret = taosArrayGet(pArray, index);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
|
@ -183,3 +185,40 @@ void taosArrayDestroy(SArray* pArray) {
|
|||
free(pArray->pData);
|
||||
free(pArray);
|
||||
}
|
||||
|
||||
void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) {
|
||||
assert(pArray != NULL);
|
||||
assert(compar != NULL);
|
||||
|
||||
qsort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
||||
}
|
||||
|
||||
void* taosArraySearch(const SArray* pArray, int (*compar)(const void*, const void*), const void* key) {
|
||||
assert(pArray != NULL);
|
||||
assert(compar != NULL);
|
||||
assert(key != NULL);
|
||||
|
||||
return bsearch(key, pArray->pData, pArray->size, pArray->elemSize, compar);
|
||||
}
|
||||
|
||||
static int taosArrayCompareString(const void* a, const void* b) {
|
||||
const char* x = *(const char**)a;
|
||||
const char* y = *(const char**)b;
|
||||
return strcmp(x, y);
|
||||
}
|
||||
|
||||
void taosArraySortString(SArray* pArray) {
|
||||
assert(pArray != NULL);
|
||||
qsort(pArray->pData, pArray->size, pArray->elemSize, taosArrayCompareString);
|
||||
}
|
||||
|
||||
char* taosArraySearchString(const SArray* pArray, const char* key) {
|
||||
assert(pArray != NULL);
|
||||
assert(key != NULL);
|
||||
|
||||
void* p = bsearch(&key, pArray->pData, pArray->size, pArray->elemSize, taosArrayCompareString);
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return *(char**)p;
|
||||
}
|
|
@ -1,42 +1,34 @@
|
|||
#include "taosdef.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#include <tarray.h>
|
||||
#include "tutil.h"
|
||||
|
||||
int32_t compareInt32Val(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = GET_INT32_VAL(pLeft) - GET_INT32_VAL(pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight);
|
||||
if (left > right) return 1;
|
||||
if (left < right) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareInt64Val(const void *pLeft, const void *pRight) {
|
||||
int64_t ret = GET_INT64_VAL(pLeft) - GET_INT64_VAL(pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
int64_t left = GET_INT64_VAL(pLeft), right = GET_INT64_VAL(pRight);
|
||||
if (left > right) return 1;
|
||||
if (left < right) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareInt16Val(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = GET_INT16_VAL(pLeft) - GET_INT16_VAL(pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
int16_t left = GET_INT16_VAL(pLeft), right = GET_INT16_VAL(pRight);
|
||||
if (left > right) return 1;
|
||||
if (left < right) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareInt8Val(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = GET_INT8_VAL(pLeft) - GET_INT8_VAL(pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight);
|
||||
if (left > right) return 1;
|
||||
if (left < right) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t compareIntDoubleVal(const void *pLeft, const void *pRight) {
|
||||
|
@ -69,12 +61,7 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
|
|||
}
|
||||
|
||||
int32_t compareStrVal(const void *pLeft, const void *pRight) {
|
||||
int32_t ret = strcmp(pLeft, pRight);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return ret > 0 ? 1 : -1;
|
||||
}
|
||||
return (int32_t)strcmp(pLeft, pRight);
|
||||
}
|
||||
|
||||
int32_t compareWStrVal(const void *pLeft, const void *pRight) {
|
||||
|
@ -228,6 +215,11 @@ static UNUSED_FUNC int32_t compareStrPatternComp(const void* pLeft, const void*
|
|||
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) {
|
||||
const SArray* arr = (const SArray*)pRight;
|
||||
return taosArraySearchString(arr, pLeft) == NULL ? 0 : 1;
|
||||
}
|
||||
|
||||
static UNUSED_FUNC int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
|
||||
SPatternCompareInfo pInfo = {'%', '_'};
|
||||
|
||||
|
@ -250,7 +242,6 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr)
|
|||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
// assert(type == filterDataType);
|
||||
|
||||
if (filterDataType == TSDB_DATA_TYPE_BIGINT || filterDataType == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
comparFn = compareInt64Val;
|
||||
} else if (filterDataType >= TSDB_DATA_TYPE_FLOAT && filterDataType <= TSDB_DATA_TYPE_DOUBLE) {
|
||||
|
@ -259,6 +250,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr)
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
if (filterDataType >= TSDB_DATA_TYPE_BOOL && filterDataType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
comparFn = compareInt32Val;
|
||||
|
@ -267,6 +259,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr)
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
if (filterDataType >= TSDB_DATA_TYPE_BOOL && filterDataType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
|
@ -276,12 +269,18 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr)
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
assert(filterDataType == TSDB_DATA_TYPE_BINARY);
|
||||
|
||||
if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
|
||||
assert(filterDataType == TSDB_DATA_TYPE_BINARY);
|
||||
comparFn = compareStrPatternComp;
|
||||
|
||||
} else if (optr == TSDB_RELATION_IN) {
|
||||
assert(filterDataType == TSDB_DATA_TYPE_ARRAY);
|
||||
comparFn = compareFindStrInArray;
|
||||
|
||||
} else { /* normal relational comparFn */
|
||||
assert(filterDataType == TSDB_DATA_TYPE_BINARY);
|
||||
comparFn = compareStrVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef struct {
|
|||
void *sync;
|
||||
void *events;
|
||||
void *cq; // continuous query
|
||||
int32_t cfgVersion;
|
||||
STsdbCfg tsdbCfg;
|
||||
SSyncCfg syncCfg;
|
||||
SWalCfg walCfg;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue