fix(sync): release SyncNode ref
This commit is contained in:
commit
103a9cd9e8
30
Jenkinsfile2
30
Jenkinsfile2
|
@ -127,6 +127,25 @@ def pre_test(){
|
||||||
'''
|
'''
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
def pre_test_build_mac() {
|
||||||
|
sh '''
|
||||||
|
hostname
|
||||||
|
date
|
||||||
|
'''
|
||||||
|
sh '''
|
||||||
|
cd ${WK}
|
||||||
|
rm -rf debug
|
||||||
|
mkdir debug
|
||||||
|
'''
|
||||||
|
sh '''
|
||||||
|
cd ${WK}/debug
|
||||||
|
cmake ..
|
||||||
|
make -j8
|
||||||
|
'''
|
||||||
|
sh '''
|
||||||
|
date
|
||||||
|
'''
|
||||||
|
}
|
||||||
def pre_test_win(){
|
def pre_test_win(){
|
||||||
bat '''
|
bat '''
|
||||||
hostname
|
hostname
|
||||||
|
@ -334,6 +353,17 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('mac test') {
|
||||||
|
agent{label " Mac_catalina "}
|
||||||
|
steps {
|
||||||
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||||
|
timeout(time: 20, unit: 'MINUTES'){
|
||||||
|
pre_test()
|
||||||
|
pre_test_build_mac()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('linux test') {
|
stage('linux test') {
|
||||||
agent{label " worker03 || slave215 || slave217 || slave219 "}
|
agent{label " worker03 || slave215 || slave217 || slave219 "}
|
||||||
options { skipDefaultCheckout() }
|
options { skipDefaultCheckout() }
|
||||||
|
|
|
@ -174,6 +174,8 @@ cmake .. -G "NMake Makefiles"
|
||||||
nmake
|
nmake
|
||||||
```
|
```
|
||||||
|
|
||||||
|
如果你使用的是 Visual Studio 2022 版本, 脚本 `vcvarsall.bat` 的默认安装路径是 `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat`。
|
||||||
|
|
||||||
### Mac OS X 系统
|
### Mac OS X 系统
|
||||||
|
|
||||||
安装 Xcode 命令行工具和 cmake. 在 Catalina 和 Big Sur 操作系统上,需要安装 XCode 11.4+ 版本。
|
安装 Xcode 命令行工具和 cmake. 在 Catalina 和 Big Sur 操作系统上,需要安装 XCode 11.4+ 版本。
|
||||||
|
|
|
@ -136,7 +136,7 @@ cmake .. -DCPUTYPE=mips64 && cmake --build .
|
||||||
|
|
||||||
### On Windows platform
|
### On Windows platform
|
||||||
|
|
||||||
If you use the Visual Studio 2013, please open a command window by executing "cmd.exe".
|
If you use Visual Studio 2013, please open a command window by executing "cmd.exe".
|
||||||
Please specify "amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
Please specify "amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
||||||
```cmd
|
```cmd
|
||||||
mkdir debug && cd debug
|
mkdir debug && cd debug
|
||||||
|
@ -145,7 +145,7 @@ cmake .. -G "NMake Makefiles"
|
||||||
nmake
|
nmake
|
||||||
```
|
```
|
||||||
|
|
||||||
If you use the Visual Studio 2019 or 2017:
|
If you use Visual Studio 2019 or 2017:
|
||||||
|
|
||||||
please open a command window by executing "cmd.exe".
|
please open a command window by executing "cmd.exe".
|
||||||
Please specify "x64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
Please specify "x64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat.
|
||||||
|
@ -164,6 +164,8 @@ cmake .. -G "NMake Makefiles"
|
||||||
nmake
|
nmake
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you use Visual Studio 2022, the only change is the default path of `vcvarsall.bat`, which is `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat`.
|
||||||
|
|
||||||
### On Mac OS X platform
|
### On Mac OS X platform
|
||||||
|
|
||||||
Please install XCode command line tools and cmake. Verified with XCode 11.4+ on Catalina and Big Sur.
|
Please install XCode command line tools and cmake. Verified with XCode 11.4+ on Catalina and Big Sur.
|
||||||
|
|
|
@ -118,6 +118,7 @@ execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
||||||
# ================================================================================================
|
# ================================================================================================
|
||||||
# googletest
|
# googletest
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
add_subdirectory(googletest EXCLUDE_FROM_ALL)
|
add_subdirectory(googletest EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
gtest
|
gtest
|
||||||
|
@ -259,7 +260,7 @@ if(${BUILD_MSVCREGEX})
|
||||||
SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex)
|
SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex)
|
||||||
endif(${BUILD_MSVCREGEX})
|
endif(${BUILD_MSVCREGEX})
|
||||||
|
|
||||||
# msvcregex
|
# wcwidth
|
||||||
if(${BUILD_WCWIDTH})
|
if(${BUILD_WCWIDTH})
|
||||||
add_library(wcwidth STATIC "")
|
add_library(wcwidth STATIC "")
|
||||||
target_sources(wcwidth
|
target_sources(wcwidth
|
||||||
|
|
|
@ -55,8 +55,9 @@ extern int32_t tMsgDict[];
|
||||||
|
|
||||||
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
|
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
|
||||||
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
|
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
|
||||||
#define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)]
|
#define TMSG_INFO(TYPE) \
|
||||||
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
|
(((TYPE) >= 0 && (TYPE) < TDMT_MAX) ? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] : 0)
|
||||||
|
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
|
||||||
|
|
||||||
typedef uint16_t tmsg_t;
|
typedef uint16_t tmsg_t;
|
||||||
|
|
||||||
|
@ -708,6 +709,7 @@ typedef struct {
|
||||||
int32_t buffer; // MB
|
int32_t buffer; // MB
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
|
int32_t lastRowMem;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
|
@ -736,6 +738,7 @@ typedef struct {
|
||||||
int32_t buffer;
|
int32_t buffer;
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
|
int32_t lastRowMem;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
|
@ -1023,8 +1026,10 @@ typedef struct {
|
||||||
int64_t clusterId;
|
int64_t clusterId;
|
||||||
int64_t rebootTime;
|
int64_t rebootTime;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
int32_t numOfCores;
|
float numOfCores;
|
||||||
int32_t numOfSupportVnodes;
|
int32_t numOfSupportVnodes;
|
||||||
|
int64_t memTotal;
|
||||||
|
int64_t memAvail;
|
||||||
char dnodeEp[TSDB_EP_LEN];
|
char dnodeEp[TSDB_EP_LEN];
|
||||||
SMnodeLoad mload;
|
SMnodeLoad mload;
|
||||||
SQnodeLoad qload;
|
SQnodeLoad qload;
|
||||||
|
@ -1079,6 +1084,7 @@ typedef struct {
|
||||||
int32_t buffer;
|
int32_t buffer;
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
|
int32_t lastRowMem;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
|
@ -1131,6 +1137,7 @@ typedef struct {
|
||||||
int32_t buffer;
|
int32_t buffer;
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
|
int32_t lastRowMem;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
|
|
|
@ -22,8 +22,8 @@ extern "C" {
|
||||||
|
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
|
||||||
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
|
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
|
||||||
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
|
#define setNodeType(nodeptr, nodetype) (((SNode*)(nodeptr))->type = (nodetype))
|
||||||
|
|
||||||
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
|
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_DROP_TABLE_STMT,
|
QUERY_NODE_DROP_TABLE_STMT,
|
||||||
QUERY_NODE_DROP_SUPER_TABLE_STMT,
|
QUERY_NODE_DROP_SUPER_TABLE_STMT,
|
||||||
QUERY_NODE_ALTER_TABLE_STMT,
|
QUERY_NODE_ALTER_TABLE_STMT,
|
||||||
|
QUERY_NODE_ALTER_SUPER_TABLE_STMT,
|
||||||
QUERY_NODE_CREATE_USER_STMT,
|
QUERY_NODE_CREATE_USER_STMT,
|
||||||
QUERY_NODE_ALTER_USER_STMT,
|
QUERY_NODE_ALTER_USER_STMT,
|
||||||
QUERY_NODE_DROP_USER_STMT,
|
QUERY_NODE_DROP_USER_STMT,
|
||||||
|
|
|
@ -82,6 +82,7 @@ typedef struct SScanLogicNode {
|
||||||
typedef struct SJoinLogicNode {
|
typedef struct SJoinLogicNode {
|
||||||
SLogicNode node;
|
SLogicNode node;
|
||||||
EJoinType joinType;
|
EJoinType joinType;
|
||||||
|
SNode* pMergeCondition;
|
||||||
SNode* pOnConditions;
|
SNode* pOnConditions;
|
||||||
bool isSingleTableJoin;
|
bool isSingleTableJoin;
|
||||||
} SJoinLogicNode;
|
} SJoinLogicNode;
|
||||||
|
@ -320,6 +321,7 @@ typedef struct SInterpFuncPhysiNode {
|
||||||
SNodeList* pFuncs;
|
SNodeList* pFuncs;
|
||||||
STimeWindow timeRange;
|
STimeWindow timeRange;
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
|
int8_t intervalUnit;
|
||||||
EFillMode fillMode;
|
EFillMode fillMode;
|
||||||
SNode* pFillValues; // SNodeListNode
|
SNode* pFillValues; // SNodeListNode
|
||||||
SNode* pTimeSeries; // SColumnNode
|
SNode* pTimeSeries; // SColumnNode
|
||||||
|
@ -328,6 +330,7 @@ typedef struct SInterpFuncPhysiNode {
|
||||||
typedef struct SJoinPhysiNode {
|
typedef struct SJoinPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
EJoinType joinType;
|
EJoinType joinType;
|
||||||
|
SNode* pMergeCondition;
|
||||||
SNode* pOnConditions;
|
SNode* pOnConditions;
|
||||||
SNodeList* pTargets;
|
SNodeList* pTargets;
|
||||||
} SJoinPhysiNode;
|
} SJoinPhysiNode;
|
||||||
|
|
|
@ -376,6 +376,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
|
||||||
typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, COLLECT_COL_TYPE_ALL } ECollectColType;
|
typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, COLLECT_COL_TYPE_ALL } ECollectColType;
|
||||||
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
|
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
|
||||||
SNodeList** pCols);
|
SNodeList** pCols);
|
||||||
|
int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols);
|
||||||
|
|
||||||
typedef bool (*FFuncClassifier)(int32_t funcId);
|
typedef bool (*FFuncClassifier)(int32_t funcId);
|
||||||
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifier classifier, SNodeList** pFuncs);
|
int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifier classifier, SNodeList** pFuncs);
|
||||||
|
|
|
@ -25,6 +25,8 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SFilterInfo SFilterInfo;
|
typedef struct SFilterInfo SFilterInfo;
|
||||||
|
|
||||||
|
int32_t scalarGetOperatorResultType(SDataType left, SDataType right, EOperatorType op, SDataType* pRes);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pNode will be freed in API;
|
pNode will be freed in API;
|
||||||
*pRes need to freed in caller
|
*pRes need to freed in caller
|
||||||
|
|
|
@ -130,7 +130,7 @@ void schedulerStopQueryHb(void *pTrans);
|
||||||
* Free the query job
|
* Free the query job
|
||||||
* @param pJob
|
* @param pJob
|
||||||
*/
|
*/
|
||||||
void schedulerFreeJob(int64_t job, int32_t errCode);
|
void schedulerFreeJob(int64_t* job, int32_t errCode);
|
||||||
|
|
||||||
void schedulerDestroy(void);
|
void schedulerDestroy(void);
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,15 @@ typedef struct {
|
||||||
} SRpcCtx;
|
} SRpcCtx;
|
||||||
|
|
||||||
int32_t rpcInit();
|
int32_t rpcInit();
|
||||||
void rpcCleanup();
|
|
||||||
void * rpcOpen(const SRpcInit *pRpc);
|
void rpcCleanup();
|
||||||
void rpcClose(void *);
|
void *rpcOpen(const SRpcInit *pRpc);
|
||||||
void * rpcMallocCont(int32_t contLen);
|
|
||||||
void rpcFreeCont(void *pCont);
|
void rpcClose(void *);
|
||||||
void * rpcReallocCont(void *ptr, int32_t contLen);
|
void rpcCloseImpl(void *);
|
||||||
|
void *rpcMallocCont(int32_t contLen);
|
||||||
|
void rpcFreeCont(void *pCont);
|
||||||
|
void *rpcReallocCont(void *ptr, int32_t contLen);
|
||||||
|
|
||||||
// Because taosd supports multi-process mode
|
// Because taosd supports multi-process mode
|
||||||
// These functions should not be used on the server side
|
// These functions should not be used on the server side
|
||||||
|
|
|
@ -173,11 +173,12 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341)
|
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341)
|
||||||
#define TSDB_CODE_MND_TOO_MANY_DNODES TAOS_DEF_ERROR_CODE(0, 0x0342)
|
#define TSDB_CODE_MND_TOO_MANY_DNODES TAOS_DEF_ERROR_CODE(0, 0x0342)
|
||||||
#define TSDB_CODE_MND_NO_ENOUGH_DNODES TAOS_DEF_ERROR_CODE(0, 0x0343)
|
#define TSDB_CODE_MND_NO_ENOUGH_DNODES TAOS_DEF_ERROR_CODE(0, 0x0343)
|
||||||
#define TSDB_CODE_MND_INVALID_CLUSTER_CFG TAOS_DEF_ERROR_CODE(0, 0x0344)
|
#define TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0344)
|
||||||
#define TSDB_CODE_MND_INVALID_CLUSTER_ID TAOS_DEF_ERROR_CODE(0, 0x0345)
|
#define TSDB_CODE_MND_INVALID_CLUSTER_CFG TAOS_DEF_ERROR_CODE(0, 0x0345)
|
||||||
#define TSDB_CODE_MND_INVALID_DNODE_CFG TAOS_DEF_ERROR_CODE(0, 0x0346)
|
#define TSDB_CODE_MND_INVALID_CLUSTER_ID TAOS_DEF_ERROR_CODE(0, 0x0346)
|
||||||
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
|
#define TSDB_CODE_MND_INVALID_DNODE_CFG TAOS_DEF_ERROR_CODE(0, 0x0347)
|
||||||
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
|
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0348)
|
||||||
|
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0349)
|
||||||
|
|
||||||
// mnode-node
|
// mnode-node
|
||||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
|
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
|
||||||
|
@ -579,6 +580,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_PAR_INVALID_TABLE_OPTION TAOS_DEF_ERROR_CODE(0, 0x265C)
|
#define TSDB_CODE_PAR_INVALID_TABLE_OPTION TAOS_DEF_ERROR_CODE(0, 0x265C)
|
||||||
#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D)
|
#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D)
|
||||||
#define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E)
|
#define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E)
|
||||||
|
#define TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE TAOS_DEF_ERROR_CODE(0, 0x265F)
|
||||||
|
|
||||||
//planner
|
//planner
|
||||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||||
|
|
|
@ -334,6 +334,9 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
||||||
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
||||||
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
||||||
|
#define TSDB_MIN_DB_LAST_ROW_MEM 1 // MB
|
||||||
|
#define TSDB_MAX_DB_LAST_ROW_MEM 65536
|
||||||
|
#define TSDB_DEFAULT_LAST_ROW_MEM 1
|
||||||
#define TSDB_DB_STREAM_MODE_OFF 0
|
#define TSDB_DB_STREAM_MODE_OFF 0
|
||||||
#define TSDB_DB_STREAM_MODE_ON 1
|
#define TSDB_DB_STREAM_MODE_ON 1
|
||||||
#define TSDB_DEFAULT_DB_STREAM_MODE 0
|
#define TSDB_DEFAULT_DB_STREAM_MODE 0
|
||||||
|
|
|
@ -65,7 +65,7 @@ enum {
|
||||||
typedef struct SAppInstInfo SAppInstInfo;
|
typedef struct SAppInstInfo SAppInstInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* key;
|
char* key;
|
||||||
// statistics
|
// statistics
|
||||||
int32_t reportCnt;
|
int32_t reportCnt;
|
||||||
int32_t connKeyCnt;
|
int32_t connKeyCnt;
|
||||||
|
@ -177,14 +177,14 @@ typedef struct SReqResultInfo {
|
||||||
} SReqResultInfo;
|
} SReqResultInfo;
|
||||||
|
|
||||||
typedef struct SRequestSendRecvBody {
|
typedef struct SRequestSendRecvBody {
|
||||||
tsem_t rspSem; // not used now
|
tsem_t rspSem; // not used now
|
||||||
__taos_async_fn_t queryFp;
|
__taos_async_fn_t queryFp;
|
||||||
__taos_async_fn_t fetchFp;
|
__taos_async_fn_t fetchFp;
|
||||||
void* param;
|
void* param;
|
||||||
SDataBuf requestMsg;
|
SDataBuf requestMsg;
|
||||||
int64_t queryJob; // query job, created according to sql query DAG.
|
int64_t queryJob; // query job, created according to sql query DAG.
|
||||||
int32_t subplanNum;
|
int32_t subplanNum;
|
||||||
SReqResultInfo resInfo;
|
SReqResultInfo resInfo;
|
||||||
} SRequestSendRecvBody;
|
} SRequestSendRecvBody;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -284,6 +284,7 @@ static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) {
|
||||||
extern SAppInfo appInfo;
|
extern SAppInfo appInfo;
|
||||||
extern int32_t clientReqRefPool;
|
extern int32_t clientReqRefPool;
|
||||||
extern int32_t clientConnRefPool;
|
extern int32_t clientConnRefPool;
|
||||||
|
extern void* tscQhandle;
|
||||||
|
|
||||||
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
||||||
|
|
||||||
|
@ -301,7 +302,7 @@ void destroyRequest(SRequestObj* pRequest);
|
||||||
SRequestObj* acquireRequest(int64_t rid);
|
SRequestObj* acquireRequest(int64_t rid);
|
||||||
int32_t releaseRequest(int64_t rid);
|
int32_t releaseRequest(int64_t rid);
|
||||||
int32_t removeRequest(int64_t rid);
|
int32_t removeRequest(int64_t rid);
|
||||||
void doDestroyRequest(void *p);
|
void doDestroyRequest(void* p);
|
||||||
|
|
||||||
char* getDbOfConnection(STscObj* pObj);
|
char* getDbOfConnection(STscObj* pObj);
|
||||||
void setConnectionDB(STscObj* pTscObj, const char* db);
|
void setConnectionDB(STscObj* pTscObj, const char* db);
|
||||||
|
@ -336,8 +337,9 @@ int hbHandleRsp(SClientHbBatchRsp* hbRsp);
|
||||||
// cluster level
|
// cluster level
|
||||||
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
||||||
void appHbMgrCleanup(void);
|
void appHbMgrCleanup(void);
|
||||||
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr);
|
void hbRemoveAppHbMrg(SAppHbMgr** pAppHbMgr);
|
||||||
void closeAllRequests(SHashObj *pRequests);
|
void destroyAllRequests(SHashObj* pRequests);
|
||||||
|
void stopAllRequests(SHashObj* pRequests);
|
||||||
|
|
||||||
// conn level
|
// conn level
|
||||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||||
|
@ -356,6 +358,9 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList); // todo move to clie
|
||||||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); // todo move to xxx
|
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); // todo move to xxx
|
||||||
bool qnodeRequired(SRequestObj* pRequest);
|
bool qnodeRequired(SRequestObj* pRequest);
|
||||||
|
|
||||||
|
void initTscQhandle();
|
||||||
|
void cleanupTscQhandle();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
#include "tsched.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
#define TSC_VAR_NOT_RELEASE 1
|
#define TSC_VAR_NOT_RELEASE 1
|
||||||
|
@ -34,9 +35,20 @@ SAppInfo appInfo;
|
||||||
int32_t clientReqRefPool = -1;
|
int32_t clientReqRefPool = -1;
|
||||||
int32_t clientConnRefPool = -1;
|
int32_t clientConnRefPool = -1;
|
||||||
|
|
||||||
|
void *tscQhandle = NULL;
|
||||||
|
|
||||||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||||
volatile int32_t tscInitRes = 0;
|
volatile int32_t tscInitRes = 0;
|
||||||
|
|
||||||
|
void initTscQhandle() {
|
||||||
|
// init handle
|
||||||
|
tscQhandle = taosInitScheduler(4096, 5, "tsc");
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanupTscQhandle() {
|
||||||
|
// destroy handle
|
||||||
|
taosCleanUpScheduler(tscQhandle);
|
||||||
|
}
|
||||||
static int32_t registerRequest(SRequestObj *pRequest) {
|
static int32_t registerRequest(SRequestObj *pRequest) {
|
||||||
STscObj *pTscObj = acquireTscObj(pRequest->pTscObj->id);
|
STscObj *pTscObj = acquireTscObj(pRequest->pTscObj->id);
|
||||||
if (NULL == pTscObj) {
|
if (NULL == pTscObj) {
|
||||||
|
@ -121,12 +133,31 @@ void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
||||||
return pDnodeConn;
|
return pDnodeConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeAllRequests(SHashObj *pRequests) {
|
void destroyAllRequests(SHashObj *pRequests) {
|
||||||
void *pIter = taosHashIterate(pRequests, NULL);
|
void *pIter = taosHashIterate(pRequests, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
int64_t *rid = pIter;
|
int64_t *rid = pIter;
|
||||||
|
|
||||||
removeRequest(*rid);
|
SRequestObj *pRequest = acquireRequest(*rid);
|
||||||
|
if (pRequest) {
|
||||||
|
destroyRequest(pRequest);
|
||||||
|
releaseRequest(*rid);
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter = taosHashIterate(pRequests, pIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopAllRequests(SHashObj *pRequests) {
|
||||||
|
void *pIter = taosHashIterate(pRequests, NULL);
|
||||||
|
while (pIter != NULL) {
|
||||||
|
int64_t *rid = pIter;
|
||||||
|
|
||||||
|
SRequestObj *pRequest = acquireRequest(*rid);
|
||||||
|
if (pRequest) {
|
||||||
|
taos_stop_query(pRequest);
|
||||||
|
releaseRequest(*rid);
|
||||||
|
}
|
||||||
|
|
||||||
pIter = taosHashIterate(pRequests, pIter);
|
pIter = taosHashIterate(pRequests, pIter);
|
||||||
}
|
}
|
||||||
|
@ -153,12 +184,18 @@ void destroyAppInst(SAppInstInfo *pAppInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyTscObj(void *pObj) {
|
void destroyTscObj(void *pObj) {
|
||||||
|
if (NULL == pObj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
STscObj *pTscObj = pObj;
|
STscObj *pTscObj = pObj;
|
||||||
|
int64_t tscId = pTscObj->id;
|
||||||
|
tscTrace("begin to destroy tscObj %" PRIx64 " p:%p", tscId, pTscObj);
|
||||||
|
|
||||||
SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType};
|
SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType};
|
||||||
hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey);
|
hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey);
|
||||||
int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||||
closeAllRequests(pTscObj->pRequests);
|
destroyAllRequests(pTscObj->pRequests);
|
||||||
schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter);
|
schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter);
|
||||||
tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj,
|
tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj,
|
||||||
pTscObj->pAppInfo->numOfConns);
|
pTscObj->pAppInfo->numOfConns);
|
||||||
|
@ -167,7 +204,9 @@ void destroyTscObj(void *pObj) {
|
||||||
destroyAppInst(pTscObj->pAppInfo);
|
destroyAppInst(pTscObj->pAppInfo);
|
||||||
}
|
}
|
||||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||||
taosMemoryFreeClear(pTscObj);
|
taosMemoryFree(pTscObj);
|
||||||
|
|
||||||
|
tscTrace("end to destroy tscObj %" PRIx64 " p:%p", tscId, pTscObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo) {
|
void *createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo) {
|
||||||
|
@ -261,14 +300,18 @@ int32_t releaseRequest(int64_t rid) { return taosReleaseRef(clientReqRefPool, ri
|
||||||
int32_t removeRequest(int64_t rid) { return taosRemoveRef(clientReqRefPool, rid); }
|
int32_t removeRequest(int64_t rid) { return taosRemoveRef(clientReqRefPool, rid); }
|
||||||
|
|
||||||
void doDestroyRequest(void *p) {
|
void doDestroyRequest(void *p) {
|
||||||
assert(p != NULL);
|
if (NULL == p) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SRequestObj *pRequest = (SRequestObj *)p;
|
SRequestObj *pRequest = (SRequestObj *)p;
|
||||||
|
|
||||||
|
int64_t reqId = pRequest->self;
|
||||||
|
tscTrace("begin to destroy request %" PRIx64 " p:%p", reqId, pRequest);
|
||||||
|
|
||||||
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||||
|
|
||||||
if (pRequest->body.queryJob != 0) {
|
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pRequest->msgBuf);
|
taosMemoryFreeClear(pRequest->msgBuf);
|
||||||
taosMemoryFreeClear(pRequest->sqlstr);
|
taosMemoryFreeClear(pRequest->sqlstr);
|
||||||
|
@ -284,7 +327,9 @@ void doDestroyRequest(void *p) {
|
||||||
if (pRequest->self) {
|
if (pRequest->self) {
|
||||||
deregisterRequest(pRequest);
|
deregisterRequest(pRequest);
|
||||||
}
|
}
|
||||||
taosMemoryFreeClear(pRequest);
|
taosMemoryFree(pRequest);
|
||||||
|
|
||||||
|
tscTrace("end to destroy request %" PRIx64 " p:%p", reqId, pRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyRequest(SRequestObj *pRequest) {
|
void destroyRequest(SRequestObj *pRequest) {
|
||||||
|
@ -292,6 +337,8 @@ void destroyRequest(SRequestObj *pRequest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taos_stop_query(pRequest);
|
||||||
|
|
||||||
removeRequest(pRequest->self);
|
removeRequest(pRequest->self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +346,7 @@ void taos_init_imp(void) {
|
||||||
// In the APIs of other program language, taos_cleanup is not available yet.
|
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||||
atexit(taos_cleanup);
|
atexit(taos_cleanup);
|
||||||
|
initTscQhandle();
|
||||||
errno = TSDB_CODE_SUCCESS;
|
errno = TSDB_CODE_SUCCESS;
|
||||||
taosSeedRand(taosGetTimestampSec());
|
taosSeedRand(taosGetTimestampSec());
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tmsgtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
|
#include "tsched.h"
|
||||||
|
|
||||||
static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet);
|
static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet);
|
||||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest);
|
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest);
|
||||||
|
@ -56,14 +57,14 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i
|
||||||
}
|
}
|
||||||
|
|
||||||
bool chkRequestKilled(void* param) {
|
bool chkRequestKilled(void* param) {
|
||||||
bool killed = false;
|
bool killed = false;
|
||||||
SRequestObj* pRequest = acquireRequest((int64_t)param);
|
SRequestObj* pRequest = acquireRequest((int64_t)param);
|
||||||
if (NULL == pRequest || pRequest->killed) {
|
if (NULL == pRequest || pRequest->killed) {
|
||||||
killed = true;
|
killed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseRequest((int64_t)param);
|
releaseRequest((int64_t)param);
|
||||||
|
|
||||||
return killed;
|
return killed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,9 +646,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
||||||
pRequest->body.resInfo.execRes = res.res;
|
pRequest->body.resInfo.execRes = res.res;
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (pRequest->body.queryJob != 0) {
|
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
pRequest->code = code;
|
pRequest->code = code;
|
||||||
terrno = code;
|
terrno = code;
|
||||||
|
@ -658,9 +657,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
||||||
TDMT_VND_CREATE_TABLE == pRequest->type) {
|
TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||||
|
|
||||||
if (pRequest->body.queryJob != 0) {
|
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pRequest->code = res.code;
|
pRequest->code = res.code;
|
||||||
|
@ -769,7 +766,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) {
|
||||||
code = handleSubmitExecRes(pRequest, pRes->res, pCatalog, &epset);
|
code = handleSubmitExecRes(pRequest, pRes->res, pCatalog, &epset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TDMT_SCH_QUERY:
|
case TDMT_SCH_QUERY:
|
||||||
case TDMT_SCH_MERGE_QUERY: {
|
case TDMT_SCH_MERGE_QUERY: {
|
||||||
code = handleQueryExecRes(pRequest, pRes->res, pCatalog, &epset);
|
code = handleQueryExecRes(pRequest, pRes->res, pCatalog, &epset);
|
||||||
break;
|
break;
|
||||||
|
@ -792,10 +789,7 @@ void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) {
|
||||||
TDMT_VND_CREATE_TABLE == pRequest->type) {
|
TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||||
pRequest->body.resInfo.numOfRows = pResult->numOfRows;
|
pRequest->body.resInfo.numOfRows = pResult->numOfRows;
|
||||||
|
|
||||||
if (pRequest->body.queryJob != 0) {
|
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
|
||||||
pRequest->body.queryJob = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(pResult);
|
taosMemoryFree(pResult);
|
||||||
|
@ -1239,7 +1233,16 @@ void updateTargetEpSet(SMsgSendInfo* pSendInfo, STscObj* pTscObj, SRpcMsg* pMsg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
typedef struct SchedArg {
|
||||||
|
SRpcMsg msg;
|
||||||
|
SEpSet* pEpset;
|
||||||
|
} SchedArg;
|
||||||
|
|
||||||
|
void doProcessMsgFromServer(SSchedMsg* schedMsg) {
|
||||||
|
SchedArg* arg = (SchedArg*)schedMsg->ahandle;
|
||||||
|
SRpcMsg* pMsg = &arg->msg;
|
||||||
|
SEpSet* pEpSet = arg->pEpset;
|
||||||
|
|
||||||
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
|
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
|
||||||
assert(pMsg->info.ahandle != NULL);
|
assert(pMsg->info.ahandle != NULL);
|
||||||
STscObj* pTscObj = NULL;
|
STscObj* pTscObj = NULL;
|
||||||
|
@ -1272,7 +1275,8 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
|
|
||||||
updateTargetEpSet(pSendInfo, pTscObj, pMsg, pEpSet);
|
updateTargetEpSet(pSendInfo, pTscObj, pMsg, pEpSet);
|
||||||
|
|
||||||
SDataBuf buf = {.msgType = pMsg->msgType, .len = pMsg->contLen, .pData = NULL, .handle = pMsg->info.handle, .pEpSet = pEpSet};
|
SDataBuf buf = {
|
||||||
|
.msgType = pMsg->msgType, .len = pMsg->contLen, .pData = NULL, .handle = pMsg->info.handle, .pEpSet = pEpSet};
|
||||||
|
|
||||||
if (pMsg->contLen > 0) {
|
if (pMsg->contLen > 0) {
|
||||||
buf.pData = taosMemoryCalloc(1, pMsg->contLen);
|
buf.pData = taosMemoryCalloc(1, pMsg->contLen);
|
||||||
|
@ -1287,6 +1291,25 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
destroySendMsgInfo(pSendInfo);
|
destroySendMsgInfo(pSendInfo);
|
||||||
|
|
||||||
|
taosMemoryFree(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
|
SSchedMsg schedMsg = {0};
|
||||||
|
|
||||||
|
SEpSet* tEpSet = pEpSet != NULL ? taosMemoryCalloc(1, sizeof(SEpSet)) : NULL;
|
||||||
|
if (tEpSet != NULL) {
|
||||||
|
*tEpSet = *pEpSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
SchedArg* arg = taosMemoryCalloc(1, sizeof(SchedArg));
|
||||||
|
arg->msg = *pMsg;
|
||||||
|
arg->pEpset = tEpSet;
|
||||||
|
|
||||||
|
schedMsg.fp = doProcessMsgFromServer;
|
||||||
|
schedMsg.ahandle = arg;
|
||||||
|
taosScheduleTask(tscQhandle, &schedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, const char* db, uint16_t port) {
|
TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, const char* db, uint16_t port) {
|
||||||
|
@ -1415,7 +1438,7 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU
|
||||||
pParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
pParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||||
tsem_init(&pParam->sem, 0, 0);
|
tsem_init(&pParam->sem, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert ucs4 to native multi-bytes string
|
// convert ucs4 to native multi-bytes string
|
||||||
pResultInfo->convertUcs4 = convertUcs4;
|
pResultInfo->convertUcs4 = convertUcs4;
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,9 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||||
atomic_store_32(&lock, 0);
|
atomic_store_32(&lock, 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function may be called by user or system, or by both simultaneously.
|
// this function may be called by user or system, or by both simultaneously.
|
||||||
void taos_cleanup(void) {
|
void taos_cleanup(void) {
|
||||||
tscInfo("start to cleanup client environment");
|
tscInfo("start to cleanup client environment");
|
||||||
|
|
||||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +72,8 @@ void taos_cleanup(void) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
schedulerDestroy();
|
schedulerDestroy();
|
||||||
|
|
||||||
|
cleanupTscQhandle();
|
||||||
rpcCleanup();
|
rpcCleanup();
|
||||||
|
|
||||||
tscInfo("all local resources released");
|
tscInfo("all local resources released");
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
@ -108,7 +106,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
||||||
if (pObj) {
|
if (pObj) {
|
||||||
int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
|
int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
|
||||||
*rid = pObj->id;
|
*rid = pObj->id;
|
||||||
return (TAOS*)rid;
|
return (TAOS *)rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -196,10 +194,10 @@ void taos_kill_query(TAOS *taos) {
|
||||||
if (NULL == taos) {
|
if (NULL == taos) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int64_t rid = *(int64_t*)taos;
|
|
||||||
|
int64_t rid = *(int64_t *)taos;
|
||||||
STscObj* pTscObj = acquireTscObj(rid);
|
STscObj *pTscObj = acquireTscObj(rid);
|
||||||
closeAllRequests(pTscObj->pRequests);
|
stopAllRequests(pTscObj->pRequests);
|
||||||
releaseTscObj(rid);
|
releaseTscObj(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +242,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else if (TD_RES_TMQ(res)) {
|
} else if (TD_RES_TMQ(res)) {
|
||||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
SMqRspObj * msg = ((SMqRspObj *)res);
|
||||||
SReqResultInfo *pResultInfo;
|
SReqResultInfo *pResultInfo;
|
||||||
if (msg->resIter == -1) {
|
if (msg->resIter == -1) {
|
||||||
pResultInfo = tmqGetNextResInfo(res, true);
|
pResultInfo = tmqGetNextResInfo(res, true);
|
||||||
|
@ -420,7 +418,7 @@ int taos_affected_rows(TAOS_RES *res) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRequestObj *pRequest = (SRequestObj *)res;
|
SRequestObj * pRequest = (SRequestObj *)res;
|
||||||
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
||||||
return pResInfo->numOfRows;
|
return pResInfo->numOfRows;
|
||||||
}
|
}
|
||||||
|
@ -480,9 +478,7 @@ void taos_stop_query(TAOS_RES *res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRequest->body.queryJob) {
|
schedulerFreeJob(&pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED);
|
||||||
schedulerFreeJob(pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
tscDebug("request %" PRIx64 " killed", pRequest->requestId);
|
tscDebug("request %" PRIx64 " killed", pRequest->requestId);
|
||||||
}
|
}
|
||||||
|
@ -606,7 +602,7 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||||
TAOS_FIELD *pField = &pResInfo->userFields[columnIndex];
|
TAOS_FIELD * pField = &pResInfo->userFields[columnIndex];
|
||||||
if (!IS_VAR_DATA_TYPE(pField->type)) {
|
if (!IS_VAR_DATA_TYPE(pField->type)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -650,8 +646,8 @@ const char *taos_get_server_info(TAOS *taos) {
|
||||||
typedef struct SqlParseWrapper {
|
typedef struct SqlParseWrapper {
|
||||||
SParseContext *pCtx;
|
SParseContext *pCtx;
|
||||||
SCatalogReq catalogReq;
|
SCatalogReq catalogReq;
|
||||||
SRequestObj *pRequest;
|
SRequestObj * pRequest;
|
||||||
SQuery *pQuery;
|
SQuery * pQuery;
|
||||||
} SqlParseWrapper;
|
} SqlParseWrapper;
|
||||||
|
|
||||||
static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
|
static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
|
||||||
|
@ -672,8 +668,8 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
|
||||||
tscDebug("enter meta callback, code %s", tstrerror(code));
|
tscDebug("enter meta callback, code %s", tstrerror(code));
|
||||||
|
|
||||||
SqlParseWrapper *pWrapper = (SqlParseWrapper *)param;
|
SqlParseWrapper *pWrapper = (SqlParseWrapper *)param;
|
||||||
SQuery *pQuery = pWrapper->pQuery;
|
SQuery * pQuery = pWrapper->pQuery;
|
||||||
SRequestObj *pRequest = pWrapper->pRequest;
|
SRequestObj * pRequest = pWrapper->pRequest;
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery);
|
code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery);
|
||||||
|
@ -722,31 +718,29 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
**pCxt = (SParseContext){
|
**pCxt = (SParseContext){.requestId = pRequest->requestId,
|
||||||
.requestId = pRequest->requestId,
|
.requestRid = pRequest->self,
|
||||||
.requestRid = pRequest->self,
|
.acctId = pTscObj->acctId,
|
||||||
.acctId = pTscObj->acctId,
|
.db = pRequest->pDb,
|
||||||
.db = pRequest->pDb,
|
.topicQuery = false,
|
||||||
.topicQuery = false,
|
.pSql = pRequest->sqlstr,
|
||||||
.pSql = pRequest->sqlstr,
|
.sqlLen = pRequest->sqlLen,
|
||||||
.sqlLen = pRequest->sqlLen,
|
.pMsg = pRequest->msgBuf,
|
||||||
.pMsg = pRequest->msgBuf,
|
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
.pStmtCb = NULL,
|
||||||
.pStmtCb = NULL,
|
.pUser = pTscObj->user,
|
||||||
.pUser = pTscObj->user,
|
.schemalessType = pTscObj->schemalessType,
|
||||||
.schemalessType = pTscObj->schemalessType,
|
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
.async = true,
|
||||||
.async = true,
|
.svrVer = pTscObj->sVer,
|
||||||
.svrVer = pTscObj->sVer,
|
.nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes)};
|
||||||
.nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes)
|
|
||||||
};
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
||||||
SParseContext *pCxt = NULL;
|
SParseContext *pCxt = NULL;
|
||||||
STscObj *pTscObj = pRequest->pTscObj;
|
STscObj * pTscObj = pRequest->pTscObj;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||||
|
@ -911,10 +905,10 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t rid = *(int64_t*)taos;
|
int64_t rid = *(int64_t *)taos;
|
||||||
const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list
|
const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SRequestObj *pRequest = NULL;
|
SRequestObj * pRequest = NULL;
|
||||||
SCatalogReq catalogReq = {0};
|
SCatalogReq catalogReq = {0};
|
||||||
|
|
||||||
if (NULL == tableNameList) {
|
if (NULL == tableNameList) {
|
||||||
|
|
|
@ -895,7 +895,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
|
||||||
SBlockOrderInfo* pOrder = taosArrayGet(pOrderInfo, 0);
|
SBlockOrderInfo* pOrder = taosArrayGet(pOrderInfo, 0);
|
||||||
|
|
||||||
int64_t p0 = taosGetTimestampUs();
|
int64_t p0 = taosGetTimestampUs();
|
||||||
|
|
||||||
__compar_fn_t fn = getKeyComparFunc(pColInfoData->info.type, pOrder->order);
|
__compar_fn_t fn = getKeyComparFunc(pColInfoData->info.type, pOrder->order);
|
||||||
taosSort(pColInfoData->pData, pDataBlock->info.rows, pColInfoData->info.bytes, fn);
|
taosSort(pColInfoData->pData, pDataBlock->info.rows, pColInfoData->info.bytes, fn);
|
||||||
|
|
||||||
|
@ -923,8 +923,9 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
|
||||||
pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId);
|
pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
terrno = 0;
|
||||||
taosqsort(index, rows, sizeof(int32_t), &helper, dataBlockCompar);
|
taosqsort(index, rows, sizeof(int32_t), &helper, dataBlockCompar);
|
||||||
if(terrno) return terrno;
|
if (terrno) return terrno;
|
||||||
|
|
||||||
int64_t p1 = taosGetTimestampUs();
|
int64_t p1 = taosGetTimestampUs();
|
||||||
|
|
||||||
|
@ -1438,21 +1439,21 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t colDataMoveVarData(SColumnInfoData* pColInfoData, size_t start, size_t end){
|
static int32_t colDataMoveVarData(SColumnInfoData* pColInfoData, size_t start, size_t end) {
|
||||||
int32_t dataOffset = -1;
|
int32_t dataOffset = -1;
|
||||||
int32_t dataLen = 0;
|
int32_t dataLen = 0;
|
||||||
int32_t beigin = start;
|
int32_t beigin = start;
|
||||||
while(beigin < end){
|
while (beigin < end) {
|
||||||
int32_t offset = pColInfoData->varmeta.offset[beigin];
|
int32_t offset = pColInfoData->varmeta.offset[beigin];
|
||||||
if(offset == -1) {
|
if (offset == -1) {
|
||||||
beigin++;
|
beigin++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(start != 0) {
|
if (start != 0) {
|
||||||
pColInfoData->varmeta.offset[beigin] = dataLen;
|
pColInfoData->varmeta.offset[beigin] = dataLen;
|
||||||
}
|
}
|
||||||
char *data = pColInfoData->pData + offset;
|
char* data = pColInfoData->pData + offset;
|
||||||
if(dataOffset == -1) dataOffset = offset; // mark the begin of data
|
if (dataOffset == -1) dataOffset = offset; // mark the begin of data
|
||||||
int32_t type = pColInfoData->info.type;
|
int32_t type = pColInfoData->info.type;
|
||||||
if (type == TSDB_DATA_TYPE_JSON) {
|
if (type == TSDB_DATA_TYPE_JSON) {
|
||||||
dataLen += getJsonValueLen(data);
|
dataLen += getJsonValueLen(data);
|
||||||
|
@ -1461,7 +1462,7 @@ static int32_t colDataMoveVarData(SColumnInfoData* pColInfoData, size_t start, s
|
||||||
}
|
}
|
||||||
beigin++;
|
beigin++;
|
||||||
}
|
}
|
||||||
if(dataOffset > 0){
|
if (dataOffset > 0) {
|
||||||
memmove(pColInfoData->pData, pColInfoData->pData + dataOffset, dataLen);
|
memmove(pColInfoData->pData, pColInfoData->pData + dataOffset, dataLen);
|
||||||
memmove(pColInfoData->varmeta.offset, &pColInfoData->varmeta.offset[start], (end - start) * sizeof(int32_t));
|
memmove(pColInfoData->varmeta.offset, &pColInfoData->varmeta.offset[start], (end - start) * sizeof(int32_t));
|
||||||
}
|
}
|
||||||
|
|
|
@ -947,8 +947,10 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
||||||
if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1;
|
if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1;
|
if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, pReq->updateTime) < 0) return -1;
|
if (tEncodeI64(&encoder, pReq->updateTime) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->numOfCores) < 0) return -1;
|
if (tEncodeFloat(&encoder, pReq->numOfCores) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->numOfSupportVnodes) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->numOfSupportVnodes) < 0) return -1;
|
||||||
|
if (tEncodeI64(&encoder, pReq->memTotal) < 0) return -1;
|
||||||
|
if (tEncodeI64(&encoder, pReq->memAvail) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->dnodeEp) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->dnodeEp) < 0) return -1;
|
||||||
|
|
||||||
// cluster cfg
|
// cluster cfg
|
||||||
|
@ -1008,8 +1010,10 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
||||||
if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1;
|
if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1;
|
if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1;
|
||||||
if (tDecodeI64(&decoder, &pReq->updateTime) < 0) return -1;
|
if (tDecodeI64(&decoder, &pReq->updateTime) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->numOfCores) < 0) return -1;
|
if (tDecodeFloat(&decoder, &pReq->numOfCores) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->numOfSupportVnodes) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->numOfSupportVnodes) < 0) return -1;
|
||||||
|
if (tDecodeI64(&decoder, &pReq->memTotal) < 0) return -1;
|
||||||
|
if (tDecodeI64(&decoder, &pReq->memAvail) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->dnodeEp) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->dnodeEp) < 0) return -1;
|
||||||
|
|
||||||
// cluster cfg
|
// cluster cfg
|
||||||
|
@ -1974,6 +1978,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
|
||||||
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
||||||
|
if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -2015,6 +2020,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
|
||||||
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
||||||
|
if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -2069,6 +2075,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
|
||||||
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
||||||
|
if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -2094,6 +2101,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
|
||||||
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
||||||
|
if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -2679,10 +2687,12 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) {
|
||||||
if (tDecodeI8(&decoder, &pRsp->strict) < 0) return -1;
|
if (tDecodeI8(&decoder, &pRsp->strict) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1;
|
if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1;
|
if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1;
|
||||||
pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention));
|
if (pRsp->numOfRetensions > 0) {
|
||||||
if (pRsp->pRetensions == NULL) {
|
pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention));
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
if (pRsp->pRetensions == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) {
|
for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) {
|
||||||
|
@ -3586,6 +3596,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR
|
||||||
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
||||||
|
if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -3643,6 +3654,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *
|
||||||
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
||||||
|
if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -3665,7 +3677,6 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *
|
||||||
SReplica *pReplica = &pReq->replicas[i];
|
SReplica *pReplica = &pReq->replicas[i];
|
||||||
if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
|
if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1;
|
||||||
pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention));
|
pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention));
|
||||||
if (pReq->pRetensions == NULL) {
|
if (pReq->pRetensions == NULL) {
|
||||||
|
@ -3768,6 +3779,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq
|
||||||
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->pages) < 0) return -1;
|
||||||
|
if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1;
|
||||||
|
@ -3782,7 +3794,6 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq
|
||||||
SReplica *pReplica = &pReq->replicas[i];
|
SReplica *pReplica = &pReq->replicas[i];
|
||||||
if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
|
if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
int32_t tlen = encoder.pos;
|
int32_t tlen = encoder.pos;
|
||||||
|
@ -3799,6 +3810,7 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR
|
||||||
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1;
|
||||||
|
if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1;
|
||||||
|
|
|
@ -67,6 +67,8 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||||
req.updateTime = pMgmt->pData->updateTime;
|
req.updateTime = pMgmt->pData->updateTime;
|
||||||
req.numOfCores = tsNumOfCores;
|
req.numOfCores = tsNumOfCores;
|
||||||
req.numOfSupportVnodes = tsNumOfSupportVnodes;
|
req.numOfSupportVnodes = tsNumOfSupportVnodes;
|
||||||
|
req.memTotal = tsTotalMemoryKB * 1024;
|
||||||
|
req.memAvail = req.memTotal - tsRpcQueueMemoryAllowed - 16 * 1024 * 1024;
|
||||||
tstrncpy(req.dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
tstrncpy(req.dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
||||||
|
|
||||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||||
|
|
|
@ -87,8 +87,8 @@ static SProcQueue *dmInitProcQueue(SProc *proc, char *ptr, int32_t size) {
|
||||||
static void dmCleanupProcQueue(SProcQueue *queue) {}
|
static void dmCleanupProcQueue(SProcQueue *queue) {}
|
||||||
|
|
||||||
static inline int32_t dmPushToProcQueue(SProc *proc, SProcQueue *queue, SRpcMsg *pMsg, EProcFuncType ftype) {
|
static inline int32_t dmPushToProcQueue(SProc *proc, SProcQueue *queue, SRpcMsg *pMsg, EProcFuncType ftype) {
|
||||||
const void *pHead = pMsg;
|
const void * pHead = pMsg;
|
||||||
const void *pBody = pMsg->pCont;
|
const void * pBody = pMsg->pCont;
|
||||||
const int16_t rawHeadLen = sizeof(SRpcMsg);
|
const int16_t rawHeadLen = sizeof(SRpcMsg);
|
||||||
const int32_t rawBodyLen = pMsg->contLen;
|
const int32_t rawBodyLen = pMsg->contLen;
|
||||||
const int16_t headLen = CEIL8(rawHeadLen);
|
const int16_t headLen = CEIL8(rawHeadLen);
|
||||||
|
@ -257,7 +257,7 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
|
||||||
proc->wrapper = pWrapper;
|
proc->wrapper = pWrapper;
|
||||||
proc->name = pWrapper->name;
|
proc->name = pWrapper->name;
|
||||||
|
|
||||||
SShm *shm = &proc->shm;
|
SShm * shm = &proc->shm;
|
||||||
int32_t cstart = 0;
|
int32_t cstart = 0;
|
||||||
int32_t csize = CEIL8(shm->size / 2);
|
int32_t csize = CEIL8(shm->size / 2);
|
||||||
int32_t pstart = csize;
|
int32_t pstart = csize;
|
||||||
|
@ -281,13 +281,13 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *dmConsumChildQueue(void *param) {
|
static void *dmConsumChildQueue(void *param) {
|
||||||
SProc *proc = param;
|
SProc * proc = param;
|
||||||
SMgmtWrapper *pWrapper = proc->wrapper;
|
SMgmtWrapper *pWrapper = proc->wrapper;
|
||||||
SProcQueue *queue = proc->cqueue;
|
SProcQueue * queue = proc->cqueue;
|
||||||
int32_t numOfMsgs = 0;
|
int32_t numOfMsgs = 0;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
EProcFuncType ftype = DND_FUNC_REQ;
|
EProcFuncType ftype = DND_FUNC_REQ;
|
||||||
SRpcMsg *pMsg = NULL;
|
SRpcMsg * pMsg = NULL;
|
||||||
|
|
||||||
dDebug("node:%s, start to consume from cqueue", proc->name);
|
dDebug("node:%s, start to consume from cqueue", proc->name);
|
||||||
do {
|
do {
|
||||||
|
@ -324,13 +324,13 @@ static void *dmConsumChildQueue(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *dmConsumParentQueue(void *param) {
|
static void *dmConsumParentQueue(void *param) {
|
||||||
SProc *proc = param;
|
SProc * proc = param;
|
||||||
SMgmtWrapper *pWrapper = proc->wrapper;
|
SMgmtWrapper *pWrapper = proc->wrapper;
|
||||||
SProcQueue *queue = proc->pqueue;
|
SProcQueue * queue = proc->pqueue;
|
||||||
int32_t numOfMsgs = 0;
|
int32_t numOfMsgs = 0;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
EProcFuncType ftype = DND_FUNC_REQ;
|
EProcFuncType ftype = DND_FUNC_REQ;
|
||||||
SRpcMsg *pMsg = NULL;
|
SRpcMsg * pMsg = NULL;
|
||||||
|
|
||||||
dDebug("node:%s, start to consume from pqueue", proc->name);
|
dDebug("node:%s, start to consume from pqueue", proc->name);
|
||||||
do {
|
do {
|
||||||
|
@ -353,7 +353,7 @@ static void *dmConsumParentQueue(void *param) {
|
||||||
rpcRegisterBrokenLinkArg(pMsg);
|
rpcRegisterBrokenLinkArg(pMsg);
|
||||||
} else if (ftype == DND_FUNC_RELEASE) {
|
} else if (ftype == DND_FUNC_RELEASE) {
|
||||||
dmRemoveProcRpcHandle(proc, pMsg->info.handle);
|
dmRemoveProcRpcHandle(proc, pMsg->info.handle);
|
||||||
rpcReleaseHandle(pMsg->info.handle, (int8_t)pMsg->code);
|
rpcReleaseHandle(&pMsg->info, TAOS_CONN_SERVER);
|
||||||
} else {
|
} else {
|
||||||
dError("node:%s, invalid ftype:%d from pqueue", proc->name, ftype);
|
dError("node:%s, invalid ftype:%d from pqueue", proc->name, ftype);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
|
|
@ -245,7 +245,7 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
|
||||||
SRpcMsg msg = {.code = type, .info = *pHandle};
|
SRpcMsg msg = {.code = type, .info = *pHandle};
|
||||||
dmPutToProcPQueue(&pWrapper->proc, &msg, DND_FUNC_RELEASE);
|
dmPutToProcPQueue(&pWrapper->proc, &msg, DND_FUNC_RELEASE);
|
||||||
} else {
|
} else {
|
||||||
rpcReleaseHandle(pHandle->handle, type);
|
rpcReleaseHandle(pHandle, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,7 @@ static void dmPrintEps(SDnodeData *pData) {
|
||||||
dDebug("print dnode list, num:%d", numOfEps);
|
dDebug("print dnode list, num:%d", numOfEps);
|
||||||
for (int32_t i = 0; i < numOfEps; i++) {
|
for (int32_t i = 0; i < numOfEps; i++) {
|
||||||
SDnodeEp *pEp = taosArrayGet(pData->dnodeEps, i);
|
SDnodeEp *pEp = taosArrayGet(pData->dnodeEps, i);
|
||||||
dDebug("dnode:%d, fqdn:%s port:%u is_mnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode);
|
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,14 @@ void Testbase::InitLog(const char* path) {
|
||||||
tsdbDebugFlag = 0;
|
tsdbDebugFlag = 0;
|
||||||
tsLogEmbedded = 1;
|
tsLogEmbedded = 1;
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
tsRpcQueueMemoryAllowed = 1024 * 1024 * 64;
|
|
||||||
|
|
||||||
taosRemoveDir(path);
|
taosRemoveDir(path);
|
||||||
taosMkDir(path);
|
taosMkDir(path);
|
||||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||||
if (taosInitLog("taosdlog", 1) != 0) {
|
|
||||||
|
taosGetSystemInfo();
|
||||||
|
tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 0.1;
|
||||||
|
if (taosInitLog("taosdlog", 1) != 0) {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,10 @@ typedef struct {
|
||||||
int32_t accessTimes;
|
int32_t accessTimes;
|
||||||
int32_t numOfVnodes;
|
int32_t numOfVnodes;
|
||||||
int32_t numOfSupportVnodes;
|
int32_t numOfSupportVnodes;
|
||||||
int32_t numOfCores;
|
float numOfCores;
|
||||||
|
int64_t memTotal;
|
||||||
|
int64_t memAvail;
|
||||||
|
int64_t memUsed;
|
||||||
EDndReason offlineReason;
|
EDndReason offlineReason;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
char fqdn[TSDB_FQDN_LEN];
|
char fqdn[TSDB_FQDN_LEN];
|
||||||
|
@ -243,6 +246,7 @@ typedef struct {
|
||||||
int32_t buffer;
|
int32_t buffer;
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
|
int32_t lastRowMem;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
|
@ -255,8 +259,8 @@ typedef struct {
|
||||||
int8_t compression;
|
int8_t compression;
|
||||||
int8_t replications;
|
int8_t replications;
|
||||||
int8_t strict;
|
int8_t strict;
|
||||||
int8_t cacheLastRow;
|
|
||||||
int8_t hashMethod; // default is 1
|
int8_t hashMethod; // default is 1
|
||||||
|
int8_t cacheLastRow;
|
||||||
int32_t numOfRetensions;
|
int32_t numOfRetensions;
|
||||||
SArray* pRetensions;
|
SArray* pRetensions;
|
||||||
int8_t schemaless;
|
int8_t schemaless;
|
||||||
|
|
|
@ -30,6 +30,8 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||||
void mndSortVnodeGid(SVgObj *pVgroup);
|
void mndSortVnodeGid(SVgObj *pVgroup);
|
||||||
|
int64_t mndGetVnodesMemory(SMnode *pMnode, int32_t dnodeId);
|
||||||
|
int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||||
|
|
||||||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
||||||
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
||||||
|
|
|
@ -93,6 +93,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.buffer, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.buffer, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pageSize, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pageSize, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pages, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pages, _OVER)
|
||||||
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.lastRowMem, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, _OVER)
|
||||||
|
@ -165,6 +166,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.buffer, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.buffer, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pageSize, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pageSize, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pages, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pages, _OVER)
|
||||||
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.lastRowMem, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, _OVER)
|
||||||
|
@ -230,8 +232,9 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
|
||||||
pOld->cfgVersion = pNew->cfgVersion;
|
pOld->cfgVersion = pNew->cfgVersion;
|
||||||
pOld->vgVersion = pNew->vgVersion;
|
pOld->vgVersion = pNew->vgVersion;
|
||||||
pOld->cfg.buffer = pNew->cfg.buffer;
|
pOld->cfg.buffer = pNew->cfg.buffer;
|
||||||
pOld->cfg.pages = pNew->cfg.pages;
|
|
||||||
pOld->cfg.pageSize = pNew->cfg.pageSize;
|
pOld->cfg.pageSize = pNew->cfg.pageSize;
|
||||||
|
pOld->cfg.pages = pNew->cfg.pages;
|
||||||
|
pOld->cfg.lastRowMem = pNew->cfg.lastRowMem;
|
||||||
pOld->cfg.daysPerFile = pNew->cfg.daysPerFile;
|
pOld->cfg.daysPerFile = pNew->cfg.daysPerFile;
|
||||||
pOld->cfg.daysToKeep0 = pNew->cfg.daysToKeep0;
|
pOld->cfg.daysToKeep0 = pNew->cfg.daysToKeep0;
|
||||||
pOld->cfg.daysToKeep1 = pNew->cfg.daysToKeep1;
|
pOld->cfg.daysToKeep1 = pNew->cfg.daysToKeep1;
|
||||||
|
@ -288,6 +291,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
||||||
if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1;
|
if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1;
|
||||||
if (pCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1;
|
if (pCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1;
|
||||||
if (pCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1;
|
if (pCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1;
|
||||||
|
if (pCfg->lastRowMem < TSDB_MIN_DB_LAST_ROW_MEM || pCfg->lastRowMem > TSDB_MAX_DB_LAST_ROW_MEM) return -1;
|
||||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
|
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
|
||||||
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
|
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
|
||||||
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
|
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
|
||||||
|
@ -336,6 +340,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
||||||
if (pCfg->replications < 0) pCfg->replications = TSDB_DEFAULT_DB_REPLICA;
|
if (pCfg->replications < 0) pCfg->replications = TSDB_DEFAULT_DB_REPLICA;
|
||||||
if (pCfg->strict < 0) pCfg->strict = TSDB_DEFAULT_DB_STRICT;
|
if (pCfg->strict < 0) pCfg->strict = TSDB_DEFAULT_DB_STRICT;
|
||||||
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
|
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
|
||||||
|
if (pCfg->lastRowMem <= 0) pCfg->lastRowMem = TSDB_DEFAULT_LAST_ROW_MEM;
|
||||||
if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0;
|
if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0;
|
||||||
if (pCfg->schemaless < 0) pCfg->schemaless = TSDB_DB_SCHEMALESS_OFF;
|
if (pCfg->schemaless < 0) pCfg->schemaless = TSDB_DB_SCHEMALESS_OFF;
|
||||||
}
|
}
|
||||||
|
@ -434,6 +439,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
||||||
.buffer = pCreate->buffer,
|
.buffer = pCreate->buffer,
|
||||||
.pageSize = pCreate->pageSize,
|
.pageSize = pCreate->pageSize,
|
||||||
.pages = pCreate->pages,
|
.pages = pCreate->pages,
|
||||||
|
.lastRowMem = pCreate->lastRowMem,
|
||||||
.daysPerFile = pCreate->daysPerFile,
|
.daysPerFile = pCreate->daysPerFile,
|
||||||
.daysToKeep0 = pCreate->daysToKeep0,
|
.daysToKeep0 = pCreate->daysToKeep0,
|
||||||
.daysToKeep1 = pCreate->daysToKeep1,
|
.daysToKeep1 = pCreate->daysToKeep1,
|
||||||
|
@ -475,7 +481,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq);
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq);
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) goto _OVER;
|
||||||
|
// mndTransSetSerial(pTrans);
|
||||||
mDebug("trans:%d, used to create db:%s", pTrans->id, pCreate->db);
|
mDebug("trans:%d, used to create db:%s", pTrans->id, pCreate->db);
|
||||||
|
|
||||||
mndTransSetDbName(pTrans, dbObj.name, NULL);
|
mndTransSetDbName(pTrans, dbObj.name, NULL);
|
||||||
|
@ -622,6 +628,11 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pAlter->lastRowMem > 0 && pAlter->lastRowMem != pDb->cfg.lastRowMem) {
|
||||||
|
pDb->cfg.lastRowMem = pAlter->lastRowMem;
|
||||||
|
terrno = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (pAlter->replications > 0 && pAlter->replications != pDb->cfg.replications) {
|
if (pAlter->replications > 0 && pAlter->replications != pDb->cfg.replications) {
|
||||||
#if 1
|
#if 1
|
||||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndPrivilege.h"
|
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
#include "mndPrivilege.h"
|
||||||
#include "mndQnode.h"
|
#include "mndQnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndSnode.h"
|
#include "mndSnode.h"
|
||||||
|
@ -274,15 +274,14 @@ static void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeEps) {
|
||||||
|
|
||||||
SDnodeEp dnodeEp = {0};
|
SDnodeEp dnodeEp = {0};
|
||||||
dnodeEp.id = pDnode->id;
|
dnodeEp.id = pDnode->id;
|
||||||
dnodeEp.isMnode = 0;
|
|
||||||
dnodeEp.ep.port = pDnode->port;
|
dnodeEp.ep.port = pDnode->port;
|
||||||
memcpy(dnodeEp.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
memcpy(dnodeEp.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||||
|
sdbRelease(pSdb, pDnode);
|
||||||
|
|
||||||
|
dnodeEp.isMnode = 0;
|
||||||
if (mndIsMnode(pMnode, pDnode->id)) {
|
if (mndIsMnode(pMnode, pDnode->id)) {
|
||||||
dnodeEp.isMnode = 1;
|
dnodeEp.isMnode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pDnode);
|
|
||||||
taosArrayPush(pDnodeEps, &dnodeEp);
|
taosArrayPush(pDnodeEps, &dnodeEp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,7 +431,8 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!online) {
|
if (!online) {
|
||||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
mInfo("dnode:%d, from offline to online, memory avail:%" PRId64 " total:%" PRId64 " cores:%.2f", pDnode->id,
|
||||||
|
statusReq.memAvail, statusReq.memTotal, statusReq.numOfCores);
|
||||||
} else {
|
} else {
|
||||||
mDebug("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
mDebug("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
||||||
statusReq.dnodeVer, dnodeVer, reboot);
|
statusReq.dnodeVer, dnodeVer, reboot);
|
||||||
|
@ -441,6 +441,8 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
pDnode->rebootTime = statusReq.rebootTime;
|
pDnode->rebootTime = statusReq.rebootTime;
|
||||||
pDnode->numOfCores = statusReq.numOfCores;
|
pDnode->numOfCores = statusReq.numOfCores;
|
||||||
pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
|
pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
|
||||||
|
pDnode->memAvail = statusReq.memAvail;
|
||||||
|
pDnode->memTotal = statusReq.memTotal;
|
||||||
|
|
||||||
SStatusRsp statusRsp = {0};
|
SStatusRsp statusRsp = {0};
|
||||||
statusRsp.dnodeVer = dnodeVer;
|
statusRsp.dnodeVer = dnodeVer;
|
||||||
|
@ -580,7 +582,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
|
||||||
strcpy(info.name, "timezone");
|
strcpy(info.name, "timezone");
|
||||||
snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr);
|
snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr);
|
||||||
taosArrayPush(rsp.variables, &info);
|
taosArrayPush(rsp.variables, &info);
|
||||||
|
|
||||||
strcpy(info.name, "locale");
|
strcpy(info.name, "locale");
|
||||||
snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsLocale);
|
snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsLocale);
|
||||||
taosArrayPush(rsp.variables, &info);
|
taosArrayPush(rsp.variables, &info);
|
||||||
|
|
|
@ -207,6 +207,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
||||||
createReq.buffer = pDb->cfg.buffer;
|
createReq.buffer = pDb->cfg.buffer;
|
||||||
createReq.pageSize = pDb->cfg.pageSize;
|
createReq.pageSize = pDb->cfg.pageSize;
|
||||||
createReq.pages = pDb->cfg.pages;
|
createReq.pages = pDb->cfg.pages;
|
||||||
|
createReq.lastRowMem = pDb->cfg.lastRowMem;
|
||||||
createReq.daysPerFile = pDb->cfg.daysPerFile;
|
createReq.daysPerFile = pDb->cfg.daysPerFile;
|
||||||
createReq.daysToKeep0 = pDb->cfg.daysToKeep0;
|
createReq.daysToKeep0 = pDb->cfg.daysToKeep0;
|
||||||
createReq.daysToKeep1 = pDb->cfg.daysToKeep1;
|
createReq.daysToKeep1 = pDb->cfg.daysToKeep1;
|
||||||
|
@ -274,8 +275,9 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_
|
||||||
SAlterVnodeReq alterReq = {0};
|
SAlterVnodeReq alterReq = {0};
|
||||||
alterReq.vgVersion = pVgroup->version;
|
alterReq.vgVersion = pVgroup->version;
|
||||||
alterReq.buffer = pDb->cfg.buffer;
|
alterReq.buffer = pDb->cfg.buffer;
|
||||||
alterReq.pages = pDb->cfg.pages;
|
|
||||||
alterReq.pageSize = pDb->cfg.pageSize;
|
alterReq.pageSize = pDb->cfg.pageSize;
|
||||||
|
alterReq.pages = pDb->cfg.pages;
|
||||||
|
alterReq.lastRowMem = pDb->cfg.lastRowMem;
|
||||||
alterReq.daysPerFile = pDb->cfg.daysPerFile;
|
alterReq.daysPerFile = pDb->cfg.daysPerFile;
|
||||||
alterReq.daysToKeep0 = pDb->cfg.daysToKeep0;
|
alterReq.daysToKeep0 = pDb->cfg.daysToKeep0;
|
||||||
alterReq.daysToKeep1 = pDb->cfg.daysToKeep1;
|
alterReq.daysToKeep1 = pDb->cfg.daysToKeep1;
|
||||||
|
@ -392,9 +394,10 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
||||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||||
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
||||||
pDnode->numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
pDnode->numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
||||||
|
pDnode->memUsed = mndGetVnodesMemory(pMnode, pDnode->id);
|
||||||
|
|
||||||
mDebug("dnode:%d, vnodes:%d support_vnodes:%d is_mnode:%d online:%d", pDnode->id, pDnode->numOfVnodes,
|
mDebug("dnode:%d, vnodes:%d supportVnodes:%d isMnode:%d online:%d memory avail:%" PRId64 " used:%" PRId64, pDnode->id,
|
||||||
pDnode->numOfSupportVnodes, isMnode, online);
|
pDnode->numOfVnodes, pDnode->numOfSupportVnodes, isMnode, online, pDnode->memAvail, pDnode->memUsed);
|
||||||
|
|
||||||
if (isMnode) {
|
if (isMnode) {
|
||||||
pDnode->numOfVnodes++;
|
pDnode->numOfVnodes++;
|
||||||
|
@ -426,15 +429,7 @@ static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) { return
|
||||||
static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
|
static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
|
||||||
float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes;
|
float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes;
|
||||||
float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes;
|
float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes;
|
||||||
#if 0
|
|
||||||
if (d1Score == d2Score) {
|
|
||||||
return pDnode2->id - pDnode1->id;
|
|
||||||
} else {
|
|
||||||
return d1Score >= d2Score ? 1 : 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return d1Score >= d2Score ? 1 : 0;
|
return d1Score >= d2Score ? 1 : 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndSortVnodeGid(SVgObj *pVgroup) {
|
void mndSortVnodeGid(SVgObj *pVgroup) {
|
||||||
|
@ -447,7 +442,7 @@ void mndSortVnodeGid(SVgObj *pVgroup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
static int32_t mndGetAvailableDnode(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t allocedVnodes = 0;
|
int32_t allocedVnodes = 0;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
@ -470,6 +465,16 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t vgMem = mndGetVgroupMemory(pMnode, pDb, pVgroup);
|
||||||
|
if (pDnode->memAvail - vgMem - pDnode->memUsed <= 0) {
|
||||||
|
mError("db:%s, vgId:%d, no enough memory:%" PRId64 " in dnode:%d, avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vgMem, pDnode->id, pDnode->memAvail, pDnode->memUsed);
|
||||||
|
terrno = TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
pDnode->memUsed += vgMem;
|
||||||
|
}
|
||||||
|
|
||||||
pVgid->dnodeId = pDnode->id;
|
pVgid->dnodeId = pDnode->id;
|
||||||
if (pVgroup->replica == 1) {
|
if (pVgroup->replica == 1) {
|
||||||
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
||||||
|
@ -477,7 +482,8 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
|
||||||
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId);
|
mInfo("db:%s, vgId:%d, vn:%d is alloced, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, v, vgMem, pVgid->dnodeId, pDnode->memAvail, pDnode->memUsed);
|
||||||
pDnode->numOfVnodes++;
|
pDnode->numOfVnodes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +504,7 @@ int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||||
pVgroup->dbUid = pDb->uid;
|
pVgroup->dbUid = pDb->uid;
|
||||||
pVgroup->replica = 1;
|
pVgroup->replica = 1;
|
||||||
|
|
||||||
if (mndGetAvailableDnode(pMnode, pVgroup, pArray) != 0) return -1;
|
if (mndGetAvailableDnode(pMnode, pDb, pVgroup, pArray) != 0) return -1;
|
||||||
|
|
||||||
mInfo("db:%s, sma vgId:%d is alloced", pDb->name, pVgroup->vgId);
|
mInfo("db:%s, sma vgId:%d is alloced", pDb->name, pVgroup->vgId);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -546,8 +552,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
||||||
pVgroup->dbUid = pDb->uid;
|
pVgroup->dbUid = pDb->uid;
|
||||||
pVgroup->replica = pDb->cfg.replications;
|
pVgroup->replica = pDb->cfg.replications;
|
||||||
|
|
||||||
if (mndGetAvailableDnode(pMnode, pVgroup, pArray) != 0) {
|
if (mndGetAvailableDnode(pMnode, pDb, pVgroup, pArray) != 0) {
|
||||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,6 +733,43 @@ int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) {
|
||||||
return numOfVnodes;
|
return numOfVnodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDbInput, SVgObj *pVgroup) {
|
||||||
|
SDbObj *pDb = pDbInput;
|
||||||
|
if (pDbInput == NULL) {
|
||||||
|
pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t vgroupMemroy = (int64_t)pDb->cfg.buffer * 1024 * 1024 + (int64_t)pDb->cfg.pages * pDb->cfg.pageSize * 1024;
|
||||||
|
if (pDb->cfg.cacheLastRow > 0) {
|
||||||
|
vgroupMemroy += (int64_t)pDb->cfg.lastRowMem * 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pDbInput == NULL) {
|
||||||
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
}
|
||||||
|
return vgroupMemroy;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool mndGetVnodeMemroyFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||||
|
SVgObj *pVgroup = pObj;
|
||||||
|
int32_t dnodeId = *(int32_t *)p1;
|
||||||
|
int64_t *pVnodeMemory = (int64_t *)p2;
|
||||||
|
|
||||||
|
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||||
|
if (pVgroup->vnodeGid[v].dnodeId == dnodeId) {
|
||||||
|
*pVnodeMemory += mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t mndGetVnodesMemory(SMnode *pMnode, int32_t dnodeId) {
|
||||||
|
int64_t vnodeMemory = 0;
|
||||||
|
sdbTraverse(pMnode->pSdb, SDB_VGROUP, mndGetVnodeMemroyFp, &dnodeId, &vnodeMemory, NULL);
|
||||||
|
return vnodeMemory;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
@ -807,9 +849,20 @@ int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
if (pDnode->memAvail - vgMem - pDnode->memUsed <= 0) {
|
||||||
|
mError("db:%s, vgId:%d, no enough memory:%" PRId64 " in dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vgMem, pDnode->id, pDnode->memAvail, pDnode->memUsed);
|
||||||
|
terrno = TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
pDnode->memUsed += vgMem;
|
||||||
|
}
|
||||||
|
|
||||||
pVgid->dnodeId = pDnode->id;
|
pVgid->dnodeId = pDnode->id;
|
||||||
pVgid->role = TAOS_SYNC_STATE_ERROR;
|
pVgid->role = TAOS_SYNC_STATE_ERROR;
|
||||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is added", pVgroup->dbName, pVgroup->vgId, pVgroup->replica, pVgid->dnodeId);
|
mInfo("db:%s, vgId:%d, vn:%d is added, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, pVgroup->replica, vgMem, pVgid->dnodeId, pDnode->memAvail, pDnode->memUsed);
|
||||||
|
|
||||||
pVgroup->replica++;
|
pVgroup->replica++;
|
||||||
pDnode->numOfVnodes++;
|
pDnode->numOfVnodes++;
|
||||||
|
@ -835,7 +888,10 @@ int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray
|
||||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||||
if (pVgid->dnodeId == pDnode->id) {
|
if (pVgid->dnodeId == pDnode->id) {
|
||||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
pDnode->memUsed -= vgMem;
|
||||||
|
mInfo("db:%s, vgId:%d, vn:%d is removed, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vn, vgMem, pVgid->dnodeId, pDnode->memAvail, pDnode->memUsed);
|
||||||
pDnode->numOfVnodes--;
|
pDnode->numOfVnodes--;
|
||||||
pVgroup->replica--;
|
pVgroup->replica--;
|
||||||
*pDelVgid = *pVgid;
|
*pDelVgid = *pVgid;
|
||||||
|
@ -1161,6 +1217,17 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
|
||||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
if (pNew1->memAvail - vgMem - pNew1->memUsed <= 0) {
|
||||||
|
mError("db:%s, vgId:%d, no enough memory:%" PRId64 " in dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vgMem, pNew1->id, pNew1->memAvail, pNew1->memUsed);
|
||||||
|
terrno = TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
pNew1->memUsed += vgMem;
|
||||||
|
}
|
||||||
|
|
||||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER;
|
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER;
|
||||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER;
|
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -1173,6 +1240,15 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
|
||||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
if (pNew2->memAvail - vgMem - pNew2->memUsed <= 0) {
|
||||||
|
mError("db:%s, vgId:%d, no enough memory:%" PRId64 " in dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vgMem, pNew2->id, pNew2->memAvail, pNew2->memUsed);
|
||||||
|
terrno = TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
pNew2->memUsed += vgMem;
|
||||||
|
}
|
||||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew2->id) != 0) goto _OVER;
|
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew2->id) != 0) goto _OVER;
|
||||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld2->id) != 0) goto _OVER;
|
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld2->id) != 0) goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -1185,6 +1261,15 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
|
||||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||||
|
if (pNew3->memAvail - vgMem - pNew3->memUsed <= 0) {
|
||||||
|
mError("db:%s, vgId:%d, no enough memory:%" PRId64 " in dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||||
|
pVgroup->dbName, pVgroup->vgId, vgMem, pNew3->id, pNew3->memAvail, pNew3->memUsed);
|
||||||
|
terrno = TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
pNew3->memUsed += vgMem;
|
||||||
|
}
|
||||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew3->id) != 0) goto _OVER;
|
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew3->id) != 0) goto _OVER;
|
||||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld3->id) != 0) goto _OVER;
|
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld3->id) != 0) goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -1415,7 +1500,7 @@ _OVER:
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
||||||
|
@ -1654,9 +1739,9 @@ static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) {
|
static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
int32_t numOfVgroups = 0;
|
int32_t numOfVgroups = 0;
|
||||||
STrans *pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
SHashObj *pBalancedVgroups = NULL;
|
SHashObj *pBalancedVgroups = NULL;
|
||||||
|
|
||||||
pBalancedVgroups = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
pBalancedVgroups = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||||
|
@ -1721,7 +1806,7 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SArray *pArray = NULL;
|
SArray *pArray = NULL;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int64_t curMs = taosGetTimestampMs();
|
int64_t curMs = taosGetTimestampMs();
|
||||||
|
|
||||||
SBalanceVgroupReq req = {0};
|
SBalanceVgroupReq req = {0};
|
||||||
|
@ -1766,7 +1851,7 @@ _OVER:
|
||||||
|
|
||||||
taosArrayDestroy(pArray);
|
taosArrayDestroy(pArray);
|
||||||
return code;
|
return code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid) { return !pVgroup->isTsma && pVgroup->dbUid == dbUid; }
|
bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid) { return !pVgroup->isTsma && pVgroup->dbUid == dbUid; }
|
|
@ -131,7 +131,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||||
hashType = TSDB_DATA_TYPE_BINARY;
|
hashType = TSDB_DATA_TYPE_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_NO_LOCK);
|
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||||
if (hash == NULL) {
|
if (hash == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -83,8 +83,8 @@ int32_t smaBegin(SSma *pSma) {
|
||||||
/**
|
/**
|
||||||
* @brief pre-commit for rollup sma.
|
* @brief pre-commit for rollup sma.
|
||||||
* 1) set trigger stat of rsma timer TASK_TRIGGER_STAT_PAUSED.
|
* 1) set trigger stat of rsma timer TASK_TRIGGER_STAT_PAUSED.
|
||||||
* 2) perform persist task for qTaskInfo
|
* 2) wait all triggered fetch tasks finished
|
||||||
* 3) wait all triggered fetch tasks finished
|
* 3) perform persist task for qTaskInfo
|
||||||
*
|
*
|
||||||
* @param pSma
|
* @param pSma
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
|
@ -102,10 +102,7 @@ static int32_t tdProcessRSmaPreCommitImpl(SSma *pSma) {
|
||||||
// step 1: set persistence task paused
|
// step 1: set persistence task paused
|
||||||
atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_PAUSED);
|
atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_PAUSED);
|
||||||
|
|
||||||
// step 2: perform persist task for qTaskInfo
|
// step 2: wait all triggered fetch tasks finished
|
||||||
tdRSmaPersistExecImpl(pRSmaStat);
|
|
||||||
|
|
||||||
// step 3: wait all triggered fetch tasks finished
|
|
||||||
int32_t nLoops = 0;
|
int32_t nLoops = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (T_REF_VAL_GET(pStat) == 0) {
|
if (T_REF_VAL_GET(pStat) == 0) {
|
||||||
|
@ -121,6 +118,9 @@ static int32_t tdProcessRSmaPreCommitImpl(SSma *pSma) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// step 3: perform persist task for qTaskInfo
|
||||||
|
tdRSmaPersistExecImpl(pRSmaStat);
|
||||||
|
|
||||||
smaDebug("vgId:%d, rsma pre commit succeess", SMA_VID(pSma));
|
smaDebug("vgId:%d, rsma pre commit succeess", SMA_VID(pSma));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -79,7 +79,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
||||||
SJson *pNodeRetentions = tjsonCreateArray();
|
SJson *pNodeRetentions = tjsonCreateArray();
|
||||||
tjsonAddItemToObject(pJson, "retentions", pNodeRetentions);
|
tjsonAddItemToObject(pJson, "retentions", pNodeRetentions);
|
||||||
for (int32_t i = 0; i < nRetention; ++i) {
|
for (int32_t i = 0; i < nRetention; ++i) {
|
||||||
SJson *pNodeRetention = tjsonCreateObject();
|
SJson * pNodeRetention = tjsonCreateObject();
|
||||||
const SRetention *pRetention = pCfg->tsdbCfg.retentions + i;
|
const SRetention *pRetention = pCfg->tsdbCfg.retentions + i;
|
||||||
tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq);
|
tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq);
|
||||||
tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit);
|
tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit);
|
||||||
|
@ -118,45 +118,45 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
||||||
|
|
||||||
int32_t code;
|
int32_t code;
|
||||||
tjsonGetNumberValue(pJson, "vgId", pCfg->vgId, code);
|
tjsonGetNumberValue(pJson, "vgId", pCfg->vgId, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
if (tjsonGetStringValue(pJson, "dbname", pCfg->dbname) < 0) return -1;
|
if (tjsonGetStringValue(pJson, "dbname", pCfg->dbname) < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "dbId", pCfg->dbId, code);
|
tjsonGetNumberValue(pJson, "dbId", pCfg->dbId, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "szPage", pCfg->szPage, code);
|
tjsonGetNumberValue(pJson, "szPage", pCfg->szPage, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "szCache", pCfg->szCache, code);
|
tjsonGetNumberValue(pJson, "szCache", pCfg->szCache, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf, code);
|
tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap, code);
|
tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "isWeak", pCfg->isWeak, code);
|
tjsonGetNumberValue(pJson, "isWeak", pCfg->isWeak, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "isTsma", pCfg->isTsma, code);
|
tjsonGetNumberValue(pJson, "isTsma", pCfg->isTsma, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "isRsma", pCfg->isRsma, code);
|
tjsonGetNumberValue(pJson, "isRsma", pCfg->isRsma, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "precision", pCfg->tsdbCfg.precision, code);
|
tjsonGetNumberValue(pJson, "precision", pCfg->tsdbCfg.precision, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "update", pCfg->tsdbCfg.update, code);
|
tjsonGetNumberValue(pJson, "update", pCfg->tsdbCfg.update, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "compression", pCfg->tsdbCfg.compression, code);
|
tjsonGetNumberValue(pJson, "compression", pCfg->tsdbCfg.compression, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "slLevel", pCfg->tsdbCfg.slLevel, code);
|
tjsonGetNumberValue(pJson, "slLevel", pCfg->tsdbCfg.slLevel, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "daysPerFile", pCfg->tsdbCfg.days, code);
|
tjsonGetNumberValue(pJson, "daysPerFile", pCfg->tsdbCfg.days, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "minRows", pCfg->tsdbCfg.minRows, code);
|
tjsonGetNumberValue(pJson, "minRows", pCfg->tsdbCfg.minRows, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "maxRows", pCfg->tsdbCfg.maxRows, code);
|
tjsonGetNumberValue(pJson, "maxRows", pCfg->tsdbCfg.maxRows, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "keep0", pCfg->tsdbCfg.keep0, code);
|
tjsonGetNumberValue(pJson, "keep0", pCfg->tsdbCfg.keep0, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1, code);
|
tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2, code);
|
tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
SJson *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions");
|
SJson * pNodeRetentions = tjsonGetObjectItem(pJson, "retentions");
|
||||||
int32_t nRetention = tjsonGetArraySize(pNodeRetentions);
|
int32_t nRetention = tjsonGetArraySize(pNodeRetentions);
|
||||||
if (nRetention > TSDB_RETENTION_MAX) {
|
if (nRetention > TSDB_RETENTION_MAX) {
|
||||||
nRetention = TSDB_RETENTION_MAX;
|
nRetention = TSDB_RETENTION_MAX;
|
||||||
|
@ -170,30 +170,30 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
||||||
tjsonGetNumberValue(pNodeRetention, "keepUnit", (pCfg->tsdbCfg.retentions)[i].keepUnit, code);
|
tjsonGetNumberValue(pNodeRetention, "keepUnit", (pCfg->tsdbCfg.retentions)[i].keepUnit, code);
|
||||||
}
|
}
|
||||||
tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId, code);
|
tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod, code);
|
tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod, code);
|
tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod, code);
|
tjsonGetNumberValue(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize, code);
|
tjsonGetNumberValue(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.segSize", pCfg->walCfg.segSize, code);
|
tjsonGetNumberValue(pJson, "wal.segSize", pCfg->walCfg.segSize, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level, code);
|
tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "hashBegin", pCfg->hashBegin, code);
|
tjsonGetNumberValue(pJson, "hashBegin", pCfg->hashBegin, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd, code);
|
tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod, code);
|
tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
|
|
||||||
tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum, code);
|
tjsonGetNumberValue(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex, code);
|
tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex, code);
|
||||||
if(code < 0) return -1;
|
if (code < 0) return -1;
|
||||||
|
|
||||||
SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
||||||
int arraySize = tjsonGetArraySize(pNodeInfoArr);
|
int arraySize = tjsonGetArraySize(pNodeInfoArr);
|
||||||
|
|
|
@ -27,10 +27,10 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
SMetaReader mer1 = {0};
|
SMetaReader mer1 = {0};
|
||||||
SMetaReader mer2 = {0};
|
SMetaReader mer2 = {0};
|
||||||
char tableFName[TSDB_TABLE_FNAME_LEN];
|
char tableFName[TSDB_TABLE_FNAME_LEN];
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
void *pRsp = NULL;
|
void * pRsp = NULL;
|
||||||
SSchemaWrapper schema = {0};
|
SSchemaWrapper schema = {0};
|
||||||
SSchemaWrapper schemaTag = {0};
|
SSchemaWrapper schemaTag = {0};
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ _exit:
|
||||||
rpcMsg.pCont = pRsp;
|
rpcMsg.pCont = pRsp;
|
||||||
rpcMsg.contLen = rspLen;
|
rpcMsg.contLen = rspLen;
|
||||||
rpcMsg.code = code;
|
rpcMsg.code = code;
|
||||||
|
rpcMsg.msgType = pMsg->msgType;
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code));
|
qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code));
|
||||||
|
@ -130,10 +131,10 @@ int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
SMetaReader mer1 = {0};
|
SMetaReader mer1 = {0};
|
||||||
SMetaReader mer2 = {0};
|
SMetaReader mer2 = {0};
|
||||||
char tableFName[TSDB_TABLE_FNAME_LEN];
|
char tableFName[TSDB_TABLE_FNAME_LEN];
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
void *pRsp = NULL;
|
void * pRsp = NULL;
|
||||||
SSchemaWrapper schema = {0};
|
SSchemaWrapper schema = {0};
|
||||||
SSchemaWrapper schemaTag = {0};
|
SSchemaWrapper schemaTag = {0};
|
||||||
|
|
||||||
|
@ -220,6 +221,7 @@ _exit:
|
||||||
rpcMsg.pCont = pRsp;
|
rpcMsg.pCont = pRsp;
|
||||||
rpcMsg.contLen = rspLen;
|
rpcMsg.contLen = rspLen;
|
||||||
rpcMsg.code = code;
|
rpcMsg.code = code;
|
||||||
|
rpcMsg.msgType = pMsg->msgType;
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
|
qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
|
||||||
|
@ -260,7 +262,7 @@ void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapper of tsdb read interface
|
// wrapper of tsdb read interface
|
||||||
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo* tableList, uint64_t qId,
|
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableList, uint64_t qId,
|
||||||
void *pMemRef) {
|
void *pMemRef) {
|
||||||
#if 0
|
#if 0
|
||||||
return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef);
|
return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef);
|
||||||
|
|
|
@ -29,13 +29,17 @@ extern "C" {
|
||||||
#define EXPLAIN_TAG_SCAN_FORMAT "Tag Scan on %s"
|
#define EXPLAIN_TAG_SCAN_FORMAT "Tag Scan on %s"
|
||||||
#define EXPLAIN_TBL_SCAN_FORMAT "Table Scan on %s"
|
#define EXPLAIN_TBL_SCAN_FORMAT "Table Scan on %s"
|
||||||
#define EXPLAIN_SYSTBL_SCAN_FORMAT "System Table Scan on %s"
|
#define EXPLAIN_SYSTBL_SCAN_FORMAT "System Table Scan on %s"
|
||||||
|
#define EXPLAIN_DISTBLK_SCAN_FORMAT "Block Dist Scan on %s"
|
||||||
|
#define EXPLAIN_LASTROW_SCAN_FORMAT "Last Row Scan on %s"
|
||||||
#define EXPLAIN_PROJECTION_FORMAT "Projection"
|
#define EXPLAIN_PROJECTION_FORMAT "Projection"
|
||||||
#define EXPLAIN_JOIN_FORMAT "%s"
|
#define EXPLAIN_JOIN_FORMAT "%s"
|
||||||
#define EXPLAIN_AGG_FORMAT "Aggragate"
|
#define EXPLAIN_AGG_FORMAT "Aggragate"
|
||||||
#define EXPLAIN_INDEF_ROWS_FORMAT "Indefinite Rows Function"
|
#define EXPLAIN_INDEF_ROWS_FORMAT "Indefinite Rows Function"
|
||||||
#define EXPLAIN_EXCHANGE_FORMAT "Data Exchange %d:1"
|
#define EXPLAIN_EXCHANGE_FORMAT "Data Exchange %d:1"
|
||||||
#define EXPLAIN_SORT_FORMAT "Sort"
|
#define EXPLAIN_SORT_FORMAT "Sort"
|
||||||
|
#define EXPLAIN_GROUP_SORT_FORMAT "Group Sort"
|
||||||
#define EXPLAIN_INTERVAL_FORMAT "Interval on Column %s"
|
#define EXPLAIN_INTERVAL_FORMAT "Interval on Column %s"
|
||||||
|
#define EXPLAIN_MERGE_INTERVAL_FORMAT "Merge Interval on Column %s"
|
||||||
#define EXPLAIN_FILL_FORMAT "Fill"
|
#define EXPLAIN_FILL_FORMAT "Fill"
|
||||||
#define EXPLAIN_SESSION_FORMAT "Session"
|
#define EXPLAIN_SESSION_FORMAT "Session"
|
||||||
#define EXPLAIN_STATE_WINDOW_FORMAT "StateWindow on Column %s"
|
#define EXPLAIN_STATE_WINDOW_FORMAT "StateWindow on Column %s"
|
||||||
|
@ -62,10 +66,12 @@ extern "C" {
|
||||||
#define EXPLAIN_COST_FORMAT "cost=%.2f..%.2f"
|
#define EXPLAIN_COST_FORMAT "cost=%.2f..%.2f"
|
||||||
#define EXPLAIN_ROWS_FORMAT "rows=%" PRIu64
|
#define EXPLAIN_ROWS_FORMAT "rows=%" PRIu64
|
||||||
#define EXPLAIN_COLUMNS_FORMAT "columns=%d"
|
#define EXPLAIN_COLUMNS_FORMAT "columns=%d"
|
||||||
|
#define EXPLAIN_PSEUDO_COLUMNS_FORMAT "pseudo_columns=%d"
|
||||||
#define EXPLAIN_WIDTH_FORMAT "width=%d"
|
#define EXPLAIN_WIDTH_FORMAT "width=%d"
|
||||||
#define EXPLAIN_TABLE_SCAN_FORMAT "order=[asc|%d desc|%d]"
|
#define EXPLAIN_TABLE_SCAN_FORMAT "order=[asc|%d desc|%d]"
|
||||||
#define EXPLAIN_GROUPS_FORMAT "groups=%d"
|
#define EXPLAIN_GROUPS_FORMAT "groups=%d"
|
||||||
#define EXPLAIN_WIDTH_FORMAT "width=%d"
|
#define EXPLAIN_WIDTH_FORMAT "width=%d"
|
||||||
|
#define EXPLAIN_INTERVAL_VALUE_FORMAT "interval=%" PRId64 "%c"
|
||||||
#define EXPLAIN_FUNCTIONS_FORMAT "functions=%d"
|
#define EXPLAIN_FUNCTIONS_FORMAT "functions=%d"
|
||||||
#define EXPLAIN_EXECINFO_FORMAT "cost=%.3f..%.3f rows=%" PRIu64
|
#define EXPLAIN_EXECINFO_FORMAT "cost=%.3f..%.3f rows=%" PRIu64
|
||||||
#define EXPLAIN_MODE_FORMAT "mode=%s"
|
#define EXPLAIN_MODE_FORMAT "mode=%s"
|
||||||
|
|
|
@ -199,6 +199,31 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo
|
||||||
pPhysiChildren = mergePhysiNode->scan.node.pChildren;
|
pPhysiChildren = mergePhysiNode->scan.node.pChildren;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: {
|
||||||
|
SBlockDistScanPhysiNode *distPhysiNode = (SBlockDistScanPhysiNode *)pNode;
|
||||||
|
pPhysiChildren = distPhysiNode->node.pChildren;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: {
|
||||||
|
SLastRowScanPhysiNode *lastRowPhysiNode = (SLastRowScanPhysiNode *)pNode;
|
||||||
|
pPhysiChildren = lastRowPhysiNode->node.pChildren;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: {
|
||||||
|
SGroupSortPhysiNode *groupSortPhysiNode = (SGroupSortPhysiNode *)pNode;
|
||||||
|
pPhysiChildren = groupSortPhysiNode->node.pChildren;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: {
|
||||||
|
SMergeIntervalPhysiNode *mergeIntPhysiNode = (SMergeIntervalPhysiNode *)pNode;
|
||||||
|
pPhysiChildren = mergeIntPhysiNode->window.node.pChildren;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: {
|
||||||
|
SInterpFuncPhysiNode *interpPhysiNode = (SInterpFuncPhysiNode *)pNode;
|
||||||
|
pPhysiChildren = interpPhysiNode->node.pChildren;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
qError("not supported physical node type %d", pNode->type);
|
qError("not supported physical node type %d", pNode->type);
|
||||||
QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
|
@ -378,6 +403,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
||||||
}
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pTagScanNode->pScanCols->length);
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pTagScanNode->pScanCols->length);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
if (pTagScanNode->pScanPseudoCols) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_PSEUDO_COLUMNS_FORMAT, pTagScanNode->pScanPseudoCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTagScanNode->node.pOutputDataBlockDesc->totalRowSize);
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTagScanNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
EXPLAIN_ROW_END();
|
EXPLAIN_ROW_END();
|
||||||
|
@ -415,6 +444,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
||||||
|
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pTblScanNode->scan.pScanCols->length);
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pTblScanNode->scan.pScanCols->length);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
if (pTblScanNode->scan.pScanPseudoCols) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_PSEUDO_COLUMNS_FORMAT, pTblScanNode->scan.pScanPseudoCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize);
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_TABLE_SCAN_FORMAT, pTblScanNode->scanSeq[0], pTblScanNode->scanSeq[1]);
|
EXPLAIN_ROW_APPEND(EXPLAIN_TABLE_SCAN_FORMAT, pTblScanNode->scanSeq[0], pTblScanNode->scanSeq[1]);
|
||||||
|
@ -516,6 +549,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
||||||
}
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pSTblScanNode->scan.pScanCols->length);
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pSTblScanNode->scan.pScanCols->length);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
if (pSTblScanNode->scan.pScanPseudoCols) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_PSEUDO_COLUMNS_FORMAT, pSTblScanNode->scan.pScanPseudoCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize);
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
@ -1131,6 +1168,258 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: {
|
||||||
|
SBlockDistScanPhysiNode *pDistScanNode = (SBlockDistScanPhysiNode *)pNode;
|
||||||
|
EXPLAIN_ROW_NEW(level, EXPLAIN_DISTBLK_SCAN_FORMAT, pDistScanNode->tableName.tname);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pDistScanNode->pScanCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
if (pDistScanNode->pScanPseudoCols) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_PSEUDO_COLUMNS_FORMAT, pDistScanNode->pScanPseudoCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDistScanNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||||
|
nodesGetOutputNumFromSlotList(pDistScanNode->node.pOutputDataBlockDesc->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDistScanNode->node.pOutputDataBlockDesc->outputRowSize);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
|
||||||
|
if (pDistScanNode->node.pConditions) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT);
|
||||||
|
QRY_ERR_RET(nodesNodeToSQL(pDistScanNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE,
|
||||||
|
TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: {
|
||||||
|
SLastRowScanPhysiNode *pLastRowNode = (SLastRowScanPhysiNode *)pNode;
|
||||||
|
EXPLAIN_ROW_NEW(level, EXPLAIN_LASTROW_SCAN_FORMAT, pLastRowNode->tableName.tname);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pLastRowNode->pScanCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
if (pLastRowNode->pScanPseudoCols) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_PSEUDO_COLUMNS_FORMAT, pLastRowNode->pScanPseudoCols->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pLastRowNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||||
|
nodesGetOutputNumFromSlotList(pLastRowNode->node.pOutputDataBlockDesc->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pLastRowNode->node.pOutputDataBlockDesc->outputRowSize);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
|
||||||
|
if (pLastRowNode->node.pConditions) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT);
|
||||||
|
QRY_ERR_RET(nodesNodeToSQL(pLastRowNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE,
|
||||||
|
TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: {
|
||||||
|
SGroupSortPhysiNode *pSortNode = (SGroupSortPhysiNode *)pNode;
|
||||||
|
EXPLAIN_ROW_NEW(level, EXPLAIN_GROUP_SORT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDataBlockDescNode *pDescNode = pSortNode->node.pOutputDataBlockDesc;
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, nodesGetOutputNumFromSlotList(pDescNode->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDescNode->totalRowSize);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
if (EXPLAIN_MODE_ANALYZE == ctx->mode) {
|
||||||
|
// sort key
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, "Sort Key: ");
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
for (int32_t i = 0; i < LIST_LENGTH(pSortNode->pSortKeys); ++i) {
|
||||||
|
SOrderByExprNode *ptn = (SOrderByExprNode *)nodesListGetNode(pSortNode->pSortKeys, i);
|
||||||
|
EXPLAIN_ROW_APPEND("%s ", nodesGetNameFromColumnNode(ptn->pExpr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
// sort method
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, "Sort Method: ");
|
||||||
|
|
||||||
|
int32_t nodeNum = taosArrayGetSize(pResNode->pExecInfo);
|
||||||
|
SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, 0);
|
||||||
|
SSortExecInfo *pExecInfo = (SSortExecInfo *)execInfo->verboseInfo;
|
||||||
|
EXPLAIN_ROW_APPEND("%s", pExecInfo->sortMethod == SORT_QSORT_T ? "quicksort" : "merge sort");
|
||||||
|
if (pExecInfo->sortBuffer > 1024 * 1024) {
|
||||||
|
EXPLAIN_ROW_APPEND(" Buffers:%.2f Mb", pExecInfo->sortBuffer / (1024 * 1024.0));
|
||||||
|
} else if (pExecInfo->sortBuffer > 1024) {
|
||||||
|
EXPLAIN_ROW_APPEND(" Buffers:%.2f Kb", pExecInfo->sortBuffer / (1024.0));
|
||||||
|
} else {
|
||||||
|
EXPLAIN_ROW_APPEND(" Buffers:%d b", pExecInfo->sortBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLAIN_ROW_APPEND(" loops:%d", pExecInfo->loops);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||||
|
nodesGetOutputNumFromSlotList(pSortNode->node.pOutputDataBlockDesc->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSortNode->node.pOutputDataBlockDesc->outputRowSize);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
|
||||||
|
if (pSortNode->node.pConditions) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT);
|
||||||
|
QRY_ERR_RET(nodesNodeToSQL(pSortNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE,
|
||||||
|
TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: {
|
||||||
|
SMergeIntervalPhysiNode *pIntNode = (SMergeIntervalPhysiNode *)pNode;
|
||||||
|
EXPLAIN_ROW_NEW(level, EXPLAIN_MERGE_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->window.pTspk));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIntNode->window.pFuncs->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||||
|
nodesGetOutputNumFromSlotList(pIntNode->window.node.pOutputDataBlockDesc->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIntNode->window.node.pOutputDataBlockDesc->outputRowSize);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
uint8_t precision = getIntervalPrecision(pIntNode);
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT,
|
||||||
|
INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision),
|
||||||
|
pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(precision),
|
||||||
|
INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision),
|
||||||
|
pIntNode->slidingUnit);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
|
||||||
|
if (pIntNode->window.node.pConditions) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT);
|
||||||
|
QRY_ERR_RET(nodesNodeToSQL(pIntNode->window.node.pConditions, tbuf + VARSTR_HEADER_SIZE,
|
||||||
|
TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: {
|
||||||
|
SInterpFuncPhysiNode *pInterpNode = (SInterpFuncPhysiNode *)pNode;
|
||||||
|
EXPLAIN_ROW_NEW(level, EXPLAIN_AGG_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||||
|
if (pResNode->pExecInfo) {
|
||||||
|
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
if (pInterpNode->pFuncs) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pInterpNode->pFuncs->length);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_MODE_FORMAT, nodesGetFillModeString(pInterpNode->fillMode));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||||
|
nodesGetOutputNumFromSlotList(pInterpNode->node.pOutputDataBlockDesc->pSlots));
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pInterpNode->node.pOutputDataBlockDesc->outputRowSize);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
if (pInterpNode->pFillValues) {
|
||||||
|
SNodeListNode *pValues = (SNodeListNode *)pInterpNode->pFillValues;
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILL_VALUE_FORMAT);
|
||||||
|
SNode *tNode = NULL;
|
||||||
|
int32_t i = 0;
|
||||||
|
FOREACH(tNode, pValues->pNodeList) {
|
||||||
|
if (i) {
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||||
|
}
|
||||||
|
SValueNode *tValue = (SValueNode *)tNode;
|
||||||
|
char *value = nodesGetStrValueFromNode(tValue);
|
||||||
|
EXPLAIN_ROW_APPEND(EXPLAIN_STRING_TYPE_FORMAT, value);
|
||||||
|
taosMemoryFree(value);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_INTERVAL_VALUE_FORMAT, pInterpNode->interval, pInterpNode->intervalUnit);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIMERANGE_FORMAT, pInterpNode->timeRange.skey, pInterpNode->timeRange.ekey);
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
|
||||||
|
if (pInterpNode->node.pConditions) {
|
||||||
|
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT);
|
||||||
|
QRY_ERR_RET(nodesNodeToSQL(pInterpNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE,
|
||||||
|
TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||||
|
EXPLAIN_ROW_END();
|
||||||
|
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
qError("not supported physical node type %d", pNode->type);
|
qError("not supported physical node type %d", pNode->type);
|
||||||
return TSDB_CODE_QRY_APP_ERROR;
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
|
|
@ -680,7 +680,7 @@ typedef struct SJoinOperatorInfo {
|
||||||
SSDataBlock *pRight;
|
SSDataBlock *pRight;
|
||||||
int32_t rightPos;
|
int32_t rightPos;
|
||||||
SColumnInfo rightCol;
|
SColumnInfo rightCol;
|
||||||
SNode *pOnCondition;
|
SNode *pCondAfterMerge;
|
||||||
} SJoinOperatorInfo;
|
} SJoinOperatorInfo;
|
||||||
|
|
||||||
#define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED)
|
#define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED)
|
||||||
|
|
|
@ -2843,11 +2843,18 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
|
||||||
|
|
||||||
int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
|
int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
|
||||||
int32_t type = pOperator->operatorType;
|
int32_t type = pOperator->operatorType;
|
||||||
|
|
||||||
|
pOperator->status = OP_OPENED;
|
||||||
|
|
||||||
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
SStreamBlockScanInfo* pScanInfo = pOperator->info;
|
SStreamBlockScanInfo* pScanInfo = pOperator->info;
|
||||||
pScanInfo->blockType = STREAM_INPUT__DATA_SCAN;
|
pScanInfo->blockType = STREAM_INPUT__DATA_SCAN;
|
||||||
|
|
||||||
|
pScanInfo->pSnapshotReadOp->status = OP_OPENED;
|
||||||
|
|
||||||
STableScanInfo* pInfo = pScanInfo->pSnapshotReadOp->info;
|
STableScanInfo* pInfo = pScanInfo->pSnapshotReadOp->info;
|
||||||
|
ASSERT(pInfo->scanMode == TABLE_SCAN__TABLE_ORDER);
|
||||||
|
|
||||||
if (uid == 0) {
|
if (uid == 0) {
|
||||||
pInfo->noTable = 1;
|
pInfo->noTable = 1;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2861,14 +2868,6 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
|
||||||
pInfo->noTable = 0;
|
pInfo->noTable = 0;
|
||||||
|
|
||||||
if (pInfo->lastStatus.uid != uid || pInfo->lastStatus.ts != ts) {
|
if (pInfo->lastStatus.uid != uid || pInfo->lastStatus.ts != ts) {
|
||||||
tsdbSetTableId(pInfo->dataReader, uid);
|
|
||||||
int64_t oldSkey = pInfo->cond.twindows[0].skey;
|
|
||||||
pInfo->cond.twindows[0].skey = ts + 1;
|
|
||||||
tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0);
|
|
||||||
pInfo->cond.twindows[0].skey = oldSkey;
|
|
||||||
pInfo->scanTimes = 0;
|
|
||||||
pInfo->curTWinIdx = 0;
|
|
||||||
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList);
|
int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList);
|
||||||
|
@ -2880,8 +2879,17 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
|
||||||
pInfo->currentTable = i;
|
pInfo->currentTable = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO after processing drop,
|
// TODO after processing drop, found can be false
|
||||||
ASSERT(found);
|
ASSERT(found);
|
||||||
|
|
||||||
|
tsdbSetTableId(pInfo->dataReader, uid);
|
||||||
|
int64_t oldSkey = pInfo->cond.twindows[0].skey;
|
||||||
|
pInfo->cond.twindows[0].skey = ts + 1;
|
||||||
|
tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0);
|
||||||
|
pInfo->cond.twindows[0].skey = oldSkey;
|
||||||
|
pInfo->scanTimes = 0;
|
||||||
|
pInfo->curTWinIdx = 0;
|
||||||
|
|
||||||
qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts,
|
qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts,
|
||||||
pInfo->currentTable, tableSz);
|
pInfo->currentTable, tableSz);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,13 +53,28 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
SNode* pOnCondition = pJoinNode->pOnConditions;
|
SNode* pMergeCondition = pJoinNode->pMergeCondition;
|
||||||
if (nodeType(pOnCondition) == QUERY_NODE_OPERATOR) {
|
if (nodeType(pMergeCondition) == QUERY_NODE_OPERATOR) {
|
||||||
SOperatorNode* pNode = (SOperatorNode*)pOnCondition;
|
SOperatorNode* pNode = (SOperatorNode*)pMergeCondition;
|
||||||
setJoinColumnInfo(&pInfo->leftCol, (SColumnNode*)pNode->pLeft);
|
setJoinColumnInfo(&pInfo->leftCol, (SColumnNode*)pNode->pLeft);
|
||||||
setJoinColumnInfo(&pInfo->rightCol, (SColumnNode*)pNode->pRight);
|
setJoinColumnInfo(&pInfo->rightCol, (SColumnNode*)pNode->pRight);
|
||||||
} else if (nodeType(pOnCondition) == QUERY_NODE_LOGIC_CONDITION) {
|
} else {
|
||||||
extractTimeCondition(pInfo, (SLogicConditionNode*)pOnCondition);
|
ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) {
|
||||||
|
pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||||
|
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pInfo->pCondAfterMerge);
|
||||||
|
pLogicCond->pParameterList = nodesMakeList();
|
||||||
|
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->pOnConditions));
|
||||||
|
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->node.pConditions));
|
||||||
|
pLogicCond->condType = LOGIC_COND_TYPE_AND;
|
||||||
|
} else if (pJoinNode->pOnConditions != NULL) {
|
||||||
|
pInfo->pCondAfterMerge = nodesCloneNode(pJoinNode->pOnConditions);
|
||||||
|
} else if (pJoinNode->node.pConditions != NULL) {
|
||||||
|
pInfo->pCondAfterMerge = nodesCloneNode(pJoinNode->node.pConditions);
|
||||||
|
} else {
|
||||||
|
pInfo->pCondAfterMerge = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pOperator->fpSet =
|
pOperator->fpSet =
|
||||||
|
@ -88,15 +103,12 @@ void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
|
||||||
|
|
||||||
void destroyMergeJoinOperator(void* param, int32_t numOfOutput) {
|
void destroyMergeJoinOperator(void* param, int32_t numOfOutput) {
|
||||||
SJoinOperatorInfo* pJoinOperator = (SJoinOperatorInfo*)param;
|
SJoinOperatorInfo* pJoinOperator = (SJoinOperatorInfo*)param;
|
||||||
|
nodesDestroyNode(pJoinOperator->pCondAfterMerge);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
|
static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) {
|
||||||
SJoinOperatorInfo* pJoinInfo = pOperator->info;
|
SJoinOperatorInfo* pJoinInfo = pOperator->info;
|
||||||
|
|
||||||
SSDataBlock* pRes = pJoinInfo->pRes;
|
|
||||||
blockDataCleanup(pRes);
|
|
||||||
blockDataEnsureCapacity(pRes, 4096);
|
|
||||||
|
|
||||||
int32_t nrows = 0;
|
int32_t nrows = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -181,7 +193,28 @@ SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
|
||||||
|
SJoinOperatorInfo* pJoinInfo = pOperator->info;
|
||||||
|
|
||||||
|
SSDataBlock* pRes = pJoinInfo->pRes;
|
||||||
|
blockDataCleanup(pRes);
|
||||||
|
blockDataEnsureCapacity(pRes, 4096);
|
||||||
|
while (true) {
|
||||||
|
int32_t numOfRowsBefore = pRes->info.rows;
|
||||||
|
doMergeJoinImpl(pOperator, pRes);
|
||||||
|
int32_t numOfNewRows = pRes->info.rows - numOfRowsBefore;
|
||||||
|
if (numOfNewRows == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pJoinInfo->pCondAfterMerge != NULL) {
|
||||||
|
doFilter(pJoinInfo->pCondAfterMerge, pRes);
|
||||||
|
}
|
||||||
|
if (pRes->info.rows >= pOperator->resultInfo.threshold) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return (pRes->info.rows > 0) ? pRes : NULL;
|
return (pRes->info.rows > 0) ? pRes : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
#include "scalar.h"
|
#include "scalar.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
|
||||||
static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) {
|
static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) {
|
||||||
va_list vArgList;
|
va_list vArgList;
|
||||||
|
@ -796,6 +797,165 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinType;
|
||||||
|
|
||||||
|
static int8_t validateHistogramBinType(char* binTypeStr) {
|
||||||
|
int8_t binType;
|
||||||
|
if (strcasecmp(binTypeStr, "user_input") == 0) {
|
||||||
|
binType = USER_INPUT_BIN;
|
||||||
|
} else if (strcasecmp(binTypeStr, "linear_bin") == 0) {
|
||||||
|
binType = LINEAR_BIN;
|
||||||
|
} else if (strcasecmp(binTypeStr, "log_bin") == 0) {
|
||||||
|
binType = LOG_BIN;
|
||||||
|
} else {
|
||||||
|
binType = UNKNOWN_BIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return binType;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* errMsg, int32_t msgLen) {
|
||||||
|
const char *msg1 = "HISTOGRAM function requires four parameters";
|
||||||
|
const char *msg3 = "HISTOGRAM function invalid format for binDesc parameter";
|
||||||
|
const char *msg4 = "HISTOGRAM function binDesc parameter \"count\" should be in range [1, 1000]";
|
||||||
|
const char *msg5 = "HISTOGRAM function bin/parameter should be in range [-DBL_MAX, DBL_MAX]";
|
||||||
|
const char *msg6 = "HISTOGRAM function binDesc parameter \"width\" cannot be 0";
|
||||||
|
const char *msg7 = "HISTOGRAM function binDesc parameter \"start\" cannot be 0 with \"log_bin\" type";
|
||||||
|
const char *msg8 = "HISTOGRAM function binDesc parameter \"factor\" cannot be negative or equal to 0/1";
|
||||||
|
|
||||||
|
cJSON* binDesc = cJSON_Parse(binDescStr);
|
||||||
|
int32_t numOfBins;
|
||||||
|
double* intervals;
|
||||||
|
if (cJSON_IsObject(binDesc)) { /* linaer/log bins */
|
||||||
|
int32_t numOfParams = cJSON_GetArraySize(binDesc);
|
||||||
|
int32_t startIndex;
|
||||||
|
if (numOfParams != 4) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* start = cJSON_GetObjectItem(binDesc, "start");
|
||||||
|
cJSON* factor = cJSON_GetObjectItem(binDesc, "factor");
|
||||||
|
cJSON* width = cJSON_GetObjectItem(binDesc, "width");
|
||||||
|
cJSON* count = cJSON_GetObjectItem(binDesc, "count");
|
||||||
|
cJSON* infinity = cJSON_GetObjectItem(binDesc, "infinity");
|
||||||
|
|
||||||
|
if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count->valueint <= 0 || count->valueint > 1000) { // limit count to 1000
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg4);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isinf(start->valuedouble) || (width != NULL && isinf(width->valuedouble)) ||
|
||||||
|
(factor != NULL && isinf(factor->valuedouble)) || (count != NULL && isinf(count->valuedouble))) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg5);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t counter = (int32_t)count->valueint;
|
||||||
|
if (infinity->valueint == false) {
|
||||||
|
startIndex = 0;
|
||||||
|
numOfBins = counter + 1;
|
||||||
|
} else {
|
||||||
|
startIndex = 1;
|
||||||
|
numOfBins = counter + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
intervals = taosMemoryCalloc(numOfBins, sizeof(double));
|
||||||
|
if (cJSON_IsNumber(width) && factor == NULL && binType == LINEAR_BIN) {
|
||||||
|
// linear bin process
|
||||||
|
if (width->valuedouble == 0) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg6);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < counter + 1; ++i) {
|
||||||
|
intervals[startIndex] = start->valuedouble + i * width->valuedouble;
|
||||||
|
if (isinf(intervals[startIndex])) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg5);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
startIndex++;
|
||||||
|
}
|
||||||
|
} else if (cJSON_IsNumber(factor) && width == NULL && binType == LOG_BIN) {
|
||||||
|
// log bin process
|
||||||
|
if (start->valuedouble == 0) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg7);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (factor->valuedouble < 0 || factor->valuedouble == 0 || factor->valuedouble == 1) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg8);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < counter + 1; ++i) {
|
||||||
|
intervals[startIndex] = start->valuedouble * pow(factor->valuedouble, i * 1.0);
|
||||||
|
if (isinf(intervals[startIndex])) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg5);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
startIndex++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (infinity->valueint == true) {
|
||||||
|
intervals[0] = -INFINITY;
|
||||||
|
intervals[numOfBins - 1] = INFINITY;
|
||||||
|
// in case of desc bin orders, -inf/inf should be swapped
|
||||||
|
ASSERT(numOfBins >= 4);
|
||||||
|
if (intervals[1] > intervals[numOfBins - 2]) {
|
||||||
|
TSWAP(intervals[0], intervals[numOfBins - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (cJSON_IsArray(binDesc)) { /* user input bins */
|
||||||
|
if (binType != USER_INPUT_BIN) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
numOfBins = cJSON_GetArraySize(binDesc);
|
||||||
|
intervals = taosMemoryCalloc(numOfBins, sizeof(double));
|
||||||
|
cJSON* bin = binDesc->child;
|
||||||
|
if (bin == NULL) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
while (bin) {
|
||||||
|
intervals[i] = bin->valuedouble;
|
||||||
|
if (!cJSON_IsNumber(bin)) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (i != 0 && intervals[i] <= intervals[i - 1]) {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bin = bin->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
snprintf(errMsg, msgLen, "%s", msg3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(intervals);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||||
if (4 != numOfParams) {
|
if (4 != numOfParams) {
|
||||||
|
@ -814,6 +974,8 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t binType;
|
||||||
|
char* binDesc;
|
||||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||||
|
@ -824,6 +986,23 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
||||||
|
|
||||||
pValue->notReserved = true;
|
pValue->notReserved = true;
|
||||||
|
|
||||||
|
if (i == 1) {
|
||||||
|
binType = validateHistogramBinType(varDataVal(pValue->datum.p));
|
||||||
|
if (binType == UNKNOWN_BIN) {
|
||||||
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
|
"HISTOGRAM function binType parameter should be "
|
||||||
|
"\"user_input\", \"log_bin\" or \"linear_bin\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 2) {
|
||||||
|
char errMsg[128] = {0};
|
||||||
|
binDesc = varDataVal(pValue->datum.p);
|
||||||
|
if (!validateHistogramBinDesc(binDesc, binType, errMsg, (int32_t)sizeof(errMsg))) {
|
||||||
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, errMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i == 3 && pValue->datum.i != 1 && pValue->datum.i != 0) {
|
if (i == 3 && pValue->datum.i != 1 && pValue->datum.i != 0) {
|
||||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
"HISTOGRAM function normalized parameter should be 0/1");
|
"HISTOGRAM function normalized parameter should be 0/1");
|
||||||
|
@ -853,6 +1032,8 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t binType;
|
||||||
|
char* binDesc;
|
||||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||||
|
@ -863,6 +1044,23 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
|
||||||
|
|
||||||
pValue->notReserved = true;
|
pValue->notReserved = true;
|
||||||
|
|
||||||
|
if (i == 1) {
|
||||||
|
binType = validateHistogramBinType(varDataVal(pValue->datum.p));
|
||||||
|
if (binType == UNKNOWN_BIN) {
|
||||||
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
|
"HISTOGRAM function binType parameter should be "
|
||||||
|
"\"user_input\", \"log_bin\" or \"linear_bin\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 2) {
|
||||||
|
char errMsg[128] = {0};
|
||||||
|
binDesc = varDataVal(pValue->datum.p);
|
||||||
|
if (!validateHistogramBinDesc(binDesc, binType, errMsg, (int32_t)sizeof(errMsg))) {
|
||||||
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, errMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i == 3 && pValue->datum.i != 1 && pValue->datum.i != 0) {
|
if (i == 3 && pValue->datum.i != 1 && pValue->datum.i != 0) {
|
||||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
"HISTOGRAM function normalized parameter should be 0/1");
|
"HISTOGRAM function normalized parameter should be 0/1");
|
||||||
|
@ -2112,7 +2310,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "histogram",
|
.name = "histogram",
|
||||||
.type = FUNCTION_TYPE_HISTOGRAM,
|
.type = FUNCTION_TYPE_HISTOGRAM,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_FILL_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_FILL_FUNC,
|
||||||
.translateFunc = translateHistogram,
|
.translateFunc = translateHistogram,
|
||||||
.getEnvFunc = getHistogramFuncEnv,
|
.getEnvFunc = getHistogramFuncEnv,
|
||||||
.initFunc = histogramFunctionSetup,
|
.initFunc = histogramFunctionSetup,
|
||||||
|
|
|
@ -719,8 +719,10 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||||
ASSERT(numOfElem >= 0);
|
ASSERT(numOfElem >= 0);
|
||||||
|
|
||||||
pAvgRes->count += numOfElem;
|
pAvgRes->count += numOfElem;
|
||||||
if (IS_INTEGER_TYPE(type)) {
|
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||||
pAvgRes->sum.isum += pAgg->sum;
|
pAvgRes->sum.isum += pAgg->sum;
|
||||||
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||||
|
pAvgRes->sum.usum += pAgg->sum;
|
||||||
} else if (IS_FLOAT_TYPE(type)) {
|
} else if (IS_FLOAT_TYPE(type)) {
|
||||||
pAvgRes->sum.dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
pAvgRes->sum.dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
||||||
}
|
}
|
||||||
|
@ -784,6 +786,64 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
uint8_t* plist = (uint8_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.usum += plist[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
uint16_t* plist = (uint16_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.usum += plist[i];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UINT: {
|
||||||
|
uint32_t* plist = (uint32_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.usum += plist[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
uint64_t* plist = (uint64_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.usum += plist[i];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
float* plist = (float*)pCol->pData;
|
float* plist = (float*)pCol->pData;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
@ -825,8 +885,10 @@ _avg_over:
|
||||||
|
|
||||||
static void avgTransferInfo(SAvgRes* pInput, SAvgRes* pOutput) {
|
static void avgTransferInfo(SAvgRes* pInput, SAvgRes* pOutput) {
|
||||||
pOutput->type = pInput->type;
|
pOutput->type = pInput->type;
|
||||||
if (IS_INTEGER_TYPE(pOutput->type)) {
|
if (IS_SIGNED_NUMERIC_TYPE(pOutput->type)) {
|
||||||
pOutput->sum.isum += pInput->sum.isum;
|
pOutput->sum.isum += pInput->sum.isum;
|
||||||
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(pOutput->type)) {
|
||||||
|
pOutput->sum.usum += pInput->sum.usum;
|
||||||
} else {
|
} else {
|
||||||
pOutput->sum.dsum += pInput->sum.dsum;
|
pOutput->sum.dsum += pInput->sum.dsum;
|
||||||
}
|
}
|
||||||
|
@ -900,6 +962,22 @@ int32_t avgInvertFunction(SqlFunctionCtx* pCtx) {
|
||||||
LIST_AVG_N(pAvgRes->sum.isum, int64_t);
|
LIST_AVG_N(pAvgRes->sum.isum, int64_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
LIST_AVG_N(pAvgRes->sum.usum, uint8_t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
LIST_AVG_N(pAvgRes->sum.usum, uint16_t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_UINT: {
|
||||||
|
LIST_AVG_N(pAvgRes->sum.usum, uint32_t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
LIST_AVG_N(pAvgRes->sum.usum, uint64_t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
LIST_AVG_N(pAvgRes->sum.dsum, float);
|
LIST_AVG_N(pAvgRes->sum.dsum, float);
|
||||||
break;
|
break;
|
||||||
|
@ -925,8 +1003,10 @@ int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
||||||
SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx);
|
SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx);
|
||||||
SAvgRes* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo);
|
SAvgRes* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo);
|
||||||
|
|
||||||
if (IS_INTEGER_TYPE(type)) {
|
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||||
pDBuf->sum.isum += pSBuf->sum.isum;
|
pDBuf->sum.isum += pSBuf->sum.isum;
|
||||||
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||||
|
pDBuf->sum.usum += pSBuf->sum.usum;
|
||||||
} else {
|
} else {
|
||||||
pDBuf->sum.dsum += pSBuf->sum.dsum;
|
pDBuf->sum.dsum += pSBuf->sum.dsum;
|
||||||
}
|
}
|
||||||
|
@ -941,8 +1021,10 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
int32_t type = pAvgRes->type;
|
int32_t type = pAvgRes->type;
|
||||||
|
|
||||||
if (IS_INTEGER_TYPE(type)) {
|
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||||
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
|
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
|
||||||
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||||
|
pAvgRes->result = pAvgRes->sum.usum / ((double)pAvgRes->count);
|
||||||
} else {
|
} else {
|
||||||
pAvgRes->result = pAvgRes->sum.dsum / ((double)pAvgRes->count);
|
pAvgRes->result = pAvgRes->sum.dsum / ((double)pAvgRes->count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ bool fmIsSameInOutType(int32_t funcId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
||||||
char msg[64] = {0};
|
char msg[128] = {0};
|
||||||
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1565,6 +1565,10 @@ void constructUdfService(void *argsThread) {
|
||||||
//TODO return value of uv_run
|
//TODO return value of uv_run
|
||||||
uv_run(&udfc->uvLoop, UV_RUN_DEFAULT);
|
uv_run(&udfc->uvLoop, UV_RUN_DEFAULT);
|
||||||
uv_loop_close(&udfc->uvLoop);
|
uv_loop_close(&udfc->uvLoop);
|
||||||
|
|
||||||
|
uv_walk(&udfc->uvLoop, udfUdfdCloseWalkCb, NULL);
|
||||||
|
uv_run(&udfc->uvLoop, UV_RUN_DEFAULT);
|
||||||
|
uv_loop_close(&udfc->uvLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t udfcOpen() {
|
int32_t udfcOpen() {
|
||||||
|
|
|
@ -368,6 +368,7 @@ static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
|
||||||
static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
|
static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
|
||||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||||
COPY_SCALAR_FIELD(joinType);
|
COPY_SCALAR_FIELD(joinType);
|
||||||
|
CLONE_NODE_FIELD(pMergeCondition);
|
||||||
CLONE_NODE_FIELD(pOnConditions);
|
CLONE_NODE_FIELD(pOnConditions);
|
||||||
COPY_SCALAR_FIELD(isSingleTableJoin);
|
COPY_SCALAR_FIELD(isSingleTableJoin);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -1254,6 +1254,7 @@ static int32_t jsonToLogicPlan(const SJson* pJson, void* pObj) {
|
||||||
|
|
||||||
static const char* jkJoinLogicPlanJoinType = "JoinType";
|
static const char* jkJoinLogicPlanJoinType = "JoinType";
|
||||||
static const char* jkJoinLogicPlanOnConditions = "OnConditions";
|
static const char* jkJoinLogicPlanOnConditions = "OnConditions";
|
||||||
|
static const char* jkJoinLogicPlanMergeCondition = "MergeConditions";
|
||||||
|
|
||||||
static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SJoinLogicNode* pNode = (const SJoinLogicNode*)pObj;
|
const SJoinLogicNode* pNode = (const SJoinLogicNode*)pObj;
|
||||||
|
@ -1262,6 +1263,9 @@ static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddIntegerToObject(pJson, jkJoinLogicPlanJoinType, pNode->joinType);
|
code = tjsonAddIntegerToObject(pJson, jkJoinLogicPlanJoinType, pNode->joinType);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddObject(pJson, jkJoinLogicPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddObject(pJson, jkJoinLogicPlanOnConditions, nodeToJson, pNode->pOnConditions);
|
code = tjsonAddObject(pJson, jkJoinLogicPlanOnConditions, nodeToJson, pNode->pOnConditions);
|
||||||
}
|
}
|
||||||
|
@ -1617,6 +1621,7 @@ static int32_t jsonToPhysiProjectNode(const SJson* pJson, void* pObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* jkJoinPhysiPlanJoinType = "JoinType";
|
static const char* jkJoinPhysiPlanJoinType = "JoinType";
|
||||||
|
static const char* jkJoinPhysiPlanMergeCondition = "MergeCondition";
|
||||||
static const char* jkJoinPhysiPlanOnConditions = "OnConditions";
|
static const char* jkJoinPhysiPlanOnConditions = "OnConditions";
|
||||||
static const char* jkJoinPhysiPlanTargets = "Targets";
|
static const char* jkJoinPhysiPlanTargets = "Targets";
|
||||||
|
|
||||||
|
@ -1627,6 +1632,9 @@ static int32_t physiJoinNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
|
code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddObject(pJson, jkJoinPhysiPlanMergeCondition, nodeToJson, pNode->pMergeCondition);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddObject(pJson, jkJoinPhysiPlanOnConditions, nodeToJson, pNode->pOnConditions);
|
code = tjsonAddObject(pJson, jkJoinPhysiPlanOnConditions, nodeToJson, pNode->pOnConditions);
|
||||||
}
|
}
|
||||||
|
@ -1648,6 +1656,9 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
|
code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeObject(pJson, jkJoinPhysiPlanMergeCondition, &pNode->pMergeCondition);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeList(pJson, jkJoinPhysiPlanTargets, &pNode->pTargets);
|
code = jsonToNodeList(pJson, jkJoinPhysiPlanTargets, &pNode->pTargets);
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,6 +470,9 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: {
|
case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: {
|
||||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)pNode;
|
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)pNode;
|
||||||
res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext);
|
res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext);
|
||||||
|
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||||
|
res = walkPhysiPlan(pJoin->pMergeCondition, order, walker, pContext);
|
||||||
|
}
|
||||||
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||||
res = walkPhysiPlan(pJoin->pOnConditions, order, walker, pContext);
|
res = walkPhysiPlan(pJoin->pOnConditions, order, walker, pContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "thash.h"
|
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
|
#include "thash.h"
|
||||||
|
|
||||||
static SNode* makeNode(ENodeType type, size_t size) {
|
static SNode* makeNode(ENodeType type, size_t size) {
|
||||||
SNode* p = taosMemoryCalloc(1, size);
|
SNode* p = taosMemoryCalloc(1, size);
|
||||||
|
@ -718,6 +718,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
case QUERY_NODE_LOGIC_PLAN_JOIN: {
|
case QUERY_NODE_LOGIC_PLAN_JOIN: {
|
||||||
SJoinLogicNode* pLogicNode = (SJoinLogicNode*)pNode;
|
SJoinLogicNode* pLogicNode = (SJoinLogicNode*)pNode;
|
||||||
destroyLogicNode((SLogicNode*)pLogicNode);
|
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||||
|
nodesDestroyNode(pLogicNode->pMergeCondition);
|
||||||
nodesDestroyNode(pLogicNode->pOnConditions);
|
nodesDestroyNode(pLogicNode->pOnConditions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -828,6 +829,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: {
|
case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: {
|
||||||
SJoinPhysiNode* pPhyNode = (SJoinPhysiNode*)pNode;
|
SJoinPhysiNode* pPhyNode = (SJoinPhysiNode*)pNode;
|
||||||
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
||||||
|
nodesDestroyNode(pPhyNode->pMergeCondition);
|
||||||
nodesDestroyNode(pPhyNode->pOnConditions);
|
nodesDestroyNode(pPhyNode->pOnConditions);
|
||||||
nodesDestroyList(pPhyNode->pTargets);
|
nodesDestroyList(pPhyNode->pTargets);
|
||||||
break;
|
break;
|
||||||
|
@ -1493,17 +1495,54 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t nodesCollectColumnsFromNode(SNode* node, const char* pTableAlias, ECollectColType type, SNodeList** pCols) {
|
||||||
|
if (NULL == pCols) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
SCollectColumnsCxt cxt = {
|
||||||
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
|
.pTableAlias = pTableAlias,
|
||||||
|
.collectType = type,
|
||||||
|
.pCols = (NULL == *pCols ? nodesMakeList() : *pCols),
|
||||||
|
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
|
||||||
|
if (NULL == cxt.pCols || NULL == cxt.pColHash) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
*pCols = NULL;
|
||||||
|
|
||||||
|
nodesWalkExpr(node, collectColumns, &cxt);
|
||||||
|
|
||||||
|
taosHashCleanup(cxt.pColHash);
|
||||||
|
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||||
|
nodesDestroyList(cxt.pCols);
|
||||||
|
return cxt.errCode;
|
||||||
|
}
|
||||||
|
if (LIST_LENGTH(cxt.pCols) > 0) {
|
||||||
|
*pCols = cxt.pCols;
|
||||||
|
} else {
|
||||||
|
nodesDestroyList(cxt.pCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct SCollectFuncsCxt {
|
typedef struct SCollectFuncsCxt {
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
FFuncClassifier classifier;
|
FFuncClassifier classifier;
|
||||||
SNodeList* pFuncs;
|
SNodeList* pFuncs;
|
||||||
|
SHashObj* pAliasName;
|
||||||
} SCollectFuncsCxt;
|
} SCollectFuncsCxt;
|
||||||
|
|
||||||
static EDealRes collectFuncs(SNode* pNode, void* pContext) {
|
static EDealRes collectFuncs(SNode* pNode, void* pContext) {
|
||||||
SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext;
|
SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext;
|
||||||
if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) &&
|
if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) &&
|
||||||
!(((SExprNode*)pNode)->orderAlias)) {
|
!(((SExprNode*)pNode)->orderAlias)) {
|
||||||
pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode));
|
SExprNode* pExpr = (SExprNode*)pNode;
|
||||||
|
if (NULL == taosHashGet(pCxt->pAliasName, pExpr->aliasName, strlen(pExpr->aliasName))) {
|
||||||
|
pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode));
|
||||||
|
taosHashPut(pCxt->pAliasName, pExpr->aliasName, strlen(pExpr->aliasName), &pExpr, POINTER_BYTES);
|
||||||
|
}
|
||||||
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||||
}
|
}
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
|
@ -1515,23 +1554,27 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifi
|
||||||
}
|
}
|
||||||
|
|
||||||
SCollectFuncsCxt cxt = {
|
SCollectFuncsCxt cxt = {
|
||||||
.errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .pFuncs = (NULL == *pFuncs ? nodesMakeList() : *pFuncs)};
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
|
.classifier = classifier,
|
||||||
|
.pFuncs = (NULL == *pFuncs ? nodesMakeList() : *pFuncs),
|
||||||
|
.pAliasName = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, false)};
|
||||||
if (NULL == cxt.pFuncs) {
|
if (NULL == cxt.pFuncs) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
*pFuncs = NULL;
|
*pFuncs = NULL;
|
||||||
nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt);
|
nodesWalkSelectStmt(pSelect, clause, collectFuncs, &cxt);
|
||||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
if (TSDB_CODE_SUCCESS == cxt.errCode) {
|
||||||
nodesDestroyList(cxt.pFuncs);
|
if (LIST_LENGTH(cxt.pFuncs) > 0) {
|
||||||
return cxt.errCode;
|
*pFuncs = cxt.pFuncs;
|
||||||
}
|
} else {
|
||||||
if (LIST_LENGTH(cxt.pFuncs) > 0) {
|
nodesDestroyList(cxt.pFuncs);
|
||||||
*pFuncs = cxt.pFuncs;
|
}
|
||||||
} else {
|
} else {
|
||||||
nodesDestroyList(cxt.pFuncs);
|
nodesDestroyList(cxt.pFuncs);
|
||||||
}
|
}
|
||||||
|
taosHashCleanup(cxt.pAliasName);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return cxt.errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SCollectSpecialNodesCxt {
|
typedef struct SCollectSpecialNodesCxt {
|
||||||
|
|
|
@ -154,6 +154,7 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
||||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
||||||
SToken* pNewColName);
|
SToken* pNewColName);
|
||||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal);
|
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal);
|
||||||
|
SNode* setAlterSuperTableType(SNode* pStmt);
|
||||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
|
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
|
||||||
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
|
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
|
||||||
|
|
|
@ -53,6 +53,7 @@ typedef struct SParseMetaCache {
|
||||||
} SParseMetaCache;
|
} SParseMetaCache;
|
||||||
|
|
||||||
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
|
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
|
||||||
|
int32_t generateSyntaxErrMsgExt(SMsgBuf* pBuf, int32_t errCode, const char* pFormat, ...);
|
||||||
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
|
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
|
||||||
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
|
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,7 @@ cmd ::= DROP TABLE multi_drop_clause(A).
|
||||||
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
|
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
|
||||||
|
|
||||||
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
||||||
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = setAlterSuperTableType(A); }
|
||||||
|
|
||||||
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
|
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
|
||||||
alter_table_clause(A) ::=
|
alter_table_clause(A) ::=
|
||||||
|
@ -259,7 +259,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C).
|
||||||
|
|
||||||
create_subtable_clause(A) ::=
|
create_subtable_clause(A) ::=
|
||||||
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
|
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
|
||||||
specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
|
specific_tags_opt(E) TAGS NK_LP expression_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
|
||||||
|
|
||||||
%type multi_drop_clause { SNodeList* }
|
%type multi_drop_clause { SNodeList* }
|
||||||
%destructor multi_drop_clause { nodesDestroyList($$); }
|
%destructor multi_drop_clause { nodesDestroyList($$); }
|
||||||
|
|
|
@ -1127,6 +1127,11 @@ SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken
|
||||||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNode* setAlterSuperTableType(SNode* pStmt) {
|
||||||
|
setNodeType(pStmt, QUERY_NODE_ALTER_SUPER_TABLE_STMT);
|
||||||
|
return pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
if (!checkDbName(pCxt, pDbName, false)) {
|
if (!checkDbName(pCxt, pDbName, false)) {
|
||||||
|
|
|
@ -247,6 +247,10 @@ static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTabl
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t collectMetaKeyFromAlterStable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
|
||||||
|
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t collectMetaKeyFromUseDatabase(SCollectMetaKeyCxt* pCxt, SUseDatabaseStmt* pStmt) {
|
static int32_t collectMetaKeyFromUseDatabase(SCollectMetaKeyCxt* pCxt, SUseDatabaseStmt* pStmt) {
|
||||||
return reserveDbVgVersionInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
return reserveDbVgVersionInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
|
@ -483,6 +487,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||||
return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
|
return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
|
||||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||||
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
|
||||||
|
return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);
|
||||||
case QUERY_NODE_USE_DATABASE_STMT:
|
case QUERY_NODE_USE_DATABASE_STMT:
|
||||||
return collectMetaKeyFromUseDatabase(pCxt, (SUseDatabaseStmt*)pStmt);
|
return collectMetaKeyFromUseDatabase(pCxt, (SUseDatabaseStmt*)pStmt);
|
||||||
case QUERY_NODE_CREATE_INDEX_STMT:
|
case QUERY_NODE_CREATE_INDEX_STMT:
|
||||||
|
|
|
@ -48,6 +48,12 @@
|
||||||
pSql += sToken.n; \
|
pSql += sToken.n; \
|
||||||
} while (TK_NK_SPACE == sToken.type)
|
} while (TK_NK_SPACE == sToken.type)
|
||||||
|
|
||||||
|
typedef struct SInsertParseBaseContext {
|
||||||
|
SParseContext* pComCxt;
|
||||||
|
char* pSql;
|
||||||
|
SMsgBuf msg;
|
||||||
|
} SInsertParseBaseContext;
|
||||||
|
|
||||||
typedef struct SInsertParseContext {
|
typedef struct SInsertParseContext {
|
||||||
SParseContext* pComCxt; // input
|
SParseContext* pComCxt; // input
|
||||||
char* pSql; // input
|
char* pSql; // input
|
||||||
|
@ -1105,6 +1111,32 @@ static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, SName*
|
||||||
return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES);
|
return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) {
|
||||||
|
SToken sToken;
|
||||||
|
int32_t expectRightParenthesis = 1;
|
||||||
|
while (1) {
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
if (TK_NK_LP == sToken.type) {
|
||||||
|
++expectRightParenthesis;
|
||||||
|
} else if (TK_NK_RP == sToken.type && 0 == --expectRightParenthesis) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (0 == sToken.n) {
|
||||||
|
return buildSyntaxErrMsg(&pCxt->msg, ") expected", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t skipBoundColumns(SInsertParseSyntaxCxt* pCxt) { return skipParentheses(pCxt); }
|
||||||
|
|
||||||
|
static int32_t ignoreBoundColumns(SInsertParseContext* pCxt) {
|
||||||
|
SInsertParseSyntaxCxt cxt = {.pComCxt = pCxt->pComCxt, .pSql = pCxt->pSql, .msg = pCxt->msg, .pMetaCache = NULL};
|
||||||
|
int32_t code = skipBoundColumns(&cxt);
|
||||||
|
pCxt->pSql = cxt.pSql;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t skipUsingClause(SInsertParseSyntaxCxt* pCxt);
|
static int32_t skipUsingClause(SInsertParseSyntaxCxt* pCxt);
|
||||||
|
|
||||||
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||||
|
@ -1453,12 +1485,29 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
||||||
tNameGetFullDbName(&name, dbFName);
|
tNameGetFullDbName(&name, dbFName);
|
||||||
CHECK_CODE(taosHashPut(pCxt->pDbFNameHashObj, dbFName, strlen(dbFName), dbFName, sizeof(dbFName)));
|
CHECK_CODE(taosHashPut(pCxt->pDbFNameHashObj, dbFName, strlen(dbFName), dbFName, sizeof(dbFName)));
|
||||||
|
|
||||||
|
bool existedUsing = false;
|
||||||
// USING clause
|
// USING clause
|
||||||
|
if (TK_USING == sToken.type) {
|
||||||
|
existedUsing = true;
|
||||||
|
CHECK_CODE(parseUsingClause(pCxt, &name, tbFName));
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
autoCreateTbl = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* pBoundColsStart = NULL;
|
||||||
|
if (TK_NK_LP == sToken.type) {
|
||||||
|
// pSql -> field1_name, ...)
|
||||||
|
pBoundColsStart = pCxt->pSql;
|
||||||
|
CHECK_CODE(ignoreBoundColumns(pCxt));
|
||||||
|
// CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
}
|
||||||
|
|
||||||
if (TK_USING == sToken.type) {
|
if (TK_USING == sToken.type) {
|
||||||
CHECK_CODE(parseUsingClause(pCxt, &name, tbFName));
|
CHECK_CODE(parseUsingClause(pCxt, &name, tbFName));
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
autoCreateTbl = true;
|
autoCreateTbl = true;
|
||||||
} else {
|
} else if (!existedUsing) {
|
||||||
CHECK_CODE(getTableMeta(pCxt, &name, dbFName));
|
CHECK_CODE(getTableMeta(pCxt, &name, dbFName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1467,10 +1516,11 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
||||||
sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta,
|
sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta,
|
||||||
&dataBuf, NULL, &pCxt->createTblReq));
|
&dataBuf, NULL, &pCxt->createTblReq));
|
||||||
|
|
||||||
if (TK_NK_LP == sToken.type) {
|
if (NULL != pBoundColsStart) {
|
||||||
// pSql -> field1_name, ...)
|
char* pCurrPos = pCxt->pSql;
|
||||||
|
pCxt->pSql = pBoundColsStart;
|
||||||
CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
|
CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
pCxt->pSql = pCurrPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TK_VALUES == sToken.type) {
|
if (TK_VALUES == sToken.type) {
|
||||||
|
@ -1610,25 +1660,6 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) {
|
|
||||||
SToken sToken;
|
|
||||||
int32_t expectRightParenthesis = 1;
|
|
||||||
while (1) {
|
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
|
||||||
if (TK_NK_LP == sToken.type) {
|
|
||||||
++expectRightParenthesis;
|
|
||||||
} else if (TK_NK_RP == sToken.type && 0 == --expectRightParenthesis) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (0 == sToken.n) {
|
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, ") expected", NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t skipBoundColumns(SInsertParseSyntaxCxt* pCxt) { return skipParentheses(pCxt); }
|
|
||||||
|
|
||||||
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
||||||
static int32_t skipValuesClause(SInsertParseSyntaxCxt* pCxt) {
|
static int32_t skipValuesClause(SInsertParseSyntaxCxt* pCxt) {
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
|
@ -1717,8 +1748,25 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
|
||||||
SToken tbnameToken = sToken;
|
SToken tbnameToken = sToken;
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
|
||||||
|
bool existedUsing = false;
|
||||||
// USING clause
|
// USING clause
|
||||||
if (TK_USING == sToken.type) {
|
if (TK_USING == sToken.type) {
|
||||||
|
existedUsing = true;
|
||||||
|
CHECK_CODE(collectAutoCreateTableMetaKey(pCxt, &tbnameToken));
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
CHECK_CODE(collectTableMetaKey(pCxt, &sToken));
|
||||||
|
CHECK_CODE(skipUsingClause(pCxt));
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TK_NK_LP == sToken.type) {
|
||||||
|
// pSql -> field1_name, ...)
|
||||||
|
CHECK_CODE(skipBoundColumns(pCxt));
|
||||||
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TK_USING == sToken.type && !existedUsing) {
|
||||||
|
existedUsing = true;
|
||||||
CHECK_CODE(collectAutoCreateTableMetaKey(pCxt, &tbnameToken));
|
CHECK_CODE(collectAutoCreateTableMetaKey(pCxt, &tbnameToken));
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
CHECK_CODE(collectTableMetaKey(pCxt, &sToken));
|
CHECK_CODE(collectTableMetaKey(pCxt, &sToken));
|
||||||
|
@ -1728,12 +1776,6 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
|
||||||
CHECK_CODE(collectTableMetaKey(pCxt, &tbnameToken));
|
CHECK_CODE(collectTableMetaKey(pCxt, &tbnameToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TK_NK_LP == sToken.type) {
|
|
||||||
// pSql -> field1_name, ...)
|
|
||||||
CHECK_CODE(skipBoundColumns(pCxt));
|
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TK_VALUES == sToken.type) {
|
if (TK_VALUES == sToken.type) {
|
||||||
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
||||||
CHECK_CODE(skipValuesClause(pCxt));
|
CHECK_CODE(skipValuesClause(pCxt));
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -215,13 +215,21 @@ int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...) {
|
||||||
return errCode;
|
return errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t generateSyntaxErrMsgExt(SMsgBuf* pBuf, int32_t errCode, const char* pFormat, ...) {
|
||||||
|
va_list vArgList;
|
||||||
|
va_start(vArgList, pFormat);
|
||||||
|
vsnprintf(pBuf->buf, pBuf->len, pFormat, vArgList);
|
||||||
|
va_end(vArgList);
|
||||||
|
return errCode;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
|
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
|
||||||
strncpy(pBuf->buf, msg, pBuf->len);
|
strncpy(pBuf->buf, msg, pBuf->len);
|
||||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr) {
|
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr) {
|
||||||
if(pBuf == NULL) return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
if (pBuf == NULL) return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||||
const char* msgFormat1 = "syntax error near \'%s\'";
|
const char* msgFormat1 = "syntax error near \'%s\'";
|
||||||
const char* msgFormat2 = "syntax error near \'%s\' (%s)";
|
const char* msgFormat2 = "syntax error near \'%s\' (%s)";
|
||||||
const char* msgFormat3 = "%s";
|
const char* msgFormat3 = "%s";
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -159,7 +159,7 @@ void generatePerformanceSchema(MockCatalogService* mcs) {
|
||||||
* c4 | column | DOUBLE | 8 |
|
* c4 | column | DOUBLE | 8 |
|
||||||
* c5 | column | DOUBLE | 8 |
|
* c5 | column | DOUBLE | 8 |
|
||||||
*/
|
*/
|
||||||
void generateTestT1(MockCatalogService* mcs) {
|
void generateTestTables(MockCatalogService* mcs) {
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
.setVgid(1)
|
.setVgid(1)
|
||||||
|
@ -183,23 +183,7 @@ void generateTestT1(MockCatalogService* mcs) {
|
||||||
* tag2 | tag | VARCHAR | 20 |
|
* tag2 | tag | VARCHAR | 20 |
|
||||||
* tag3 | tag | TIMESTAMP | 8 |
|
* tag3 | tag | TIMESTAMP | 8 |
|
||||||
* Child Table: st1s1, st1s2
|
* Child Table: st1s1, st1s2
|
||||||
*/
|
*
|
||||||
void generateTestST1(MockCatalogService* mcs) {
|
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 3)
|
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
|
||||||
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
|
||||||
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
|
||||||
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
|
||||||
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
|
||||||
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
|
|
||||||
.addTag("tag3", TSDB_DATA_TYPE_TIMESTAMP);
|
|
||||||
builder.done();
|
|
||||||
mcs->createSubTable("test", "st1", "st1s1", 1);
|
|
||||||
mcs->createSubTable("test", "st1", "st1s2", 2);
|
|
||||||
mcs->createSubTable("test", "st1", "st1s3", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Super Table: st2
|
* Super Table: st2
|
||||||
* Field | Type | DataType | Bytes |
|
* Field | Type | DataType | Bytes |
|
||||||
* ==========================================================================
|
* ==========================================================================
|
||||||
|
@ -209,16 +193,32 @@ void generateTestST1(MockCatalogService* mcs) {
|
||||||
* jtag | tag | json | -- |
|
* jtag | tag | json | -- |
|
||||||
* Child Table: st2s1, st2s2
|
* Child Table: st2s1, st2s2
|
||||||
*/
|
*/
|
||||||
void generateTestST2(MockCatalogService* mcs) {
|
void generateTestStables(MockCatalogService* mcs) {
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st2", TSDB_SUPER_TABLE, 3, 1)
|
{
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 3)
|
||||||
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||||
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||||
.addTag("jtag", TSDB_DATA_TYPE_JSON);
|
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
builder.done();
|
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
||||||
mcs->createSubTable("test", "st2", "st2s1", 1);
|
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
mcs->createSubTable("test", "st2", "st2s2", 2);
|
.addTag("tag3", TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
|
builder.done();
|
||||||
|
mcs->createSubTable("test", "st1", "st1s1", 1);
|
||||||
|
mcs->createSubTable("test", "st1", "st1s2", 2);
|
||||||
|
mcs->createSubTable("test", "st1", "st1s3", 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ITableBuilder& builder = mcs->createTableBuilder("test", "st2", TSDB_SUPER_TABLE, 3, 1)
|
||||||
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
|
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||||
|
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||||
|
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
|
.addTag("jtag", TSDB_DATA_TYPE_JSON);
|
||||||
|
builder.done();
|
||||||
|
mcs->createSubTable("test", "st2", "st2s1", 1);
|
||||||
|
mcs->createSubTable("test", "st2", "st2s2", 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateFunctions(MockCatalogService* mcs) {
|
void generateFunctions(MockCatalogService* mcs) {
|
||||||
|
@ -233,6 +233,11 @@ void generateDnodes(MockCatalogService* mcs) {
|
||||||
mcs->createDnode(3, "host3", 7030);
|
mcs->createDnode(3, "host3", 7030);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void generateDatabases(MockCatalogService* mcs) {
|
||||||
|
mcs->createDatabase("test");
|
||||||
|
mcs->createDatabase("rollup_db", true);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
||||||
|
@ -262,7 +267,7 @@ int32_t __catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg) {
|
int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg) {
|
||||||
return 0;
|
return g_mockCatalogService->catalogGetDBCfg(dbFName, pDbCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||||
|
@ -359,11 +364,11 @@ void initMetaDataEnv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateMetaData() {
|
void generateMetaData() {
|
||||||
|
generateDatabases(g_mockCatalogService.get());
|
||||||
generateInformationSchema(g_mockCatalogService.get());
|
generateInformationSchema(g_mockCatalogService.get());
|
||||||
generatePerformanceSchema(g_mockCatalogService.get());
|
generatePerformanceSchema(g_mockCatalogService.get());
|
||||||
generateTestT1(g_mockCatalogService.get());
|
generateTestTables(g_mockCatalogService.get());
|
||||||
generateTestST1(g_mockCatalogService.get());
|
generateTestStables(g_mockCatalogService.get());
|
||||||
generateTestST2(g_mockCatalogService.get());
|
|
||||||
generateFunctions(g_mockCatalogService.get());
|
generateFunctions(g_mockCatalogService.get());
|
||||||
generateDnodes(g_mockCatalogService.get());
|
generateDnodes(g_mockCatalogService.get());
|
||||||
g_mockCatalogService->showTables();
|
g_mockCatalogService->showTables();
|
||||||
|
|
|
@ -140,6 +140,17 @@ class MockCatalogServiceImpl {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const {
|
||||||
|
std::string dbFName(pDbFName);
|
||||||
|
DbCfgCache::const_iterator it = dbCfg_.find(dbFName.substr(std::string(pDbFName).find_last_of('.') + 1));
|
||||||
|
if (dbCfg_.end() == it) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pDbCfg, &(it->second), sizeof(SDbCfgInfo));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const {
|
int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const {
|
||||||
auto it = udf_.find(funcName);
|
auto it = udf_.find(funcName);
|
||||||
if (udf_.end() == it) {
|
if (udf_.end() == it) {
|
||||||
|
@ -323,12 +334,21 @@ class MockCatalogServiceImpl {
|
||||||
dnode_.insert(std::make_pair(dnodeId, epSet));
|
dnode_.insert(std::make_pair(dnodeId, epSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createDatabase(const std::string& db, bool rollup) {
|
||||||
|
SDbCfgInfo cfg = {0};
|
||||||
|
if (rollup) {
|
||||||
|
cfg.pRetensions = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SRetention));
|
||||||
|
}
|
||||||
|
dbCfg_.insert(std::make_pair(db, cfg));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, std::shared_ptr<MockTableMeta>> TableMetaCache;
|
typedef std::map<std::string, std::shared_ptr<MockTableMeta>> TableMetaCache;
|
||||||
typedef std::map<std::string, TableMetaCache> DbMetaCache;
|
typedef std::map<std::string, TableMetaCache> DbMetaCache;
|
||||||
typedef std::map<std::string, std::shared_ptr<SFuncInfo>> UdfMetaCache;
|
typedef std::map<std::string, std::shared_ptr<SFuncInfo>> UdfMetaCache;
|
||||||
typedef std::map<std::string, std::vector<STableIndexInfo>> IndexMetaCache;
|
typedef std::map<std::string, std::vector<STableIndexInfo>> IndexMetaCache;
|
||||||
typedef std::map<int32_t, SEpSet> DnodeCache;
|
typedef std::map<int32_t, SEpSet> DnodeCache;
|
||||||
|
typedef std::map<std::string, SDbCfgInfo> DbCfgCache;
|
||||||
|
|
||||||
uint64_t getNextId() { return id_++; }
|
uint64_t getNextId() { return id_++; }
|
||||||
|
|
||||||
|
@ -486,6 +506,7 @@ class MockCatalogServiceImpl {
|
||||||
for (int32_t i = 0; i < ndbs; ++i) {
|
for (int32_t i = 0; i < ndbs; ++i) {
|
||||||
SMetaRes res = {0};
|
SMetaRes res = {0};
|
||||||
res.pRes = taosMemoryCalloc(1, sizeof(SDbCfgInfo));
|
res.pRes = taosMemoryCalloc(1, sizeof(SDbCfgInfo));
|
||||||
|
res.code = catalogGetDBCfg((const char*)taosArrayGet(pDbCfgReq, i), (SDbCfgInfo*)res.pRes);
|
||||||
taosArrayPush(*pDbCfgData, &res);
|
taosArrayPush(*pDbCfgData, &res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,6 +597,7 @@ class MockCatalogServiceImpl {
|
||||||
UdfMetaCache udf_;
|
UdfMetaCache udf_;
|
||||||
IndexMetaCache index_;
|
IndexMetaCache index_;
|
||||||
DnodeCache dnode_;
|
DnodeCache dnode_;
|
||||||
|
DbCfgCache dbCfg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {}
|
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {}
|
||||||
|
@ -605,6 +627,8 @@ void MockCatalogService::createDnode(int32_t dnodeId, const std::string& host, i
|
||||||
impl_->createDnode(dnodeId, host, port);
|
impl_->createDnode(dnodeId, host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MockCatalogService::createDatabase(const std::string& db, bool rollup) { impl_->createDatabase(db, rollup); }
|
||||||
|
|
||||||
int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
|
int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
|
||||||
return impl_->catalogGetTableMeta(pTableName, pTableMeta);
|
return impl_->catalogGetTableMeta(pTableName, pTableMeta);
|
||||||
}
|
}
|
||||||
|
@ -621,6 +645,10 @@ int32_t MockCatalogService::catalogGetDBVgInfo(const char* pDbFName, SArray** pV
|
||||||
return impl_->catalogGetDBVgInfo(pDbFName, pVgList);
|
return impl_->catalogGetDBVgInfo(pDbFName, pVgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t MockCatalogService::catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const {
|
||||||
|
return impl_->catalogGetDBCfg(pDbFName, pDbCfg);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t MockCatalogService::catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const {
|
int32_t MockCatalogService::catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const {
|
||||||
return impl_->catalogGetUdfInfo(funcName, pInfo);
|
return impl_->catalogGetUdfInfo(funcName, pInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,11 +63,13 @@ class MockCatalogService {
|
||||||
void createFunction(const std::string& func, int8_t funcType, int8_t outputType, int32_t outputLen, int32_t bufSize);
|
void createFunction(const std::string& func, int8_t funcType, int8_t outputType, int32_t outputLen, int32_t bufSize);
|
||||||
void createSmaIndex(const SMCreateSmaReq* pReq);
|
void createSmaIndex(const SMCreateSmaReq* pReq);
|
||||||
void createDnode(int32_t dnodeId, const std::string& host, int16_t port);
|
void createDnode(int32_t dnodeId, const std::string& host, int16_t port);
|
||||||
|
void createDatabase(const std::string& db, bool rollup = false);
|
||||||
|
|
||||||
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const;
|
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const;
|
||||||
int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const;
|
int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const;
|
||||||
int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const;
|
int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const;
|
||||||
int32_t catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const;
|
int32_t catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const;
|
||||||
|
int32_t catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const;
|
||||||
int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const;
|
int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const;
|
||||||
int32_t catalogGetTableIndex(const SName* pTableName, SArray** pIndexes) const;
|
int32_t catalogGetTableIndex(const SName* pTableName, SArray** pIndexes) const;
|
||||||
int32_t catalogGetDnodeList(SArray** pDnodes) const;
|
int32_t catalogGetDnodeList(SArray** pDnodes) const;
|
||||||
|
|
|
@ -38,9 +38,9 @@ TEST_F(ParserInitialATest, alterDnode) {
|
||||||
TEST_F(ParserInitialATest, alterDatabase) {
|
TEST_F(ParserInitialATest, alterDatabase) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("ALTER DATABASE wxy_db CACHELAST 1 FSYNC 200 WAL 1");
|
run("ALTER DATABASE test CACHELAST 1 FSYNC 200 WAL 1");
|
||||||
|
|
||||||
run("ALTER DATABASE wxy_db KEEP 2400");
|
run("ALTER DATABASE test KEEP 2400");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialATest, alterLocal) {
|
TEST_F(ParserInitialATest, alterLocal) {
|
||||||
|
@ -77,8 +77,6 @@ TEST_F(ParserInitialATest, alterLocal) {
|
||||||
clearAlterLocal();
|
clearAlterLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo ALTER stable
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ALTER TABLE [db_name.]tb_name alter_table_clause
|
* ALTER TABLE [db_name.]tb_name alter_table_clause
|
||||||
*
|
*
|
||||||
|
@ -157,7 +155,7 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
};
|
};
|
||||||
|
|
||||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||||
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_TABLE_STMT);
|
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_SUPER_TABLE_STMT);
|
||||||
SMAlterStbReq req = {0};
|
SMAlterStbReq req = {0};
|
||||||
ASSERT_EQ(tDeserializeSMAlterStbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(tDeserializeSMAlterStbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
|
||||||
ASSERT_EQ(std::string(req.name), std::string(expect.name));
|
ASSERT_EQ(std::string(req.name), std::string(expect.name));
|
||||||
|
@ -181,44 +179,44 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
|
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
|
||||||
// run("ALTER TABLE st1 TTL 10");
|
// run("ALTER STABLE st1 TTL 10");
|
||||||
// clearAlterStbReq();
|
// clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test");
|
||||||
run("ALTER TABLE st1 COMMENT 'test'");
|
run("ALTER STABLE st1 COMMENT 'test'");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_ADD_COLUMN, 1, "cc1", TSDB_DATA_TYPE_BIGINT);
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_ADD_COLUMN, 1, "cc1", TSDB_DATA_TYPE_BIGINT);
|
||||||
run("ALTER TABLE st1 ADD COLUMN cc1 BIGINT");
|
run("ALTER STABLE st1 ADD COLUMN cc1 BIGINT");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_DROP_COLUMN, 1, "c1");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_DROP_COLUMN, 1, "c1");
|
||||||
run("ALTER TABLE st1 DROP COLUMN c1");
|
run("ALTER STABLE st1 DROP COLUMN c1");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 1, "c2", TSDB_DATA_TYPE_VARCHAR,
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 1, "c2", TSDB_DATA_TYPE_VARCHAR,
|
||||||
30 + VARSTR_HEADER_SIZE);
|
30 + VARSTR_HEADER_SIZE);
|
||||||
run("ALTER TABLE st1 MODIFY COLUMN c2 VARCHAR(30)");
|
run("ALTER STABLE st1 MODIFY COLUMN c2 VARCHAR(30)");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
|
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
|
||||||
// run("ALTER TABLE st1 RENAME COLUMN c1 cc1");
|
// run("ALTER STABLE st1 RENAME COLUMN c1 cc1");
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_ADD_TAG, 1, "tag11", TSDB_DATA_TYPE_BIGINT);
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_ADD_TAG, 1, "tag11", TSDB_DATA_TYPE_BIGINT);
|
||||||
run("ALTER TABLE st1 ADD TAG tag11 BIGINT");
|
run("ALTER STABLE st1 ADD TAG tag11 BIGINT");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_DROP_TAG, 1, "tag1");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_DROP_TAG, 1, "tag1");
|
||||||
run("ALTER TABLE st1 DROP TAG tag1");
|
run("ALTER STABLE st1 DROP TAG tag1");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag2", TSDB_DATA_TYPE_VARCHAR,
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag2", TSDB_DATA_TYPE_VARCHAR,
|
||||||
30 + VARSTR_HEADER_SIZE);
|
30 + VARSTR_HEADER_SIZE);
|
||||||
run("ALTER TABLE st1 MODIFY TAG tag2 VARCHAR(30)");
|
run("ALTER STABLE st1 MODIFY TAG tag2 VARCHAR(30)");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
|
||||||
run("ALTER TABLE st1 RENAME TAG tag1 tag11");
|
run("ALTER STABLE st1 RENAME TAG tag1 tag11");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
|
@ -228,11 +226,11 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
TEST_F(ParserInitialATest, alterSTableSemanticCheck) {
|
TEST_F(ParserInitialATest, alterSTableSemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("ALTER TABLE st1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
run("ALTER STABLE st1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
|
|
||||||
run("ALTER TABLE st1 MODIFY COLUMN c2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
run("ALTER STABLE st1 MODIFY COLUMN c2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||||
|
|
||||||
run("ALTER TABLE st1 MODIFY TAG tag2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
run("ALTER STABLE st1 MODIFY TAG tag2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialATest, alterTable) {
|
TEST_F(ParserInitialATest, alterTable) {
|
||||||
|
|
|
@ -359,11 +359,11 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
memset(&expect, 0, sizeof(SMCreateStbReq));
|
memset(&expect, 0, sizeof(SMCreateStbReq));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto setCreateStbReqFunc = [&](const char* pTbname, int8_t igExists = 0, int64_t delay1 = -1, int64_t delay2 = -1,
|
auto setCreateStbReqFunc = [&](const char* pDbName, const char* pTbName, int8_t igExists = 0, int64_t delay1 = -1,
|
||||||
int64_t watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK,
|
int64_t delay2 = -1, int64_t watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK,
|
||||||
int64_t watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK,
|
int64_t watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK,
|
||||||
int32_t ttl = TSDB_DEFAULT_TABLE_TTL, const char* pComment = nullptr) {
|
int32_t ttl = TSDB_DEFAULT_TABLE_TTL, const char* pComment = nullptr) {
|
||||||
int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname);
|
int32_t len = snprintf(expect.name, sizeof(expect.name), "0.%s.%s", pDbName, pTbName);
|
||||||
expect.name[len] = '\0';
|
expect.name[len] = '\0';
|
||||||
expect.igExists = igExists;
|
expect.igExists = igExists;
|
||||||
expect.delay1 = delay1;
|
expect.delay1 = delay1;
|
||||||
|
@ -454,14 +454,14 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
tFreeSMCreateStbReq(&req);
|
tFreeSMCreateStbReq(&req);
|
||||||
});
|
});
|
||||||
|
|
||||||
setCreateStbReqFunc("t1");
|
setCreateStbReqFunc("test", "t1");
|
||||||
addFieldToCreateStbReqFunc(true, "ts", TSDB_DATA_TYPE_TIMESTAMP);
|
addFieldToCreateStbReqFunc(true, "ts", TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
addFieldToCreateStbReqFunc(true, "c1", TSDB_DATA_TYPE_INT);
|
addFieldToCreateStbReqFunc(true, "c1", TSDB_DATA_TYPE_INT);
|
||||||
addFieldToCreateStbReqFunc(false, "id", TSDB_DATA_TYPE_INT);
|
addFieldToCreateStbReqFunc(false, "id", TSDB_DATA_TYPE_INT);
|
||||||
run("CREATE STABLE t1(ts TIMESTAMP, c1 INT) TAGS(id INT)");
|
run("CREATE STABLE t1(ts TIMESTAMP, c1 INT) TAGS(id INT)");
|
||||||
clearCreateStbReq();
|
clearCreateStbReq();
|
||||||
|
|
||||||
setCreateStbReqFunc("t1", 1, 100 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_MINUTE, 10,
|
setCreateStbReqFunc("rollup_db", "t1", 1, 100 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_MINUTE, 10,
|
||||||
1 * MILLISECOND_PER_MINUTE, 100, "test create table");
|
1 * MILLISECOND_PER_MINUTE, 100, "test create table");
|
||||||
addFieldToCreateStbReqFunc(true, "ts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
|
addFieldToCreateStbReqFunc(true, "ts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
|
||||||
addFieldToCreateStbReqFunc(true, "c1", TSDB_DATA_TYPE_INT);
|
addFieldToCreateStbReqFunc(true, "c1", TSDB_DATA_TYPE_INT);
|
||||||
|
@ -493,7 +493,7 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
addFieldToCreateStbReqFunc(false, "a13", TSDB_DATA_TYPE_BOOL);
|
addFieldToCreateStbReqFunc(false, "a13", TSDB_DATA_TYPE_BOOL);
|
||||||
addFieldToCreateStbReqFunc(false, "a14", TSDB_DATA_TYPE_NCHAR, 30 * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
addFieldToCreateStbReqFunc(false, "a14", TSDB_DATA_TYPE_NCHAR, 30 * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
||||||
addFieldToCreateStbReqFunc(false, "a15", TSDB_DATA_TYPE_VARCHAR, 50 + VARSTR_HEADER_SIZE);
|
addFieldToCreateStbReqFunc(false, "a15", TSDB_DATA_TYPE_VARCHAR, 50 + VARSTR_HEADER_SIZE);
|
||||||
run("CREATE STABLE IF NOT EXISTS test.t1("
|
run("CREATE STABLE IF NOT EXISTS rollup_db.t1("
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
||||||
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
||||||
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
||||||
|
@ -507,12 +507,13 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
TEST_F(ParserInitialCTest, createStableSemanticCheck) {
|
TEST_F(ParserInitialCTest, createStableSemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(CEIL)", TSDB_CODE_PAR_INVALID_ROLLUP_OPTION);
|
run("CREATE STABLE rollup_db.stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(CEIL)",
|
||||||
|
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION);
|
||||||
|
|
||||||
run("CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 0s WATERMARK 1m",
|
run("CREATE STABLE rollup_db.stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 0s WATERMARK 1m",
|
||||||
TSDB_CODE_PAR_INVALID_RANGE_OPTION);
|
TSDB_CODE_PAR_INVALID_RANGE_OPTION);
|
||||||
|
|
||||||
run("CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 10s WATERMARK 18m",
|
run("CREATE STABLE rollup_db.stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 10s WATERMARK 18m",
|
||||||
TSDB_CODE_PAR_INVALID_RANGE_OPTION);
|
TSDB_CODE_PAR_INVALID_RANGE_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,30 +562,33 @@ TEST_F(ParserInitialCTest, createStream) {
|
||||||
tFreeSCMCreateStreamReq(&req);
|
tFreeSCMCreateStreamReq(&req);
|
||||||
});
|
});
|
||||||
|
|
||||||
setCreateStreamReqFunc("s1", "test", "create stream s1 as select * from t1");
|
setCreateStreamReqFunc("s1", "test", "create stream s1 as select count(*) from t1 interval(10s)");
|
||||||
run("CREATE STREAM s1 AS SELECT * FROM t1");
|
run("CREATE STREAM s1 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)");
|
||||||
clearCreateStreamReq();
|
clearCreateStreamReq();
|
||||||
|
|
||||||
setCreateStreamReqFunc("s1", "test", "create stream if not exists s1 as select * from t1", nullptr, 1);
|
setCreateStreamReqFunc("s1", "test", "create stream if not exists s1 as select count(*) from t1 interval(10s)",
|
||||||
run("CREATE STREAM IF NOT EXISTS s1 AS SELECT * FROM t1");
|
nullptr, 1);
|
||||||
|
run("CREATE STREAM IF NOT EXISTS s1 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)");
|
||||||
clearCreateStreamReq();
|
clearCreateStreamReq();
|
||||||
|
|
||||||
setCreateStreamReqFunc("s1", "test", "create stream s1 into st1 as select * from t1", "st1");
|
setCreateStreamReqFunc("s1", "test", "create stream s1 into st1 as select count(*) from t1 interval(10s)", "st1");
|
||||||
run("CREATE STREAM s1 INTO st1 AS SELECT * FROM t1");
|
run("CREATE STREAM s1 INTO st1 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)");
|
||||||
clearCreateStreamReq();
|
clearCreateStreamReq();
|
||||||
|
|
||||||
setCreateStreamReqFunc(
|
setCreateStreamReqFunc("s1", "test",
|
||||||
"s1", "test",
|
"create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired into st1 "
|
||||||
"create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired into st1 as select * from t1",
|
"as select count(*) from t1 interval(10s)",
|
||||||
"st1", 1, STREAM_TRIGGER_MAX_DELAY, 20 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_SECOND, 1);
|
"st1", 1, STREAM_TRIGGER_MAX_DELAY, 20 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_SECOND,
|
||||||
run("CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED INTO st1 AS SELECT * FROM t1");
|
1);
|
||||||
|
run("CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED INTO st1 AS SELECT COUNT(*) "
|
||||||
|
"FROM t1 INTERVAL(10S)");
|
||||||
clearCreateStreamReq();
|
clearCreateStreamReq();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialCTest, createStreamSemanticCheck) {
|
TEST_F(ParserInitialCTest, createStreamSemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("CREATE STREAM s1 AS SELECT PERCENTILE(c1, 30) FROM t1", TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC);
|
run("CREATE STREAM s1 AS SELECT PERCENTILE(c1, 30) FROM t1 INTERVAL(10S)", TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialCTest, createTable) {
|
TEST_F(ParserInitialCTest, createTable) {
|
||||||
|
@ -598,7 +602,7 @@ TEST_F(ParserInitialCTest, createTable) {
|
||||||
"c13 NCHAR(30), c15 VARCHAR(50)) "
|
"c13 NCHAR(30), c15 VARCHAR(50)) "
|
||||||
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
||||||
|
|
||||||
run("CREATE TABLE IF NOT EXISTS test.t1("
|
run("CREATE TABLE IF NOT EXISTS rollup_db.t1("
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
||||||
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
||||||
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
||||||
|
@ -617,6 +621,21 @@ TEST_F(ParserInitialCTest, createTable) {
|
||||||
// run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW + 1S)");
|
// run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW + 1S)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserInitialCTest, createTableSemanticCheck) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
string sql = "CREATE TABLE st1(ts TIMESTAMP, ";
|
||||||
|
for (int32_t i = 1; i < 4096; ++i) {
|
||||||
|
if (i > 1) {
|
||||||
|
sql.append(", ");
|
||||||
|
}
|
||||||
|
sql.append("c" + to_string(i) + " INT");
|
||||||
|
}
|
||||||
|
sql.append(") TAGS (t1 int)");
|
||||||
|
|
||||||
|
run(sql, TSDB_CODE_PAR_TOO_MANY_COLUMNS);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialCTest, createTopic) {
|
TEST_F(ParserInitialCTest, createTopic) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
|
|
@ -480,12 +480,18 @@ static int32_t pushDownCondOptPushCondToProject(SOptimizeContext* pCxt, SProject
|
||||||
return pushDownCondOptAppendCond(&pProject->node.pConditions, pCond);
|
return pushDownCondOptAppendCond(&pProject->node.pConditions, pCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicNode * pJoin, SNode** pCond) {
|
||||||
|
return pushDownCondOptAppendCond(&pJoin->node.pConditions, pCond);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t pushDownCondOptPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) {
|
static int32_t pushDownCondOptPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) {
|
||||||
switch (nodeType(pChild)) {
|
switch (nodeType(pChild)) {
|
||||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||||
return pushDownCondOptPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond);
|
return pushDownCondOptPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond);
|
||||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||||
return pushDownCondOptPushCondToProject(pCxt, (SProjectLogicNode*)pChild, pCond);
|
return pushDownCondOptPushCondToProject(pCxt, (SProjectLogicNode*)pChild, pCond);
|
||||||
|
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||||
|
return pushDownCondOptPushCondToJoin(pCxt, (SJoinLogicNode*)pChild, pCond);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -554,13 +560,83 @@ static int32_t pushDownCondOptCheckJoinOnCond(SOptimizeContext* pCxt, SJoinLogic
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t pushDownCondOptPartJoinOnCondLogicCond(SJoinLogicNode* pJoin, SNode** ppMergeCond, SNode** ppOnCond) {
|
||||||
|
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pJoin->pOnConditions);
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
SNodeList* pOnConds = NULL;
|
||||||
|
SNode* pCond = NULL;
|
||||||
|
FOREACH(pCond, pLogicCond->pParameterList) {
|
||||||
|
if (pushDownCondOptIsPriKeyEqualCond(pJoin, pCond)) {
|
||||||
|
*ppMergeCond = nodesCloneNode(pCond);
|
||||||
|
} else {
|
||||||
|
code = nodesListMakeAppend(&pOnConds, nodesCloneNode(pCond));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* pTempOnCond = NULL;
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesMergeConds(&pTempOnCond, &pOnConds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != *ppMergeCond) {
|
||||||
|
*ppOnCond = pTempOnCond;
|
||||||
|
nodesDestroyNode(pJoin->pOnConditions);
|
||||||
|
pJoin->pOnConditions = NULL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else {
|
||||||
|
nodesDestroyList(pOnConds);
|
||||||
|
nodesDestroyNode(pTempOnCond);
|
||||||
|
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t pushDownCondOptPartJoinOnCond(SJoinLogicNode* pJoin, SNode** ppMergeCond, SNode** ppOnCond) {
|
||||||
|
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->pOnConditions) &&
|
||||||
|
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)(pJoin->pOnConditions))->condType) {
|
||||||
|
return pushDownCondOptPartJoinOnCondLogicCond(pJoin, ppMergeCond, ppOnCond);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pushDownCondOptIsPriKeyEqualCond(pJoin, pJoin->pOnConditions)) {
|
||||||
|
*ppMergeCond = nodesCloneNode(pJoin->pOnConditions);
|
||||||
|
*ppOnCond = NULL;
|
||||||
|
nodesDestroyNode(pJoin->pOnConditions);
|
||||||
|
pJoin->pOnConditions = NULL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t pushDownCondOptJoinExtractMergeCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
||||||
|
int32_t code = pushDownCondOptCheckJoinOnCond(pCxt, pJoin);
|
||||||
|
SNode* pJoinMergeCond = NULL;
|
||||||
|
SNode* pJoinOnCond = NULL;
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = pushDownCondOptPartJoinOnCond(pJoin, &pJoinMergeCond, &pJoinOnCond);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pJoin->pMergeCondition = pJoinMergeCond;
|
||||||
|
pJoin->pOnConditions = pJoinOnCond;
|
||||||
|
} else {
|
||||||
|
nodesDestroyNode(pJoinMergeCond);
|
||||||
|
nodesDestroyNode(pJoinOnCond);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) {
|
||||||
if (OPTIMIZE_FLAG_TEST_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE)) {
|
if (OPTIMIZE_FLAG_TEST_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pJoin->node.pConditions) {
|
if (NULL == pJoin->node.pConditions) {
|
||||||
return pushDownCondOptCheckJoinOnCond(pCxt, pJoin);
|
int32_t code = pushDownCondOptJoinExtractMergeCond(pCxt, pJoin);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
OPTIMIZE_FLAG_SET_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE);
|
||||||
|
pCxt->optimized = true;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* pOnCond = NULL;
|
SNode* pOnCond = NULL;
|
||||||
|
@ -579,10 +655,13 @@ static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* p
|
||||||
pushDownCondOptPushCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1), &pRightChildCond);
|
pushDownCondOptPushCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1), &pRightChildCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = pushDownCondOptJoinExtractMergeCond(pCxt, pJoin);
|
||||||
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
OPTIMIZE_FLAG_SET_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE);
|
OPTIMIZE_FLAG_SET_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE);
|
||||||
pCxt->optimized = true;
|
pCxt->optimized = true;
|
||||||
code = pushDownCondOptCheckJoinOnCond(pCxt, pJoin);
|
|
||||||
} else {
|
} else {
|
||||||
nodesDestroyNode(pOnCond);
|
nodesDestroyNode(pOnCond);
|
||||||
nodesDestroyNode(pLeftChildCond);
|
nodesDestroyNode(pLeftChildCond);
|
||||||
|
@ -720,7 +799,8 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
|
||||||
// TODO: remove it after full implementation of pushing down to child
|
// TODO: remove it after full implementation of pushing down to child
|
||||||
if (1 != LIST_LENGTH(pAgg->node.pChildren) ||
|
if (1 != LIST_LENGTH(pAgg->node.pChildren) ||
|
||||||
QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pAgg->node.pChildren, 0)) &&
|
QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pAgg->node.pChildren, 0)) &&
|
||||||
QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(nodesListGetNode(pAgg->node.pChildren, 0))) {
|
QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(nodesListGetNode(pAgg->node.pChildren, 0)) &&
|
||||||
|
QUERY_NODE_LOGIC_PLAN_JOIN != nodeType(nodesListGetNode(pAgg->node.pChildren, 0))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1251,7 +1331,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pFunc->functionName, pFuncName);
|
strcpy(pFunc->functionName, pFuncName);
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TBNAME != ((SColumnNode*)pNode)->colType) {
|
||||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||||
partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName);
|
partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1868,6 +1948,8 @@ static EDealRes mergeProjectionsExpr(SNode** pNode, void* pContext) {
|
||||||
pCxt->errCode = terrno;
|
pCxt->errCode = terrno;
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
snprintf(((SExprNode*)pExpr)->aliasName, sizeof(((SExprNode*)pExpr)->aliasName), "%s",
|
||||||
|
((SExprNode*)*pNode)->aliasName);
|
||||||
nodesDestroyNode(*pNode);
|
nodesDestroyNode(*pNode);
|
||||||
*pNode = pExpr;
|
*pNode = pExpr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,6 +552,9 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
||||||
if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLES) ||
|
if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLES) ||
|
||||||
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED)) {
|
0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED)) {
|
||||||
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
|
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
|
||||||
|
} else {
|
||||||
|
pSubplan->execNode.nodeId = MNODE_HANDLE;
|
||||||
|
pSubplan->execNode.epSet = pCxt->pPlanCxt->mgmtEpSet;
|
||||||
}
|
}
|
||||||
SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0};
|
SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0};
|
||||||
taosArrayPush(pCxt->pExecNodeList, &node);
|
taosArrayPush(pCxt->pExecNodeList, &node);
|
||||||
|
@ -609,10 +612,8 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
pJoin->joinType = pJoinLogicNode->joinType;
|
pJoin->joinType = pJoinLogicNode->joinType;
|
||||||
if (NULL != pJoinLogicNode->pOnConditions) {
|
setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pMergeCondition,
|
||||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions,
|
&pJoin->pMergeCondition);
|
||||||
&pJoin->pOnConditions);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets,
|
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets,
|
||||||
&pJoin->pTargets);
|
&pJoin->pTargets);
|
||||||
|
@ -620,6 +621,21 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNodeList* condCols = nodesMakeList();
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pOnConditions) {
|
||||||
|
code = nodesCollectColumnsFromNode(pJoinLogicNode->pOnConditions, NULL, COLLECT_COL_TYPE_ALL, &condCols);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = addDataBlockSlots(pCxt, condCols, pJoin->node.pOutputDataBlockDesc);
|
||||||
|
nodesDestroyList(condCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pOnConditions) {
|
||||||
|
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pJoinLogicNode->pOnConditions,
|
||||||
|
&pJoin->pOnConditions);
|
||||||
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -986,6 +986,10 @@ static bool unionIsChildSubplan(SLogicNode* pLogicNode, int32_t groupId) {
|
||||||
return ((SExchangeLogicNode*)pLogicNode)->srcGroupId == groupId;
|
return ((SExchangeLogicNode*)pLogicNode)->srcGroupId == groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (QUERY_NODE_LOGIC_PLAN_MERGE == nodeType(pLogicNode)) {
|
||||||
|
return ((SMergeLogicNode*)pLogicNode)->srcGroupId == groupId;
|
||||||
|
}
|
||||||
|
|
||||||
SNode* pChild;
|
SNode* pChild;
|
||||||
FOREACH(pChild, pLogicNode->pChildren) {
|
FOREACH(pChild, pLogicNode->pChildren) {
|
||||||
bool isChild = unionIsChildSubplan((SLogicNode*)pChild, groupId);
|
bool isChild = unionIsChildSubplan((SLogicNode*)pChild, groupId);
|
||||||
|
@ -1014,14 +1018,14 @@ static int32_t unionMountSubplan(SLogicSubplan* pParent, SNodeList* pChildren) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SLogicSubplan* unionCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode) {
|
static SLogicSubplan* unionCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode, ESubplanType subplanType) {
|
||||||
SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
||||||
if (NULL == pSubplan) {
|
if (NULL == pSubplan) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pSubplan->id.queryId = pCxt->queryId;
|
pSubplan->id.queryId = pCxt->queryId;
|
||||||
pSubplan->id.groupId = pCxt->groupId;
|
pSubplan->id.groupId = pCxt->groupId;
|
||||||
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
|
pSubplan->subplanType = subplanType;
|
||||||
pSubplan->pNode = pNode;
|
pSubplan->pNode = pNode;
|
||||||
pNode->pParent = NULL;
|
pNode->pParent = NULL;
|
||||||
return pSubplan;
|
return pSubplan;
|
||||||
|
@ -1035,7 +1039,7 @@ static int32_t unionSplitSubplan(SSplitContext* pCxt, SLogicSubplan* pUnionSubpl
|
||||||
|
|
||||||
SNode* pChild = NULL;
|
SNode* pChild = NULL;
|
||||||
FOREACH(pChild, pSplitNode->pChildren) {
|
FOREACH(pChild, pSplitNode->pChildren) {
|
||||||
SLogicSubplan* pNewSubplan = unionCreateSubplan(pCxt, (SLogicNode*)pChild);
|
SLogicSubplan* pNewSubplan = unionCreateSubplan(pCxt, (SLogicNode*)pChild, pUnionSubplan->subplanType);
|
||||||
code = nodesListMakeStrictAppend(&pUnionSubplan->pChildren, (SNode*)pNewSubplan);
|
code = nodesListMakeStrictAppend(&pUnionSubplan->pChildren, (SNode*)pNewSubplan);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
REPLACE_NODE(NULL);
|
REPLACE_NODE(NULL);
|
||||||
|
@ -1216,6 +1220,7 @@ static int32_t qnodeSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||||
if (!splMatch(pCxt, pSubplan, 0, (FSplFindSplitNode)qndSplFindSplitNode, &info)) {
|
if (!splMatch(pCxt, pSubplan, 0, (FSplFindSplitNode)qndSplFindSplitNode, &info)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
((SScanLogicNode*)info.pSplitNode)->dataRequired = FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||||
int32_t code = splCreateExchangeNodeForSubplan(pCxt, info.pSubplan, info.pSplitNode, info.pSubplan->subplanType);
|
int32_t code = splCreateExchangeNodeForSubplan(pCxt, info.pSubplan, info.pSplitNode, info.pSubplan->subplanType);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
SLogicSubplan* pScanSubplan = splCreateScanSubplan(pCxt, info.pSplitNode, 0);
|
SLogicSubplan* pScanSubplan = splCreateScanSubplan(pCxt, info.pSplitNode, 0);
|
||||||
|
|
|
@ -68,6 +68,8 @@ TEST_F(PlanOptimizeTest, PartitionTags) {
|
||||||
run("SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1");
|
run("SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1");
|
||||||
|
|
||||||
run("SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10");
|
run("SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), tbname FROM st1 GROUP BY tbname");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanOptimizeTest, eliminateProjection) {
|
TEST_F(PlanOptimizeTest, eliminateProjection) {
|
||||||
|
|
|
@ -97,7 +97,15 @@ TEST_F(PlanSetOpTest, unionSubquery) {
|
||||||
run("SELECT * FROM (SELECT c1, c2 FROM t1 UNION SELECT c1, c2 FROM t1)");
|
run("SELECT * FROM (SELECT c1, c2 FROM t1 UNION SELECT c1, c2 FROM t1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanSetOpTest, bug001) {
|
TEST_F(PlanSetOpTest, unionWithSubquery) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT c1 FROM (SELECT c1 FROM st1) UNION SELECT c2 FROM (SELECT c1 AS c2 FROM st2)");
|
||||||
|
|
||||||
|
run("SELECT c1 FROM (SELECT c1 FROM st1 ORDER BY c2) UNION SELECT c1 FROM (SELECT c1 FROM st2)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PlanSetOpTest, unionDataTypeConversion) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("SELECT c2 FROM t1 WHERE c1 IS NOT NULL GROUP BY c2 "
|
run("SELECT c2 FROM t1 WHERE c1 IS NOT NULL GROUP BY c2 "
|
||||||
|
|
|
@ -1035,3 +1035,72 @@ _return:
|
||||||
sclFreeRes(ctx.pRes);
|
sclFreeRes(ctx.pRes);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t scalarGetOperatorResultType(SDataType left, SDataType right, EOperatorType op, SDataType* pRes) {
|
||||||
|
switch (op) {
|
||||||
|
case OP_TYPE_ADD:
|
||||||
|
if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type);
|
||||||
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
|
}
|
||||||
|
if ((left.type == TSDB_DATA_TYPE_TIMESTAMP && (IS_INTEGER_TYPE(right.type) || right.type == TSDB_DATA_TYPE_BOOL)) ||
|
||||||
|
(right.type == TSDB_DATA_TYPE_TIMESTAMP && (IS_INTEGER_TYPE(left.type) || left.type == TSDB_DATA_TYPE_BOOL))) {
|
||||||
|
pRes->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
pRes->type = TSDB_DATA_TYPE_DOUBLE;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case OP_TYPE_SUB:
|
||||||
|
if ((left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_BIGINT) ||
|
||||||
|
(right.type == TSDB_DATA_TYPE_TIMESTAMP && left.type == TSDB_DATA_TYPE_BIGINT)) {
|
||||||
|
pRes->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
pRes->type = TSDB_DATA_TYPE_DOUBLE;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case OP_TYPE_MULTI:
|
||||||
|
if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type);
|
||||||
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
|
}
|
||||||
|
case OP_TYPE_DIV:
|
||||||
|
if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type);
|
||||||
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
|
}
|
||||||
|
case OP_TYPE_REM:
|
||||||
|
case OP_TYPE_MINUS:
|
||||||
|
pRes->type = TSDB_DATA_TYPE_DOUBLE;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case OP_TYPE_GREATER_THAN:
|
||||||
|
case OP_TYPE_GREATER_EQUAL:
|
||||||
|
case OP_TYPE_LOWER_THAN:
|
||||||
|
case OP_TYPE_LOWER_EQUAL:
|
||||||
|
case OP_TYPE_EQUAL:
|
||||||
|
case OP_TYPE_NOT_EQUAL:
|
||||||
|
case OP_TYPE_IN:
|
||||||
|
case OP_TYPE_NOT_IN:
|
||||||
|
case OP_TYPE_LIKE:
|
||||||
|
case OP_TYPE_NOT_LIKE:
|
||||||
|
case OP_TYPE_MATCH:
|
||||||
|
case OP_TYPE_NMATCH:
|
||||||
|
case OP_TYPE_IS_NULL:
|
||||||
|
case OP_TYPE_IS_NOT_NULL:
|
||||||
|
case OP_TYPE_IS_TRUE:
|
||||||
|
case OP_TYPE_JSON_CONTAINS:
|
||||||
|
pRes->type = TSDB_DATA_TYPE_BOOL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case OP_TYPE_BIT_AND:
|
||||||
|
case OP_TYPE_BIT_OR:
|
||||||
|
pRes->type = TSDB_DATA_TYPE_BIGINT;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case OP_TYPE_JSON_GET_VALUE:
|
||||||
|
pRes->type = TSDB_DATA_TYPE_JSON;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
return TSDB_CODE_APP_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -360,9 +360,6 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
|
||||||
|
|
||||||
static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) {
|
static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) {
|
||||||
int32_t type = GET_PARAM_TYPE(pInput);
|
int32_t type = GET_PARAM_TYPE(pInput);
|
||||||
if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
SColumnInfoData *pInputData = pInput->columnData;
|
SColumnInfoData *pInputData = pInput->columnData;
|
||||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||||
|
@ -586,9 +583,6 @@ DONE:
|
||||||
|
|
||||||
static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) {
|
static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) {
|
||||||
int32_t type = GET_PARAM_TYPE(pInput);
|
int32_t type = GET_PARAM_TYPE(pInput);
|
||||||
if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
SColumnInfoData *pInputData = pInput->columnData;
|
SColumnInfoData *pInputData = pInput->columnData;
|
||||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||||
|
@ -628,9 +622,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
|
||||||
|
|
||||||
static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) {
|
static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) {
|
||||||
int32_t type = GET_PARAM_TYPE(pInput);
|
int32_t type = GET_PARAM_TYPE(pInput);
|
||||||
if (inputNum != 1 || !IS_VAR_DATA_TYPE(type)) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
SColumnInfoData *pInputData = pInput->columnData;
|
SColumnInfoData *pInputData = pInput->columnData;
|
||||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||||
|
@ -664,16 +655,10 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
|
||||||
int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
int32_t subPos = 0;
|
int32_t subPos = 0;
|
||||||
GET_TYPED_DATA(subPos, int32_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
|
GET_TYPED_DATA(subPos, int32_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
|
||||||
if (subPos == 0) { //subPos needs to be positive or negative values;
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t subLen = INT16_MAX;
|
int32_t subLen = INT16_MAX;
|
||||||
if (inputNum == 3) {
|
if (inputNum == 3) {
|
||||||
GET_TYPED_DATA(subLen, int32_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
GET_TYPED_DATA(subLen, int32_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||||
if (subLen < 0 || subLen > INT16_MAX) { //subLen cannot be negative
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE;
|
subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,13 +1134,6 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
|
||||||
|
|
||||||
int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
int32_t type = GET_PARAM_TYPE(pInput);
|
int32_t type = GET_PARAM_TYPE(pInput);
|
||||||
if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputNum != 1) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
char tmp[TSDB_MAX_JSON_TAG_LEN] = {0};
|
char tmp[TSDB_MAX_JSON_TAG_LEN] = {0};
|
||||||
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
||||||
|
@ -1196,6 +1174,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
|
||||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||||
|
|
||||||
|
timeUnit = timeUnit * 1000 / factor;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
||||||
if (colDataIsNull_s(pInput[0].columnData, i)) {
|
if (colDataIsNull_s(pInput[0].columnData, i)) {
|
||||||
colDataAppendNULL(pOutput->columnData, i);
|
colDataAppendNULL(pOutput->columnData, i);
|
||||||
|
@ -1228,7 +1208,6 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
|
||||||
char buf[20] = {0};
|
char buf[20] = {0};
|
||||||
NUM_TO_STRING(TSDB_DATA_TYPE_BIGINT, &timeVal, sizeof(buf), buf);
|
NUM_TO_STRING(TSDB_DATA_TYPE_BIGINT, &timeVal, sizeof(buf), buf);
|
||||||
int32_t tsDigits = (int32_t)strlen(buf);
|
int32_t tsDigits = (int32_t)strlen(buf);
|
||||||
timeUnit = timeUnit * 1000 / factor;
|
|
||||||
|
|
||||||
switch (timeUnit) {
|
switch (timeUnit) {
|
||||||
case 0: { /* 1u */
|
case 0: { /* 1u */
|
||||||
|
@ -1384,6 +1363,11 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
||||||
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||||
|
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||||
|
|
||||||
|
timeUnit = timeUnit * 1000 / factor;
|
||||||
|
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
for (int32_t i = 0; i < inputNum; ++i) {
|
for (int32_t i = 0; i < inputNum; ++i) {
|
||||||
if (pInput[i].numOfRows > numOfRows) {
|
if (pInput[i].numOfRows > numOfRows) {
|
||||||
|
@ -1463,9 +1447,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
|
||||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
|
||||||
timeUnit = timeUnit * 1000 / factor;
|
|
||||||
switch(timeUnit) {
|
switch(timeUnit) {
|
||||||
case 0: { /* 1u */
|
case 0: { /* 1u */
|
||||||
result = result / 1000;
|
result = result / 1000;
|
||||||
|
|
|
@ -184,9 +184,7 @@ FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*pJob->chkKillFp)(pJob->chkKillParam)) {
|
if ((*pJob->chkKillFp)(pJob->chkKillParam)) {
|
||||||
schUpdateJobStatus(pJob, JOB_TASK_STATUS_DROPPING);
|
|
||||||
schUpdateJobErrCode(pJob, TSDB_CODE_TSC_QUERY_KILLED);
|
schUpdateJobErrCode(pJob, TSDB_CODE_TSC_QUERY_KILLED);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,6 +667,11 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SCH_IS_DATA_SRC_QRY_TASK(pTask)) {
|
||||||
|
SCH_TASK_ELOG("no execNode specifed for data src task, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps);
|
||||||
|
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
SCH_ERR_RET(schSetAddrsFromNodeList(pJob, pTask));
|
SCH_ERR_RET(schSetAddrsFromNodeList(pJob, pTask));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -811,14 +814,6 @@ int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) {
|
int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) {
|
||||||
int8_t status = 0;
|
|
||||||
|
|
||||||
if (schJobNeedToStop(pJob, &status)) {
|
|
||||||
*needRetry = false;
|
|
||||||
SCH_TASK_DLOG("task no more retry cause of job status, job status:%s", jobTaskStatusStr(status));
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TSDB_CODE_SCH_TIMEOUT_ERROR == errCode) {
|
if (TSDB_CODE_SCH_TIMEOUT_ERROR == errCode) {
|
||||||
pTask->maxExecTimes++;
|
pTask->maxExecTimes++;
|
||||||
if (pTask->timeoutUsec < SCH_MAX_TASK_TIMEOUT_USEC) {
|
if (pTask->timeoutUsec < SCH_MAX_TASK_TIMEOUT_USEC) {
|
||||||
|
@ -1277,7 +1272,7 @@ int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList) {
|
||||||
for (int32_t i = 0; i < taskNum; ++i) {
|
for (int32_t i = 0; i < taskNum; ++i) {
|
||||||
STaskStatus *taskStatus = taosArrayGet(pStatusList, i);
|
STaskStatus *taskStatus = taosArrayGet(pStatusList, i);
|
||||||
|
|
||||||
qDebug("QID:%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s",
|
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s",
|
||||||
taskStatus->queryId, taskStatus->taskId, taskStatus->execId, jobTaskStatusStr(taskStatus->status));
|
taskStatus->queryId, taskStatus->taskId, taskStatus->execId, jobTaskStatusStr(taskStatus->status));
|
||||||
|
|
||||||
SSchJob *pJob = schAcquireJob(taskStatus->refId);
|
SSchJob *pJob = schAcquireJob(taskStatus->refId);
|
||||||
|
@ -1495,6 +1490,8 @@ void schFreeJobImpl(void *job) {
|
||||||
uint64_t queryId = pJob->queryId;
|
uint64_t queryId = pJob->queryId;
|
||||||
int64_t refId = pJob->refId;
|
int64_t refId = pJob->refId;
|
||||||
|
|
||||||
|
qDebug("QID:0x%" PRIx64 " begin to free sch job, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob);
|
||||||
|
|
||||||
if (pJob->status == JOB_TASK_STATUS_EXECUTING) {
|
if (pJob->status == JOB_TASK_STATUS_EXECUTING) {
|
||||||
schCancelJob(pJob);
|
schCancelJob(pJob);
|
||||||
}
|
}
|
||||||
|
@ -1535,12 +1532,12 @@ void schFreeJobImpl(void *job) {
|
||||||
taosMemoryFreeClear(pJob->resData);
|
taosMemoryFreeClear(pJob->resData);
|
||||||
taosMemoryFree(pJob);
|
taosMemoryFree(pJob);
|
||||||
|
|
||||||
qDebug("QID:0x%" PRIx64 " sch job freed, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob);
|
|
||||||
|
|
||||||
int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1);
|
int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1);
|
||||||
if (jobNum == 0) {
|
if (jobNum == 0) {
|
||||||
schCloseJobRef();
|
schCloseJobRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug("QID:0x%" PRIx64 " sch job freed, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t schLaunchStaticExplainJob(SSchedulerReq *pReq, SSchJob *pJob, bool sync) {
|
int32_t schLaunchStaticExplainJob(SSchedulerReq *pReq, SSchJob *pJob, bool sync) {
|
||||||
|
@ -1687,11 +1684,6 @@ _return:
|
||||||
|
|
||||||
int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) {
|
int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int8_t status = 0;
|
|
||||||
if (schJobNeedToStop(pJob, &status)) {
|
|
||||||
SCH_TASK_ELOG("redirect will no continue cause of job status %s", jobTaskStatusStr(status));
|
|
||||||
SCH_RET(atomic_load_32(&pJob->errCode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((pTask->execId + 1) >= pTask->maxExecTimes) {
|
if ((pTask->execId + 1) >= pTask->maxExecTimes) {
|
||||||
SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId);
|
SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId);
|
||||||
|
|
|
@ -402,12 +402,16 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) {
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode);
|
schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode);
|
||||||
pMsg->pData = NULL;
|
pMsg->pData = NULL;
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
if (pTask) {
|
if (pTask) {
|
||||||
|
if (code) {
|
||||||
|
schProcessOnTaskFailure(pJob, pTask, code);
|
||||||
|
}
|
||||||
|
|
||||||
SCH_UNLOCK_TASK(pTask);
|
SCH_UNLOCK_TASK(pTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,26 +225,33 @@ void schedulerStopQueryHb(void *pTrans) {
|
||||||
schCleanClusterHb(pTrans);
|
schCleanClusterHb(pTrans);
|
||||||
}
|
}
|
||||||
|
|
||||||
void schedulerFreeJob(int64_t job, int32_t errCode) {
|
void schedulerFreeJob(int64_t* job, int32_t errCode) {
|
||||||
SSchJob *pJob = schAcquireJob(job);
|
if (0 == *job) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSchJob *pJob = schAcquireJob(*job);
|
||||||
if (NULL == pJob) {
|
if (NULL == pJob) {
|
||||||
qError("acquire job from jobRef list failed, may be dropped, jobId:0x%" PRIx64, job);
|
qError("acquire sch job failed, may be dropped, jobId:0x%" PRIx64, *job);
|
||||||
|
*job = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = schProcessOnJobDropped(pJob, errCode);
|
int32_t code = schProcessOnJobDropped(pJob, errCode);
|
||||||
if (TSDB_CODE_SCH_JOB_IS_DROPPING == code) {
|
if (TSDB_CODE_SCH_JOB_IS_DROPPING == code) {
|
||||||
SCH_JOB_DLOG("sch job is already dropping, refId:0x%" PRIx64, job);
|
SCH_JOB_DLOG("sch job is already dropping, refId:0x%" PRIx64, *job);
|
||||||
|
*job = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_JOB_DLOG("start to remove job from jobRef list, refId:0x%" PRIx64, job);
|
SCH_JOB_DLOG("start to remove job from jobRef list, refId:0x%" PRIx64, *job);
|
||||||
|
|
||||||
if (taosRemoveRef(schMgmt.jobRef, job)) {
|
if (taosRemoveRef(schMgmt.jobRef, *job)) {
|
||||||
SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, job);
|
SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, *job);
|
||||||
}
|
}
|
||||||
|
|
||||||
schReleaseJob(job);
|
schReleaseJob(*job);
|
||||||
|
*job = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void schedulerDestroy(void) {
|
void schedulerDestroy(void) {
|
||||||
|
|
|
@ -457,7 +457,7 @@ void schtFreeQueryJob(int32_t freeThread) {
|
||||||
int64_t job = queryJobRefId;
|
int64_t job = queryJobRefId;
|
||||||
|
|
||||||
if (job && atomic_val_compare_exchange_64(&queryJobRefId, job, 0)) {
|
if (job && atomic_val_compare_exchange_64(&queryJobRefId, job, 0)) {
|
||||||
schedulerFreeJob(job, 0);
|
schedulerFreeJob(&job, 0);
|
||||||
if (freeThread) {
|
if (freeThread) {
|
||||||
if (++freeNum % schtTestPrintNum == 0) {
|
if (++freeNum % schtTestPrintNum == 0) {
|
||||||
printf("FreeNum:%d\n", freeNum);
|
printf("FreeNum:%d\n", freeNum);
|
||||||
|
@ -724,7 +724,7 @@ TEST(queryTest, normalCase) {
|
||||||
|
|
||||||
schReleaseJob(job);
|
schReleaseJob(job);
|
||||||
|
|
||||||
schedulerFreeJob(job, 0);
|
schedulerFreeJob(&job, 0);
|
||||||
|
|
||||||
schtFreeQueryDag(&dag);
|
schtFreeQueryDag(&dag);
|
||||||
|
|
||||||
|
@ -828,7 +828,7 @@ TEST(queryTest, readyFirstCase) {
|
||||||
|
|
||||||
schReleaseJob(job);
|
schReleaseJob(job);
|
||||||
|
|
||||||
schedulerFreeJob(job, 0);
|
schedulerFreeJob(&job, 0);
|
||||||
|
|
||||||
schtFreeQueryDag(&dag);
|
schtFreeQueryDag(&dag);
|
||||||
|
|
||||||
|
@ -940,7 +940,7 @@ TEST(queryTest, flowCtrlCase) {
|
||||||
|
|
||||||
schReleaseJob(job);
|
schReleaseJob(job);
|
||||||
|
|
||||||
schedulerFreeJob(job, 0);
|
schedulerFreeJob(&job, 0);
|
||||||
|
|
||||||
schtFreeQueryDag(&dag);
|
schtFreeQueryDag(&dag);
|
||||||
|
|
||||||
|
@ -994,7 +994,7 @@ TEST(insertTest, normalCase) {
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
ASSERT_EQ(res.numOfRows, 20);
|
ASSERT_EQ(res.numOfRows, 20);
|
||||||
|
|
||||||
schedulerFreeJob(insertJobRefId, 0);
|
schedulerFreeJob(&insertJobRefId, 0);
|
||||||
|
|
||||||
schedulerDestroy();
|
schedulerDestroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ int32_t syncInit() {
|
||||||
syncCleanUp();
|
syncCleanUp();
|
||||||
ret = -1;
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
|
sDebug("sync rsetId:%" PRId64 " is open", tsNodeRefId);
|
||||||
ret = syncEnvStart();
|
ret = syncEnvStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +78,7 @@ void syncCleanUp() {
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
if (tsNodeRefId != -1) {
|
if (tsNodeRefId != -1) {
|
||||||
|
sDebug("sync rsetId:%" PRId64 " is closed", tsNodeRefId);
|
||||||
taosCloseRef(tsNodeRefId);
|
taosCloseRef(tsNodeRefId);
|
||||||
tsNodeRefId = -1;
|
tsNodeRefId = -1;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +98,7 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sDebug("vgId:%d, rid:%" PRId64 " is added to rsetId:%" PRId64, pSyncInfo->vgId, pSyncNode->rid, tsNodeRefId);
|
||||||
return pSyncNode->rid;
|
return pSyncNode->rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,12 +139,14 @@ void syncStartStandBy(int64_t rid) {
|
||||||
|
|
||||||
void syncStop(int64_t rid) {
|
void syncStop(int64_t rid) {
|
||||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||||
if (pSyncNode != NULL) {
|
if (pSyncNode == NULL) return;
|
||||||
syncNodeClose(pSyncNode);
|
|
||||||
}
|
int32_t vgId = pSyncNode->vgId;
|
||||||
|
syncNodeClose(pSyncNode);
|
||||||
|
|
||||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||||
taosRemoveRef(tsNodeRefId, rid);
|
taosRemoveRef(tsNodeRefId, rid);
|
||||||
|
sDebug("vgId:%d, rid:%" PRId64 " is removed from rsetId:%" PRId64, vgId, rid, tsNodeRefId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncSetStandby(int64_t rid) {
|
int32_t syncSetStandby(int64_t rid) {
|
||||||
|
|
|
@ -40,8 +40,8 @@ struct SBTree {
|
||||||
#define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT)
|
#define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT)
|
||||||
#define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF)
|
#define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF)
|
||||||
#define TDB_BTREE_PAGE_IS_OVFL(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_OVFL)
|
#define TDB_BTREE_PAGE_IS_OVFL(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_OVFL)
|
||||||
#define TDB_BTREE_ASSERT_FLAG(flags) \
|
#define TDB_BTREE_ASSERT_FLAG(flags) \
|
||||||
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
|
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
|
||||||
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0) || \
|
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0) || \
|
||||||
TDB_FLAG_IS(flags, TDB_BTREE_OVFL))
|
TDB_FLAG_IS(flags, TDB_BTREE_OVFL))
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ typedef struct {
|
||||||
|
|
||||||
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
|
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
|
||||||
static int tdbBtreeOpenImpl(SBTree *pBt);
|
static int tdbBtreeOpenImpl(SBTree *pBt);
|
||||||
//static int tdbBtreeInitPage(SPage *pPage, void *arg, int init);
|
// static int tdbBtreeInitPage(SPage *pPage, void *arg, int init);
|
||||||
static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell,
|
static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell,
|
||||||
int *szCell, TXN *pTxn, SBTree *pBt);
|
int *szCell, TXN *pTxn, SBTree *pBt);
|
||||||
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt);
|
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt);
|
||||||
|
@ -321,7 +321,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// 1. TODO: Search the main DB to check if the DB exists
|
// 1. TODO: Search the main DB to check if the DB exists
|
||||||
ret = tdbPagerOpenDB(pBt->pPager, &pgno, true);
|
ret = tdbPagerOpenDB(pBt->pPager, &pgno, true, pBt);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +721,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
int szNewCell;
|
int szNewCell;
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
||||||
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn, pBt);
|
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn,
|
||||||
|
pBt);
|
||||||
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
||||||
tdbOsFree(pNewCell);
|
tdbOsFree(pNewCell);
|
||||||
}
|
}
|
||||||
|
@ -916,10 +917,10 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
||||||
int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno));
|
int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno));
|
||||||
int nLocal = surplus <= maxLocal ? surplus : minLocal;
|
int nLocal = surplus <= maxLocal ? surplus : minLocal;
|
||||||
|
|
||||||
//int ofpCap = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr));
|
// int ofpCap = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr));
|
||||||
|
|
||||||
// fetch a new ofp and make it dirty
|
// fetch a new ofp and make it dirty
|
||||||
SPgno pgno = 0;
|
SPgno pgno = 0;
|
||||||
SPage *ofp, *nextOfp;
|
SPage *ofp, *nextOfp;
|
||||||
|
|
||||||
ret = tdbFetchOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbFetchOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
|
@ -942,8 +943,8 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
||||||
nLeft -= kLen;
|
nLeft -= kLen;
|
||||||
// pack partial val to local if any space left
|
// pack partial val to local if any space left
|
||||||
if (nLocal > kLen + 4) {
|
if (nLocal > kLen + 4) {
|
||||||
memcpy(pCell + nHeader + kLen, pVal, nLocal - kLen - sizeof(SPgno));
|
memcpy(pCell + nHeader + kLen, pVal, nLocal - kLen - sizeof(SPgno));
|
||||||
nLeft -= nLocal - kLen - sizeof(SPgno);
|
nLeft -= nLocal - kLen - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pack nextPgno
|
// pack nextPgno
|
||||||
|
@ -951,132 +952,132 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
||||||
|
|
||||||
// pack left val data to ovpages
|
// pack left val data to ovpages
|
||||||
do {
|
do {
|
||||||
lastPage = 0;
|
lastPage = 0;
|
||||||
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeft;
|
bytes = nLeft;
|
||||||
lastPage = 1;
|
lastPage = 1;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch next ofp if not last page
|
// fetch next ofp if not last page
|
||||||
if (!lastPage) {
|
if (!lastPage) {
|
||||||
// fetch a new ofp and make it dirty
|
// fetch a new ofp and make it dirty
|
||||||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbFree(pBuf);
|
tdbFree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pgno = 0;
|
pgno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes);
|
memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes);
|
||||||
memcpy(pBuf + bytes, &pgno, sizeof(pgno));
|
memcpy(pBuf + bytes, &pgno, sizeof(pgno));
|
||||||
|
|
||||||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbFree(pBuf);
|
tdbFree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofp = nextOfp;
|
ofp = nextOfp;
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
} while (nLeft > 0);
|
} while (nLeft > 0);
|
||||||
} else {
|
} else {
|
||||||
int nLeftKey = kLen;
|
int nLeftKey = kLen;
|
||||||
// pack partial key and nextPgno
|
// pack partial key and nextPgno
|
||||||
memcpy(pCell + nHeader, pKey, nLocal - 4);
|
memcpy(pCell + nHeader, pKey, nLocal - 4);
|
||||||
nLeft -= nLocal - 4;
|
nLeft -= nLocal - 4;
|
||||||
nLeftKey -= nLocal -4;
|
nLeftKey -= nLocal - 4;
|
||||||
|
|
||||||
memcpy(pCell + nHeader + nLocal - 4, &pgno, sizeof(pgno));
|
memcpy(pCell + nHeader + nLocal - 4, &pgno, sizeof(pgno));
|
||||||
|
|
||||||
int lastKeyPageSpace = 0;
|
int lastKeyPageSpace = 0;
|
||||||
// pack left key & val to ovpages
|
// pack left key & val to ovpages
|
||||||
do {
|
do {
|
||||||
// cal key to cpy
|
// cal key to cpy
|
||||||
int lastKeyPage = 0;
|
int lastKeyPage = 0;
|
||||||
if (nLeftKey <= ofp->maxLocal - sizeof(SPgno)) {
|
if (nLeftKey <= ofp->maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeftKey;
|
bytes = nLeftKey;
|
||||||
lastKeyPage = 1;
|
lastKeyPage = 1;
|
||||||
lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey;
|
lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cpy key
|
// cpy key
|
||||||
memcpy(pBuf, ((SCell *)pKey) + kLen - nLeftKey, bytes);
|
memcpy(pBuf, ((SCell *)pKey) + kLen - nLeftKey, bytes);
|
||||||
|
|
||||||
if (lastKeyPage) {
|
if (lastKeyPage) {
|
||||||
if (lastKeyPageSpace >= vLen) {
|
if (lastKeyPageSpace >= vLen) {
|
||||||
memcpy(pBuf + kLen -nLeftKey, pVal, vLen);
|
memcpy(pBuf + kLen - nLeftKey, pVal, vLen);
|
||||||
|
|
||||||
nLeft -= vLen;
|
nLeft -= vLen;
|
||||||
pgno = 0;
|
pgno = 0;
|
||||||
} else {
|
} else {
|
||||||
memcpy(pBuf + kLen -nLeftKey, pVal, lastKeyPageSpace);
|
memcpy(pBuf + kLen - nLeftKey, pVal, lastKeyPageSpace);
|
||||||
nLeft -= lastKeyPageSpace;
|
nLeft -= lastKeyPageSpace;
|
||||||
|
|
||||||
// fetch next ofp, a new ofp and make it dirty
|
// fetch next ofp, a new ofp and make it dirty
|
||||||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// fetch next ofp, a new ofp and make it dirty
|
// fetch next ofp, a new ofp and make it dirty
|
||||||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pBuf + kLen - nLeft, &pgno, sizeof(pgno));
|
memcpy(pBuf + kLen - nLeft, &pgno, sizeof(pgno));
|
||||||
|
|
||||||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofp = nextOfp;
|
ofp = nextOfp;
|
||||||
nLeftKey -= bytes;
|
nLeftKey -= bytes;
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
} while (nLeftKey > 0);
|
} while (nLeftKey > 0);
|
||||||
|
|
||||||
while (nLeft > 0) {
|
while (nLeft > 0) {
|
||||||
// pack left val data to ovpages
|
// pack left val data to ovpages
|
||||||
lastPage = 0;
|
lastPage = 0;
|
||||||
if (nLeft <= maxLocal - sizeof(SPgno)) {
|
if (nLeft <= maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeft;
|
bytes = nLeft;
|
||||||
lastPage = 1;
|
lastPage = 1;
|
||||||
} else {
|
} else {
|
||||||
bytes = maxLocal - sizeof(SPgno);
|
bytes = maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch next ofp if not last page
|
// fetch next ofp if not last page
|
||||||
if (!lastPage) {
|
if (!lastPage) {
|
||||||
// fetch a new ofp and make it dirty
|
// fetch a new ofp and make it dirty
|
||||||
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbFree(pBuf);
|
tdbFree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pgno = 0;
|
pgno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes);
|
memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes);
|
||||||
memcpy(pBuf + bytes, &pgno, sizeof(pgno));
|
memcpy(pBuf + bytes, &pgno, sizeof(pgno));
|
||||||
|
|
||||||
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbFree(pBuf);
|
tdbFree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofp = nextOfp;
|
ofp = nextOfp;
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1142,7 +1143,8 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt) {
|
static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder, TXN *pTxn,
|
||||||
|
SBTree *pBt) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nPayload;
|
int nPayload;
|
||||||
int maxLocal = pPage->maxLocal;
|
int maxLocal = pPage->maxLocal;
|
||||||
|
@ -1171,149 +1173,149 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
||||||
int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno));
|
int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno));
|
||||||
int nLocal = surplus <= maxLocal ? surplus : minLocal;
|
int nLocal = surplus <= maxLocal ? surplus : minLocal;
|
||||||
|
|
||||||
int nLeft = nPayload;
|
int nLeft = nPayload;
|
||||||
SPgno pgno = 0;
|
SPgno pgno = 0;
|
||||||
SPage *ofp;
|
SPage *ofp;
|
||||||
SCell *ofpCell;
|
SCell *ofpCell;
|
||||||
int bytes;
|
int bytes;
|
||||||
int lastPage = 0;
|
int lastPage = 0;
|
||||||
|
|
||||||
if (nLocal >= pDecoder->kLen + 4) {
|
if (nLocal >= pDecoder->kLen + 4) {
|
||||||
pDecoder->pKey = (SCell *)pCell + nHeader;
|
pDecoder->pKey = (SCell *)pCell + nHeader;
|
||||||
nLeft -= kLen;
|
nLeft -= kLen;
|
||||||
if (nLocal > kLen + 4) {
|
if (nLocal > kLen + 4) {
|
||||||
// read partial val to local
|
// read partial val to local
|
||||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||||
if (pDecoder->pVal == NULL) {
|
if (pDecoder->pVal == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||||
|
|
||||||
memcpy(pDecoder->pVal, pCell + nHeader + kLen, nLocal - kLen - sizeof(SPgno));
|
memcpy(pDecoder->pVal, pCell + nHeader + kLen, nLocal - kLen - sizeof(SPgno));
|
||||||
|
|
||||||
nLeft -= nLocal - kLen - sizeof(SPgno);
|
nLeft -= nLocal - kLen - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&pgno, pCell + nHeader + nPayload - nLeft, sizeof(pgno));
|
memcpy(&pgno, pCell + nHeader + nPayload - nLeft, sizeof(pgno));
|
||||||
|
|
||||||
// unpack left val data from ovpages
|
// unpack left val data from ovpages
|
||||||
while (pgno != 0) {
|
while (pgno != 0) {
|
||||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofpCell = tdbPageGetCell(ofp, 0);
|
ofpCell = tdbPageGetCell(ofp, 0);
|
||||||
|
|
||||||
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeft;
|
bytes = nLeft;
|
||||||
lastPage = 1;
|
lastPage = 1;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pDecoder->pVal + vLen - nLeft, ofpCell, bytes);
|
memcpy(pDecoder->pVal + vLen - nLeft, ofpCell, bytes);
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
|
|
||||||
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int nLeftKey = kLen;
|
int nLeftKey = kLen;
|
||||||
// load partial key and nextPgno
|
// load partial key and nextPgno
|
||||||
pDecoder->pKey = tdbRealloc(pDecoder->pKey, kLen);
|
pDecoder->pKey = tdbRealloc(pDecoder->pKey, kLen);
|
||||||
if (pDecoder->pKey == NULL) {
|
if (pDecoder->pKey == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TDB_CELLDECODER_SET_FREE_KEY(pDecoder);
|
TDB_CELLDECODER_SET_FREE_KEY(pDecoder);
|
||||||
|
|
||||||
memcpy(pDecoder->pKey, pCell + nHeader, nLocal - 4);
|
memcpy(pDecoder->pKey, pCell + nHeader, nLocal - 4);
|
||||||
nLeft -= nLocal - 4;
|
nLeft -= nLocal - 4;
|
||||||
nLeftKey -= nLocal -4;
|
nLeftKey -= nLocal - 4;
|
||||||
|
|
||||||
memcpy(&pgno, pCell + nHeader + nLocal - 4, sizeof(pgno));
|
memcpy(&pgno, pCell + nHeader + nLocal - 4, sizeof(pgno));
|
||||||
|
|
||||||
int lastKeyPageSpace = 0;
|
int lastKeyPageSpace = 0;
|
||||||
// load left key & val to ovpages
|
// load left key & val to ovpages
|
||||||
while (pgno != 0) {
|
while (pgno != 0) {
|
||||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofpCell = tdbPageGetCell(ofp, 0);
|
ofpCell = tdbPageGetCell(ofp, 0);
|
||||||
|
|
||||||
int lastKeyPage = 0;
|
int lastKeyPage = 0;
|
||||||
if (nLeftKey <= maxLocal - sizeof(SPgno)) {
|
if (nLeftKey <= maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeftKey;
|
bytes = nLeftKey;
|
||||||
lastKeyPage = 1;
|
lastKeyPage = 1;
|
||||||
lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey;
|
lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cpy key
|
// cpy key
|
||||||
memcpy(pDecoder->pKey + kLen - nLeftKey, ofpCell, bytes);
|
memcpy(pDecoder->pKey + kLen - nLeftKey, ofpCell, bytes);
|
||||||
|
|
||||||
if (lastKeyPage) {
|
if (lastKeyPage) {
|
||||||
if (lastKeyPageSpace >= vLen) {
|
if (lastKeyPageSpace >= vLen) {
|
||||||
pDecoder->pVal = ofpCell + kLen -nLeftKey;
|
pDecoder->pVal = ofpCell + kLen - nLeftKey;
|
||||||
|
|
||||||
nLeft -= vLen;
|
nLeft -= vLen;
|
||||||
pgno = 0;
|
pgno = 0;
|
||||||
} else {
|
} else {
|
||||||
// read partial val to local
|
// read partial val to local
|
||||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||||
if (pDecoder->pVal == NULL) {
|
if (pDecoder->pVal == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||||
|
|
||||||
memcpy(pDecoder->pVal, ofpCell + kLen -nLeftKey, lastKeyPageSpace);
|
memcpy(pDecoder->pVal, ofpCell + kLen - nLeftKey, lastKeyPageSpace);
|
||||||
nLeft -= lastKeyPageSpace;
|
nLeft -= lastKeyPageSpace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
||||||
|
|
||||||
nLeftKey -= bytes;
|
nLeftKey -= bytes;
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nLeft > 0) {
|
while (nLeft > 0) {
|
||||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofpCell = tdbPageGetCell(ofp, 0);
|
ofpCell = tdbPageGetCell(ofp, 0);
|
||||||
|
|
||||||
// load left val data to ovpages
|
// load left val data to ovpages
|
||||||
lastPage = 0;
|
lastPage = 0;
|
||||||
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeft;
|
bytes = nLeft;
|
||||||
lastPage = 1;
|
lastPage = 1;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastPage) {
|
if (lastPage) {
|
||||||
pgno = 0;
|
pgno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pDecoder->pVal) {
|
if (!pDecoder->pVal) {
|
||||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||||
if (pDecoder->pVal == NULL) {
|
if (pDecoder->pVal == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
TDB_CELLDECODER_SET_FREE_VAL(pDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pDecoder->pVal, ofpCell + vLen - nLeft, bytes);
|
memcpy(pDecoder->pVal, ofpCell + vLen - nLeft, bytes);
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
|
|
||||||
memcpy(&pgno, ofpCell + vLen - nLeft + bytes, sizeof(pgno));
|
memcpy(&pgno, ofpCell + vLen - nLeft + bytes, sizeof(pgno));
|
||||||
|
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1404,31 +1406,31 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
||||||
|
|
||||||
// free ofp pages' cells
|
// free ofp pages' cells
|
||||||
if (dropOfp) {
|
if (dropOfp) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
SPgno pgno = *(SPgno *) (pCell + nHeader + nLocal - sizeof(SPgno));
|
SPgno pgno = *(SPgno *)(pCell + nHeader + nLocal - sizeof(SPgno));
|
||||||
int nLeft = nPayload - nLocal + sizeof(SPgno);
|
int nLeft = nPayload - nLocal + sizeof(SPgno);
|
||||||
SPage *ofp;
|
SPage *ofp;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
||||||
while (pgno != 0) {
|
while (pgno != 0) {
|
||||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCell *ofpCell = tdbPageGetCell(ofp, 0);
|
SCell *ofpCell = tdbPageGetCell(ofp, 0);
|
||||||
|
|
||||||
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
||||||
bytes = nLeft;
|
bytes = nLeft;
|
||||||
} else {
|
} else {
|
||||||
bytes = ofp->maxLocal - sizeof(SPgno);
|
bytes = ofp->maxLocal - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
||||||
|
|
||||||
tdbPagerReturnPage(pPage->pPager, ofp, pTxn);
|
tdbPagerReturnPage(pPage->pPager, ofp, pTxn);
|
||||||
|
|
||||||
nLeft -= bytes;
|
nLeft -= bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1932,7 +1934,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
|
|
||||||
// alloc space
|
// alloc space
|
||||||
szBuf = kLen + nData + 14;
|
szBuf = kLen + nData + 14;
|
||||||
pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize);
|
pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize);
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -98,7 +98,7 @@ int tdbPagerClose(SPager *pPager) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
|
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt) {
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
SPage *pPage;
|
SPage *pPage;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -110,25 +110,41 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// TODO: try to search the main DB to get the page number
|
// TODO: try to search the main DB to get the page number
|
||||||
// pgno = 0;
|
// pgno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (pgno == 0 && toCreate) {
|
if (pgno == 0 && toCreate) {
|
||||||
// ret = tdbPagerAllocPage(pPager, &pPage, &pgno);
|
// allocate a new child page
|
||||||
// if (ret < 0) {
|
TXN txn;
|
||||||
// return -1;
|
tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, 0);
|
||||||
// }
|
|
||||||
|
|
||||||
// // TODO: Need to zero the page
|
pPager->inTran = 1;
|
||||||
|
|
||||||
// ret = tdbPagerWrite(pPager, pPage);
|
SBtreeInitPageArg zArg;
|
||||||
// if (ret < 0) {
|
zArg.flags = 0x1 | 0x2; // root leaf node;
|
||||||
// return -1;
|
zArg.pBt = pBt;
|
||||||
// }
|
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, &txn);
|
||||||
// }
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*ppgno = pgno;
|
// ret = tdbPagerAllocPage(pPager, &pPage, &pgno);
|
||||||
|
// if (ret < 0) {
|
||||||
|
// return -1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// TODO: Need to zero the page
|
||||||
|
|
||||||
|
ret = tdbPagerWrite(pPager, pPage);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdbTxnClose(&txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppgno = pgno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,9 +443,9 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
SPgno journalSize = 0;
|
SPgno journalSize = 0;
|
||||||
u8 *pageBuf = NULL;
|
u8 *pageBuf = NULL;
|
||||||
|
|
||||||
tdb_fd_t jfd = tdbOsOpen(pPager->jFileName, TDB_O_RDWR, 0755);
|
tdb_fd_t jfd = tdbOsOpen(pPager->jFileName, TDB_O_RDWR, 0755);
|
||||||
if (jfd == NULL) {
|
if (jfd == NULL) {
|
||||||
|
@ -454,7 +470,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
|
||||||
|
|
||||||
for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
|
for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
|
||||||
// read pgno & the page from journal
|
// read pgno & the page from journal
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
SPage *pPage;
|
SPage *pPage;
|
||||||
|
|
||||||
int ret = tdbOsRead(jfd, &pgno, sizeof(pgno));
|
int ret = tdbOsRead(jfd, &pgno, sizeof(pgno));
|
||||||
|
|
|
@ -128,13 +128,13 @@ typedef struct SBtInfo {
|
||||||
#define TDB_CELLDECODER_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV & TDB_CELLD_F_VAL)
|
#define TDB_CELLDECODER_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV & TDB_CELLD_F_VAL)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int kLen;
|
int kLen;
|
||||||
u8 *pKey;
|
u8 *pKey;
|
||||||
int vLen;
|
int vLen;
|
||||||
u8 *pVal;
|
u8 *pVal;
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
u8 *pBuf;
|
u8 *pBuf;
|
||||||
u8 freeKV;
|
u8 freeKV;
|
||||||
} SCellDecoder;
|
} SCellDecoder;
|
||||||
|
|
||||||
struct SBTC {
|
struct SBTC {
|
||||||
|
@ -184,7 +184,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
|
|
||||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
||||||
int tdbPagerClose(SPager *pPager);
|
int tdbPagerClose(SPager *pPager);
|
||||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
|
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt);
|
||||||
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
||||||
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
||||||
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
||||||
|
@ -192,7 +192,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initP
|
||||||
TXN *pTxn);
|
TXN *pTxn);
|
||||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
|
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
|
||||||
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
|
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
|
||||||
int tdbPagerRestore(SPager *pPager, SBTree *pBt);
|
int tdbPagerRestore(SPager *pPager, SBTree *pBt);
|
||||||
|
|
||||||
// tdbPCache.c ====================================
|
// tdbPCache.c ====================================
|
||||||
#define TDB_PCACHE_PAGE \
|
#define TDB_PCACHE_PAGE \
|
||||||
|
@ -314,19 +314,18 @@ static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
|
||||||
#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
|
#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
||||||
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
||||||
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||||
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
||||||
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell, 0, NULL, NULL) + (pPage)->pPageMethods->szOffset)
|
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) \
|
||||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
((*(pPage)->xCellSize)(pPage, pCell, 0, NULL, NULL) + (pPage)->pPageMethods->szOffset)
|
||||||
|
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
||||||
|
|
||||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
||||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
||||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int,
|
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt));
|
||||||
TXN *, SBTree *pBt));
|
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt));
|
||||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int,
|
|
||||||
TXN *, SBTree *pBt));
|
|
||||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||||
int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt);
|
int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt);
|
||||||
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt);
|
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt);
|
||||||
|
|
|
@ -291,7 +291,7 @@ int32_t tfsRmdir(STfs *pTfs, const char *rname) {
|
||||||
for (int32_t id = 0; id < pTier->ndisk; id++) {
|
for (int32_t id = 0; id < pTier->ndisk; id++) {
|
||||||
STfsDisk *pDisk = pTier->disks[id];
|
STfsDisk *pDisk = pTier->disks[id];
|
||||||
snprintf(aname, TMPNAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname);
|
snprintf(aname, TMPNAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname);
|
||||||
uInfo("====> tfs remove dir : path:%s aname:%s rname:[%s]", pDisk->path, aname, rname);
|
uInfo("tfs remove dir : path:%s aname:%s rname:[%s]", pDisk->path, aname, rname);
|
||||||
taosRemoveDir(aname);
|
taosRemoveDir(aname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ int transAsyncSend(SAsyncPool* pool, queue* mq);
|
||||||
do { \
|
do { \
|
||||||
if (id > 0) { \
|
if (id > 0) { \
|
||||||
tTrace("handle step1"); \
|
tTrace("handle step1"); \
|
||||||
SExHandle* exh2 = transAcquireExHandle(id); \
|
SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \
|
||||||
if (exh2 == NULL || id != exh2->refId) { \
|
if (exh2 == NULL || id != exh2->refId) { \
|
||||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \
|
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \
|
||||||
exh2 ? exh2->refId : 0, id); \
|
exh2 ? exh2->refId : 0, id); \
|
||||||
|
@ -261,7 +261,7 @@ int transAsyncSend(SAsyncPool* pool, queue* mq);
|
||||||
} \
|
} \
|
||||||
} else if (id == 0) { \
|
} else if (id == 0) { \
|
||||||
tTrace("handle step2"); \
|
tTrace("handle step2"); \
|
||||||
SExHandle* exh2 = transAcquireExHandle(id); \
|
SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \
|
||||||
if (exh2 == NULL || id == exh2->refId) { \
|
if (exh2 == NULL || id == exh2->refId) { \
|
||||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, id, \
|
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, id, \
|
||||||
exh2 ? exh2->refId : 0); \
|
exh2 ? exh2->refId : 0); \
|
||||||
|
@ -391,13 +391,16 @@ void transThreadOnce();
|
||||||
void transInit();
|
void transInit();
|
||||||
void transCleanup();
|
void transCleanup();
|
||||||
|
|
||||||
int32_t transOpenExHandleMgt(int size);
|
int32_t transOpenRefMgt(int size, void (*func)(void*));
|
||||||
void transCloseExHandleMgt();
|
void transCloseRefMgt(int32_t refMgt);
|
||||||
int64_t transAddExHandle(void* p);
|
int64_t transAddExHandle(int32_t refMgt, void* p);
|
||||||
int32_t transRemoveExHandle(int64_t refId);
|
int32_t transRemoveExHandle(int32_t refMgt, int64_t refId);
|
||||||
SExHandle* transAcquireExHandle(int64_t refId);
|
void* transAcquireExHandle(int32_t refMgt, int64_t refId);
|
||||||
int32_t transReleaseExHandle(int64_t refId);
|
int32_t transReleaseExHandle(int32_t refMgt, int64_t refId);
|
||||||
void transDestoryExHandle(void* handle);
|
void transDestoryExHandle(void* handle);
|
||||||
|
|
||||||
|
int32_t transGetRefMgt();
|
||||||
|
int32_t transGetInstMgt();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ typedef struct {
|
||||||
|
|
||||||
void* parent;
|
void* parent;
|
||||||
void* tcphandle; // returned handle from TCP initialization
|
void* tcphandle; // returned handle from TCP initialization
|
||||||
int32_t refMgt;
|
int64_t refId;
|
||||||
TdThreadMutex mutex;
|
TdThreadMutex mutex;
|
||||||
} SRpcInfo;
|
} SRpcInfo;
|
||||||
|
|
||||||
|
|
|
@ -76,16 +76,23 @@ void* rpcOpen(const SRpcInit* pInit) {
|
||||||
if (pInit->user) {
|
if (pInit->user) {
|
||||||
memcpy(pRpc->user, pInit->user, strlen(pInit->user));
|
memcpy(pRpc->user, pInit->user, strlen(pInit->user));
|
||||||
}
|
}
|
||||||
return pRpc;
|
|
||||||
|
int64_t refId = transAddExHandle(transGetInstMgt(), pRpc);
|
||||||
|
transAcquireExHandle(transGetInstMgt(), refId);
|
||||||
|
pRpc->refId = refId;
|
||||||
|
return (void*)refId;
|
||||||
}
|
}
|
||||||
void rpcClose(void* arg) {
|
void rpcClose(void* arg) {
|
||||||
tInfo("start to close rpc");
|
tInfo("start to close rpc");
|
||||||
|
transRemoveExHandle(transGetInstMgt(), (int64_t)arg);
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)arg);
|
||||||
|
tInfo("finish to close rpc");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void rpcCloseImpl(void* arg) {
|
||||||
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
||||||
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
||||||
taosMemoryFree(pRpc);
|
taosMemoryFree(pRpc);
|
||||||
tInfo("finish to close rpc");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* rpcMallocCont(int32_t contLen) {
|
void* rpcMallocCont(int32_t contLen) {
|
||||||
|
@ -140,11 +147,10 @@ void rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) {
|
||||||
transSendRecv(shandle, pEpSet, pMsg, pRsp);
|
transSendRecv(shandle, pEpSet, pMsg, pRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpcSendResponse(const SRpcMsg* pMsg) { transSendResponse(pMsg); }
|
void rpcSendResponse(const SRpcMsg* pMsg) { transSendResponse(pMsg); }
|
||||||
|
|
||||||
int32_t rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) { return 0; }
|
int32_t rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) { return 0; }
|
||||||
|
|
||||||
|
|
||||||
void rpcRefHandle(void* handle, int8_t type) {
|
void rpcRefHandle(void* handle, int8_t type) {
|
||||||
assert(type == TAOS_CONN_SERVER || type == TAOS_CONN_CLIENT);
|
assert(type == TAOS_CONN_SERVER || type == TAOS_CONN_CLIENT);
|
||||||
(*taosRefHandle[type])(handle);
|
(*taosRefHandle[type])(handle);
|
||||||
|
|
|
@ -47,6 +47,7 @@ typedef struct SCliMsg {
|
||||||
queue q;
|
queue q;
|
||||||
STransMsgType type;
|
STransMsgType type;
|
||||||
|
|
||||||
|
int64_t refId;
|
||||||
uint64_t st;
|
uint64_t st;
|
||||||
int sent; //(0: no send, 1: alread sent)
|
int sent; //(0: no send, 1: alread sent)
|
||||||
} SCliMsg;
|
} SCliMsg;
|
||||||
|
@ -262,13 +263,17 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
||||||
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1)
|
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1)
|
||||||
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
||||||
|
|
||||||
|
#define EPSET_IS_VALID(epSet) ((epSet) != NULL && (epSet)->numOfEps != 0)
|
||||||
#define EPSET_GET_SIZE(epSet) (epSet)->numOfEps
|
#define EPSET_GET_SIZE(epSet) (epSet)->numOfEps
|
||||||
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
#define EPSET_GET_INUSE_IP(epSet) ((epSet)->eps[(epSet)->inUse].fqdn)
|
||||||
#define EPSET_GET_INUSE_PORT(epSet) ((epSet)->eps[(epSet)->inUse].port)
|
#define EPSET_GET_INUSE_PORT(epSet) ((epSet)->eps[(epSet)->inUse].port)
|
||||||
#define EPSET_FORWARD_INUSE(epSet) \
|
#define EPSET_FORWARD_INUSE(epSet) \
|
||||||
do { \
|
do { \
|
||||||
(epSet)->inUse = (++((epSet)->inUse)) % ((epSet)->numOfEps); \
|
if ((epSet)->numOfEps != 0) { \
|
||||||
|
(epSet)->inUse = (++((epSet)->inUse)) % ((epSet)->numOfEps); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define EPSET_DEBUG_STR(epSet, tbuf) \
|
#define EPSET_DEBUG_STR(epSet, tbuf) \
|
||||||
do { \
|
do { \
|
||||||
int len = snprintf(tbuf, sizeof(tbuf), "epset:{"); \
|
int len = snprintf(tbuf, sizeof(tbuf), "epset:{"); \
|
||||||
|
@ -501,18 +506,17 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
||||||
}
|
}
|
||||||
static void allocConnRef(SCliConn* conn, bool update) {
|
static void allocConnRef(SCliConn* conn, bool update) {
|
||||||
if (update) {
|
if (update) {
|
||||||
transRemoveExHandle(conn->refId);
|
transRemoveExHandle(transGetRefMgt(), conn->refId);
|
||||||
conn->refId = -1;
|
conn->refId = -1;
|
||||||
}
|
}
|
||||||
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
||||||
exh->handle = conn;
|
exh->handle = conn;
|
||||||
exh->pThrd = conn->hostThrd;
|
exh->pThrd = conn->hostThrd;
|
||||||
exh->refId = transAddExHandle(exh);
|
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
||||||
conn->refId = exh->refId;
|
conn->refId = exh->refId;
|
||||||
}
|
}
|
||||||
static void addConnToPool(void* pool, SCliConn* conn) {
|
static void addConnToPool(void* pool, SCliConn* conn) {
|
||||||
if (conn->status == ConnInPool) {
|
if (conn->status == ConnInPool) {
|
||||||
// assert(0);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SCliThrd* thrd = conn->hostThrd;
|
SCliThrd* thrd = conn->hostThrd;
|
||||||
|
@ -601,16 +605,14 @@ static void cliDestroyConn(SCliConn* conn, bool clear) {
|
||||||
tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
||||||
QUEUE_REMOVE(&conn->conn);
|
QUEUE_REMOVE(&conn->conn);
|
||||||
QUEUE_INIT(&conn->conn);
|
QUEUE_INIT(&conn->conn);
|
||||||
transRemoveExHandle(conn->refId);
|
transRemoveExHandle(transGetRefMgt(), conn->refId);
|
||||||
conn->refId = -1;
|
conn->refId = -1;
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
if (!uv_is_closing((uv_handle_t*)conn->stream)) {
|
if (!uv_is_closing((uv_handle_t*)conn->stream)) {
|
||||||
|
uv_read_stop(conn->stream);
|
||||||
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
||||||
}
|
}
|
||||||
//} else {
|
|
||||||
// cliDestroy((uv_handle_t*)conn->stream);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void cliDestroy(uv_handle_t* handle) {
|
static void cliDestroy(uv_handle_t* handle) {
|
||||||
|
@ -619,7 +621,7 @@ static void cliDestroy(uv_handle_t* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SCliConn* conn = handle->data;
|
SCliConn* conn = handle->data;
|
||||||
transRemoveExHandle(conn->refId);
|
transRemoveExHandle(transGetRefMgt(), conn->refId);
|
||||||
taosMemoryFree(conn->ip);
|
taosMemoryFree(conn->ip);
|
||||||
conn->stream->data = NULL;
|
conn->stream->data = NULL;
|
||||||
taosMemoryFree(conn->stream);
|
taosMemoryFree(conn->stream);
|
||||||
|
@ -635,7 +637,6 @@ static bool cliHandleNoResp(SCliConn* conn) {
|
||||||
SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0);
|
SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0);
|
||||||
if (REQUEST_NO_RESP(&pMsg->msg)) {
|
if (REQUEST_NO_RESP(&pMsg->msg)) {
|
||||||
transQueuePop(&conn->cliMsgs);
|
transQueuePop(&conn->cliMsgs);
|
||||||
// taosArrayRemove(msgs, 0);
|
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
|
@ -668,7 +669,6 @@ static void cliSendCb(uv_write_t* req, int status) {
|
||||||
void cliSend(SCliConn* pConn) {
|
void cliSend(SCliConn* pConn) {
|
||||||
CONN_HANDLE_BROKEN(pConn);
|
CONN_HANDLE_BROKEN(pConn);
|
||||||
|
|
||||||
// assert(taosArrayGetSize(pConn->cliMsgs) > 0);
|
|
||||||
assert(!transQueueEmpty(&pConn->cliMsgs));
|
assert(!transQueueEmpty(&pConn->cliMsgs));
|
||||||
|
|
||||||
SCliMsg* pCliMsg = NULL;
|
SCliMsg* pCliMsg = NULL;
|
||||||
|
@ -747,7 +747,7 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
}
|
}
|
||||||
static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) {
|
static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||||
SExHandle* exh = transAcquireExHandle(refId);
|
SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId);
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
tDebug("%" PRId64 " already release", refId);
|
tDebug("%" PRId64 " already release", refId);
|
||||||
}
|
}
|
||||||
|
@ -773,14 +773,14 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore) {
|
||||||
SCliConn* conn = NULL;
|
SCliConn* conn = NULL;
|
||||||
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||||
if (refId != 0) {
|
if (refId != 0) {
|
||||||
SExHandle* exh = transAcquireExHandle(refId);
|
SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId);
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
*ignore = true;
|
*ignore = true;
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
conn = exh->handle;
|
conn = exh->handle;
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
}
|
}
|
||||||
return conn;
|
return conn;
|
||||||
};
|
};
|
||||||
|
@ -810,6 +810,11 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
cliMayCvtFqdnToIp(&pCtx->epSet, &pThrd->cvtAddr);
|
cliMayCvtFqdnToIp(&pCtx->epSet, &pThrd->cvtAddr);
|
||||||
|
if (!EPSET_IS_VALID(&pCtx->epSet)) {
|
||||||
|
destroyCmsg(pMsg);
|
||||||
|
tError("invalid epset");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool ignore = false;
|
bool ignore = false;
|
||||||
SCliConn* conn = cliGetConn(pMsg, pThrd, &ignore);
|
SCliConn* conn = cliGetConn(pMsg, pThrd, &ignore);
|
||||||
|
@ -977,6 +982,7 @@ void cliSendQuit(SCliThrd* thrd) {
|
||||||
}
|
}
|
||||||
void cliWalkCb(uv_handle_t* handle, void* arg) {
|
void cliWalkCb(uv_handle_t* handle, void* arg) {
|
||||||
if (!uv_is_closing(handle)) {
|
if (!uv_is_closing(handle)) {
|
||||||
|
uv_read_stop((uv_stream_t*)handle);
|
||||||
uv_close(handle, cliDestroy);
|
uv_close(handle, cliDestroy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1066,7 +1072,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
pMsg->sent = 0;
|
pMsg->sent = 0;
|
||||||
pCtx->retryCnt += 1;
|
pCtx->retryCnt += 1;
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK) {
|
||||||
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, EPSET_GET_SIZE(&pCtx->epSet) * 3);
|
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, EPSET_GET_SIZE(&pCtx->epSet) * 3);
|
||||||
if (pCtx->retryCnt < pCtx->retryLimit) {
|
if (pCtx->retryCnt < pCtx->retryLimit) {
|
||||||
transUnrefCliHandle(pConn);
|
transUnrefCliHandle(pConn);
|
||||||
|
@ -1077,12 +1083,14 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
} else {
|
} else {
|
||||||
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, TRANS_RETRY_COUNT_LIMIT);
|
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, TRANS_RETRY_COUNT_LIMIT);
|
||||||
if (pCtx->retryCnt < pCtx->retryLimit) {
|
if (pCtx->retryCnt < pCtx->retryLimit) {
|
||||||
addConnToPool(pThrd->pool, pConn);
|
|
||||||
if (pResp->contLen == 0) {
|
if (pResp->contLen == 0) {
|
||||||
EPSET_FORWARD_INUSE(&pCtx->epSet);
|
EPSET_FORWARD_INUSE(&pCtx->epSet);
|
||||||
} else {
|
} else {
|
||||||
tDeserializeSEpSet(pResp->pCont, pResp->contLen, &pCtx->epSet);
|
if (tDeserializeSEpSet(pResp->pCont, pResp->contLen, &pCtx->epSet) < 0) {
|
||||||
|
tError("%s conn %p failed to deserialize epset", CONN_GET_INST_LABEL(pConn));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
addConnToPool(pThrd->pool, pConn);
|
||||||
transFreeMsg(pResp->pCont);
|
transFreeMsg(pResp->pCont);
|
||||||
cliSchedMsgToNextNode(pMsg, pThrd);
|
cliSchedMsgToNextNode(pMsg, pThrd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1152,12 +1160,12 @@ void transUnrefCliHandle(void* handle) {
|
||||||
}
|
}
|
||||||
SCliThrd* transGetWorkThrdFromHandle(int64_t handle) {
|
SCliThrd* transGetWorkThrdFromHandle(int64_t handle) {
|
||||||
SCliThrd* pThrd = NULL;
|
SCliThrd* pThrd = NULL;
|
||||||
SExHandle* exh = transAcquireExHandle(handle);
|
SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle);
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pThrd = exh->pThrd;
|
pThrd = exh->pThrd;
|
||||||
transReleaseExHandle(handle);
|
transReleaseExHandle(transGetRefMgt(), handle);
|
||||||
return pThrd;
|
return pThrd;
|
||||||
}
|
}
|
||||||
SCliThrd* transGetWorkThrd(STrans* trans, int64_t handle) {
|
SCliThrd* transGetWorkThrd(STrans* trans, int64_t handle) {
|
||||||
|
@ -1184,10 +1192,13 @@ void transReleaseCliHandle(void* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) {
|
void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) {
|
||||||
STrans* pTransInst = (STrans*)shandle;
|
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
|
if (pTransInst == NULL) return;
|
||||||
|
|
||||||
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
transFreeMsg(pReq->pCont);
|
transFreeMsg(pReq->pCont);
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,19 +1219,24 @@ void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
cliMsg->msg = *pReq;
|
cliMsg->msg = *pReq;
|
||||||
cliMsg->st = taosGetTimestampUs();
|
cliMsg->st = taosGetTimestampUs();
|
||||||
cliMsg->type = Normal;
|
cliMsg->type = Normal;
|
||||||
|
cliMsg->refId = (int64_t)shandle;
|
||||||
|
|
||||||
STraceId* trace = &pReq->info.traceId;
|
STraceId* trace = &pReq->info.traceId;
|
||||||
tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid,
|
tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid,
|
||||||
EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle);
|
EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle);
|
||||||
ASSERT(transAsyncSend(pThrd->asyncPool, &(cliMsg->q)) == 0);
|
ASSERT(transAsyncSend(pThrd->asyncPool, &(cliMsg->q)) == 0);
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) {
|
void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) {
|
||||||
STrans* pTransInst = (STrans*)shandle;
|
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
|
if (pTransInst == NULL) return;
|
||||||
|
|
||||||
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
transFreeMsg(pReq->pCont);
|
transFreeMsg(pReq->pCont);
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
||||||
|
@ -1241,6 +1257,7 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM
|
||||||
cliMsg->msg = *pReq;
|
cliMsg->msg = *pReq;
|
||||||
cliMsg->st = taosGetTimestampUs();
|
cliMsg->st = taosGetTimestampUs();
|
||||||
cliMsg->type = Normal;
|
cliMsg->type = Normal;
|
||||||
|
cliMsg->refId = (int64_t)shandle;
|
||||||
|
|
||||||
STraceId* trace = &pReq->info.traceId;
|
STraceId* trace = &pReq->info.traceId;
|
||||||
tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid,
|
tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid,
|
||||||
|
@ -1250,13 +1267,16 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM
|
||||||
tsem_wait(sem);
|
tsem_wait(sem);
|
||||||
tsem_destroy(sem);
|
tsem_destroy(sem);
|
||||||
taosMemoryFree(sem);
|
taosMemoryFree(sem);
|
||||||
|
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
STrans* pTransInst = shandle;
|
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
|
if (pTransInst == NULL) return;
|
||||||
|
|
||||||
SCvtAddr cvtAddr = {0};
|
SCvtAddr cvtAddr = {0};
|
||||||
if (ip != NULL && fqdn != NULL) {
|
if (ip != NULL && fqdn != NULL) {
|
||||||
|
@ -1271,11 +1291,13 @@ void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
cliMsg->ctx = pCtx;
|
cliMsg->ctx = pCtx;
|
||||||
cliMsg->type = Update;
|
cliMsg->type = Update;
|
||||||
|
cliMsg->refId = (int64_t)shandle;
|
||||||
|
|
||||||
SCliThrd* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i];
|
SCliThrd* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i];
|
||||||
tDebug("%s update epset at thread:%08" PRId64 "", pTransInst->label, thrd->pid);
|
tDebug("%s update epset at thread:%08" PRId64 "", pTransInst->label, thrd->pid);
|
||||||
|
|
||||||
transAsyncSend(thrd->asyncPool, &(cliMsg->q));
|
transAsyncSend(thrd->asyncPool, &(cliMsg->q));
|
||||||
}
|
}
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)shandle);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT;
|
static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT;
|
||||||
|
|
||||||
static int32_t refMgt;
|
static int32_t refMgt;
|
||||||
|
static int32_t instMgt;
|
||||||
|
|
||||||
int transAuthenticateMsg(void* pMsg, int msgLen, void* pAuth, void* pKey) {
|
int transAuthenticateMsg(void* pMsg, int msgLen, void* pAuth, void* pKey) {
|
||||||
T_MD5_CTX context;
|
T_MD5_CTX context;
|
||||||
|
@ -479,53 +480,54 @@ bool transEpSetIsEqual(SEpSet* a, SEpSet* b) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static int32_t transGetRefMgt() {
|
|
||||||
//
|
|
||||||
return refMgt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void transInitEnv() {
|
static void transInitEnv() {
|
||||||
refMgt = transOpenExHandleMgt(50000);
|
refMgt = transOpenRefMgt(50000, transDestoryExHandle);
|
||||||
|
instMgt = taosOpenRef(50, rpcCloseImpl);
|
||||||
uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1");
|
uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1");
|
||||||
}
|
}
|
||||||
static void transDestroyEnv() {
|
static void transDestroyEnv() {
|
||||||
// close ref
|
transCloseRefMgt(refMgt);
|
||||||
transCloseExHandleMgt();
|
transCloseRefMgt(instMgt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void transInit() {
|
void transInit() {
|
||||||
// init env
|
// init env
|
||||||
taosThreadOnce(&transModuleInit, transInitEnv);
|
taosThreadOnce(&transModuleInit, transInitEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t transGetRefMgt() { return refMgt; }
|
||||||
|
int32_t transGetInstMgt() { return instMgt; }
|
||||||
|
|
||||||
void transCleanup() {
|
void transCleanup() {
|
||||||
// clean env
|
// clean env
|
||||||
transDestroyEnv();
|
transDestroyEnv();
|
||||||
}
|
}
|
||||||
int32_t transOpenExHandleMgt(int size) {
|
int32_t transOpenRefMgt(int size, void (*func)(void*)) {
|
||||||
// added into once later
|
// added into once later
|
||||||
return taosOpenRef(size, transDestoryExHandle);
|
return taosOpenRef(size, func);
|
||||||
}
|
}
|
||||||
void transCloseExHandleMgt() {
|
void transCloseRefMgt(int32_t mgt) {
|
||||||
// close ref
|
// close ref
|
||||||
taosCloseRef(transGetRefMgt());
|
taosCloseRef(mgt);
|
||||||
}
|
}
|
||||||
int64_t transAddExHandle(void* p) {
|
int64_t transAddExHandle(int32_t refMgt, void* p) {
|
||||||
// acquire extern handle
|
// acquire extern handle
|
||||||
return taosAddRef(transGetRefMgt(), p);
|
return taosAddRef(refMgt, p);
|
||||||
}
|
}
|
||||||
int32_t transRemoveExHandle(int64_t refId) {
|
int32_t transRemoveExHandle(int32_t refMgt, int64_t refId) {
|
||||||
// acquire extern handle
|
// acquire extern handle
|
||||||
return taosRemoveRef(transGetRefMgt(), refId);
|
return taosRemoveRef(refMgt, refId);
|
||||||
}
|
}
|
||||||
|
|
||||||
SExHandle* transAcquireExHandle(int64_t refId) {
|
void* transAcquireExHandle(int32_t refMgt, int64_t refId) {
|
||||||
// acquire extern handle
|
// acquire extern handle
|
||||||
return (SExHandle*)taosAcquireRef(transGetRefMgt(), refId);
|
return (void*)taosAcquireRef(refMgt, refId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t transReleaseExHandle(int64_t refId) {
|
int32_t transReleaseExHandle(int32_t refMgt, int64_t refId) {
|
||||||
// release extern handle
|
// release extern handle
|
||||||
return taosReleaseRef(transGetRefMgt(), refId);
|
return taosReleaseRef(refMgt, refId);
|
||||||
}
|
}
|
||||||
void transDestoryExHandle(void* handle) {
|
void transDestoryExHandle(void* handle) {
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
|
|
|
@ -261,7 +261,7 @@ static void uvHandleReq(SSvrConn* pConn) {
|
||||||
// 2. once send out data, cli conn released to conn pool immediately
|
// 2. once send out data, cli conn released to conn pool immediately
|
||||||
// 3. not mixed with persist
|
// 3. not mixed with persist
|
||||||
transMsg.info.ahandle = (void*)pHead->ahandle;
|
transMsg.info.ahandle = (void*)pHead->ahandle;
|
||||||
transMsg.info.handle = (void*)transAcquireExHandle(pConn->refId);
|
transMsg.info.handle = (void*)transAcquireExHandle(transGetRefMgt(), pConn->refId);
|
||||||
transMsg.info.refId = pConn->refId;
|
transMsg.info.refId = pConn->refId;
|
||||||
transMsg.info.traceId = pHead->traceId;
|
transMsg.info.traceId = pHead->traceId;
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ static void uvHandleReq(SSvrConn* pConn) {
|
||||||
pConnInfo->clientPort = ntohs(pConn->addr.sin_port);
|
pConnInfo->clientPort = ntohs(pConn->addr.sin_port);
|
||||||
tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user));
|
tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user));
|
||||||
|
|
||||||
transReleaseExHandle(pConn->refId);
|
transReleaseExHandle(transGetRefMgt(), pConn->refId);
|
||||||
|
|
||||||
STrans* pTransInst = pConn->pTransInst;
|
STrans* pTransInst = pConn->pTransInst;
|
||||||
(*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
(*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
||||||
|
@ -402,8 +402,9 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
|
||||||
} else {
|
} else {
|
||||||
pHead->msgType = pMsg->msgType;
|
pHead->msgType = pMsg->msgType;
|
||||||
// set up resp msg type
|
// set up resp msg type
|
||||||
if (pHead->msgType == 0 && transMsgLenFromCont(pMsg->contLen) == sizeof(STransMsgHead))
|
if (pHead->msgType == 0 && transMsgLenFromCont(pMsg->contLen) == sizeof(STransMsgHead)) {
|
||||||
pHead->msgType = pConn->inType + 1;
|
pHead->msgType = pConn->inType + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,15 +508,15 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
||||||
|
|
||||||
SExHandle* exh1 = transMsg.info.handle;
|
SExHandle* exh1 = transMsg.info.handle;
|
||||||
int64_t refId = transMsg.info.refId;
|
int64_t refId = transMsg.info.refId;
|
||||||
SExHandle* exh2 = transAcquireExHandle(refId);
|
SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId);
|
||||||
if (exh2 == NULL || exh1 != exh2) {
|
if (exh2 == NULL || exh1 != exh2) {
|
||||||
tTrace("handle except msg %p, ignore it", exh1);
|
tTrace("handle except msg %p, ignore it", exh1);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
destroySmsg(msg);
|
destroySmsg(msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
msg->pConn = exh1->handle;
|
msg->pConn = exh1->handle;
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
(*transAsyncHandle[msg->type])(msg, pThrd);
|
(*transAsyncHandle[msg->type])(msg, pThrd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -757,8 +758,8 @@ static SSvrConn* createConn(void* hThrd) {
|
||||||
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
||||||
exh->handle = pConn;
|
exh->handle = pConn;
|
||||||
exh->pThrd = pThrd;
|
exh->pThrd = pThrd;
|
||||||
exh->refId = transAddExHandle(exh);
|
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
||||||
transAcquireExHandle(exh->refId);
|
transAcquireExHandle(transGetRefMgt(), exh->refId);
|
||||||
|
|
||||||
pConn->refId = exh->refId;
|
pConn->refId = exh->refId;
|
||||||
transRefSrvHandle(pConn);
|
transRefSrvHandle(pConn);
|
||||||
|
@ -789,14 +790,14 @@ static void destroyConnRegArg(SSvrConn* conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int reallocConnRef(SSvrConn* conn) {
|
static int reallocConnRef(SSvrConn* conn) {
|
||||||
transReleaseExHandle(conn->refId);
|
transReleaseExHandle(transGetRefMgt(), conn->refId);
|
||||||
transRemoveExHandle(conn->refId);
|
transRemoveExHandle(transGetRefMgt(), conn->refId);
|
||||||
// avoid app continue to send msg on invalid handle
|
// avoid app continue to send msg on invalid handle
|
||||||
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
||||||
exh->handle = conn;
|
exh->handle = conn;
|
||||||
exh->pThrd = conn->hostThrd;
|
exh->pThrd = conn->hostThrd;
|
||||||
exh->refId = transAddExHandle(exh);
|
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
||||||
transAcquireExHandle(exh->refId);
|
transAcquireExHandle(transGetRefMgt(), exh->refId);
|
||||||
conn->refId = exh->refId;
|
conn->refId = exh->refId;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -808,8 +809,8 @@ static void uvDestroyConn(uv_handle_t* handle) {
|
||||||
}
|
}
|
||||||
SWorkThrd* thrd = conn->hostThrd;
|
SWorkThrd* thrd = conn->hostThrd;
|
||||||
|
|
||||||
transReleaseExHandle(conn->refId);
|
transReleaseExHandle(transGetRefMgt(), conn->refId);
|
||||||
transRemoveExHandle(conn->refId);
|
transRemoveExHandle(transGetRefMgt(), conn->refId);
|
||||||
|
|
||||||
tDebug("%s conn %p destroy", transLabel(thrd->pTransInst), conn);
|
tDebug("%s conn %p destroy", transLabel(thrd->pTransInst), conn);
|
||||||
transQueueDestroy(&conn->srvMsgs);
|
transQueueDestroy(&conn->srvMsgs);
|
||||||
|
@ -1029,8 +1030,9 @@ void transUnrefSrvHandle(void* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void transReleaseSrvHandle(void* handle) {
|
void transReleaseSrvHandle(void* handle) {
|
||||||
SExHandle* exh = handle;
|
SRpcHandleInfo* info = handle;
|
||||||
int64_t refId = exh->refId;
|
SExHandle* exh = info->handle;
|
||||||
|
int64_t refId = info->refId;
|
||||||
|
|
||||||
ASYNC_CHECK_HANDLE(exh, refId);
|
ASYNC_CHECK_HANDLE(exh, refId);
|
||||||
|
|
||||||
|
@ -1045,11 +1047,11 @@ void transReleaseSrvHandle(void* handle) {
|
||||||
|
|
||||||
tTrace("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle);
|
tTrace("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle);
|
||||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
_return1:
|
_return1:
|
||||||
tTrace("handle %p failed to send to release handle", exh);
|
tTrace("handle %p failed to send to release handle", exh);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
_return2:
|
_return2:
|
||||||
tTrace("handle %p failed to send to release handle", exh);
|
tTrace("handle %p failed to send to release handle", exh);
|
||||||
|
@ -1074,12 +1076,12 @@ void transSendResponse(const STransMsg* msg) {
|
||||||
STraceId* trace = (STraceId*)&msg->info.traceId;
|
STraceId* trace = (STraceId*)&msg->info.traceId;
|
||||||
tGTrace("conn %p start to send resp (1/2)", exh->handle);
|
tGTrace("conn %p start to send resp (1/2)", exh->handle);
|
||||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
_return1:
|
_return1:
|
||||||
tTrace("handle %p failed to send resp", exh);
|
tTrace("handle %p failed to send resp", exh);
|
||||||
rpcFreeCont(msg->pCont);
|
rpcFreeCont(msg->pCont);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
_return2:
|
_return2:
|
||||||
tTrace("handle %p failed to send resp", exh);
|
tTrace("handle %p failed to send resp", exh);
|
||||||
|
@ -1103,13 +1105,13 @@ void transRegisterMsg(const STransMsg* msg) {
|
||||||
|
|
||||||
tTrace("%s conn %p start to register brokenlink callback", transLabel(pThrd->pTransInst), exh->handle);
|
tTrace("%s conn %p start to register brokenlink callback", transLabel(pThrd->pTransInst), exh->handle);
|
||||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_return1:
|
_return1:
|
||||||
tTrace("handle %p failed to register brokenlink", exh);
|
tTrace("handle %p failed to register brokenlink", exh);
|
||||||
rpcFreeCont(msg->pCont);
|
rpcFreeCont(msg->pCont);
|
||||||
transReleaseExHandle(refId);
|
transReleaseExHandle(transGetRefMgt(), refId);
|
||||||
return;
|
return;
|
||||||
_return2:
|
_return2:
|
||||||
tTrace("handle %p failed to register brokenlink", exh);
|
tTrace("handle %p failed to register brokenlink", exh);
|
||||||
|
|
|
@ -175,7 +175,7 @@ static void processReleaseHandleCb(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet)
|
||||||
rpcMsg.code = 0;
|
rpcMsg.code = 0;
|
||||||
rpcSendResponse(&rpcMsg);
|
rpcSendResponse(&rpcMsg);
|
||||||
|
|
||||||
rpcReleaseHandle(pMsg->info.handle, TAOS_CONN_SERVER);
|
rpcReleaseHandle(&pMsg->info, TAOS_CONN_SERVER);
|
||||||
}
|
}
|
||||||
static void processRegisterFailure(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
static void processRegisterFailure(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
{
|
{
|
||||||
|
|
|
@ -332,21 +332,25 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
|
||||||
terrno = TSDB_CODE_WAL_SIZE_LIMIT;
|
terrno = TSDB_CODE_WAL_SIZE_LIMIT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
taosThreadMutexLock(&pWal->mutex);
|
||||||
|
|
||||||
if (index == pWal->vers.lastVer + 1) {
|
if (index == pWal->vers.lastVer + 1) {
|
||||||
if (taosArrayGetSize(pWal->fileInfoSet) == 0) {
|
if (taosArrayGetSize(pWal->fileInfoSet) == 0) {
|
||||||
pWal->vers.firstVer = index;
|
pWal->vers.firstVer = index;
|
||||||
if (walRoll(pWal) < 0) {
|
if (walRoll(pWal) < 0) {
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int64_t passed = walGetSeq() - pWal->lastRollSeq;
|
int64_t passed = walGetSeq() - pWal->lastRollSeq;
|
||||||
if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) {
|
if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) {
|
||||||
if (walRoll(pWal) < 0) {
|
if (walRoll(pWal) < 0) {
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) {
|
} else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) {
|
||||||
if (walRoll(pWal) < 0) {
|
if (walRoll(pWal) < 0) {
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,6 +359,7 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
|
||||||
// reject skip log or rewrite log
|
// reject skip log or rewrite log
|
||||||
// must truncate explicitly first
|
// must truncate explicitly first
|
||||||
terrno = TSDB_CODE_WAL_INVALID_VER;
|
terrno = TSDB_CODE_WAL_INVALID_VER;
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,8 +367,6 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
|
||||||
|
|
||||||
ASSERT(pWal->writeCur >= 0);
|
ASSERT(pWal->writeCur >= 0);
|
||||||
|
|
||||||
taosThreadMutexLock(&pWal->mutex);
|
|
||||||
|
|
||||||
if (pWal->pWriteIdxTFile == NULL || pWal->pWriteLogTFile == NULL) {
|
if (pWal->pWriteIdxTFile == NULL || pWal->pWriteLogTFile == NULL) {
|
||||||
walSetWrite(pWal);
|
walSetWrite(pWal);
|
||||||
taosLSeekFile(pWal->pWriteLogTFile, 0, SEEK_END);
|
taosLSeekFile(pWal->pWriteLogTFile, 0, SEEK_END);
|
||||||
|
|
|
@ -177,6 +177,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "Dnode already exists"
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, "Dnode does not exist")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, "Dnode does not exist")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DNODES, "Too many dnodes")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DNODES, "Too many dnodes")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, "Out of dnodes")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, "Out of dnodes")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_MEM_IN_DNODE, "No enough memory in dnode")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_CFG, "Cluster cfg inconsistent")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_CFG, "Cluster cfg inconsistent")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_ID, "Cluster id not match")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_ID, "Cluster id not match")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG, "Invalid dnode cfg")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG, "Invalid dnode cfg")
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
|
#include "tdef.h"
|
||||||
|
|
||||||
#define tmrFatal(...) \
|
#define tmrFatal(...) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -110,7 +111,7 @@ typedef struct time_wheel_t {
|
||||||
tmr_obj_t** slots;
|
tmr_obj_t** slots;
|
||||||
} time_wheel_t;
|
} time_wheel_t;
|
||||||
|
|
||||||
static int32_t tsMaxTmrCtrl = 512;
|
static int32_t tsMaxTmrCtrl = TSDB_MAX_VNODES_PER_DB + 100;
|
||||||
|
|
||||||
static TdThreadOnce tmrModuleInit = PTHREAD_ONCE_INIT;
|
static TdThreadOnce tmrModuleInit = PTHREAD_ONCE_INIT;
|
||||||
static TdThreadMutex tmrCtrlMutex;
|
static TdThreadMutex tmrCtrlMutex;
|
||||||
|
|
|
@ -52,6 +52,7 @@ typedef struct {
|
||||||
typedef struct SSP_CB_PARAM {
|
typedef struct SSP_CB_PARAM {
|
||||||
TAOS *taos;
|
TAOS *taos;
|
||||||
bool fetch;
|
bool fetch;
|
||||||
|
bool free;
|
||||||
int32_t *end;
|
int32_t *end;
|
||||||
} SSP_CB_PARAM;
|
} SSP_CB_PARAM;
|
||||||
|
|
||||||
|
@ -156,7 +157,58 @@ void sqCloseQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqSyncStopQuery(bool fetch) {
|
void sqKillFetchCb(void *param, TAOS_RES *pRes, int numOfRows) {
|
||||||
|
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||||
|
taos_kill_query(qParam->taos);
|
||||||
|
|
||||||
|
*qParam->end = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sqKillQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||||
|
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||||
|
if (code == 0 && pRes) {
|
||||||
|
if (qParam->fetch) {
|
||||||
|
taos_fetch_rows_a(pRes, sqKillFetchCb, param);
|
||||||
|
} else {
|
||||||
|
taos_kill_query(qParam->taos);
|
||||||
|
*qParam->end = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sqExit("select", taos_errstr(pRes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sqAsyncFetchCb(void *param, TAOS_RES *pRes, int numOfRows) {
|
||||||
|
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||||
|
if (numOfRows > 0) {
|
||||||
|
taos_fetch_rows_a(pRes, sqAsyncFetchCb, param);
|
||||||
|
} else {
|
||||||
|
*qParam->end = 1;
|
||||||
|
if (qParam->free) {
|
||||||
|
taos_free_result(pRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sqAsyncQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||||
|
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||||
|
if (code == 0 && pRes) {
|
||||||
|
if (qParam->fetch) {
|
||||||
|
taos_fetch_rows_a(pRes, sqAsyncFetchCb, param);
|
||||||
|
} else {
|
||||||
|
if (qParam->free) {
|
||||||
|
taos_free_result(pRes);
|
||||||
|
}
|
||||||
|
*qParam->end = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sqExit("select", taos_errstr(pRes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sqStopSyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -189,7 +241,7 @@ int sqSyncStopQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqAsyncStopQuery(bool fetch) {
|
int sqStopAsyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -219,7 +271,7 @@ int sqAsyncStopQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqSyncFreeQuery(bool fetch) {
|
int sqFreeSyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -250,7 +302,7 @@ int sqSyncFreeQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqAsyncFreeQuery(bool fetch) {
|
int sqFreeAsyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -280,7 +332,7 @@ int sqAsyncFreeQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqSyncCloseQuery(bool fetch) {
|
int sqCloseSyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -310,7 +362,7 @@ int sqSyncCloseQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqAsyncCloseQuery(bool fetch) {
|
int sqCloseAsyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
char sql[1024] = {0};
|
char sql[1024] = {0};
|
||||||
|
@ -360,9 +412,39 @@ void *syncQueryThreadFp(void *arg) {
|
||||||
taos_fetch_row(pRes);
|
taos_fetch_row(pRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
taos_free_result(pRes);
|
if (qParam->free) {
|
||||||
|
taos_free_result(pRes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *asyncQueryThreadFp(void *arg) {
|
||||||
|
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
||||||
|
char sql[1024] = {0};
|
||||||
|
int32_t code = 0;
|
||||||
|
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||||
|
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||||
|
|
||||||
|
qParam->taos = taos;
|
||||||
|
|
||||||
|
sprintf(sql, "reset query cache");
|
||||||
|
sqExecSQLE(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "use %s", dbName);
|
||||||
|
sqExecSQLE(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "select * from %s", tbName);
|
||||||
|
|
||||||
|
int32_t qEnd = 0;
|
||||||
|
SSP_CB_PARAM param = {0};
|
||||||
|
param.fetch = qParam->fetch;
|
||||||
|
param.end = &qEnd;
|
||||||
|
taos_query_a(taos, sql, sqAsyncQueryCb, ¶m);
|
||||||
|
while (0 == qEnd) {
|
||||||
|
usleep(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *closeThreadFp(void *arg) {
|
void *closeThreadFp(void *arg) {
|
||||||
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -376,7 +458,22 @@ void *closeThreadFp(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sqConSyncCloseQuery(bool fetch) {
|
|
||||||
|
void *killThreadFp(void *arg) {
|
||||||
|
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
||||||
|
while (true) {
|
||||||
|
if (qParam->taos) {
|
||||||
|
usleep(rand() % 10000);
|
||||||
|
taos_kill_query(qParam->taos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int sqConCloseSyncQuery(bool fetch) {
|
||||||
CASE_ENTER();
|
CASE_ENTER();
|
||||||
pthread_t qid, cid;
|
pthread_t qid, cid;
|
||||||
for (int32_t i = 0; i < runTimes; ++i) {
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
@ -391,26 +488,160 @@ int sqConSyncCloseQuery(bool fetch) {
|
||||||
CASE_LEAVE();
|
CASE_LEAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sqConCloseAsyncQuery(bool fetch) {
|
||||||
|
CASE_ENTER();
|
||||||
|
pthread_t qid, cid;
|
||||||
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
SSP_CB_PARAM param = {0};
|
||||||
|
param.fetch = fetch;
|
||||||
|
pthread_create(&qid, NULL, asyncQueryThreadFp, (void*)¶m);
|
||||||
|
pthread_create(&cid, NULL, closeThreadFp, (void*)¶m);
|
||||||
|
|
||||||
|
pthread_join(qid, NULL);
|
||||||
|
pthread_join(cid, NULL);
|
||||||
|
}
|
||||||
|
CASE_LEAVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sqKillSyncQuery(bool fetch) {
|
||||||
|
CASE_ENTER();
|
||||||
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
char sql[1024] = {0};
|
||||||
|
int32_t code = 0;
|
||||||
|
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||||
|
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||||
|
|
||||||
|
sprintf(sql, "reset query cache");
|
||||||
|
sqExecSQL(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "use %s", dbName);
|
||||||
|
sqExecSQL(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "select * from %s", tbName);
|
||||||
|
TAOS_RES* pRes = taos_query(taos, sql);
|
||||||
|
code = taos_errno(pRes);
|
||||||
|
if (code) {
|
||||||
|
sqExit("taos_query", taos_errstr(pRes));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fetch) {
|
||||||
|
taos_fetch_row(pRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
taos_kill_query(taos);
|
||||||
|
|
||||||
|
taos_close(taos);
|
||||||
|
}
|
||||||
|
CASE_LEAVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
int sqKillAsyncQuery(bool fetch) {
|
||||||
|
CASE_ENTER();
|
||||||
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
char sql[1024] = {0};
|
||||||
|
int32_t code = 0;
|
||||||
|
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||||
|
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||||
|
|
||||||
|
sprintf(sql, "reset query cache");
|
||||||
|
sqExecSQL(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "use %s", dbName);
|
||||||
|
sqExecSQL(taos, sql);
|
||||||
|
|
||||||
|
sprintf(sql, "select * from %s", tbName);
|
||||||
|
|
||||||
|
int32_t qEnd = 0;
|
||||||
|
SSP_CB_PARAM param = {0};
|
||||||
|
param.fetch = fetch;
|
||||||
|
param.end = &qEnd;
|
||||||
|
param.taos = taos;
|
||||||
|
taos_query_a(taos, sql, sqKillQueryCb, ¶m);
|
||||||
|
while (0 == qEnd) {
|
||||||
|
usleep(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
taos_close(taos);
|
||||||
|
}
|
||||||
|
CASE_LEAVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
int sqConKillSyncQuery(bool fetch) {
|
||||||
|
CASE_ENTER();
|
||||||
|
pthread_t qid, cid;
|
||||||
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
SSP_CB_PARAM param = {0};
|
||||||
|
param.fetch = fetch;
|
||||||
|
pthread_create(&qid, NULL, syncQueryThreadFp, (void*)¶m);
|
||||||
|
pthread_create(&cid, NULL, killThreadFp, (void*)¶m);
|
||||||
|
|
||||||
|
pthread_join(qid, NULL);
|
||||||
|
pthread_join(cid, NULL);
|
||||||
|
}
|
||||||
|
CASE_LEAVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
int sqConKillAsyncQuery(bool fetch) {
|
||||||
|
CASE_ENTER();
|
||||||
|
pthread_t qid, cid;
|
||||||
|
for (int32_t i = 0; i < runTimes; ++i) {
|
||||||
|
SSP_CB_PARAM param = {0};
|
||||||
|
param.fetch = fetch;
|
||||||
|
pthread_create(&qid, NULL, asyncQueryThreadFp, (void*)¶m);
|
||||||
|
pthread_create(&cid, NULL, killThreadFp, (void*)¶m);
|
||||||
|
|
||||||
|
pthread_join(qid, NULL);
|
||||||
|
pthread_join(cid, NULL);
|
||||||
|
}
|
||||||
|
CASE_LEAVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void sqRunAllCase(void) {
|
void sqRunAllCase(void) {
|
||||||
/*
|
/*
|
||||||
sqSyncStopQuery(false);
|
sqStopSyncQuery(false);
|
||||||
sqSyncStopQuery(true);
|
sqStopSyncQuery(true);
|
||||||
sqAsyncStopQuery(false);
|
sqStopAsyncQuery(false);
|
||||||
sqAsyncStopQuery(true);
|
sqStopAsyncQuery(true);
|
||||||
|
|
||||||
sqSyncFreeQuery(false);
|
sqFreeSyncQuery(false);
|
||||||
sqSyncFreeQuery(true);
|
sqFreeSyncQuery(true);
|
||||||
sqAsyncFreeQuery(false);
|
sqFreeAsyncQuery(false);
|
||||||
sqAsyncFreeQuery(true);
|
sqFreeAsyncQuery(true);
|
||||||
|
|
||||||
sqSyncCloseQuery(false);
|
sqCloseSyncQuery(false);
|
||||||
sqSyncCloseQuery(true);
|
sqCloseSyncQuery(true);
|
||||||
sqAsyncCloseQuery(false);
|
sqCloseAsyncQuery(false);
|
||||||
sqAsyncCloseQuery(true);
|
sqCloseAsyncQuery(true);
|
||||||
*/
|
|
||||||
sqConSyncCloseQuery(false);
|
sqConCloseSyncQuery(false);
|
||||||
sqConSyncCloseQuery(true);
|
sqConCloseSyncQuery(true);
|
||||||
|
sqConCloseAsyncQuery(false);
|
||||||
|
sqConCloseAsyncQuery(true);
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
sqKillSyncQuery(false);
|
||||||
|
sqKillSyncQuery(true);
|
||||||
|
sqKillAsyncQuery(false);
|
||||||
|
sqKillAsyncQuery(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//sqConKillSyncQuery(false);
|
||||||
|
sqConKillSyncQuery(true);
|
||||||
|
#if 0
|
||||||
|
sqConKillAsyncQuery(false);
|
||||||
|
sqConKillAsyncQuery(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t l = 5;
|
||||||
|
while (l) {
|
||||||
|
printf("%d\n", l--);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,7 @@
|
||||||
./test.sh -f tsim/sma/drop_sma.sim
|
./test.sh -f tsim/sma/drop_sma.sim
|
||||||
./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim
|
./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim
|
||||||
./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim
|
./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim
|
||||||
|
./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim
|
||||||
|
|
||||||
# --- valgrind
|
# --- valgrind
|
||||||
./test.sh -f tsim/valgrind/checkError.sim -v
|
./test.sh -f tsim/valgrind/checkError.sim -v
|
||||||
|
|
|
@ -121,7 +121,7 @@ echo "firstEp ${HOSTNAME}:7100" >> $TAOS_CFG
|
||||||
echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
|
echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
|
||||||
echo "fqdn ${HOSTNAME}" >> $TAOS_CFG
|
echo "fqdn ${HOSTNAME}" >> $TAOS_CFG
|
||||||
echo "serverPort ${NODE}" >> $TAOS_CFG
|
echo "serverPort ${NODE}" >> $TAOS_CFG
|
||||||
echo "supportVnodes 128" >> $TAOS_CFG
|
echo "supportVnodes 1024" >> $TAOS_CFG
|
||||||
echo "dataDir $DATA_DIR" >> $TAOS_CFG
|
echo "dataDir $DATA_DIR" >> $TAOS_CFG
|
||||||
echo "logDir $LOG_DIR" >> $TAOS_CFG
|
echo "logDir $LOG_DIR" >> $TAOS_CFG
|
||||||
echo "debugFlag 0" >> $TAOS_CFG
|
echo "debugFlag 0" >> $TAOS_CFG
|
||||||
|
@ -135,7 +135,7 @@ echo "jniDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "qDebugFlag 143" >> $TAOS_CFG
|
echo "qDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "rpcDebugFlag 143" >> $TAOS_CFG
|
echo "rpcDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "tmrDebugFlag 131" >> $TAOS_CFG
|
echo "tmrDebugFlag 131" >> $TAOS_CFG
|
||||||
echo "uDebugFlag 131" >> $TAOS_CFG
|
echo "uDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "sDebugFlag 143" >> $TAOS_CFG
|
echo "sDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "wDebugFlag 143" >> $TAOS_CFG
|
echo "wDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "numOfLogLines 20000000" >> $TAOS_CFG
|
echo "numOfLogLines 20000000" >> $TAOS_CFG
|
||||||
|
|
|
@ -14,7 +14,7 @@ while [ -n "$PID" ]; do
|
||||||
echo kill -9 $PID
|
echo kill -9 $PID
|
||||||
#pkill -9 taosd
|
#pkill -9 taosd
|
||||||
kill -9 $PID
|
kill -9 $PID
|
||||||
echo "Killing processes locking on port 6030"
|
echo "Killing taosd processes"
|
||||||
if [ "$OS_TYPE" != "Darwin" ]; then
|
if [ "$OS_TYPE" != "Darwin" ]; then
|
||||||
fuser -k -n tcp 6030
|
fuser -k -n tcp 6030
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,39 +7,33 @@ system sh/deploy.sh -n dnode4 -i 4
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/deploy.sh -n dnode2 -i 2
|
|
||||||
system sh/deploy.sh -n dnode3 -i 3
|
|
||||||
system sh/deploy.sh -n dnode4 -i 4
|
|
||||||
system sh/deploy.sh -n dnode5 -i 5
|
|
||||||
system sh/deploy.sh -n dnode6 -i 6
|
|
||||||
system sh/deploy.sh -n dnode7 -i 7
|
|
||||||
system sh/deploy.sh -n dnode8 -i 8
|
|
||||||
system sh/deploy.sh -n dnode9 -i 9
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start
|
||||||
system sh/exec.sh -n dnode2 -s start
|
sql connect
|
||||||
system sh/exec.sh -n dnode3 -s start
|
|
||||||
system sh/exec.sh -n dnode4 -s start
|
|
||||||
system sh/exec.sh -n dnode5 -s start
|
|
||||||
system sh/exec.sh -n dnode6 -s start
|
|
||||||
system sh/exec.sh -n dnode7 -s start
|
|
||||||
system sh/exec.sh -n dnode8 -s start
|
|
||||||
system sh/exec.sh -n dnode9 -s start
|
|
||||||
|
|
||||||
sleep 2000
|
$num = 200
|
||||||
|
$i = 0
|
||||||
|
while $i < $num
|
||||||
|
$port = $i + 8000
|
||||||
|
$i = $i + 1
|
||||||
|
sql create dnode $hostname port $port
|
||||||
|
endw
|
||||||
|
|
||||||
sql create dnode $hostname port 7200
|
$i = 0
|
||||||
sql create dnode $hostname port 7300
|
while $i < $num
|
||||||
sql create dnode $hostname port 7400
|
$port = $i + 8000
|
||||||
sql create dnode $hostname port 7500
|
$i = $i + 1
|
||||||
sql create dnode $hostname port 7600
|
$name = dnode . $port
|
||||||
sql create dnode $hostname port 7700
|
system sh/deploy.sh -n $name -i 1
|
||||||
sql create dnode $hostname port 7800
|
system sh/cfg.sh -n $name -c serverPort -v $port
|
||||||
sql create dnode $hostname port 7900
|
system sh/exec.sh -n $name -s start
|
||||||
|
endw
|
||||||
|
|
||||||
sql show dnodes;
|
return
|
||||||
print $data00 $data01
|
|
||||||
print $data10 $data11
|
sql create database db vgroups 1024 buffer 3;
|
||||||
print $data20 $data21
|
sql use db;
|
||||||
print $data30 $data31
|
sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned);
|
||||||
print $data40 $data41
|
sql create table ct1 using stb tags(1000);
|
||||||
|
sql create table ct2 using stb tags(1000) ;
|
||||||
|
sql show db.tables;
|
||||||
|
sql insert into ct1 values(now+0s, 10, 2.0, 3.0);
|
|
@ -0,0 +1,237 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sleep 50
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print =============== create database with retentions
|
||||||
|
sql create database d0 retentions 5s:7d,5m:21d,15m:365d;
|
||||||
|
sql use d0
|
||||||
|
|
||||||
|
print =============== create super table and register rsma
|
||||||
|
sql create table if not exists stb (ts timestamp, c1 int, c2 float) tags (city binary(20),district binary(20)) rollup(max) max_delay 5s,5s watermark 2s,3s;
|
||||||
|
|
||||||
|
sql show stables
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== create child table
|
||||||
|
sql create table ct1 using stb tags("BeiJing", "ChaoYang");
|
||||||
|
|
||||||
|
sql show tables
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== insert data and trigger rollup
|
||||||
|
sql insert into ct1 values(now, 10, 10.0);
|
||||||
|
sql insert into ct1 values(now+1s, 1, 1.0);
|
||||||
|
sql insert into ct1 values(now+2s, 100, 100.0);
|
||||||
|
|
||||||
|
print =============== wait maxdelay 5+1 seconds for results
|
||||||
|
sleep 6000
|
||||||
|
|
||||||
|
print =============== select * from retention level 2 from memory
|
||||||
|
sql select * from ct1;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 2 file rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 2 file result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== select * from retention level 1 from memory
|
||||||
|
sql select * from ct1 where ts > now-8d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 1 file rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 1 file result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== select * from retention level 0 from memory
|
||||||
|
sql select * from ct1 where ts > now-3d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
print $data10 $data11 $data12
|
||||||
|
print $data20 $data21 $data22
|
||||||
|
|
||||||
|
if $rows < 1 then
|
||||||
|
print retention level 0 file rows $rows < 1
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 0 file result $data01 != 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
#===================================================================
|
||||||
|
|
||||||
|
|
||||||
|
#==================== reboot to trigger commit data to file
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
|
print =============== select * from retention level 2 from file
|
||||||
|
sql select * from ct1;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 2 file rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 2 file result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== select * from retention level 1 from file
|
||||||
|
sql select * from ct1 where ts > now-8d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 1 file rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 1 file result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== select * from retention level 0 from file
|
||||||
|
sql select * from ct1 where ts > now-3d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
print $data10 $data11 $data12
|
||||||
|
print $data20 $data21 $data22
|
||||||
|
if $rows < 1 then
|
||||||
|
print retention level 0 file rows $rows < 1
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 0 file result $data01 != 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== insert after rsma qtaskinfo recovery
|
||||||
|
sql insert into ct1 values(now, 50, 500.0);
|
||||||
|
sql insert into ct1 values(now+1s, 40, 40.0);
|
||||||
|
|
||||||
|
print =============== wait maxdelay 5+1 seconds for results
|
||||||
|
sleep 6000
|
||||||
|
|
||||||
|
print =============== select * from retention level 2 from file and memory after rsma qtaskinfo recovery
|
||||||
|
sql select * from ct1;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 2 file/mem rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 2 file/mem result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data02 != 500.00000 then
|
||||||
|
if $data02 != 100.00000 then
|
||||||
|
print retention level 1 file/mem result $data02 != 500.00000 or 100.00000
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== select * from retention level 1 from file and memory after rsma qtaskinfo recovery
|
||||||
|
sql select * from ct1 where ts > now-8d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
if $rows > 2 then
|
||||||
|
print retention level 1 file/mem rows $rows > 2
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 100 then
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 1 file/mem result $data01 != 100 or 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data02 != 500.00000 then
|
||||||
|
if $data02 != 100.00000 then
|
||||||
|
print retention level 1 file/mem result $data02 != 500.00000 or 100.00000
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
print =============== select * from retention level 0 from file and memory after rsma qtaskinfo recovery
|
||||||
|
sql select * from ct1 where ts > now-3d;
|
||||||
|
print $data00 $data01 $data02
|
||||||
|
print $data10 $data11 $data12
|
||||||
|
print $data20 $data21 $data22
|
||||||
|
print $data30 $data31 $data32
|
||||||
|
print $data40 $data41 $data42
|
||||||
|
|
||||||
|
if $rows < 1 then
|
||||||
|
print retention level 0 file/mem rows $rows < 1
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 10 then
|
||||||
|
print retention level 0 file/mem result $data01 != 10
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data11 != 1 then
|
||||||
|
print retention level 0 file/mem result $data11 != 1
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data21 != 100 then
|
||||||
|
print retention level 0 file/mem result $data21 != 100
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data31 != 50 then
|
||||||
|
print retention level 0 file/mem result $data31 != 50
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data32 != 500.00000 then
|
||||||
|
print retention level 0 file/mem result $data32 != 500.00000
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
if $data41 != 40 then
|
||||||
|
print retention level 0 file/mem result $data41 != 40
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data42 != 40.00000 then
|
||||||
|
print retention level 0 file/mem result $data42 != 40.00000
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -1,8 +1,33 @@
|
||||||
system sh/stop_dnodes.sh
|
system sh/stop_dnodes.sh
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start -v
|
||||||
sql connect
|
sql connect
|
||||||
|
|
||||||
sql create database d0 vgroups 1;
|
print =============== step1: create drop show dnodes
|
||||||
|
$x = 0
|
||||||
|
step1:
|
||||||
|
$x = $x + 1
|
||||||
|
sleep 1000
|
||||||
|
if $x == 10 then
|
||||||
|
print ====> dnode not ready!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql show dnodes
|
||||||
|
print ===> $data00 $data01 $data02 $data03 $data04 $data05
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
goto _OVER
|
||||||
|
|
||||||
|
print =============== step2: create alter drop show user
|
||||||
|
sql create user u1 pass 'taosdata'
|
||||||
|
sql show users
|
||||||
|
sql alter user u1 sysinfo 1
|
||||||
|
sql alter user u1 enable 1
|
||||||
|
sql alter user u1 pass 'taosdata'
|
||||||
|
sql drop user u1
|
||||||
|
sql_error alter user u2 sysinfo 0
|
||||||
|
|
||||||
|
_OVER:
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start -v
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print =============== step1: create drop show dnodes
|
||||||
|
$x = 0
|
||||||
|
step1:
|
||||||
|
$x = $x + 1
|
||||||
|
sleep 1000
|
||||||
|
if $x == 10 then
|
||||||
|
print ====> dnode not ready!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql show dnodes
|
||||||
|
print ===> $data00 $data01 $data02 $data03 $data04 $data05
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step2: create db
|
||||||
|
sql create database db vgroups 1
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -0,0 +1,442 @@
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import List, Any, Tuple
|
||||||
|
from util.log import *
|
||||||
|
from util.sql import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.dnodes import *
|
||||||
|
from util.constant import *
|
||||||
|
|
||||||
|
PRIMARY_COL = "ts"
|
||||||
|
|
||||||
|
INT_COL = "c_int"
|
||||||
|
BINT_COL = "c_bint"
|
||||||
|
SINT_COL = "c_sint"
|
||||||
|
TINT_COL = "c_tint"
|
||||||
|
FLOAT_COL = "c_float"
|
||||||
|
DOUBLE_COL = "c_double"
|
||||||
|
BOOL_COL = "c_bool"
|
||||||
|
TINT_UN_COL = "c_utint"
|
||||||
|
SINT_UN_COL = "c_usint"
|
||||||
|
BINT_UN_COL = "c_ubint"
|
||||||
|
INT_UN_COL = "c_uint"
|
||||||
|
BINARY_COL = "c_binary"
|
||||||
|
NCHAR_COL = "c_nchar"
|
||||||
|
TS_COL = "c_ts"
|
||||||
|
|
||||||
|
NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ]
|
||||||
|
CHAR_COL = [BINARY_COL, NCHAR_COL, ]
|
||||||
|
BOOLEAN_COL = [BOOL_COL, ]
|
||||||
|
TS_TYPE_COL = [TS_COL, ]
|
||||||
|
|
||||||
|
INT_TAG = "t_int"
|
||||||
|
|
||||||
|
ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BINARY_COL, NCHAR_COL, BOOL_COL, TS_COL]
|
||||||
|
TAG_COL = [INT_TAG]
|
||||||
|
|
||||||
|
# insert data args:
|
||||||
|
TIME_STEP = 10000
|
||||||
|
NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
|
||||||
|
|
||||||
|
# init db/table
|
||||||
|
DBNAME = "db"
|
||||||
|
STBNAME = "stb1"
|
||||||
|
CTBNAME = "ct1"
|
||||||
|
NTBNAME = "nt1"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DataSet:
|
||||||
|
ts_data : List[int] = field(default_factory=list)
|
||||||
|
int_data : List[int] = field(default_factory=list)
|
||||||
|
bint_data : List[int] = field(default_factory=list)
|
||||||
|
sint_data : List[int] = field(default_factory=list)
|
||||||
|
tint_data : List[int] = field(default_factory=list)
|
||||||
|
int_un_data : List[int] = field(default_factory=list)
|
||||||
|
bint_un_data: List[int] = field(default_factory=list)
|
||||||
|
sint_un_data: List[int] = field(default_factory=list)
|
||||||
|
tint_un_data: List[int] = field(default_factory=list)
|
||||||
|
float_data : List[float] = field(default_factory=list)
|
||||||
|
double_data : List[float] = field(default_factory=list)
|
||||||
|
bool_data : List[int] = field(default_factory=list)
|
||||||
|
binary_data : List[str] = field(default_factory=list)
|
||||||
|
nchar_data : List[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BSMAschema:
|
||||||
|
creation : str = "CREATE"
|
||||||
|
tb_type : str = "stable"
|
||||||
|
tbname : str = STBNAME
|
||||||
|
cols : Tuple[str] = None
|
||||||
|
tags : Tuple[str] = None
|
||||||
|
sma_flag : str = "SMA"
|
||||||
|
sma_cols : Tuple[str] = None
|
||||||
|
create_tabel_sql : str = None
|
||||||
|
other : Any = None
|
||||||
|
|
||||||
|
drop : str = "DROP"
|
||||||
|
drop_flag : str = "INDEX"
|
||||||
|
querySmaOptimize : int = 1
|
||||||
|
show : str = "SHOW"
|
||||||
|
show_msg : str = "INDEXES"
|
||||||
|
show_oper : str = "FROM"
|
||||||
|
dbname : str = None
|
||||||
|
rollup_db : bool = False
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if isinstance(self.other, dict):
|
||||||
|
for k,v in self.other.items():
|
||||||
|
|
||||||
|
if k.lower() == "tbname" and isinstance(v, str) and not self.tbname:
|
||||||
|
self.tbname = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "cols" and (isinstance(v, tuple) or isinstance(v, list)) and not self.cols:
|
||||||
|
self.cols = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "tags" and (isinstance(v, tuple) or isinstance(v, list)) and not self.tags:
|
||||||
|
self.tags = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "sma_flag" and isinstance(v, str) and not self.sma_flag:
|
||||||
|
self.sma_flag = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "sma_cols" and (isinstance(v, tuple) or isinstance(v, list)) and not self.sma_cols:
|
||||||
|
self.sma_cols = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "create_tabel_sql" and isinstance(v, str) and not self.create_tabel_sql:
|
||||||
|
self.create_tabel_sql = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
# bSma show and drop operator is not completed
|
||||||
|
if k.lower() == "drop_flag" and isinstance(v, str) and not self.drop_flag:
|
||||||
|
self.drop_flag = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "show_msg" and isinstance(v, str) and not self.show_msg:
|
||||||
|
self.show_msg = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "dbname" and isinstance(v, str) and not self.dbname:
|
||||||
|
self.dbname = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "show_oper" and isinstance(v, str) and not self.show_oper:
|
||||||
|
self.show_oper = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
if k.lower() == "rollup_db" and isinstance(v, bool) and not self.rollup_db:
|
||||||
|
self.rollup_db = v
|
||||||
|
del self.other[k]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# from ...pytest.util.sql import *
|
||||||
|
# from ...pytest.util.constant import *
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
|
tdSql.init(conn.cursor(), False)
|
||||||
|
self.precision = "ms"
|
||||||
|
self.sma_count = 0
|
||||||
|
self.sma_created_index = []
|
||||||
|
|
||||||
|
def __create_sma_index(self, sma:BSMAschema):
|
||||||
|
if sma.create_tabel_sql:
|
||||||
|
sql = sma.create_tabel_sql
|
||||||
|
else:
|
||||||
|
sql = f"{sma.creation} {sma.tb_type} {sma.tbname} ({', '.join(sma.cols)}) "
|
||||||
|
|
||||||
|
if sma.tb_type == "stable" or (sma.tb_type=="table" and sma.tags):
|
||||||
|
sql = f"{sma.creation} {sma.tb_type} {sma.tbname} ({', '.join(sma.cols)}) tags ({', '.join(sma.tags)}) "
|
||||||
|
|
||||||
|
|
||||||
|
if sma.sma_flag:
|
||||||
|
sql += sma.sma_flag
|
||||||
|
if sma.sma_cols:
|
||||||
|
sql += f"({', '.join(sma.sma_cols)})"
|
||||||
|
|
||||||
|
if isinstance(sma.other, dict):
|
||||||
|
for k,v in sma.other.items():
|
||||||
|
if isinstance(v,tuple) or isinstance(v, list):
|
||||||
|
sql += f" {k} ({' '.join(v)})"
|
||||||
|
else:
|
||||||
|
sql += f" {k} {v}"
|
||||||
|
if isinstance(sma.other, tuple) or isinstance(sma.other, list):
|
||||||
|
sql += " ".join(sma.other)
|
||||||
|
if isinstance(sma.other, int) or isinstance(sma.other, float) or isinstance(sma.other, str):
|
||||||
|
sql += f" {sma.other}"
|
||||||
|
|
||||||
|
return sql
|
||||||
|
|
||||||
|
def __get_bsma_table_col_tag_str(self, sql:str):
|
||||||
|
p = re.compile(r"[(](.*)[)]", re.S)
|
||||||
|
|
||||||
|
if "tags" in (col_str := sql):
|
||||||
|
col_str = re.findall(p, sql.split("tags")[0])[0].split(",")
|
||||||
|
if (tag_str := re.findall(p, sql.split("tags")[1])[0].split(",") ):
|
||||||
|
col_str.extend(tag_str)
|
||||||
|
|
||||||
|
return col_str
|
||||||
|
|
||||||
|
def __get_bsma_col_tag_names(self, col_tags:list):
|
||||||
|
return [ col_tag.strip().split(" ")[0] for col_tag in col_tags ]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __get_db_tbname(self):
|
||||||
|
tb_list = []
|
||||||
|
tdSql.query("show tables")
|
||||||
|
for row in tdSql.queryResult:
|
||||||
|
tb_list.append(row[0])
|
||||||
|
tdSql.query("show tables")
|
||||||
|
for row in tdSql.queryResult:
|
||||||
|
tb_list.append(row[0])
|
||||||
|
|
||||||
|
return tb_list
|
||||||
|
|
||||||
|
def __bsma_create_check(self, sma:BSMAschema):
|
||||||
|
if not sma.creation:
|
||||||
|
return False
|
||||||
|
if not sma.create_tabel_sql and (not sma.tbname or not sma.tb_type or not sma.cols):
|
||||||
|
return False
|
||||||
|
if not sma.create_tabel_sql and (sma.tb_type == "stable" and not sma.tags):
|
||||||
|
return False
|
||||||
|
if not sma.sma_flag or not isinstance(sma.sma_flag, str) or sma.sma_flag.upper() != "SMA":
|
||||||
|
return False
|
||||||
|
if sma.tbname in self.__get_db_tbname:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if sma.create_tabel_sql:
|
||||||
|
col_tag_list = self.__get_bsma_col_tag_names(self.__get_bsma_table_col_tag_str(sma.create_tabel_sql))
|
||||||
|
else:
|
||||||
|
col_str = list(sma.cols)
|
||||||
|
if sma.tags:
|
||||||
|
col_str.extend(list(sma.tags))
|
||||||
|
col_tag_list = self.__get_bsma_col_tag_names(col_str)
|
||||||
|
if not sma.sma_cols:
|
||||||
|
return False
|
||||||
|
for col in sma.sma_cols:
|
||||||
|
if col not in col_tag_list:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def bsma_create_check(self, sma:BSMAschema):
|
||||||
|
if self.__bsma_create_check(sma):
|
||||||
|
tdSql.query(self.__create_sma_index(sma))
|
||||||
|
tdLog.info(f"current sql: {self.__create_sma_index(sma)}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
tdSql.error(self.__create_sma_index(sma))
|
||||||
|
|
||||||
|
|
||||||
|
def __sma_drop_check(self, sma:BSMAschema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sma_drop_check(self, sma:BSMAschema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __show_sma_index(self, sma:BSMAschema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __sma_show_check(self, sma:BSMAschema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sma_show_check(self, sma:BSMAschema):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __create_sma_sql(self):
|
||||||
|
err_sqls = []
|
||||||
|
cur_sqls = []
|
||||||
|
# err_set
|
||||||
|
### case 1: required fields check
|
||||||
|
err_sqls.append( BSMAschema(creation="", tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
err_sqls.append( BSMAschema(tbname="", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
err_sqls.append( BSMAschema(tbname="stb2", cols=(), tags=(f"{INT_TAG} int",), sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
err_sqls.append( BSMAschema(tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(), sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
err_sqls.append( BSMAschema(tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_flag="", sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
err_sqls.append( BSMAschema(tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_cols=() ) )
|
||||||
|
### case 2:
|
||||||
|
err_sqls.append( BSMAschema(tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_cols=({BINT_COL}) ) )
|
||||||
|
|
||||||
|
# current_set
|
||||||
|
cur_sqls.append( BSMAschema(tbname="stb2", cols=(f"{PRIMARY_COL} timestamp", f"{INT_COL} int"), tags=(f"{INT_TAG} int",), sma_cols=(PRIMARY_COL, INT_COL ) ) )
|
||||||
|
|
||||||
|
return err_sqls, cur_sqls
|
||||||
|
|
||||||
|
def test_create_sma(self):
|
||||||
|
err_sqls , cur_sqls = self.__create_sma_sql
|
||||||
|
for err_sql in err_sqls:
|
||||||
|
self.bsma_create_check(err_sql)
|
||||||
|
for cur_sql in cur_sqls:
|
||||||
|
self.bsma_create_check(cur_sql)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __drop_sma_sql(self):
|
||||||
|
err_sqls = []
|
||||||
|
cur_sqls = []
|
||||||
|
# err_set
|
||||||
|
## case 1: required fields check
|
||||||
|
return err_sqls, cur_sqls
|
||||||
|
|
||||||
|
def test_drop_sma(self):
|
||||||
|
err_sqls , cur_sqls = self.__drop_sma_sql
|
||||||
|
for err_sql in err_sqls:
|
||||||
|
self.sma_drop_check(err_sql)
|
||||||
|
for cur_sql in cur_sqls:
|
||||||
|
self.sma_drop_check(cur_sql)
|
||||||
|
|
||||||
|
def all_test(self):
|
||||||
|
self.test_create_sma()
|
||||||
|
|
||||||
|
def __create_tb(self):
|
||||||
|
tdLog.printNoPrefix("==========step: create table")
|
||||||
|
create_stb_sql = f'''create table {STBNAME}(
|
||||||
|
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
|
||||||
|
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
|
||||||
|
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp,
|
||||||
|
{TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned,
|
||||||
|
{INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned
|
||||||
|
) tags ({INT_TAG} int)
|
||||||
|
'''
|
||||||
|
create_ntb_sql = f'''create table {NTBNAME}(
|
||||||
|
ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
|
||||||
|
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
|
||||||
|
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp,
|
||||||
|
{TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned,
|
||||||
|
{INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
tdSql.execute(create_stb_sql)
|
||||||
|
tdSql.execute(create_ntb_sql)
|
||||||
|
|
||||||
|
for i in range(4):
|
||||||
|
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )')
|
||||||
|
|
||||||
|
def __data_set(self, rows):
|
||||||
|
data_set = DataSet()
|
||||||
|
|
||||||
|
for i in range(rows):
|
||||||
|
data_set.ts_data.append(NOW + 1 * (rows - i))
|
||||||
|
data_set.int_data.append(rows - i)
|
||||||
|
data_set.bint_data.append(11111 * (rows - i))
|
||||||
|
data_set.sint_data.append(111 * (rows - i) % 32767)
|
||||||
|
data_set.tint_data.append(11 * (rows - i) % 127)
|
||||||
|
data_set.int_un_data.append(rows - i)
|
||||||
|
data_set.bint_un_data.append(11111 * (rows - i))
|
||||||
|
data_set.sint_un_data.append(111 * (rows - i) % 32767)
|
||||||
|
data_set.tint_un_data.append(11 * (rows - i) % 127)
|
||||||
|
data_set.float_data.append(1.11 * (rows - i))
|
||||||
|
data_set.double_data.append(1100.0011 * (rows - i))
|
||||||
|
data_set.bool_data.append((rows - i) % 2)
|
||||||
|
data_set.binary_data.append(f'binary{(rows - i)}')
|
||||||
|
data_set.nchar_data.append(f'nchar_测试_{(rows - i)}')
|
||||||
|
|
||||||
|
return data_set
|
||||||
|
|
||||||
|
def __insert_data(self):
|
||||||
|
tdLog.printNoPrefix("==========step: start inser data into tables now.....")
|
||||||
|
data = self.__data_set(rows=self.rows)
|
||||||
|
|
||||||
|
# now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
|
||||||
|
null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null'''
|
||||||
|
zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0"
|
||||||
|
|
||||||
|
for i in range(self.rows):
|
||||||
|
row_data = f'''
|
||||||
|
{data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]},
|
||||||
|
{data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]},
|
||||||
|
{data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]}
|
||||||
|
'''
|
||||||
|
neg_row_data = f'''
|
||||||
|
{-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]},
|
||||||
|
{data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]},
|
||||||
|
{1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]}
|
||||||
|
'''
|
||||||
|
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into {NTBNAME} values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )")
|
||||||
|
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )")
|
||||||
|
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )")
|
||||||
|
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into {NTBNAME} values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into {NTBNAME} values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )")
|
||||||
|
tdSql.execute(
|
||||||
|
f"insert into {NTBNAME} values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.rows = 10
|
||||||
|
|
||||||
|
tdLog.printNoPrefix("==========step0:all check")
|
||||||
|
|
||||||
|
tdLog.printNoPrefix("==========step1:create table in normal database")
|
||||||
|
tdSql.prepare()
|
||||||
|
self.__create_tb()
|
||||||
|
self.__insert_data()
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
|
# drop databases, create same name db、stb and sma index
|
||||||
|
tdSql.prepare()
|
||||||
|
self.__create_tb()
|
||||||
|
self.__insert_data()
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
|
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
||||||
|
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
|
||||||
|
tdSql.execute("use db3")
|
||||||
|
tdSql.query(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL})")
|
||||||
|
|
||||||
|
tdSql.execute("drop database if exists db1 ")
|
||||||
|
tdSql.execute("drop database if exists db2 ")
|
||||||
|
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
tdDnodes.start(1)
|
||||||
|
|
||||||
|
tdLog.printNoPrefix("==========step4:after wal, all check again ")
|
||||||
|
tdSql.prepare()
|
||||||
|
self.__create_tb()
|
||||||
|
self.__insert_data()
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
|
# drop databases, create same name db、stb and sma index
|
||||||
|
tdSql.prepare()
|
||||||
|
self.__create_tb()
|
||||||
|
self.__insert_data()
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success(f"{__file__} successfully executed")
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
|
@ -1,6 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from typing import List
|
from typing import List
|
||||||
from util.log import *
|
from util.log import *
|
||||||
from util.sql import *
|
from util.sql import *
|
||||||
|
@ -36,36 +36,20 @@ NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DataSet:
|
class DataSet:
|
||||||
ts_data : List[int] = None
|
ts_data : List[int] = field(default_factory=list)
|
||||||
int_data : List[int] = None
|
int_data : List[int] = field(default_factory=list)
|
||||||
bint_data : List[int] = None
|
bint_data : List[int] = field(default_factory=list)
|
||||||
sint_data : List[int] = None
|
sint_data : List[int] = field(default_factory=list)
|
||||||
tint_data : List[int] = None
|
tint_data : List[int] = field(default_factory=list)
|
||||||
int_un_data : List[int] = None
|
int_un_data : List[int] = field(default_factory=list)
|
||||||
bint_un_data : List[int] = None
|
bint_un_data: List[int] = field(default_factory=list)
|
||||||
sint_un_data : List[int] = None
|
sint_un_data: List[int] = field(default_factory=list)
|
||||||
tint_un_data : List[int] = None
|
tint_un_data: List[int] = field(default_factory=list)
|
||||||
float_data : List[float] = None
|
float_data : List[float] = field(default_factory=list)
|
||||||
double_data : List[float] = None
|
double_data : List[float] = field(default_factory=list)
|
||||||
bool_data : List[int] = None
|
bool_data : List[int] = field(default_factory=list)
|
||||||
binary_data : List[str] = None
|
binary_data : List[str] = field(default_factory=list)
|
||||||
nchar_data : List[str] = None
|
nchar_data : List[str] = field(default_factory=list)
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
self.ts_data = []
|
|
||||||
self.int_data = []
|
|
||||||
self.bint_data = []
|
|
||||||
self.sint_data = []
|
|
||||||
self.tint_data = []
|
|
||||||
self.int_un_data = []
|
|
||||||
self.bint_un_data = []
|
|
||||||
self.sint_un_data = []
|
|
||||||
self.tint_un_data = []
|
|
||||||
self.float_data = []
|
|
||||||
self.double_data = []
|
|
||||||
self.bool_data = []
|
|
||||||
self.binary_data = []
|
|
||||||
self.nchar_data = []
|
|
||||||
|
|
||||||
|
|
||||||
class TDTestCase:
|
class TDTestCase:
|
||||||
|
@ -107,15 +91,15 @@ class TDTestCase:
|
||||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min",
|
||||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay -1s",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay -1s",
|
||||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m",
|
||||||
# f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ",
|
||||||
# f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_delay 1m ",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_delay 1m ",
|
||||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s",
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s",
|
||||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) rollup(avg) max_delay 1m",
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) rollup(avg) max_delay 1m",
|
||||||
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s max_delay 1s",
|
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) rollup(avg) watermark 1s max_delay 1s",
|
||||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) " ,
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {NCHAR_COL} nchar(16)) tags (tag1 int) " ,
|
||||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " ,
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " ,
|
||||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " ,
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " ,
|
||||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " ,
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " ,
|
||||||
|
|
||||||
# watermark, max_delay: [0, 900000], [ms, s, m, ?]
|
# watermark, max_delay: [0, 900000], [ms, s, m, ?]
|
||||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1u",
|
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1u",
|
||||||
|
@ -136,8 +120,9 @@ class TDTestCase:
|
||||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 5s max_delay 1m",
|
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 5s max_delay 1m",
|
||||||
f"create stable stb3 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(max) watermark 5s max_delay 1m",
|
f"create stable stb3 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(max) watermark 5s max_delay 1m",
|
||||||
f"create stable stb4 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(sum) watermark 5s max_delay 1m",
|
f"create stable stb4 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(sum) watermark 5s max_delay 1m",
|
||||||
# f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s max_delay 1m",
|
f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s max_delay 1m",
|
||||||
# f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m",
|
f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m",
|
||||||
|
f"create stable stb7 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL})",
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_create_stb(self):
|
def test_create_stb(self):
|
||||||
|
@ -150,7 +135,7 @@ class TDTestCase:
|
||||||
# assert "rollup" in tdSql.description
|
# assert "rollup" in tdSql.description
|
||||||
tdSql.checkRows(len(self.create_stable_sql_current))
|
tdSql.checkRows(len(self.create_stable_sql_current))
|
||||||
|
|
||||||
# tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup database
|
tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup stable
|
||||||
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 5s max_delay 1m")
|
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 5s max_delay 1m")
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,20 +195,6 @@ class TDTestCase:
|
||||||
data_set.binary_data.append(f'binary{(rows - i)}')
|
data_set.binary_data.append(f'binary{(rows - i)}')
|
||||||
data_set.nchar_data.append(f'nchar_测试_{(rows - i)}')
|
data_set.nchar_data.append(f'nchar_测试_{(rows - i)}')
|
||||||
|
|
||||||
# neg_data_set.ts_data.append(-1 * i)
|
|
||||||
# neg_data_set.int_data.append(-i)
|
|
||||||
# neg_data_set.bint_data.append(-11111 * i)
|
|
||||||
# neg_data_set.sint_data.append(-111 * i % 32767)
|
|
||||||
# neg_data_set.tint_data.append(-11 * i % 127)
|
|
||||||
# neg_data_set.int_un_data.append(-i)
|
|
||||||
# neg_data_set.bint_un_data.append(-11111 * i)
|
|
||||||
# neg_data_set.sint_un_data.append(-111 * i % 32767)
|
|
||||||
# neg_data_set.tint_un_data.append(-11 * i % 127)
|
|
||||||
# neg_data_set.float_data.append(-1.11 * i)
|
|
||||||
# neg_data_set.double_data.append(-1100.0011 * i)
|
|
||||||
# neg_data_set.binary_data.append(f'binary{i}')
|
|
||||||
# neg_data_set.nchar_data.append(f'nchar_测试_{i}')
|
|
||||||
|
|
||||||
return data_set
|
return data_set
|
||||||
|
|
||||||
def __insert_data(self):
|
def __insert_data(self):
|
||||||
|
@ -279,9 +250,14 @@ class TDTestCase:
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
||||||
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
|
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
|
||||||
|
|
||||||
|
tdSql.execute("drop database if exists db1 ")
|
||||||
|
tdSql.execute("drop database if exists db2 ")
|
||||||
|
|
||||||
tdSql.execute("use db3")
|
tdSql.execute("use db3")
|
||||||
self.__create_tb()
|
# self.__create_tb()
|
||||||
self.__insert_data()
|
# self.__insert_data()
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
tdSql.execute("drop database if exists db1 ")
|
tdSql.execute("drop database if exists db1 ")
|
||||||
tdSql.execute("drop database if exists db2 ")
|
tdSql.execute("drop database if exists db2 ")
|
||||||
|
|
|
@ -325,7 +325,7 @@ class TDTestCase:
|
||||||
def __sma_create_check(self, sma:SMAschema):
|
def __sma_create_check(self, sma:SMAschema):
|
||||||
if self.updatecfgDict["querySmaOptimize"] == 0:
|
if self.updatecfgDict["querySmaOptimize"] == 0:
|
||||||
return False
|
return False
|
||||||
# # TODO: if database is a rollup-db, can not create sma index
|
# TODO: if database is a rollup-db, can not create sma index
|
||||||
# tdSql.query("select database()")
|
# tdSql.query("select database()")
|
||||||
# if sma.rollup_db :
|
# if sma.rollup_db :
|
||||||
# return False
|
# return False
|
||||||
|
@ -493,8 +493,8 @@ class TDTestCase:
|
||||||
err_sqls , cur_sqls = self.__drop_sma_sql
|
err_sqls , cur_sqls = self.__drop_sma_sql
|
||||||
for err_sql in err_sqls:
|
for err_sql in err_sqls:
|
||||||
self.sma_drop_check(err_sql)
|
self.sma_drop_check(err_sql)
|
||||||
# for cur_sql in cur_sqls:
|
for cur_sql in cur_sqls:
|
||||||
# self.sma_drop_check(cur_sql)
|
self.sma_drop_check(cur_sql)
|
||||||
|
|
||||||
def all_test(self):
|
def all_test(self):
|
||||||
self.test_create_sma()
|
self.test_create_sma()
|
||||||
|
@ -605,24 +605,23 @@ class TDTestCase:
|
||||||
tdLog.printNoPrefix("==========step1:create table in normal database")
|
tdLog.printNoPrefix("==========step1:create table in normal database")
|
||||||
tdSql.prepare()
|
tdSql.prepare()
|
||||||
self.__create_tb()
|
self.__create_tb()
|
||||||
# self.__insert_data()
|
self.__insert_data()
|
||||||
self.all_test()
|
self.all_test()
|
||||||
|
|
||||||
# drop databases, create same name db、stb and sma index
|
# drop databases, create same name db、stb and sma index
|
||||||
# tdSql.prepare()
|
tdSql.prepare()
|
||||||
# self.__create_tb()
|
self.__create_tb()
|
||||||
# self.__insert_data()
|
self.__insert_data()
|
||||||
# self.all_test()
|
self.all_test()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
||||||
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
|
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
|
||||||
tdSql.execute("use db3")
|
tdSql.execute("use db3")
|
||||||
self.__create_tb()
|
# self.__create_tb()
|
||||||
self.__insert_data()
|
tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ")
|
||||||
|
self.all_test()
|
||||||
|
|
||||||
|
# self.__insert_data()
|
||||||
|
|
||||||
tdSql.execute("drop database if exists db1 ")
|
tdSql.execute("drop database if exists db1 ")
|
||||||
tdSql.execute("drop database if exists db2 ")
|
tdSql.execute("drop database if exists db2 ")
|
||||||
|
|
|
@ -139,7 +139,7 @@ class TDTestCase:
|
||||||
)
|
)
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
|
f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
|
||||||
|
|
||||||
for i in range(9):
|
for i in range(9):
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TDTestCase:
|
||||||
def init(self, conn, logSql):
|
def init(self, conn, logSql):
|
||||||
tdLog.debug(f"start to excute {__file__}")
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
tdSql.init(conn.cursor(), True)
|
tdSql.init(conn.cursor(), True)
|
||||||
|
|
||||||
def prepare_datas(self):
|
def prepare_datas(self):
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
'''create table stb1
|
'''create table stb1
|
||||||
|
@ -22,7 +22,7 @@ class TDTestCase:
|
||||||
tags (t1 int)
|
tags (t1 int)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
'''
|
'''
|
||||||
create table t1
|
create table t1
|
||||||
|
@ -64,7 +64,7 @@ class TDTestCase:
|
||||||
( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_avg(self ,origin_query , check_query):
|
def check_avg(self ,origin_query , check_query):
|
||||||
avg_result = tdSql.getResult(origin_query)
|
avg_result = tdSql.getResult(origin_query)
|
||||||
origin_result = tdSql.getResult(check_query)
|
origin_result = tdSql.getResult(check_query)
|
||||||
|
@ -73,13 +73,13 @@ class TDTestCase:
|
||||||
for row_index , row in enumerate(avg_result):
|
for row_index , row in enumerate(avg_result):
|
||||||
for col_index , elem in enumerate(row):
|
for col_index , elem in enumerate(row):
|
||||||
if avg_result[row_index][col_index] != origin_result[row_index][col_index]:
|
if avg_result[row_index][col_index] != origin_result[row_index][col_index]:
|
||||||
check_status = False
|
check_status = False
|
||||||
if not check_status:
|
if not check_status:
|
||||||
tdLog.notice("avg function value has not as expected , sql is \"%s\" "%origin_query )
|
tdLog.notice("avg function value has not as expected , sql is \"%s\" "%origin_query )
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query )
|
tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query )
|
||||||
|
|
||||||
def test_errors(self):
|
def test_errors(self):
|
||||||
error_sql_lists = [
|
error_sql_lists = [
|
||||||
"select avg from t1",
|
"select avg from t1",
|
||||||
|
@ -113,42 +113,42 @@ class TDTestCase:
|
||||||
]
|
]
|
||||||
for error_sql in error_sql_lists:
|
for error_sql in error_sql_lists:
|
||||||
tdSql.error(error_sql)
|
tdSql.error(error_sql)
|
||||||
|
|
||||||
def support_types(self):
|
def support_types(self):
|
||||||
type_error_sql_lists = [
|
type_error_sql_lists = [
|
||||||
"select avg(ts) from t1" ,
|
"select avg(ts) from t1" ,
|
||||||
"select avg(c7) from t1",
|
"select avg(c7) from t1",
|
||||||
"select avg(c8) from t1",
|
"select avg(c8) from t1",
|
||||||
"select avg(c9) from t1",
|
"select avg(c9) from t1",
|
||||||
"select avg(ts) from ct1" ,
|
"select avg(ts) from ct1" ,
|
||||||
"select avg(c7) from ct1",
|
"select avg(c7) from ct1",
|
||||||
"select avg(c8) from ct1",
|
"select avg(c8) from ct1",
|
||||||
"select avg(c9) from ct1",
|
"select avg(c9) from ct1",
|
||||||
"select avg(ts) from ct3" ,
|
"select avg(ts) from ct3" ,
|
||||||
"select avg(c7) from ct3",
|
"select avg(c7) from ct3",
|
||||||
"select avg(c8) from ct3",
|
"select avg(c8) from ct3",
|
||||||
"select avg(c9) from ct3",
|
"select avg(c9) from ct3",
|
||||||
"select avg(ts) from ct4" ,
|
"select avg(ts) from ct4" ,
|
||||||
"select avg(c7) from ct4",
|
"select avg(c7) from ct4",
|
||||||
"select avg(c8) from ct4",
|
"select avg(c8) from ct4",
|
||||||
"select avg(c9) from ct4",
|
"select avg(c9) from ct4",
|
||||||
"select avg(ts) from stb1" ,
|
"select avg(ts) from stb1" ,
|
||||||
"select avg(c7) from stb1",
|
"select avg(c7) from stb1",
|
||||||
"select avg(c8) from stb1",
|
"select avg(c8) from stb1",
|
||||||
"select avg(c9) from stb1" ,
|
"select avg(c9) from stb1" ,
|
||||||
|
|
||||||
"select avg(ts) from stbbb1" ,
|
"select avg(ts) from stbbb1" ,
|
||||||
"select avg(c7) from stbbb1",
|
"select avg(c7) from stbbb1",
|
||||||
|
|
||||||
"select avg(ts) from tbname",
|
"select avg(ts) from tbname",
|
||||||
"select avg(c9) from tbname"
|
"select avg(c9) from tbname"
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for type_sql in type_error_sql_lists:
|
for type_sql in type_error_sql_lists:
|
||||||
tdSql.error(type_sql)
|
tdSql.error(type_sql)
|
||||||
|
|
||||||
|
|
||||||
type_sql_lists = [
|
type_sql_lists = [
|
||||||
"select avg(c1) from t1",
|
"select avg(c1) from t1",
|
||||||
"select avg(c2) from t1",
|
"select avg(c2) from t1",
|
||||||
|
@ -178,16 +178,16 @@ class TDTestCase:
|
||||||
"select avg(c5) from stb1",
|
"select avg(c5) from stb1",
|
||||||
"select avg(c6) from stb1",
|
"select avg(c6) from stb1",
|
||||||
|
|
||||||
"select avg(c6) as alisb from stb1",
|
"select avg(c6) as alisb from stb1",
|
||||||
"select avg(c6) alisb from stb1",
|
"select avg(c6) alisb from stb1",
|
||||||
]
|
]
|
||||||
|
|
||||||
for type_sql in type_sql_lists:
|
for type_sql in type_sql_lists:
|
||||||
tdSql.query(type_sql)
|
tdSql.query(type_sql)
|
||||||
|
|
||||||
def basic_avg_function(self):
|
def basic_avg_function(self):
|
||||||
|
|
||||||
# basic query
|
# basic query
|
||||||
tdSql.query("select c1 from ct3")
|
tdSql.query("select c1 from ct3")
|
||||||
tdSql.checkRows(0)
|
tdSql.checkRows(0)
|
||||||
tdSql.query("select c1 from t1")
|
tdSql.query("select c1 from t1")
|
||||||
|
@ -207,18 +207,18 @@ class TDTestCase:
|
||||||
tdSql.query("select avg(c5) from ct3")
|
tdSql.query("select avg(c5) from ct3")
|
||||||
tdSql.checkRows(0)
|
tdSql.checkRows(0)
|
||||||
tdSql.query("select avg(c6) from ct3")
|
tdSql.query("select avg(c6) from ct3")
|
||||||
|
|
||||||
# used for regular table
|
# used for regular table
|
||||||
tdSql.query("select avg(c1) from t1")
|
tdSql.query("select avg(c1) from t1")
|
||||||
tdSql.checkData(0, 0, 5.000000000)
|
tdSql.checkData(0, 0, 5.000000000)
|
||||||
|
|
||||||
|
|
||||||
tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1")
|
tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1")
|
||||||
tdSql.checkData(1, 5, 1.11000)
|
tdSql.checkData(1, 5, 1.11000)
|
||||||
tdSql.checkData(3, 4, 33)
|
tdSql.checkData(3, 4, 33)
|
||||||
tdSql.checkData(5, 5, None)
|
tdSql.checkData(5, 5, None)
|
||||||
self.check_avg(" select avg(c1) , avg(c2) , avg(c3) from t1 " , " select sum(c1)/count(c1) , sum(c2)/count(c2) , sum(c3)/count(c3) from t1 ")
|
self.check_avg(" select avg(c1) , avg(c2) , avg(c3) from t1 " , " select sum(c1)/count(c1) , sum(c2)/count(c2) , sum(c3)/count(c3) from t1 ")
|
||||||
|
|
||||||
# used for sub table
|
# used for sub table
|
||||||
tdSql.query("select avg(c1) from ct1")
|
tdSql.query("select avg(c1) from ct1")
|
||||||
tdSql.checkData(0, 0, 4.846153846)
|
tdSql.checkData(0, 0, 4.846153846)
|
||||||
|
@ -229,8 +229,8 @@ class TDTestCase:
|
||||||
self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from t1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from t1 ")
|
self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from t1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from t1 ")
|
||||||
self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from stb1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from stb1 ")
|
self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from stb1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from stb1 ")
|
||||||
|
|
||||||
# used for stable table
|
# used for stable table
|
||||||
|
|
||||||
tdSql.query("select avg(c1) from stb1")
|
tdSql.query("select avg(c1) from stb1")
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
|
|
||||||
|
@ -241,10 +241,10 @@ class TDTestCase:
|
||||||
tdSql.error("select avg(c1) from tbname")
|
tdSql.error("select avg(c1) from tbname")
|
||||||
tdSql.error("select avg(c1) from ct5")
|
tdSql.error("select avg(c1) from ct5")
|
||||||
|
|
||||||
# mix with common col
|
# mix with common col
|
||||||
tdSql.error("select c1, avg(c1) from ct1")
|
tdSql.error("select c1, avg(c1) from ct1")
|
||||||
tdSql.error("select c1, avg(c1) from ct4")
|
tdSql.error("select c1, avg(c1) from ct4")
|
||||||
|
|
||||||
|
|
||||||
# mix with common functions
|
# mix with common functions
|
||||||
tdSql.error("select c1, avg(c1),c5, floor(c5) from ct4 ")
|
tdSql.error("select c1, avg(c1),c5, floor(c5) from ct4 ")
|
||||||
|
@ -278,11 +278,11 @@ class TDTestCase:
|
||||||
tdSql.query("select count(*) from stb1 ")
|
tdSql.query("select count(*) from stb1 ")
|
||||||
tdSql.checkData(0,0,25)
|
tdSql.checkData(0,0,25)
|
||||||
|
|
||||||
# bug fix for compute
|
# bug fix for compute
|
||||||
tdSql.error("select c1, avg(c1) -0 ,ceil(c1)-0 from ct4 ")
|
tdSql.error("select c1, avg(c1) -0 ,ceil(c1)-0 from ct4 ")
|
||||||
tdSql.error(" select c1, avg(c1) -0 ,avg(ceil(c1-0.1))-0.1 from ct4")
|
tdSql.error(" select c1, avg(c1) -0 ,avg(ceil(c1-0.1))-0.1 from ct4")
|
||||||
|
|
||||||
# mix with nest query
|
# mix with nest query
|
||||||
self.check_avg("select avg(col) from (select abs(c1) col from stb1)" , "select avg(abs(c1)) from stb1")
|
self.check_avg("select avg(col) from (select abs(c1) col from stb1)" , "select avg(abs(c1)) from stb1")
|
||||||
self.check_avg("select avg(col) from (select ceil(abs(c1)) col from stb1)" , "select avg(abs(c1)) from stb1")
|
self.check_avg("select avg(col) from (select ceil(abs(c1)) col from stb1)" , "select avg(abs(c1)) from stb1")
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ class TDTestCase:
|
||||||
tdSql.query(" select avg(c1) from stb1 where c1 is null ")
|
tdSql.query(" select avg(c1) from stb1 where c1 is null ")
|
||||||
tdSql.checkRows(0)
|
tdSql.checkRows(0)
|
||||||
|
|
||||||
|
|
||||||
def avg_func_filter(self):
|
def avg_func_filter(self):
|
||||||
tdSql.execute("use db")
|
tdSql.execute("use db")
|
||||||
tdSql.query(" select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from ct4 where c1>5 ")
|
tdSql.query(" select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from ct4 where c1>5 ")
|
||||||
|
@ -324,7 +324,7 @@ class TDTestCase:
|
||||||
|
|
||||||
def avg_Arithmetic(self):
|
def avg_Arithmetic(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def check_boundary_values(self):
|
def check_boundary_values(self):
|
||||||
|
|
||||||
tdSql.execute("drop database if exists bound_test")
|
tdSql.execute("drop database if exists bound_test")
|
||||||
|
@ -344,11 +344,11 @@ class TDTestCase:
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||||
)
|
)
|
||||||
|
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
f"insert into sub1_bound values ( now(), 2147483645, 9223372036854775805, 32765, 125, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )"
|
f"insert into sub1_bound values ( now(), 2147483645, 9223372036854775805, 32765, 125, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||||
)
|
)
|
||||||
|
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
f"insert into sub1_bound values ( now(), 2147483644, 9223372036854775804, 32764, 124, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )"
|
f"insert into sub1_bound values ( now(), 2147483644, 9223372036854775804, 32764, 124, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||||
)
|
)
|
||||||
|
@ -359,14 +359,14 @@ class TDTestCase:
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
tdSql.error(
|
tdSql.error(
|
||||||
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||||
)
|
)
|
||||||
self.check_avg("select avg(c1), avg(c2), avg(c3) , avg(c4), avg(c5) ,avg(c6) from sub1_bound " , " select sum(c1)/count(c1), sum(c2)/count(c2) ,sum(c3)/count(c3), sum(c4)/count(c4), sum(c5)/count(c5) ,sum(c6)/count(c6) from sub1_bound ")
|
self.check_avg("select avg(c1), avg(c2), avg(c3) , avg(c4), avg(c5) ,avg(c6) from sub1_bound " , " select sum(c1)/count(c1), sum(c2)/count(c2) ,sum(c3)/count(c3), sum(c4)/count(c4), sum(c5)/count(c5) ,sum(c6)/count(c6) from sub1_bound ")
|
||||||
|
|
||||||
|
|
||||||
# check basic elem for table per row
|
# check basic elem for table per row
|
||||||
tdSql.query("select avg(c1) ,avg(c2) , avg(c3) , avg(c4), avg(c5), avg(c6) from sub1_bound ")
|
tdSql.query("select avg(c1) ,avg(c2) , avg(c3) , avg(c4), avg(c5), avg(c6) from sub1_bound ")
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
|
@ -376,8 +376,8 @@ class TDTestCase:
|
||||||
tdSql.checkData(0,3,53.571428571)
|
tdSql.checkData(0,3,53.571428571)
|
||||||
tdSql.checkData(0,4,5.828571332045761e+37)
|
tdSql.checkData(0,4,5.828571332045761e+37)
|
||||||
# tdSql.checkData(0,5,None)
|
# tdSql.checkData(0,5,None)
|
||||||
|
|
||||||
|
|
||||||
# check + - * / in functions
|
# check + - * / in functions
|
||||||
tdSql.query(" select avg(c1+1) ,avg(c2) , avg(c3*1) , avg(c4/2), avg(c5)/2, avg(c6) from sub1_bound ")
|
tdSql.query(" select avg(c1+1) ,avg(c2) , avg(c3*1) , avg(c4/2), avg(c5)/2, avg(c6) from sub1_bound ")
|
||||||
tdSql.checkData(0,0,920350134.5714285)
|
tdSql.checkData(0,0,920350134.5714285)
|
||||||
|
@ -386,33 +386,33 @@ class TDTestCase:
|
||||||
tdSql.checkData(0,3,26.785714286)
|
tdSql.checkData(0,3,26.785714286)
|
||||||
tdSql.checkData(0,4,2.9142856660228804e+37)
|
tdSql.checkData(0,4,2.9142856660228804e+37)
|
||||||
# tdSql.checkData(0,5,None)
|
# tdSql.checkData(0,5,None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
|
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
|
||||||
tdSql.prepare()
|
tdSql.prepare()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step1:create table ==============")
|
tdLog.printNoPrefix("==========step1:create table ==============")
|
||||||
|
|
||||||
self.prepare_datas()
|
self.prepare_datas()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step2:test errors ==============")
|
tdLog.printNoPrefix("==========step2:test errors ==============")
|
||||||
|
|
||||||
self.test_errors()
|
self.test_errors()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step3:support types ============")
|
tdLog.printNoPrefix("==========step3:support types ============")
|
||||||
|
|
||||||
self.support_types()
|
self.support_types()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step4: avg basic query ============")
|
tdLog.printNoPrefix("==========step4: avg basic query ============")
|
||||||
|
|
||||||
self.basic_avg_function()
|
self.basic_avg_function()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step5: avg boundary query ============")
|
tdLog.printNoPrefix("==========step5: avg boundary query ============")
|
||||||
|
|
||||||
self.check_boundary_values()
|
self.check_boundary_values()
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step6: avg filter query ============")
|
tdLog.printNoPrefix("==========step6: avg filter query ============")
|
||||||
|
|
||||||
self.avg_func_filter()
|
self.avg_func_filter()
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TDTestCase:
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
|
tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
|
||||||
|
|
||||||
for i in range(9):
|
for i in range(9):
|
||||||
tdSql.execute(
|
tdSql.execute(
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue