Merge branch 'develop' into feature/TD-1925
This commit is contained in:
commit
dd459c531a
|
@ -3,6 +3,7 @@ os: Visual Studio 2015
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- ARCH: amd64
|
- ARCH: amd64
|
||||||
|
- ARCH: x86
|
||||||
|
|
||||||
clone_folder: c:\dev\TDengine
|
clone_folder: c:\dev\TDengine
|
||||||
clone_depth: 1
|
clone_depth: 1
|
||||||
|
@ -23,6 +24,7 @@ notifications:
|
||||||
- provider: Email
|
- provider: Email
|
||||||
to:
|
to:
|
||||||
- sangshuduo@gmail.com
|
- sangshuduo@gmail.com
|
||||||
|
|
||||||
on_build_success: true
|
on_build_success: true
|
||||||
on_build_failure: true
|
on_build_failure: true
|
||||||
on_build_status_changed: true
|
on_build_status_changed: true
|
||||||
|
|
|
@ -1,92 +1,109 @@
|
||||||
|
import hudson.model.Result
|
||||||
|
import jenkins.model.CauseOfInterruption
|
||||||
|
properties([pipelineTriggers([githubPush()])])
|
||||||
|
node {
|
||||||
|
git url: 'https://github.com/taosdata/TDengine.git'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def abortPreviousBuilds() {
|
||||||
|
def currentJobName = env.JOB_NAME
|
||||||
|
def currentBuildNumber = env.BUILD_NUMBER.toInteger()
|
||||||
|
def jobs = Jenkins.instance.getItemByFullName(currentJobName)
|
||||||
|
def builds = jobs.getBuilds()
|
||||||
|
|
||||||
|
for (build in builds) {
|
||||||
|
if (!build.isBuilding()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentBuildNumber == build.getNumber().toInteger()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
build.doKill() //doTerm(),doKill(),doTerm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//abort previous build
|
||||||
|
abortPreviousBuilds()
|
||||||
|
def abort_previous(){
|
||||||
|
def buildNumber = env.BUILD_NUMBER as int
|
||||||
|
if (buildNumber > 1) milestone(buildNumber - 1)
|
||||||
|
milestone(buildNumber)
|
||||||
|
}
|
||||||
|
def pre_test(){
|
||||||
|
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||||
|
sh '''
|
||||||
|
sudo rmtaos
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
sh '''
|
||||||
|
|
||||||
|
cd ${WKC}
|
||||||
|
rm -rf *
|
||||||
|
cd ${WK}
|
||||||
|
git reset --hard
|
||||||
|
git checkout develop
|
||||||
|
git pull
|
||||||
|
cd ${WKC}
|
||||||
|
rm -rf *
|
||||||
|
mv ${WORKSPACE}/* .
|
||||||
|
cd ${WK}
|
||||||
|
export TZ=Asia/Harbin
|
||||||
|
date
|
||||||
|
rm -rf ${WK}/debug
|
||||||
|
mkdir debug
|
||||||
|
cd debug
|
||||||
|
cmake .. > /dev/null
|
||||||
|
make > /dev/null
|
||||||
|
make install > /dev/null
|
||||||
|
cd ${WKC}/tests
|
||||||
|
'''
|
||||||
|
return 1
|
||||||
|
}
|
||||||
pipeline {
|
pipeline {
|
||||||
agent none
|
agent none
|
||||||
|
|
||||||
environment{
|
environment{
|
||||||
WK = '/var/lib/jenkins/workspace/TDinternal'
|
WK = '/var/lib/jenkins/workspace/TDinternal'
|
||||||
WKC= '/var/lib/jenkins/workspace/TDinternal/community'
|
WKC= '/var/lib/jenkins/workspace/TDinternal/community'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
|
|
||||||
stage('Parallel test stage') {
|
stage('Parallel test stage') {
|
||||||
|
//only build pr
|
||||||
|
when {
|
||||||
|
changeRequest()
|
||||||
|
}
|
||||||
parallel {
|
parallel {
|
||||||
stage('pytest') {
|
stage('python') {
|
||||||
agent{label '184'}
|
agent{label 'pytest'}
|
||||||
steps {
|
steps {
|
||||||
|
|
||||||
|
pre_test()
|
||||||
sh '''
|
sh '''
|
||||||
date
|
|
||||||
cd ${WKC}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
git submodule update
|
|
||||||
cd ${WK}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
export TZ=Asia/Harbin
|
|
||||||
date
|
|
||||||
rm -rf ${WK}/debug
|
|
||||||
mkdir debug
|
|
||||||
cd debug
|
|
||||||
cmake .. > /dev/null
|
|
||||||
make > /dev/null
|
|
||||||
make install > /dev/null
|
|
||||||
cd ${WKC}/tests
|
cd ${WKC}/tests
|
||||||
#./test-all.sh smoke
|
|
||||||
./test-all.sh pytest
|
./test-all.sh pytest
|
||||||
date'''
|
date'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('test_b1') {
|
stage('test_b1') {
|
||||||
agent{label 'master'}
|
agent{label 'b1'}
|
||||||
steps {
|
steps {
|
||||||
|
pre_test()
|
||||||
sh '''
|
sh '''
|
||||||
cd ${WKC}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
|
|
||||||
git submodule update
|
|
||||||
cd ${WK}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
export TZ=Asia/Harbin
|
|
||||||
date
|
|
||||||
rm -rf ${WK}/debug
|
|
||||||
mkdir debug
|
|
||||||
cd debug
|
|
||||||
cmake .. > /dev/null
|
|
||||||
make > /dev/null
|
|
||||||
cd ${WKC}/tests
|
cd ${WKC}/tests
|
||||||
#./test-all.sh smoke
|
|
||||||
./test-all.sh b1
|
./test-all.sh b1
|
||||||
date'''
|
date'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('test_crash_gen') {
|
stage('test_crash_gen') {
|
||||||
agent{label "185"}
|
agent{label "b2"}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
pre_test()
|
||||||
cd ${WKC}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
|
|
||||||
git submodule update
|
|
||||||
cd ${WK}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
export TZ=Asia/Harbin
|
|
||||||
|
|
||||||
rm -rf ${WK}/debug
|
|
||||||
mkdir debug
|
|
||||||
cd debug
|
|
||||||
cmake .. > /dev/null
|
|
||||||
make > /dev/null
|
|
||||||
cd ${WKC}/tests/pytest
|
|
||||||
'''
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||||
sh '''
|
sh '''
|
||||||
cd ${WKC}/tests/pytest
|
cd ${WKC}/tests/pytest
|
||||||
|
@ -109,193 +126,28 @@ pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('test_valgrind') {
|
stage('test_valgrind') {
|
||||||
agent{label "186"}
|
agent{label "b3"}
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
|
pre_test()
|
||||||
|
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||||
|
sh '''
|
||||||
|
cd ${WKC}/tests/pytest
|
||||||
|
./valgrind-test.sh 2>&1 > mem-error-out.log
|
||||||
|
./handle_val_log.sh
|
||||||
|
'''
|
||||||
|
}
|
||||||
sh '''
|
sh '''
|
||||||
cd ${WKC}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
|
|
||||||
git submodule update
|
|
||||||
cd ${WK}
|
|
||||||
git reset --hard
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
export TZ=Asia/Harbin
|
|
||||||
date
|
|
||||||
rm -rf ${WK}/debug
|
|
||||||
mkdir debug
|
|
||||||
cd debug
|
|
||||||
cmake .. > /dev/null
|
|
||||||
make > /dev/null
|
|
||||||
cd ${WKC}/tests/pytest
|
|
||||||
./valgrind-test.sh 2>&1 > mem-error-out.log
|
|
||||||
./handle_val_log.sh
|
|
||||||
|
|
||||||
date
|
date
|
||||||
cd ${WKC}/tests
|
cd ${WKC}/tests
|
||||||
./test-all.sh b3
|
./test-all.sh b3
|
||||||
date'''
|
date'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('connector'){
|
|
||||||
agent{label "release"}
|
|
||||||
steps{
|
|
||||||
sh'''
|
|
||||||
cd ${WORKSPACE}
|
|
||||||
git checkout develop
|
|
||||||
'''
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh '''
|
|
||||||
cd ${WORKSPACE}/tests/gotest
|
|
||||||
bash batchtest.sh
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh '''
|
|
||||||
cd ${WORKSPACE}/tests/examples/python/PYTHONConnectorChecker
|
|
||||||
python3 PythonChecker.py
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh '''
|
|
||||||
cd ${WORKSPACE}/tests/examples/JDBC/JDBCDemo/
|
|
||||||
mvn clean package assembly:single >/dev/null
|
|
||||||
java -jar target/jdbcChecker-SNAPSHOT-jar-with-dependencies.jar -host 127.0.0.1
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh '''
|
|
||||||
cd ${JENKINS_HOME}/workspace/C#NET/src/CheckC#
|
|
||||||
dotnet run
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('arm64_build'){
|
|
||||||
agent{label 'arm64'}
|
|
||||||
steps{
|
|
||||||
sh '''
|
|
||||||
cd ${WK}
|
|
||||||
git fetch
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
cd ${WKC}
|
|
||||||
git fetch
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
git submodule update
|
|
||||||
cd ${WKC}/packaging
|
|
||||||
./release.sh -v cluster -c aarch64 -n 2.0.0.0 -m 2.0.0.0
|
|
||||||
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('arm32_build'){
|
|
||||||
agent{label 'arm32'}
|
|
||||||
steps{
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh '''
|
|
||||||
cd ${WK}
|
|
||||||
git fetch
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
cd ${WKC}
|
|
||||||
git fetch
|
|
||||||
git checkout develop
|
|
||||||
git pull
|
|
||||||
git submodule update
|
|
||||||
cd ${WKC}/packaging
|
|
||||||
./release.sh -v cluster -c aarch32 -n 2.0.0.0 -m 2.0.0.0
|
|
||||||
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
post {
|
}
|
||||||
success {
|
|
||||||
emailext (
|
}
|
||||||
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
|
||||||
body: '''<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
</head>
|
|
||||||
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
|
|
||||||
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 16pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
|
|
||||||
<tr>
|
|
||||||
<td><br />
|
|
||||||
<b><font color="#0B610B"><font size="6">构建信息</font></font></b>
|
|
||||||
<hr size="2" width="100%" align="center" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<ul>
|
|
||||||
<div style="font-size:18px">
|
|
||||||
<li>构建名称>>分支:${PROJECT_NAME}</li>
|
|
||||||
<li>构建结果:<span style="color:green"> Successful </span></li>
|
|
||||||
<li>构建编号:${BUILD_NUMBER}</li>
|
|
||||||
<li>触发用户:${CAUSE}</li>
|
|
||||||
<li>变更概要:${CHANGES}</li>
|
|
||||||
<li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
|
|
||||||
<li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
|
|
||||||
<li>变更集:${JELLY_SCRIPT}</li>
|
|
||||||
</div>
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table></font>
|
|
||||||
</body>
|
|
||||||
</html>''',
|
|
||||||
to: "yqliu@taosdata.com,pxiao@taosdata.com",
|
|
||||||
from: "support@taosdata.com"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
failure {
|
|
||||||
emailext (
|
|
||||||
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
|
||||||
body: '''<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
</head>
|
|
||||||
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
|
|
||||||
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 16pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
|
|
||||||
<tr>
|
|
||||||
<td><br />
|
|
||||||
<b><font color="#0B610B"><font size="6">构建信息</font></font></b>
|
|
||||||
<hr size="2" width="100%" align="center" /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<ul>
|
|
||||||
<div style="font-size:18px">
|
|
||||||
<li>构建名称>>分支:${PROJECT_NAME}</li>
|
|
||||||
<li>构建结果:<span style="color:green"> Successful </span></li>
|
|
||||||
<li>构建编号:${BUILD_NUMBER}</li>
|
|
||||||
<li>触发用户:${CAUSE}</li>
|
|
||||||
<li>变更概要:${CHANGES}</li>
|
|
||||||
<li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
|
|
||||||
<li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
|
|
||||||
<li>变更集:${JELLY_SCRIPT}</li>
|
|
||||||
</div>
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table></font>
|
|
||||||
</body>
|
|
||||||
</html>''',
|
|
||||||
to: "yqliu@taosdata.com,pxiao@taosdata.com",
|
|
||||||
from: "support@taosdata.com"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ IF (TD_LINUX_64)
|
||||||
ADD_DEFINITIONS(-D_M_X64)
|
ADD_DEFINITIONS(-D_M_X64)
|
||||||
ADD_DEFINITIONS(-D_TD_LINUX_64)
|
ADD_DEFINITIONS(-D_TD_LINUX_64)
|
||||||
MESSAGE(STATUS "linux64 is defined")
|
MESSAGE(STATUS "linux64 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ IF (TD_LINUX_32)
|
||||||
ADD_DEFINITIONS(-D_TD_LINUX_32)
|
ADD_DEFINITIONS(-D_TD_LINUX_32)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "linux32 is defined")
|
MESSAGE(STATUS "linux32 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_ARM_64)
|
IF (TD_ARM_64)
|
||||||
|
@ -66,7 +66,7 @@ IF (TD_ARM_64)
|
||||||
ADD_DEFINITIONS(-D_TD_ARM_)
|
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "arm64 is defined")
|
MESSAGE(STATUS "arm64 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_ARM_32)
|
IF (TD_ARM_32)
|
||||||
|
@ -74,21 +74,21 @@ IF (TD_ARM_32)
|
||||||
ADD_DEFINITIONS(-D_TD_ARM_)
|
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "arm32 is defined")
|
MESSAGE(STATUS "arm32 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_MIPS_64)
|
IF (TD_MIPS_64)
|
||||||
ADD_DEFINITIONS(-D_TD_MIPS_64_)
|
ADD_DEFINITIONS(-D_TD_MIPS_64_)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "mips64 is defined")
|
MESSAGE(STATUS "mips64 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_MIPS_32)
|
IF (TD_MIPS_32)
|
||||||
ADD_DEFINITIONS(-D_TD_MIPS_32_)
|
ADD_DEFINITIONS(-D_TD_MIPS_32_)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "mips32 is defined")
|
MESSAGE(STATUS "mips32 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_APLHINE)
|
IF (TD_APLHINE)
|
||||||
|
@ -109,8 +109,8 @@ IF (TD_LINUX)
|
||||||
MESSAGE(STATUS "set ningsi macro to true")
|
MESSAGE(STATUS "set ningsi macro to true")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
|
||||||
SET(RELEASE_FLAGS "-O0 -Wno-unused-variable -Wunused-but-set-variable")
|
SET(RELEASE_FLAGS "-O3 -Wno-error")
|
||||||
|
|
||||||
IF (${COVER} MATCHES "true")
|
IF (${COVER} MATCHES "true")
|
||||||
MESSAGE(STATUS "Test coverage mode, add extra flags")
|
MESSAGE(STATUS "Test coverage mode, add extra flags")
|
||||||
|
@ -129,9 +129,9 @@ IF (TD_DARWIN_64)
|
||||||
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
|
||||||
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
ADD_DEFINITIONS(-DUSE_LIBICONV)
|
||||||
MESSAGE(STATUS "darwin64 is defined")
|
MESSAGE(STATUS "darwin64 is defined")
|
||||||
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
|
||||||
SET(DEBUG_FLAGS "-O0 -DDEBUG")
|
SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG")
|
||||||
SET(RELEASE_FLAGS "-O0")
|
SET(RELEASE_FLAGS "-Og")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (TD_WINDOWS)
|
IF (TD_WINDOWS)
|
||||||
|
@ -144,7 +144,7 @@ IF (TD_WINDOWS)
|
||||||
IF (NOT TD_GODLL)
|
IF (NOT TD_GODLL)
|
||||||
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd2220 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd2220 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
||||||
SET(DEBUG_FLAGS "/Zi /W3 /GL")
|
SET(DEBUG_FLAGS "/Zi /W3 /GL")
|
||||||
SET(RELEASE_FLAGS "/W0 /GL")
|
SET(RELEASE_FLAGS "/W0 /O3 /GL")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
||||||
|
|
|
@ -41,8 +41,10 @@ SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_FLAGS} ${RELEASE_FL
|
||||||
# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
|
# SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
|
||||||
|
|
||||||
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
|
IF (${CMAKE_BUILD_TYPE} MATCHES "Debug")
|
||||||
|
SET(CMAKE_BUILD_TYPE "Debug")
|
||||||
MESSAGE(STATUS "Build Debug Version")
|
MESSAGE(STATUS "Build Debug Version")
|
||||||
ELSEIF (${CMAKE_BUILD_TYPE} MATCHES "Release")
|
ELSEIF (${CMAKE_BUILD_TYPE} MATCHES "Release")
|
||||||
|
SET(CMAKE_BUILD_TYPE "Release")
|
||||||
MESSAGE(STATUS "Build Release Version")
|
MESSAGE(STATUS "Build Release Version")
|
||||||
ELSE ()
|
ELSE ()
|
||||||
IF (TD_WINDOWS)
|
IF (TD_WINDOWS)
|
||||||
|
|
|
@ -4,7 +4,7 @@ PROJECT(TDengine)
|
||||||
IF (DEFINED VERNUMBER)
|
IF (DEFINED VERNUMBER)
|
||||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||||
ELSE ()
|
ELSE ()
|
||||||
SET(TD_VER_NUMBER "2.0.9.0")
|
SET(TD_VER_NUMBER "2.0.11.0")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (DEFINED VERCOMPATIBLE)
|
IF (DEFINED VERCOMPATIBLE)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
|
@ -84,6 +84,7 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专
|
||||||
- [数据导出](https://www.taosdata.com/cn/documentation20/administrator/#数据导出):从shell按表导出,也可用taosdump工具做各种导出
|
- [数据导出](https://www.taosdata.com/cn/documentation20/administrator/#数据导出):从shell按表导出,也可用taosdump工具做各种导出
|
||||||
- [系统监控](https://www.taosdata.com/cn/documentation20/administrator/#系统监控):检查系统现有的连接、查询、流式计算,日志和事件等
|
- [系统监控](https://www.taosdata.com/cn/documentation20/administrator/#系统监控):检查系统现有的连接、查询、流式计算,日志和事件等
|
||||||
- [文件目录结构](https://www.taosdata.com/cn/documentation20/administrator/#文件目录结构):TDengine数据文件、配置文件等所在目录
|
- [文件目录结构](https://www.taosdata.com/cn/documentation20/administrator/#文件目录结构):TDengine数据文件、配置文件等所在目录
|
||||||
|
- [参数限制和保留关键字](https://www.taosdata.com/cn/documentation20/administrator/#参数限制和保留关键字):TDengine的参数限制和保留关键字列表
|
||||||
|
|
||||||
## [TAOS SQL](https://www.taosdata.com/cn/documentation20/taos-sql)
|
## [TAOS SQL](https://www.taosdata.com/cn/documentation20/taos-sql)
|
||||||
|
|
||||||
|
@ -128,4 +129,4 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专
|
||||||
## [培训和FAQ](https://www.taosdata.com/cn/faq)
|
## [培训和FAQ](https://www.taosdata.com/cn/faq)
|
||||||
|
|
||||||
- [FAQ](https://www.taosdata.com/cn/documentation20/faq):常见问题与答案
|
- [FAQ](https://www.taosdata.com/cn/documentation20/faq):常见问题与答案
|
||||||
- [应用案列](https://www.taosdata.com/cn/blog/?categories=4):一些使用实例来解释如何使用TDengine
|
- [应用案列](https://www.taosdata.com/cn/blog/?categories=4):一些使用实例来解释如何使用TDengine
|
||||||
|
|
|
@ -59,5 +59,3 @@ TDengine的模块之一是时序数据库。但除此之外,为减少研发的
|
||||||
|要求运维学习成本可控| | | √ |同上。|
|
|要求运维学习成本可控| | | √ |同上。|
|
||||||
|要求市场有大量人才储备| √ | | |TDengine作为新一代产品,目前人才市场里面有经验的人员还有限。但是学习成本低,我们作为厂家也提供运维的培训和辅助服务。|
|
|要求市场有大量人才储备| √ | | |TDengine作为新一代产品,目前人才市场里面有经验的人员还有限。但是学习成本低,我们作为厂家也提供运维的培训和辅助服务。|
|
||||||
|
|
||||||
## TDengine 性能指标介绍和验证方法
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## 快捷安装
|
## 快捷安装
|
||||||
|
|
||||||
TDengine软件分为服务器、客户端和报警模块三部分,目前2.0版仅能在Linux系统上安装和运行,后续会支持Windows、MAC OS等系统。如果应用需要在Windows或Mac上运行,目前只能使用TDengine的RESTful接口连接服务器。硬件支持X64,后续会支持ARM、龙芯等CPU系统。用户可根据需求选择通过[源码](https://www.taosdata.com/cn/getting-started/#通过源码安装)或者[安装包](https://www.taosdata.com/cn/getting-started/#通过安装包安装)来安装。
|
TDengine软件分为服务器、客户端和报警模块三部分,目前2.0版服务器仅能在Linux系统上安装和运行,后续会支持Windows、mac OS等系统。客户端可以在Windows或Linux上安装和运行。任何OS的应用也可以选择RESTful接口连接服务器taosd。CPU支持X64/ARM64/MIPS64/Alpha64,后续会支持ARM32、RISC-V等CPU架构。用户可根据需求选择通过[源码](https://www.taosdata.com/cn/getting-started/#通过源码安装)或者[安装包](https://www.taosdata.com/cn/getting-started/#通过安装包安装)来安装。
|
||||||
|
|
||||||
### 通过源码安装
|
### 通过源码安装
|
||||||
|
|
||||||
|
@ -14,29 +14,11 @@ TDengine软件分为服务器、客户端和报警模块三部分,目前2.0版
|
||||||
|
|
||||||
### 通过安装包安装
|
### 通过安装包安装
|
||||||
|
|
||||||
服务器部分,我们提供三种安装包,您可以根据需要选择。TDengine的安装非常简单,从下载到安装成功仅仅只要几秒钟。
|
TDengine的安装非常简单,从下载到安装成功仅仅只要几秒钟。服务端安装包包含客户端和连接器,我们提供三种安装包,您可以根据需要选择:
|
||||||
|
|
||||||
<ul id='packageList'>
|
- TDengine-server-2.0.10.0-Linux-x64.rpm (4.2M)
|
||||||
<li><a id='tdengine-rpm' style='color:var(--b2)'>TDengine-server-2.0.0.0-Linux-x64.rpm (5.3M)</a></li>
|
- TDengine-server-2.0.10.0-Linux-x64.deb (2.7M)
|
||||||
<li><a id='tdengine-deb' style='color:var(--b2)'>TDengine-server-2.0.0.0-Linux-x64.deb (2.5M)</a></li>
|
- TDengine-server-2.0.10.0-Linux-x64.tar.gz (4.5M)
|
||||||
<li><a id='tdengine-tar' style='color:var(--b2)'>TDengine-server-2.0.0.0-Linux-x64.tar.gz (5.3M)</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
客户端部分,Linux安装包如下:
|
|
||||||
|
|
||||||
- TDengine-client-2.0.0.0-Linux-x64.tar.gz (3.4M)
|
|
||||||
|
|
||||||
报警模块的Linux安装包如下(请参考[报警模块的使用方法](https://github.com/taosdata/TDengine/blob/master/alert/README_cn.md)):
|
|
||||||
|
|
||||||
- TDengine-alert-2.0.0-Linux-x64.tar.gz (8.1M)
|
|
||||||
|
|
||||||
目前,TDengine只支持在使用[`systemd`](https://en.wikipedia.org/wiki/Systemd)做进程服务管理的linux系统上安装。其他linux系统的支持正在开发中。用`which systemctl`命令来检测系统中是否存在`systemd`包:
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
which systemctl
|
|
||||||
```
|
|
||||||
|
|
||||||
如果系统中不存在`systemd`包,请考虑[通过源码安装](#通过源码安装)TDengine。
|
|
||||||
|
|
||||||
具体的安装过程,请参见<a href="https://www.taosdata.com/blog/2019/08/09/566.html">TDengine多种安装包的安装和卸载</a>。
|
具体的安装过程,请参见<a href="https://www.taosdata.com/blog/2019/08/09/566.html">TDengine多种安装包的安装和卸载</a>。
|
||||||
|
|
||||||
|
@ -44,28 +26,39 @@ which systemctl
|
||||||
|
|
||||||
安装成功后,用户可使用`systemctl`命令来启动TDengine的服务进程。
|
安装成功后,用户可使用`systemctl`命令来启动TDengine的服务进程。
|
||||||
|
|
||||||
```cmd
|
```bash
|
||||||
systemctl start taosd
|
$ systemctl start taosd
|
||||||
```
|
```
|
||||||
|
|
||||||
检查服务是否正常工作。
|
检查服务是否正常工作。
|
||||||
```cmd
|
```bash
|
||||||
systemctl status taosd
|
$ systemctl status taosd
|
||||||
```
|
```
|
||||||
|
|
||||||
如果TDengine服务正常工作,那么您可以通过TDengine的命令行程序`taos`来访问并体验TDengine。
|
如果TDengine服务正常工作,那么您可以通过TDengine的命令行程序`taos`来访问并体验TDengine。
|
||||||
|
|
||||||
**注意:**
|
**注意:**
|
||||||
|
|
||||||
- systemctl命令需要 _root_ 权限来运行,如果您非 _root_ 用户,请在命令前添加 sudo
|
- systemctl命令需要 _root_ 权限来运行,如果您非 _root_ 用户,请在命令前添加 sudo
|
||||||
- 为更好的获得产品反馈,改善产品,TDengine会采集基本的使用信息,但您可以修改系统配置文件taos.cfg里的配置参数telemetryReporting, 将其设为0,就可将其关闭。
|
- 为更好的获得产品反馈,改善产品,TDengine会采集基本的使用信息,但您可以修改系统配置文件taos.cfg里的配置参数telemetryReporting, 将其设为0,就可将其关闭。
|
||||||
|
- TDengine采用FQDN(一般就是hostname)作为节点的ID,为保证正常运行,需要给运行taosd的服务器配置好hostname,在客户端应用运行的机器配置好DNS服务或hosts文件,保证FQDN能够解析。
|
||||||
|
|
||||||
|
* TDengine 支持在使用[`systemd`](https://en.wikipedia.org/wiki/Systemd)做进程服务管理的linux系统上安装,用`which systemctl`命令来检测系统中是否存在`systemd`包:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ which systemctl
|
||||||
|
```
|
||||||
|
|
||||||
|
如果系统中不支持systemd,也可以用手动运行 /usr/local/taos/bin/taosd 方式启动 TDengine 服务。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## TDengine命令行程序
|
## TDengine命令行程序
|
||||||
|
|
||||||
执行TDengine命令行程序,您只要在Linux终端执行`taos`即可。
|
执行TDengine命令行程序,您只要在Linux终端执行`taos`即可。
|
||||||
|
|
||||||
```cmd
|
```bash
|
||||||
taos
|
$ taos
|
||||||
```
|
```
|
||||||
|
|
||||||
如果TDengine终端连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考[FAQ](https://www.taosdata.com/cn/faq/)来解决终端连接服务端失败的问题)。TDengine终端的提示符号如下:
|
如果TDengine终端连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考[FAQ](https://www.taosdata.com/cn/faq/)来解决终端连接服务端失败的问题)。TDengine终端的提示符号如下:
|
||||||
|
@ -105,15 +98,15 @@ Query OK, 2 row(s) in set (0.001700s)
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
```cmd
|
```bash
|
||||||
taos -h 192.168.0.1 -s "use db; show tables;"
|
$ taos -h 192.168.0.1 -s "use db; show tables;"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 运行SQL命令脚本
|
### 运行SQL命令脚本
|
||||||
|
|
||||||
TDengine终端可以通过`source`命令来运行SQL命令脚本.
|
TDengine终端可以通过`source`命令来运行SQL命令脚本.
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos> source <filename>;
|
taos> source <filename>;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -128,8 +121,8 @@ taos> source <filename>;
|
||||||
|
|
||||||
启动TDengine的服务,在Linux终端执行taosdemo
|
启动TDengine的服务,在Linux终端执行taosdemo
|
||||||
|
|
||||||
```
|
```bash
|
||||||
> taosdemo
|
$ taosdemo
|
||||||
```
|
```
|
||||||
|
|
||||||
该命令将在数据库test下面自动创建一张超级表meters,该超级表下有1万张表,表名为"t0" 到"t9999",每张表有10万条记录,每条记录有 (f1, f2, f3)三个字段,时间戳从"2017-07-14 10:40:00 000" 到"2017-07-14 10:41:39 999",每张表带有标签areaid和loc, areaid被设置为1到10, loc被设置为"beijing"或者“shanghai"。
|
该命令将在数据库test下面自动创建一张超级表meters,该超级表下有1万张表,表名为"t0" 到"t9999",每张表有10万条记录,每条记录有 (f1, f2, f3)三个字段,时间戳从"2017-07-14 10:40:00 000" 到"2017-07-14 10:41:39 999",每张表带有标签areaid和loc, areaid被设置为1到10, loc被设置为"beijing"或者“shanghai"。
|
||||||
|
@ -140,33 +133,92 @@ taos> source <filename>;
|
||||||
|
|
||||||
- 查询超级表下记录总条数:
|
- 查询超级表下记录总条数:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos>select count(*) from test.meters;
|
taos> select count(*) from test.meters;
|
||||||
```
|
```
|
||||||
|
|
||||||
- 查询10亿条记录的平均值、最大值、最小值等:
|
- 查询10亿条记录的平均值、最大值、最小值等:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos>select avg(f1), max(f2), min(f3) from test.meters;
|
taos> select avg(f1), max(f2), min(f3) from test.meters;
|
||||||
```
|
```
|
||||||
|
|
||||||
- 查询loc="beijing"的记录总条数:
|
- 查询loc="beijing"的记录总条数:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos>select count(*) from test.meters where loc="beijing";
|
taos> select count(*) from test.meters where loc="beijing";
|
||||||
```
|
```
|
||||||
|
|
||||||
- 查询areaid=10的所有记录的平均值、最大值、最小值等:
|
- 查询areaid=10的所有记录的平均值、最大值、最小值等:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos>select avg(f1), max(f2), min(f3) from test.meters where areaid=10;
|
taos> select avg(f1), max(f2), min(f3) from test.meters where areaid=10;
|
||||||
```
|
```
|
||||||
|
|
||||||
- 对表t10按10s进行平均值、最大值和最小值聚合统计:
|
- 对表t10按10s进行平均值、最大值和最小值聚合统计:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos>select avg(f1), max(f2), min(f3) from test.t10 interval(10s);
|
taos> select avg(f1), max(f2), min(f3) from test.t10 interval(10s);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** taosdemo命令本身带有很多选项,配置表的数目、记录条数等等,请执行 `taosdemo --help`详细列出。您可以设置不同参数进行体验。
|
**Note:** taosdemo命令本身带有很多选项,配置表的数目、记录条数等等,请执行 `taosdemo --help`详细列出。您可以设置不同参数进行体验。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 客户端和报警模块
|
||||||
|
|
||||||
|
如果客户端和服务端运行在不同的电脑上,可以单独安装客户端。Linux和Windows安装包如下:
|
||||||
|
|
||||||
|
- TDengine-client-2.0.10.0-Linux-x64.tar.gz(3.0M)
|
||||||
|
- TDengine-client-2.0.10.0-Windows-x64.exe(2.8M)
|
||||||
|
- TDengine-client-2.0.10.0-Windows-x86.exe(2.8M)
|
||||||
|
|
||||||
|
报警模块的Linux安装包如下(请参考[报警模块的使用方法](https://github.com/taosdata/TDengine/blob/master/alert/README_cn.md)):
|
||||||
|
|
||||||
|
- TDengine-alert-2.0.10.0-Linux-x64.tar.gz (8.1M)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## **支持平台列表**
|
||||||
|
|
||||||
|
### TDengine服务器支持的平台列表
|
||||||
|
|
||||||
|
| | **CentOS** **6/7/8** | **Ubuntu** **16/18/20** | **Other Linux** | **统信****UOS** | **银河****/****中标麒麟** | **凝思** **V60/V80** |
|
||||||
|
| -------------- | --------------------- | ------------------------ | --------------- | --------------- | ------------------------- | --------------------- |
|
||||||
|
| X64 | ● | ● | | ○ | ● | ● |
|
||||||
|
| 树莓派ARM32 | | ● | ● | | | |
|
||||||
|
| 龙芯MIPS64 | | | ● | | | |
|
||||||
|
| 鲲鹏 ARM64 | | ○ | ○ | | ● | |
|
||||||
|
| 申威 Alpha64 | | | ○ | ● | | |
|
||||||
|
| 飞腾ARM64 | | ○优麒麟 | | | | |
|
||||||
|
| 海光X64 | ● | ● | ● | ○ | ● | ● |
|
||||||
|
| 瑞芯微ARM64/32 | | | ○ | | | |
|
||||||
|
| 全志ARM64/32 | | | ○ | | | |
|
||||||
|
| 炬力ARM64/32 | | | ○ | | | |
|
||||||
|
| TI ARM32 | | | ○ | | | |
|
||||||
|
|
||||||
|
注: ● 表示经过官方测试验证, ○ 表示非官方测试验证。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### TDengine客户端和连接器支持的平台列表
|
||||||
|
|
||||||
|
目前TDengine的连接器可支持的平台广泛,目前包括:X64/X86/ARM64/ARM32/MIPS/Alpha等硬件平台,以及Linux/Win64/Win32等开发环境。
|
||||||
|
|
||||||
|
对照矩阵如下:
|
||||||
|
|
||||||
|
| **CPU** | **X64 64bit** | | | **X86 32bit** | **ARM64** | **ARM32** | **MIPS ** **龙芯** | **Alpha ** **申威** | **X64 ** **海光** |
|
||||||
|
| ----------- | --------------- | --------- | --------- | --------------- | --------- | --------- | ------------------- | -------------------- | ------------------ |
|
||||||
|
| **OS** | **Linux** | **Win64** | **Win32** | **Win32** | **Linux** | **Linux** | **Linux** | **Linux** | **Linux** |
|
||||||
|
| **C/C++** | ● | ● | ● | ○ | ● | ● | ● | ● | ● |
|
||||||
|
| **JDBC** | ● | ● | ● | ○ | ● | ● | ● | ● | ● |
|
||||||
|
| **Python** | ● | ● | ● | ○ | ● | ● | ● | -- | ● |
|
||||||
|
| **Go** | ● | ● | ● | ○ | ● | ● | ○ | -- | -- |
|
||||||
|
| **NodeJs** | ● | ● | ○ | ○ | ● | ● | ○ | -- | -- |
|
||||||
|
| **C#** | ○ | ● | ● | ○ | ○ | ○ | ○ | -- | -- |
|
||||||
|
| **RESTful** | ● | ● | ● | ● | ● | ● | ● | ● | ● |
|
||||||
|
|
||||||
|
注: ● 表示经过官方测试验证, ○ 表示非官方测试验证。
|
||||||
|
|
||||||
|
请跳转到 [连接器 ](https://www.taosdata.com/cn/documentation/connector)查看更详细的信息。
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,16 @@ TDengine采用关系型数据模型,需要建库、建表。因此对于一个
|
||||||
|
|
||||||
## 创建库
|
## 创建库
|
||||||
|
|
||||||
不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小等等。为让各种场景下TDengine都能最大效率的工作,TDengine建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除SQL标准的选项外,应用还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如:
|
不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为让各种场景下TDengine都能最大效率的工作,TDengine建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除SQL标准的选项外,应用还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如:
|
||||||
|
|
||||||
```cmd
|
```mysql
|
||||||
CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 4;
|
CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 4 UPDATE 1;
|
||||||
```
|
```
|
||||||
上述语句将创建一个名为power的库,这个库的数据将保留365天(超过365天将被自动删除),每10天一个数据文件,内存块数为4。详细的语法及参数请见<a href="https://www.taosdata.com/cn/documentation20/taos-sql/">TAOS SQL</a>
|
上述语句将创建一个名为power的库,这个库的数据将保留365天(超过365天将被自动删除),每10天一个数据文件,内存块数为4,允许更新数据。详细的语法及参数请见<a href="https://www.taosdata.com/cn/documentation20/taos-sql/">TAOS SQL</a>
|
||||||
|
|
||||||
创建库之后,需要使用SQL命令USE将当前库切换过来,例如:
|
创建库之后,需要使用SQL命令USE将当前库切换过来,例如:
|
||||||
|
|
||||||
```cmd
|
```mysql
|
||||||
USE power;
|
USE power;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ USE power;
|
||||||
|
|
||||||
## 创建超级表
|
## 创建超级表
|
||||||
一个物联网系统,往往存在多种类型的设备,比如对于电网,存在智能电表、变压器、母线、开关等等。为便于多表之间的聚合,使用TDengine, 需要对每个类型的数据采集点创建一超级表。以表一中的智能电表为例,可以使用如下的SQL命令创建超级表:
|
一个物联网系统,往往存在多种类型的设备,比如对于电网,存在智能电表、变压器、母线、开关等等。为便于多表之间的聚合,使用TDengine, 需要对每个类型的数据采集点创建一超级表。以表一中的智能电表为例,可以使用如下的SQL命令创建超级表:
|
||||||
```cmd
|
```mysql
|
||||||
CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);
|
CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);
|
||||||
```
|
```
|
||||||
与创建普通表一样,创建表时,需要提供表名(示例中为meters),表结构Schema,即数据列的定义。第一列必须为时间戳(示例中为ts),其他列为采集的物理量(示例中为current, voltage, phase),数据类型可以为整型、浮点型、字符串等。除此之外,还需要提供标签的schema (示例中为location, groupId),标签的数据类型可以为整型、浮点型、字符串等。采集点的静态属性往往可以作为标签,比如采集点的地理位置、设备型号、设备组ID、管理员ID等等。标签的schema可以事后增加、删除、修改。具体定义以及细节请见 <a href="https://www.taosdata.com/cn/documentation20/taos-sql/">TAOS SQL </a>一节。
|
与创建普通表一样,创建表时,需要提供表名(示例中为meters),表结构Schema,即数据列的定义。第一列必须为时间戳(示例中为ts),其他列为采集的物理量(示例中为current, voltage, phase),数据类型可以为整型、浮点型、字符串等。除此之外,还需要提供标签的schema (示例中为location, groupId),标签的数据类型可以为整型、浮点型、字符串等。采集点的静态属性往往可以作为标签,比如采集点的地理位置、设备型号、设备组ID、管理员ID等等。标签的schema可以事后增加、删除、修改。具体定义以及细节请见 <a href="https://www.taosdata.com/cn/documentation20/taos-sql/">TAOS SQL </a>一节。
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
本文档说明TAOS SQL支持的语法规则、主要查询功能、支持的SQL查询函数,以及常用技巧等内容。阅读本文档需要读者具有基本的SQL语言的基础。
|
本文档说明TAOS SQL支持的语法规则、主要查询功能、支持的SQL查询函数,以及常用技巧等内容。阅读本文档需要读者具有基本的SQL语言的基础。
|
||||||
|
|
||||||
TAOS SQL是用户对TDengine进行数据写入和查询的主要工具。TAOS SQL为了便于用户快速上手,在一定程度上提供类似于标准SQL类似的风格和模式。严格意义上,TAOS SQL并不是也不试图提供SQL标准的语法。此外,由于TDengine针对的时序性结构化数据不提供修改和更新功能,因此在TAO SQL中不提供数据更新和数据删除的相关功能。
|
TAOS SQL是用户对TDengine进行数据写入和查询的主要工具。TAOS SQL为了便于用户快速上手,在一定程度上提供类似于标准SQL类似的风格和模式。严格意义上,TAOS SQL并不是也不试图提供SQL标准的语法。此外,由于TDengine针对的时序性结构化数据不提供删除功能,因此在TAO SQL中不提供数据删除的相关功能。
|
||||||
|
|
||||||
本章节SQL语法遵循如下约定:
|
本章节SQL语法遵循如下约定:
|
||||||
|
|
||||||
|
@ -57,18 +57,29 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
||||||
## 数据库管理
|
## 数据库管理
|
||||||
|
|
||||||
- **创建数据库**
|
- **创建数据库**
|
||||||
```mysql
|
|
||||||
CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep];
|
```mysql
|
||||||
```
|
CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [UPDATE 1];
|
||||||
说明:
|
```
|
||||||
|
说明:
|
||||||
1) `KEEP`是该数据库的数据保留多长天数,缺省是3650天(10年),数据库会自动删除超过时限的数据;
|
|
||||||
2) 数据库名最大长度为33;
|
1) KEEP是该数据库的数据保留多长天数,缺省是3650天(10年),数据库会自动删除超过时限的数据;
|
||||||
3) 一条SQL 语句的最大长度为65480个字符;
|
|
||||||
4) 数据库还有更多与存储相关的配置参数,请参见[系统管理](../administrator/#服务端配置)。
|
2) UPDATE 标志数据库支持更新相同时间戳数据;
|
||||||
|
|
||||||
|
3) 数据库名最大长度为33;
|
||||||
|
4) 一条SQL 语句的最大长度为65480个字符;
|
||||||
|
5) 数据库还有更多与存储相关的配置参数,请参见系统管理。
|
||||||
|
|
||||||
|
- **显示系统当前参数**
|
||||||
|
|
||||||
|
```mysql
|
||||||
|
SHOW VARIABLES;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
- **使用数据库**
|
- **使用数据库**
|
||||||
|
|
||||||
```mysql
|
```mysql
|
||||||
USE db_name;
|
USE db_name;
|
||||||
```
|
```
|
||||||
|
@ -143,6 +154,12 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
||||||
显示当前数据库下的所有数据表信息。说明:可在like中使用通配符进行名称的匹配。 通配符匹配:1)’%’ (百分号)匹配0到任意个字符;2)’_’下划线匹配一个字符。
|
显示当前数据库下的所有数据表信息。说明:可在like中使用通配符进行名称的匹配。 通配符匹配:1)’%’ (百分号)匹配0到任意个字符;2)’_’下划线匹配一个字符。
|
||||||
|
|
||||||
|
|
||||||
|
- **在线修改显示字符宽度**
|
||||||
|
|
||||||
|
```mysql
|
||||||
|
SET MAX_BINARY_DISPLAY_WIDTH <nn>;
|
||||||
|
```
|
||||||
|
|
||||||
- **获取表的结构信息**
|
- **获取表的结构信息**
|
||||||
|
|
||||||
```mysql
|
```mysql
|
||||||
|
@ -1022,3 +1039,21 @@ SELECT AVG(current),MAX(current),LEASTSQUARES(current, start_val, step_val), PER
|
||||||
- 标签最多允许128个,可以0个,标签总长度不超过16k个字符
|
- 标签最多允许128个,可以0个,标签总长度不超过16k个字符
|
||||||
- SQL语句最大长度65480个字符,但可通过系统配置参数maxSQLLength修改,最长可配置为1M
|
- SQL语句最大长度65480个字符,但可通过系统配置参数maxSQLLength修改,最长可配置为1M
|
||||||
- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制
|
- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## TAOS SQL其他约定
|
||||||
|
|
||||||
|
**group by的限制**
|
||||||
|
|
||||||
|
TAOS SQL支持对标签、tbname进行group by操作,也支持普通列进行group by,前提是:仅限一列且该列的唯一值小于10万个。
|
||||||
|
|
||||||
|
**join操作的限制**
|
||||||
|
|
||||||
|
TAOS SQL支持表之间按主键时间戳来join两张表的列,暂不支持两个表之间聚合后的四则运算。
|
||||||
|
|
||||||
|
**is not null与不为空的表达式适用范围**
|
||||||
|
|
||||||
|
is not null支持所有类型的列。不为空的表达式为 <>"",仅对非数值类型的列适用。
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,12 @@ TDengine集群的节点数必须大于等于副本数,否则创建表时将报
|
||||||
|
|
||||||
TDengine系统后台服务由taosd提供,可以在配置文件taos.cfg里修改配置参数,以满足不同场景的需求。配置文件的缺省位置在/etc/taos目录,可以通过taosd命令行执行参数-c指定配置文件目录。比如taosd -c /home/user来指定配置文件位于/home/user这个目录。
|
TDengine系统后台服务由taosd提供,可以在配置文件taos.cfg里修改配置参数,以满足不同场景的需求。配置文件的缺省位置在/etc/taos目录,可以通过taosd命令行执行参数-c指定配置文件目录。比如taosd -c /home/user来指定配置文件位于/home/user这个目录。
|
||||||
|
|
||||||
|
另外可以使用 “-C” 显示当前服务器配置参数:
|
||||||
|
|
||||||
|
```
|
||||||
|
taosd -C
|
||||||
|
```
|
||||||
|
|
||||||
下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。**
|
下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。**
|
||||||
|
|
||||||
- firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。
|
- firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。
|
||||||
|
@ -96,6 +102,8 @@ TDengine系统后台服务由taosd提供,可以在配置文件taos.cfg里修
|
||||||
- maxSQLLength:单条SQL语句允许最长限制。默认值:65380字节。
|
- maxSQLLength:单条SQL语句允许最长限制。默认值:65380字节。
|
||||||
- telemetryReporting: 是否允许 TDengine 采集和上报基本使用信息,0表示不允许,1表示允许。 默认值:1。
|
- telemetryReporting: 是否允许 TDengine 采集和上报基本使用信息,0表示不允许,1表示允许。 默认值:1。
|
||||||
- stream: 是否启用连续查询(流计算功能),0表示不允许,1表示允许。 默认值:1。
|
- stream: 是否启用连续查询(流计算功能),0表示不允许,1表示允许。 默认值:1。
|
||||||
|
- queryBufferSize: 为所有并发查询占用保留的内存大小。计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。单位为字节。
|
||||||
|
- ratioOfQueryCores: 设置查询线程的最大数量。最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。
|
||||||
|
|
||||||
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030都6042共13个端口,而且必须TCP和UDP都打开。
|
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030都6042共13个端口,而且必须TCP和UDP都打开。
|
||||||
|
|
||||||
|
@ -151,11 +159,20 @@ ALTER DNODE <dnode_id> <config>
|
||||||
|
|
||||||
## 客户端配置
|
## 客户端配置
|
||||||
|
|
||||||
TDengine系统的前台交互客户端应用程序为taos,它与taosd共享同一个配置文件taos.cfg。运行taos时,使用参数-c指定配置文件目录,如taos -c /home/cfg,表示使用/home/cfg/目录下的taos.cfg配置文件中的参数,缺省目录是/etc/taos。本节主要说明 taos 客户端应用在配置文件 taos.cfg 文件中使用到的参数。
|
TDengine系统的前台交互客户端应用程序为taos,以及应用驱动,它与taosd共享同一个配置文件taos.cfg。运行taos时,使用参数-c指定配置文件目录,如taos -c /home/cfg,表示使用/home/cfg/目录下的taos.cfg配置文件中的参数,缺省目录是/etc/taos。更多taos的使用方法请见[Shell命令行程序](https://www.taosdata.com/cn/documentation/administrator/#_TDengine_Shell命令行程序)。本节主要说明 taos 客户端应用在配置文件 taos.cfg 文件中使用到的参数。
|
||||||
|
|
||||||
|
**2.0.10.0 之后版本支持命令行以下参数显示当前客户端参数的配置**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
taos -C 或 taos --dump-config
|
||||||
|
```
|
||||||
|
|
||||||
客户端配置参数
|
客户端配置参数
|
||||||
|
|
||||||
- firstEp: taos启动时,主动连接的集群中第一个taosd实例的end point, 缺省值为 localhost:6030。
|
- firstEp: taos启动时,主动连接的集群中第一个taosd实例的end point, 缺省值为 localhost:6030。
|
||||||
|
|
||||||
|
- secondEp: taos 启动时,如果 firstEp 连不上,将尝试连接 secondEp。
|
||||||
|
|
||||||
- locale
|
- locale
|
||||||
|
|
||||||
默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置
|
默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置
|
||||||
|
@ -211,15 +228,15 @@ TDengine系统的前台交互客户端应用程序为taos,它与taosd共享同
|
||||||
均是合法的设置东八区时区的格式。
|
均是合法的设置东八区时区的格式。
|
||||||
|
|
||||||
时区的设置对于查询和写入SQL语句中非Unix时间戳的内容(时间戳字符串、关键词now的解析)产生影响。例如:
|
时区的设置对于查询和写入SQL语句中非Unix时间戳的内容(时间戳字符串、关键词now的解析)产生影响。例如:
|
||||||
```
|
```sql
|
||||||
SELECT count(*) FROM table_name WHERE TS<'2019-04-11 12:01:08';
|
SELECT count(*) FROM table_name WHERE TS<'2019-04-11 12:01:08';
|
||||||
```
|
```
|
||||||
在东八区,SQL语句等效于
|
在东八区,SQL语句等效于
|
||||||
```
|
```sql
|
||||||
SELECT count(*) FROM table_name WHERE TS<1554955268000;
|
SELECT count(*) FROM table_name WHERE TS<1554955268000;
|
||||||
```
|
```
|
||||||
在UTC时区,SQL语句等效于
|
在UTC时区,SQL语句等效于
|
||||||
```
|
```sql
|
||||||
SELECT count(*) FROM table_name WHERE TS<1554984068000;
|
SELECT count(*) FROM table_name WHERE TS<1554984068000;
|
||||||
```
|
```
|
||||||
为了避免使用字符串时间格式带来的不确定性,也可以直接使用Unix时间戳。此外,还可以在SQL语句中使用带有时区的时间戳字符串,例如:RFC3339格式的时间戳字符串,2013-04-12T15:52:01.123+08:00或者ISO-8601格式时间戳字符串2013-04-12T15:52:01.123+0800。上述两个字符串转化为Unix时间戳不受系统所在时区的影响。
|
为了避免使用字符串时间格式带来的不确定性,也可以直接使用Unix时间戳。此外,还可以在SQL语句中使用带有时区的时间戳字符串,例如:RFC3339格式的时间戳字符串,2013-04-12T15:52:01.123+08:00或者ISO-8601格式时间戳字符串2013-04-12T15:52:01.123+0800。上述两个字符串转化为Unix时间戳不受系统所在时区的影响。
|
||||||
|
@ -229,42 +246,42 @@ TDengine系统的前台交互客户端应用程序为taos,它与taosd共享同
|
||||||
- maxBinaryDisplayWidth
|
- maxBinaryDisplayWidth
|
||||||
|
|
||||||
Shell中binary 和 nchar字段的显示宽度上限,超过此限制的部分将被隐藏。默认值:30。可在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项。
|
Shell中binary 和 nchar字段的显示宽度上限,超过此限制的部分将被隐藏。默认值:30。可在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项。
|
||||||
|
|
||||||
|
|
||||||
## 用户管理
|
## 用户管理
|
||||||
|
|
||||||
系统管理员可以在CLI界面里添加、删除用户,也可以修改密码。CLI里SQL语法如下:
|
系统管理员可以在CLI界面里添加、删除用户,也可以修改密码。CLI里SQL语法如下:
|
||||||
|
|
||||||
```
|
```sql
|
||||||
CREATE USER <user_name> PASS <'password'>;
|
CREATE USER <user_name> PASS <'password'>;
|
||||||
```
|
```
|
||||||
|
|
||||||
创建用户,并指定用户名和密码,密码需要用单引号引起来,单引号为英文半角
|
创建用户,并指定用户名和密码,密码需要用单引号引起来,单引号为英文半角
|
||||||
|
|
||||||
```
|
```sql
|
||||||
DROP USER <user_name>;
|
DROP USER <user_name>;
|
||||||
```
|
```
|
||||||
|
|
||||||
删除用户,限root用户使用
|
删除用户,限root用户使用
|
||||||
|
|
||||||
```
|
```sql
|
||||||
ALTER USER <user_name> PASS <'password'>;
|
ALTER USER <user_name> PASS <'password'>;
|
||||||
```
|
```
|
||||||
|
|
||||||
修改用户密码, 为避免被转换为小写,密码需要用单引号引用,单引号为英文半角
|
修改用户密码, 为避免被转换为小写,密码需要用单引号引用,单引号为英文半角
|
||||||
|
|
||||||
```
|
```sql
|
||||||
ALTER USER <user_name> PRIVILEGE <super|write|read>;
|
ALTER USER <user_name> PRIVILEGE <super|write|read>;
|
||||||
```
|
```
|
||||||
|
|
||||||
修改用户权限为:super/write/read,不需要添加单引号
|
修改用户权限为:super/write/read,不需要添加单引号
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
SHOW USERS;
|
SHOW USERS;
|
||||||
```
|
```
|
||||||
|
|
||||||
显示所有用户
|
显示所有用户
|
||||||
|
|
||||||
**注意:**SQL 语法中,< >表示需要用户输入的部分,但请不要输入< >本身
|
**注意:**SQL 语法中,< >表示需要用户输入的部分,但请不要输入< >本身
|
||||||
|
|
||||||
## 数据导入
|
## 数据导入
|
||||||
|
@ -312,12 +329,11 @@ taos> DESCRIBE d1001
|
||||||
```
|
```
|
||||||
那么可以用如下命令导入数据
|
那么可以用如下命令导入数据
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
taos> insert into d1001 file '~/data.csv';
|
taos> insert into d1001 file '~/data.csv';
|
||||||
Query OK, 9 row(s) affected (0.004763s)
|
Query OK, 9 row(s) affected (0.004763s)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
**taosdump工具导入**
|
**taosdump工具导入**
|
||||||
|
|
||||||
TDengine提供了方便的数据库导入导出工具taosdump。用户可以将taosdump从一个系统导出的数据,导入到其他系统中。具体使用方法,请参见博客:<a href='https://www.taosdata.com/blog/2020/03/09/1334.html'>TDengine DUMP工具使用指南</a>
|
TDengine提供了方便的数据库导入导出工具taosdump。用户可以将taosdump从一个系统导出的数据,导入到其他系统中。具体使用方法,请参见博客:<a href='https://www.taosdata.com/blog/2020/03/09/1334.html'>TDengine DUMP工具使用指南</a>
|
||||||
|
@ -330,7 +346,7 @@ TDengine提供了方便的数据库导入导出工具taosdump。用户可以将t
|
||||||
|
|
||||||
如果用户需要导出一个表或一个STable中的数据,可在shell中运行
|
如果用户需要导出一个表或一个STable中的数据,可在shell中运行
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
select * from <tb_name> >> data.csv;
|
select * from <tb_name> >> data.csv;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -344,37 +360,37 @@ TDengine提供了方便的数据库导出工具taosdump。用户可以根据需
|
||||||
|
|
||||||
系统管理员可以从CLI查询系统的连接、正在进行的查询、流式计算,并且可以关闭连接、停止正在进行的查询和流式计算。CLI里SQL语法如下:
|
系统管理员可以从CLI查询系统的连接、正在进行的查询、流式计算,并且可以关闭连接、停止正在进行的查询和流式计算。CLI里SQL语法如下:
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
SHOW CONNECTIONS;
|
SHOW CONNECTIONS;
|
||||||
```
|
```
|
||||||
|
|
||||||
显示数据库的连接,其中一列显示ip:port, 为连接的IP地址和端口号。
|
显示数据库的连接,其中一列显示ip:port, 为连接的IP地址和端口号。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
KILL CONNECTION <connection-id>;
|
KILL CONNECTION <connection-id>;
|
||||||
```
|
```
|
||||||
|
|
||||||
强制关闭数据库连接,其中的connection-id是SHOW CONNECTIONS中显示的第一列的数字。
|
强制关闭数据库连接,其中的connection-id是SHOW CONNECTIONS中显示的第一列的数字。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
SHOW QUERIES;
|
SHOW QUERIES;
|
||||||
```
|
```
|
||||||
|
|
||||||
显示数据查询,其中第一列显示的以冒号隔开的两个数字为query-id,为发起该query应用连接的connection-id和查询次数。
|
显示数据查询,其中第一列显示的以冒号隔开的两个数字为query-id,为发起该query应用连接的connection-id和查询次数。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
KILL QUERY <query-id>;
|
KILL QUERY <query-id>;
|
||||||
```
|
```
|
||||||
|
|
||||||
强制关闭数据查询,其中query-id是SHOW QUERIES中显示的 connection-id:query-no字串,如“105:2”,拷贝粘贴即可。
|
强制关闭数据查询,其中query-id是SHOW QUERIES中显示的 connection-id:query-no字串,如“105:2”,拷贝粘贴即可。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
SHOW STREAMS;
|
SHOW STREAMS;
|
||||||
```
|
```
|
||||||
|
|
||||||
显示流式计算,其中第一列显示的以冒号隔开的两个数字为stream-id, 为启动该stream应用连接的connection-id和发起stream的次数。
|
显示流式计算,其中第一列显示的以冒号隔开的两个数字为stream-id, 为启动该stream应用连接的connection-id和发起stream的次数。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
KILL STREAM <stream-id>;
|
KILL STREAM <stream-id>;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -413,3 +429,65 @@ TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下
|
||||||
您可以通过修改系统配置文件taos.cfg来配置不同的数据目录和日志目录。
|
您可以通过修改系统配置文件taos.cfg来配置不同的数据目录和日志目录。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## TDengine参数限制与保留关键字
|
||||||
|
|
||||||
|
- 数据库名:不能包含“.”以及特殊字符,不能超过32个字符
|
||||||
|
- 表名:不能包含“.”以及特殊字符,与所属数据库名一起,不能超过192个字符
|
||||||
|
- 表的列名:不能包含特殊字符,不能超过64个字符
|
||||||
|
- 表的列数:不能超过1024列
|
||||||
|
- 记录的最大长度:包括时间戳8 byte,不能超过16KB
|
||||||
|
- 单条SQL语句默认最大字符串长度:65480 byte
|
||||||
|
- 数据库副本数:不能超过3
|
||||||
|
- 用户名:不能超过20个byte
|
||||||
|
- 用户密码:不能超过15个byte
|
||||||
|
- 标签(Tags)数量:不能超过128个
|
||||||
|
- 标签的总长度:不能超过16Kbyte
|
||||||
|
- 记录条数:仅受存储空间限制
|
||||||
|
- 表的个数:仅受节点个数限制
|
||||||
|
- 库的个数:仅受节点个数限制
|
||||||
|
- 单个库上虚拟节点个数:不能超过64个
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
目前TDengine有将近200个内部保留关键字,这些关键字无论大小写均不可以用作库名、表名、STable名、数据列名及标签列名等。这些关键字列表如下:
|
||||||
|
|
||||||
|
| 关键字列表 | | | | |
|
||||||
|
| ---------- | ----------- | ------------ | ---------- | --------- |
|
||||||
|
| ABLOCKS | CONNECTION | GT | MINUS | SHOW |
|
||||||
|
| ABORT | CONNECTIONS | ID | MNODES | SLASH |
|
||||||
|
| ACCOUNT | COPY | IF | MODULES | SLIDING |
|
||||||
|
| ACCOUNTS | COUNT | IGNORE | NCHAR | SMALLINT |
|
||||||
|
| ADD | CREATE | IMMEDIATE | NE | SPREAD |
|
||||||
|
| AFTER | CTIME | IMPORT | NONE | STAR |
|
||||||
|
| ALL | DATABASE | IN | NOT | STATEMENT |
|
||||||
|
| ALTER | DATABASES | INITIALLY | NOTNULL | STDDEV |
|
||||||
|
| AND | DAYS | INSERT | NOW | STREAM |
|
||||||
|
| AS | DEFERRED | INSTEAD | OF | STREAMS |
|
||||||
|
| ASC | DELIMITERS | INTEGER | OFFSET | STRING |
|
||||||
|
| ATTACH | DESC | INTERVAL | OR | SUM |
|
||||||
|
| AVG | DESCRIBE | INTO | ORDER | TABLE |
|
||||||
|
| BEFORE | DETACH | IP | PASS | TABLES |
|
||||||
|
| BEGIN | DIFF | IS | PERCENTILE | TAG |
|
||||||
|
| BETWEEN | DIVIDE | ISNULL | PLUS | TAGS |
|
||||||
|
| BIGINT | DNODE | JOIN | PRAGMA | TBLOCKS |
|
||||||
|
| BINARY | DNODES | KEEP | PREV | TBNAME |
|
||||||
|
| BITAND | DOT | KEY | PRIVILEGE | TIMES |
|
||||||
|
| BITNOT | DOUBLE | KILL | QUERIES | TIMESTAMP |
|
||||||
|
| BITOR | DROP | LAST | QUERY | TINYINT |
|
||||||
|
| BOOL | EACH | LE | RAISE | TOP |
|
||||||
|
| BOTTOM | END | LEASTSQUARES | REM | TRIGGER |
|
||||||
|
| BY | EQ | LIKE | REPLACE | UMINUS |
|
||||||
|
| CACHE | EXISTS | LIMIT | REPLICA | UPLUS |
|
||||||
|
| CASCADE | EXPLAIN | LINEAR | RESET | USE |
|
||||||
|
| CHANGE | FAIL | LOCAL | RESTRICT | USER |
|
||||||
|
| CLOG | FILL | LP | ROW | USERS |
|
||||||
|
| CLUSTER | FIRST | LSHIFT | ROWS | USING |
|
||||||
|
| COLON | FLOAT | LT | RP | VALUES |
|
||||||
|
| COLUMN | FOR | MATCH | RSHIFT | VARIABLE |
|
||||||
|
| COMMA | FROM | MAX | SCORES | VGROUPS |
|
||||||
|
| COMP | GE | METRIC | SELECT | VIEW |
|
||||||
|
| CONCAT | GLOB | METRICS | SEMI | WAVG |
|
||||||
|
| CONFIGS | GRANTS | MIN | SET | WHERE |
|
||||||
|
| CONFLICT | GROUP | | | |
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ create table avg_vol as select avg(voltage) from meters interval(1m) sliding(30s
|
||||||
会自动创建一个名为 `avg_vol` 的新表,然后每隔30秒,TDengine会增量执行 `as` 后面的 SQL 语句,
|
会自动创建一个名为 `avg_vol` 的新表,然后每隔30秒,TDengine会增量执行 `as` 后面的 SQL 语句,
|
||||||
并将查询结果写入这个表中,用户程序后续只要从 `avg_vol` 中查询数据即可。 例如:
|
并将查询结果写入这个表中,用户程序后续只要从 `avg_vol` 中查询数据即可。 例如:
|
||||||
|
|
||||||
```shell
|
```mysql
|
||||||
taos> select * from avg_vol;
|
taos> select * from avg_vol;
|
||||||
ts | avg_voltage_ |
|
ts | avg_voltage_ |
|
||||||
===================================================
|
===================================================
|
||||||
|
@ -72,14 +72,13 @@ taos> select * from avg_vol;
|
||||||
|
|
||||||
需要注意,查询时间窗口的最小值是10毫秒,没有时间窗口范围的上限。
|
需要注意,查询时间窗口的最小值是10毫秒,没有时间窗口范围的上限。
|
||||||
|
|
||||||
|
|
||||||
此外,TDengine还支持用户指定连续查询的起止时间。
|
此外,TDengine还支持用户指定连续查询的起止时间。
|
||||||
如果不输入开始时间,连续查询将从第一条原始数据所在的时间窗口开始;
|
如果不输入开始时间,连续查询将从第一条原始数据所在的时间窗口开始;
|
||||||
如果没有输入结束时间,连续查询将永久运行;
|
如果没有输入结束时间,连续查询将永久运行;
|
||||||
如果用户指定了结束时间,连续查询在系统时间达到指定的时间以后停止运行。
|
如果用户指定了结束时间,连续查询在系统时间达到指定的时间以后停止运行。
|
||||||
比如使用下面的SQL创建的连续查询将运行一小时,之后会自动停止。
|
比如使用下面的SQL创建的连续查询将运行一小时,之后会自动停止。
|
||||||
|
|
||||||
```sql
|
```mysql
|
||||||
create table avg_vol as select avg(voltage) from meters where ts > now and ts <= now + 1h interval(1m) sliding(30s);
|
create table avg_vol as select avg(voltage) from meters where ts > now and ts <= now + 1h interval(1m) sliding(30s);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,16 @@ DROP DNODE "fqdn:port";
|
||||||
|
|
||||||
其中fqdn是被删除的节点的FQDN,port是其对外服务器的端口号
|
其中fqdn是被删除的节点的FQDN,port是其对外服务器的端口号
|
||||||
|
|
||||||
|
<font color=green>**【注意】**</font>
|
||||||
|
|
||||||
|
- 一个数据节点一旦被drop之后,不能重新加入集群。需要将此节点重新部署(清空数据文件夹)。集群在完成drop dnode操作之前,会将该dnode的数据迁移走。
|
||||||
|
|
||||||
|
- 请注意 drop dnode 和 停止taosd进程是两个不同的概念,不要混淆:因为删除dnode之前要执行迁移数据的操作,因此被删除的dnode必须保持在线状态。待删除操作结束之后,才能停止taosd进程。
|
||||||
|
|
||||||
|
- 一个数据节点被drop之后,其他节点都会感知到这个dnodeID的删除操作,任何集群中的节点都不会再接收此dnodeID的请求。
|
||||||
|
|
||||||
|
- dnodeID的是集群自动分配的,不得人工指定。它在生成时递增的,不会重复。
|
||||||
|
|
||||||
### 查看数据节点
|
### 查看数据节点
|
||||||
|
|
||||||
执行CLI程序taos,使用root账号登录进TDengine系统,执行:
|
执行CLI程序taos,使用root账号登录进TDengine系统,执行:
|
||||||
|
|
|
@ -1,8 +1,28 @@
|
||||||
# 连接器
|
# 连接器
|
||||||
|
|
||||||
TDengine提供了丰富的应用程序开发接口,其中包括C/C++、JAVA、Python、RESTful、Go等,便于用户快速开发应用。
|
TDengine提供了丰富的应用程序开发接口,其中包括C/C++、C# 、Java、Python、Go、Node.js、RESTful 等,便于用户快速开发应用。
|
||||||
|
|
||||||
注意:所有执行 SQL 语句的 API,例如 C/C++ Connector 中的 `tao_query`、`taos_query_a`、`taos_subscribe` 等,以及其它语言中与它们对应的API,每次都只能执行一条 SQL 语句,如果实际参数中包含了多条语句,它们的行为是未定义的。
|

|
||||||
|
|
||||||
|
目前TDengine的连接器可支持的平台广泛,目前包括:X64/X86/ARM64/ARM32/MIPS/Alpha等硬件平台,以及Linux/Win64/Win32等开发环境。对照矩阵如下:
|
||||||
|
|
||||||
|
| **CPU** | **X64 64bit** | **X64 64bit** | **X64 64bit** | **X86 32bit** | **ARM64** | **ARM32** | **MIPS 龙芯** | **Alpha 申威** | **X64 海光** |
|
||||||
|
| ----------- | --------------- | --------------- | --------------- | --------------- | --------- | --------- | --------------- | ---------------- | -------------- |
|
||||||
|
| **OS** | **Linux** | **Win64** | **Win32** | **Win32** | **Linux** | **Linux** | **Linux** | **Linux** | **Linux** |
|
||||||
|
| **C/C++** | ● | ● | ● | ○ | ● | ● | ● | ● | ● |
|
||||||
|
| **JDBC** | ● | ● | ● | ○ | ● | ● | ● | ● | ● |
|
||||||
|
| **Python** | ● | ● | ● | ○ | ● | ● | ● | -- | ● |
|
||||||
|
| **Go** | ● | ● | ● | ○ | ● | ● | ○ | -- | -- |
|
||||||
|
| **NodeJs** | ● | ● | ○ | ○ | ● | ● | ○ | -- | -- |
|
||||||
|
| **C#** | ○ | ● | ● | ○ | ○ | ○ | ○ | -- | -- |
|
||||||
|
| **RESTful** | ● | ● | ● | ● | ● | ● | ● | ● | ● |
|
||||||
|
|
||||||
|
其中 ● 表示经过官方测试验证, ○ 表示非官方测试验证。
|
||||||
|
|
||||||
|
注意:
|
||||||
|
|
||||||
|
* 所有执行 SQL 语句的 API,例如 C/C++ Connector 中的 `tao_query`、`taos_query_a`、`taos_subscribe` 等,以及其它语言中与它们对应的API,每次都只能执行一条 SQL 语句,如果实际参数中包含了多条语句,它们的行为是未定义的。
|
||||||
|
* 升级到TDengine到2.0.8.0版本的用户,必须更新JDBC连接TDengine必须升级taos-jdbcdriver到2.0.12及以上。
|
||||||
|
|
||||||
## C/C++ Connector
|
## C/C++ Connector
|
||||||
|
|
||||||
|
@ -285,7 +305,7 @@ TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时
|
||||||
### 安装准备
|
### 安装准备
|
||||||
* 已安装TDengine, 如果客户端在Windows上,需要安装Windows 版本的TDengine客户端 [(Windows TDengine 客户端安装)][4]
|
* 已安装TDengine, 如果客户端在Windows上,需要安装Windows 版本的TDengine客户端 [(Windows TDengine 客户端安装)][4]
|
||||||
* 已安装python 2.7 or >= 3.4
|
* 已安装python 2.7 or >= 3.4
|
||||||
* 已安装pip
|
* 已安装pip 或 pip3
|
||||||
|
|
||||||
### Python客户端安装
|
### Python客户端安装
|
||||||
|
|
||||||
|
@ -297,7 +317,7 @@ TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时
|
||||||
|
|
||||||
或
|
或
|
||||||
|
|
||||||
`pip install src/connector/python/linux/python3/`
|
`pip3 install src/connector/python/linux/python3/`
|
||||||
|
|
||||||
#### Windows
|
#### Windows
|
||||||
在已安装Windows TDengine 客户端的情况下, 将文件"C:\TDengine\driver\taos.dll" 拷贝到 "C:\windows\system32" 目录下, 然后进入Windwos <em>cmd</em> 命令行界面
|
在已安装Windows TDengine 客户端的情况下, 将文件"C:\TDengine\driver\taos.dll" 拷贝到 "C:\windows\system32" 目录下, 然后进入Windwos <em>cmd</em> 命令行界面
|
||||||
|
@ -457,13 +477,13 @@ HTTP请求的BODY里就是一个完整的SQL语句,SQL语句中的数据表应
|
||||||
|
|
||||||
使用curl通过自定义身份认证方式来发起一个HTTP Request,语法如下:
|
使用curl通过自定义身份认证方式来发起一个HTTP Request,语法如下:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl -H 'Authorization: Basic <TOKEN>' -d '<SQL>' <ip>:<PORT>/rest/sql
|
curl -H 'Authorization: Basic <TOKEN>' -d '<SQL>' <ip>:<PORT>/rest/sql
|
||||||
```
|
```
|
||||||
|
|
||||||
或者
|
或者
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
|
curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -473,7 +493,7 @@ curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
|
||||||
|
|
||||||
返回值为JSON格式,如下:
|
返回值为JSON格式,如下:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"head": ["Time Stamp","current", …],
|
"head": ["Time Stamp","current", …],
|
||||||
|
@ -496,7 +516,7 @@ curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
|
||||||
|
|
||||||
HTTP请求中需要带有授权码`<TOKEN>`,用于身份识别。授权码通常由管理员提供,可简单的通过发送`HTTP GET`请求来获取授权码,操作如下:
|
HTTP请求中需要带有授权码`<TOKEN>`,用于身份识别。授权码通常由管理员提供,可简单的通过发送`HTTP GET`请求来获取授权码,操作如下:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl http://<ip>:6041/rest/login/<username>/<password>
|
curl http://<ip>:6041/rest/login/<username>/<password>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -510,13 +530,13 @@ curl http://<ip>:6041/rest/login/<username>/<password>
|
||||||
|
|
||||||
获取授权码示例:
|
获取授权码示例:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl http://192.168.0.1:6041/rest/login/root/taosdata
|
curl http://192.168.0.1:6041/rest/login/root/taosdata
|
||||||
```
|
```
|
||||||
|
|
||||||
返回值:
|
返回值:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
@ -528,12 +548,12 @@ curl http://192.168.0.1:6041/rest/login/root/taosdata
|
||||||
|
|
||||||
- 在demo库里查询表d1001的所有记录:
|
- 在demo库里查询表d1001的所有记录:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sql
|
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sql
|
||||||
```
|
```
|
||||||
返回值:
|
返回值:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"head": ["Time Stamp","current","voltage","phase"],
|
"head": ["Time Stamp","current","voltage","phase"],
|
||||||
|
@ -547,12 +567,12 @@ curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001
|
||||||
|
|
||||||
- 创建库demo:
|
- 创建库demo:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 192.168.0.1:6041/rest/sql
|
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 192.168.0.1:6041/rest/sql
|
||||||
```
|
```
|
||||||
|
|
||||||
返回值:
|
返回值:
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"head": ["affected_rows"],
|
"head": ["affected_rows"],
|
||||||
|
@ -567,13 +587,13 @@ curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 19
|
||||||
|
|
||||||
HTTP请求URL采用`sqlt`时,返回结果集的时间戳将采用Unix时间戳格式表示,例如
|
HTTP请求URL采用`sqlt`时,返回结果集的时间戳将采用Unix时间戳格式表示,例如
|
||||||
|
|
||||||
```
|
```bash
|
||||||
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sqlt
|
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sqlt
|
||||||
```
|
```
|
||||||
|
|
||||||
返回值:
|
返回值:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"head": ["column1","column2","column3"],
|
"head": ["column1","column2","column3"],
|
||||||
|
@ -588,13 +608,13 @@ curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001
|
||||||
#### 结果集采用UTC时间字符串
|
#### 结果集采用UTC时间字符串
|
||||||
|
|
||||||
HTTP请求URL采用`sqlutc`时,返回结果集的时间戳将采用UTC时间字符串表示,例如
|
HTTP请求URL采用`sqlutc`时,返回结果集的时间戳将采用UTC时间字符串表示,例如
|
||||||
```
|
```bash
|
||||||
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.t1' 192.168.0.1:6041/rest/sqlutc
|
curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.t1' 192.168.0.1:6041/rest/sqlutc
|
||||||
```
|
```
|
||||||
|
|
||||||
返回值:
|
返回值:
|
||||||
|
|
||||||
```
|
```json
|
||||||
{
|
{
|
||||||
"status": "succ",
|
"status": "succ",
|
||||||
"head": ["column1","column2","column3"],
|
"head": ["column1","column2","column3"],
|
||||||
|
@ -664,30 +684,52 @@ import (
|
||||||
_ "github.com/taosdata/driver-go/taosSql"
|
_ "github.com/taosdata/driver-go/taosSql"
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
**建议Go版本是1.13或以上,并开启模块支持:**
|
||||||
|
|
||||||
|
```
|
||||||
|
go env -w GO111MODULE=on
|
||||||
|
go env -w GOPROXY=https://goproxy.io,direct
|
||||||
|
```
|
||||||
|
|
||||||
### 常用API
|
### 常用API
|
||||||
* `sql.Open(DRIVER_NAME string, dataSourceName string) *DB`
|
|
||||||
|
- sql.Open(DRIVER_NAME string, dataSourceName string) *DB`
|
||||||
该API用来打开DB,返回一个类型为*DB的对象,一般情况下,DRIVER_NAME设置为字符串`taosSql`, dataSourceName设置为字符串`user:password@/tcp(host:port)/dbname`,如果客户想要用多个goroutine并发访问TDengine, 那么需要在各个goroutine中分别创建一个sql.Open对象并用之访问TDengine
|
|
||||||
|
该API用来打开DB,返回一个类型为*DB的对象,一般情况下,DRIVER_NAME设置为字符串`taosSql`, dataSourceName设置为字符串`user:password@/tcp(host:port)/dbname`,如果客户想要用多个goroutine并发访问TDengine, 那么需要在各个goroutine中分别创建一个sql.Open对象并用之访问TDengine
|
||||||
**注意**: 该API成功创建的时候,并没有做权限等检查,只有在真正执行Query或者Exec的时候才能真正的去创建连接,并同时检查user/password/host/port是不是合法。 另外,由于整个驱动程序大部分实现都下沉到taosSql所依赖的libtaos中。所以,sql.Open本身特别轻量。
|
|
||||||
|
**注意**: 该API成功创建的时候,并没有做权限等检查,只有在真正执行Query或者Exec的时候才能真正的去创建连接,并同时检查user/password/host/port是不是合法。 另外,由于整个驱动程序大部分实现都下沉到taosSql所依赖的libtaos中。所以,sql.Open本身特别轻量。
|
||||||
* `func (db *DB) Exec(query string, args ...interface{}) (Result, error)`
|
|
||||||
|
- `func (db *DB) Exec(query string, args ...interface{}) (Result, error)`
|
||||||
|
|
||||||
sql.Open内置的方法,用来执行非查询相关SQL
|
sql.Open内置的方法,用来执行非查询相关SQL
|
||||||
|
|
||||||
|
- `func (db *DB) Query(query string, args ...interface{}) (*Rows, error)`
|
||||||
* `func (db *DB) Query(query string, args ...interface{}) (*Rows, error)`
|
|
||||||
|
|
||||||
sql.Open内置的方法,用来执行查询语句
|
sql.Open内置的方法,用来执行查询语句
|
||||||
|
|
||||||
|
- `func (db *DB) Prepare(query string) (*Stmt, error)`
|
||||||
|
|
||||||
|
sql.Open内置的方法,Prepare creates a prepared statement for later queries or executions.
|
||||||
|
|
||||||
|
- `func (s *Stmt) Exec(args ...interface{}) (Result, error)`
|
||||||
|
|
||||||
|
sql.Open内置的方法,executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
|
||||||
|
|
||||||
|
- `func (s *Stmt) Query(args ...interface{}) (*Rows, error)`
|
||||||
|
|
||||||
|
sql.Open内置的方法,Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
|
||||||
|
|
||||||
|
- `func (s *Stmt) Close() error`
|
||||||
|
|
||||||
|
sql.Open内置的方法,Close closes the statement.
|
||||||
|
|
||||||
## Node.js Connector
|
## Node.js Connector
|
||||||
|
|
||||||
TDengine 同时也提供了node.js 的连接器。用户可以通过[npm](https://www.npmjs.com/)来进行安装,也可以通过源代码*src/connector/nodejs/* 来进行安装。[具体安装步骤如下](https://github.com/taosdata/tdengine/tree/master/src/connector/nodejs):
|
TDengine 同时也提供了node.js 的连接器。用户可以通过[npm](https://www.npmjs.com/)来进行安装,也可以通过源代码*src/connector/nodejs/* 来进行安装。[具体安装步骤如下](https://github.com/taosdata/tdengine/tree/master/src/connector/nodejs):
|
||||||
|
|
||||||
首先,通过[npm](https://www.npmjs.com/)安装node.js 连接器.
|
首先,通过[npm](https://www.npmjs.com/)安装node.js 连接器.
|
||||||
|
|
||||||
```cmd
|
```bash
|
||||||
npm install td2.0-connector
|
npm install td2.0-connector
|
||||||
```
|
```
|
||||||
我们建议用户使用npm 安装node.js连接器。如果您没有安装npm, 可以将*src/connector/nodejs/*拷贝到您的nodejs 项目目录下
|
我们建议用户使用npm 安装node.js连接器。如果您没有安装npm, 可以将*src/connector/nodejs/*拷贝到您的nodejs 项目目录下
|
||||||
|
@ -701,32 +743,6 @@ npm install td2.0-connector
|
||||||
- `make`
|
- `make`
|
||||||
- c语言编译器比如[GCC](https://gcc.gnu.org)
|
- c语言编译器比如[GCC](https://gcc.gnu.org)
|
||||||
|
|
||||||
### macOS
|
|
||||||
|
|
||||||
- `python` (建议`v2.7` , `v3.x.x` 目前还不支持)
|
|
||||||
|
|
||||||
- Xcode
|
|
||||||
|
|
||||||
- 然后通过Xcode安装
|
|
||||||
|
|
||||||
```
|
|
||||||
Command Line Tools
|
|
||||||
```
|
|
||||||
|
|
||||||
在
|
|
||||||
```
|
|
||||||
Xcode -> Preferences -> Locations
|
|
||||||
```
|
|
||||||
|
|
||||||
目录下可以找到这个工具。或者在终端里执行
|
|
||||||
|
|
||||||
```
|
|
||||||
xcode-select --install
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
- 该步执行后 `gcc` 和 `make`就被安装上了
|
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
#### 安装方法1
|
#### 安装方法1
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Java Connector
|
# Java Connector
|
||||||
|
|
||||||
|
Java连接器支持的系统有: Linux 64/Windows x64/Windows x86。
|
||||||
|
|
||||||
TDengine 为了方便 Java 应用使用,提供了遵循 JDBC 标准(3.0)API 规范的 `taos-jdbcdriver` 实现。目前可以通过 [Sonatype Repository][1] 搜索并下载。
|
TDengine 为了方便 Java 应用使用,提供了遵循 JDBC 标准(3.0)API 规范的 `taos-jdbcdriver` 实现。目前可以通过 [Sonatype Repository][1] 搜索并下载。
|
||||||
|
|
||||||
由于 TDengine 是使用 c 语言开发的,使用 taos-jdbcdriver 驱动包时需要依赖系统对应的本地函数库。
|
由于 TDengine 是使用 c 语言开发的,使用 taos-jdbcdriver 驱动包时需要依赖系统对应的本地函数库。
|
||||||
|
@ -24,7 +26,8 @@ TDengine 的 JDBC 驱动实现尽可能的与关系型数据库驱动保持一
|
||||||
|
|
||||||
| taos-jdbcdriver 版本 | TDengine 版本 | JDK 版本 |
|
| taos-jdbcdriver 版本 | TDengine 版本 | JDK 版本 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 2.0.4 | 2.0.0.x 及以上 | 1.8.x |
|
| 2.0.12 及以上 | 2.0.8.0 及以上 | 1.8.x |
|
||||||
|
| 2.0.4 - 2.0.11 | 2.0.0.0 - 2.0.7.x | 1.8.x |
|
||||||
| 1.0.3 | 1.6.1.x 及以上 | 1.8.x |
|
| 1.0.3 | 1.6.1.x 及以上 | 1.8.x |
|
||||||
| 1.0.2 | 1.6.1.x 及以上 | 1.8.x |
|
| 1.0.2 | 1.6.1.x 及以上 | 1.8.x |
|
||||||
| 1.0.1 | 1.6.1.x 及以上 | 1.8.x |
|
| 1.0.1 | 1.6.1.x 及以上 | 1.8.x |
|
||||||
|
|
|
@ -117,7 +117,17 @@ Connection = DriverManager.getConnection(url, properties);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 16. 怎么报告问题?
|
## 16. 如何进行数据迁移?
|
||||||
|
|
||||||
|
TDengine是根据hostname唯一标志一台机器的,在数据文件从机器A移动机器B时,注意如下两件事:
|
||||||
|
|
||||||
|
- 2.0.0.0 至 2.0.6.x 的版本,重新配置机器B的hostname为机器A的hostname
|
||||||
|
- 2.0.7.0 及以后的版本,到/var/lib/taos/dnode下,修复dnodeEps.json的dnodeId对应的FQDN,重启。确保机器内所有机器的此文件是完全相同的。
|
||||||
|
- 1.x 和 2.x 版本的存储结构不兼容,需要使用迁移工具或者自己开发应用导出导入数据。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 17. 怎么报告问题?
|
||||||
|
|
||||||
如果 FAQ 中的信息不能够帮到您,需要 TDengine 技术团队的技术支持与协助,请将以下两个目录中内容打包:
|
如果 FAQ 中的信息不能够帮到您,需要 TDengine 技术团队的技术支持与协助,请将以下两个目录中内容打包:
|
||||||
1. /var/log/taos
|
1. /var/log/taos
|
||||||
|
|
|
@ -24,7 +24,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6,
|
||||||
|
|
||||||
- 要提高写入效率,需要批量写入。一批写入的记录条数越多,插入效率就越高。但一条记录不能超过16K,一条SQL语句总长度不能超过64K(可通过参数maxSQLLength配置,最大可配置为1M)。
|
- 要提高写入效率,需要批量写入。一批写入的记录条数越多,插入效率就越高。但一条记录不能超过16K,一条SQL语句总长度不能超过64K(可通过参数maxSQLLength配置,最大可配置为1M)。
|
||||||
- TDengine支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开20个以上的线程同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程切频繁切换,带来额外开销。
|
- TDengine支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开20个以上的线程同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程切频繁切换,带来额外开销。
|
||||||
- 对同一张表,如果新插入记录的时间戳已经存在,新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。
|
- 对同一张表,如果新插入记录的时间戳已经存在,默认(没有使用 UPDATE 1 创建数据库)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。
|
||||||
- 写入的数据的时间戳必须大于当前时间减去配置参数keep的时间。如果keep配置为3650天,那么无法写入比3650天还老的数据。写入数据的时间戳也不能大于当前时间加配置参数days。如果days配置为2,那么无法写入比当前时间还晚2天的数据。
|
- 写入的数据的时间戳必须大于当前时间减去配置参数keep的时间。如果keep配置为3650天,那么无法写入比3650天还老的数据。写入数据的时间戳也不能大于当前时间加配置参数days。如果days配置为2,那么无法写入比当前时间还晚2天的数据。
|
||||||
|
|
||||||
## Prometheus直接写入
|
## Prometheus直接写入
|
||||||
|
@ -37,7 +37,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6,
|
||||||
- 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在bailongma所在的linux服务器(可以与TDengine在同一台服务器,或者不同服务器)
|
- 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在bailongma所在的linux服务器(可以与TDengine在同一台服务器,或者不同服务器)
|
||||||
|
|
||||||
Bailongma项目中有一个文件夹blm_prometheus,存放了prometheus的写入API程序。编译过程如下:
|
Bailongma项目中有一个文件夹blm_prometheus,存放了prometheus的写入API程序。编译过程如下:
|
||||||
```
|
```bash
|
||||||
cd blm_prometheus
|
cd blm_prometheus
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
|
@ -79,7 +79,7 @@ blm_prometheus对prometheus提供服务的端口号。
|
||||||
### 启动示例
|
### 启动示例
|
||||||
|
|
||||||
通过以下命令启动一个blm_prometheus的API服务
|
通过以下命令启动一个blm_prometheus的API服务
|
||||||
```
|
```bash
|
||||||
./blm_prometheus -port 8088
|
./blm_prometheus -port 8088
|
||||||
```
|
```
|
||||||
假设blm_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中<remote_write>部分增加url为
|
假设blm_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中<remote_write>部分增加url为
|
||||||
|
@ -107,7 +107,7 @@ prometheus产生的数据格式如下:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。blm_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
|
其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。blm_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
|
||||||
```
|
```mysql
|
||||||
use prometheus;
|
use prometheus;
|
||||||
select * from apiserver_request_latencies_bucket;
|
select * from apiserver_request_latencies_bucket;
|
||||||
```
|
```
|
||||||
|
@ -124,7 +124,7 @@ select * from apiserver_request_latencies_bucket;
|
||||||
|
|
||||||
Bailongma项目中有一个文件夹blm_telegraf,存放了Telegraf的写入API程序。编译过程如下:
|
Bailongma项目中有一个文件夹blm_telegraf,存放了Telegraf的写入API程序。编译过程如下:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
cd blm_telegraf
|
cd blm_telegraf
|
||||||
go build
|
go build
|
||||||
```
|
```
|
||||||
|
@ -175,7 +175,7 @@ blm_telegraf对telegraf提供服务的端口号。
|
||||||
|
|
||||||
### 启动示例
|
### 启动示例
|
||||||
通过以下命令启动一个blm_telegraf的API服务
|
通过以下命令启动一个blm_telegraf的API服务
|
||||||
```
|
```bash
|
||||||
./blm_telegraf -host 127.0.0.1 -port 8089
|
./blm_telegraf -host 127.0.0.1 -port 8089
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ telegraf产生的数据格式如下:
|
||||||
|
|
||||||
其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。blm_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,Timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
|
其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。blm_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,Timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。
|
||||||
|
|
||||||
```
|
```mysql
|
||||||
use telegraf;
|
use telegraf;
|
||||||
select * from cpu;
|
select * from cpu;
|
||||||
```
|
```
|
||||||
|
|
|
@ -29,8 +29,12 @@
|
||||||
# number of threads per CPU core
|
# number of threads per CPU core
|
||||||
# numOfThreadsPerCore 1.0
|
# numOfThreadsPerCore 1.0
|
||||||
|
|
||||||
# the proportion of total threads responsible for query
|
# the proportion of total CPU cores available for query processing
|
||||||
# ratioOfQueryThreads 0.5
|
# 2.0: the query threads will be set to double of the CPU cores.
|
||||||
|
# 1.0: all CPU cores are available for query processing [default].
|
||||||
|
# 0.5: only half of the CPU cores are available for query.
|
||||||
|
# 0.0: only one core available.
|
||||||
|
# tsRatioOfQueryCores 1.0
|
||||||
|
|
||||||
# number of management nodes in the system
|
# number of management nodes in the system
|
||||||
# numOfMnodes 3
|
# numOfMnodes 3
|
||||||
|
@ -265,5 +269,5 @@
|
||||||
# enable/disable stream (continuous query)
|
# enable/disable stream (continuous query)
|
||||||
# stream 1
|
# stream 1
|
||||||
|
|
||||||
# only 50% CPU resources will be used in query processing
|
# in retrieve blocking model, only in 50% query threads will be used in query processing in dnode
|
||||||
# halfCoresForQuery 0
|
# retrieveBlockingModel 0
|
||||||
|
|
|
@ -9,6 +9,9 @@ set -e
|
||||||
verMode=edge
|
verMode=edge
|
||||||
pagMode=full
|
pagMode=full
|
||||||
|
|
||||||
|
iplist=""
|
||||||
|
serverFqdn=""
|
||||||
|
|
||||||
# -----------------------Variables definition---------------------
|
# -----------------------Variables definition---------------------
|
||||||
script_dir=$(dirname $(readlink -f "$0"))
|
script_dir=$(dirname $(readlink -f "$0"))
|
||||||
# Dynamic directory
|
# Dynamic directory
|
||||||
|
@ -227,6 +230,157 @@ function install_header() {
|
||||||
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_newHostname_to_hosts() {
|
||||||
|
localIp="127.0.0.1"
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
iphost=$(cat /etc/hosts | grep $1 | awk '{print $1}')
|
||||||
|
arr=($iphost)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$localIp" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||:
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_hostname() {
|
||||||
|
echo -e -n "${GREEN}Please enter one hostname(must not be 'localhost')${NC}:"
|
||||||
|
read newHostname
|
||||||
|
while true; do
|
||||||
|
if [[ ! -z "$newHostname" && "$newHostname" != "localhost" ]]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
read -p "Please enter one hostname(must not be 'localhost'):" newHostname
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
${csudo} hostname $newHostname ||:
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
echo
|
||||||
|
echo "set hostname fail!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
#echo -e -n "$(hostnamectl status --static)"
|
||||||
|
#echo -e -n "$(hostnamectl status --transient)"
|
||||||
|
#echo -e -n "$(hostnamectl status --pretty)"
|
||||||
|
|
||||||
|
#ubuntu/centos /etc/hostname
|
||||||
|
if [[ -e /etc/hostname ]]; then
|
||||||
|
${csudo} echo $newHostname > /etc/hostname ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
#debian: #HOSTNAME=yourname
|
||||||
|
if [[ -e /etc/sysconfig/network ]]; then
|
||||||
|
${csudo} sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$newHostname
|
||||||
|
|
||||||
|
if [[ -e /etc/hosts ]]; then
|
||||||
|
add_newHostname_to_hosts $newHostname
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_correct_ipaddr() {
|
||||||
|
newIp=$1
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
arr=($iplist)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$newIp" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_ipAsFqdn() {
|
||||||
|
iplist=$(ip address |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F "/" '{print $1}') ||:
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
iplist=$(ifconfig |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F ":" '{print $2}') ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}"
|
||||||
|
localFqdn="127.0.0.1"
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
echo
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e -n "${GREEN}Please choose an IP from local IP list${NC}:"
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}$iplist${NC}"
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Notes: if IP is used as the node name, data can NOT be migrated to other machine directly${NC}:"
|
||||||
|
read localFqdn
|
||||||
|
while true; do
|
||||||
|
if [ ! -z "$localFqdn" ]; then
|
||||||
|
# Check if correct ip address
|
||||||
|
is_correct_ipaddr $localFqdn
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
else
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function local_fqdn_check() {
|
||||||
|
#serverFqdn=$(hostname -f)
|
||||||
|
echo
|
||||||
|
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||||
|
echo
|
||||||
|
if [[ "$serverFqdn" == "" ]] || [[ "$serverFqdn" == "localhost" ]]; then
|
||||||
|
echo -e -n "${GREEN}It is strongly recommended to configure a hostname for this machine ${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
read -r -p "Set hostname now? [Y/n] " input
|
||||||
|
if [ ! -n "$input" ]; then
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
else
|
||||||
|
case $input in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
[nN][oO]|[nN])
|
||||||
|
set_ipAsFqdn
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Invalid input..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function install_config() {
|
function install_config() {
|
||||||
#${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || :
|
#${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || :
|
||||||
|
|
||||||
|
@ -247,7 +401,9 @@ function install_config() {
|
||||||
|
|
||||||
if [ "$interactiveFqdn" == "no" ]; then
|
if [ "$interactiveFqdn" == "no" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local_fqdn_check
|
||||||
|
|
||||||
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
||||||
#FQDN_FORMAT="(:[1-6][0-9][0-9][0-9][0-9]$)"
|
#FQDN_FORMAT="(:[1-6][0-9][0-9][0-9][0-9]$)"
|
||||||
|
@ -446,6 +602,9 @@ function install_service_on_systemd() {
|
||||||
${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}"
|
${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}"
|
||||||
|
#${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/setDelay.sh' >> ${taosd_service_config}"
|
||||||
|
#${csudo} bash -c "echo 'ExecStartPost=/usr/local/taos/bin/resetDelay.sh' >> ${taosd_service_config}"
|
||||||
|
#${csudo} bash -c "echo 'ExecStopPost=/usr/local/taos/bin/resetDelay.sh' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
||||||
|
@ -454,6 +613,7 @@ function install_service_on_systemd() {
|
||||||
${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
||||||
|
#${csudo} bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo >> ${taosd_service_config}"
|
${csudo} bash -c "echo >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}"
|
${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}"
|
||||||
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
||||||
|
@ -634,9 +794,9 @@ function update_TDengine() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${openresty_work} = 'true' ]; then
|
if [ ${openresty_work} = 'true' ]; then
|
||||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos -h $serverFqdn${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}"
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos -h $serverFqdn${NC} in shell${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -655,8 +815,8 @@ function update_TDengine() {
|
||||||
function install_TDengine() {
|
function install_TDengine() {
|
||||||
# Start to install
|
# Start to install
|
||||||
if [ ! -e taos.tar.gz ]; then
|
if [ ! -e taos.tar.gz ]; then
|
||||||
echo "File taos.tar.gz does not exist"
|
echo "File taos.tar.gz does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
tar -zxf taos.tar.gz
|
tar -zxf taos.tar.gz
|
||||||
|
|
||||||
|
@ -702,41 +862,54 @@ function install_TDengine() {
|
||||||
echo
|
echo
|
||||||
echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg"
|
echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg"
|
||||||
if ((${service_mod}==0)); then
|
if ((${service_mod}==0)); then
|
||||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}"
|
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}"
|
||||||
elif ((${service_mod}==1)); then
|
elif ((${service_mod}==1)); then
|
||||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}"
|
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}"
|
echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${openresty_work} = 'true' ]; then
|
#if [ ${openresty_work} = 'true' ]; then
|
||||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
# echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
||||||
else
|
#else
|
||||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}"
|
# echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}"
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
if [ ! -z "$firstEp" ]; then
|
if [ ! -z "$firstEp" ]; then
|
||||||
echo
|
tmpFqdn=${firstEp%%:*}
|
||||||
echo -e "${GREEN_DARK}Please run${NC}: taos -h $firstEp${GREEN_DARK} to login into cluster, then${NC}"
|
substr=":"
|
||||||
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
if [[ $firstEp =~ $substr ]];then
|
||||||
echo
|
tmpPort=${firstEp#*:}
|
||||||
|
else
|
||||||
|
tmpPort=""
|
||||||
|
fi
|
||||||
|
if [[ "$tmpPort" != "" ]];then
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
fi
|
||||||
|
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
||||||
|
echo
|
||||||
|
elif [ ! -z "$serverFqdn" ]; then
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}"
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||||
echo
|
echo
|
||||||
else # Only install client
|
else # Only install client
|
||||||
install_bin
|
install_bin
|
||||||
install_config
|
install_config
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}"
|
echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}"
|
||||||
fi
|
fi
|
||||||
touch ~/.taos_history
|
touch ~/.taos_history
|
||||||
|
|
||||||
rm -rf $(tar -tf taos.tar.gz)
|
rm -rf $(tar -tf taos.tar.gz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## ==============================Main program starts from here============================
|
## ==============================Main program starts from here============================
|
||||||
|
serverFqdn=$(hostname -f)
|
||||||
if [ "$verType" == "server" ]; then
|
if [ "$verType" == "server" ]; then
|
||||||
# Install server and client
|
# Install server and client
|
||||||
if [ -x ${bin_dir}/taosd ]; then
|
if [ -x ${bin_dir}/taosd ]; then
|
||||||
|
|
|
@ -9,6 +9,8 @@ set -e
|
||||||
verMode=edge
|
verMode=edge
|
||||||
pagMode=full
|
pagMode=full
|
||||||
|
|
||||||
|
iplist=""
|
||||||
|
serverFqdn=""
|
||||||
# -----------------------Variables definition---------------------
|
# -----------------------Variables definition---------------------
|
||||||
script_dir=$(dirname $(readlink -f "$0"))
|
script_dir=$(dirname $(readlink -f "$0"))
|
||||||
# Dynamic directory
|
# Dynamic directory
|
||||||
|
@ -172,7 +174,6 @@ function install_bin() {
|
||||||
${csudo} rm -f ${bin_link_dir}/power || :
|
${csudo} rm -f ${bin_link_dir}/power || :
|
||||||
${csudo} rm -f ${bin_link_dir}/powerd || :
|
${csudo} rm -f ${bin_link_dir}/powerd || :
|
||||||
${csudo} rm -f ${bin_link_dir}/powerdemo || :
|
${csudo} rm -f ${bin_link_dir}/powerdemo || :
|
||||||
${csudo} rm -f ${bin_link_dir}/powerdump || :
|
|
||||||
${csudo} rm -f ${bin_link_dir}/rmpower || :
|
${csudo} rm -f ${bin_link_dir}/rmpower || :
|
||||||
${csudo} rm -f ${bin_link_dir}/tarbitrator || :
|
${csudo} rm -f ${bin_link_dir}/tarbitrator || :
|
||||||
${csudo} rm -f ${bin_link_dir}/set_core || :
|
${csudo} rm -f ${bin_link_dir}/set_core || :
|
||||||
|
@ -183,7 +184,6 @@ function install_bin() {
|
||||||
[ -x ${install_main_dir}/bin/power ] && ${csudo} ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || :
|
[ -x ${install_main_dir}/bin/power ] && ${csudo} ln -s ${install_main_dir}/bin/power ${bin_link_dir}/power || :
|
||||||
[ -x ${install_main_dir}/bin/powerd ] && ${csudo} ln -s ${install_main_dir}/bin/powerd ${bin_link_dir}/powerd || :
|
[ -x ${install_main_dir}/bin/powerd ] && ${csudo} ln -s ${install_main_dir}/bin/powerd ${bin_link_dir}/powerd || :
|
||||||
[ -x ${install_main_dir}/bin/powerdemo ] && ${csudo} ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || :
|
[ -x ${install_main_dir}/bin/powerdemo ] && ${csudo} ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || :
|
||||||
[ -x ${install_main_dir}/bin/powerdump ] && ${csudo} ln -s ${install_main_dir}/bin/powerdump ${bin_link_dir}/powerdump || :
|
|
||||||
[ -x ${install_main_dir}/bin/remove_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_power.sh ${bin_link_dir}/rmpower || :
|
[ -x ${install_main_dir}/bin/remove_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_power.sh ${bin_link_dir}/rmpower || :
|
||||||
[ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
[ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
||||||
[ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || :
|
[ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || :
|
||||||
|
@ -227,6 +227,157 @@ function install_header() {
|
||||||
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_newHostname_to_hosts() {
|
||||||
|
localIp="127.0.0.1"
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
iphost=$(cat /etc/hosts | grep $1 | awk '{print $1}')
|
||||||
|
arr=($iphost)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$localIp" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||:
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_hostname() {
|
||||||
|
echo -e -n "${GREEN}Please enter one hostname(must not be 'localhost')${NC}:"
|
||||||
|
read newHostname
|
||||||
|
while true; do
|
||||||
|
if [[ ! -z "$newHostname" && "$newHostname" != "localhost" ]]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
read -p "Please enter one hostname(must not be 'localhost'):" newHostname
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
${csudo} hostname $newHostname ||:
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
echo
|
||||||
|
echo "set hostname fail!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
#echo -e -n "$(hostnamectl status --static)"
|
||||||
|
#echo -e -n "$(hostnamectl status --transient)"
|
||||||
|
#echo -e -n "$(hostnamectl status --pretty)"
|
||||||
|
|
||||||
|
#ubuntu/centos /etc/hostname
|
||||||
|
if [[ -e /etc/hostname ]]; then
|
||||||
|
${csudo} echo $newHostname > /etc/hostname ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
#debian: #HOSTNAME=yourname
|
||||||
|
if [[ -e /etc/sysconfig/network ]]; then
|
||||||
|
${csudo} sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$newHostname
|
||||||
|
|
||||||
|
if [[ -e /etc/hosts ]]; then
|
||||||
|
add_newHostname_to_hosts $newHostname
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_correct_ipaddr() {
|
||||||
|
newIp=$1
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
arr=($iplist)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$newIp" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_ipAsFqdn() {
|
||||||
|
iplist=$(ip address |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F "/" '{print $1}') ||:
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
iplist=$(ifconfig |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F ":" '{print $2}') ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}"
|
||||||
|
localFqdn="127.0.0.1"
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
echo
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e -n "${GREEN}Please choose an IP from local IP list${NC}:"
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}$iplist${NC}"
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Notes: if IP is used as the node name, data can NOT be migrated to other machine directly${NC}:"
|
||||||
|
read localFqdn
|
||||||
|
while true; do
|
||||||
|
if [ ! -z "$localFqdn" ]; then
|
||||||
|
# Check if correct ip address
|
||||||
|
is_correct_ipaddr $localFqdn
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
else
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function local_fqdn_check() {
|
||||||
|
#serverFqdn=$(hostname -f)
|
||||||
|
echo
|
||||||
|
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||||
|
echo
|
||||||
|
if [[ "$serverFqdn" == "" ]] || [[ "$serverFqdn" == "localhost" ]]; then
|
||||||
|
echo -e -n "${GREEN}It is strongly recommended to configure a hostname for this machine ${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
read -r -p "Set hostname now? [Y/n] " input
|
||||||
|
if [ ! -n "$input" ]; then
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
else
|
||||||
|
case $input in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
[nN][oO]|[nN])
|
||||||
|
set_ipAsFqdn
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Invalid input..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function install_config() {
|
function install_config() {
|
||||||
#${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || :
|
#${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || :
|
||||||
|
|
||||||
|
@ -248,6 +399,8 @@ function install_config() {
|
||||||
if [ "$interactiveFqdn" == "no" ]; then
|
if [ "$interactiveFqdn" == "no" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local_fqdn_check
|
||||||
|
|
||||||
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
||||||
#FQDN_FORMAT="(:[1-6][0-9][0-9][0-9][0-9]$)"
|
#FQDN_FORMAT="(:[1-6][0-9][0-9][0-9][0-9]$)"
|
||||||
|
@ -611,9 +764,9 @@ function update_PowerDB() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${openresty_work} = 'true' ]; then
|
if [ ${openresty_work} = 'true' ]; then
|
||||||
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power -h $serverFqdn${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell${NC}"
|
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power -h $serverFqdn${NC} in shell${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -686,17 +839,30 @@ function install_PowerDB() {
|
||||||
echo -e "${GREEN_DARK}To start PowerDB ${NC}: powerd${NC}"
|
echo -e "${GREEN_DARK}To start PowerDB ${NC}: powerd${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${openresty_work} = 'true' ]; then
|
#if [ ${openresty_work} = 'true' ]; then
|
||||||
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
# echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
||||||
else
|
#else
|
||||||
echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell${NC}"
|
# echo -e "${GREEN_DARK}To access PowerDB ${NC}: use ${GREEN_UNDERLINE}power${NC} in shell${NC}"
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
if [ ! -z "$firstEp" ]; then
|
if [ ! -z "$firstEp" ]; then
|
||||||
echo
|
tmpFqdn=${firstEp%%:*}
|
||||||
echo -e "${GREEN_DARK}Please run${NC}: power -h $firstEp${GREEN_DARK} to login into cluster, then${NC}"
|
substr=":"
|
||||||
|
if [[ $firstEp =~ $substr ]];then
|
||||||
|
tmpPort=${firstEp#*:}
|
||||||
|
else
|
||||||
|
tmpPort=""
|
||||||
|
fi
|
||||||
|
if [[ "$tmpPort" != "" ]];then
|
||||||
|
echo -e "${GREEN_DARK}To access PowerDB ${NC}: power -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN_DARK}To access PowerDB ${NC}: power -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
fi
|
||||||
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
||||||
echo
|
echo
|
||||||
|
elif [ ! -z "$serverFqdn" ]; then
|
||||||
|
echo -e "${GREEN_DARK}To access PowerDB ${NC}: power -h $serverFqdn${GREEN_DARK} to login into PowerDB server${NC}"
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
echo -e "\033[44;32;1mPowerDB is installed successfully!${NC}"
|
echo -e "\033[44;32;1mPowerDB is installed successfully!${NC}"
|
||||||
echo
|
echo
|
||||||
|
@ -713,6 +879,7 @@ function install_PowerDB() {
|
||||||
|
|
||||||
|
|
||||||
## ==============================Main program starts from here============================
|
## ==============================Main program starts from here============================
|
||||||
|
serverFqdn=$(hostname -f)
|
||||||
if [ "$verType" == "server" ]; then
|
if [ "$verType" == "server" ]; then
|
||||||
# Install server and client
|
# Install server and client
|
||||||
if [ -x ${bin_dir}/powerd ]; then
|
if [ -x ${bin_dir}/powerd ]; then
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
# This file is used to install tdengine rpm package on centos systems. The operating system
|
# This file is used to install tdengine rpm package on centos systems. The operating system
|
||||||
# is required to use systemd to manage services at boot
|
# is required to use systemd to manage services at boot
|
||||||
#set -x
|
#set -x
|
||||||
|
|
||||||
|
iplist=""
|
||||||
|
serverFqdn=""
|
||||||
|
|
||||||
# -----------------------Variables definition---------------------
|
# -----------------------Variables definition---------------------
|
||||||
script_dir=$(dirname $(readlink -f "$0"))
|
script_dir=$(dirname $(readlink -f "$0"))
|
||||||
# Dynamic directory
|
# Dynamic directory
|
||||||
|
@ -92,7 +96,6 @@ function install_bin() {
|
||||||
${csudo} rm -f ${bin_link_dir}/taos || :
|
${csudo} rm -f ${bin_link_dir}/taos || :
|
||||||
${csudo} rm -f ${bin_link_dir}/taosd || :
|
${csudo} rm -f ${bin_link_dir}/taosd || :
|
||||||
${csudo} rm -f ${bin_link_dir}/taosdemo || :
|
${csudo} rm -f ${bin_link_dir}/taosdemo || :
|
||||||
${csudo} rm -f ${bin_link_dir}/taosdump || :
|
|
||||||
${csudo} rm -f ${bin_link_dir}/rmtaos || :
|
${csudo} rm -f ${bin_link_dir}/rmtaos || :
|
||||||
${csudo} rm -f ${bin_link_dir}/set_core || :
|
${csudo} rm -f ${bin_link_dir}/set_core || :
|
||||||
|
|
||||||
|
@ -102,10 +105,160 @@ function install_bin() {
|
||||||
[ -x ${bin_dir}/taos ] && ${csudo} ln -s ${bin_dir}/taos ${bin_link_dir}/taos || :
|
[ -x ${bin_dir}/taos ] && ${csudo} ln -s ${bin_dir}/taos ${bin_link_dir}/taos || :
|
||||||
[ -x ${bin_dir}/taosd ] && ${csudo} ln -s ${bin_dir}/taosd ${bin_link_dir}/taosd || :
|
[ -x ${bin_dir}/taosd ] && ${csudo} ln -s ${bin_dir}/taosd ${bin_link_dir}/taosd || :
|
||||||
[ -x ${bin_dir}/taosdemo ] && ${csudo} ln -s ${bin_dir}/taosdemo ${bin_link_dir}/taosdemo || :
|
[ -x ${bin_dir}/taosdemo ] && ${csudo} ln -s ${bin_dir}/taosdemo ${bin_link_dir}/taosdemo || :
|
||||||
[ -x ${bin_dir}/taosdump ] && ${csudo} ln -s ${bin_dir}/taosdump ${bin_link_dir}/taosdump || :
|
|
||||||
[ -x ${bin_dir}/set_core.sh ] && ${csudo} ln -s ${bin_dir}/set_core.sh ${bin_link_dir}/set_core || :
|
[ -x ${bin_dir}/set_core.sh ] && ${csudo} ln -s ${bin_dir}/set_core.sh ${bin_link_dir}/set_core || :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_newHostname_to_hosts() {
|
||||||
|
localIp="127.0.0.1"
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
iphost=$(cat /etc/hosts | grep $1 | awk '{print $1}')
|
||||||
|
arr=($iphost)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$localIp" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
${csudo} echo "127.0.0.1 $1" >> /etc/hosts ||:
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_hostname() {
|
||||||
|
echo -e -n "${GREEN}Please enter one hostname(must not be 'localhost')${NC}:"
|
||||||
|
read newHostname
|
||||||
|
while true; do
|
||||||
|
if [[ ! -z "$newHostname" && "$newHostname" != "localhost" ]]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
read -p "Please enter one hostname(must not be 'localhost'):" newHostname
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
${csudo} hostname $newHostname ||:
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
echo
|
||||||
|
echo "set hostname fail!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
#echo -e -n "$(hostnamectl status --static)"
|
||||||
|
#echo -e -n "$(hostnamectl status --transient)"
|
||||||
|
#echo -e -n "$(hostnamectl status --pretty)"
|
||||||
|
|
||||||
|
#ubuntu/centos /etc/hostname
|
||||||
|
if [[ -e /etc/hostname ]]; then
|
||||||
|
${csudo} echo $newHostname > /etc/hostname ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
#debian: #HOSTNAME=yourname
|
||||||
|
if [[ -e /etc/sysconfig/network ]]; then
|
||||||
|
${csudo} sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$newHostname
|
||||||
|
|
||||||
|
if [[ -e /etc/hosts ]]; then
|
||||||
|
add_newHostname_to_hosts $newHostname
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_correct_ipaddr() {
|
||||||
|
newIp=$1
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
IFS=" "
|
||||||
|
arr=($iplist)
|
||||||
|
IFS="$OLD_IFS"
|
||||||
|
for s in ${arr[@]}
|
||||||
|
do
|
||||||
|
if [[ "$s" == "$newIp" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_ipAsFqdn() {
|
||||||
|
iplist=$(ip address |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F "/" '{print $1}') ||:
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
iplist=$(ifconfig |grep inet |grep -v inet6 |grep -v 127.0.0.1 |awk '{print $2}' |awk -F ":" '{print $2}') ||:
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$iplist" ]; then
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}"
|
||||||
|
localFqdn="127.0.0.1"
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
echo
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e -n "${GREEN}Please choose an IP from local IP list${NC}:"
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}$iplist${NC}"
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo -e -n "${GREEN}Notes: if IP is used as the node name, data can NOT be migrated to other machine directly${NC}:"
|
||||||
|
read localFqdn
|
||||||
|
while true; do
|
||||||
|
if [ ! -z "$localFqdn" ]; then
|
||||||
|
# Check if correct ip address
|
||||||
|
is_correct_ipaddr $localFqdn
|
||||||
|
retval=`echo $?`
|
||||||
|
if [[ $retval != 0 ]]; then
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
else
|
||||||
|
# Write the local FQDN to configuration file
|
||||||
|
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||||
|
serverFqdn=$localFqdn
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
read -p "Please choose an IP from local IP list:" localFqdn
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function local_fqdn_check() {
|
||||||
|
#serverFqdn=$(hostname -f)
|
||||||
|
echo
|
||||||
|
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||||
|
echo
|
||||||
|
if [[ "$serverFqdn" == "" ]] || [[ "$serverFqdn" == "localhost" ]]; then
|
||||||
|
echo -e -n "${GREEN}It is strongly recommended to configure a hostname for this machine ${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
read -r -p "Set hostname now? [Y/n] " input
|
||||||
|
if [ ! -n "$input" ]; then
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
else
|
||||||
|
case $input in
|
||||||
|
[yY][eE][sS]|[yY])
|
||||||
|
set_hostname
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
[nN][oO]|[nN])
|
||||||
|
set_ipAsFqdn
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Invalid input..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function install_config() {
|
function install_config() {
|
||||||
if [ ! -f ${cfg_install_dir}/taos.cfg ]; then
|
if [ ! -f ${cfg_install_dir}/taos.cfg ]; then
|
||||||
${csudo} ${csudo} mkdir -p ${cfg_install_dir}
|
${csudo} ${csudo} mkdir -p ${cfg_install_dir}
|
||||||
|
@ -113,6 +266,8 @@ function install_config() {
|
||||||
${csudo} chmod 644 ${cfg_install_dir}/*
|
${csudo} chmod 644 ${cfg_install_dir}/*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local_fqdn_check
|
||||||
|
|
||||||
${csudo} mv ${cfg_dir}/taos.cfg ${cfg_dir}/taos.cfg.org
|
${csudo} mv ${cfg_dir}/taos.cfg ${cfg_dir}/taos.cfg.org
|
||||||
${csudo} ln -s ${cfg_install_dir}/taos.cfg ${cfg_dir}
|
${csudo} ln -s ${cfg_install_dir}/taos.cfg ${cfg_dir}
|
||||||
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
#FQDN_FORMAT="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
||||||
|
@ -130,19 +285,19 @@ function install_config() {
|
||||||
read firstEp;
|
read firstEp;
|
||||||
fi
|
fi
|
||||||
while true; do
|
while true; do
|
||||||
if [ ! -z "$firstEp" ]; then
|
if [ ! -z "$firstEp" ]; then
|
||||||
# check the format of the firstEp
|
# check the format of the firstEp
|
||||||
#if [[ $firstEp == $FQDN_PATTERN ]]; then
|
#if [[ $firstEp == $FQDN_PATTERN ]]; then
|
||||||
# Write the first FQDN to configuration file
|
# Write the first FQDN to configuration file
|
||||||
${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg
|
${csudo} sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/taos.cfg
|
||||||
break
|
|
||||||
#else
|
|
||||||
# read -p "Please enter the correct FQDN:port: " firstEp
|
|
||||||
#fi
|
|
||||||
else
|
|
||||||
break
|
break
|
||||||
fi
|
#else
|
||||||
done
|
# read -p "Please enter the correct FQDN:port: " firstEp
|
||||||
|
#fi
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# user email
|
# user email
|
||||||
#EMAIL_PATTERN='^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$'
|
#EMAIL_PATTERN='^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$'
|
||||||
|
@ -300,18 +455,32 @@ function install_TDengine() {
|
||||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}"
|
echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}"
|
|
||||||
|
|
||||||
if [ ! -z "$firstEp" ]; then
|
if [ ! -z "$firstEp" ]; then
|
||||||
echo
|
tmpFqdn=${firstEp%%:*}
|
||||||
echo -e "${GREEN_DARK}Please run${NC}: taos -h $firstEp${GREEN_DARK} to login into cluster, then${NC}"
|
substr=":"
|
||||||
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
if [[ $firstEp =~ $substr ]];then
|
||||||
echo
|
tmpPort=${firstEp#*:}
|
||||||
fi
|
else
|
||||||
|
tmpPort=""
|
||||||
|
fi
|
||||||
|
if [[ "$tmpPort" != "" ]];then
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||||
|
fi
|
||||||
|
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
||||||
|
echo
|
||||||
|
elif [ ! -z "$serverFqdn" ]; then
|
||||||
|
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## ==============================Main program starts from here============================
|
## ==============================Main program starts from here============================
|
||||||
|
serverFqdn=$(hostname -f)
|
||||||
install_TDengine
|
install_TDengine
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: tdengine
|
name: tdengine
|
||||||
base: core18
|
base: core18
|
||||||
version: '2.0.9.0'
|
version: '2.0.11.0'
|
||||||
icon: snap/gui/t-dengine.svg
|
icon: snap/gui/t-dengine.svg
|
||||||
summary: an open-source big data platform designed and optimized for IoT.
|
summary: an open-source big data platform designed and optimized for IoT.
|
||||||
description: |
|
description: |
|
||||||
|
@ -72,7 +72,7 @@ parts:
|
||||||
- usr/bin/taosd
|
- usr/bin/taosd
|
||||||
- usr/bin/taos
|
- usr/bin/taos
|
||||||
- usr/bin/taosdemo
|
- usr/bin/taosdemo
|
||||||
- usr/lib/libtaos.so.2.0.9.0
|
- usr/lib/libtaos.so.2.0.11.0
|
||||||
- usr/lib/libtaos.so.1
|
- usr/lib/libtaos.so.1
|
||||||
- usr/lib/libtaos.so
|
- usr/lib/libtaos.so
|
||||||
|
|
||||||
|
|
|
@ -22,16 +22,16 @@ extern "C" {
|
||||||
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
extern int32_t cDebugFlag;
|
extern uint32_t cDebugFlag;
|
||||||
extern int32_t tscEmbedded;
|
extern uint32_t tscEmbedded;
|
||||||
|
|
||||||
#define tscFatal(...) { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscError(...) { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscWarn(...) { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscInfo(...) { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }}
|
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }}
|
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }}
|
#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql);
|
||||||
|
|
||||||
int32_t tscHandleMultivnodeInsert(SSqlObj *pSql);
|
int32_t tscHandleMultivnodeInsert(SSqlObj *pSql);
|
||||||
|
|
||||||
int32_t tscHandleInsertRetry(SSqlObj* pSql);
|
int32_t tscHandleInsertRetry(SSqlObj* parent, SSqlObj* child);
|
||||||
|
|
||||||
void tscBuildResFromSubqueries(SSqlObj *pSql);
|
void tscBuildResFromSubqueries(SSqlObj *pSql);
|
||||||
TAOS_ROW doSetResultRowData(SSqlObj *pSql);
|
TAOS_ROW doSetResultRowData(SSqlObj *pSql);
|
||||||
|
|
|
@ -110,11 +110,12 @@ SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint
|
||||||
uint32_t offset);
|
uint32_t offset);
|
||||||
|
|
||||||
void* tscDestroyBlockArrayList(SArray* pDataBlockList);
|
void* tscDestroyBlockArrayList(SArray* pDataBlockList);
|
||||||
|
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable);
|
||||||
|
|
||||||
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
|
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
|
||||||
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pDataList);
|
int32_t tscMergeTableDataBlocks(SSqlObj* pSql);
|
||||||
int32_t tscGetDataBlockFromList(void* pHashList, SArray* pDataBlockList, int64_t id, int32_t size,
|
int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
STableDataBlocks** dataBlocks, SArray* pBlockList);
|
||||||
STableDataBlocks** dataBlocks);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for the projection query on metric or point interpolation query on metric,
|
* for the projection query on metric or point interpolation query on metric,
|
||||||
|
@ -233,7 +234,7 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo);
|
||||||
|
|
||||||
int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex);
|
int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex);
|
||||||
int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
|
int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
|
||||||
int tscGetMeterMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists);
|
int tscGetTableMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists);
|
||||||
|
|
||||||
void tscResetForNextRetrieve(SSqlRes* pRes);
|
void tscResetForNextRetrieve(SSqlRes* pRes);
|
||||||
void tscDoQuery(SSqlObj* pSql);
|
void tscDoQuery(SSqlObj* pSql);
|
||||||
|
@ -275,6 +276,8 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex);
|
||||||
bool hasMoreVnodesToTry(SSqlObj *pSql);
|
bool hasMoreVnodesToTry(SSqlObj *pSql);
|
||||||
bool hasMoreClauseToTry(SSqlObj* pSql);
|
bool hasMoreClauseToTry(SSqlObj* pSql);
|
||||||
|
|
||||||
|
void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeFromCache);
|
||||||
|
|
||||||
void tscTryQueryNextVnode(SSqlObj *pSql, __async_cb_func_t fp);
|
void tscTryQueryNextVnode(SSqlObj *pSql, __async_cb_func_t fp);
|
||||||
void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
||||||
void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp);
|
void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp);
|
||||||
|
@ -284,6 +287,9 @@ bool tscSetSqlOwner(SSqlObj* pSql);
|
||||||
void tscClearSqlOwner(SSqlObj* pSql);
|
void tscClearSqlOwner(SSqlObj* pSql);
|
||||||
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize);
|
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize);
|
||||||
|
|
||||||
|
char* serializeTagData(STagData* pTagData, char* pMsg);
|
||||||
|
int32_t copyTagData(STagData* dst, const STagData* src);
|
||||||
|
|
||||||
void* malloc_throw(size_t size);
|
void* malloc_throw(size_t size);
|
||||||
void* calloc_throw(size_t nmemb, size_t size);
|
void* calloc_throw(size_t nmemb, size_t size);
|
||||||
char* strdup_throw(const char* str);
|
char* strdup_throw(const char* str);
|
||||||
|
|
|
@ -37,40 +37,6 @@ extern "C" {
|
||||||
#include "qTsbuf.h"
|
#include "qTsbuf.h"
|
||||||
#include "tcmdtype.h"
|
#include "tcmdtype.h"
|
||||||
|
|
||||||
#if 0
|
|
||||||
static UNUSED_FUNC void *u_malloc (size_t __size) {
|
|
||||||
uint32_t v = rand();
|
|
||||||
|
|
||||||
if (v % 5000 <= 0) {
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
return malloc(__size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
|
|
||||||
uint32_t v = rand();
|
|
||||||
if (v % 5000 <= 0) {
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
return calloc(num, __size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
|
|
||||||
uint32_t v = rand();
|
|
||||||
if (v % 5000 <= 0) {
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
return realloc(p, __size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define calloc u_calloc
|
|
||||||
#define malloc u_malloc
|
|
||||||
#define realloc u_realloc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// forward declaration
|
// forward declaration
|
||||||
struct SSqlInfo;
|
struct SSqlInfo;
|
||||||
struct SLocalReducer;
|
struct SLocalReducer;
|
||||||
|
@ -78,7 +44,7 @@ struct SLocalReducer;
|
||||||
// data source from sql string or from file
|
// data source from sql string or from file
|
||||||
enum {
|
enum {
|
||||||
DATA_FROM_SQL_STRING = 1,
|
DATA_FROM_SQL_STRING = 1,
|
||||||
DATA_FROM_DATA_FILE = 2,
|
DATA_FROM_DATA_FILE = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int32_t numOfRows);
|
typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int32_t numOfRows);
|
||||||
|
@ -118,10 +84,10 @@ typedef struct STableMetaInfo {
|
||||||
* 1. keep the vgroup index during the multi-vnode super table projection query
|
* 1. keep the vgroup index during the multi-vnode super table projection query
|
||||||
* 2. keep the vgroup index for multi-vnode insertion
|
* 2. keep the vgroup index for multi-vnode insertion
|
||||||
*/
|
*/
|
||||||
int32_t vgroupIndex;
|
int32_t vgroupIndex;
|
||||||
char name[TSDB_TABLE_FNAME_LEN]; // (super) table name
|
char name[TSDB_TABLE_FNAME_LEN]; // (super) table name
|
||||||
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
||||||
SArray* tagColList; // SArray<SColumn*>, involved tag columns
|
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||||
} STableMetaInfo;
|
} STableMetaInfo;
|
||||||
|
|
||||||
/* the structure for sql function in select clause */
|
/* the structure for sql function in select clause */
|
||||||
|
@ -136,7 +102,7 @@ typedef struct SSqlExpr {
|
||||||
int16_t numOfParams; // argument value of each function
|
int16_t numOfParams; // argument value of each function
|
||||||
tVariant param[3]; // parameters are not more than 3
|
tVariant param[3]; // parameters are not more than 3
|
||||||
int32_t offset; // sub result column value of arithmetic expression.
|
int32_t offset; // sub result column value of arithmetic expression.
|
||||||
int16_t resColId; // result column id
|
int16_t resColId; // result column id
|
||||||
} SSqlExpr;
|
} SSqlExpr;
|
||||||
|
|
||||||
typedef struct SColumnIndex {
|
typedef struct SColumnIndex {
|
||||||
|
@ -204,22 +170,17 @@ typedef struct SParamInfo {
|
||||||
} SParamInfo;
|
} SParamInfo;
|
||||||
|
|
||||||
typedef struct STableDataBlocks {
|
typedef struct STableDataBlocks {
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||||
int8_t tsSource; // where does the UNIX timestamp come from, server or client
|
int8_t tsSource; // where does the UNIX timestamp come from, server or client
|
||||||
bool ordered; // if current rows are ordered or not
|
bool ordered; // if current rows are ordered or not
|
||||||
int64_t vgId; // virtual group id
|
int64_t vgId; // virtual group id
|
||||||
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
|
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
|
||||||
int32_t numOfTables; // number of tables in current submit block
|
int32_t numOfTables; // number of tables in current submit block
|
||||||
int32_t rowSize; // row size for current table
|
int32_t rowSize; // row size for current table
|
||||||
uint32_t nAllocSize;
|
uint32_t nAllocSize;
|
||||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
|
||||||
/*
|
|
||||||
* the table meta of table, the table meta will be used during submit, keep a ref
|
|
||||||
* to avoid it to be removed from cache
|
|
||||||
*/
|
|
||||||
STableMeta *pTableMeta;
|
|
||||||
char *pData;
|
char *pData;
|
||||||
|
|
||||||
// for parameter ('?') binding
|
// for parameter ('?') binding
|
||||||
|
@ -252,7 +213,7 @@ typedef struct SQueryInfo {
|
||||||
int64_t clauseLimit; // limit for current sub clause
|
int64_t clauseLimit; // limit for current sub clause
|
||||||
|
|
||||||
int64_t prjOffset; // offset value in the original sql expression, only applied at client side
|
int64_t prjOffset; // offset value in the original sql expression, only applied at client side
|
||||||
int64_t tableLimit; // table limit in case of super table projection query + global order + limit
|
int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit
|
||||||
|
|
||||||
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
||||||
int16_t resColumnId; // result column id
|
int16_t resColumnId; // result column id
|
||||||
|
@ -268,7 +229,7 @@ typedef struct {
|
||||||
int32_t numOfTablesInSubmit;
|
int32_t numOfTablesInSubmit;
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t insertType;
|
uint32_t insertType;
|
||||||
int32_t clauseIndex; // index of multiple subclause query
|
int32_t clauseIndex; // index of multiple subclause query
|
||||||
|
|
||||||
char * curSql; // current sql, resume position of sql after parsing paused
|
char * curSql; // current sql, resume position of sql after parsing paused
|
||||||
|
@ -284,10 +245,14 @@ typedef struct {
|
||||||
int32_t numOfParams;
|
int32_t numOfParams;
|
||||||
|
|
||||||
int8_t dataSourceType; // load data from file or not
|
int8_t dataSourceType; // load data from file or not
|
||||||
int8_t submitSchema; // submit block is built with table schema
|
int8_t submitSchema; // submit block is built with table schema
|
||||||
STagData *pTagData; // NOTE: pTagData->data is used as a variant length array
|
STagData tagData; // NOTE: pTagData->data is used as a variant length array
|
||||||
SHashObj *pTableList; // referred table involved in sql
|
|
||||||
SArray *pDataBlocks; // SArray<STableDataBlocks*> submit data blocks after parsing sql
|
STableMeta **pTableMetaList; // all involved tableMeta list of current insert sql statement.
|
||||||
|
int32_t numOfTables;
|
||||||
|
|
||||||
|
SHashObj *pTableBlockHashList; // data block for each table
|
||||||
|
SArray *pDataBlocks; // SArray<STableDataBlocks*>. Merged submit block for each vgroup
|
||||||
} SSqlCmd;
|
} SSqlCmd;
|
||||||
|
|
||||||
typedef struct SResRec {
|
typedef struct SResRec {
|
||||||
|
@ -320,8 +285,8 @@ typedef struct {
|
||||||
char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t)
|
char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t)
|
||||||
SColumnIndex* pColumnIndex;
|
SColumnIndex* pColumnIndex;
|
||||||
|
|
||||||
SArithmeticSupport* pArithSup; // support the arithmetic expression calculation on agg functions
|
SArithmeticSupport *pArithSup; // support the arithmetic expression calculation on agg functions
|
||||||
struct SLocalReducer* pLocalReducer;
|
struct SLocalReducer *pLocalReducer;
|
||||||
} SSqlRes;
|
} SSqlRes;
|
||||||
|
|
||||||
typedef struct STscObj {
|
typedef struct STscObj {
|
||||||
|
@ -382,6 +347,7 @@ typedef struct SSqlObj {
|
||||||
|
|
||||||
typedef struct SSqlStream {
|
typedef struct SSqlStream {
|
||||||
SSqlObj *pSql;
|
SSqlObj *pSql;
|
||||||
|
const char* dstTable;
|
||||||
uint32_t streamId;
|
uint32_t streamId;
|
||||||
char listed;
|
char listed;
|
||||||
bool isProject;
|
bool isProject;
|
||||||
|
@ -408,6 +374,8 @@ typedef struct SSqlStream {
|
||||||
struct SSqlStream *prev, *next;
|
struct SSqlStream *prev, *next;
|
||||||
} SSqlStream;
|
} SSqlStream;
|
||||||
|
|
||||||
|
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable);
|
||||||
|
|
||||||
int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn);
|
int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn);
|
||||||
void tscInitMsgsFp();
|
void tscInitMsgsFp();
|
||||||
|
|
||||||
|
|
|
@ -365,6 +365,7 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
|
||||||
static void tscProcessAsyncError(SSchedMsg *pMsg) {
|
static void tscProcessAsyncError(SSchedMsg *pMsg) {
|
||||||
void (*fp)() = pMsg->ahandle;
|
void (*fp)() = pMsg->ahandle;
|
||||||
terrno = *(int32_t*) pMsg->msg;
|
terrno = *(int32_t*) pMsg->msg;
|
||||||
|
tfree(pMsg->msg);
|
||||||
(*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg);
|
(*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,6 +381,7 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
|
||||||
taosScheduleTask(tscQhandle, &schedMsg);
|
taosScheduleTask(tscQhandle, &schedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void tscQueueAsyncRes(SSqlObj *pSql) {
|
void tscQueueAsyncRes(SSqlObj *pSql) {
|
||||||
if (pSql == NULL || pSql->signature != pSql) {
|
if (pSql == NULL || pSql->signature != pSql) {
|
||||||
tscDebug("%p SqlObj is freed, not add into queue async res", pSql);
|
tscDebug("%p SqlObj is freed, not add into queue async res", pSql);
|
||||||
|
@ -389,7 +391,10 @@ void tscQueueAsyncRes(SSqlObj *pSql) {
|
||||||
tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code));
|
tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code));
|
||||||
|
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
assert(pSql->fp != NULL && pSql->fetchFp != NULL);
|
|
||||||
|
if (pSql->fp == NULL || pSql->fetchFp == NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pSql->fp = pSql->fetchFp;
|
pSql->fp = pSql->fetchFp;
|
||||||
(*pSql->fp)(pSql->param, pSql, pRes->code);
|
(*pSql->fp)(pSql->param, pSql, pRes->code);
|
||||||
|
@ -410,52 +415,26 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tscError("%p get %s failed, code:%s", pSql, msg, tstrerror(code));
|
tscError("%p get %s failed, code:%s", pSql, msg, tstrerror(code));
|
||||||
goto _error;
|
goto _error;
|
||||||
} else {
|
|
||||||
tscDebug("%p get %s successfully", pSql, msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tscDebug("%p get %s successfully", pSql, msg);
|
||||||
if (pSql->pStream == NULL) {
|
if (pSql->pStream == NULL) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
|
|
||||||
// check if it is a sub-query of super table query first, if true, enter another routine
|
// check if it is a sub-query of super table query first, if true, enter another routine
|
||||||
if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_STABLE_SUBQUERY)) {
|
if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, (TSDB_QUERY_TYPE_STABLE_SUBQUERY|TSDB_QUERY_TYPE_TAG_FILTER_QUERY))) {
|
||||||
tscDebug("%p update table meta in local cache, continue to process sql and send corresponding subquery", pSql);
|
tscDebug("%p update table meta in local cache, continue to process sql and send the corresponding query", pSql);
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
|
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS || code == TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
assert(code == TSDB_CODE_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// param already freed by other routine and pSql in tscCache when ctrl + c
|
|
||||||
if (atomic_load_ptr(&pSql->param) == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0));
|
|
||||||
|
|
||||||
SRetrieveSupport *trs = (SRetrieveSupport *)pSql->param;
|
|
||||||
SSqlObj * pParObj = trs->pParentSql;
|
|
||||||
|
|
||||||
// NOTE: the vgroupInfo for the queried super table must be existed here.
|
|
||||||
assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex &&
|
|
||||||
pTableMetaInfo->vgroupIndex >= 0 && pTableMetaInfo->vgroupList != NULL);
|
|
||||||
|
|
||||||
// tscProcessSql can add error into async res
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
return;
|
|
||||||
} else if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) {
|
|
||||||
tscDebug("%p update table meta in local cache, continue to process sql and send corresponding tid_tag query", pSql);
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
|
||||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
|
||||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
assert(code == TSDB_CODE_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0));
|
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0));
|
||||||
|
|
||||||
// tscProcessSql can add error into async res
|
// tscProcessSql can add error into async res
|
||||||
tscProcessSql(pSql);
|
tscProcessSql(pSql);
|
||||||
return;
|
return;
|
||||||
|
@ -465,16 +444,15 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
|
|
||||||
|
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS || code == TSDB_CODE_SUCCESS);
|
||||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
assert(code == TSDB_CODE_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of insert, redo parsing the sql string and build new submit data block for two reasons:
|
assert(pCmd->command != TSDB_SQL_INSERT);
|
||||||
// 1. the table Id(tid & uid) may have been update, the submit block needs to be updated accordingly.
|
|
||||||
// 2. vnode may need the schema information along with submit block to update its local table schema.
|
if (pCmd->command == TSDB_SQL_SELECT) {
|
||||||
if (pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_SELECT) {
|
|
||||||
tscDebug("%p redo parse sql string and proceed", pSql);
|
tscDebug("%p redo parse sql string and proceed", pSql);
|
||||||
pCmd->parseFinished = false;
|
pCmd->parseFinished = false;
|
||||||
tscResetSqlCmdObj(pCmd, false);
|
tscResetSqlCmdObj(pCmd, false);
|
||||||
|
@ -486,17 +464,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->command == TSDB_SQL_INSERT) {
|
tscProcessSql(pSql);
|
||||||
/*
|
} else { // in all other cases, simple retry
|
||||||
* Discard previous built submit blocks, and then parse the sql string again and build up all submit blocks,
|
|
||||||
* and send the required submit block according to index value in supporter to server.
|
|
||||||
*/
|
|
||||||
pSql->fp = pSql->fetchFp; // restore the fp
|
|
||||||
tscHandleInsertRetry(pSql);
|
|
||||||
} else if (pCmd->command == TSDB_SQL_SELECT) { // in case of other query type, continue
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
}
|
|
||||||
}else { // in all other cases, simple retry
|
|
||||||
tscProcessSql(pSql);
|
tscProcessSql(pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,6 +520,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
if (!pSql->cmd.parseFinished) {
|
if (!pSql->cmd.parseFinished) {
|
||||||
tsParseSql(pSql, false);
|
tsParseSql(pSql, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pSql->fp)(pSql->param, pSql, code);
|
(*pSql->fp)(pSql->param, pSql, code);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
GET_RES_INFO(ctx)->numOfRes = (res); \
|
GET_RES_INFO(ctx)->numOfRes = (res); \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define INC_INIT_VAL(ctx, res) (GET_RES_INFO(ctx)->numOfRes += (res));
|
#define INC_INIT_VAL(ctx, res) (GET_RES_INFO(ctx)->numOfRes += (res));
|
||||||
|
|
||||||
|
@ -482,17 +482,16 @@ int32_t no_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId
|
||||||
DO_UPDATE_TAG_COLUMNS(ctx, k); \
|
DO_UPDATE_TAG_COLUMNS(ctx, k); \
|
||||||
(num) += 1; \
|
(num) += 1; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define DUPATE_DATA_WITHOUT_TS(ctx, left, right, num, sign) \
|
#define DUPATE_DATA_WITHOUT_TS(ctx, left, right, num, sign) \
|
||||||
do { \
|
do { \
|
||||||
if (((left) < (right)) ^ (sign)) { \
|
if (((left) < (right)) ^ (sign)) { \
|
||||||
(left) = (right); \
|
(left) = (right); \
|
||||||
DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx); \
|
DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx); \
|
||||||
(num) += 1; \
|
(num) += 1; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
#define LOOPCHECK_N(val, list, ctx, tsdbType, sign, num) \
|
#define LOOPCHECK_N(val, list, ctx, tsdbType, sign, num) \
|
||||||
for (int32_t i = 0; i < ((ctx)->size); ++i) { \
|
for (int32_t i = 0; i < ((ctx)->size); ++i) { \
|
||||||
|
@ -709,15 +708,14 @@ static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY en
|
||||||
return BLK_DATA_ALL_NEEDED;
|
return BLK_DATA_ALL_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BLK_DATA_ALL_NEEDED;
|
// the pCtx should be set to current Ctx and output buffer before call this function. Otherwise, pCtx->aOutputBuf is
|
||||||
// TODO pCtx->aOutputBuf is the previous windowRes output buffer, not current unloaded block. so the following filter
|
// the previous windowRes output buffer, not current unloaded block. In this case, the following filter is invalid
|
||||||
// is invalid
|
SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
||||||
// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||||
// if (pInfo->hasResult != DATA_SET_FLAG) {
|
return BLK_DATA_ALL_NEEDED;
|
||||||
// return BLK_DATA_ALL_NEEDED;
|
} else { // data in current block is not earlier than current result
|
||||||
// } else { // data in current block is not earlier than current result
|
return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
||||||
// return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
|
@ -730,16 +728,14 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end
|
||||||
return BLK_DATA_ALL_NEEDED;
|
return BLK_DATA_ALL_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BLK_DATA_ALL_NEEDED;
|
// the pCtx should be set to current Ctx and output buffer before call this function. Otherwise, pCtx->aOutputBuf is
|
||||||
// TODO pCtx->aOutputBuf is the previous windowRes output buffer, not current unloaded block. so the following filter
|
// the previous windowRes output buffer, not current unloaded block. In this case, the following filter is invalid
|
||||||
// is invalid
|
SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
||||||
|
if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||||
// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
|
return BLK_DATA_ALL_NEEDED;
|
||||||
// if (pInfo->hasResult != DATA_SET_FLAG) {
|
} else {
|
||||||
// return BLK_DATA_ALL_NEEDED;
|
return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
||||||
// } else {
|
}
|
||||||
// return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1909,7 +1905,7 @@ static void valuePairAssign(tValuePair *dst, int16_t type, const char *val, int6
|
||||||
(dst)->timestamp = (src)->timestamp; \
|
(dst)->timestamp = (src)->timestamp; \
|
||||||
(dst)->v = (src)->v; \
|
(dst)->v = (src)->v; \
|
||||||
memcpy((dst)->pTags, (src)->pTags, (size_t)(__l)); \
|
memcpy((dst)->pTags, (src)->pTags, (size_t)(__l)); \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData, int64_t ts, uint16_t type,
|
static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData, int64_t ts, uint16_t type,
|
||||||
SExtTagsInfo *pTagInfo, char *pTags, int16_t stage) {
|
SExtTagsInfo *pTagInfo, char *pTags, int16_t stage) {
|
||||||
|
@ -2222,7 +2218,8 @@ static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) {
|
||||||
tmp += POINTER_BYTES * pCtx->param[0].i64Key;
|
tmp += POINTER_BYTES * pCtx->param[0].i64Key;
|
||||||
|
|
||||||
size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen;
|
size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen;
|
||||||
|
// assert(pCtx->param[0].i64Key > 0);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCtx->param[0].i64Key; ++i) {
|
for (int32_t i = 0; i < pCtx->param[0].i64Key; ++i) {
|
||||||
pTopBotInfo->res[i] = (tValuePair*) tmp;
|
pTopBotInfo->res[i] = (tValuePair*) tmp;
|
||||||
pTopBotInfo->res[i]->pTags = tmp + sizeof(tValuePair);
|
pTopBotInfo->res[i]->pTags = tmp + sizeof(tValuePair);
|
||||||
|
@ -2589,10 +2586,11 @@ static void percentile_next_step(SQLFunctionCtx *pCtx) {
|
||||||
// all data are null, set it completed
|
// all data are null, set it completed
|
||||||
if (pInfo->numOfElems == 0) {
|
if (pInfo->numOfElems == 0) {
|
||||||
pResInfo->complete = true;
|
pResInfo->complete = true;
|
||||||
|
} else {
|
||||||
|
pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, GET_DOUBLE_VAL(&pInfo->minval), GET_DOUBLE_VAL(&pInfo->maxval));
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->stage += 1;
|
pInfo->stage += 1;
|
||||||
pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, GET_DOUBLE_VAL(&pInfo->minval), GET_DOUBLE_VAL(&pInfo->maxval));
|
|
||||||
} else {
|
} else {
|
||||||
pResInfo->complete = true;
|
pResInfo->complete = true;
|
||||||
}
|
}
|
||||||
|
@ -2883,7 +2881,7 @@ static void leastsquares_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
int32_t *p = pData;
|
int32_t *p = pData;
|
||||||
LEASTSQR_CAL(param, pInfo->startVal, p, 0, pCtx->param[1].dKey);
|
LEASTSQR_CAL(param, pInfo->startVal, p, 0, pCtx->param[1].dKey);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
int8_t *p = pData;
|
int8_t *p = pData;
|
||||||
LEASTSQR_CAL(param, pInfo->startVal, p, 0, pCtx->param[1].dKey);
|
LEASTSQR_CAL(param, pInfo->startVal, p, 0, pCtx->param[1].dKey);
|
||||||
|
@ -3647,11 +3645,21 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
|
||||||
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
pInfo->lastKey = INT64_MIN;
|
pInfo->p.key = INT64_MIN;
|
||||||
pInfo->win = TSWINDOW_INITIALIZER;
|
pInfo->win = TSWINDOW_INITIALIZER;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double twa_get_area(SPoint1 s, SPoint1 e) {
|
||||||
|
if ((s.val >= 0 && e.val >= 0)|| (s.val <=0 && e.val <= 0)) {
|
||||||
|
return (s.val + e.val) * (e.key - s.key) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = (s.key * e.val - e.key * s.val)/(e.val - s.val);
|
||||||
|
double val = (s.val * (x - s.key) + e.val * (e.key - x)) / 2;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t index, int32_t size) {
|
static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t index, int32_t size) {
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
TSKEY *primaryKey = pCtx->ptsList;
|
TSKEY *primaryKey = pCtx->ptsList;
|
||||||
|
@ -3662,28 +3670,29 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
|
|
||||||
int32_t i = index;
|
int32_t i = index;
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
||||||
|
SPoint1* last = &pInfo->p;
|
||||||
|
|
||||||
if (pCtx->start.key != INT64_MIN) {
|
if (pCtx->start.key != INT64_MIN) {
|
||||||
assert((pCtx->start.key < primaryKey[tsIndex + i] && pCtx->order == TSDB_ORDER_ASC) ||
|
assert((pCtx->start.key < primaryKey[tsIndex + i] && pCtx->order == TSDB_ORDER_ASC) ||
|
||||||
(pCtx->start.key > primaryKey[tsIndex + i] && pCtx->order == TSDB_ORDER_DESC));
|
(pCtx->start.key > primaryKey[tsIndex + i] && pCtx->order == TSDB_ORDER_DESC));
|
||||||
|
|
||||||
assert(pInfo->lastKey == INT64_MIN);
|
assert(last->key == INT64_MIN);
|
||||||
|
|
||||||
pInfo->lastKey = primaryKey[tsIndex + i];
|
last->key = primaryKey[tsIndex + i];
|
||||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
GET_TYPED_DATA(last->val, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
||||||
|
|
||||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->start.val) / 2) * (pInfo->lastKey - pCtx->start.key);
|
pInfo->dOutput += twa_get_area(pCtx->start, *last);
|
||||||
|
|
||||||
pInfo->hasResult = DATA_SET_FLAG;
|
pInfo->hasResult = DATA_SET_FLAG;
|
||||||
pInfo->win.skey = pCtx->start.key;
|
pInfo->win.skey = pCtx->start.key;
|
||||||
notNullElems++;
|
notNullElems++;
|
||||||
i += step;
|
i += step;
|
||||||
} else if (pInfo->lastKey == INT64_MIN) {
|
} else if (pInfo->p.key == INT64_MIN) {
|
||||||
pInfo->lastKey = primaryKey[tsIndex + i];
|
last->key = primaryKey[tsIndex + i];
|
||||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
GET_TYPED_DATA(last->val, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
||||||
|
|
||||||
pInfo->hasResult = DATA_SET_FLAG;
|
pInfo->hasResult = DATA_SET_FLAG;
|
||||||
pInfo->win.skey = pInfo->lastKey;
|
pInfo->win.skey = last->key;
|
||||||
notNullElems++;
|
notNullElems++;
|
||||||
i += step;
|
i += step;
|
||||||
}
|
}
|
||||||
|
@ -3697,9 +3706,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3710,9 +3719,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3723,9 +3732,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3736,9 +3745,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = (double) val[i]};
|
||||||
pInfo->lastValue = (double) val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3749,9 +3758,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3762,9 +3771,9 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + tsIndex] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + tsIndex], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + tsIndex];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3773,20 +3782,19 @@ static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t tsIndex, int32_t
|
||||||
|
|
||||||
// the last interpolated time window value
|
// the last interpolated time window value
|
||||||
if (pCtx->end.key != INT64_MIN) {
|
if (pCtx->end.key != INT64_MIN) {
|
||||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->end.val) / 2) * (pCtx->end.key - pInfo->lastKey);
|
pInfo->dOutput += twa_get_area(pInfo->p, pCtx->end);
|
||||||
pInfo->lastValue = pCtx->end.val;
|
pInfo->p = pCtx->end;
|
||||||
pInfo->lastKey = pCtx->end.key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->win.ekey = pInfo->lastKey;
|
pInfo->win.ekey = pInfo->p.key;
|
||||||
return notNullElems;
|
return notNullElems;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void twa_function(SQLFunctionCtx *pCtx) {
|
static void twa_function(SQLFunctionCtx *pCtx) {
|
||||||
void * data = GET_INPUT_CHAR(pCtx);
|
void *data = GET_INPUT_CHAR(pCtx);
|
||||||
|
|
||||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
STwaInfo * pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
// skip null value
|
// skip null value
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
|
||||||
|
@ -3807,6 +3815,7 @@ static void twa_function(SQLFunctionCtx *pCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO refactor
|
||||||
static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
void *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
|
void *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||||
if (pCtx->hasNull && isNull(pData, pCtx->inputType)) {
|
if (pCtx->hasNull && isNull(pData, pCtx->inputType)) {
|
||||||
|
@ -3823,23 +3832,23 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
int32_t size = pCtx->size;
|
int32_t size = pCtx->size;
|
||||||
|
|
||||||
if (pCtx->start.key != INT64_MIN) {
|
if (pCtx->start.key != INT64_MIN) {
|
||||||
assert(pInfo->lastKey == INT64_MIN);
|
assert(pInfo->p.key == INT64_MIN);
|
||||||
|
|
||||||
pInfo->lastKey = primaryKey[index];
|
pInfo->p.key = primaryKey[index];
|
||||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
GET_TYPED_DATA(pInfo->p.val, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
||||||
|
|
||||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->start.val) / 2) * (pInfo->lastKey - pCtx->start.key);
|
pInfo->dOutput += twa_get_area(pCtx->start, pInfo->p);
|
||||||
|
|
||||||
pInfo->hasResult = DATA_SET_FLAG;
|
pInfo->hasResult = DATA_SET_FLAG;
|
||||||
pInfo->win.skey = pCtx->start.key;
|
pInfo->win.skey = pCtx->start.key;
|
||||||
notNullElems++;
|
notNullElems++;
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (pInfo->lastKey == INT64_MIN) {
|
} else if (pInfo->p.key == INT64_MIN) {
|
||||||
pInfo->lastKey = primaryKey[index];
|
pInfo->p.key = primaryKey[index];
|
||||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
GET_TYPED_DATA(pInfo->p.val, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, index));
|
||||||
|
|
||||||
pInfo->hasResult = DATA_SET_FLAG;
|
pInfo->hasResult = DATA_SET_FLAG;
|
||||||
pInfo->win.skey = pInfo->lastKey;
|
pInfo->win.skey = pInfo->p.key;
|
||||||
notNullElems++;
|
notNullElems++;
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
@ -3853,9 +3862,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3866,9 +3875,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3879,9 +3888,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3892,9 +3901,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = (double) val[i]};
|
||||||
pInfo->lastValue = (double) val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3905,9 +3914,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);//((val[i] + pInfo->p.val) / 2) * (primaryKey[i + index] - pInfo->p.key);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3918,9 +3927,9 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i + index] - pInfo->lastKey);
|
SPoint1 st = {.key = primaryKey[i + index], .val = val[i]};
|
||||||
pInfo->lastValue = val[i];
|
pInfo->dOutput += twa_get_area(pInfo->p, st);//((val[i] + pInfo->p.val) / 2) * (primaryKey[i + index] - pInfo->p.key);
|
||||||
pInfo->lastKey = primaryKey[i + index];
|
pInfo->p = st;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3929,12 +3938,11 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
|
|
||||||
// the last interpolated time window value
|
// the last interpolated time window value
|
||||||
if (pCtx->end.key != INT64_MIN) {
|
if (pCtx->end.key != INT64_MIN) {
|
||||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->end.val) / 2) * (pCtx->end.key - pInfo->lastKey);
|
pInfo->dOutput += twa_get_area(pInfo->p, pCtx->end);//((pInfo->p.val + pCtx->end.val) / 2) * (pCtx->end.key - pInfo->p.key);
|
||||||
pInfo->lastValue = pCtx->end.val;
|
pInfo->p = pCtx->end;
|
||||||
pInfo->lastKey = pCtx->end.key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->win.ekey = pInfo->lastKey;
|
pInfo->win.ekey = pInfo->p.key;
|
||||||
|
|
||||||
SET_VAL(pCtx, notNullElems, 1);
|
SET_VAL(pCtx, notNullElems, 1);
|
||||||
|
|
||||||
|
@ -3965,7 +3973,7 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
|
||||||
pBuf->dOutput += pInput->dOutput;
|
pBuf->dOutput += pInput->dOutput;
|
||||||
|
|
||||||
pBuf->win = pInput->win;
|
pBuf->win = pInput->win;
|
||||||
pBuf->lastKey = pInput->lastKey;
|
pBuf->p = pInput->p;
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_VAL(pCtx, numOfNotNull, 1);
|
SET_VAL(pCtx, numOfNotNull, 1);
|
||||||
|
@ -3992,15 +4000,14 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
|
||||||
STwaInfo *pInfo = (STwaInfo *)GET_ROWCELL_INTERBUF(pResInfo);
|
STwaInfo *pInfo = (STwaInfo *)GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
assert(pInfo->win.ekey == pInfo->lastKey && pInfo->hasResult == pResInfo->hasResult);
|
|
||||||
|
|
||||||
if (pInfo->hasResult != DATA_SET_FLAG) {
|
if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||||
setNull(pCtx->aOutputBuf, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
|
setNull(pCtx->aOutputBuf, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(pInfo->win.ekey == pInfo->p.key && pInfo->hasResult == pResInfo->hasResult);
|
||||||
if (pInfo->win.ekey == pInfo->win.skey) {
|
if (pInfo->win.ekey == pInfo->win.skey) {
|
||||||
*(double *)pCtx->aOutputBuf = pInfo->lastValue;
|
*(double *)pCtx->aOutputBuf = pInfo->p.val;
|
||||||
} else {
|
} else {
|
||||||
*(double *)pCtx->aOutputBuf = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey);
|
*(double *)pCtx->aOutputBuf = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,8 @@ typedef struct SCreateBuilder {
|
||||||
SSqlObj *pInterSql;
|
SSqlObj *pInterSql;
|
||||||
int32_t (*fp)(void *para, char* result);
|
int32_t (*fp)(void *para, char* result);
|
||||||
Stage callStage;
|
Stage callStage;
|
||||||
} SCreateBuilder;
|
} SCreateBuilder;
|
||||||
|
|
||||||
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength);
|
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength);
|
||||||
|
|
||||||
static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
||||||
|
@ -207,10 +208,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||||
const int32_t TYPE_COLUMN_LENGTH = 16;
|
const int32_t TYPE_COLUMN_LENGTH = 16;
|
||||||
const int32_t NOTE_COLUMN_MIN_LENGTH = 8;
|
const int32_t NOTE_COLUMN_MIN_LENGTH = 8;
|
||||||
|
|
||||||
int32_t noteFieldLen = NOTE_COLUMN_MIN_LENGTH;//tscMaxLengthOfTagsFields(pSql);
|
int32_t noteFieldLen = NOTE_COLUMN_MIN_LENGTH;
|
||||||
// if (noteFieldLen == 0) {
|
|
||||||
// noteFieldLen = NOTE_COLUMN_MIN_LENGTH;
|
|
||||||
// }
|
|
||||||
|
|
||||||
int32_t rowLen = tscBuildTableSchemaResultFields(pSql, NUM_OF_DESC_TABLE_COLUMNS, TYPE_COLUMN_LENGTH, noteFieldLen);
|
int32_t rowLen = tscBuildTableSchemaResultFields(pSql, NUM_OF_DESC_TABLE_COLUMNS, TYPE_COLUMN_LENGTH, noteFieldLen);
|
||||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||||
|
@ -571,7 +569,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
char fullName[TSDB_TABLE_FNAME_LEN] = {0};
|
char fullName[TSDB_TABLE_FNAME_LEN * 2] = {0};
|
||||||
extractDBName(pTableMetaInfo->name, fullName);
|
extractDBName(pTableMetaInfo->name, fullName);
|
||||||
extractTableName(pMeta->sTableId, param->sTableName);
|
extractTableName(pMeta->sTableId, param->sTableName);
|
||||||
snprintf(fullName + strlen(fullName), TSDB_TABLE_FNAME_LEN - strlen(fullName), ".%s", param->sTableName);
|
snprintf(fullName + strlen(fullName), TSDB_TABLE_FNAME_LEN - strlen(fullName), ".%s", param->sTableName);
|
||||||
|
@ -822,26 +820,39 @@ static int32_t tscProcessClientVer(SSqlObj *pSql) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO add test cases.
|
||||||
|
static int32_t checkForOnlineNode(SSqlObj* pSql) {
|
||||||
|
int32_t* data = pSql->res.length;
|
||||||
|
if (data == NULL) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t total = data[0];
|
||||||
|
int32_t online = data[1];
|
||||||
|
return (online < total)? TSDB_CODE_RPC_NETWORK_UNAVAIL:TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
||||||
STscObj* pObj = pSql->pTscObj;
|
STscObj* pObj = pSql->pTscObj;
|
||||||
|
|
||||||
SSqlObj* pHb = (SSqlObj*)taosAcquireRef(tscObjRef, pObj->hbrid);
|
SSqlObj* pHb = (SSqlObj*)taosAcquireRef(tscObjRef, pObj->hbrid);
|
||||||
if (pHb != NULL) {
|
if (pHb != NULL) {
|
||||||
int32_t code = pHb->res.code;
|
pSql->res.code = pHb->res.code;
|
||||||
taosReleaseRef(tscObjRef, pObj->hbrid);
|
taosReleaseRef(tscObjRef, pObj->hbrid);
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
}
|
||||||
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
|
||||||
return pSql->res.code;
|
if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
}
|
return pSql->res.code;
|
||||||
} else {
|
}
|
||||||
if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
|
||||||
return pSql->res.code;
|
pSql->res.code = checkForOnlineNode(pHb);
|
||||||
}
|
if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
|
return pSql->res.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
|
|
||||||
int32_t val = 1;
|
int32_t val = 1;
|
||||||
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -726,10 +726,14 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
|
||||||
SSchema p1 = {0};
|
SSchema p1 = {0};
|
||||||
if (pExpr->colInfo.colIndex != TSDB_TBNAME_COLUMN_INDEX) {
|
if (pExpr->colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
p1 = *tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex);
|
|
||||||
} else {
|
|
||||||
p1 = tGetTableNameColumnSchema();
|
p1 = tGetTableNameColumnSchema();
|
||||||
|
} else if (TSDB_COL_IS_UD_COL(pExpr->colInfo.flag)) {
|
||||||
|
p1.bytes = pExpr->resBytes;
|
||||||
|
p1.type = (uint8_t) pExpr->resType;
|
||||||
|
tstrncpy(p1.name, pExpr->aliasName, tListLen(p1.name));
|
||||||
|
} else {
|
||||||
|
p1 = *tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t inter = 0;
|
int32_t inter = 0;
|
||||||
|
|
|
@ -686,17 +686,14 @@ void tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableList, char **str, SParsedDataColInfo *spd,
|
static int32_t doParseInsertStatement(SSqlCmd* pCmd, char **str, SParsedDataColInfo *spd, int32_t *totalNum) {
|
||||||
int32_t *totalNum) {
|
|
||||||
SSqlCmd * pCmd = &pSql->cmd;
|
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
STableMeta *pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
|
||||||
STableDataBlocks *dataBuf = NULL;
|
STableDataBlocks *dataBuf = NULL;
|
||||||
int32_t ret = tscGetDataBlockFromList(pTableList, pCmd->pDataBlocks, pTableMeta->id.uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
int32_t ret = tscGetDataBlockFromList(pCmd->pTableBlockHashList, pTableMeta->id.uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||||
sizeof(SSubmitBlk), tinfo.rowSize, pTableMetaInfo->name,
|
sizeof(SSubmitBlk), tinfo.rowSize, pTableMetaInfo->name, pTableMeta, &dataBuf, NULL);
|
||||||
pTableMeta, &dataBuf);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -799,8 +796,6 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||||
sql += index;
|
sql += index;
|
||||||
|
|
||||||
tscAllocPayload(pCmd, sizeof(STagData));
|
|
||||||
|
|
||||||
//the source super table is moved to the secondary position of the pTableMetaInfo list
|
//the source super table is moved to the secondary position of the pTableMetaInfo list
|
||||||
if (pQueryInfo->numOfTables < 2) {
|
if (pQueryInfo->numOfTables < 2) {
|
||||||
tscAddEmptyMetaInfo(pQueryInfo);
|
tscAddEmptyMetaInfo(pQueryInfo);
|
||||||
|
@ -812,13 +807,8 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
STagData *pTag = realloc(pCmd->pTagData, offsetof(STagData, data));
|
tstrncpy(pCmd->tagData.name, pSTableMeterMetaInfo->name, sizeof(pCmd->tagData.name));
|
||||||
if (pTag == NULL) {
|
pCmd->tagData.dataLen = 0;
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
memset(pTag, 0, offsetof(STagData, data));
|
|
||||||
tstrncpy(pTag->name, pSTableMeterMetaInfo->name, sizeof(pTag->name));
|
|
||||||
pCmd->pTagData = pTag;
|
|
||||||
|
|
||||||
code = tscGetTableMeta(pSql, pSTableMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pSTableMeterMetaInfo);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -949,14 +939,15 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
tdSortKVRowByColIdx(row);
|
tdSortKVRowByColIdx(row);
|
||||||
|
|
||||||
pTag = (STagData*)realloc(pCmd->pTagData, offsetof(STagData, data) + kvRowLen(row));
|
pCmd->tagData.dataLen = kvRowLen(row);
|
||||||
|
char* pTag = realloc(pCmd->tagData.data, pCmd->tagData.dataLen);
|
||||||
if (pTag == NULL) {
|
if (pTag == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCmd->pTagData = pTag;
|
|
||||||
pTag->dataLen = htonl(kvRowLen(row));
|
kvRowCpy(pTag, row);
|
||||||
kvRowCpy(pTag->data, row);
|
|
||||||
free(row);
|
free(row);
|
||||||
|
pCmd->tagData.data = pTag;
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||||
|
@ -975,7 +966,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
createTable = true;
|
createTable = true;
|
||||||
code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true);
|
code = tscGetTableMetaEx(pSql, pTableMetaInfo, true);
|
||||||
if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) {
|
if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -986,7 +977,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
} else {
|
} else {
|
||||||
sql = sToken.z;
|
sql = sToken.z;
|
||||||
}
|
}
|
||||||
code = tscGetMeterMetaEx(pSql, pTableMetaInfo, false);
|
code = tscGetTableMetaEx(pSql, pTableMetaInfo, false);
|
||||||
|
|
||||||
if (pCmd->curSql == NULL) {
|
if (pCmd->curSql == NULL) {
|
||||||
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS);
|
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS);
|
||||||
|
@ -1058,18 +1049,17 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pCmd->pTableList) {
|
if (NULL == pCmd->pTableBlockHashList) {
|
||||||
pCmd->pTableList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
pCmd->pTableBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||||
pCmd->pDataBlocks = taosArrayInit(4, POINTER_BYTES);
|
if (NULL == pCmd->pTableBlockHashList) {
|
||||||
if (NULL == pCmd->pTableList || NULL == pSql->cmd.pDataBlocks) {
|
|
||||||
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str = pCmd->curSql;
|
str = pCmd->curSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDebug("%p create data block list for submit data:%p, pTableList:%p", pSql, pCmd->pDataBlocks, pCmd->pTableList);
|
tscDebug("%p create data block list hashList:%p", pSql, pCmd->pTableBlockHashList);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
|
@ -1091,7 +1081,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
*/
|
*/
|
||||||
if (totalNum == 0) {
|
if (totalNum == 0) {
|
||||||
code = TSDB_CODE_TSC_INVALID_SQL;
|
code = TSDB_CODE_TSC_INVALID_SQL;
|
||||||
goto _error;
|
goto _clean;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1104,11 +1094,11 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
// Check if the table name available or not
|
// Check if the table name available or not
|
||||||
if (validateTableName(sToken.z, sToken.n, &sTblToken) != TSDB_CODE_SUCCESS) {
|
if (validateTableName(sToken.z, sToken.n, &sTblToken) != TSDB_CODE_SUCCESS) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "table name invalid", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "table name invalid", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = tscSetTableFullName(pTableMetaInfo, &sTblToken, pSql)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscSetTableFullName(pTableMetaInfo, &sTblToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = tscCheckIfCreateTable(&str, pSql)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscCheckIfCreateTable(&str, pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1122,12 +1112,12 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
tscError("%p async insert parse error, code:%s", pSql, tstrerror(code));
|
tscError("%p async insert parse error, code:%s", pSql, tstrerror(code));
|
||||||
pCmd->curSql = NULL;
|
pCmd->curSql = NULL;
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "insert data into super table is not supported", NULL);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "insert data into super table is not supported", NULL);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
|
@ -1136,7 +1126,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
if (sToken.n == 0) {
|
if (sToken.n == 0) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE required", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE required", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
@ -1148,32 +1138,32 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns);
|
tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns);
|
||||||
|
|
||||||
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* app here insert data in different vnodes, so we need to set the following
|
* app here insert data in different vnodes, so we need to set the following
|
||||||
* data in another submit procedure using async insert routines
|
* data in another submit procedure using async insert routines
|
||||||
*/
|
*/
|
||||||
code = doParseInsertStatement(pSql, pCmd->pTableList, &str, &spd, &totalNum);
|
code = doParseInsertStatement(pCmd, &str, &spd, &totalNum);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
} else if (sToken.type == TK_FILE) {
|
} else if (sToken.type == TK_FILE) {
|
||||||
if (validateDataSource(pCmd, DATA_FROM_DATA_FILE, sToken.z) != TSDB_CODE_SUCCESS) {
|
if (validateDataSource(pCmd, DATA_FROM_DATA_FILE, sToken.z) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
sToken = tStrGetToken(str, &index, false, 0, NULL);
|
sToken = tStrGetToken(str, &index, false, 0, NULL);
|
||||||
if (sToken.type != TK_STRING && sToken.type != TK_ID) {
|
if (sToken.type != TK_STRING && sToken.type != TK_ID) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "file path is required following keyword FILE", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "file path is required following keyword FILE", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
str += index;
|
str += index;
|
||||||
if (sToken.n == 0) {
|
if (sToken.n == 0) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "file path is required following keyword FILE", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "file path is required following keyword FILE", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(pCmd->payload, sToken.z, sToken.n);
|
strncpy(pCmd->payload, sToken.z, sToken.n);
|
||||||
|
@ -1183,7 +1173,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
wordexp_t full_path;
|
wordexp_t full_path;
|
||||||
if (wordexp(pCmd->payload, &full_path, 0) != 0) {
|
if (wordexp(pCmd->payload, &full_path, 0) != 0) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid filename", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid filename", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstrncpy(pCmd->payload, full_path.we_wordv[0], pCmd->allocSize);
|
tstrncpy(pCmd->payload, full_path.we_wordv[0], pCmd->allocSize);
|
||||||
|
@ -1195,7 +1185,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
SSchema * pSchema = tscGetTableSchema(pTableMeta);
|
SSchema * pSchema = tscGetTableSchema(pTableMeta);
|
||||||
|
|
||||||
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
SParsedDataColInfo spd = {0};
|
SParsedDataColInfo spd = {0};
|
||||||
|
@ -1230,7 +1220,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
if (spd.hasVal[t] == true) {
|
if (spd.hasVal[t] == true) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "duplicated column name", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "duplicated column name", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
spd.hasVal[t] = true;
|
spd.hasVal[t] = true;
|
||||||
|
@ -1241,13 +1231,13 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
if (!findColumnIndex) {
|
if (!findColumnIndex) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid column name", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid column name", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spd.numOfAssignedCols == 0 || spd.numOfAssignedCols > tinfo.numOfColumns) {
|
if (spd.numOfAssignedCols == 0 || spd.numOfAssignedCols > tinfo.numOfColumns) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "column name expected", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "column name expected", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
|
@ -1256,16 +1246,16 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
if (sToken.type != TK_VALUES) {
|
if (sToken.type != TK_VALUES) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES is expected", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES is expected", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doParseInsertStatement(pSql, pCmd->pTableList, &str, &spd, &totalNum);
|
code = doParseInsertStatement(pCmd, &str, &spd, &totalNum);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE are required", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE are required", sToken.z);
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1274,25 +1264,18 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
goto _clean;
|
goto _clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayGetSize(pCmd->pDataBlocks) > 0) { // merge according to vgId
|
if (taosHashGetSize(pCmd->pTableBlockHashList) > 0) { // merge according to vgId
|
||||||
if ((code = tscMergeTableDataBlocks(pSql, pCmd->pDataBlocks)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscMergeTableDataBlocks(pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _clean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code = TSDB_CODE_SUCCESS;
|
code = TSDB_CODE_SUCCESS;
|
||||||
goto _clean;
|
goto _clean;
|
||||||
|
|
||||||
_error:
|
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
|
||||||
|
|
||||||
_clean:
|
_clean:
|
||||||
taosHashCleanup(pCmd->pTableList);
|
pCmd->curSql = NULL;
|
||||||
pCmd->pTableList = NULL;
|
|
||||||
|
|
||||||
pCmd->curSql = NULL;
|
|
||||||
pCmd->parseFinished = 1;
|
pCmd->parseFinished = 1;
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1309,7 +1292,6 @@ int tsInsertInitialCheck(SSqlObj *pSql) {
|
||||||
|
|
||||||
pCmd->count = 0;
|
pCmd->count = 0;
|
||||||
pCmd->command = TSDB_SQL_INSERT;
|
pCmd->command = TSDB_SQL_INSERT;
|
||||||
pSql->res.numOfRows = 0;
|
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex);
|
||||||
|
|
||||||
|
@ -1373,7 +1355,8 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
||||||
pSql->parseRetry++;
|
pSql->parseRetry++;
|
||||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||||
}
|
}
|
||||||
SQLInfoDestroy(&SQLInfo);
|
|
||||||
|
SqlInfoDestroy(&SQLInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1399,7 +1382,7 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
|
||||||
return tscInvalidSQLErrMsg(pCmd->payload, "too many rows in sql, total number of rows should be less than 32767", NULL);
|
return tscInvalidSQLErrMsg(pCmd->payload, "too many rows in sql, total number of rows should be less than 32767", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = tscMergeTableDataBlocks(pSql, pCmd->pDataBlocks)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscMergeTableDataBlocks(pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1456,18 +1439,21 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) {
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
int32_t maxRows = 0;
|
int32_t maxRows = 0;
|
||||||
|
|
||||||
tscDestroyBlockArrayList(pSql->cmd.pDataBlocks);
|
tfree(pCmd->pTableMetaList);
|
||||||
pCmd->pDataBlocks = taosArrayInit(1, POINTER_BYTES);
|
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||||
|
|
||||||
|
if (pCmd->pTableBlockHashList == NULL) {
|
||||||
|
pCmd->pTableBlockHashList = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||||
|
}
|
||||||
|
|
||||||
STableDataBlocks *pTableDataBlock = NULL;
|
STableDataBlocks *pTableDataBlock = NULL;
|
||||||
int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, tinfo.rowSize, sizeof(SSubmitBlk), pTableMetaInfo->name, pTableMeta, &pTableDataBlock);
|
int32_t ret = tscGetDataBlockFromList(pCmd->pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE,
|
||||||
|
sizeof(SSubmitBlk), tinfo.rowSize, pTableMetaInfo->name, pTableMeta, &pTableDataBlock, NULL);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
// return ret;
|
// return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(pCmd->pDataBlocks, &pTableDataBlock);
|
|
||||||
tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows);
|
tscAllocateMemIfNeed(pTableDataBlock, tinfo.rowSize, &maxRows);
|
||||||
|
|
||||||
char *tokenBuf = calloc(1, 4096);
|
char *tokenBuf = calloc(1, 4096);
|
||||||
|
|
||||||
while ((readLen = tgetline(&line, &n, fp)) != -1) {
|
while ((readLen = tgetline(&line, &n, fp)) != -1) {
|
||||||
|
@ -1529,8 +1515,6 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) {
|
||||||
|
|
||||||
SImportFileSupport *pSupporter = calloc(1, sizeof(SImportFileSupport));
|
SImportFileSupport *pSupporter = calloc(1, sizeof(SImportFileSupport));
|
||||||
SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL);
|
SSqlObj *pNew = createSubqueryObj(pSql, 0, parseFileSendDataBlock, pSupporter, TSDB_SQL_INSERT, NULL);
|
||||||
|
|
||||||
pNew->cmd.pDataBlocks = taosArrayInit(4, POINTER_BYTES);
|
|
||||||
pCmd->count = 1;
|
pCmd->count = 1;
|
||||||
|
|
||||||
FILE *fp = fopen(pCmd->payload, "r");
|
FILE *fp = fopen(pCmd->payload, "r");
|
||||||
|
@ -1538,7 +1522,7 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) {
|
||||||
pSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
pSql->res.code = TAOS_SYSTEM_ERROR(errno);
|
||||||
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
||||||
|
|
||||||
tfree(pSupporter)
|
tfree(pSupporter);
|
||||||
tscQueueAsyncRes(pSql);
|
tscQueueAsyncRes(pSql);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -800,9 +800,9 @@ static int insertStmtExecute(STscStmt* stmt) {
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
|
|
||||||
if (taosArrayGetSize(pCmd->pDataBlocks) > 0) {
|
if (taosHashGetSize(pCmd->pTableBlockHashList) > 0) {
|
||||||
// merge according to vgid
|
// merge according to vgid
|
||||||
int code = tscMergeTableDataBlocks(stmt->pSql, pCmd->pDataBlocks);
|
int code = tscMergeTableDataBlocks(stmt->pSql);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,6 +262,11 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
|
||||||
SSqlStream *pStream = pObj->streamList;
|
SSqlStream *pStream = pObj->streamList;
|
||||||
while (pStream) {
|
while (pStream) {
|
||||||
tstrncpy(pSdesc->sql, pStream->pSql->sqlstr, sizeof(pSdesc->sql));
|
tstrncpy(pSdesc->sql, pStream->pSql->sqlstr, sizeof(pSdesc->sql));
|
||||||
|
if (pStream->dstTable == NULL) {
|
||||||
|
pSdesc->dstTable[0] = 0;
|
||||||
|
} else {
|
||||||
|
tstrncpy(pSdesc->dstTable, pStream->dstTable, sizeof(pSdesc->dstTable));
|
||||||
|
}
|
||||||
pSdesc->streamId = htonl(pStream->streamId);
|
pSdesc->streamId = htonl(pStream->streamId);
|
||||||
pSdesc->num = htobe64(pStream->num);
|
pSdesc->num = htobe64(pStream->num);
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,9 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
|
||||||
|
|
||||||
static int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* len);
|
static int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* len);
|
||||||
|
|
||||||
static void getColumnName(tSQLExprItem* pItem, char* resultFieldName, int32_t nameLength);
|
static void getColumnName(tSqlExprItem* pItem, char* resultFieldName, int32_t nameLength);
|
||||||
|
|
||||||
static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExprItem* pItem, bool finalResult);
|
static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult);
|
||||||
static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes,
|
static int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnList* pIdList, int16_t bytes,
|
||||||
int8_t type, char* fieldName, SSqlExpr* pSqlExpr);
|
int8_t type, char* fieldName, SSqlExpr* pSqlExpr);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ static int32_t parseIntervalClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuery
|
||||||
static int32_t parseOffsetClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
static int32_t parseOffsetClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
||||||
static int32_t parseSlidingClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
static int32_t parseSlidingClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql);
|
||||||
|
|
||||||
static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExprItem* pItem);
|
static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem);
|
||||||
|
|
||||||
static int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql);
|
static int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql);
|
||||||
static int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL);
|
static int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL);
|
||||||
|
@ -1279,7 +1279,7 @@ static void tscInsertPrimaryTSSourceColumn(SQueryInfo* pQueryInfo, SColumnIndex*
|
||||||
tscColumnListInsert(pQueryInfo->colList, &tsCol);
|
tscColumnListInsert(pQueryInfo->colList, &tsCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t exprIndex, tSQLExprItem* pItem) {
|
static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t exprIndex, tSqlExprItem* pItem) {
|
||||||
const char* msg1 = "invalid column name, illegal column type, or columns in arithmetic expression from two tables";
|
const char* msg1 = "invalid column name, illegal column type, or columns in arithmetic expression from two tables";
|
||||||
const char* msg2 = "invalid arithmetic expression in select clause";
|
const char* msg2 = "invalid arithmetic expression in select clause";
|
||||||
const char* msg3 = "tag columns can not be used in arithmetic expression";
|
const char* msg3 = "tag columns can not be used in arithmetic expression";
|
||||||
|
@ -1310,7 +1310,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
||||||
SColumnIndex index = {.tableIndex = tableIndex};
|
SColumnIndex index = {.tableIndex = tableIndex};
|
||||||
|
|
||||||
SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_ARITHM, &index, TSDB_DATA_TYPE_DOUBLE, sizeof(double),
|
SSqlExpr* pExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_ARITHM, &index, TSDB_DATA_TYPE_DOUBLE, sizeof(double),
|
||||||
-1000, sizeof(double), false);
|
getNewResColId(pQueryInfo), sizeof(double), false);
|
||||||
|
|
||||||
char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->token.z;
|
char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->token.z;
|
||||||
size_t len = MIN(sizeof(pExpr->aliasName), pItem->pNode->token.n + 1);
|
size_t len = MIN(sizeof(pExpr->aliasName), pItem->pNode->token.n + 1);
|
||||||
|
@ -1420,7 +1420,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSQLExprItem* pItem) {
|
static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSqlExprItem* pItem) {
|
||||||
SSqlExpr* pExpr = doAddProjectCol(pQueryInfo, pIndex->columnIndex, pIndex->tableIndex);
|
SSqlExpr* pExpr = doAddProjectCol(pQueryInfo, pIndex->columnIndex, pIndex->tableIndex);
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex);
|
||||||
|
@ -1484,7 +1484,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSelection->nExpr; ++i) {
|
for (int32_t i = 0; i < pSelection->nExpr; ++i) {
|
||||||
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
tSQLExprItem* pItem = &pSelection->a[i];
|
tSqlExprItem* pItem = &pSelection->a[i];
|
||||||
|
|
||||||
// project on all fields
|
// project on all fields
|
||||||
int32_t optr = pItem->pNode->nSQLOptr;
|
int32_t optr = pItem->pNode->nSQLOptr;
|
||||||
|
@ -1643,7 +1643,7 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
|
||||||
return numOfTotalColumns;
|
return numOfTotalColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQLExprItem* pItem) {
|
int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem) {
|
||||||
const char* msg0 = "invalid column name";
|
const char* msg0 = "invalid column name";
|
||||||
const char* msg1 = "tag for normal table query is not allowed";
|
const char* msg1 = "tag for normal table query is not allowed";
|
||||||
|
|
||||||
|
@ -1767,7 +1767,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setResultColName(char* name, tSQLExprItem* pItem, int32_t functionId, SStrToken* pToken, bool multiCols) {
|
void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrToken* pToken, bool multiCols) {
|
||||||
if (pItem->aliasName != NULL) {
|
if (pItem->aliasName != NULL) {
|
||||||
tstrncpy(name, pItem->aliasName, TSDB_COL_NAME_LEN);
|
tstrncpy(name, pItem->aliasName, TSDB_COL_NAME_LEN);
|
||||||
} else if (multiCols) {
|
} else if (multiCols) {
|
||||||
|
@ -1775,19 +1775,22 @@ void setResultColName(char* name, tSQLExprItem* pItem, int32_t functionId, SStrT
|
||||||
int32_t len = MIN(pToken->n + 1, TSDB_COL_NAME_LEN);
|
int32_t len = MIN(pToken->n + 1, TSDB_COL_NAME_LEN);
|
||||||
tstrncpy(uname, pToken->z, len);
|
tstrncpy(uname, pToken->z, len);
|
||||||
|
|
||||||
int32_t size = TSDB_COL_NAME_LEN + tListLen(aAggs[functionId].aName) + 2 + 1;
|
if (tsKeepOriginalColumnName) { // keep the original column name
|
||||||
char tmp[TSDB_COL_NAME_LEN + tListLen(aAggs[functionId].aName) + 2 + 1] = {0};
|
tstrncpy(name, uname, TSDB_COL_NAME_LEN);
|
||||||
|
} else {
|
||||||
|
int32_t size = TSDB_COL_NAME_LEN + tListLen(aAggs[functionId].aName) + 2 + 1;
|
||||||
|
char tmp[TSDB_COL_NAME_LEN + tListLen(aAggs[functionId].aName) + 2 + 1] = {0};
|
||||||
|
snprintf(tmp, size, "%s(%s)", aAggs[functionId].aName, uname);
|
||||||
|
|
||||||
snprintf(tmp, size, "%s(%s)", aAggs[functionId].aName, uname);
|
tstrncpy(name, tmp, TSDB_COL_NAME_LEN);
|
||||||
|
}
|
||||||
tstrncpy(name, tmp, TSDB_COL_NAME_LEN);
|
|
||||||
} else { // use the user-input result column name
|
} else { // use the user-input result column name
|
||||||
int32_t len = MIN(pItem->pNode->token.n + 1, TSDB_COL_NAME_LEN);
|
int32_t len = MIN(pItem->pNode->token.n + 1, TSDB_COL_NAME_LEN);
|
||||||
tstrncpy(name, pItem->pNode->token.z, len);
|
tstrncpy(name, pItem->pNode->token.z, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExprItem* pItem, bool finalResult) {
|
int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, bool finalResult) {
|
||||||
STableMetaInfo* pTableMetaInfo = NULL;
|
STableMetaInfo* pTableMetaInfo = NULL;
|
||||||
int32_t optr = pItem->pNode->nSQLOptr;
|
int32_t optr = pItem->pNode->nSQLOptr;
|
||||||
|
|
||||||
|
@ -1817,7 +1820,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
||||||
|
|
||||||
if (pItem->pNode->pParam != NULL) {
|
if (pItem->pNode->pParam != NULL) {
|
||||||
tSQLExprItem* pParamElem = &pItem->pNode->pParam->a[0];
|
tSqlExprItem* pParamElem = &pItem->pNode->pParam->a[0];
|
||||||
SStrToken* pToken = &pParamElem->pNode->colInfo;
|
SStrToken* pToken = &pParamElem->pNode->colInfo;
|
||||||
int16_t sqlOptr = pParamElem->pNode->nSQLOptr;
|
int16_t sqlOptr = pParamElem->pNode->nSQLOptr;
|
||||||
if ((pToken->z == NULL || pToken->n == 0)
|
if ((pToken->z == NULL || pToken->n == 0)
|
||||||
|
@ -1918,7 +1921,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
tSQLExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
|
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
|
||||||
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) {
|
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
@ -2037,7 +2040,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
|
|
||||||
/* in first/last function, multiple columns can be add to resultset */
|
/* in first/last function, multiple columns can be add to resultset */
|
||||||
for (int32_t i = 0; i < pItem->pNode->pParam->nExpr; ++i) {
|
for (int32_t i = 0; i < pItem->pNode->pParam->nExpr; ++i) {
|
||||||
tSQLExprItem* pParamElem = &(pItem->pNode->pParam->a[i]);
|
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[i]);
|
||||||
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) {
|
if (pParamElem->pNode->nSQLOptr != TK_ALL && pParamElem->pNode->nSQLOptr != TK_ID) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
|
@ -2150,7 +2153,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
tSQLExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
|
tSqlExprItem* pParamElem = &(pItem->pNode->pParam->a[0]);
|
||||||
if (pParamElem->pNode->nSQLOptr != TK_ID) {
|
if (pParamElem->pNode->nSQLOptr != TK_ID) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
@ -2350,7 +2353,7 @@ static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t column
|
||||||
return columnList;
|
return columnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getColumnName(tSQLExprItem* pItem, char* resultFieldName, int32_t nameLength) {
|
void getColumnName(tSqlExprItem* pItem, char* resultFieldName, int32_t nameLength) {
|
||||||
if (pItem->aliasName != NULL) {
|
if (pItem->aliasName != NULL) {
|
||||||
strncpy(resultFieldName, pItem->aliasName, nameLength);
|
strncpy(resultFieldName, pItem->aliasName, nameLength);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3517,7 +3520,7 @@ static int32_t validateSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQuer
|
||||||
|
|
||||||
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
int32_t outputIndex = (int32_t)tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
|
|
||||||
tSQLExprItem item = {.pNode = pExpr, .aliasName = NULL};
|
tSqlExprItem item = {.pNode = pExpr, .aliasName = NULL};
|
||||||
|
|
||||||
// sql function list in selection clause.
|
// sql function list in selection clause.
|
||||||
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
|
// Append the sqlExpr into exprList of pQueryInfo structure sequentially
|
||||||
|
@ -3734,7 +3737,7 @@ static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg
|
||||||
return invalidSqlErrMsg(msgBuf, msg);
|
return invalidSqlErrMsg(msgBuf, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
*parent = tSQLExprCreate((*parent), pExpr, parentOptr);
|
*parent = tSqlExprCreate((*parent), pExpr, parentOptr);
|
||||||
} else {
|
} else {
|
||||||
*parent = pExpr;
|
*parent = pExpr;
|
||||||
}
|
}
|
||||||
|
@ -3782,7 +3785,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSQL
|
||||||
* to release expression, e.g., m1.ts = m2.ts,
|
* to release expression, e.g., m1.ts = m2.ts,
|
||||||
* since this expression is used to set the join query type
|
* since this expression is used to set the join query type
|
||||||
*/
|
*/
|
||||||
tSQLExprDestroy(*pExpr);
|
tSqlExprDestroy(*pExpr);
|
||||||
} else {
|
} else {
|
||||||
ret = setExprToCond(&pCondExpr->pTimewindow, *pExpr, msg3, parentOptr, pQueryInfo->msg);
|
ret = setExprToCond(&pCondExpr->pTimewindow, *pExpr, msg3, parentOptr, pQueryInfo->msg);
|
||||||
}
|
}
|
||||||
|
@ -3928,17 +3931,17 @@ static void doCompactQueryExpr(tSQLExpr** pExpr) {
|
||||||
|
|
||||||
if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL &&
|
if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight == NULL &&
|
||||||
((*pExpr)->nSQLOptr == TK_OR || (*pExpr)->nSQLOptr == TK_AND)) {
|
((*pExpr)->nSQLOptr == TK_OR || (*pExpr)->nSQLOptr == TK_AND)) {
|
||||||
tSQLExprNodeDestroy(*pExpr);
|
tSqlExprNodeDestroy(*pExpr);
|
||||||
*pExpr = NULL;
|
*pExpr = NULL;
|
||||||
|
|
||||||
} else if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight != NULL) {
|
} else if ((*pExpr)->pLeft == NULL && (*pExpr)->pRight != NULL) {
|
||||||
tSQLExpr* tmpPtr = (*pExpr)->pRight;
|
tSQLExpr* tmpPtr = (*pExpr)->pRight;
|
||||||
tSQLExprNodeDestroy(*pExpr);
|
tSqlExprNodeDestroy(*pExpr);
|
||||||
|
|
||||||
(*pExpr) = tmpPtr;
|
(*pExpr) = tmpPtr;
|
||||||
} else if ((*pExpr)->pRight == NULL && (*pExpr)->pLeft != NULL) {
|
} else if ((*pExpr)->pRight == NULL && (*pExpr)->pLeft != NULL) {
|
||||||
tSQLExpr* tmpPtr = (*pExpr)->pLeft;
|
tSQLExpr* tmpPtr = (*pExpr)->pLeft;
|
||||||
tSQLExprNodeDestroy(*pExpr);
|
tSqlExprNodeDestroy(*pExpr);
|
||||||
|
|
||||||
(*pExpr) = tmpPtr;
|
(*pExpr) = tmpPtr;
|
||||||
}
|
}
|
||||||
|
@ -3961,7 +3964,7 @@ static void doExtractExprForSTable(SSqlCmd* pCmd, tSQLExpr** pExpr, SQueryInfo*
|
||||||
(*pExpr) = NULL;
|
(*pExpr) = NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*pOut = tSQLExprCreate(NULL, NULL, (*pExpr)->nSQLOptr);
|
*pOut = tSqlExprCreate(NULL, NULL, (*pExpr)->nSQLOptr);
|
||||||
|
|
||||||
doExtractExprForSTable(pCmd, &(*pExpr)->pLeft, pQueryInfo, &((*pOut)->pLeft), tableIndex);
|
doExtractExprForSTable(pCmd, &(*pExpr)->pLeft, pQueryInfo, &((*pOut)->pLeft), tableIndex);
|
||||||
doExtractExprForSTable(pCmd, &(*pExpr)->pRight, pQueryInfo, &((*pOut)->pRight), tableIndex);
|
doExtractExprForSTable(pCmd, &(*pExpr)->pRight, pQueryInfo, &((*pOut)->pRight), tableIndex);
|
||||||
|
@ -4168,23 +4171,23 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr
|
||||||
|
|
||||||
static void cleanQueryExpr(SCondExpr* pCondExpr) {
|
static void cleanQueryExpr(SCondExpr* pCondExpr) {
|
||||||
if (pCondExpr->pTableCond) {
|
if (pCondExpr->pTableCond) {
|
||||||
tSQLExprDestroy(pCondExpr->pTableCond);
|
tSqlExprDestroy(pCondExpr->pTableCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCondExpr->pTagCond) {
|
if (pCondExpr->pTagCond) {
|
||||||
tSQLExprDestroy(pCondExpr->pTagCond);
|
tSqlExprDestroy(pCondExpr->pTagCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCondExpr->pColumnCond) {
|
if (pCondExpr->pColumnCond) {
|
||||||
tSQLExprDestroy(pCondExpr->pColumnCond);
|
tSqlExprDestroy(pCondExpr->pColumnCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCondExpr->pTimewindow) {
|
if (pCondExpr->pTimewindow) {
|
||||||
tSQLExprDestroy(pCondExpr->pTimewindow);
|
tSqlExprDestroy(pCondExpr->pTimewindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCondExpr->pJoinExpr) {
|
if (pCondExpr->pJoinExpr) {
|
||||||
tSQLExprDestroy(pCondExpr->pJoinExpr);
|
tSqlExprDestroy(pCondExpr->pJoinExpr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4252,8 +4255,8 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
|
||||||
|
|
||||||
tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw);
|
tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw);
|
||||||
doCompactQueryExpr(pExpr);
|
doCompactQueryExpr(pExpr);
|
||||||
|
|
||||||
tSQLExprDestroy(p1);
|
tSqlExprDestroy(p1);
|
||||||
tExprTreeDestroy(&p, NULL);
|
tExprTreeDestroy(&p, NULL);
|
||||||
|
|
||||||
taosArrayDestroy(colList);
|
taosArrayDestroy(colList);
|
||||||
|
@ -4910,6 +4913,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
tVariantListItem* pItem = taosArrayGet(pVarList, 1);
|
tVariantListItem* pItem = taosArrayGet(pVarList, 1);
|
||||||
SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex);
|
SSchema* pTagsSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, columnIndex.columnIndex);
|
||||||
|
pAlterSQL->tagData.data = calloc(1, pTagsSchema->bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
if (tVariantDump(&pItem->pVar, pAlterSQL->tagData.data, pTagsSchema->type, true) != TSDB_CODE_SUCCESS) {
|
if (tVariantDump(&pItem->pVar, pAlterSQL->tagData.data, pTagsSchema->type, true) != TSDB_CODE_SUCCESS) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg13);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg13);
|
||||||
}
|
}
|
||||||
|
@ -5317,7 +5322,7 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
|
||||||
// keep original limitation value in globalLimit
|
// keep original limitation value in globalLimit
|
||||||
pQueryInfo->clauseLimit = pQueryInfo->limit.limit;
|
pQueryInfo->clauseLimit = pQueryInfo->limit.limit;
|
||||||
pQueryInfo->prjOffset = pQueryInfo->limit.offset;
|
pQueryInfo->prjOffset = pQueryInfo->limit.offset;
|
||||||
pQueryInfo->tableLimit = -1;
|
pQueryInfo->vgroupLimit = -1;
|
||||||
|
|
||||||
if (tscOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
|
if (tscOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
|
||||||
/*
|
/*
|
||||||
|
@ -5327,7 +5332,7 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
|
||||||
* than or equal to the value of limit.
|
* than or equal to the value of limit.
|
||||||
*/
|
*/
|
||||||
if (pQueryInfo->limit.limit > 0) {
|
if (pQueryInfo->limit.limit > 0) {
|
||||||
pQueryInfo->tableLimit = pQueryInfo->limit.limit + pQueryInfo->limit.offset;
|
pQueryInfo->vgroupLimit = pQueryInfo->limit.limit + pQueryInfo->limit.offset;
|
||||||
pQueryInfo->limit.limit = -1;
|
pQueryInfo->limit.limit = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5913,25 +5918,33 @@ int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
|
||||||
if (pExprList->nExpr != 1) {
|
if (pExprList->nExpr != 1) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
}
|
}
|
||||||
|
bool server_status = false;
|
||||||
tSQLExpr* pExpr = pExprList->a[0].pNode;
|
tSQLExpr* pExpr = pExprList->a[0].pNode;
|
||||||
if (pExpr->operand.z == NULL) {
|
if (pExpr->operand.z == NULL) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
//handle 'select 1'
|
||||||
}
|
if (pExpr->token.n == 1 && 0 == strncasecmp(pExpr->token.z, "1", 1)) {
|
||||||
|
server_status = true;
|
||||||
|
} else {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO redefine the function
|
// TODO redefine the function
|
||||||
SDNodeDynConfOption functionsInfo[5] = {{"database()", 10},
|
SDNodeDynConfOption functionsInfo[5] = {{"database()", 10},
|
||||||
{"server_version()", 16},
|
{"server_version()", 16},
|
||||||
{"server_status()", 15},
|
{"server_status()", 15},
|
||||||
{"client_version()", 16},
|
{"client_version()", 16},
|
||||||
{"current_user()", 14}};
|
{"current_user()", 14}};
|
||||||
|
|
||||||
int32_t index = -1;
|
int32_t index = -1;
|
||||||
for (int32_t i = 0; i < tListLen(functionsInfo); ++i) {
|
if (server_status == true) {
|
||||||
if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 &&
|
index = 2;
|
||||||
functionsInfo[i].len == pExpr->operand.n) {
|
} else {
|
||||||
index = i;
|
for (int32_t i = 0; i < tListLen(functionsInfo); ++i) {
|
||||||
break;
|
if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 &&
|
||||||
|
functionsInfo[i].len == pExpr->operand.n) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6141,96 +6154,105 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
|
||||||
const int32_t TABLE_INDEX = 0;
|
const int32_t TABLE_INDEX = 0;
|
||||||
const int32_t STABLE_INDEX = 1;
|
const int32_t STABLE_INDEX = 1;
|
||||||
|
|
||||||
STableMetaInfo* pStableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX);
|
STableMetaInfo* pStableMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX);
|
||||||
|
|
||||||
// super table name, create table by using dst
|
// super table name, create table by using dst
|
||||||
SStrToken* pToken = &(pCreateTable->usingInfo.stableName);
|
int32_t numOfTables = (int32_t) taosArrayGetSize(pCreateTable->childTableInfo);
|
||||||
|
for(int32_t j = 0; j < numOfTables; ++j) {
|
||||||
|
SCreatedTableInfo* pCreateTableInfo = taosArrayGet(pCreateTable->childTableInfo, j);
|
||||||
|
|
||||||
if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
|
SStrToken* pToken = &pCreateTableInfo->stableName;
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
|
||||||
}
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
|
|
||||||
int32_t code = tscSetTableFullName(pStableMeterMetaInfo, pToken, pSql);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get meter meta from mnode
|
|
||||||
tstrncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, sizeof(pCreateTable->usingInfo.tagdata.name));
|
|
||||||
SArray* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals;
|
|
||||||
|
|
||||||
code = tscGetTableMeta(pSql, pStableMeterMetaInfo);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = taosArrayGetSize(pList);
|
|
||||||
if (tscGetNumOfTags(pStableMeterMetaInfo->pTableMeta) != size) {
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// too long tag values will return invalid sql, not be truncated automatically
|
|
||||||
SSchema* pTagSchema = tscGetTableTagSchema(pStableMeterMetaInfo->pTableMeta);
|
|
||||||
|
|
||||||
STagData* pTag = &pCreateTable->usingInfo.tagdata;
|
|
||||||
SKVRowBuilder kvRowBuilder = {0};
|
|
||||||
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ret = TSDB_CODE_SUCCESS;
|
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
|
||||||
SSchema* pSchema = &pTagSchema[i];
|
|
||||||
tVariantListItem* pItem = taosArrayGet(pList, i);
|
|
||||||
|
|
||||||
char tagVal[TSDB_MAX_TAGS_LEN];
|
|
||||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
|
||||||
if (pItem->pVar.nLen > pSchema->bytes) {
|
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true);
|
int32_t code = tscSetTableFullName(pStableMetaInfo, pToken, pSql);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
// check again after the convert since it may be converted from binary to nchar.
|
return code;
|
||||||
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
|
||||||
int16_t len = varDataTLen(tagVal);
|
|
||||||
if (len > pSchema->bytes) {
|
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get table meta from mnode
|
||||||
|
tstrncpy(pCreateTableInfo->tagdata.name, pStableMetaInfo->name, tListLen(pCreateTableInfo->tagdata.name));
|
||||||
|
SArray* pList = pCreateTableInfo->pTagVals;
|
||||||
|
|
||||||
|
code = tscGetTableMeta(pSql, pStableMetaInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = taosArrayGetSize(pList);
|
||||||
|
if (tscGetNumOfTags(pStableMetaInfo->pTableMeta) != size) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// too long tag values will return invalid sql, not be truncated automatically
|
||||||
|
SSchema *pTagSchema = tscGetTableTagSchema(pStableMetaInfo->pTableMeta);
|
||||||
|
STagData *pTag = &pCreateTableInfo->tagdata;
|
||||||
|
|
||||||
|
SKVRowBuilder kvRowBuilder = {0};
|
||||||
|
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = TSDB_CODE_SUCCESS;
|
||||||
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
|
SSchema* pSchema = &pTagSchema[i];
|
||||||
|
tVariantListItem* pItem = taosArrayGet(pList, i);
|
||||||
|
|
||||||
|
char tagVal[TSDB_MAX_TAGS_LEN];
|
||||||
|
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
if (pItem->pVar.nLen > pSchema->bytes) {
|
||||||
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true);
|
||||||
|
|
||||||
|
// check again after the convert since it may be converted from binary to nchar.
|
||||||
|
if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
int16_t len = varDataTLen(tagVal);
|
||||||
|
if (len > pSchema->bytes) {
|
||||||
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||||
|
}
|
||||||
|
|
||||||
|
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
||||||
|
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||||
|
if (row == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tdSortKVRowByColIdx(row);
|
||||||
|
pTag->dataLen = kvRowLen(row);
|
||||||
|
|
||||||
|
if (pTag->data == NULL) {
|
||||||
|
pTag->data = malloc(pTag->dataLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
kvRowCpy(pTag->data, row);
|
||||||
|
free(row);
|
||||||
|
|
||||||
|
// table name
|
||||||
|
if (tscValidateName(&(pCreateTableInfo->name)) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX);
|
||||||
|
ret = tscSetTableFullName(pTableMetaInfo, &pCreateTableInfo->name, pSql);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
return ret;
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pCreateTableInfo->fullname = strndup(pTableMetaInfo->name, TSDB_TABLE_FNAME_LEN);
|
||||||
|
|
||||||
tdAddColToKVRow(&kvRowBuilder, pSchema->colId, pSchema->type, tagVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
|
||||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
|
||||||
if (row == NULL) {
|
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
tdSortKVRowByColIdx(row);
|
|
||||||
pTag->dataLen = kvRowLen(row);
|
|
||||||
kvRowCpy(pTag->data, row);
|
|
||||||
free(row);
|
|
||||||
|
|
||||||
// table name
|
|
||||||
if (tscValidateName(&pInfo->pCreateTableInfo->name) != TSDB_CODE_SUCCESS) {
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
|
||||||
}
|
|
||||||
|
|
||||||
STableMetaInfo* pTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX);
|
|
||||||
ret = tscSetTableFullName(pTableMeterMetaInfo, &pInfo->pCreateTableInfo->name, pSql);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -6347,14 +6369,13 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
assert(pQuerySql != NULL && (pQuerySql->from == NULL || taosArrayGetSize(pQuerySql->from) > 0));
|
assert(pQuerySql != NULL && (pQuerySql->from == NULL || taosArrayGetSize(pQuerySql->from) > 0));
|
||||||
|
|
||||||
const char* msg0 = "invalid table name";
|
const char* msg0 = "invalid table name";
|
||||||
const char* msg2 = "point interpolation query needs timestamp";
|
const char* msg1 = "point interpolation query needs timestamp";
|
||||||
const char* msg5 = "fill only available for interval query";
|
const char* msg2 = "fill only available for interval query";
|
||||||
const char* msg6 = "start(end) time of query range required or time range too large";
|
const char* msg3 = "start(end) time of query range required or time range too large";
|
||||||
const char* msg7 = "illegal number of tables in from clause";
|
const char* msg4 = "illegal number of tables in from clause";
|
||||||
const char* msg8 = "too many columns in selection clause";
|
const char* msg5 = "too many columns in selection clause";
|
||||||
const char* msg9 = "TWA query requires both the start and end time";
|
const char* msg6 = "too many tables in from clause";
|
||||||
const char* msg10 = "too many tables in from clause";
|
const char* msg7 = "invalid table alias name";
|
||||||
const char* msg11 = "invalid table alias name";
|
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@ -6370,7 +6391,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
|
|
||||||
// too many result columns not support order by in query
|
// too many result columns not support order by in query
|
||||||
if (pQuerySql->pSelection->nExpr > TSDB_MAX_COLUMNS) {
|
if (pQuerySql->pSelection->nExpr > TSDB_MAX_COLUMNS) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg8);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6388,13 +6409,13 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
|
|
||||||
size_t fromSize = taosArrayGetSize(pQuerySql->from);
|
size_t fromSize = taosArrayGetSize(pQuerySql->from);
|
||||||
if (fromSize > TSDB_MAX_JOIN_TABLE_NUM * 2) {
|
if (fromSize > TSDB_MAX_JOIN_TABLE_NUM * 2) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||||
}
|
}
|
||||||
|
|
||||||
pQueryInfo->command = TSDB_SQL_SELECT;
|
pQueryInfo->command = TSDB_SQL_SELECT;
|
||||||
|
|
||||||
if (fromSize > 4) {
|
if (fromSize > 4) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg10);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set all query tables, which are maybe more than one.
|
// set all query tables, which are maybe more than one.
|
||||||
|
@ -6427,12 +6448,12 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
|
|
||||||
tVariantListItem* p1 = taosArrayGet(pQuerySql->from, i + 1);
|
tVariantListItem* p1 = taosArrayGet(pQuerySql->from, i + 1);
|
||||||
if (p1->pVar.nType != TSDB_DATA_TYPE_BINARY) {
|
if (p1->pVar.nType != TSDB_DATA_TYPE_BINARY) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg11);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||||
}
|
}
|
||||||
|
|
||||||
SStrToken aliasName = {.z = p1->pVar.pz, .n = p1->pVar.nLen, .type = TK_STRING};
|
SStrToken aliasName = {.z = p1->pVar.pz, .n = p1->pVar.nLen, .type = TK_STRING};
|
||||||
if (tscValidateName(&aliasName) != TSDB_CODE_SUCCESS) {
|
if (tscValidateName(&aliasName) != TSDB_CODE_SUCCESS) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg11);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// has no table alias name
|
// has no table alias name
|
||||||
|
@ -6510,12 +6531,6 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// user does not specified the query time window, twa is not allowed in such case.
|
|
||||||
if ((pQueryInfo->window.skey == INT64_MIN || pQueryInfo->window.ekey == INT64_MAX ||
|
|
||||||
(pQueryInfo->window.ekey == INT64_MAX / 1000 && tinfo.precision == TSDB_TIME_PRECISION_MILLI)) && tscIsTWAQuery(pQueryInfo)) {
|
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg9);
|
|
||||||
}
|
|
||||||
|
|
||||||
// no result due to invalid query time range
|
// no result due to invalid query time range
|
||||||
if (pQueryInfo->window.skey > pQueryInfo->window.ekey) {
|
if (pQueryInfo->window.skey > pQueryInfo->window.ekey) {
|
||||||
pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||||
|
@ -6523,7 +6538,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasTimestampForPointInterpQuery(pQueryInfo)) {
|
if (!hasTimestampForPointInterpQuery(pQueryInfo)) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of join query, time range is required.
|
// in case of join query, time range is required.
|
||||||
|
@ -6531,7 +6546,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
||||||
|
|
||||||
if (timeRange == 0 && pQueryInfo->window.skey == 0) {
|
if (timeRange == 0 && pQueryInfo->window.skey == 0) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6551,19 +6566,19 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
|
||||||
*/
|
*/
|
||||||
if (pQuerySql->fillType != NULL) {
|
if (pQuerySql->fillType != NULL) {
|
||||||
if (pQueryInfo->interval.interval == 0 && (!tscIsPointInterpQuery(pQueryInfo))) {
|
if (pQueryInfo->interval.interval == 0 && (!tscIsPointInterpQuery(pQueryInfo))) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pQueryInfo->interval.interval > 0 && pQueryInfo->interval.intervalUnit != 'n' && pQueryInfo->interval.intervalUnit != 'y') {
|
if (pQueryInfo->interval.interval > 0) {
|
||||||
bool initialWindows = TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER);
|
bool initialWindows = TSWINDOW_IS_EQUAL(pQueryInfo->window, TSWINDOW_INITIALIZER);
|
||||||
if (initialWindows) {
|
if (initialWindows) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
||||||
// number of result is not greater than 10,000,000
|
// number of result is not greater than 10,000,000
|
||||||
if ((timeRange == 0) || (timeRange / pQueryInfo->interval.interval) > MAX_INTERVAL_TIME_WINDOW) {
|
if ((timeRange == 0) || (timeRange / pQueryInfo->interval.interval) > MAX_INTERVAL_TIME_WINDOW) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,12 +147,18 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
|
||||||
SSqlObj *pSql = tres;
|
SSqlObj *pSql = tres;
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
if (code == 0) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp;
|
SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp;
|
||||||
SRpcEpSet * epSet = &pRsp->epSet;
|
SRpcEpSet *epSet = &pRsp->epSet;
|
||||||
if (epSet->numOfEps > 0) {
|
if (epSet->numOfEps > 0) {
|
||||||
tscEpSetHtons(epSet);
|
tscEpSetHtons(epSet);
|
||||||
tscUpdateMgmtEpSet(pSql, epSet);
|
if (!tscEpSetIsEqual(&pSql->pTscObj->tscCorMgmtEpSet->epSet, epSet)) {
|
||||||
|
tscTrace("%p updating epset: numOfEps: %d, inUse: %d", pSql, epSet->numOfEps, epSet->inUse);
|
||||||
|
for (int8_t i = 0; i < epSet->numOfEps; i++) {
|
||||||
|
tscTrace("endpoint %d: fqdn=%s, port=%d", i, epSet->fqdn[i], epSet->port[i]);
|
||||||
|
}
|
||||||
|
tscUpdateMgmtEpSet(pSql, epSet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->pTscObj->connId = htonl(pRsp->connId);
|
pSql->pTscObj->connId = htonl(pRsp->connId);
|
||||||
|
@ -161,11 +167,40 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
|
||||||
tscKillConnection(pObj);
|
tscKillConnection(pObj);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (pRsp->queryId) tscKillQuery(pObj, htonl(pRsp->queryId));
|
if (pRsp->queryId) {
|
||||||
if (pRsp->streamId) tscKillStream(pObj, htonl(pRsp->streamId));
|
tscKillQuery(pObj, htonl(pRsp->queryId));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRsp->streamId) {
|
||||||
|
tscKillStream(pObj, htonl(pRsp->streamId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t total = htonl(pRsp->totalDnodes);
|
||||||
|
int32_t online = htonl(pRsp->onlineDnodes);
|
||||||
|
assert(online <= total);
|
||||||
|
|
||||||
|
if (online < total) {
|
||||||
|
tscError("HB:%p, total dnode:%d, online dnode:%d", pSql, total, online);
|
||||||
|
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRes->length == NULL) {
|
||||||
|
pRes->length = calloc(2, sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
pRes->length[0] = total;
|
||||||
|
pRes->length[1] = online;
|
||||||
} else {
|
} else {
|
||||||
tscDebug("%" PRId64 " heartbeat failed, code:%s", pObj->hbrid, tstrerror(code));
|
tscDebug("%" PRId64 " heartbeat failed, code:%s", pObj->hbrid, tstrerror(code));
|
||||||
|
if (pRes->length == NULL) {
|
||||||
|
pRes->length = calloc(2, sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
pRes->length[1] = 0;
|
||||||
|
if (pRes->length[0] == 0) {
|
||||||
|
pRes->length[0] = 1; // make sure that the value of the total node is greater than the online node
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pObj->hbrid != 0) {
|
if (pObj->hbrid != 0) {
|
||||||
|
@ -280,18 +315,20 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cmd = pCmd->command;
|
int32_t cmd = pCmd->command;
|
||||||
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_FETCH || cmd == TSDB_SQL_INSERT || cmd == TSDB_SQL_UPDATE_TAGS_VAL) &&
|
|
||||||
|
// set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
||||||
|
if (cmd == TSDB_SQL_INSERT && rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
|
pSql->cmd.submitSchema = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_FETCH || cmd == TSDB_SQL_UPDATE_TAGS_VAL) &&
|
||||||
(rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID ||
|
(rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID ||
|
||||||
rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
||||||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL ||
|
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL ||
|
||||||
rpcMsg->code == TSDB_CODE_APP_NOT_READY ||
|
rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
|
||||||
rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE)) {
|
|
||||||
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
|
pSql->retry++;
|
||||||
|
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), pSql->retry);
|
||||||
// set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
|
||||||
if (rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
|
||||||
pSql->cmd.submitSchema = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSql->res.code = rpcMsg->code; // keep the previous error code
|
pSql->res.code = rpcMsg->code; // keep the previous error code
|
||||||
if (pSql->retry > pSql->maxRetry) {
|
if (pSql->retry > pSql->maxRetry) {
|
||||||
|
@ -451,10 +488,10 @@ int tscProcessSql(SSqlObj *pSql) {
|
||||||
|
|
||||||
int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload;
|
SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload;
|
||||||
pRetrieveMsg->qhandle = htobe64(pSql->res.qhandle);
|
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||||
pRetrieveMsg->free = htons(pQueryInfo->type);
|
pRetrieveMsg->free = htons(pQueryInfo->type);
|
||||||
|
pRetrieveMsg->qhandle = htobe64(pSql->res.qhandle);
|
||||||
|
|
||||||
// todo valid the vgroupId at the client side
|
// todo valid the vgroupId at the client side
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
@ -681,7 +718,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType);
|
pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType);
|
||||||
pQueryMsg->numOfTags = htonl(numOfTags);
|
pQueryMsg->numOfTags = htonl(numOfTags);
|
||||||
pQueryMsg->queryType = htonl(pQueryInfo->type);
|
pQueryMsg->queryType = htonl(pQueryInfo->type);
|
||||||
pQueryMsg->tableLimit = htobe64(pQueryInfo->tableLimit);
|
pQueryMsg->vgroupLimit = htobe64(pQueryInfo->vgroupLimit);
|
||||||
|
|
||||||
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
pQueryMsg->numOfOutput = htons((int16_t)numOfOutput); // this is the stage one output column number
|
pQueryMsg->numOfOutput = htons((int16_t)numOfOutput); // this is the stage one output column number
|
||||||
|
@ -1234,12 +1271,12 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &(pSql->cmd);
|
SSqlCmd *pCmd = &(pSql->cmd);
|
||||||
|
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg);
|
||||||
int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg);
|
|
||||||
|
|
||||||
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
|
SCreateTableSQL *pCreateTableInfo = pInfo->pCreateTableInfo;
|
||||||
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
|
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
|
||||||
size += sizeof(STagData);
|
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
|
||||||
|
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN);
|
||||||
} else {
|
} else {
|
||||||
size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count);
|
size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count);
|
||||||
}
|
}
|
||||||
|
@ -1267,33 +1304,55 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SCMCreateTableMsg *pCreateTableMsg = (SCMCreateTableMsg *)pCmd->payload;
|
SCMCreateTableMsg *pCreateTableMsg = (SCMCreateTableMsg *)pCmd->payload;
|
||||||
strcpy(pCreateTableMsg->tableId, pTableMetaInfo->name);
|
|
||||||
|
|
||||||
// use dbinfo from table id without modifying current db info
|
SCreateTableMsg* pCreateMsg = (SCreateTableMsg*)((char*) pCreateTableMsg + sizeof(SCMCreateTableMsg));
|
||||||
tscGetDBInfoFromTableFullName(pTableMetaInfo->name, pCreateTableMsg->db);
|
char* pMsg = NULL;
|
||||||
|
|
||||||
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
|
|
||||||
|
|
||||||
pCreateTableMsg->igExists = pCreateTable->existCheck ? 1 : 0;
|
|
||||||
pCreateTableMsg->numOfColumns = htons(pCmd->numOfCols);
|
|
||||||
pCreateTableMsg->numOfTags = htons(pCmd->count);
|
|
||||||
|
|
||||||
pCreateTableMsg->sqlLen = 0;
|
|
||||||
char *pMsg = (char *)pCreateTableMsg->schema;
|
|
||||||
|
|
||||||
int8_t type = pInfo->pCreateTableInfo->type;
|
int8_t type = pInfo->pCreateTableInfo->type;
|
||||||
if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value
|
if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value
|
||||||
STagData* pTag = &pInfo->pCreateTableInfo->usingInfo.tagdata;
|
SArray* list = pInfo->pCreateTableInfo->childTableInfo;
|
||||||
*(int32_t*)pMsg = htonl(pTag->dataLen);
|
|
||||||
pMsg += sizeof(int32_t);
|
int32_t numOfTables = (int32_t) taosArrayGetSize(list);
|
||||||
memcpy(pMsg, pTag->name, sizeof(pTag->name));
|
pCreateTableMsg->numOfTables = htonl(numOfTables);
|
||||||
pMsg += sizeof(pTag->name);
|
|
||||||
memcpy(pMsg, pTag->data, pTag->dataLen);
|
pMsg = (char*) pCreateMsg;
|
||||||
pMsg += pTag->dataLen;
|
for(int32_t i = 0; i < numOfTables; ++i) {
|
||||||
|
SCreateTableMsg* pCreate = (SCreateTableMsg*) pMsg;
|
||||||
|
|
||||||
|
pCreate->numOfColumns = htons(pCmd->numOfCols);
|
||||||
|
pCreate->numOfTags = htons(pCmd->count);
|
||||||
|
pMsg += sizeof(SCreateTableMsg);
|
||||||
|
|
||||||
|
SCreatedTableInfo* p = taosArrayGet(list, i);
|
||||||
|
strcpy(pCreate->tableId, p->fullname);
|
||||||
|
pCreate->igExists = (p->igExist)? 1 : 0;
|
||||||
|
|
||||||
|
// use dbinfo from table id without modifying current db info
|
||||||
|
tscGetDBInfoFromTableFullName(p->fullname, pCreate->db);
|
||||||
|
pMsg = serializeTagData(&p->tagdata, pMsg);
|
||||||
|
|
||||||
|
int32_t len = (int32_t)(pMsg - (char*) pCreate);
|
||||||
|
pCreate->len = htonl(len);
|
||||||
|
}
|
||||||
} else { // create (super) table
|
} else { // create (super) table
|
||||||
pSchema = (SSchema *)pCreateTableMsg->schema;
|
pCreateTableMsg->numOfTables = htonl(1); // only one table will be created
|
||||||
|
|
||||||
|
strcpy(pCreateMsg->tableId, pTableMetaInfo->name);
|
||||||
|
|
||||||
|
// use dbinfo from table id without modifying current db info
|
||||||
|
tscGetDBInfoFromTableFullName(pTableMetaInfo->name, pCreateMsg->db);
|
||||||
|
|
||||||
|
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
|
||||||
|
|
||||||
|
pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0;
|
||||||
|
pCreateMsg->numOfColumns = htons(pCmd->numOfCols);
|
||||||
|
pCreateMsg->numOfTags = htons(pCmd->count);
|
||||||
|
|
||||||
|
pCreateMsg->sqlLen = 0;
|
||||||
|
pMsg = (char *)pCreateMsg->schema;
|
||||||
|
|
||||||
|
pSchema = (SSchema *)pCreateMsg->schema;
|
||||||
|
|
||||||
for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) {
|
for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||||
|
@ -1310,7 +1369,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SQuerySQL *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
SQuerySQL *pQuerySql = pInfo->pCreateTableInfo->pSelect;
|
||||||
|
|
||||||
strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1);
|
strncpy(pMsg, pQuerySql->selectToken.z, pQuerySql->selectToken.n + 1);
|
||||||
pCreateTableMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
|
pCreateMsg->sqlLen = htons(pQuerySql->selectToken.n + 1);
|
||||||
pMsg += pQuerySql->selectToken.n + 1;
|
pMsg += pQuerySql->selectToken.n + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1394,6 +1453,43 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//int tscBuildCancelQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
// SCancelQueryMsg *pCancelMsg = (SCancelQueryMsg*) pSql->cmd.payload;
|
||||||
|
// pCancelMsg->qhandle = htobe64(pSql->res.qhandle);
|
||||||
|
//
|
||||||
|
// SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||||
|
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
//
|
||||||
|
// if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||||
|
// int32_t vgIndex = pTableMetaInfo->vgroupIndex;
|
||||||
|
// if (pTableMetaInfo->pVgroupTables == NULL) {
|
||||||
|
// SVgroupsInfo *pVgroupInfo = pTableMetaInfo->vgroupList;
|
||||||
|
// assert(pVgroupInfo->vgroups[vgIndex].vgId > 0 && vgIndex < pTableMetaInfo->vgroupList->numOfVgroups);
|
||||||
|
//
|
||||||
|
// pCancelMsg->header.vgId = htonl(pVgroupInfo->vgroups[vgIndex].vgId);
|
||||||
|
// tscDebug("%p build cancel query msg from vgId:%d, vgIndex:%d", pSql, pVgroupInfo->vgroups[vgIndex].vgId, vgIndex);
|
||||||
|
// } else {
|
||||||
|
// int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables);
|
||||||
|
// assert(vgIndex >= 0 && vgIndex < numOfVgroups);
|
||||||
|
//
|
||||||
|
// SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, vgIndex);
|
||||||
|
//
|
||||||
|
// pCancelMsg->header.vgId = htonl(pTableIdList->vgInfo.vgId);
|
||||||
|
// tscDebug("%p build cancel query msg from vgId:%d, vgIndex:%d", pSql, pTableIdList->vgInfo.vgId, vgIndex);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
// pCancelMsg->header.vgId = htonl(pTableMeta->vgroupInfo.vgId);
|
||||||
|
// tscDebug("%p build cancel query msg from only one vgroup, vgId:%d", pSql, pTableMeta->vgroupInfo.vgId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// pSql->cmd.payloadLen = sizeof(SCancelQueryMsg);
|
||||||
|
// pSql->cmd.msgType = TSDB_MSG_TYPE_CANCEL_QUERY;
|
||||||
|
//
|
||||||
|
// pCancelMsg->header.contLen = htonl(sizeof(SCancelQueryMsg));
|
||||||
|
// return TSDB_CODE_SUCCESS;
|
||||||
|
//}
|
||||||
|
|
||||||
int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
pCmd->payloadLen = sizeof(SAlterDbMsg);
|
pCmd->payloadLen = sizeof(SAlterDbMsg);
|
||||||
|
@ -1550,13 +1646,8 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||||
|
|
||||||
char *pMsg = (char *)pInfoMsg + sizeof(STableInfoMsg);
|
char *pMsg = (char *)pInfoMsg + sizeof(STableInfoMsg);
|
||||||
|
|
||||||
if (pCmd->autoCreated && pCmd->pTagData != NULL) {
|
if (pCmd->autoCreated && pCmd->tagData.dataLen != 0) {
|
||||||
int len = htonl(pCmd->pTagData->dataLen);
|
pMsg = serializeTagData(&pCmd->tagData, pMsg);
|
||||||
if (len > 0) {
|
|
||||||
len += sizeof(pCmd->pTagData->name) + sizeof(pCmd->pTagData->dataLen);
|
|
||||||
memcpy(pInfoMsg->tags, pCmd->pTagData, len);
|
|
||||||
pMsg += len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pCmd->payloadLen = (int32_t)(pMsg - (char*)pInfoMsg);
|
pCmd->payloadLen = (int32_t)(pMsg - (char*)pInfoMsg);
|
||||||
|
@ -2056,6 +2147,10 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
|
||||||
if (pConnect->epSet.numOfEps > 0) {
|
if (pConnect->epSet.numOfEps > 0) {
|
||||||
tscEpSetHtons(&pConnect->epSet);
|
tscEpSetHtons(&pConnect->epSet);
|
||||||
tscUpdateMgmtEpSet(pSql, &pConnect->epSet);
|
tscUpdateMgmtEpSet(pSql, &pConnect->epSet);
|
||||||
|
|
||||||
|
for (int i = 0; i < pConnect->epSet.numOfEps; ++i) {
|
||||||
|
tscDebug("%p epSet.fqdn[%d]: %s, pObj:%p", pSql, i, pConnect->epSet.fqdn[i], pObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pObj->sversion, pConnect->serverVersion);
|
strcpy(pObj->sversion, pConnect->serverVersion);
|
||||||
|
@ -2102,10 +2197,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
|
||||||
*/
|
*/
|
||||||
tscDebug("%p force release table meta after drop table:%s", pSql, pTableMetaInfo->name);
|
tscDebug("%p force release table meta after drop table:%s", pSql, pTableMetaInfo->name);
|
||||||
taosCacheRelease(tscMetaCache, (void **)&pTableMeta, true);
|
taosCacheRelease(tscMetaCache, (void **)&pTableMeta, true);
|
||||||
|
assert(pTableMetaInfo->pTableMeta == NULL);
|
||||||
if (pTableMetaInfo->pTableMeta) {
|
|
||||||
taosCacheRelease(tscMetaCache, (void **)&(pTableMetaInfo->pTableMeta), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2213,7 +2305,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
||||||
|
|
||||||
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
|
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code);
|
||||||
|
|
||||||
static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) {
|
static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) {
|
||||||
SSqlObj *pNew = calloc(1, sizeof(SSqlObj));
|
SSqlObj *pNew = calloc(1, sizeof(SSqlObj));
|
||||||
if (NULL == pNew) {
|
if (NULL == pNew) {
|
||||||
tscError("%p malloc failed for new sqlobj to get table meta", pSql);
|
tscError("%p malloc failed for new sqlobj to get table meta", pSql);
|
||||||
|
@ -2240,15 +2332,13 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf
|
||||||
|
|
||||||
tstrncpy(pNewMeterMetaInfo->name, pTableMetaInfo->name, sizeof(pNewMeterMetaInfo->name));
|
tstrncpy(pNewMeterMetaInfo->name, pTableMetaInfo->name, sizeof(pNewMeterMetaInfo->name));
|
||||||
|
|
||||||
if (pSql->cmd.pTagData != NULL) {
|
if (pSql->cmd.autoCreated) {
|
||||||
int size = offsetof(STagData, data) + htonl(pSql->cmd.pTagData->dataLen);
|
int32_t code = copyTagData(&pNew->cmd.tagData, &pSql->cmd.tagData);
|
||||||
pNew->cmd.pTagData = calloc(1, size);
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (pNew->cmd.pTagData == NULL) {
|
|
||||||
tscError("%p malloc failed for new tag data to get table meta", pSql);
|
tscError("%p malloc failed for new tag data to get table meta", pSql);
|
||||||
tscFreeSqlObj(pNew);
|
tscFreeSqlObj(pNew);
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
memcpy(pNew->cmd.pTagData, pSql->cmd.pTagData, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDebug("%p new pSqlObj:%p to get tableMeta, auto create:%d", pSql, pNew, pNew->cmd.autoCreated);
|
tscDebug("%p new pSqlObj:%p to get tableMeta, auto create:%d", pSql, pNew, pNew->cmd.autoCreated);
|
||||||
|
@ -2283,10 +2373,10 @@ int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getTableMetaFromMgmt(pSql, pTableMetaInfo);
|
return getTableMetaFromMnode(pSql, pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tscGetMeterMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists) {
|
int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists) {
|
||||||
pSql->cmd.autoCreated = createIfNotExists;
|
pSql->cmd.autoCreated = createIfNotExists;
|
||||||
return tscGetTableMeta(pSql, pTableMetaInfo);
|
return tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
@ -2310,7 +2400,7 @@ int tscRenewTableMeta(SSqlObj *pSql, int32_t tableIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCacheRelease(tscMetaCache, (void **)&(pTableMetaInfo->pTableMeta), true);
|
taosCacheRelease(tscMetaCache, (void **)&(pTableMetaInfo->pTableMeta), true);
|
||||||
return getTableMetaFromMgmt(pSql, pTableMetaInfo);
|
return getTableMetaFromMnode(pSql, pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
|
static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) {
|
||||||
|
|
|
@ -900,9 +900,9 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
|
||||||
strtolower(pSql->sqlstr, sql);
|
strtolower(pSql->sqlstr, sql);
|
||||||
|
|
||||||
pCmd->curSql = NULL;
|
pCmd->curSql = NULL;
|
||||||
if (NULL != pCmd->pTableList) {
|
if (NULL != pCmd->pTableBlockHashList) {
|
||||||
taosHashCleanup(pCmd->pTableList);
|
taosHashCleanup(pCmd->pTableBlockHashList);
|
||||||
pCmd->pTableList = NULL;
|
pCmd->pTableBlockHashList = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->fp = asyncCallback;
|
pSql->fp = asyncCallback;
|
||||||
|
|
|
@ -535,6 +535,10 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
|
||||||
pStream, pTableMetaInfo->name, pStream->interval.interval, pStream->interval.sliding, starttime, pSql->sqlstr);
|
pStream, pTableMetaInfo->name, pStream->interval.interval, pStream->interval.sliding, starttime, pSql->sqlstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable) {
|
||||||
|
pStream->dstTable = dstTable;
|
||||||
|
}
|
||||||
|
|
||||||
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||||
int64_t stime, void *param, void (*callback)(void *)) {
|
int64_t stime, void *param, void (*callback)(void *)) {
|
||||||
STscObj *pObj = (STscObj *)taos;
|
STscObj *pObj = (STscObj *)taos;
|
||||||
|
|
|
@ -384,7 +384,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo *pSubQueryInfo = tscGetQueryInfoDetail(&pPrevSub->cmd, 0);
|
SQueryInfo *pSubQueryInfo = tscGetQueryInfoDetail(&pPrevSub->cmd, 0);
|
||||||
STSBuf *pTSBuf = pSubQueryInfo->tsBuf;
|
STSBuf *pTsBuf = pSubQueryInfo->tsBuf;
|
||||||
pSubQueryInfo->tsBuf = NULL;
|
pSubQueryInfo->tsBuf = NULL;
|
||||||
|
|
||||||
// free result for async object will also free sqlObj
|
// free result for async object will also free sqlObj
|
||||||
|
@ -402,7 +402,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
||||||
pSql->pSubs[i] = pNew;
|
pSql->pSubs[i] = pNew;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
||||||
pQueryInfo->tsBuf = pTSBuf; // transfer the ownership of timestamp comp-z data to the new created object
|
pQueryInfo->tsBuf = pTsBuf; // transfer the ownership of timestamp comp-z data to the new created object
|
||||||
|
|
||||||
// set the second stage sub query for join process
|
// set the second stage sub query for join process
|
||||||
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE);
|
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE);
|
||||||
|
@ -1648,7 +1648,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||||
|
|
||||||
pRes->qhandle = 0x1; // hack the qhandle check
|
pRes->qhandle = 0x1; // hack the qhandle check
|
||||||
|
|
||||||
const uint32_t nBufferSize = (1u << 16); // 64KB
|
const uint32_t nBufferSize = (1u << 16u); // 64KB
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
@ -2149,6 +2149,38 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool needRetryInsert(SSqlObj* pParentObj, int32_t numOfSub) {
|
||||||
|
if (pParentObj->retry > pParentObj->maxRetry) {
|
||||||
|
tscError("%p max retry reached, abort the retry effort", pParentObj);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < numOfSub; ++i) {
|
||||||
|
int32_t code = pParentObj->pSubs[i]->res.code;
|
||||||
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code != TSDB_CODE_TDB_TABLE_RECONFIGURE && code != TSDB_CODE_TDB_INVALID_TABLE_ID &&
|
||||||
|
code != TSDB_CODE_VND_INVALID_VGROUP_ID && code != TSDB_CODE_RPC_NETWORK_UNAVAIL &&
|
||||||
|
code != TSDB_CODE_APP_NOT_READY) {
|
||||||
|
pParentObj->res.code = code;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void doFreeInsertSupporter(SSqlObj* pSqlObj) {
|
||||||
|
assert(pSqlObj != NULL && pSqlObj->subState.numOfSub > 0);
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < pSqlObj->subState.numOfSub; ++i) {
|
||||||
|
SSqlObj* pSql = pSqlObj->pSubs[i];
|
||||||
|
tfree(pSql->param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) {
|
static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) {
|
||||||
SInsertSupporter *pSupporter = (SInsertSupporter *)param;
|
SInsertSupporter *pSupporter = (SInsertSupporter *)param;
|
||||||
SSqlObj* pParentObj = pSupporter->pSql;
|
SSqlObj* pParentObj = pSupporter->pSql;
|
||||||
|
@ -2163,23 +2195,81 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
|
||||||
assert(pSql != NULL && pSql->res.code == numOfRows);
|
assert(pSql != NULL && pSql->res.code == numOfRows);
|
||||||
|
|
||||||
pParentObj->res.code = pSql->res.code;
|
pParentObj->res.code = pSql->res.code;
|
||||||
}
|
|
||||||
|
|
||||||
tfree(pSupporter);
|
// set the flag in the parent sqlObj
|
||||||
|
if (pSql->cmd.submitSchema) {
|
||||||
|
pParentObj->cmd.submitSchema = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (atomic_sub_fetch_32(&pParentObj->subState.numOfRemain, 1) > 0) {
|
if (atomic_sub_fetch_32(&pParentObj->subState.numOfRemain, 1) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDebug("%p Async insertion completed, total inserted:%d", pParentObj, pParentObj->res.numOfRows);
|
|
||||||
|
|
||||||
// restore user defined fp
|
// restore user defined fp
|
||||||
pParentObj->fp = pParentObj->fetchFp;
|
pParentObj->fp = pParentObj->fetchFp;
|
||||||
|
int32_t numOfSub = pParentObj->subState.numOfSub;
|
||||||
|
doFreeInsertSupporter(pParentObj);
|
||||||
|
|
||||||
// todo remove this parameter in async callback function definition.
|
if (pParentObj->res.code == TSDB_CODE_SUCCESS) {
|
||||||
// all data has been sent to vnode, call user function
|
tscDebug("%p Async insertion completed, total inserted:%d", pParentObj, pParentObj->res.numOfRows);
|
||||||
int32_t v = (pParentObj->res.code != TSDB_CODE_SUCCESS) ? pParentObj->res.code : (int32_t)pParentObj->res.numOfRows;
|
|
||||||
(*pParentObj->fp)(pParentObj->param, pParentObj, v);
|
// todo remove this parameter in async callback function definition.
|
||||||
|
// all data has been sent to vnode, call user function
|
||||||
|
int32_t v = (pParentObj->res.code != TSDB_CODE_SUCCESS) ? pParentObj->res.code : (int32_t)pParentObj->res.numOfRows;
|
||||||
|
(*pParentObj->fp)(pParentObj->param, pParentObj, v);
|
||||||
|
} else {
|
||||||
|
if (!needRetryInsert(pParentObj, numOfSub)) {
|
||||||
|
tscQueueAsyncRes(pParentObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t numOfFailed = 0;
|
||||||
|
for(int32_t i = 0; i < numOfSub; ++i) {
|
||||||
|
SSqlObj* pSql = pParentObj->pSubs[i];
|
||||||
|
if (pSql->res.code != TSDB_CODE_SUCCESS) {
|
||||||
|
numOfFailed += 1;
|
||||||
|
|
||||||
|
// clean up tableMeta in cache
|
||||||
|
tscFreeQueryInfo(&pSql->cmd, true);
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetailSafely(&pSql->cmd, 0);
|
||||||
|
STableMetaInfo* pMasterTableMetaInfo = tscGetTableMetaInfoFromCmd(&pParentObj->cmd, pSql->cmd.clauseIndex, 0);
|
||||||
|
tscAddTableMetaInfo(pQueryInfo, pMasterTableMetaInfo->name, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
tscDebug("%p, failed sub:%d, %p", pParentObj, i, pSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tscError("%p Async insertion completed, total inserted:%d rows, numOfFailed:%d, numOfTotal:%d", pParentObj,
|
||||||
|
pParentObj->res.numOfRows, numOfFailed, numOfSub);
|
||||||
|
|
||||||
|
tscDebug("%p cleanup %d tableMeta in cache", pParentObj, pParentObj->cmd.numOfTables);
|
||||||
|
for(int32_t i = 0; i < pParentObj->cmd.numOfTables; ++i) {
|
||||||
|
taosCacheRelease(tscMetaCache, (void**)&(pParentObj->cmd.pTableMetaList[i]), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
pParentObj->cmd.parseFinished = false;
|
||||||
|
pParentObj->subState.numOfRemain = numOfFailed;
|
||||||
|
|
||||||
|
tscResetSqlCmdObj(&pParentObj->cmd, false);
|
||||||
|
|
||||||
|
// in case of insert, redo parsing the sql string and build new submit data block for two reasons:
|
||||||
|
// 1. the table Id(tid & uid) may have been update, the submit block needs to be updated accordingly.
|
||||||
|
// 2. vnode may need the schema information along with submit block to update its local table schema.
|
||||||
|
tscDebug("%p re-parse sql to generate submit data, retry:%d", pParentObj, pParentObj->retry);
|
||||||
|
pParentObj->retry++;
|
||||||
|
|
||||||
|
int32_t code = tsParseSql(pParentObj, true);
|
||||||
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return;
|
||||||
|
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
pParentObj->res.code = code;
|
||||||
|
tscQueueAsyncRes(pParentObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tscDoQuery(pParentObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2187,20 +2277,16 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows)
|
||||||
* @param pSql
|
* @param pSql
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t tscHandleInsertRetry(SSqlObj* pSql) {
|
int32_t tscHandleInsertRetry(SSqlObj* pParent, SSqlObj* pSql) {
|
||||||
assert(pSql != NULL && pSql->param != NULL);
|
assert(pSql != NULL && pSql->param != NULL);
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
|
||||||
SSqlRes* pRes = &pSql->res;
|
SSqlRes* pRes = &pSql->res;
|
||||||
|
|
||||||
SInsertSupporter* pSupporter = (SInsertSupporter*) pSql->param;
|
SInsertSupporter* pSupporter = (SInsertSupporter*) pSql->param;
|
||||||
assert(pSupporter->index < pSupporter->pSql->subState.numOfSub);
|
assert(pSupporter->index < pSupporter->pSql->subState.numOfSub);
|
||||||
|
|
||||||
STableDataBlocks* pTableDataBlock = taosArrayGetP(pCmd->pDataBlocks, pSupporter->index);
|
STableDataBlocks* pTableDataBlock = taosArrayGetP(pParent->cmd.pDataBlocks, pSupporter->index);
|
||||||
int32_t code = tscCopyDataBlockToPayload(pSql, pTableDataBlock);
|
int32_t code = tscCopyDataBlockToPayload(pSql, pTableDataBlock);
|
||||||
|
|
||||||
// free the data block created from insert sql string
|
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
|
||||||
|
|
||||||
if ((pRes->code = code)!= TSDB_CODE_SUCCESS) {
|
if ((pRes->code = code)!= TSDB_CODE_SUCCESS) {
|
||||||
tscQueueAsyncRes(pSql);
|
tscQueueAsyncRes(pSql);
|
||||||
return code; // here the pSql may have been released already.
|
return code; // here the pSql may have been released already.
|
||||||
|
@ -2213,6 +2299,24 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) {
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
|
// it is the failure retry insert
|
||||||
|
if (pSql->pSubs != NULL) {
|
||||||
|
for(int32_t i = 0; i < pSql->subState.numOfSub; ++i) {
|
||||||
|
SSqlObj* pSub = pSql->pSubs[i];
|
||||||
|
SInsertSupporter* pSup = calloc(1, sizeof(SInsertSupporter));
|
||||||
|
pSup->index = i;
|
||||||
|
pSup->pSql = pSql;
|
||||||
|
|
||||||
|
pSub->param = pSup;
|
||||||
|
tscDebug("%p sub:%p launch sub insert, orderOfSub:%d", pSql, pSub, i);
|
||||||
|
if (pSub->res.code != TSDB_CODE_SUCCESS) {
|
||||||
|
tscHandleInsertRetry(pSql, pSub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
pSql->subState.numOfSub = (uint16_t)taosArrayGetSize(pCmd->pDataBlocks);
|
pSql->subState.numOfSub = (uint16_t)taosArrayGetSize(pCmd->pDataBlocks);
|
||||||
assert(pSql->subState.numOfSub > 0);
|
assert(pSql->subState.numOfSub > 0);
|
||||||
|
|
||||||
|
@ -2399,12 +2503,12 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
|
||||||
tscRestoreSQLFuncForSTableQuery(pQueryInfo);
|
tscRestoreSQLFuncForSTableQuery(pQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
assert (pRes->row >= pRes->numOfRows);
|
||||||
assert (pRes->row >= pRes->numOfRows);
|
doBuildResFromSubqueries(pSql);
|
||||||
|
if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||||
doBuildResFromSubqueries(pSql);
|
(*pSql->fp)(pSql->param, pSql, pRes->numOfRows);
|
||||||
tsem_post(&pSql->rspSem);
|
} else {
|
||||||
return;
|
tscQueueAsyncRes(pSql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -333,13 +333,15 @@ void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
||||||
|
|
||||||
if (isNull(p, TSDB_DATA_TYPE_NCHAR)) {
|
if (isNull(p, TSDB_DATA_TYPE_NCHAR)) {
|
||||||
memcpy(dst, p, varDataTLen(p));
|
memcpy(dst, p, varDataTLen(p));
|
||||||
} else {
|
} else if (varDataLen(p) > 0) {
|
||||||
int32_t length = taosUcs4ToMbs(varDataVal(p), varDataLen(p), varDataVal(dst));
|
int32_t length = taosUcs4ToMbs(varDataVal(p), varDataLen(p), varDataVal(dst));
|
||||||
varDataSetLen(dst, length);
|
varDataSetLen(dst, length);
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)p);
|
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)p);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
varDataSetLen(dst, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
p += pInfo->field.bytes;
|
p += pInfo->field.bytes;
|
||||||
|
@ -377,7 +379,7 @@ static void tscDestroyResPointerInfo(SSqlRes* pRes) {
|
||||||
pRes->data = NULL; // pRes->data points to the buffer of pRsp, no need to free
|
pRes->data = NULL; // pRes->data points to the buffer of pRsp, no need to free
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeFromCache) {
|
void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeFromCache) {
|
||||||
if (pCmd == NULL || pCmd->numOfClause == 0) {
|
if (pCmd == NULL || pCmd->numOfClause == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -403,12 +405,18 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd, bool removeFromCache) {
|
||||||
pCmd->msgType = 0;
|
pCmd->msgType = 0;
|
||||||
pCmd->parseFinished = 0;
|
pCmd->parseFinished = 0;
|
||||||
pCmd->autoCreated = 0;
|
pCmd->autoCreated = 0;
|
||||||
|
|
||||||
taosHashCleanup(pCmd->pTableList);
|
|
||||||
pCmd->pTableList = NULL;
|
|
||||||
|
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < pCmd->numOfTables; ++i) {
|
||||||
|
if (pCmd->pTableMetaList && pCmd->pTableMetaList[i]) {
|
||||||
|
taosCacheRelease(tscMetaCache, (void**)&(pCmd->pTableMetaList[i]), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pCmd->numOfTables = 0;
|
||||||
|
tfree(pCmd->pTableMetaList);
|
||||||
|
|
||||||
|
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList);
|
||||||
|
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||||
tscFreeQueryInfo(pCmd, removeFromCache);
|
tscFreeQueryInfo(pCmd, removeFromCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,7 +518,8 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
||||||
tscFreeSqlResult(pSql);
|
tscFreeSqlResult(pSql);
|
||||||
tscResetSqlCmdObj(pCmd, false);
|
tscResetSqlCmdObj(pCmd, false);
|
||||||
|
|
||||||
tfree(pCmd->pTagData);
|
tfree(pCmd->tagData.data);
|
||||||
|
pCmd->tagData.dataLen = 0;
|
||||||
|
|
||||||
memset(pCmd->payload, 0, (size_t)pCmd->allocSize);
|
memset(pCmd->payload, 0, (size_t)pCmd->allocSize);
|
||||||
tfree(pCmd->payload);
|
tfree(pCmd->payload);
|
||||||
|
@ -575,6 +584,21 @@ void* tscDestroyBlockArrayList(SArray* pDataBlockList) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* tscDestroyBlockHashTable(SHashObj* pBlockHashTable) {
|
||||||
|
if (pBlockHashTable == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
STableDataBlocks** p = taosHashIterate(pBlockHashTable, NULL);
|
||||||
|
while(p) {
|
||||||
|
tscDestroyDataBlock(*p);
|
||||||
|
p = taosHashIterate(pBlockHashTable, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashCleanup(pBlockHashTable);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
|
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
SSqlCmd* pCmd = &pSql->cmd;
|
||||||
assert(pDataBlock->pTableMeta != NULL);
|
assert(pDataBlock->pTableMeta != NULL);
|
||||||
|
@ -671,9 +695,8 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscGetDataBlockFromList(void* pHashList, SArray* pDataBlockList, int64_t id, int32_t size,
|
int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
STableDataBlocks** dataBlocks, SArray* pBlockList) {
|
||||||
STableDataBlocks** dataBlocks) {
|
|
||||||
*dataBlocks = NULL;
|
*dataBlocks = NULL;
|
||||||
|
|
||||||
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id));
|
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id));
|
||||||
|
@ -688,7 +711,9 @@ int32_t tscGetDataBlockFromList(void* pHashList, SArray* pDataBlockList, int64_t
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashPut(pHashList, (const char*)&id, sizeof(int64_t), (char*)dataBlocks, POINTER_BYTES);
|
taosHashPut(pHashList, (const char*)&id, sizeof(int64_t), (char*)dataBlocks, POINTER_BYTES);
|
||||||
taosArrayPush(pDataBlockList, dataBlocks);
|
if (pBlockList) {
|
||||||
|
taosArrayPush(pBlockList, dataBlocks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -769,22 +794,37 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) {
|
static void extractTableMeta(SSqlCmd* pCmd) {
|
||||||
|
pCmd->numOfTables = (int32_t) taosHashGetSize(pCmd->pTableBlockHashList);
|
||||||
|
pCmd->pTableMetaList = calloc(pCmd->numOfTables, POINTER_BYTES);
|
||||||
|
|
||||||
|
STableDataBlocks **p1 = taosHashIterate(pCmd->pTableBlockHashList, NULL);
|
||||||
|
int32_t i = 0;
|
||||||
|
while(p1) {
|
||||||
|
STableDataBlocks* pBlocks = *p1;
|
||||||
|
pCmd->pTableMetaList[i++] = taosCacheTransfer(tscMetaCache, (void**) &pBlocks->pTableMeta);
|
||||||
|
p1 = taosHashIterate(pCmd->pTableBlockHashList, p1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pCmd->pTableBlockHashList = tscDestroyBlockHashTable(pCmd->pTableBlockHashList);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tscMergeTableDataBlocks(SSqlObj* pSql) {
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
SSqlCmd* pCmd = &pSql->cmd;
|
||||||
|
|
||||||
void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||||
SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES);
|
SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES);
|
||||||
|
|
||||||
size_t total = taosArrayGetSize(pTableDataBlockList);
|
STableDataBlocks** p = taosHashIterate(pCmd->pTableBlockHashList, NULL);
|
||||||
for (int32_t i = 0; i < total; ++i) {
|
|
||||||
|
STableDataBlocks* pOneTableBlock = *p;
|
||||||
|
while(pOneTableBlock) {
|
||||||
// the maximum expanded size in byte when a row-wise data is converted to SDataRow format
|
// the maximum expanded size in byte when a row-wise data is converted to SDataRow format
|
||||||
STableDataBlocks* pOneTableBlock = taosArrayGetP(pTableDataBlockList, i);
|
|
||||||
int32_t expandSize = getRowExpandSize(pOneTableBlock->pTableMeta);
|
int32_t expandSize = getRowExpandSize(pOneTableBlock->pTableMeta);
|
||||||
STableDataBlocks* dataBuf = NULL;
|
STableDataBlocks* dataBuf = NULL;
|
||||||
|
|
||||||
int32_t ret =
|
int32_t ret = tscGetDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE,
|
||||||
tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE,
|
tsInsertHeadSize, 0, pOneTableBlock->tableId, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList);
|
||||||
tsInsertHeadSize, 0, pOneTableBlock->tableId, pOneTableBlock->pTableMeta, &dataBuf);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tscError("%p failed to prepare the data block buffer for merging table data, code:%d", pSql, ret);
|
tscError("%p failed to prepare the data block buffer for merging table data, code:%d", pSql, ret);
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
taosHashCleanup(pVnodeDataBlockHashList);
|
||||||
|
@ -839,14 +879,19 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) {
|
||||||
// the length does not include the SSubmitBlk structure
|
// the length does not include the SSubmitBlk structure
|
||||||
pBlocks->dataLen = htonl(finalLen);
|
pBlocks->dataLen = htonl(finalLen);
|
||||||
dataBuf->numOfTables += 1;
|
dataBuf->numOfTables += 1;
|
||||||
|
|
||||||
|
p = taosHashIterate(pCmd->pTableBlockHashList, p);
|
||||||
|
if (p == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pOneTableBlock = *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDestroyBlockArrayList(pTableDataBlockList);
|
extractTableMeta(pCmd);
|
||||||
|
|
||||||
// free the table data blocks;
|
// free the table data blocks;
|
||||||
pCmd->pDataBlocks = pVnodeDataBlockList;
|
pCmd->pDataBlocks = pVnodeDataBlockList;
|
||||||
|
|
||||||
// tscFreeUnusedDataBlocks(pCmd->pDataBlocks);
|
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
taosHashCleanup(pVnodeDataBlockHashList);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1893,15 +1938,11 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm
|
||||||
pCmd->parseFinished = 1;
|
pCmd->parseFinished = 1;
|
||||||
pCmd->autoCreated = pSql->cmd.autoCreated;
|
pCmd->autoCreated = pSql->cmd.autoCreated;
|
||||||
|
|
||||||
if (pSql->cmd.pTagData != NULL) {
|
int32_t code = copyTagData(&pNew->cmd.tagData, &pSql->cmd.tagData);
|
||||||
int size = offsetof(STagData, data) + htonl(pSql->cmd.pTagData->dataLen);
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pNew->cmd.pTagData = calloc(1, size);
|
tscError("%p new subquery failed, unable to malloc tag data, tableIndex:%d", pSql, 0);
|
||||||
if (pNew->cmd.pTagData == NULL) {
|
free(pNew);
|
||||||
tscError("%p new subquery failed, unable to malloc tag data, tableIndex:%d", pSql, 0);
|
return NULL;
|
||||||
free(pNew);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(pNew->cmd.pTagData, pSql->cmd.pTagData, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) {
|
if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -2006,7 +2047,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
pnCmd->numOfClause = 0;
|
pnCmd->numOfClause = 0;
|
||||||
pnCmd->clauseIndex = 0;
|
pnCmd->clauseIndex = 0;
|
||||||
pnCmd->pDataBlocks = NULL;
|
pnCmd->pDataBlocks = NULL;
|
||||||
|
|
||||||
|
pnCmd->numOfTables = 0;
|
||||||
pnCmd->parseFinished = 1;
|
pnCmd->parseFinished = 1;
|
||||||
|
pnCmd->pTableMetaList = NULL;
|
||||||
|
pnCmd->pTableBlockHashList = NULL;
|
||||||
|
|
||||||
if (tscAddSubqueryInfo(pnCmd) != TSDB_CODE_SUCCESS) {
|
if (tscAddSubqueryInfo(pnCmd) != TSDB_CODE_SUCCESS) {
|
||||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
@ -2023,6 +2068,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
pNewQueryInfo->limit = pQueryInfo->limit;
|
pNewQueryInfo->limit = pQueryInfo->limit;
|
||||||
pNewQueryInfo->slimit = pQueryInfo->slimit;
|
pNewQueryInfo->slimit = pQueryInfo->slimit;
|
||||||
pNewQueryInfo->order = pQueryInfo->order;
|
pNewQueryInfo->order = pQueryInfo->order;
|
||||||
|
pNewQueryInfo->vgroupLimit = pQueryInfo->vgroupLimit;
|
||||||
pNewQueryInfo->tsBuf = NULL;
|
pNewQueryInfo->tsBuf = NULL;
|
||||||
pNewQueryInfo->fillType = pQueryInfo->fillType;
|
pNewQueryInfo->fillType = pQueryInfo->fillType;
|
||||||
pNewQueryInfo->fillVal = NULL;
|
pNewQueryInfo->fillVal = NULL;
|
||||||
|
@ -2531,6 +2577,9 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) {
|
||||||
for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) {
|
for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) {
|
||||||
tfree(pVgroupInfo->epAddr[j].fqdn);
|
tfree(pVgroupInfo->epAddr[j].fqdn);
|
||||||
}
|
}
|
||||||
|
for(int32_t j = pVgroupInfo->numOfEps; j < TSDB_MAX_REPLICA; j++) {
|
||||||
|
assert( pVgroupInfo->epAddr[j].fqdn == NULL );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(vgroupList);
|
tfree(vgroupList);
|
||||||
|
@ -2543,6 +2592,41 @@ void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src) {
|
||||||
for(int32_t i = 0; i < dst->numOfEps; ++i) {
|
for(int32_t i = 0; i < dst->numOfEps; ++i) {
|
||||||
tfree(dst->epAddr[i].fqdn);
|
tfree(dst->epAddr[i].fqdn);
|
||||||
dst->epAddr[i].port = src->epAddr[i].port;
|
dst->epAddr[i].port = src->epAddr[i].port;
|
||||||
|
assert(dst->epAddr[i].fqdn == NULL);
|
||||||
|
|
||||||
dst->epAddr[i].fqdn = strdup(src->epAddr[i].fqdn);
|
dst->epAddr[i].fqdn = strdup(src->epAddr[i].fqdn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* serializeTagData(STagData* pTagData, char* pMsg) {
|
||||||
|
int32_t n = (int32_t) strlen(pTagData->name);
|
||||||
|
*(int32_t*) pMsg = htonl(n);
|
||||||
|
pMsg += sizeof(n);
|
||||||
|
|
||||||
|
memcpy(pMsg, pTagData->name, n);
|
||||||
|
pMsg += n;
|
||||||
|
|
||||||
|
*(int32_t*)pMsg = htonl(pTagData->dataLen);
|
||||||
|
pMsg += sizeof(int32_t);
|
||||||
|
|
||||||
|
memcpy(pMsg, pTagData->data, pTagData->dataLen);
|
||||||
|
pMsg += pTagData->dataLen;
|
||||||
|
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t copyTagData(STagData* dst, const STagData* src) {
|
||||||
|
dst->dataLen = src->dataLen;
|
||||||
|
tstrncpy(dst->name, src->name, tListLen(dst->name));
|
||||||
|
|
||||||
|
if (dst->dataLen > 0) {
|
||||||
|
dst->data = malloc(dst->dataLen);
|
||||||
|
if (dst->data == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(dst->data, src->data, dst->dataLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ enum {
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_FETCH, "fetch" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_FETCH, "fetch" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_INSERT, "insert" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_INSERT, "insert" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAGS_VAL, "update-tag-val" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAGS_VAL, "update-tag-val" )
|
||||||
|
|
||||||
// the SQL below is for mgmt node
|
// the SQL below is for mgmt node
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" )
|
||||||
|
|
|
@ -46,7 +46,7 @@ extern int32_t tsShellActivityTimer;
|
||||||
extern uint32_t tsMaxTmrCtrl;
|
extern uint32_t tsMaxTmrCtrl;
|
||||||
extern float tsNumOfThreadsPerCore;
|
extern float tsNumOfThreadsPerCore;
|
||||||
extern int32_t tsNumOfCommitThreads;
|
extern int32_t tsNumOfCommitThreads;
|
||||||
extern float tsRatioOfQueryThreads; // todo remove it
|
extern float tsRatioOfQueryCores;
|
||||||
extern int8_t tsDaylight;
|
extern int8_t tsDaylight;
|
||||||
extern char tsTimezone[];
|
extern char tsTimezone[];
|
||||||
extern char tsLocale[];
|
extern char tsLocale[];
|
||||||
|
@ -57,7 +57,9 @@ extern char tsTempDir[];
|
||||||
|
|
||||||
//query buffer management
|
//query buffer management
|
||||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer for each data node during query processing
|
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer for each data node during query processing
|
||||||
extern int32_t tsHalfCoresForQuery; // only 50% will be used in query processing
|
extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked
|
||||||
|
|
||||||
|
extern int32_t tsKeepOriginalColumnName;
|
||||||
|
|
||||||
// client
|
// client
|
||||||
extern int32_t tsTableMetaKeepTimer;
|
extern int32_t tsTableMetaKeepTimer;
|
||||||
|
@ -132,7 +134,7 @@ extern int32_t tsEnableStream;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
extern int32_t tsPrintAuth;
|
extern int32_t tsPrintAuth;
|
||||||
extern int32_t tscEmbedded;
|
extern uint32_t tscEmbedded;
|
||||||
extern char configDir[];
|
extern char configDir[];
|
||||||
extern char tsVnodeDir[];
|
extern char tsVnodeDir[];
|
||||||
extern char tsDnodeDir[];
|
extern char tsDnodeDir[];
|
||||||
|
@ -174,7 +176,7 @@ extern int32_t tsLogKeepDays;
|
||||||
extern int32_t dDebugFlag;
|
extern int32_t dDebugFlag;
|
||||||
extern int32_t vDebugFlag;
|
extern int32_t vDebugFlag;
|
||||||
extern int32_t mDebugFlag;
|
extern int32_t mDebugFlag;
|
||||||
extern int32_t cDebugFlag;
|
extern uint32_t cDebugFlag;
|
||||||
extern int32_t jniDebugFlag;
|
extern int32_t jniDebugFlag;
|
||||||
extern int32_t tmrDebugFlag;
|
extern int32_t tmrDebugFlag;
|
||||||
extern int32_t sdbDebugFlag;
|
extern int32_t sdbDebugFlag;
|
||||||
|
@ -184,7 +186,7 @@ extern int32_t monDebugFlag;
|
||||||
extern int32_t uDebugFlag;
|
extern int32_t uDebugFlag;
|
||||||
extern int32_t rpcDebugFlag;
|
extern int32_t rpcDebugFlag;
|
||||||
extern int32_t odbcDebugFlag;
|
extern int32_t odbcDebugFlag;
|
||||||
extern int32_t qDebugFlag;
|
extern uint32_t qDebugFlag;
|
||||||
extern int32_t wDebugFlag;
|
extern int32_t wDebugFlag;
|
||||||
extern int32_t cqDebugFlag;
|
extern int32_t cqDebugFlag;
|
||||||
extern int32_t debugFlag;
|
extern int32_t debugFlag;
|
||||||
|
|
|
@ -23,7 +23,7 @@ extern "C" {
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
extern int32_t uDebugFlag;
|
extern int32_t uDebugFlag;
|
||||||
extern int32_t tscEmbedded;
|
extern uint32_t tscEmbedded;
|
||||||
|
|
||||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tlocale.h"
|
#include "tlocale.h"
|
||||||
#include "ttimezone.h"
|
#include "ttimezone.h"
|
||||||
#include "tsync.h"
|
|
||||||
|
|
||||||
// cluster
|
// cluster
|
||||||
char tsFirst[TSDB_EP_LEN] = {0};
|
char tsFirst[TSDB_EP_LEN] = {0};
|
||||||
|
@ -52,7 +51,7 @@ int32_t tsMaxConnections = 5000;
|
||||||
int32_t tsShellActivityTimer = 3; // second
|
int32_t tsShellActivityTimer = 3; // second
|
||||||
float tsNumOfThreadsPerCore = 1.0f;
|
float tsNumOfThreadsPerCore = 1.0f;
|
||||||
int32_t tsNumOfCommitThreads = 1;
|
int32_t tsNumOfCommitThreads = 1;
|
||||||
float tsRatioOfQueryThreads = 0.5f;
|
float tsRatioOfQueryCores = 1.0f;
|
||||||
int8_t tsDaylight = 0;
|
int8_t tsDaylight = 0;
|
||||||
char tsTimezone[TSDB_TIMEZONE_LEN] = {0};
|
char tsTimezone[TSDB_TIMEZONE_LEN] = {0};
|
||||||
char tsLocale[TSDB_LOCALE_LEN] = {0};
|
char tsLocale[TSDB_LOCALE_LEN] = {0};
|
||||||
|
@ -107,8 +106,11 @@ int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance
|
||||||
// positive value (in MB)
|
// positive value (in MB)
|
||||||
int32_t tsQueryBufferSize = -1;
|
int32_t tsQueryBufferSize = -1;
|
||||||
|
|
||||||
// only 50% cpu will be used in query processing in dnode
|
// in retrieve blocking model, the retrieve threads will wait for the completion of the query processing.
|
||||||
int32_t tsHalfCoresForQuery = 0;
|
int32_t tsRetrieveBlockingModel = 0;
|
||||||
|
|
||||||
|
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
|
||||||
|
int32_t tsKeepOriginalColumnName = 0;
|
||||||
|
|
||||||
// db parameters
|
// db parameters
|
||||||
int32_t tsCacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
int32_t tsCacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||||
|
@ -209,24 +211,24 @@ int32_t tsVersion = 0;
|
||||||
|
|
||||||
// log
|
// log
|
||||||
int32_t tsNumOfLogLines = 10000000;
|
int32_t tsNumOfLogLines = 10000000;
|
||||||
int32_t mDebugFlag = 135;
|
int32_t mDebugFlag = 131;
|
||||||
int32_t sdbDebugFlag = 135;
|
int32_t sdbDebugFlag = 131;
|
||||||
int32_t dDebugFlag = 135;
|
int32_t dDebugFlag = 135;
|
||||||
int32_t vDebugFlag = 135;
|
int32_t vDebugFlag = 135;
|
||||||
int32_t cDebugFlag = 131;
|
uint32_t cDebugFlag = 131;
|
||||||
int32_t jniDebugFlag = 131;
|
int32_t jniDebugFlag = 131;
|
||||||
int32_t odbcDebugFlag = 131;
|
int32_t odbcDebugFlag = 131;
|
||||||
int32_t httpDebugFlag = 131;
|
int32_t httpDebugFlag = 131;
|
||||||
int32_t mqttDebugFlag = 131;
|
int32_t mqttDebugFlag = 131;
|
||||||
int32_t monDebugFlag = 131;
|
int32_t monDebugFlag = 131;
|
||||||
int32_t qDebugFlag = 131;
|
uint32_t qDebugFlag = 131;
|
||||||
int32_t rpcDebugFlag = 131;
|
int32_t rpcDebugFlag = 131;
|
||||||
int32_t uDebugFlag = 131;
|
int32_t uDebugFlag = 131;
|
||||||
int32_t debugFlag = 0;
|
int32_t debugFlag = 0;
|
||||||
int32_t sDebugFlag = 135;
|
int32_t sDebugFlag = 135;
|
||||||
int32_t wDebugFlag = 135;
|
int32_t wDebugFlag = 135;
|
||||||
int32_t tsdbDebugFlag = 131;
|
int32_t tsdbDebugFlag = 131;
|
||||||
int32_t cqDebugFlag = 135;
|
int32_t cqDebugFlag = 131;
|
||||||
int32_t fsDebugFlag = 135;
|
int32_t fsDebugFlag = 135;
|
||||||
|
|
||||||
int32_t (*monStartSystemFp)() = NULL;
|
int32_t (*monStartSystemFp)() = NULL;
|
||||||
|
@ -456,7 +458,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.option = "arbitrator";
|
cfg.option = "arbitrator";
|
||||||
cfg.ptr = tsArbitrator;
|
cfg.ptr = tsArbitrator;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = TSDB_EP_LEN;
|
cfg.ptrLength = TSDB_EP_LEN;
|
||||||
|
@ -484,12 +486,12 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "ratioOfQueryThreads";
|
cfg.option = "ratioOfQueryCores";
|
||||||
cfg.ptr = &tsRatioOfQueryThreads;
|
cfg.ptr = &tsRatioOfQueryCores;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||||
cfg.minValue = 0.1f;
|
cfg.minValue = 0.0f;
|
||||||
cfg.maxValue = 0.9f;
|
cfg.maxValue = 2.0f;
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
@ -927,8 +929,8 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "halfCoresForQuery";
|
cfg.option = "retrieveBlockingModel";
|
||||||
cfg.ptr = &tsHalfCoresForQuery;
|
cfg.ptr = &tsRetrieveBlockingModel;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
|
@ -937,11 +939,21 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
cfg.option = "keepColumnName";
|
||||||
|
cfg.ptr = &tsKeepOriginalColumnName;
|
||||||
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
|
cfg.minValue = 0;
|
||||||
|
cfg.maxValue = 1;
|
||||||
|
cfg.ptrLength = 1;
|
||||||
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
// locale & charset
|
// locale & charset
|
||||||
cfg.option = "timezone";
|
cfg.option = "timezone";
|
||||||
cfg.ptr = tsTimezone;
|
cfg.ptr = tsTimezone;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsTimezone);
|
cfg.ptrLength = tListLen(tsTimezone);
|
||||||
|
@ -951,7 +963,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.option = "locale";
|
cfg.option = "locale";
|
||||||
cfg.ptr = tsLocale;
|
cfg.ptr = tsLocale;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsLocale);
|
cfg.ptrLength = tListLen(tsLocale);
|
||||||
|
@ -961,7 +973,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.option = "charset";
|
cfg.option = "charset";
|
||||||
cfg.ptr = tsCharset;
|
cfg.ptr = tsCharset;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsCharset);
|
cfg.ptrLength = tListLen(tsCharset);
|
||||||
|
|
|
@ -705,7 +705,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
||||||
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
double value;
|
double value = -1;
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
ret = convertToDouble(pVariant->pz, pVariant->nLen, &value);
|
ret = convertToDouble(pVariant->pz, pVariant->nLen, &value);
|
||||||
if ((errno == ERANGE && (float)value == -1) || (ret != 0)) {
|
if ((errno == ERANGE && (float)value == -1) || (ret != 0)) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ec77d9049a719dabfd1a7c1122a209e201861944
|
Subproject commit 32e2c97a4cf7bedaa99f5d6dd8cb036e7f4470df
|
|
@ -57,6 +57,7 @@ typedef struct SCqObj {
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
int32_t tid; // table ID
|
int32_t tid; // table ID
|
||||||
int32_t rowSize; // bytes of a row
|
int32_t rowSize; // bytes of a row
|
||||||
|
char * dstTable;
|
||||||
char * sqlStr; // SQL string
|
char * sqlStr; // SQL string
|
||||||
STSchema * pSchema; // pointer to schema array
|
STSchema * pSchema; // pointer to schema array
|
||||||
void * pStream;
|
void * pStream;
|
||||||
|
@ -96,7 +97,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) {
|
||||||
|
|
||||||
pthread_mutex_init(&pContext->mutex, NULL);
|
pthread_mutex_init(&pContext->mutex, NULL);
|
||||||
|
|
||||||
cInfo("vgId:%d, CQ is opened", pContext->vgId);
|
cDebug("vgId:%d, CQ is opened", pContext->vgId);
|
||||||
|
|
||||||
return pContext;
|
return pContext;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,7 @@ void cqClose(void *handle) {
|
||||||
taosTmrCleanUp(pContext->tmrCtrl);
|
taosTmrCleanUp(pContext->tmrCtrl);
|
||||||
pContext->tmrCtrl = NULL;
|
pContext->tmrCtrl = NULL;
|
||||||
|
|
||||||
cInfo("vgId:%d, CQ is closed", pContext->vgId);
|
cDebug("vgId:%d, CQ is closed", pContext->vgId);
|
||||||
free(pContext);
|
free(pContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ void cqStart(void *handle) {
|
||||||
SCqContext *pContext = handle;
|
SCqContext *pContext = handle;
|
||||||
if (pContext->dbConn || pContext->master) return;
|
if (pContext->dbConn || pContext->master) return;
|
||||||
|
|
||||||
cInfo("vgId:%d, start all CQs", pContext->vgId);
|
cDebug("vgId:%d, start all CQs", pContext->vgId);
|
||||||
pthread_mutex_lock(&pContext->mutex);
|
pthread_mutex_lock(&pContext->mutex);
|
||||||
|
|
||||||
pContext->master = 1;
|
pContext->master = 1;
|
||||||
|
@ -160,7 +161,7 @@ void cqStop(void *handle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SCqContext *pContext = handle;
|
SCqContext *pContext = handle;
|
||||||
cInfo("vgId:%d, stop all CQs", pContext->vgId);
|
cDebug("vgId:%d, stop all CQs", pContext->vgId);
|
||||||
if (pContext->dbConn == NULL || pContext->master == 0) return;
|
if (pContext->dbConn == NULL || pContext->master == 0) return;
|
||||||
|
|
||||||
pthread_mutex_lock(&pContext->mutex);
|
pthread_mutex_lock(&pContext->mutex);
|
||||||
|
@ -185,7 +186,7 @@ void cqStop(void *handle) {
|
||||||
pthread_mutex_unlock(&pContext->mutex);
|
pthread_mutex_unlock(&pContext->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *cqCreate(void *handle, uint64_t uid, int32_t tid, char *sqlStr, STSchema *pSchema) {
|
void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, char *sqlStr, STSchema *pSchema) {
|
||||||
if (tsEnableStream == 0) {
|
if (tsEnableStream == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -195,9 +196,11 @@ void *cqCreate(void *handle, uint64_t uid, int32_t tid, char *sqlStr, STSchema *
|
||||||
if (pObj == NULL) return NULL;
|
if (pObj == NULL) return NULL;
|
||||||
|
|
||||||
pObj->uid = uid;
|
pObj->uid = uid;
|
||||||
pObj->tid = tid;
|
pObj->tid = sid;
|
||||||
pObj->sqlStr = malloc(strlen(sqlStr)+1);
|
if (dstTable != NULL) {
|
||||||
strcpy(pObj->sqlStr, sqlStr);
|
pObj->dstTable = strdup(dstTable);
|
||||||
|
}
|
||||||
|
pObj->sqlStr = strdup(sqlStr);
|
||||||
|
|
||||||
pObj->pSchema = tdDupSchema(pSchema);
|
pObj->pSchema = tdDupSchema(pSchema);
|
||||||
pObj->rowSize = schemaTLen(pSchema);
|
pObj->rowSize = schemaTLen(pSchema);
|
||||||
|
@ -247,6 +250,7 @@ void cqDrop(void *handle) {
|
||||||
|
|
||||||
cInfo("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr);
|
cInfo("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr);
|
||||||
tdFreeSchema(pObj->pSchema);
|
tdFreeSchema(pObj->pSchema);
|
||||||
|
free(pObj->dstTable);
|
||||||
free(pObj->sqlStr);
|
free(pObj->sqlStr);
|
||||||
free(pObj);
|
free(pObj);
|
||||||
|
|
||||||
|
@ -292,8 +296,9 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
|
||||||
if (pObj->pStream == NULL) {
|
if (pObj->pStream == NULL) {
|
||||||
pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, pObj, NULL);
|
pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, pObj, NULL);
|
||||||
if (pObj->pStream) {
|
if (pObj->pStream) {
|
||||||
|
tscSetStreamDestTable(pObj->pStream, pObj->dstTable);
|
||||||
pContext->num++;
|
pContext->num++;
|
||||||
cInfo("vgId:%d, id:%d CQ:%s is openned", pContext->vgId, pObj->tid, pObj->sqlStr);
|
cDebug("vgId:%d, id:%d CQ:%s is opened", pContext->vgId, pObj->tid, pObj->sqlStr);
|
||||||
} else {
|
} else {
|
||||||
cError("vgId:%d, id:%d CQ:%s, failed to open", pContext->vgId, pObj->tid, pObj->sqlStr);
|
cError("vgId:%d, id:%d CQ:%s, failed to open", pContext->vgId, pObj->tid, pObj->sqlStr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
|
||||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
|
||||||
for (int sid =1; sid<10; ++sid) {
|
for (int sid =1; sid<10; ++sid) {
|
||||||
cqCreate(pCq, sid, sid, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema);
|
cqCreate(pCq, sid, sid, NULL, "select avg(speed) from demo.t1 sliding(1s) interval(5s)", pSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
tdFreeSchema(pSchema);
|
tdFreeSchema(pSchema);
|
||||||
|
|
|
@ -36,6 +36,14 @@ extern int32_t dDebugFlag;
|
||||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TSDB_RUN_STATUS_INITIALIZE,
|
||||||
|
TSDB_RUN_STATUS_RUNING,
|
||||||
|
TSDB_RUN_STATUS_STOPPED
|
||||||
|
} SRunStatus;
|
||||||
|
|
||||||
|
SRunStatus dnodeGetRunStatus();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,8 +22,8 @@ extern "C" {
|
||||||
#include "dnodeInt.h"
|
#include "dnodeInt.h"
|
||||||
|
|
||||||
int32_t dnodeInitModules();
|
int32_t dnodeInitModules();
|
||||||
void dnodeStartModules();
|
|
||||||
void dnodeCleanupModules();
|
void dnodeCleanupModules();
|
||||||
|
bool dnodeStartMnode(SMInfos *pMinfos);
|
||||||
void dnodeProcessModuleStatus(uint32_t moduleStatus);
|
void dnodeProcessModuleStatus(uint32_t moduleStatus);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -24,8 +24,10 @@ extern "C" {
|
||||||
int32_t dnodeInitVRead();
|
int32_t dnodeInitVRead();
|
||||||
void dnodeCleanupVRead();
|
void dnodeCleanupVRead();
|
||||||
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg);
|
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg);
|
||||||
void * dnodeAllocVReadQueue(void *pVnode);
|
void * dnodeAllocVQueryQueue(void *pVnode);
|
||||||
void dnodeFreeVReadQueue(void *pRqueue);
|
void * dnodeAllocVFetchQueue(void *pVnode);
|
||||||
|
void dnodeFreeVQueryQueue(void *pQqueue);
|
||||||
|
void dnodeFreeVFetchQueue(void *pFqueue);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
||||||
|
|
||||||
int32_t dnodeInitVnodes();
|
int32_t dnodeInitVnodes();
|
||||||
void dnodeCleanupVnodes();
|
void dnodeCleanupVnodes();
|
||||||
int32_t dnodeInitTimer();
|
int32_t dnodeInitStatusTimer();
|
||||||
void dnodeCleanupTimer();
|
void dnodeCleanupStatusTimer();
|
||||||
void dnodeSendStatusMsgToMnode();
|
void dnodeSendStatusMsgToMnode();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -130,7 +130,7 @@ static void dnodePrintEps(SDnodeEps *eps) {
|
||||||
dDebug("print dnodeEp, dnodeNum:%d", eps->dnodeNum);
|
dDebug("print dnodeEp, dnodeNum:%d", eps->dnodeNum);
|
||||||
for (int32_t i = 0; i < eps->dnodeNum; i++) {
|
for (int32_t i = 0; i < eps->dnodeNum; i++) {
|
||||||
SDnodeEp *ep = &eps->dnodeEps[i];
|
SDnodeEp *ep = &eps->dnodeEps[i];
|
||||||
dDebug("dnodeId:%d, dnodeFqdn:%s dnodePort:%u", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort);
|
dDebug("dnode:%d, dnodeFqdn:%s dnodePort:%u", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ void dnodeDispatchToMWriteQueue(SRpcMsg *pMsg) {
|
||||||
dnodeSendRedirectMsg(pMsg, true);
|
dnodeSendRedirectMsg(pMsg, true);
|
||||||
} else {
|
} else {
|
||||||
SMnodeMsg *pWrite = mnodeCreateMsg(pMsg);
|
SMnodeMsg *pWrite = mnodeCreateMsg(pMsg);
|
||||||
dDebug("msg:%p, app:%p type:%s is put into mwrite queue:%p", pWrite, pWrite->rpcMsg.ahandle,
|
dTrace("msg:%p, app:%p type:%s is put into mwrite queue:%p", pWrite, pWrite->rpcMsg.ahandle,
|
||||||
taosMsg[pWrite->rpcMsg.msgType], tsMWriteQueue);
|
taosMsg[pWrite->rpcMsg.msgType], tsMWriteQueue);
|
||||||
taosWriteQitem(tsMWriteQueue, TAOS_QTYPE_RPC, pWrite);
|
taosWriteQitem(tsMWriteQueue, TAOS_QTYPE_RPC, pWrite);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ void dnodeDispatchToMWriteQueue(SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dnodeFreeMWriteMsg(SMnodeMsg *pWrite) {
|
static void dnodeFreeMWriteMsg(SMnodeMsg *pWrite) {
|
||||||
dDebug("msg:%p, app:%p type:%s is freed from mwrite queue:%p", pWrite, pWrite->rpcMsg.ahandle,
|
dTrace("msg:%p, app:%p type:%s is freed from mwrite queue:%p", pWrite, pWrite->rpcMsg.ahandle,
|
||||||
taosMsg[pWrite->rpcMsg.msgType], tsMWriteQueue);
|
taosMsg[pWrite->rpcMsg.msgType], tsMWriteQueue);
|
||||||
|
|
||||||
mnodeCleanupMsg(pWrite);
|
mnodeCleanupMsg(pWrite);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tnote.h"
|
#include "tnote.h"
|
||||||
|
#include "ttimer.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tfile.h"
|
#include "tfile.h"
|
||||||
#include "twal.h"
|
#include "twal.h"
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
#include "dnodeShell.h"
|
#include "dnodeShell.h"
|
||||||
#include "dnodeTelemetry.h"
|
#include "dnodeTelemetry.h"
|
||||||
|
|
||||||
|
void *tsDnodeTmr = NULL;
|
||||||
static SRunStatus tsRunStatus = TSDB_RUN_STATUS_STOPPED;
|
static SRunStatus tsRunStatus = TSDB_RUN_STATUS_STOPPED;
|
||||||
|
|
||||||
static int32_t dnodeInitStorage();
|
static int32_t dnodeInitStorage();
|
||||||
|
@ -68,8 +70,8 @@ static SStep tsDnodeSteps[] = {
|
||||||
{"dnode-server", dnodeInitServer, dnodeCleanupServer},
|
{"dnode-server", dnodeInitServer, dnodeCleanupServer},
|
||||||
{"dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes},
|
{"dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes},
|
||||||
{"dnode-modules", dnodeInitModules, dnodeCleanupModules},
|
{"dnode-modules", dnodeInitModules, dnodeCleanupModules},
|
||||||
{"dnode-tmr", dnodeInitTimer, dnodeCleanupTimer},
|
|
||||||
{"dnode-shell", dnodeInitShell, dnodeCleanupShell},
|
{"dnode-shell", dnodeInitShell, dnodeCleanupShell},
|
||||||
|
{"dnode-statustmr", dnodeInitStatusTimer,dnodeCleanupStatusTimer},
|
||||||
{"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry},
|
{"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,6 +93,23 @@ static int32_t dnodeInitComponents() {
|
||||||
return dnodeStepInit(tsDnodeSteps, stepSize);
|
return dnodeStepInit(tsDnodeSteps, stepSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeInitTmr() {
|
||||||
|
tsDnodeTmr = taosTmrInit(100, 200, 60000, "DND-DM");
|
||||||
|
if (tsDnodeTmr == NULL) {
|
||||||
|
dError("failed to init dnode timer");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dnodeCleanupTmr() {
|
||||||
|
if (tsDnodeTmr != NULL) {
|
||||||
|
taosTmrCleanUp(tsDnodeTmr);
|
||||||
|
tsDnodeTmr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dnodeInitSystem() {
|
int32_t dnodeInitSystem() {
|
||||||
dnodeSetRunStatus(TSDB_RUN_STATUS_INITIALIZE);
|
dnodeSetRunStatus(TSDB_RUN_STATUS_INITIALIZE);
|
||||||
tscEmbedded = 1;
|
tscEmbedded = 1;
|
||||||
|
@ -100,6 +119,7 @@ int32_t dnodeInitSystem() {
|
||||||
taosReadGlobalLogCfg();
|
taosReadGlobalLogCfg();
|
||||||
taosSetCoreDump();
|
taosSetCoreDump();
|
||||||
taosInitNotes();
|
taosInitNotes();
|
||||||
|
dnodeInitTmr();
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
if (dnodeCreateDir(tsLogDir) < 0) {
|
if (dnodeCreateDir(tsLogDir) < 0) {
|
||||||
|
@ -125,9 +145,9 @@ int32_t dnodeInitSystem() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dnodeStartModules();
|
|
||||||
dnodeSetRunStatus(TSDB_RUN_STATUS_RUNING);
|
dnodeSetRunStatus(TSDB_RUN_STATUS_RUNING);
|
||||||
|
|
||||||
|
dnodeReportStep("TDengine", "initialized successfully", 1);
|
||||||
dInfo("TDengine is initialized successfully");
|
dInfo("TDengine is initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -136,6 +156,7 @@ int32_t dnodeInitSystem() {
|
||||||
void dnodeCleanUpSystem() {
|
void dnodeCleanUpSystem() {
|
||||||
if (dnodeGetRunStatus() != TSDB_RUN_STATUS_STOPPED) {
|
if (dnodeGetRunStatus() != TSDB_RUN_STATUS_STOPPED) {
|
||||||
dnodeSetRunStatus(TSDB_RUN_STATUS_STOPPED);
|
dnodeSetRunStatus(TSDB_RUN_STATUS_STOPPED);
|
||||||
|
dnodeCleanupTmr();
|
||||||
dnodeCleanupComponents();
|
dnodeCleanupComponents();
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
|
|
@ -97,6 +97,20 @@ void dnodeCleanupModules() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeStartModules() {
|
||||||
|
for (EModuleType module = 1; module < TSDB_MOD_MAX; ++module) {
|
||||||
|
if (tsModule[module].enable && tsModule[module].startFp) {
|
||||||
|
int32_t code = (*tsModule[module].startFp)();
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to start module:%s, code:%d", tsModule[module].name, code);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dnodeInitModules() {
|
int32_t dnodeInitModules() {
|
||||||
dnodeAllocModules();
|
dnodeAllocModules();
|
||||||
|
|
||||||
|
@ -110,17 +124,7 @@ int32_t dnodeInitModules() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("dnode modules is initialized");
|
dInfo("dnode modules is initialized");
|
||||||
return 0;
|
return dnodeStartModules();
|
||||||
}
|
|
||||||
|
|
||||||
void dnodeStartModules() {
|
|
||||||
for (EModuleType module = 1; module < TSDB_MOD_MAX; ++module) {
|
|
||||||
if (tsModule[module].enable && tsModule[module].startFp) {
|
|
||||||
if ((*tsModule[module].startFp)() != 0) {
|
|
||||||
dError("failed to start module:%s", tsModule[module].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeProcessModuleStatus(uint32_t moduleStatus) {
|
void dnodeProcessModuleStatus(uint32_t moduleStatus) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||||
rpcSendResponse(&rspMsg);
|
rpcSendResponse(&rspMsg);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
dDebug("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
|
dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ void dnodeCleanupClient() {
|
||||||
static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
static void dnodeProcessRspFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||||
if (dnodeGetRunStatus() == TSDB_RUN_STATUS_STOPPED) {
|
if (dnodeGetRunStatus() == TSDB_RUN_STATUS_STOPPED) {
|
||||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||||
dDebug("msg:%p is ignored since dnode is stopping", pMsg);
|
dTrace("msg:%p is ignored since dnode is stopping", pMsg);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,7 @@ int32_t dnodeInitShell() {
|
||||||
|
|
||||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep;
|
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeSendStartupStep;
|
||||||
|
|
||||||
int32_t numOfThreads = tsNumOfCores * tsNumOfThreadsPerCore;
|
int32_t numOfThreads = (tsNumOfCores * tsNumOfThreadsPerCore) / 2.0;
|
||||||
numOfThreads = (int32_t) ((1.0 - tsRatioOfQueryThreads) * numOfThreads / 2.0);
|
|
||||||
if (numOfThreads < 1) {
|
if (numOfThreads < 1) {
|
||||||
numOfThreads = 1;
|
numOfThreads = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,12 +57,13 @@ int32_t dnodeStepInit(SStep *pSteps, int32_t stepSize) {
|
||||||
|
|
||||||
int32_t code = (*pStep->initFp)();
|
int32_t code = (*pStep->initFp)();
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dDebug("step:%s will init", pStep->name);
|
dDebug("step:%s will cleanup", pStep->name);
|
||||||
taosStepCleanupImp(pSteps, step);
|
taosStepCleanupImp(pSteps, step);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
dInfo("step:%s is initialized", pStep->name);
|
||||||
|
|
||||||
dnodeReportStep(pStep->name, "Initialization complete", step + 1 >= stepSize);
|
dnodeReportStep(pStep->name, "Initialization complete", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -16,12 +16,15 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tgrant.h"
|
#include "tgrant.h"
|
||||||
|
#include "tconfig.h"
|
||||||
#include "dnodeMain.h"
|
#include "dnodeMain.h"
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||||
static tsem_t exitSem;
|
static tsem_t exitSem;
|
||||||
|
|
||||||
int32_t main(int32_t argc, char *argv[]) {
|
int32_t main(int32_t argc, char *argv[]) {
|
||||||
|
int dump_config = 0;
|
||||||
|
|
||||||
// Set global configuration file
|
// Set global configuration file
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
|
@ -35,6 +38,8 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
printf("'-c' requires a parameter, default:%s\n", configDir);
|
printf("'-c' requires a parameter, default:%s\n", configDir);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
|
dump_config = 1;
|
||||||
} else if (strcmp(argv[i], "-V") == 0) {
|
} else if (strcmp(argv[i], "-V") == 0) {
|
||||||
#ifdef _ACCT
|
#ifdef _ACCT
|
||||||
char *versionStr = "enterprise";
|
char *versionStr = "enterprise";
|
||||||
|
@ -87,6 +92,20 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 != dump_config) {
|
||||||
|
tscEmbedded = 1;
|
||||||
|
taosInitGlobalCfg();
|
||||||
|
taosReadGlobalLogCfg();
|
||||||
|
|
||||||
|
if (!taosReadGlobalCfg()) {
|
||||||
|
printf("TDengine read global config failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosDumpGlobalCfg();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
if (tsem_init(&exitSem, 0, 0) != 0) {
|
if (tsem_init(&exitSem, 0, 0) != 0) {
|
||||||
printf("failed to create exit semphore\n");
|
printf("failed to create exit semphore\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
|
#include "tworker.h"
|
||||||
#include "dnodeVMgmt.h"
|
#include "dnodeVMgmt.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -23,9 +24,8 @@ typedef struct {
|
||||||
char pCont[];
|
char pCont[];
|
||||||
} SMgmtMsg;
|
} SMgmtMsg;
|
||||||
|
|
||||||
static taos_qset tsMgmtQset = NULL;
|
static SWorkerPool tsVMgmtWP;
|
||||||
static taos_queue tsMgmtQueue = NULL;
|
static taos_queue tsVMgmtQueue = NULL;
|
||||||
static pthread_t tsQthread;
|
|
||||||
|
|
||||||
static void * dnodeProcessMgmtQueue(void *param);
|
static void * dnodeProcessMgmtQueue(void *param);
|
||||||
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg);
|
||||||
|
@ -47,45 +47,23 @@ int32_t dnodeInitVMgmt() {
|
||||||
int32_t code = vnodeInitMgmt();
|
int32_t code = vnodeInitMgmt();
|
||||||
if (code != TSDB_CODE_SUCCESS) return -1;
|
if (code != TSDB_CODE_SUCCESS) return -1;
|
||||||
|
|
||||||
tsMgmtQset = taosOpenQset();
|
tsVMgmtWP.name = "vmgmt";
|
||||||
if (tsMgmtQset == NULL) {
|
tsVMgmtWP.workerFp = dnodeProcessMgmtQueue;
|
||||||
dError("failed to create the vmgmt queue set");
|
tsVMgmtWP.min = 1;
|
||||||
return -1;
|
tsVMgmtWP.max = 1;
|
||||||
}
|
if (tWorkerInit(&tsVMgmtWP) != 0) return -1;
|
||||||
|
|
||||||
tsMgmtQueue = taosOpenQueue();
|
tsVMgmtQueue = tWorkerAllocQueue(&tsVMgmtWP, NULL);
|
||||||
if (tsMgmtQueue == NULL) {
|
|
||||||
dError("failed to create the vmgmt queue");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosAddIntoQset(tsMgmtQset, tsMgmtQueue, NULL);
|
|
||||||
|
|
||||||
pthread_attr_t thAttr;
|
|
||||||
pthread_attr_init(&thAttr);
|
|
||||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
|
||||||
|
|
||||||
code = pthread_create(&tsQthread, &thAttr, dnodeProcessMgmtQueue, NULL);
|
|
||||||
pthread_attr_destroy(&thAttr);
|
|
||||||
if (code != 0) {
|
|
||||||
dError("failed to create thread to process vmgmt queue, reason:%s", strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("dnode vmgmt is initialized");
|
dInfo("dnode vmgmt is initialized");
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeCleanupVMgmt() {
|
void dnodeCleanupVMgmt() {
|
||||||
if (tsMgmtQset) taosQsetThreadResume(tsMgmtQset);
|
tWorkerFreeQueue(&tsVMgmtWP, tsVMgmtQueue);
|
||||||
if (tsQthread) pthread_join(tsQthread, NULL);
|
tWorkerCleanup(&tsVMgmtWP);
|
||||||
|
|
||||||
if (tsMgmtQueue) taosCloseQueue(tsMgmtQueue);
|
|
||||||
if (tsMgmtQset) taosCloseQset(tsMgmtQset);
|
|
||||||
|
|
||||||
tsMgmtQset = NULL;
|
|
||||||
tsMgmtQueue = NULL;
|
|
||||||
|
|
||||||
|
tsVMgmtQueue = NULL;
|
||||||
vnodeCleanupMgmt();
|
vnodeCleanupMgmt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +75,7 @@ static int32_t dnodeWriteToMgmtQueue(SRpcMsg *pMsg) {
|
||||||
pMgmt->rpcMsg = *pMsg;
|
pMgmt->rpcMsg = *pMsg;
|
||||||
pMgmt->rpcMsg.pCont = pMgmt->pCont;
|
pMgmt->rpcMsg.pCont = pMgmt->pCont;
|
||||||
memcpy(pMgmt->pCont, pMsg->pCont, pMsg->contLen);
|
memcpy(pMgmt->pCont, pMsg->pCont, pMsg->contLen);
|
||||||
taosWriteQitem(tsMgmtQueue, TAOS_QTYPE_RPC, pMgmt);
|
taosWriteQitem(tsVMgmtQueue, TAOS_QTYPE_RPC, pMgmt);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -112,28 +90,30 @@ void dnodeDispatchToVMgmtQueue(SRpcMsg *pMsg) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *dnodeProcessMgmtQueue(void *param) {
|
static void *dnodeProcessMgmtQueue(void *wparam) {
|
||||||
SMgmtMsg *pMgmt;
|
SWorker * pWorker = wparam;
|
||||||
SRpcMsg * pMsg;
|
SWorkerPool *pPool = pWorker->pPool;
|
||||||
SRpcMsg rsp = {0};
|
SMgmtMsg * pMgmt;
|
||||||
int32_t qtype;
|
SRpcMsg * pMsg;
|
||||||
void * handle;
|
SRpcMsg rsp = {0};
|
||||||
|
int32_t qtype;
|
||||||
|
void * handle;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (taosReadQitemFromQset(tsMgmtQset, &qtype, (void **)&pMgmt, &handle) == 0) {
|
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pMgmt, &handle) == 0) {
|
||||||
dDebug("qset:%p, dnode mgmt got no message from qset, exit", tsMgmtQset);
|
dDebug("qdnode mgmt got no message from qset:%p, , exit", pPool->qset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMsg = &pMgmt->rpcMsg;
|
pMsg = &pMgmt->rpcMsg;
|
||||||
dDebug("msg:%p, ahandle:%p type:%s will be processed", pMgmt, pMsg->ahandle, taosMsg[pMsg->msgType]);
|
dTrace("msg:%p, ahandle:%p type:%s will be processed", pMgmt, pMsg->ahandle, taosMsg[pMsg->msgType]);
|
||||||
if (dnodeProcessMgmtMsgFp[pMsg->msgType]) {
|
if (dnodeProcessMgmtMsgFp[pMsg->msgType]) {
|
||||||
rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg);
|
rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg);
|
||||||
} else {
|
} else {
|
||||||
rsp.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
rsp.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("msg:%p, is processed, code:0x%x", pMgmt, rsp.code);
|
dTrace("msg:%p, is processed, code:0x%x", pMgmt, rsp.code);
|
||||||
if (rsp.code != TSDB_CODE_DND_ACTION_IN_PROGRESS) {
|
if (rsp.code != TSDB_CODE_DND_ACTION_IN_PROGRESS) {
|
||||||
rsp.handle = pMsg->handle;
|
rsp.handle = pMsg->handle;
|
||||||
rsp.pCont = NULL;
|
rsp.pCont = NULL;
|
||||||
|
@ -218,7 +198,7 @@ static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
||||||
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||||
dDebug("dnodeId:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
dDebug("dnode:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
||||||
return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED;
|
return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +207,7 @@ static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnodeId:%d, create mnode msg is received from mnodes, numOfMnodes:%d", pCfg->dnodeId, pCfg->mnodes.mnodeNum);
|
dDebug("dnode:%d, create mnode msg is received from mnodes, numOfMnodes:%d", pCfg->dnodeId, pCfg->mnodes.mnodeNum);
|
||||||
for (int i = 0; i < pCfg->mnodes.mnodeNum; ++i) {
|
for (int i = 0; i < pCfg->mnodes.mnodeNum; ++i) {
|
||||||
pCfg->mnodes.mnodeInfos[i].mnodeId = htonl(pCfg->mnodes.mnodeInfos[i].mnodeId);
|
pCfg->mnodes.mnodeInfos[i].mnodeId = htonl(pCfg->mnodes.mnodeInfos[i].mnodeId);
|
||||||
dDebug("mnode index:%d, mnode:%d:%s", i, pCfg->mnodes.mnodeInfos[i].mnodeId, pCfg->mnodes.mnodeInfos[i].mnodeEp);
|
dDebug("mnode index:%d, mnode:%d:%s", i, pCfg->mnodes.mnodeInfos[i].mnodeId, pCfg->mnodes.mnodeInfos[i].mnodeEp);
|
||||||
|
|
|
@ -16,66 +16,39 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
|
#include "tworker.h"
|
||||||
#include "dnodeVRead.h"
|
#include "dnodeVRead.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
pthread_t thread; // thread
|
|
||||||
int32_t workerId; // worker ID
|
|
||||||
} SVReadWorker;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t max; // max number of workers
|
|
||||||
int32_t min; // min number of workers
|
|
||||||
int32_t num; // current number of workers
|
|
||||||
SVReadWorker * worker;
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
} SVReadWorkerPool;
|
|
||||||
|
|
||||||
static void *dnodeProcessReadQueue(void *pWorker);
|
static void *dnodeProcessReadQueue(void *pWorker);
|
||||||
|
|
||||||
// module global variable
|
// module global variable
|
||||||
static SVReadWorkerPool tsVReadWP;
|
static SWorkerPool tsVQueryWP;
|
||||||
static taos_qset tsVReadQset;
|
static SWorkerPool tsVFetchWP;
|
||||||
|
|
||||||
int32_t dnodeInitVRead() {
|
int32_t dnodeInitVRead() {
|
||||||
tsVReadQset = taosOpenQset();
|
const int32_t maxFetchThreads = 4;
|
||||||
|
|
||||||
tsVReadWP.min = tsNumOfCores;
|
// calculate the available query thread
|
||||||
tsVReadWP.max = tsNumOfCores * tsNumOfThreadsPerCore;
|
float threadsForQuery = MAX(tsNumOfCores * tsRatioOfQueryCores, 1);
|
||||||
if (tsVReadWP.max <= tsVReadWP.min * 2) tsVReadWP.max = 2 * tsVReadWP.min;
|
|
||||||
tsVReadWP.worker = calloc(sizeof(SVReadWorker), tsVReadWP.max);
|
|
||||||
pthread_mutex_init(&tsVReadWP.mutex, NULL);
|
|
||||||
|
|
||||||
if (tsVReadWP.worker == NULL) return -1;
|
tsVQueryWP.name = "vquery";
|
||||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
tsVQueryWP.workerFp = dnodeProcessReadQueue;
|
||||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
tsVQueryWP.min = (int32_t) threadsForQuery;
|
||||||
pWorker->workerId = i;
|
tsVQueryWP.max = tsVQueryWP.min;
|
||||||
}
|
if (tWorkerInit(&tsVQueryWP) != 0) return -1;
|
||||||
|
|
||||||
|
tsVFetchWP.name = "vfetch";
|
||||||
|
tsVFetchWP.workerFp = dnodeProcessReadQueue;
|
||||||
|
tsVFetchWP.min = MIN(maxFetchThreads, tsNumOfCores);
|
||||||
|
tsVFetchWP.max = tsVFetchWP.min;
|
||||||
|
if (tWorkerInit(&tsVFetchWP) != 0) return -1;
|
||||||
|
|
||||||
dInfo("dnode vread is initialized, min worker:%d max worker:%d", tsVReadWP.min, tsVReadWP.max);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeCleanupVRead() {
|
void dnodeCleanupVRead() {
|
||||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
tWorkerCleanup(&tsVFetchWP);
|
||||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
tWorkerCleanup(&tsVQueryWP);
|
||||||
if (pWorker->thread) {
|
|
||||||
taosQsetThreadResume(tsVReadQset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
|
||||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
|
||||||
if (pWorker->thread) {
|
|
||||||
pthread_join(pWorker->thread, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(tsVReadWP.worker);
|
|
||||||
taosCloseQset(tsVReadQset);
|
|
||||||
pthread_mutex_destroy(&tsVReadWP.mutex);
|
|
||||||
|
|
||||||
dInfo("dnode vread is closed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) {
|
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) {
|
||||||
|
@ -88,6 +61,7 @@ void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) {
|
||||||
pHead->vgId = htonl(pHead->vgId);
|
pHead->vgId = htonl(pHead->vgId);
|
||||||
pHead->contLen = htonl(pHead->contLen);
|
pHead->contLen = htonl(pHead->contLen);
|
||||||
|
|
||||||
|
assert(pHead->contLen > 0);
|
||||||
void *pVnode = vnodeAcquire(pHead->vgId);
|
void *pVnode = vnodeAcquire(pHead->vgId);
|
||||||
if (pVnode != NULL) {
|
if (pVnode != NULL) {
|
||||||
int32_t code = vnodeWriteToRQueue(pVnode, pCont, pHead->contLen, TAOS_QTYPE_RPC, pMsg);
|
int32_t code = vnodeWriteToRQueue(pVnode, pCont, pHead->contLen, TAOS_QTYPE_RPC, pMsg);
|
||||||
|
@ -107,43 +81,20 @@ void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *dnodeAllocVReadQueue(void *pVnode) {
|
void *dnodeAllocVQueryQueue(void *pVnode) {
|
||||||
pthread_mutex_lock(&tsVReadWP.mutex);
|
return tWorkerAllocQueue(&tsVQueryWP, pVnode);
|
||||||
taos_queue queue = taosOpenQueue();
|
|
||||||
if (queue == NULL) {
|
|
||||||
pthread_mutex_unlock(&tsVReadWP.mutex);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosAddIntoQset(tsVReadQset, queue, pVnode);
|
|
||||||
|
|
||||||
// spawn a thread to process queue
|
|
||||||
if (tsVReadWP.num < tsVReadWP.max) {
|
|
||||||
do {
|
|
||||||
SVReadWorker *pWorker = tsVReadWP.worker + tsVReadWP.num;
|
|
||||||
|
|
||||||
pthread_attr_t thAttr;
|
|
||||||
pthread_attr_init(&thAttr);
|
|
||||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
|
||||||
|
|
||||||
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessReadQueue, pWorker) != 0) {
|
|
||||||
dError("failed to create thread to process vread vqueue since %s", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_attr_destroy(&thAttr);
|
|
||||||
tsVReadWP.num++;
|
|
||||||
dDebug("dnode vread worker:%d is launched, total:%d", pWorker->workerId, tsVReadWP.num);
|
|
||||||
} while (tsVReadWP.num < tsVReadWP.min);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&tsVReadWP.mutex);
|
|
||||||
dDebug("pVnode:%p, dnode vread queue:%p is allocated", pVnode, queue);
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeFreeVReadQueue(void *pRqueue) {
|
void *dnodeAllocVFetchQueue(void *pVnode) {
|
||||||
taosCloseQueue(pRqueue);
|
return tWorkerAllocQueue(&tsVFetchWP, pVnode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeFreeVQueryQueue(void *pQqueue) {
|
||||||
|
tWorkerFreeQueue(&tsVQueryWP, pQqueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeFreeVFetchQueue(void *pFqueue) {
|
||||||
|
tWorkerFreeQueue(&tsVFetchWP, pFqueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeSendRpcVReadRsp(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
void dnodeSendRpcVReadRsp(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
||||||
|
@ -160,18 +111,20 @@ void dnodeSendRpcVReadRsp(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
||||||
void dnodeDispatchNonRspMsg(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
void dnodeDispatchNonRspMsg(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *dnodeProcessReadQueue(void *pWorker) {
|
static void *dnodeProcessReadQueue(void *wparam) {
|
||||||
SVReadMsg *pRead;
|
SWorker * pWorker = wparam;
|
||||||
int32_t qtype;
|
SWorkerPool *pPool = pWorker->pPool;
|
||||||
void * pVnode;
|
SVReadMsg * pRead;
|
||||||
|
int32_t qtype;
|
||||||
|
void * pVnode;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (taosReadQitemFromQset(tsVReadQset, &qtype, (void **)&pRead, &pVnode) == 0) {
|
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pRead, &pVnode) == 0) {
|
||||||
dDebug("qset:%p dnode vread got no message from qset, exiting", tsVReadQset);
|
dDebug("dnode vquery got no message from qset:%p, exiting", pPool->qset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, app:%p type:%s will be processed in vread queue, qtype:%d", pRead, pRead->rpcAhandle,
|
dTrace("msg:%p, app:%p type:%s will be processed in vquery queue, qtype:%d", pRead, pRead->rpcAhandle,
|
||||||
taosMsg[pRead->msgType], qtype);
|
taosMsg[pRead->msgType], qtype);
|
||||||
|
|
||||||
int32_t code = vnodeProcessRead(pVnode, pRead);
|
int32_t code = vnodeProcessRead(pVnode, pRead);
|
||||||
|
|
|
@ -30,39 +30,30 @@ typedef struct {
|
||||||
int32_t * vnodeList;
|
int32_t * vnodeList;
|
||||||
} SOpenVnodeThread;
|
} SOpenVnodeThread;
|
||||||
|
|
||||||
void * tsDnodeTmr = NULL;
|
extern void * tsDnodeTmr;
|
||||||
static void * tsStatusTimer = NULL;
|
static void * tsStatusTimer = NULL;
|
||||||
static uint32_t tsRebootTime = 0;
|
static uint32_t tsRebootTime = 0;
|
||||||
|
static int32_t tsOpenVnodes = 0;
|
||||||
|
static int32_t tsTotalVnodes = 0;
|
||||||
|
|
||||||
static void dnodeSendStatusMsg(void *handle, void *tmrId);
|
static void dnodeSendStatusMsg(void *handle, void *tmrId);
|
||||||
static void dnodeProcessStatusRsp(SRpcMsg *pMsg);
|
static void dnodeProcessStatusRsp(SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t dnodeInitTimer() {
|
int32_t dnodeInitStatusTimer() {
|
||||||
tsDnodeTmr = taosTmrInit(100, 200, 60000, "DND-DM");
|
|
||||||
if (tsDnodeTmr == NULL) {
|
|
||||||
dError("failed to init dnode timer");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dnodeAddClientRspHandle(TSDB_MSG_TYPE_DM_STATUS_RSP, dnodeProcessStatusRsp);
|
dnodeAddClientRspHandle(TSDB_MSG_TYPE_DM_STATUS_RSP, dnodeProcessStatusRsp);
|
||||||
|
|
||||||
tsRebootTime = taosGetTimestampSec();
|
tsRebootTime = taosGetTimestampSec();
|
||||||
taosTmrReset(dnodeSendStatusMsg, 500, NULL, tsDnodeTmr, &tsStatusTimer);
|
taosTmrReset(dnodeSendStatusMsg, 500, NULL, tsDnodeTmr, &tsStatusTimer);
|
||||||
|
|
||||||
dInfo("dnode timer is initialized");
|
dInfo("dnode status timer is initialized");
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeCleanupTimer() {
|
void dnodeCleanupStatusTimer() {
|
||||||
if (tsStatusTimer != NULL) {
|
if (tsStatusTimer != NULL) {
|
||||||
taosTmrStopA(&tsStatusTimer);
|
taosTmrStopA(&tsStatusTimer);
|
||||||
tsStatusTimer = NULL;
|
tsStatusTimer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsDnodeTmr != NULL) {
|
|
||||||
taosTmrCleanUp(tsDnodeTmr);
|
|
||||||
tsDnodeTmr = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||||
|
@ -95,21 +86,27 @@ static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||||
|
|
||||||
static void *dnodeOpenVnode(void *param) {
|
static void *dnodeOpenVnode(void *param) {
|
||||||
SOpenVnodeThread *pThread = param;
|
SOpenVnodeThread *pThread = param;
|
||||||
|
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||||
|
|
||||||
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||||
|
|
||||||
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
||||||
int32_t vgId = pThread->vnodeList[v];
|
int32_t vgId = pThread->vnodeList[v];
|
||||||
|
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, tsOpenVnodes, tsTotalVnodes);
|
||||||
|
dnodeReportStep("open-vnodes", stepDesc, 0);
|
||||||
|
|
||||||
if (vnodeOpen(vgId) < 0) {
|
if (vnodeOpen(vgId) < 0) {
|
||||||
dError("vgId:%d, failed to open vnode by thread:%d", vgId, pThread->threadIndex);
|
dError("vgId:%d, failed to open vnode by thread:%d", vgId, pThread->threadIndex);
|
||||||
pThread->failed++;
|
pThread->failed++;
|
||||||
} else {
|
} else {
|
||||||
dDebug("vgId:%d, is openned by thread:%d", vgId, pThread->threadIndex);
|
dDebug("vgId:%d, is opened by thread:%d", vgId, pThread->threadIndex);
|
||||||
pThread->opened++;
|
pThread->opened++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic_add_fetch_32(&tsOpenVnodes, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("thread:%d, total vnodes:%d, openned:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
dDebug("thread:%d, total vnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||||
pThread->failed);
|
pThread->failed);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +115,7 @@ int32_t dnodeInitVnodes() {
|
||||||
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes);
|
int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes);
|
||||||
|
tsTotalVnodes = numOfVnodes;
|
||||||
|
|
||||||
if (status != TSDB_CODE_SUCCESS) {
|
if (status != TSDB_CODE_SUCCESS) {
|
||||||
dInfo("get dnode list failed");
|
dInfo("get dnode list failed");
|
||||||
|
@ -138,7 +136,7 @@ int32_t dnodeInitVnodes() {
|
||||||
pThread->vnodeList[pThread->vnodeNum++] = vnodeList[v];
|
pThread->vnodeList[pThread->vnodeNum++] = vnodeList[v];
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("start %d threads to open %d vnodes", threadNum, numOfVnodes);
|
dInfo("start %d threads to open %d vnodes", threadNum, numOfVnodes);
|
||||||
|
|
||||||
for (int32_t t = 0; t < threadNum; ++t) {
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
SOpenVnodeThread *pThread = &threads[t];
|
SOpenVnodeThread *pThread = &threads[t];
|
||||||
|
@ -167,7 +165,7 @@ int32_t dnodeInitVnodes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
free(threads);
|
free(threads);
|
||||||
dInfo("there are total vnodes:%d, openned:%d", numOfVnodes, openVnodes);
|
dInfo("there are total vnodes:%d, opened:%d", numOfVnodes, openVnodes);
|
||||||
|
|
||||||
if (failedVnodes != 0) {
|
if (failedVnodes != 0) {
|
||||||
dError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes);
|
dError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes);
|
||||||
|
|
|
@ -29,13 +29,6 @@ typedef struct {
|
||||||
int32_t httpReqNum;
|
int32_t httpReqNum;
|
||||||
} SStatisInfo;
|
} SStatisInfo;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TSDB_RUN_STATUS_INITIALIZE,
|
|
||||||
TSDB_RUN_STATUS_RUNING,
|
|
||||||
TSDB_RUN_STATUS_STOPPED
|
|
||||||
} SRunStatus;
|
|
||||||
|
|
||||||
SRunStatus dnodeGetRunStatus();
|
|
||||||
SStatisInfo dnodeGetStatisInfo();
|
SStatisInfo dnodeGetStatisInfo();
|
||||||
|
|
||||||
bool dnodeIsFirstDeploy();
|
bool dnodeIsFirstDeploy();
|
||||||
|
@ -56,8 +49,10 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid);
|
||||||
void *dnodeAllocVWriteQueue(void *pVnode);
|
void *dnodeAllocVWriteQueue(void *pVnode);
|
||||||
void dnodeFreeVWriteQueue(void *pWqueue);
|
void dnodeFreeVWriteQueue(void *pWqueue);
|
||||||
void dnodeSendRpcVWriteRsp(void *pVnode, void *pWrite, int32_t code);
|
void dnodeSendRpcVWriteRsp(void *pVnode, void *pWrite, int32_t code);
|
||||||
void *dnodeAllocVReadQueue(void *pVnode);
|
void *dnodeAllocVQueryQueue(void *pVnode);
|
||||||
void dnodeFreeVReadQueue(void *pRqueue);
|
void *dnodeAllocVFetchQueue(void *pVnode);
|
||||||
|
void dnodeFreeVQueryQueue(void *pQqueue);
|
||||||
|
void dnodeFreeVFetchQueue(void *pFqueue);
|
||||||
|
|
||||||
int32_t dnodeAllocateMPeerQueue();
|
int32_t dnodeAllocateMPeerQueue();
|
||||||
void dnodeFreeMPeerQueue();
|
void dnodeFreeMPeerQueue();
|
||||||
|
|
|
@ -206,9 +206,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "Missing da
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "Out of memory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "Out of memory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "Unexpected generic error in vnode")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "Unexpected generic error in vnode")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VRESION_FILE, 0, 0x050A, "Invalid version file")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VRESION_FILE, 0, 0x050A, "Invalid version file")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FULL, 0, 0x050B, "Vnode memory is full because commit failed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FULL, 0, 0x050B, "Database memory is full for commit failed")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FLOWCTRL, 0, 0x050C, "Database memory is full for waiting commit")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, 0, 0x0511, "Database suspended")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, 0, 0x0511, "Database suspended")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0512, "Write operation denied")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0512, "Database write operation denied")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_SYNCING, 0, 0x0513, "Database is syncing")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_SYNCING, 0, 0x0513, "Database is syncing")
|
||||||
|
|
||||||
// tsdb
|
// tsdb
|
||||||
|
@ -265,6 +266,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "Invalid Sy
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "Sync module not enabled")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "Sync module not enabled")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_VERSION, 0, 0x0902, "Invalid Sync version")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_VERSION, 0, 0x0902, "Invalid Sync version")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_CONFIRM_EXPIRED, 0, 0x0903, "Sync confirm expired")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_CONFIRM_EXPIRED, 0, 0x0903, "Sync confirm expired")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TOO_MANY_FWDINFO, 0, 0x0904, "Too many sync fwd infos")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_MISMATCHED_PROTOCOL, 0, 0x0905, "Mismatched protocol")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_MISMATCHED_CLUSTERID, 0, 0x0906, "Mismatched clusterId")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_MISMATCHED_SIGNATURE, 0, 0x0907, "Mismatched signature")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CHECKSUM, 0, 0x0908, "Invalid msg checksum")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGLEN, 0, 0x0909, "Invalid msg length")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGTYPE, 0, 0x090A, "Invalid msg type")
|
||||||
|
|
||||||
// wal
|
// wal
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal")
|
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal")
|
||||||
|
|
|
@ -266,6 +266,7 @@ typedef struct {
|
||||||
} SMDCreateTableMsg;
|
} SMDCreateTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
int32_t len; // one create table message
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||||
int8_t igExists;
|
int8_t igExists;
|
||||||
|
@ -273,9 +274,13 @@ typedef struct {
|
||||||
int16_t numOfTags;
|
int16_t numOfTags;
|
||||||
int16_t numOfColumns;
|
int16_t numOfColumns;
|
||||||
int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
|
int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
|
||||||
int32_t contLen;
|
|
||||||
int8_t reserved[16];
|
int8_t reserved[16];
|
||||||
char schema[];
|
char schema[];
|
||||||
|
} SCreateTableMsg;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t numOfTables;
|
||||||
|
int32_t contLen;
|
||||||
} SCMCreateTableMsg;
|
} SCMCreateTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -473,7 +478,7 @@ typedef struct {
|
||||||
int16_t numOfGroupCols; // num of group by columns
|
int16_t numOfGroupCols; // num of group by columns
|
||||||
int16_t orderByIdx;
|
int16_t orderByIdx;
|
||||||
int16_t orderType; // used in group by xx order by xxx
|
int16_t orderType; // used in group by xx order by xxx
|
||||||
int64_t tableLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
|
int64_t vgroupLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
|
||||||
int16_t prjOrder; // global order in super table projection query.
|
int16_t prjOrder; // global order in super table projection query.
|
||||||
int64_t limit;
|
int64_t limit;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
|
@ -730,8 +735,8 @@ typedef struct SMultiTableMeta {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dataLen;
|
int32_t dataLen;
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
char data[TSDB_MAX_TAGS_LEN + TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * TSDB_MAX_TAGS];
|
char *data;
|
||||||
} STagData;
|
} STagData;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -787,6 +792,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char sql[TSDB_SHOW_SQL_LEN];
|
char sql[TSDB_SHOW_SQL_LEN];
|
||||||
|
char dstTable[TSDB_TABLE_NAME_LEN];
|
||||||
uint32_t streamId;
|
uint32_t streamId;
|
||||||
int64_t num; // number of computing/cycles
|
int64_t num; // number of computing/cycles
|
||||||
int64_t useconds;
|
int64_t useconds;
|
||||||
|
|
|
@ -42,7 +42,7 @@ void cqStart(void *handle);
|
||||||
void cqStop(void *handle);
|
void cqStop(void *handle);
|
||||||
|
|
||||||
// cqCreate is called by TSDB to start an instance of CQ
|
// cqCreate is called by TSDB to start an instance of CQ
|
||||||
void *cqCreate(void *handle, uint64_t uid, int32_t sid, char *sqlStr, STSchema *pSchema);
|
void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, char *sqlStr, STSchema *pSchema);
|
||||||
|
|
||||||
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
|
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
|
||||||
void cqDrop(void *handle);
|
void cqDrop(void *handle);
|
||||||
|
|
|
@ -48,7 +48,7 @@ typedef struct {
|
||||||
void *cqH;
|
void *cqH;
|
||||||
int (*notifyStatus)(void *, int status, int eno);
|
int (*notifyStatus)(void *, int status, int eno);
|
||||||
int (*eventCallBack)(void *);
|
int (*eventCallBack)(void *);
|
||||||
void *(*cqCreateFunc)(void *handle, uint64_t uid, int sid, char *sqlStr, STSchema *pSchema);
|
void *(*cqCreateFunc)(void *handle, uint64_t uid, int32_t sid, const char* dstTable, char *sqlStr, STSchema *pSchema);
|
||||||
void (*cqDropFunc)(void *handle);
|
void (*cqDropFunc)(void *handle);
|
||||||
} STsdbAppH;
|
} STsdbAppH;
|
||||||
|
|
||||||
|
|
|
@ -119,11 +119,6 @@ int32_t syncGetNodesRole(int64_t rid, SNodesRole *);
|
||||||
extern char *syncRole[];
|
extern char *syncRole[];
|
||||||
|
|
||||||
//global configurable parameters
|
//global configurable parameters
|
||||||
extern int32_t tsMaxSyncNum;
|
|
||||||
extern int32_t tsSyncTcpThreads;
|
|
||||||
extern int32_t tsMaxWatchFiles;
|
|
||||||
extern int32_t tsSyncTimer;
|
|
||||||
extern int32_t tsMaxFwdInfo;
|
|
||||||
extern int32_t sDebugFlag;
|
extern int32_t sDebugFlag;
|
||||||
extern char tsArbitrator[];
|
extern char tsArbitrator[];
|
||||||
extern uint16_t tsSyncPort;
|
extern uint16_t tsSyncPort;
|
||||||
|
|
|
@ -8,25 +8,26 @@ extern "C" {
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
#define GET_TYPED_DATA(_v, _finalType, _type, _data) \
|
#define GET_TYPED_DATA(_v, _finalType, _type, _data) \
|
||||||
switch (_type) { \
|
switch (_type) { \
|
||||||
case TSDB_DATA_TYPE_TINYINT: \
|
case TSDB_DATA_TYPE_BOOL: \
|
||||||
|
case TSDB_DATA_TYPE_TINYINT: \
|
||||||
(_v) = (_finalType)GET_INT8_VAL(_data); \
|
(_v) = (_finalType)GET_INT8_VAL(_data); \
|
||||||
break; \
|
break; \
|
||||||
case TSDB_DATA_TYPE_SMALLINT: \
|
case TSDB_DATA_TYPE_SMALLINT: \
|
||||||
(_v) = (_finalType)GET_INT16_VAL(_data); \
|
(_v) = (_finalType)GET_INT16_VAL(_data); \
|
||||||
break; \
|
break; \
|
||||||
case TSDB_DATA_TYPE_BIGINT: \
|
case TSDB_DATA_TYPE_BIGINT: \
|
||||||
(_v) = (_finalType)(GET_INT64_VAL(_data)); \
|
(_v) = (_finalType)(GET_INT64_VAL(_data)); \
|
||||||
break; \
|
break; \
|
||||||
case TSDB_DATA_TYPE_FLOAT: \
|
case TSDB_DATA_TYPE_FLOAT: \
|
||||||
(_v) = (_finalType)GET_FLOAT_VAL(_data); \
|
(_v) = (_finalType)GET_FLOAT_VAL(_data); \
|
||||||
break; \
|
break; \
|
||||||
case TSDB_DATA_TYPE_DOUBLE: \
|
case TSDB_DATA_TYPE_DOUBLE: \
|
||||||
(_v) = (_finalType)GET_DOUBLE_VAL(_data); \
|
(_v) = (_finalType)GET_DOUBLE_VAL(_data); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
(_v) = (_finalType)GET_INT32_VAL(_data); \
|
(_v) = (_finalType)GET_INT32_VAL(_data); \
|
||||||
break; \
|
break; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -34,6 +34,7 @@ typedef struct {
|
||||||
void * rpcHandle;
|
void * rpcHandle;
|
||||||
void * rpcAhandle;
|
void * rpcAhandle;
|
||||||
void * qhandle;
|
void * qhandle;
|
||||||
|
void * pVnode;
|
||||||
int8_t qtype;
|
int8_t qtype;
|
||||||
int8_t msgType;
|
int8_t msgType;
|
||||||
SRspRet rspRet;
|
SRspRet rspRet;
|
||||||
|
@ -47,7 +48,7 @@ typedef struct {
|
||||||
void * pVnode;
|
void * pVnode;
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
SRspRet rspRet;
|
SRspRet rspRet;
|
||||||
char reserveForSync[16];
|
char reserveForSync[24];
|
||||||
SWalHead pHead[];
|
SWalHead pHead[];
|
||||||
} SVWriteMsg;
|
} SVWriteMsg;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct SShellArguments {
|
||||||
char* timezone;
|
char* timezone;
|
||||||
bool is_raw_time;
|
bool is_raw_time;
|
||||||
bool is_use_passwd;
|
bool is_use_passwd;
|
||||||
|
bool dump_config;
|
||||||
char file[TSDB_FILENAME_LEN];
|
char file[TSDB_FILENAME_LEN];
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
int threadNum;
|
int threadNum;
|
||||||
|
@ -85,6 +86,6 @@ extern void set_terminal_mode();
|
||||||
extern int get_old_terminal_mode(struct termios* tio);
|
extern int get_old_terminal_mode(struct termios* tio);
|
||||||
extern void reset_terminal_mode();
|
extern void reset_terminal_mode();
|
||||||
extern SShellArguments args;
|
extern SShellArguments args;
|
||||||
extern TAOS_RES* result;
|
extern int64_t result;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,7 +46,7 @@ char CONTINUE_PROMPT[] = " -> ";
|
||||||
int prompt_size = 6;
|
int prompt_size = 6;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TAOS_RES *result = NULL;
|
int64_t result = 0;
|
||||||
SShellHistory history;
|
SShellHistory history;
|
||||||
|
|
||||||
#define DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30
|
#define DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30
|
||||||
|
@ -260,6 +260,14 @@ int32_t shellRunCommand(TAOS* con, char* command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void freeResultWithRid(int64_t rid) {
|
||||||
|
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
||||||
|
if(pSql){
|
||||||
|
taos_free_result(pSql);
|
||||||
|
taosReleaseRef(tscObjRef, rid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void shellRunCommandOnServer(TAOS *con, char command[]) {
|
void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
int64_t st, et;
|
int64_t st, et;
|
||||||
wordexp_t full_path;
|
wordexp_t full_path;
|
||||||
|
@ -294,18 +302,22 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
|
|
||||||
st = taosGetTimestampUs();
|
st = taosGetTimestampUs();
|
||||||
|
|
||||||
TAOS_RES* pSql = taos_query_h(con, command, &result);
|
TAOS_RES* tmpSql = NULL;
|
||||||
|
TAOS_RES* pSql = taos_query_h(con, command, &tmpSql);
|
||||||
if (taos_errno(pSql)) {
|
if (taos_errno(pSql)) {
|
||||||
taos_error(pSql, st);
|
taos_error(pSql, st);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic_store_64(&result, ((SSqlObj*)tmpSql)->self);
|
||||||
|
int64_t oresult = atomic_load_64(&result);
|
||||||
|
|
||||||
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
|
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
|
||||||
fprintf(stdout, "Database changed.\n\n");
|
fprintf(stdout, "Database changed.\n\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
atomic_store_ptr(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,8 +325,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
int error_no = 0;
|
int error_no = 0;
|
||||||
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
|
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
|
||||||
if (numOfRows < 0) {
|
if (numOfRows < 0) {
|
||||||
atomic_store_ptr(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,8 +348,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_store_ptr(&result, 0);
|
atomic_store_64(&result, 0);
|
||||||
taos_free_result(pSql);
|
freeResultWithRid(oresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to do regular expression check */
|
/* Function to do regular expression check */
|
||||||
|
@ -501,7 +513,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
|
||||||
row = taos_fetch_row(tres);
|
row = taos_fetch_row(tres);
|
||||||
} while( row != NULL);
|
} while( row != NULL);
|
||||||
|
|
||||||
result = NULL;
|
result = 0;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
|
@ -509,7 +521,9 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
|
||||||
|
|
||||||
|
|
||||||
static void shellPrintNChar(const char *str, int length, int width) {
|
static void shellPrintNChar(const char *str, int length, int width) {
|
||||||
int pos = 0, cols = 0;
|
wchar_t tail[3];
|
||||||
|
int pos = 0, cols = 0, totalCols = 0, tailLen = 0;
|
||||||
|
|
||||||
while (pos < length) {
|
while (pos < length) {
|
||||||
wchar_t wc;
|
wchar_t wc;
|
||||||
int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
||||||
|
@ -526,15 +540,44 @@ static void shellPrintNChar(const char *str, int length, int width) {
|
||||||
#else
|
#else
|
||||||
int w = wcwidth(wc);
|
int w = wcwidth(wc);
|
||||||
#endif
|
#endif
|
||||||
if (w > 0) {
|
if (w <= 0) {
|
||||||
if (width > 0 && cols + w > width) {
|
continue;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
if (width <= 0) {
|
||||||
|
printf("%lc", wc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalCols += w;
|
||||||
|
if (totalCols > width) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (totalCols <= (width - 3)) {
|
||||||
printf("%lc", wc);
|
printf("%lc", wc);
|
||||||
cols += w;
|
cols += w;
|
||||||
|
} else {
|
||||||
|
tail[tailLen] = wc;
|
||||||
|
tailLen++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (totalCols > width) {
|
||||||
|
// width could be 1 or 2, so printf("...") cannot be used
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (cols >= width) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
putchar('.');
|
||||||
|
++cols;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < tailLen; i++) {
|
||||||
|
printf("%lc", tail[i]);
|
||||||
|
}
|
||||||
|
cols = totalCols;
|
||||||
|
}
|
||||||
|
|
||||||
for (; cols < width; cols++) {
|
for (; cols < width; cols++) {
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
|
@ -656,13 +699,21 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
|
||||||
return MAX(25, width);
|
return MAX(25, width);
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
if (field->bytes > tsMaxBinaryDisplayWidth) {
|
if (field->bytes > tsMaxBinaryDisplayWidth) {
|
||||||
return MAX(tsMaxBinaryDisplayWidth, width);
|
return MAX(tsMaxBinaryDisplayWidth, width);
|
||||||
} else {
|
} else {
|
||||||
return MAX(field->bytes, width);
|
return MAX(field->bytes, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_NCHAR: {
|
||||||
|
int16_t bytes = field->bytes * TSDB_NCHAR_SIZE;
|
||||||
|
if (bytes > tsMaxBinaryDisplayWidth) {
|
||||||
|
return MAX(tsMaxBinaryDisplayWidth, width);
|
||||||
|
} else {
|
||||||
|
return MAX(bytes, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
if (args.is_raw_time) {
|
if (args.is_raw_time) {
|
||||||
return MAX(14, width);
|
return MAX(14, width);
|
||||||
|
|
|
@ -33,12 +33,13 @@ const char *argp_program_bug_address = "<support@taosdata.com>";
|
||||||
static char doc[] = "";
|
static char doc[] = "";
|
||||||
static char args_doc[] = "";
|
static char args_doc[] = "";
|
||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"host", 'h', "HOST", 0, "TDengine server IP address to connect. The default host is localhost."},
|
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
|
||||||
{"password", 'p', "PASSWORD", OPTION_ARG_OPTIONAL, "The password to use when connecting to the server."},
|
{"password", 'p', "PASSWORD", OPTION_ARG_OPTIONAL, "The password to use when connecting to the server."},
|
||||||
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
|
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
|
||||||
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
||||||
{"user", 'A', "Auth", 0, "The user auth to use when connecting to the server."},
|
{"user", 'A', "Auth", 0, "The user auth to use when connecting to the server."},
|
||||||
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
||||||
|
{"dump-config", 'C', 0, 0, "Dump configuration."},
|
||||||
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
||||||
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
||||||
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
||||||
|
@ -96,6 +97,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN);
|
tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN);
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
arguments->dump_config = true;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
arguments->commands = arg;
|
arguments->commands = arg;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,18 +15,35 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
#include "tconfig.h"
|
||||||
#include "tnettest.h"
|
#include "tnettest.h"
|
||||||
|
|
||||||
pthread_t pid;
|
pthread_t pid;
|
||||||
|
static tsem_t cancelSem;
|
||||||
|
|
||||||
void shellQueryInterruptHandler(int signum) {
|
void shellQueryInterruptHandler(int signum) {
|
||||||
|
tsem_post(&cancelSem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *cancelHandler(void *arg) {
|
||||||
|
while(1) {
|
||||||
|
if (tsem_wait(&cancelSem) != 0) {
|
||||||
|
taosMsleep(10);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
void* pResHandle = atomic_val_compare_exchange_64(&result, result, 0);
|
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
|
||||||
taos_stop_query(pResHandle);
|
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
|
||||||
|
taos_stop_query(pSql);
|
||||||
|
taosReleaseRef(tscObjRef, rid);
|
||||||
#else
|
#else
|
||||||
printf("\nReceive ctrl+c or other signal, quit shell.\n");
|
printf("\nReceive ctrl+c or other signal, quit shell.\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkVersion() {
|
int checkVersion() {
|
||||||
|
@ -58,6 +75,7 @@ SShellArguments args = {
|
||||||
.timezone = NULL,
|
.timezone = NULL,
|
||||||
.is_raw_time = false,
|
.is_raw_time = false,
|
||||||
.is_use_passwd = false,
|
.is_use_passwd = false,
|
||||||
|
.dump_config = false,
|
||||||
.file = "\0",
|
.file = "\0",
|
||||||
.dir = "\0",
|
.dir = "\0",
|
||||||
.threadNum = 5,
|
.threadNum = 5,
|
||||||
|
@ -78,6 +96,19 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
shellParseArgument(argc, argv, &args);
|
shellParseArgument(argc, argv, &args);
|
||||||
|
|
||||||
|
if (args.dump_config) {
|
||||||
|
taosInitGlobalCfg();
|
||||||
|
taosReadGlobalLogCfg();
|
||||||
|
|
||||||
|
if (!taosReadGlobalCfg()) {
|
||||||
|
printf("TDengine read global config failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosDumpGlobalCfg();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args.netTestRole && args.netTestRole[0] != 0) {
|
if (args.netTestRole && args.netTestRole[0] != 0) {
|
||||||
taos_init();
|
taos_init();
|
||||||
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen);
|
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen);
|
||||||
|
@ -90,6 +121,14 @@ int main(int argc, char* argv[]) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tsem_init(&cancelSem, 0, 0) != 0) {
|
||||||
|
printf("failed to create cancel semphore\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_t spid;
|
||||||
|
pthread_create(&spid, NULL, cancelHandler, NULL);
|
||||||
|
|
||||||
/* Interrupt handler. */
|
/* Interrupt handler. */
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
memset(&act, 0, sizeof(struct sigaction));
|
memset(&act, 0, sizeof(struct sigaction));
|
||||||
|
|
|
@ -24,7 +24,7 @@ void printHelp() {
|
||||||
printf("taos shell is used to test the TDengine database\n");
|
printf("taos shell is used to test the TDengine database\n");
|
||||||
|
|
||||||
printf("%s%s\n", indent, "-h");
|
printf("%s%s\n", indent, "-h");
|
||||||
printf("%s%s%s\n", indent, indent, "TDengine server IP address to connect. The default host is localhost.");
|
printf("%s%s%s\n", indent, indent, "TDengine server FQDN to connect. The default host is localhost.");
|
||||||
printf("%s%s\n", indent, "-p");
|
printf("%s%s\n", indent, "-p");
|
||||||
printf("%s%s%s\n", indent, indent, "The password to use when connecting to the server.");
|
printf("%s%s%s\n", indent, indent, "The password to use when connecting to the server.");
|
||||||
printf("%s%s\n", indent, "-P");
|
printf("%s%s\n", indent, "-P");
|
||||||
|
@ -35,6 +35,8 @@ void printHelp() {
|
||||||
printf("%s%s%s\n", indent, indent, "The user auth to use when connecting to the server.");
|
printf("%s%s%s\n", indent, indent, "The user auth to use when connecting to the server.");
|
||||||
printf("%s%s\n", indent, "-c");
|
printf("%s%s\n", indent, "-c");
|
||||||
printf("%s%s%s\n", indent, indent, "Configuration directory.");
|
printf("%s%s%s\n", indent, indent, "Configuration directory.");
|
||||||
|
printf("%s%s\n", indent, "-C");
|
||||||
|
printf("%s%s%s\n", indent, indent, "Dump configuration.");
|
||||||
printf("%s%s\n", indent, "-s");
|
printf("%s%s\n", indent, "-s");
|
||||||
printf("%s%s%s\n", indent, indent, "Commands to run without enter the shell.");
|
printf("%s%s%s\n", indent, indent, "Commands to run without enter the shell.");
|
||||||
printf("%s%s\n", indent, "-r");
|
printf("%s%s\n", indent, "-r");
|
||||||
|
@ -104,6 +106,8 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
|
||||||
fprintf(stderr, "Option -c requires an argument\n");
|
fprintf(stderr, "Option -c requires an argument\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
|
arguments->dump_config = true;
|
||||||
} else if (strcmp(argv[i], "-s") == 0) {
|
} else if (strcmp(argv[i], "-s") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
arguments->commands = argv[++i];
|
arguments->commands = argv[++i];
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,8 +43,8 @@ void mnodeIncMnodeRef(struct SMnodeObj *pMnode);
|
||||||
void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
|
void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
|
||||||
|
|
||||||
char * mnodeGetMnodeRoleStr();
|
char * mnodeGetMnodeRoleStr();
|
||||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet);
|
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect);
|
||||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet);
|
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect);
|
||||||
char* mnodeGetMnodeMasterEp();
|
char* mnodeGetMnodeMasterEp();
|
||||||
|
|
||||||
void mnodeGetMnodeInfos(void *mnodes);
|
void mnodeGetMnodeInfos(void *mnodes);
|
||||||
|
|
|
@ -59,7 +59,7 @@ typedef struct SSdbRow {
|
||||||
SMnodeMsg *pMsg;
|
SMnodeMsg *pMsg;
|
||||||
int32_t (*fpReq)(SMnodeMsg *pMsg);
|
int32_t (*fpReq)(SMnodeMsg *pMsg);
|
||||||
int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
|
int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
|
||||||
char reserveForSync[16];
|
char reserveForSync[24];
|
||||||
SWalHead pHead[];
|
SWalHead pHead[];
|
||||||
} SSdbRow;
|
} SSdbRow;
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ static int32_t mnodeDnodeActionInsert(SSdbRow *pRow) {
|
||||||
dnodeUpdateEp(pDnode->dnodeId, pDnode->dnodeEp, pDnode->dnodeFqdn, &pDnode->dnodePort);
|
dnodeUpdateEp(pDnode->dnodeId, pDnode->dnodeEp, pDnode->dnodeFqdn, &pDnode->dnodePort);
|
||||||
mnodeUpdateDnodeEps();
|
mnodeUpdateDnodeEps();
|
||||||
|
|
||||||
mInfo("dnode:%d, fqdn:%s ep:%s port:%d, do insert action", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp, pDnode->dnodePort);
|
mInfo("dnode:%d, fqdn:%s ep:%s port:%d is created", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp, pDnode->dnodePort);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ void mnodeUpdateDnode(SDnodeObj *pDnode) {
|
||||||
|
|
||||||
int32_t code = sdbUpdateRow(&row);
|
int32_t code = sdbUpdateRow(&row);
|
||||||
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||||
mError("dnodeId:%d, failed update", pDnode->dnodeId);
|
mError("dnode:%d, failed update", pDnode->dnodeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ int32_t mnodeStartSystem() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dnodeReportStep("mnode-grant", "start to set grant infomation", 0);
|
||||||
grantReset(TSDB_GRANT_ALL, 0);
|
grantReset(TSDB_GRANT_ALL, 0);
|
||||||
tsMgmtIsRunning = true;
|
tsMgmtIsRunning = true;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ static int32_t mnodeMnodeActionInsert(SSdbRow *pRow) {
|
||||||
pDnode->isMgmt = true;
|
pDnode->isMgmt = true;
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
|
||||||
mInfo("mnode:%d, fqdn:%s ep:%s port:%u, do insert action", pMnode->mnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp,
|
mInfo("mnode:%d, fqdn:%s ep:%s port:%u is created", pMnode->mnodeId, pDnode->dnodeFqdn, pDnode->dnodeEp,
|
||||||
pDnode->dnodePort);
|
pDnode->dnodePort);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -202,13 +202,13 @@ void mnodeCancelGetNextMnode(void *pIter) {
|
||||||
void mnodeUpdateMnodeEpSet(SMInfos *pMinfos) {
|
void mnodeUpdateMnodeEpSet(SMInfos *pMinfos) {
|
||||||
bool set = false;
|
bool set = false;
|
||||||
SMInfos mInfos = {0};
|
SMInfos mInfos = {0};
|
||||||
mInfo("vgId:1, update mnodes epSet, numOfMnodes:%d pMinfos:%p", mnodeGetMnodesNum(), pMinfos);
|
|
||||||
|
|
||||||
if (pMinfos != NULL) {
|
if (pMinfos != NULL) {
|
||||||
|
mInfo("vgId:1, update mnodes epSet, numOfMinfos:%d", pMinfos->mnodeNum);
|
||||||
set = true;
|
set = true;
|
||||||
mInfos = *pMinfos;
|
mInfos = *pMinfos;
|
||||||
}
|
} else {
|
||||||
else {
|
mInfo("vgId:1, update mnodes epSet, numOfMnodes:%d", mnodeGetMnodesNum());
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
void * pIter = NULL;
|
void * pIter = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -273,14 +273,14 @@ void mnodeUpdateMnodeEpSet(SMInfos *pMinfos) {
|
||||||
mnodeMnodeUnLock();
|
mnodeMnodeUnLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet) {
|
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect) {
|
||||||
mnodeMnodeRdLock();
|
mnodeMnodeRdLock();
|
||||||
*epSet = tsMEpForPeer;
|
*epSet = tsMEpForPeer;
|
||||||
mnodeMnodeUnLock();
|
mnodeMnodeUnLock();
|
||||||
|
|
||||||
mTrace("vgId:1, mnodes epSet for peer is returned, num:%d inUse:%d", tsMEpForPeer.numOfEps, tsMEpForPeer.inUse);
|
mTrace("vgId:1, mnodes epSet for peer is returned, num:%d inUse:%d", tsMEpForPeer.numOfEps, tsMEpForPeer.inUse);
|
||||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort + TSDB_PORT_DNODEDNODE) {
|
if (redirect && strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort + TSDB_PORT_DNODEDNODE) {
|
||||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||||
mTrace("vgId:1, mnode:%d, for peer ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
mTrace("vgId:1, mnode:%d, for peer ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||||
} else {
|
} else {
|
||||||
|
@ -289,14 +289,19 @@ void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet) {
|
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect) {
|
||||||
mnodeMnodeRdLock();
|
mnodeMnodeRdLock();
|
||||||
*epSet = tsMEpForShell;
|
*epSet = tsMEpForShell;
|
||||||
mnodeMnodeUnLock();
|
mnodeMnodeUnLock();
|
||||||
|
|
||||||
|
if (mnodeGetDnodesNum() <= 1) {
|
||||||
|
epSet->numOfEps = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mTrace("vgId:1, mnodes epSet for shell is returned, num:%d inUse:%d", tsMEpForShell.numOfEps, tsMEpForShell.inUse);
|
mTrace("vgId:1, mnodes epSet for shell is returned, num:%d inUse:%d", tsMEpForShell.numOfEps, tsMEpForShell.inUse);
|
||||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
if (redirect && strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
||||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||||
mTrace("vgId:1, mnode:%d, for shell ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
mTrace("vgId:1, mnode:%d, for shell ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,7 +53,7 @@ int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
|
||||||
if (!sdbIsMaster()) {
|
if (!sdbIsMaster()) {
|
||||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||||
mnodeGetMnodeEpSetForPeer(epSet);
|
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||||
rpcRsp->rsp = epSet;
|
rpcRsp->rsp = epSet;
|
||||||
rpcRsp->len = sizeof(SRpcEpSet);
|
rpcRsp->len = sizeof(SRpcEpSet);
|
||||||
|
|
||||||
|
|
|
@ -282,27 +282,34 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi
|
||||||
|
|
||||||
// not thread safe, need optimized
|
// not thread safe, need optimized
|
||||||
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg) {
|
int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg) {
|
||||||
pConn->numOfQueries = htonl(pHBMsg->numOfQueries);
|
pConn->numOfQueries = 0;
|
||||||
if (pConn->numOfQueries > 0) {
|
pConn->numOfStreams = 0;
|
||||||
|
int32_t numOfQueries = htonl(pHBMsg->numOfQueries);
|
||||||
|
int32_t numOfStreams = htonl(pHBMsg->numOfStreams);
|
||||||
|
|
||||||
|
if (numOfQueries > 0) {
|
||||||
if (pConn->pQueries == NULL) {
|
if (pConn->pQueries == NULL) {
|
||||||
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_STREAM_SAVE_SIZE);
|
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_STREAM_SAVE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t saveSize = MIN(QUERY_STREAM_SAVE_SIZE, pConn->numOfQueries) * sizeof(SQueryDesc);
|
pConn->numOfQueries = MIN(QUERY_STREAM_SAVE_SIZE, numOfQueries);
|
||||||
|
|
||||||
|
int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc);
|
||||||
if (saveSize > 0 && pConn->pQueries != NULL) {
|
if (saveSize > 0 && pConn->pQueries != NULL) {
|
||||||
memcpy(pConn->pQueries, pHBMsg->pData, saveSize);
|
memcpy(pConn->pQueries, pHBMsg->pData, saveSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pConn->numOfStreams = htonl(pHBMsg->numOfStreams);
|
if (numOfStreams > 0) {
|
||||||
if (pConn->numOfStreams > 0) {
|
|
||||||
if (pConn->pStreams == NULL) {
|
if (pConn->pStreams == NULL) {
|
||||||
pConn->pStreams = calloc(sizeof(SStreamDesc), QUERY_STREAM_SAVE_SIZE);
|
pConn->pStreams = calloc(sizeof(SStreamDesc), QUERY_STREAM_SAVE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t saveSize = MIN(QUERY_STREAM_SAVE_SIZE, pConn->numOfStreams) * sizeof(SStreamDesc);
|
pConn->numOfStreams = MIN(QUERY_STREAM_SAVE_SIZE, numOfStreams);
|
||||||
|
|
||||||
|
int32_t saveSize = pConn->numOfStreams * sizeof(SStreamDesc);
|
||||||
if (saveSize > 0 && pConn->pStreams != NULL) {
|
if (saveSize > 0 && pConn->pStreams != NULL) {
|
||||||
memcpy(pConn->pStreams, pHBMsg->pData + pConn->numOfQueries * sizeof(SQueryDesc), saveSize);
|
memcpy(pConn->pStreams, pHBMsg->pData + numOfQueries * sizeof(SQueryDesc), saveSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,6 +457,12 @@ static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "dest table");
|
||||||
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "ip:port");
|
strcpy(pSchema[cols].name, "ip:port");
|
||||||
|
@ -524,6 +537,10 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]);
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->dstTable, pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port);
|
snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port);
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
||||||
|
|
|
@ -50,7 +50,7 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
|
||||||
if (!sdbIsMaster()) {
|
if (!sdbIsMaster()) {
|
||||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||||
mnodeGetMnodeEpSetForShell(epSet);
|
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||||
rpcRsp->rsp = epSet;
|
rpcRsp->rsp = epSet;
|
||||||
rpcRsp->len = sizeof(SRpcEpSet);
|
rpcRsp->len = sizeof(SRpcEpSet);
|
||||||
|
|
||||||
|
|
|
@ -183,18 +183,23 @@ static int32_t sdbInitWal() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbInfo("vgId:1, open wal for restore");
|
sdbInfo("vgId:1, open sdb wal for restore");
|
||||||
int32_t code = walRestore(tsSdbMgmt.wal, NULL, sdbProcessWrite);
|
int32_t code = walRestore(tsSdbMgmt.wal, NULL, sdbProcessWrite);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
sdbError("vgId:1, failed to open wal for restore since %s", tstrerror(code));
|
sdbError("vgId:1, failed to open wal for restore since %s", tstrerror(code));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdbInfo("vgId:1, sdb wal load success");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdbRestoreTables() {
|
static void sdbRestoreTables() {
|
||||||
int32_t totalRows = 0;
|
int32_t totalRows = 0;
|
||||||
int32_t numOfTables = 0;
|
int32_t numOfTables = 0;
|
||||||
|
|
||||||
|
sdbInfo("vgId:1, sdb start to check for integrity");
|
||||||
|
|
||||||
for (int32_t tableId = 0; tableId < SDB_TABLE_MAX; ++tableId) {
|
for (int32_t tableId = 0; tableId < SDB_TABLE_MAX; ++tableId) {
|
||||||
SSdbTable *pTable = sdbGetTableFromId(tableId);
|
SSdbTable *pTable = sdbGetTableFromId(tableId);
|
||||||
if (pTable == NULL) continue;
|
if (pTable == NULL) continue;
|
||||||
|
@ -204,7 +209,7 @@ static void sdbRestoreTables() {
|
||||||
|
|
||||||
totalRows += pTable->numOfRows;
|
totalRows += pTable->numOfRows;
|
||||||
numOfTables++;
|
numOfTables++;
|
||||||
sdbDebug("vgId:1, sdb:%s is restored, rows:%" PRId64, pTable->name, pTable->numOfRows);
|
sdbInfo("vgId:1, sdb:%s is checked, rows:%" PRId64, pTable->name, pTable->numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbMgmt.version, totalRows, numOfTables);
|
sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbMgmt.version, totalRows, numOfTables);
|
||||||
|
@ -628,6 +633,12 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *
|
||||||
SSdbTable *pTable = sdbGetTableFromId(tableId);
|
SSdbTable *pTable = sdbGetTableFromId(tableId);
|
||||||
assert(pTable != NULL);
|
assert(pTable != NULL);
|
||||||
|
|
||||||
|
if (!mnodeIsRunning() && tsSdbMgmt.version % 100000 == 0) {
|
||||||
|
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||||
|
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "%" PRIu64 " rows have been restored", tsSdbMgmt.version);
|
||||||
|
dnodeReportStep("mnode-sdb", stepDesc, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (qtype == TAOS_QTYPE_QUERY) return sdbPerformDeleteAction(pHead, pTable);
|
if (qtype == TAOS_QTYPE_QUERY) return sdbPerformDeleteAction(pHead, pTable);
|
||||||
|
|
||||||
pthread_mutex_lock(&tsSdbMgmt.mutex);
|
pthread_mutex_lock(&tsSdbMgmt.mutex);
|
||||||
|
|
|
@ -282,7 +282,7 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
pRsp->onlineDnodes = htonl(mnodeGetOnlineDnodesNum());
|
pRsp->onlineDnodes = htonl(mnodeGetOnlineDnodesNum());
|
||||||
pRsp->totalDnodes = htonl(mnodeGetDnodesNum());
|
pRsp->totalDnodes = htonl(mnodeGetDnodesNum());
|
||||||
mnodeGetMnodeEpSetForShell(&pRsp->epSet);
|
mnodeGetMnodeEpSetForShell(&pRsp->epSet, false);
|
||||||
|
|
||||||
pMsg->rpcRsp.rsp = pRsp;
|
pMsg->rpcRsp.rsp = pRsp;
|
||||||
pMsg->rpcRsp.len = sizeof(SHeartBeatRsp);
|
pMsg->rpcRsp.len = sizeof(SHeartBeatRsp);
|
||||||
|
@ -349,7 +349,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||||
pConnectRsp->writeAuth = pUser->writeAuth;
|
pConnectRsp->writeAuth = pUser->writeAuth;
|
||||||
pConnectRsp->superAuth = pUser->superAuth;
|
pConnectRsp->superAuth = pUser->superAuth;
|
||||||
|
|
||||||
mnodeGetMnodeEpSetForShell(&pConnectRsp->epSet);
|
mnodeGetMnodeEpSetForShell(&pConnectRsp->epSet, false);
|
||||||
|
|
||||||
connect_over:
|
connect_over:
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
|
@ -49,12 +49,14 @@
|
||||||
#define CREATE_CTABLE_RETRY_TIMES 10
|
#define CREATE_CTABLE_RETRY_TIMES 10
|
||||||
#define CREATE_CTABLE_RETRY_SEC 14
|
#define CREATE_CTABLE_RETRY_SEC 14
|
||||||
|
|
||||||
int64_t tsCTableRid = -1;
|
int64_t tsCTableRid = -1;
|
||||||
static void * tsChildTableSdb;
|
static void * tsChildTableSdb;
|
||||||
int64_t tsSTableRid = -1;
|
int64_t tsSTableRid = -1;
|
||||||
static void * tsSuperTableSdb;
|
static void * tsSuperTableSdb;
|
||||||
static int32_t tsChildTableUpdateSize;
|
static SHashObj *tsSTableUidHash;
|
||||||
static int32_t tsSuperTableUpdateSize;
|
static int32_t tsChildTableUpdateSize;
|
||||||
|
static int32_t tsSuperTableUpdateSize;
|
||||||
|
|
||||||
static void * mnodeGetChildTable(char *tableId);
|
static void * mnodeGetChildTable(char *tableId);
|
||||||
static void * mnodeGetSuperTable(char *tableId);
|
static void * mnodeGetSuperTable(char *tableId);
|
||||||
static void * mnodeGetSuperTableByUid(uint64_t uid);
|
static void * mnodeGetSuperTableByUid(uint64_t uid);
|
||||||
|
@ -289,6 +291,7 @@ static int32_t mnodeChildTableActionDecode(SSdbRow *pRow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeChildTableActionRestored() {
|
static int32_t mnodeChildTableActionRestored() {
|
||||||
|
#if 0
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
SCTableObj *pTable = NULL;
|
SCTableObj *pTable = NULL;
|
||||||
|
|
||||||
|
@ -345,6 +348,7 @@ static int32_t mnodeChildTableActionRestored() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeCancelGetNextChildTable(pIter);
|
mnodeCancelGetNextChildTable(pIter);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,6 +451,7 @@ static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) {
|
||||||
}
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
|
taosHashPut(tsSTableUidHash, &pStable->uid, sizeof(int64_t), &pStable, sizeof(int64_t));
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,6 +464,7 @@ static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) {
|
||||||
}
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
|
taosHashRemove(tsSTableUidHash, &pStable->uid, sizeof(int64_t));
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,6 +576,7 @@ static int32_t mnodeInitSuperTables() {
|
||||||
.fpRestored = mnodeSuperTableActionRestored
|
.fpRestored = mnodeSuperTableActionRestored
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tsSTableUidHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||||
tsSTableRid = sdbOpenTable(&desc);
|
tsSTableRid = sdbOpenTable(&desc);
|
||||||
tsSuperTableSdb = sdbGetTableByRid(tsSTableRid);
|
tsSuperTableSdb = sdbGetTableByRid(tsSTableRid);
|
||||||
if (tsSuperTableSdb == NULL) {
|
if (tsSuperTableSdb == NULL) {
|
||||||
|
@ -584,6 +591,9 @@ static int32_t mnodeInitSuperTables() {
|
||||||
static void mnodeCleanupSuperTables() {
|
static void mnodeCleanupSuperTables() {
|
||||||
sdbCloseTable(tsSTableRid);
|
sdbCloseTable(tsSTableRid);
|
||||||
tsSuperTableSdb = NULL;
|
tsSuperTableSdb = NULL;
|
||||||
|
|
||||||
|
taosHashCleanup(tsSTableUidHash);
|
||||||
|
tsSTableUidHash = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitTables() {
|
int32_t mnodeInitTables() {
|
||||||
|
@ -633,20 +643,12 @@ static void *mnodeGetSuperTable(char *tableId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mnodeGetSuperTableByUid(uint64_t uid) {
|
static void *mnodeGetSuperTableByUid(uint64_t uid) {
|
||||||
SSTableObj *pStable = NULL;
|
SSTableObj **ppStable = taosHashGet(tsSTableUidHash, &uid, sizeof(int64_t));
|
||||||
void *pIter = NULL;
|
if (ppStable == NULL || *ppStable == NULL) return NULL;
|
||||||
|
|
||||||
while (1) {
|
SSTableObj *pStable = *ppStable;
|
||||||
pIter = mnodeGetNextSuperTable(pIter, &pStable);
|
mnodeIncTableRef(pStable);
|
||||||
if (pStable == NULL) break;
|
return pStable;
|
||||||
if (pStable->uid == uid) {
|
|
||||||
mnodeCancelGetNextSuperTable(pIter);
|
|
||||||
return pStable;
|
|
||||||
}
|
|
||||||
mnodeDecTableRef(pStable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mnodeGetTable(char *tableId) {
|
void *mnodeGetTable(char *tableId) {
|
||||||
|
@ -720,10 +722,17 @@ static void mnodeExtractTableName(char* tableId, char* name) {
|
||||||
|
|
||||||
static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db);
|
int32_t numOfTables = htonl(pCreate->numOfTables);
|
||||||
|
int32_t contentLen = htonl(pCreate->contLen);
|
||||||
|
if (numOfTables == 0 || contentLen == 0) {
|
||||||
|
// todo return error
|
||||||
|
}
|
||||||
|
|
||||||
|
SCreateTableMsg *p = (SCreateTableMsg*)((char*) pCreate + sizeof(SCMCreateTableMsg));
|
||||||
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(p->db);
|
||||||
if (pMsg->pDb == NULL) {
|
if (pMsg->pDb == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, failed to create, db not selected", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
mError("msg:%p, app:%p table:%s, failed to create, db not selected", pMsg, pMsg->rpcMsg.ahandle, p->tableId);
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,28 +741,28 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_DB_IN_DROPPING;
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
|
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(p->tableId);
|
||||||
if (pMsg->pTable != NULL && pMsg->retry == 0) {
|
if (pMsg->pTable != NULL && pMsg->retry == 0) {
|
||||||
if (pCreate->getMeta) {
|
if (p->getMeta) {
|
||||||
mDebug("msg:%p, app:%p table:%s, continue to get meta", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
mDebug("msg:%p, app:%p table:%s, continue to get meta", pMsg, pMsg->rpcMsg.ahandle, p->tableId);
|
||||||
return mnodeGetChildTableMeta(pMsg);
|
return mnodeGetChildTableMeta(pMsg);
|
||||||
} else if (pCreate->igExists) {
|
} else if (p->igExists) {
|
||||||
mDebug("msg:%p, app:%p table:%s, is already exist", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
mDebug("msg:%p, app:%p table:%s, is already exist", pMsg, pMsg->rpcMsg.ahandle, p->tableId);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
mError("msg:%p, app:%p table:%s, failed to create, table already exist", pMsg, pMsg->rpcMsg.ahandle,
|
mError("msg:%p, app:%p table:%s, failed to create, table already exist", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pCreate->tableId);
|
p->tableId);
|
||||||
return TSDB_CODE_MND_TABLE_ALREADY_EXIST;
|
return TSDB_CODE_MND_TABLE_ALREADY_EXIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreate->numOfTags != 0) {
|
if (p->numOfTags != 0) {
|
||||||
mDebug("msg:%p, app:%p table:%s, create stable msg is received from thandle:%p", pMsg, pMsg->rpcMsg.ahandle,
|
mDebug("msg:%p, app:%p table:%s, create stable msg is received from thandle:%p", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pCreate->tableId, pMsg->rpcMsg.handle);
|
p->tableId, pMsg->rpcMsg.handle);
|
||||||
return mnodeProcessCreateSuperTableMsg(pMsg);
|
return mnodeProcessCreateSuperTableMsg(pMsg);
|
||||||
} else {
|
} else {
|
||||||
mDebug("msg:%p, app:%p table:%s, create ctable msg is received from thandle:%p", pMsg, pMsg->rpcMsg.ahandle,
|
mDebug("msg:%p, app:%p table:%s, create ctable msg is received from thandle:%p", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pCreate->tableId, pMsg->rpcMsg.handle);
|
p->tableId, pMsg->rpcMsg.handle);
|
||||||
return mnodeProcessCreateChildTableMsg(pMsg);
|
return mnodeProcessCreateChildTableMsg(pMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -859,7 +868,13 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
|
||||||
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
|
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
|
||||||
|
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCMCreateTableMsg *pCreate1 = pMsg->rpcMsg.pCont;
|
||||||
|
if (pCreate1->numOfTables == 0) {
|
||||||
|
// todo return to error message
|
||||||
|
}
|
||||||
|
|
||||||
|
SCreateTableMsg* pCreate = (SCreateTableMsg*)((char*)pCreate1 + sizeof(SCMCreateTableMsg));
|
||||||
|
|
||||||
SSTableObj * pStable = calloc(1, sizeof(SSTableObj));
|
SSTableObj * pStable = calloc(1, sizeof(SSTableObj));
|
||||||
if (pStable == NULL) {
|
if (pStable == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, failed to create, no enough memory", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
mError("msg:%p, app:%p table:%s, failed to create, no enough memory", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||||
|
@ -1599,8 +1614,11 @@ static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg) {
|
||||||
mInfo("drop stable rsp received, result:%s", tstrerror(rpcMsg->code));
|
mInfo("drop stable rsp received, result:%s", tstrerror(rpcMsg->code));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SCTableObj *pTable) {
|
static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pCreateMsg, SCTableObj *pTable) {
|
||||||
STagData * pTagData = NULL;
|
SCreateTableMsg* pMsg = (SCreateTableMsg*) ((char*)pCreateMsg + sizeof(SCMCreateTableMsg));
|
||||||
|
|
||||||
|
char* tagData = NULL;
|
||||||
|
|
||||||
int32_t tagDataLen = 0;
|
int32_t tagDataLen = 0;
|
||||||
int32_t totalCols = 0;
|
int32_t totalCols = 0;
|
||||||
int32_t contLen = 0;
|
int32_t contLen = 0;
|
||||||
|
@ -1608,9 +1626,13 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SCTableObj *
|
||||||
totalCols = pTable->superTable->numOfColumns + pTable->superTable->numOfTags;
|
totalCols = pTable->superTable->numOfColumns + pTable->superTable->numOfTags;
|
||||||
contLen = sizeof(SMDCreateTableMsg) + totalCols * sizeof(SSchema) + pTable->sqlLen;
|
contLen = sizeof(SMDCreateTableMsg) + totalCols * sizeof(SSchema) + pTable->sqlLen;
|
||||||
if (pMsg != NULL) {
|
if (pMsg != NULL) {
|
||||||
pTagData = (STagData *)pMsg->schema;
|
int32_t nameLen = htonl(*(int32_t*)pMsg->schema);
|
||||||
tagDataLen = htonl(pTagData->dataLen);
|
char* p = pMsg->schema + nameLen + sizeof(int32_t);
|
||||||
|
|
||||||
|
tagDataLen = htonl(*(int32_t*) p);
|
||||||
contLen += tagDataLen;
|
contLen += tagDataLen;
|
||||||
|
|
||||||
|
tagData = p + sizeof(int32_t);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
totalCols = pTable->numOfColumns;
|
totalCols = pTable->numOfColumns;
|
||||||
|
@ -1662,7 +1684,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SCTableObj *
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->info.type == TSDB_CHILD_TABLE && pMsg != NULL) {
|
if (pTable->info.type == TSDB_CHILD_TABLE && pMsg != NULL) {
|
||||||
memcpy(pCreate->data + totalCols * sizeof(SSchema), pTagData->data, tagDataLen);
|
memcpy(pCreate->data + totalCols * sizeof(SSchema), tagData, tagDataLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->info.type == TSDB_STREAM_TABLE) {
|
if (pTable->info.type == TSDB_STREAM_TABLE) {
|
||||||
|
@ -1700,7 +1722,8 @@ static int32_t mnodeDoCreateChildTableFp(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
SCTableObj *pTable = (SCTableObj *)pMsg->pTable;
|
SCTableObj *pTable = (SCTableObj *)pMsg->pTable;
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
|
||||||
|
SCreateTableMsg *pCreate = (SCreateTableMsg*) ((char*)pMsg->rpcMsg.pCont + sizeof(SCMCreateTableMsg));
|
||||||
assert(pTable);
|
assert(pTable);
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1728,40 +1751,42 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
|
|
||||||
static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
|
static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
|
||||||
SVgObj *pVgroup = pMsg->pVgroup;
|
SVgObj *pVgroup = pMsg->pVgroup;
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
|
||||||
|
SCMCreateTableMsg *p1 = pMsg->rpcMsg.pCont;
|
||||||
|
SCreateTableMsg *pCreate = (SCreateTableMsg*)((char*)p1 + sizeof(SCMCreateTableMsg));
|
||||||
|
|
||||||
SCTableObj *pTable = calloc(1, sizeof(SCTableObj));
|
SCTableObj *pTable = calloc(1, sizeof(SCTableObj));
|
||||||
if (pTable == NULL) {
|
if (pTable == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, failed to alloc memory", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
mError("msg:%p, app:%p table:%s, failed to alloc memory", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreate->numOfColumns == 0) {
|
pTable->info.type = (pCreate->numOfColumns == 0)? TSDB_CHILD_TABLE:TSDB_NORMAL_TABLE;
|
||||||
pTable->info.type = TSDB_CHILD_TABLE;
|
pTable->info.tableId = strdup(pCreate->tableId);
|
||||||
} else {
|
|
||||||
pTable->info.type = TSDB_NORMAL_TABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
pTable->info.tableId = strdup(pCreate->tableId);
|
|
||||||
pTable->createdTime = taosGetTimestampMs();
|
pTable->createdTime = taosGetTimestampMs();
|
||||||
pTable->tid = tid;
|
pTable->tid = tid;
|
||||||
pTable->vgId = pVgroup->vgId;
|
pTable->vgId = pVgroup->vgId;
|
||||||
|
|
||||||
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
||||||
STagData *pTagData = (STagData *)pCreate->schema; // it is a tag key
|
int32_t nameLen = htonl(*(int32_t*) pCreate->schema);
|
||||||
|
char* name = (char*)pCreate->schema + sizeof(int32_t);
|
||||||
|
|
||||||
|
char stableName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||||
|
memcpy(stableName, name, nameLen);
|
||||||
|
|
||||||
char prefix[64] = {0};
|
char prefix[64] = {0};
|
||||||
size_t prefixLen = tableIdPrefix(pMsg->pDb->name, prefix, 64);
|
size_t prefixLen = tableIdPrefix(pMsg->pDb->name, prefix, 64);
|
||||||
if (0 != strncasecmp(prefix, pTagData->name, prefixLen)) {
|
if (0 != strncasecmp(prefix, stableName, prefixLen)) {
|
||||||
mError("msg:%p, app:%p table:%s, corresponding super table:%s not in this db", pMsg, pMsg->rpcMsg.ahandle,
|
mError("msg:%p, app:%p table:%s, corresponding super table:%s not in this db", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pCreate->tableId, pTagData->name);
|
pCreate->tableId, stableName);
|
||||||
mnodeDestroyChildTable(pTable);
|
mnodeDestroyChildTable(pTable);
|
||||||
return TSDB_CODE_TDB_INVALID_CREATE_TB_MSG;
|
return TSDB_CODE_TDB_INVALID_CREATE_TB_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->pSTable == NULL) pMsg->pSTable = mnodeGetSuperTable(pTagData->name);
|
if (pMsg->pSTable == NULL) pMsg->pSTable = mnodeGetSuperTable(stableName);
|
||||||
if (pMsg->pSTable == NULL) {
|
if (pMsg->pSTable == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, corresponding super table:%s does not exist", pMsg, pMsg->rpcMsg.ahandle,
|
mError("msg:%p, app:%p table:%s, corresponding super table:%s does not exist", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pCreate->tableId, pTagData->name);
|
pCreate->tableId, stableName);
|
||||||
mnodeDestroyChildTable(pTable);
|
mnodeDestroyChildTable(pTable);
|
||||||
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||||
}
|
}
|
||||||
|
@ -1839,7 +1864,9 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
//SCMCreateTableMsg* p1 = pMsg->rpcMsg.pCont; // there are several tables here.
|
||||||
|
SCreateTableMsg* pCreate = (SCreateTableMsg*)(pMsg->rpcMsg.pCont + sizeof(SCMCreateTableMsg));
|
||||||
|
|
||||||
int32_t code = grantCheck(TSDB_GRANT_TIMESERIES);
|
int32_t code = grantCheck(TSDB_GRANT_TIMESERIES);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
mError("msg:%p, app:%p table:%s, failed to create, grant timeseries failed", pMsg, pMsg->rpcMsg.ahandle,
|
mError("msg:%p, app:%p table:%s, failed to create, grant timeseries failed", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
|
@ -2187,15 +2214,23 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
|
||||||
|
|
||||||
static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
||||||
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||||
STagData *pTags = (STagData *)pInfo->tags;
|
|
||||||
int32_t tagLen = htonl(pTags->dataLen);
|
char* p = pInfo->tags;
|
||||||
if (pTags->name[0] == 0) {
|
int32_t nameLen = htonl(*(int32_t*) p);
|
||||||
mError("msg:%p, app:%p table:%s, failed to create table on demand for stable is empty, tagLen:%d", pMsg,
|
p += sizeof(int32_t);
|
||||||
|
p += nameLen;
|
||||||
|
|
||||||
|
int32_t tagLen = htonl(*(int32_t*) p);
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
|
int32_t totalLen = nameLen + tagLen + sizeof(int32_t)*2;
|
||||||
|
if (tagLen == 0 || nameLen == 0) {
|
||||||
|
mError("msg:%p, app:%p table:%s, failed to create table on demand for super table is empty, tagLen:%d", pMsg,
|
||||||
pMsg->rpcMsg.ahandle, pInfo->tableId, tagLen);
|
pMsg->rpcMsg.ahandle, pInfo->tableId, tagLen);
|
||||||
return TSDB_CODE_MND_INVALID_STABLE_NAME;
|
return TSDB_CODE_MND_INVALID_STABLE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t contLen = sizeof(SCMCreateTableMsg) + offsetof(STagData, data) + tagLen;
|
int32_t contLen = sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg) + totalLen;
|
||||||
SCMCreateTableMsg *pCreateMsg = calloc(1, contLen);
|
SCMCreateTableMsg *pCreateMsg = calloc(1, contLen);
|
||||||
if (pCreateMsg == NULL) {
|
if (pCreateMsg == NULL) {
|
||||||
mError("msg:%p, app:%p table:%s, failed to create table while get meta info, no enough memory", pMsg,
|
mError("msg:%p, app:%p table:%s, failed to create table while get meta info, no enough memory", pMsg,
|
||||||
|
@ -2203,16 +2238,24 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = sizeof(pInfo->tableId);
|
SCreateTableMsg* pCreate = (SCreateTableMsg*) ((char*) pCreateMsg + sizeof(SCMCreateTableMsg));
|
||||||
tstrncpy(pCreateMsg->tableId, pInfo->tableId, size);
|
|
||||||
tstrncpy(pCreateMsg->db, pMsg->pDb->name, sizeof(pCreateMsg->db));
|
size_t size = tListLen(pInfo->tableId);
|
||||||
pCreateMsg->igExists = 1;
|
tstrncpy(pCreate->tableId, pInfo->tableId, size);
|
||||||
pCreateMsg->getMeta = 1;
|
tstrncpy(pCreate->db, pMsg->pDb->name, sizeof(pCreate->db));
|
||||||
|
pCreate->igExists = 1;
|
||||||
|
pCreate->getMeta = 1;
|
||||||
|
|
||||||
|
pCreateMsg->numOfTables = htonl(1);
|
||||||
pCreateMsg->contLen = htonl(contLen);
|
pCreateMsg->contLen = htonl(contLen);
|
||||||
|
|
||||||
memcpy(pCreateMsg->schema, pTags, contLen - sizeof(SCMCreateTableMsg));
|
memcpy(pCreate->schema, pInfo->tags, totalLen);
|
||||||
|
|
||||||
|
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||||
|
memcpy(name, pInfo->tags + sizeof(int32_t), nameLen);
|
||||||
|
|
||||||
mDebug("msg:%p, app:%p table:%s, start to create on demand, tagLen:%d stable:%s", pMsg, pMsg->rpcMsg.ahandle,
|
mDebug("msg:%p, app:%p table:%s, start to create on demand, tagLen:%d stable:%s", pMsg, pMsg->rpcMsg.ahandle,
|
||||||
pInfo->tableId, tagLen, pTags->name);
|
pInfo->tableId, tagLen, name);
|
||||||
|
|
||||||
if (pMsg->rpcMsg.pCont != pMsg->pCont) {
|
if (pMsg->rpcMsg.pCont != pMsg->pCont) {
|
||||||
tfree(pMsg->rpcMsg.pCont);
|
tfree(pMsg->rpcMsg.pCont);
|
||||||
|
|
|
@ -315,7 +315,8 @@ void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVl
|
||||||
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||||
if (pVgid->pDnode == pDnode) {
|
if (pVgid->pDnode == pDnode) {
|
||||||
mTrace("dnode:%d, receive status from dnode, vgId:%d status is %d:%s", pDnode->dnodeId, pVgroup->vgId, pVgid->role, syncRole[pVgid->role]);
|
mTrace("dnode:%d, receive status from dnode, vgId:%d status:%s last:%s", pDnode->dnodeId, pVgroup->vgId,
|
||||||
|
syncRole[pVload->role], syncRole[pVgid->role]);
|
||||||
pVgid->role = pVload->role;
|
pVgid->role = pVload->role;
|
||||||
if (pVload->role == TAOS_SYNC_ROLE_MASTER) {
|
if (pVload->role == TAOS_SYNC_ROLE_MASTER) {
|
||||||
pVgroup->inUse = i;
|
pVgroup->inUse = i;
|
||||||
|
|
|
@ -50,7 +50,7 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
|
||||||
if (!sdbIsMaster()) {
|
if (!sdbIsMaster()) {
|
||||||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||||
mnodeGetMnodeEpSetForShell(epSet);
|
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||||
rpcRsp->rsp = epSet;
|
rpcRsp->rsp = epSet;
|
||||||
rpcRsp->len = sizeof(SRpcEpSet);
|
rpcRsp->len = sizeof(SRpcEpSet);
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ void taosTMemset(void *ptr, int c);
|
||||||
free((void *)(x)); \
|
free((void *)(x)); \
|
||||||
x = 0; \
|
x = 0; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#ifdef TAOS_MEM_CHECK
|
#ifdef TAOS_MEM_CHECK
|
||||||
#ifdef TAOS_MEM_CHECK_TEST
|
#ifdef TAOS_MEM_CHECK_TEST
|
||||||
|
|
|
@ -39,7 +39,7 @@ extern "C" {
|
||||||
do { \
|
do { \
|
||||||
strncpy((dst), (src), (size)); \
|
strncpy((dst), (src), (size)); \
|
||||||
(dst)[(size)-1] = 0; \
|
(dst)[(size)-1] = 0; \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
|
#ifndef TAOS_OS_FUNC_STRING_STR2INT64
|
||||||
int64_t tsosStr2int64(char *str);
|
int64_t tsosStr2int64(char *str);
|
||||||
|
|
|
@ -140,6 +140,11 @@ typedef struct SQueryCostInfo {
|
||||||
uint64_t numOfTimeWindows;
|
uint64_t numOfTimeWindows;
|
||||||
} SQueryCostInfo;
|
} SQueryCostInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t vgroupLimit;
|
||||||
|
int64_t ts;
|
||||||
|
} SOrderedPrjQueryInfo;
|
||||||
|
|
||||||
typedef struct SQuery {
|
typedef struct SQuery {
|
||||||
int16_t numOfCols;
|
int16_t numOfCols;
|
||||||
int16_t numOfTags;
|
int16_t numOfTags;
|
||||||
|
@ -167,6 +172,7 @@ typedef struct SQuery {
|
||||||
tFilePage** sdata;
|
tFilePage** sdata;
|
||||||
STableQueryInfo* current;
|
STableQueryInfo* current;
|
||||||
|
|
||||||
|
SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query.
|
||||||
SSingleColumnFilterInfo* pFilterInfo;
|
SSingleColumnFilterInfo* pFilterInfo;
|
||||||
} SQuery;
|
} SQuery;
|
||||||
|
|
||||||
|
@ -179,13 +185,13 @@ typedef struct SQueryRuntimeEnv {
|
||||||
uint16_t scanFlag; // denotes reversed scan of data or not
|
uint16_t scanFlag; // denotes reversed scan of data or not
|
||||||
SFillInfo* pFillInfo;
|
SFillInfo* pFillInfo;
|
||||||
SResultRowInfo windowResInfo;
|
SResultRowInfo windowResInfo;
|
||||||
STSBuf* pTSBuf;
|
STSBuf* pTsBuf;
|
||||||
STSCursor cur;
|
STSCursor cur;
|
||||||
SQueryCostInfo summary;
|
SQueryCostInfo summary;
|
||||||
void* pQueryHandle;
|
void* pQueryHandle;
|
||||||
void* pSecQueryHandle; // another thread for
|
void* pSecQueryHandle; // another thread for
|
||||||
bool stableQuery; // super table query or not
|
bool stableQuery; // super table query or not
|
||||||
bool topBotQuery; // false
|
bool topBotQuery; // TODO used bitwise flag
|
||||||
bool groupbyNormalCol; // denote if this is a groupby normal column query
|
bool groupbyNormalCol; // denote if this is a groupby normal column query
|
||||||
bool hasTagResults; // if there are tag values in final result or not
|
bool hasTagResults; // if there are tag values in final result or not
|
||||||
bool timeWindowInterpo;// if the time window start/end required interpolation
|
bool timeWindowInterpo;// if the time window start/end required interpolation
|
||||||
|
@ -210,14 +216,13 @@ enum {
|
||||||
typedef struct SQInfo {
|
typedef struct SQInfo {
|
||||||
void* signature;
|
void* signature;
|
||||||
int32_t code; // error code to returned to client
|
int32_t code; // error code to returned to client
|
||||||
int64_t owner; // if it is in execution
|
int64_t owner; // if it is in execution
|
||||||
void* tsdb;
|
void* tsdb;
|
||||||
SMemRef memRef;
|
SMemRef memRef;
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
||||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||||
SQueryRuntimeEnv runtimeEnv;
|
SQueryRuntimeEnv runtimeEnv;
|
||||||
// SArray* arrTableIdInfo;
|
|
||||||
SHashObj* arrTableIdInfo;
|
SHashObj* arrTableIdInfo;
|
||||||
int32_t groupIndex;
|
int32_t groupIndex;
|
||||||
|
|
||||||
|
@ -233,6 +238,7 @@ typedef struct SQInfo {
|
||||||
tsem_t ready;
|
tsem_t ready;
|
||||||
int32_t dataReady; // denote if query result is ready or not
|
int32_t dataReady; // denote if query result is ready or not
|
||||||
void* rspContext; // response context
|
void* rspContext; // response context
|
||||||
|
int64_t startExecTs; // start to exec timestamp
|
||||||
} SQInfo;
|
} SQInfo;
|
||||||
|
|
||||||
#endif // TDENGINE_QUERYEXECUTOR_H
|
#endif // TDENGINE_QUERYEXECUTOR_H
|
||||||
|
|
|
@ -73,23 +73,27 @@ typedef struct SQuerySQL {
|
||||||
SStrToken selectToken; // sql string
|
SStrToken selectToken; // sql string
|
||||||
} SQuerySQL;
|
} SQuerySQL;
|
||||||
|
|
||||||
|
typedef struct SCreatedTableInfo {
|
||||||
|
SStrToken name; // table name token
|
||||||
|
SStrToken stableName; // super table name token , for using clause
|
||||||
|
SArray *pTagVals; // create by using super table, tag value
|
||||||
|
char *fullname; // table full name
|
||||||
|
STagData tagdata; // true tag data, super table full name is in STagData
|
||||||
|
int8_t igExist; // ignore if exists
|
||||||
|
} SCreatedTableInfo;
|
||||||
|
|
||||||
typedef struct SCreateTableSQL {
|
typedef struct SCreateTableSQL {
|
||||||
struct SStrToken name; // meter name, create table [meterName] xxx
|
SStrToken name; // table name, create table [name] xxx
|
||||||
bool existCheck;
|
int8_t type; // create normal table/from super table/ stream
|
||||||
|
bool existCheck;
|
||||||
int8_t type; // create normal table/from super table/ stream
|
|
||||||
struct {
|
struct {
|
||||||
SArray *pTagColumns; // SArray<TAOS_FIELD>
|
SArray *pTagColumns; // SArray<TAOS_FIELD>
|
||||||
SArray *pColumns; // SArray<TAOS_FIELD>
|
SArray *pColumns; // SArray<TAOS_FIELD>
|
||||||
} colInfo;
|
} colInfo;
|
||||||
|
|
||||||
struct {
|
SArray *childTableInfo; // SArray<SCreatedTableInfo>
|
||||||
SStrToken stableName; // super table name, for using clause
|
SQuerySQL *pSelect;
|
||||||
SArray *pTagVals; // create by using metric, tag value
|
|
||||||
STagData tagdata;
|
|
||||||
} usingInfo;
|
|
||||||
|
|
||||||
SQuerySQL *pSelect;
|
|
||||||
} SCreateTableSQL;
|
} SCreateTableSQL;
|
||||||
|
|
||||||
typedef struct SAlterTableSQL {
|
typedef struct SAlterTableSQL {
|
||||||
|
@ -198,16 +202,16 @@ typedef struct tSQLExpr {
|
||||||
} tSQLExpr;
|
} tSQLExpr;
|
||||||
|
|
||||||
// used in select clause. select <tSQLExprList> from xxx
|
// used in select clause. select <tSQLExprList> from xxx
|
||||||
typedef struct tSQLExprItem {
|
typedef struct tSqlExprItem {
|
||||||
tSQLExpr *pNode; // The list of expressions
|
tSQLExpr *pNode; // The list of expressions
|
||||||
char * aliasName; // alias name, null-terminated string
|
char * aliasName; // alias name, null-terminated string
|
||||||
} tSQLExprItem;
|
} tSqlExprItem;
|
||||||
|
|
||||||
// todo refactor by using SArray
|
// todo refactor by using SArray
|
||||||
typedef struct tSQLExprList {
|
typedef struct tSQLExprList {
|
||||||
int32_t nExpr; /* Number of expressions on the list */
|
int32_t nExpr; /* Number of expressions on the list */
|
||||||
int32_t nAlloc; /* Number of entries allocated below */
|
int32_t nAlloc; /* Number of entries allocated below */
|
||||||
tSQLExprItem *a; /* One entry for each expression */
|
tSqlExprItem *a; /* One entry for each expression */
|
||||||
} tSQLExprList;
|
} tSQLExprList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,62 +233,63 @@ SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
|
||||||
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
|
||||||
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
|
||||||
|
|
||||||
tSQLExpr *tSQLExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optType);
|
tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType);
|
||||||
|
|
||||||
void tSQLExprDestroy(tSQLExpr *);
|
void tSqlExprDestroy(tSQLExpr *pExpr);
|
||||||
|
|
||||||
tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pToken);
|
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pToken);
|
||||||
|
|
||||||
void tSQLExprListDestroy(tSQLExprList *pList);
|
void tSqlExprListDestroy(tSQLExprList *pList);
|
||||||
|
|
||||||
SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
SQuerySQL *tSetQuerySqlElems(SStrToken *pSelectToken, tSQLExprList *pSelection, SArray *pFrom, tSQLExpr *pWhere,
|
||||||
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
|
||||||
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
||||||
|
|
||||||
SCreateTableSQL *tSetCreateSQLElems(SArray *pCols, SArray *pTags, SStrToken *pMetricName,
|
SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSelect, int32_t type);
|
||||||
SArray *pTagVals, SQuerySQL *pSelect, int32_t type);
|
|
||||||
|
|
||||||
void tSQLExprNodeDestroy(tSQLExpr *pExpr);
|
void tSqlExprNodeDestroy(tSQLExpr *pExpr);
|
||||||
|
|
||||||
SAlterTableSQL *tAlterTableSQLElems(SStrToken *pMeterName, SArray *pCols, SArray *pVals, int32_t type);
|
SAlterTableSQL * tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type);
|
||||||
|
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
|
||||||
|
|
||||||
void destroyAllSelectClause(SSubclauseInfo *pSql);
|
void destroyAllSelectClause(SSubclauseInfo *pSql);
|
||||||
void doDestroyQuerySql(SQuerySQL *pSql);
|
void doDestroyQuerySql(SQuerySQL *pSql);
|
||||||
|
void freeCreateTableInfo(void* p);
|
||||||
|
|
||||||
SSqlInfo * setSQLInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pMeterName, int32_t type);
|
SSqlInfo * setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SStrToken *pTableName, int32_t type);
|
||||||
SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo);
|
SSubclauseInfo *setSubclause(SSubclauseInfo *pClause, void *pSqlExprInfo);
|
||||||
|
|
||||||
SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause);
|
SSubclauseInfo *appendSelectClause(SSubclauseInfo *pInfo, void *pSubclause);
|
||||||
|
|
||||||
void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pMeterName, SStrToken *pIfNotExists);
|
void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken *pIfNotExists);
|
||||||
|
|
||||||
void SQLInfoDestroy(SSqlInfo *pInfo);
|
void SqlInfoDestroy(SSqlInfo *pInfo);
|
||||||
|
|
||||||
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
|
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
|
||||||
void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck);
|
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck);
|
||||||
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
|
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
|
||||||
|
|
||||||
tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SStrToken *pToken);
|
tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SStrToken *pToken);
|
||||||
|
|
||||||
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDBInfo *pDB, SStrToken *pIgExists);
|
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SStrToken *pToken, SCreateDBInfo *pDB, SStrToken *pIgExists);
|
||||||
|
|
||||||
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctSQL *pAcctInfo);
|
void setCreateAcctSql(SSqlInfo *pInfo, int32_t type, SStrToken *pName, SStrToken *pPwd, SCreateAcctSQL *pAcctInfo);
|
||||||
void setCreateUserSQL(SSqlInfo *pInfo, SStrToken *pName, SStrToken *pPasswd);
|
void setCreateUserSql(SSqlInfo *pInfo, SStrToken *pName, SStrToken *pPasswd);
|
||||||
void setKillSQL(SSqlInfo *pInfo, int32_t type, SStrToken *ip);
|
void setKillSql(SSqlInfo *pInfo, int32_t type, SStrToken *ip);
|
||||||
void setAlterUserSQL(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken* pPwd, SStrToken *pPrivilege);
|
void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken* pPwd, SStrToken *pPrivilege);
|
||||||
|
|
||||||
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo);
|
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo);
|
||||||
|
|
||||||
// prefix show db.tables;
|
// prefix show db.tables;
|
||||||
void setDBName(SStrToken *pCpxName, SStrToken *pDB);
|
void setDbName(SStrToken *pCpxName, SStrToken *pDb);
|
||||||
|
|
||||||
tSQLExpr *tSQLExprIdValueCreate(SStrToken *pToken, int32_t optType);
|
tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType);
|
||||||
|
|
||||||
tSQLExpr *tSQLExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
|
tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
|
||||||
|
|
||||||
void tSQLSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
|
void tSqlSetColumnInfo(TAOS_FIELD *pField, SStrToken *pName, TAOS_FIELD *pType);
|
||||||
|
|
||||||
void tSQLSetColumnType(TAOS_FIELD *pField, SStrToken *pToken);
|
void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type);
|
||||||
|
|
||||||
void *ParseAlloc(void *(*mallocProc)(size_t));
|
void *ParseAlloc(void *(*mallocProc)(size_t));
|
||||||
|
|
||||||
|
|
|
@ -24,35 +24,34 @@
|
||||||
|
|
||||||
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
|
#define GET_RES_WINDOW_KEY_LEN(_l) ((_l) + sizeof(uint64_t))
|
||||||
|
|
||||||
int32_t getOutputInterResultBufSize(SQuery* pQuery);
|
|
||||||
|
|
||||||
void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pRow, int16_t type);
|
|
||||||
void copyResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* dst, const SResultRow* src, int16_t type);
|
|
||||||
SResultRowCellInfo* getResultCell(SQueryRuntimeEnv* pRuntimeEnv, const SResultRow* pRow, int32_t index);
|
|
||||||
|
|
||||||
int32_t initWindowResInfo(SResultRowInfo* pWindowResInfo, int32_t size, int16_t type);
|
|
||||||
|
|
||||||
void cleanupTimeWindowInfo(SResultRowInfo* pWindowResInfo);
|
|
||||||
void resetTimeWindowInfo(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pWindowResInfo);
|
|
||||||
void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num);
|
|
||||||
|
|
||||||
void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv);
|
|
||||||
int32_t numOfClosedTimeWindow(SResultRowInfo* pWindowResInfo);
|
|
||||||
void closeTimeWindow(SResultRowInfo* pWindowResInfo, int32_t slot);
|
|
||||||
void closeAllTimeWindow(SResultRowInfo* pWindowResInfo);
|
|
||||||
void removeRedundantWindow(SResultRowInfo *pWindowResInfo, TSKEY lastKey, int32_t order);
|
|
||||||
|
|
||||||
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pWindowResInfo, int32_t slot) {
|
|
||||||
assert(pWindowResInfo != NULL && slot >= 0 && slot < pWindowResInfo->size);
|
|
||||||
return pWindowResInfo->pResult[slot];
|
|
||||||
}
|
|
||||||
|
|
||||||
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
||||||
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
|
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
|
||||||
|
|
||||||
bool isWindowResClosed(SResultRowInfo *pWindowResInfo, int32_t slot);
|
int32_t getOutputInterResultBufSize(SQuery* pQuery);
|
||||||
|
|
||||||
|
size_t getResultRowSize(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
int32_t initResultRowInfo(SResultRowInfo* pResultRowInfo, int32_t size, int16_t type);
|
||||||
|
void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo);
|
||||||
|
|
||||||
|
void resetResultRowInfo(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo);
|
||||||
|
void popFrontResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, int32_t num);
|
||||||
|
void clearClosedResultRows(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo *pResultRowInfo);
|
||||||
|
int32_t numOfClosedResultRows(SResultRowInfo* pResultRowInfo);
|
||||||
|
void closeAllResultRows(SResultRowInfo* pResultRowInfo);
|
||||||
|
void removeRedundantResultRows(SResultRowInfo *pResultRowInfo, TSKEY lastKey, int32_t order);
|
||||||
|
|
||||||
int32_t initResultRow(SResultRow *pResultRow);
|
int32_t initResultRow(SResultRow *pResultRow);
|
||||||
|
void closeResultRow(SResultRowInfo* pResultRowInfo, int32_t slot);
|
||||||
|
bool isResultRowClosed(SResultRowInfo *pResultRowInfo, int32_t slot);
|
||||||
|
void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pResultRow, int16_t type);
|
||||||
|
void copyResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* dst, const SResultRow* src, int16_t type);
|
||||||
|
|
||||||
|
SResultRowCellInfo* getResultCell(SQueryRuntimeEnv* pRuntimeEnv, const SResultRow* pRow, int32_t index);
|
||||||
|
|
||||||
|
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {
|
||||||
|
assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size);
|
||||||
|
return pResultRowInfo->pResult[slot];
|
||||||
|
}
|
||||||
|
|
||||||
static FORCE_INLINE char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SResultRow *pResult,
|
static FORCE_INLINE char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SResultRow *pResult,
|
||||||
tFilePage* page) {
|
tFilePage* page) {
|
||||||
|
@ -71,8 +70,6 @@ bool notNull_filter(SColumnFilterElem *pFilter, char* minval, char* maxval);
|
||||||
__filter_func_t *getRangeFilterFuncArray(int32_t type);
|
__filter_func_t *getRangeFilterFuncArray(int32_t type);
|
||||||
__filter_func_t *getValueFilterFuncArray(int32_t type);
|
__filter_func_t *getValueFilterFuncArray(int32_t type);
|
||||||
|
|
||||||
size_t getWindowResultSize(SQueryRuntimeEnv* pRuntimeEnv);
|
|
||||||
|
|
||||||
SResultRowPool* initResultRowPool(size_t size);
|
SResultRowPool* initResultRowPool(size_t size);
|
||||||
SResultRow* getNewResultRow(SResultRowPool* p);
|
SResultRow* getNewResultRow(SResultRowPool* p);
|
||||||
int64_t getResultRowPoolMemSize(SResultRowPool* p);
|
int64_t getResultRowPoolMemSize(SResultRowPool* p);
|
||||||
|
|
|
@ -22,15 +22,15 @@ extern "C" {
|
||||||
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
extern int32_t qDebugFlag;
|
extern uint32_t qDebugFlag;
|
||||||
extern int32_t tscEmbedded;
|
extern uint32_t tscEmbedded;
|
||||||
|
|
||||||
#define qFatal(...) { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", 255, __VA_ARGS__); }}
|
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", 255, __VA_ARGS__); }} while(0)
|
||||||
#define qError(...) { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", 255, __VA_ARGS__); }}
|
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", 255, __VA_ARGS__); }} while(0)
|
||||||
#define qWarn(...) { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }}
|
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }} while(0)
|
||||||
#define qInfo(...) { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", 255, __VA_ARGS__); }}
|
#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", 255, __VA_ARGS__); }} while(0)
|
||||||
#define qDebug(...) { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }}
|
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qTrace(...) { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }}
|
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,12 +168,12 @@ ids(A) ::= ID(X). {A = X; }
|
||||||
ids(A) ::= STRING(X). {A = X; }
|
ids(A) ::= STRING(X). {A = X; }
|
||||||
|
|
||||||
%type ifexists {SStrToken}
|
%type ifexists {SStrToken}
|
||||||
ifexists(X) ::= IF EXISTS. {X.n = 1;}
|
ifexists(X) ::= IF EXISTS. { X.n = 1;}
|
||||||
ifexists(X) ::= . {X.n = 0;}
|
ifexists(X) ::= . { X.n = 0;}
|
||||||
|
|
||||||
%type ifnotexists {SStrToken}
|
%type ifnotexists {SStrToken}
|
||||||
ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;}
|
ifnotexists(X) ::= IF NOT EXISTS. { X.n = 1;}
|
||||||
ifnotexists(X) ::= . {X.n = 0;}
|
ifnotexists(X) ::= . { X.n = 0;}
|
||||||
|
|
||||||
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
|
||||||
//create option for dnode/db/user/account
|
//create option for dnode/db/user/account
|
||||||
|
@ -183,32 +183,32 @@ cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
|
||||||
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
|
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
|
||||||
cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSQL(pInfo, &X, &Y);}
|
cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSQL(pInfo, &X, &Y);}
|
||||||
|
|
||||||
pps(Y) ::= . {Y.n = 0; }
|
pps(Y) ::= . { Y.n = 0; }
|
||||||
pps(Y) ::= PPS INTEGER(X). {Y = X; }
|
pps(Y) ::= PPS INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
tseries(Y) ::= . {Y.n = 0; }
|
tseries(Y) ::= . { Y.n = 0; }
|
||||||
tseries(Y) ::= TSERIES INTEGER(X). {Y = X; }
|
tseries(Y) ::= TSERIES INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
dbs(Y) ::= . {Y.n = 0; }
|
dbs(Y) ::= . { Y.n = 0; }
|
||||||
dbs(Y) ::= DBS INTEGER(X). {Y = X; }
|
dbs(Y) ::= DBS INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
streams(Y) ::= . {Y.n = 0; }
|
streams(Y) ::= . { Y.n = 0; }
|
||||||
streams(Y) ::= STREAMS INTEGER(X). {Y = X; }
|
streams(Y) ::= STREAMS INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
storage(Y) ::= . {Y.n = 0; }
|
storage(Y) ::= . { Y.n = 0; }
|
||||||
storage(Y) ::= STORAGE INTEGER(X). {Y = X; }
|
storage(Y) ::= STORAGE INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
qtime(Y) ::= . {Y.n = 0; }
|
qtime(Y) ::= . { Y.n = 0; }
|
||||||
qtime(Y) ::= QTIME INTEGER(X). {Y = X; }
|
qtime(Y) ::= QTIME INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
users(Y) ::= . {Y.n = 0; }
|
users(Y) ::= . { Y.n = 0; }
|
||||||
users(Y) ::= USERS INTEGER(X). {Y = X; }
|
users(Y) ::= USERS INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
conns(Y) ::= . {Y.n = 0; }
|
conns(Y) ::= . { Y.n = 0; }
|
||||||
conns(Y) ::= CONNS INTEGER(X). {Y = X; }
|
conns(Y) ::= CONNS INTEGER(X). { Y = X; }
|
||||||
|
|
||||||
state(Y) ::= . {Y.n = 0; }
|
state(Y) ::= . { Y.n = 0; }
|
||||||
state(Y) ::= STATE ids(X). {Y = X; }
|
state(Y) ::= STATE ids(X). { Y = X; }
|
||||||
|
|
||||||
%type acct_optr {SCreateAcctSQL}
|
%type acct_optr {SCreateAcctSQL}
|
||||||
acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). {
|
acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). {
|
||||||
|
@ -269,7 +269,7 @@ alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = s
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
|
||||||
|
|
||||||
%type typename {TAOS_FIELD}
|
%type typename {TAOS_FIELD}
|
||||||
typename(A) ::= ids(X). {
|
typename(A) ::= ids(X). {
|
||||||
|
@ -279,13 +279,13 @@ typename(A) ::= ids(X). {
|
||||||
|
|
||||||
//define binary type, e.g., binary(10), nchar(10)
|
//define binary type, e.g., binary(10), nchar(10)
|
||||||
typename(A) ::= ids(X) LP signed(Y) RP. {
|
typename(A) ::= ids(X) LP signed(Y) RP. {
|
||||||
if (Y <= 0) {
|
if (Y <= 0) {
|
||||||
X.type = 0;
|
X.type = 0;
|
||||||
tSQLSetColumnType(&A, &X);
|
tSQLSetColumnType(&A, &X);
|
||||||
} else {
|
} else {
|
||||||
X.type = -Y; // negative value of name length
|
X.type = -Y; // negative value of name length
|
||||||
tSQLSetColumnType(&A, &X);
|
tSQLSetColumnType(&A, &X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%type signed {int64_t}
|
%type signed {int64_t}
|
||||||
|
@ -294,36 +294,60 @@ signed(A) ::= PLUS INTEGER(X). { A = strtol(X.z, NULL, 10); }
|
||||||
signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);}
|
signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);}
|
||||||
|
|
||||||
////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
|
////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
|
||||||
cmd ::= CREATE TABLE ifnotexists(Y) ids(X) cpxName(Z) create_table_args. {
|
cmd ::= CREATE TABLE create_table_args. {}
|
||||||
X.n += Z.n;
|
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
|
||||||
setCreatedTableName(pInfo, &X, &Y);
|
|
||||||
|
%type create_table_list{SCreateTableSQL*}
|
||||||
|
%destructor create_table_list{destroyCreateTableSql($$);}
|
||||||
|
create_table_list(A) ::= create_from_stable(Z). {
|
||||||
|
SCreateTableSQL* pCreateTable = calloc(1, sizeof(SCreateTableSQL));
|
||||||
|
pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));
|
||||||
|
|
||||||
|
taosArrayPush(pCreateTable->childTableInfo, &Z);
|
||||||
|
pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE;
|
||||||
|
A = pCreateTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
|
||||||
|
taosArrayPush(X->childTableInfo, &Z);
|
||||||
|
A = X;
|
||||||
}
|
}
|
||||||
|
|
||||||
%type create_table_args{SCreateTableSQL*}
|
%type create_table_args{SCreateTableSQL*}
|
||||||
create_table_args(A) ::= LP columnlist(X) RP. {
|
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
|
||||||
A = tSetCreateSQLElems(X, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE);
|
A = tSetCreateSQLElems(X, NULL, NULL, TSQL_CREATE_TABLE);
|
||||||
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
|
V.n += Z.n;
|
||||||
|
setCreatedTableName(pInfo, &V, &U);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create super table
|
// create super table
|
||||||
create_table_args(A) ::= LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
|
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
|
||||||
A = tSetCreateSQLElems(X, Y, NULL, NULL, NULL, TSQL_CREATE_STABLE);
|
A = tSetCreateSQLElems(X, Y, NULL, TSQL_CREATE_STABLE);
|
||||||
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
|
V.n += Z.n;
|
||||||
|
setCreatedTableName(pInfo, &V, &U);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create table by using super table
|
// create table by using super table
|
||||||
// create table table_name using super_table_name tags(tag_values1, tag_values2)
|
// create table table_name using super_table_name tags(tag_values1, tag_values2)
|
||||||
create_table_args(A) ::= USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. {
|
%type create_from_stable{SCreatedTableInfo}
|
||||||
X.n += F.n;
|
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. {
|
||||||
A = tSetCreateSQLElems(NULL, NULL, &X, Y, NULL, TSQL_CREATE_TABLE_FROM_STABLE);
|
X.n += F.n;
|
||||||
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
V.n += Z.n;
|
||||||
|
A = createNewChildTableInfo(&X, Y, &V, &U);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create stream
|
// create stream
|
||||||
// create table table_name as select count(*) from super_table_name interval(time)
|
// create table table_name as select count(*) from super_table_name interval(time)
|
||||||
create_table_args(A) ::= AS select(S). {
|
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
|
||||||
A = tSetCreateSQLElems(NULL, NULL, NULL, NULL, S, TSQL_CREATE_STREAM);
|
A = tSetCreateSQLElems(NULL, NULL, S, TSQL_CREATE_STREAM);
|
||||||
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
setSQLInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
|
||||||
|
|
||||||
|
V.n += Z.n;
|
||||||
|
setCreatedTableName(pInfo, &V, &U);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type column{TAOS_FIELD}
|
%type column{TAOS_FIELD}
|
||||||
|
@ -335,7 +359,7 @@ columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(T
|
||||||
// The information used for a column is the name and type of column:
|
// The information used for a column is the name and type of column:
|
||||||
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
|
||||||
column(A) ::= ids(X) typename(Y). {
|
column(A) ::= ids(X) typename(Y). {
|
||||||
tSQLSetColumnInfo(&A, &X, &Y);
|
tSQLSetColumnInfo(&A, &X, &Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
%type tagitemlist {SArray*}
|
%type tagitemlist {SArray*}
|
||||||
|
@ -345,10 +369,10 @@ column(A) ::= ids(X) typename(Y). {
|
||||||
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
|
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
|
||||||
tagitemlist(A) ::= tagitem(X). { A = tVariantListAppend(NULL, &X, -1); }
|
tagitemlist(A) ::= tagitem(X). { A = tVariantListAppend(NULL, &X, -1); }
|
||||||
|
|
||||||
tagitem(A) ::= INTEGER(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= FLOAT(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= STRING(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= STRING(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= BOOL(X). {toTSDBType(X.type); tVariantCreate(&A, &X); }
|
tagitem(A) ::= BOOL(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
|
||||||
tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
|
tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
|
||||||
|
|
||||||
tagitem(A) ::= MINUS(X) INTEGER(Y).{
|
tagitem(A) ::= MINUS(X) INTEGER(Y).{
|
||||||
|
@ -445,11 +469,11 @@ tablelist(A) ::= ids(X) cpxName(Y). {
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
|
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
toTSDBType(Z.type);
|
toTSDBType(Z.type);
|
||||||
X.n += Y.n;
|
X.n += Y.n;
|
||||||
A = tVariantListAppendToken(NULL, &X, -1);
|
A = tVariantListAppendToken(NULL, &X, -1);
|
||||||
A = tVariantListAppendToken(A, &Z, -1);
|
A = tVariantListAppendToken(A, &Z, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
||||||
|
@ -460,11 +484,11 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
|
||||||
}
|
}
|
||||||
|
|
||||||
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
|
||||||
toTSDBType(X.type);
|
toTSDBType(X.type);
|
||||||
toTSDBType(F.type);
|
toTSDBType(F.type);
|
||||||
X.n += Z.n;
|
X.n += Z.n;
|
||||||
A = tVariantListAppendToken(Y, &X, -1);
|
A = tVariantListAppendToken(Y, &X, -1);
|
||||||
A = tVariantListAppendToken(A, &F, -1);
|
A = tVariantListAppendToken(A, &F, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
|
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
|
||||||
|
@ -526,9 +550,9 @@ item(A) ::= ids(X) cpxName(Y). {
|
||||||
}
|
}
|
||||||
|
|
||||||
%type sortorder {int}
|
%type sortorder {int}
|
||||||
sortorder(A) ::= ASC. {A = TSDB_ORDER_ASC; }
|
sortorder(A) ::= ASC. { A = TSDB_ORDER_ASC; }
|
||||||
sortorder(A) ::= DESC. {A = TSDB_ORDER_DESC;}
|
sortorder(A) ::= DESC. { A = TSDB_ORDER_DESC;}
|
||||||
sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend order
|
sortorder(A) ::= . { A = TSDB_ORDER_ASC; } // Ascending order by default
|
||||||
|
|
||||||
//group by clause
|
//group by clause
|
||||||
%type groupby_opt {SArray*}
|
%type groupby_opt {SArray*}
|
||||||
|
@ -536,8 +560,8 @@ sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend orde
|
||||||
%type grouplist {SArray*}
|
%type grouplist {SArray*}
|
||||||
%destructor grouplist {taosArrayDestroy($$);}
|
%destructor grouplist {taosArrayDestroy($$);}
|
||||||
|
|
||||||
groupby_opt(A) ::= . {A = 0;}
|
groupby_opt(A) ::= . { A = 0;}
|
||||||
groupby_opt(A) ::= GROUP BY grouplist(X). {A = X;}
|
groupby_opt(A) ::= GROUP BY grouplist(X). { A = X;}
|
||||||
|
|
||||||
grouplist(A) ::= grouplist(X) COMMA item(Y). {
|
grouplist(A) ::= grouplist(X) COMMA item(Y). {
|
||||||
A = tVariantListAppend(X, &Y, -1);
|
A = tVariantListAppend(X, &Y, -1);
|
||||||
|
@ -583,20 +607,20 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
|
||||||
|
|
||||||
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->token.z = X.z; A->token.n = (Z.z - X.z + 1);}
|
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->token.z = X.z; A->token.n = (Z.z - X.z + 1);}
|
||||||
|
|
||||||
expr(A) ::= ID(X). {A = tSQLExprIdValueCreate(&X, TK_ID);}
|
expr(A) ::= ID(X). { A = tSQLExprIdValueCreate(&X, TK_ID);}
|
||||||
expr(A) ::= ID(X) DOT ID(Y). {X.n += (1+Y.n); A = tSQLExprIdValueCreate(&X, TK_ID);}
|
expr(A) ::= ID(X) DOT ID(Y). { X.n += (1+Y.n); A = tSQLExprIdValueCreate(&X, TK_ID);}
|
||||||
expr(A) ::= ID(X) DOT STAR(Y). {X.n += (1+Y.n); A = tSQLExprIdValueCreate(&X, TK_ALL);}
|
expr(A) ::= ID(X) DOT STAR(Y). { X.n += (1+Y.n); A = tSQLExprIdValueCreate(&X, TK_ALL);}
|
||||||
|
|
||||||
expr(A) ::= INTEGER(X). {A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= INTEGER(X). { A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
||||||
expr(A) ::= MINUS(X) INTEGER(Y). {X.n += Y.n; X.type = TK_INTEGER; A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
||||||
expr(A) ::= PLUS(X) INTEGER(Y). {X.n += Y.n; X.type = TK_INTEGER; A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
expr(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSQLExprIdValueCreate(&X, TK_INTEGER);}
|
||||||
expr(A) ::= FLOAT(X). {A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= FLOAT(X). { A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
||||||
expr(A) ::= MINUS(X) FLOAT(Y). {X.n += Y.n; X.type = TK_FLOAT; A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= MINUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
||||||
expr(A) ::= PLUS(X) FLOAT(Y). {X.n += Y.n; X.type = TK_FLOAT; A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
expr(A) ::= PLUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSQLExprIdValueCreate(&X, TK_FLOAT);}
|
||||||
expr(A) ::= STRING(X). {A = tSQLExprIdValueCreate(&X, TK_STRING);}
|
expr(A) ::= STRING(X). { A = tSQLExprIdValueCreate(&X, TK_STRING);}
|
||||||
expr(A) ::= NOW(X). {A = tSQLExprIdValueCreate(&X, TK_NOW); }
|
expr(A) ::= NOW(X). { A = tSQLExprIdValueCreate(&X, TK_NOW); }
|
||||||
expr(A) ::= VARIABLE(X). {A = tSQLExprIdValueCreate(&X, TK_VARIABLE);}
|
expr(A) ::= VARIABLE(X). { A = tSQLExprIdValueCreate(&X, TK_VARIABLE);}
|
||||||
expr(A) ::= BOOL(X). {A = tSQLExprIdValueCreate(&X, TK_BOOL);}
|
expr(A) ::= BOOL(X). { A = tSQLExprIdValueCreate(&X, TK_BOOL);}
|
||||||
|
|
||||||
// ordinary functions: min(x), max(x), top(k, 20)
|
// ordinary functions: min(x), max(x), top(k, 20)
|
||||||
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSQLExprCreateFunction(Y, &X, &E, X.type); }
|
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { A = tSQLExprCreateFunction(Y, &X, &E, X.type); }
|
||||||
|
|
|
@ -250,10 +250,9 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct STwaInfo {
|
typedef struct STwaInfo {
|
||||||
TSKEY lastKey;
|
|
||||||
int8_t hasResult; // flag to denote has value
|
int8_t hasResult; // flag to denote has value
|
||||||
double dOutput;
|
double dOutput;
|
||||||
double lastValue;
|
SPoint1 p;
|
||||||
STimeWindow win;
|
STimeWindow win;
|
||||||
} STwaInfo;
|
} STwaInfo;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,6 +21,12 @@
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
|
|
||||||
|
#define FLT_EQUAL(_x, _y) (fabs((_x) - (_y)) <= (4 * FLT_EPSILON))
|
||||||
|
#define FLT_GREATER(_x, _y) (!FLT_EQUAL((_x), (_y)) && ((_x) > (_y)))
|
||||||
|
#define FLT_LESS(_x, _y) (!FLT_EQUAL((_x), (_y)) && ((_x) < (_y)))
|
||||||
|
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
|
||||||
|
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
|
||||||
|
|
||||||
bool less_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool less_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(int8_t *)minval < pFilter->filterInfo.upperBndi);
|
return (*(int8_t *)minval < pFilter->filterInfo.upperBndi);
|
||||||
}
|
}
|
||||||
|
@ -38,35 +44,35 @@ bool less_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool less_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool less_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)minval < pFilter->filterInfo.upperBndd);
|
return FLT_LESS(*(float*)minval, pFilter->filterInfo.upperBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool less_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool less_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(double *)minval < pFilter->filterInfo.upperBndd);
|
return *(double *)minval < pFilter->filterInfo.upperBndd;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
bool large_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_i8(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(int8_t *)maxval > pFilter->filterInfo.lowerBndi);
|
return (*(int8_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_i16(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(int16_t *)maxval > pFilter->filterInfo.lowerBndi);
|
return (*(int16_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_i32(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(int32_t *)maxval > pFilter->filterInfo.lowerBndi);
|
return (*(int32_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(int64_t *)maxval > pFilter->filterInfo.lowerBndi);
|
return (*(int64_t *)maxval > pFilter->filterInfo.lowerBndi);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)maxval > pFilter->filterInfo.lowerBndd);
|
return FLT_GREATER(*(float*)maxval, pFilter->filterInfo.lowerBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool large_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool larger_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(double *)maxval > pFilter->filterInfo.lowerBndd);
|
return (*(double *)maxval > pFilter->filterInfo.lowerBndd);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
@ -88,10 +94,14 @@ bool lessEqual_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lessEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool lessEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd);
|
return FLT_LESSEQUAL(*(float*)minval, pFilter->filterInfo.upperBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lessEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool lessEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
|
if ((fabs(*(double*)minval) - pFilter->filterInfo.upperBndd) <= 2 * DBL_EPSILON) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return (*(double *)minval <= pFilter->filterInfo.upperBndd);
|
return (*(double *)minval <= pFilter->filterInfo.upperBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +123,15 @@ bool largeEqual_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool largeEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool largeEqual_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)maxval >= pFilter->filterInfo.lowerBndd);
|
return FLT_GREATEREQUAL(*(float*)maxval, pFilter->filterInfo.lowerBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool largeEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool largeEqual_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(double *)maxval >= pFilter->filterInfo.lowerBndd);
|
if (fabs(*(double *)maxval - pFilter->filterInfo.lowerBndd) <= 2 * DBL_EPSILON) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*(double *)maxval - pFilter->filterInfo.lowerBndd > (2 * DBL_EPSILON));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -162,10 +176,12 @@ bool equal_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// user specified input filter value and the original saved float value may needs to
|
||||||
|
// increase the tolerance to obtain the correct result.
|
||||||
bool equal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool equal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
if (*(float *)minval == *(float *)maxval) {
|
if (*(float *)minval == *(float *)maxval) {
|
||||||
return (fabs(*(float *)minval - pFilter->filterInfo.lowerBndd) <= FLT_EPSILON);
|
return FLT_EQUAL(*(float*)minval, pFilter->filterInfo.lowerBndd);
|
||||||
} else { /* range filter */
|
} else { // range filter
|
||||||
assert(*(float *)minval < *(float *)maxval);
|
assert(*(float *)minval < *(float *)maxval);
|
||||||
return *(float *)minval <= pFilter->filterInfo.lowerBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd;
|
return *(float *)minval <= pFilter->filterInfo.lowerBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd;
|
||||||
}
|
}
|
||||||
|
@ -173,10 +189,9 @@ bool equal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
|
|
||||||
bool equal_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool equal_dd(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
if (*(double *)minval == *(double *)maxval) {
|
if (*(double *)minval == *(double *)maxval) {
|
||||||
return (*(double *)minval == pFilter->filterInfo.lowerBndd);
|
return (fabs(*(double *)minval - pFilter->filterInfo.lowerBndd) <= 2 * DBL_EPSILON);
|
||||||
} else { /* range filter */
|
} else { // range filter
|
||||||
assert(*(double *)minval < *(double *)maxval);
|
assert(*(double *)minval < *(double *)maxval);
|
||||||
|
|
||||||
return *(double *)minval <= pFilter->filterInfo.lowerBndi && *(double *)maxval >= pFilter->filterInfo.lowerBndi;
|
return *(double *)minval <= pFilter->filterInfo.lowerBndi && *(double *)maxval >= pFilter->filterInfo.lowerBndi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,7 +270,7 @@ bool nequal_i64(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
|
|
||||||
bool nequal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool nequal_ds(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
if (*(float *)minval == *(float *)maxval) {
|
if (*(float *)minval == *(float *)maxval) {
|
||||||
return (*(float *)minval != pFilter->filterInfo.lowerBndd);
|
return !FLT_EQUAL(*(float *)minval, pFilter->filterInfo.lowerBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -364,7 +379,8 @@ bool rangeFilter_i64_ei(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
bool rangeFilter_ds_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool rangeFilter_ds_ii(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd && *(float *)maxval >= pFilter->filterInfo.lowerBndd);
|
return FLT_LESSEQUAL(*(float *)minval, pFilter->filterInfo.upperBndd) &&
|
||||||
|
FLT_GREATEREQUAL(*(float *)maxval, pFilter->filterInfo.lowerBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rangeFilter_ds_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool rangeFilter_ds_ee(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
|
@ -376,7 +392,8 @@ bool rangeFilter_ds_ie(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rangeFilter_ds_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
bool rangeFilter_ds_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
return (*(float *)minval <= pFilter->filterInfo.upperBndd && *(float *)maxval > pFilter->filterInfo.lowerBndd);
|
return FLT_GREATER(*(float *)maxval, pFilter->filterInfo.lowerBndd) &&
|
||||||
|
FLT_LESSEQUAL(*(float *)minval, pFilter->filterInfo.upperBndd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -400,7 +417,7 @@ bool rangeFilter_dd_ei(SColumnFilterElem *pFilter, char *minval, char *maxval) {
|
||||||
bool (*filterFunc_i8[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_i8[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_i8,
|
less_i8,
|
||||||
large_i8,
|
larger_i8,
|
||||||
equal_i8,
|
equal_i8,
|
||||||
lessEqual_i8,
|
lessEqual_i8,
|
||||||
largeEqual_i8,
|
largeEqual_i8,
|
||||||
|
@ -413,7 +430,7 @@ bool (*filterFunc_i8[])(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
bool (*filterFunc_i16[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_i16[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_i16,
|
less_i16,
|
||||||
large_i16,
|
larger_i16,
|
||||||
equal_i16,
|
equal_i16,
|
||||||
lessEqual_i16,
|
lessEqual_i16,
|
||||||
largeEqual_i16,
|
largeEqual_i16,
|
||||||
|
@ -426,7 +443,7 @@ bool (*filterFunc_i16[])(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
bool (*filterFunc_i32[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_i32[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_i32,
|
less_i32,
|
||||||
large_i32,
|
larger_i32,
|
||||||
equal_i32,
|
equal_i32,
|
||||||
lessEqual_i32,
|
lessEqual_i32,
|
||||||
largeEqual_i32,
|
largeEqual_i32,
|
||||||
|
@ -439,7 +456,7 @@ bool (*filterFunc_i32[])(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
bool (*filterFunc_i64[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_i64[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_i64,
|
less_i64,
|
||||||
large_i64,
|
larger_i64,
|
||||||
equal_i64,
|
equal_i64,
|
||||||
lessEqual_i64,
|
lessEqual_i64,
|
||||||
largeEqual_i64,
|
largeEqual_i64,
|
||||||
|
@ -452,7 +469,7 @@ bool (*filterFunc_i64[])(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
bool (*filterFunc_ds[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_ds[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_ds,
|
less_ds,
|
||||||
large_ds,
|
larger_ds,
|
||||||
equal_ds,
|
equal_ds,
|
||||||
lessEqual_ds,
|
lessEqual_ds,
|
||||||
largeEqual_ds,
|
largeEqual_ds,
|
||||||
|
@ -465,7 +482,7 @@ bool (*filterFunc_ds[])(SColumnFilterElem *pFilter, char *minval, char *maxval)
|
||||||
bool (*filterFunc_dd[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
bool (*filterFunc_dd[])(SColumnFilterElem *pFilter, char *minval, char *maxval) = {
|
||||||
NULL,
|
NULL,
|
||||||
less_dd,
|
less_dd,
|
||||||
large_dd,
|
larger_dd,
|
||||||
equal_dd,
|
equal_dd,
|
||||||
lessEqual_dd,
|
lessEqual_dd,
|
||||||
largeEqual_dd,
|
largeEqual_dd,
|
||||||
|
@ -551,7 +568,7 @@ bool (*rangeFilterFunc_dd[])(SColumnFilterElem *pFilter, char *minval, char *max
|
||||||
|
|
||||||
__filter_func_t* getRangeFilterFuncArray(int32_t type) {
|
__filter_func_t* getRangeFilterFuncArray(int32_t type) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case TSDB_DATA_TYPE_BOOL: return rangeFilterFunc_i8;
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDB_DATA_TYPE_TINYINT: return rangeFilterFunc_i8;
|
case TSDB_DATA_TYPE_TINYINT: return rangeFilterFunc_i8;
|
||||||
case TSDB_DATA_TYPE_SMALLINT: return rangeFilterFunc_i16;
|
case TSDB_DATA_TYPE_SMALLINT: return rangeFilterFunc_i16;
|
||||||
case TSDB_DATA_TYPE_INT: return rangeFilterFunc_i32;
|
case TSDB_DATA_TYPE_INT: return rangeFilterFunc_i32;
|
||||||
|
@ -565,7 +582,7 @@ __filter_func_t* getRangeFilterFuncArray(int32_t type) {
|
||||||
|
|
||||||
__filter_func_t* getValueFilterFuncArray(int32_t type) {
|
__filter_func_t* getValueFilterFuncArray(int32_t type) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case TSDB_DATA_TYPE_BOOL: return filterFunc_i8;
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDB_DATA_TYPE_TINYINT: return filterFunc_i8;
|
case TSDB_DATA_TYPE_TINYINT: return filterFunc_i8;
|
||||||
case TSDB_DATA_TYPE_SMALLINT: return filterFunc_i16;
|
case TSDB_DATA_TYPE_SMALLINT: return filterFunc_i16;
|
||||||
case TSDB_DATA_TYPE_INT: return filterFunc_i32;
|
case TSDB_DATA_TYPE_INT: return filterFunc_i32;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue