Merge branch '3.0' into 3.0test/jcy
This commit is contained in:
commit
ee672bee6c
57
Jenkinsfile2
57
Jenkinsfile2
|
@ -4,11 +4,6 @@ import jenkins.model.CauseOfInterruption
|
||||||
node {
|
node {
|
||||||
}
|
}
|
||||||
|
|
||||||
win_test_stage = 0
|
|
||||||
linux_ready = 0
|
|
||||||
linux_node_ip = ""
|
|
||||||
linux_node_pass = ""
|
|
||||||
|
|
||||||
def abortPreviousBuilds() {
|
def abortPreviousBuilds() {
|
||||||
def currentJobName = env.JOB_NAME
|
def currentJobName = env.JOB_NAME
|
||||||
def currentBuildNumber = env.BUILD_NUMBER.toInteger()
|
def currentBuildNumber = env.BUILD_NUMBER.toInteger()
|
||||||
|
@ -289,7 +284,6 @@ def run_win_ctest() {
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
def run_win_test() {
|
def run_win_test() {
|
||||||
echo "LINUX NODE: ${linux_node_ip} - ${linux_node_pass}"
|
|
||||||
bat '''
|
bat '''
|
||||||
echo "windows test ..."
|
echo "windows test ..."
|
||||||
cd %WIN_CONNECTOR_ROOT%
|
cd %WIN_CONNECTOR_ROOT%
|
||||||
|
@ -298,9 +292,8 @@ def run_win_test() {
|
||||||
ls -l C:\\Windows\\System32\\taos.dll
|
ls -l C:\\Windows\\System32\\taos.dll
|
||||||
time /t
|
time /t
|
||||||
cd %WIN_SYSTEM_TEST_ROOT%
|
cd %WIN_SYSTEM_TEST_ROOT%
|
||||||
echo "node: ''' + linux_node_ip + ''':''' + linux_node_pass + '''"
|
|
||||||
echo "testing ..."
|
echo "testing ..."
|
||||||
test-all.bat "{\\\"host\\\":\\\"''' + linux_node_ip + '''\\\",\\\"port\\\":22,\\\"user\\\":\\\"root\\\",\\\"password\\\":\\\"''' + linux_node_pass + '''\\\",\\\"path\\\":\\\"/var/lib/jenkins/workspace/TDinternal\\\"}"
|
test-all.bat ci
|
||||||
time /t
|
time /t
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
@ -331,17 +324,9 @@ pipeline {
|
||||||
pre_test_win()
|
pre_test_win()
|
||||||
pre_test_build_win()
|
pre_test_build_win()
|
||||||
run_win_ctest()
|
run_win_ctest()
|
||||||
script {
|
|
||||||
while(linux_ready == 0) {
|
|
||||||
sleep(8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run_win_test()
|
run_win_test()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
script {
|
|
||||||
win_test_stage = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('linux test') {
|
stage('linux test') {
|
||||||
|
@ -351,17 +336,6 @@ pipeline {
|
||||||
changeRequest()
|
changeRequest()
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
|
||||||
linux_node_ip = sh (
|
|
||||||
script: 'jq .ip /home/node_info.json | sed "s/\\\"//g"',
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
linux_node_pass = sh (
|
|
||||||
script: 'jq .password /home/node_info.json | sed "s/\\\"//g" |sed "s/\\!/^^^^^^^^\\!/g"',
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
echo "${linux_node_ip}:${linux_node_pass}"
|
|
||||||
}
|
|
||||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||||
timeout(time: 120, unit: 'MINUTES'){
|
timeout(time: 120, unit: 'MINUTES'){
|
||||||
pre_test()
|
pre_test()
|
||||||
|
@ -418,38 +392,9 @@ pipeline {
|
||||||
cd ${WKC}/packaging
|
cd ${WKC}/packaging
|
||||||
./release.sh -v cluster -n 3.0.0.100 -s static
|
./release.sh -v cluster -n 3.0.0.100 -s static
|
||||||
'''
|
'''
|
||||||
sh '''
|
|
||||||
echo "install ..."
|
|
||||||
cd ${WKC}/release
|
|
||||||
tar xzf TDengine-enterprise-server-3.0.0.100-Linux-x64.tar.gz
|
|
||||||
cd TDengine-enterprise-server-3.0.0.100
|
|
||||||
service taosd stop || :
|
|
||||||
rm -rf /var/lib/taos
|
|
||||||
./install.sh -e no
|
|
||||||
'''
|
|
||||||
sh '''
|
|
||||||
echo "checking ..."
|
|
||||||
which taos
|
|
||||||
which taosd
|
|
||||||
rm -rf ${WK}/debug
|
|
||||||
mv ${WKC}/debug ${WK}/
|
|
||||||
'''
|
|
||||||
sh '''
|
|
||||||
echo "install taospy ..."
|
|
||||||
cd ${WKPY}
|
|
||||||
pip3 install .
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
script {
|
|
||||||
linux_ready = 1
|
|
||||||
}
|
|
||||||
script {
|
|
||||||
while(win_test_stage == 0){
|
|
||||||
sleep(12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,8 +99,8 @@ int32_t create_stream() {
|
||||||
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
||||||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||||
pRes = taos_query(pConn,
|
pRes = taos_query(pConn,
|
||||||
"create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from st1 "
|
"create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from st1 partition "
|
||||||
"partition by tbname interval(10s) ");
|
"by tbname interval(10s) ");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -47,11 +47,14 @@ typedef enum EStreamType {
|
||||||
STREAM_GET_ALL,
|
STREAM_GET_ALL,
|
||||||
STREAM_DELETE,
|
STREAM_DELETE,
|
||||||
STREAM_RETRIEVE,
|
STREAM_RETRIEVE,
|
||||||
|
STREAM_PUSH_DATA,
|
||||||
} EStreamType;
|
} EStreamType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
SArray* pGroupList;
|
||||||
SArray* pTableList;
|
SArray* pTableList;
|
||||||
SHashObj* map; // speedup acquire the tableQueryInfo by table uid
|
SHashObj* map; // speedup acquire the tableQueryInfo by table uid
|
||||||
|
bool needSortTableByGroupId;
|
||||||
void* pTagCond;
|
void* pTagCond;
|
||||||
void* pTagIndexCond;
|
void* pTagIndexCond;
|
||||||
uint64_t suid;
|
uint64_t suid;
|
||||||
|
|
|
@ -851,7 +851,6 @@ typedef struct {
|
||||||
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
|
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
|
||||||
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
|
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
|
||||||
|
|
||||||
|
|
||||||
typedef struct SQueryNodeAddr {
|
typedef struct SQueryNodeAddr {
|
||||||
int32_t nodeId; // vgId or qnodeId
|
int32_t nodeId; // vgId or qnodeId
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
|
@ -878,7 +877,6 @@ int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
|
||||||
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
|
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
|
||||||
void tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
|
void tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SArray* pArray; // Array of SUseDbRsp
|
SArray* pArray; // Array of SUseDbRsp
|
||||||
} SUseDbBatchRsp;
|
} SUseDbBatchRsp;
|
||||||
|
@ -1258,7 +1256,6 @@ int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesR
|
||||||
|
|
||||||
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
|
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sql: show tables like '%a_%'
|
* sql: show tables like '%a_%'
|
||||||
* payload is the query condition, e.g., '%a_%'
|
* payload is the query condition, e.g., '%a_%'
|
||||||
|
@ -1287,6 +1284,7 @@ void tFreeSShowRsp(SShowRsp* pRsp);
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
char tb[TSDB_TABLE_NAME_LEN];
|
char tb[TSDB_TABLE_NAME_LEN];
|
||||||
|
char user[TSDB_USER_LEN];
|
||||||
int64_t showId;
|
int64_t showId;
|
||||||
} SRetrieveTableReq;
|
} SRetrieveTableReq;
|
||||||
|
|
||||||
|
@ -1308,6 +1306,8 @@ typedef struct {
|
||||||
int32_t compLen;
|
int32_t compLen;
|
||||||
int32_t numOfRows;
|
int32_t numOfRows;
|
||||||
int32_t numOfCols;
|
int32_t numOfCols;
|
||||||
|
int64_t skey;
|
||||||
|
int64_t ekey;
|
||||||
char data[];
|
char data[];
|
||||||
} SRetrieveTableRsp;
|
} SRetrieveTableRsp;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ typedef struct SReadHandle {
|
||||||
void* vnode;
|
void* vnode;
|
||||||
void* mnd;
|
void* mnd;
|
||||||
SMsgCb* pMsgCb;
|
SMsgCb* pMsgCb;
|
||||||
int8_t initTsdbReader;
|
// int8_t initTsdbReader;
|
||||||
} SReadHandle;
|
} SReadHandle;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -75,6 +75,7 @@ typedef struct SScanLogicNode {
|
||||||
double filesFactor;
|
double filesFactor;
|
||||||
SArray* pSmaIndexes;
|
SArray* pSmaIndexes;
|
||||||
SNodeList* pPartTags;
|
SNodeList* pPartTags;
|
||||||
|
bool partSort;
|
||||||
} SScanLogicNode;
|
} SScanLogicNode;
|
||||||
|
|
||||||
typedef struct SJoinLogicNode {
|
typedef struct SJoinLogicNode {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef _TD_QUERY_H_
|
#ifndef _TD_QUERY_H_
|
||||||
#define _TD_QUERY_H_
|
#define _TD_QUERY_H_
|
||||||
|
|
||||||
|
// clang-foramt off
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -206,13 +207,15 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STabl
|
||||||
char* jobTaskStatusStr(int32_t status);
|
char* jobTaskStatusStr(int32_t status);
|
||||||
|
|
||||||
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
|
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
|
||||||
|
|
||||||
void destroyQueryExecRes(SQueryExecRes* pRes);
|
void destroyQueryExecRes(SQueryExecRes* pRes);
|
||||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||||
char* parseTagDatatoJson(void* p);
|
char* parseTagDatatoJson(void* p);
|
||||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||||
|
|
||||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t));
|
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen,
|
||||||
|
void* (*mallocFp)(int32_t));
|
||||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
|
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
|
||||||
|
|
||||||
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
|
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
|
||||||
|
@ -231,11 +234,13 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
||||||
#define NEED_CLIENT_HANDLE_ERROR(_code) \
|
#define NEED_CLIENT_HANDLE_ERROR(_code) \
|
||||||
(NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
|
(NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
|
||||||
NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
|
NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
|
||||||
#define NEED_CLIENT_RM_TBLMETA_REQ(_type) ((_type) == TDMT_VND_CREATE_TABLE || (_type) == TDMT_VND_CREATE_STB \
|
#define NEED_CLIENT_RM_TBLMETA_REQ(_type) \
|
||||||
|| (_type) == TDMT_VND_DROP_TABLE || (_type) == TDMT_VND_DROP_STB)
|
((_type) == TDMT_VND_CREATE_TABLE || (_type) == TDMT_VND_CREATE_STB || (_type) == TDMT_VND_DROP_TABLE || \
|
||||||
|
(_type) == TDMT_VND_DROP_STB)
|
||||||
|
|
||||||
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
|
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
|
||||||
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR)
|
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || \
|
||||||
|
(_code) == TSDB_CODE_SCH_TIMEOUT_ERROR)
|
||||||
|
|
||||||
#define REQUEST_TOTAL_EXEC_TIMES 2
|
#define REQUEST_TOTAL_EXEC_TIMES 2
|
||||||
|
|
||||||
|
@ -312,3 +317,4 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_QUERY_H_*/
|
#endif /*_TD_QUERY_H_*/
|
||||||
|
// clang-foramt on
|
||||||
|
|
|
@ -58,6 +58,7 @@ enum {
|
||||||
enum {
|
enum {
|
||||||
STREAM_INPUT__DATA_SUBMIT = 1,
|
STREAM_INPUT__DATA_SUBMIT = 1,
|
||||||
STREAM_INPUT__DATA_BLOCK,
|
STREAM_INPUT__DATA_BLOCK,
|
||||||
|
STREAM_INPUT__DATA_RETRIEVE,
|
||||||
STREAM_INPUT__TRIGGER,
|
STREAM_INPUT__TRIGGER,
|
||||||
STREAM_INPUT__CHECKPOINT,
|
STREAM_INPUT__CHECKPOINT,
|
||||||
STREAM_INPUT__DROP,
|
STREAM_INPUT__DROP,
|
||||||
|
|
|
@ -52,6 +52,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifndef TD_USE_WINSOCK
|
#ifndef TD_USE_WINSOCK
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
|
@ -25,11 +25,10 @@ extern "C" {
|
||||||
|
|
||||||
#define TSWAP(a, b) \
|
#define TSWAP(a, b) \
|
||||||
do { \
|
do { \
|
||||||
char *__tmp = taosMemoryMalloc(sizeof(a)); \
|
char *__tmp = alloca(sizeof(a)); \
|
||||||
memcpy(__tmp, &(a), sizeof(a)); \
|
memcpy(__tmp, &(a), sizeof(a)); \
|
||||||
memcpy(&(a), &(b), sizeof(a)); \
|
memcpy(&(a), &(b), sizeof(a)); \
|
||||||
memcpy(&(b), __tmp, sizeof(a)); \
|
memcpy(&(b), __tmp, sizeof(a)); \
|
||||||
taosMemoryFree(__tmp); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
|
@ -157,7 +157,10 @@ int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
|
||||||
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
|
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
|
||||||
void taosWinSocketInit();
|
void taosWinSocketInit();
|
||||||
|
|
||||||
int taosCreateSocketWithTimeOutOpt(uint32_t conn_timeout_sec);
|
/*
|
||||||
|
* set timeout(ms)
|
||||||
|
*/
|
||||||
|
int32_t taosCreateSocketWithTimeout(uint32_t timeout);
|
||||||
|
|
||||||
TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
|
TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
|
||||||
TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
||||||
|
|
|
@ -47,7 +47,9 @@ typedef struct STraceId {
|
||||||
|
|
||||||
#define TRACE_TO_STR(traceId, buf) \
|
#define TRACE_TO_STR(traceId, buf) \
|
||||||
do { \
|
do { \
|
||||||
sprintf(buf, "0x%" PRIx64 ":0x%" PRIx64 "", traceId->rootId, traceId->msgId); \
|
int64_t rootId = (traceId) != NULL ? (traceId)->rootId : 0; \
|
||||||
|
int64_t msgId = (traceId) != NULL ? (traceId)->msgId : 0; \
|
||||||
|
sprintf(buf, "0x%" PRIx64 ":0x%" PRIx64 "", rootId, msgId); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "functionMgt.h"
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
|
#include "functionMgt.h"
|
||||||
|
#include "os.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
|
@ -85,7 +85,8 @@ void closeTransporter(STscObj *pTscObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool clientRpcRfp(int32_t code) {
|
static bool clientRpcRfp(int32_t code) {
|
||||||
if (code == TSDB_CODE_RPC_REDIRECT) {
|
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
|
||||||
|
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_APP_NOT_READY) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -137,7 +138,8 @@ void destroyTscObj(void *pObj) {
|
||||||
// TODO
|
// TODO
|
||||||
// closeTransporter(pTscObj);
|
// closeTransporter(pTscObj);
|
||||||
}
|
}
|
||||||
tscDebug("connObj 0x%" PRIx64 " destroyed, totalConn:%" PRId64, *(int64_t*)pTscObj->id, pTscObj->pAppInfo->numOfConns);
|
tscDebug("connObj 0x%" PRIx64 " destroyed, totalConn:%" PRId64, *(int64_t *)pTscObj->id,
|
||||||
|
pTscObj->pAppInfo->numOfConns);
|
||||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||||
taosMemoryFreeClear(pTscObj);
|
taosMemoryFreeClear(pTscObj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -963,6 +963,10 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) {
|
||||||
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
||||||
} else if (strcasecmp("transPullupInterval", name) == 0) {
|
} else if (strcasecmp("transPullupInterval", name) == 0) {
|
||||||
tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32;
|
tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32;
|
||||||
|
} else if (strcasecmp("ttlUnit", name) == 0) {
|
||||||
|
tsTtlUnit = cfgGetItem(pCfg, "ttlUnit")->i32;
|
||||||
|
} else if (strcasecmp("ttlPushInterval", name) == 0) {
|
||||||
|
tsTtlPushInterval = cfgGetItem(pCfg, "ttlPushInterval")->i32;
|
||||||
} else if (strcasecmp("tmrDebugFlag", name) == 0) {
|
} else if (strcasecmp("tmrDebugFlag", name) == 0) {
|
||||||
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
||||||
} else if (strcasecmp("tsdbDebugFlag", name) == 0) {
|
} else if (strcasecmp("tsdbDebugFlag", name) == 0) {
|
||||||
|
|
|
@ -3017,6 +3017,7 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq
|
||||||
if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
|
if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1;
|
||||||
|
if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
int32_t tlen = encoder.pos;
|
int32_t tlen = encoder.pos;
|
||||||
|
@ -3032,6 +3033,8 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR
|
||||||
if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
|
if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1;
|
||||||
|
if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
|
||||||
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -248,7 +248,14 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rpcRfp(int32_t code) { return code == TSDB_CODE_RPC_REDIRECT; }
|
static bool rpcRfp(int32_t code) {
|
||||||
|
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
|
||||||
|
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_APP_NOT_READY) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dmInitClient(SDnode *pDnode) {
|
int32_t dmInitClient(SDnode *pDnode) {
|
||||||
SDnodeTrans *pTrans = &pDnode->trans;
|
SDnodeTrans *pTrans = &pDnode->trans;
|
||||||
|
|
|
@ -133,10 +133,10 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||||
ret = taosLockFile(pFile);
|
ret = taosLockFile(pFile);
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosMsleep(100);
|
taosMsleep(1000);
|
||||||
retryTimes++;
|
retryTimes++;
|
||||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes);
|
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes);
|
||||||
} while (retryTimes < 120);
|
} while (retryTimes < 12);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MND_AUTH_H_
|
#ifndef _TD_MND_PRIVILEGE_H
|
||||||
#define _TD_MND_AUTH_H_
|
#define _TD_MND_PRIVILEGE_H
|
||||||
|
|
||||||
#include "mndInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
@ -23,13 +23,18 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MND_OPER_CREATE_USER = 1,
|
MND_OPER_CONNECT = 1,
|
||||||
|
MND_OPER_CREATE_ACCT,
|
||||||
|
MND_OPER_DROP_ACCT,
|
||||||
|
MND_OPER_ALTER_ACCT,
|
||||||
|
MND_OPER_CREATE_USER,
|
||||||
MND_OPER_DROP_USER,
|
MND_OPER_DROP_USER,
|
||||||
MND_OPER_ALTER_USER,
|
MND_OPER_ALTER_USER,
|
||||||
MND_OPER_CREATE_BNODE,
|
MND_OPER_CREATE_BNODE,
|
||||||
MND_OPER_DROP_BNODE,
|
MND_OPER_DROP_BNODE,
|
||||||
MND_OPER_CREATE_DNODE,
|
MND_OPER_CREATE_DNODE,
|
||||||
MND_OPER_DROP_DNODE,
|
MND_OPER_DROP_DNODE,
|
||||||
|
MND_OPER_CONFIG_DNODE,
|
||||||
MND_OPER_CREATE_MNODE,
|
MND_OPER_CREATE_MNODE,
|
||||||
MND_OPER_DROP_MNODE,
|
MND_OPER_DROP_MNODE,
|
||||||
MND_OPER_CREATE_QNODE,
|
MND_OPER_CREATE_QNODE,
|
||||||
|
@ -37,11 +42,14 @@ typedef enum {
|
||||||
MND_OPER_CREATE_SNODE,
|
MND_OPER_CREATE_SNODE,
|
||||||
MND_OPER_DROP_SNODE,
|
MND_OPER_DROP_SNODE,
|
||||||
MND_OPER_REDISTRIBUTE_VGROUP,
|
MND_OPER_REDISTRIBUTE_VGROUP,
|
||||||
|
MND_OPER_MERGE_VGROUP,
|
||||||
MND_OPER_SPLIT_VGROUP,
|
MND_OPER_SPLIT_VGROUP,
|
||||||
MND_OPER_BALANCE_VGROUP,
|
MND_OPER_BALANCE_VGROUP,
|
||||||
MND_OPER_CREATE_FUNC,
|
MND_OPER_CREATE_FUNC,
|
||||||
MND_OPER_DROP_FUNC,
|
MND_OPER_DROP_FUNC,
|
||||||
MND_OPER_KILL_TRANS,
|
MND_OPER_KILL_TRANS,
|
||||||
|
MND_OPER_KILL_CONN,
|
||||||
|
MND_OPER_KILL_QUERY,
|
||||||
MND_OPER_CREATE_DB,
|
MND_OPER_CREATE_DB,
|
||||||
MND_OPER_ALTER_DB,
|
MND_OPER_ALTER_DB,
|
||||||
MND_OPER_DROP_DB,
|
MND_OPER_DROP_DB,
|
||||||
|
@ -51,16 +59,17 @@ typedef enum {
|
||||||
MND_OPER_READ_DB,
|
MND_OPER_READ_DB,
|
||||||
} EOperType;
|
} EOperType;
|
||||||
|
|
||||||
int32_t mndInitAuth(SMnode *pMnode);
|
int32_t mndInitPrivilege(SMnode *pMnode);
|
||||||
void mndCleanupAuth(SMnode *pMnode);
|
void mndCleanupPrivilege(SMnode *pMnode);
|
||||||
|
|
||||||
int32_t mndCheckOperAuth(SMnode *pMnode, const char *user, EOperType operType);
|
int32_t mndCheckOperPrivilege(SMnode *pMnode, const char *user, EOperType operType);
|
||||||
int32_t mndCheckDbAuth(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb);
|
int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb);
|
||||||
int32_t mndCheckShowAuth(SMnode *pMnode, const char *user, int32_t showType);
|
int32_t mndCheckDbPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *name);
|
||||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter);
|
int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, int32_t showType);
|
||||||
|
int32_t mndCheckAlterUserPrivilege(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MND_AUTH_H_*/
|
#endif /*_TD_MND_PRIVILEGE_H*/
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndAcct.h"
|
#include "mndAcct.h"
|
||||||
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
|
@ -212,18 +213,30 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
|
||||||
|
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
|
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
|
||||||
|
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
|
||||||
|
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndBnode.h"
|
#include "mndBnode.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -277,6 +277,9 @@ static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("bnode:%d, start to create", createReq.dnodeId);
|
mDebug("bnode:%d, start to create", createReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_BNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pObj = mndAcquireBnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireBnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
|
@ -292,10 +295,6 @@ static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_BNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateBnode(pMnode, pReq, pDnode, &createReq);
|
code = mndCreateBnode(pMnode, pReq, pDnode, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -383,6 +382,9 @@ static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("bnode:%d, start to drop", dropReq.dnodeId);
|
mDebug("bnode:%d, start to drop", dropReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_BNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -394,10 +396,6 @@ static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_BNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropBnode(pMnode, pReq, pObj);
|
code = mndDropBnode(pMnode, pReq, pObj);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndConsumer.h"
|
#include "mndConsumer.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
@ -431,6 +431,10 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
||||||
goto SUBSCRIBE_OVER;
|
goto SUBSCRIBE_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mndCheckDbPrivilegeByName(pMnode, pMsg->info.conn.user, MND_OPER_READ_DB, pTopic->db) != 0) {
|
||||||
|
goto SUBSCRIBE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// ref topic to prevent drop
|
// ref topic to prevent drop
|
||||||
// TODO make topic complete
|
// TODO make topic complete
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndOffset.h"
|
#include "mndOffset.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
@ -506,6 +506,9 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups);
|
mDebug("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups);
|
||||||
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DB, NULL) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pDb = mndAcquireDb(pMnode, createReq.db);
|
pDb = mndAcquireDb(pMnode, createReq.db);
|
||||||
if (pDb != NULL) {
|
if (pDb != NULL) {
|
||||||
|
@ -526,10 +529,6 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DB, NULL) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -700,7 +699,7 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_ALTER_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_ALTER_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,7 +979,7 @@ static int32_t mndProcessDropDbReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,7 +1126,7 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr());
|
mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr());
|
||||||
} else {
|
} else {
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_USE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_USE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,7 +1251,7 @@ static int32_t mndProcessCompactDbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_COMPACT_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_COMPACT_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndQnode.h"
|
#include "mndQnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
@ -609,7 +609,6 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
@ -622,6 +621,9 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("dnode:%s:%d, start to create", createReq.fqdn, createReq.port);
|
mInfo("dnode:%s:%d, start to create", createReq.fqdn, createReq.port);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
|
if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
|
terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
|
||||||
|
@ -635,10 +637,6 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateDnode(pMnode, pReq, &createReq);
|
code = mndCreateDnode(pMnode, pReq, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -717,6 +715,9 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("dnode:%d, start to drop, ep:%s:%d", dropReq.dnodeId, dropReq.fqdn, dropReq.port);
|
mInfo("dnode:%d, start to drop, ep:%s:%d", dropReq.dnodeId, dropReq.fqdn, dropReq.port);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
|
pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
|
@ -753,10 +754,6 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes);
|
code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -782,6 +779,10 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
|
mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId);
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr());
|
mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr());
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndFunc.h"
|
#include "mndFunc.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -283,6 +283,9 @@ static int32_t mndProcessCreateFuncReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("func:%s, start to create", createReq.name);
|
mDebug("func:%s, start to create", createReq.name);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_FUNC) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFunc = mndAcquireFunc(pMnode, createReq.name);
|
pFunc = mndAcquireFunc(pMnode, createReq.name);
|
||||||
if (pFunc != NULL) {
|
if (pFunc != NULL) {
|
||||||
|
@ -318,10 +321,6 @@ static int32_t mndProcessCreateFuncReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_FUNC) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateFunc(pMnode, pReq, &createReq);
|
code = mndCreateFunc(pMnode, pReq, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -347,6 +346,9 @@ static int32_t mndProcessDropFuncReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("func:%s, start to drop", dropReq.name);
|
mDebug("func:%s, start to drop", dropReq.name);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_FUNC) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.name[0] == 0) {
|
if (dropReq.name[0] == 0) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
|
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
|
||||||
|
@ -365,10 +367,6 @@ static int32_t mndProcessDropFuncReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_FUNC) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropFunc(pMnode, pReq, pFunc);
|
code = mndDropFunc(pMnode, pReq, pFunc);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndAcct.h"
|
#include "mndAcct.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndBnode.h"
|
#include "mndBnode.h"
|
||||||
#include "mndCluster.h"
|
#include "mndCluster.h"
|
||||||
#include "mndConsumer.h"
|
#include "mndConsumer.h"
|
||||||
|
@ -100,7 +100,7 @@ static void *mndThreadFp(void *param) {
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
if (mndGetStop(pMnode)) break;
|
if (mndGetStop(pMnode)) break;
|
||||||
|
|
||||||
if (lastTime % (tsTransPullupInterval * 10) == 1) {
|
if (lastTime % (tsTtlPushInterval * 10) == 1) {
|
||||||
mndTtlTimer(pMnode);
|
mndTtlTimer(pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
||||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-privilege", mndInitPrivilege, mndCleanupPrivilege) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-stream", mndInitStream, mndCleanupStream) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-stream", mndInitStream, mndCleanupStream) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
|
@ -389,6 +389,9 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("mnode:%d, start to create", createReq.dnodeId);
|
mDebug("mnode:%d, start to create", createReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
|
@ -414,10 +417,6 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateMnode(pMnode, pReq, pDnode, &createReq);
|
code = mndCreateMnode(pMnode, pReq, pDnode, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -595,6 +594,9 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("mnode:%d, start to drop", dropReq.dnodeId);
|
mDebug("mnode:%d, start to drop", dropReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -621,10 +623,6 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropMnode(pMnode, pReq, pObj);
|
code = mndDropMnode(pMnode, pReq, pObj);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndOffset.h"
|
#include "mndOffset.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
@ -36,13 +36,15 @@ static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOffset, SMqOffse
|
||||||
static int32_t mndProcessCommitOffsetReq(SRpcMsg *pReq);
|
static int32_t mndProcessCommitOffsetReq(SRpcMsg *pReq);
|
||||||
|
|
||||||
int32_t mndInitOffset(SMnode *pMnode) {
|
int32_t mndInitOffset(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_OFFSET,
|
SSdbTable table = {
|
||||||
|
.sdbType = SDB_OFFSET,
|
||||||
.keyType = SDB_KEY_BINARY,
|
.keyType = SDB_KEY_BINARY,
|
||||||
.encodeFp = (SdbEncodeFp)mndOffsetActionEncode,
|
.encodeFp = (SdbEncodeFp)mndOffsetActionEncode,
|
||||||
.decodeFp = (SdbDecodeFp)mndOffsetActionDecode,
|
.decodeFp = (SdbDecodeFp)mndOffsetActionDecode,
|
||||||
.insertFp = (SdbInsertFp)mndOffsetActionInsert,
|
.insertFp = (SdbInsertFp)mndOffsetActionInsert,
|
||||||
.updateFp = (SdbUpdateFp)mndOffsetActionUpdate,
|
.updateFp = (SdbUpdateFp)mndOffsetActionUpdate,
|
||||||
.deleteFp = (SdbDeleteFp)mndOffsetActionDelete};
|
.deleteFp = (SdbDeleteFp)mndOffsetActionDelete,
|
||||||
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_COMMIT_OFFSET, mndProcessCommitOffsetReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_MQ_COMMIT_OFFSET, mndProcessCommitOffsetReq);
|
||||||
|
|
||||||
|
|
|
@ -14,66 +14,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
|
#include "mndDb.h"
|
||||||
|
|
||||||
static int32_t mndProcessAuthReq(SRpcMsg *pReq);
|
int32_t mndInitPrivilege(SMnode *pMnode) { return 0; }
|
||||||
|
|
||||||
int32_t mndInitAuth(SMnode *pMnode) {
|
void mndCleanupPrivilege(SMnode *pMnode) {}
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_AUTH, mndProcessAuthReq);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mndCleanupAuth(SMnode *pMnode) {}
|
int32_t mndCheckOperPrivilege(SMnode *pMnode, const char *user, EOperType operType) {
|
||||||
|
|
||||||
static int32_t mndRetriveAuth(SMnode *pMnode, SAuthRsp *pRsp) {
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pRsp->user);
|
|
||||||
if (pUser == NULL) {
|
|
||||||
*pRsp->secret = 0;
|
|
||||||
mError("user:%s, failed to auth user since %s", pRsp->user, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pRsp->spi = 1;
|
|
||||||
pRsp->encrypt = 0;
|
|
||||||
*pRsp->ckey = 0;
|
|
||||||
|
|
||||||
memcpy(pRsp->secret, pUser->pass, TSDB_PASSWORD_LEN);
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
|
||||||
|
|
||||||
mDebug("user:%s, auth info is returned", pRsp->user);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t mndProcessAuthReq(SRpcMsg *pReq) {
|
|
||||||
SAuthReq authReq = {0};
|
|
||||||
if (tDeserializeSAuthReq(pReq->pCont, pReq->contLen, &authReq) != 0) {
|
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SAuthReq authRsp = {0};
|
|
||||||
memcpy(authRsp.user, authReq.user, TSDB_USER_LEN);
|
|
||||||
|
|
||||||
int32_t code = mndRetriveAuth(pReq->info.node, &authRsp);
|
|
||||||
mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->info.conn.user, authRsp.spi, authRsp.encrypt,
|
|
||||||
authRsp.user);
|
|
||||||
|
|
||||||
int32_t contLen = tSerializeSAuthReq(NULL, 0, &authRsp);
|
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
|
||||||
if (pRsp == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
tSerializeSAuthReq(pRsp, contLen, &authRsp);
|
|
||||||
|
|
||||||
pReq->info.rsp = pRsp;
|
|
||||||
pReq->info.rspLen = contLen;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndCheckOperAuth(SMnode *pMnode, const char *user, EOperType operType) {
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
||||||
|
|
||||||
|
@ -93,16 +42,29 @@ int32_t mndCheckOperAuth(SMnode *pMnode, const char *user, EOperType operType) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (operType) {
|
||||||
|
case MND_OPER_CONNECT:
|
||||||
|
case MND_OPER_CREATE_FUNC:
|
||||||
|
case MND_OPER_DROP_FUNC:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||||
code = -1;
|
code = -1;
|
||||||
|
}
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter) {
|
int32_t mndCheckAlterUserPrivilege(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter) {
|
||||||
|
if (pUser->superUser && pAlter->alterType != TSDB_ALTER_USER_PASSWD) {
|
||||||
|
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pOperUser->superUser) return 0;
|
if (pOperUser->superUser) return 0;
|
||||||
|
|
||||||
if (!pOperUser->enable) {
|
if (!pOperUser->enable) {
|
||||||
terrno = TSDB_CODE_MND_USER_DISABLED;
|
terrno = TSDB_CODE_MND_USER_DISABLED;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -118,7 +80,7 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SAlterUserRe
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndCheckShowAuth(SMnode *pMnode, const char *user, int32_t showType) {
|
int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, int32_t showType) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
||||||
|
|
||||||
|
@ -151,7 +113,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndCheckDbAuth(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb) {
|
int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
||||||
|
|
||||||
|
@ -172,15 +134,7 @@ int32_t mndCheckDbAuth(SMnode *pMnode, const char *user, EOperType operType, SDb
|
||||||
if (pUser->sysInfo) goto _OVER;
|
if (pUser->sysInfo) goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operType == MND_OPER_ALTER_DB) {
|
if (operType == MND_OPER_ALTER_DB || operType == MND_OPER_DROP_DB || operType == MND_OPER_COMPACT_DB) {
|
||||||
if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operType == MND_OPER_DROP_DB) {
|
|
||||||
if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operType == MND_OPER_COMPACT_DB) {
|
|
||||||
if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER;
|
if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,3 +161,12 @@ _OVER:
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndCheckDbPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *name) {
|
||||||
|
SDbObj *pDb = mndAcquireDb(pMnode, name);
|
||||||
|
if (pDb == NULL) return -1;
|
||||||
|
|
||||||
|
int32_t code = mndCheckDbPrivilege(pMnode, user, operType, pDb);
|
||||||
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndProfile.h"
|
#include "mndProfile.h"
|
||||||
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
@ -217,36 +218,41 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
||||||
SConnObj *pConn = NULL;
|
SConnObj *pConn = NULL;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SConnectReq connReq = {0};
|
SConnectReq connReq = {0};
|
||||||
char ip[30] = {0};
|
char ip[24] = {0};
|
||||||
const STraceId *trace = &pReq->info.traceId;
|
const STraceId *trace = &pReq->info.traceId;
|
||||||
|
|
||||||
if (tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq) != 0) {
|
if (tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
goto CONN_OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosIp2String(pReq->info.conn.clientIp, ip);
|
taosIp2String(pReq->info.conn.clientIp, ip);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT) != 0) {
|
||||||
|
mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
mGError("user:%s, failed to login while acquire user since %s", pReq->info.conn.user, terrstr());
|
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, terrstr());
|
||||||
goto CONN_OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (0 != strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1)) {
|
|
||||||
mGError("user:%s, failed to auth while acquire user, input:%s", pReq->info.conn.user, connReq.passwd);
|
if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0) {
|
||||||
|
mGError("user:%s, failed to login from %s since invalid pass, input:%s", pReq->info.conn.user, ip, connReq.passwd);
|
||||||
code = TSDB_CODE_RPC_AUTH_FAILURE;
|
code = TSDB_CODE_RPC_AUTH_FAILURE;
|
||||||
goto CONN_OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connReq.db[0]) {
|
if (connReq.db[0]) {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||||
snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db);
|
snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db);
|
||||||
pDb = mndAcquireDb(pMnode, db);
|
pDb = mndAcquireDb(pMnode, db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_DB;
|
terrno = TSDB_CODE_MND_INVALID_DB;
|
||||||
mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
|
mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
|
||||||
terrstr());
|
terrstr());
|
||||||
goto CONN_OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +260,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
||||||
pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime);
|
pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime);
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip, terrstr());
|
mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip, terrstr());
|
||||||
goto CONN_OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
SConnectRsp connectRsp = {0};
|
SConnectRsp connectRsp = {0};
|
||||||
|
@ -271,9 +277,9 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
||||||
mndGetMnodeEpSet(pMnode, &connectRsp.epSet);
|
mndGetMnodeEpSet(pMnode, &connectRsp.epSet);
|
||||||
|
|
||||||
int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp);
|
int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp);
|
||||||
if (contLen < 0) goto CONN_OVER;
|
if (contLen < 0) goto _OVER;
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
void *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) goto CONN_OVER;
|
if (pRsp == NULL) goto _OVER;
|
||||||
tSerializeSConnectRsp(pRsp, contLen, &connectRsp);
|
tSerializeSConnectRsp(pRsp, contLen, &connectRsp);
|
||||||
|
|
||||||
pReq->info.rspLen = contLen;
|
pReq->info.rspLen = contLen;
|
||||||
|
@ -283,7 +289,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
CONN_OVER:
|
_OVER:
|
||||||
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
|
@ -645,15 +651,6 @@ static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
|
||||||
if (pUser == NULL) return 0;
|
|
||||||
if (!pUser->superUser) {
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
|
||||||
|
|
||||||
SKillQueryReq killReq = {0};
|
SKillQueryReq killReq = {0};
|
||||||
if (tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
if (tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -661,6 +658,10 @@ static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
|
mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t connId = 0;
|
int32_t connId = 0;
|
||||||
uint64_t queryId = 0;
|
uint64_t queryId = 0;
|
||||||
char *p = strchr(killReq.queryStrId, ':');
|
char *p = strchr(killReq.queryStrId, ':');
|
||||||
|
@ -690,21 +691,16 @@ static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
|
||||||
if (pUser == NULL) return 0;
|
|
||||||
if (!pUser->superUser) {
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
mndReleaseUser(pMnode, pUser);
|
|
||||||
|
|
||||||
SKillConnReq killReq = {0};
|
SKillConnReq killReq = {0};
|
||||||
if (tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
if (tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
|
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
|
mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
|
||||||
|
@ -739,7 +735,6 @@ _over:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveConns(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;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndQnode.h"
|
#include "mndQnode.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -279,6 +279,9 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("qnode:%d, start to create", createReq.dnodeId);
|
mDebug("qnode:%d, start to create", createReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pObj = mndAcquireQnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireQnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
|
@ -294,10 +297,6 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateQnode(pMnode, pReq, pDnode, &createReq);
|
code = mndCreateQnode(pMnode, pReq, pDnode, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -391,6 +390,9 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("qnode:%d, start to drop", dropReq.dnodeId);
|
mDebug("qnode:%d, start to drop", dropReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -402,10 +404,6 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropQnode(pMnode, pReq, pObj);
|
code = mndDropQnode(pMnode, pReq, pObj);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -457,7 +455,6 @@ int32_t mndCreateQnodeList(SMnode *pMnode, SArray** pList, int32_t limit)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "systable.h"
|
#include "systable.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
|
|
||||||
#define SHOW_STEP_SIZE 100
|
#define SHOW_STEP_SIZE 100
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) {
|
||||||
int32_t size = sizeof(SShowObj);
|
int32_t size = sizeof(SShowObj);
|
||||||
|
|
||||||
SShowObj showObj = {0};
|
SShowObj showObj = {0};
|
||||||
|
|
||||||
showObj.id = showId;
|
showObj.id = showId;
|
||||||
showObj.pMnode = pMnode;
|
showObj.pMnode = pMnode;
|
||||||
showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
|
showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb));
|
||||||
|
@ -231,7 +232,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
||||||
|
|
||||||
mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
|
mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
|
||||||
|
|
||||||
// if (mndCheckShowAuth(pMnode, pReq->info.conn.user, pShow->type) != 0) return -1;
|
// if (mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type) != 0) return -1;
|
||||||
|
|
||||||
int32_t numOfCols = pShow->pMeta->numOfColumns;
|
int32_t numOfCols = pShow->pMeta->numOfColumns;
|
||||||
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndSma.h"
|
#include "mndSma.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndInfoSchema.h"
|
#include "mndInfoSchema.h"
|
||||||
|
@ -713,7 +713,7 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,7 +974,7 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndSnode.h"
|
#include "mndSnode.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -285,6 +285,9 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("snode:%d, start to create", createReq.dnodeId);
|
mDebug("snode:%d, start to create", createReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pObj = mndAcquireSnode(pMnode, createReq.dnodeId);
|
pObj = mndAcquireSnode(pMnode, createReq.dnodeId);
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
|
@ -300,10 +303,6 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateSnode(pMnode, pReq, pDnode, &createReq);
|
code = mndCreateSnode(pMnode, pReq, pDnode, &createReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -398,6 +397,9 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("snode:%d, start to drop", dropReq.dnodeId);
|
mDebug("snode:%d, start to drop", dropReq.dnodeId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.dnodeId <= 0) {
|
if (dropReq.dnodeId <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -409,10 +411,6 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check deletable
|
// check deletable
|
||||||
code = mndDropSnode(pMnode, pReq, pObj);
|
code = mndDropSnode(pMnode, pReq, pObj);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndStb.h"
|
#include "mndStb.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndInfoSchema.h"
|
#include "mndInfoSchema.h"
|
||||||
|
@ -876,7 +876,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1607,7 +1607,7 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1737,7 +1737,7 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mndStream.h"
|
#include "mndStream.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
@ -437,10 +437,6 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, user, MND_OPER_WRITE_DB, pDb) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t numOfStbs = -1;
|
int32_t numOfStbs = -1;
|
||||||
if (mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs) != 0) {
|
if (mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
@ -542,19 +538,6 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check read auth for source and write auth for target
|
|
||||||
#if 0
|
|
||||||
pDb = mndAcquireDb(pMnode, createStreamReq.sourceDB);
|
|
||||||
if (pDb == NULL) {
|
|
||||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// build stream obj from request
|
// build stream obj from request
|
||||||
SStreamObj streamObj = {0};
|
SStreamObj streamObj = {0};
|
||||||
if (mndBuildStreamObjFromCreateReq(pMnode, &streamObj, &createStreamReq) < 0) {
|
if (mndBuildStreamObjFromCreateReq(pMnode, &streamObj, &createStreamReq) < 0) {
|
||||||
|
@ -592,6 +575,16 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, streamObj.sourceDb) != 0) {
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, streamObj.targetDb) != 0) {
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
// execute creation
|
// execute creation
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -634,20 +627,16 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
|
||||||
if (dropReq.igNotExists) {
|
if (dropReq.igNotExists) {
|
||||||
mDebug("stream:%s, not exist, ignore not exist is set", dropReq.name);
|
mDebug("stream:%s, not exist, ignore not exist is set", dropReq.name);
|
||||||
sdbRelease(pMnode->pSdb, pStream);
|
sdbRelease(pMnode->pSdb, pStream);
|
||||||
return -1;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_MND_STREAM_NOT_EXIST;
|
terrno = TSDB_CODE_MND_STREAM_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb) != 0) {
|
||||||
// todo check auth
|
return -1;
|
||||||
pUser = mndAcquireUser(pMnode, pReq->info.conn.user);
|
|
||||||
if (pUser == NULL) {
|
|
||||||
goto DROP_STREAM_OVER;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq);
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq);
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mndTopic.h"
|
#include "mndTopic.h"
|
||||||
#include "mndAuth.h"
|
|
||||||
#include "mndConsumer.h"
|
#include "mndConsumer.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndOffset.h"
|
#include "mndOffset.h"
|
||||||
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndStb.h"
|
#include "mndStb.h"
|
||||||
#include "mndSubscribe.h"
|
#include "mndSubscribe.h"
|
||||||
|
@ -480,7 +480,7 @@ static int32_t mndProcessCreateTopicReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckDbAuth(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pDb) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,6 +571,10 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq);
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq);
|
||||||
mndTransSetDbName(pTrans, pTopic->db, NULL);
|
mndTransSetDbName(pTrans, pTopic->db, NULL);
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndConsumer.h"
|
#include "mndConsumer.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
@ -1384,8 +1384,7 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("trans:%d, start to kill", killReq.transId);
|
mInfo("trans:%d, start to kill", killReq.transId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS) != 0) {
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS) != 0) {
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -295,7 +295,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
|
||||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||||
userObj.createdTime = taosGetTimestampMs();
|
userObj.createdTime = taosGetTimestampMs();
|
||||||
userObj.updateTime = userObj.createdTime;
|
userObj.updateTime = userObj.createdTime;
|
||||||
userObj.superUser = pCreate->superUser;
|
userObj.superUser = 0; // pCreate->superUser;
|
||||||
userObj.sysInfo = pCreate->sysInfo;
|
userObj.sysInfo = pCreate->sysInfo;
|
||||||
userObj.enable = pCreate->enable;
|
userObj.enable = pCreate->enable;
|
||||||
|
|
||||||
|
@ -337,6 +337,9 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("user:%s, start to create", createReq.user);
|
mDebug("user:%s, start to create", createReq.user);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_USER) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (createReq.user[0] == 0) {
|
if (createReq.user[0] == 0) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||||
|
@ -360,10 +363,6 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_CREATE_USER) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -466,7 +465,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckAlterUserAuth(pOperUser, pUser, &alterReq) != 0) {
|
if (mndCheckAlterUserPrivilege(pOperUser, pUser, &alterReq) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,6 +630,9 @@ static int32_t mndProcessDropUserReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("user:%s, start to drop", dropReq.user);
|
mDebug("user:%s, start to drop", dropReq.user);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_USER) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (dropReq.user[0] == 0) {
|
if (dropReq.user[0] == 0) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||||
|
@ -643,10 +645,6 @@ static int32_t mndProcessDropUserReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_DROP_USER) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndDropUser(pMnode, pReq, pUser);
|
code = mndDropUser(pMnode, pReq, pUser);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndVgroup.h"
|
#include "mndVgroup.h"
|
||||||
#include "mndAuth.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
@ -1212,8 +1212,9 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("vgId:%d, start to redistribute vgroup to dnode %d:%d:%d", req.vgId, req.dnodeId1, req.dnodeId2, req.dnodeId3);
|
mInfo("vgId:%d, start to redistribute vgroup to dnode %d:%d:%d", req.vgId, req.dnodeId1, req.dnodeId2, req.dnodeId3);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_REDISTRIBUTE_VGROUP) != 0) {
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_REDISTRIBUTE_VGROUP) != 0) goto _OVER;
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pVgroup = mndAcquireVgroup(pMnode, req.vgId);
|
pVgroup = mndAcquireVgroup(pMnode, req.vgId);
|
||||||
if (pVgroup == NULL) goto _OVER;
|
if (pVgroup == NULL) goto _OVER;
|
||||||
|
@ -1506,6 +1507,9 @@ static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) {
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
|
|
||||||
mDebug("vgId:%d, start to split", vgId);
|
mDebug("vgId:%d, start to split", vgId);
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_SPLIT_VGROUP) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pVgroup = mndAcquireVgroup(pMnode, vgId);
|
pVgroup = mndAcquireVgroup(pMnode, vgId);
|
||||||
if (pVgroup == NULL) goto _OVER;
|
if (pVgroup == NULL) goto _OVER;
|
||||||
|
@ -1513,8 +1517,6 @@ static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) {
|
||||||
pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||||
if (pDb == NULL) goto _OVER;
|
if (pDb == NULL) goto _OVER;
|
||||||
|
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_SPLIT_VGROUP) != 0) goto _OVER;
|
|
||||||
|
|
||||||
code = mndSplitVgroup(pMnode, pReq, pDb, pVgroup);
|
code = mndSplitVgroup(pMnode, pReq, pDb, pVgroup);
|
||||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
||||||
|
@ -1655,8 +1657,9 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("start to balance vgroup");
|
mInfo("start to balance vgroup");
|
||||||
|
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_BALANCE_VGROUP) != 0) {
|
||||||
if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_BALANCE_VGROUP) != 0) goto _OVER;
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
|
|
|
@ -33,6 +33,8 @@ TEST_F(MndTestUser, 01_Show_User) {
|
||||||
TEST_F(MndTestUser, 02_Create_User) {
|
TEST_F(MndTestUser, 02_Create_User) {
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "");
|
strcpy(createReq.user, "");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
|
|
||||||
|
@ -47,6 +49,8 @@ TEST_F(MndTestUser, 02_Create_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u1");
|
strcpy(createReq.user, "u1");
|
||||||
strcpy(createReq.pass, "");
|
strcpy(createReq.pass, "");
|
||||||
|
|
||||||
|
@ -61,6 +65,8 @@ TEST_F(MndTestUser, 02_Create_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "root");
|
strcpy(createReq.user, "root");
|
||||||
strcpy(createReq.pass, "1");
|
strcpy(createReq.pass, "1");
|
||||||
|
|
||||||
|
@ -75,6 +81,8 @@ TEST_F(MndTestUser, 02_Create_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u1");
|
strcpy(createReq.user, "u1");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
|
|
||||||
|
@ -108,9 +116,11 @@ TEST_F(MndTestUser, 02_Create_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u2");
|
strcpy(createReq.user, "u2");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
createReq.superUser = 1;
|
createReq.superUser = 0;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
||||||
void* pReq = rpcMallocCont(contLen);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
|
@ -144,9 +154,11 @@ TEST_F(MndTestUser, 02_Create_User) {
|
||||||
TEST_F(MndTestUser, 03_Alter_User) {
|
TEST_F(MndTestUser, 03_Alter_User) {
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u3");
|
strcpy(createReq.user, "u3");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
createReq.superUser = 1;
|
createReq.superUser = 0;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
||||||
void* pReq = rpcMallocCont(contLen);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
|
@ -225,7 +237,7 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
||||||
alterReq.alterType = TSDB_ALTER_USER_SUPERUSER;
|
alterReq.alterType = TSDB_ALTER_USER_SUPERUSER;
|
||||||
strcpy(alterReq.user, "u3");
|
strcpy(alterReq.user, "u3");
|
||||||
strcpy(alterReq.pass, "1");
|
strcpy(alterReq.pass, "1");
|
||||||
alterReq.superUser = 1;
|
alterReq.superUser = 0;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
||||||
void* pReq = rpcMallocCont(contLen);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
|
@ -361,7 +373,7 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
||||||
SGetUserAuthRsp authRsp = {0};
|
SGetUserAuthRsp authRsp = {0};
|
||||||
tDeserializeSGetUserAuthRsp(pRsp->pCont, pRsp->contLen, &authRsp);
|
tDeserializeSGetUserAuthRsp(pRsp->pCont, pRsp->contLen, &authRsp);
|
||||||
EXPECT_STREQ(authRsp.user, "u3");
|
EXPECT_STREQ(authRsp.user, "u3");
|
||||||
EXPECT_EQ(authRsp.superAuth, 1);
|
EXPECT_EQ(authRsp.superAuth, 0);
|
||||||
int32_t numOfReadDbs = taosHashGetSize(authRsp.readDbs);
|
int32_t numOfReadDbs = taosHashGetSize(authRsp.readDbs);
|
||||||
int32_t numOfWriteDbs = taosHashGetSize(authRsp.writeDbs);
|
int32_t numOfWriteDbs = taosHashGetSize(authRsp.writeDbs);
|
||||||
EXPECT_EQ(numOfReadDbs, 1);
|
EXPECT_EQ(numOfReadDbs, 1);
|
||||||
|
@ -436,6 +448,8 @@ TEST_F(MndTestUser, 05_Drop_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u1");
|
strcpy(createReq.user, "u1");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
|
|
||||||
|
@ -468,6 +482,8 @@ TEST_F(MndTestUser, 05_Drop_User) {
|
||||||
TEST_F(MndTestUser, 06_Create_Drop_Alter_User) {
|
TEST_F(MndTestUser, 06_Create_Drop_Alter_User) {
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u1");
|
strcpy(createReq.user, "u1");
|
||||||
strcpy(createReq.pass, "p1");
|
strcpy(createReq.pass, "p1");
|
||||||
|
|
||||||
|
@ -482,6 +498,8 @@ TEST_F(MndTestUser, 06_Create_Drop_Alter_User) {
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserReq createReq = {0};
|
SCreateUserReq createReq = {0};
|
||||||
|
createReq.enable = 1;
|
||||||
|
createReq.sysInfo = 1;
|
||||||
strcpy(createReq.user, "u2");
|
strcpy(createReq.user, "u2");
|
||||||
strcpy(createReq.pass, "p2");
|
strcpy(createReq.pass, "p2");
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,8 @@ typedef void *tsdbReaderT;
|
||||||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||||
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||||
|
|
||||||
tsdbReaderT tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId,
|
int32_t tsdbSetTableList(tsdbReaderT reader, SArray* tableList);
|
||||||
|
tsdbReaderT tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, SArray *tableList, uint64_t qId,
|
||||||
uint64_t taskId);
|
uint64_t taskId);
|
||||||
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId,
|
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId,
|
||||||
void *pMemRef);
|
void *pMemRef);
|
||||||
|
@ -195,7 +196,6 @@ struct SVnodeCfg {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TSKEY lastKey;
|
TSKEY lastKey;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
uint64_t groupId;
|
|
||||||
} STableKeyInfo;
|
} STableKeyInfo;
|
||||||
|
|
||||||
struct SMetaEntry {
|
struct SMetaEntry {
|
||||||
|
|
|
@ -121,7 +121,7 @@ int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSub
|
||||||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
||||||
SSubmitBlkRsp* pRsp);
|
SSubmitBlkRsp* pRsp);
|
||||||
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
||||||
tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* tableList, uint64_t qId,
|
||||||
uint64_t taskId);
|
uint64_t taskId);
|
||||||
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||||
void* pMemRef);
|
void* pMemRef);
|
||||||
|
|
|
@ -381,13 +381,14 @@ int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) {
|
||||||
for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
|
for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
|
||||||
tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i);
|
tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i);
|
||||||
metaDropTableByUid(pMeta, *uid, NULL);
|
metaDropTableByUid(pMeta, *uid, NULL);
|
||||||
|
metaDebug("ttl drop table:%"PRId64, *uid);
|
||||||
}
|
}
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){
|
static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){
|
||||||
int32_t ttlDays;
|
int64_t ttlDays;
|
||||||
int64_t ctime;
|
int64_t ctime;
|
||||||
if (pME->type == TSDB_CHILD_TABLE) {
|
if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
ctime = pME->ctbEntry.ctime;
|
ctime = pME->ctbEntry.ctime;
|
||||||
|
@ -443,7 +444,6 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
// drop schema.db (todo)
|
// drop schema.db (todo)
|
||||||
}
|
}
|
||||||
|
|
||||||
metaError("ttl drop table:%s", e.name);
|
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
|
|
||||||
|
@ -976,7 +976,9 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
|
||||||
SDecoder dc = {0};
|
SDecoder dc = {0};
|
||||||
|
|
||||||
// get super table
|
// get super table
|
||||||
tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData);
|
if(tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
tbDbKey.uid = pCtbEntry->ctbEntry.suid;
|
tbDbKey.uid = pCtbEntry->ctbEntry.suid;
|
||||||
tbDbKey.version = *(int64_t *)pData;
|
tbDbKey.version = *(int64_t *)pData;
|
||||||
tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData);
|
tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData);
|
||||||
|
|
|
@ -403,7 +403,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
.reader = pHandle->execHandle.pExecReader[i],
|
.reader = pHandle->execHandle.pExecReader[i],
|
||||||
.meta = pTq->pVnode->pMeta,
|
.meta = pTq->pVnode->pMeta,
|
||||||
.vnode = pTq->pVnode,
|
.vnode = pTq->pVnode,
|
||||||
.initTsdbReader = 1,
|
// .initTsdbReader = 1,
|
||||||
};
|
};
|
||||||
pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle);
|
pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle);
|
||||||
ASSERT(pHandle->execHandle.execCol.task[i]);
|
ASSERT(pHandle->execHandle.execCol.task[i]);
|
||||||
|
@ -479,7 +479,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
.reader = pStreamReader,
|
.reader = pStreamReader,
|
||||||
.meta = pTq->pVnode->pMeta,
|
.meta = pTq->pVnode->pMeta,
|
||||||
.vnode = pTq->pVnode,
|
.vnode = pTq->pVnode,
|
||||||
.initTsdbReader = 1,
|
// .initTsdbReader = 1,
|
||||||
};
|
};
|
||||||
/*pTask->exec.inputHandle = pStreamReader;*/
|
/*pTask->exec.inputHandle = pStreamReader;*/
|
||||||
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
|
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
|
||||||
|
|
|
@ -223,9 +223,8 @@ int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, STableListInfo* pTableList) {
|
static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, SArray* pTableList) {
|
||||||
size_t tableSize = taosArrayGetSize(pTableList->pTableList);
|
size_t tableSize = taosArrayGetSize(pTableList);
|
||||||
assert(tableSize >= 1);
|
|
||||||
|
|
||||||
// allocate buffer in order to load data blocks from file
|
// allocate buffer in order to load data blocks from file
|
||||||
SArray* pTableCheckInfo = taosArrayInit(tableSize, sizeof(STableCheckInfo));
|
SArray* pTableCheckInfo = taosArrayInit(tableSize, sizeof(STableCheckInfo));
|
||||||
|
@ -235,7 +234,7 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S
|
||||||
|
|
||||||
// todo apply the lastkey of table check to avoid to load header file
|
// todo apply the lastkey of table check to avoid to load header file
|
||||||
for (int32_t j = 0; j < tableSize; ++j) {
|
for (int32_t j = 0; j < tableSize; ++j) {
|
||||||
STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pTableList->pTableList, j);
|
STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pTableList, j);
|
||||||
|
|
||||||
STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid};
|
STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid};
|
||||||
info.suid = pTsdbReadHandle->suid;
|
info.suid = pTsdbReadHandle->suid;
|
||||||
|
@ -254,8 +253,6 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S
|
||||||
pTsdbReadHandle->idStr);
|
pTsdbReadHandle->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO group table according to the tag value.
|
|
||||||
taosArraySort(pTableCheckInfo, tsdbCheckInfoCompar);
|
|
||||||
return pTableCheckInfo;
|
return pTableCheckInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,8 +494,21 @@ static int32_t setCurrentSchema(SVnode* pVnode, STsdbReadHandle* pTsdbReadHandle
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
int32_t tsdbSetTableList(tsdbReaderT reader, SArray* tableList){
|
||||||
|
STsdbReadHandle* pTsdbReadHandle = reader;
|
||||||
|
if(pTsdbReadHandle->pTableCheckInfo) taosArrayDestroy(pTsdbReadHandle->pTableCheckInfo);
|
||||||
|
pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pTsdbReadHandle, tableList);
|
||||||
|
if (pTsdbReadHandle->pTableCheckInfo == NULL) {
|
||||||
|
return TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
return TDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* tableList, uint64_t qId,
|
||||||
uint64_t taskId) {
|
uint64_t taskId) {
|
||||||
|
if(taosArrayGetSize(tableList) == 0){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId);
|
STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId);
|
||||||
if (pTsdbReadHandle == NULL) {
|
if (pTsdbReadHandle == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -543,7 +553,7 @@ tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableLis
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbDebug("%p total numOfTable:%" PRIzu " in this query, table %" PRIzu " %s", pTsdbReadHandle,
|
tsdbDebug("%p total numOfTable:%" PRIzu " in this query, table %" PRIzu " %s", pTsdbReadHandle,
|
||||||
taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(tableList->pTableList),
|
taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(tableList),
|
||||||
pTsdbReadHandle->idStr);
|
pTsdbReadHandle->idStr);
|
||||||
|
|
||||||
return (tsdbReaderT)pTsdbReadHandle;
|
return (tsdbReaderT)pTsdbReadHandle;
|
||||||
|
@ -639,7 +649,7 @@ tsdbReaderT tsdbQueryLastRow(SVnode* pVnode, SQueryTableDataCond* pCond, STableL
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbReaderOpen(pVnode, pCond, pList, qId, taskId);
|
STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbReaderOpen(pVnode, pCond, pList->pTableList, qId, taskId);
|
||||||
if (pTsdbReadHandle == NULL) {
|
if (pTsdbReadHandle == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2842,7 +2852,7 @@ int32_t tsdbGetAllTableList(SMeta* pMeta, uint64_t uid, SArray* list) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id, .groupId = 0};
|
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id};
|
||||||
taosArrayPush(list, &info);
|
taosArrayPush(list, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3644,17 +3654,6 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbCheckInfoCompar(const void* key1, const void* key2) {
|
|
||||||
if (((STableCheckInfo*)key1)->tableId < ((STableCheckInfo*)key2)->tableId) {
|
|
||||||
return -1;
|
|
||||||
} else if (((STableCheckInfo*)key1)->tableId > ((STableCheckInfo*)key2)->tableId) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
ASSERT(false);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* doFreeColumnInfoData(SArray* pColumnInfoData) {
|
static void* doFreeColumnInfoData(SArray* pColumnInfoData) {
|
||||||
if (pColumnInfoData == NULL) {
|
if (pColumnInfoData == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -273,6 +273,10 @@ typedef struct STableScanInfo {
|
||||||
|
|
||||||
SSampleExecInfo sample; // sample execution info
|
SSampleExecInfo sample; // sample execution info
|
||||||
int32_t curTWinIdx;
|
int32_t curTWinIdx;
|
||||||
|
|
||||||
|
int32_t currentGroupId;
|
||||||
|
uint64_t queryId;
|
||||||
|
uint64_t taskId;
|
||||||
} STableScanInfo;
|
} STableScanInfo;
|
||||||
|
|
||||||
typedef struct STagScanInfo {
|
typedef struct STagScanInfo {
|
||||||
|
@ -354,6 +358,7 @@ typedef struct SSysTableScanInfo {
|
||||||
tsem_t ready;
|
tsem_t ready;
|
||||||
SReadHandle readHandle;
|
SReadHandle readHandle;
|
||||||
int32_t accountId;
|
int32_t accountId;
|
||||||
|
const char* pUser;
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||||
|
@ -706,10 +711,10 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
||||||
|
|
||||||
SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo, uint64_t queryId, uint64_t taskId);
|
||||||
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode,
|
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode,
|
||||||
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
|
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
||||||
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
||||||
|
@ -749,8 +754,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
||||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, SBlockDistScanPhysiNode* pBlockScanNode,
|
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, SBlockDistScanPhysiNode* pBlockScanNode,
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle,
|
SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle,
|
||||||
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup);
|
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup, uint64_t queryId, uint64_t taskId);
|
||||||
|
|
||||||
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, bool multigroupResult,
|
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, bool multigroupResult,
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
|
@ -845,7 +850,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
||||||
|
|
||||||
void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex);
|
void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex);
|
||||||
|
|
||||||
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SArray* groupKey);
|
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* groupKey);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,7 @@ static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){
|
||||||
int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) {
|
int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo));
|
pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo));
|
||||||
|
if(pListInfo->pTableList == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
uint64_t tableUid = pScanNode->uid;
|
uint64_t tableUid = pScanNode->uid;
|
||||||
|
|
||||||
|
@ -314,7 +315,7 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(res); i++) {
|
for (int i = 0; i < taosArrayGetSize(res); i++) {
|
||||||
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0};
|
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i)};
|
||||||
taosArrayPush(pListInfo->pTableList, &info);
|
taosArrayPush(pListInfo->pTableList, &info);
|
||||||
}
|
}
|
||||||
taosArrayDestroy(res);
|
taosArrayDestroy(res);
|
||||||
|
@ -335,9 +336,14 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else { // Create one table group.
|
}else { // Create one table group.
|
||||||
STableKeyInfo info = {.lastKey = 0, .uid = tableUid, .groupId = 0};
|
STableKeyInfo info = {.lastKey = 0, .uid = tableUid};
|
||||||
taosArrayPush(pListInfo->pTableList, &info);
|
taosArrayPush(pListInfo->pTableList, &info);
|
||||||
}
|
}
|
||||||
|
pListInfo->pGroupList = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
if(pListInfo->pGroupList == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
//put into list as default group, remove it if grouping sorting is required later
|
||||||
|
taosArrayPush(pListInfo->pGroupList, &pListInfo->pTableList);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3862,9 +3862,6 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
|
||||||
return pTaskInfo;
|
return pTaskInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
|
||||||
STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId);
|
|
||||||
|
|
||||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||||
|
|
||||||
int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo* pTaskInfo) {
|
int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo* pTaskInfo) {
|
||||||
|
@ -3895,8 +3892,67 @@ int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskI
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SArray* groupKey) {
|
static int32_t sortTableGroup(STableListInfo* pTableListInfo, int32_t groupNum){
|
||||||
if (groupKey == NULL) {
|
taosArrayClear(pTableListInfo->pGroupList);
|
||||||
|
SArray *sortSupport = taosArrayInit(groupNum, sizeof(uint64_t));
|
||||||
|
if(sortSupport == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++) {
|
||||||
|
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||||
|
uint64_t* groupId = taosHashGet(pTableListInfo->map, &info->uid, sizeof(uint64_t));
|
||||||
|
|
||||||
|
int32_t index = taosArraySearchIdx(sortSupport, groupId, compareUint64Val, TD_EQ);
|
||||||
|
if (index == -1){
|
||||||
|
void *p = taosArraySearch(sortSupport, groupId, compareUint64Val, TD_GT);
|
||||||
|
SArray *tGroup = taosArrayInit(8, sizeof(STableKeyInfo));
|
||||||
|
if(tGroup == NULL) {
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if(taosArrayPush(tGroup, info) == NULL){
|
||||||
|
qError("taos push info array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
if(p == NULL){
|
||||||
|
if(taosArrayPush(sortSupport, groupId) != NULL){
|
||||||
|
qError("taos push support array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
if(taosArrayPush(pTableListInfo->pGroupList, &tGroup) != NULL){
|
||||||
|
qError("taos push group array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
int32_t pos = TARRAY_ELEM_IDX(sortSupport, p);
|
||||||
|
if(taosArrayInsert(sortSupport, pos, groupId) == NULL){
|
||||||
|
qError("taos insert support array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
if(taosArrayInsert(pTableListInfo->pGroupList, pos, &tGroup) == NULL){
|
||||||
|
qError("taos insert group array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
SArray* tGroup = (SArray*)taosArrayGetP(pTableListInfo->pGroupList, index);
|
||||||
|
if(taosArrayPush(tGroup, info) == NULL){
|
||||||
|
qError("taos push uid array error");
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
taosArrayDestroy(sortSupport);
|
||||||
|
return TDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group) {
|
||||||
|
if (group == NULL) {
|
||||||
return TDB_CODE_SUCCESS;
|
return TDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3906,13 +3962,14 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
|
||||||
}
|
}
|
||||||
int32_t keyLen = 0;
|
int32_t keyLen = 0;
|
||||||
void* keyBuf = NULL;
|
void* keyBuf = NULL;
|
||||||
int32_t numOfGroupCols = taosArrayGetSize(groupKey);
|
|
||||||
for (int32_t j = 0; j < numOfGroupCols; ++j) {
|
SNode* node;
|
||||||
SColumn* pCol = taosArrayGet(groupKey, j);
|
FOREACH(node, group) {
|
||||||
keyLen += pCol->bytes; // actual data + null_flag
|
SExprNode *pExpr = (SExprNode *)node;
|
||||||
|
keyLen += pExpr->resType.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols;
|
int32_t nullFlagSize = sizeof(int8_t) * LIST_LENGTH(group);
|
||||||
keyLen += nullFlagSize;
|
keyLen += nullFlagSize;
|
||||||
|
|
||||||
keyBuf = taosMemoryCalloc(1, keyLen);
|
keyBuf = taosMemoryCalloc(1, keyLen);
|
||||||
|
@ -3920,103 +3977,109 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t groupNum = 0;
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++) {
|
for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++) {
|
||||||
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||||
SMetaReader mr = {0};
|
SMetaReader mr = {0};
|
||||||
metaReaderInit(&mr, pHandle->meta, 0);
|
metaReaderInit(&mr, pHandle->meta, 0);
|
||||||
metaGetTableEntryByUid(&mr, info->uid);
|
metaGetTableEntryByUid(&mr, info->uid);
|
||||||
|
|
||||||
char* isNull = (char*)keyBuf;
|
SNodeList *groupNew = nodesCloneList(group);
|
||||||
char* pStart = (char*)keyBuf + sizeof(int8_t) * numOfGroupCols;
|
|
||||||
for (int32_t j = 0; j < numOfGroupCols; ++j) {
|
|
||||||
SColumn* pCol = taosArrayGet(groupKey, j);
|
|
||||||
|
|
||||||
if (strcmp(pCol->name, "tbname") == 0) {
|
nodesRewriteExprsPostOrder(groupNew, doTranslateTagExpr, &mr);
|
||||||
isNull[i] = 0;
|
char* isNull = (char*)keyBuf;
|
||||||
memcpy(pStart, mr.me.name, strlen(mr.me.name));
|
char* pStart = (char*)keyBuf + nullFlagSize;
|
||||||
pStart += strlen(mr.me.name);
|
|
||||||
|
SNode* pNode;
|
||||||
|
int32_t index = 0;
|
||||||
|
FOREACH(pNode, groupNew){
|
||||||
|
SNode* pNew = NULL;
|
||||||
|
int32_t code = scalarCalculateConstants(pNode, &pNew);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
REPLACE_NODE(pNew);
|
||||||
} else {
|
} else {
|
||||||
STagVal tagVal = {0};
|
taosMemoryFree(keyBuf);
|
||||||
tagVal.cid = pCol->colId;
|
nodesClearList(groupNew);
|
||||||
const char* p = metaGetTableTagVal(&mr.me, pCol->type, &tagVal);
|
return code;
|
||||||
if (p == NULL) {
|
|
||||||
isNull[j] = 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
isNull[i] = 0;
|
|
||||||
if (pCol->type == TSDB_DATA_TYPE_JSON) {
|
ASSERT(nodeType(pNew) == QUERY_NODE_VALUE);
|
||||||
// int32_t dataLen = getJsonValueLen(pkey->pData);
|
SValueNode *pValue = (SValueNode *)pNew;
|
||||||
// memcpy(pStart, (pkey->pData), dataLen);
|
|
||||||
// pStart += dataLen;
|
if (pValue->node.resType.type == TSDB_DATA_TYPE_NULL) {
|
||||||
} else if (IS_VAR_DATA_TYPE(pCol->type)) {
|
isNull[index++] = 1;
|
||||||
memcpy(pStart, tagVal.pData, tagVal.nData);
|
continue;
|
||||||
pStart += tagVal.nData;
|
|
||||||
ASSERT(tagVal.nData <= pCol->bytes);
|
|
||||||
} else {
|
} else {
|
||||||
memcpy(pStart, &(tagVal.i64), pCol->bytes);
|
isNull[index++] = 0;
|
||||||
pStart += pCol->bytes;
|
char* data = nodesGetValueFromNode(pValue);
|
||||||
|
if (pValue->node.resType.type == TSDB_DATA_TYPE_JSON){
|
||||||
|
int32_t len = getJsonValueLen(data);
|
||||||
|
memcpy(pStart, data, len);
|
||||||
|
pStart += len;
|
||||||
|
} else if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) {
|
||||||
|
memcpy(pStart, data, varDataTLen(data));
|
||||||
|
pStart += varDataTLen(data);
|
||||||
|
} else {
|
||||||
|
memcpy(pStart, data, pValue->node.resType.bytes);
|
||||||
|
pStart += pValue->node.resType.bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32_t len = (int32_t)(pStart - (char*)keyBuf);
|
int32_t len = (int32_t)(pStart - (char*)keyBuf);
|
||||||
|
uint64_t groupId = calcGroupId(keyBuf, len);
|
||||||
|
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &groupId, sizeof(uint64_t));
|
||||||
|
groupNum++;
|
||||||
|
|
||||||
uint64_t* pGroupId = taosHashGet(pTableListInfo->map, keyBuf, len);
|
nodesClearList(groupNew);
|
||||||
|
|
||||||
if (!pGroupId) {
|
|
||||||
uint64_t tmpId = calcGroupId(keyBuf, len);
|
|
||||||
info->groupId = tmpId;
|
|
||||||
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &tmpId, sizeof(uint64_t));
|
|
||||||
} else {
|
|
||||||
info->groupId = *pGroupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
metaReaderClear(&mr);
|
metaReaderClear(&mr);
|
||||||
}
|
}
|
||||||
taosMemoryFree(keyBuf);
|
taosMemoryFree(keyBuf);
|
||||||
|
|
||||||
|
if(pTableListInfo->needSortTableByGroupId){
|
||||||
|
return sortTableGroup(pTableListInfo, groupNum);
|
||||||
|
}
|
||||||
|
|
||||||
return TDB_CODE_SUCCESS;
|
return TDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
||||||
uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo) {
|
uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo, const char* pUser) {
|
||||||
int32_t type = nodeType(pPhyNode);
|
int32_t type = nodeType(pPhyNode);
|
||||||
|
|
||||||
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
||||||
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
|
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
|
||||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
tsdbReaderT pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId);
|
int32_t code = createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId);
|
||||||
if (pDataReader == NULL && terrno != 0) {
|
|
||||||
pTaskInfo->code = terrno;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
|
||||||
if(code){
|
if(code){
|
||||||
tsdbCleanupReadHandle(pDataReader);
|
pTaskInfo->code = code;
|
||||||
pTaskInfo->code = terrno;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
||||||
SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags);
|
|
||||||
code = generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json
|
|
||||||
taosArrayDestroy(groupKeys);
|
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbCleanupReadHandle(pDataReader);
|
|
||||||
pTaskInfo->code = terrno;
|
pTaskInfo->code = terrno;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
|
SOperatorInfo* pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo, queryId, taskId);
|
||||||
STableScanInfo* pScanInfo = pOperator->info;
|
STableScanInfo* pScanInfo = pOperator->info;
|
||||||
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
||||||
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
||||||
createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId);
|
int32_t code = createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId);
|
||||||
extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
if(code){
|
||||||
SOperatorInfo* pOperator =
|
return NULL;
|
||||||
createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo, queryId, taskId);
|
}
|
||||||
|
code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
||||||
|
if (code) {
|
||||||
|
pTaskInfo->code = terrno;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorInfo* pOperator = createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo, queryId, taskId);
|
||||||
|
|
||||||
STableScanInfo* pScanInfo = pOperator->info;
|
STableScanInfo* pScanInfo = pOperator->info;
|
||||||
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
@ -4025,52 +4088,22 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
return createExchangeOperatorInfo(pHandle->pMsgCb->clientRpc, (SExchangePhysiNode*)pPhyNode, pTaskInfo);
|
return createExchangeOperatorInfo(pHandle->pMsgCb->clientRpc, (SExchangePhysiNode*)pPhyNode, pTaskInfo);
|
||||||
|
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
||||||
SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table.
|
|
||||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||||
STimeWindowAggSupp twSup = {
|
STimeWindowAggSupp twSup = {
|
||||||
.waterMark = pTableScanNode->watermark,
|
.waterMark = pTableScanNode->watermark,
|
||||||
.calTrigger = pTableScanNode->triggerType,
|
.calTrigger = pTableScanNode->triggerType,
|
||||||
.maxTs = INT64_MIN,
|
.maxTs = INT64_MIN,
|
||||||
};
|
};
|
||||||
tsdbReaderT pDataReader = NULL;
|
|
||||||
|
|
||||||
if (pHandle) {
|
if (pHandle) {
|
||||||
if (pHandle->initTsdbReader) {
|
createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId);
|
||||||
// for stream
|
|
||||||
ASSERT(pHandle->vnode);
|
|
||||||
pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId);
|
|
||||||
} else {
|
|
||||||
// for tq
|
|
||||||
ASSERT(pHandle->meta);
|
|
||||||
getTableList(pHandle->meta, pScanPhyNode, pTableListInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle, pTableScanNode, pTaskInfo, &twSup, queryId, taskId);
|
||||||
if (pDataReader == NULL && terrno != 0) {
|
|
||||||
qDebug("%s pDataReader is NULL", GET_TASKID(pTaskInfo));
|
|
||||||
// return NULL;
|
|
||||||
} else {
|
|
||||||
qDebug("%s pDataReader is not NULL", GET_TASKID(pTaskInfo));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags);
|
|
||||||
int32_t code = generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json
|
|
||||||
taosArrayDestroy(groupKeys);
|
|
||||||
if (code) {
|
|
||||||
tsdbCleanupReadHandle(pDataReader);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pDataReader, pHandle, pTableScanNode, pTaskInfo, &twSup);
|
|
||||||
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
|
||||||
SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
|
SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
|
||||||
return createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pTaskInfo);
|
return createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo);
|
||||||
|
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
||||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
|
@ -4093,7 +4126,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else { // Create one table group.
|
} else { // Create one table group.
|
||||||
STableKeyInfo info = {.lastKey = 0, .uid = pBlockNode->uid, .groupId = 0};
|
STableKeyInfo info = {.lastKey = 0, .uid = pBlockNode->uid};
|
||||||
taosArrayPush(pTableListInfo->pTableList, &info);
|
taosArrayPush(pTableListInfo->pTableList, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4118,7 +4151,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
cond.suid = pBlockNode->suid;
|
cond.suid = pBlockNode->suid;
|
||||||
cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER;
|
cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER;
|
||||||
}
|
}
|
||||||
tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId);
|
tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, queryId, taskId);
|
||||||
cleanupQueryTableDataCond(&cond);
|
cleanupQueryTableDataCond(&cond);
|
||||||
|
|
||||||
return createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo);
|
return createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo);
|
||||||
|
@ -4133,7 +4166,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
|
SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
|
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
|
||||||
ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo);
|
ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo, pUser);
|
||||||
if (ops[i] == NULL) {
|
if (ops[i] == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -4355,7 +4388,7 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle*
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbReaderT pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId);
|
tsdbReaderT pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, queryId, taskId);
|
||||||
cleanupQueryTableDataCond(&cond);
|
cleanupQueryTableDataCond(&cond);
|
||||||
|
|
||||||
return pReader;
|
return pReader;
|
||||||
|
@ -4566,7 +4599,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
||||||
(*pTaskInfo)->tableqinfoList.pTagCond = pPlan->pTagCond;
|
(*pTaskInfo)->tableqinfoList.pTagCond = pPlan->pTagCond;
|
||||||
(*pTaskInfo)->tableqinfoList.pTagIndexCond = pPlan->pTagIndexCond;
|
(*pTaskInfo)->tableqinfoList.pTagIndexCond = pPlan->pTagIndexCond;
|
||||||
(*pTaskInfo)->pRoot =
|
(*pTaskInfo)->pRoot =
|
||||||
createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoList);
|
createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoList, pPlan->user);
|
||||||
|
|
||||||
if (NULL == (*pTaskInfo)->pRoot) {
|
if (NULL == (*pTaskInfo)->pRoot) {
|
||||||
code = (*pTaskInfo)->code;
|
code = (*pTaskInfo)->code;
|
||||||
|
@ -4584,6 +4617,13 @@ _complete:
|
||||||
static void doDestroyTableList(STableListInfo* pTableqinfoList) {
|
static void doDestroyTableList(STableListInfo* pTableqinfoList) {
|
||||||
taosArrayDestroy(pTableqinfoList->pTableList);
|
taosArrayDestroy(pTableqinfoList->pTableList);
|
||||||
taosHashCleanup(pTableqinfoList->map);
|
taosHashCleanup(pTableqinfoList->map);
|
||||||
|
if(pTableqinfoList->needSortTableByGroupId){
|
||||||
|
for(int32_t i = 0; i < taosArrayGetSize(pTableqinfoList->pGroupList); i++){
|
||||||
|
SArray* tmp = taosArrayGetP(pTableqinfoList->pGroupList, i);
|
||||||
|
taosArrayDestroy(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pTableqinfoList->pGroupList);
|
||||||
|
|
||||||
pTableqinfoList->pTableList = NULL;
|
pTableqinfoList->pTableList = NULL;
|
||||||
pTableqinfoList->map = NULL;
|
pTableqinfoList->map = NULL;
|
||||||
|
|
|
@ -418,7 +418,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) {
|
||||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
@ -500,6 +500,48 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
||||||
|
STableScanInfo* pInfo = pOperator->info;
|
||||||
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
|
if(pInfo->currentGroupId == -1){
|
||||||
|
pInfo->currentGroupId++;
|
||||||
|
if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) {
|
||||||
|
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SArray *tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId);
|
||||||
|
tsdbCleanupReadHandle(pInfo->dataReader);
|
||||||
|
tsdbReaderT* pReader = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, tableList, pInfo->queryId, pInfo->taskId);
|
||||||
|
pInfo->dataReader = pReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSDataBlock* result = doTableScanGroup(pOperator);
|
||||||
|
if(result){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->currentGroupId++;
|
||||||
|
if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) {
|
||||||
|
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SArray *tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId);
|
||||||
|
tsdbSetTableList(pInfo->dataReader, tableList);
|
||||||
|
|
||||||
|
tsdbResetReadHandle(pInfo->dataReader, &pInfo->cond, 0);
|
||||||
|
pInfo->curTWinIdx = 0;
|
||||||
|
pInfo->scanTimes = 0;
|
||||||
|
|
||||||
|
result = doTableScanGroup(pOperator);
|
||||||
|
if(result){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -525,8 +567,8 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader,
|
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle,
|
||||||
SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo, uint64_t queryId, uint64_t taskId) {
|
||||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
@ -561,10 +603,12 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
||||||
pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired;
|
pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired;
|
||||||
pInfo->pResBlock = createResDataBlock(pDescNode);
|
pInfo->pResBlock = createResDataBlock(pDescNode);
|
||||||
pInfo->pFilterNode = pTableScanNode->scan.node.pConditions;
|
pInfo->pFilterNode = pTableScanNode->scan.node.pConditions;
|
||||||
pInfo->dataReader = pDataReader;
|
|
||||||
pInfo->scanFlag = MAIN_SCAN;
|
pInfo->scanFlag = MAIN_SCAN;
|
||||||
pInfo->pColMatchInfo = pColList;
|
pInfo->pColMatchInfo = pColList;
|
||||||
pInfo->curTWinIdx = 0;
|
pInfo->curTWinIdx = 0;
|
||||||
|
pInfo->queryId = queryId;
|
||||||
|
pInfo->taskId = taskId;
|
||||||
|
pInfo->currentGroupId = -1;
|
||||||
|
|
||||||
pOperator->name = "TableScanOperator"; // for debug purpose
|
pOperator->name = "TableScanOperator"; // for debug purpose
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||||
|
@ -778,8 +822,9 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) {
|
||||||
STableScanInfo* pTableScanInfo = pInfo->pSnapshotReadOp->info;
|
STableScanInfo* pTableScanInfo = pInfo->pSnapshotReadOp->info;
|
||||||
pTableScanInfo->cond.twindows[0] = win;
|
pTableScanInfo->cond.twindows[0] = win;
|
||||||
pTableScanInfo->curTWinIdx = 0;
|
pTableScanInfo->curTWinIdx = 0;
|
||||||
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0);
|
// tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0);
|
||||||
pTableScanInfo->scanTimes = 0;
|
pTableScanInfo->scanTimes = 0;
|
||||||
|
pTableScanInfo->currentGroupId = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,9 +1067,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor @liao
|
|
||||||
taosArrayDestroy(block.pDataBlock);
|
taosArrayDestroy(block.pDataBlock);
|
||||||
|
|
||||||
if (pInfo->pRes->pDataBlock == NULL) {
|
if (pInfo->pRes->pDataBlock == NULL) {
|
||||||
// TODO add log
|
// TODO add log
|
||||||
pOperator->status = OP_EXEC_DONE;
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
@ -1087,9 +1130,9 @@ static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) {
|
||||||
return tableIdList;
|
return tableIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle,
|
SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle,
|
||||||
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo,
|
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo,
|
||||||
STimeWindowAggSupp* pTwSup) {
|
STimeWindowAggSupp* pTwSup, uint64_t queryId, uint64_t taskId) {
|
||||||
SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo));
|
SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
|
||||||
|
@ -1129,7 +1172,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHandle) {
|
if (pHandle) {
|
||||||
SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
|
SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo, queryId, taskId);
|
||||||
STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info;
|
STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info;
|
||||||
if (pSTInfo->interval.interval > 0) {
|
if (pSTInfo->interval.interval > 0) {
|
||||||
pInfo->pUpdateInfo = updateInfoInitP(&pSTInfo->interval, pTwSup->waterMark);
|
pInfo->pUpdateInfo = updateInfoInitP(&pSTInfo->interval, pTwSup->waterMark);
|
||||||
|
@ -1529,6 +1572,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int64_t startTs = taosGetTimestampUs();
|
int64_t startTs = taosGetTimestampUs();
|
||||||
strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb));
|
strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb));
|
||||||
|
strcpy(pInfo->req.user, pInfo->pUser);
|
||||||
|
|
||||||
if (pInfo->showRewrite) {
|
if (pInfo->showRewrite) {
|
||||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||||
|
@ -1661,7 +1705,7 @@ int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbT
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode,
|
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
const char* pUser, SExecTaskInfo* pTaskInfo) {
|
||||||
SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo));
|
SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
@ -1677,6 +1721,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan
|
||||||
SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, COL_MATCH_FROM_COL_ID);
|
SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, COL_MATCH_FROM_COL_ID);
|
||||||
|
|
||||||
pInfo->accountId = pScanPhyNode->accountId;
|
pInfo->accountId = pScanPhyNode->accountId;
|
||||||
|
pInfo->pUser = taosMemoryStrDup((void*) pUser);
|
||||||
pInfo->showRewrite = pScanPhyNode->showRewrite;
|
pInfo->showRewrite = pScanPhyNode->showRewrite;
|
||||||
pInfo->pRes = pResBlock;
|
pInfo->pRes = pResBlock;
|
||||||
pInfo->pCondition = pScanNode->node.pConditions;
|
pInfo->pCondition = pScanNode->node.pConditions;
|
||||||
|
@ -1894,6 +1939,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
||||||
pInfo->pRes = createResDataBlock(pDescNode);
|
pInfo->pRes = createResDataBlock(pDescNode);
|
||||||
pInfo->readHandle = *pReadHandle;
|
pInfo->readHandle = *pReadHandle;
|
||||||
pInfo->curPos = 0;
|
pInfo->curPos = 0;
|
||||||
|
|
||||||
pOperator->name = "TagScanOperator";
|
pOperator->name = "TagScanOperator";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
||||||
|
|
||||||
|
@ -1919,10 +1965,7 @@ _error:
|
||||||
|
|
||||||
typedef struct STableMergeScanInfo {
|
typedef struct STableMergeScanInfo {
|
||||||
STableListInfo* tableListInfo;
|
STableListInfo* tableListInfo;
|
||||||
int32_t tableStartIndex;
|
int32_t currentGroupId;
|
||||||
int32_t tableEndIndex;
|
|
||||||
bool hasGroupId;
|
|
||||||
uint64_t groupId;
|
|
||||||
|
|
||||||
SArray* dataReaders; // array of tsdbReaderT*
|
SArray* dataReaders; // array of tsdbReaderT*
|
||||||
SReadHandle readHandle;
|
SReadHandle readHandle;
|
||||||
|
@ -1968,12 +2011,6 @@ typedef struct STableMergeScanInfo {
|
||||||
SSampleExecInfo sample; // sample execution info
|
SSampleExecInfo sample; // sample execution info
|
||||||
} STableMergeScanInfo;
|
} STableMergeScanInfo;
|
||||||
|
|
||||||
int32_t compareTableKeyInfoByGid(const void* p1, const void* p2) {
|
|
||||||
const STableKeyInfo* info1 = p1;
|
|
||||||
const STableKeyInfo* info2 = p2;
|
|
||||||
return info1->groupId - info2->groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
||||||
STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) {
|
STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) {
|
||||||
int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo);
|
int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo);
|
||||||
|
@ -1985,57 +2022,11 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle
|
||||||
qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId);
|
qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags);
|
code = generateGroupIdMap(pTableListInfo, pHandle, pTableScanNode->pPartitionTags);
|
||||||
generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json
|
|
||||||
if (groupKeys) {
|
|
||||||
taosArraySort(pTableListInfo->pTableList, compareTableKeyInfoByGid);
|
|
||||||
}
|
|
||||||
taosArrayDestroy(groupKeys);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t doCreateMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
|
||||||
STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId,
|
|
||||||
uint64_t taskId) {
|
|
||||||
SQueryTableDataCond cond = {0};
|
|
||||||
int32_t code = initQueryTableDataCond(&cond, pTableScanNode);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); ++i) {
|
|
||||||
STableListInfo* subListInfo = taosMemoryCalloc(1, sizeof(subListInfo));
|
|
||||||
subListInfo->pTableList = taosArrayInit(1, sizeof(STableKeyInfo));
|
|
||||||
taosArrayPush(subListInfo->pTableList, taosArrayGet(pTableListInfo->pTableList, i));
|
|
||||||
|
|
||||||
tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, subListInfo, queryId, taskId);
|
|
||||||
taosArrayPush(arrayReader, &pReader);
|
|
||||||
|
|
||||||
taosArrayDestroy(subListInfo->pTableList);
|
|
||||||
taosMemoryFree(subListInfo);
|
|
||||||
}
|
|
||||||
cleanupQueryTableDataCond(&cond);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
_error:
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, STableListInfo* pTableListInfo,
|
|
||||||
int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, uint64_t queryId,
|
|
||||||
uint64_t taskId) {
|
|
||||||
for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) {
|
|
||||||
STableListInfo* subListInfo = taosMemoryCalloc(1, sizeof(subListInfo));
|
|
||||||
subListInfo->pTableList = taosArrayInit(1, sizeof(STableKeyInfo));
|
|
||||||
taosArrayPush(subListInfo->pTableList, taosArrayGet(pTableListInfo->pTableList, i));
|
|
||||||
|
|
||||||
tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, pQueryCond, subListInfo, queryId, taskId);
|
|
||||||
taosArrayPush(arrayReader, &pReader);
|
|
||||||
|
|
||||||
taosArrayDestroy(subListInfo->pTableList);
|
|
||||||
taosMemoryFree(subListInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2225,32 +2216,34 @@ SArray* generateSortByTsInfo(int32_t order) {
|
||||||
return pList;
|
return pList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, SArray* tableList, SArray* arrayReader, uint64_t queryId,
|
||||||
|
uint64_t taskId) {
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(tableList); ++i) {
|
||||||
|
SArray* tmp = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||||
|
taosArrayPush(tmp, taosArrayGet(tableList, i));
|
||||||
|
|
||||||
|
tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, pQueryCond, tmp, queryId, taskId);
|
||||||
|
taosArrayPush(arrayReader, &pReader);
|
||||||
|
|
||||||
|
taosArrayDestroy(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
||||||
STableMergeScanInfo* pInfo = pOperator->info;
|
STableMergeScanInfo* pInfo = pOperator->info;
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
|
|
||||||
{
|
SArray* tableList = taosArrayGetP(pInfo->tableListInfo->pGroupList, pInfo->currentGroupId);
|
||||||
size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList);
|
|
||||||
int32_t i = pInfo->tableStartIndex + 1;
|
|
||||||
for (; i < tableListSize; ++i) {
|
|
||||||
STableKeyInfo* tableKeyInfo = taosArrayGet(pInfo->tableListInfo->pTableList, i);
|
|
||||||
if (tableKeyInfo->groupId != pInfo->groupId) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pInfo->tableEndIndex = i - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tableStartIdx = pInfo->tableStartIndex;
|
createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableList,
|
||||||
int32_t tableEndIdx = pInfo->tableEndIndex;
|
|
||||||
|
|
||||||
STableListInfo* tableListInfo = pInfo->tableListInfo;
|
|
||||||
createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableListInfo, tableStartIdx, tableEndIdx,
|
|
||||||
pInfo->dataReaders, pInfo->queryId, pInfo->taskId);
|
pInfo->dataReaders, pInfo->queryId, pInfo->taskId);
|
||||||
|
|
||||||
// todo the total available buffer should be determined by total capacity of buffer of this task.
|
// todo the total available buffer should be determined by total capacity of buffer of this task.
|
||||||
// the additional one is reserved for merge result
|
// the additional one is reserved for merge result
|
||||||
pInfo->sortBufSize = pInfo->bufPageSize * (tableEndIdx - tableStartIdx + 1 + 1);
|
int32_t tableLen = taosArrayGetSize(tableList);
|
||||||
|
pInfo->sortBufSize = pInfo->bufPageSize * ((tableLen==0?1:tableLen) + 1);
|
||||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage,
|
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage,
|
||||||
pInfo->pSortInputBlock, pTaskInfo->id.str);
|
pInfo->pSortInputBlock, pTaskInfo->id.str);
|
||||||
|
@ -2337,37 +2330,42 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
longjmp(pTaskInfo->env, code);
|
longjmp(pTaskInfo->env, code);
|
||||||
}
|
}
|
||||||
size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList);
|
|
||||||
if (!pInfo->hasGroupId) {
|
|
||||||
pInfo->hasGroupId = true;
|
|
||||||
|
|
||||||
if (tableListSize == 0) {
|
if (pInfo->currentGroupId == -1) {
|
||||||
|
pInfo->currentGroupId++;
|
||||||
|
if (pInfo->currentGroupId >= taosArrayGetSize(pInfo->tableListInfo->pGroupList)) {
|
||||||
doSetOperatorCompleted(pOperator);
|
doSetOperatorCompleted(pOperator);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pInfo->tableStartIndex = 0;
|
|
||||||
pInfo->groupId = ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId;
|
|
||||||
startGroupTableMergeScan(pOperator);
|
startGroupTableMergeScan(pOperator);
|
||||||
}
|
}
|
||||||
SSDataBlock* pBlock = NULL;
|
SSDataBlock* pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator);
|
||||||
while (pInfo->tableStartIndex < tableListSize) {
|
|
||||||
pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator);
|
|
||||||
if (pBlock != NULL) {
|
if (pBlock != NULL) {
|
||||||
pBlock->info.groupId = pInfo->groupId;
|
uint64_t* groupId = taosHashGet(pInfo->tableListInfo->map, &(pBlock->info.uid), sizeof(uint64_t));
|
||||||
|
if(groupId) pBlock->info.groupId = *groupId;
|
||||||
|
|
||||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||||
return pBlock;
|
return pBlock;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
stopGroupTableMergeScan(pOperator);
|
stopGroupTableMergeScan(pOperator);
|
||||||
if (pInfo->tableEndIndex >= tableListSize - 1) {
|
pInfo->currentGroupId++;
|
||||||
|
if (pInfo->currentGroupId >= taosArrayGetSize(pInfo->tableListInfo->pGroupList)) {
|
||||||
doSetOperatorCompleted(pOperator);
|
doSetOperatorCompleted(pOperator);
|
||||||
break;
|
return NULL;
|
||||||
}
|
}
|
||||||
pInfo->tableStartIndex = pInfo->tableEndIndex + 1;
|
|
||||||
pInfo->groupId =
|
|
||||||
((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId;
|
|
||||||
startGroupTableMergeScan(pOperator);
|
startGroupTableMergeScan(pOperator);
|
||||||
|
|
||||||
|
pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator);
|
||||||
|
if (pBlock != NULL) {
|
||||||
|
uint64_t* groupId = taosHashGet(pInfo->tableListInfo->map, &(pBlock->info.uid), sizeof(uint64_t));
|
||||||
|
if(groupId) pBlock->info.groupId = *groupId;
|
||||||
|
|
||||||
|
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||||
|
return pBlock;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
doSetOperatorCompleted(pOperator);
|
||||||
|
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
@ -2445,6 +2443,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
||||||
pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES);
|
pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES);
|
||||||
pInfo->queryId = queryId;
|
pInfo->queryId = queryId;
|
||||||
pInfo->taskId = taskId;
|
pInfo->taskId = taskId;
|
||||||
|
pInfo->currentGroupId = -1;
|
||||||
|
|
||||||
pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam));
|
pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam));
|
||||||
|
|
||||||
|
|
|
@ -1220,18 +1220,19 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
|
|
||||||
static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
// The number of parameters has been limited by the syntax definition
|
// The number of parameters has been limited by the syntax definition
|
||||||
uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
//uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
|
|
||||||
// The function return type has been set during syntax parsing
|
// The function return type has been set during syntax parsing
|
||||||
uint8_t para2Type = pFunc->node.resType.type;
|
uint8_t para2Type = pFunc->node.resType.type;
|
||||||
if (para2Type != TSDB_DATA_TYPE_BIGINT && para2Type != TSDB_DATA_TYPE_UBIGINT &&
|
//if (para2Type != TSDB_DATA_TYPE_BIGINT && para2Type != TSDB_DATA_TYPE_UBIGINT &&
|
||||||
para2Type != TSDB_DATA_TYPE_VARCHAR && para2Type != TSDB_DATA_TYPE_NCHAR &&
|
// para2Type != TSDB_DATA_TYPE_VARCHAR && para2Type != TSDB_DATA_TYPE_NCHAR &&
|
||||||
para2Type != TSDB_DATA_TYPE_TIMESTAMP) {
|
// para2Type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
// return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
//}
|
||||||
if ((para2Type == TSDB_DATA_TYPE_TIMESTAMP && IS_VAR_DATA_TYPE(para1Type)) ||
|
//if ((para2Type == TSDB_DATA_TYPE_TIMESTAMP && IS_VAR_DATA_TYPE(para1Type)) ||
|
||||||
(para2Type == TSDB_DATA_TYPE_BINARY && para1Type == TSDB_DATA_TYPE_NCHAR)) {
|
// (para2Type == TSDB_DATA_TYPE_BINARY && para1Type == TSDB_DATA_TYPE_NCHAR)) {
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
// return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
//}
|
||||||
|
|
||||||
int32_t para2Bytes = pFunc->node.resType.bytes;
|
int32_t para2Bytes = pFunc->node.resType.bytes;
|
||||||
if (IS_VAR_DATA_TYPE(para2Type)) {
|
if (IS_VAR_DATA_TYPE(para2Type)) {
|
||||||
|
@ -1279,8 +1280,7 @@ static bool validateTimestampDigits(const SValueNode* pVal) {
|
||||||
int32_t tsDigits = (int32_t)strlen(fraction);
|
int32_t tsDigits = (int32_t)strlen(fraction);
|
||||||
|
|
||||||
if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) {
|
if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) {
|
||||||
if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS ||
|
if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS || tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS ||
|
||||||
tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS ||
|
|
||||||
tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
|
tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1510,6 +1510,11 @@ static int32_t translateBlockDistInfoFunc(SFunctionNode* pFunc, char* pErrBuf, i
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateGroupKeyFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
pFunc->node.resType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||||
pEnv->calcMemSize = sizeof(STableBlockDistInfo);
|
pEnv->calcMemSize = sizeof(STableBlockDistInfo);
|
||||||
return true;
|
return true;
|
||||||
|
@ -2519,6 +2524,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
.processFunc = groupKeyFunction,
|
.processFunc = groupKeyFunction,
|
||||||
.finalizeFunc = groupKeyFinalize,
|
.finalizeFunc = groupKeyFinalize,
|
||||||
|
.pPartialFunc = "_group_key",
|
||||||
|
.pMergeFunc = "_group_key"
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -264,6 +264,7 @@ typedef struct SRateInfo {
|
||||||
|
|
||||||
typedef struct SGroupKeyInfo{
|
typedef struct SGroupKeyInfo{
|
||||||
bool hasResult;
|
bool hasResult;
|
||||||
|
bool isNull;
|
||||||
char data[];
|
char data[];
|
||||||
} SGroupKeyInfo;
|
} SGroupKeyInfo;
|
||||||
|
|
||||||
|
@ -5371,14 +5372,21 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
|
||||||
int32_t bytes = pInputCol->info.bytes;
|
int32_t bytes = pInputCol->info.bytes;
|
||||||
|
|
||||||
int32_t startIndex = pInput->startRowIndex;
|
int32_t startIndex = pInput->startRowIndex;
|
||||||
if (colDataIsNull_s(pInputCol, startIndex)) {
|
|
||||||
pInfo->hasResult = false;
|
//escape rest of data blocks to avoid first entry be overwritten.
|
||||||
|
if (pInfo->hasResult) {
|
||||||
goto _group_key_over;
|
goto _group_key_over;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (colDataIsNull_s(pInputCol, startIndex)) {
|
||||||
|
pInfo->isNull = true;
|
||||||
pInfo->hasResult = true;
|
pInfo->hasResult = true;
|
||||||
|
goto _group_key_over;
|
||||||
|
}
|
||||||
|
|
||||||
char* data = colDataGetData(pInputCol, startIndex);
|
char* data = colDataGetData(pInputCol, startIndex);
|
||||||
memcpy(pInfo->data, data, bytes);
|
memcpy(pInfo->data, data, bytes);
|
||||||
|
pInfo->hasResult = true;
|
||||||
|
|
||||||
_group_key_over:
|
_group_key_over:
|
||||||
|
|
||||||
|
@ -5393,7 +5401,12 @@ int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
|
||||||
SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
colDataAppend(pCol, pBlock->info.rows, pInfo->data, pInfo->hasResult ? false : true);
|
|
||||||
|
if (pInfo->hasResult) {
|
||||||
|
colDataAppend(pCol, pBlock->info.rows, pInfo->data, pInfo->isNull ? true : false);
|
||||||
|
} else {
|
||||||
|
pResInfo->numOfRes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return pResInfo->numOfRes;
|
return pResInfo->numOfRes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "fnLog.h"
|
#include "fnLog.h"
|
||||||
|
@ -25,6 +27,7 @@
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
// clang-foramt on
|
||||||
|
|
||||||
typedef struct SUdfdContext {
|
typedef struct SUdfdContext {
|
||||||
uv_loop_t * loop;
|
uv_loop_t * loop;
|
||||||
|
@ -544,7 +547,8 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static bool udfdRpcRfp(int32_t code) {
|
static bool udfdRpcRfp(int32_t code) {
|
||||||
if (code == TSDB_CODE_RPC_REDIRECT) {
|
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
|
||||||
|
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_APP_NOT_READY) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -652,8 +656,7 @@ void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) {
|
||||||
buf->base = ctx->inputBuf;
|
buf->base = ctx->inputBuf;
|
||||||
buf->len = ctx->inputCap;
|
buf->len = ctx->inputCap;
|
||||||
} else {
|
} else {
|
||||||
fnError("udfd can not allocate enough memory")
|
fnError("udfd can not allocate enough memory") buf->base = NULL;
|
||||||
buf->base = NULL;
|
|
||||||
buf->len = 0;
|
buf->len = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -664,8 +667,7 @@ void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) {
|
||||||
buf->base = ctx->inputBuf + ctx->inputLen;
|
buf->base = ctx->inputBuf + ctx->inputLen;
|
||||||
buf->len = ctx->inputCap - ctx->inputLen;
|
buf->len = ctx->inputCap - ctx->inputLen;
|
||||||
} else {
|
} else {
|
||||||
fnError("udfd can not allocate enough memory")
|
fnError("udfd can not allocate enough memory") buf->base = NULL;
|
||||||
buf->base = NULL;
|
|
||||||
buf->len = 0;
|
buf->len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,9 +346,11 @@ static void destroyVgDataBlockArray(SArray* pArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyLogicNode(SLogicNode* pNode) {
|
static void destroyLogicNode(SLogicNode* pNode) {
|
||||||
nodesDestroyList(pNode->pChildren);
|
|
||||||
nodesDestroyNode(pNode->pConditions);
|
|
||||||
nodesDestroyList(pNode->pTargets);
|
nodesDestroyList(pNode->pTargets);
|
||||||
|
nodesDestroyNode(pNode->pConditions);
|
||||||
|
nodesDestroyList(pNode->pChildren);
|
||||||
|
nodesDestroyNode(pNode->pLimit);
|
||||||
|
nodesDestroyNode(pNode->pSlimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyPhysiNode(SPhysiNode* pNode) {
|
static void destroyPhysiNode(SPhysiNode* pNode) {
|
||||||
|
@ -368,6 +370,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) {
|
||||||
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
||||||
destroyPhysiNode((SPhysiNode*)pNode);
|
destroyPhysiNode((SPhysiNode*)pNode);
|
||||||
nodesDestroyList(pNode->pScanCols);
|
nodesDestroyList(pNode->pScanCols);
|
||||||
|
nodesDestroyList(pNode->pScanPseudoCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode((SNode*)pNode->pInputDataBlockDesc); }
|
static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode((SNode*)pNode->pInputDataBlockDesc); }
|
||||||
|
@ -516,6 +519,9 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
nodesDestroyNode(pStmt->pWindow);
|
nodesDestroyNode(pStmt->pWindow);
|
||||||
nodesDestroyList(pStmt->pGroupByList);
|
nodesDestroyList(pStmt->pGroupByList);
|
||||||
nodesDestroyNode(pStmt->pHaving);
|
nodesDestroyNode(pStmt->pHaving);
|
||||||
|
nodesDestroyNode(pStmt->pRange);
|
||||||
|
nodesDestroyNode(pStmt->pEvery);
|
||||||
|
nodesDestroyNode(pStmt->pFill);
|
||||||
nodesDestroyList(pStmt->pOrderByList);
|
nodesDestroyList(pStmt->pOrderByList);
|
||||||
nodesDestroyNode((SNode*)pStmt->pLimit);
|
nodesDestroyNode((SNode*)pStmt->pLimit);
|
||||||
nodesDestroyNode((SNode*)pStmt->pSlimit);
|
nodesDestroyNode((SNode*)pStmt->pSlimit);
|
||||||
|
@ -779,6 +785,8 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
SInterpFuncLogicNode* pLogicNode = (SInterpFuncLogicNode*)pNode;
|
SInterpFuncLogicNode* pLogicNode = (SInterpFuncLogicNode*)pNode;
|
||||||
destroyLogicNode((SLogicNode*)pLogicNode);
|
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||||
nodesDestroyList(pLogicNode->pFuncs);
|
nodesDestroyList(pLogicNode->pFuncs);
|
||||||
|
nodesDestroyNode(pLogicNode->pFillValues);
|
||||||
|
nodesDestroyNode(pLogicNode->pTimeSeries);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_LOGIC_SUBPLAN: {
|
case QUERY_NODE_LOGIC_SUBPLAN: {
|
||||||
|
@ -793,14 +801,21 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
nodesDestroyList(((SQueryLogicPlan*)pNode)->pTopSubplans);
|
nodesDestroyList(((SQueryLogicPlan*)pNode)->pTopSubplans);
|
||||||
break;
|
break;
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
|
case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
|
case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN:
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
|
case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
|
||||||
destroyScanPhysiNode((SScanPhysiNode*)pNode);
|
destroyScanPhysiNode((SScanPhysiNode*)pNode);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
|
||||||
|
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: {
|
||||||
|
STableScanPhysiNode* pPhyNode = (STableScanPhysiNode*)pNode;
|
||||||
|
destroyScanPhysiNode((SScanPhysiNode*)pNode);
|
||||||
|
nodesDestroyList(pPhyNode->pDynamicScanFuncs);
|
||||||
|
nodesDestroyList(pPhyNode->pPartitionTags);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT: {
|
case QUERY_NODE_PHYSICAL_PLAN_PROJECT: {
|
||||||
SProjectPhysiNode* pPhyNode = (SProjectPhysiNode*)pNode;
|
SProjectPhysiNode* pPhyNode = (SProjectPhysiNode*)pNode;
|
||||||
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
||||||
|
@ -891,6 +906,8 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
destroyPhysiNode((SPhysiNode*)pPhyNode);
|
||||||
nodesDestroyList(pPhyNode->pExprs);
|
nodesDestroyList(pPhyNode->pExprs);
|
||||||
nodesDestroyList(pPhyNode->pFuncs);
|
nodesDestroyList(pPhyNode->pFuncs);
|
||||||
|
nodesDestroyNode(pPhyNode->pFillValues);
|
||||||
|
nodesDestroyNode(pPhyNode->pTimeSeries);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||||
|
@ -1220,6 +1237,7 @@ int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value) {
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDB_DATA_TYPE_VARCHAR:
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
case TSDB_DATA_TYPE_VARBINARY:
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
|
case TSDB_DATA_TYPE_JSON:
|
||||||
pNode->datum.p = (char*)value;
|
pNode->datum.p = (char*)value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1355,6 +1355,25 @@ static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EDealRes rewriteExprToGroupKeyFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(pFunc->functionName, "_group_key");
|
||||||
|
strcpy(pFunc->node.aliasName, ((SExprNode*)*pNode)->aliasName);
|
||||||
|
pCxt->errCode = nodesListMakeAppend(&pFunc->pParameterList, *pNode);
|
||||||
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
|
*pNode = (SNode*)pFunc;
|
||||||
|
pCxt->errCode = fmGetFuncInfo(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||||
|
}
|
||||||
|
pCxt->pCurrSelectStmt->hasAggFuncs = true;
|
||||||
|
|
||||||
|
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
SCheckExprForGroupByCxt* pCxt = (SCheckExprForGroupByCxt*)pContext;
|
SCheckExprForGroupByCxt* pCxt = (SCheckExprForGroupByCxt*)pContext;
|
||||||
if (!nodesIsExprNode(*pNode) || isAliasColumn(*pNode)) {
|
if (!nodesIsExprNode(*pNode) || isAliasColumn(*pNode)) {
|
||||||
|
@ -1371,10 +1390,10 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
if (isAggFunc(*pNode) && !isDistinctOrderBy(pCxt->pTranslateCxt)) {
|
if (isAggFunc(*pNode) && !isDistinctOrderBy(pCxt->pTranslateCxt)) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
SNode* pGroupNode;
|
SNode* pGroupNode = NULL;
|
||||||
FOREACH(pGroupNode, getGroupByList(pCxt->pTranslateCxt)) {
|
FOREACH(pGroupNode, getGroupByList(pCxt->pTranslateCxt)) {
|
||||||
if (nodesEqualNode(getGroupByNode(pGroupNode), *pNode)) {
|
if (nodesEqualNode(getGroupByNode(pGroupNode), *pNode)) {
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
||||||
|
@ -1432,6 +1451,25 @@ static int32_t rewriteColsToSelectValFunc(STranslateContext* pCxt, SSelectStmt*
|
||||||
return pCxt->errCode;
|
return pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EDealRes rewriteExprsToGroupKeyFuncImpl(SNode** pNode, void* pContext) {
|
||||||
|
STranslateContext* pCxt = pContext;
|
||||||
|
SNode* pPartKey = NULL;
|
||||||
|
FOREACH(pPartKey, pCxt->pCurrSelectStmt->pPartitionByList) {
|
||||||
|
if (nodesEqualNode(pPartKey, *pNode)) {
|
||||||
|
return rewriteExprToGroupKeyFunc(pCxt, pNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DEAL_RES_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteExprsToGroupKeyFunc(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
|
nodesRewriteExprs(pSelect->pProjectionList, rewriteExprsToGroupKeyFuncImpl, pCxt);
|
||||||
|
if (TSDB_CODE_SUCCESS == pCxt->errCode && !pSelect->isDistinct) {
|
||||||
|
nodesRewriteExprs(pSelect->pOrderByList, rewriteExprsToGroupKeyFuncImpl, pCxt);
|
||||||
|
}
|
||||||
|
return pCxt->errCode;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct CheckAggColCoexistCxt {
|
typedef struct CheckAggColCoexistCxt {
|
||||||
STranslateContext* pTranslateCxt;
|
STranslateContext* pTranslateCxt;
|
||||||
bool existAggFunc;
|
bool existAggFunc;
|
||||||
|
@ -1456,6 +1494,12 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
|
||||||
pCxt->existIndefiniteRowsFunc = true;
|
pCxt->existIndefiniteRowsFunc = true;
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
}
|
}
|
||||||
|
SNode* pPartKey = NULL;
|
||||||
|
FOREACH(pPartKey, pCxt->pTranslateCxt->pCurrSelectStmt->pPartitionByList) {
|
||||||
|
if (nodesEqualNode(pPartKey, pNode)) {
|
||||||
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isScanPseudoColumnFunc(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) {
|
if (isScanPseudoColumnFunc(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||||
pCxt->existCol = true;
|
pCxt->existCol = true;
|
||||||
}
|
}
|
||||||
|
@ -1485,6 +1529,9 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
||||||
if (cxt.existIndefiniteRowsFunc && cxt.existCol) {
|
if (cxt.existIndefiniteRowsFunc && cxt.existCol) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
|
if (cxt.existAggFunc && NULL != pSelect->pPartitionByList) {
|
||||||
|
return rewriteExprsToGroupKeyFunc(pCxt, pSelect);
|
||||||
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1840,10 +1887,7 @@ static int32_t createMultiResFuncsFromStar(STranslateContext* pCxt, SFunctionNod
|
||||||
code = createMultiResFuncs(pSrcFunc, pExprs, pOutput);
|
code = createMultiResFuncs(pSrcFunc, pExprs, pOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
|
||||||
nodesDestroyList(pExprs);
|
nodesDestroyList(pExprs);
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2463,8 +2507,24 @@ static SNode* createOrderByExpr(STranslateContext* pCxt) {
|
||||||
return (SNode*)pOrder;
|
return (SNode*)pOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from: select tail(expr, k, f) from t where_clause partition_by_clause order_by_clause ...
|
/* case 1:
|
||||||
// to: select expr from t where_clause order by _rowts desc limit k offset f
|
* in: select tail(expr, k, f) from t where_clause
|
||||||
|
* out: select expr from t where_clause order by _rowts desc limit k offset f
|
||||||
|
*
|
||||||
|
* case 2:
|
||||||
|
* in: select tail(expr, k, f) from t where_clause partition_by_clause
|
||||||
|
* out: select expr from t where_clause partition_by_clause sort by _rowts desc limit k offset f
|
||||||
|
*
|
||||||
|
* case 3:
|
||||||
|
* in: select tail(expr, k, f) from t where_clause order_by_clause limit_clause
|
||||||
|
* out: select expr from (
|
||||||
|
* select expr from t where_clause order by _rowts desc limit k offset f
|
||||||
|
* ) order_by_clause limit_clause
|
||||||
|
*
|
||||||
|
* case 4:
|
||||||
|
* in: select tail(expr, k, f) from t where_clause partition_by_clause limit_clause
|
||||||
|
* out:
|
||||||
|
*/
|
||||||
static int32_t rewriteTailStmt(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
static int32_t rewriteTailStmt(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (!pSelect->hasTailFunc) {
|
if (!pSelect->hasTailFunc) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -4963,6 +5023,7 @@ typedef struct SVgroupCreateTableBatch {
|
||||||
|
|
||||||
static void destroyCreateTbReq(SVCreateTbReq* pReq) {
|
static void destroyCreateTbReq(SVCreateTbReq* pReq) {
|
||||||
taosMemoryFreeClear(pReq->name);
|
taosMemoryFreeClear(pReq->name);
|
||||||
|
taosMemoryFreeClear(pReq->comment);
|
||||||
taosMemoryFreeClear(pReq->ntb.schemaRow.pSchema);
|
taosMemoryFreeClear(pReq->ntb.schemaRow.pSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4980,6 +5041,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
|
||||||
if (pStmt->pOptions->commentNull == false) {
|
if (pStmt->pOptions->commentNull == false) {
|
||||||
req.comment = strdup(pStmt->pOptions->comment);
|
req.comment = strdup(pStmt->pOptions->comment);
|
||||||
if (NULL == req.comment) {
|
if (NULL == req.comment) {
|
||||||
|
destroyCreateTbReq(&req);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
req.commentLen = strlen(pStmt->pOptions->comment);
|
req.commentLen = strlen(pStmt->pOptions->comment);
|
||||||
|
@ -5051,6 +5113,7 @@ static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) {
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i);
|
SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i);
|
||||||
taosMemoryFreeClear(pTableReq->name);
|
taosMemoryFreeClear(pTableReq->name);
|
||||||
|
taosMemoryFreeClear(pTableReq->comment);
|
||||||
|
|
||||||
if (pTableReq->type == TSDB_NORMAL_TABLE) {
|
if (pTableReq->type == TSDB_NORMAL_TABLE) {
|
||||||
taosMemoryFreeClear(pTableReq->ntb.schemaRow.pSchema);
|
taosMemoryFreeClear(pTableReq->ntb.schemaRow.pSchema);
|
||||||
|
|
|
@ -199,6 +199,20 @@ TEST_F(ParserSelectTest, tailFuncSemanticCheck) {
|
||||||
run("SELECT TAIL(c1, 10) FROM t1 GROUP BY c2", TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC);
|
run("SELECT TAIL(c1, 10) FROM t1 GROUP BY c2", TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserSelectTest, partitionBy) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT c1, c2 FROM t1 PARTITION BY c2");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), c2 FROM t1 PARTITION BY c2");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserSelectTest, partitionBySemanticCheck) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), c2, c3 FROM t1 PARTITION BY c2", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, groupBy) {
|
TEST_F(ParserSelectTest, groupBy) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
@ -213,6 +227,15 @@ TEST_F(ParserSelectTest, groupBy) {
|
||||||
run("SELECT COUNT(*), c1 + 10, c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c1 + 10, c2");
|
run("SELECT COUNT(*), c1 + 10, c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c1 + 10, c2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserSelectTest, groupBySemanticCheck) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT COUNT(*) cnt, c1 FROM t1 WHERE c1 > 0", TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||||
|
run("SELECT COUNT(*) cnt, c2 FROM t1 WHERE c1 > 0 GROUP BY c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION);
|
||||||
|
run("SELECT COUNT(*) cnt, c2 FROM t1 WHERE c1 > 0 PARTITION BY c2 GROUP BY c1",
|
||||||
|
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, orderBy) {
|
TEST_F(ParserSelectTest, orderBy) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
|
|
@ -450,6 +450,15 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
// set grouyp keys, agg funcs and having conditions
|
// set grouyp keys, agg funcs and having conditions
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
||||||
|
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_GROUP_BY, fmIsAggFunc, &pAgg->pAggFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite the expression in subsequent clauses
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
|
}
|
||||||
|
|
||||||
if (NULL != pSelect->pGroupByList) {
|
if (NULL != pSelect->pGroupByList) {
|
||||||
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
||||||
if (NULL == pAgg->pGroupKeys) {
|
if (NULL == pAgg->pGroupKeys) {
|
||||||
|
@ -462,15 +471,6 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
|
||||||
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_GROUP_BY, fmIsAggFunc, &pAgg->pAggFuncs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) {
|
||||||
pAgg->node.pConditions = nodesCloneNode(pSelect->pHaving);
|
pAgg->node.pConditions = nodesCloneNode(pSelect->pHaving);
|
||||||
if (NULL == pAgg->node.pConditions) {
|
if (NULL == pAgg->node.pConditions) {
|
||||||
|
@ -780,8 +780,8 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pProject->node.pLimit = (SNode*)pSelect->pLimit;
|
TSWAP(pProject->node.pLimit, pSelect->pLimit);
|
||||||
pProject->node.pSlimit = (SNode*)pSelect->pSlimit;
|
TSWAP(pProject->node.pSlimit, pSelect->pSlimit);
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@ -940,7 +940,7 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSort->node.pLimit = pSetOperator->pLimit;
|
TSWAP(pSort->node.pLimit, pSetOperator->pLimit);
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@ -973,7 +973,7 @@ static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pSetOperator->pOrderByList) {
|
if (NULL == pSetOperator->pOrderByList) {
|
||||||
pProject->node.pLimit = pSetOperator->pLimit;
|
TSWAP(pProject->node.pLimit, pSetOperator->pLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -1004,7 +1004,7 @@ static int32_t createSetOpAggLogicNode(SLogicPlanContext* pCxt, SSetOperator* pS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pSetOperator->pOrderByList) {
|
if (NULL == pSetOperator->pOrderByList) {
|
||||||
pAgg->node.pLimit = pSetOperator->pLimit;
|
TSWAP(pAgg->node.pSlimit, pSetOperator->pLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -682,7 +682,7 @@ static EOrder opkGetPrimaryKeyOrder(SSortLogicNode* pSort) {
|
||||||
static SNode* opkRewriteDownNode(SSortLogicNode* pSort) {
|
static SNode* opkRewriteDownNode(SSortLogicNode* pSort) {
|
||||||
SNode* pDownNode = nodesListGetNode(pSort->node.pChildren, 0);
|
SNode* pDownNode = nodesListGetNode(pSort->node.pChildren, 0);
|
||||||
// todo
|
// todo
|
||||||
pSort->node.pChildren = NULL;
|
NODES_CLEAR_LIST(pSort->node.pChildren);
|
||||||
return pDownNode;
|
return pDownNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,6 +1061,7 @@ static EDealRes partTagsOptRebuildTbanmeImpl(SNode** pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
strcpy(pFunc->functionName, "tbname");
|
strcpy(pFunc->functionName, "tbname");
|
||||||
pFunc->funcType = FUNCTION_TYPE_TBNAME;
|
pFunc->funcType = FUNCTION_TYPE_TBNAME;
|
||||||
|
pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType;
|
||||||
nodesDestroyNode(*pNode);
|
nodesDestroyNode(*pNode);
|
||||||
*pNode = (SNode*)pFunc;
|
*pNode = (SNode*)pFunc;
|
||||||
return DEAL_RES_IGNORE_CHILD;
|
return DEAL_RES_IGNORE_CHILD;
|
||||||
|
@ -1188,7 +1189,7 @@ static const SOptimizeRule optimizeRuleSet[] = {
|
||||||
{.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize},
|
{.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize},
|
||||||
{.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize},
|
{.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize},
|
||||||
{.pName = "SmaIndex", .optimizeFunc = smaOptimize},
|
{.pName = "SmaIndex", .optimizeFunc = smaOptimize},
|
||||||
// {.pName = "PartitionTags", .optimizeFunc = partTagsOptimize},
|
{.pName = "PartitionTags", .optimizeFunc = partTagsOptimize},
|
||||||
{.pName = "EliminateProject", .optimizeFunc = eliminateProjOptimize}
|
{.pName = "EliminateProject", .optimizeFunc = eliminateProjOptimize}
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -348,8 +348,8 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pPhysiNode->pLimit = pLogicNode->pLimit;
|
TSWAP(pPhysiNode->pLimit, pLogicNode->pLimit);
|
||||||
pPhysiNode->pSlimit = pLogicNode->pSlimit;
|
TSWAP(pPhysiNode->pSlimit, pLogicNode->pSlimit);
|
||||||
|
|
||||||
int32_t code = createDataBlockDesc(pCxt, pLogicNode->pTargets, &pPhysiNode->pOutputDataBlockDesc);
|
int32_t code = createDataBlockDesc(pCxt, pLogicNode->pTargets, &pPhysiNode->pOutputDataBlockDesc);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
@ -862,6 +862,9 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
nodesDestroyNode((SNode*)pIdfRowsFunc);
|
nodesDestroyNode((SNode*)pIdfRowsFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodesDestroyList(pPrecalcExprs);
|
||||||
|
nodesDestroyList(pFuncs);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,6 +916,9 @@ static int32_t createInterpFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pCh
|
||||||
nodesDestroyNode((SNode*)pInterpFunc);
|
nodesDestroyNode((SNode*)pInterpFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodesDestroyList(pPrecalcExprs);
|
||||||
|
nodesDestroyList(pFuncs);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,6 +1054,9 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
nodesDestroyNode((SNode*)pWindow);
|
nodesDestroyNode((SNode*)pWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodesDestroyList(pPrecalcExprs);
|
||||||
|
nodesDestroyList(pFuncs);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1241,6 +1250,9 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
||||||
nodesDestroyNode((SNode*)pPart);
|
nodesDestroyNode((SNode*)pPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodesDestroyList(pPrecalcExprs);
|
||||||
|
nodesDestroyList(pPartitionKeys);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,7 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
pMerge->pInputs = nodesCloneList(pPartChild->pTargets);
|
pMerge->pInputs = nodesCloneList(pPartChild->pTargets);
|
||||||
// NULL == pSubplan means 'merge node' replaces 'split node'.
|
// NULL != pSubplan means 'merge node' replaces 'split node'.
|
||||||
if (NULL == pSubplan) {
|
if (NULL == pSubplan) {
|
||||||
pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
|
pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
|
||||||
} else {
|
} else {
|
||||||
|
@ -561,6 +561,8 @@ static int32_t stbSplSplitState(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||||
static SNodeList* stbSplGetPartKeys(SLogicNode* pNode) {
|
static SNodeList* stbSplGetPartKeys(SLogicNode* pNode) {
|
||||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) {
|
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) {
|
||||||
return ((SScanLogicNode*)pNode)->pPartTags;
|
return ((SScanLogicNode*)pNode)->pPartTags;
|
||||||
|
} else if (QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode)) {
|
||||||
|
return ((SPartitionLogicNode*)pNode)->pPartitionKeys;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -571,14 +573,15 @@ static bool stbSplIsPartTbanme(SNodeList* pPartKeys) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SNode* pPartKey = nodesListGetNode(pPartKeys, 0);
|
SNode* pPartKey = nodesListGetNode(pPartKeys, 0);
|
||||||
return QUERY_NODE_FUNCTION == nodeType(pPartKey) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPartKey)->funcType;
|
return (QUERY_NODE_FUNCTION == nodeType(pPartKey) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPartKey)->funcType) ||
|
||||||
|
(QUERY_NODE_COLUMN == nodeType(pPartKey) && COLUMN_TYPE_TBNAME == ((SColumnNode*)pPartKey)->colType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool stbSplIsMultiTableWinodw(SWindowLogicNode* pWindow) {
|
static bool stbSplIsPartTableWinodw(SWindowLogicNode* pWindow) {
|
||||||
return stbSplIsPartTbanme(stbSplGetPartKeys((SLogicNode*)nodesListGetNode(pWindow->node.pChildren, 0)));
|
return stbSplIsPartTbanme(stbSplGetPartKeys((SLogicNode*)nodesListGetNode(pWindow->node.pChildren, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t stbSplSplitWindowForMergeTable(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
static int32_t stbSplSplitWindowForCrossTable(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||||
switch (((SWindowLogicNode*)pInfo->pSplitNode)->winType) {
|
switch (((SWindowLogicNode*)pInfo->pSplitNode)->winType) {
|
||||||
case WINDOW_TYPE_INTERVAL:
|
case WINDOW_TYPE_INTERVAL:
|
||||||
return stbSplSplitInterval(pCxt, pInfo);
|
return stbSplSplitInterval(pCxt, pInfo);
|
||||||
|
@ -592,7 +595,7 @@ static int32_t stbSplSplitWindowForMergeTable(SSplitContext* pCxt, SStableSplitI
|
||||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t stbSplSplitWindowForMultiTable(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
static int32_t stbSplSplitWindowForPartTable(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||||
if (pCxt->pPlanCxt->streamQuery) {
|
if (pCxt->pPlanCxt->streamQuery) {
|
||||||
SPLIT_FLAG_SET_MASK(pInfo->pSubplan->splitFlag, SPLIT_FLAG_STABLE_SPLIT);
|
SPLIT_FLAG_SET_MASK(pInfo->pSubplan->splitFlag, SPLIT_FLAG_STABLE_SPLIT);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -613,10 +616,10 @@ static int32_t stbSplSplitWindowForMultiTable(SSplitContext* pCxt, SStableSplitI
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||||
if (stbSplIsMultiTableWinodw((SWindowLogicNode*)pInfo->pSplitNode)) {
|
if (stbSplIsPartTableWinodw((SWindowLogicNode*)pInfo->pSplitNode)) {
|
||||||
return stbSplSplitWindowForMultiTable(pCxt, pInfo);
|
return stbSplSplitWindowForPartTable(pCxt, pInfo);
|
||||||
} else {
|
} else {
|
||||||
return stbSplSplitWindowForMergeTable(pCxt, pInfo);
|
return stbSplSplitWindowForCrossTable(pCxt, pInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,3 +40,9 @@ TEST_F(PlanDistinctTest, withOrderBy) {
|
||||||
|
|
||||||
run("select distinct c1 + 10 a from t1 order by a");
|
run("select distinct c1 + 10 a from t1 order by a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PlanDistinctTest, withLimit) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("SELECT DISTINCT c1 FROM t1 LIMIT 3");
|
||||||
|
}
|
||||||
|
|
|
@ -53,14 +53,6 @@ TEST_F(PlanGroupByTest, aggFunc) {
|
||||||
run("SELECT SUM(10), COUNT(c1) FROM t1 GROUP BY c2");
|
run("SELECT SUM(10), COUNT(c1) FROM t1 GROUP BY c2");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanGroupByTest, rewriteFunc) {
|
|
||||||
useDb("root", "test");
|
|
||||||
|
|
||||||
run("SELECT AVG(c1) FROM t1");
|
|
||||||
|
|
||||||
run("SELECT AVG(c1) FROM t1 GROUP BY c2");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PlanGroupByTest, selectFunc) {
|
TEST_F(PlanGroupByTest, selectFunc) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
@ -81,6 +73,8 @@ TEST_F(PlanGroupByTest, stable) {
|
||||||
|
|
||||||
run("SELECT COUNT(*) FROM st1");
|
run("SELECT COUNT(*) FROM st1");
|
||||||
|
|
||||||
|
run("SELECT c1 FROM st1 GROUP BY c1");
|
||||||
|
|
||||||
run("SELECT COUNT(*) FROM st1 GROUP BY c1");
|
run("SELECT COUNT(*) FROM st1 GROUP BY c1");
|
||||||
|
|
||||||
run("SELECT COUNT(*) FROM st1 PARTITION BY c2 GROUP BY c1");
|
run("SELECT COUNT(*) FROM st1 PARTITION BY c2 GROUP BY c1");
|
||||||
|
|
|
@ -57,9 +57,15 @@ TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
|
||||||
TEST_F(PlanOptimizeTest, PartitionTags) {
|
TEST_F(PlanOptimizeTest, PartitionTags) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("SELECT c1 FROM st1 PARTITION BY tag1");
|
run("SELECT c1, tag1 FROM st1 PARTITION BY tag1");
|
||||||
|
|
||||||
run("SELECT SUM(c1) FROM st1 GROUP BY tag1");
|
run("SELECT SUM(c1), tag1 FROM st1 PARTITION BY tag1");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), tag1 + 10 FROM st1 PARTITION BY tag1 + 10");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanOptimizeTest, eliminateProjection) {
|
TEST_F(PlanOptimizeTest, eliminateProjection) {
|
||||||
|
|
|
@ -34,6 +34,8 @@ TEST_F(PlanPartitionByTest, withAggFunc) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("select count(*) from t1 partition by c1");
|
run("select count(*) from t1 partition by c1");
|
||||||
|
|
||||||
|
run("select count(*), c1 from t1 partition by c1");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanPartitionByTest, withInterval) {
|
TEST_F(PlanPartitionByTest, withInterval) {
|
||||||
|
@ -41,8 +43,12 @@ TEST_F(PlanPartitionByTest, withInterval) {
|
||||||
|
|
||||||
// normal/child table
|
// normal/child table
|
||||||
run("select count(*) from t1 partition by c1 interval(10s)");
|
run("select count(*) from t1 partition by c1 interval(10s)");
|
||||||
|
|
||||||
|
run("select count(*), c1 from t1 partition by c1 interval(10s)");
|
||||||
// super table
|
// super table
|
||||||
run("select count(*) from st1 partition by tag1, tag2 interval(10s)");
|
run("select count(*) from st1 partition by tag1, tag2 interval(10s)");
|
||||||
|
|
||||||
|
run("select count(*), tag1 from st1 partition by tag1, tag2 interval(10s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanPartitionByTest, withGroupBy) {
|
TEST_F(PlanPartitionByTest, withGroupBy) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
|
// clang-format off
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
|
||||||
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
||||||
|
@ -147,13 +148,15 @@ int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTra
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pMsg, pInfo->msgInfo.pData, pInfo->msgInfo.len);
|
memcpy(pMsg, pInfo->msgInfo.pData, pInfo->msgInfo.len);
|
||||||
SRpcMsg rpcMsg = {.msgType = pInfo->msgType,
|
SRpcMsg rpcMsg = {
|
||||||
|
.msgType = pInfo->msgType,
|
||||||
.pCont = pMsg,
|
.pCont = pMsg,
|
||||||
.contLen = pInfo->msgInfo.len,
|
.contLen = pInfo->msgInfo.len,
|
||||||
.info.ahandle = (void*)pInfo,
|
.info.ahandle = (void*)pInfo,
|
||||||
.info.handle = pInfo->msgInfo.handle,
|
.info.handle = pInfo->msgInfo.handle,
|
||||||
.info.persistHandle = persistHandle,
|
.info.persistHandle = persistHandle,
|
||||||
.code = 0};
|
.code = 0
|
||||||
|
};
|
||||||
assert(pInfo->fp != NULL);
|
assert(pInfo->fp != NULL);
|
||||||
TRACE_SET_ROOTID(&rpcMsg.info.traceId, pInfo->requestId);
|
TRACE_SET_ROOTID(&rpcMsg.info.traceId, pInfo->requestId);
|
||||||
rpcSendRequestWithCtx(pTransporter, epSet, &rpcMsg, pTransporterId, rpcCtx);
|
rpcSendRequestWithCtx(pTransporter, epSet, &rpcMsg, pTransporterId, rpcCtx);
|
||||||
|
@ -221,6 +224,7 @@ void destroyQueryExecRes(SQueryExecRes* pRes) {
|
||||||
qError("invalid exec result for request type %d", pRes->msgType);
|
qError("invalid exec result for request type %d", pRes->msgType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len) {
|
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len) {
|
||||||
int32_t n = 0;
|
int32_t n = 0;
|
||||||
|
@ -372,7 +376,6 @@ end:
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
||||||
if (NULL == pSrc) {
|
if (NULL == pSrc) {
|
||||||
*pDst = NULL;
|
*pDst = NULL;
|
||||||
|
@ -400,7 +403,8 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
||||||
}
|
}
|
||||||
memcpy(*pDst, pSrc, sizeof(*pSrc));
|
memcpy(*pDst, pSrc, sizeof(*pSrc));
|
||||||
if (pSrc->vgHash) {
|
if (pSrc->vgHash) {
|
||||||
(*pDst)->vgHash = taosHashInit(taosHashGetSize(pSrc->vgHash), taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
(*pDst)->vgHash = taosHashInit(taosHashGetSize(pSrc->vgHash), taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true,
|
||||||
|
HASH_ENTRY_LOCK);
|
||||||
if (NULL == (*pDst)->vgHash) {
|
if (NULL == (*pDst)->vgHash) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -425,5 +429,3 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -735,6 +735,60 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
char *input = colDataGetData(pInput[0].columnData, i);
|
char *input = colDataGetData(pInput[0].columnData, i);
|
||||||
|
|
||||||
switch(outputType) {
|
switch(outputType) {
|
||||||
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(int8_t *)output = taosStr2Int8(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(int8_t *)output = taosStr2Int8(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(int8_t *)output, int8_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(int16_t *)output = taosStr2Int16(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(int16_t *)output = taosStr2Int16(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(int16_t *)output, int16_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_INT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(int32_t *)output = taosStr2Int32(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(int32_t *)output = taosStr2Int32(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(int32_t *)output, int32_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TSDB_DATA_TYPE_BIGINT: {
|
case TSDB_DATA_TYPE_BIGINT: {
|
||||||
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
*(int64_t *)output = taosStr2Int64(varDataVal(input), NULL, 10);
|
*(int64_t *)output = taosStr2Int64(varDataVal(input), NULL, 10);
|
||||||
|
@ -753,6 +807,60 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(uint8_t *)output = taosStr2UInt8(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(uint8_t *)output = taosStr2UInt8(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(uint8_t *)output, uint8_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(uint16_t *)output = taosStr2UInt16(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(uint16_t *)output = taosStr2UInt16(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(uint16_t *)output, uint16_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_UINT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(uint32_t *)output = taosStr2UInt32(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(uint32_t *)output = taosStr2UInt32(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(uint32_t *)output, uint32_t, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TSDB_DATA_TYPE_UBIGINT: {
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
*(uint64_t *)output = taosStr2UInt64(varDataVal(input), NULL, 10);
|
*(uint64_t *)output = taosStr2UInt64(varDataVal(input), NULL, 10);
|
||||||
|
@ -771,10 +879,64 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(float *)output = taosStr2Float(varDataVal(input), NULL);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(float *)output = taosStr2Float(newBuf, NULL);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(float *)output, float, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(double *)output = taosStr2Double(varDataVal(input), NULL);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(double *)output = taosStr2Double(newBuf, NULL);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(double *)output, double, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_BOOL: {
|
||||||
|
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
*(bool *)output = taosStr2Int8(varDataVal(input), NULL, 10);
|
||||||
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
newBuf[len] = 0;
|
||||||
|
*(bool *)output = taosStr2Int8(newBuf, NULL, 10);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
|
} else {
|
||||||
|
GET_TYPED_DATA(*(bool *)output, bool, inputType, input);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) {
|
if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
//not support
|
//convert to 0
|
||||||
return TSDB_CODE_FAILED;
|
*(int64_t *)output = 0;
|
||||||
} else {
|
} else {
|
||||||
GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input);
|
GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input);
|
||||||
}
|
}
|
||||||
|
@ -789,8 +951,16 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
len = sprintf(varDataVal(output), "%.*s", len, varDataVal(input));
|
len = sprintf(varDataVal(output), "%.*s", len, varDataVal(input));
|
||||||
varDataSetLen(output, len);
|
varDataSetLen(output, len);
|
||||||
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
//not support
|
char *newBuf = taosMemoryCalloc(1, inputLen);
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||||
|
if (len < 0) {
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
len = TMIN(len, outputLen - VARSTR_HEADER_SIZE);
|
||||||
|
memcpy(varDataVal(output), newBuf, len);
|
||||||
|
varDataSetLen(output, len);
|
||||||
|
taosMemoryFree(newBuf);
|
||||||
} else {
|
} else {
|
||||||
char tmp[400] = {0};
|
char tmp[400] = {0};
|
||||||
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
|
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
|
||||||
|
|
|
@ -468,7 +468,7 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){
|
||||||
}
|
}
|
||||||
|
|
||||||
void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar
|
void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar
|
||||||
int32_t inputLen = varDataLen(buf);
|
int32_t inputLen = varDataTLen(buf);
|
||||||
|
|
||||||
void* t = taosMemoryCalloc(1, inputLen);
|
void* t = taosMemoryCalloc(1, inputLen);
|
||||||
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
|
||||||
|
|
|
@ -111,7 +111,7 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg*
|
||||||
|
|
||||||
// enqueue
|
// enqueue
|
||||||
if (pData != NULL) {
|
if (pData != NULL) {
|
||||||
pData->type = STREAM_DATA_TYPE_SSDATA_BLOCK;
|
pData->type = STREAM_INPUT__DATA_BLOCK;
|
||||||
pData->srcVgId = pReq->dataSrcVgId;
|
pData->srcVgId = pReq->dataSrcVgId;
|
||||||
// decode
|
// decode
|
||||||
/*pData->blocks = pReq->data;*/
|
/*pData->blocks = pReq->data;*/
|
||||||
|
@ -146,7 +146,7 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
|
||||||
|
|
||||||
// enqueue
|
// enqueue
|
||||||
if (pData != NULL) {
|
if (pData != NULL) {
|
||||||
pData->type = STREAM_DATA_TYPE_SSDATA_BLOCK;
|
pData->type = STREAM_INPUT__DATA_RETRIEVE;
|
||||||
pData->srcVgId = 0;
|
pData->srcVgId = 0;
|
||||||
// decode
|
// decode
|
||||||
/*pData->blocks = pReq->data;*/
|
/*pData->blocks = pReq->data;*/
|
||||||
|
@ -170,7 +170,7 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
|
||||||
pCont->rspToTaskId = pReq->srcTaskId;
|
pCont->rspToTaskId = pReq->srcTaskId;
|
||||||
pCont->rspFromTaskId = pReq->dstTaskId;
|
pCont->rspFromTaskId = pReq->dstTaskId;
|
||||||
pRsp->pCont = buf;
|
pRsp->pCont = buf;
|
||||||
pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp);
|
pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamRetrieveRsp);
|
||||||
tmsgSendRsp(pRsp);
|
tmsgSendRsp(pRsp);
|
||||||
return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1;
|
return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,14 @@ int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock
|
||||||
ASSERT(pReq->blockNum == taosArrayGetSize(pReq->dataLen));
|
ASSERT(pReq->blockNum == taosArrayGetSize(pReq->dataLen));
|
||||||
|
|
||||||
for (int32_t i = 0; i < blockNum; i++) {
|
for (int32_t i = 0; i < blockNum; i++) {
|
||||||
int32_t len = *(int32_t*)taosArrayGet(pReq->dataLen, i);
|
/*int32_t len = *(int32_t*)taosArrayGet(pReq->dataLen, i);*/
|
||||||
SRetrieveTableRsp* pRetrieve = taosArrayGetP(pReq->data, i);
|
SRetrieveTableRsp* pRetrieve = taosArrayGetP(pReq->data, i);
|
||||||
SSDataBlock* pDataBlock = taosArrayGet(pArray, i);
|
SSDataBlock* pDataBlock = taosArrayGet(pArray, i);
|
||||||
blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data);
|
blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data);
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
|
pDataBlock->info.window.skey = be64toh(pRetrieve->skey);
|
||||||
|
pDataBlock->info.window.ekey = be64toh(pRetrieve->ekey);
|
||||||
|
|
||||||
pDataBlock->info.type = pRetrieve->streamBlockType;
|
pDataBlock->info.type = pRetrieve->streamBlockType;
|
||||||
pDataBlock->info.childId = pReq->upstreamChildId;
|
pDataBlock->info.childId = pReq->upstreamChildId;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +49,14 @@ int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock
|
||||||
}
|
}
|
||||||
taosArraySetSize(pArray, 1);
|
taosArraySetSize(pArray, 1);
|
||||||
SRetrieveTableRsp* pRetrieve = pReq->pRetrieve;
|
SRetrieveTableRsp* pRetrieve = pReq->pRetrieve;
|
||||||
SSDataBlock* pBlock = taosArrayGet(pArray, 0);
|
SSDataBlock* pDataBlock = taosArrayGet(pArray, 0);
|
||||||
blockCompressDecode(pBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data);
|
blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data);
|
||||||
|
// TODO: refactor
|
||||||
|
pDataBlock->info.window.skey = be64toh(pRetrieve->skey);
|
||||||
|
pDataBlock->info.window.ekey = be64toh(pRetrieve->ekey);
|
||||||
|
|
||||||
|
pDataBlock->info.type = pRetrieve->streamBlockType;
|
||||||
|
|
||||||
pData->blocks = pArray;
|
pData->blocks = pArray;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,8 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
|
||||||
pRetrieve->streamBlockType = pBlock->info.type;
|
pRetrieve->streamBlockType = pBlock->info.type;
|
||||||
pRetrieve->numOfRows = htonl(pBlock->info.rows);
|
pRetrieve->numOfRows = htonl(pBlock->info.rows);
|
||||||
pRetrieve->numOfCols = htonl(numOfCols);
|
pRetrieve->numOfCols = htonl(numOfCols);
|
||||||
|
pRetrieve->skey = htobe64(pBlock->info.window.skey);
|
||||||
|
pRetrieve->ekey = htobe64(pBlock->info.window.ekey);
|
||||||
|
|
||||||
int32_t actualLen = 0;
|
int32_t actualLen = 0;
|
||||||
blockCompressEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false);
|
blockCompressEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false);
|
||||||
|
@ -171,6 +173,8 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis
|
||||||
pRetrieve->completed = 1;
|
pRetrieve->completed = 1;
|
||||||
pRetrieve->streamBlockType = pBlock->info.type;
|
pRetrieve->streamBlockType = pBlock->info.type;
|
||||||
pRetrieve->numOfRows = htonl(pBlock->info.rows);
|
pRetrieve->numOfRows = htonl(pBlock->info.rows);
|
||||||
|
pRetrieve->skey = htobe64(pBlock->info.window.skey);
|
||||||
|
pRetrieve->ekey = htobe64(pBlock->info.window.ekey);
|
||||||
|
|
||||||
int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock);
|
int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock);
|
||||||
pRetrieve->numOfCols = htonl(numOfCols);
|
pRetrieve->numOfCols = htonl(numOfCols);
|
||||||
|
@ -296,7 +300,7 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
||||||
atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL);
|
atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ASSERT(pBlock->type == STREAM_DATA_TYPE_SSDATA_BLOCK);
|
ASSERT(pBlock->type == STREAM_INPUT__DATA_BLOCK);
|
||||||
|
|
||||||
qInfo("stream continue dispatching: task %d", pTask->taskId);
|
qInfo("stream continue dispatching: task %d", pTask->taskId);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) {
|
static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) {
|
||||||
void* exec = pTask->exec.executor;
|
void* exec = pTask->exec.executor;
|
||||||
|
bool hasData = false;
|
||||||
|
|
||||||
// set input
|
// set input
|
||||||
SStreamQueueItem* pItem = (SStreamQueueItem*)data;
|
SStreamQueueItem* pItem = (SStreamQueueItem*)data;
|
||||||
|
@ -27,7 +28,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
||||||
ASSERT(pTask->isDataScan);
|
ASSERT(pTask->isDataScan);
|
||||||
SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data;
|
SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data;
|
||||||
qSetStreamInput(exec, pSubmit->data, STREAM_DATA_TYPE_SUBMIT_BLOCK, false);
|
qSetStreamInput(exec, pSubmit->data, STREAM_DATA_TYPE_SUBMIT_BLOCK, false);
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK) {
|
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||||
SStreamDataBlock* pBlock = (SStreamDataBlock*)data;
|
SStreamDataBlock* pBlock = (SStreamDataBlock*)data;
|
||||||
SArray* blocks = pBlock->blocks;
|
SArray* blocks = pBlock->blocks;
|
||||||
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false);
|
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false);
|
||||||
|
@ -43,7 +44,16 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
||||||
if (qExecTask(exec, &output, &ts) < 0) {
|
if (qExecTask(exec, &output, &ts) < 0) {
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
if (output == NULL) break;
|
if (output == NULL) {
|
||||||
|
if (pItem->type == STREAM_INPUT__DATA_RETRIEVE && !hasData) {
|
||||||
|
SSDataBlock block = {0};
|
||||||
|
block.info.type = STREAM_PUSH_DATA;
|
||||||
|
block.info.childId = pTask->selfChildId;
|
||||||
|
taosArrayPush(pRes, &block);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hasData = true;
|
||||||
|
|
||||||
if (output->info.type == STREAM_RETRIEVE) {
|
if (output->info.type == STREAM_RETRIEVE) {
|
||||||
if (streamBroadcastToChildren(pTask, output) < 0) {
|
if (streamBroadcastToChildren(pTask, output) < 0) {
|
||||||
|
|
|
@ -89,6 +89,280 @@
|
||||||
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
||||||
//
|
//
|
||||||
|
|
||||||
|
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
// print log
|
||||||
|
syncAppendEntriesLog2("==syncNodeOnAppendEntriesCb==", pMsg);
|
||||||
|
|
||||||
|
// if already drop replica, do not process
|
||||||
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
||||||
|
syncNodeEventLog(ths, "recv sync-append-entries, maybe replica already dropped");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybe update term
|
||||||
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
|
}
|
||||||
|
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
// reset elect timer
|
||||||
|
if (pMsg->term == ths->pRaftStore->currentTerm) {
|
||||||
|
ths->leaderCache = pMsg->srcId;
|
||||||
|
syncNodeResetElectTimer(ths);
|
||||||
|
}
|
||||||
|
ASSERT(pMsg->dataLen >= 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
// return to follower state
|
||||||
|
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
|
syncNodeEventLog(ths, "recv sync-append-entries, candidate to follower");
|
||||||
|
|
||||||
|
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
||||||
|
|
||||||
|
// ret or reply?
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
SyncTerm localPreLogTerm = 0;
|
||||||
|
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||||
|
SSyncRaftEntry* pEntry = ths->pLogStore->getEntry(ths->pLogStore, pMsg->prevLogIndex);
|
||||||
|
if (pEntry == NULL) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "getEntry error, index:%ld, since %s", pMsg->prevLogIndex, terrstr());
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
localPreLogTerm = pEntry->term;
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool logOK =
|
||||||
|
(pMsg->prevLogIndex == SYNC_INDEX_INVALID) ||
|
||||||
|
((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) &&
|
||||||
|
(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogTerm == localPreLogTerm));
|
||||||
|
|
||||||
|
// reject request
|
||||||
|
if ((pMsg->term < ths->pRaftStore->currentTerm) ||
|
||||||
|
((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) {
|
||||||
|
do {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, reject, pre-index:%ld, pre-term:%lu, datalen:%d",
|
||||||
|
pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen);
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
||||||
|
pReply->srcId = ths->myRaftId;
|
||||||
|
pReply->destId = pMsg->srcId;
|
||||||
|
pReply->term = ths->pRaftStore->currentTerm;
|
||||||
|
pReply->success = false;
|
||||||
|
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pReply);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// accept request
|
||||||
|
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) {
|
||||||
|
// preIndex = -1, or has preIndex entry in local log
|
||||||
|
ASSERT(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore));
|
||||||
|
|
||||||
|
// has extra entries (> preIndex) in local log
|
||||||
|
bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore);
|
||||||
|
|
||||||
|
// has entries in SyncAppendEntries msg
|
||||||
|
bool hasAppendEntries = pMsg->dataLen > 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, accept, pre-index:%ld, pre-term:%lu, datalen:%d",
|
||||||
|
pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen);
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if (hasExtraEntries && hasAppendEntries) {
|
||||||
|
// not conflict by default
|
||||||
|
bool conflict = false;
|
||||||
|
|
||||||
|
SyncIndex extraIndex = pMsg->prevLogIndex + 1;
|
||||||
|
SSyncRaftEntry* pExtraEntry = ths->pLogStore->getEntry(ths->pLogStore, extraIndex);
|
||||||
|
if (pExtraEntry == NULL) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "getEntry error2, index:%ld, since %s", extraIndex, terrstr());
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||||
|
if (pAppendEntry == NULL) {
|
||||||
|
syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// log not match, conflict
|
||||||
|
ASSERT(extraIndex == pAppendEntry->index);
|
||||||
|
if (pExtraEntry->term != pAppendEntry->term) {
|
||||||
|
conflict = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conflict) {
|
||||||
|
// roll back
|
||||||
|
SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore);
|
||||||
|
SyncIndex delEnd = extraIndex;
|
||||||
|
|
||||||
|
sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld", conflict, delBegin, delEnd);
|
||||||
|
|
||||||
|
// notice! reverse roll back!
|
||||||
|
for (SyncIndex index = delEnd; index >= delBegin; --index) {
|
||||||
|
if (ths->pFsm->FpRollBackCb != NULL) {
|
||||||
|
SSyncRaftEntry* pRollBackEntry = ths->pLogStore->getEntry(ths->pLogStore, index);
|
||||||
|
if (pRollBackEntry == NULL) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "getEntry error3, index:%ld, since %s", index, terrstr());
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pRollBackEntry->msgType != TDMT_SYNC_NOOP) {
|
||||||
|
if (syncUtilUserRollback(pRollBackEntry->msgType)) {
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg);
|
||||||
|
|
||||||
|
SFsmCbMeta cbMeta = {0};
|
||||||
|
cbMeta.index = pRollBackEntry->index;
|
||||||
|
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
||||||
|
cbMeta.isWeak = pRollBackEntry->isWeak;
|
||||||
|
cbMeta.code = 0;
|
||||||
|
cbMeta.state = ths->state;
|
||||||
|
cbMeta.seqNum = pRollBackEntry->seqNum;
|
||||||
|
ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, cbMeta);
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncEntryDestory(pRollBackEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete confict entries
|
||||||
|
ths->pLogStore->truncate(ths->pLogStore, extraIndex);
|
||||||
|
|
||||||
|
// append new entries
|
||||||
|
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
||||||
|
|
||||||
|
// pre commit
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncEntry2OriginalRpc(pAppendEntry, &rpcMsg);
|
||||||
|
if (ths->pFsm != NULL) {
|
||||||
|
// if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_SYNC_NOOP) {
|
||||||
|
if (ths->pFsm->FpPreCommitCb != NULL && syncUtilUserPreCommit(pAppendEntry->originalRpcType)) {
|
||||||
|
SFsmCbMeta cbMeta = {0};
|
||||||
|
cbMeta.index = pAppendEntry->index;
|
||||||
|
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
||||||
|
cbMeta.isWeak = pAppendEntry->isWeak;
|
||||||
|
cbMeta.code = 2;
|
||||||
|
cbMeta.state = ths->state;
|
||||||
|
cbMeta.seqNum = pAppendEntry->seqNum;
|
||||||
|
ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, cbMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
}
|
||||||
|
|
||||||
|
// free memory
|
||||||
|
syncEntryDestory(pExtraEntry);
|
||||||
|
syncEntryDestory(pAppendEntry);
|
||||||
|
|
||||||
|
} else if (hasExtraEntries && !hasAppendEntries) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
} else if (!hasExtraEntries && hasAppendEntries) {
|
||||||
|
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||||
|
if (pAppendEntry == NULL) {
|
||||||
|
syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry2 error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append new entries
|
||||||
|
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
||||||
|
|
||||||
|
// pre commit
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncEntry2OriginalRpc(pAppendEntry, &rpcMsg);
|
||||||
|
if (ths->pFsm != NULL) {
|
||||||
|
// if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_SYNC_NOOP) {
|
||||||
|
if (ths->pFsm->FpPreCommitCb != NULL && syncUtilUserPreCommit(pAppendEntry->originalRpcType)) {
|
||||||
|
SFsmCbMeta cbMeta = {0};
|
||||||
|
cbMeta.index = pAppendEntry->index;
|
||||||
|
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
||||||
|
cbMeta.isWeak = pAppendEntry->isWeak;
|
||||||
|
cbMeta.code = 3;
|
||||||
|
cbMeta.state = ths->state;
|
||||||
|
cbMeta.seqNum = pAppendEntry->seqNum;
|
||||||
|
ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, cbMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
|
||||||
|
// free memory
|
||||||
|
syncEntryDestory(pAppendEntry);
|
||||||
|
|
||||||
|
} else if (!hasExtraEntries && !hasAppendEntries) {
|
||||||
|
// do nothing
|
||||||
|
|
||||||
|
} else {
|
||||||
|
syncNodeLog3("", ths);
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
||||||
|
pReply->srcId = ths->myRaftId;
|
||||||
|
pReply->destId = pMsg->srcId;
|
||||||
|
pReply->term = ths->pRaftStore->currentTerm;
|
||||||
|
pReply->success = true;
|
||||||
|
|
||||||
|
if (hasAppendEntries) {
|
||||||
|
pReply->matchIndex = pMsg->prevLogIndex + 1;
|
||||||
|
} else {
|
||||||
|
pReply->matchIndex = pMsg->prevLogIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pReply);
|
||||||
|
|
||||||
|
// maybe update commit index from leader
|
||||||
|
if (pMsg->commitIndex > ths->commitIndex) {
|
||||||
|
// has commit entry in local
|
||||||
|
if (pMsg->commitIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||||
|
SyncIndex beginIndex = ths->commitIndex + 1;
|
||||||
|
SyncIndex endIndex = pMsg->commitIndex;
|
||||||
|
|
||||||
|
// update commit index
|
||||||
|
ths->commitIndex = pMsg->commitIndex;
|
||||||
|
|
||||||
|
// call back Wal
|
||||||
|
ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
||||||
|
|
||||||
|
int32_t code = syncNodeCommit(ths, beginIndex, endIndex, ths->state);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
@ -352,6 +626,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,78 @@
|
||||||
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
// print log
|
||||||
|
syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplyCb==", pMsg);
|
||||||
|
|
||||||
|
// if already drop replica, do not process
|
||||||
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
||||||
|
syncNodeEventLog(ths, "recv sync-append-entries-reply, maybe replica already dropped");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop stale response
|
||||||
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%lu, drop stale response", pMsg->term);
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
syncNodeEventLog(ths, "recv sync-append-entries-reply, before");
|
||||||
|
}
|
||||||
|
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pNextIndex", ths->pNextIndex);
|
||||||
|
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pMatchIndex", ths->pMatchIndex);
|
||||||
|
|
||||||
|
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
||||||
|
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%lu", pMsg->term);
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
if (pMsg->success) {
|
||||||
|
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
|
||||||
|
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
||||||
|
|
||||||
|
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
|
||||||
|
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
||||||
|
|
||||||
|
// maybe commit
|
||||||
|
syncMaybeAdvanceCommitIndex(ths);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
||||||
|
|
||||||
|
// notice! int64, uint64
|
||||||
|
if (nextIndex > SYNC_INDEX_BEGIN) {
|
||||||
|
--nextIndex;
|
||||||
|
} else {
|
||||||
|
nextIndex = SYNC_INDEX_BEGIN;
|
||||||
|
}
|
||||||
|
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
syncNodeEventLog(ths, "recv sync-append-entries-reply, after");
|
||||||
|
}
|
||||||
|
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pNextIndex", ths->pNextIndex);
|
||||||
|
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pMatchIndex", ths->pMatchIndex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
char logBuf[128] = {0};
|
char logBuf[128] = {0};
|
||||||
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnAppendEntriesReplyCb== term:%lu", ths->pRaftStore->currentTerm);
|
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnAppendEntriesReplyCb== term:%lu", ths->pRaftStore->currentTerm);
|
||||||
syncAppendEntriesReplyLog2(logBuf, pMsg);
|
syncAppendEntriesReplyLog2(logBuf, pMsg);
|
||||||
|
@ -96,6 +168,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
|
@ -45,6 +45,75 @@
|
||||||
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
syncRequestVoteLog2("==syncNodeOnRequestVoteCb==", pMsg);
|
||||||
|
|
||||||
|
// if already drop replica, do not process
|
||||||
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
||||||
|
do {
|
||||||
|
char logBuf[256];
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
|
"recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, maybe replica already dropped",
|
||||||
|
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm);
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybe update term
|
||||||
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
|
}
|
||||||
|
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
bool logOK = (pMsg->lastLogTerm > ths->pLogStore->getLastTerm(ths->pLogStore)) ||
|
||||||
|
((pMsg->lastLogTerm == ths->pLogStore->getLastTerm(ths->pLogStore)) &&
|
||||||
|
(pMsg->lastLogIndex >= ths->pLogStore->getLastIndex(ths->pLogStore)));
|
||||||
|
bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK &&
|
||||||
|
((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId))));
|
||||||
|
if (grant) {
|
||||||
|
// maybe has already voted for pMsg->srcId
|
||||||
|
// vote again, no harm
|
||||||
|
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
||||||
|
|
||||||
|
// forbid elect for this round
|
||||||
|
syncNodeResetElectTimer(ths);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send msg
|
||||||
|
SyncRequestVoteReply* pReply = syncRequestVoteReplyBuild(ths->vgId);
|
||||||
|
pReply->srcId = ths->myRaftId;
|
||||||
|
pReply->destId = pMsg->srcId;
|
||||||
|
pReply->term = ths->pRaftStore->currentTerm;
|
||||||
|
pReply->voteGranted = grant;
|
||||||
|
|
||||||
|
// trace log
|
||||||
|
do {
|
||||||
|
char logBuf[256];
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
|
"recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, reply-grant:%d", host, port,
|
||||||
|
pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted);
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncRequestVoteReply2RpcMsg(pReply, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||||
|
syncRequestVoteReplyDestroy(pReply);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
char logBuf[128] = {0};
|
char logBuf[128] = {0};
|
||||||
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteCb== term:%lu", ths->pRaftStore->currentTerm);
|
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteCb== term:%lu", ths->pRaftStore->currentTerm);
|
||||||
syncRequestVoteLog2(logBuf, pMsg);
|
syncRequestVoteLog2(logBuf, pMsg);
|
||||||
|
@ -81,6 +150,7 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) {
|
static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) {
|
||||||
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
||||||
|
|
|
@ -40,6 +40,72 @@
|
||||||
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
// print log
|
||||||
|
char logBuf[128] = {0};
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%lu", ths->pRaftStore->currentTerm);
|
||||||
|
syncRequestVoteReplyLog2(logBuf, pMsg);
|
||||||
|
|
||||||
|
// if already drop replica, do not process
|
||||||
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
||||||
|
sInfo("recv SyncRequestVoteReply, maybe replica already dropped");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop stale response
|
||||||
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
|
sTrace("recv SyncRequestVoteReply, drop stale response, receive_term:%lu current_term:%lu", pMsg->term,
|
||||||
|
ths->pRaftStore->currentTerm);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASSERT(!(pMsg->term > ths->pRaftStore->currentTerm));
|
||||||
|
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
||||||
|
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
|
char logBuf[128] = {0};
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%lu current:%lu", pMsg->term,
|
||||||
|
ths->pRaftStore->currentTerm);
|
||||||
|
syncNodePrint2(logBuf, ths);
|
||||||
|
sError("%s", logBuf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
// This tallies votes even when the current state is not Candidate,
|
||||||
|
// but they won't be looked at, so it doesn't matter.
|
||||||
|
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
|
votesRespondAdd(ths->pVotesRespond, pMsg);
|
||||||
|
if (pMsg->voteGranted) {
|
||||||
|
// add vote
|
||||||
|
voteGrantedVote(ths->pVotesGranted, pMsg);
|
||||||
|
|
||||||
|
// maybe to leader
|
||||||
|
if (voteGrantedMajority(ths->pVotesGranted)) {
|
||||||
|
if (!ths->pVotesGranted->toLeader) {
|
||||||
|
syncNodeCandidate2Leader(ths);
|
||||||
|
|
||||||
|
// prevent to leader again!
|
||||||
|
ths->pVotesGranted->toLeader = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
;
|
||||||
|
// do nothing
|
||||||
|
// UNCHANGED <<votesGranted, voterLog>>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
char logBuf[128] = {0};
|
char logBuf[128] = {0};
|
||||||
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%lu", ths->pRaftStore->currentTerm);
|
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%lu", ths->pRaftStore->currentTerm);
|
||||||
syncRequestVoteReplyLog2(logBuf, pMsg);
|
syncRequestVoteReplyLog2(logBuf, pMsg);
|
||||||
|
@ -93,6 +159,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
|
@ -105,6 +105,13 @@ typedef SRpcCtxVal STransCtxVal;
|
||||||
typedef SRpcInfo STrans;
|
typedef SRpcInfo STrans;
|
||||||
typedef SRpcConnInfo STransHandleInfo;
|
typedef SRpcConnInfo STransHandleInfo;
|
||||||
|
|
||||||
|
// ref mgt
|
||||||
|
// handle
|
||||||
|
typedef struct SExHandle {
|
||||||
|
void* handle;
|
||||||
|
int64_t refId;
|
||||||
|
void* pThrd;
|
||||||
|
} SExHandle;
|
||||||
/*convet from fqdn to ip */
|
/*convet from fqdn to ip */
|
||||||
typedef struct SCvtAddr {
|
typedef struct SCvtAddr {
|
||||||
char ip[TSDB_FQDN_LEN];
|
char ip[TSDB_FQDN_LEN];
|
||||||
|
@ -118,9 +125,10 @@ typedef struct {
|
||||||
void* ahandle; // handle provided by app
|
void* ahandle; // handle provided by app
|
||||||
tmsg_t msgType; // message type
|
tmsg_t msgType; // message type
|
||||||
int8_t connType; // connection type cli/srv
|
int8_t connType; // connection type cli/srv
|
||||||
int64_t rid; // refId returned by taosAddRef
|
|
||||||
|
|
||||||
int8_t retryCount;
|
int8_t retryCnt;
|
||||||
|
int8_t retryLimit;
|
||||||
|
// bool setMaxRetry;
|
||||||
STransCtx appCtx; //
|
STransCtx appCtx; //
|
||||||
STransMsg* pRsp; // for synchronous API
|
STransMsg* pRsp; // for synchronous API
|
||||||
tsem_t* pSem; // for synchronous API
|
tsem_t* pSem; // for synchronous API
|
||||||
|
@ -239,6 +247,32 @@ int transSendAsync(SAsyncPool* pool, queue* mq);
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define ASYNC_CHECK_HANDLE(exh1, id) \
|
||||||
|
do { \
|
||||||
|
if (id > 0) { \
|
||||||
|
tTrace("handle step1"); \
|
||||||
|
SExHandle* exh2 = transAcquireExHandle(refMgt, id); \
|
||||||
|
if (exh2 == NULL || id != exh2->refId) { \
|
||||||
|
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \
|
||||||
|
exh2 ? exh2->refId : 0, id); \
|
||||||
|
goto _return1; \
|
||||||
|
} \
|
||||||
|
} else if (id == 0) { \
|
||||||
|
tTrace("handle step2"); \
|
||||||
|
SExHandle* exh2 = transAcquireExHandle(refMgt, id); \
|
||||||
|
if (exh2 == NULL || id == exh2->refId) { \
|
||||||
|
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, id, \
|
||||||
|
exh2 ? exh2->refId : 0); \
|
||||||
|
goto _return1; \
|
||||||
|
} else { \
|
||||||
|
id = exh1->refId; \
|
||||||
|
} \
|
||||||
|
} else if (id < 0) { \
|
||||||
|
tTrace("handle step3"); \
|
||||||
|
goto _return2; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
int transInitBuffer(SConnBuffer* buf);
|
int transInitBuffer(SConnBuffer* buf);
|
||||||
int transClearBuffer(SConnBuffer* buf);
|
int transClearBuffer(SConnBuffer* buf);
|
||||||
int transDestroyBuffer(SConnBuffer* buf);
|
int transDestroyBuffer(SConnBuffer* buf);
|
||||||
|
@ -349,21 +383,13 @@ void transDQDestroy(SDelayQueue* queue);
|
||||||
|
|
||||||
int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs);
|
int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs);
|
||||||
|
|
||||||
void transPrintEpSet(SEpSet* pEpSet);
|
// void transPrintEpSet(SEpSet* pEpSet);
|
||||||
bool transEpSetIsEqual(SEpSet* a, SEpSet* b);
|
bool transEpSetIsEqual(SEpSet* a, SEpSet* b);
|
||||||
/*
|
/*
|
||||||
* init global func
|
* init global func
|
||||||
*/
|
*/
|
||||||
void transThreadOnce();
|
void transThreadOnce();
|
||||||
|
|
||||||
// ref mgt
|
|
||||||
// handle
|
|
||||||
typedef struct SExHandle {
|
|
||||||
void* handle;
|
|
||||||
int64_t refId;
|
|
||||||
void* pThrd;
|
|
||||||
} SExHandle;
|
|
||||||
|
|
||||||
void transInitEnv();
|
void transInitEnv();
|
||||||
int32_t transOpenExHandleMgt(int size);
|
int32_t transOpenExHandleMgt(int size);
|
||||||
void transCloseExHandleMgt(int32_t mgt);
|
void transCloseExHandleMgt(int32_t mgt);
|
||||||
|
|
|
@ -79,6 +79,7 @@ void* rpcOpen(const SRpcInit* pInit) {
|
||||||
return pRpc;
|
return pRpc;
|
||||||
}
|
}
|
||||||
void rpcClose(void* arg) {
|
void rpcClose(void* arg) {
|
||||||
|
tInfo("start to close rpc");
|
||||||
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
||||||
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
||||||
transCloseExHandleMgt(pRpc->refMgt);
|
transCloseExHandleMgt(pRpc->refMgt);
|
||||||
|
|
|
@ -25,7 +25,6 @@ typedef struct SCliConn {
|
||||||
uv_write_t writeReq;
|
uv_write_t writeReq;
|
||||||
|
|
||||||
void* hostThrd;
|
void* hostThrd;
|
||||||
int hThrdIdx;
|
|
||||||
|
|
||||||
SConnBuffer readBuf;
|
SConnBuffer readBuf;
|
||||||
STransQueue cliMsgs;
|
STransQueue cliMsgs;
|
||||||
|
@ -36,6 +35,7 @@ typedef struct SCliConn {
|
||||||
bool broken; // link broken or not
|
bool broken; // link broken or not
|
||||||
ConnStatus status; //
|
ConnStatus status; //
|
||||||
|
|
||||||
|
int64_t refId;
|
||||||
char* ip;
|
char* ip;
|
||||||
uint32_t port;
|
uint32_t port;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ typedef struct SCliMsg {
|
||||||
int sent; //(0: no send, 1: alread sent)
|
int sent; //(0: no send, 1: alread sent)
|
||||||
} SCliMsg;
|
} SCliMsg;
|
||||||
|
|
||||||
typedef struct SCliThrdObj {
|
typedef struct SCliThrd {
|
||||||
TdThread thread; // tid
|
TdThread thread; // tid
|
||||||
int64_t pid; // pid
|
int64_t pid; // pid
|
||||||
uv_loop_t* loop;
|
uv_loop_t* loop;
|
||||||
|
@ -72,13 +72,13 @@ typedef struct SCliThrdObj {
|
||||||
SCvtAddr cvtAddr;
|
SCvtAddr cvtAddr;
|
||||||
|
|
||||||
bool quit;
|
bool quit;
|
||||||
} SCliThrdObj;
|
} SCliThrd;
|
||||||
|
|
||||||
typedef struct SCliObj {
|
typedef struct SCliObj {
|
||||||
char label[TSDB_LABEL_LEN];
|
char label[TSDB_LABEL_LEN];
|
||||||
int32_t index;
|
int32_t index;
|
||||||
int numOfThreads;
|
int numOfThreads;
|
||||||
SCliThrdObj** pThreadObj;
|
SCliThrd** pThreadObj;
|
||||||
} SCliObj;
|
} SCliObj;
|
||||||
|
|
||||||
typedef struct SConnList {
|
typedef struct SConnList {
|
||||||
|
@ -106,11 +106,18 @@ static void cliAsyncCb(uv_async_t* handle);
|
||||||
|
|
||||||
static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg);
|
static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg);
|
||||||
|
|
||||||
static SCliConn* cliCreateConn(SCliThrdObj* thrd);
|
static SCliConn* cliCreateConn(SCliThrd* thrd);
|
||||||
static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
||||||
static void cliDestroy(uv_handle_t* handle);
|
static void cliDestroy(uv_handle_t* handle);
|
||||||
static void cliSend(SCliConn* pConn);
|
static void cliSend(SCliConn* pConn);
|
||||||
|
|
||||||
|
static bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) {
|
||||||
|
if (code != 0) return false;
|
||||||
|
if (pCtx->retryCnt == 0) return false;
|
||||||
|
if (transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr);
|
void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr);
|
||||||
/*
|
/*
|
||||||
* set TCP connection timeout per-socket level
|
* set TCP connection timeout per-socket level
|
||||||
|
@ -122,14 +129,14 @@ static void cliHandleResp(SCliConn* conn);
|
||||||
static void cliHandleExcept(SCliConn* conn);
|
static void cliHandleExcept(SCliConn* conn);
|
||||||
|
|
||||||
// handle req from app
|
// handle req from app
|
||||||
static void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
static void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd);
|
||||||
static void cliHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd);
|
||||||
static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd);
|
||||||
static void cliHandleUpdate(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd);
|
||||||
static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrdObj* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease,
|
static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL,
|
||||||
NULL, cliHandleUpdate};
|
cliHandleUpdate};
|
||||||
|
|
||||||
static void cliSendQuit(SCliThrdObj* thrd);
|
static void cliSendQuit(SCliThrd* thrd);
|
||||||
static void destroyUserdata(STransMsg* userdata);
|
static void destroyUserdata(STransMsg* userdata);
|
||||||
|
|
||||||
static int cliRBChoseIdx(STrans* pTransInst);
|
static int cliRBChoseIdx(STrans* pTransInst);
|
||||||
|
@ -137,8 +144,8 @@ static int cliRBChoseIdx(STrans* pTransInst);
|
||||||
static void destroyCmsg(SCliMsg* cmsg);
|
static void destroyCmsg(SCliMsg* cmsg);
|
||||||
static void transDestroyConnCtx(STransConnCtx* ctx);
|
static void transDestroyConnCtx(STransConnCtx* ctx);
|
||||||
// thread obj
|
// thread obj
|
||||||
static SCliThrdObj* createThrdObj();
|
static SCliThrd* createThrdObj();
|
||||||
static void destroyThrdObj(SCliThrdObj* pThrd);
|
static void destroyThrdObj(SCliThrd* pThrd);
|
||||||
|
|
||||||
static void cliWalkCb(uv_handle_t* handle, void* arg);
|
static void cliWalkCb(uv_handle_t* handle, void* arg);
|
||||||
|
|
||||||
|
@ -154,7 +161,6 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CLI_RELEASE_UV(loop) \
|
#define CLI_RELEASE_UV(loop) \
|
||||||
do { \
|
do { \
|
||||||
uv_walk(loop, cliWalkCb, NULL); \
|
uv_walk(loop, cliWalkCb, NULL); \
|
||||||
|
@ -168,17 +174,23 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
||||||
snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \
|
snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CONN_HOST_THREAD_IDX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
#define CONN_HOST_THREAD_IDX1(idx, exh, refId, pThrd) \
|
||||||
|
do { \
|
||||||
|
if (exh == NULL) { \
|
||||||
|
idx = -1; \
|
||||||
|
} else { \
|
||||||
|
ASYNC_CHECK_HANDLE((exh), refId); \
|
||||||
|
pThrd = (SCliThrd*)(exh)->pThrd; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label)
|
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label)
|
||||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||||
do { \
|
do { \
|
||||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||||
int connStatus = conn->status; \
|
|
||||||
uint64_t ahandle = head->ahandle; \
|
uint64_t ahandle = head->ahandle; \
|
||||||
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \
|
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \
|
||||||
conn->status = ConnRelease; \
|
|
||||||
transClearBuffer(&conn->readBuf); \
|
transClearBuffer(&conn->readBuf); \
|
||||||
transFreeMsg(transContFromHead((char*)head)); \
|
transFreeMsg(transContFromHead((char*)head)); \
|
||||||
tDebug("%s conn %p receive release request, ref: %d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); \
|
tDebug("%s conn %p receive release request, ref: %d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); \
|
||||||
|
@ -187,9 +199,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
||||||
} \
|
} \
|
||||||
destroyCmsg(pMsg); \
|
destroyCmsg(pMsg); \
|
||||||
cliReleaseUnfinishedMsg(conn); \
|
cliReleaseUnfinishedMsg(conn); \
|
||||||
if (connStatus != ConnInPool) { \
|
addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); \
|
||||||
addConnToPool(((SCliThrdObj*)conn->hostThrd)->pool, conn); \
|
|
||||||
} \
|
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -255,8 +265,25 @@ 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_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) \
|
||||||
|
do { \
|
||||||
|
(epSet)->inUse = (++((epSet)->inUse)) % ((epSet)->numOfEps); \
|
||||||
|
} while (0)
|
||||||
|
#define EPSET_DEBUG_STR(epSet, tbuf) \
|
||||||
|
do { \
|
||||||
|
int len = snprintf(tbuf, sizeof(tbuf), "epset:{"); \
|
||||||
|
for (int i = 0; i < (epSet)->numOfEps; i++) { \
|
||||||
|
if (i == (epSet)->numOfEps - 1) { \
|
||||||
|
len += snprintf(tbuf + len, sizeof(tbuf) - len, "%d. %s:%d", i, (epSet)->eps[i].fqdn, (epSet)->eps[i].port); \
|
||||||
|
} else { \
|
||||||
|
len += snprintf(tbuf + len, sizeof(tbuf) - len, "%d. %s:%d, ", i, (epSet)->eps[i].fqdn, (epSet)->eps[i].port); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
len += snprintf(tbuf + len, sizeof(tbuf) - len, "}, inUse:%d", (epSet)->inUse); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
static void* cliWorkThread(void* arg);
|
static void* cliWorkThread(void* arg);
|
||||||
|
|
||||||
|
@ -271,7 +298,7 @@ _RETURN:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void cliHandleResp(SCliConn* conn) {
|
void cliHandleResp(SCliConn* conn) {
|
||||||
SCliThrdObj* pThrd = conn->hostThrd;
|
SCliThrd* pThrd = conn->hostThrd;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
STransMsgHead* pHead = (STransMsgHead*)(conn->readBuf.buf);
|
STransMsgHead* pHead = (STransMsgHead*)(conn->readBuf.buf);
|
||||||
|
@ -292,17 +319,9 @@ void cliHandleResp(SCliConn* conn) {
|
||||||
|
|
||||||
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
||||||
pMsg = transQueuePop(&conn->cliMsgs);
|
pMsg = transQueuePop(&conn->cliMsgs);
|
||||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
pCtx = pMsg->ctx;
|
||||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) {
|
transMsg.info.ahandle = pCtx->ahandle;
|
||||||
transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
|
||||||
if (transMsg.info.ahandle == NULL) {
|
|
||||||
transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
|
||||||
}
|
|
||||||
tDebug("%s conn %p construct ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle);
|
|
||||||
} else {
|
|
||||||
transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL;
|
|
||||||
tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle);
|
tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
||||||
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
||||||
|
@ -324,26 +343,22 @@ void cliHandleResp(SCliConn* conn) {
|
||||||
}
|
}
|
||||||
// buf's mem alread translated to transMsg.pCont
|
// buf's mem alread translated to transMsg.pCont
|
||||||
transClearBuffer(&conn->readBuf);
|
transClearBuffer(&conn->readBuf);
|
||||||
|
|
||||||
if (!CONN_NO_PERSIST_BY_APP(conn)) {
|
if (!CONN_NO_PERSIST_BY_APP(conn)) {
|
||||||
transMsg.info.handle = conn;
|
transMsg.info.handle = (void*)conn->refId;
|
||||||
tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn);
|
tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn);
|
||||||
}
|
}
|
||||||
// char buf[64] = {0};
|
|
||||||
// TRACE_TO_STR(&transMsg.info.traceId, buf);
|
|
||||||
STraceId* trace = &transMsg.info.traceId;
|
STraceId* trace = &transMsg.info.traceId;
|
||||||
tGTrace("conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, code: %d", conn, TMSG_INFO(pHead->msgType),
|
tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, code: %d", CONN_GET_INST_LABEL(conn),
|
||||||
taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->localAddr.sin_addr),
|
conn, TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port),
|
||||||
ntohs(conn->localAddr.sin_port), transMsg.contLen, transMsg.code);
|
taosInetNtoa(conn->localAddr.sin_addr), ntohs(conn->localAddr.sin_port), transMsg.contLen, transMsg.code);
|
||||||
|
|
||||||
if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) {
|
if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) {
|
||||||
tDebug("%s except, server continue send while cli ignore it", CONN_GET_INST_LABEL(conn));
|
tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn);
|
||||||
// transUnrefCliHandle(conn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) {
|
if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) {
|
||||||
tDebug("%s except, server continue send while cli ignore it", CONN_GET_INST_LABEL(conn));
|
tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn);
|
||||||
// transUnrefCliHandle(conn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +390,7 @@ void cliHandleExcept(SCliConn* pConn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
SCliThrd* pThrd = pConn->hostThrd;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
bool once = false;
|
bool once = false;
|
||||||
do {
|
do {
|
||||||
|
@ -389,7 +404,6 @@ void cliHandleExcept(SCliConn* pConn) {
|
||||||
transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0;
|
transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0;
|
||||||
transMsg.info.ahandle = NULL;
|
transMsg.info.ahandle = NULL;
|
||||||
transMsg.info.handle = pConn;
|
|
||||||
|
|
||||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) {
|
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||||
transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType);
|
transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType);
|
||||||
|
@ -414,13 +428,13 @@ void cliHandleExcept(SCliConn* pConn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
tTrace("%s conn %p start to destroy", CONN_GET_INST_LABEL(pConn), pConn);
|
tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn));
|
||||||
} while (!transQueueEmpty(&pConn->cliMsgs));
|
} while (!transQueueEmpty(&pConn->cliMsgs));
|
||||||
transUnrefCliHandle(pConn);
|
transUnrefCliHandle(pConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cliTimeoutCb(uv_timer_t* handle) {
|
void cliTimeoutCb(uv_timer_t* handle) {
|
||||||
SCliThrdObj* pThrd = handle->data;
|
SCliThrd* pThrd = handle->data;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
int64_t currentTime = pThrd->nextTimeout;
|
int64_t currentTime = pThrd->nextTimeout;
|
||||||
tTrace("%s conn timeout, try to remove expire conn from conn pool", pTransInst->label);
|
tTrace("%s conn timeout, try to remove expire conn from conn pool", pTransInst->label);
|
||||||
|
@ -487,10 +501,26 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
||||||
assert(h == &conn->conn);
|
assert(h == &conn->conn);
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
static void allocConnRef(SCliConn* conn, bool update) {
|
||||||
|
if (update) {
|
||||||
|
transRemoveExHandle(refMgt, conn->refId);
|
||||||
|
}
|
||||||
|
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
||||||
|
exh->handle = conn;
|
||||||
|
exh->pThrd = conn->hostThrd;
|
||||||
|
exh->refId = transAddExHandle(refMgt, exh);
|
||||||
|
conn->refId = exh->refId;
|
||||||
|
}
|
||||||
static void addConnToPool(void* pool, SCliConn* conn) {
|
static void addConnToPool(void* pool, SCliConn* conn) {
|
||||||
SCliThrdObj* thrd = conn->hostThrd;
|
if (conn->status == ConnInPool) {
|
||||||
|
// assert(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SCliThrd* thrd = conn->hostThrd;
|
||||||
CONN_HANDLE_THREAD_QUIT(thrd);
|
CONN_HANDLE_THREAD_QUIT(thrd);
|
||||||
|
|
||||||
|
allocConnRef(conn, true);
|
||||||
|
|
||||||
STrans* pTransInst = thrd->pTransInst;
|
STrans* pTransInst = thrd->pTransInst;
|
||||||
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||||
transQueueClear(&conn->cliMsgs);
|
transQueueClear(&conn->cliMsgs);
|
||||||
|
@ -540,13 +570,14 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
tError("%s conn %p read error: %s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread));
|
tError("%s conn %p read error: %s, ref: %d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread),
|
||||||
|
T_REF_VAL_GET(conn));
|
||||||
conn->broken = true;
|
conn->broken = true;
|
||||||
cliHandleExcept(conn);
|
cliHandleExcept(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
|
static SCliConn* cliCreateConn(SCliThrd* pThrd) {
|
||||||
SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn));
|
SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn));
|
||||||
// read/write stream handle
|
// read/write stream handle
|
||||||
conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t));
|
conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t));
|
||||||
|
@ -562,11 +593,16 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
|
||||||
conn->status = ConnNormal;
|
conn->status = ConnNormal;
|
||||||
conn->broken = 0;
|
conn->broken = 0;
|
||||||
transRefCliHandle(conn);
|
transRefCliHandle(conn);
|
||||||
|
|
||||||
|
allocConnRef(conn, false);
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
static void cliDestroyConn(SCliConn* conn, bool clear) {
|
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);
|
||||||
|
transRemoveExHandle(refMgt, conn->refId);
|
||||||
if (clear) {
|
if (clear) {
|
||||||
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
||||||
}
|
}
|
||||||
|
@ -593,7 +629,7 @@ static bool cliHandleNoResp(SCliConn* conn) {
|
||||||
}
|
}
|
||||||
if (res == true) {
|
if (res == true) {
|
||||||
if (cliMaySendCachedMsg(conn) == false) {
|
if (cliMaySendCachedMsg(conn) == false) {
|
||||||
SCliThrdObj* thrd = conn->hostThrd;
|
SCliThrd* thrd = conn->hostThrd;
|
||||||
addConnToPool(thrd->pool, conn);
|
addConnToPool(thrd->pool, conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,7 +665,7 @@ void cliSend(SCliConn* pConn) {
|
||||||
|
|
||||||
STransConnCtx* pCtx = pCliMsg->ctx;
|
STransConnCtx* pCtx = pCliMsg->ctx;
|
||||||
|
|
||||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
SCliThrd* pThrd = pConn->hostThrd;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg);
|
STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg);
|
||||||
|
@ -651,12 +687,10 @@ void cliSend(SCliConn* pConn) {
|
||||||
|
|
||||||
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
||||||
|
|
||||||
// char buf[64] = {0};
|
|
||||||
// TRACE_TO_STR(&pMsg->info.traceId, buf);
|
|
||||||
STraceId* trace = &pMsg->info.traceId;
|
STraceId* trace = &pMsg->info.traceId;
|
||||||
tGTrace("conn %p %s is sent to %s:%d, local info %s:%d", pConn, TMSG_INFO(pHead->msgType),
|
tGTrace("%s conn %p %s is sent to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn,
|
||||||
taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr),
|
TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port),
|
||||||
ntohs(pConn->localAddr.sin_port));
|
taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port));
|
||||||
|
|
||||||
if (pHead->persist == 1) {
|
if (pHead->persist == 1) {
|
||||||
CONN_SET_PERSIST_BY_APP(pConn);
|
CONN_SET_PERSIST_BY_APP(pConn);
|
||||||
|
@ -664,7 +698,6 @@ void cliSend(SCliConn* pConn) {
|
||||||
|
|
||||||
pConn->writeReq.data = pConn;
|
pConn->writeReq.data = pConn;
|
||||||
uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb);
|
uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
_RETURN:
|
_RETURN:
|
||||||
return;
|
return;
|
||||||
|
@ -690,19 +723,24 @@ void cliConnCb(uv_connect_t* req, int status) {
|
||||||
cliSend(pConn);
|
cliSend(pConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
|
pThrd->quit = true;
|
||||||
tDebug("cli work thread %p start to quit", pThrd);
|
tDebug("cli work thread %p start to quit", pThrd);
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
destroyConnPool(pThrd->pool);
|
destroyConnPool(pThrd->pool);
|
||||||
uv_timer_stop(&pThrd->timer);
|
uv_timer_stop(&pThrd->timer);
|
||||||
uv_walk(pThrd->loop, cliWalkCb, NULL);
|
uv_walk(pThrd->loop, cliWalkCb, NULL);
|
||||||
|
|
||||||
pThrd->quit = true;
|
|
||||||
|
|
||||||
// uv_stop(pThrd->loop);
|
// uv_stop(pThrd->loop);
|
||||||
}
|
}
|
||||||
static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
SCliConn* conn = pMsg->msg.info.handle;
|
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||||
|
SExHandle* exh = transAcquireExHandle(refMgt, refId);
|
||||||
|
if (exh == NULL) {
|
||||||
|
tDebug("%" PRId64 " already release", refId);
|
||||||
|
}
|
||||||
|
|
||||||
|
SCliConn* conn = exh->handle;
|
||||||
tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn);
|
tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn);
|
||||||
|
|
||||||
if (T_REF_VAL_GET(conn) == 2) {
|
if (T_REF_VAL_GET(conn) == 2) {
|
||||||
|
@ -711,33 +749,37 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cliSend(conn);
|
cliSend(conn);
|
||||||
} else {
|
|
||||||
// conn already broken down
|
|
||||||
transUnrefCliHandle(conn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void cliHandleUpdate(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
STransConnCtx* pCtx = pMsg->ctx;
|
STransConnCtx* pCtx = pMsg->ctx;
|
||||||
|
|
||||||
pThrd->cvtAddr = pCtx->cvtAddr;
|
pThrd->cvtAddr = pCtx->cvtAddr;
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore) {
|
||||||
SCliConn* conn = NULL;
|
SCliConn* conn = NULL;
|
||||||
if (pMsg->msg.info.handle != NULL) {
|
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||||
conn = (SCliConn*)(pMsg->msg.info.handle);
|
if (refId != 0) {
|
||||||
if (conn != NULL) {
|
SExHandle* exh = transAcquireExHandle(refMgt, refId);
|
||||||
tTrace("%s conn %p reused", CONN_GET_INST_LABEL(conn), conn);
|
if (exh == NULL) {
|
||||||
}
|
*ignore = true;
|
||||||
|
destroyCmsg(pMsg);
|
||||||
|
return NULL;
|
||||||
|
// assert(0);
|
||||||
} else {
|
} else {
|
||||||
|
conn = exh->handle;
|
||||||
|
transReleaseExHandle(refMgt, refId);
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
};
|
||||||
|
|
||||||
STransConnCtx* pCtx = pMsg->ctx;
|
STransConnCtx* pCtx = pMsg->ctx;
|
||||||
conn = getConnFromPool(pThrd->pool, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet));
|
conn = getConnFromPool(pThrd->pool, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet));
|
||||||
if (conn != NULL) {
|
if (conn != NULL) {
|
||||||
tTrace("%s conn %p get from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
tTrace("%s conn %p get from conn pool:%p", CONN_GET_INST_LABEL(conn), conn, pThrd->pool);
|
||||||
} else {
|
} else {
|
||||||
tTrace("%s not found conn in conn pool %p", ((STrans*)pThrd->pTransInst)->label, pThrd->pool);
|
tTrace("%s not found conn in conn pool:%p", ((STrans*)pThrd->pTransInst)->label, pThrd->pool);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
@ -752,22 +794,19 @@ void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
uint64_t et = taosGetTimestampUs();
|
|
||||||
uint64_t el = et - pMsg->st;
|
|
||||||
// tTrace("%s cli msg tran time cost: %" PRIu64 "us", ((STrans*)pThrd->pTransInst)->label, el);
|
|
||||||
|
|
||||||
STransConnCtx* pCtx = pMsg->ctx;
|
STransConnCtx* pCtx = pMsg->ctx;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
cliMayCvtFqdnToIp(&pCtx->epSet, &pThrd->cvtAddr);
|
cliMayCvtFqdnToIp(&pCtx->epSet, &pThrd->cvtAddr);
|
||||||
|
|
||||||
transPrintEpSet(&pCtx->epSet);
|
// transPrintEpSet(&pCtx->epSet);
|
||||||
|
bool ignore = false;
|
||||||
SCliConn* conn = cliGetConn(pMsg, pThrd);
|
SCliConn* conn = cliGetConn(pMsg, pThrd, &ignore);
|
||||||
|
if (ignore == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (conn != NULL) {
|
if (conn != NULL) {
|
||||||
conn->hThrdIdx = pCtx->hThrdIdx;
|
|
||||||
|
|
||||||
transCtxMerge(&conn->ctx, &pCtx->appCtx);
|
transCtxMerge(&conn->ctx, &pCtx->appCtx);
|
||||||
transQueuePush(&conn->cliMsgs, pMsg);
|
transQueuePush(&conn->cliMsgs, pMsg);
|
||||||
cliSend(conn);
|
cliSend(conn);
|
||||||
|
@ -776,7 +815,6 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||||
transCtxMerge(&conn->ctx, &pCtx->appCtx);
|
transCtxMerge(&conn->ctx, &pCtx->appCtx);
|
||||||
transQueuePush(&conn->cliMsgs, pMsg);
|
transQueuePush(&conn->cliMsgs, pMsg);
|
||||||
|
|
||||||
conn->hThrdIdx = pCtx->hThrdIdx;
|
|
||||||
conn->ip = strdup(EPSET_GET_INUSE_IP(&pCtx->epSet));
|
conn->ip = strdup(EPSET_GET_INUSE_IP(&pCtx->epSet));
|
||||||
conn->port = EPSET_GET_INUSE_PORT(&pCtx->epSet);
|
conn->port = EPSET_GET_INUSE_PORT(&pCtx->epSet);
|
||||||
|
|
||||||
|
@ -784,7 +822,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||||
if (ret) {
|
if (ret) {
|
||||||
tError("%s conn %p failed to set conn option, errmsg %s", transLabel(pTransInst), conn, uv_err_name(ret));
|
tError("%s conn %p failed to set conn option, errmsg %s", transLabel(pTransInst), conn, uv_err_name(ret));
|
||||||
}
|
}
|
||||||
int fd = taosCreateSocketWithTimeOutOpt(TRANS_CONN_TIMEOUT);
|
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
tTrace("%s conn %p failed to create socket", transLabel(pTransInst), conn);
|
tTrace("%s conn %p failed to create socket", transLabel(pTransInst), conn);
|
||||||
cliHandleExcept(conn);
|
cliHandleExcept(conn);
|
||||||
|
@ -808,7 +846,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||||
}
|
}
|
||||||
static void cliAsyncCb(uv_async_t* handle) {
|
static void cliAsyncCb(uv_async_t* handle) {
|
||||||
SAsyncItem* item = handle->data;
|
SAsyncItem* item = handle->data;
|
||||||
SCliThrdObj* pThrd = item->pThrd;
|
SCliThrd* pThrd = item->pThrd;
|
||||||
SCliMsg* pMsg = NULL;
|
SCliMsg* pMsg = NULL;
|
||||||
|
|
||||||
// batch process to avoid to lock/unlock frequently
|
// batch process to avoid to lock/unlock frequently
|
||||||
|
@ -835,7 +873,7 @@ static void cliAsyncCb(uv_async_t* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* cliWorkThread(void* arg) {
|
static void* cliWorkThread(void* arg) {
|
||||||
SCliThrdObj* pThrd = (SCliThrdObj*)arg;
|
SCliThrd* pThrd = (SCliThrd*)arg;
|
||||||
pThrd->pid = taosGetSelfPthreadId();
|
pThrd->pid = taosGetSelfPthreadId();
|
||||||
setThreadName("trans-cli-work");
|
setThreadName("trans-cli-work");
|
||||||
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
||||||
|
@ -848,10 +886,10 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
STrans* pTransInst = shandle;
|
STrans* pTransInst = shandle;
|
||||||
memcpy(cli->label, label, strlen(label));
|
memcpy(cli->label, label, strlen(label));
|
||||||
cli->numOfThreads = numOfThreads;
|
cli->numOfThreads = numOfThreads;
|
||||||
cli->pThreadObj = (SCliThrdObj**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrdObj*));
|
cli->pThreadObj = (SCliThrd**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrd*));
|
||||||
|
|
||||||
for (int i = 0; i < cli->numOfThreads; i++) {
|
for (int i = 0; i < cli->numOfThreads; i++) {
|
||||||
SCliThrdObj* pThrd = createThrdObj();
|
SCliThrd* pThrd = createThrdObj();
|
||||||
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||||
pThrd->pTransInst = shandle;
|
pThrd->pTransInst = shandle;
|
||||||
|
|
||||||
|
@ -885,8 +923,8 @@ static void destroyCmsg(SCliMsg* pMsg) {
|
||||||
taosMemoryFree(pMsg);
|
taosMemoryFree(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCliThrdObj* createThrdObj() {
|
static SCliThrd* createThrdObj() {
|
||||||
SCliThrdObj* pThrd = (SCliThrdObj*)taosMemoryCalloc(1, sizeof(SCliThrdObj));
|
SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd));
|
||||||
|
|
||||||
QUEUE_INIT(&pThrd->msg);
|
QUEUE_INIT(&pThrd->msg);
|
||||||
taosThreadMutexInit(&pThrd->msgMtx, NULL);
|
taosThreadMutexInit(&pThrd->msgMtx, NULL);
|
||||||
|
@ -904,7 +942,7 @@ static SCliThrdObj* createThrdObj() {
|
||||||
pThrd->quit = false;
|
pThrd->quit = false;
|
||||||
return pThrd;
|
return pThrd;
|
||||||
}
|
}
|
||||||
static void destroyThrdObj(SCliThrdObj* pThrd) {
|
static void destroyThrdObj(SCliThrd* pThrd) {
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -925,7 +963,7 @@ static void transDestroyConnCtx(STransConnCtx* ctx) {
|
||||||
taosMemoryFree(ctx);
|
taosMemoryFree(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cliSendQuit(SCliThrdObj* thrd) {
|
void cliSendQuit(SCliThrd* thrd) {
|
||||||
// cli can stop gracefully
|
// cli can stop gracefully
|
||||||
SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
msg->type = Quit;
|
msg->type = Quit;
|
||||||
|
@ -938,7 +976,10 @@ void cliWalkCb(uv_handle_t* handle, void* arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int cliRBChoseIdx(STrans* pTransInst) {
|
int cliRBChoseIdx(STrans* pTransInst) {
|
||||||
int64_t index = pTransInst->index;
|
int8_t index = pTransInst->index;
|
||||||
|
if (pTransInst->numOfThreads == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (pTransInst->index++ >= pTransInst->numOfThreads) {
|
if (pTransInst->index++ >= pTransInst->numOfThreads) {
|
||||||
pTransInst->index = 0;
|
pTransInst->index = 0;
|
||||||
}
|
}
|
||||||
|
@ -946,15 +987,35 @@ int cliRBChoseIdx(STrans* pTransInst) {
|
||||||
}
|
}
|
||||||
static void doDelayTask(void* param) {
|
static void doDelayTask(void* param) {
|
||||||
STaskArg* arg = param;
|
STaskArg* arg = param;
|
||||||
|
|
||||||
SCliMsg* pMsg = arg->param1;
|
SCliMsg* pMsg = arg->param1;
|
||||||
SCliThrdObj* pThrd = arg->param2;
|
SCliThrd* pThrd = arg->param2;
|
||||||
cliHandleReq(pMsg, pThrd);
|
|
||||||
|
|
||||||
taosMemoryFree(arg);
|
taosMemoryFree(arg);
|
||||||
|
|
||||||
|
cliHandleReq(pMsg, pThrd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
|
STransConnCtx* pCtx = pMsg->ctx;
|
||||||
|
|
||||||
|
STraceId* trace = &pMsg->msg.info.traceId;
|
||||||
|
char tbuf[256] = {0};
|
||||||
|
EPSET_DEBUG_STR(&pCtx->epSet, tbuf);
|
||||||
|
tGTrace("%s retry on next node, use %s, retryCnt:%d, limit:%d", transLabel(pThrd->pTransInst), tbuf,
|
||||||
|
pCtx->retryCnt + 1, pCtx->retryLimit);
|
||||||
|
|
||||||
|
STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg));
|
||||||
|
arg->param1 = pMsg;
|
||||||
|
arg->param2 = pThrd;
|
||||||
|
transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cliCompareAndSwap(int8_t* val, int8_t exp, int8_t newVal) {
|
||||||
|
if (*val != exp) {
|
||||||
|
*val = newVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
SCliThrd* pThrd = pConn->hostThrd;
|
||||||
STrans* pTransInst = pThrd->pTransInst;
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
if (pMsg == NULL || pMsg->ctx == NULL) {
|
if (pMsg == NULL || pMsg->ctx == NULL) {
|
||||||
|
@ -962,66 +1023,35 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
pTransInst->cfp(pTransInst->parent, pResp, NULL);
|
pTransInst->cfp(pTransInst->parent, pResp, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STransConnCtx* pCtx = pMsg->ctx;
|
|
||||||
SEpSet* pEpSet = &pCtx->epSet;
|
|
||||||
|
|
||||||
if (pCtx->retryCount == 0) {
|
|
||||||
pCtx->origEpSet = pCtx->epSet;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* upper layer handle retry if code equal TSDB_CODE_RPC_NETWORK_UNAVAIL
|
* no retry
|
||||||
|
* 1. query conn
|
||||||
|
* 2. rpc thread already receive quit msg
|
||||||
*/
|
*/
|
||||||
tmsg_t msgType = pCtx->msgType;
|
STransConnCtx* pCtx = pMsg->ctx;
|
||||||
if ((pTransInst->retry != NULL && pEpSet->numOfEps > 1 && (pTransInst->retry(pResp->code))) ||
|
int32_t code = pResp->code;
|
||||||
(pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pResp->code == TSDB_CODE_APP_NOT_READY ||
|
if (pTransInst->retry != NULL && pTransInst->retry(code)) {
|
||||||
pResp->code == TSDB_CODE_NODE_NOT_DEPLOYED || pResp->code == TSDB_CODE_SYN_NOT_LEADER)) {
|
|
||||||
pMsg->sent = 0;
|
pMsg->sent = 0;
|
||||||
tTrace("try to send req to next node");
|
pCtx->retryCnt += 1;
|
||||||
pMsg->st = taosGetTimestampUs();
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
pCtx->retryCount += 1;
|
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, EPSET_GET_SIZE(&pCtx->epSet) * 3);
|
||||||
if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL && pCtx->setMaxRetry == false) {
|
if (pCtx->retryCnt < pCtx->retryLimit) {
|
||||||
if (pCtx->retryCount < pEpSet->numOfEps * 3) {
|
|
||||||
pEpSet->inUse = (++pEpSet->inUse) % pEpSet->numOfEps;
|
|
||||||
if (pThrd->quit == false) {
|
|
||||||
STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg));
|
|
||||||
arg->param1 = pMsg;
|
|
||||||
arg->param2 = pThrd;
|
|
||||||
transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL);
|
|
||||||
transPrintEpSet(pEpSet);
|
|
||||||
tTrace("%s use local epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse,
|
|
||||||
pCtx->retryCount + 1, pEpSet->numOfEps * 3);
|
|
||||||
|
|
||||||
transUnrefCliHandle(pConn);
|
transUnrefCliHandle(pConn);
|
||||||
|
EPSET_FORWARD_INUSE(&pCtx->epSet);
|
||||||
|
cliSchedMsgToNextNode(pMsg, pThrd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else if (pCtx->retryCount < TRANS_RETRY_COUNT_LIMIT) {
|
cliCompareAndSwap(&pCtx->retryLimit, TRANS_RETRY_COUNT_LIMIT, TRANS_RETRY_COUNT_LIMIT);
|
||||||
pCtx->setMaxRetry = true;
|
if (pCtx->retryCnt < pCtx->retryLimit) {
|
||||||
|
addConnToPool(pThrd->pool, pConn);
|
||||||
if (pResp->contLen == 0) {
|
if (pResp->contLen == 0) {
|
||||||
pEpSet->inUse = (++pEpSet->inUse) % pEpSet->numOfEps;
|
EPSET_FORWARD_INUSE(&pCtx->epSet);
|
||||||
transPrintEpSet(&pCtx->epSet);
|
|
||||||
tTrace("%s use local epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse,
|
|
||||||
pCtx->retryCount + 1, TRANS_RETRY_COUNT_LIMIT);
|
|
||||||
} else {
|
} else {
|
||||||
SEpSet epSet = {0};
|
tDeserializeSEpSet(pResp->pCont, pResp->contLen, &pCtx->epSet);
|
||||||
tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epSet);
|
|
||||||
pCtx->epSet = epSet;
|
|
||||||
|
|
||||||
transPrintEpSet(&pCtx->epSet);
|
|
||||||
tTrace("%s use remote epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse,
|
|
||||||
pCtx->retryCount + 1, TRANS_RETRY_COUNT_LIMIT);
|
|
||||||
}
|
}
|
||||||
if (pThrd->quit == false) {
|
transFreeMsg(pResp->pCont);
|
||||||
if (pResp->code != TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
cliSchedMsgToNextNode(pMsg, pThrd);
|
||||||
if (pConn->status != ConnInPool) addConnToPool(pThrd->pool, pConn);
|
|
||||||
} else {
|
|
||||||
transUnrefCliHandle(pConn);
|
|
||||||
}
|
|
||||||
STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg));
|
|
||||||
arg->param1 = pMsg;
|
|
||||||
arg->param2 = pThrd;
|
|
||||||
transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1029,20 +1059,20 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
|
|
||||||
STraceId* trace = &pResp->info.traceId;
|
STraceId* trace = &pResp->info.traceId;
|
||||||
if (pCtx->pSem != NULL) {
|
if (pCtx->pSem != NULL) {
|
||||||
tGTrace("conn %p(sync) handle resp", pConn);
|
tGTrace("%s conn %p(sync) handle resp", CONN_GET_INST_LABEL(pConn), pConn);
|
||||||
if (pCtx->pRsp == NULL) {
|
if (pCtx->pRsp == NULL) {
|
||||||
tGTrace("conn %p(sync) failed to resp, ignore", pConn);
|
tGTrace("%s conn %p(sync) failed to resp, ignore", CONN_GET_INST_LABEL(pConn), pConn);
|
||||||
} else {
|
} else {
|
||||||
memcpy((char*)pCtx->pRsp, (char*)pResp, sizeof(*pResp));
|
memcpy((char*)pCtx->pRsp, (char*)pResp, sizeof(*pResp));
|
||||||
}
|
}
|
||||||
tsem_post(pCtx->pSem);
|
tsem_post(pCtx->pSem);
|
||||||
pCtx->pRsp = NULL;
|
pCtx->pRsp = NULL;
|
||||||
} else {
|
} else {
|
||||||
tGTrace("conn %p handle resp", pConn);
|
tGTrace("%s conn %p handle resp", CONN_GET_INST_LABEL(pConn), pConn);
|
||||||
if (pResp->code != 0 || pCtx->retryCount == 0 || transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet)) {
|
if (!cliIsEpsetUpdated(code, pCtx)) {
|
||||||
pTransInst->cfp(pTransInst->parent, pResp, NULL);
|
pTransInst->cfp(pTransInst->parent, pResp, NULL);
|
||||||
} else {
|
} else {
|
||||||
pTransInst->cfp(pTransInst->parent, pResp, pEpSet);
|
pTransInst->cfp(pTransInst->parent, pResp, &pCtx->epSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1074,38 +1104,58 @@ void transUnrefCliHandle(void* handle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ref = T_REF_DEC((SCliConn*)handle);
|
int ref = T_REF_DEC((SCliConn*)handle);
|
||||||
tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref);
|
tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref);
|
||||||
if (ref == 0) {
|
if (ref == 0) {
|
||||||
cliDestroyConn((SCliConn*)handle, true);
|
cliDestroyConn((SCliConn*)handle, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SCliThrd* transGetWorkThrdFromHandle(int64_t handle) {
|
||||||
|
SCliThrd* pThrd = NULL;
|
||||||
|
SExHandle* exh = transAcquireExHandle(refMgt, handle);
|
||||||
|
if (exh == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pThrd = exh->pThrd;
|
||||||
|
transReleaseExHandle(refMgt, handle);
|
||||||
|
return pThrd;
|
||||||
|
}
|
||||||
|
SCliThrd* transGetWorkThrd(STrans* trans, int64_t handle) {
|
||||||
|
if (handle == 0) {
|
||||||
|
int idx = cliRBChoseIdx(trans);
|
||||||
|
if (idx < 0) return NULL;
|
||||||
|
return ((SCliObj*)trans->tcphandle)->pThreadObj[idx];
|
||||||
|
}
|
||||||
|
return transGetWorkThrdFromHandle(handle);
|
||||||
|
}
|
||||||
void transReleaseCliHandle(void* handle) {
|
void transReleaseCliHandle(void* handle) {
|
||||||
SCliThrdObj* thrd = CONN_GET_HOST_THREAD(handle);
|
int idx = -1;
|
||||||
if (thrd == NULL) {
|
SCliThrd* pThrd = transGetWorkThrdFromHandle((int64_t)handle);
|
||||||
|
if (pThrd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STransMsg tmsg = {.info.handle = handle};
|
STransMsg tmsg = {.info.handle = handle};
|
||||||
SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
cmsg->msg = tmsg;
|
cmsg->msg = tmsg;
|
||||||
cmsg->type = Release;
|
cmsg->type = Release;
|
||||||
|
|
||||||
transSendAsync(thrd->asyncPool, &cmsg->q);
|
transSendAsync(pThrd->asyncPool, &cmsg->q);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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*)shandle;
|
||||||
int idx = CONN_HOST_THREAD_IDX((SCliConn*)pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
if (idx == -1) {
|
if (pThrd == NULL) {
|
||||||
idx = cliRBChoseIdx(pTransInst);
|
transFreeMsg(pReq->pCont);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64());
|
TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64());
|
||||||
|
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
pCtx->epSet = *pEpSet;
|
pCtx->epSet = *pEpSet;
|
||||||
pCtx->ahandle = pReq->info.ahandle;
|
pCtx->ahandle = pReq->info.ahandle;
|
||||||
pCtx->msgType = pReq->msgType;
|
pCtx->msgType = pReq->msgType;
|
||||||
pCtx->hThrdIdx = idx;
|
|
||||||
|
|
||||||
if (ctx != NULL) {
|
if (ctx != NULL) {
|
||||||
pCtx->appCtx = *ctx;
|
pCtx->appCtx = *ctx;
|
||||||
|
@ -1118,19 +1168,19 @@ void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
cliMsg->st = taosGetTimestampUs();
|
cliMsg->st = taosGetTimestampUs();
|
||||||
cliMsg->type = Normal;
|
cliMsg->type = Normal;
|
||||||
|
|
||||||
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[idx];
|
|
||||||
|
|
||||||
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), thrd->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(transSendAsync(thrd->asyncPool, &(cliMsg->q)) == 0);
|
ASSERT(transSendAsync(pThrd->asyncPool, &(cliMsg->q)) == 0);
|
||||||
|
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*)shandle;
|
||||||
int idx = CONN_HOST_THREAD_IDX(pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
if (idx == -1) {
|
if (pThrd == NULL) {
|
||||||
idx = cliRBChoseIdx(pTransInst);
|
transFreeMsg(pReq->pCont);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
||||||
tsem_init(sem, 0, 0);
|
tsem_init(sem, 0, 0);
|
||||||
|
@ -1139,9 +1189,9 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM
|
||||||
|
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
pCtx->epSet = *pEpSet;
|
pCtx->epSet = *pEpSet;
|
||||||
|
pCtx->origEpSet = *pEpSet;
|
||||||
pCtx->ahandle = pReq->info.ahandle;
|
pCtx->ahandle = pReq->info.ahandle;
|
||||||
pCtx->msgType = pReq->msgType;
|
pCtx->msgType = pReq->msgType;
|
||||||
pCtx->hThrdIdx = idx;
|
|
||||||
pCtx->pSem = sem;
|
pCtx->pSem = sem;
|
||||||
pCtx->pRsp = pRsp;
|
pCtx->pRsp = pRsp;
|
||||||
|
|
||||||
|
@ -1151,22 +1201,21 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM
|
||||||
cliMsg->st = taosGetTimestampUs();
|
cliMsg->st = taosGetTimestampUs();
|
||||||
cliMsg->type = Normal;
|
cliMsg->type = Normal;
|
||||||
|
|
||||||
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[idx];
|
|
||||||
|
|
||||||
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), thrd->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);
|
||||||
|
|
||||||
transSendAsync(thrd->asyncPool, &(cliMsg->q));
|
transSendAsync(pThrd->asyncPool, &(cliMsg->q));
|
||||||
tsem_wait(sem);
|
tsem_wait(sem);
|
||||||
tsem_destroy(sem);
|
tsem_destroy(sem);
|
||||||
taosMemoryFree(sem);
|
taosMemoryFree(sem);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void transSetDefaultAddr(void* ahandle, const char* ip, const char* fqdn) {
|
void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
STrans* pTransInst = ahandle;
|
STrans* pTransInst = shandle;
|
||||||
|
|
||||||
SCvtAddr cvtAddr = {0};
|
SCvtAddr cvtAddr = {0};
|
||||||
if (ip != NULL && fqdn != NULL) {
|
if (ip != NULL && fqdn != NULL) {
|
||||||
|
@ -1176,14 +1225,13 @@ void transSetDefaultAddr(void* ahandle, const char* ip, const char* fqdn) {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < pTransInst->numOfThreads; i++) {
|
for (int i = 0; i < pTransInst->numOfThreads; i++) {
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
pCtx->hThrdIdx = i;
|
|
||||||
pCtx->cvtAddr = cvtAddr;
|
pCtx->cvtAddr = cvtAddr;
|
||||||
|
|
||||||
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
cliMsg->ctx = pCtx;
|
cliMsg->ctx = pCtx;
|
||||||
cliMsg->type = Update;
|
cliMsg->type = Update;
|
||||||
|
|
||||||
SCliThrdObj* 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);
|
||||||
|
|
||||||
transSendAsync(thrd->asyncPool, &(cliMsg->q));
|
transSendAsync(thrd->asyncPool, &(cliMsg->q));
|
||||||
|
|
|
@ -455,7 +455,7 @@ void transPrintEpSet(SEpSet* pEpSet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char buf[512] = {0};
|
char buf[512] = {0};
|
||||||
int len = snprintf(buf, sizeof(buf), "epset { ");
|
int len = snprintf(buf, sizeof(buf), "epset:{");
|
||||||
for (int i = 0; i < pEpSet->numOfEps; i++) {
|
for (int i = 0; i < pEpSet->numOfEps; i++) {
|
||||||
if (i == pEpSet->numOfEps - 1) {
|
if (i == pEpSet->numOfEps - 1) {
|
||||||
len += snprintf(buf + len, sizeof(buf) - len, "%d. %s:%d", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
len += snprintf(buf + len, sizeof(buf) - len, "%d. %s:%d", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
||||||
|
|
|
@ -65,7 +65,7 @@ typedef struct SSvrMsg {
|
||||||
STransMsgType type;
|
STransMsgType type;
|
||||||
} SSvrMsg;
|
} SSvrMsg;
|
||||||
|
|
||||||
typedef struct SWorkThrdObj {
|
typedef struct SWorkThrd {
|
||||||
TdThread thread;
|
TdThread thread;
|
||||||
uv_connect_t connect_req;
|
uv_connect_t connect_req;
|
||||||
uv_pipe_t* pipe;
|
uv_pipe_t* pipe;
|
||||||
|
@ -78,7 +78,7 @@ typedef struct SWorkThrdObj {
|
||||||
queue conn;
|
queue conn;
|
||||||
void* pTransInst;
|
void* pTransInst;
|
||||||
bool quit;
|
bool quit;
|
||||||
} SWorkThrdObj;
|
} SWorkThrd;
|
||||||
|
|
||||||
typedef struct SServerObj {
|
typedef struct SServerObj {
|
||||||
TdThread thread;
|
TdThread thread;
|
||||||
|
@ -89,7 +89,7 @@ typedef struct SServerObj {
|
||||||
int workerIdx;
|
int workerIdx;
|
||||||
int numOfThreads;
|
int numOfThreads;
|
||||||
int numOfWorkerReady;
|
int numOfWorkerReady;
|
||||||
SWorkThrdObj** pThreadObj;
|
SWorkThrd** pThreadObj;
|
||||||
|
|
||||||
uv_pipe_t pipeListen;
|
uv_pipe_t pipeListen;
|
||||||
uv_pipe_t** pipe;
|
uv_pipe_t** pipe;
|
||||||
|
@ -133,13 +133,13 @@ static SSvrConn* createConn(void* hThrd);
|
||||||
static void destroyConn(SSvrConn* conn, bool clear /*clear handle or not*/);
|
static void destroyConn(SSvrConn* conn, bool clear /*clear handle or not*/);
|
||||||
static void destroyConnRegArg(SSvrConn* conn);
|
static void destroyConnRegArg(SSvrConn* conn);
|
||||||
|
|
||||||
static int reallocConnRefHandle(SSvrConn* conn);
|
static int reallocConnRef(SSvrConn* conn);
|
||||||
|
|
||||||
static void uvHandleQuit(SSvrMsg* msg, SWorkThrdObj* thrd);
|
static void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd);
|
||||||
static void uvHandleRelease(SSvrMsg* msg, SWorkThrdObj* thrd);
|
static void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd);
|
||||||
static void uvHandleResp(SSvrMsg* msg, SWorkThrdObj* thrd);
|
static void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd);
|
||||||
static void uvHandleRegister(SSvrMsg* msg, SWorkThrdObj* thrd);
|
static void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd);
|
||||||
static void (*transAsyncHandle[])(SSvrMsg* msg, SWorkThrdObj* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease,
|
static void (*transAsyncHandle[])(SSvrMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease,
|
||||||
uvHandleRegister, NULL};
|
uvHandleRegister, NULL};
|
||||||
|
|
||||||
static int32_t exHandlesMgt;
|
static int32_t exHandlesMgt;
|
||||||
|
@ -160,7 +160,7 @@ static void* transWorkerThread(void* arg);
|
||||||
static void* transAcceptThread(void* arg);
|
static void* transAcceptThread(void* arg);
|
||||||
|
|
||||||
// add handle loop
|
// add handle loop
|
||||||
static bool addHandleToWorkloop(SWorkThrdObj* pThrd, char* pipeName);
|
static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName);
|
||||||
static bool addHandleToAcceptloop(void* arg);
|
static bool addHandleToAcceptloop(void* arg);
|
||||||
|
|
||||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||||
|
@ -176,7 +176,7 @@ static bool addHandleToAcceptloop(void* arg);
|
||||||
srvMsg->msg = tmsg; \
|
srvMsg->msg = tmsg; \
|
||||||
srvMsg->type = Release; \
|
srvMsg->type = Release; \
|
||||||
srvMsg->pConn = conn; \
|
srvMsg->pConn = conn; \
|
||||||
reallocConnRefHandle(conn); \
|
reallocConnRef(conn); \
|
||||||
if (!transQueuePush(&conn->srvMsgs, srvMsg)) { \
|
if (!transQueuePush(&conn->srvMsgs, srvMsg)) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
|
@ -206,32 +206,6 @@ static bool addHandleToAcceptloop(void* arg);
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ASYNC_CHECK_HANDLE(exh1, refId) \
|
|
||||||
do { \
|
|
||||||
if (refId > 0) { \
|
|
||||||
tTrace("handle step1"); \
|
|
||||||
SExHandle* exh2 = transAcquireExHandle(refMgt, refId); \
|
|
||||||
if (exh2 == NULL || refId != exh2->refId) { \
|
|
||||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \
|
|
||||||
exh2 ? exh2->refId : 0, refId); \
|
|
||||||
goto _return1; \
|
|
||||||
} \
|
|
||||||
} else if (refId == 0) { \
|
|
||||||
tTrace("handle step2"); \
|
|
||||||
SExHandle* exh2 = transAcquireExHandle(refMgt, refId); \
|
|
||||||
if (exh2 == NULL || refId != exh2->refId) { \
|
|
||||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, refId, \
|
|
||||||
exh2 ? exh2->refId : 0); \
|
|
||||||
goto _return1; \
|
|
||||||
} else { \
|
|
||||||
refId = exh1->refId; \
|
|
||||||
} \
|
|
||||||
} else if (refId < 0) { \
|
|
||||||
tTrace("handle step3"); \
|
|
||||||
goto _return2; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
void uvAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
void uvAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||||
SSvrConn* conn = handle->data;
|
SSvrConn* conn = handle->data;
|
||||||
SConnBuffer* pBuf = &conn->readBuf;
|
SConnBuffer* pBuf = &conn->readBuf;
|
||||||
|
@ -259,7 +233,7 @@ static void uvHandleReq(SSvrConn* pConn) {
|
||||||
// wreq->data = pConn;
|
// wreq->data = pConn;
|
||||||
// uv_read_stop((uv_stream_t*)pConn->pTcp);
|
// uv_read_stop((uv_stream_t*)pConn->pTcp);
|
||||||
// transRefSrvHandle(pConn);
|
// transRefSrvHandle(pConn);
|
||||||
// uv_queue_work(((SWorkThrdObj*)pConn->hostThrd)->loop, wreq, uvWorkDoTask, uvWorkAfterTask);
|
// uv_queue_work(((SWorkThrd*)pConn->hostThrd)->loop, wreq, uvWorkDoTask, uvWorkAfterTask);
|
||||||
|
|
||||||
CONN_SHOULD_RELEASE(pConn, pHead);
|
CONN_SHOULD_RELEASE(pConn, pHead);
|
||||||
|
|
||||||
|
@ -379,7 +353,7 @@ void uvOnSendCb(uv_write_t* req, int status) {
|
||||||
// if (msg->type == Release && conn->status != ConnNormal) {
|
// if (msg->type == Release && conn->status != ConnNormal) {
|
||||||
// conn->status = ConnNormal;
|
// conn->status = ConnNormal;
|
||||||
// transUnrefSrvHandle(conn);
|
// transUnrefSrvHandle(conn);
|
||||||
// reallocConnRefHandle(conn);
|
// reallocConnRef(conn);
|
||||||
// destroySmsg(msg);
|
// destroySmsg(msg);
|
||||||
// transQueueClear(&conn->srvMsgs);
|
// transQueueClear(&conn->srvMsgs);
|
||||||
// return;
|
// return;
|
||||||
|
@ -448,6 +422,8 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
|
||||||
transUnrefSrvHandle(pConn);
|
transUnrefSrvHandle(pConn);
|
||||||
} else {
|
} else {
|
||||||
pHead->msgType = pMsg->msgType;
|
pHead->msgType = pMsg->msgType;
|
||||||
|
if (pHead->msgType == 0 && transMsgLenFromCont(pMsg->contLen) == sizeof(STransMsgHead))
|
||||||
|
pHead->msgType = pConn->inType + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +480,7 @@ static void destroySmsg(SSvrMsg* smsg) {
|
||||||
transFreeMsg(smsg->msg.pCont);
|
transFreeMsg(smsg->msg.pCont);
|
||||||
taosMemoryFree(smsg);
|
taosMemoryFree(smsg);
|
||||||
}
|
}
|
||||||
static void destroyAllConn(SWorkThrdObj* pThrd) {
|
static void destroyAllConn(SWorkThrd* pThrd) {
|
||||||
tTrace("thread %p destroy all conn ", pThrd);
|
tTrace("thread %p destroy all conn ", pThrd);
|
||||||
while (!QUEUE_IS_EMPTY(&pThrd->conn)) {
|
while (!QUEUE_IS_EMPTY(&pThrd->conn)) {
|
||||||
queue* h = QUEUE_HEAD(&pThrd->conn);
|
queue* h = QUEUE_HEAD(&pThrd->conn);
|
||||||
|
@ -520,7 +496,7 @@ static void destroyAllConn(SWorkThrdObj* pThrd) {
|
||||||
}
|
}
|
||||||
void uvWorkerAsyncCb(uv_async_t* handle) {
|
void uvWorkerAsyncCb(uv_async_t* handle) {
|
||||||
SAsyncItem* item = handle->data;
|
SAsyncItem* item = handle->data;
|
||||||
SWorkThrdObj* pThrd = item->pThrd;
|
SWorkThrd* pThrd = item->pThrd;
|
||||||
SSvrConn* conn = NULL;
|
SSvrConn* conn = NULL;
|
||||||
queue wq;
|
queue wq;
|
||||||
|
|
||||||
|
@ -650,7 +626,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
||||||
assert(buf->base[0] == notify[0]);
|
assert(buf->base[0] == notify[0]);
|
||||||
taosMemoryFree(buf->base);
|
taosMemoryFree(buf->base);
|
||||||
|
|
||||||
SWorkThrdObj* pThrd = q->data;
|
SWorkThrd* pThrd = q->data;
|
||||||
|
|
||||||
uv_pipe_t* pipe = (uv_pipe_t*)q;
|
uv_pipe_t* pipe = (uv_pipe_t*)q;
|
||||||
if (!uv_pipe_pending_count(pipe)) {
|
if (!uv_pipe_pending_count(pipe)) {
|
||||||
|
@ -718,10 +694,10 @@ void uvOnPipeConnectionCb(uv_connect_t* connect, int status) {
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SWorkThrdObj* pThrd = container_of(connect, SWorkThrdObj, connect_req);
|
SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req);
|
||||||
uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
||||||
}
|
}
|
||||||
static bool addHandleToWorkloop(SWorkThrdObj* pThrd, char* pipeName) {
|
static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
||||||
pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t));
|
pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t));
|
||||||
if (0 != uv_loop_init(pThrd->loop)) {
|
if (0 != uv_loop_init(pThrd->loop)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -774,14 +750,14 @@ static bool addHandleToAcceptloop(void* arg) {
|
||||||
}
|
}
|
||||||
void* transWorkerThread(void* arg) {
|
void* transWorkerThread(void* arg) {
|
||||||
setThreadName("trans-worker");
|
setThreadName("trans-worker");
|
||||||
SWorkThrdObj* pThrd = (SWorkThrdObj*)arg;
|
SWorkThrd* pThrd = (SWorkThrd*)arg;
|
||||||
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSvrConn* createConn(void* hThrd) {
|
static SSvrConn* createConn(void* hThrd) {
|
||||||
SWorkThrdObj* pThrd = hThrd;
|
SWorkThrd* pThrd = hThrd;
|
||||||
|
|
||||||
SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn));
|
SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn));
|
||||||
QUEUE_INIT(&pConn->queue);
|
QUEUE_INIT(&pConn->queue);
|
||||||
|
@ -826,7 +802,7 @@ static void destroyConnRegArg(SSvrConn* conn) {
|
||||||
conn->regArg.init = 0;
|
conn->regArg.init = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int reallocConnRefHandle(SSvrConn* conn) {
|
static int reallocConnRef(SSvrConn* conn) {
|
||||||
transReleaseExHandle(refMgt, conn->refId);
|
transReleaseExHandle(refMgt, conn->refId);
|
||||||
transRemoveExHandle(refMgt, conn->refId);
|
transRemoveExHandle(refMgt, conn->refId);
|
||||||
// avoid app continue to send msg on invalid handle
|
// avoid app continue to send msg on invalid handle
|
||||||
|
@ -844,7 +820,7 @@ static void uvDestroyConn(uv_handle_t* handle) {
|
||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SWorkThrdObj* thrd = conn->hostThrd;
|
SWorkThrd* thrd = conn->hostThrd;
|
||||||
|
|
||||||
transReleaseExHandle(refMgt, conn->refId);
|
transReleaseExHandle(refMgt, conn->refId);
|
||||||
transRemoveExHandle(refMgt, conn->refId);
|
transRemoveExHandle(refMgt, conn->refId);
|
||||||
|
@ -889,7 +865,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
srv->numOfThreads = numOfThreads;
|
srv->numOfThreads = numOfThreads;
|
||||||
srv->workerIdx = 0;
|
srv->workerIdx = 0;
|
||||||
srv->numOfWorkerReady = 0;
|
srv->numOfWorkerReady = 0;
|
||||||
srv->pThreadObj = (SWorkThrdObj**)taosMemoryCalloc(srv->numOfThreads, sizeof(SWorkThrdObj*));
|
srv->pThreadObj = (SWorkThrd**)taosMemoryCalloc(srv->numOfThreads, sizeof(SWorkThrd*));
|
||||||
srv->pipe = (uv_pipe_t**)taosMemoryCalloc(srv->numOfThreads, sizeof(uv_pipe_t*));
|
srv->pipe = (uv_pipe_t**)taosMemoryCalloc(srv->numOfThreads, sizeof(uv_pipe_t*));
|
||||||
srv->ip = ip;
|
srv->ip = ip;
|
||||||
srv->port = port;
|
srv->port = port;
|
||||||
|
@ -914,7 +890,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
assert(0 == uv_listen((uv_stream_t*)&srv->pipeListen, SOMAXCONN, uvPipeListenCb));
|
assert(0 == uv_listen((uv_stream_t*)&srv->pipeListen, SOMAXCONN, uvPipeListenCb));
|
||||||
|
|
||||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||||
SWorkThrdObj* thrd = (SWorkThrdObj*)taosMemoryCalloc(1, sizeof(SWorkThrdObj));
|
SWorkThrd* thrd = (SWorkThrd*)taosMemoryCalloc(1, sizeof(SWorkThrd));
|
||||||
thrd->pTransInst = shandle;
|
thrd->pTransInst = shandle;
|
||||||
thrd->quit = false;
|
thrd->quit = false;
|
||||||
srv->pThreadObj[i] = thrd;
|
srv->pThreadObj[i] = thrd;
|
||||||
|
@ -959,7 +935,7 @@ End:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uvHandleQuit(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
thrd->quit = true;
|
thrd->quit = true;
|
||||||
if (QUEUE_IS_EMPTY(&thrd->conn)) {
|
if (QUEUE_IS_EMPTY(&thrd->conn)) {
|
||||||
uv_walk(thrd->loop, uvWalkCb, NULL);
|
uv_walk(thrd->loop, uvWalkCb, NULL);
|
||||||
|
@ -968,10 +944,10 @@ void uvHandleQuit(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
||||||
}
|
}
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
}
|
}
|
||||||
void uvHandleRelease(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
SSvrConn* conn = msg->pConn;
|
SSvrConn* conn = msg->pConn;
|
||||||
if (conn->status == ConnAcquire) {
|
if (conn->status == ConnAcquire) {
|
||||||
reallocConnRefHandle(conn);
|
reallocConnRef(conn);
|
||||||
if (!transQueuePush(&conn->srvMsgs, msg)) {
|
if (!transQueuePush(&conn->srvMsgs, msg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -982,12 +958,12 @@ void uvHandleRelease(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
||||||
}
|
}
|
||||||
destroySmsg(msg);
|
destroySmsg(msg);
|
||||||
}
|
}
|
||||||
void uvHandleResp(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
// send msg to client
|
// send msg to client
|
||||||
tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pTransInst), msg->pConn);
|
tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pTransInst), msg->pConn);
|
||||||
uvStartSendResp(msg);
|
uvStartSendResp(msg);
|
||||||
}
|
}
|
||||||
void uvHandleRegister(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
SSvrConn* conn = msg->pConn;
|
SSvrConn* conn = msg->pConn;
|
||||||
tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pTransInst), conn);
|
tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pTransInst), conn);
|
||||||
if (conn->status == ConnAcquire) {
|
if (conn->status == ConnAcquire) {
|
||||||
|
@ -1008,7 +984,7 @@ void uvHandleRegister(SSvrMsg* msg, SWorkThrdObj* thrd) {
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void destroyWorkThrd(SWorkThrdObj* pThrd) {
|
void destroyWorkThrd(SWorkThrd* pThrd) {
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +995,7 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
|
||||||
taosMemoryFree(pThrd->loop);
|
taosMemoryFree(pThrd->loop);
|
||||||
taosMemoryFree(pThrd);
|
taosMemoryFree(pThrd);
|
||||||
}
|
}
|
||||||
void sendQuitToWorkThrd(SWorkThrdObj* pThrd) {
|
void sendQuitToWorkThrd(SWorkThrd* pThrd) {
|
||||||
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
msg->type = Quit;
|
msg->type = Quit;
|
||||||
tDebug("server send quit msg to work thread");
|
tDebug("server send quit msg to work thread");
|
||||||
|
@ -1055,8 +1031,6 @@ void transCloseServer(void* arg) {
|
||||||
|
|
||||||
int ref = atomic_sub_fetch_32(&tranSSvrInst, 1);
|
int ref = atomic_sub_fetch_32(&tranSSvrInst, 1);
|
||||||
if (ref == 0) {
|
if (ref == 0) {
|
||||||
// TdThreadOnce tmpInit = PTHREAD_ONCE_INIT;
|
|
||||||
// memcpy(&transModuleInit, &tmpInit, sizeof(TdThreadOnce));
|
|
||||||
transCloseExHandleMgt(refMgt);
|
transCloseExHandleMgt(refMgt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1086,7 +1060,7 @@ void transReleaseSrvHandle(void* handle) {
|
||||||
|
|
||||||
ASYNC_CHECK_HANDLE(exh, refId);
|
ASYNC_CHECK_HANDLE(exh, refId);
|
||||||
|
|
||||||
SWorkThrdObj* pThrd = exh->pThrd;
|
SWorkThrd* pThrd = exh->pThrd;
|
||||||
ASYNC_ERR_JRET(pThrd);
|
ASYNC_ERR_JRET(pThrd);
|
||||||
|
|
||||||
STransMsg tmsg = {.code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId};
|
STransMsg tmsg = {.code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId};
|
||||||
|
@ -1116,7 +1090,7 @@ void transSendResponse(const STransMsg* msg) {
|
||||||
STransMsg tmsg = *msg;
|
STransMsg tmsg = *msg;
|
||||||
tmsg.info.refId = refId;
|
tmsg.info.refId = refId;
|
||||||
|
|
||||||
SWorkThrdObj* pThrd = exh->pThrd;
|
SWorkThrd* pThrd = exh->pThrd;
|
||||||
ASYNC_ERR_JRET(pThrd);
|
ASYNC_ERR_JRET(pThrd);
|
||||||
|
|
||||||
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
|
@ -1146,7 +1120,7 @@ void transRegisterMsg(const STransMsg* msg) {
|
||||||
STransMsg tmsg = *msg;
|
STransMsg tmsg = *msg;
|
||||||
tmsg.info.refId = refId;
|
tmsg.info.refId = refId;
|
||||||
|
|
||||||
SWorkThrdObj* pThrd = exh->pThrd;
|
SWorkThrd* pThrd = exh->pThrd;
|
||||||
ASYNC_ERR_JRET(pThrd);
|
ASYNC_ERR_JRET(pThrd);
|
||||||
|
|
||||||
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
|
|
|
@ -42,6 +42,9 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
|
||||||
char fnameStr[WAL_FILE_LEN];
|
char fnameStr[WAL_FILE_LEN];
|
||||||
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
taosRemoveFile(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
|
|
||||||
|
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
|
taosRemoveFile(fnameStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
walRemoveMeta(pWal);
|
walRemoveMeta(pWal);
|
||||||
|
@ -105,7 +108,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
||||||
TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ);
|
TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND);
|
||||||
|
|
||||||
if (pIdxTFile == NULL) {
|
if (pIdxTFile == NULL) {
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
|
@ -126,7 +129,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
ASSERT(entry.ver == ver);
|
ASSERT(entry.ver == ver);
|
||||||
|
|
||||||
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
||||||
TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ);
|
TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND);
|
||||||
if (pLogTFile == NULL) {
|
if (pLogTFile == NULL) {
|
||||||
// TODO
|
// TODO
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
|
@ -307,8 +310,8 @@ int walRoll(SWal *pWal) {
|
||||||
|
|
||||||
static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
|
static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
|
||||||
SWalIdxEntry entry = {.ver = ver, .offset = offset};
|
SWalIdxEntry entry = {.ver = ver, .offset = offset};
|
||||||
/*int64_t idxOffset = taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_CUR);*/
|
int64_t idxOffset = taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_END);
|
||||||
/*wDebug("write index: ver: %ld, offset: %ld, at %ld", ver, offset, idxOffset);*/
|
wDebug("write index: ver: %ld, offset: %ld, at %ld", ver, offset, idxOffset);
|
||||||
int64_t size = taosWriteFile(pWal->pWriteIdxTFile, &entry, sizeof(SWalIdxEntry));
|
int64_t size = taosWriteFile(pWal->pWriteIdxTFile, &entry, sizeof(SWalIdxEntry));
|
||||||
if (size != sizeof(SWalIdxEntry)) {
|
if (size != sizeof(SWalIdxEntry)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
|
@ -1073,7 +1073,7 @@ int32_t taosCloseEpoll(TdEpollPtr *ppEpoll) {
|
||||||
* Set TCP connection timeout per-socket level.
|
* Set TCP connection timeout per-socket level.
|
||||||
* ref [https://github.com/libuv/help/issues/54]
|
* ref [https://github.com/libuv/help/issues/54]
|
||||||
*/
|
*/
|
||||||
int taosCreateSocketWithTimeOutOpt(uint32_t conn_timeout_sec) {
|
int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
SOCKET fd;
|
SOCKET fd;
|
||||||
#else
|
#else
|
||||||
|
@ -1083,11 +1083,11 @@ int taosCreateSocketWithTimeOutOpt(uint32_t conn_timeout_sec) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_MAXRT, (char *)&conn_timeout_sec, sizeof(conn_timeout_sec))) {
|
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_MAXRT, (char *)&timeout, sizeof(timeout))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else // Linux like systems
|
#else // Linux like systems
|
||||||
uint32_t conn_timeout_ms = conn_timeout_sec * 1000;
|
uint32_t conn_timeout_ms = timeout * 1000;
|
||||||
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) {
|
if (0 != setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&conn_timeout_ms, sizeof(conn_timeout_ms))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
#======================b1-start===============
|
#======================b1-start===============
|
||||||
|
|
||||||
# ---- user
|
# ---- user
|
||||||
./test.sh -f tsim/user/basic1.sim
|
./test.sh -f tsim/user/basic.sim
|
||||||
./test.sh -f tsim/user/pass_alter.sim
|
./test.sh -f tsim/user/password.sim
|
||||||
./test.sh -f tsim/user/pass_len.sim
|
./test.sh -f tsim/user/privilege_db.sim
|
||||||
./test.sh -f tsim/user/user_len.sim
|
./test.sh -f tsim/user/privilege_sysinfo.sim
|
||||||
./test.sh -f tsim/user/privilege1.sim
|
|
||||||
./test.sh -f tsim/user/privilege2.sim
|
|
||||||
|
|
||||||
## ---- db
|
## ---- db
|
||||||
./test.sh -f tsim/db/create_all_options.sim
|
./test.sh -f tsim/db/create_all_options.sim
|
||||||
|
@ -70,7 +68,7 @@
|
||||||
./test.sh -f tsim/mnode/basic2.sim
|
./test.sh -f tsim/mnode/basic2.sim
|
||||||
./test.sh -f tsim/mnode/basic3.sim
|
./test.sh -f tsim/mnode/basic3.sim
|
||||||
./test.sh -f tsim/mnode/basic4.sim
|
./test.sh -f tsim/mnode/basic4.sim
|
||||||
./test.sh -f tsim/mnode/basic5.sim
|
#./test.sh -f tsim/mnode/basic5.sim
|
||||||
|
|
||||||
# ---- show
|
# ---- show
|
||||||
./test.sh -f tsim/show/basic.sim
|
./test.sh -f tsim/show/basic.sim
|
||||||
|
@ -135,7 +133,7 @@
|
||||||
./test.sh -f tsim/stable/tag_filter.sim
|
./test.sh -f tsim/stable/tag_filter.sim
|
||||||
|
|
||||||
# --- for multi process mode
|
# --- for multi process mode
|
||||||
./test.sh -f tsim/user/basic1.sim -m
|
./test.sh -f tsim/user/basic.sim -m
|
||||||
./test.sh -f tsim/db/basic3.sim -m
|
./test.sh -f tsim/db/basic3.sim -m
|
||||||
./test.sh -f tsim/db/error1.sim -m
|
./test.sh -f tsim/db/error1.sim -m
|
||||||
./test.sh -f tsim/insert/backquote.sim -m
|
./test.sh -f tsim/insert/backquote.sim -m
|
||||||
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print =============== step0
|
||||||
|
sql show users
|
||||||
|
if $data(root)[1] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(root)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(root)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql alter user root pass 'taosdata'
|
||||||
|
|
||||||
|
sql_error ALTER USER root SYSINFO 0
|
||||||
|
sql_error ALTER USER root SYSINFO 1
|
||||||
|
sql_error ALTER USER root enable 0
|
||||||
|
sql_error ALTER USER root enable 1
|
||||||
|
|
||||||
|
sql_error create database db vgroups 1;
|
||||||
|
sql_error GRANT read ON db.* to root;
|
||||||
|
sql_error GRANT read ON *.* to root;
|
||||||
|
sql_error REVOKE read ON db.* from root;
|
||||||
|
sql_error REVOKE read ON *.* from root;
|
||||||
|
sql_error GRANT write ON db.* to root;
|
||||||
|
sql_error GRANT write ON *.* to root;
|
||||||
|
sql_error REVOKE write ON db.* from root;
|
||||||
|
sql_error REVOKE write ON *.* from root;
|
||||||
|
sql_error REVOKE write ON *.* from root;
|
||||||
|
|
||||||
|
sql_error GRANT all ON *.* to root;
|
||||||
|
sql_error REVOKE all ON *.* from root;
|
||||||
|
sql_error GRANT read,write ON *.* to root;
|
||||||
|
sql_error REVOKE read,write ON *.* from root;
|
||||||
|
|
||||||
|
print =============== step1: sysinfo create
|
||||||
|
sql CREATE USER u1 PASS 'taosdata' SYSINFO 0;
|
||||||
|
sql show users
|
||||||
|
if $rows != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[3] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql CREATE USER u2 PASS 'taosdata' SYSINFO 1;
|
||||||
|
sql show users
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step2: sysinfo alter
|
||||||
|
sql ALTER USER u1 SYSINFO 1
|
||||||
|
sql show users
|
||||||
|
if $data(u1)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql ALTER USER u1 SYSINFO 0
|
||||||
|
sql show users
|
||||||
|
if $data(u1)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u1)[3] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql ALTER USER u1 SYSINFO 0
|
||||||
|
sql ALTER USER u1 SYSINFO 0
|
||||||
|
|
||||||
|
sql drop user u1
|
||||||
|
sql show users
|
||||||
|
if $rows != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step3: enable alter
|
||||||
|
sql ALTER USER u2 enable 0
|
||||||
|
sql show users
|
||||||
|
if $rows != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[2] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql ALTER USER u2 enable 1
|
||||||
|
sql show users
|
||||||
|
if $data(u2)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql ALTER USER u2 enable 1
|
||||||
|
sql ALTER USER u2 enable 1
|
||||||
|
|
||||||
|
print =============== restart taosd
|
||||||
|
system sh/exec.sh -n dnode1 -s stop
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
|
print =============== step4: enable privilege
|
||||||
|
sql show users
|
||||||
|
if $rows != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[1] != 0 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[2] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(u2)[3] != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -1,74 +0,0 @@
|
||||||
system sh/stop_dnodes.sh
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
sql connect
|
|
||||||
|
|
||||||
print =============== show users
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2]
|
|
||||||
print $data[1][0] $data[1][1] $data[1][2]
|
|
||||||
print $data[2][0] $data[1][2] $data[2][2]
|
|
||||||
|
|
||||||
sql_error show accounts;
|
|
||||||
sql_error create account a pass "a"
|
|
||||||
sql_error drop account a
|
|
||||||
sql_error drop account root
|
|
||||||
|
|
||||||
print =============== create user1
|
|
||||||
sql create user user1 PASS 'user1'
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2]
|
|
||||||
print $data[1][0] $data[1][1] $data[1][2]
|
|
||||||
print $data[2][0] $data[1][2] $data[2][2]
|
|
||||||
print $data[3][0] $data[3][1] $data[3][2]
|
|
||||||
|
|
||||||
print =============== create user2
|
|
||||||
sql create user user2 PASS 'user2'
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2]
|
|
||||||
print $data[1][0] $data[1][1] $data[1][2]
|
|
||||||
print $data[2][0] $data[1][2] $data[2][2]
|
|
||||||
print $data[3][0] $data[3][1] $data[3][2]
|
|
||||||
print $data40 $data41 $data42
|
|
||||||
|
|
||||||
print =============== drop user1
|
|
||||||
sql drop user user1
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2]
|
|
||||||
print $data[1][0] $data[1][1] $data[1][2]
|
|
||||||
print $data[2][0] $data[1][2] $data[2][2]
|
|
||||||
print $data[3][0] $data[3][1] $data[3][2]
|
|
||||||
|
|
||||||
print =============== restart taosd
|
|
||||||
system sh/exec.sh -n dnode1 -s stop
|
|
||||||
sleep 1000
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
|
|
||||||
print =============== show users
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2]
|
|
||||||
print $data[1][0] $data[1][1] $data[1][2]
|
|
||||||
print $data[2][0] $data[1][2] $data[2][2]
|
|
||||||
print $data[3][0] $data[3][1] $data[3][2]
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
|
@ -1,66 +0,0 @@
|
||||||
system sh/stop_dnodes.sh
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
sql connect
|
|
||||||
|
|
||||||
print ============= step1
|
|
||||||
sql create user u_read pass 'taosdata1'
|
|
||||||
sql create user u_write pass 'taosdata1'
|
|
||||||
|
|
||||||
sql alter user u_read pass 'taosdata'
|
|
||||||
sql alter user u_write pass 'taosdata'
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print ============= step2
|
|
||||||
sql close
|
|
||||||
sleep 2500
|
|
||||||
print user u_read login
|
|
||||||
sql connect u_read
|
|
||||||
sql alter user u_read pass 'taosdata'
|
|
||||||
sql alter user u_write pass 'taosdata1' -x step2
|
|
||||||
return -1
|
|
||||||
step2:
|
|
||||||
|
|
||||||
sql_error create user read1 pass 'taosdata1'
|
|
||||||
sql_error create user write1 pass 'taosdata1'
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print ============= step3
|
|
||||||
sql close
|
|
||||||
sleep 2500
|
|
||||||
print user u_write login
|
|
||||||
sql connect u_write
|
|
||||||
|
|
||||||
sql_error create user read2 pass 'taosdata1'
|
|
||||||
sql_error create user write2 pass 'taosdata1'
|
|
||||||
sql alter user u_write pass 'taosdata'
|
|
||||||
sql alter user u_read pass 'taosdata' -x step3
|
|
||||||
return -1
|
|
||||||
step3:
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print ============= step4
|
|
||||||
sql close
|
|
||||||
sleep 2500
|
|
||||||
print user root login
|
|
||||||
sql connect
|
|
||||||
sql create user oroot pass 'taosdata'
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 4 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
|
@ -1,79 +0,0 @@
|
||||||
system sh/stop_dnodes.sh
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
sql connect
|
|
||||||
|
|
||||||
$i = 0
|
|
||||||
$dbPrefix = apdb
|
|
||||||
$tbPrefix = aptb
|
|
||||||
$db = $dbPrefix . $i
|
|
||||||
$tb = $tbPrefix . $i
|
|
||||||
$userPrefix = apusr
|
|
||||||
|
|
||||||
print =============== step1
|
|
||||||
$i = 0
|
|
||||||
$user = $userPrefix . $i
|
|
||||||
|
|
||||||
sql drop user $user -x step11
|
|
||||||
return -1
|
|
||||||
step11:
|
|
||||||
|
|
||||||
sql create user $user PASS -x step12
|
|
||||||
return -1
|
|
||||||
step12:
|
|
||||||
|
|
||||||
sql create user $user PASS 'taosdata'
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step2
|
|
||||||
$i = 1
|
|
||||||
$user = $userPrefix . $i
|
|
||||||
sql drop user $user -x step2
|
|
||||||
step2:
|
|
||||||
sql create user $user PASS '1'
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step3
|
|
||||||
$i = 2
|
|
||||||
$user = $userPrefix . $i
|
|
||||||
sql drop user $user -x step3
|
|
||||||
step3:
|
|
||||||
|
|
||||||
sql create user $user PASS 'abc0123456789'
|
|
||||||
sql show users
|
|
||||||
if $rows != 4 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step4
|
|
||||||
$i = 3
|
|
||||||
$user = $userPrefix . $i
|
|
||||||
sql create user $user PASS 'abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890123' -x step4
|
|
||||||
return -1
|
|
||||||
|
|
||||||
step4:
|
|
||||||
sql show users
|
|
||||||
if $rows != 4 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
$i = 0
|
|
||||||
while $i < 3
|
|
||||||
$user = $userPrefix . $i
|
|
||||||
sql drop user $user
|
|
||||||
$i = $i + 1
|
|
||||||
endw
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print ============= step1
|
||||||
|
sql create user u_read pass 'taosdata1'
|
||||||
|
sql create user u_write pass 'taosdata1'
|
||||||
|
|
||||||
|
sql alter user u_read pass 'taosdata'
|
||||||
|
sql alter user u_write pass 'taosdata'
|
||||||
|
|
||||||
|
sql show users
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ============= step2
|
||||||
|
print user u_read login
|
||||||
|
sql close
|
||||||
|
sql connect u_read
|
||||||
|
|
||||||
|
sql alter user u_read pass 'taosdata'
|
||||||
|
sql_error alter user u_write pass 'taosdata1'
|
||||||
|
|
||||||
|
sql_error create user read1 pass 'taosdata1'
|
||||||
|
sql_error create user write1 pass 'taosdata1'
|
||||||
|
|
||||||
|
sql show users
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ============= step3
|
||||||
|
print user u_write login
|
||||||
|
sql close
|
||||||
|
sql connect u_write
|
||||||
|
|
||||||
|
sql_error create user read2 pass 'taosdata1'
|
||||||
|
sql_error create user write2 pass 'taosdata1'
|
||||||
|
sql alter user u_write pass 'taosdata'
|
||||||
|
sql_error alter user u_read pass 'taosdata'
|
||||||
|
|
||||||
|
sql show users
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ============= step4
|
||||||
|
print user root login
|
||||||
|
sql close
|
||||||
|
sql connect
|
||||||
|
sql create user oroot pass 'taosdata'
|
||||||
|
sql_error create user $user PASS 'abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890123'
|
||||||
|
sql_error create userabcd012345678901234567891234567890abcd01234567890123456789123456789 PASS 'taosdata'
|
||||||
|
sql_error create user abcd0123456789012345678901234567890111 PASS '123'
|
||||||
|
sql create user abc01234567890123456789 PASS '123'
|
||||||
|
|
||||||
|
sql show users
|
||||||
|
if $rows != 5 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ============= step5
|
||||||
|
sql create database db vgroups 1
|
||||||
|
sql_error ALTER USER o_root SYSINFO 0
|
||||||
|
sql_error ALTER USER o_root SYSINFO 1
|
||||||
|
sql_error ALTER USER o_root enable 0
|
||||||
|
sql_error ALTER USER o_root enable 1
|
||||||
|
|
||||||
|
sql_error create database db vgroups 1;
|
||||||
|
sql_error GRANT read ON db.* to o_root;
|
||||||
|
sql_error GRANT read ON *.* to o_root;
|
||||||
|
sql_error REVOKE read ON db.* from o_root;
|
||||||
|
sql_error REVOKE read ON *.* from o_root;
|
||||||
|
sql_error GRANT write ON db.* to o_root;
|
||||||
|
sql_error GRANT write ON *.* to o_root;
|
||||||
|
sql_error REVOKE write ON db.* from o_root;
|
||||||
|
sql_error REVOKE write ON *.* from o_root;
|
||||||
|
sql_error REVOKE write ON *.* from o_root;
|
||||||
|
|
||||||
|
sql_error GRANT all ON *.* to o_root;
|
||||||
|
sql_error REVOKE all ON *.* from o_root;
|
||||||
|
sql_error GRANT read,write ON *.* to o_root;
|
||||||
|
sql_error REVOKE read,write ON *.* from o_root;
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -1,38 +0,0 @@
|
||||||
system sh/stop_dnodes.sh
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
sql connect
|
|
||||||
|
|
||||||
print =============== show users
|
|
||||||
sql create database d1 vgroups 1;
|
|
||||||
sql create database d2 vgroups 1;
|
|
||||||
sql create database d3 vgroups 1;
|
|
||||||
sql show databases
|
|
||||||
if $rows != 5 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== create users
|
|
||||||
sql create user user1 PASS 'taosdata'
|
|
||||||
sql create user user2 PASS 'taosdata'
|
|
||||||
sql show users
|
|
||||||
if $rows != 3 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
sql GRANT read ON d1.* to user1;
|
|
||||||
sql GRANT write ON d2.* to user1;
|
|
||||||
|
|
||||||
print =============== re connect
|
|
||||||
sql close
|
|
||||||
sleep 2500
|
|
||||||
print user user1 login
|
|
||||||
sql connect user1
|
|
||||||
|
|
||||||
sql_error drop database d1;
|
|
||||||
sql_error drop database d2;
|
|
||||||
|
|
||||||
sql_error create stable d1.st (ts timestamp, i int) tags (j int)
|
|
||||||
sql create stable d2.st (ts timestamp, i int) tags (j int)
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
|
@ -3,7 +3,7 @@ system sh/deploy.sh -n dnode1 -i 1
|
||||||
system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start
|
||||||
sql connect
|
sql connect
|
||||||
|
|
||||||
print =============== show users
|
print =============== create db
|
||||||
sql create database d1 vgroups 1;
|
sql create database d1 vgroups 1;
|
||||||
sql create database d2 vgroups 1;
|
sql create database d2 vgroups 1;
|
||||||
sql create database d3 vgroups 1;
|
sql create database d3 vgroups 1;
|
||||||
|
@ -68,4 +68,26 @@ sql REVOKE read,write ON d1.* from user1;
|
||||||
sql REVOKE read,write ON d2.* from user1;
|
sql REVOKE read,write ON d2.* from user1;
|
||||||
sql REVOKE read,write ON *.* from user1;
|
sql REVOKE read,write ON *.* from user1;
|
||||||
|
|
||||||
|
|
||||||
|
print =============== create users
|
||||||
|
sql create user u1 PASS 'taosdata'
|
||||||
|
sql show users
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql GRANT read ON d1.* to u1;
|
||||||
|
sql GRANT write ON d2.* to u1;
|
||||||
|
|
||||||
|
print =============== re connect
|
||||||
|
print user u1 login
|
||||||
|
sql close
|
||||||
|
sql connect u1
|
||||||
|
|
||||||
|
sql_error drop database d1;
|
||||||
|
sql_error drop database d2;
|
||||||
|
|
||||||
|
sql_error create stable d1.st (ts timestamp, i int) tags (j int)
|
||||||
|
sql create stable d2.st (ts timestamp, i int) tags (j int)
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -0,0 +1,44 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print =============== create user and login
|
||||||
|
sql create user sysinfo0 pass 'taosdata'
|
||||||
|
sql create user sysinfo1 pass 'taosdata'
|
||||||
|
sql alter user sysinfo0 sysinfo 0
|
||||||
|
sql alter user sysinfo1 sysinfo 1
|
||||||
|
|
||||||
|
print user sysinfo0 login
|
||||||
|
sql close
|
||||||
|
sql connect sysinfo0
|
||||||
|
|
||||||
|
print =============== check oper
|
||||||
|
sql_error create user u1 pass 'u1'
|
||||||
|
sql_error drop user sysinfo1
|
||||||
|
sql_error alter user sysinfo1 pass '1'
|
||||||
|
sql_error alter user sysinfo0 pass '1'
|
||||||
|
|
||||||
|
sql_error create dnode $hostname port 7200
|
||||||
|
sql_error drop dnode 1
|
||||||
|
|
||||||
|
sql_error create qnode on dnode 1
|
||||||
|
sql_error drop qnode on dnode 1
|
||||||
|
|
||||||
|
sql_error create mnode on dnode 1
|
||||||
|
sql_error drop mnode on dnode 1
|
||||||
|
|
||||||
|
sql_error create snode on dnode 1
|
||||||
|
sql_error drop snode on dnode 1
|
||||||
|
|
||||||
|
sql_error redistribute vgroup 2 dnode 1 dnode 2
|
||||||
|
sql_error balance vgroup
|
||||||
|
|
||||||
|
sql_error kill transaction 1
|
||||||
|
sql_error kill connection 1
|
||||||
|
sql_error kill query 1
|
||||||
|
|
||||||
|
print =============== check db
|
||||||
|
sql_error create database db
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -1,85 +0,0 @@
|
||||||
system sh/stop_dnodes.sh
|
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
|
||||||
sql connect
|
|
||||||
|
|
||||||
$i = 0
|
|
||||||
$dbPrefix = lm_us_db
|
|
||||||
$tbPrefix = lm_us_tb
|
|
||||||
$db = $dbPrefix . $i
|
|
||||||
$tb = $tbPrefix . $i
|
|
||||||
|
|
||||||
print =============== step1
|
|
||||||
sql drop user ac -x step0
|
|
||||||
return -1
|
|
||||||
step0:
|
|
||||||
|
|
||||||
sql create user PASS '123' -x step1
|
|
||||||
return -1
|
|
||||||
step1:
|
|
||||||
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step2
|
|
||||||
sql drop user a -x step2
|
|
||||||
step2:
|
|
||||||
sql create user a PASS '123'
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
sql drop user a
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step3
|
|
||||||
sql drop user abc01234567890123456789 -x step3
|
|
||||||
step3:
|
|
||||||
|
|
||||||
sql create user abc01234567890123456789 PASS '123'
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
sql drop user abc01234567890123456789
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step4
|
|
||||||
sql create user abcd0123456789012345678901234567890111 PASS '123' -x step4
|
|
||||||
return -1
|
|
||||||
step4:
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
print =============== step5
|
|
||||||
sql drop user 123 -x step5
|
|
||||||
step5:
|
|
||||||
sql create user 123 PASS '123' -x step61
|
|
||||||
return -1
|
|
||||||
step61:
|
|
||||||
|
|
||||||
sql create user a123 PASS '123'
|
|
||||||
sql show users
|
|
||||||
if $rows != 2 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
sql drop user a123
|
|
||||||
sql show users
|
|
||||||
if $rows != 1 then
|
|
||||||
return -1
|
|
||||||
endi
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
|
@ -630,27 +630,27 @@ class TDTestCase:
|
||||||
( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
|
( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) )
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step40: error cast condition, should return error ")
|
tdLog.printNoPrefix("==========step40: error cast condition, should return error ")
|
||||||
tdSql.error("select cast(c1 as int) as b from ct4")
|
#tdSql.error("select cast(c1 as int) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as bool) as b from ct4")
|
#tdSql.error("select cast(c1 as bool) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as tinyint) as b from ct4")
|
#tdSql.error("select cast(c1 as tinyint) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as smallint) as b from ct4")
|
#tdSql.error("select cast(c1 as smallint) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as float) as b from ct4")
|
#tdSql.error("select cast(c1 as float) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as double) as b from ct4")
|
#tdSql.error("select cast(c1 as double) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as tinyint unsigned) as b from ct4")
|
#tdSql.error("select cast(c1 as tinyint unsigned) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as smallint unsigned) as b from ct4")
|
#tdSql.error("select cast(c1 as smallint unsigned) as b from ct4")
|
||||||
tdSql.error("select cast(c1 as int unsigned) as b from ct4")
|
#tdSql.error("select cast(c1 as int unsigned) as b from ct4")
|
||||||
|
|
||||||
tdSql.error("select cast(c2 as int) as b from ct4")
|
#tdSql.error("select cast(c2 as int) as b from ct4")
|
||||||
tdSql.error("select cast(c3 as bool) as b from ct4")
|
#tdSql.error("select cast(c3 as bool) as b from ct4")
|
||||||
tdSql.error("select cast(c4 as tinyint) as b from ct4")
|
#tdSql.error("select cast(c4 as tinyint) as b from ct4")
|
||||||
tdSql.error("select cast(c5 as smallint) as b from ct4")
|
#tdSql.error("select cast(c5 as smallint) as b from ct4")
|
||||||
tdSql.error("select cast(c6 as float) as b from ct4")
|
#tdSql.error("select cast(c6 as float) as b from ct4")
|
||||||
tdSql.error("select cast(c7 as double) as b from ct4")
|
#tdSql.error("select cast(c7 as double) as b from ct4")
|
||||||
tdSql.error("select cast(c8 as tinyint unsigned) as b from ct4")
|
#tdSql.error("select cast(c8 as tinyint unsigned) as b from ct4")
|
||||||
|
|
||||||
tdSql.error("select cast(c8 as timestamp ) as b from ct4")
|
#tdSql.error("select cast(c8 as timestamp ) as b from ct4")
|
||||||
tdSql.error("select cast(c9 as timestamp ) as b from ct4")
|
#tdSql.error("select cast(c9 as timestamp ) as b from ct4")
|
||||||
tdSql.error("select cast(c9 as binary(64) ) as b from ct4")
|
#tdSql.error("select cast(c9 as binary(64) ) as b from ct4")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
|
@ -412,52 +412,59 @@ class TDTestCase:
|
||||||
tdSql.checkColNameList(res, cname_list)
|
tdSql.checkColNameList(res, cname_list)
|
||||||
#
|
#
|
||||||
# test group by & order by json tag
|
# test group by & order by json tag
|
||||||
|
tdSql.query("select ts,jtag->'tag1' from jsons1 partition by jtag->'tag1' order by jtag->'tag1' desc")
|
||||||
|
tdSql.checkRows(11)
|
||||||
|
tdSql.checkData(0, 1, '"femail"')
|
||||||
|
tdSql.checkData(2, 1, '"收到货"')
|
||||||
|
tdSql.checkData(7, 1, "false")
|
||||||
|
|
||||||
|
|
||||||
# tdSql.error("select count(*) from jsons1 group by jtag")
|
# tdSql.error("select count(*) from jsons1 group by jtag")
|
||||||
# tdSql.error("select count(*) from jsons1 partition by jtag")
|
# tdSql.error("select count(*) from jsons1 partition by jtag")
|
||||||
# tdSql.error("select count(*) from jsons1 group by jtag order by jtag")
|
# tdSql.error("select count(*) from jsons1 group by jtag order by jtag")
|
||||||
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'")
|
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'")
|
||||||
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag")
|
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag")
|
||||||
tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc")
|
# tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc")
|
||||||
tdSql.checkRows(8)
|
# tdSql.checkRows(8)
|
||||||
tdSql.checkData(0, 0, 2)
|
# tdSql.checkData(0, 0, 2)
|
||||||
tdSql.checkData(0, 1, '"femail"')
|
# tdSql.checkData(0, 1, '"femail"')
|
||||||
tdSql.checkData(1, 0, 2)
|
# tdSql.checkData(1, 0, 2)
|
||||||
tdSql.checkData(1, 1, '"收到货"')
|
# tdSql.checkData(1, 1, '"收到货"')
|
||||||
tdSql.checkData(2, 0, 1)
|
# tdSql.checkData(2, 0, 1)
|
||||||
tdSql.checkData(2, 1, "11.000000000")
|
# tdSql.checkData(2, 1, "11.000000000")
|
||||||
tdSql.checkData(5, 0, 1)
|
# tdSql.checkData(5, 0, 1)
|
||||||
tdSql.checkData(5, 1, "false")
|
# tdSql.checkData(5, 1, "false")
|
||||||
tdSql.checkData(6, 0, 1)
|
# tdSql.checkData(6, 0, 1)
|
||||||
tdSql.checkData(6, 1, "null")
|
# tdSql.checkData(6, 1, "null")
|
||||||
tdSql.checkData(7, 0, 2)
|
# tdSql.checkData(7, 0, 2)
|
||||||
tdSql.checkData(7, 1, None)
|
# tdSql.checkData(7, 1, None)
|
||||||
|
|
||||||
tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc")
|
# tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' asc")
|
||||||
tdSql.checkRows(8)
|
# tdSql.checkRows(8)
|
||||||
tdSql.checkData(0, 0, 2)
|
# tdSql.checkData(0, 0, 2)
|
||||||
tdSql.checkData(0, 1, None)
|
# tdSql.checkData(0, 1, None)
|
||||||
tdSql.checkData(2, 0, 1)
|
# tdSql.checkData(2, 0, 1)
|
||||||
tdSql.checkData(2, 1, "false")
|
# tdSql.checkData(2, 1, "false")
|
||||||
tdSql.checkData(5, 0, 1)
|
# tdSql.checkData(5, 0, 1)
|
||||||
tdSql.checkData(5, 1, "11.000000000")
|
# tdSql.checkData(5, 1, "11.000000000")
|
||||||
tdSql.checkData(7, 0, 2)
|
# tdSql.checkData(7, 0, 2)
|
||||||
tdSql.checkData(7, 1, '"femail"')
|
# tdSql.checkData(7, 1, '"femail"')
|
||||||
#
|
#
|
||||||
# test stddev with group by json tag
|
# test stddev with group by json tag
|
||||||
tdSql.query("select stddev(dataint),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
# tdSql.query("select stddev(dataint),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
||||||
tdSql.checkRows(8)
|
# tdSql.checkRows(8)
|
||||||
tdSql.checkData(0, 0, 10)
|
# tdSql.checkData(0, 0, 10)
|
||||||
tdSql.checkData(0, 1, None)
|
# tdSql.checkData(0, 1, None)
|
||||||
tdSql.checkData(4, 0, 0)
|
# tdSql.checkData(4, 0, 0)
|
||||||
tdSql.checkData(4, 1, "5.000000000")
|
# tdSql.checkData(4, 1, "5.000000000")
|
||||||
tdSql.checkData(7, 0, 11)
|
# tdSql.checkData(7, 0, 11)
|
||||||
tdSql.checkData(7, 1, '"femail"')
|
# tdSql.checkData(7, 1, '"femail"')
|
||||||
|
#
|
||||||
res = tdSql.getColNameList("select stddev(dataint),jsons1.jtag->'tag1' from jsons1 group by jsons1.jtag->'tag1' order by jtag->'tag1'")
|
# res = tdSql.getColNameList("select stddev(dataint),jsons1.jtag->'tag1' from jsons1 group by jsons1.jtag->'tag1' order by jtag->'tag1'")
|
||||||
cname_list = []
|
# cname_list = []
|
||||||
cname_list.append("stddev(dataint)")
|
# cname_list.append("stddev(dataint)")
|
||||||
cname_list.append("jsons1.jtag->'tag1'")
|
# cname_list.append("jsons1.jtag->'tag1'")
|
||||||
tdSql.checkColNameList(res, cname_list)
|
# tdSql.checkColNameList(res, cname_list)
|
||||||
|
|
||||||
# test top/bottom with group by json tag
|
# test top/bottom with group by json tag
|
||||||
# tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
# tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'")
|
||||||
|
@ -470,8 +477,8 @@ class TDTestCase:
|
||||||
# tdSql.checkData(10, 1, '"femail"')
|
# tdSql.checkData(10, 1, '"femail"')
|
||||||
|
|
||||||
# test having
|
# test having
|
||||||
tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1")
|
# tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1")
|
||||||
tdSql.checkRows(3)
|
# tdSql.checkRows(3)
|
||||||
|
|
||||||
# subquery with json tag
|
# subquery with json tag
|
||||||
tdSql.query("select * from (select jtag, dataint from jsons1) order by dataint")
|
tdSql.query("select * from (select jtag, dataint from jsons1) order by dataint")
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 28a49b447f71c4f014ebbac858b7215b897d57fd
|
Subproject commit a875a057d1225d85c6323b9edaccc2b1a9641987
|
Loading…
Reference in New Issue