Merge branch '3.0' into feature/3.0_liaohj
This commit is contained in:
commit
c3f4d74f9b
|
@ -18,6 +18,7 @@ mac/
|
|||
.mypy_cache
|
||||
*.tmp
|
||||
*.swp
|
||||
*.orig
|
||||
src/connector/nodejs/node_modules/
|
||||
src/connector/nodejs/out/
|
||||
tests/test/
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import hudson.model.Result
|
||||
import hudson.model.*;
|
||||
import jenkins.model.CauseOfInterruption
|
||||
properties([pipelineTriggers([githubPush()])])
|
||||
node {
|
||||
git url: 'https://github.com/taosdata/TDengine.git'
|
||||
}
|
||||
|
||||
def skipbuild=0
|
||||
def win_stop=0
|
||||
|
||||
def abortPreviousBuilds() {
|
||||
def currentJobName = env.JOB_NAME
|
||||
|
@ -41,72 +41,72 @@ def pre_test(){
|
|||
killall -9 taosd ||echo "no taosd running"
|
||||
killall -9 gdb || echo "no gdb running"
|
||||
killall -9 python3.8 || echo "no python program running"
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git reset --hard HEAD~10 >/dev/null
|
||||
'''
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
sh '''
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git checkout master
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '2.0'){
|
||||
sh '''
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git checkout 2.0
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '3.0'){
|
||||
sh '''
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git checkout 3.0
|
||||
'''
|
||||
}
|
||||
else{
|
||||
sh '''
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
sh'''
|
||||
cd ${WORKSPACE}
|
||||
cd ${WKC}
|
||||
git pull >/dev/null
|
||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
git clean -dfx
|
||||
'''
|
||||
// script {
|
||||
// if (env.CHANGE_TARGET == 'master') {
|
||||
// sh '''
|
||||
// cd ${WK}
|
||||
// git checkout master
|
||||
// '''
|
||||
// }
|
||||
// else if(env.CHANGE_TARGET == '2.0'){
|
||||
// sh '''
|
||||
// cd ${WK}
|
||||
// git checkout 2.0
|
||||
// '''
|
||||
// }
|
||||
// else if(env.CHANGE_TARGET == '3.0'){
|
||||
// sh '''
|
||||
// cd ${WK}
|
||||
// git checkout 3.0
|
||||
// '''
|
||||
// }
|
||||
// else{
|
||||
// sh '''
|
||||
// cd ${WK}
|
||||
// git checkout develop
|
||||
// '''
|
||||
// }
|
||||
// }
|
||||
// sh '''
|
||||
// cd ${WK}
|
||||
// git pull >/dev/null
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout master
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '2.0'){
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout 2.0
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '3.0'){
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout 3.0
|
||||
'''
|
||||
}
|
||||
else{
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git pull >/dev/null
|
||||
git clean -dfx
|
||||
export TZ=Asia/Harbin
|
||||
date
|
||||
mkdir debug
|
||||
|
@ -121,6 +121,7 @@ def pre_test(){
|
|||
|
||||
pipeline {
|
||||
agent none
|
||||
options { skipDefaultCheckout() }
|
||||
environment{
|
||||
WK = '/var/lib/jenkins/workspace/TDinternal'
|
||||
WKC= '/var/lib/jenkins/workspace/TDinternal/community'
|
||||
|
@ -128,6 +129,7 @@ pipeline {
|
|||
stages {
|
||||
stage('pre_build'){
|
||||
agent{label 'master'}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
}
|
||||
|
@ -136,269 +138,228 @@ pipeline {
|
|||
abort_previous()
|
||||
abortPreviousBuilds()
|
||||
}
|
||||
sh'''
|
||||
rm -rf ${WORKSPACE}.tes
|
||||
cp -r ${WORKSPACE} ${WORKSPACE}.tes
|
||||
cd ${WORKSPACE}.tes
|
||||
git fetch
|
||||
'''
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
sh '''
|
||||
git checkout master
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '2.0'){
|
||||
sh '''
|
||||
git checkout 2.0
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '3.0'){
|
||||
sh '''
|
||||
git checkout 3.0
|
||||
'''
|
||||
}
|
||||
else{
|
||||
sh '''
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
sh'''
|
||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
'''
|
||||
|
||||
script{
|
||||
skipbuild='2'
|
||||
skipbuild=sh(script: "git log -2 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]' && echo 1 || echo 2", returnStdout:true)
|
||||
println skipbuild
|
||||
}
|
||||
sh'''
|
||||
rm -rf ${WORKSPACE}.tes
|
||||
'''
|
||||
pre_test()
|
||||
}
|
||||
}
|
||||
stage('Parallel test stage') {
|
||||
//only build pr
|
||||
when {
|
||||
allOf{
|
||||
changeRequest()
|
||||
expression{
|
||||
return skipbuild.trim() == '2'
|
||||
}
|
||||
}
|
||||
}
|
||||
parallel {
|
||||
stage('python_1_s1') {
|
||||
agent{label " slave1 || slave11 "}
|
||||
steps {
|
||||
// stage('Parallel test stage') {
|
||||
// //only build pr
|
||||
// options { skipDefaultCheckout() }
|
||||
// when {
|
||||
// allOf{
|
||||
// changeRequest()
|
||||
|
||||
// }
|
||||
// }
|
||||
// parallel {
|
||||
// stage('python_1_s1') {
|
||||
// agent{label " slave1 || slave11 "}
|
||||
// steps {
|
||||
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh p1
|
||||
// date'''
|
||||
// }
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p1
|
||||
// // date'''
|
||||
// // }
|
||||
|
||||
}
|
||||
}
|
||||
stage('python_2_s5') {
|
||||
agent{label " slave5 || slave15 "}
|
||||
steps {
|
||||
// }
|
||||
// }
|
||||
// stage('python_2_s5') {
|
||||
// agent{label " slave5 || slave15 "}
|
||||
// steps {
|
||||
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh p2
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('python_3_s6') {
|
||||
agent{label " slave6 || slave16 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p2
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('python_3_s6') {
|
||||
// agent{label " slave6 || slave16 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh p3
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_b1_s2') {
|
||||
agent{label " slave2 || slave12 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p3
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b1_s2') {
|
||||
// agent{label " slave2 || slave12 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// rm -rf /var/lib/taos/*
|
||||
// rm -rf /var/log/taos/*
|
||||
// nohup taosd >/dev/null &
|
||||
// sleep 10
|
||||
// '''
|
||||
// sh '''
|
||||
// cd ${WKC}/tests/examples/nodejs
|
||||
// npm install td2.0-connector > /dev/null 2>&1
|
||||
// node nodejsChecker.js host=localhost
|
||||
// node test1970.js
|
||||
// cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport
|
||||
// npm install td2.0-connector > /dev/null 2>&1
|
||||
// node nanosecondTest.js
|
||||
// // sh '''
|
||||
// // rm -rf /var/lib/taos/*
|
||||
// // rm -rf /var/log/taos/*
|
||||
// // nohup taosd >/dev/null &
|
||||
// // sleep 10
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/examples/nodejs
|
||||
// // npm install td2.0-connector > /dev/null 2>&1
|
||||
// // node nodejsChecker.js host=localhost
|
||||
// // node test1970.js
|
||||
// // cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport
|
||||
// // npm install td2.0-connector > /dev/null 2>&1
|
||||
// // node nanosecondTest.js
|
||||
|
||||
// '''
|
||||
// sh '''
|
||||
// cd ${WKC}/tests/examples/C#/taosdemo
|
||||
// mcs -out:taosdemo *.cs > /dev/null 2>&1
|
||||
// echo '' |./taosdemo -c /etc/taos
|
||||
// cd ${WKC}/tests/connectorTest/C#Test/nanosupport
|
||||
// mcs -out:nano *.cs > /dev/null 2>&1
|
||||
// echo '' |./nano
|
||||
// '''
|
||||
// sh '''
|
||||
// cd ${WKC}/tests/gotest
|
||||
// bash batchtest.sh
|
||||
// '''
|
||||
// sh '''
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b1fq
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_crash_gen_s3') {
|
||||
agent{label " slave3 || slave13 "}
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/examples/C#/taosdemo
|
||||
// // mcs -out:taosdemo *.cs > /dev/null 2>&1
|
||||
// // echo '' |./taosdemo -c /etc/taos
|
||||
// // cd ${WKC}/tests/connectorTest/C#Test/nanosupport
|
||||
// // mcs -out:nano *.cs > /dev/null 2>&1
|
||||
// // echo '' |./nano
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/gotest
|
||||
// // bash batchtest.sh
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b1fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_crash_gen_s3') {
|
||||
// agent{label " slave3 || slave13 "}
|
||||
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 60, unit: 'MINUTES'){
|
||||
// sh '''
|
||||
// cd ${WKC}/tests/pytest
|
||||
// ./crash_gen.sh -a -p -t 4 -s 2000
|
||||
// '''
|
||||
// }
|
||||
// timeout(time: 60, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // rm -rf /var/lib/taos/*
|
||||
// // rm -rf /var/log/taos/*
|
||||
// // ./handle_crash_gen_val_log.sh
|
||||
// // '''
|
||||
// sh '''
|
||||
// cd ${WKC}/tests/pytest
|
||||
// rm -rf /var/lib/taos/*
|
||||
// rm -rf /var/log/taos/*
|
||||
// ./handle_taosd_val_log.sh
|
||||
// '''
|
||||
// }
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b2fq
|
||||
// date
|
||||
// '''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_valgrind_s4') {
|
||||
agent{label " slave4 || slave14 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 60, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // ./crash_gen.sh -a -p -t 4 -s 2000
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 60, unit: 'MINUTES'){
|
||||
// // // sh '''
|
||||
// // // cd ${WKC}/tests/pytest
|
||||
// // // rm -rf /var/lib/taos/*
|
||||
// // // rm -rf /var/log/taos/*
|
||||
// // // ./handle_crash_gen_val_log.sh
|
||||
// // // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // rm -rf /var/lib/taos/*
|
||||
// // rm -rf /var/log/taos/*
|
||||
// // ./handle_taosd_val_log.sh
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b2fq
|
||||
// // date
|
||||
// // '''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_valgrind_s4') {
|
||||
// agent{label " slave4 || slave14 "}
|
||||
|
||||
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
|
||||
// '''
|
||||
// }
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b3fq
|
||||
// date'''
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh full example
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_b4_s7') {
|
||||
agent{label " slave7 || slave17 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// 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
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b3fq
|
||||
// // date'''
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full example
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b4_s7') {
|
||||
// agent{label " slave7 || slave17 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b4fq
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh p4
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh full jdbc
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh full unit
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_b5_s8') {
|
||||
agent{label " slave8 || slave18 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b4fq
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p4
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full jdbc
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full unit
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b5_s8') {
|
||||
// agent{label " slave8 || slave18 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b5fq
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_b6_s9') {
|
||||
agent{label " slave9 || slave19 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b5fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b6_s9') {
|
||||
// agent{label " slave9 || slave19 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b6fq
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
stage('test_b7_s10') {
|
||||
agent{label " slave10 || slave20 "}
|
||||
steps {
|
||||
pre_test()
|
||||
// timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b6fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b7_s10') {
|
||||
// agent{label " slave10 || slave20 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// sh '''
|
||||
// date
|
||||
// cd ${WKC}/tests
|
||||
// ./test-all.sh b7fq
|
||||
// date'''
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b7fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
post {
|
||||
success {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# lucene
|
||||
ExternalProject_Add(lucene
|
||||
GIT_REPOSITORY https://github.com/taosdata-contrib/LucenePlusPlus.git
|
||||
GIT_TAG rel_3.0.8
|
||||
GIT_TAG rel_3.0.8_td
|
||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/lucene"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -2,3 +2,7 @@
|
|||
if(${BUILD_WITH_ROCKSDB})
|
||||
add_subdirectory(rocksdb)
|
||||
endif(${BUILD_WITH_ROCKSDB})
|
||||
|
||||
if(${BUILD_WITH_LUCENE})
|
||||
add_subdirectory(lucene)
|
||||
endif(${BUILD_WITH_LUCENE})
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
add_executable(luceneTest "")
|
||||
target_sources(luceneTest
|
||||
PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
|
||||
)
|
||||
target_link_libraries(luceneTest lucene++)
|
|
@ -0,0 +1,6 @@
|
|||
#include <iostream>
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
std::cout << "Hello, this is lucene test" << std::endl;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,236 @@
|
|||
```plantuml
|
||||
@startuml create_table
|
||||
skinparam sequenceMessageAlign center
|
||||
skinparam responseMessageBelowArrow true
|
||||
|
||||
participant APP as app
|
||||
box "dnode1"
|
||||
participant RPC as rpc
|
||||
participant VNODE as vnode
|
||||
participant SYNC as sync
|
||||
end box
|
||||
|
||||
box "dnode2"
|
||||
participant SYNC as sync2
|
||||
participant VNODE as vnode2
|
||||
end box
|
||||
|
||||
box "dnode3"
|
||||
participant SYNC as sync3
|
||||
participant VNODE as vnode3
|
||||
end box
|
||||
|
||||
' APP send request to dnode and RPC in dnode recv the request
|
||||
app ->rpc: create table req
|
||||
|
||||
' RPC call vnodeProcessReq() function to process the request
|
||||
rpc -> vnode: vnodeProcessReq
|
||||
note right
|
||||
callback function
|
||||
run in RPC module
|
||||
threads. The function
|
||||
only puts the request
|
||||
to a vnode queue.
|
||||
end note
|
||||
|
||||
' VNODE call vnodeProcessReqs() function to integrate requests and process as a whole
|
||||
vnode -> vnode: vnodeProcessReqs()
|
||||
note right
|
||||
integrate reqs and
|
||||
process as a whole
|
||||
end note
|
||||
|
||||
|
||||
' sync the request to other nodes
|
||||
vnode -> sync: syncProcessReqs()
|
||||
|
||||
' make request persistent
|
||||
' sync -->vnode: walWrite()\n(callback function)
|
||||
|
||||
' replicate requests to other DNODES
|
||||
sync -> sync2: replication req
|
||||
sync -> sync3: replication req
|
||||
sync2 -> vnode2: walWrite()\n(callback function)
|
||||
sync2 --> sync: replication rsp\n(confirm)
|
||||
sync3 -> vnode3: walWrite()\n(callback function)
|
||||
|
||||
sync3 --> sync: replication rsp\n(confirm)
|
||||
|
||||
' send apply request
|
||||
sync -> sync2: apply req
|
||||
sync -> sync3: apply req
|
||||
|
||||
' vnode apply
|
||||
sync2 -> vnode2: vnodeApplyReqs()
|
||||
sync3 -> vnode3: vnodeApplyReqs()
|
||||
|
||||
' call apply request
|
||||
sync --> vnode: vnodeApplyReqs()\n(callback function)
|
||||
|
||||
' send response
|
||||
vnode --> rpc: rpcSendRsp()
|
||||
|
||||
' dnode send response to APP
|
||||
rpc --> app: create table rsp
|
||||
@enduml
|
||||
```
|
||||
|
||||
## Leader处理强一致写入请求
|
||||
```plantuml
|
||||
@startuml leader_process_stict_consistency
|
||||
box "dnode1"
|
||||
participant CRPC as crpc
|
||||
participant VNODE as vnode
|
||||
participant SYNC as sync
|
||||
end box
|
||||
|
||||
-> crpc: create table/submit req
|
||||
|
||||
' In CRPC threads
|
||||
group #pink "In CRPC threads"
|
||||
crpc -> vnode:vnodeProcessReq()
|
||||
note right
|
||||
A callback function
|
||||
run by CRPC thread
|
||||
to put the request
|
||||
to a vnode queue
|
||||
end note
|
||||
end
|
||||
|
||||
' In VNODE worker threads
|
||||
group #lightblue "In VNODE worker threads"
|
||||
vnode -> vnode: vnodeProcessReqs()
|
||||
note right
|
||||
VNODE process requests
|
||||
accumulated in a
|
||||
vnode write queue and
|
||||
process the batch reqs
|
||||
as a whole
|
||||
end note
|
||||
|
||||
vnode -> sync: syncProcessReqs()
|
||||
|
||||
sync -> : replication req1
|
||||
sync -> : replication req2
|
||||
end
|
||||
|
||||
group #red "SYNC threads"
|
||||
sync <- : replication rsp1
|
||||
sync <- : replication rsp2
|
||||
sync -> vnode: notify apply
|
||||
sync -> : apply rsp1
|
||||
sync -> : apply rsp2
|
||||
end
|
||||
|
||||
group #lightblue "In VNODE worker threads"
|
||||
vnode -> vnode: vnodeApplyReqs()
|
||||
vnode -> crpc:
|
||||
end
|
||||
|
||||
<- crpc: create table/submit rsp
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
## Follower处理强一致写入请求
|
||||
```plantuml
|
||||
@startuml follower_process_strict_consistency
|
||||
participant SYNC as sync
|
||||
participant VNODE as vnode
|
||||
|
||||
group #pink "SYNC threads"
|
||||
-> sync: replication req
|
||||
|
||||
sync -> sync: syncProcessReqs()
|
||||
note right
|
||||
In the replication
|
||||
only data is
|
||||
persisted and response
|
||||
is sent back
|
||||
end note
|
||||
|
||||
<- sync: replication rsp
|
||||
|
||||
-> sync: apply req
|
||||
|
||||
sync -> vnode: notify apply
|
||||
end
|
||||
|
||||
group #lightblue "VNODE worker threads"
|
||||
vnode -> vnode: vnodeApplyReqs()
|
||||
end
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
## Leader处理最终一致写入请求
|
||||
```plantuml
|
||||
@startuml leader_process_eventual_consistency
|
||||
box "dnode1"
|
||||
participant CRPC as crpc
|
||||
participant VNODE as vnode
|
||||
participant SYNC as sync
|
||||
end box
|
||||
|
||||
-> crpc: create table/submit req
|
||||
|
||||
' In CRPC threads
|
||||
group #pink "In CRPC threads"
|
||||
crpc -> vnode:vnodeProcessReq()
|
||||
note right
|
||||
A callback function
|
||||
run by CRPC thread
|
||||
to put the request
|
||||
to a vnode queue
|
||||
end note
|
||||
end
|
||||
|
||||
' In VNODE worker threads
|
||||
group #lightblue "In VNODE worker threads"
|
||||
vnode -> vnode: vnodeProcessReqs()
|
||||
note right
|
||||
VNODE process requests
|
||||
accumulated in a
|
||||
vnode write queue and
|
||||
process the batch reqs
|
||||
as a whole
|
||||
end note
|
||||
|
||||
vnode -> sync: syncProcessReqs()
|
||||
|
||||
sync -> : replication req1
|
||||
sync -> : replication req2
|
||||
|
||||
sync -> vnode: notify apply
|
||||
end
|
||||
|
||||
|
||||
group #lightblue "In VNODE worker threads"
|
||||
vnode -> vnode: vnodeApplyReqs()
|
||||
vnode -> crpc:
|
||||
end
|
||||
|
||||
<- crpc: create table/submit rsp
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
## Follower处理最终一致写入请求
|
||||
```plantuml
|
||||
@startuml follower_process_eventual_consistency
|
||||
participant SYNC as sync
|
||||
participant VNODE as vnode
|
||||
|
||||
group #pink "SYNC threads"
|
||||
-> sync: replication rsp
|
||||
|
||||
sync -> sync: syncProcessReqs()
|
||||
|
||||
sync -> vnode: notify VNODE \nthread to process\n the reqs
|
||||
end
|
||||
|
||||
group #lightblue "VNODE worker threads"
|
||||
vnode -> vnode: vnodeApplyReqs()
|
||||
end
|
||||
@enduml
|
||||
```
|
|
@ -0,0 +1,311 @@
|
|||
<center><h1>VNODE Write Processes</h1></center>
|
||||
|
||||
## META Operations
|
||||
META data write operations including:
|
||||
|
||||
1. create table
|
||||
2. drop table
|
||||
3. alter table
|
||||
|
||||
We take create table as an example to figure out the whole process.
|
||||
```plantuml
|
||||
@startuml create_table
|
||||
skinparam sequenceMessageAlign center
|
||||
skinparam responseMessageBelowArrow true
|
||||
|
||||
participant APP as app
|
||||
box "dnode1"
|
||||
participant RPC as rpc
|
||||
participant VNODE as vnode
|
||||
participant SYNC as sync
|
||||
end box
|
||||
|
||||
box "dnode2"
|
||||
participant SYNC as sync2
|
||||
participant VNODE as vnode2
|
||||
end box
|
||||
|
||||
box "dnode3"
|
||||
participant SYNC as sync3
|
||||
participant VNODE as vnode3
|
||||
end box
|
||||
|
||||
' APP send request to dnode and RPC in dnode recv the request
|
||||
app ->rpc: create table req
|
||||
|
||||
' RPC call vnodeProcessReq() function to process the request
|
||||
rpc -> vnode: vnodeProcessReq
|
||||
note right
|
||||
callback function
|
||||
run in RPC module
|
||||
threads. The function
|
||||
only puts the request
|
||||
to a vnode queue.
|
||||
end note
|
||||
|
||||
' VNODE call vnodeProcessReqs() function to integrate requests and process as a whole
|
||||
vnode -> vnode: vnodeProcessReqs()
|
||||
note right
|
||||
integrate reqs and
|
||||
process as a whole
|
||||
end note
|
||||
|
||||
|
||||
' sync the request to other nodes
|
||||
vnode -> sync: syncProcessReqs()
|
||||
|
||||
' make request persistent
|
||||
' sync -->vnode: walWrite()\n(callback function)
|
||||
|
||||
' replicate requests to other DNODES
|
||||
sync -> sync2: replication req
|
||||
sync -> sync3: replication req
|
||||
sync2 -> vnode2: walWrite()\n(callback function)
|
||||
sync2 --> sync: replication rsp\n(confirm)
|
||||
sync3 -> vnode3: walWrite()\n(callback function)
|
||||
|
||||
sync3 --> sync: replication rsp\n(confirm)
|
||||
|
||||
' send apply request
|
||||
sync -> sync2: apply req
|
||||
sync -> sync3: apply req
|
||||
|
||||
' vnode apply
|
||||
sync2 -> vnode2: vnodeApplyReqs()
|
||||
sync3 -> vnode3: vnodeApplyReqs()
|
||||
|
||||
' call apply request
|
||||
sync --> vnode: vnodeApplyReqs()\n(callback function)
|
||||
|
||||
' send response
|
||||
vnode --> rpc: rpcSendRsp()
|
||||
|
||||
' dnode send response to APP
|
||||
rpc --> app: create table rsp
|
||||
@enduml
|
||||
```
|
||||
|
||||
## Time-series data Operations
|
||||
There are only one operations for time-series data: data insert. We will figure out the whole process.
|
||||
|
||||
```plantuml
|
||||
@startuml create_table
|
||||
skinparam sequenceMessageAlign center
|
||||
skinparam responseMessageBelowArrow true
|
||||
|
||||
participant APP as app
|
||||
box "dnode1"
|
||||
participant RPC as rpc
|
||||
participant VNODE as vnode
|
||||
participant SYNC as sync
|
||||
end box
|
||||
|
||||
box "dnode2"
|
||||
participant SYNC as sync2
|
||||
participant VNODE as vnode2
|
||||
end box
|
||||
|
||||
box "dnode3"
|
||||
participant SYNC as sync3
|
||||
participant VNODE as vnode3
|
||||
end box
|
||||
|
||||
' APP send request to dnode and RPC in dnode recv the request
|
||||
app ->rpc: insert data req
|
||||
|
||||
' RPC call vnodeProcessReq() function to process the request
|
||||
rpc -> vnode: vnodeProcessReq
|
||||
note right
|
||||
callback function
|
||||
run in RPC module
|
||||
threads. The function
|
||||
only puts the request
|
||||
to a vnode queue.
|
||||
end note
|
||||
|
||||
' VNODE call vnodeProcessReqs() function to integrate requests and process as a whole
|
||||
vnode -> vnode: vnodeProcessReqs()
|
||||
note right
|
||||
integrate reqs and
|
||||
process as a whole
|
||||
end note
|
||||
|
||||
|
||||
' sync the request to other nodes
|
||||
vnode -> sync: syncProcessReqs()
|
||||
|
||||
' ' make request persistent
|
||||
' ' sync -->vnode: walWrite()\n(callback function)
|
||||
|
||||
' ' replicate requests to other DNODES
|
||||
sync -> sync2: replication req
|
||||
sync -> sync3: replication req
|
||||
|
||||
' vnode apply
|
||||
sync2 -> vnode2: vnodeApplyReqs()
|
||||
sync3 -> vnode3: vnodeApplyReqs()
|
||||
|
||||
' call apply request
|
||||
sync --> vnode: vnodeApplyReqs()\n(callback function)
|
||||
|
||||
' send response
|
||||
vnode --> rpc: rpcSendRsp()
|
||||
|
||||
' dnode send response to APP
|
||||
rpc --> app: insert data rsp
|
||||
@enduml
|
||||
```
|
||||
|
||||
## vnodeProcessReqs()
|
||||
```plantuml
|
||||
@startuml vnodeProcessReqs()
|
||||
participant VNODE as v
|
||||
participant SYNC as s
|
||||
|
||||
group vnodeProcessReqs()
|
||||
' Group requests and get a request batch to process as a whole
|
||||
v -> v: vnodeGetReqsFromQueue()
|
||||
note right
|
||||
integrate all write
|
||||
requests as a batch
|
||||
to process as a whole
|
||||
end note
|
||||
|
||||
' VNODE call syncProcessReqs() function to process the batch request
|
||||
v -> s: syncProcessReqs()
|
||||
|
||||
group syncProcessReqs()
|
||||
' Check if current node is leader
|
||||
alt not leader
|
||||
return NOT_LEADER
|
||||
end
|
||||
|
||||
s -> s: syncAppendReqsToLogStore()
|
||||
group syncAppendReqsToLogStore()
|
||||
s -> v: walWrite()
|
||||
note right
|
||||
There must be a
|
||||
callback function
|
||||
provided by VNODE
|
||||
to persist the
|
||||
requests in WAL
|
||||
end note
|
||||
|
||||
alt (no unapplied reqs) AND (only one node OR no meta requests)
|
||||
s -> v: vnodeApplyReqs()
|
||||
note right
|
||||
just use the woker
|
||||
thread to apply
|
||||
the requests. This
|
||||
is a callback function
|
||||
provided by VNODE
|
||||
end note
|
||||
else other cases need to wait response
|
||||
s -> s:
|
||||
note right
|
||||
save the requests in log store
|
||||
and wait for comfirmation or
|
||||
other cases
|
||||
end note
|
||||
|
||||
s ->]: send replication requests
|
||||
s ->]: send replication requests
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@enduml
|
||||
```
|
||||
|
||||
<!-- ## syncProcessReplicationReq()
|
||||
```plantuml
|
||||
@startuml syncProcessReplicationReq
|
||||
participant SYNC as s
|
||||
participant VNODE as v
|
||||
|
||||
-> s: replication request
|
||||
s -> s:
|
||||
note right
|
||||
process the request
|
||||
to get the request
|
||||
batch
|
||||
end note
|
||||
|
||||
s -> s: syncAppendReqToLogStore()
|
||||
|
||||
s -> v: walWrite()
|
||||
|
||||
alt has meta req
|
||||
<- s: comfirmation
|
||||
else
|
||||
s -> v: vnodeApplyReqs()
|
||||
end
|
||||
|
||||
@enduml -->
|
||||
<!-- ``` -->
|
||||
|
||||
## vnodeApplyReqs()
|
||||
The function *vnodeApplyReqs()* is the actual function running by a vnode to process the requests.
|
||||
```plantuml
|
||||
@startuml vnodeApplyReqs()
|
||||
skinparam sequenceMessageAlign left
|
||||
skinparam responseMessageBelowArrow true
|
||||
|
||||
participant VNODE as vnode
|
||||
participant TQ as tq
|
||||
participant TSDB as tsdb
|
||||
participant META as meta
|
||||
|
||||
group vnodeApplyReqs()
|
||||
autonumber
|
||||
loop nReqs
|
||||
' Copy request message to vnode buffer pool
|
||||
vnode -> vnode: vnodeCopyReq()
|
||||
note right
|
||||
copy request to
|
||||
vnode buffer pool
|
||||
end note
|
||||
|
||||
vnode -> tq: tqPush()
|
||||
note right
|
||||
push the request
|
||||
to TQ so consumers
|
||||
can consume
|
||||
end note
|
||||
alt META_REQ
|
||||
autonumber 3
|
||||
vnode -> meta: metaApplyReq()
|
||||
else TS_REQ
|
||||
autonumber 3
|
||||
vnode -> tsdb: tsdbApplyReq()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
' Check if need to commit
|
||||
alt vnode buffer pool is full
|
||||
group vnodeCommit()
|
||||
autonumber 4.1
|
||||
vnode -> tq: tqCommit()
|
||||
note right
|
||||
tqCommit may renew wal
|
||||
end note
|
||||
vnode -> meta: metaCommit();
|
||||
note right
|
||||
commit meta data
|
||||
end note
|
||||
vnode -> tsdb: tsdbCommit();
|
||||
note right
|
||||
commit time-series data
|
||||
end note
|
||||
end
|
||||
end
|
||||
end
|
||||
@enduml
|
||||
```
|
||||
<!-- meta操作:建表,删表,改表(队队列/同步)
|
||||
数据写入
|
||||
快照文件与sync的结合
|
||||
vnodeOpen()
|
||||
vnodeClose()
|
||||
sync.h -->
|
|
@ -363,6 +363,8 @@ typedef struct {
|
|||
} SConnectRsp;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
|
@ -374,12 +376,6 @@ typedef struct {
|
|||
int64_t maxInbound;
|
||||
int64_t maxOutbound;
|
||||
int8_t accessState; // Configured only by command
|
||||
} SAcctCfg;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
SAcctCfg cfg;
|
||||
} SCreateAcctMsg, SAlterAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -660,15 +656,18 @@ typedef struct SVgroupAccess {
|
|||
} SVgroupAccess;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
uint32_t moduleStatus;
|
||||
uint32_t numOfVnodes;
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
char reserved[16];
|
||||
int32_t dnodeId;
|
||||
int8_t dropped;
|
||||
char reserved[19];
|
||||
int64_t clusterId;
|
||||
int32_t numOfDnodes;
|
||||
int32_t numOfVnodes;
|
||||
} SDnodeCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t isMnode;
|
||||
int8_t reserved;
|
||||
uint16_t dnodePort;
|
||||
char dnodeFqdn[TSDB_FQDN_LEN];
|
||||
} SDnodeEp;
|
||||
|
@ -679,55 +678,29 @@ typedef struct {
|
|||
} SDnodeEps;
|
||||
|
||||
typedef struct {
|
||||
int32_t mnodeId;
|
||||
char mnodeEp[TSDB_EP_LEN];
|
||||
} SMInfo;
|
||||
|
||||
typedef struct SMInfos {
|
||||
int8_t inUse;
|
||||
int8_t mnodeNum;
|
||||
SMInfo mnodeInfos[TSDB_MAX_REPLICA];
|
||||
} SMInfos;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfMnodes; // tsNumOfMnodes
|
||||
int32_t mnodeEqualVnodeNum; // tsMnodeEqualVnodeNum
|
||||
int32_t offlineThreshold; // tsOfflineThreshold
|
||||
int32_t statusInterval; // tsStatusInterval
|
||||
int32_t maxtablesPerVnode;
|
||||
int32_t maxVgroupsPerDb;
|
||||
char arbitrator[TSDB_EP_LEN]; // tsArbitrator
|
||||
char reserve[2]; // to solve arm32 bus error
|
||||
char timezone[64]; // tsTimezone
|
||||
int64_t checkTime; // 1970-01-01 00:00:00.000
|
||||
char locale[TSDB_LOCALE_LEN]; // tsLocale
|
||||
char charset[TSDB_LOCALE_LEN]; // tsCharset
|
||||
int8_t enableBalance; // tsEnableBalance
|
||||
int8_t flowCtrl;
|
||||
int8_t slaveQuery;
|
||||
int8_t adjustMaster;
|
||||
int8_t reserved[4];
|
||||
int32_t statusInterval; // tsStatusInterval
|
||||
int8_t reserved[36];
|
||||
int64_t checkTime; // 1970-01-01 00:00:00.000
|
||||
char timezone[64]; // tsTimezone
|
||||
char locale[TSDB_LOCALE_LEN]; // tsLocale
|
||||
char charset[TSDB_LOCALE_LEN]; // tsCharset
|
||||
} SClusterCfg;
|
||||
|
||||
typedef struct SStatusMsg {
|
||||
uint32_t version;
|
||||
int32_t dnodeId;
|
||||
uint32_t lastReboot; // time stamp for last reboot
|
||||
int32_t openVnodes;
|
||||
int32_t numOfCores;
|
||||
float diskAvailable;
|
||||
int8_t reserved[36];
|
||||
char dnodeEp[TSDB_EP_LEN];
|
||||
uint32_t moduleStatus;
|
||||
uint32_t lastReboot; // time stamp for last reboot
|
||||
uint16_t reserve1; // from config file
|
||||
uint16_t openVnodes;
|
||||
uint16_t numOfCores;
|
||||
float diskAvailable; // GB
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
uint8_t alternativeRole;
|
||||
uint8_t reserve2[15];
|
||||
int64_t clusterId;
|
||||
SClusterCfg clusterCfg;
|
||||
SVnodeLoad load[];
|
||||
} SStatusMsg;
|
||||
|
||||
typedef struct {
|
||||
SMInfos mnodes;
|
||||
SDnodeCfg dnodeCfg;
|
||||
SVgroupAccess vgAccess[];
|
||||
} SStatusRsp;
|
||||
|
@ -863,9 +836,9 @@ typedef struct {
|
|||
} SCreateDnodeMsg, SDropDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char dnodeEp[TSDB_EP_LEN]; // end point, hostname:port
|
||||
SMInfos mnodes;
|
||||
int32_t dnodeId;
|
||||
int32_t mnodeNum;
|
||||
SDnodeEp mnodeEps[];
|
||||
} SCreateMnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -151,8 +151,6 @@ extern int8_t tsPrintAuth;
|
|||
extern int8_t tscEmbedded;
|
||||
extern char tsVnodeDir[];
|
||||
extern char tsMnodeDir[];
|
||||
extern char tsMnodeBakDir[];
|
||||
extern char tsMnodeTmpDir[];
|
||||
extern int64_t tsTickPerDay[3];
|
||||
extern int32_t tsTopicBianryLen;
|
||||
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <cli@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TD_RAFT_H
|
||||
#define TD_RAFT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "taosdef.h"
|
||||
|
||||
typedef unsigned int RaftId;
|
||||
typedef unsigned int RaftGroupId;
|
||||
|
||||
// buffer holding data
|
||||
typedef struct RaftBuffer {
|
||||
void* data;
|
||||
size_t len;
|
||||
} RaftBuffer;
|
||||
|
||||
// a single server information in a cluster
|
||||
typedef struct RaftServer {
|
||||
RaftId id;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
uint16_t port;
|
||||
} RaftServer;
|
||||
|
||||
// all servers in a cluster
|
||||
typedef struct RaftConfiguration {
|
||||
RaftServer *servers;
|
||||
int nServer;
|
||||
} RaftConfiguration;
|
||||
|
||||
// raft lib module
|
||||
struct Raft;
|
||||
typedef struct Raft Raft;
|
||||
|
||||
struct RaftNode;
|
||||
typedef struct RaftNode RaftNode;
|
||||
|
||||
// raft state machine
|
||||
struct RaftFSM;
|
||||
typedef struct RaftFSM {
|
||||
// statemachine user data
|
||||
void *data;
|
||||
|
||||
// apply buffer data, bufs will be free by raft module
|
||||
int (*apply)(struct RaftFSM *fsm, const RaftBuffer *bufs[], int nBufs);
|
||||
|
||||
// configuration commit callback
|
||||
int (*onConfigurationCommit)(const RaftConfiguration* cluster);
|
||||
|
||||
// fsm return snapshot in ppBuf, bufs will be free by raft module
|
||||
// TODO: getSnapshot SHOULD be async?
|
||||
int (*getSnapshot)(struct RaftFSM *fsm, RaftBuffer **ppBuf);
|
||||
|
||||
// fsm restore with pBuf data
|
||||
int (*restore)(struct RaftFSM *fsm, RaftBuffer *pBuf);
|
||||
|
||||
// fsm send data in buf to server,buf will be free by raft module
|
||||
int (*send)(struct RaftFSM* fsm, const RaftServer* server, const RaftBuffer *buf);
|
||||
} RaftFSM;
|
||||
|
||||
typedef struct RaftNodeOptions {
|
||||
// user define state machine
|
||||
RaftFSM* pFSM;
|
||||
|
||||
// election timeout(in ms)
|
||||
// by default: 1000
|
||||
int electionTimeoutMS;
|
||||
|
||||
// heart timeout(in ms)
|
||||
// by default: 100
|
||||
int heartbeatTimeoutMS;
|
||||
|
||||
// install snapshot timeout(in ms)
|
||||
int installSnapshotTimeoutMS;
|
||||
|
||||
/**
|
||||
* number of log entries before starting a new snapshot.
|
||||
* by default: 1024
|
||||
*/
|
||||
int snapshotThreshold;
|
||||
|
||||
/**
|
||||
* Number of log entries to keep in the log after a snapshot has
|
||||
* been taken.
|
||||
* by default: 128.
|
||||
*/
|
||||
int snapshotTrailing;
|
||||
|
||||
/**
|
||||
* Enable or disable pre-vote support.
|
||||
* by default: false
|
||||
*/
|
||||
bool preVote;
|
||||
|
||||
} RaftNodeOptions;
|
||||
|
||||
// create raft lib
|
||||
int RaftCreate(Raft** ppRaft);
|
||||
|
||||
int RaftDestroy(Raft* pRaft);
|
||||
|
||||
// start a raft node with options,node id,group id
|
||||
int RaftStart(Raft* pRaft,
|
||||
RaftId selfId,
|
||||
RaftGroupId selfGroupId,
|
||||
const RaftConfiguration* cluster,
|
||||
const RaftNodeOptions* options,
|
||||
RaftNode **ppNode);
|
||||
|
||||
// stop a raft node
|
||||
int RaftStop(RaftNode* pNode);
|
||||
|
||||
// client apply a cmd in buf
|
||||
typedef void (*RaftApplyFp)(const RaftBuffer *pBuf, int result);
|
||||
|
||||
int RaftApply(RaftNode *pNode,
|
||||
const RaftBuffer *pBuf,
|
||||
RaftApplyFp applyCb);
|
||||
|
||||
// recv data from other servers in cluster,buf will be free in raft
|
||||
int RaftRecv(RaftNode *pNode, const RaftBuffer* pBuf);
|
||||
|
||||
// change cluster servers API
|
||||
typedef void (*RaftChangeFp)(const RaftServer* pServer, int result);
|
||||
|
||||
int RaftAddServer(RaftNode *pNode,
|
||||
const RaftServer* pServer,
|
||||
RaftChangeFp changeCb);
|
||||
|
||||
int RaftRemoveServer(RaftNode *pNode,
|
||||
const RaftServer* pServer,
|
||||
RaftChangeFp changeCb);
|
||||
|
||||
// transfer leader to id
|
||||
typedef void (*RaftTransferFp)(RaftId id, int result);
|
||||
int RaftTransfer(RaftNode *pNode,
|
||||
RaftId id,
|
||||
RaftTransferFp transferCb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TD_RAFT_H */
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <cli@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_LIBS_SYNC_H
|
||||
#define _TD_LIBS_SYNC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "taosdef.h"
|
||||
#include "wal.h"
|
||||
|
||||
typedef int64_t SyncNodeId;
|
||||
typedef int32_t SyncGroupId;
|
||||
typedef int64_t SyncIndex;
|
||||
typedef uint64_t SSyncTerm;
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_ROLE_FOLLOWER = 0,
|
||||
TAOS_SYNC_ROLE_CANDIDATE = 1,
|
||||
TAOS_SYNC_ROLE_LEADER = 2,
|
||||
} ESyncRole;
|
||||
|
||||
typedef struct {
|
||||
void* data;
|
||||
size_t len;
|
||||
} SSyncBuffer;
|
||||
|
||||
typedef struct {
|
||||
uint16_t nodePort; // node sync Port
|
||||
char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
|
||||
} SNodeInfo;
|
||||
|
||||
typedef struct {
|
||||
int selfIndex;
|
||||
int nNode;
|
||||
SNodeInfo* nodeInfo;
|
||||
} SSyncCluster;
|
||||
|
||||
typedef struct {
|
||||
int32_t selfIndex;
|
||||
int nNode;
|
||||
SNodeInfo* node;
|
||||
ESyncRole* role;
|
||||
} SNodesRole;
|
||||
|
||||
typedef struct SSyncFSM {
|
||||
void* pData;
|
||||
|
||||
// apply committed log, bufs will be free by raft module
|
||||
int (*applyLog)(struct SSyncFSM* fsm, SyncIndex index, const SSyncBuffer* buf, void* pData);
|
||||
|
||||
// cluster commit callback
|
||||
int (*onClusterChanged)(struct SSyncFSM* fsm, const SSyncCluster* cluster, void* pData);
|
||||
|
||||
// fsm return snapshot in ppBuf, bufs will be free by raft module
|
||||
// TODO: getSnapshot SHOULD be async?
|
||||
int (*getSnapshot)(struct SSyncFSM* fsm, SSyncBuffer** ppBuf, int* objId, bool* isLast);
|
||||
|
||||
// fsm apply snapshot with pBuf data
|
||||
int (*applySnapshot)(struct SSyncFSM* fsm, SSyncBuffer* pBuf, int objId, bool isLast);
|
||||
|
||||
// call when restore snapshot and log done
|
||||
int (*onRestoreDone)(struct SSyncFSM* fsm);
|
||||
|
||||
void (*onRollback)(struct SSyncFSM* fsm, SyncIndex index, const SSyncBuffer* buf);
|
||||
|
||||
void (*onRoleChanged)(struct SSyncFSM* fsm, const SNodesRole* pRole);
|
||||
|
||||
} SSyncFSM;
|
||||
|
||||
typedef struct SSyncServerState {
|
||||
SNodeInfo voteFor;
|
||||
SSyncTerm term;
|
||||
} SSyncServerState;
|
||||
|
||||
typedef struct SStateManager {
|
||||
void* pData;
|
||||
|
||||
void (*saveServerState)(struct SStateManager* stateMng, const SSyncServerState* state);
|
||||
|
||||
const SSyncServerState* (*readServerState)(struct SStateManager* stateMng);
|
||||
|
||||
void (*saveCluster)(struct SStateManager* stateMng, const SSyncCluster* cluster);
|
||||
|
||||
const SSyncCluster* (*readCluster)(struct SStateManager* stateMng);
|
||||
} SStateManager;
|
||||
|
||||
typedef struct {
|
||||
SyncGroupId vgId;
|
||||
|
||||
twalh walHandle;
|
||||
|
||||
SyncIndex snapshotIndex;
|
||||
SSyncCluster syncCfg;
|
||||
|
||||
SSyncFSM fsm;
|
||||
|
||||
SStateManager stateManager;
|
||||
} SSyncInfo;
|
||||
|
||||
int32_t syncInit();
|
||||
void syncCleanUp();
|
||||
|
||||
SyncNodeId syncStart(const SSyncInfo*);
|
||||
void syncStop(SyncNodeId);
|
||||
|
||||
int32_t syncPropose(SyncNodeId nodeId, SSyncBuffer buffer, void* pData, bool isWeak);
|
||||
|
||||
int32_t syncAddNode(SyncNodeId nodeId, const SNodeInfo *pNode);
|
||||
|
||||
int32_t syncRemoveNode(SyncNodeId nodeId, const SNodeInfo *pNode);
|
||||
|
||||
extern int32_t syncDebugFlag;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_LIBS_SYNC_H*/
|
|
@ -58,9 +58,9 @@ void walStop(twalh);
|
|||
void walClose(twalh);
|
||||
|
||||
//write
|
||||
int64_t walWriteWithMsgType(twalh, int8_t msgType, void* body, int32_t bodyLen);
|
||||
//int64_t walWriteWithMsgType(twalh, int8_t msgType, void* body, int32_t bodyLen);
|
||||
int64_t walWrite(twalh, void* body, int32_t bodyLen);
|
||||
int64_t walWriteBatch(twalh, void* body, int32_t* bodyLen, int32_t batchSize);
|
||||
int64_t walWriteBatch(twalh, void** bodies, int32_t* bodyLen, int32_t batchSize);
|
||||
|
||||
//apis for lifecycle management
|
||||
void walFsync(twalh, bool force);
|
||||
|
|
|
@ -178,6 +178,12 @@ extern "C" {
|
|||
#define setThreadName(name)
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define TD_DIRSEP "\\"
|
||||
#else
|
||||
#define TD_DIRSEP "/"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -65,7 +65,7 @@ void dnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell);
|
|||
* @param fqdn, the fqdn of dnode.
|
||||
* @param port, the port of dnode.
|
||||
*/
|
||||
void dnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||
void dnodeGetEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { MN_STATUS_UNINIT = 0, MN_STATUS_INIT = 1, MN_STATUS_READY = 2, MN_STATUS_CLOSING = 3 } EMnStatus;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* Send messages to other dnodes, such as create vnode message.
|
||||
|
@ -54,13 +56,12 @@ typedef struct {
|
|||
* @param port, the port of dnode.
|
||||
*/
|
||||
void (*GetDnodeEp)(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||
|
||||
} SMnodeFp;
|
||||
|
||||
typedef struct {
|
||||
SMnodeFp fp;
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
int32_t dnodeId;
|
||||
SMnodeFp fp;
|
||||
int64_t clusterId;
|
||||
int32_t dnodeId;
|
||||
} SMnodePara;
|
||||
|
||||
/**
|
||||
|
@ -79,10 +80,9 @@ void mnodeCleanup();
|
|||
/**
|
||||
* Deploy mnode instances in dnode.
|
||||
*
|
||||
* @param minfos, server information used to deploy the mnode instance.
|
||||
* @return Error Code.
|
||||
*/
|
||||
int32_t mnodeDeploy(struct SMInfos *minfos);
|
||||
int32_t mnodeDeploy();
|
||||
|
||||
/**
|
||||
* Delete the mnode instance deployed in dnode.
|
||||
|
@ -94,7 +94,7 @@ void mnodeUnDeploy();
|
|||
*
|
||||
* @return Server status.
|
||||
*/
|
||||
bool mnodeIsServing();
|
||||
EMnStatus mnodeGetStatus();
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfDnode;
|
||||
|
|
|
@ -24,9 +24,10 @@ extern "C" {
|
|||
|
||||
typedef struct tmqMsgHead {
|
||||
int32_t headLen;
|
||||
int32_t msgVer;
|
||||
int32_t protoVer;
|
||||
int64_t cgId;
|
||||
int64_t topicId;
|
||||
int64_t clientId;
|
||||
int32_t checksum;
|
||||
int32_t msgType;
|
||||
} tmqMsgHead;
|
||||
|
@ -34,35 +35,43 @@ typedef struct tmqMsgHead {
|
|||
//TODO: put msgs into common
|
||||
typedef struct tmqConnectReq {
|
||||
tmqMsgHead head;
|
||||
|
||||
} tmqConnectReq;
|
||||
|
||||
typedef struct tmqConnectResp {
|
||||
|
||||
tmqMsgHead head;
|
||||
int8_t status;
|
||||
} tmqConnectResp;
|
||||
|
||||
typedef struct tmqDisconnectReq {
|
||||
|
||||
tmqMsgHead head;
|
||||
} tmqDisconnectReq;
|
||||
|
||||
typedef struct tmqDisconnectResp {
|
||||
|
||||
tmqMsgHead head;
|
||||
int8_t status;
|
||||
} tmqDiconnectResp;
|
||||
|
||||
typedef struct tmqConsumeReq {
|
||||
|
||||
tmqMsgHead head;
|
||||
int64_t commitOffset;
|
||||
} tmqConsumeReq;
|
||||
|
||||
typedef struct tmqConsumeResp {
|
||||
|
||||
tmqMsgHead head;
|
||||
char content[];
|
||||
} tmqConsumeResp;
|
||||
|
||||
typedef struct tmqSubscribeReq {
|
||||
|
||||
//
|
||||
typedef struct tmqMnodeSubscribeReq {
|
||||
tmqMsgHead head;
|
||||
int64_t topicLen;
|
||||
char topic[];
|
||||
} tmqSubscribeReq;
|
||||
|
||||
typedef struct tmqSubscribeResp {
|
||||
|
||||
typedef struct tmqMnodeSubscribeResp {
|
||||
tmqMsgHead head;
|
||||
int64_t vgId;
|
||||
char ep[]; //TSDB_EP_LEN
|
||||
} tmqSubscribeResp;
|
||||
|
||||
typedef struct tmqHeartbeatReq {
|
||||
|
@ -92,6 +101,24 @@ typedef struct STQ {
|
|||
//value=consumeOffset: int64_t
|
||||
} STQ;
|
||||
|
||||
#define TQ_BUFFER_SIZE 8
|
||||
|
||||
typedef struct tqBufferItem {
|
||||
int64_t offset;
|
||||
void* executor;
|
||||
void* content;
|
||||
} tqBufferItem;
|
||||
|
||||
typedef struct tqGroupHandle {
|
||||
char* topic; //c style, end with '\0'
|
||||
int64_t cgId;
|
||||
void* ahandle;
|
||||
int64_t consumeOffset;
|
||||
int32_t head;
|
||||
int32_t tail;
|
||||
tqBufferItem buffer[TQ_BUFFER_SIZE];
|
||||
} tqGroupHandle;
|
||||
|
||||
//init in each vnode
|
||||
STQ* tqInit(void* ref_func(void*), void* unref_func(void*));
|
||||
void tqCleanUp(STQ*);
|
||||
|
@ -103,6 +130,17 @@ int tqCommit(STQ*);
|
|||
//void* will be replace by a msg type
|
||||
int tqHandleConsumeMsg(STQ*, tmqConsumeReq* msg);
|
||||
|
||||
tqGroupHandle* tqFindGHandleBycId(STQ*, int64_t cId);
|
||||
|
||||
int tqOpenTCGroup(STQ*, int64_t topicId, int64_t cgId, int64_t cId);
|
||||
int tqCloseTCGroup(STQ*, int64_t topicId, int64_t cgId, int64_t cId);
|
||||
int tqMoveOffsetToNext(tqGroupHandle*);
|
||||
int tqResetOffset(STQ*, int64_t topicId, int64_t cgId, int64_t offset);
|
||||
int tqFetchMsg(tqGroupHandle*, void*);
|
||||
int tqRegisterContext(tqGroupHandle*, void*);
|
||||
int tqLaunchQuery(STQ*, int64_t topicId, int64_t cgId, void* query);
|
||||
int tqSendLaunchQuery(STQ*, int64_t topicId, int64_t cgId, void* query);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -166,6 +166,9 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0354) //"Can not get user from conn")
|
||||
#define TSDB_CODE_MND_TOO_MANY_USERS TAOS_DEF_ERROR_CODE(0, 0x0355) //"Too many users")
|
||||
|
||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0348) //"Mnode already exists")
|
||||
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0349) //"Mnode not there")
|
||||
|
||||
#define TSDB_CODE_MND_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) //"Table already exists")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist")
|
||||
|
|
|
@ -62,6 +62,7 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_DATA_NULL_STR "NULL"
|
||||
#define TSDB_DATA_NULL_STR_L "null"
|
||||
|
||||
#define TSDB_NETTEST_USER "nettestinternal"
|
||||
#define TSDB_DEFAULT_USER "root"
|
||||
#ifdef _TD_POWER_
|
||||
#define TSDB_DEFAULT_PASS "powerdb"
|
||||
|
|
|
@ -20,14 +20,15 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SSteps SSteps;
|
||||
typedef int32_t (*InitFp)();
|
||||
typedef void (*CleanupFp)();
|
||||
typedef void (*ReportFp)(char *name, char *desc);
|
||||
|
||||
struct SSteps *taosStepInit(int32_t maxsize, ReportFp fp);
|
||||
int32_t taosStepExec(struct SSteps *steps);
|
||||
void taosStepCleanup(struct SSteps *steps);
|
||||
int32_t taosStepAdd(struct SSteps *steps, char *name, InitFp initFp, CleanupFp cleanupFp);
|
||||
SSteps *taosStepInit(int32_t maxsize, ReportFp fp);
|
||||
int32_t taosStepExec(SSteps *steps);
|
||||
void taosStepCleanup(SSteps *steps);
|
||||
int32_t taosStepAdd(SSteps *steps, char *name, InitFp initFp, CleanupFp cleanupFp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_UTIL_WORKER_H
|
||||
#define _TD_UTIL_WORKER_H
|
||||
|
||||
#include "tqueue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -7,4 +7,4 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
taos
|
||||
INTERFACE api
|
||||
)
|
||||
)
|
||||
|
|
|
@ -19,3 +19,5 @@
|
|||
//
|
||||
//}
|
||||
|
||||
int taos_init() { return 0; }
|
||||
void taos_cleanup(void) {}
|
||||
|
|
|
@ -201,8 +201,6 @@ int8_t tscEmbedded = 0;
|
|||
char tsVnodeDir[PATH_MAX] = {0};
|
||||
char tsDnodeDir[PATH_MAX] = {0};
|
||||
char tsMnodeDir[PATH_MAX] = {0};
|
||||
char tsMnodeTmpDir[PATH_MAX] = {0};
|
||||
char tsMnodeBakDir[PATH_MAX] = {0};
|
||||
|
||||
int32_t tsDiskCfgNum = 0;
|
||||
int32_t tsTopicBianryLen = 16000;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
add_subdirectory(transport)
|
||||
add_subdirectory(raft)
|
||||
add_subdirectory(sync)
|
||||
add_subdirectory(tkv)
|
||||
add_subdirectory(index)
|
||||
add_subdirectory(wal)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
aux_source_directory(src RAFT_SRC)
|
||||
add_library(raft ${RAFT_SRC})
|
||||
target_include_directories(
|
||||
raft
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/raft"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
aux_source_directory(src SYNC_SRC)
|
||||
add_library(sync ${SYNC_SRC})
|
||||
|
||||
target_link_libraries(
|
||||
sync
|
||||
PUBLIC common
|
||||
PUBLIC util
|
||||
PUBLIC wal
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
sync
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -11,4 +11,9 @@
|
|||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "sync.h"
|
||||
|
||||
int32_t syncInit() {return 0;}
|
||||
void syncCleanUp() {}
|
|
@ -11,4 +11,9 @@
|
|||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "wal.h"
|
||||
|
||||
int32_t walInit() {return 0;}
|
||||
void walCleanUp() {}
|
|
@ -5,6 +5,9 @@ target_link_libraries(
|
|||
PUBLIC cjson
|
||||
PUBLIC mnode
|
||||
PUBLIC vnode
|
||||
PUBLIC wal
|
||||
PUBLIC sync
|
||||
PUBLIC taos
|
||||
)
|
||||
target_include_directories(
|
||||
dnode
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_CFG_H_
|
||||
#define _TD_DNODE_CFG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
|
||||
|
||||
int32_t dnodeInitCfg();
|
||||
void dnodeCleanupCfg();
|
||||
void dnodeUpdateCfg(SDnodeCfg *data);
|
||||
int32_t dnodeGetDnodeId();
|
||||
void dnodeGetClusterId(char *clusterId);
|
||||
void dnodeGetCfg(int32_t *dnodeId, char *clusterId);
|
||||
void dnodeSetDropped();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_CFG_H_*/
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
#include "dnodeInt.h"
|
||||
|
||||
|
||||
int32_t dnodeInitCheck();
|
||||
void dnodeCleanupCheck();
|
||||
|
||||
|
|
|
@ -23,9 +23,17 @@ extern "C" {
|
|||
|
||||
int32_t dnodeInitEps();
|
||||
void dnodeCleanupEps();
|
||||
void dnodeUpdateEps(SDnodeEps *data);
|
||||
bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr);
|
||||
void dnodeGetDnodeEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port);
|
||||
|
||||
void dnodeUpdateCfg(SDnodeCfg *data);
|
||||
void dnodeUpdateDnodeEps(SDnodeEps *data);
|
||||
void dnodeUpdateMnodeEps(SRpcEpSet *pEpSet);
|
||||
int32_t dnodeGetDnodeId();
|
||||
int64_t dnodeGetClusterId();
|
||||
void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port);
|
||||
|
||||
void dnodeGetEpSetForPeer(SRpcEpSet *epSet);
|
||||
void dnodeGetEpSetForShell(SRpcEpSet *epSet);
|
||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "dnode.h"
|
||||
|
||||
extern int32_t dDebugFlag;
|
||||
|
@ -33,6 +36,12 @@ extern int32_t dDebugFlag;
|
|||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef enum { DN_RUN_STAT_INIT, DN_RUN_STAT_RUNNING, DN_RUN_STAT_STOPPED } EDnStat;
|
||||
|
||||
EDnStat dnodeGetRunStat();
|
||||
void dnodeSetRunStat();
|
||||
void dnodeGetStartup(SStartupStep *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_MAIN_H_
|
||||
#define _TD_DNODE_MAIN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
|
||||
typedef enum {
|
||||
TD_RUN_STAT_INIT,
|
||||
TD_RUN_STAT_RUNNING,
|
||||
TD_RUN_STAT_STOPPED
|
||||
} RunStat;
|
||||
|
||||
int32_t dnodeInitMain();
|
||||
void dnodeCleanupMain();
|
||||
int32_t dnodeInitStorage();
|
||||
void dnodeCleanupStorage();
|
||||
void dnodeReportStartup(char *name, char *desc);
|
||||
void dnodeReportStartupFinished(char *name, char *desc);
|
||||
void dnodeProcessStartupReq(SRpcMsg *pMsg);
|
||||
void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg);
|
||||
void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg);
|
||||
RunStat dnodeGetRunStat();
|
||||
void dnodeSetRunStat();
|
||||
void* dnodeGetTimer();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_MAIN_H_*/
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_MNODE_EP_H_
|
||||
#define _TD_DNODE_MNODE_EP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
|
||||
int32_t dnodeInitMnodeEps();
|
||||
void dnodeCleanupMnodeEps();
|
||||
void dnodeUpdateMnodeFromStatus(SMInfos *pMinfos);
|
||||
void dnodeUpdateMnodeFromPeer(SRpcEpSet *pEpSet);
|
||||
void dnodeGetEpSetForPeer(SRpcEpSet *epSet);
|
||||
void dnodeGetEpSetForShell(SRpcEpSet *epSet);
|
||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_MNODE_EP_H_*/
|
|
@ -21,9 +21,12 @@ extern "C" {
|
|||
#endif
|
||||
#include "dnodeInt.h"
|
||||
|
||||
int32_t dnodeInitStatus();
|
||||
void dnodeCleanupStatus();
|
||||
int32_t dnodeInitMsg();
|
||||
void dnodeCleanupMsg();
|
||||
void dnodeProcessStatusRsp(SRpcMsg *pMsg);
|
||||
void dnodeProcessStartupReq(SRpcMsg *pMsg);
|
||||
void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg);
|
||||
void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -25,7 +25,6 @@ int32_t dnodeInitTrans();
|
|||
void dnodeCleanupTrans();
|
||||
void dnodeSendMsgToMnode(SRpcMsg *rpcMsg);
|
||||
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg);
|
||||
void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp, SRpcEpSet *epSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "cJSON.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeCfg.h"
|
||||
|
||||
static struct DnCfg {
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
char file[PATH_MAX + 20];
|
||||
pthread_mutex_t mutex;
|
||||
} tsDcfg;
|
||||
|
||||
static int32_t dnodeReadCfg() {
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 200;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
cJSON * root = NULL;
|
||||
FILE * fp = NULL;
|
||||
|
||||
fp = fopen(tsDcfg.file, "r");
|
||||
if (!fp) {
|
||||
dDebug("file %s not exist", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_Number) {
|
||||
dError("failed to read %s since dnodeId not found", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
tsDcfg.dnodeId = (int32_t)dnodeId->valueint;
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
tsDcfg.dropped = (int32_t)dropped->valueint;
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", tsDcfg.file);
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
tstrncpy(tsDcfg.clusterId, clusterId->valuestring, TSDB_CLUSTER_ID_LEN);
|
||||
|
||||
dInfo("successed to read %s", tsDcfg.file);
|
||||
|
||||
PARSE_CFG_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
terrno = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeWriteCfg() {
|
||||
FILE *fp = fopen(tsDcfg.file, "w");
|
||||
if (!fp) {
|
||||
dError("failed to write %s since %s", tsDcfg.file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 200;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsDcfg.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", tsDcfg.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%s\"\n", tsDcfg.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
dInfo("successed to write %s", tsDcfg.file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dnodeInitCfg() {
|
||||
tsDcfg.dnodeId = 0;
|
||||
tsDcfg.dropped = 0;
|
||||
tsDcfg.clusterId[0] = 0;
|
||||
snprintf(tsDcfg.file, sizeof(tsDcfg.file), "%s/dnodeCfg.json", tsDnodeDir);
|
||||
pthread_mutex_init(&tsDcfg.mutex, NULL);
|
||||
|
||||
int32_t ret = dnodeReadCfg();
|
||||
if (ret == 0) {
|
||||
dInfo("dnode cfg is initialized");
|
||||
}
|
||||
|
||||
if (tsDcfg.dropped) {
|
||||
dInfo("dnode is dropped and start to exit");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dnodeCleanupCfg() {
|
||||
pthread_mutex_destroy(&tsDcfg.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateCfg(SDnodeCfg *data) {
|
||||
if (tsDcfg.dnodeId != 0) return;
|
||||
|
||||
pthread_mutex_lock(&tsDcfg.mutex);
|
||||
|
||||
tsDcfg.dnodeId = data->dnodeId;
|
||||
tstrncpy(tsDcfg.clusterId, data->clusterId, TSDB_CLUSTER_ID_LEN);
|
||||
dInfo("dnodeId is set to %d, clusterId is set to %s", data->dnodeId, data->clusterId);
|
||||
|
||||
dnodeWriteCfg();
|
||||
pthread_mutex_unlock(&tsDcfg.mutex);
|
||||
}
|
||||
|
||||
void dnodeSetDropped() {
|
||||
pthread_mutex_lock(&tsDcfg.mutex);
|
||||
tsDcfg.dropped = 1;
|
||||
dnodeWriteCfg();
|
||||
pthread_mutex_unlock(&tsDcfg.mutex);
|
||||
}
|
||||
|
||||
int32_t dnodeGetDnodeId() {
|
||||
int32_t dnodeId = 0;
|
||||
pthread_mutex_lock(&tsDcfg.mutex);
|
||||
dnodeId = tsDcfg.dnodeId;
|
||||
pthread_mutex_unlock(&tsDcfg.mutex);
|
||||
return dnodeId;
|
||||
}
|
||||
|
||||
void dnodeGetClusterId(char *clusterId) {
|
||||
pthread_mutex_lock(&tsDcfg.mutex);
|
||||
tstrncpy(clusterId, tsDcfg.clusterId, TSDB_CLUSTER_ID_LEN);
|
||||
pthread_mutex_unlock(&tsDcfg.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetCfg(int32_t *dnodeId, char *clusterId) {
|
||||
pthread_mutex_lock(&tsDcfg.mutex);
|
||||
*dnodeId = tsDcfg.dnodeId;
|
||||
tstrncpy(clusterId, tsDcfg.clusterId, TSDB_CLUSTER_ID_LEN);
|
||||
pthread_mutex_unlock(&tsDcfg.mutex);
|
||||
}
|
|
@ -14,8 +14,6 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeCheck.h"
|
||||
|
||||
#define MIN_AVAIL_MEMORY_MB 32
|
||||
|
|
|
@ -14,131 +14,250 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "cJSON.h"
|
||||
#include "thash.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "dnodeCfg.h"
|
||||
|
||||
static struct {
|
||||
int32_t dnodeId;
|
||||
int32_t dnodeNum;
|
||||
SDnodeEp * dnodeList;
|
||||
SHashObj * dnodeHash;
|
||||
char file[PATH_MAX + 20];
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
SDnodeEps *dnodeEps;
|
||||
SHashObj *dnodeHash;
|
||||
SRpcEpSet mnodeEpSetForShell;
|
||||
SRpcEpSet mnodeEpSetForPeer;
|
||||
char file[PATH_MAX + 20];
|
||||
pthread_mutex_t mutex;
|
||||
} tsDeps;
|
||||
} tsEps;
|
||||
|
||||
void dnodeGetEpSetForPeer(SRpcEpSet *epSet) {
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
*epSet = tsEps.mnodeEpSetForPeer;
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetEpSetForShell(SRpcEpSet *epSet) {
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
*epSet = tsEps.mnodeEpSetForShell;
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateMnodeEps(SRpcEpSet *ep) {
|
||||
if (ep != NULL || ep->numOfEps <= 0) {
|
||||
dError("mnode is changed, but content is invalid, discard it");
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
dInfo("mnode is changed, num:%d use:%d", ep->numOfEps, ep->inUse);
|
||||
|
||||
tsEps.mnodeEpSetForPeer = *ep;
|
||||
for (int32_t i = 0; i < ep->numOfEps; ++i) {
|
||||
ep->port[i] -= TSDB_PORT_DNODEDNODE;
|
||||
dInfo("mnode index:%d %s:%u", i, ep->fqdn[i], ep->port[i]);
|
||||
}
|
||||
tsEps.mnodeEpSetForShell = *ep;
|
||||
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
rpcGetConnInfo(rpcMsg->handle, &connInfo);
|
||||
|
||||
SRpcEpSet epSet = {0};
|
||||
if (forShell) {
|
||||
dnodeGetEpSetForShell(&epSet);
|
||||
} else {
|
||||
dnodeGetEpSetForPeer(&epSet);
|
||||
}
|
||||
|
||||
dDebug("msg:%s will be redirected, num:%d use:%d", taosMsg[rpcMsg->msgType], epSet.numOfEps, epSet.inUse);
|
||||
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%d", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], tsLocalFqdn) == 0) {
|
||||
if ((epSet.port[i] == tsServerPort + TSDB_PORT_DNODEDNODE && !forShell) ||
|
||||
(epSet.port[i] == tsServerPort && forShell)) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse);
|
||||
}
|
||||
}
|
||||
|
||||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(rpcMsg->handle, &epSet);
|
||||
}
|
||||
|
||||
static void dnodePrintEps() {
|
||||
dDebug("print dnodeEp, dnodeNum:%d", tsDeps.dnodeNum);
|
||||
for (int32_t i = 0; i < tsDeps.dnodeNum; i++) {
|
||||
SDnodeEp *ep = &tsDeps.dnodeList[i];
|
||||
dDebug("dnode:%d, dnodeFqdn:%s dnodePort:%u", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort);
|
||||
dDebug("print dnode list, num:%d", tsEps.dnodeEps->dnodeNum);
|
||||
for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; i++) {
|
||||
SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i];
|
||||
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort, ep->isMnode);
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeResetEps(SDnodeEps *data) {
|
||||
assert(data != NULL);
|
||||
|
||||
if (data->dnodeNum > tsDeps.dnodeNum) {
|
||||
SDnodeEp *tmp = calloc(data->dnodeNum, sizeof(SDnodeEp));
|
||||
int32_t size = sizeof(SDnodeEps) + data->dnodeNum * sizeof(SDnodeEp);
|
||||
|
||||
if (data->dnodeNum > tsEps.dnodeEps->dnodeNum) {
|
||||
SDnodeEps *tmp = calloc(1, size);
|
||||
if (tmp == NULL) return;
|
||||
|
||||
tfree(tsDeps.dnodeList);
|
||||
tsDeps.dnodeList = tmp;
|
||||
tsDeps.dnodeNum = data->dnodeNum;
|
||||
memcpy(tsDeps.dnodeList, data->dnodeEps, tsDeps.dnodeNum * sizeof(SDnodeEp));
|
||||
dnodePrintEps();
|
||||
|
||||
for (int32_t i = 0; i < tsDeps.dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsDeps.dnodeList[i];
|
||||
taosHashPut(tsDeps.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp));
|
||||
}
|
||||
tfree(tsEps.dnodeEps);
|
||||
tsEps.dnodeEps = tmp;
|
||||
}
|
||||
|
||||
if (tsEps.dnodeEps != data) {
|
||||
memcpy(tsEps.dnodeEps, data, size);
|
||||
}
|
||||
|
||||
tsEps.mnodeEpSetForPeer.inUse = 0;
|
||||
tsEps.mnodeEpSetForShell.inUse = 0;
|
||||
int32_t index = 0;
|
||||
for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; i++) {
|
||||
SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i];
|
||||
if (!ep->isMnode) continue;
|
||||
if (index >= TSDB_MAX_REPLICA) continue;
|
||||
strcpy(tsEps.mnodeEpSetForShell.fqdn[index], ep->dnodeFqdn);
|
||||
strcpy(tsEps.mnodeEpSetForPeer.fqdn[index], ep->dnodeFqdn);
|
||||
tsEps.mnodeEpSetForShell.port[index] = ep->dnodePort;
|
||||
tsEps.mnodeEpSetForShell.port[index] = ep->dnodePort + tsDnodeDnodePort;
|
||||
index++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i];
|
||||
taosHashPut(tsEps.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp));
|
||||
}
|
||||
|
||||
dnodePrintEps();
|
||||
}
|
||||
|
||||
static bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) {
|
||||
bool changed = false;
|
||||
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
SDnodeEp *ep = taosHashGet(tsEps.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (ep != NULL) {
|
||||
char epSaved[TSDB_EP_LEN + 1];
|
||||
snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort);
|
||||
changed = strcmp(epstr, epSaved) != 0;
|
||||
tstrncpy(epstr, epSaved, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int32_t dnodeReadEps() {
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
cJSON * root = NULL;
|
||||
FILE * fp = NULL;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen(tsDeps.file, "r");
|
||||
fp = fopen(tsEps.file, "r");
|
||||
if (!fp) {
|
||||
dDebug("file %s not exist", tsDeps.file);
|
||||
dDebug("file %s not exist", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", tsDeps.file);
|
||||
dError("failed to read %s since content is null", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", tsDeps.file);
|
||||
dError("failed to read %s since invalid json format", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
cJSON *dnodeNum = cJSON_GetObjectItem(root, "dnodeNum");
|
||||
if (!dnodeNum || dnodeNum->type != cJSON_Number) {
|
||||
dError("failed to read %s since dnodeNum not found", tsDeps.file);
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s since dnodeId not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
tsEps.dnodeId = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
dError("failed to read %s since dropped not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
tsEps.dropped = atoi(dropped->valuestring);
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
tsEps.clusterId = atoll(clusterId->valuestring);
|
||||
|
||||
cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos");
|
||||
if (!dnodeInfos || dnodeInfos->type != cJSON_Array) {
|
||||
dError("failed to read %s since dnodeInfos not found", tsDeps.file);
|
||||
dError("failed to read %s since dnodeInfos not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos);
|
||||
if (dnodeInfosSize != dnodeNum->valueint) {
|
||||
dError("failed to read %s since dnodeInfos size:%d not matched dnodeNum:%d", tsDeps.file, dnodeInfosSize,
|
||||
(int32_t)dnodeNum->valueint);
|
||||
if (dnodeInfosSize <= 0) {
|
||||
dError("failed to read %s since dnodeInfos size:%d invalid", tsEps.file, dnodeInfosSize);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
|
||||
tsDeps.dnodeNum = dnodeInfosSize;
|
||||
tsDeps.dnodeList = calloc(dnodeInfosSize, sizeof(SDnodeEp));
|
||||
if (tsDeps.dnodeList == NULL) {
|
||||
tsEps.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps));
|
||||
if (tsEps.dnodeEps == NULL) {
|
||||
dError("failed to calloc dnodeEpList since %s", strerror(errno));
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
tsEps.dnodeEps->dnodeNum = dnodeInfosSize;
|
||||
|
||||
for (int32_t i = 0; i < dnodeInfosSize; ++i) {
|
||||
cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i);
|
||||
if (dnodeInfo == NULL) break;
|
||||
|
||||
SDnodeEp *ep = &tsDeps.dnodeList[i];
|
||||
SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i];
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_Number) {
|
||||
dError("failed to read %s, dnodeId not found", tsDeps.file);
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodeId not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
ep->dnodeId = (int32_t)dnodeId->valueint;
|
||||
ep->dnodeId = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode");
|
||||
if (!isMnode || isMnode->type != cJSON_String) {
|
||||
dError("failed to read %s, isMnode not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
ep->isMnode = atoi(isMnode->valuestring);
|
||||
|
||||
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
|
||||
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||
dError("failed to read %s, dnodeFqdn not found", tsDeps.file);
|
||||
dError("failed to read %s, dnodeFqdn not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
tstrncpy(ep->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN);
|
||||
|
||||
cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort");
|
||||
if (!dnodePort || dnodePort->type != cJSON_Number) {
|
||||
dError("failed to read %s, dnodePort not found", tsDeps.file);
|
||||
if (!dnodePort || dnodePort->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodePort not found", tsEps.file);
|
||||
goto PRASE_EPS_OVER;
|
||||
}
|
||||
ep->dnodePort = (uint16_t)dnodePort->valueint;
|
||||
ep->dnodePort = atoi(dnodePort->valuestring);
|
||||
}
|
||||
|
||||
dInfo("succcessed to read file %s", tsDeps.file);
|
||||
dInfo("succcessed to read file %s", tsEps.file);
|
||||
dnodePrintEps();
|
||||
|
||||
PRASE_EPS_OVER:
|
||||
|
@ -146,35 +265,40 @@ PRASE_EPS_OVER:
|
|||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
if (dnodeIsDnodeEpChanged(tsDeps.dnodeId, tsLocalEp)) {
|
||||
dError("dnode:%d, localEp different from %s dnodeEps.json and need reconfigured", tsDeps.dnodeId, tsLocalEp);
|
||||
if (dnodeIsDnodeEpChanged(tsEps.dnodeId, tsLocalEp)) {
|
||||
dError("dnode:%d, localEp %s different with dnodeEps.json and need reconfigured", tsEps.dnodeId, tsLocalEp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dnodeResetEps(tsEps.dnodeEps);
|
||||
|
||||
terrno = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeWriteEps() {
|
||||
FILE *fp = fopen(tsDeps.file, "w");
|
||||
FILE *fp = fopen(tsEps.file, "w");
|
||||
if (!fp) {
|
||||
dError("failed to write %s since %s", tsDeps.file, strerror(errno));
|
||||
dError("failed to write %s since %s", tsEps.file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeNum\": %d,\n", tsDeps.dnodeNum);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsEps.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsEps.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsEps.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n");
|
||||
for (int32_t i = 0; i < tsDeps.dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsDeps.dnodeList[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", ep->dnodeId);
|
||||
for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", ep->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", ep->isMnode);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodePort\": %u\n", ep->dnodePort);
|
||||
if (i < tsDeps.dnodeNum - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", ep->dnodePort);
|
||||
if (i < tsEps.dnodeEps->dnodeNum - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
|
@ -188,18 +312,20 @@ static int32_t dnodeWriteEps() {
|
|||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
dInfo("successed to write %s", tsDeps.file);
|
||||
dInfo("successed to write %s", tsEps.file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dnodeInitEps() {
|
||||
tsDeps.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (tsDeps.dnodeHash == NULL) return -1;
|
||||
tsEps.dnodeId = 0;
|
||||
tsEps.dropped = 0;
|
||||
tsEps.clusterId = 0;
|
||||
tsEps.dnodeEps = NULL;
|
||||
snprintf(tsEps.file, sizeof(tsEps.file), "%s/dnodeEps.json", tsDnodeDir);
|
||||
pthread_mutex_init(&tsEps.mutex, NULL);
|
||||
|
||||
tsDeps.dnodeId = dnodeGetDnodeId();
|
||||
tsDeps.dnodeNum = 0;
|
||||
snprintf(tsDeps.file, sizeof(tsDeps.file), "%s/dnodeEps.json", tsDnodeDir);
|
||||
pthread_mutex_init(&tsDeps.mutex, NULL);
|
||||
tsEps.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (tsEps.dnodeHash == NULL) return -1;
|
||||
|
||||
int32_t ret = dnodeReadEps();
|
||||
if (ret == 0) {
|
||||
|
@ -210,75 +336,80 @@ int32_t dnodeInitEps() {
|
|||
}
|
||||
|
||||
void dnodeCleanupEps() {
|
||||
pthread_mutex_lock(&tsDeps.mutex);
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
if (tsDeps.dnodeList != NULL) {
|
||||
free(tsDeps.dnodeList);
|
||||
tsDeps.dnodeList = NULL;
|
||||
if (tsEps.dnodeEps != NULL) {
|
||||
free(tsEps.dnodeEps);
|
||||
tsEps.dnodeEps = NULL;
|
||||
}
|
||||
|
||||
if (tsDeps.dnodeHash) {
|
||||
taosHashCleanup(tsDeps.dnodeHash);
|
||||
tsDeps.dnodeHash = NULL;
|
||||
if (tsEps.dnodeHash) {
|
||||
taosHashCleanup(tsEps.dnodeHash);
|
||||
tsEps.dnodeHash = NULL;
|
||||
}
|
||||
|
||||
tsDeps.dnodeNum = 0;
|
||||
pthread_mutex_unlock(&tsDeps.mutex);
|
||||
pthread_mutex_destroy(&tsDeps.mutex);
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
pthread_mutex_destroy(&tsEps.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateEps(SDnodeEps *data) {
|
||||
void dnodeUpdateDnodeEps(SDnodeEps *data) {
|
||||
if (data == NULL || data->dnodeNum <= 0) return;
|
||||
|
||||
data->dnodeNum = htonl(data->dnodeNum);
|
||||
for (int32_t i = 0; i < data->dnodeNum; ++i) {
|
||||
data->dnodeEps[i].dnodeId = htonl(data->dnodeEps[i].dnodeId);
|
||||
data->dnodeEps[i].dnodePort = htons(data->dnodeEps[i].dnodePort);
|
||||
}
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
pthread_mutex_lock(&tsDeps.mutex);
|
||||
|
||||
if (data->dnodeNum != tsDeps.dnodeNum) {
|
||||
if (data->dnodeNum != tsEps.dnodeEps->dnodeNum) {
|
||||
dnodeResetEps(data);
|
||||
dnodeWriteEps();
|
||||
} else {
|
||||
int32_t size = data->dnodeNum * sizeof(SDnodeEp);
|
||||
if (memcmp(tsDeps.dnodeList, data->dnodeEps, size) != 0) {
|
||||
int32_t size = data->dnodeNum * sizeof(SDnodeEp) + sizeof(SDnodeEps);
|
||||
if (memcmp(tsEps.dnodeEps, data, size) != 0) {
|
||||
dnodeResetEps(data);
|
||||
dnodeWriteEps();
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDeps.mutex);
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) {
|
||||
bool changed = false;
|
||||
void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) {
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
pthread_mutex_lock(&tsDeps.mutex);
|
||||
|
||||
SDnodeEp *ep = taosHashGet(tsDeps.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (ep != NULL) {
|
||||
char epSaved[TSDB_EP_LEN + 1];
|
||||
snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort);
|
||||
changed = strcmp(epstr, epSaved) != 0;
|
||||
tstrncpy(epstr, epSaved, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDeps.mutex);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void dnodeGetDnodeEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) {
|
||||
pthread_mutex_lock(&tsDeps.mutex);
|
||||
|
||||
SDnodeEp *ep = taosHashGet(tsDeps.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
SDnodeEp *ep = taosHashGet(tsEps.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (ep != NULL) {
|
||||
if (port) *port = ep->dnodePort;
|
||||
if (fqdn) tstrncpy(fqdn, ep->dnodeFqdn, TSDB_FQDN_LEN);
|
||||
if (epstr) snprintf(epstr, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDeps.mutex);
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateCfg(SDnodeCfg *data) {
|
||||
if (tsEps.dnodeId != 0 && !data->dropped) return;
|
||||
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
|
||||
tsEps.dnodeId = data->dnodeId;
|
||||
tsEps.clusterId = data->clusterId;
|
||||
tsEps.dropped = data->dropped;
|
||||
dInfo("dnodeId is set to %d, clusterId is set to %" PRId64, data->dnodeId, data->clusterId);
|
||||
|
||||
dnodeWriteEps();
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
}
|
||||
|
||||
int32_t dnodeGetDnodeId() {
|
||||
int32_t dnodeId = 0;
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
dnodeId = tsEps.dnodeId;
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
return dnodeId;
|
||||
}
|
||||
|
||||
int64_t dnodeGetClusterId() {
|
||||
int64_t clusterId = 0;
|
||||
pthread_mutex_lock(&tsEps.mutex);
|
||||
clusterId = tsEps.clusterId;
|
||||
pthread_mutex_unlock(&tsEps.mutex);
|
||||
return clusterId;
|
||||
}
|
||||
|
|
|
@ -14,71 +14,178 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#if 0
|
||||
#include "qScript.h"
|
||||
#include "tfile.h"
|
||||
#include "tsync.h"
|
||||
#include "twal.h"
|
||||
#endif
|
||||
#include "tstep.h"
|
||||
#include "dnodeCfg.h"
|
||||
#include "dnodeCheck.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "dnodeMain.h"
|
||||
#include "dnodeMnodeEps.h"
|
||||
#include "dnodeStatus.h"
|
||||
#include "dnodeTelem.h"
|
||||
#include "dnodeMsg.h"
|
||||
#include "dnodeTrans.h"
|
||||
#include "mnode.h"
|
||||
#include "sync.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tnote.h"
|
||||
#include "tstep.h"
|
||||
#include "vnode.h"
|
||||
#include "wal.h"
|
||||
|
||||
static struct SSteps *tsSteps;
|
||||
static struct {
|
||||
EDnStat runStatus;
|
||||
SStartupStep startup;
|
||||
SSteps *steps;
|
||||
} tsDnode;
|
||||
|
||||
static int32_t dnodeInitVnodeModule(void **unused) {
|
||||
EDnStat dnodeGetRunStat() { return tsDnode.runStatus; }
|
||||
|
||||
void dnodeSetRunStat(EDnStat stat) { tsDnode.runStatus = stat; }
|
||||
|
||||
static void dnodeReportStartup(char *name, char *desc) {
|
||||
SStartupStep *startup = &tsDnode.startup;
|
||||
tstrncpy(startup->name, name, strlen(startup->name));
|
||||
tstrncpy(startup->desc, desc, strlen(startup->desc));
|
||||
startup->finished = 0;
|
||||
}
|
||||
|
||||
static void dnodeReportStartupFinished(char *name, char *desc) {
|
||||
SStartupStep *startup = &tsDnode.startup;
|
||||
tstrncpy(startup->name, name, strlen(startup->name));
|
||||
tstrncpy(startup->desc, desc, strlen(startup->desc));
|
||||
startup->finished = 1;
|
||||
}
|
||||
|
||||
void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsDnode.startup, sizeof(SStartupStep)); }
|
||||
|
||||
static int32_t dnodeInitVnode() {
|
||||
SVnodePara para;
|
||||
para.fp.GetDnodeEp = dnodeGetDnodeEp;
|
||||
para.fp.GetDnodeEp = dnodeGetEp;
|
||||
para.fp.SendMsgToDnode = dnodeSendMsgToDnode;
|
||||
para.fp.SendMsgToMnode = dnodeSendMsgToMnode;
|
||||
|
||||
return vnodeInit(para);
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMnodeModule(void **unused) {
|
||||
static int32_t dnodeInitMnode() {
|
||||
SMnodePara para;
|
||||
para.fp.GetDnodeEp = dnodeGetDnodeEp;
|
||||
para.fp.GetDnodeEp = dnodeGetEp;
|
||||
para.fp.SendMsgToDnode = dnodeSendMsgToDnode;
|
||||
para.fp.SendMsgToMnode = dnodeSendMsgToMnode;
|
||||
para.fp.SendRedirectMsg = dnodeSendRedirectMsg;
|
||||
dnodeGetCfg(¶.dnodeId, para.clusterId);
|
||||
para.dnodeId = dnodeGetDnodeId();
|
||||
para.clusterId = dnodeGetClusterId();
|
||||
|
||||
return mnodeInit(para);
|
||||
}
|
||||
|
||||
static int32_t dnodeInitTfs() {}
|
||||
|
||||
static int32_t dnodeInitMain() {
|
||||
tsDnode.runStatus = DN_RUN_STAT_STOPPED;
|
||||
tscEmbedded = 1;
|
||||
taosIgnSIGPIPE();
|
||||
taosBlockSIGPIPE();
|
||||
taosResolveCRC();
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
taosSetCoreDump(tsEnableCoreFile);
|
||||
|
||||
if (!taosMkDir(tsLogDir)) {
|
||||
printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char temp[TSDB_FILENAME_LEN];
|
||||
sprintf(temp, "%s/taosdlog", tsLogDir);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
|
||||
if (!taosReadGlobalCfg()) {
|
||||
taosPrintGlobalCfg();
|
||||
dError("TDengine read global config failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("start to initialize TDengine");
|
||||
|
||||
taosInitNotes();
|
||||
|
||||
return taosCheckGlobalCfg();
|
||||
}
|
||||
|
||||
static void dnodeCleanupMain() {
|
||||
taos_cleanup();
|
||||
taosCloseLog();
|
||||
taosStopCacheRefreshWorker();
|
||||
}
|
||||
|
||||
static int32_t dnodeCheckRunning(char *dir) {
|
||||
char filepath[256] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s/.running", dir);
|
||||
|
||||
FileFd fd = taosOpenFileCreateWriteTrunc(filepath);
|
||||
if (fd < 0) {
|
||||
dError("failed to open lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = taosLockFile(fd);
|
||||
if (ret != 0) {
|
||||
dError("failed to lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
taosCloseFile(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitDir() {
|
||||
sprintf(tsMnodeDir, "%s/mnode", tsDataDir);
|
||||
sprintf(tsVnodeDir, "%s/vnode", tsDataDir);
|
||||
sprintf(tsDnodeDir, "%s/dnode", tsDataDir);
|
||||
|
||||
if (!taosMkDir(tsDnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsDnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsMnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsMnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsVnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsVnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dnodeCheckRunning(tsDnodeDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupDir() {}
|
||||
|
||||
int32_t dnodeInit() {
|
||||
tsSteps = taosStepInit(24, dnodeReportStartup);
|
||||
if (tsSteps == NULL) return -1;
|
||||
SSteps *steps = taosStepInit(24, dnodeReportStartup);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(tsSteps, "dnode-main", dnodeInitMain, dnodeCleanupMain);
|
||||
taosStepAdd(tsSteps, "dnode-storage", dnodeInitStorage, dnodeCleanupStorage);
|
||||
//taosStepAdd(tsSteps, "dnode-tfs", tfInit, tfCleanup);
|
||||
taosStepAdd(tsSteps, "dnode-rpc", rpcInit, rpcCleanup);
|
||||
taosStepAdd(tsSteps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck);
|
||||
taosStepAdd(tsSteps, "dnode-cfg", dnodeInitCfg, dnodeCleanupCfg);
|
||||
taosStepAdd(tsSteps, "dnode-deps", dnodeInitEps, dnodeCleanupEps);
|
||||
taosStepAdd(tsSteps, "dnode-meps", dnodeInitMnodeEps, dnodeCleanupMnodeEps);
|
||||
//taosStepAdd(tsSteps, "dnode-wal", walInit, walCleanUp);
|
||||
//taosStepAdd(tsSteps, "dnode-sync", syncInit, syncCleanUp);
|
||||
taosStepAdd(tsSteps, "dnode-vnode", dnodeInitVnodeModule, vnodeCleanup);
|
||||
taosStepAdd(tsSteps, "dnode-mnode", dnodeInitMnodeModule, mnodeCleanup);
|
||||
taosStepAdd(tsSteps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans);
|
||||
taosStepAdd(tsSteps, "dnode-status", dnodeInitStatus, dnodeCleanupStatus);
|
||||
taosStepAdd(tsSteps, "dnode-telem", dnodeInitTelem, dnodeCleanupTelem);
|
||||
//taosStepAdd(tsSteps, "dnode-script",scriptEnvPoolInit, scriptEnvPoolCleanup);
|
||||
taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain);
|
||||
taosStepAdd(steps, "dnode-dir", dnodeInitDir, dnodeCleanupDir);
|
||||
taosStepAdd(steps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck);
|
||||
taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup);
|
||||
taosStepAdd(steps, "dnode-tfs", dnodeInitTfs, NULL);
|
||||
taosStepAdd(steps, "dnode-wal", walInit, walCleanUp);
|
||||
taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
|
||||
taosStepAdd(steps, "dnode-eps", dnodeInitEps, dnodeCleanupEps);
|
||||
taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup);
|
||||
taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup);
|
||||
taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans);
|
||||
taosStepAdd(steps, "dnode-msg", dnodeInitMsg, dnodeCleanupMsg);
|
||||
|
||||
taosStepExec(tsSteps);
|
||||
tsDnode.steps = steps;
|
||||
taosStepExec(tsDnode.steps);
|
||||
|
||||
dnodeSetRunStat(TD_RUN_STAT_RUNNING);
|
||||
dnodeSetRunStat(DN_RUN_STAT_RUNNING);
|
||||
dnodeReportStartupFinished("TDengine", "initialized successfully");
|
||||
dInfo("TDengine is initialized successfully");
|
||||
|
||||
|
@ -86,9 +193,9 @@ int32_t dnodeInit() {
|
|||
}
|
||||
|
||||
void dnodeCleanup() {
|
||||
if (dnodeGetRunStat() != TD_RUN_STAT_STOPPED) {
|
||||
dnodeSetRunStat(TD_RUN_STAT_STOPPED);
|
||||
taosStepCleanup(tsSteps);
|
||||
tsSteps = NULL;
|
||||
if (dnodeGetRunStat() != DN_RUN_STAT_STOPPED) {
|
||||
dnodeSetRunStat(DN_RUN_STAT_STOPPED);
|
||||
taosStepCleanup(tsDnode.steps);
|
||||
tsDnode.steps = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,267 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#if 0
|
||||
#include "tfs.h"
|
||||
#endif
|
||||
#include "tnote.h"
|
||||
#include "tcompression.h"
|
||||
#include "ttimer.h"
|
||||
#include "dnodeCfg.h"
|
||||
#include "dnodeMain.h"
|
||||
#include "mnode.h"
|
||||
|
||||
static struct {
|
||||
RunStat runStatus;
|
||||
void * dnodeTimer;
|
||||
SStartupStep startup;
|
||||
} tsDmain;
|
||||
|
||||
static void dnodeCheckDataDirOpenned(char *dir) {
|
||||
#if 0
|
||||
char filepath[256] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s/.running", dir);
|
||||
|
||||
int32_t fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (fd < 0) {
|
||||
dError("failed to open lock file:%s, reason: %s, quit", filepath, strerror(errno));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int32_t ret = flock(fd, LOCK_EX | LOCK_NB);
|
||||
if (ret != 0) {
|
||||
dError("failed to lock file:%s ret:%d since %s, database may be running, quit", filepath, ret, strerror(errno));
|
||||
close(fd);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t dnodeInitMain() {
|
||||
tsDmain.runStatus = TD_RUN_STAT_STOPPED;
|
||||
tsDmain.dnodeTimer = taosTmrInit(100, 200, 60000, "DND-TMR");
|
||||
if (tsDmain.dnodeTimer == NULL) {
|
||||
dError("failed to init dnode timer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tscEmbedded = 1;
|
||||
taosIgnSIGPIPE();
|
||||
taosBlockSIGPIPE();
|
||||
taosResolveCRC();
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
taosSetCoreDump(tsEnableCoreFile);
|
||||
|
||||
if (!taosMkDir(tsLogDir)) {
|
||||
printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char temp[TSDB_FILENAME_LEN];
|
||||
sprintf(temp, "%s/taosdlog", tsLogDir);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
|
||||
if (!taosReadGlobalCfg()) {
|
||||
taosPrintGlobalCfg();
|
||||
dError("TDengine read global config failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("start to initialize TDengine");
|
||||
|
||||
taosInitNotes();
|
||||
|
||||
return taosCheckGlobalCfg();
|
||||
}
|
||||
|
||||
void dnodeCleanupMain() {
|
||||
if (tsDmain.dnodeTimer != NULL) {
|
||||
taosTmrCleanUp(tsDmain.dnodeTimer);
|
||||
tsDmain.dnodeTimer = NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
taos_cleanup();
|
||||
#endif
|
||||
taosCloseLog();
|
||||
taosStopCacheRefreshWorker();
|
||||
}
|
||||
|
||||
int32_t dnodeInitStorage() {
|
||||
#ifdef TD_TSZ
|
||||
// compress module init
|
||||
tsCompressInit();
|
||||
#endif
|
||||
|
||||
// storage module init
|
||||
if (tsDiskCfgNum == 1 && !taosMkDir(tsDataDir)) {
|
||||
dError("failed to create dir:%s since %s", tsDataDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (tfsInit(tsDiskCfg, tsDiskCfgNum) < 0) {
|
||||
dError("failed to init TFS since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(tsDataDir, TFS_PRIMARY_PATH(), TSDB_FILENAME_LEN);
|
||||
#endif
|
||||
sprintf(tsMnodeDir, "%s/mnode", tsDataDir);
|
||||
sprintf(tsVnodeDir, "%s/vnode", tsDataDir);
|
||||
sprintf(tsDnodeDir, "%s/dnode", tsDataDir);
|
||||
|
||||
if (!taosMkDir(tsMnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsMnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsDnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsDnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (tfsMkdir("vnode") < 0) {
|
||||
dError("failed to create vnode dir since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tfsMkdir("vnode_bak") < 0) {
|
||||
dError("failed to create vnode_bak dir since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
TDIR *tdir = tfsOpendir("vnode_bak/.staging");
|
||||
bool stagingNotEmpty = tfsReaddir(tdir) != NULL;
|
||||
tfsClosedir(tdir);
|
||||
|
||||
if (stagingNotEmpty) {
|
||||
dError("vnode_bak/.staging dir not empty, fix it first.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tfsMkdir("vnode_bak/.staging") < 0) {
|
||||
dError("failed to create vnode_bak/.staging dir since %s", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
dnodeCheckDataDirOpenned(tsDnodeDir);
|
||||
|
||||
taosGetDisk();
|
||||
dnodePrintDiskInfo();
|
||||
#endif
|
||||
|
||||
dInfo("dnode storage is initialized at %s", tsDnodeDir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupStorage() {
|
||||
#if 0
|
||||
// storage destroy
|
||||
tfsDestroy();
|
||||
|
||||
#ifdef TD_TSZ
|
||||
// compress destroy
|
||||
tsCompressExit();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void dnodeReportStartup(char *name, char *desc) {
|
||||
SStartupStep *startup = &tsDmain.startup;
|
||||
tstrncpy(startup->name, name, strlen(startup->name));
|
||||
tstrncpy(startup->desc, desc, strlen(startup->desc));
|
||||
startup->finished = 0;
|
||||
}
|
||||
|
||||
void dnodeReportStartupFinished(char *name, char *desc) {
|
||||
SStartupStep *startup = &tsDmain.startup;
|
||||
tstrncpy(startup->name, name, strlen(startup->name));
|
||||
tstrncpy(startup->desc, desc, strlen(startup->desc));
|
||||
startup->finished = 1;
|
||||
}
|
||||
|
||||
void dnodeProcessStartupReq(SRpcMsg *pMsg) {
|
||||
dInfo("startup msg is received, cont:%s", (char *)pMsg->pCont);
|
||||
|
||||
SStartupStep *pStep = rpcMallocCont(sizeof(SStartupStep));
|
||||
memcpy(pStep, &tsDmain.startup, sizeof(SStartupStep));
|
||||
|
||||
dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStep->name, pStep->desc, pStep->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static int32_t dnodeStartMnode(SRpcMsg *pMsg) {
|
||||
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||
dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId,
|
||||
dnodeGetDnodeId());
|
||||
return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
if (strcmp(pCfg->dnodeEp, tsLocalEp) != 0) {
|
||||
dDebug("dnodeEp:%s, in create meps msg is not equal with saved dnodeEp:%s", pCfg->dnodeEp, tsLocalEp);
|
||||
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
dDebug("dnode:%d, create meps msg is received from mnodes, numOfMnodes:%d", pCfg->dnodeId, pCfg->mnodes.mnodeNum);
|
||||
for (int32_t i = 0; i < pCfg->mnodes.mnodeNum; ++i) {
|
||||
pCfg->mnodes.mnodeInfos[i].mnodeId = htonl(pCfg->mnodes.mnodeInfos[i].mnodeId);
|
||||
dDebug("meps index:%d, meps:%d:%s", i, pCfg->mnodes.mnodeInfos[i].mnodeId, pCfg->mnodes.mnodeInfos[i].mnodeEp);
|
||||
}
|
||||
|
||||
if (mnodeIsServing()) return 0;
|
||||
|
||||
return mnodeDeploy(&pCfg->mnodes);
|
||||
}
|
||||
|
||||
void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) {
|
||||
int32_t code = dnodeStartMnode(pMsg);
|
||||
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) {
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
|
||||
int32_t code = taosCfgDynamicOptions(pCfg->config);
|
||||
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
RunStat dnodeGetRunStat() { return tsDmain.runStatus; }
|
||||
|
||||
void dnodeSetRunStat(RunStat stat) { tsDmain.runStatus = stat; }
|
||||
|
||||
void* dnodeGetTimer() { return tsDmain.dnodeTimer; }
|
|
@ -1,311 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "cJSON.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeCfg.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "dnodeMnodeEps.h"
|
||||
#include "mnode.h"
|
||||
|
||||
static struct {
|
||||
SRpcEpSet mnodeEpSet;
|
||||
SMInfos mnodeInfos;
|
||||
char file[PATH_MAX + 20];
|
||||
pthread_mutex_t mutex;
|
||||
} tsDmeps;
|
||||
|
||||
|
||||
static void dnodePrintMnodeEps() {
|
||||
SRpcEpSet *epset = &tsDmeps.mnodeEpSet;
|
||||
dInfo("print mnode eps, num:%d inuse:%d", epset->numOfEps, epset->inUse);
|
||||
for (int32_t i = 0; i < epset->numOfEps; i++) {
|
||||
dInfo("ep index:%d, %s:%u", i, epset->fqdn[i], epset->port[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeResetMnodeEps(SMInfos *mInfos) {
|
||||
if (mInfos == NULL || mInfos->mnodeNum == 0) {
|
||||
tsDmeps.mnodeEpSet.numOfEps = 1;
|
||||
taosGetFqdnPortFromEp(tsFirst, tsDmeps.mnodeEpSet.fqdn[0], &tsDmeps.mnodeEpSet.port[0]);
|
||||
|
||||
if (strcmp(tsSecond, tsFirst) != 0) {
|
||||
tsDmeps.mnodeEpSet.numOfEps = 2;
|
||||
taosGetFqdnPortFromEp(tsSecond, tsDmeps.mnodeEpSet.fqdn[1], &tsDmeps.mnodeEpSet.port[1]);
|
||||
}
|
||||
dnodePrintMnodeEps();
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SMInfos);
|
||||
memcpy(&tsDmeps.mnodeInfos, mInfos, size);
|
||||
|
||||
tsDmeps.mnodeEpSet.inUse = tsDmeps.mnodeInfos.inUse;
|
||||
tsDmeps.mnodeEpSet.numOfEps = tsDmeps.mnodeInfos.mnodeNum;
|
||||
for (int32_t i = 0; i < tsDmeps.mnodeInfos.mnodeNum; i++) {
|
||||
taosGetFqdnPortFromEp(tsDmeps.mnodeInfos.mnodeInfos[i].mnodeEp, tsDmeps.mnodeEpSet.fqdn[i], &tsDmeps.mnodeEpSet.port[i]);
|
||||
}
|
||||
|
||||
dnodePrintMnodeEps();
|
||||
}
|
||||
|
||||
static int32_t dnodeWriteMnodeEps() {
|
||||
FILE *fp = fopen(tsDmeps.file, "w");
|
||||
if (!fp) {
|
||||
dError("failed to write %s since %s", tsDmeps.file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 2000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"inUse\": %d,\n", tsDmeps.mnodeInfos.inUse);
|
||||
len += snprintf(content + len, maxLen - len, " \"nodeNum\": %d,\n", tsDmeps.mnodeInfos.mnodeNum);
|
||||
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
|
||||
for (int32_t i = 0; i < tsDmeps.mnodeInfos.mnodeNum; i++) {
|
||||
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsDmeps.mnodeInfos.mnodeInfos[i].mnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsDmeps.mnodeInfos.mnodeInfos[i].mnodeEp);
|
||||
if (i < tsDmeps.mnodeInfos.mnodeNum - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
dInfo("successed to write %s", tsDmeps.file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeReadMnodeEps() {
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 2000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
cJSON * root = NULL;
|
||||
FILE * fp = NULL;
|
||||
SMInfos mInfos = {0};
|
||||
bool nodeChanged = false;
|
||||
|
||||
fp = fopen(tsDmeps.file, "r");
|
||||
if (!fp) {
|
||||
dDebug("file %s not exist", tsDmeps.file);
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", tsDmeps.file);
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", tsDmeps.file);
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
cJSON *inUse = cJSON_GetObjectItem(root, "inUse");
|
||||
if (!inUse || inUse->type != cJSON_Number) {
|
||||
dError("failed to read mnodeEpSet.json since inUse not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
tsDmeps.mnodeInfos.inUse = (int8_t)inUse->valueint;
|
||||
|
||||
cJSON *nodeNum = cJSON_GetObjectItem(root, "nodeNum");
|
||||
if (!nodeNum || nodeNum->type != cJSON_Number) {
|
||||
dError("failed to read mnodeEpSet.json since nodeNum not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
mInfos.mnodeNum = (int8_t)nodeNum->valueint;
|
||||
|
||||
cJSON *nodeInfos = cJSON_GetObjectItem(root, "nodeInfos");
|
||||
if (!nodeInfos || nodeInfos->type != cJSON_Array) {
|
||||
dError("failed to read mnodeEpSet.json since nodeInfos not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
int32_t size = cJSON_GetArraySize(nodeInfos);
|
||||
if (size != mInfos.mnodeNum) {
|
||||
dError("failed to read mnodeEpSet.json since nodeInfos size not matched");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
cJSON *nodeInfo = cJSON_GetArrayItem(nodeInfos, i);
|
||||
if (nodeInfo == NULL) continue;
|
||||
|
||||
cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "nodeId");
|
||||
if (!nodeId || nodeId->type != cJSON_Number) {
|
||||
dError("failed to read mnodeEpSet.json since nodeId not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
|
||||
if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
|
||||
dError("failed to read mnodeEpSet.json since nodeName not found");
|
||||
goto PARSE_MINFOS_OVER;
|
||||
}
|
||||
|
||||
SMInfo *mInfo = &mInfos.mnodeInfos[i];
|
||||
mInfo->mnodeId = (int32_t)nodeId->valueint;
|
||||
tstrncpy(mInfo->mnodeEp, nodeEp->valuestring, TSDB_EP_LEN);
|
||||
|
||||
bool changed = dnodeIsDnodeEpChanged(mInfo->mnodeId, mInfo->mnodeEp);
|
||||
if (changed) nodeChanged = changed;
|
||||
}
|
||||
|
||||
dInfo("successed to read file %s", tsDmeps.file);
|
||||
|
||||
PARSE_MINFOS_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
terrno = 0;
|
||||
|
||||
for (int32_t i = 0; i < mInfos.mnodeNum; ++i) {
|
||||
SMInfo *mInfo = &mInfos.mnodeInfos[i];
|
||||
dnodeGetDnodeEp(mInfo->mnodeId, mInfo->mnodeEp, NULL, NULL);
|
||||
}
|
||||
|
||||
dnodeResetMnodeEps(&mInfos);
|
||||
|
||||
if (nodeChanged) {
|
||||
dnodeWriteMnodeEps();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
rpcGetConnInfo(rpcMsg->handle, &connInfo);
|
||||
|
||||
SRpcEpSet epSet = {0};
|
||||
if (forShell) {
|
||||
dnodeGetEpSetForShell(&epSet);
|
||||
} else {
|
||||
dnodeGetEpSetForPeer(&epSet);
|
||||
}
|
||||
|
||||
dDebug("msg:%s will be redirected, dnodeIp:%s user:%s, numOfEps:%d inUse:%d", taosMsg[rpcMsg->msgType],
|
||||
taosIpStr(connInfo.clientIp), connInfo.user, epSet.numOfEps, epSet.inUse);
|
||||
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%d", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], tsLocalFqdn) == 0) {
|
||||
if ((epSet.port[i] == tsServerPort + TSDB_PORT_DNODEDNODE && !forShell) ||
|
||||
(epSet.port[i] == tsServerPort && forShell)) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse);
|
||||
}
|
||||
}
|
||||
|
||||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(rpcMsg->handle, &epSet);
|
||||
}
|
||||
|
||||
int32_t dnodeInitMnodeEps() {
|
||||
snprintf(tsDmeps.file, sizeof(tsDmeps.file), "%s/mnodeEpSet.json", tsDnodeDir);
|
||||
pthread_mutex_init(&tsDmeps.mutex, NULL);
|
||||
|
||||
dnodeResetMnodeEps(NULL);
|
||||
int32_t ret = dnodeReadMnodeEps();
|
||||
if (ret == 0) {
|
||||
dInfo("dnode mInfos is initialized");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dnodeCleanupMnodeEps() {
|
||||
pthread_mutex_destroy(&tsDmeps.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateMnodeFromStatus(SMInfos *mInfos) {
|
||||
if (mInfos->mnodeNum <= 0 || mInfos->mnodeNum > TSDB_MAX_REPLICA) {
|
||||
dError("invalid mInfos since num:%d invalid", mInfos->mnodeNum);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < mInfos->mnodeNum; ++i) {
|
||||
SMInfo *minfo = &mInfos->mnodeInfos[i];
|
||||
minfo->mnodeId = htonl(minfo->mnodeId);
|
||||
if (minfo->mnodeId <= 0 || strlen(minfo->mnodeEp) <= 5) {
|
||||
dError("invalid mInfo:%d since id:%d and ep:%s invalid", i, minfo->mnodeId, minfo->mnodeEp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsDmeps.mutex);
|
||||
if (mInfos->mnodeNum != tsDmeps.mnodeInfos.mnodeNum) {
|
||||
dnodeResetMnodeEps(mInfos);
|
||||
dnodeWriteMnodeEps();
|
||||
} else {
|
||||
int32_t size = sizeof(SMInfos);
|
||||
if (memcmp(mInfos, &tsDmeps.mnodeInfos, size) != 0) {
|
||||
dnodeResetMnodeEps(mInfos);
|
||||
dnodeWriteMnodeEps();
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&tsDmeps.mutex);
|
||||
}
|
||||
|
||||
void dnodeUpdateMnodeFromPeer(SRpcEpSet *ep) {
|
||||
if (ep->numOfEps <= 0) {
|
||||
dError("mInfos is changed, but content is invalid, discard it");
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsDmeps.mutex);
|
||||
|
||||
dInfo("mInfos is changed, numOfEps:%d inUse:%d", ep->numOfEps, ep->inUse);
|
||||
for (int32_t i = 0; i < ep->numOfEps; ++i) {
|
||||
ep->port[i] -= TSDB_PORT_DNODEDNODE;
|
||||
dInfo("minfo:%d %s:%u", i, ep->fqdn[i], ep->port[i]);
|
||||
}
|
||||
tsDmeps.mnodeEpSet = *ep;
|
||||
|
||||
pthread_mutex_unlock(&tsDmeps.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetEpSetForPeer(SRpcEpSet *epSet) {
|
||||
pthread_mutex_lock(&tsDmeps.mutex);
|
||||
|
||||
*epSet = tsDmeps.mnodeEpSet;
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
epSet->port[i] += TSDB_PORT_DNODEDNODE;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDmeps.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetEpSetForShell(SRpcEpSet *epSet) {
|
||||
pthread_mutex_lock(&tsDmeps.mutex);
|
||||
*epSet = tsDmeps.mnodeEpSet;
|
||||
pthread_mutex_unlock(&tsDmeps.mutex);
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dnodeMsg.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "mnode.h"
|
||||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
#include "vnode.h"
|
||||
|
||||
static struct {
|
||||
pthread_t *threadId;
|
||||
bool stop;
|
||||
uint32_t rebootTime;
|
||||
} tsMsg;
|
||||
|
||||
static void dnodeSendStatusMsg() {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
}
|
||||
|
||||
pStatus->version = htonl(tsVersion);
|
||||
pStatus->dnodeId = htonl(dnodeGetDnodeId());
|
||||
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
||||
pStatus->clusterId = htobe64(dnodeGetClusterId());
|
||||
pStatus->lastReboot = htonl(tsMsg.rebootTime);
|
||||
pStatus->numOfCores = htonl(tsNumOfCores);
|
||||
pStatus->diskAvailable = tsAvailDataDirGB;
|
||||
|
||||
// fill cluster cfg parameters
|
||||
pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval);
|
||||
pStatus->clusterCfg.checkTime = 0;
|
||||
tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, 64);
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
|
||||
vnodeGetStatus(pStatus);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad);
|
||||
pStatus->openVnodes = htons(pStatus->openVnodes);
|
||||
|
||||
SRpcMsg rpcMsg = {.ahandle = NULL, .pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_DM_STATUS};
|
||||
|
||||
dnodeSendMsgToMnode(&rpcMsg);
|
||||
}
|
||||
|
||||
void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
||||
dTrace("status rsp is received, code:%s", tstrerror(pMsg->code));
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) return;
|
||||
|
||||
SStatusRsp *pStatusRsp = pMsg->pCont;
|
||||
|
||||
SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
|
||||
pCfg->numOfDnodes = htonl(pCfg->numOfDnodes);
|
||||
dnodeUpdateCfg(pCfg);
|
||||
|
||||
if (pCfg->dropped) {
|
||||
dError("status rsp is received, and set dnode to drop status");
|
||||
return;
|
||||
}
|
||||
|
||||
vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes);
|
||||
|
||||
SDnodeEps *eps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess));
|
||||
eps->dnodeNum = htonl(eps->dnodeNum);
|
||||
for (int32_t i = 0; i < eps->dnodeNum; ++i) {
|
||||
eps->dnodeEps[i].dnodeId = htonl(eps->dnodeEps[i].dnodeId);
|
||||
eps->dnodeEps[i].dnodePort = htons(eps->dnodeEps[i].dnodePort);
|
||||
}
|
||||
|
||||
dnodeUpdateDnodeEps(eps);
|
||||
}
|
||||
|
||||
static void *dnodeThreadRoutine(void *param) {
|
||||
int32_t ms = tsStatusInterval * 1000;
|
||||
while (!tsMsg.stop) {
|
||||
taosMsleep(ms);
|
||||
dnodeSendStatusMsg();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitMsg() {
|
||||
tsMsg.stop = false;
|
||||
tsMsg.rebootTime = taosGetTimestampSec();
|
||||
tsMsg.threadId = taosCreateThread(dnodeThreadRoutine, NULL);
|
||||
if (tsMsg.threadId == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode msg is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupMsg() {
|
||||
if (tsMsg.threadId != NULL) {
|
||||
tsMsg.stop = true;
|
||||
taosDestoryThread(tsMsg.threadId);
|
||||
tsMsg.threadId = NULL;
|
||||
}
|
||||
|
||||
dInfo("dnode msg is cleanuped");
|
||||
}
|
||||
|
||||
static int32_t dnodeStartMnode(SRpcMsg *pMsg) {
|
||||
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->mnodeNum = htonl(pCfg->mnodeNum);
|
||||
for (int32_t i = 0; i < pCfg->mnodeNum; ++i) {
|
||||
pCfg->mnodeEps[i].dnodeId = htonl(pCfg->mnodeEps[i].dnodeId);
|
||||
pCfg->mnodeEps[i].dnodePort = htons(pCfg->mnodeEps[i].dnodePort);
|
||||
}
|
||||
|
||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||
dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
||||
return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
if (mnodeGetStatus() == MN_STATUS_READY) return 0;
|
||||
|
||||
return mnodeDeploy();
|
||||
}
|
||||
|
||||
void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) {
|
||||
int32_t code = dnodeStartMnode(pMsg);
|
||||
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) {
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
|
||||
int32_t code = taosCfgDynamicOptions(pCfg->config);
|
||||
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
void dnodeProcessStartupReq(SRpcMsg *pMsg) {
|
||||
dInfo("startup msg is received, cont:%s", (char *)pMsg->pCont);
|
||||
|
||||
SStartupStep *pStep = rpcMallocCont(sizeof(SStartupStep));
|
||||
dnodeGetStartup(pStep);
|
||||
|
||||
dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStep->name, pStep->desc, pStep->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeCfg.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "dnodeMnodeEps.h"
|
||||
#include "dnodeStatus.h"
|
||||
#include "dnodeMain.h"
|
||||
#include "vnode.h"
|
||||
|
||||
static struct {
|
||||
void * dnodeTimer;
|
||||
void * statusTimer;
|
||||
uint32_t rebootTime;
|
||||
} tsStatus;
|
||||
|
||||
static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
||||
if (tsStatus.statusTimer == NULL) {
|
||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsStatus.dnodeTimer, &tsStatus.statusTimer);
|
||||
dError("failed to start status timer");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsStatus.dnodeTimer, &tsStatus.statusTimer);
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
}
|
||||
|
||||
dnodeGetCfg(&pStatus->dnodeId, pStatus->clusterId);
|
||||
pStatus->dnodeId = htonl(dnodeGetDnodeId());
|
||||
pStatus->version = htonl(tsVersion);
|
||||
pStatus->lastReboot = htonl(tsStatus.rebootTime);
|
||||
pStatus->numOfCores = htons((uint16_t)tsNumOfCores);
|
||||
pStatus->diskAvailable = tsAvailDataDirGB;
|
||||
pStatus->alternativeRole = tsAlternativeRole;
|
||||
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
||||
|
||||
// fill cluster cfg parameters
|
||||
pStatus->clusterCfg.numOfMnodes = htonl(tsNumOfMnodes);
|
||||
pStatus->clusterCfg.mnodeEqualVnodeNum = htonl(tsMnodeEqualVnodeNum);
|
||||
pStatus->clusterCfg.offlineThreshold = htonl(tsOfflineThreshold);
|
||||
pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval);
|
||||
pStatus->clusterCfg.maxtablesPerVnode = htonl(tsMaxTablePerVnode);
|
||||
pStatus->clusterCfg.maxVgroupsPerDb = htonl(tsMaxVgroupsPerDb);
|
||||
tstrncpy(pStatus->clusterCfg.arbitrator, tsArbitrator, TSDB_EP_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, 64);
|
||||
pStatus->clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
|
||||
pStatus->clusterCfg.enableBalance = tsEnableBalance;
|
||||
pStatus->clusterCfg.flowCtrl = tsEnableFlowCtrl;
|
||||
pStatus->clusterCfg.slaveQuery = tsEnableSlaveQuery;
|
||||
pStatus->clusterCfg.adjustMaster = tsEnableAdjustMaster;
|
||||
|
||||
vnodeGetStatus(pStatus);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad);
|
||||
pStatus->openVnodes = htons(pStatus->openVnodes);
|
||||
|
||||
SRpcMsg rpcMsg = {.ahandle = NULL, .pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_DM_STATUS};
|
||||
|
||||
dnodeSendMsgToMnode(&rpcMsg);
|
||||
}
|
||||
|
||||
void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||
dError("status rsp is received, error:%s", tstrerror(pMsg->code));
|
||||
if (pMsg->code == TSDB_CODE_MND_DNODE_NOT_EXIST) {
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
dnodeGetClusterId(clusterId);
|
||||
if (clusterId[0] != '\0') {
|
||||
dnodeSetDropped();
|
||||
dError("exit zombie dropped dnode");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsStatus.dnodeTimer, &tsStatus.statusTimer);
|
||||
return;
|
||||
}
|
||||
|
||||
SStatusRsp *pStatusRsp = pMsg->pCont;
|
||||
SMInfos * minfos = &pStatusRsp->mnodes;
|
||||
dnodeUpdateMnodeFromStatus(minfos);
|
||||
|
||||
SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg;
|
||||
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
|
||||
pCfg->moduleStatus = htonl(pCfg->moduleStatus);
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
dnodeUpdateCfg(pCfg);
|
||||
|
||||
vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes);
|
||||
|
||||
SDnodeEps *pEps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess));
|
||||
dnodeUpdateEps(pEps);
|
||||
|
||||
taosTmrReset(dnodeSendStatusMsg, tsStatusInterval * 1000, NULL, tsStatus.dnodeTimer, &tsStatus.statusTimer);
|
||||
}
|
||||
|
||||
int32_t dnodeInitStatus() {
|
||||
tsStatus.statusTimer = NULL;
|
||||
tsStatus.dnodeTimer = dnodeGetTimer();
|
||||
tsStatus.rebootTime = taosGetTimestampSec();
|
||||
taosTmrReset(dnodeSendStatusMsg, 500, NULL, tsStatus.dnodeTimer, &tsStatus.statusTimer);
|
||||
dInfo("dnode status timer is initialized");
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void dnodeCleanupStatus() {
|
||||
if (tsStatus.statusTimer != NULL) {
|
||||
taosTmrStopA(&tsStatus.statusTimer);
|
||||
tsStatus.statusTimer = NULL;
|
||||
}
|
||||
}
|
|
@ -20,21 +20,18 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeMain.h"
|
||||
#include "dnodeMnodeEps.h"
|
||||
#include "dnodeStatus.h"
|
||||
#include "dnodeTrans.h"
|
||||
#include "vnode.h"
|
||||
#include "dnodeEps.h"
|
||||
#include "dnodeMsg.h"
|
||||
#include "mnode.h"
|
||||
#include "vnode.h"
|
||||
|
||||
typedef void (*RpcMsgFp)( SRpcMsg *pMsg);
|
||||
typedef void (*RpcMsgFp)(SRpcMsg *pMsg);
|
||||
|
||||
static struct {
|
||||
void * serverRpc;
|
||||
void * clientRpc;
|
||||
void * shellRpc;
|
||||
void *serverRpc;
|
||||
void *clientRpc;
|
||||
void *shellRpc;
|
||||
int32_t queryReqNum;
|
||||
int32_t submitReqNum;
|
||||
RpcMsgFp peerMsgFp[TSDB_MSG_TYPE_MAX];
|
||||
|
@ -43,18 +40,18 @@ static struct {
|
|||
|
||||
static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0};
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (pMsg->pCont == NULL) return;
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||
dnodeProcessStartupReq(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dnodeGetRunStat() != TD_RUN_STAT_RUNNING) {
|
||||
if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) {
|
||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
dTrace("RPC %p, peer req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -64,41 +61,47 @@ static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
|||
return;
|
||||
}
|
||||
|
||||
RpcMsgFp fp = tsTrans.peerMsgFp[pMsg->msgType];
|
||||
RpcMsgFp fp = tsTrans.peerMsgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, peer req:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pMsg);
|
||||
} else {
|
||||
dDebug("RPC %p, peer req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
dError("RPC %p, peer req:%s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitServer() {
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessMsg;
|
||||
static int32_t dnodeInitServer() {
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeReq;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE] = dnodeProcessCreateMnodeReq;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeReq;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE] = dnodeProcessCreateMnodeReq;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg;
|
||||
/*tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessRead;*/
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
|
@ -120,7 +123,7 @@ int32_t dnodeInitServer() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupServer() {
|
||||
static void dnodeCleanupServer() {
|
||||
if (tsTrans.serverRpc) {
|
||||
rpcClose(tsTrans.serverRpc);
|
||||
tsTrans.serverRpc = NULL;
|
||||
|
@ -128,66 +131,66 @@ void dnodeCleanupServer() {
|
|||
}
|
||||
}
|
||||
|
||||
static void dnodeProcessRspFromPeer(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||
if (dnodeGetRunStat() == TD_RUN_STAT_STOPPED) {
|
||||
static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||
dTrace("msg:%p is ignored since dnode is stopping", pMsg);
|
||||
dTrace("RPC %p, peer rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) {
|
||||
dnodeUpdateMnodeFromPeer(pEpSet);
|
||||
if (msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) {
|
||||
dnodeUpdateMnodeEps(pEpSet);
|
||||
}
|
||||
|
||||
RpcMsgFp fp = tsTrans.peerMsgFp[pMsg->msgType];
|
||||
RpcMsgFp fp = tsTrans.peerMsgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, peer rsp:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pMsg);
|
||||
} else {
|
||||
dDebug("RPC %p, peer rsp:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0};
|
||||
rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
dDebug("RPC %p, peer rsp:%s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
int32_t dnodeInitClient() {
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeProcessMsg;
|
||||
static int32_t dnodeInitClient() {
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM_RSP] = mnodeProcessMsg;
|
||||
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE_RSP] = mnodeProcessMsg;
|
||||
|
||||
char secret[TSDB_KEY_LEN] = "secret";
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = mnodeProcessMsg;
|
||||
tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp;
|
||||
|
||||
char secret[TSDB_KEY_LEN] = "secret";
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = dnodeProcessRspFromPeer;
|
||||
rpcInit.sessions = TSDB_MAX_VNODES << 4;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = "t";
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.secret = secret;
|
||||
rpcInit.cfp = dnodeProcessPeerRsp;
|
||||
rpcInit.sessions = TSDB_MAX_VNODES << 4;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = "t";
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.secret = secret;
|
||||
|
||||
tsTrans.clientRpc = rpcOpen(&rpcInit);
|
||||
if (tsTrans.clientRpc == NULL) {
|
||||
|
@ -199,7 +202,7 @@ int32_t dnodeInitClient() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupClient() {
|
||||
static void dnodeCleanupClient() {
|
||||
if (tsTrans.clientRpc) {
|
||||
rpcClose(tsTrans.clientRpc);
|
||||
tsTrans.clientRpc = NULL;
|
||||
|
@ -207,59 +210,50 @@ void dnodeCleanupClient() {
|
|||
}
|
||||
}
|
||||
|
||||
static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||
SRpcMsg rpcMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0};
|
||||
static void dnodeProcessShellReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0};
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (pMsg->pCont == NULL) return;
|
||||
if (dnodeGetRunStat() == TD_RUN_STAT_STOPPED) {
|
||||
dError("RPC %p, shell msg:%s is ignored since dnode exiting", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
rpcMsg.code = TSDB_CODE_DND_EXITING;
|
||||
rpcSendResponse(&rpcMsg);
|
||||
if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) {
|
||||
dError("RPC %p, shell req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_EXITING;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
} else if (dnodeGetRunStat() != TD_RUN_STAT_RUNNING) {
|
||||
dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
rpcMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
rpcSendResponse(&rpcMsg);
|
||||
} else if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) {
|
||||
dError("RPC %p, shell req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_QUERY) {
|
||||
atomic_fetch_add_32(&tsTrans.queryReqNum, 1);
|
||||
} else if (pMsg->msgType == TSDB_MSG_TYPE_SUBMIT) {
|
||||
atomic_fetch_add_32(&tsTrans.submitReqNum, 1);
|
||||
} else {}
|
||||
if (pMsg->pCont == NULL) {
|
||||
rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN;
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
RpcMsgFp fp = tsTrans.shellMsgFp[pMsg->msgType];
|
||||
if (msgType == TSDB_MSG_TYPE_QUERY) {
|
||||
atomic_fetch_add_32(&tsTrans.queryReqNum, 1);
|
||||
} else if (msgType == TSDB_MSG_TYPE_SUBMIT) {
|
||||
atomic_fetch_add_32(&tsTrans.submitReqNum, 1);
|
||||
} else {
|
||||
}
|
||||
|
||||
RpcMsgFp fp = tsTrans.shellMsgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, shell req:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pMsg);
|
||||
} else {
|
||||
dError("RPC %p, shell req:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rpcMsg);
|
||||
dError("RPC %p, shell req:%s is not processed", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dnodeAuthNetTest(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, "nettestinternal") == 0) {
|
||||
char pass[32] = {0};
|
||||
taosEncryptPass((uint8_t *)user, strlen(user), pass);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
dTrace("nettest user is authorized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg) {
|
||||
rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL);
|
||||
}
|
||||
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg) { rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL); }
|
||||
|
||||
void dnodeSendMsgToMnode(SRpcMsg *rpcMsg) {
|
||||
SRpcEpSet epSet = {0};
|
||||
|
@ -267,19 +261,13 @@ void dnodeSendMsgToMnode(SRpcMsg *rpcMsg) {
|
|||
dnodeSendMsgToDnode(&epSet, rpcMsg);
|
||||
}
|
||||
|
||||
void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
|
||||
static void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
|
||||
SRpcEpSet epSet = {0};
|
||||
dnodeGetEpSetForPeer(&epSet);
|
||||
rpcSendRecv(tsTrans.clientRpc, &epSet, rpcMsg, rpcRsp);
|
||||
}
|
||||
|
||||
void dnodeSendMsgToDnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp, SRpcEpSet *epSet) {
|
||||
rpcSendRecv(tsTrans.clientRpc, epSet, rpcMsg, rpcRsp);
|
||||
}
|
||||
|
||||
static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (dnodeAuthNetTest(user, spi, encrypt, secret, ckey) == 0) return 0;
|
||||
|
||||
int32_t code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
|
||||
if (code != TSDB_CODE_APP_NOT_READY) return code;
|
||||
|
||||
|
@ -310,54 +298,54 @@ static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, c
|
|||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
int32_t dnodeInitShell() {
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg;
|
||||
static int32_t dnodeInitShell() {
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg;
|
||||
|
||||
// the following message shall be treated as mnode write
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeProcessMsg;
|
||||
|
||||
// the following message shall be treated as mnode query
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeProcessMsg;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeProcessMsg;
|
||||
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq;
|
||||
tsTrans.shellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq;
|
||||
|
||||
int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0);
|
||||
if (numOfThreads < 1) {
|
||||
|
@ -366,14 +354,14 @@ int32_t dnodeInitShell() {
|
|||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = tsDnodeShellPort;
|
||||
rpcInit.label = "SHELL";
|
||||
rpcInit.localPort = tsDnodeShellPort;
|
||||
rpcInit.label = "SHELL";
|
||||
rpcInit.numOfThreads = numOfThreads;
|
||||
rpcInit.cfp = dnodeProcessMsgFromShell;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = dnodeRetrieveUserAuthInfo;
|
||||
rpcInit.cfp = dnodeProcessShellReq;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = dnodeRetrieveUserAuthInfo;
|
||||
|
||||
tsTrans.shellRpc = rpcOpen(&rpcInit);
|
||||
if (tsTrans.shellRpc == NULL) {
|
||||
|
@ -385,7 +373,7 @@ int32_t dnodeInitShell() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupShell() {
|
||||
static void dnodeCleanupShell() {
|
||||
if (tsTrans.shellRpc) {
|
||||
rpcClose(tsTrans.shellRpc);
|
||||
tsTrans.shellRpc = NULL;
|
||||
|
|
|
@ -8,4 +8,5 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
mnode
|
||||
PUBLIC transport
|
||||
PUBLIC cjson
|
||||
)
|
|
@ -13,19 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MNODE_READ_H
|
||||
#define TDENGINE_MNODE_READ_H
|
||||
#ifndef _TD_MNODE_ACCT_H_
|
||||
#define _TD_MNODE_ACCT_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessRead(SMnodeMsg *pMsg);
|
||||
int32_t mnodeInitAcct();
|
||||
void mnodeCleanupAcct();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /*_TD_MNODE_ACCT_H_*/
|
|
@ -13,19 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MNODE_WRITE_H
|
||||
#define TDENGINE_MNODE_WRITE_H
|
||||
#ifndef _TD_MNODE_AUTH_H_
|
||||
#define _TD_MNODE_AUTH_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessRead(SMnodeMsg *pMsg);
|
||||
int32_t mnodeInitAuth();
|
||||
void mnodeCleanupAuth();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /*_TD_MNODE_AUTH_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_BALANCE_H_
|
||||
#define _TD_MNODE_BALANCE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitBalance();
|
||||
void mnodeCleanupBalance();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_BALANCE_H_*/
|
|
@ -13,8 +13,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MNODE_CLUSTER_H
|
||||
#define TDENGINE_MNODE_CLUSTER_H
|
||||
#ifndef _TD_MNODE_CLUSTER_H_
|
||||
#define _TD_MNODE_CLUSTER_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -22,13 +24,9 @@ extern "C" {
|
|||
|
||||
int32_t mnodeInitCluster();
|
||||
void mnodeCleanupCluster();
|
||||
void mnodeUpdateClusterId();
|
||||
const char* mnodeGetClusterId();
|
||||
|
||||
int32_t mnodeCompactCluster();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /*_TD_MNODE_CLUSTER_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_DATABASE_H_
|
||||
#define _TD_MNODE_DATABASE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitDb();
|
||||
void mnodeCleanupDb();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_DATABASE_H_*/
|
|
@ -0,0 +1,320 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_DEF_H_
|
||||
#define _TD_MNODE_DEF_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "thash.h"
|
||||
#include "cJSON.h"
|
||||
#include "mnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int32_t mDebugFlag;
|
||||
|
||||
// mnode log function
|
||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
|
||||
// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
||||
// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
|
||||
|
||||
#define mLError(...) {mError(__VA_ARGS__) }
|
||||
#define mLWarn(...) {mWarn(__VA_ARGS__) }
|
||||
#define mLInfo(...) {mInfo(__VA_ARGS__) }
|
||||
|
||||
typedef struct SClusterObj SClusterObj;
|
||||
typedef struct SDnodeObj SDnodeObj;
|
||||
typedef struct SMnodeObj SMnodeObj;
|
||||
typedef struct SAcctObj SAcctObj;
|
||||
typedef struct SUserObj SUserObj;
|
||||
typedef struct SDbObj SDbObj;
|
||||
typedef struct SVgObj SVgObj;
|
||||
typedef struct SSTableObj SSTableObj;
|
||||
typedef struct SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
typedef struct SMnMsg SMnMsg;
|
||||
|
||||
typedef enum {
|
||||
MN_SDB_START = 0,
|
||||
MN_SDB_CLUSTER = 1,
|
||||
MN_SDB_DNODE = 2,
|
||||
MN_SDB_MNODE = 3,
|
||||
MN_SDB_ACCT = 4,
|
||||
MN_SDB_AUTH = 5,
|
||||
MN_SDB_USER = 6,
|
||||
MN_SDB_DB = 7,
|
||||
MN_SDB_VGROUP = 8,
|
||||
MN_SDB_STABLE = 9,
|
||||
MN_SDB_FUNC = 10,
|
||||
MN_SDB_OPER = 11,
|
||||
MN_SDB_MAX = 12
|
||||
} EMnSdb;
|
||||
|
||||
typedef enum { MN_OP_START = 0, MN_OP_INSERT = 1, MN_OP_UPDATE = 2, MN_OP_DELETE = 3, MN_OP_MAX = 4 } EMnOp;
|
||||
|
||||
typedef enum { MN_KEY_START = 0, MN_KEY_BINARY = 1, MN_KEY_INT32 = 2, MN_KEY_INT64 = 3, MN_KEY_MAX } EMnKey;
|
||||
|
||||
typedef enum {
|
||||
MN_AUTH_ACCT_START = 0,
|
||||
MN_AUTH_ACCT_USER,
|
||||
MN_AUTH_ACCT_DNODE,
|
||||
MN_AUTH_ACCT_MNODE,
|
||||
MN_AUTH_ACCT_DB,
|
||||
MN_AUTH_ACCT_TABLE,
|
||||
MN_AUTH_ACCT_MAX
|
||||
} EMnAuthAcct;
|
||||
|
||||
typedef enum {
|
||||
MN_AUTH_OP_START = 0,
|
||||
MN_AUTH_OP_CREATE_USER,
|
||||
MN_AUTH_OP_ALTER_USER,
|
||||
MN_AUTH_OP_DROP_USER,
|
||||
MN_AUTH_MAX
|
||||
} EMnAuthOp;
|
||||
|
||||
typedef enum { MN_SDB_STAT_AVAIL = 0, MN_SDB_STAT_DROPPED = 1 } EMnSdbStat;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int8_t status;
|
||||
int8_t align[6];
|
||||
} SdbHead;
|
||||
|
||||
typedef struct SClusterObj {
|
||||
SdbHead head;
|
||||
int64_t id;
|
||||
char uid[TSDB_CLUSTER_ID_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
} SClusterObj;
|
||||
|
||||
typedef struct SDnodeObj {
|
||||
SdbHead head;
|
||||
int32_t id;
|
||||
int32_t vnodes;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int64_t lastAccess;
|
||||
int64_t lastReboot; // time stamp for last reboot
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
char ep[TSDB_EP_LEN];
|
||||
uint16_t port;
|
||||
int16_t numOfCores; // from dnode status msg
|
||||
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
|
||||
int8_t status; // set in balance function
|
||||
int8_t offlineReason;
|
||||
} SDnodeObj;
|
||||
|
||||
typedef struct SMnodeObj {
|
||||
SdbHead head;
|
||||
int32_t id;
|
||||
int8_t status;
|
||||
int8_t role;
|
||||
int32_t roleTerm;
|
||||
int64_t roleTime;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDnodeObj *pDnode;
|
||||
} SMnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int8_t accessState; // Configured only by command
|
||||
} SAcctCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfUsers;
|
||||
int32_t numOfDbs;
|
||||
int32_t numOfTimeSeries;
|
||||
int32_t numOfStreams;
|
||||
int64_t totalStorage; // Total storage wrtten from this account
|
||||
int64_t compStorage; // Compressed storage on disk
|
||||
} SAcctInfo;
|
||||
|
||||
typedef struct SAcctObj {
|
||||
SdbHead head;
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t acctId;
|
||||
int8_t status;
|
||||
SAcctCfg cfg;
|
||||
SAcctInfo info;
|
||||
} SAcctObj;
|
||||
|
||||
typedef struct SUserObj {
|
||||
SdbHead head;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int8_t rootAuth;
|
||||
SHashObj *prohibitDbHash;
|
||||
SAcctObj *pAcct;
|
||||
} SUserObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep0;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t commitTime;
|
||||
int32_t fsyncPeriod;
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t walLevel;
|
||||
int8_t replications;
|
||||
int8_t quorum;
|
||||
int8_t update;
|
||||
int8_t cacheLastRow;
|
||||
int8_t dbType;
|
||||
int16_t partitions;
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
SdbHead head;
|
||||
char name[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDbCfg cfg;
|
||||
int8_t status;
|
||||
int32_t numOfVgroups;
|
||||
int32_t numOfTables;
|
||||
int32_t numOfSuperTables;
|
||||
int32_t vgListSize;
|
||||
int32_t vgListIndex;
|
||||
SVgObj **vgList;
|
||||
SAcctObj *pAcct;
|
||||
} SDbObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t role;
|
||||
SDnodeObj *pDnode;
|
||||
} SVnodeGid;
|
||||
|
||||
typedef struct SVgObj {
|
||||
uint32_t vgId;
|
||||
int32_t numOfVnodes;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t lbDnodeId;
|
||||
int32_t lbTime;
|
||||
char dbName[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t inUse;
|
||||
int8_t accessState;
|
||||
int8_t status;
|
||||
SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
|
||||
int32_t vgCfgVersion;
|
||||
int8_t compact;
|
||||
int32_t numOfTables;
|
||||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
SDbObj *pDb;
|
||||
} SVgObj;
|
||||
|
||||
typedef struct SSTableObj {
|
||||
SdbHead head;
|
||||
char tableId[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t uid;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t numOfColumns; // used by normal table
|
||||
int32_t numOfTags;
|
||||
SSchema * schema;
|
||||
} SSTableObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
SdbHead head;
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
char path[128];
|
||||
int32_t contLen;
|
||||
char cont[TSDB_FUNC_CODE_LEN];
|
||||
int32_t funcType;
|
||||
int32_t bufSize;
|
||||
int64_t createdTime;
|
||||
uint8_t resType;
|
||||
int16_t resBytes;
|
||||
int64_t sig;
|
||||
int16_t type;
|
||||
} SFuncObj;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int8_t maxReplica;
|
||||
int16_t numOfColumns;
|
||||
int32_t index;
|
||||
int32_t rowSize;
|
||||
int32_t numOfRows;
|
||||
int32_t numOfReads;
|
||||
uint16_t payloadLen;
|
||||
void *pIter;
|
||||
void *pVgIter;
|
||||
void **ppShow;
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int16_t offset[TSDB_MAX_COLUMNS];
|
||||
int32_t bytes[TSDB_MAX_COLUMNS];
|
||||
char payload[];
|
||||
} SShowObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t len;
|
||||
void *rsp;
|
||||
} SMnRsp;
|
||||
|
||||
typedef struct SMnMsg {
|
||||
void (*fp)(SMnMsg *pMsg, int32_t code);
|
||||
SUserObj *pUser;
|
||||
int16_t received;
|
||||
int16_t successed;
|
||||
int16_t expected;
|
||||
int16_t retry;
|
||||
int32_t code;
|
||||
int64_t createdTime;
|
||||
SMnRsp rpcRsp;
|
||||
SRpcMsg rpcMsg;
|
||||
char pCont[];
|
||||
} SMnReq;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_DEF_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_DNODE_H_
|
||||
#define _TD_MNODE_DNODE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitDnode();
|
||||
void mnodeCleanupDnode();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_DNODE_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_FUNC_H_
|
||||
#define _TD_MNODE_FUNC_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitFunc();
|
||||
void mnodeCleanupFunc();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_FUNC_H_*/
|
|
@ -16,17 +16,24 @@
|
|||
#ifndef _TD_MNODE_INT_H_
|
||||
#define _TD_MNODE_INT_H_
|
||||
|
||||
#include "mnodeDef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "trpc.h"
|
||||
#include "mnode.h"
|
||||
tmr_h mnodeGetTimer();
|
||||
int32_t mnodeGetDnodeId();
|
||||
char *mnodeGetClusterId();
|
||||
EMnStatus mnodeGetStatus();
|
||||
|
||||
void mnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell);
|
||||
void mnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_INT_H_*/
|
||||
#endif /*_TD_MNODE_INT_H_*/
|
||||
|
|
|
@ -13,21 +13,22 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MNODE_PEER_H
|
||||
#define TDENGINE_MNODE_PEER_H
|
||||
#ifndef _TD_MNODE_MNODE_H_
|
||||
#define _TD_MNODE_MNODE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeDef.h"
|
||||
|
||||
void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
|
||||
void mnodeAddPeerMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg));
|
||||
int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg);
|
||||
void mnodeProcessPeerRsp(SRpcMsg *pMsg);
|
||||
int32_t mnodeInitMnode();
|
||||
void mnodeCleanupMnode();
|
||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect);
|
||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /*_TD_MNODE_MNODE_H_*/
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_OPER_H_
|
||||
#define _TD_MNODE_OPER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitOper();
|
||||
void mnodeCleanupOper();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_OPER_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_PROFILE_H_
|
||||
#define _TD_MNODE_PROFILE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitProfile();
|
||||
void mnodeCleanupProfile();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_PROFILE_H_*/
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_SDB_H_
|
||||
#define _TD_MNODE_SDB_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*SdbDeployFp)();
|
||||
typedef void *(*SdbDecodeFp)(cJSON *root);
|
||||
typedef int32_t (*SdbEncodeFp)(void *pHead, char *buf, int32_t maxLen);
|
||||
|
||||
int32_t sdbInit();
|
||||
void sdbCleanup();
|
||||
|
||||
int32_t sdbRead();
|
||||
int32_t sdbCommit();
|
||||
|
||||
int32_t sdbDeploy();
|
||||
void sdbUnDeploy();
|
||||
|
||||
void *sdbInsertRow(EMnSdb sdb, void *pObj);
|
||||
void sdbDeleteRow(EMnSdb sdb, void *pHead);
|
||||
void *sdbUpdateRow(EMnSdb sdb, void *pHead);
|
||||
void *sdbGetRow(EMnSdb sdb, void *pKey);
|
||||
void *sdbFetchRow(EMnSdb sdb, void *pIter);
|
||||
void sdbCancelFetch(EMnSdb sdb, void *pIter);
|
||||
int32_t sdbGetCount(EMnSdb sdb);
|
||||
|
||||
void sdbSetFp(EMnSdb, EMnKey, SdbDeployFp, SdbEncodeFp, SdbDecodeFp, int32_t dataSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_INT_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_SHOW_H_
|
||||
#define _TD_MNODE_SHOW_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitShow();
|
||||
void mnodeCleanUpShow();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_SHOW_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_STABLE_H_
|
||||
#define _TD_MNODE_STABLE_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitStable();
|
||||
void mnodeCleanupStable();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_STABLE_H_*/
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_SYNC_H_
|
||||
#define _TD_MNODE_SYNC_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitSync();
|
||||
void mnodeCleanUpSync();
|
||||
|
||||
bool mnodeIsMaster();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_SYNC_H_*/
|
|
@ -13,19 +13,19 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_TELEMETRY_H_
|
||||
#define _TD_DNODE_TELEMETRY_H_
|
||||
#ifndef _TD_MNODE_TELEMETRY_H_
|
||||
#define _TD_MNODE_TELEMETRY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t dnodeInitTelem();
|
||||
void dnodeCleanupTelem();
|
||||
int32_t mnodeInitTelem();
|
||||
void mnodeCleanupTelem();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_TELEMETRY_H_*/
|
||||
#endif /*_TD_MNODE_TELEMETRY_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_USER_H_
|
||||
#define _TD_MNODE_USER_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitUser();
|
||||
void mnodeCleanupUser();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_USER_H_*/
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_VGROUP_H_
|
||||
#define _TD_MNODE_VGROUP_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitVgroup();
|
||||
void mnodeCleanupVgroup();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_VGROUP_H_*/
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_WORKER_H_
|
||||
#define _TD_MNODE_WORKER_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitWorker();
|
||||
void mnodeCleanupWorker();
|
||||
void mnodeProcessMsg(SRpcMsg *rpcMsg);
|
||||
void mnodeSendRsp(SMnMsg *pMsg, int32_t code);
|
||||
void mnodeReDispatchToWriteQueue(SMnMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_WORKER_H_*/
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static void mnodeCreateDefaultAcct() {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = 128,
|
||||
.maxDbs = 128,
|
||||
.maxTimeSeries = INT32_MAX,
|
||||
.maxStreams = 1000,
|
||||
.maxStorage = INT64_MAX,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS};
|
||||
acctObj.acctId = 1;
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
acctObj.updateTime = taosGetTimestampMs();
|
||||
|
||||
sdbInsertRow(MN_SDB_ACCT, &acctObj);
|
||||
}
|
||||
|
||||
int32_t mnodeEncodeAcct(SAcctObj *pAcct, char *buf, int32_t maxLen) {
|
||||
int32_t len = 0;
|
||||
|
||||
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_ACCT);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pAcct->acct);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acctId\":\"%d\", ", pAcct->acctId);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxUsers\":\"%d\", ", pAcct->cfg.maxUsers);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxDbs\":\"%d\", ", pAcct->cfg.maxDbs);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxTimeSeries\":\"%d\", ", pAcct->cfg.maxTimeSeries);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxStreams\":\"%d\", ", pAcct->cfg.maxStreams);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxStorage\":\"%" PRIu64 "\", ", pAcct->cfg.maxStorage);
|
||||
len += snprintf(buf + len, maxLen - len, "\"accessState\":\"%d\", ", pAcct->cfg.accessState);
|
||||
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pAcct->createdTime);
|
||||
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pAcct->updateTime);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
SAcctObj *mnodeDecodeAcct(cJSON *root) {
|
||||
int32_t code = -1;
|
||||
SAcctObj *pAcct = calloc(1, sizeof(SAcctObj));
|
||||
|
||||
cJSON *acct = cJSON_GetObjectItem(root, "acct");
|
||||
if (!acct || acct->type != cJSON_String) {
|
||||
mError("failed to parse acct since acct not found");
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
tstrncpy(pAcct->acct, acct->valuestring, TSDB_USER_LEN);
|
||||
|
||||
cJSON *acctId = cJSON_GetObjectItem(root, "acctId");
|
||||
if (!acctId || acctId->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since acctId not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->acctId = atol(acctId->valuestring);
|
||||
|
||||
cJSON *maxUsers = cJSON_GetObjectItem(root, "maxUsers");
|
||||
if (!maxUsers || maxUsers->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxUsers not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxUsers = atol(maxUsers->valuestring);
|
||||
|
||||
cJSON *maxDbs = cJSON_GetObjectItem(root, "maxDbs");
|
||||
if (!maxDbs || maxDbs->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxDbs not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxDbs = atol(maxDbs->valuestring);
|
||||
|
||||
cJSON *maxTimeSeries = cJSON_GetObjectItem(root, "maxTimeSeries");
|
||||
if (!maxTimeSeries || maxTimeSeries->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxTimeSeries not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxTimeSeries = atol(maxTimeSeries->valuestring);
|
||||
|
||||
cJSON *maxStreams = cJSON_GetObjectItem(root, "maxStreams");
|
||||
if (!maxStreams || maxStreams->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStreams not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStreams = atol(maxStreams->valuestring);
|
||||
|
||||
cJSON *maxStorage = cJSON_GetObjectItem(root, "maxStorage");
|
||||
if (!maxStorage || maxStorage->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStorage not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStorage = atoll(maxStorage->valuestring);
|
||||
|
||||
cJSON *accessState = cJSON_GetObjectItem(root, "accessState");
|
||||
if (!accessState || accessState->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since accessState not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.accessState = atol(accessState->valuestring);
|
||||
|
||||
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime");
|
||||
if (!createdTime || createdTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since createdTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->createdTime = atol(createdTime->valuestring);
|
||||
|
||||
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime");
|
||||
if (!updateTime || updateTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since updateTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->updateTime = atol(updateTime->valuestring);
|
||||
|
||||
code = 0;
|
||||
mTrace("acct:%s, parse success", pAcct->acct);
|
||||
|
||||
DECODE_ACCT_OVER:
|
||||
if (code != 0) {
|
||||
free(pAcct);
|
||||
pAcct = NULL;
|
||||
}
|
||||
return pAcct;
|
||||
}
|
||||
|
||||
int32_t mnodeInitAcct() {
|
||||
sdbSetFp(MN_SDB_ACCT, MN_KEY_BINARY, mnodeCreateDefaultAcct, (SdbEncodeFp)mnodeEncodeAcct,
|
||||
(SdbDecodeFp)(mnodeDecodeAcct), sizeof(SAcctObj));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupAcct() {}
|
|
@ -13,20 +13,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mnodeInt.h"
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeAuth.h"
|
||||
|
||||
int32_t mnodeInit(SMnodePara para) { return 0; }
|
||||
int32_t mnodeInitAuth() { return 0; }
|
||||
void mnodeCleanupAuth() {}
|
||||
|
||||
void mnodeCleanup() {}
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, TSDB_NETTEST_USER) == 0) {
|
||||
char pass[32] = {0};
|
||||
taosEncryptPass((uint8_t *)user, strlen(user), pass);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
mDebug("nettest user is authorized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mnodeDeploy(struct SMInfos *minfos) { return 0; }
|
||||
|
||||
void mnodeUnDeploy() {}
|
||||
|
||||
bool mnodeIsServing() { return false; }
|
||||
|
||||
int32_t mnodeGetStatistics(SMnodeStat *stat) { return 0; }
|
||||
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { return 0; }
|
||||
|
||||
void mnodeProcessMsg(SRpcMsg *rpcMsg) {}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitBalance() { return 0; }
|
||||
void mnodeCleanupBalance() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitCluster() { return 0; }
|
||||
void mnodeCleanupCluster() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitDb() { return 0; }
|
||||
void mnodeCleanupDb() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitDnode() { return 0; }
|
||||
void mnodeCleanupDnode() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitFunc() { return 0; }
|
||||
void mnodeCleanupFunc() {}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitMnode() { return 0; }
|
||||
void mnodeCleanupMnode() {}
|
||||
|
||||
void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet, bool redirect) {}
|
||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet, bool redirect) {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitOper() { return 0; }
|
||||
void mnodeCleanupOper() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitProfile() { return 0; }
|
||||
void mnodeCleanupProfile() {}
|
|
@ -0,0 +1,395 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "tglobal.h"
|
||||
#include "cJSON.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static struct {
|
||||
char currDir[PATH_MAX];
|
||||
char backDir[PATH_MAX];
|
||||
char tmpDir[PATH_MAX];
|
||||
int64_t version;
|
||||
EMnKey hashKey[MN_SDB_MAX];
|
||||
int32_t dataSize[MN_SDB_MAX];
|
||||
SHashObj *hashObj[MN_SDB_MAX];
|
||||
SdbDeployFp deployFp[MN_SDB_MAX];
|
||||
SdbEncodeFp encodeFp[MN_SDB_MAX];
|
||||
SdbDecodeFp decodeFp[MN_SDB_MAX];
|
||||
} tsSdb = {0};
|
||||
|
||||
static int32_t sdbCreateDir() {
|
||||
if (!taosMkDir(tsSdb.currDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.currDir);
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.backDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.backDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.tmpDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.tmpDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbRunDeployFp() {
|
||||
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) {
|
||||
SdbDeployFp fp = tsSdb.deployFp[i];
|
||||
if (fp) {
|
||||
(*fp)();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbReadVersion(cJSON *root) {
|
||||
cJSON *ver = cJSON_GetObjectItem(root, "version");
|
||||
if (!ver || ver->type != cJSON_String) {
|
||||
mError("failed to parse version since version not found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsSdb.version = (int64_t)atoll(ver->valuestring);
|
||||
mTrace("parse version success, version:%" PRIu64, tsSdb.version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sdbWriteVersion(FileFd fd) {
|
||||
char content[128];
|
||||
int32_t len =
|
||||
snprintf(content, sizeof(content), "{\"type\":0, \"version\":\"%" PRIu64 "\", \"updateTime\":\"%" PRIu64 "\"}\n",
|
||||
tsSdb.version, taosGetTimestampMs());
|
||||
taosWriteFile(fd, content, len);
|
||||
}
|
||||
|
||||
static int32_t sdbReadDataFile() {
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 4096;
|
||||
char *line = calloc(1, len);
|
||||
int32_t code = -1;
|
||||
FILE *fp = NULL;
|
||||
cJSON *root = NULL;
|
||||
|
||||
char file[PATH_MAX + 20];
|
||||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) {
|
||||
mDebug("failed to open file:%s for read since %s", file, strerror(errno));
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
if (len <= 10) continue;
|
||||
|
||||
root = cJSON_Parse(line);
|
||||
if (root == NULL) {
|
||||
mError("failed to parse since invalid json format, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
cJSON *type = cJSON_GetObjectItem(root, "type");
|
||||
if (!type || type->type != cJSON_Number) {
|
||||
mError("failed to parse since invalid type not found, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
if (type->valueint >= MN_SDB_MAX || type->valueint < MN_SDB_START) {
|
||||
mError("failed to parse since invalid type, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
if (type->valueint == MN_SDB_START) {
|
||||
if (sdbReadVersion(root) != 0) {
|
||||
mError("failed to parse version, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
root = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
SdbDecodeFp decodeFp = tsSdb.decodeFp[type->valueint];
|
||||
SdbHead *pHead = (*decodeFp)(root);
|
||||
if (pHead == NULL) {
|
||||
mError("failed to parse since decode error, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
pHead->type = type->valueint;
|
||||
pHead->status = MN_SDB_STAT_AVAIL;
|
||||
|
||||
sdbInsertRow(pHead->type, pHead);
|
||||
free(pHead);
|
||||
cJSON_Delete(root);
|
||||
root = NULL;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
PARSE_SDB_DATA_ERROR:
|
||||
if (line) free(line);
|
||||
if (fp) fclose(fp);
|
||||
if (root) cJSON_Delete(root);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteDataFile() {
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
FileFd fd = taosOpenFileCreateWrite(file);
|
||||
if (fd <= 0) {
|
||||
mError("failed to open file:%s for write since %s", file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len;
|
||||
int32_t maxLen = 10240;
|
||||
char *buf = malloc(maxLen);
|
||||
|
||||
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObj[i];
|
||||
if (!hash) continue;
|
||||
|
||||
SdbEncodeFp encodeFp = tsSdb.encodeFp[i];
|
||||
if (!encodeFp) continue;
|
||||
|
||||
SdbHead *pHead = taosHashIterate(hash, NULL);
|
||||
while (pHead != NULL) {
|
||||
len = (*encodeFp)(pHead, buf, maxLen);
|
||||
if (len >= 0) {
|
||||
taosWriteFile(fd, buf, len);
|
||||
}
|
||||
|
||||
pHead = taosHashIterate(hash, pHead);
|
||||
}
|
||||
}
|
||||
|
||||
sdbWriteVersion(fd);
|
||||
taosFsyncFile(fd);
|
||||
taosCloseFile(fd);
|
||||
|
||||
mInfo("write file:%s successfully", file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbCommit() {
|
||||
int32_t code = sdbWriteDataFile();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbRead() {
|
||||
int32_t code = sdbReadDataFile();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
mInfo("read sdb file successfully");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t sdbDeploy() {
|
||||
if (sdbCreateDir() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbRunDeployFp() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbCommit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if (!taosMkDir())
|
||||
// if (pMinfos == NULL) { // first deploy
|
||||
// tsMint.dnodeId = 1;
|
||||
// bool getuid = taosGetSystemUid(tsMint.clusterId);
|
||||
// if (!getuid) {
|
||||
// strcpy(tsMint.clusterId, "tdengine3.0");
|
||||
// mError("deploy new mnode but failed to get uid, set to default val %s", tsMint.clusterId);
|
||||
// } else {
|
||||
// mDebug("deploy new mnode and uid is %s", tsMint.clusterId);
|
||||
// }
|
||||
// } else { // todo
|
||||
// }
|
||||
|
||||
// if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
|
||||
// mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
|
||||
// return -1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbUnDeploy() {}
|
||||
|
||||
int32_t sdbInit() {
|
||||
snprintf(tsSdb.currDir, PATH_MAX, "%s%scurrent%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(tsSdb.backDir, PATH_MAX, "%s%sbackup%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(tsSdb.tmpDir, PATH_MAX, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
for (int32_t i = 0; i < MN_SDB_MAX; ++i) {
|
||||
int32_t type;
|
||||
if (tsSdb.hashKey[i] == MN_KEY_INT32) {
|
||||
type = TSDB_DATA_TYPE_INT;
|
||||
} else if (tsSdb.hashKey[i] == MN_KEY_INT64) {
|
||||
type = TSDB_DATA_TYPE_BIGINT;
|
||||
} else {
|
||||
type = TSDB_DATA_TYPE_BINARY;
|
||||
}
|
||||
|
||||
SHashObj *hash = taosHashInit(128, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
|
||||
if (hash == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsSdb.hashObj[i] = hash;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbCleanup() {
|
||||
for (int32_t i = 0; i < MN_SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObj[i];
|
||||
if (hash != NULL) {
|
||||
taosHashCleanup(hash);
|
||||
}
|
||||
tsSdb.hashObj[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void sdbSetFp(EMnSdb sdb, EMnKey keyType, SdbDeployFp deployFp, SdbEncodeFp encodeFp, SdbDecodeFp decodeFp,
|
||||
int32_t dataSize) {
|
||||
tsSdb.deployFp[sdb] = deployFp;
|
||||
tsSdb.encodeFp[sdb] = encodeFp;
|
||||
tsSdb.decodeFp[sdb] = decodeFp;
|
||||
tsSdb.dataSize[sdb] = dataSize;
|
||||
tsSdb.hashKey[sdb] = keyType;
|
||||
}
|
||||
|
||||
static SHashObj *sdbGetHash(int32_t sdb) {
|
||||
if (sdb >= MN_SDB_MAX || sdb <= MN_SDB_START) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHashObj *hash = tsSdb.hashObj[sdb];
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
void *sdbInsertRow(EMnSdb sdb, void *p) {
|
||||
SdbHead *pHead = p;
|
||||
pHead->type = sdb;
|
||||
pHead->status = MN_SDB_STAT_AVAIL;
|
||||
|
||||
char *pKey = (char *)pHead + sizeof(pHead);
|
||||
int32_t keySize;
|
||||
EMnKey keyType = tsSdb.hashKey[pHead->type];
|
||||
int32_t dataSize = tsSdb.dataSize[pHead->type];
|
||||
|
||||
SHashObj *hash = sdbGetHash(pHead->type);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (keyType == MN_KEY_INT32) {
|
||||
keySize = sizeof(int32_t);
|
||||
} else if (keyType == MN_KEY_BINARY) {
|
||||
keySize = strlen(pKey) + 1;
|
||||
} else {
|
||||
keySize = sizeof(int64_t);
|
||||
}
|
||||
|
||||
taosHashPut(hash, pKey, keySize, pHead, dataSize);
|
||||
return taosHashGet(hash, pKey, keySize);
|
||||
}
|
||||
|
||||
void sdbDeleteRow(EMnSdb sdb, void *p) {
|
||||
SdbHead *pHead = p;
|
||||
pHead->status = MN_SDB_STAT_DROPPED;
|
||||
}
|
||||
|
||||
void *sdbUpdateRow(EMnSdb sdb, void *pHead) { return sdbInsertRow(sdb, pHead); }
|
||||
|
||||
void *sdbGetRow(EMnSdb sdb, void *pKey) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t keySize;
|
||||
EMnKey keyType = tsSdb.hashKey[sdb];
|
||||
|
||||
if (keyType == MN_KEY_INT32) {
|
||||
keySize = sizeof(int32_t);
|
||||
} else if (keyType == MN_KEY_BINARY) {
|
||||
keySize = strlen(pKey) + 1;
|
||||
} else {
|
||||
keySize = sizeof(int64_t);
|
||||
}
|
||||
|
||||
return taosHashGet(hash, pKey, keySize);
|
||||
}
|
||||
|
||||
void *sdbFetchRow(EMnSdb sdb, void *pIter) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taosHashIterate(hash, pIter);
|
||||
}
|
||||
|
||||
void sdbCancelFetch(EMnSdb sdb, void *pIter) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosHashCancelIterate(hash, pIter);
|
||||
}
|
||||
|
||||
int32_t sdbGetCount(EMnSdb sdb) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return taosHashGetSize(hash);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitShow() { return 0; }
|
||||
void mnodeCleanUpShow() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitStable() { return 0; }
|
||||
void mnodeCleanupStable() {}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitSync() { return 0; }
|
||||
void mnodeCleanUpSync() {}
|
||||
|
||||
bool mnodeIsMaster() { return true; }
|
|
@ -14,12 +14,9 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeTelem.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeCfg.h"
|
||||
#include "dnodeTelem.h"
|
||||
#include "mnode.h"
|
||||
|
||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||
#define TELEMETRY_PORT 80
|
||||
|
@ -38,9 +35,9 @@ static struct {
|
|||
char email[TSDB_FQDN_LEN];
|
||||
} tsTelem;
|
||||
|
||||
static void dnodeBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
||||
static void mnodeBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
||||
|
||||
static void dnodeCloseObject(SBufferWriter* bw) {
|
||||
static void mnodeCloseObject(SBufferWriter* bw) {
|
||||
size_t len = tbufTell(bw);
|
||||
if (tbufGetData(bw, false)[len - 1] == ',') {
|
||||
tbufWriteCharAt(bw, len - 1, '}');
|
||||
|
@ -66,14 +63,14 @@ static void closeArray(SBufferWriter* bw) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void dnodeWriteString(SBufferWriter* bw, const char* str) {
|
||||
static void mnodeWriteString(SBufferWriter* bw, const char* str) {
|
||||
tbufWriteChar(bw, '"');
|
||||
tbufWrite(bw, str, strlen(str));
|
||||
tbufWriteChar(bw, '"');
|
||||
}
|
||||
|
||||
static void dnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||
dnodeWriteString(bw, k);
|
||||
static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||
mnodeWriteString(bw, k);
|
||||
tbufWriteChar(bw, ':');
|
||||
char buf[32];
|
||||
sprintf(buf, "%" PRId64, v);
|
||||
|
@ -81,14 +78,14 @@ static void dnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
|||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
|
||||
static void dnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
||||
dnodeWriteString(bw, k);
|
||||
static void mnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
||||
mnodeWriteString(bw, k);
|
||||
tbufWriteChar(bw, ':');
|
||||
dnodeWriteString(bw, v);
|
||||
mnodeWriteString(bw, v);
|
||||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
|
||||
static void dnodeAddCpuInfo(SBufferWriter* bw) {
|
||||
static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
int32_t done = 0;
|
||||
|
@ -102,11 +99,11 @@ static void dnodeAddCpuInfo(SBufferWriter* bw) {
|
|||
line[size - 1] = '\0';
|
||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
||||
const char* v = strchr(line, ':') + 2;
|
||||
dnodeAddStringField(bw, "cpuModel", v);
|
||||
mnodeAddStringField(bw, "cpuModel", v);
|
||||
done |= 1;
|
||||
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
||||
const char* v = strchr(line, ':') + 2;
|
||||
dnodeWriteString(bw, "numOfCpu");
|
||||
mnodeWriteString(bw, "numOfCpu");
|
||||
tbufWriteChar(bw, ':');
|
||||
tbufWrite(bw, v, strlen(v));
|
||||
tbufWriteChar(bw, ',');
|
||||
|
@ -118,7 +115,7 @@ static void dnodeAddCpuInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void dnodeAddOsInfo(SBufferWriter* bw) {
|
||||
static void mnodeAddOsInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
|
@ -135,7 +132,7 @@ static void dnodeAddOsInfo(SBufferWriter* bw) {
|
|||
p++;
|
||||
line[size - 2] = 0;
|
||||
}
|
||||
dnodeAddStringField(bw, "os", p);
|
||||
mnodeAddStringField(bw, "os", p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +141,7 @@ static void dnodeAddOsInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void dnodeAddMemoryInfo(SBufferWriter* bw) {
|
||||
static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
|
@ -158,7 +155,7 @@ static void dnodeAddMemoryInfo(SBufferWriter* bw) {
|
|||
if (strncmp(line, "MemTotal", 8) == 0) {
|
||||
const char* p = strchr(line, ':') + 1;
|
||||
while (*p == ' ') p++;
|
||||
dnodeAddStringField(bw, "memory", p);
|
||||
mnodeAddStringField(bw, "memory", p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -167,57 +164,57 @@ static void dnodeAddMemoryInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void dnodeAddVersionInfo(SBufferWriter* bw) {
|
||||
dnodeAddStringField(bw, "version", version);
|
||||
dnodeAddStringField(bw, "buildInfo", buildinfo);
|
||||
dnodeAddStringField(bw, "gitInfo", gitinfo);
|
||||
dnodeAddStringField(bw, "email", tsTelem.email);
|
||||
static void mnodeAddVersionInfo(SBufferWriter* bw) {
|
||||
mnodeAddStringField(bw, "version", version);
|
||||
mnodeAddStringField(bw, "buildInfo", buildinfo);
|
||||
mnodeAddStringField(bw, "gitInfo", gitinfo);
|
||||
mnodeAddStringField(bw, "email", tsTelem.email);
|
||||
}
|
||||
|
||||
static void dnodeAddRuntimeInfo(SBufferWriter* bw) {
|
||||
static void mnodeAddRuntimeInfo(SBufferWriter* bw) {
|
||||
SMnodeStat stat = {0};
|
||||
if (mnodeGetStatistics(&stat) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
dnodeAddIntField(bw, "numOfDnode", stat.numOfDnode);
|
||||
dnodeAddIntField(bw, "numOfMnode", stat.numOfMnode);
|
||||
dnodeAddIntField(bw, "numOfVgroup", stat.numOfVgroup);
|
||||
dnodeAddIntField(bw, "numOfDatabase", stat.numOfDatabase);
|
||||
dnodeAddIntField(bw, "numOfSuperTable", stat.numOfSuperTable);
|
||||
dnodeAddIntField(bw, "numOfChildTable", stat.numOfChildTable);
|
||||
dnodeAddIntField(bw, "numOfColumn", stat.numOfColumn);
|
||||
dnodeAddIntField(bw, "numOfPoint", stat.totalPoints);
|
||||
dnodeAddIntField(bw, "totalStorage", stat.totalStorage);
|
||||
dnodeAddIntField(bw, "compStorage", stat.compStorage);
|
||||
mnodeAddIntField(bw, "numOfDnode", stat.numOfDnode);
|
||||
mnodeAddIntField(bw, "numOfMnode", stat.numOfMnode);
|
||||
mnodeAddIntField(bw, "numOfVgroup", stat.numOfVgroup);
|
||||
mnodeAddIntField(bw, "numOfDatabase", stat.numOfDatabase);
|
||||
mnodeAddIntField(bw, "numOfSuperTable", stat.numOfSuperTable);
|
||||
mnodeAddIntField(bw, "numOfChildTable", stat.numOfChildTable);
|
||||
mnodeAddIntField(bw, "numOfColumn", stat.numOfColumn);
|
||||
mnodeAddIntField(bw, "numOfPoint", stat.totalPoints);
|
||||
mnodeAddIntField(bw, "totalStorage", stat.totalStorage);
|
||||
mnodeAddIntField(bw, "compStorage", stat.compStorage);
|
||||
}
|
||||
|
||||
static void dnodeSendTelemetryReport() {
|
||||
static void mnodeSendTelemetryReport() {
|
||||
char buf[128] = {0};
|
||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||
if (ip == 0xffffffff) {
|
||||
dTrace("failed to get IP address of " TELEMETRY_SERVER ", reason:%s", strerror(errno));
|
||||
mTrace("failed to get IP address of " TELEMETRY_SERVER ", reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
SOCKET fd = taosOpenTcpClientSocket(ip, TELEMETRY_PORT, 0);
|
||||
if (fd < 0) {
|
||||
dTrace("failed to create socket for telemetry, reason:%s", strerror(errno));
|
||||
mTrace("failed to create socket for telemetry, reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN] = {0};
|
||||
dnodeGetClusterId(clusterId);
|
||||
mnodeGetClusterId(clusterId);
|
||||
|
||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
dnodeBeginObject(&bw);
|
||||
dnodeAddStringField(&bw, "instanceId", clusterId);
|
||||
dnodeAddIntField(&bw, "reportVersion", 1);
|
||||
dnodeAddOsInfo(&bw);
|
||||
dnodeAddCpuInfo(&bw);
|
||||
dnodeAddMemoryInfo(&bw);
|
||||
dnodeAddVersionInfo(&bw);
|
||||
dnodeAddRuntimeInfo(&bw);
|
||||
dnodeCloseObject(&bw);
|
||||
mnodeBeginObject(&bw);
|
||||
mnodeAddStringField(&bw, "instanceId", clusterId);
|
||||
mnodeAddIntField(&bw, "reportVersion", 1);
|
||||
mnodeAddOsInfo(&bw);
|
||||
mnodeAddCpuInfo(&bw);
|
||||
mnodeAddMemoryInfo(&bw);
|
||||
mnodeAddVersionInfo(&bw);
|
||||
mnodeAddRuntimeInfo(&bw);
|
||||
mnodeCloseObject(&bw);
|
||||
|
||||
const char* header =
|
||||
"POST /report HTTP/1.1\n"
|
||||
|
@ -235,18 +232,18 @@ static void dnodeSendTelemetryReport() {
|
|||
|
||||
// read something to avoid nginx error 499
|
||||
if (taosReadSocket(fd, buf, 10) < 0) {
|
||||
dTrace("failed to receive response since %s", strerror(errno));
|
||||
mTrace("failed to receive response since %s", strerror(errno));
|
||||
}
|
||||
|
||||
taosCloseSocket(fd);
|
||||
}
|
||||
|
||||
static void* dnodeTelemThreadFp(void* param) {
|
||||
static void* mnodeTelemThreadFp(void* param) {
|
||||
struct timespec end = {0};
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||
|
||||
setThreadName("dnode-telem");
|
||||
setThreadName("mnode-telem");
|
||||
|
||||
while (!tsTelem.exit) {
|
||||
int32_t r = 0;
|
||||
|
@ -257,8 +254,8 @@ static void* dnodeTelemThreadFp(void* param) {
|
|||
if (r == 0) break;
|
||||
if (r != ETIMEDOUT) continue;
|
||||
|
||||
if (mnodeIsServing()) {
|
||||
dnodeSendTelemetryReport();
|
||||
if (mnodeGetStatus() == MN_STATUS_READY) {
|
||||
mnodeSendTelemetryReport();
|
||||
}
|
||||
end.tv_sec += REPORT_INTERVAL;
|
||||
}
|
||||
|
@ -266,20 +263,20 @@ static void* dnodeTelemThreadFp(void* param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void dnodeGetEmail(char* filepath) {
|
||||
static void mnodeGetEmail(char* filepath) {
|
||||
int32_t fd = taosOpenFileRead(filepath);
|
||||
if (fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (taosReadFile(fd, (void*)tsTelem.email, TSDB_FQDN_LEN) < 0) {
|
||||
dError("failed to read %d bytes from file %s since %s", TSDB_FQDN_LEN, filepath, strerror(errno));
|
||||
mError("failed to read %d bytes from file %s since %s", TSDB_FQDN_LEN, filepath, strerror(errno));
|
||||
}
|
||||
|
||||
taosCloseFile(fd);
|
||||
}
|
||||
|
||||
int32_t dnodeInitTelem() {
|
||||
int32_t mnodeInitTelem() {
|
||||
tsTelem.enable = tsEnableTelemetryReporting;
|
||||
if (!tsTelem.enable) return 0;
|
||||
|
||||
|
@ -288,23 +285,23 @@ int32_t dnodeInitTelem() {
|
|||
pthread_cond_init(&tsTelem.cond, NULL);
|
||||
tsTelem.email[0] = 0;
|
||||
|
||||
dnodeGetEmail("/usr/local/taos/email");
|
||||
mnodeGetEmail("/usr/local/taos/email");
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
int32_t code = pthread_create(&tsTelem.thread, &attr, dnodeTelemThreadFp, NULL);
|
||||
int32_t code = pthread_create(&tsTelem.thread, &attr, mnodeTelemThreadFp, NULL);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (code != 0) {
|
||||
dTrace("failed to create telemetry thread since :%s", strerror(code));
|
||||
mTrace("failed to create telemetry thread since :%s", strerror(code));
|
||||
}
|
||||
|
||||
dInfo("dnode telemetry is initialized");
|
||||
mInfo("mnode telemetry is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupTelem() {
|
||||
void mnodeCleanupTelem() {
|
||||
if (!tsTelem.enable) return;
|
||||
|
||||
if (taosCheckPthreadValid(tsTelem.thread)) {
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tkey.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = taosGetTimestampMs();
|
||||
|
||||
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
|
||||
userObj.rootAuth = 1;
|
||||
}
|
||||
|
||||
sdbInsertRow(MN_SDB_USER, &userObj);
|
||||
}
|
||||
|
||||
static void mnodeCreateDefaultUsers() {
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS);
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass);
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass);
|
||||
}
|
||||
|
||||
int32_t mnodeEncodeUser(SUserObj *pUser, char *buf, int32_t maxLen) {
|
||||
int32_t len = 0;
|
||||
char *base64 = base64_encode((const unsigned char *)pUser->pass, TSDB_KEY_LEN);
|
||||
|
||||
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_USER);
|
||||
len += snprintf(buf + len, maxLen - len, "\"user\":\"%s\", ", pUser->user);
|
||||
len += snprintf(buf + len, maxLen - len, "\"auth\":\"%24s\", ", base64);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pUser->acct);
|
||||
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pUser->createdTime);
|
||||
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pUser->updateTime);
|
||||
|
||||
free(base64);
|
||||
return len;
|
||||
}
|
||||
|
||||
SUserObj *mnodeDecodeUser(cJSON *root) {
|
||||
int32_t code = -1;
|
||||
SUserObj *pUser = calloc(1, sizeof(SUserObj));
|
||||
|
||||
cJSON *user = cJSON_GetObjectItem(root, "user");
|
||||
if (!user || user->type != cJSON_String) {
|
||||
mError("failed to parse user since user not found");
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
tstrncpy(pUser->user, user->valuestring, TSDB_USER_LEN);
|
||||
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
pUser->rootAuth = 1;
|
||||
}
|
||||
|
||||
cJSON *pass = cJSON_GetObjectItem(root, "auth");
|
||||
if (!pass || pass->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since auth not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
|
||||
int32_t outlen = 0;
|
||||
char *base64 = (char *)base64_decode(pass->valuestring, strlen(pass->valuestring), &outlen);
|
||||
if (outlen != TSDB_KEY_LEN) {
|
||||
mError("user:%s, failed to parse since invalid auth format", pUser->user);
|
||||
free(base64);
|
||||
goto DECODE_USER_OVER;
|
||||
} else {
|
||||
memcpy(pUser->pass, base64, outlen);
|
||||
free(base64);
|
||||
}
|
||||
|
||||
cJSON *acct = cJSON_GetObjectItem(root, "acct");
|
||||
if (!acct || acct->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since acct not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
tstrncpy(pUser->acct, acct->valuestring, TSDB_USER_LEN);
|
||||
|
||||
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime");
|
||||
if (!createdTime || createdTime->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since createdTime not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
pUser->createdTime = atol(createdTime->valuestring);
|
||||
|
||||
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime");
|
||||
if (!updateTime || updateTime->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since updateTime not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
pUser->updateTime = atol(updateTime->valuestring);
|
||||
|
||||
code = 0;
|
||||
mTrace("user:%s, parse success", pUser->user);
|
||||
|
||||
DECODE_USER_OVER:
|
||||
if (code != 0) {
|
||||
free(pUser);
|
||||
pUser = NULL;
|
||||
}
|
||||
return pUser;
|
||||
}
|
||||
|
||||
int32_t mnodeInitUser() {
|
||||
sdbSetFp(MN_SDB_USER, MN_KEY_BINARY, mnodeCreateDefaultUsers, (SdbEncodeFp)mnodeEncodeUser,
|
||||
(SdbDecodeFp)(mnodeDecodeUser), sizeof(SUserObj));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupUser() {}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
|
||||
int32_t mnodeInitVgroup() { return 0; }
|
||||
void mnodeCleanupVgroup() {}
|
|
@ -0,0 +1,487 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tworker.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeWorker.h"
|
||||
|
||||
static struct {
|
||||
SWorkerPool read;
|
||||
SWorkerPool write;
|
||||
SWorkerPool peerReq;
|
||||
SWorkerPool peerRsp;
|
||||
taos_queue readQ;
|
||||
taos_queue writeQ;
|
||||
taos_queue peerReqQ;
|
||||
taos_queue peerRspQ;
|
||||
int32_t (*writeMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
int32_t (*readMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
int32_t (*peerReqFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
void (*peerRspFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
void (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *pMsg);
|
||||
} tsMworker = {0};
|
||||
|
||||
static SMnMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
|
||||
int32_t size = sizeof(SMnMsg) + pRpcMsg->contLen;
|
||||
SMnMsg *pMsg = taosAllocateQitem(size);
|
||||
|
||||
pMsg->rpcMsg = *pRpcMsg;
|
||||
pMsg->rpcMsg.pCont = pMsg->pCont;
|
||||
pMsg->createdTime = taosGetTimestampSec();
|
||||
memcpy(pMsg->pCont, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) == 0) {
|
||||
pMsg->pUser = sdbGetRow(MN_SDB_USER, connInfo.user);
|
||||
}
|
||||
|
||||
if (pMsg->pUser == NULL) {
|
||||
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
||||
taosFreeQitem(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
static void mnodeCleanupMsg(SMnMsg *pMsg) {
|
||||
if (pMsg == NULL) return;
|
||||
if (pMsg->rpcMsg.pCont != pMsg->pCont) {
|
||||
tfree(pMsg->rpcMsg.pCont);
|
||||
}
|
||||
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeDispatchToWriteQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.writeQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, true);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into wqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.writeQ, TAOS_QTYPE_RPC, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void mnodeReDispatchToWriteQueue(SMnMsg *pMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.writeQ == NULL) {
|
||||
mnodeSendRedirectMsg(&pMsg->rpcMsg, true);
|
||||
mnodeCleanupMsg(pMsg);
|
||||
} else {
|
||||
taosWriteQitem(tsMworker.writeQ, TAOS_QTYPE_RPC, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void mnodeDispatchToReadQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.readQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, true);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into rqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.readQ, TAOS_QTYPE_RPC, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.peerReqQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, false);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into peer req queue", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.peerReqQ, TAOS_QTYPE_RPC, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void mnodeDispatchToPeerRspQueue(SRpcMsg *pRpcMsg) {
|
||||
SMnMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into peer rsp queue", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.peerRspQ, TAOS_QTYPE_RPC, pMsg);
|
||||
}
|
||||
|
||||
// rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
static void mnodeSendRpcRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype, int32_t code) {
|
||||
if (pMsg == NULL) return;
|
||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
|
||||
if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
|
||||
mnodeReDispatchToWriteQueue(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pMsg->rpcMsg.handle,
|
||||
.pCont = pMsg->rpcRsp.rsp,
|
||||
.contLen = pMsg->rpcRsp.len,
|
||||
.code = code,
|
||||
};
|
||||
|
||||
rpcSendResponse(&rpcRsp);
|
||||
mnodeCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
void mnodeSendRsp(SMnMsg *pMsg, int32_t code) { mnodeSendRpcRsp(NULL, pMsg, 0, code); }
|
||||
|
||||
static void mnodeProcessPeerRspEnd(void *ahandle, SMnMsg *pMsg, int32_t qtype, int32_t code) {
|
||||
mnodeCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeInitMsgFp() {
|
||||
// // peer req
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeProcessTableCfgMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeProcessVnodeCfgMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessAuthMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeDispatchToPeerQueue;
|
||||
// // tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_GRANT] = grantProcessMsgInMgmt;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessDnodeStatusMsg;
|
||||
|
||||
// // peer rsp
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeProcessCfgDnodeMsgRsp;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeProcessDropSuperTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeProcessCreateChildTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeProcessDropChildTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeProcessAlterTableRsp;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeProcessCreateVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeProcessAlterVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeProcessCompactVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessDropVnodeRsp;
|
||||
|
||||
// // read msg
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeProcessHeartBeatMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeProcessConnectMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeProcessUseMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeProcessTableMetaMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeProcessMultiTableMetaMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeProcessSuperTableVgroupMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeProcessShowMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeProcessRetrieveMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeProcessRetrieveFuncReq;
|
||||
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = acctProcessCreateAcctMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = acctProcessDropAcctMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = acctProcessAlterAcctMsg;
|
||||
|
||||
// // write msg
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeProcessCreateUserMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeProcessAlterUserMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeProcessDropUserMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeProcessCreateDnodeMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeProcessDropDnodeMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeProcessCfgDnodeMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeProcessCreateDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeProcessAlterDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeProcessDropDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeProcessSyncDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeProcessCompactMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeProcessCreateFuncMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeProcessDropFuncMsg;
|
||||
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = tpProcessCreateTpMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = tpProcessAlterTpMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = tpProcessDropTpMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeProcessCreateTableMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeProcessDropTableMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeProcessAlterTableMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = NULL;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeProcessKillQueryMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeProcessKillStreamMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessKillConnectionMsg;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessWriteReq(void *unused, SMnMsg *pMsg, int32_t qtype) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMworker.writeMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
return (*tsMworker.writeMsgFp[msgType])(pMsg);
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessReadReq(void* unused, SMnMsg *pMsg, int32_t qtype) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
if (!epSet) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
|
||||
epSet->numOfEps, epSet->inUse);
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMworker.readMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
|
||||
return (*tsMworker.readMsgFp[msgType])(pMsg);
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessPeerReq(void *unused, SMnMsg *pMsg, int32_t qtype) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void * ahandle = pMsg->rpcMsg.ahandle;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
if (tsMworker.peerReqFp[msgType] == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
return TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
return (*tsMworker.peerReqFp[msgType])(pMsg);
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessPeerRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tsMworker.peerRspFp[msgType]) {
|
||||
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
|
||||
} else {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mnodeInitWorker() {
|
||||
mnodeInitMsgFp();
|
||||
|
||||
SWorkerPool *pPool = &tsMworker.write;
|
||||
pPool->name = "mnode-write";
|
||||
pPool->startFp = (ProcessStartFp)mnodeProcessWriteReq;
|
||||
pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp;
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.read;
|
||||
pPool->name = "mnode-read";
|
||||
pPool->startFp = (ProcessStartFp)mnodeProcessReadReq;
|
||||
pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp;
|
||||
pPool->min = 2;
|
||||
pPool->max = (int32_t)(tsNumOfCores * tsNumOfThreadsPerCore / 2);
|
||||
pPool->max = MAX(2, pPool->max);
|
||||
pPool->max = MIN(4, pPool->max);
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.readQ = tWorkerAllocQueue(pPool, NULL);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.peerReq;
|
||||
pPool->name = "mnode-peer-req";
|
||||
pPool->startFp = (ProcessStartFp)mnodeProcessPeerReq;
|
||||
pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp;
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.peerRsp;
|
||||
pPool->name = "mnode-peer-rsp";
|
||||
pPool->startFp = (ProcessStartFp)mnodeProcessPeerRsp;
|
||||
pPool->endFp = (ProcessEndFp)mnodeProcessPeerRspEnd;
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL);
|
||||
}
|
||||
|
||||
mInfo("mnode worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupWorker() {
|
||||
tWorkerFreeQueue(&tsMworker.write, tsMworker.writeQ);
|
||||
tWorkerCleanup(&tsMworker.write);
|
||||
tsMworker.writeQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.read, tsMworker.readQ);
|
||||
tWorkerCleanup(&tsMworker.read);
|
||||
tsMworker.readQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.peerReq, tsMworker.peerReqQ);
|
||||
tWorkerCleanup(&tsMworker.peerReq);
|
||||
tsMworker.peerReqQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.peerRsp, tsMworker.peerRspQ);
|
||||
tWorkerCleanup(&tsMworker.peerRsp);
|
||||
tsMworker.peerRspQ = NULL;
|
||||
|
||||
mInfo("mnode worker is closed");
|
||||
}
|
||||
|
||||
void mnodeProcessMsg(SRpcMsg *pMsg) {
|
||||
if (tsMworker.msgFp[pMsg->msgType]) {
|
||||
(*tsMworker.msgFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tstep.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeAuth.h"
|
||||
#include "mnodeBalance.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeOper.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeStable.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeWorker.h"
|
||||
#include "mnodeTelem.h"
|
||||
|
||||
static struct {
|
||||
int32_t state;
|
||||
int32_t dnodeId;
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
tmr_h timer;
|
||||
SMnodeFp fp;
|
||||
SSteps * steps1;
|
||||
SSteps * steps2;
|
||||
} tsMint;
|
||||
|
||||
tmr_h mnodeGetTimer() { return tsMint.timer; }
|
||||
|
||||
int32_t mnodeGetDnodeId() { return tsMint.dnodeId; }
|
||||
|
||||
char *mnodeGetClusterId() { return tsMint.clusterId; }
|
||||
|
||||
EMnStatus mnodeGetStatus() { return tsMint.state; }
|
||||
|
||||
void mnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg) {
|
||||
(*tsMint.fp.SendMsgToDnode)(epSet, rpcMsg);
|
||||
}
|
||||
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsMint.fp.SendMsgToMnode)(rpcMsg); }
|
||||
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell) { (*tsMint.fp.SendRedirectMsg)(rpcMsg, forShell); }
|
||||
|
||||
void mnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port) {
|
||||
(*tsMint.fp.GetDnodeEp)(dnodeId, ep, fqdn, port);
|
||||
}
|
||||
|
||||
int32_t mnodeGetStatistics(SMnodeStat *stat) { return 0; }
|
||||
|
||||
static int32_t mnodeSetPara(SMnodePara para) {
|
||||
tsMint.fp = para.fp;
|
||||
tsMint.dnodeId = para.dnodeId;
|
||||
strncpy(tsMint.clusterId, para.clusterId, TSDB_CLUSTER_ID_LEN);
|
||||
|
||||
if (tsMint.fp.SendMsgToDnode == NULL) return -1;
|
||||
if (tsMint.fp.SendMsgToMnode == NULL) return -1;
|
||||
if (tsMint.fp.SendRedirectMsg == NULL) return -1;
|
||||
if (tsMint.dnodeId < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeInitTimer() {
|
||||
if (tsMint.timer == NULL) {
|
||||
tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeCleanupTimer() {
|
||||
if (tsMint.timer != NULL) {
|
||||
taosTmrCleanUp(tsMint.timer);
|
||||
tsMint.timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeInitStep1() {
|
||||
struct SSteps *steps = taosStepInit(16, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "mnode-sdb", sdbInit, sdbCleanup);
|
||||
taosStepAdd(steps, "mnode-cluster", mnodeInitCluster, mnodeCleanupCluster);
|
||||
taosStepAdd(steps, "mnode-dnode", mnodeInitDnode, mnodeCleanupDnode);
|
||||
taosStepAdd(steps, "mnode-mnode", mnodeInitMnode, mnodeCleanupMnode);
|
||||
taosStepAdd(steps, "mnode-acct", mnodeInitAcct, mnodeCleanupAcct);
|
||||
taosStepAdd(steps, "mnode-auth", mnodeInitAuth, mnodeCleanupAuth);
|
||||
taosStepAdd(steps, "mnode-user", mnodeInitUser, mnodeCleanupUser);
|
||||
taosStepAdd(steps, "mnode-db", mnodeInitDb, mnodeCleanupDb);
|
||||
taosStepAdd(steps, "mnode-vgroup", mnodeInitVgroup, mnodeCleanupVgroup);
|
||||
taosStepAdd(steps, "mnode-stable", mnodeInitStable, mnodeCleanupStable);
|
||||
taosStepAdd(steps, "mnode-func", mnodeInitFunc, mnodeCleanupFunc);
|
||||
taosStepAdd(steps, "mnode-oper", mnodeInitOper, mnodeCleanupOper);
|
||||
|
||||
tsMint.steps1 = steps;
|
||||
return taosStepExec(tsMint.steps1);
|
||||
}
|
||||
|
||||
static int32_t mnodeInitStep2() {
|
||||
struct SSteps *steps = taosStepInit(12, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL);
|
||||
taosStepAdd(steps, "mnode-worker", mnodeInitWorker, NULL);
|
||||
taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance);
|
||||
taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile);
|
||||
taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow);
|
||||
taosStepAdd(steps, "mnode-sync", mnodeInitSync, mnodeCleanUpSync);
|
||||
taosStepAdd(steps, "mnode-worker", NULL, mnodeCleanupWorker);
|
||||
taosStepAdd(steps, "mnode-telem", mnodeInitTelem, mnodeCleanupTelem);
|
||||
taosStepAdd(steps, "mnode-timer", NULL, mnodeCleanupTimer);
|
||||
|
||||
tsMint.steps2 = steps;
|
||||
return taosStepExec(tsMint.steps2);
|
||||
}
|
||||
|
||||
static void mnodeCleanupStep1() { taosStepCleanup(tsMint.steps1); }
|
||||
|
||||
static void mnodeCleanupStep2() { taosStepCleanup(tsMint.steps2); }
|
||||
|
||||
static bool mnodeNeedDeploy() {
|
||||
if (tsMint.dnodeId > 0) return false;
|
||||
if (tsMint.clusterId[0] != 0) return false;
|
||||
if (strcmp(tsFirst, tsLocalEp) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t mnodeDeploy() {
|
||||
if (tsMint.state != MN_STATUS_UNINIT) {
|
||||
mError("failed to deploy mnode since its deployed");
|
||||
return 0;
|
||||
} else {
|
||||
tsMint.state = MN_STATUS_INIT;
|
||||
}
|
||||
|
||||
if (tsMint.dnodeId <= 0 || tsMint.clusterId[0] == 0) {
|
||||
mError("failed to deploy mnode since cluster not ready");
|
||||
return TSDB_CODE_MND_NOT_READY;
|
||||
}
|
||||
|
||||
mInfo("starting to deploy mnode");
|
||||
|
||||
int32_t code = mnodeInitStep1();
|
||||
if (code != 0) {
|
||||
mError("failed to deploy mnode since init step1 error");
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return TSDB_CODE_MND_SDB_ERROR;
|
||||
}
|
||||
|
||||
code = mnodeInitStep2();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
mError("failed to deploy mnode since init step2 error");
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return TSDB_CODE_MND_SDB_ERROR;
|
||||
}
|
||||
|
||||
mDebug("mnode is deployed and waiting for raft to confirm");
|
||||
tsMint.state = MN_STATUS_READY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeUnDeploy() {
|
||||
sdbUnDeploy();
|
||||
mnodeCleanup();
|
||||
}
|
||||
|
||||
int32_t mnodeInit(SMnodePara para) {
|
||||
mDebugFlag = 207;
|
||||
if (tsMint.state != MN_STATUS_UNINIT) {
|
||||
return 0;
|
||||
} else {
|
||||
tsMint.state = MN_STATUS_INIT;
|
||||
}
|
||||
|
||||
mInfo("starting to initialize mnode ...");
|
||||
|
||||
int32_t code = mnodeSetPara(para);
|
||||
if (code != 0) {
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = mnodeInitStep1();
|
||||
if (code != 0) {
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
code = sdbRead();
|
||||
if (code != 0) {
|
||||
if (mnodeNeedDeploy()) {
|
||||
code = sdbDeploy();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
code = mnodeInitStep2();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsMint.state = MN_STATUS_READY;
|
||||
mInfo("mnode is initialized successfully");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanup() {
|
||||
if (tsMint.state != MN_STATUS_UNINIT && tsMint.state != MN_STATUS_CLOSING) {
|
||||
mInfo("starting to clean up mnode");
|
||||
tsMint.state = MN_STATUS_CLOSING;
|
||||
|
||||
mnodeCleanupStep2();
|
||||
mnodeCleanupStep1();
|
||||
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
mInfo("mnode is cleaned up");
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ target_link_libraries(
|
|||
PUBLIC tq
|
||||
PUBLIC tsdb
|
||||
PUBLIC wal
|
||||
PUBLIC sync
|
||||
PUBLIC cjson
|
||||
)
|
||||
|
||||
|
|
|
@ -16,18 +16,19 @@
|
|||
#ifndef _TD_VNODE_INT_H_
|
||||
#define _TD_VNODE_INT_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "amalloc.h"
|
||||
#include "meta.h"
|
||||
#include "os.h"
|
||||
#include "sync.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tlog.h"
|
||||
#include "tq.h"
|
||||
#include "tqueue.h"
|
||||
#include "trpc.h"
|
||||
#include "tsdb.h"
|
||||
#include "vnode.h"
|
||||
#include "tlog.h"
|
||||
#include "tqueue.h"
|
||||
#include "wal.h"
|
||||
#include "tworker.h"
|
||||
#include "vnode.h"
|
||||
#include "wal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -43,51 +44,28 @@ extern int32_t vDebugFlag;
|
|||
#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef struct {
|
||||
SMeta * pMeta;
|
||||
STsdb * pTsdb;
|
||||
STQ * pTQ;
|
||||
SMemAllocator *allocator;
|
||||
|
||||
int32_t vgId; // global vnode group ID
|
||||
int32_t refCount; // reference count
|
||||
int64_t queuedWMsgSize;
|
||||
int32_t queuedWMsg;
|
||||
int32_t queuedRMsg;
|
||||
int32_t numOfExistQHandle; // current initialized and existed query handle in current dnode
|
||||
int32_t flowctrlLevel;
|
||||
int8_t preClose; // drop and close switch
|
||||
int8_t reserved[3];
|
||||
int64_t sequence; // for topic
|
||||
int8_t status;
|
||||
int8_t role;
|
||||
int8_t accessState;
|
||||
int8_t isFull;
|
||||
int8_t isCommiting;
|
||||
int8_t dbReplica;
|
||||
int8_t dropped;
|
||||
int8_t dbType;
|
||||
uint64_t version; // current version
|
||||
uint64_t cversion; // version while commit start
|
||||
uint64_t fversion; // version on saved data file
|
||||
void * wqueue; // write queue
|
||||
void * qqueue; // read query queue
|
||||
void * fqueue; // read fetch/cancel queue
|
||||
void * wal;
|
||||
void * tsdb;
|
||||
int64_t sync;
|
||||
void * events;
|
||||
void * cq; // continuous query
|
||||
int32_t dbCfgVersion;
|
||||
int32_t vgCfgVersion;
|
||||
// STsdbCfg tsdbCfg;
|
||||
#if 0
|
||||
SSyncCfg syncCfg;
|
||||
#endif
|
||||
SWalCfg walCfg;
|
||||
void * qMgmt;
|
||||
char * rootDir;
|
||||
tsem_t sem;
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int32_t vgId; // global vnode group ID
|
||||
int32_t refCount; // reference count
|
||||
SMemAllocator *allocator;
|
||||
SMeta *pMeta;
|
||||
STsdb *pTsdb;
|
||||
STQ *pTQ;
|
||||
twalh pWal;
|
||||
SyncNodeId syncNode;
|
||||
taos_queue pWriteQ; // write queue
|
||||
taos_queue pQueryQ; // read query queue
|
||||
taos_queue pFetchQ; // read fetch/cancel queue
|
||||
SWalCfg walCfg;
|
||||
SSyncCluster syncCfg;
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int64_t queuedWMsgSize;
|
||||
int32_t queuedWMsg;
|
||||
int32_t queuedRMsg;
|
||||
int32_t numOfQHandle; // current initialized and existed query handle in current dnode
|
||||
int8_t status;
|
||||
int8_t role;
|
||||
int8_t accessState;
|
||||
int8_t dropped;
|
||||
pthread_mutex_t statusMutex;
|
||||
} SVnode;
|
||||
|
||||
|
@ -97,8 +75,26 @@ typedef struct {
|
|||
void * qhandle; // used by query and retrieve msg
|
||||
} SVnRsp;
|
||||
|
||||
void vnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
void vnodeSendMsgToMnode(struct SRpcMsg *rpcMsg);
|
||||
void vnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port);
|
||||
|
||||
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg);
|
||||
int32_t vnodeDrop(int32_t vgId);
|
||||
int32_t vnodeOpen(int32_t vgId);
|
||||
int32_t vnodeAlter(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg);
|
||||
int32_t vnodeSync(int32_t vgId);
|
||||
int32_t vnodeClose(int32_t vgId);
|
||||
void vnodeCleanUp(SVnode *pVnode);
|
||||
void vnodeDestroy(SVnode *pVnode);
|
||||
int32_t vnodeCompact(int32_t vgId);
|
||||
void vnodeBackup(int32_t vgId);
|
||||
void vnodeGetStatus(struct SStatusMsg *status);
|
||||
|
||||
SVnode *vnodeAcquire(int32_t vgId);
|
||||
SVnode *vnodeAcquireNotClose(int32_t vgId);
|
||||
void vnodeRelease(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_VNODE_MAIN_H_
|
||||
#define _TD_VNODE_MAIN_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t vnodeInitMain();
|
||||
void vnodeCleanupMain();
|
||||
|
||||
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg);
|
||||
int32_t vnodeDrop(int32_t vgId);
|
||||
int32_t vnodeOpen(int32_t vgId);
|
||||
int32_t vnodeAlter(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg);
|
||||
int32_t vnodeSync(int32_t vgId);
|
||||
int32_t vnodeClose(int32_t vgId);
|
||||
void vnodeCleanUp(SVnode *pVnode);
|
||||
void vnodeDestroy(SVnode *pVnode);
|
||||
int32_t vnodeCompact(int32_t vgId);
|
||||
void vnodeBackup(int32_t vgId);
|
||||
void vnodeGetStatus(struct SStatusMsg *status);
|
||||
|
||||
SVnode *vnodeAcquire(int32_t vgId);
|
||||
SVnode *vnodeAcquireNotClose(int32_t vgId);
|
||||
void vnodeRelease(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_VNODE_MAIN_H_*/
|
|
@ -14,38 +14,935 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "thash.h"
|
||||
// #include "query.h"
|
||||
#include "vnodeCfg.h"
|
||||
#include "vnodeMgmt.h"
|
||||
#include "vnodeRead.h"
|
||||
#include "vnodeStatus.h"
|
||||
#include "vnodeVersion.h"
|
||||
#include "vnodeWorker.h"
|
||||
#include "vnodeWrite.h"
|
||||
#include "tstep.h"
|
||||
#include "vnodeMain.h"
|
||||
#include "vnodeMgmt.h"
|
||||
#include "vnodeRead.h"
|
||||
#include "vnodeWorker.h"
|
||||
#include "vnodeWrite.h"
|
||||
|
||||
typedef struct {
|
||||
pthread_t thread;
|
||||
int32_t threadIndex;
|
||||
int32_t failed;
|
||||
int32_t opened;
|
||||
int32_t vnodeNum;
|
||||
int32_t * vnodeList;
|
||||
} SOpenVnodeThread;
|
||||
|
||||
static struct {
|
||||
struct SSteps *steps;
|
||||
SVnodeFp fp;
|
||||
} tsVint;
|
||||
SSteps *steps;
|
||||
SVnodeFp fp;
|
||||
void * timer;
|
||||
SHashObj *hash;
|
||||
int32_t openVnodes;
|
||||
int32_t totalVnodes;
|
||||
void (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
} tsVnode;
|
||||
|
||||
void vnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port) {
|
||||
return (*tsVnode.fp.GetDnodeEp)(dnodeId, ep, fqdn, port);
|
||||
}
|
||||
|
||||
void vnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg) {
|
||||
(*tsVnode.fp.SendMsgToDnode)(epSet, rpcMsg);
|
||||
}
|
||||
|
||||
void vnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsVnode.fp.SendMsgToMnode)(rpcMsg); }
|
||||
|
||||
static void vnodeIncRef(void *ptNode) {
|
||||
assert(ptNode != NULL);
|
||||
|
||||
SVnode **ppVnode = (SVnode **)ptNode;
|
||||
assert(ppVnode);
|
||||
assert(*ppVnode);
|
||||
|
||||
SVnode *pVnode = *ppVnode;
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
vTrace("vgId:%d, get vnode, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
}
|
||||
|
||||
SVnode *vnodeAcquire(int32_t vgId) {
|
||||
SVnode *pVnode = NULL;
|
||||
|
||||
// taosHashGetClone(tsVnode.hash, &vgId, sizeof(int32_t), vnodeIncRef, (void*)&pVnode);
|
||||
if (pVnode == NULL) {
|
||||
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
vDebug("vgId:%d, not exist", vgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
SVnode *vnodeAcquireNotClose(int32_t vgId) {
|
||||
// SVnode *pVnode = vnodeAcquire(vgId);
|
||||
// if (pVnode != NULL && pVnode->preClose == 1) {
|
||||
// vnodeRelease(pVnode);
|
||||
// terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
// vDebug("vgId:%d, not exist, pre closing", vgId);
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
// return pVnode;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vnodeRelease(SVnode *pVnode) {
|
||||
if (pVnode == NULL) return;
|
||||
|
||||
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
int32_t vgId = pVnode->vgId;
|
||||
|
||||
vTrace("vgId:%d, release vnode, refCount:%d pVnode:%p", vgId, refCount, pVnode);
|
||||
assert(refCount >= 0);
|
||||
|
||||
if (refCount <= 0) {
|
||||
vDebug("vgId:%d, vnode will be destroyed, refCount:%d pVnode:%p", vgId, refCount, pVnode);
|
||||
vnodeProcessDestroyTask(pVnode);
|
||||
int32_t count = taosHashGetSize(tsVnode.hash);
|
||||
vDebug("vgId:%d, vnode is destroyed, vnodes:%d", vgId, count);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno);
|
||||
|
||||
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
||||
int32_t code;
|
||||
|
||||
SVnode *pVnode = vnodeAcquire(pVnodeCfg->cfg.vgId);
|
||||
if (pVnode != NULL) {
|
||||
vDebug("vgId:%d, vnode already exist, refCount:%d pVnode:%p", pVnodeCfg->cfg.vgId, pVnode->refCount, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (tfsMkdir("vnode") < 0) {
|
||||
vError("vgId:%d, failed to create vnode dir, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char vnodeDir[TSDB_FILENAME_LEN] = "\0";
|
||||
snprintf(vnodeDir, TSDB_FILENAME_LEN, "/vnode/vnode%d", pVnodeCfg->cfg.vgId);
|
||||
if (tfsMkdir(vnodeDir) < 0) {
|
||||
vError("vgId:%d, failed to create vnode dir %s, reason:%s", pVnodeCfg->cfg.vgId, vnodeDir, strerror(errno));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = vnodeWriteCfg(pVnodeCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tsdbCreateRepo(pVnodeCfg->cfg.vgId) < 0) {
|
||||
vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||
return TSDB_CODE_VND_INIT_FAILED;
|
||||
}
|
||||
#endif
|
||||
vInfo("vgId:%d, vnode dir is created, walLevel:%d fsyncPeriod:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel,
|
||||
pVnodeCfg->cfg.fsyncPeriod);
|
||||
code = vnodeOpen(pVnodeCfg->cfg.vgId);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodeSync(int32_t vgId) {
|
||||
#if 0
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) {
|
||||
vDebug("vgId:%d, failed to sync, vnode not find", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
|
||||
if (pVnode->role == TAOS_SYNC_ROLE_SLAVE) {
|
||||
vInfo("vgId:%d, vnode will sync, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
pVnode->version = 0;
|
||||
pVnode->fversion = 0;
|
||||
walResetVersion(pVnode->wal, pVnode->fversion);
|
||||
|
||||
syncRecover(pVnode->sync);
|
||||
}
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeDrop(int32_t vgId) {
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) {
|
||||
vDebug("vgId:%d, failed to drop, vnode not find", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
if (pVnode->dropped) {
|
||||
vnodeRelease(pVnode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, vnode will be dropped, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
pVnode->dropped = 1;
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
vnodeProcessCleanupTask(pVnode);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeCompact(int32_t vgId) {
|
||||
#if 0
|
||||
SVnode *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode != NULL) {
|
||||
vDebug("vgId:%d, compact vnode msg is received", vgId);
|
||||
// not care success or not
|
||||
tsdbCompact(((SVnode *)pVnode)->tsdb);
|
||||
vnodeRelease(pVnode);
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode not exist, can't compact it", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeAlterImp(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg) {
|
||||
#if 0
|
||||
STsdbCfg tsdbCfg = pVnode->tsdbCfg;
|
||||
SSyncCfg syncCfg = pVnode->syncCfg;
|
||||
int32_t dbCfgVersion = pVnode->dbCfgVersion;
|
||||
int32_t vgCfgVersion = pVnode->vgCfgVersion;
|
||||
|
||||
int32_t code = vnodeWriteCfg(pVnodeCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = vnodeReadCfg(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = walAlter(pVnode->wal, &pVnode->walCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool tsdbCfgChanged = (memcmp(&tsdbCfg, &pVnode->tsdbCfg, sizeof(STsdbCfg)) != 0);
|
||||
bool syncCfgChanged = (memcmp(&syncCfg, &pVnode->syncCfg, sizeof(SSyncCfg)) != 0);
|
||||
|
||||
vDebug("vgId:%d, tsdbchanged:%d syncchanged:%d while alter vnode", pVnode->vgId, tsdbCfgChanged, syncCfgChanged);
|
||||
|
||||
if (tsdbCfgChanged || syncCfgChanged) {
|
||||
// vnode in non-ready state and still needs to return success instead of TSDB_CODE_VND_INVALID_STATUS
|
||||
// dbCfgVersion can be corrected by status msg
|
||||
if (syncCfgChanged) {
|
||||
if (!vnodeSetUpdatingStatus(pVnode)) {
|
||||
vDebug("vgId:%d, vnode is not ready, do alter operation later", pVnode->vgId);
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
code = syncReconfig(pVnode->sync, &pVnode->syncCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (tsdbCfgChanged && pVnode->tsdb) {
|
||||
code = tsdbConfigRepo(pVnode->tsdb, &pVnode->tsdbCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg) {
|
||||
#if 0
|
||||
vDebug("vgId:%d, current dbCfgVersion:%d vgCfgVersion:%d, input dbCfgVersion:%d vgCfgVersion:%d", pVnode->vgId,
|
||||
pVnode->dbCfgVersion, pVnode->vgCfgVersion, pVnodeCfg->cfg.dbCfgVersion, pVnodeCfg->cfg.vgCfgVersion);
|
||||
|
||||
if (pVnode->dbCfgVersion == pVnodeCfg->cfg.dbCfgVersion && pVnode->vgCfgVersion == pVnodeCfg->cfg.vgCfgVersion) {
|
||||
vDebug("vgId:%d, cfg not change", pVnode->vgId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = vnodeAlterImp(pVnode, pVnodeCfg);
|
||||
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to alter vnode, code:0x%x", pVnode->vgId, code);
|
||||
} else {
|
||||
vDebug("vgId:%d, vnode is altered", pVnode->vgId);
|
||||
}
|
||||
|
||||
return code;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vnodeFindWalRootDir(int32_t vgId, char *walRootDir) {
|
||||
#if 0
|
||||
char vnodeDir[TSDB_FILENAME_LEN] = "\0";
|
||||
snprintf(vnodeDir, TSDB_FILENAME_LEN, "/vnode/vnode%d/wal", vgId);
|
||||
|
||||
TDIR *tdir = tfsOpendir(vnodeDir);
|
||||
if (!tdir) return;
|
||||
|
||||
const TFILE *tfile = tfsReaddir(tdir);
|
||||
if (!tfile) {
|
||||
tfsClosedir(tdir);
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(walRootDir, "%s/vnode/vnode%d", TFS_DISK_PATH(tfile->level, tfile->id), vgId);
|
||||
|
||||
tfsClosedir(tdir);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t vnodeOpen(int32_t vgId) {
|
||||
#if 0
|
||||
char temp[TSDB_FILENAME_LEN * 3];
|
||||
char rootDir[TSDB_FILENAME_LEN * 2];
|
||||
char walRootDir[TSDB_FILENAME_LEN * 2] = {0};
|
||||
snprintf(rootDir, TSDB_FILENAME_LEN * 2, "%s/vnode%d", tsVnodeDir, vgId);
|
||||
|
||||
SVnode *pVnode = calloc(sizeof(SVnode), 1);
|
||||
if (pVnode == NULL) {
|
||||
vError("vgId:%d, failed to open vnode since no enough memory", vgId);
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
|
||||
pVnode->vgId = vgId;
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = 0;
|
||||
pVnode->tsdbCfg.tsdbId = pVnode->vgId;
|
||||
pVnode->rootDir = strdup(rootDir);
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
tsem_init(&pVnode->sem, 0, 0);
|
||||
pthread_mutex_init(&pVnode->statusMutex, NULL);
|
||||
vnodeSetInitStatus(pVnode);
|
||||
|
||||
tsdbIncCommitRef(pVnode->vgId);
|
||||
|
||||
int32_t code = vnodeReadCfg(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to read config file, set cfgVersion to 0", pVnode->vgId);
|
||||
vnodeCleanUp(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
code = vnodeReadVersion(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->version = 0;
|
||||
vError("vgId:%d, failed to read file version, generate it from data file", pVnode->vgId);
|
||||
// Allow vnode start even when read file version fails, set file version as wal version or zero
|
||||
// vnodeCleanUp(pVnode);
|
||||
// return code;
|
||||
}
|
||||
|
||||
pVnode->fversion = pVnode->version;
|
||||
|
||||
pVnode->pWriteQ = vnodeAllocWriteQueue(pVnode);
|
||||
pVnode->pQueryQ = vnodeAllocQueryQueue(pVnode);
|
||||
pVnode->pFetchQ = vnodeAllocFetchQueue(pVnode);
|
||||
if (pVnode->pWriteQ == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
STsdbAppH appH = {0};
|
||||
appH.appH = (void *)pVnode;
|
||||
appH.notifyStatus = vnodeProcessTsdbStatus;
|
||||
appH.cqH = pVnode->cq;
|
||||
appH.cqCreateFunc = cqCreate;
|
||||
appH.cqDropFunc = cqDrop;
|
||||
|
||||
terrno = 0;
|
||||
pVnode->tsdb = tsdbOpenRepo(&(pVnode->tsdbCfg), &appH);
|
||||
if (pVnode->tsdb == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
} else if (tsdbGetState(pVnode->tsdb) != TSDB_STATE_OK) {
|
||||
vError("vgId:%d, failed to open tsdb(state: %d), replica:%d reason:%s", pVnode->vgId, tsdbGetState(pVnode->tsdb),
|
||||
pVnode->syncCfg.replica, tstrerror(terrno));
|
||||
if (pVnode->syncCfg.replica <= 1) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return TSDB_CODE_VND_INVALID_TSDB_STATE;
|
||||
} else {
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// walRootDir for wal & syncInfo.path (not empty dir of /vnode/vnode{pVnode->vgId}/wal)
|
||||
vnodeFindWalRootDir(pVnode->vgId, walRootDir);
|
||||
if (walRootDir[0] == 0) {
|
||||
int level = -1, id = -1;
|
||||
|
||||
tfsAllocDisk(TFS_PRIMARY_LEVEL, &level, &id);
|
||||
if (level < 0 || id < 0) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
sprintf(walRootDir, "%s/vnode/vnode%d", TFS_DISK_PATH(level, id), vgId);
|
||||
}
|
||||
|
||||
sprintf(temp, "%s/wal", walRootDir);
|
||||
pVnode->walCfg.vgId = pVnode->vgId;
|
||||
pVnode->wal = walOpen(temp, &pVnode->walCfg);
|
||||
if (pVnode->wal == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
walRestore(pVnode->wal, pVnode, (FWalWrite)vnodeProcessWalMsg);
|
||||
if (pVnode->version == 0) {
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = walGetVersion(pVnode->wal);
|
||||
}
|
||||
|
||||
code = tsdbSyncCommit(pVnode->tsdb);
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to commit after restore from wal since %s", pVnode->vgId, tstrerror(code));
|
||||
vnodeCleanUp(pVnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
walRemoveAllOldFiles(pVnode->wal);
|
||||
walRenew(pVnode->wal);
|
||||
|
||||
pVnode->qMgmt = qOpenQueryMgmt(pVnode->vgId);
|
||||
if (pVnode->qMgmt == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pVnode->events = NULL;
|
||||
|
||||
vDebug("vgId:%d, vnode is opened in %s - %s, pVnode:%p", pVnode->vgId, rootDir, walRootDir, pVnode);
|
||||
|
||||
taosHashPut(tsVnode.hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnode *));
|
||||
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
pVnode->role = TAOS_SYNC_ROLE_MASTER;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeClose(int32_t vgId) {
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) return 0;
|
||||
if (pVnode->dropped) {
|
||||
vnodeRelease(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pVnode->preClose = 1;
|
||||
|
||||
vDebug("vgId:%d, vnode will be closed, pVnode:%p", pVnode->vgId, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
vnodeCleanUp(pVnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeDestroy(SVnode *pVnode) {
|
||||
#if 0
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pVnode->vgId;
|
||||
|
||||
if (pVnode->qMgmt) {
|
||||
qCleanupQueryMgmt(pVnode->qMgmt);
|
||||
pVnode->qMgmt = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->wal) {
|
||||
walStop(pVnode->wal);
|
||||
}
|
||||
|
||||
if (pVnode->tsdb) {
|
||||
// the deleted vnode does not need to commit, so as to speed up the deletion
|
||||
int toCommit = 1;
|
||||
if (pVnode->dropped) toCommit = 0;
|
||||
|
||||
code = tsdbCloseRepo(pVnode->tsdb, toCommit);
|
||||
pVnode->tsdb = NULL;
|
||||
}
|
||||
|
||||
// stop continuous query
|
||||
if (pVnode->cq) {
|
||||
void *cq = pVnode->cq;
|
||||
pVnode->cq = NULL;
|
||||
cqClose(cq);
|
||||
}
|
||||
|
||||
if (pVnode->wal) {
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to commit while close tsdb repo, keep wal", pVnode->vgId);
|
||||
} else {
|
||||
walRemoveAllOldFiles(pVnode->wal);
|
||||
}
|
||||
walClose(pVnode->wal);
|
||||
pVnode->wal = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->pWriteQ) {
|
||||
vnodeFreeWriteQueue(pVnode->pWriteQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->pQueryQ) {
|
||||
vnodeFreeQueryQueue(pVnode->pQueryQ);
|
||||
pVnode->pQueryQ = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->pFetchQ) {
|
||||
vnodeFreeFetchQueue(pVnode->pFetchQ);
|
||||
pVnode->pFetchQ = NULL;
|
||||
}
|
||||
|
||||
tfree(pVnode->rootDir);
|
||||
|
||||
if (pVnode->dropped) {
|
||||
char rootDir[TSDB_FILENAME_LEN] = {0};
|
||||
char stagingDir[TSDB_FILENAME_LEN] = {0};
|
||||
sprintf(rootDir, "%s/vnode%d", "vnode", vgId);
|
||||
sprintf(stagingDir, "%s/.staging/vnode%d", "vnode_bak", vgId);
|
||||
|
||||
tfsRename(rootDir, stagingDir);
|
||||
|
||||
vnodeProcessBackupTask(pVnode);
|
||||
|
||||
// dnodeSendStatusMsgToMnode();
|
||||
}
|
||||
|
||||
tsem_destroy(&pVnode->sem);
|
||||
pthread_mutex_destroy(&pVnode->statusMutex);
|
||||
free(pVnode);
|
||||
tsdbDecCommitRef(vgId);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vnodeCleanUp(SVnode *pVnode) {
|
||||
#if 0
|
||||
vDebug("vgId:%d, vnode will cleanup, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
vnodeSetClosingStatus(pVnode);
|
||||
|
||||
taosHashRemove(tsVnode.hash, &pVnode->vgId, sizeof(int32_t));
|
||||
|
||||
// stop replication module
|
||||
if (pVnode->sync > 0) {
|
||||
int64_t sync = pVnode->sync;
|
||||
pVnode->sync = -1;
|
||||
syncStop(sync);
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, vnode is cleaned, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
|
||||
SVnode *pVnode = arg;
|
||||
|
||||
if (eno != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to commit since %s, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, tstrerror(eno),
|
||||
pVnode->fversion, pVnode->version);
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status == TSDB_STATUS_COMMIT_START) {
|
||||
pVnode->isCommiting = 1;
|
||||
pVnode->cversion = pVnode->version;
|
||||
vInfo("vgId:%d, start commit, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
if (!vnodeInInitStatus(pVnode)) {
|
||||
return walRenew(pVnode->wal);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status == TSDB_STATUS_COMMIT_OVER) {
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 0;
|
||||
pVnode->fversion = pVnode->cversion;
|
||||
vInfo("vgId:%d, commit over, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
if (!vnodeInInitStatus(pVnode)) {
|
||||
walRemoveOneOldFile(pVnode->wal);
|
||||
}
|
||||
return vnodeSaveVersion(pVnode);
|
||||
}
|
||||
|
||||
// timer thread callback
|
||||
if (status == TSDB_STATUS_COMMIT_NOBLOCK) {
|
||||
qSolveCommitNoBlock(pVnode->tsdb, pVnode->qMgmt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *vnodeOpenVnode(void *param) {
|
||||
SOpenVnodeThread *pThread = param;
|
||||
|
||||
vDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("vnodeOpenVnode");
|
||||
|
||||
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
||||
int32_t vgId = pThread->vnodeList[v];
|
||||
|
||||
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId,
|
||||
tsVnode.openVnodes, tsVnode.totalVnodes);
|
||||
// (*vnodeInst()->fp.ReportStartup)("open-vnodes", stepDesc);
|
||||
|
||||
if (vnodeOpen(vgId) < 0) {
|
||||
vError("vgId:%d, failed to open vnode by thread:%d", vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
} else {
|
||||
vDebug("vgId:%d, is opened by thread:%d", vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&tsVnode.openVnodes, 1);
|
||||
}
|
||||
|
||||
vDebug("thread:%d, total vnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||
pThread->failed);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t vnodeGetVnodeListFromDisk(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||
#if 0
|
||||
DIR *dir = opendir(tsVnodeDir);
|
||||
if (dir == NULL) return TSDB_CODE_DND_NO_WRITE_ACCESS;
|
||||
|
||||
*numOfVnodes = 0;
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||
if (de->d_type & DT_DIR) {
|
||||
if (strncmp("vnode", de->d_name, 5) != 0) continue;
|
||||
int32_t vnode = atoi(de->d_name + 5);
|
||||
if (vnode == 0) continue;
|
||||
|
||||
(*numOfVnodes)++;
|
||||
|
||||
if (*numOfVnodes >= TSDB_MAX_VNODES) {
|
||||
vError("vgId:%d, too many vnode directory in disk, exist:%d max:%d", vnode, *numOfVnodes, TSDB_MAX_VNODES);
|
||||
closedir(dir);
|
||||
return TSDB_CODE_DND_TOO_MANY_VNODES;
|
||||
} else {
|
||||
vnodeList[*numOfVnodes - 1] = vnode;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeOpenVnodes() {
|
||||
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
int32_t status = vnodeGetVnodeListFromDisk(vnodeList, &numOfVnodes);
|
||||
|
||||
if (status != TSDB_CODE_SUCCESS) {
|
||||
vInfo("failed to get vnode list from disk since code:%d", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
tsVnode.totalVnodes = numOfVnodes;
|
||||
|
||||
int32_t threadNum = tsNumOfCores;
|
||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||
|
||||
SOpenVnodeThread *threads = calloc(threadNum, sizeof(SOpenVnodeThread));
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
threads[t].threadIndex = t;
|
||||
threads[t].vnodeList = calloc(vnodesPerThread, sizeof(int32_t));
|
||||
}
|
||||
|
||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||
int32_t t = v % threadNum;
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
pThread->vnodeList[pThread->vnodeNum++] = vnodeList[v];
|
||||
}
|
||||
|
||||
vInfo("start %d threads to open %d vnodes", threadNum, numOfVnodes);
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum == 0) continue;
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (pthread_create(&pThread->thread, &thAttr, vnodeOpenVnode, pThread) != 0) {
|
||||
vError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno));
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
}
|
||||
|
||||
int32_t openVnodes = 0;
|
||||
int32_t failedVnodes = 0;
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
|
||||
pthread_join(pThread->thread, NULL);
|
||||
}
|
||||
openVnodes += pThread->opened;
|
||||
failedVnodes += pThread->failed;
|
||||
free(pThread->vnodeList);
|
||||
}
|
||||
|
||||
free(threads);
|
||||
vInfo("there are total vnodes:%d, opened:%d", numOfVnodes, openVnodes);
|
||||
|
||||
if (failedVnodes != 0) {
|
||||
vError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||
void *pIter = taosHashIterate(tsVnode.hash, NULL);
|
||||
while (pIter) {
|
||||
SVnode **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
(*numOfVnodes)++;
|
||||
if (*numOfVnodes >= TSDB_MAX_VNODES) {
|
||||
vError("vgId:%d, too many open vnodes, exist:%d max:%d", (*pVnode)->vgId, *numOfVnodes, TSDB_MAX_VNODES);
|
||||
continue;
|
||||
} else {
|
||||
vnodeList[*numOfVnodes - 1] = (*pVnode)->vgId;
|
||||
}
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(tsVnode.hash, pIter);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void vnodeCleanupVnodes() {
|
||||
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
|
||||
int32_t code = vnodeGetVnodeList(vnodeList, &numOfVnodes);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vInfo("failed to get dnode list since code %d", code);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
vnodeClose(vnodeList[i]);
|
||||
}
|
||||
|
||||
vInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||
}
|
||||
|
||||
static void vnodeInitMsgFp() {
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessWriteMsg;
|
||||
//mq related
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessWriteMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessReadMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessReadMsg;
|
||||
//mq related end
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessReadMsg;
|
||||
tsVnode.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessReadMsg;
|
||||
}
|
||||
|
||||
void vnodeProcessMsg(SRpcMsg *pMsg) {
|
||||
if (tsVnode.msgFp[pMsg->msgType]) {
|
||||
(*tsVnode.msgFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t vnodeInitMain() {
|
||||
vnodeInitMsgFp();
|
||||
|
||||
tsVnode.timer = taosTmrInit(100, 200, 60000, "VND-TIMER");
|
||||
if (tsVnode.timer == NULL) {
|
||||
vError("failed to init vnode timer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsVnode.hash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (tsVnode.hash == NULL) {
|
||||
taosTmrCleanUp(tsVnode.timer);
|
||||
vError("failed to init vnode mgmt");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vInfo("vnode main is initialized");
|
||||
return vnodeOpenVnodes();
|
||||
}
|
||||
|
||||
void vnodeCleanupMain() {
|
||||
taosTmrCleanUp(tsVnode.timer);
|
||||
tsVnode.timer = NULL;
|
||||
|
||||
vnodeCleanupVnodes();
|
||||
|
||||
taosHashCleanup(tsVnode.hash);
|
||||
tsVnode.hash = NULL;
|
||||
}
|
||||
|
||||
static void vnodeBuildVloadMsg(SVnode *pVnode, SStatusMsg *pStatus) {
|
||||
#if 0
|
||||
int64_t totalStorage = 0;
|
||||
int64_t compStorage = 0;
|
||||
int64_t pointsWritten = 0;
|
||||
|
||||
if (vnodeInClosingStatus(pVnode)) return;
|
||||
if (pStatus->openVnodes >= TSDB_MAX_VNODES) return;
|
||||
|
||||
if (pVnode->tsdb) {
|
||||
tsdbReportStat(pVnode->tsdb, &pointsWritten, &totalStorage, &compStorage);
|
||||
}
|
||||
|
||||
SVnodeLoad *pLoad = &pStatus->load[pStatus->openVnodes++];
|
||||
pLoad->vgId = htonl(pVnode->vgId);
|
||||
pLoad->dbCfgVersion = htonl(pVnode->dbCfgVersion);
|
||||
pLoad->vgCfgVersion = htonl(pVnode->vgCfgVersion);
|
||||
pLoad->totalStorage = htobe64(totalStorage);
|
||||
pLoad->compStorage = htobe64(compStorage);
|
||||
pLoad->pointsWritten = htobe64(pointsWritten);
|
||||
pLoad->vnodeVersion = htobe64(pVnode->version);
|
||||
pLoad->status = pVnode->status;
|
||||
pLoad->role = pVnode->role;
|
||||
pLoad->replica = pVnode->syncCfg.replica;
|
||||
pLoad->compact = (pVnode->tsdb != NULL) ? tsdbGetCompactState(pVnode->tsdb) : 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void vnodeGetStatus(struct SStatusMsg *pStatus) {
|
||||
void *pIter = taosHashIterate(tsVnode.hash, NULL);
|
||||
while (pIter) {
|
||||
SVnode **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
vnodeBuildVloadMsg(*pVnode, pStatus);
|
||||
}
|
||||
pIter = taosHashIterate(tsVnode.hash, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void vnodeSetAccess(struct SVgroupAccess *pAccess, int32_t numOfVnodes) {
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
pAccess[i].vgId = htonl(pAccess[i].vgId);
|
||||
SVnode *pVnode = vnodeAcquireNotClose(pAccess[i].vgId);
|
||||
if (pVnode != NULL) {
|
||||
pVnode->accessState = pAccess[i].accessState;
|
||||
if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) {
|
||||
vDebug("vgId:%d, access state is set to %d", pAccess[i].vgId, pVnode->accessState);
|
||||
}
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vnodeBackup(int32_t vgId) {
|
||||
char newDir[TSDB_FILENAME_LEN] = {0};
|
||||
char stagingDir[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
sprintf(newDir, "%s/vnode%d", "vnode_bak", vgId);
|
||||
sprintf(stagingDir, "%s/.staging/vnode%d", "vnode_bak", vgId);
|
||||
|
||||
#if 0
|
||||
if (tsEnableVnodeBak) {
|
||||
tfsRmdir(newDir);
|
||||
tfsRename(stagingDir, newDir);
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode backup not enabled", vgId);
|
||||
|
||||
tfsRmdir(stagingDir);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t vnodeInit(SVnodePara para) {
|
||||
tsVint.fp = para.fp;
|
||||
tsVnode.fp = para.fp;
|
||||
|
||||
struct SSteps *steps = taosStepInit(8, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "vnode-main", vnodeInitMain, vnodeCleanupMain);
|
||||
taosStepAdd(steps, "vnode-worker",vnodeInitWorker, vnodeCleanupWorker);
|
||||
taosStepAdd(steps, "vnode-worker", vnodeInitWorker, vnodeCleanupWorker);
|
||||
taosStepAdd(steps, "vnode-read", vnodeInitRead, vnodeCleanupRead);
|
||||
taosStepAdd(steps, "vnode-mgmt", vnodeInitMgmt, vnodeCleanupMgmt);
|
||||
taosStepAdd(steps, "vnode-write", vnodeInitWrite, vnodeCleanupWrite);
|
||||
// taosStepAdd(steps, "vnode-queue", tsdbInitCommitQueue, tsdbDestroyCommitQueue);
|
||||
|
||||
tsVint.steps = steps;
|
||||
return taosStepExec(tsVint.steps);
|
||||
tsVnode.steps = steps;
|
||||
return taosStepExec(tsVnode.steps);
|
||||
}
|
||||
|
||||
void vnodeCleanup() { taosStepCleanup(tsVint.steps); }
|
||||
|
||||
void vnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port) {
|
||||
return (*tsVint.fp.GetDnodeEp)(dnodeId, ep, fqdn, port);
|
||||
}
|
||||
void vnodeCleanup() { taosStepCleanup(tsVnode.steps); }
|
||||
|
|
|
@ -1,917 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "thash.h"
|
||||
// #include "query.h"
|
||||
#include "vnodeCfg.h"
|
||||
#include "vnodeMain.h"
|
||||
#include "vnodeMgmt.h"
|
||||
#include "vnodeRead.h"
|
||||
#include "vnodeStatus.h"
|
||||
#include "vnodeVersion.h"
|
||||
#include "vnodeWorker.h"
|
||||
#include "vnodeWrite.h"
|
||||
|
||||
typedef struct {
|
||||
pthread_t thread;
|
||||
int32_t threadIndex;
|
||||
int32_t failed;
|
||||
int32_t opened;
|
||||
int32_t vnodeNum;
|
||||
int32_t * vnodeList;
|
||||
} SOpenVnodeThread;
|
||||
|
||||
static struct {
|
||||
void * timer;
|
||||
SHashObj *hash;
|
||||
int32_t openVnodes;
|
||||
int32_t totalVnodes;
|
||||
void (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
} tsVmain;
|
||||
|
||||
static void vnodeIncRef(void *ptNode) {
|
||||
assert(ptNode != NULL);
|
||||
|
||||
SVnode **ppVnode = (SVnode **)ptNode;
|
||||
assert(ppVnode);
|
||||
assert(*ppVnode);
|
||||
|
||||
SVnode *pVnode = *ppVnode;
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
vTrace("vgId:%d, get vnode, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
}
|
||||
|
||||
SVnode *vnodeAcquire(int32_t vgId) {
|
||||
SVnode *pVnode = NULL;
|
||||
|
||||
#if 0
|
||||
taosHashGetClone(tsVmain.hash, &vgId, sizeof(int32_t), vnodeIncRef, &pVnode);
|
||||
#endif
|
||||
if (pVnode == NULL) {
|
||||
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
vDebug("vgId:%d, not exist", vgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
SVnode *vnodeAcquireNotClose(int32_t vgId) {
|
||||
SVnode *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode != NULL && pVnode->preClose == 1) {
|
||||
vnodeRelease(pVnode);
|
||||
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
vDebug("vgId:%d, not exist, pre closing", vgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
void vnodeRelease(SVnode *pVnode) {
|
||||
if (pVnode == NULL) return;
|
||||
|
||||
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
int32_t vgId = pVnode->vgId;
|
||||
|
||||
vTrace("vgId:%d, release vnode, refCount:%d pVnode:%p", vgId, refCount, pVnode);
|
||||
assert(refCount >= 0);
|
||||
|
||||
if (refCount <= 0) {
|
||||
vDebug("vgId:%d, vnode will be destroyed, refCount:%d pVnode:%p", vgId, refCount, pVnode);
|
||||
vnodeProcessDestroyTask(pVnode);
|
||||
int32_t count = taosHashGetSize(tsVmain.hash);
|
||||
vDebug("vgId:%d, vnode is destroyed, vnodes:%d", vgId, count);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno);
|
||||
|
||||
int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
||||
int32_t code;
|
||||
|
||||
SVnode *pVnode = vnodeAcquire(pVnodeCfg->cfg.vgId);
|
||||
if (pVnode != NULL) {
|
||||
vDebug("vgId:%d, vnode already exist, refCount:%d pVnode:%p", pVnodeCfg->cfg.vgId, pVnode->refCount, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (tfsMkdir("vnode") < 0) {
|
||||
vError("vgId:%d, failed to create vnode dir, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
char vnodeDir[TSDB_FILENAME_LEN] = "\0";
|
||||
snprintf(vnodeDir, TSDB_FILENAME_LEN, "/vnode/vnode%d", pVnodeCfg->cfg.vgId);
|
||||
if (tfsMkdir(vnodeDir) < 0) {
|
||||
vError("vgId:%d, failed to create vnode dir %s, reason:%s", pVnodeCfg->cfg.vgId, vnodeDir, strerror(errno));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = vnodeWriteCfg(pVnodeCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to save vnode cfg, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tsdbCreateRepo(pVnodeCfg->cfg.vgId) < 0) {
|
||||
vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(terrno));
|
||||
return TSDB_CODE_VND_INIT_FAILED;
|
||||
}
|
||||
#endif
|
||||
vInfo("vgId:%d, vnode dir is created, walLevel:%d fsyncPeriod:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel,
|
||||
pVnodeCfg->cfg.fsyncPeriod);
|
||||
code = vnodeOpen(pVnodeCfg->cfg.vgId);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodeSync(int32_t vgId) {
|
||||
#if 0
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) {
|
||||
vDebug("vgId:%d, failed to sync, vnode not find", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
|
||||
if (pVnode->role == TAOS_SYNC_ROLE_SLAVE) {
|
||||
vInfo("vgId:%d, vnode will sync, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
pVnode->version = 0;
|
||||
pVnode->fversion = 0;
|
||||
walResetVersion(pVnode->wal, pVnode->fversion);
|
||||
|
||||
syncRecover(pVnode->sync);
|
||||
}
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeDrop(int32_t vgId) {
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) {
|
||||
vDebug("vgId:%d, failed to drop, vnode not find", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
if (pVnode->dropped) {
|
||||
vnodeRelease(pVnode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, vnode will be dropped, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
pVnode->dropped = 1;
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
vnodeProcessCleanupTask(pVnode);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeCompact(int32_t vgId) {
|
||||
#if 0
|
||||
SVnode *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode != NULL) {
|
||||
vDebug("vgId:%d, compact vnode msg is received", vgId);
|
||||
// not care success or not
|
||||
tsdbCompact(((SVnode *)pVnode)->tsdb);
|
||||
vnodeRelease(pVnode);
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode not exist, can't compact it", vgId);
|
||||
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeAlterImp(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg) {
|
||||
#if 0
|
||||
STsdbCfg tsdbCfg = pVnode->tsdbCfg;
|
||||
SSyncCfg syncCfg = pVnode->syncCfg;
|
||||
int32_t dbCfgVersion = pVnode->dbCfgVersion;
|
||||
int32_t vgCfgVersion = pVnode->vgCfgVersion;
|
||||
|
||||
int32_t code = vnodeWriteCfg(pVnodeCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = vnodeReadCfg(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = walAlter(pVnode->wal, &pVnode->walCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool tsdbCfgChanged = (memcmp(&tsdbCfg, &pVnode->tsdbCfg, sizeof(STsdbCfg)) != 0);
|
||||
bool syncCfgChanged = (memcmp(&syncCfg, &pVnode->syncCfg, sizeof(SSyncCfg)) != 0);
|
||||
|
||||
vDebug("vgId:%d, tsdbchanged:%d syncchanged:%d while alter vnode", pVnode->vgId, tsdbCfgChanged, syncCfgChanged);
|
||||
|
||||
if (tsdbCfgChanged || syncCfgChanged) {
|
||||
// vnode in non-ready state and still needs to return success instead of TSDB_CODE_VND_INVALID_STATUS
|
||||
// dbCfgVersion can be corrected by status msg
|
||||
if (syncCfgChanged) {
|
||||
if (!vnodeSetUpdatingStatus(pVnode)) {
|
||||
vDebug("vgId:%d, vnode is not ready, do alter operation later", pVnode->vgId);
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
code = syncReconfig(pVnode->sync, &pVnode->syncCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (tsdbCfgChanged && pVnode->tsdb) {
|
||||
code = tsdbConfigRepo(pVnode->tsdb, &pVnode->tsdbCfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->dbCfgVersion = dbCfgVersion;
|
||||
pVnode->vgCfgVersion = vgCfgVersion;
|
||||
pVnode->syncCfg = syncCfg;
|
||||
pVnode->tsdbCfg = tsdbCfg;
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, SCreateVnodeMsg *pVnodeCfg) {
|
||||
vDebug("vgId:%d, current dbCfgVersion:%d vgCfgVersion:%d, input dbCfgVersion:%d vgCfgVersion:%d", pVnode->vgId,
|
||||
pVnode->dbCfgVersion, pVnode->vgCfgVersion, pVnodeCfg->cfg.dbCfgVersion, pVnodeCfg->cfg.vgCfgVersion);
|
||||
|
||||
if (pVnode->dbCfgVersion == pVnodeCfg->cfg.dbCfgVersion && pVnode->vgCfgVersion == pVnodeCfg->cfg.vgCfgVersion) {
|
||||
vDebug("vgId:%d, cfg not change", pVnode->vgId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = vnodeAlterImp(pVnode, pVnodeCfg);
|
||||
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to alter vnode, code:0x%x", pVnode->vgId, code);
|
||||
} else {
|
||||
vDebug("vgId:%d, vnode is altered", pVnode->vgId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void vnodeFindWalRootDir(int32_t vgId, char *walRootDir) {
|
||||
#if 0
|
||||
char vnodeDir[TSDB_FILENAME_LEN] = "\0";
|
||||
snprintf(vnodeDir, TSDB_FILENAME_LEN, "/vnode/vnode%d/wal", vgId);
|
||||
|
||||
TDIR *tdir = tfsOpendir(vnodeDir);
|
||||
if (!tdir) return;
|
||||
|
||||
const TFILE *tfile = tfsReaddir(tdir);
|
||||
if (!tfile) {
|
||||
tfsClosedir(tdir);
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(walRootDir, "%s/vnode/vnode%d", TFS_DISK_PATH(tfile->level, tfile->id), vgId);
|
||||
|
||||
tfsClosedir(tdir);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t vnodeOpen(int32_t vgId) {
|
||||
#if 0
|
||||
char temp[TSDB_FILENAME_LEN * 3];
|
||||
char rootDir[TSDB_FILENAME_LEN * 2];
|
||||
char walRootDir[TSDB_FILENAME_LEN * 2] = {0};
|
||||
snprintf(rootDir, TSDB_FILENAME_LEN * 2, "%s/vnode%d", tsVnodeDir, vgId);
|
||||
|
||||
SVnode *pVnode = calloc(sizeof(SVnode), 1);
|
||||
if (pVnode == NULL) {
|
||||
vError("vgId:%d, failed to open vnode since no enough memory", vgId);
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
|
||||
pVnode->vgId = vgId;
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = 0;
|
||||
pVnode->tsdbCfg.tsdbId = pVnode->vgId;
|
||||
pVnode->rootDir = strdup(rootDir);
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
tsem_init(&pVnode->sem, 0, 0);
|
||||
pthread_mutex_init(&pVnode->statusMutex, NULL);
|
||||
vnodeSetInitStatus(pVnode);
|
||||
|
||||
tsdbIncCommitRef(pVnode->vgId);
|
||||
|
||||
int32_t code = vnodeReadCfg(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to read config file, set cfgVersion to 0", pVnode->vgId);
|
||||
vnodeCleanUp(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
code = vnodeReadVersion(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pVnode->version = 0;
|
||||
vError("vgId:%d, failed to read file version, generate it from data file", pVnode->vgId);
|
||||
// Allow vnode start even when read file version fails, set file version as wal version or zero
|
||||
// vnodeCleanUp(pVnode);
|
||||
// return code;
|
||||
}
|
||||
|
||||
pVnode->fversion = pVnode->version;
|
||||
|
||||
pVnode->wqueue = vnodeAllocWriteQueue(pVnode);
|
||||
pVnode->qqueue = vnodeAllocQueryQueue(pVnode);
|
||||
pVnode->fqueue = vnodeAllocFetchQueue(pVnode);
|
||||
if (pVnode->wqueue == NULL || pVnode->qqueue == NULL || pVnode->fqueue == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
STsdbAppH appH = {0};
|
||||
appH.appH = (void *)pVnode;
|
||||
appH.notifyStatus = vnodeProcessTsdbStatus;
|
||||
appH.cqH = pVnode->cq;
|
||||
appH.cqCreateFunc = cqCreate;
|
||||
appH.cqDropFunc = cqDrop;
|
||||
|
||||
terrno = 0;
|
||||
pVnode->tsdb = tsdbOpenRepo(&(pVnode->tsdbCfg), &appH);
|
||||
if (pVnode->tsdb == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
} else if (tsdbGetState(pVnode->tsdb) != TSDB_STATE_OK) {
|
||||
vError("vgId:%d, failed to open tsdb(state: %d), replica:%d reason:%s", pVnode->vgId, tsdbGetState(pVnode->tsdb),
|
||||
pVnode->syncCfg.replica, tstrerror(terrno));
|
||||
if (pVnode->syncCfg.replica <= 1) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return TSDB_CODE_VND_INVALID_TSDB_STATE;
|
||||
} else {
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// walRootDir for wal & syncInfo.path (not empty dir of /vnode/vnode{pVnode->vgId}/wal)
|
||||
vnodeFindWalRootDir(pVnode->vgId, walRootDir);
|
||||
if (walRootDir[0] == 0) {
|
||||
int level = -1, id = -1;
|
||||
|
||||
tfsAllocDisk(TFS_PRIMARY_LEVEL, &level, &id);
|
||||
if (level < 0 || id < 0) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
sprintf(walRootDir, "%s/vnode/vnode%d", TFS_DISK_PATH(level, id), vgId);
|
||||
}
|
||||
|
||||
sprintf(temp, "%s/wal", walRootDir);
|
||||
pVnode->walCfg.vgId = pVnode->vgId;
|
||||
pVnode->wal = walOpen(temp, &pVnode->walCfg);
|
||||
if (pVnode->wal == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
walRestore(pVnode->wal, pVnode, (FWalWrite)vnodeProcessWalMsg);
|
||||
if (pVnode->version == 0) {
|
||||
pVnode->fversion = 0;
|
||||
pVnode->version = walGetVersion(pVnode->wal);
|
||||
}
|
||||
|
||||
code = tsdbSyncCommit(pVnode->tsdb);
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to commit after restore from wal since %s", pVnode->vgId, tstrerror(code));
|
||||
vnodeCleanUp(pVnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
walRemoveAllOldFiles(pVnode->wal);
|
||||
walRenew(pVnode->wal);
|
||||
|
||||
pVnode->qMgmt = qOpenQueryMgmt(pVnode->vgId);
|
||||
if (pVnode->qMgmt == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pVnode->events = NULL;
|
||||
|
||||
vDebug("vgId:%d, vnode is opened in %s - %s, pVnode:%p", pVnode->vgId, rootDir, walRootDir, pVnode);
|
||||
|
||||
taosHashPut(tsVmain.hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnode *));
|
||||
|
||||
vnodeSetReadyStatus(pVnode);
|
||||
pVnode->role = TAOS_SYNC_ROLE_MASTER;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t vnodeClose(int32_t vgId) {
|
||||
SVnode *pVnode = vnodeAcquireNotClose(vgId);
|
||||
if (pVnode == NULL) return 0;
|
||||
if (pVnode->dropped) {
|
||||
vnodeRelease(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pVnode->preClose = 1;
|
||||
|
||||
vDebug("vgId:%d, vnode will be closed, pVnode:%p", pVnode->vgId, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
vnodeCleanUp(pVnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeDestroy(SVnode *pVnode) {
|
||||
#if 0
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pVnode->vgId;
|
||||
|
||||
if (pVnode->qMgmt) {
|
||||
qCleanupQueryMgmt(pVnode->qMgmt);
|
||||
pVnode->qMgmt = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->wal) {
|
||||
walStop(pVnode->wal);
|
||||
}
|
||||
|
||||
if (pVnode->tsdb) {
|
||||
// the deleted vnode does not need to commit, so as to speed up the deletion
|
||||
int toCommit = 1;
|
||||
if (pVnode->dropped) toCommit = 0;
|
||||
|
||||
code = tsdbCloseRepo(pVnode->tsdb, toCommit);
|
||||
pVnode->tsdb = NULL;
|
||||
}
|
||||
|
||||
// stop continuous query
|
||||
if (pVnode->cq) {
|
||||
void *cq = pVnode->cq;
|
||||
pVnode->cq = NULL;
|
||||
cqClose(cq);
|
||||
}
|
||||
|
||||
if (pVnode->wal) {
|
||||
if (code != 0) {
|
||||
vError("vgId:%d, failed to commit while close tsdb repo, keep wal", pVnode->vgId);
|
||||
} else {
|
||||
walRemoveAllOldFiles(pVnode->wal);
|
||||
}
|
||||
walClose(pVnode->wal);
|
||||
pVnode->wal = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->wqueue) {
|
||||
vnodeFreeWriteQueue(pVnode->wqueue);
|
||||
pVnode->wqueue = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->qqueue) {
|
||||
vnodeFreeQueryQueue(pVnode->qqueue);
|
||||
pVnode->qqueue = NULL;
|
||||
}
|
||||
|
||||
if (pVnode->fqueue) {
|
||||
vnodeFreeFetchQueue(pVnode->fqueue);
|
||||
pVnode->fqueue = NULL;
|
||||
}
|
||||
|
||||
tfree(pVnode->rootDir);
|
||||
|
||||
if (pVnode->dropped) {
|
||||
char rootDir[TSDB_FILENAME_LEN] = {0};
|
||||
char stagingDir[TSDB_FILENAME_LEN] = {0};
|
||||
sprintf(rootDir, "%s/vnode%d", "vnode", vgId);
|
||||
sprintf(stagingDir, "%s/.staging/vnode%d", "vnode_bak", vgId);
|
||||
|
||||
tfsRename(rootDir, stagingDir);
|
||||
|
||||
vnodeProcessBackupTask(pVnode);
|
||||
|
||||
// dnodeSendStatusMsgToMnode();
|
||||
}
|
||||
|
||||
tsem_destroy(&pVnode->sem);
|
||||
pthread_mutex_destroy(&pVnode->statusMutex);
|
||||
free(pVnode);
|
||||
tsdbDecCommitRef(vgId);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vnodeCleanUp(SVnode *pVnode) {
|
||||
#if 0
|
||||
vDebug("vgId:%d, vnode will cleanup, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
vnodeSetClosingStatus(pVnode);
|
||||
|
||||
taosHashRemove(tsVmain.hash, &pVnode->vgId, sizeof(int32_t));
|
||||
|
||||
// stop replication module
|
||||
if (pVnode->sync > 0) {
|
||||
int64_t sync = pVnode->sync;
|
||||
pVnode->sync = -1;
|
||||
syncStop(sync);
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, vnode is cleaned, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
vnodeRelease(pVnode);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
|
||||
SVnode *pVnode = arg;
|
||||
|
||||
if (eno != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to commit since %s, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, tstrerror(eno),
|
||||
pVnode->fversion, pVnode->version);
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status == TSDB_STATUS_COMMIT_START) {
|
||||
pVnode->isCommiting = 1;
|
||||
pVnode->cversion = pVnode->version;
|
||||
vInfo("vgId:%d, start commit, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
if (!vnodeInInitStatus(pVnode)) {
|
||||
return walRenew(pVnode->wal);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status == TSDB_STATUS_COMMIT_OVER) {
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 0;
|
||||
pVnode->fversion = pVnode->cversion;
|
||||
vInfo("vgId:%d, commit over, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
if (!vnodeInInitStatus(pVnode)) {
|
||||
walRemoveOneOldFile(pVnode->wal);
|
||||
}
|
||||
return vnodeSaveVersion(pVnode);
|
||||
}
|
||||
|
||||
// timer thread callback
|
||||
if (status == TSDB_STATUS_COMMIT_NOBLOCK) {
|
||||
qSolveCommitNoBlock(pVnode->tsdb, pVnode->qMgmt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *vnodeOpenVnode(void *param) {
|
||||
SOpenVnodeThread *pThread = param;
|
||||
|
||||
vDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("vnodeOpenVnode");
|
||||
|
||||
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
||||
int32_t vgId = pThread->vnodeList[v];
|
||||
|
||||
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId,
|
||||
tsVmain.openVnodes, tsVmain.totalVnodes);
|
||||
// (*vnodeInst()->fp.ReportStartup)("open-vnodes", stepDesc);
|
||||
|
||||
if (vnodeOpen(vgId) < 0) {
|
||||
vError("vgId:%d, failed to open vnode by thread:%d", vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
} else {
|
||||
vDebug("vgId:%d, is opened by thread:%d", vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&tsVmain.openVnodes, 1);
|
||||
}
|
||||
|
||||
vDebug("thread:%d, total vnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||
pThread->failed);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t vnodeGetVnodeListFromDisk(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||
#if 0
|
||||
DIR *dir = opendir(tsVnodeDir);
|
||||
if (dir == NULL) return TSDB_CODE_DND_NO_WRITE_ACCESS;
|
||||
|
||||
*numOfVnodes = 0;
|
||||
struct dirent *de = NULL;
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||
if (de->d_type & DT_DIR) {
|
||||
if (strncmp("vnode", de->d_name, 5) != 0) continue;
|
||||
int32_t vnode = atoi(de->d_name + 5);
|
||||
if (vnode == 0) continue;
|
||||
|
||||
(*numOfVnodes)++;
|
||||
|
||||
if (*numOfVnodes >= TSDB_MAX_VNODES) {
|
||||
vError("vgId:%d, too many vnode directory in disk, exist:%d max:%d", vnode, *numOfVnodes, TSDB_MAX_VNODES);
|
||||
closedir(dir);
|
||||
return TSDB_CODE_DND_TOO_MANY_VNODES;
|
||||
} else {
|
||||
vnodeList[*numOfVnodes - 1] = vnode;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeOpenVnodes() {
|
||||
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
int32_t status = vnodeGetVnodeListFromDisk(vnodeList, &numOfVnodes);
|
||||
|
||||
if (status != TSDB_CODE_SUCCESS) {
|
||||
vInfo("failed to get vnode list from disk since code:%d", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
tsVmain.totalVnodes = numOfVnodes;
|
||||
|
||||
int32_t threadNum = tsNumOfCores;
|
||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||
|
||||
SOpenVnodeThread *threads = calloc(threadNum, sizeof(SOpenVnodeThread));
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
threads[t].threadIndex = t;
|
||||
threads[t].vnodeList = calloc(vnodesPerThread, sizeof(int32_t));
|
||||
}
|
||||
|
||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||
int32_t t = v % threadNum;
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
pThread->vnodeList[pThread->vnodeNum++] = vnodeList[v];
|
||||
}
|
||||
|
||||
vInfo("start %d threads to open %d vnodes", threadNum, numOfVnodes);
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum == 0) continue;
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (pthread_create(&pThread->thread, &thAttr, vnodeOpenVnode, pThread) != 0) {
|
||||
vError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno));
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
}
|
||||
|
||||
int32_t openVnodes = 0;
|
||||
int32_t failedVnodes = 0;
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SOpenVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
|
||||
pthread_join(pThread->thread, NULL);
|
||||
}
|
||||
openVnodes += pThread->opened;
|
||||
failedVnodes += pThread->failed;
|
||||
free(pThread->vnodeList);
|
||||
}
|
||||
|
||||
free(threads);
|
||||
vInfo("there are total vnodes:%d, opened:%d", numOfVnodes, openVnodes);
|
||||
|
||||
if (failedVnodes != 0) {
|
||||
vError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||
void *pIter = taosHashIterate(tsVmain.hash, NULL);
|
||||
while (pIter) {
|
||||
SVnode **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
(*numOfVnodes)++;
|
||||
if (*numOfVnodes >= TSDB_MAX_VNODES) {
|
||||
vError("vgId:%d, too many open vnodes, exist:%d max:%d", (*pVnode)->vgId, *numOfVnodes, TSDB_MAX_VNODES);
|
||||
continue;
|
||||
} else {
|
||||
vnodeList[*numOfVnodes - 1] = (*pVnode)->vgId;
|
||||
}
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(tsVmain.hash, pIter);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void vnodeCleanupVnodes() {
|
||||
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
|
||||
int32_t code = vnodeGetVnodeList(vnodeList, &numOfVnodes);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vInfo("failed to get dnode list since code %d", code);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
vnodeClose(vnodeList[i]);
|
||||
}
|
||||
|
||||
vInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||
}
|
||||
|
||||
static void vnodeInitMsgFp() {
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessWriteMsg;
|
||||
//mq related
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessWriteMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessWriteMsg;
|
||||
//mq related end
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessReadMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessReadMsg;
|
||||
//mq related
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessReadMsg;
|
||||
tsVmain.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessReadMsg;
|
||||
//mq related end
|
||||
}
|
||||
|
||||
void vnodeProcessMsg(SRpcMsg *pMsg) {
|
||||
if (tsVmain.msgFp[pMsg->msgType]) {
|
||||
(*tsVmain.msgFp[pMsg->msgType])(pMsg);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t vnodeInitMain() {
|
||||
vnodeInitMsgFp();
|
||||
|
||||
tsVmain.timer = taosTmrInit(100, 200, 60000, "VND-TIMER");
|
||||
if (tsVmain.timer == NULL) {
|
||||
vError("failed to init vnode timer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsVmain.hash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (tsVmain.hash == NULL) {
|
||||
taosTmrCleanUp(tsVmain.timer);
|
||||
vError("failed to init vnode mgmt");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vInfo("vnode main is initialized");
|
||||
return vnodeOpenVnodes();
|
||||
}
|
||||
|
||||
void vnodeCleanupMain() {
|
||||
taosTmrCleanUp(tsVmain.timer);
|
||||
tsVmain.timer = NULL;
|
||||
|
||||
vnodeCleanupVnodes();
|
||||
|
||||
taosHashCleanup(tsVmain.hash);
|
||||
tsVmain.hash = NULL;
|
||||
}
|
||||
|
||||
static void vnodeBuildVloadMsg(SVnode *pVnode, SStatusMsg *pStatus) {
|
||||
#if 0
|
||||
int64_t totalStorage = 0;
|
||||
int64_t compStorage = 0;
|
||||
int64_t pointsWritten = 0;
|
||||
|
||||
if (vnodeInClosingStatus(pVnode)) return;
|
||||
if (pStatus->openVnodes >= TSDB_MAX_VNODES) return;
|
||||
|
||||
if (pVnode->tsdb) {
|
||||
tsdbReportStat(pVnode->tsdb, &pointsWritten, &totalStorage, &compStorage);
|
||||
}
|
||||
|
||||
SVnodeLoad *pLoad = &pStatus->load[pStatus->openVnodes++];
|
||||
pLoad->vgId = htonl(pVnode->vgId);
|
||||
pLoad->dbCfgVersion = htonl(pVnode->dbCfgVersion);
|
||||
pLoad->vgCfgVersion = htonl(pVnode->vgCfgVersion);
|
||||
pLoad->totalStorage = htobe64(totalStorage);
|
||||
pLoad->compStorage = htobe64(compStorage);
|
||||
pLoad->pointsWritten = htobe64(pointsWritten);
|
||||
pLoad->vnodeVersion = htobe64(pVnode->version);
|
||||
pLoad->status = pVnode->status;
|
||||
pLoad->role = pVnode->role;
|
||||
pLoad->replica = pVnode->syncCfg.replica;
|
||||
pLoad->compact = (pVnode->tsdb != NULL) ? tsdbGetCompactState(pVnode->tsdb) : 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void vnodeGetStatus(struct SStatusMsg *pStatus) {
|
||||
void *pIter = taosHashIterate(tsVmain.hash, NULL);
|
||||
while (pIter) {
|
||||
SVnode **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
vnodeBuildVloadMsg(*pVnode, pStatus);
|
||||
}
|
||||
pIter = taosHashIterate(tsVmain.hash, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void vnodeSetAccess(struct SVgroupAccess *pAccess, int32_t numOfVnodes) {
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
pAccess[i].vgId = htonl(pAccess[i].vgId);
|
||||
SVnode *pVnode = vnodeAcquireNotClose(pAccess[i].vgId);
|
||||
if (pVnode != NULL) {
|
||||
pVnode->accessState = pAccess[i].accessState;
|
||||
if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) {
|
||||
vDebug("vgId:%d, access state is set to %d", pAccess[i].vgId, pVnode->accessState);
|
||||
}
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vnodeBackup(int32_t vgId) {
|
||||
char newDir[TSDB_FILENAME_LEN] = {0};
|
||||
char stagingDir[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
sprintf(newDir, "%s/vnode%d", "vnode_bak", vgId);
|
||||
sprintf(stagingDir, "%s/.staging/vnode%d", "vnode_bak", vgId);
|
||||
|
||||
#if 0
|
||||
if (tsEnableVnodeBak) {
|
||||
tfsRmdir(newDir);
|
||||
tfsRename(stagingDir, newDir);
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode backup not enabled", vgId);
|
||||
|
||||
tfsRmdir(stagingDir);
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "vnodeMain.h"
|
||||
|
||||
#include "vnodeMgmt.h"
|
||||
#include "vnodeMgmtMsg.h"
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "vnodeMain.h"
|
||||
|
||||
#include "vnodeMgmtMsg.h"
|
||||
|
||||
static SCreateVnodeMsg* vnodeParseVnodeMsg(SRpcMsg *rpcMsg) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
// #include "query.h"
|
||||
#include "vnodeMain.h"
|
||||
|
||||
#include "vnodeRead.h"
|
||||
#include "vnodeReadMsg.h"
|
||||
#include "vnodeStatus.h"
|
||||
|
@ -81,9 +81,9 @@ static int32_t vnodeWriteToRQueue(SVnode *pVnode, void *pCont, int32_t contLen,
|
|||
atomic_add_fetch_32(&pVnode->queuedRMsg, 1);
|
||||
|
||||
if (pRead->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRead->msgType == TSDB_MSG_TYPE_FETCH) {
|
||||
return taosWriteQitem(pVnode->fqueue, qtype, pRead);
|
||||
return taosWriteQitem(pVnode->pFetchQ, qtype, pRead);
|
||||
} else {
|
||||
return taosWriteQitem(pVnode->qqueue, qtype, pRead);
|
||||
return taosWriteQitem(pVnode->pQueryQ, qtype, pRead);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t remain = atomic_add_fetch_32(&pVnode->numOfExistQHandle, 1);
|
||||
int32_t remain = atomic_add_fetch_32(&pVnode->numOfQHandle, 1);
|
||||
vTrace("vgId:%d, new qhandle created, total qhandle:%d", pVnode->vgId, remain);
|
||||
} else {
|
||||
assert(pCont != NULL);
|
||||
|
@ -203,7 +203,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
// If the building of result is not required, simply free it. Otherwise, mandatorily free the qhandle
|
||||
if (freehandle || (!buildRes)) {
|
||||
if (freehandle) {
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfExistQHandle, 1);
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1);
|
||||
vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *qhandle, remain);
|
||||
}
|
||||
|
||||
|
@ -218,10 +218,34 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
}
|
||||
|
||||
//mq related
|
||||
int32_t vnodeProcessConsumeMsg(SVnode *pVnode, SReadMsg *pRead){
|
||||
int32_t vnodeProcessConsumeMsg(SVnode *pVnode, SReadMsg *pRead) {
|
||||
//parse message and optionally move offset
|
||||
void* pMsg = pRead->pCont;
|
||||
tmqConsumeReq *pConsumeMsg = (tmqConsumeReq*) pMsg;
|
||||
tmqMsgHead msgHead = pConsumeMsg->head;
|
||||
//extract head
|
||||
STQ *pTq = pVnode->pTQ;
|
||||
tqGroupHandle *pHandle = tqFindGHandleBycId(pTq, msgHead.clientId);
|
||||
//return msg if offset not moved
|
||||
if(pConsumeMsg->commitOffset == pHandle->consumeOffset) {
|
||||
//return msg
|
||||
return 0;
|
||||
}
|
||||
//or move offset
|
||||
tqMoveOffsetToNext(pHandle);
|
||||
//fetch or register context
|
||||
tqFetchMsg(pHandle, pRead);
|
||||
//judge mode, tail read or catch up read
|
||||
/*int64_t lastVer = walLastVer(pVnode->wal);*/
|
||||
//launch new query
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeProcessTqQueryMsg(SVnode *pVnode, SReadMsg *pRead) {
|
||||
//get operator tree from tq data structure
|
||||
//execute operator tree
|
||||
//put data into ringbuffer
|
||||
//unref memory
|
||||
return 0;
|
||||
}
|
||||
//mq related end
|
||||
|
@ -259,7 +283,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
|
||||
// kill current query and free corresponding resources.
|
||||
if (pRetrieve->free == 1) {
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfExistQHandle, 1);
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1);
|
||||
vWarn("vgId:%d, QInfo:%" PRIx64 "-%p, retrieve msg received to kill query and free qhandle, remain qhandle:%d",
|
||||
pVnode->vgId, pRetrieve->qId, *handle, remain);
|
||||
|
||||
|
@ -273,7 +297,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
|
||||
// register the qhandle to connect to quit query immediate if connection is broken
|
||||
if (vnodeNotifyCurrentQhandle(pRead->rpcHandle, pRetrieve->qId, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfExistQHandle, 1);
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1);
|
||||
vError("vgId:%d, QInfo:%" PRIu64 "-%p, retrieve discarded since link is broken, conn:%p, remain qhandle:%d",
|
||||
pVnode->vgId, pRetrieve->qhandle, *handle, pRead->rpcHandle, remain);
|
||||
|
||||
|
@ -310,7 +334,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SReadMsg *pRead) {
|
|||
// If qhandle is not added into vread queue, the query should be completed already or paused with error.
|
||||
// Here free qhandle immediately
|
||||
if (freeHandle) {
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfExistQHandle, 1);
|
||||
int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1);
|
||||
vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *handle, remain);
|
||||
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
|
||||
}
|
||||
|
|
|
@ -58,10 +58,12 @@ int32_t vnodeReadVersion(SVnode *pVnode) {
|
|||
vError("vgId:%d, failed to read %s, version not found", pVnode->vgId, file);
|
||||
goto PARSE_VER_ERROR;
|
||||
}
|
||||
#if 0
|
||||
pVnode->version = (uint64_t)ver->valueint;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
vInfo("vgId:%d, read %s successfully, fver:%" PRIu64, pVnode->vgId, file, pVnode->version);
|
||||
#endif
|
||||
|
||||
PARSE_VER_ERROR:
|
||||
if (content != NULL) free(content);
|
||||
|
@ -85,16 +87,17 @@ int32_t vnodeSaveVersion(SVnode *pVnode) {
|
|||
int32_t maxLen = 100;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
|
||||
#if 0
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"version\": %" PRIu64 "\n", pVnode->fversion);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
#endif
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
vInfo("vgId:%d, successed to write %s, fver:%" PRIu64, pVnode->vgId, file, pVnode->fversion);
|
||||
// vInfo("vgId:%d, successed to write %s, fver:%" PRIu64, pVnode->vgId, file, pVnode->fversion);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "vnodeMain.h"
|
||||
|
||||
#include "vnodeWorker.h"
|
||||
|
||||
enum { CLEANUP_TASK = 0, DESTROY_TASK = 1, BACKUP_TASK = 2 };
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue