提交 0ba6a7cd 编写于 作者: H Hongze Cheng

Merge branch 'develop' into feature/mergeimport

...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
<p>Like a table, you can create, show, delete and describe STables. Most query operations on tables can be applied to STable too, including the aggregation and selector functions. For queries on a STable, if no tags filter, the operations are applied to all the tables created via this STable. If there is a tag filter, the operations are applied only to a subset of the tables which satisfy the tag filter conditions. It will be very convenient to use tags to put devices into different groups for aggregation.</p> <p>Like a table, you can create, show, delete and describe STables. Most query operations on tables can be applied to STable too, including the aggregation and selector functions. For queries on a STable, if no tags filter, the operations are applied to all the tables created via this STable. If there is a tag filter, the operations are applied only to a subset of the tables which satisfy the tag filter conditions. It will be very convenient to use tags to put devices into different groups for aggregation.</p>
<a class='anchor' id='Create-a-STable'></a><h2>Create a STable</h2> <a class='anchor' id='Create-a-STable'></a><h2>Create a STable</h2>
<p>Similiar to creating a standard table, syntax is: </p> <p>Similiar to creating a standard table, syntax is: </p>
<pre><code class="mysql language-mysql">CREATE TABLE &lt;stable_name&gt; (&lt;field_name&gt; TIMESTAMP, field_name1 field_type,…) TAGS(tag_name tag_type, …)</code></pre> <pre><code class="mysql language-mysql">CREATE TABLE &lt;stable_name&gt; (&lt;field_name&gt; TIMESTAMP, field_name1 field_type, ...) TAGS(tag_name tag_type, ...)</code></pre>
<p>New keyword "tags" is introduced, where tag_name is the tag name, and tag_type is the associated data type. </p> <p>New keyword "tags" is introduced, where tag_name is the tag name, and tag_type is the associated data type. </p>
<p>Note</p> <p>Note: </p>
<ol> <ol>
<li>The bytes of all tags together shall be less than 512 </li> <li>The bytes of all tags together shall be less than 512 </li>
<li>Tag's data type can not be time stamp or nchar</li> <li>Tag's data type can not be time stamp or nchar</li>
...@@ -30,12 +30,12 @@ tags (location binary(20), type int)</code></pre> ...@@ -30,12 +30,12 @@ tags (location binary(20), type int)</code></pre>
create table t4 using thermometer tags ('shanghai', 20); create table t4 using thermometer tags ('shanghai', 20);
create table t5 using thermometer tags ('new york', 10);</code></pre> create table t5 using thermometer tags ('new york', 10);</code></pre>
<a class='anchor' id='Aggregate-Tables-via-STable'></a><h2>Aggregate Tables via STable</h2> <a class='anchor' id='Aggregate-Tables-via-STable'></a><h2>Aggregate Tables via STable</h2>
<p>You can group a set of tables together by specifying the tags filter condition, then apply the aggregation operations. The result set can be grouped and ordered based on tag value. Syntax is</p> <p>You can group a set of tables together by specifying the tags filter condition, then apply the aggregation operations. The result set can be grouped and ordered based on tag value. Syntax is:</p>
<pre><code class="mysql language-mysql">SELECT function&lt;field_name&gt;, <pre><code class="mysql language-mysql">SELECT function&lt;field_name&gt;, ...
FROM &lt;stable_name&gt; FROM &lt;stable_name&gt;
WHERE &lt;tag_name&gt; &lt;[=|&lt;=|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] …) WHERE &lt;tag_name&gt; &lt;[=|&lt;=|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] ...
INTERVAL (&lt;time range&gt;) INTERVAL (&lt;time range&gt;)
GROUP BY &lt;tag_name&gt;, &lt;tag_name&gt; GROUP BY &lt;tag_name&gt;, &lt;tag_name&gt; ...
ORDER BY &lt;tag_name&gt; &lt;asc|desc&gt; ORDER BY &lt;tag_name&gt; &lt;asc|desc&gt;
SLIMIT &lt;group_limit&gt; SLIMIT &lt;group_limit&gt;
SOFFSET &lt;group_offset&gt; SOFFSET &lt;group_offset&gt;
...@@ -75,9 +75,9 @@ INTERVAL(10M)</code></pre> ...@@ -75,9 +75,9 @@ INTERVAL(10M)</code></pre>
<pre><code class="mysql language-mysql">DROP TABLE &lt;stable_name&gt;</code></pre> <pre><code class="mysql language-mysql">DROP TABLE &lt;stable_name&gt;</code></pre>
<p>To delete a STable, all the tables created via this STable shall be deleted first, otherwise, it will fail.</p> <p>To delete a STable, all the tables created via this STable shall be deleted first, otherwise, it will fail.</p>
<a class='anchor' id='List-the-Associated-Tables-of-a-STable'></a><h3>List the Associated Tables of a STable</h3> <a class='anchor' id='List-the-Associated-Tables-of-a-STable'></a><h3>List the Associated Tables of a STable</h3>
<pre><code class="mysql language-mysql">SELECT TBNAME,[TAG_NAME,…] FROM &lt;stable_name&gt; WHERE &lt;tag_name&gt; &lt;[=|=&lt;|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] …)</code></pre> <pre><code class="mysql language-mysql">SELECT TBNAME,[TAG_NAME, ...] FROM &lt;stable_name&gt; WHERE &lt;tag_name&gt; &lt;[=|=&lt;|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] ...)</code></pre>
<p>It will list all the tables which satisfy the tag filter conditions. The tables are all created from this specific STable. TBNAME is a new keyword introduced, it is the table name associated with the STable. </p> <p>It will list all the tables which satisfy the tag filter conditions. The tables are all created from this specific STable. TBNAME is a new keyword introduced, it is the table name associated with the STable. </p>
<pre><code class="mysql language-mysql">SELECT COUNT(TBNAME) FROM &lt;stable_name&gt; WHERE &lt;tag_name&gt; &lt;[=|=&lt;|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] )</code></pre> <pre><code class="mysql language-mysql">SELECT COUNT(TBNAME) FROM &lt;stable_name&gt; WHERE &lt;tag_name&gt; &lt;[=|=&lt;|&gt;=|&lt;&gt;] values..&gt; ([AND|OR] ...)</code></pre>
<p>The above SQL statement will list the number of tables in a STable, which satisfy the filter condition.</p> <p>The above SQL statement will list the number of tables in a STable, which satisfy the filter condition.</p>
<a class='anchor' id='Management-of-Tags'></a><h2>Management of Tags</h2> <a class='anchor' id='Management-of-Tags'></a><h2>Management of Tags</h2>
<p>You can add, delete and change the tags for a STable, and you can change the tag value of a table. The SQL commands are listed below. </p> <p>You can add, delete and change the tags for a STable, and you can change the tag value of a table. The SQL commands are listed below. </p>
......
...@@ -9,13 +9,13 @@ fi ...@@ -9,13 +9,13 @@ fi
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
${csudo} systemctl stop taosd || : ${csudo} systemctl stop taosd || :
elif $(which insserv &> /dev/null); then elif $(which service &> /dev/null); then
${csudo} service taosd stop || :
elif $(which update-rc.d &> /dev/null); then
${csudo} service taosd stop || : ${csudo} service taosd stop || :
else else
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
fi fi
echo "Stop taosd service success!" echo "Stop taosd service success!"
sleep 1 sleep 1
......
...@@ -35,6 +35,8 @@ else ...@@ -35,6 +35,8 @@ else
${csudo} rm -f ${data_link_dir} || : ${csudo} rm -f ${data_link_dir} || :
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
fi fi
...@@ -24,8 +24,7 @@ fi ...@@ -24,8 +24,7 @@ fi
mkdir -p ${pkg_dir} mkdir -p ${pkg_dir}
cd ${pkg_dir} cd ${pkg_dir}
versioninfo=$(${script_dir}/../tools/get_version.sh ${script_dir}/../../src/util/src/version.c) libfile="libtaos.so.${tdengine_ver}"
libfile="libtaos.so.${versioninfo}"
# create install dir # create install dir
install_home_path="/usr/local/taos" install_home_path="/usr/local/taos"
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
# Generate the deb package for ubunt, or rpm package for centos, or tar.gz package for other linux os # Generate the deb package for ubunt, or rpm package for centos, or tar.gz package for other linux os
set -e set -e
#set -x # set -x
armver=$1
curr_dir=$(pwd) curr_dir=$(pwd)
script_dir="$(dirname $(readlink -f $0))" script_dir="$(dirname $(readlink -f $0))"
...@@ -110,21 +112,28 @@ echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo ...@@ -110,21 +112,28 @@ echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo
echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo} echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo}
# 2. cmake executable file # 2. cmake executable file
#default use debug mode
compile_mode="debug"
if [[ $1 == "Release" ]] || [[ $1 == "release" ]]; then
compile_mode="Release"
fi
compile_dir="${top_dir}/${compile_mode}" compile_dir="${top_dir}/debug"
if [ -d ${compile_dir} ]; then if [ -d ${compile_dir} ]; then
${csudo} rm -rf ${compile_dir} ${csudo} rm -rf ${compile_dir}
fi fi
${csudo} mkdir -p ${compile_dir} ${csudo} mkdir -p ${compile_dir}
cd ${compile_dir} cd ${compile_dir}
${csudo} cmake -DCMAKE_BUILD_TYPE=${compile_mode} ${top_dir}
${csudo} make # arm only support lite ver
if [ -z "$armver" ]; then
cmake ${top_dir}/../
elif [ "$armver" == "arm64" ]; then
cmake ${top_dir}/../ -DVERSION=lite -DARMVER=arm64
elif [ "$armver" == "arm32" ]; then
cmake ${top_dir}/../ -DVERSION=lite -DARMVER=arm32
else
echo "input parameter error!!!"
return
fi
make
cd ${curr_dir} cd ${curr_dir}
...@@ -153,7 +162,8 @@ ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${version} ...@@ -153,7 +162,8 @@ ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${version}
echo "do tar.gz package for all systems" echo "do tar.gz package for all systems"
cd ${script_dir}/tools cd ${script_dir}/tools
${csudo} ./makepkg.sh ${compile_dir} ${version} "${build_time}" ${csudo} ./makepkg.sh ${compile_dir} ${version} "${build_time}" ${armver}
${csudo} ./makeclient.sh ${compile_dir} ${version} "${build_time}" ${armver}
# 4. Clean up temporary compile directories # 4. Clean up temporary compile directories
#${csudo} rm -rf ${compile_dir} #${csudo} rm -rf ${compile_dir}
......
...@@ -39,8 +39,7 @@ echo topdir: %{_topdir} ...@@ -39,8 +39,7 @@ echo topdir: %{_topdir}
echo version: %{_version} echo version: %{_version}
echo buildroot: %{buildroot} echo buildroot: %{buildroot}
versioninfo=$(%{_compiledir}/../packaging/tools/get_version.sh ../../src/util/src/version.c) libfile="libtaos.so.%{_version}"
libfile="libtaos.so.${versioninfo}"
# create install path, and cp file # create install path, and cp file
mkdir -p %{buildroot}%{homepath}/bin mkdir -p %{buildroot}%{homepath}/bin
...@@ -80,18 +79,17 @@ fi ...@@ -80,18 +79,17 @@ fi
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
${csudo} systemctl stop taosd || : ${csudo} systemctl stop taosd || :
elif $(which insserv &> /dev/null); then elif $(which service &> /dev/null); then
${csudo} service taosd stop || :
elif $(which update-rc.d &> /dev/null); then
${csudo} service taosd stop || : ${csudo} service taosd stop || :
else else
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
fi fi
echo "Stop taosd service success!" echo "Stop taosd service success!"
sleep 1 sleep 1
fi fi
# if taos.cfg already softlink, remove it # if taos.cfg already softlink, remove it
if [ -f %{cfg_install_dir}/taos.cfg ]; then if [ -f %{cfg_install_dir}/taos.cfg ]; then
${csudo} rm -f %{homepath}/cfg/taos.cfg || : ${csudo} rm -f %{homepath}/cfg/taos.cfg || :
...@@ -146,7 +144,9 @@ if [ $1 -eq 0 ];then ...@@ -146,7 +144,9 @@ if [ $1 -eq 0 ];then
${csudo} rm -f ${data_link_dir} || : ${csudo} rm -f ${data_link_dir} || :
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
fi fi
fi fi
......
#!/bin/bash #!/bin/bash
# #
# This file is used to install TAOS time-series database on linux systems. The operating system # This file is used to install database on linux systems. The operating system
# is required to use systemd to manage services at boot # is required to use systemd to manage services at boot
set -e set -e
...@@ -41,19 +41,58 @@ if command -v sudo > /dev/null; then ...@@ -41,19 +41,58 @@ if command -v sudo > /dev/null; then
csudo="sudo" csudo="sudo"
fi fi
initd_mod=0
service_mod=2 service_mod=2
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
service_mod=0 service_mod=0
elif $(which update-rc.d &> /dev/null); then elif $(which service &> /dev/null); then
service_mod=1 service_mod=1
service_config_dir="/etc/init.d" service_config_dir="/etc/init.d"
if $(which chkconfig &> /dev/null); then
initd_mod=1
elif $(which insserv &> /dev/null); then
initd_mod=2
elif $(which update-rc.d &> /dev/null); then
initd_mod=3
else
service_mod=2
fi
else else
service_mod=2 service_mod=2
fi fi
# get the operating system type for using the corresponding init file
# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2)
#echo "osinfo: ${osinfo}"
os_type=0
if echo $osinfo | grep -qwi "ubuntu" ; then
echo "this is ubuntu system"
os_type=1
elif echo $osinfo | grep -qwi "debian" ; then
echo "this is debian system"
os_type=1
elif echo $osinfo | grep -qwi "Kylin" ; then
echo "this is Kylin system"
os_type=1
elif echo $osinfo | grep -qwi "centos" ; then
echo "this is centos system"
os_type=2
elif echo $osinfo | grep -qwi "fedora" ; then
echo "this is fedora system"
os_type=2
else
echo "this is other linux system"
os_type=0
fi
function kill_taosd() { function kill_taosd() {
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 pid || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
} }
function install_main_path() { function install_main_path() {
...@@ -117,6 +156,7 @@ function install_config() { ...@@ -117,6 +156,7 @@ function install_config() {
${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg
} }
function install_log() { function install_log() {
${csudo} rm -rf ${log_dir} || : ${csudo} rm -rf ${log_dir} || :
${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir}
...@@ -139,14 +179,26 @@ function install_examples() { ...@@ -139,14 +179,26 @@ function install_examples() {
} }
function clean_service_on_sysvinit() { function clean_service_on_sysvinit() {
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
${csudo} service taosd stop || : ${csudo} service taosd stop || :
fi fi
${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
${csudo} rm -f ${service_config_dir}/taosd || : if ((${initd_mod}==1)); then
${csudo} chkconfig --del taosd || :
elif ((${initd_mod}==2)); then
${csudo} insserv -r taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d -f taosd remove || : ${csudo} update-rc.d -f taosd remove || :
fi
${csudo} rm -f ${service_config_dir}/taosd || :
if $(which init &> /dev/null); then
${csudo} init q || : ${csudo} init q || :
fi
} }
function install_service_on_sysvinit() { function install_service_on_sysvinit() {
...@@ -155,14 +207,27 @@ function install_service_on_sysvinit() { ...@@ -155,14 +207,27 @@ function install_service_on_sysvinit() {
sleep 1 sleep 1
# Install taosd service # Install taosd service
${csudo} cp -f ${script_dir}/init.d/taosd ${install_main_dir}/init.d
${csudo} cp ${script_dir}/init.d/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd if ((${os_type}==1)); then
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" ${csudo} cp -f ${script_dir}/init.d/taosd.deb ${install_main_dir}/init.d/taosd
${csudo} cp ${script_dir}/init.d/taosd.deb ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd
${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" elif ((${os_type}==2)); then
# TODO: for centos, change here ${csudo} cp -f ${script_dir}/init.d/taosd.rpm ${install_main_dir}/init.d/taosd
${csudo} update-rc.d taosd defaults ${csudo} cp ${script_dir}/init.d/taosd.rpm ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd
# chkconfig mysqld on fi
#restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab"
if ((${initd_mod}==1)); then
${csudo} chkconfig --add taosd || :
${csudo} chkconfig --level 2345 taosd on || :
elif ((${initd_mod}==2)); then
${csudo} insserv taosd || :
${csudo} insserv -d taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d taosd defaults || :
fi
} }
function clean_service_on_systemd() { function clean_service_on_systemd() {
...@@ -212,7 +277,7 @@ function install_service() { ...@@ -212,7 +277,7 @@ function install_service() {
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
install_service_on_sysvinit install_service_on_sysvinit
else else
# must manual start taosd # must manual stop taosd
kill_taosd kill_taosd
fi fi
} }
...@@ -274,7 +339,7 @@ function update_TDengine() { ...@@ -274,7 +339,7 @@ function update_TDengine() {
return 1 return 1
fi fi
echo -e "${GREEN}Start to update TDEngine...${NC}" echo -e "${GREEN}Start to update TDengine...${NC}"
# Stop the service if running # Stop the service if running
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
if ((${service_mod}==0)); then if ((${service_mod}==0)); then
...@@ -306,8 +371,7 @@ function update_TDengine() { ...@@ -306,8 +371,7 @@ function update_TDengine() {
if ((${service_mod}==0)); then if ((${service_mod}==0)); then
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}"
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} update-rc.d taosd default ${RED} for the first time${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}"
echo -e " : ${csudo} service taosd start ${RED} after${NC}"
else else
echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}"
fi fi
...@@ -316,7 +380,7 @@ function update_TDengine() { ...@@ -316,7 +380,7 @@ function update_TDengine() {
echo echo
echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" echo -e "\033[44;32;1mTDengine is updated successfully!${NC}"
else else
install_bin $1 install_bin
install_config install_config
echo echo
...@@ -334,7 +398,7 @@ function install_TDengine() { ...@@ -334,7 +398,7 @@ function install_TDengine() {
fi fi
tar -zxf taos.tar.gz tar -zxf taos.tar.gz
echo -e "${GREEN}Start to install TDEngine...${NC}" echo -e "${GREEN}Start to install TDengine...${NC}"
install_main_path install_main_path
...@@ -362,10 +426,9 @@ function install_TDengine() { ...@@ -362,10 +426,9 @@ function install_TDengine() {
if ((${service_mod}==0)); then if ((${service_mod}==0)); then
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}"
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} update-rc.d taosd default ${RED} for the first time${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}"
echo -e " : ${csudo} service taosd start ${RED} after${NC}"
else else
echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}"
fi fi
echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}"
......
#!/bin/bash #!/bin/bash
#
# This file is used to install TDengine client on linux systems. The operating system
# is required to use systemd to manage services at boot
set -e
#set -x
# -----------------------Variables definition---------------------
script_dir=$(dirname $(readlink -m "$0")) script_dir=$(dirname $(readlink -m "$0"))
${script_dir}/install.sh client # Dynamic directory
data_dir="/var/lib/taos"
log_dir="/var/log/taos"
log_link_dir="/usr/local/taos/log"
cfg_install_dir="/etc/taos"
bin_link_dir="/usr/bin"
lib_link_dir="/usr/lib"
inc_link_dir="/usr/include"
#install main path
install_main_dir="/usr/local/taos"
# old bin dir
bin_dir="/usr/local/taos/bin"
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
update_flag=0
function kill_client() {
pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}')
if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
}
function install_main_path() {
#create install main dir and all sub dir
${csudo} rm -rf ${install_main_dir} || :
${csudo} mkdir -p ${install_main_dir}
${csudo} mkdir -p ${install_main_dir}/cfg
${csudo} mkdir -p ${install_main_dir}/bin
${csudo} mkdir -p ${install_main_dir}/connector
${csudo} mkdir -p ${install_main_dir}/driver
${csudo} mkdir -p ${install_main_dir}/examples
${csudo} mkdir -p ${install_main_dir}/include
}
function install_bin() {
# Remove links
${csudo} rm -f ${bin_link_dir}/taos || :
${csudo} rm -f ${bin_link_dir}/taosdump || :
${csudo} rm -f ${bin_link_dir}/rmtaos || :
${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/*
#Make link
[ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || :
[ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
[ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || :
}
function clean_lib() {
sudo rm -f /usr/lib/libtaos.so || :
sudo rm -rf ${lib_dir} || :
}
function install_lib() {
# Remove links
${csudo} rm -f ${lib_link_dir}/libtaos.* || :
${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/*
${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1
${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
}
function install_header() {
${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || :
${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/*
${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
}
function install_config() {
#${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || :
if [ ! -f ${cfg_install_dir}/taos.cfg ]; then
${csudo} mkdir -p ${cfg_install_dir}
[ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir}
${csudo} chmod 644 ${cfg_install_dir}/*
fi
${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org
${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg
}
function install_log() {
${csudo} rm -rf ${log_dir} || :
${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir}
${csudo} ln -s ${log_dir} ${install_main_dir}/log
}
function install_connector() {
${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector
}
function install_examples() {
if [ -d ${script_dir}/examples ]; then
${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples
fi
}
function update_TDengine() {
# Start to update
if [ ! -e taos.tar.gz ]; then
echo "File taos.tar.gz does not exist"
exit 1
fi
tar -zxf taos.tar.gz
echo -e "${GREEN}Start to update TDengine client...${NC}"
# Stop the client shell if running
if pidof taos &> /dev/null; then
kill_client
sleep 1
fi
install_main_path
install_log
install_header
install_lib
install_connector
install_examples
install_bin
install_config
echo
echo -e "\033[44;32;1mTDengine client is updated successfully!${NC}"
rm -rf $(tar -tf taos.tar.gz)
}
function install_TDengine() {
# Start to install
if [ ! -e taos.tar.gz ]; then
echo "File taos.tar.gz does not exist"
exit 1
fi
tar -zxf taos.tar.gz
echo -e "${GREEN}Start to install TDengine client...${NC}"
install_main_path
install_log
install_header
install_lib
install_connector
install_examples
install_bin
install_config
echo
echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}"
rm -rf $(tar -tf taos.tar.gz)
}
## ==============================Main program starts from here============================
# Install or updata client and client
# if server is already install, don't install client
if [ -e ${bin_dir}/taosd ]; then
echo -e "\033[44;32;1mThere are already installed TDengine server, so don't need install client!${NC}"
exit 0
fi
if [ -x ${bin_dir}/taos ]; then
update_flag=1
update_TDengine
else
install_TDengine
fi
#!/bin/bash
#
# Generate tar.gz package for linux client
set -e
set -x
curr_dir=$(pwd)
compile_dir=$1
version=$2
build_time=$3
armver=$4
script_dir="$(dirname $(readlink -f $0))"
top_dir="$(readlink -m ${script_dir}/../..)"
# create compressed install file.
build_dir="${compile_dir}/build"
code_dir="${top_dir}/src"
release_dir="${top_dir}/release"
community_dir="${script_dir}/../../../community/src"
package_name='linux'
install_dir="${release_dir}/TDengine-client-enterprise-${version}-${package_name}-$(echo ${build_time}| tr ': ' -)"
# Directories and files.
bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${script_dir}/remove_client.sh"
lib_files="${build_dir}/lib/libtaos.so.${version}"
header_files="${community_dir}/inc/taos.h ${community_dir}/inc/taoserror.h"
cfg_dir="${top_dir}/packaging/cfg"
install_files="${script_dir}/install_client.sh"
# make directories.
mkdir -p ${install_dir}
mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc
mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg
mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/*
cd ${install_dir}
tar -zcv -f taos.tar.gz * --remove-files || :
cd ${curr_dir}
cp ${install_files} ${install_dir} && chmod a+x ${install_dir}/install*
# Copy example code
mkdir -p ${install_dir}/examples
cp -r ${top_dir}/tests/examples/c ${install_dir}/examples
cp -r ${top_dir}/tests/examples/JDBC ${install_dir}/examples
cp -r ${top_dir}/tests/examples/matlab ${install_dir}/examples
cp -r ${top_dir}/tests/examples/python ${install_dir}/examples
cp -r ${top_dir}/tests/examples/R ${install_dir}/examples
cp -r ${top_dir}/tests/examples/go ${install_dir}/examples
# Copy driver
mkdir -p ${install_dir}/driver
cp ${lib_files} ${install_dir}/driver
# Copy connector
connector_dir="${community_dir}/connector"
mkdir -p ${install_dir}/connector
cp ${build_dir}/lib/*.jar ${install_dir}/connector
cp -r ${connector_dir}/grafana ${install_dir}/connector/
cp -r ${connector_dir}/python ${install_dir}/connector/
cp -r ${connector_dir}/go ${install_dir}/connector
# Copy release note
# cp ${script_dir}/release_note ${install_dir}
# exit 1
cd ${release_dir}
if [ -z "$armver" ]; then
tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files
elif [ "$armver" == "arm64" ]; then
tar -zcv -f "$(basename ${install_dir})-arm64.tar.gz" $(basename ${install_dir}) --remove-files
elif [ "$armver" == "arm32" ]; then
tar -zcv -f "$(basename ${install_dir})-arm32.tar.gz" $(basename ${install_dir}) --remove-files
fi
cd ${curr_dir}
...@@ -6,6 +6,7 @@ curr_dir=$(pwd) ...@@ -6,6 +6,7 @@ curr_dir=$(pwd)
compile_dir=$1 compile_dir=$1
version=$2 version=$2
build_time=$3 build_time=$3
armver=$4
script_dir="$(dirname $(readlink -f $0))" script_dir="$(dirname $(readlink -f $0))"
top_dir="$(readlink -m ${script_dir}/../..)" top_dir="$(readlink -m ${script_dir}/../..)"
...@@ -20,11 +21,10 @@ install_dir="${release_dir}/taos-${version}-${package_name}-$(echo ${build_time} ...@@ -20,11 +21,10 @@ install_dir="${release_dir}/taos-${version}-${package_name}-$(echo ${build_time}
# Directories and files. # Directories and files.
bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdump ${script_dir}/remove.sh" bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdump ${script_dir}/remove.sh"
versioninfo=$(${script_dir}/get_version.sh ${code_dir}/util/src/version.c) lib_files="${build_dir}/lib/libtaos.so.${version}"
lib_files="${build_dir}/lib/libtaos.so.${versioninfo}"
header_files="${code_dir}/inc/taos.h ${code_dir}/inc/taoserror.h" header_files="${code_dir}/inc/taos.h ${code_dir}/inc/taoserror.h"
cfg_files="${top_dir}/packaging/cfg/*.cfg" cfg_dir="${top_dir}/packaging/cfg"
install_files="${script_dir}/install.sh ${script_dir}/install_client.sh" install_files="${script_dir}/install.sh"
# Init file # Init file
#init_dir=${script_dir}/deb #init_dir=${script_dir}/deb
...@@ -33,14 +33,16 @@ install_files="${script_dir}/install.sh ${script_dir}/install_client.sh" ...@@ -33,14 +33,16 @@ install_files="${script_dir}/install.sh ${script_dir}/install_client.sh"
#fi #fi
#init_files=${init_dir}/taosd #init_files=${init_dir}/taosd
# temp use rpm's taosd. TODO: later modify according to os type # temp use rpm's taosd. TODO: later modify according to os type
init_files=${script_dir}/../rpm/taosd init_file_deb=${script_dir}/../deb/taosd
init_file_rpm=${script_dir}/../rpm/taosd
# make directories. # make directories.
mkdir -p ${install_dir} mkdir -p ${install_dir}
mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc
mkdir -p ${install_dir}/cfg && cp ${cfg_files} ${install_dir}/cfg mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg
mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/*
mkdir -p ${install_dir}/init.d && cp ${init_files} ${install_dir}/init.d mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/taosd.deb
mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/taosd.rpm
cd ${install_dir} cd ${install_dir}
tar -zcv -f taos.tar.gz * --remove-files || : tar -zcv -f taos.tar.gz * --remove-files || :
...@@ -50,12 +52,13 @@ cp ${install_files} ${install_dir} && chmod a+x ${install_dir}/install* ...@@ -50,12 +52,13 @@ cp ${install_files} ${install_dir} && chmod a+x ${install_dir}/install*
# Copy example code # Copy example code
mkdir -p ${install_dir}/examples mkdir -p ${install_dir}/examples
cp -r ${top_dir}/tests/examples/c ${install_dir}/examples examples_dir="${top_dir}/tests/examples"
cp -r ${top_dir}/tests/examples/JDBC ${install_dir}/examples cp -r ${examples_dir}/c ${install_dir}/examples
cp -r ${top_dir}/tests/examples/matlab ${install_dir}/examples cp -r ${examples_dir}/JDBC ${install_dir}/examples
cp -r ${top_dir}/tests/examples/python ${install_dir}/examples cp -r ${examples_dir}/matlab ${install_dir}/examples
cp -r ${top_dir}/tests/examples/R ${install_dir}/examples cp -r ${examples_dir}/python ${install_dir}/examples
cp -r ${top_dir}/tests/examples/go ${install_dir}/examples cp -r ${examples_dir}/R ${install_dir}/examples
cp -r ${examples_dir}/go ${install_dir}/examples
# Copy driver # Copy driver
mkdir -p ${install_dir}/driver mkdir -p ${install_dir}/driver
...@@ -64,18 +67,23 @@ cp ${lib_files} ${install_dir}/driver ...@@ -64,18 +67,23 @@ cp ${lib_files} ${install_dir}/driver
# Copy connector # Copy connector
connector_dir="${code_dir}/connector" connector_dir="${code_dir}/connector"
mkdir -p ${install_dir}/connector mkdir -p ${install_dir}/connector
cp ${build_dir}/lib/*.jar ${install_dir}/connector
cp -r ${connector_dir}/grafana ${install_dir}/connector/ cp -r ${connector_dir}/grafana ${install_dir}/connector/
cp -r ${connector_dir}/python ${install_dir}/connector/ cp -r ${connector_dir}/python ${install_dir}/connector/
cp -r ${connector_dir}/go ${install_dir}/connector cp -r ${connector_dir}/go ${install_dir}/connector
cp ${build_dir}/lib/*.jar ${install_dir}/connector
# Copy release note # Copy release note
cp ${script_dir}/release_note ${install_dir} # cp ${script_dir}/release_note ${install_dir}
# exit 1 # exit 1
cd ${release_dir} cd ${release_dir}
tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files if [ -z "$armver" ]; then
tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files
elif [ "$armver" == "arm64" ]; then
tar -zcv -f "$(basename ${install_dir})-arm64.tar.gz" $(basename ${install_dir}) --remove-files
elif [ "$armver" == "arm32" ]; then
tar -zcv -f "$(basename ${install_dir})-arm32.tar.gz" $(basename ${install_dir}) --remove-files
fi
cd ${curr_dir} cd ${curr_dir}
...@@ -42,14 +42,18 @@ initd_mod=0 ...@@ -42,14 +42,18 @@ initd_mod=0
service_mod=2 service_mod=2
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
service_mod=0 service_mod=0
elif $(which insserv &> /dev/null); then elif $(which service &> /dev/null); then
service_mod=1 service_mod=1
initd_mod=1
service_config_dir="/etc/init.d" service_config_dir="/etc/init.d"
elif $(which update-rc.d &> /dev/null); then if $(which chkconfig &> /dev/null); then
service_mod=1 initd_mod=1
elif $(which insserv &> /dev/null); then
initd_mod=2 initd_mod=2
service_config_dir="/etc/init.d" elif $(which update-rc.d &> /dev/null); then
initd_mod=3
else
service_mod=2
fi
else else
service_mod=2 service_mod=2
fi fi
...@@ -57,7 +61,9 @@ fi ...@@ -57,7 +61,9 @@ fi
function kill_taosd() { function kill_taosd() {
# ${csudo} pkill -f taosd || : # ${csudo} pkill -f taosd || :
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
} }
function install_include() { function install_include() {
...@@ -103,20 +109,26 @@ function install_config() { ...@@ -103,20 +109,26 @@ function install_config() {
} }
function clean_service_on_sysvinit() { function clean_service_on_sysvinit() {
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
${csudo} service taosd stop || : ${csudo} service taosd stop || :
fi fi
${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
${csudo} rm -f ${service_config_dir}/taosd || :
if ((${initd_mod}==1)); then if ((${initd_mod}==1)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : ${csudo} chkconfig --del taosd || :
elif ((${initd_mod}==2)); then elif ((${initd_mod}==2)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : ${csudo} insserv -r taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d -f taosd remove || :
fi fi
# ${csudo} update-rc.d -f taosd remove || :
${csudo} rm -f ${service_config_dir}/taosd || :
if $(which init &> /dev/null); then
${csudo} init q || : ${csudo} init q || :
fi
} }
function install_service_on_sysvinit() { function install_service_on_sysvinit() {
...@@ -127,18 +139,24 @@ function install_service_on_sysvinit() { ...@@ -127,18 +139,24 @@ function install_service_on_sysvinit() {
# Install taosd service # Install taosd service
${csudo} cp %{init_d_dir}/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd ${csudo} cp %{init_d_dir}/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab"
${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" if ((${initd_mod}==1)); then
# TODO: for centos, change here ${csudo} chkconfig --add taosd || :
${csudo} update-rc.d taosd defaults ${csudo} chkconfig --level 2345 taosd on || :
# chkconfig mysqld on elif ((${initd_mod}==2)); then
${csudo} insserv taosd || :
${csudo} insserv -d taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d taosd defaults || :
fi
} }
function clean_service_on_systemd() { function clean_service_on_systemd() {
taosd_service_config="${service_config_dir}/taosd.service" taosd_service_config="${service_config_dir}/taosd.service"
# taosd service already is stoped before install # taosd service already is stoped before install in preinst script
#if systemctl is-active --quiet taosd; then #if systemctl is-active --quiet taosd; then
# echo "TDengine is running, stopping it..." # echo "TDengine is running, stopping it..."
# ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null # ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null
......
...@@ -26,22 +26,27 @@ initd_mod=0 ...@@ -26,22 +26,27 @@ initd_mod=0
service_mod=2 service_mod=2
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
service_mod=0 service_mod=0
elif $(which insserv &> /dev/null); then elif $(which service &> /dev/null); then
service_mod=1 service_mod=1
initd_mod=1
service_config_dir="/etc/init.d" service_config_dir="/etc/init.d"
elif $(which update-rc.d &> /dev/null); then if $(which chkconfig &> /dev/null); then
service_mod=1 initd_mod=1
elif $(which insserv &> /dev/null); then
initd_mod=2 initd_mod=2
service_config_dir="/etc/init.d" elif $(which update-rc.d &> /dev/null); then
initd_mod=3
else
service_mod=2
fi
else else
service_mod=2 service_mod=2
fi fi
function kill_taosd() { function kill_taosd() {
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
} }
function clean_service_on_systemd() { function clean_service_on_systemd() {
...@@ -57,20 +62,27 @@ function clean_service_on_systemd() { ...@@ -57,20 +62,27 @@ function clean_service_on_systemd() {
} }
function clean_service_on_sysvinit() { function clean_service_on_sysvinit() {
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
echo "TDengine taosd is running, stopping it..."
${csudo} service taosd stop || : ${csudo} service taosd stop || :
fi fi
${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
${csudo} rm -f ${service_config_dir}/taosd || :
if ((${initd_mod}==1)); then if ((${initd_mod}==1)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : ${csudo} chkconfig --del taosd || :
elif ((${initd_mod}==2)); then elif ((${initd_mod}==2)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : ${csudo} insserv -r taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d -f taosd remove || :
fi fi
# ${csudo} update-rc.d -f taosd remove || :
${csudo} rm -f ${service_config_dir}/taosd || :
if $(which init &> /dev/null); then
${csudo} init q || : ${csudo} init q || :
fi
} }
function clean_service() { function clean_service() {
...@@ -79,7 +91,7 @@ function clean_service() { ...@@ -79,7 +91,7 @@ function clean_service() {
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
clean_service_on_sysvinit clean_service_on_sysvinit
else else
# must manual start taosd # must manual stop taosd
kill_taosd kill_taosd
fi fi
} }
......
#!/bin/bash #!/bin/bash
# #
# Script to stop the service and uninstall tdengine, but retain the config, data and log files. # Script to stop the service and uninstall TDengine, but retain the config, data and log files.
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[1;32m' GREEN='\033[1;32m'
...@@ -27,21 +27,27 @@ initd_mod=0 ...@@ -27,21 +27,27 @@ initd_mod=0
service_mod=2 service_mod=2
if pidof systemd &> /dev/null; then if pidof systemd &> /dev/null; then
service_mod=0 service_mod=0
elif $(which insserv &> /dev/null); then elif $(which service &> /dev/null); then
service_mod=1 service_mod=1
initd_mod=1
service_config_dir="/etc/init.d" service_config_dir="/etc/init.d"
elif $(which update-rc.d &> /dev/null); then if $(which chkconfig &> /dev/null); then
service_mod=1 initd_mod=1
elif $(which insserv &> /dev/null); then
initd_mod=2 initd_mod=2
service_config_dir="/etc/init.d" elif $(which update-rc.d &> /dev/null); then
initd_mod=3
else
service_mod=2
fi
else else
service_mod=2 service_mod=2
fi fi
function kill_taosd() { function kill_taosd() {
pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}')
${csudo} kill -9 ${pid} || : if [ -n "$pid" ]; then
${csudo} kill -9 $pid || :
fi
} }
function clean_bin() { function clean_bin() {
...@@ -87,20 +93,27 @@ function clean_service_on_systemd() { ...@@ -87,20 +93,27 @@ function clean_service_on_systemd() {
} }
function clean_service_on_sysvinit() { function clean_service_on_sysvinit() {
restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start"
#${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
if pidof taosd &> /dev/null; then if pidof taosd &> /dev/null; then
echo "TDengine taosd is running, stopping it..."
${csudo} service taosd stop || : ${csudo} service taosd stop || :
fi fi
${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || :
${csudo} rm -f ${service_config_dir}/taosd || :
if ((${initd_mod}==1)); then if ((${initd_mod}==1)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : ${csudo} chkconfig --del taosd || :
elif ((${initd_mod}==2)); then elif ((${initd_mod}==2)); then
${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : ${csudo} insserv -r taosd || :
elif ((${initd_mod}==3)); then
${csudo} update-rc.d -f taosd remove || :
fi fi
# ${csudo} update-rc.d -f taosd remove || :
${csudo} rm -f ${service_config_dir}/taosd || :
if $(which init &> /dev/null); then
${csudo} init q || : ${csudo} init q || :
fi
} }
function clean_service() { function clean_service() {
...@@ -109,7 +122,7 @@ function clean_service() { ...@@ -109,7 +122,7 @@ function clean_service() {
elif ((${service_mod}==1)); then elif ((${service_mod}==1)); then
clean_service_on_sysvinit clean_service_on_sysvinit
else else
# must manual start taosd # must manual stop taosd
kill_taosd kill_taosd
fi fi
} }
...@@ -140,4 +153,4 @@ elif echo $osinfo | grep -qwi "centos" ; then ...@@ -140,4 +153,4 @@ elif echo $osinfo | grep -qwi "centos" ; then
${csudo} rpm -e --noscripts tdengine || : ${csudo} rpm -e --noscripts tdengine || :
fi fi
echo -e "${GREEN}TDEngine is removed successfully!${NC}" echo -e "${GREEN}TDengine is removed successfully!${NC}"
#!/bin/bash
#
# Script to stop the client and uninstall database, but retain the config and log files.
set -e
# set -x
RED='\033[0;31m'
GREEN='\033[1;32m'
NC='\033[0m'
#install main path
install_main_dir="/usr/local/taos"
log_link_dir="/usr/local/taos/log"
cfg_link_dir="/usr/local/taos/cfg"
bin_link_dir="/usr/bin"
lib_link_dir="/usr/lib"
inc_link_dir="/usr/include"
csudo=""
if command -v sudo > /dev/null; then
csudo="sudo"
fi
function kill_client() {
#pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}')
if [ -n "$(pidof taos)" ]; then
${csudo} kill -9 $pid || :
fi
}
function clean_bin() {
# Remove link
${csudo} rm -f ${bin_link_dir}/taos || :
${csudo} rm -f ${bin_link_dir}/taosump || :
${csudo} rm -f ${bin_link_dir}/rmtaos || :
}
function clean_lib() {
# Remove link
${csudo} rm -f ${lib_link_dir}/libtaos.* || :
}
function clean_header() {
# Remove link
${csudo} rm -f ${inc_link_dir}/taos.h || :
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
}
function clean_config() {
# Remove link
${csudo} rm -f ${cfg_link_dir}/* || :
}
function clean_log() {
# Remove link
${csudo} rm -rf ${log_link_dir} || :
}
# Stop client.
kill_client
# Remove binary file and links
clean_bin
# Remove header file.
clean_header
# Remove lib file
clean_lib
# Remove link log directory
clean_log
# Remove link configuration file
clean_config
${csudo} rm -rf ${install_main_dir}
echo -e "${GREEN}TDengine client is removed successfully!${NC}"
...@@ -23,23 +23,10 @@ extern "C" { ...@@ -23,23 +23,10 @@ extern "C" {
#include "taos.h" #include "taos.h"
#include "tsqldef.h" #include "tsqldef.h"
#include "ttypes.h" #include "ttypes.h"
#include "taosmsg.h"
#define TK_SPACE 200
#define TK_COMMENT 201
#define TK_ILLEGAL 202
#define TK_HEX 203 // hex number 0x123
#define TK_OCT 204 // oct number
#define TK_BIN 205 // bin format data 0b111
#define TK_FILE 206
#define TSQL_SO_ASC 1
#define TSQL_SO_DESC 0
#define MAX_TOKEN_LEN 30 #define MAX_TOKEN_LEN 30
#define TSQL_TBNAME "TBNAME"
#define TSQL_TBNAME_L "tbname"
// token type // token type
enum { enum {
TSQL_NODE_TYPE_EXPR = 0x1, TSQL_NODE_TYPE_EXPR = 0x1,
...@@ -277,8 +264,7 @@ typedef struct tSQLExpr { ...@@ -277,8 +264,7 @@ typedef struct tSQLExpr {
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr) uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
// the full sql string of function(col, param), which is actually the raw // the full sql string of function(col, param), which is actually the raw
// field name, // field name, since the function name is kept in nSQLOptr already
// since the function name is kept in nSQLOptr already
SSQLToken operand; SSQLToken operand;
struct tSQLExprList *pParam; // function parameters struct tSQLExprList *pParam; // function parameters
...@@ -345,8 +331,6 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken ...@@ -345,8 +331,6 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken
void tSQLExprListDestroy(tSQLExprList *pList); void tSQLExprListDestroy(tSQLExprList *pList);
int32_t tSQLSyntaxNodeToString(tSQLExpr *pNode, char *dst);
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit); SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
...@@ -378,6 +362,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken); ...@@ -378,6 +362,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken);
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists);
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo); void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo);
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo);
// prefix show db.tables; // prefix show db.tables;
void setDBName(SSQLToken *pCpxName, SSQLToken *pDB); void setDBName(SSQLToken *pCpxName, SSQLToken *pDB);
......
...@@ -127,7 +127,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size); ...@@ -127,7 +127,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size);
void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema); void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema);
void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField); void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField);
void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, char* name, int16_t bytes); void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes);
void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible); void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible);
void tscFieldInfoCalOffset(SSqlCmd* pCmd); void tscFieldInfoCalOffset(SSqlCmd* pCmd);
...@@ -143,7 +143,9 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo); ...@@ -143,7 +143,9 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo);
void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex); void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex);
SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type, SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type,
int16_t size, /*int16_t colId,*/ int16_t interSize); int16_t size, int16_t interSize);
SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId);
SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type, SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type,
int16_t size); int16_t size);
......
...@@ -35,7 +35,7 @@ extern "C" { ...@@ -35,7 +35,7 @@ extern "C" {
#include "tlog.h" #include "tlog.h"
#include "tscCache.h" #include "tscCache.h"
#include "tsdb.h" #include "tsdb.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "tsqlfunction.h" #include "tsqlfunction.h"
#include "tutil.h" #include "tutil.h"
...@@ -92,7 +92,12 @@ enum _sql_cmd { ...@@ -92,7 +92,12 @@ enum _sql_cmd {
*/ */
TSDB_SQL_RETRIEVE_EMPTY_RESULT, TSDB_SQL_RETRIEVE_EMPTY_RESULT,
TSDB_SQL_RESET_CACHE, TSDB_SQL_RESET_CACHE, // 40
TSDB_SQL_SERV_STATUS,
TSDB_SQL_CURRENT_DB,
TSDB_SQL_SERV_VERSION,
TSDB_SQL_CLI_VERSION,
TSDB_SQL_CURRENT_USER,
TSDB_SQL_CFG_LOCAL, TSDB_SQL_CFG_LOCAL,
TSDB_SQL_MAX TSDB_SQL_MAX
...@@ -346,7 +351,7 @@ typedef struct _tsc_obj { ...@@ -346,7 +351,7 @@ typedef struct _tsc_obj {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_KEY_LEN];
char acctId[TSDB_DB_NAME_LEN]; char acctId[TSDB_DB_NAME_LEN];
char db[TSDB_DB_NAME_LEN]; char db[TSDB_METER_ID_LEN];
char sversion[TSDB_VERSION_LEN]; char sversion[TSDB_VERSION_LEN];
char writeAuth : 1; char writeAuth : 1;
char superAuth : 1; char superAuth : 1;
......
...@@ -21,8 +21,12 @@ ...@@ -21,8 +21,12 @@
#include "tschemautil.h" #include "tschemautil.h"
#include "tsdb.h" #include "tsdb.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tsqldef.h"
#include "tsqlfunction.h" #include "tsqlfunction.h"
#include "tstoken.h"
#include "ttypes.h"
#include "tutil.h" #include "tutil.h"
#include "tscSQLParser.h"
/* /*
* *
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include "tscUtil.h" #include "tscUtil.h"
#include "tsclient.h" #include "tsclient.h"
#include "tsocket.h" #include "tsocket.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "tutil.h" #include "tutil.h"
#include "tnote.h"
void tscProcessFetchRow(SSchedMsg *pMsg); void tscProcessFetchRow(SSchedMsg *pMsg);
void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows); void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows);
...@@ -55,6 +56,8 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *, ...@@ -55,6 +56,8 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *,
return; return;
} }
taosNotePrintTsc(sqlstr);
SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj)); SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
tscError("failed to malloc sqlObj"); tscError("failed to malloc sqlObj");
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "tschemautil.h" #include "tschemautil.h"
#include "tsocket.h" #include "tsocket.h"
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength);
static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) { static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) {
char buf[512] = {0}; char buf[512] = {0};
...@@ -39,7 +41,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type ...@@ -39,7 +41,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
double dv = 0; double dv = 0;
*(int64_t*)(&dv) = *(int64_t*)pData; *(int64_t *)(&dv) = *(int64_t *)pData;
len = sprintf(buf, "%f", dv); len = sprintf(buf, "%f", dv);
#else #else
len = sprintf(buf, "%lf", *(double *)pData); len = sprintf(buf, "%lf", *(double *)pData);
...@@ -47,12 +49,11 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type ...@@ -47,12 +49,11 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
if (strncasecmp("nan", buf, 3) == 0) { if (strncasecmp("nan", buf, 3) == 0) {
len = 4; len = 4;
} }
} } break;
break;
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
float fv = 0; float fv = 0;
*(int32_t*)(&fv) = *(int32_t*)pData; *(int32_t *)(&fv) = *(int32_t *)pData;
len = sprintf(buf, "%f", fv); len = sprintf(buf, "%f", fv);
#else #else
len = sprintf(buf, "%f", *(float *)pData); len = sprintf(buf, "%f", *(float *)pData);
...@@ -60,8 +61,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type ...@@ -60,8 +61,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
if (strncasecmp("nan", buf, 3) == 0) { if (strncasecmp("nan", buf, 3) == 0) {
len = 4; len = 4;
} }
} } break;
break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
len = sprintf(buf, "%lld", *(int64_t *)pData); len = sprintf(buf, "%lld", *(int64_t *)pData);
...@@ -203,23 +203,21 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { ...@@ -203,23 +203,21 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
float fv = 0; float fv = 0;
*(int32_t*)(&fv) = *(int32_t*)pTagValue; *(int32_t *)(&fv) = *(int32_t *)pTagValue;
sprintf(target, "%f", fv); sprintf(target, "%f", fv);
#else #else
sprintf(target, "%f", *(float *)pTagValue); sprintf(target, "%f", *(float *)pTagValue);
#endif #endif
} } break;
break;
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
double dv = 0; double dv = 0;
*(int64_t*)(&dv) = *(int64_t*)pTagValue; *(int64_t *)(&dv) = *(int64_t *)pTagValue;
sprintf(target, "%lf", dv); sprintf(target, "%lf", dv);
#else #else
sprintf(target, "%lf", *(double *)pTagValue); sprintf(target, "%lf", *(double *)pTagValue);
#endif #endif
} } break;
break;
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
sprintf(target, "%d", *(int8_t *)pTagValue); sprintf(target, "%d", *(int8_t *)pTagValue);
break; break;
...@@ -391,6 +389,68 @@ static int tscProcessQueryTags(SSqlObj *pSql) { ...@@ -391,6 +389,68 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
} }
} }
static void tscProcessCurrentUser(SSqlObj *pSql) {
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0);
tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN);
}
static void tscProcessCurrentDB(SSqlObj *pSql) {
char db[TSDB_DB_NAME_LEN + 1] = {0};
extractDBName(pSql->pTscObj->db, db);
// no use db is invoked before.
if (strlen(db) == 0) {
setNull(db, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
}
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0);
tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN);
}
static void tscProcessServerVer(SSqlObj *pSql) {
const char* v = pSql->pTscObj->sversion;
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0);
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, tListLen(pSql->pTscObj->sversion));
}
static void tscProcessClientVer(SSqlObj *pSql) {
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0);
tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version));
}
static void tscProcessServStatus(SSqlObj *pSql) {
STscObj* pObj = pSql->pTscObj;
if (pObj->pHb != NULL) {
if (pObj->pHb->res.code == TSDB_CODE_NETWORK_UNAVAIL) {
pSql->res.code = TSDB_CODE_NETWORK_UNAVAIL;
return;
}
} else {
if (pSql->res.code == TSDB_CODE_NETWORK_UNAVAIL) {
return;
}
}
SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0);
tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2);
}
void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength) {
SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res;
pCmd->numOfCols = 1;
pCmd->order.order = TSQL_SO_ASC;
tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength);
tscInitResObjForLocalQuery(pSql, 1, valueLength);
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0);
strncpy(pRes->data, val, pField->bytes);
}
int tscProcessLocalCmd(SSqlObj *pSql) { int tscProcessLocalCmd(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
...@@ -402,13 +462,23 @@ int tscProcessLocalCmd(SSqlObj *pSql) { ...@@ -402,13 +462,23 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
pSql->res.code = (uint8_t)tscProcessQueryTags(pSql); pSql->res.code = (uint8_t)tscProcessQueryTags(pSql);
} else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { } else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
/* /*
* pass the qhandle check, in order to call partial release function to * set the qhandle to be 1 in order to pass the qhandle check, and to call partial release function to
* free allocated resources and remove the SqlObj from linked list * free allocated resources and remove the SqlObj from sql query linked list
*/ */
pSql->res.qhandle = 0x1; // pass the qhandle check pSql->res.qhandle = 0x1;
pSql->res.numOfRows = 0; pSql->res.numOfRows = 0;
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) { } else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
taosClearDataCache(tscCacheHandle); taosClearDataCache(tscCacheHandle);
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
tscProcessServerVer(pSql);
} else if (pCmd->command == TSDB_SQL_CLI_VERSION) {
tscProcessClientVer(pSql);
} else if (pCmd->command == TSDB_SQL_CURRENT_USER) {
tscProcessCurrentUser(pSql);
} else if (pCmd->command == TSDB_SQL_CURRENT_DB) {
tscProcessCurrentDB(pSql);
} else if (pCmd->command == TSDB_SQL_SERV_STATUS) {
tscProcessServStatus(pSql);
} else { } else {
pSql->res.code = TSDB_CODE_INVALID_SQL; pSql->res.code = TSDB_CODE_INVALID_SQL;
tscError("%p not support command:%d", pSql, pCmd->command); tscError("%p not support command:%d", pSql, pCmd->command);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "taos.h" #include "taos.h"
#include "tsclient.h" #include "tsclient.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "ttimer.h" #include "ttimer.h"
#include "taosmsg.h" #include "taosmsg.h"
......
此差异已折叠。
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
*/ */
#include "os.h" #include "os.h"
#include "taosmsg.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "tsql.h" #include "tlog.h"
#include "tscSQLParser.h"
#include "tstoken.h" #include "tstoken.h"
#include "ttime.h" #include "ttime.h"
#include "tutil.h" #include "tutil.h"
...@@ -500,7 +502,7 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) { ...@@ -500,7 +502,7 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) {
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) { SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) {
assert(pSelection != NULL && pFrom != NULL && pInterval != NULL && pLimit != NULL && pGLimit != NULL); assert(pSelection != NULL);
SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL)); SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL));
pQuery->selectToken = *pSelectToken; pQuery->selectToken = *pSelectToken;
...@@ -512,13 +514,23 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, ...@@ -512,13 +514,23 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection,
pQuery->pSortOrder = pSortOrder; pQuery->pSortOrder = pSortOrder;
pQuery->pWhere = pWhere; pQuery->pWhere = pWhere;
if (pLimit != NULL) {
pQuery->limit = *pLimit; pQuery->limit = *pLimit;
}
if (pGLimit != NULL) {
pQuery->slimit = *pGLimit; pQuery->slimit = *pGLimit;
}
if (pInterval != NULL) {
pQuery->interval = *pInterval; pQuery->interval = *pInterval;
}
if (pSliding != NULL) {
pQuery->sliding = *pSliding; pQuery->sliding = *pSliding;
pQuery->fillType = pFill; }
pQuery->fillType = pFill;
return pQuery; return pQuery;
} }
...@@ -732,3 +744,22 @@ void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken ...@@ -732,3 +744,22 @@ void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken
tTokenListAppend(pInfo->pDCLInfo, pPwd); tTokenListAppend(pInfo->pDCLInfo, pPwd);
} }
} }
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
pDBInfo->numOfBlocksPerTable = -1;
pDBInfo->compressionLevel = -1;
pDBInfo->commitLog = -1;
pDBInfo->commitTime = -1;
pDBInfo->tablesPerVnode = -1;
pDBInfo->numOfAvgCacheBlocks = -1;
pDBInfo->cacheBlockSize = -1;
pDBInfo->rowPerFileBlock = -1;
pDBInfo->daysPerFile = -1;
pDBInfo->replica = -1;
pDBInfo->keep = NULL;
memset(&pDBInfo->precision, 0, sizeof(SSQLToken));
}
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h" #include "os.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "tsclient.h" #include "tsclient.h"
#include "tscompression.h" #include "tscompression.h"
#include "tsocket.h" #include "tsocket.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
...@@ -59,6 +59,22 @@ void tscPrintMgmtIp() { ...@@ -59,6 +59,22 @@ void tscPrintMgmtIp() {
} }
#endif #endif
/*
* For each management node, try twice at least in case of poor network situation.
* If the client start to connect to a non-management node from the client, and the first retry may fail due to
* the poor network quality. And then, the second retry get the response with redirection command.
* The retry will not be executed since only *two* retry is allowed in case of single management node in the cluster.
* Therefore, we need to multiply the retry times by factor of 2 to fix this problem.
*/
static int32_t tscGetMgmtConnMaxRetryTimes() {
int32_t factor = 2;
#ifdef CLUSTER
return tscMgmtIpList.numOfIps * factor;
#else
return 1*factor;
#endif
}
void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
STscObj *pObj = (STscObj *)param; STscObj *pObj = (STscObj *)param;
if (pObj == NULL) return; if (pObj == NULL) return;
...@@ -134,18 +150,17 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { ...@@ -134,18 +150,17 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
tscProcessSql(pObj->pHb); tscProcessSql(pObj->pHb);
} }
//TODO HANDLE error from mgmt
void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) {
STscObj *pTscObj = pSql->pTscObj; STscObj *pTscObj = pSql->pTscObj;
#ifdef CLUSTER #ifdef CLUSTER
if (pSql->retry < tscMgmtIpList.numOfIps) { if (pSql->retry < tscGetMgmtConnMaxRetryTimes()) {
*pCode = 0; *pCode = 0;
pSql->retry++; pSql->retry++;
pSql->index = pSql->index % tscMgmtIpList.numOfIps; pSql->index = pSql->index % tscMgmtIpList.numOfIps;
if (pSql->cmd.command > TSDB_SQL_READ && pSql->index == 0) pSql->index = 1; if (pSql->cmd.command > TSDB_SQL_READ && pSql->index == 0) pSql->index = 1;
void *thandle = taosGetConnFromCache(tscConnCache, tscMgmtIpList.ip[pSql->index], TSC_MGMT_VNODE, pTscObj->user); void *thandle = taosGetConnFromCache(tscConnCache, tscMgmtIpList.ip[pSql->index], TSC_MGMT_VNODE, pTscObj->user);
#else #else
if (pSql->retry < 1) { if (pSql->retry < tscGetMgmtConnMaxRetryTimes()) {
*pCode = 0; *pCode = 0;
pSql->retry++; pSql->retry++;
void *thandle = taosGetConnFromCache(tscConnCache, tsServerIp, TSC_MGMT_VNODE, pTscObj->user); void *thandle = taosGetConnFromCache(tscConnCache, tsServerIp, TSC_MGMT_VNODE, pTscObj->user);
...@@ -184,6 +199,15 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { ...@@ -184,6 +199,15 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) {
pSql->vnode = TSC_MGMT_VNODE; pSql->vnode = TSC_MGMT_VNODE;
#endif #endif
} }
// the pSql->res.code is the previous error(status) code.
if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) {
if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) {
*pCode = pSql->res.code;
}
tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode);
}
} }
void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) { void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
...@@ -435,8 +459,8 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { ...@@ -435,8 +459,8 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
} }
} else { } else {
uint16_t rspCode = pMsg->content[0]; uint16_t rspCode = pMsg->content[0];
#ifdef CLUSTER
#ifdef CLUSTER
if (rspCode == TSDB_CODE_REDIRECT) { if (rspCode == TSDB_CODE_REDIRECT) {
tscTrace("%p it shall be redirected!", pSql); tscTrace("%p it shall be redirected!", pSql);
...@@ -1795,7 +1819,7 @@ int tscBuildCreateDbMsg(SSqlObj *pSql) { ...@@ -1795,7 +1819,7 @@ int tscBuildCreateDbMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
pCreateDbMsg = (SCreateDbMsg *)pMsg; pCreateDbMsg = (SCreateDbMsg *)pMsg;
strcpy(pCreateDbMsg->db, pMeterMetaInfo->name); strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db));
pMsg += sizeof(SCreateDbMsg); pMsg += sizeof(SCreateDbMsg);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
...@@ -2017,7 +2041,7 @@ int tscBuildDropDbMsg(SSqlObj *pSql) { ...@@ -2017,7 +2041,7 @@ int tscBuildDropDbMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
pDropDbMsg = (SDropDbMsg *)pMsg; pDropDbMsg = (SDropDbMsg *)pMsg;
strcpy(pDropDbMsg->db, pMeterMetaInfo->name); strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db));
pDropDbMsg->ignoreNotExists = htons(pCmd->existsCheck ? 1 : 0); pDropDbMsg->ignoreNotExists = htons(pCmd->existsCheck ? 1 : 0);
...@@ -3795,7 +3819,14 @@ void tscInitMsgs() { ...@@ -3795,7 +3819,14 @@ void tscInitMsgs() {
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function.
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp;
......
此差异已折叠。
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "os.h" #include "os.h"
#include "tlog.h" #include "tlog.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "os.h" #include "os.h"
#include "tscSyntaxtreefunction.h" #include "tscSyntaxtreefunction.h"
#include "tsql.h" #include "tscSQLParser.h"
#include "ttypes.h" #include "ttypes.h"
#include "tutil.h" #include "tutil.h"
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册