Merge branch 'develop' into feature/mergeimport

This commit is contained in:
Hongze Cheng 2019-11-20 09:39:34 +08:00
commit f60eb20ee7
154 changed files with 2583 additions and 1667 deletions

View File

@ -38,21 +38,56 @@ IF (NOT DEFINED TD_CLUSTER)
# Set macro definitions according to os platform # Set macro definitions according to os platform
SET(TD_LINUX_64 FALSE) SET(TD_LINUX_64 FALSE)
SET(TD_LINUX_32 FALSE) SET(TD_LINUX_32 FALSE)
SET(TD_ARM FALSE)
SET(TD_ARM_64 FALSE) SET(TD_ARM_64 FALSE)
SET(TD_ARM_32 FALSE) SET(TD_ARM_32 FALSE)
SET(TD_MIPS_64 FALSE) SET(TD_MIPS_64 FALSE)
SET(TD_DARWIN_64 FALSE) SET(TD_DARWIN_64 FALSE)
SET(TD_WINDOWS_64 FALSE) SET(TD_WINDOWS_64 FALSE)
# if generate ARM version:
# cmake -DARMVER=arm32 .. or cmake -DARMVER=arm64
IF (${ARMVER} MATCHES "arm32")
SET(TD_ARM TRUE)
SET(TD_ARM_32 TRUE)
ADD_DEFINITIONS(-D_TD_ARM_)
ADD_DEFINITIONS(-D_TD_ARM_32_)
ELSEIF (${ARMVER} MATCHES "arm64")
SET(TD_ARM TRUE)
SET(TD_ARM_64 TRUE)
ADD_DEFINITIONS(-D_TD_ARM_)
ADD_DEFINITIONS(-D_TD_ARM_64_)
ENDIF ()
IF (TD_ARM)
ADD_DEFINITIONS(-D_TD_ARM_)
IF (TD_ARM_32)
ADD_DEFINITIONS(-D_TD_ARM_32_)
ELSEIF (TD_ARM_64)
ADD_DEFINITIONS(-D_TD_ARM_64_)
ELSE ()
EXIT ()
ENDIF ()
ENDIF ()
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8) IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
SET(TD_LINUX_64 TRUE) SET(TD_LINUX_64 TRUE)
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux) SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
ADD_DEFINITIONS(-D_M_X64) ADD_DEFINITIONS(-D_M_X64)
MESSAGE(STATUS "The current platform is Linux 64-bit") MESSAGE(STATUS "The current platform is Linux 64-bit")
ELSE () ELSEIF (${CMAKE_SIZEOF_VOID_P} MATCHES 4)
IF (TD_ARM)
SET(TD_LINUX_32 TRUE) SET(TD_LINUX_32 TRUE)
MESSAGE(FATAL_ERROR "The current platform is Linux 32-bit, not supported yet") SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
#ADD_DEFINITIONS(-D_M_IX86)
MESSAGE(STATUS "The current platform is Linux 32-bit")
ELSE ()
MESSAGE(FATAL_ERROR "The current platform is Linux 32-bit, but no ARM not supported yet")
EXIT ()
ENDIF ()
ELSE ()
MESSAGE(FATAL_ERROR "The current platform is Linux neither 32-bit nor 64-bit, not supported yet")
EXIT () EXIT ()
ENDIF () ENDIF ()
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@ -102,13 +137,27 @@ IF (NOT DEFINED TD_CLUSTER)
IF (TD_LINUX_64) IF (TD_LINUX_64)
SET(DEBUG_FLAGS "-O0 -DDEBUG") SET(DEBUG_FLAGS "-O0 -DDEBUG")
SET(RELEASE_FLAGS "-O0") SET(RELEASE_FLAGS "-O0")
IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") IF (NOT TD_ARM)
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ELSE ()
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF ()
ELSE () ELSE ()
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -Wno-char-subscripts -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -Wno-char-subscripts -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ENDIF () ENDIF ()
ADD_DEFINITIONS(-DLINUX) ADD_DEFINITIONS(-DLINUX)
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
ELSEIF (TD_LINUX_32)
IF (NOT TD_ARM)
EXIT ()
ENDIF ()
SET(DEBUG_FLAGS "-O0 -DDEBUG")
SET(RELEASE_FLAGS "-O0")
SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -Wno-char-subscripts -fsigned-char -munaligned-access -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE")
ADD_DEFINITIONS(-DLINUX)
ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT)
ADD_DEFINITIONS(-DUSE_LIBICONV)
ELSEIF (TD_WINDOWS_64) ELSEIF (TD_WINDOWS_64)
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
@ -169,6 +218,14 @@ IF (NOT DEFINED TD_CLUSTER)
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")") INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})") INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})") INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})")
ELSEIF (TD_LINUX_32)
IF (NOT TD_ARM)
EXIT ()
ENDIF ()
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
INSTALL(CODE "execute_process(COMMAND chmod 777 ${TD_MAKE_INSTALL_SH})")
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} ${TD_COMMUNITY_DIR} ${PROJECT_BINARY_DIR})")
ELSEIF (TD_WINDOWS_64) ELSEIF (TD_WINDOWS_64)
SET(CMAKE_INSTALL_PREFIX C:/TDengine) SET(CMAKE_INSTALL_PREFIX C:/TDengine)
INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/go DESTINATION connector) INSTALL(DIRECTORY ${TD_COMMUNITY_DIR}/src/connector/go DESTINATION connector)

View File

@ -63,7 +63,7 @@ Query OK, 2 row(s) in set (0.001700s)</code></pre>
<a class='anchor' id='主要功能'></a><h2>主要功能</h2> <a class='anchor' id='主要功能'></a><h2>主要功能</h2>
<p>TDengine的核心功能是时序数据库。除此之外为减少研发的复杂度、系统维护的难度TDengine还提供缓存、消息队列、订阅、流式计算等功能。更详细的功能如下</p> <p>TDengine的核心功能是时序数据库。除此之外为减少研发的复杂度、系统维护的难度TDengine还提供缓存、消息队列、订阅、流式计算等功能。更详细的功能如下</p>
<ul> <ul>
<li>使用类SQL语言插入或查询数据</li> <li>使用类SQL语言插入或查询数据</li>
<li>支持C/C++, Java(JDBC), Python, Go, RESTful, and Node.JS 开发接口</li> <li>支持C/C++, Java(JDBC), Python, Go, RESTful, and Node.JS 开发接口</li>
<li>可通过Python/R/Matlab or TDengine shell做Ad Hoc查询分析</li> <li>可通过Python/R/Matlab or TDengine shell做Ad Hoc查询分析</li>
<li>通过定时连续查询支持基于滑动窗口的流式计算</li> <li>通过定时连续查询支持基于滑动窗口的流式计算</li>

View File

@ -24,7 +24,7 @@ tags (location binary(20), type int)</code></pre>
<p>说明:</p> <p>说明:</p>
<ol> <ol>
<li>TAGS列总长度不能超过512 bytes</li> <li>TAGS列总长度不能超过512 bytes</li>
<li>TAGS列的数据类型不能是timestamp和nchar类型;</li> <li>TAGS列的数据类型不能是timestamp类型</li>
<li>TAGS列名不能与其他列名相同;</li> <li>TAGS列名不能与其他列名相同;</li>
<li>TAGS列名不能为预留关键字. </li></ol></li> <li>TAGS列名不能为预留关键字. </li></ol></li>
<li><p>显示已创建的超级表</p> <li><p>显示已创建的超级表</p>
@ -40,7 +40,7 @@ tags (location binary(20), type int)</code></pre>
<p>统计属于某个STable并满足查询条件的子表的数量</p></li> <p>统计属于某个STable并满足查询条件的子表的数量</p></li>
</ul> </ul>
<a class='anchor' id='写数据时自动建子表'></a><h2>写数据时自动建子表</h2> <a class='anchor' id='写数据时自动建子表'></a><h2>写数据时自动建子表</h2>
<p>在某些特殊场景中,用户在写数据时并不确定某个设备的表是否存在,此时可使用自动建表语法来实现写入数据时用超级表定义的表结构自动创建不存在的子表若该表已存在则不会建立新表。注意自动建表语句只能自动建立子表而不能建立超级表这就要求超级表已经被事先定义好。自动建表语法跟insert/import语法非常相似唯一区别是语句中增加了超级表和标签信息。具体语法如下</p> <p>在某些特殊场景中用户在写数据时并不确定某个设备的表是否存在此时可使用自动建表语法来实现写入数据时用超级表定义的表结构自动创建不存在的子表若该表已存在则不会建立新表。注意自动建表语句只能自动建立子表而不能建立超级表这就要求超级表已经被事先定义好。自动建表语法跟insert/import语法非常相似唯一区别是语句中增加了超级表和标签信息。具体语法如下</p>
<pre><code class="mysql language-mysql">INSERT INTO &lt;tb_name&gt; USING &lt;stb_name&gt; TAGS (&lt;tag1_value&gt;, ...) VALUES (field_value, ...) (field_value, ...) ...;</code></pre> <pre><code class="mysql language-mysql">INSERT INTO &lt;tb_name&gt; USING &lt;stb_name&gt; TAGS (&lt;tag1_value&gt;, ...) VALUES (field_value, ...) (field_value, ...) ...;</code></pre>
<p>向表tb_name中插入一条或多条记录如果tb_name这张表不存在则会用超级表stb_name定义的表结构以及用户指定的标签值(即tag1_value…)来创建名为tb_name新表并将用户指定的值写入表中。如果tb_name已经存在则建表过程会被忽略系统也不会检查tb_name的标签是否与用户指定的标签值一致也即不会更新已存在表的标签。</p> <p>向表tb_name中插入一条或多条记录如果tb_name这张表不存在则会用超级表stb_name定义的表结构以及用户指定的标签值(即tag1_value…)来创建名为tb_name新表并将用户指定的值写入表中。如果tb_name已经存在则建表过程会被忽略系统也不会检查tb_name的标签是否与用户指定的标签值一致也即不会更新已存在表的标签。</p>
<pre><code class="mysql language-mysql">INSERT INTO &lt;tb1_name&gt; USING &lt;stb1_name&gt; TAGS (&lt;tag1_value1&gt;, ...) VALUES (&lt;field1_value1&gt;, ...) (&lt;field1_value2&gt;, ...) ... &lt;tb_name2&gt; USING &lt;stb_name2&gt; TAGS(&lt;tag1_value2&gt;, ...) VALUES (&lt;field1_value1&gt;, ...) ...;</code></pre> <pre><code class="mysql language-mysql">INSERT INTO &lt;tb1_name&gt; USING &lt;stb1_name&gt; TAGS (&lt;tag1_value1&gt;, ...) VALUES (&lt;field1_value1&gt;, ...) (&lt;field1_value2&gt;, ...) ... &lt;tb_name2&gt; USING &lt;stb_name2&gt; TAGS(&lt;tag1_value2&gt;, ...) VALUES (&lt;field1_value1&gt;, ...) ...;</code></pre>
@ -105,6 +105,6 @@ GROUP BY location, type </code></pre>
<p>查询仅位于北京以外地区的温度传感器最近24小时(24h)采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)和最低温度min(degree)将采集结果按照10分钟为周期进行聚合并将结果按所处地域(location)和传感器类型(type)再次进行聚合。</p> <p>查询仅位于北京以外地区的温度传感器最近24小时(24h)采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)和最低温度min(degree)将采集结果按照10分钟为周期进行聚合并将结果按所处地域(location)和传感器类型(type)再次进行聚合。</p>
<pre><code class="mysql language-mysql">SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree) <pre><code class="mysql language-mysql">SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree)
FROM thermometer FROM thermometer
WHERE name&lt;&gt;'beijing' and ts&gt;=now-1d WHERE location&lt;&gt;'beijing' and ts&gt;=now-1d
INTERVAL(10M) INTERVAL(10M)
GROUP BY location, type</code></pre><a href='../index.html'>回去</a></section></main></div><?php include($s.'/footer.php'); ?><script>$('pre').addClass('prettyprint linenums');PR.prettyPrint()</script><script src='lib/docs/liner.js'></script></body></html> GROUP BY location, type</code></pre><a href='../index.html'>回去</a></section></main></div><?php include($s.'/footer.php'); ?><script>$('pre').addClass('prettyprint linenums');PR.prettyPrint()</script><script src='lib/docs/liner.js'></script></body></html>

View File

@ -169,7 +169,7 @@ SELECT function<field_name>,…
以温度传感器采集时序数据作为例示范STable的使用。 在这个例子中对每个温度计都会建立一张表表名为温度计的ID温度计读数的时刻记为ts采集的值记为degree。通过tags给每个采集器打上不同的标签其中记录温度计的地区和类型以方便我们后面的查询。所有温度计的采集量都一样因此我们用STable来定义表结构。 以温度传感器采集时序数据作为例示范STable的使用。 在这个例子中对每个温度计都会建立一张表表名为温度计的ID温度计读数的时刻记为ts采集的值记为degree。通过tags给每个采集器打上不同的标签其中记录温度计的地区和类型以方便我们后面的查询。所有温度计的采集量都一样因此我们用STable来定义表结构。
###定义STable表结构并使用它创建子表 ###1:定义STable表结构并使用它创建子表
创建STable语句如下 创建STable语句如下
@ -189,7 +189,7 @@ CREATE TABLE therm4 USING thermometer TAGS ('shanghai', 3);
其中therm1therm2therm3therm4是超级表thermometer四个具体的子表也即普通的Table。以therm1为例它表示采集器therm1的数据表结构完全由thermometer定义标签location=”beijing”, type=1表示therm1的地区是北京类型是第1类的温度计。 其中therm1therm2therm3therm4是超级表thermometer四个具体的子表也即普通的Table。以therm1为例它表示采集器therm1的数据表结构完全由thermometer定义标签location=”beijing”, type=1表示therm1的地区是北京类型是第1类的温度计。
###写入数据 ###2:写入数据
注意写入数据时不能直接对STable操作而是要对每张子表进行操作。我们分别向四张表therm1therm2 therm3 therm4写入一条数据写入语句如下 注意写入数据时不能直接对STable操作而是要对每张子表进行操作。我们分别向四张表therm1therm2 therm3 therm4写入一条数据写入语句如下
@ -200,7 +200,7 @@ INSERT INTO therm3 VALUES ('2018-01-01 00:00:00.000', 24);
INSERT INTO therm4 VALUES ('2018-01-01 00:00:00.000', 23); INSERT INTO therm4 VALUES ('2018-01-01 00:00:00.000', 23);
``` ```
### 按标签聚合查询 ###3:按标签聚合查询
查询位于北京(beijing)和天津(tianjing)两个地区的温度传感器采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)、最低温度min(degree),并将结果按所处地域(location)和传感器类型(type)进行聚合。 查询位于北京(beijing)和天津(tianjing)两个地区的温度传感器采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)、最低温度min(degree),并将结果按所处地域(location)和传感器类型(type)进行聚合。
@ -211,7 +211,7 @@ WHERE location='beijing' or location='tianjin'
GROUP BY location, type GROUP BY location, type
``` ```
### 按时间周期聚合查询 ###4:按时间周期聚合查询
查询仅位于北京以外地区的温度传感器最近24小时(24h)采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)和最低温度min(degree)将采集结果按照10分钟为周期进行聚合并将结果按所处地域(location)和传感器类型(type)再次进行聚合。 查询仅位于北京以外地区的温度传感器最近24小时(24h)采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)和最低温度min(degree)将采集结果按照10分钟为周期进行聚合并将结果按所处地域(location)和传感器类型(type)再次进行聚合。

View File

@ -269,13 +269,14 @@ public Connection getConn() throws Exception{
用户可以在源代码的src/connector/python文件夹下找到python2和python3的安装包。用户可以通过pip命令安装 用户可以在源代码的src/connector/python文件夹下找到python2和python3的安装包。用户可以通过pip命令安装
`pip install src/connector/python/python2/` `pip install src/connector/python/[linux|windows]/python2/`
`pip install src/connector/python/python3/` `pip install src/connector/python/[linux|windows]/python3/`
如果机器上没有pip命令用户可将src/connector/python/python3或src/connector/python/python2下的taos文件夹拷贝到应用程序的目录使用。 如果机器上没有pip命令用户可将src/connector/python/python3或src/connector/python/python2下的taos文件夹拷贝到应用程序的目录使用。
对于windows 客户端安装TDengine windows 客户端后将C:\TDengine\driver\taos.dll拷贝到C:\windows\system32目录下即可。所有TDengine的连接器均需依赖taos.dll。
### Python客户端接口 ### Python客户端接口

View File

@ -49,6 +49,7 @@ cp ${compile_dir}/build/bin/taosd ${pkg_dir}${install_home_pat
cp ${compile_dir}/build/bin/taos ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taos ${pkg_dir}${install_home_path}/bin
cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver
cp ${compile_dir}/../src/inc/taos.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../src/inc/taos.h ${pkg_dir}${install_home_path}/include
cp ${compile_dir}/../src/inc/taoserror.h ${pkg_dir}${install_home_path}/include
cp -r ${top_dir}/tests/examples/* ${pkg_dir}${install_home_path}/examples cp -r ${top_dir}/tests/examples/* ${pkg_dir}${install_home_path}/examples
cp -r ${top_dir}/src/connector/grafana ${pkg_dir}${install_home_path}/connector cp -r ${top_dir}/src/connector/grafana ${pkg_dir}${install_home_path}/connector
cp -r ${top_dir}/src/connector/python ${pkg_dir}${install_home_path}/connector cp -r ${top_dir}/src/connector/python ${pkg_dir}${install_home_path}/connector

View File

@ -62,6 +62,7 @@ cp %{_compiledir}/build/bin/taosdemo %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver
cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include
cp %{_compiledir}/../src/inc/taoserror.h %{buildroot}%{homepath}/include
cp -r %{_compiledir}/../src/connector/grafana %{buildroot}%{homepath}/connector cp -r %{_compiledir}/../src/connector/grafana %{buildroot}%{homepath}/connector
cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector
cp -r %{_compiledir}/../src/connector/go %{buildroot}%{homepath}/connector cp -r %{_compiledir}/../src/connector/go %{buildroot}%{homepath}/connector
@ -138,6 +139,7 @@ if [ $1 -eq 0 ];then
${csudo} rm -f ${bin_link_dir}/taosdump || : ${csudo} rm -f ${bin_link_dir}/taosdump || :
${csudo} rm -f ${cfg_link_dir}/* || : ${csudo} rm -f ${cfg_link_dir}/* || :
${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taos.h || :
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} rm -f ${lib_link_dir}/libtaos.* || :
${csudo} rm -f ${log_link_dir} || : ${csudo} rm -f ${log_link_dir} || :

View File

@ -98,9 +98,10 @@ function install_lib() {
} }
function install_header() { function install_header() {
${csudo} rm -f ${inc_link_dir}/taos.h || : ${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} 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/taos.h ${inc_link_dir}/taos.h
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
} }
function install_config() { function install_config() {
@ -247,9 +248,9 @@ vercomp () {
function is_version_compatible() { function is_version_compatible() {
curr_version=$(${bin_dir}/taosd -V | cut -d ' ' -f 1) curr_version=$(${bin_dir}/taosd -V | cut -d ' ' -f 2)
min_compatible_version=$(${script_dir}/bin/taosd -V | cut -d ' ' -f 2) min_compatible_version=$(${script_dir}/bin/taosd -V | cut -d ' ' -f 4)
vercomp $curr_version $min_compatible_version vercomp $curr_version $min_compatible_version
case $? in case $? in

View File

@ -109,9 +109,10 @@ function install_lib() {
function install_header() { function install_header() {
${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || :
${csudo} cp -f ${source_dir}/src/inc/taos.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* ${csudo} cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taoserror.h ${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/taos.h ${inc_link_dir}/taos.h
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
} }
function install_config() { function install_config() {

View File

@ -22,7 +22,7 @@ install_dir="${release_dir}/taos-${version}-${package_name}-$(echo ${build_time}
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) versioninfo=$(${script_dir}/get_version.sh ${code_dir}/util/src/version.c)
lib_files="${build_dir}/lib/libtaos.so.${versioninfo}" lib_files="${build_dir}/lib/libtaos.so.${versioninfo}"
header_files="${code_dir}/inc/taos.h" header_files="${code_dir}/inc/taos.h ${code_dir}/inc/taoserror.h"
cfg_files="${top_dir}/packaging/cfg/*.cfg" cfg_files="${top_dir}/packaging/cfg/*.cfg"
install_files="${script_dir}/install.sh ${script_dir}/install_client.sh" install_files="${script_dir}/install.sh ${script_dir}/install_client.sh"

View File

@ -61,8 +61,9 @@ function kill_taosd() {
} }
function install_include() { function install_include() {
${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h|| :
${csudo} ln -s ${inc_dir}/taos.h ${inc_link_dir}/taos.h ${csudo} ln -s ${inc_dir}/taos.h ${inc_link_dir}/taos.h
${csudo} ln -s ${inc_dir}/taoserror.h ${inc_link_dir}/taoserror.h
} }
function install_lib() { function install_lib() {

View File

@ -94,6 +94,7 @@ ${csudo} rm -f ${bin_link_dir}/taosdemo || :
${csudo} rm -f ${bin_link_dir}/taosdump || : ${csudo} rm -f ${bin_link_dir}/taosdump || :
${csudo} rm -f ${cfg_link_dir}/* || : ${csudo} rm -f ${cfg_link_dir}/* || :
${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taos.h || :
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} rm -f ${lib_link_dir}/libtaos.* || :
${csudo} rm -f ${log_link_dir} || : ${csudo} rm -f ${log_link_dir} || :

View File

@ -61,6 +61,7 @@ function clean_lib() {
function clean_header() { function clean_header() {
# Remove link # Remove link
${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taos.h || :
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
} }
function clean_config() { function clean_config() {

View File

@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
AUX_SOURCE_DIRECTORY(./src SRC) AUX_SOURCE_DIRECTORY(./src SRC)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/linux)
# set the static lib name # set the static lib name

View File

@ -30,10 +30,10 @@ extern "C" {
#include "tsdb.h" #include "tsdb.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#define UTIL_METER_IS_METRIC(cmd) (((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_METRIC)) #define UTIL_METER_IS_METRIC(metaInfo) (((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_METRIC))
#define UTIL_METER_IS_NOMRAL_METER(cmd) (!(UTIL_METER_IS_METRIC(cmd))) #define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_METRIC(metaInfo)))
#define UTIL_METER_IS_CREATE_FROM_METRIC(cmd) \ #define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \
(((cmd)->pMeterMeta != NULL) && ((cmd)->pMeterMeta->meterType == TSDB_METER_MTABLE)) (((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_MTABLE))
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0) #define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)

View File

@ -479,6 +479,7 @@ void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql);
void tscKillMetricQuery(SSqlObj *pSql); void tscKillMetricQuery(SSqlObj *pSql);
void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen); void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen);
int32_t tscBuildResultsForEmptyRetrieval(SSqlObj *pSql); int32_t tscBuildResultsForEmptyRetrieval(SSqlObj *pSql);
bool tscIsUpdateQuery(STscObj *pObj);
// transfer SSqlInfo to SqlCmd struct // transfer SSqlInfo to SqlCmd struct
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);

View File

@ -13,8 +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 <stdbool.h>
#include "os.h" #include "os.h"
#include "com_taosdata_jdbc_TSDBJNIConnector.h" #include "com_taosdata_jdbc_TSDBJNIConnector.h"
#include "taos.h" #include "taos.h"
@ -63,13 +61,13 @@ jmethodID g_rowdataSetByteArrayFp;
void jniGetGlobalMethod(JNIEnv *env) { void jniGetGlobalMethod(JNIEnv *env) {
// make sure init function executed once // make sure init function executed once
switch (__sync_val_compare_and_swap_32(&__init, 0, 1)) { switch (atomic_val_compare_exchange_32(&__init, 0, 1)) {
case 0: case 0:
break; break;
case 1: case 1:
do { do {
taosMsleep(0); taosMsleep(0);
} while (__sync_val_load_32(&__init) == 1); } while (atomic_load_32(&__init) == 1);
case 2: case 2:
return; return;
} }
@ -109,7 +107,7 @@ void jniGetGlobalMethod(JNIEnv *env) {
g_rowdataSetByteArrayFp = (*env)->GetMethodID(env, g_rowdataClass, "setByteArray", "(I[B)V"); g_rowdataSetByteArrayFp = (*env)->GetMethodID(env, g_rowdataClass, "setByteArray", "(I[B)V");
(*env)->DeleteLocalRef(env, rowdataClass); (*env)->DeleteLocalRef(env, rowdataClass);
__sync_val_restore_32(&__init, 2); atomic_store_32(&__init, 2);
jniTrace("native method register finished"); jniTrace("native method register finished");
} }
@ -208,10 +206,10 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEn
ret = (jlong)taos_connect((char *)host, (char *)user, (char *)pass, (char *)dbname, jport); ret = (jlong)taos_connect((char *)host, (char *)user, (char *)pass, (char *)dbname, jport);
if (ret == 0) { if (ret == 0) {
jniError("jobj:%p, taos:%p, connect to tdengine failed, host=%s, user=%s, dbname=%s, port=%d", jobj, (void *)ret, jniError("jobj:%p, conn:%p, connect to database failed, host=%s, user=%s, dbname=%s, port=%d", jobj, (void *)ret,
(char *)host, (char *)user, (char *)dbname, jport); (char *)host, (char *)user, (char *)dbname, jport);
} else { } else {
jniTrace("jobj:%p, taos:%p, connect to tdengine succeed, host=%s, user=%s, dbname=%s, port=%d", jobj, (void *)ret, jniTrace("jobj:%p, conn:%p, connect to database succeed, host=%s, user=%s, dbname=%s, port=%d", jobj, (void *)ret,
(char *)host, (char *)user, (char *)dbname, jport); (char *)host, (char *)user, (char *)dbname, jport);
} }
@ -232,7 +230,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
} }
if (jsql == NULL) { if (jsql == NULL) {
jniError("jobj:%p, taos:%p, sql is null", jobj, tscon); jniError("jobj:%p, conn:%p, sql is null", jobj, tscon);
return JNI_SQL_NULL; return JNI_SQL_NULL;
} }
@ -250,7 +248,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
int code = taos_query(tscon, dst); int code = taos_query(tscon, dst);
if (code != 0) { if (code != 0) {
jniError("jobj:%p, taos:%p, code:%d, msg:%s, sql:%s", jobj, tscon, code, taos_errstr(tscon), dst); jniError("jobj:%p, conn:%p, code:%d, msg:%s, sql:%s", jobj, tscon, code, taos_errstr(tscon), dst);
free(dst); free(dst);
return JNI_TDENGINE_ERROR; return JNI_TDENGINE_ERROR;
} else { } else {
@ -259,9 +257,9 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J
if (pSql->cmd.command == TSDB_SQL_INSERT) { if (pSql->cmd.command == TSDB_SQL_INSERT) {
affectRows = taos_affected_rows(tscon); affectRows = taos_affected_rows(tscon);
jniTrace("jobj:%p, taos:%p, code:%d, affect rows:%d, sql:%s", jobj, tscon, code, affectRows, dst); jniTrace("jobj:%p, conn:%p, code:%d, affect rows:%d, sql:%s", jobj, tscon, code, affectRows, dst);
} else { } else {
jniTrace("jobj:%p, taos:%p, code:%d, sql:%s", jobj, tscon, code, dst); jniTrace("jobj:%p, conn:%p, code:%d, sql:%s", jobj, tscon, code, dst);
} }
free(dst); free(dst);
@ -291,15 +289,17 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp(
return JNI_CONNECTION_NULL; return JNI_CONNECTION_NULL;
} }
int num_fields = taos_field_count(tscon); jlong ret = 0;
if (num_fields != 0) {
jlong ret = (jlong)taos_use_result(tscon); if (tscIsUpdateQuery(tscon)) {
jniTrace("jobj:%p, taos:%p, get resultset:%p", jobj, tscon, (void *)ret); ret = 0; // for update query, no result pointer
return ret; jniTrace("jobj:%p, conn:%p, no result", jobj, tscon);
} else {
ret = (jlong) taos_use_result(tscon);
jniTrace("jobj:%p, conn:%p, get resultset:%p", jobj, tscon, (void *) ret);
} }
jniTrace("jobj:%p, taos:%p, no resultset", jobj, tscon); return ret;
return 0;
} }
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con, JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(JNIEnv *env, jobject jobj, jlong con,
@ -311,12 +311,12 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_freeResultSetImp(
} }
if ((void *)res == NULL) { if ((void *)res == NULL) {
jniError("jobj:%p, taos:%p, resultset is null", jobj, tscon); jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL; return JNI_RESULT_SET_NULL;
} }
taos_free_result((void *)res); taos_free_result((void *)res);
jniTrace("jobj:%p, taos:%p, free resultset:%p", jobj, tscon, (void *)res); jniTrace("jobj:%p, conn:%p, free resultset:%p", jobj, tscon, (void *)res);
return JNI_SUCCESS; return JNI_SUCCESS;
} }
@ -330,7 +330,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsIm
jint ret = taos_affected_rows(tscon); jint ret = taos_affected_rows(tscon);
jniTrace("jobj:%p, taos:%p, affect rows:%d", jobj, tscon, (void *)con, ret); jniTrace("jobj:%p, conn:%p, affect rows:%d", jobj, tscon, (void *)con, ret);
return ret; return ret;
} }
@ -346,7 +346,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getSchemaMetaData
TAOS_RES *result = (TAOS_RES *)res; TAOS_RES *result = (TAOS_RES *)res;
if (result == NULL) { if (result == NULL) {
jniError("jobj:%p, taos:%p, resultset is null", jobj, tscon); jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL; return JNI_RESULT_SET_NULL;
} }
@ -356,10 +356,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getSchemaMetaData
// jobject arrayListObj = (*env)->NewObject(env, g_arrayListClass, g_arrayListConstructFp, ""); // jobject arrayListObj = (*env)->NewObject(env, g_arrayListClass, g_arrayListConstructFp, "");
if (num_fields == 0) { if (num_fields == 0) {
jniError("jobj:%p, taos:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields);
return JNI_NUM_OF_FIELDS_0; return JNI_NUM_OF_FIELDS_0;
} else { } else {
jniTrace("jobj:%p, taos:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields);
for (int i = 0; i < num_fields; ++i) { for (int i = 0; i < num_fields; ++i) {
jobject metadataObj = (*env)->NewObject(env, g_metadataClass, g_metadataConstructFp); jobject metadataObj = (*env)->NewObject(env, g_metadataClass, g_metadataConstructFp);
(*env)->SetIntField(env, metadataObj, g_metadataColtypeField, fields[i].type); (*env)->SetIntField(env, metadataObj, g_metadataColtypeField, fields[i].type);
@ -402,7 +402,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
TAOS_RES *result = (TAOS_RES *)res; TAOS_RES *result = (TAOS_RES *)res;
if (result == NULL) { if (result == NULL) {
jniError("jobj:%p, taos:%p, resultset is null", jobj, tscon); jniError("jobj:%p, conn:%p, resultset is null", jobj, tscon);
return JNI_RESULT_SET_NULL; return JNI_RESULT_SET_NULL;
} }
@ -410,7 +410,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
int num_fields = taos_num_fields(result); int num_fields = taos_num_fields(result);
if (num_fields == 0) { if (num_fields == 0) {
jniError("jobj:%p, taos:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields);
return JNI_NUM_OF_FIELDS_0; return JNI_NUM_OF_FIELDS_0;
} }
@ -418,10 +418,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
if (row == NULL) { if (row == NULL) {
int tserrno = taos_errno(tscon); int tserrno = taos_errno(tscon);
if (tserrno == 0) { if (tserrno == 0) {
jniTrace("jobj:%p, taos:%p, resultset:%p, fields size is %d, fetch row to the end", jobj, tscon, res, num_fields); jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d, fetch row to the end", jobj, tscon, res, num_fields);
return JNI_FETCH_END; return JNI_FETCH_END;
} else { } else {
jniTrace("jobj:%p, taos:%p, interruptted query", jobj, tscon); jniTrace("jobj:%p, conn:%p, interruptted query", jobj, tscon);
return JNI_RESULT_SET_NULL; return JNI_RESULT_SET_NULL;
} }
} }
@ -485,7 +485,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_closeConnectionIm
jniError("jobj:%p, connection is closed", jobj); jniError("jobj:%p, connection is closed", jobj);
return JNI_CONNECTION_NULL; return JNI_CONNECTION_NULL;
} else { } else {
jniTrace("jobj:%p, taos:%p, close connection success", jobj, tscon); jniTrace("jobj:%p, conn:%p, close connection success", jobj, tscon);
taos_close(tscon); taos_close(tscon);
return JNI_SUCCESS; return JNI_SUCCESS;
} }
@ -640,7 +640,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_validateCreateTab
} }
if (jsql == NULL) { if (jsql == NULL) {
jniError("jobj:%p, taos:%p, sql is null", jobj, tscon); jniError("jobj:%p, conn:%p, sql is null", jobj, tscon);
return JNI_SQL_NULL; return JNI_SQL_NULL;
} }

View File

@ -13,12 +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 <assert.h>
#include <float.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tast.h" #include "tast.h"
@ -261,8 +255,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
t0 = tStrGetToken(str, i, false, 0, NULL); t0 = tStrGetToken(str, i, false, 0, NULL);
if (t0.n == 0 || t0.type == TK_RP) { if (t0.n == 0 || t0.type == TK_RP) {
if (pLeft->nodeType != TSQL_NODE_EXPR) { if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr
// if left is not the expr, it is not a legal expr
tSQLSyntaxNodeDestroy(pLeft, NULL); tSQLSyntaxNodeDestroy(pLeft, NULL);
return NULL; return NULL;
} }
@ -326,13 +319,13 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
pn->colId = -1; pn->colId = -1;
return pn; return pn;
} else { } else {
int32_t optr = getBinaryExprOptr(&t0); uint8_t localOptr = getBinaryExprOptr(&t0);
if (optr <= 0) { if (localOptr <= 0) {
pError("not support binary operator:%d", t0.type); pError("not support binary operator:%d", t0.type);
return NULL; return NULL;
} }
return parseRemainStr(str, pBinExpr, pSchema, optr, numOfCols, i); return parseRemainStr(str, pBinExpr, pSchema, localOptr, numOfCols, i);
} }
} }

View File

@ -13,8 +13,7 @@
* 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 <stdio.h> #include "os.h"
#include <stdlib.h>
#include "tlog.h" #include "tlog.h"
#include "trpc.h" #include "trpc.h"

View File

@ -13,14 +13,7 @@
* 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 <assert.h> #include "os.h"
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "tlog.h" #include "tlog.h"

File diff suppressed because it is too large Load Diff

View File

@ -13,13 +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 <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <tsclient.h>
#include <sys/stat.h>
#include "os.h" #include "os.h"
#include "tcache.h" #include "tcache.h"
#include "tscJoinProcess.h" #include "tscJoinProcess.h"
@ -360,7 +353,7 @@ static void doQuitSubquery(SSqlObj* pParentSql) {
} }
static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter) { static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter) {
if (__sync_add_and_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) { if (atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) {
pSqlObj->res.code = abs(pSupporter->pState->code); pSqlObj->res.code = abs(pSupporter->pState->code);
tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code); tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code);
@ -419,7 +412,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
taos_fetch_rows_a(tres, joinRetrieveCallback, param); taos_fetch_rows_a(tres, joinRetrieveCallback, param);
} else if (numOfRows == 0) { // no data from this vnode anymore } else if (numOfRows == 0) { // no data from this vnode anymore
if (__sync_add_and_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) { if (atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) {
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, tres, tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, tres,
@ -458,7 +451,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
tscError("%p retrieve failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex); tscError("%p retrieve failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex);
} }
if (__sync_add_and_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) { if (atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) {
tscTrace("%p secondary retrieve completed, global code:%d", tres, pParentSql->res.code); tscTrace("%p secondary retrieve completed, global code:%d", tres, pParentSql->res.code);
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
pParentSql->res.code = abs(pSupporter->pState->code); pParentSql->res.code = abs(pSupporter->pState->code);
@ -567,7 +560,7 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param; SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
// if (__sync_add_and_fetch_32(pSupporter->numOfComplete, 1) >= // if (atomic_add_fetch_32(pSupporter->numOfComplete, 1) >=
// pSupporter->numOfTotal) { // pSupporter->numOfTotal) {
// SSqlObj *pParentObj = pSupporter->pObj; // SSqlObj *pParentObj = pSupporter->pObj;
// //
@ -612,7 +605,7 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
quitAllSubquery(pParentSql, pSupporter); quitAllSubquery(pParentSql, pSupporter);
} else { } else {
if (__sync_add_and_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) { if (atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1) >= pSupporter->pState->numOfTotal) {
tscSetupOutputColumnIndex(pParentSql); tscSetupOutputColumnIndex(pParentSql);
if (pParentSql->fp == NULL) { if (pParentSql->fp == NULL) {

View File

@ -13,9 +13,7 @@
* 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 <stdint.h> #include "os.h"
#include <stdio.h>
#include <stdlib.h>
#include "taosmsg.h" #include "taosmsg.h"
#include "tcache.h" #include "tcache.h"

View File

@ -21,22 +21,8 @@
#pragma GCC diagnostic ignored "-Woverflow" #pragma GCC diagnostic ignored "-Woverflow"
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <assert.h>
#include <float.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include "ihash.h"
#include "os.h" #include "os.h"
#include "ihash.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tschemautil.h" #include "tschemautil.h"
@ -205,10 +191,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
*((int8_t *)payload) = TSDB_DATA_TINYINT_NULL; *((int8_t *)payload) = TSDB_DATA_TINYINT_NULL;
} else { } else {
numType = tscToInteger(pToken, &iv, &endptr); numType = tscToInteger(pToken, &iv, &endptr);
if (errno == ERANGE || iv > INT8_MAX || iv <= INT8_MIN) { if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} else if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is illegal"); INVALID_SQL_RET_MSG(msg, "data is illegal");
} else if (errno == ERANGE || iv > INT8_MAX || iv <= INT8_MIN) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} }
*((int8_t *)payload) = (int8_t)iv; *((int8_t *)payload) = (int8_t)iv;
@ -224,10 +210,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
*((int16_t *)payload) = TSDB_DATA_SMALLINT_NULL; *((int16_t *)payload) = TSDB_DATA_SMALLINT_NULL;
} else { } else {
numType = tscToInteger(pToken, &iv, &endptr); numType = tscToInteger(pToken, &iv, &endptr);
if (errno == ERANGE || iv > INT16_MAX || iv <= INT16_MIN) { if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} else if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is illegal"); INVALID_SQL_RET_MSG(msg, "data is illegal");
} else if (errno == ERANGE || iv > INT16_MAX || iv <= INT16_MIN) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} }
*((int16_t *)payload) = (int16_t)iv; *((int16_t *)payload) = (int16_t)iv;
@ -242,10 +228,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
*((int32_t *)payload) = TSDB_DATA_INT_NULL; *((int32_t *)payload) = TSDB_DATA_INT_NULL;
} else { } else {
numType = tscToInteger(pToken, &iv, &endptr); numType = tscToInteger(pToken, &iv, &endptr);
if (errno == ERANGE || iv > INT32_MAX || iv <= INT32_MIN) { if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} else if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is illegal"); INVALID_SQL_RET_MSG(msg, "data is illegal");
} else if (errno == ERANGE || iv > INT32_MAX || iv <= INT32_MIN) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} }
*((int32_t *)payload) = (int32_t)iv; *((int32_t *)payload) = (int32_t)iv;
@ -261,10 +247,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
*((int64_t *)payload) = TSDB_DATA_BIGINT_NULL; *((int64_t *)payload) = TSDB_DATA_BIGINT_NULL;
} else { } else {
numType = tscToInteger(pToken, &iv, &endptr); numType = tscToInteger(pToken, &iv, &endptr);
if (errno == ERANGE || iv > INT64_MAX || iv <= INT64_MIN) { if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} else if (TK_ILLEGAL == numType) {
INVALID_SQL_RET_MSG(msg, "data is illegal"); INVALID_SQL_RET_MSG(msg, "data is illegal");
} else if (errno == ERANGE || iv > INT64_MAX || iv <= INT64_MIN) {
INVALID_SQL_RET_MSG(msg, "data is overflow");
} }
*((int64_t *)payload) = iv; *((int64_t *)payload) = iv;

View File

@ -13,9 +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 <stdio.h>
#include <stdlib.h>
#include "taos.h" #include "taos.h"
#include "tsclient.h" #include "tsclient.h"
#include "tsql.h" #include "tsql.h"

View File

@ -13,9 +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 <stdio.h>
#include <stdlib.h>
#include "os.h" #include "os.h"
#include "tlog.h" #include "tlog.h"
#include "tsclient.h" #include "tsclient.h"
@ -23,6 +20,27 @@
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
void tscSaveSlowQueryFp(void *handle, void *tmrId);
void *tscSlowQueryConn = NULL;
bool tscSlowQueryConnInitialized = false;
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, int port, void (*fp)(void *, TAOS_RES *, int),
void *param, void **taos);
void tscInitConnCb(void *param, TAOS_RES *result, int code) {
char *sql = param;
if (code < 0) {
tscError("taos:%p, slow query connect failed, code:%d", tscSlowQueryConn, code);
taos_close(tscSlowQueryConn);
tscSlowQueryConn = NULL;
tscSlowQueryConnInitialized = false;
free(sql);
} else {
tscTrace("taos:%p, slow query connect success, code:%d", tscSlowQueryConn, code);
tscSlowQueryConnInitialized = true;
tscSaveSlowQueryFp(sql, NULL);
}
}
void tscAddIntoSqlList(SSqlObj *pSql) { void tscAddIntoSqlList(SSqlObj *pSql) {
static uint32_t queryId = 1; static uint32_t queryId = 1;
@ -47,33 +65,35 @@ void tscAddIntoSqlList(SSqlObj *pSql) {
void tscSaveSlowQueryFpCb(void *param, TAOS_RES *result, int code) { void tscSaveSlowQueryFpCb(void *param, TAOS_RES *result, int code) {
if (code < 0) { if (code < 0) {
tscError("failed to save slowquery, code:%d", code); tscError("failed to save slow query, code:%d", code);
} else {
tscTrace("success to save slow query, code:%d", code);
} }
} }
void tscSaveSlowQueryFp(void *handle, void *tmrId) { void tscSaveSlowQueryFp(void *handle, void *tmrId) {
char *sql = handle; char *sql = handle;
static void *taos = NULL; if (!tscSlowQueryConnInitialized) {
if (taos == NULL) { if (tscSlowQueryConn == NULL) {
taos = taos_connect(NULL, "monitor", tsInternalPass, NULL, 0); tscTrace("start to init slow query connect");
if (taos == NULL) { taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, tscInitConnCb, sql, &tscSlowQueryConn);
tscError("failed to save slow query, can't connect to server"); } else {
tscError("taos:%p, slow query connect is already initialized", tscSlowQueryConn);
free(sql); free(sql);
return;
} }
} else {
tscTrace("taos:%p, save slow query:%s", tscSlowQueryConn, sql);
taos_query_a(tscSlowQueryConn, sql, tscSaveSlowQueryFpCb, NULL);
free(sql);
} }
tscTrace("save slow query:sql", sql);
taos_query_a(taos, sql, tscSaveSlowQueryFpCb, NULL);
free(sql);
} }
void tscSaveSlowQuery(SSqlObj *pSql) { void tscSaveSlowQuery(SSqlObj *pSql) {
const static int64_t SLOW_QUERY_INTERVAL = 3000000L; const static int64_t SLOW_QUERY_INTERVAL = 3000000L;
if (pSql->res.useconds < SLOW_QUERY_INTERVAL) return; if (pSql->res.useconds < SLOW_QUERY_INTERVAL) return;
tscTrace("%p query time:%ld sql:%s", pSql, pSql->res.useconds, pSql->sqlstr); tscTrace("%p query time:%lld sql:%s", pSql, pSql->res.useconds, pSql->sqlstr);
char *sql = malloc(200); char *sql = malloc(200);
int len = snprintf(sql, 200, "insert into %s.slowquery values(now, '%s', %lld, %lld, '", tsMonitorDbName, int len = snprintf(sql, 200, "insert into %s.slowquery values(now, '%s', %lld, %lld, '", tsMonitorDbName,

View File

@ -81,7 +81,7 @@ static bool validateIpAddress(char* ip);
static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd); static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd);
static bool functionCompatibleCheck(SSqlCmd* pCmd); static bool functionCompatibleCheck(SSqlCmd* pCmd);
static void setColumnOffsetValueInResultset(SSqlCmd* pCmd); static void setColumnOffsetValueInResultset(SSqlCmd* pCmd);
static int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList); static int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList);
static int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql); static int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql);
@ -94,7 +94,7 @@ static int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL);
static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema, int32_t numOfCols); static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema, int32_t numOfCols);
static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd); static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd);
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField); static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd); static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd);
static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString); static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString);
@ -105,8 +105,8 @@ static int32_t validateLocalConfig(tDCLSQL* pOptions);
static int32_t validateColumnName(char* name); static int32_t validateColumnName(char* name);
static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd); static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd);
static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex); static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex);
static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql); static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql);
static int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd); static int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd);
@ -115,13 +115,12 @@ static int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnInde
static int32_t optrToString(tSQLExpr* pExpr, char** exprString); static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex); static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex); static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql); static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql);
static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) { static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) {
assert(QUERY_IS_STABLE_QUERY(pCmd->type)); assert(QUERY_IS_STABLE_QUERY(pCmd->type));
// here colIdx == -1 means the special column tbname that is the name of each table
*queryOnMetricTags = true; *queryOnMetricTags = true;
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
@ -1151,7 +1150,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) {
} }
// check the invalid sql expresssion: select count(tbname)/count(tag1)/count(tag2) from super_table interval(1d); // check the invalid sql expresssion: select count(tbname)/count(tag1)/count(tag2) from super_table interval(1d);
for(int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { if (pExpr->functionId == TSDB_FUNC_COUNT && TSDB_COL_IS_TAG(pExpr->colInfo.flag)) {
setErrMsg(pCmd, msg1); setErrMsg(pCmd, msg1);
@ -2791,10 +2790,14 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) {
// diff function cannot be executed with other function // diff function cannot be executed with other function
// arithmetic function can be executed with other arithmetic functions // arithmetic function can be executed with other arithmetic functions
for (int32_t i = startIdx + 1; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = startIdx + 1; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (functionId == TSDB_FUNC_TAGPRJ ||
functionId == TSDB_FUNC_TAG || int16_t functionId = pExpr->functionId;
functionId == TSDB_FUNC_TS) { if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) {
continue;
}
if (functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
continue; continue;
} }
@ -2803,61 +2806,6 @@ static bool functionCompatibleCheck(SSqlCmd* pCmd) {
} }
} }
// additional check for select aggfuntion(column), column1 from table_name group by(column1);
if ((pCmd->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) == TSDB_QUERY_TYPE_PROJECTION_QUERY) {
bool isAggFunc = false;
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
int16_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId == TSDB_FUNC_PRJ ||
functionId == TSDB_FUNC_TAGPRJ ||
functionId == TSDB_FUNC_TS ||
functionId == TSDB_FUNC_ARITHM) {
continue;
}
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == 0) {
isAggFunc = true;
break;
}
}
// TODO change the type, the type is not correct
if (isAggFunc) {
pCmd->type &= (~TSDB_QUERY_TYPE_PROJECTION_QUERY);
// agg function mixed up with project query without group by exists
if (pCmd->groupbyExpr.numOfGroupCols == 0) {
return false;
}
// get the project column
int32_t numOfPrjColumn = 0;
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_PRJ) {
numOfPrjColumn += 1;
bool qualifiedCol = false;
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) {
qualifiedCol = true;
pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value
pExpr->numOfParams = 1;
break;
}
}
if (!qualifiedCol) {
setErrMsg(pCmd, msg1);
return false;
}
}
}
}
}
return true; return true;
} }
@ -4986,19 +4934,37 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) {
int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
bool isProjectionFunction = false; bool isProjectionFunction = false;
const char* msg = "column projection is not compatible with interval"; const char* msg1 = "column projection is not compatible with interval";
const char* msg2 = "interval not allowed for tag queries";
// multi-output set/ todo refactor // multi-output set/ todo refactor
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, k); SSqlExpr* pExpr = tscSqlExprGet(pCmd, k);
// projection query on primary timestamp, the selectivity function needs to be present.
if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
bool hasSelectivity = false;
for(int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
SSqlExpr* pEx = tscSqlExprGet(pCmd, j);
if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) {
hasSelectivity = true;
break;
}
}
if (hasSelectivity) {
continue;
}
}
if (pExpr->functionId == TSDB_FUNC_PRJ || pExpr->functionId == TSDB_FUNC_DIFF || if (pExpr->functionId == TSDB_FUNC_PRJ || pExpr->functionId == TSDB_FUNC_DIFF ||
pExpr->functionId == TSDB_FUNC_ARITHM) { pExpr->functionId == TSDB_FUNC_ARITHM) {
isProjectionFunction = true; isProjectionFunction = true;
} }
} }
if (isProjectionFunction) { if (isProjectionFunction) {
setErrMsg(pCmd, msg); setErrMsg(pCmd, msg1);
} }
return isProjectionFunction == true ? TSDB_CODE_INVALID_SQL : TSDB_CODE_SUCCESS; return isProjectionFunction == true ? TSDB_CODE_INVALID_SQL : TSDB_CODE_SUCCESS;
@ -5164,8 +5130,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
bool queryOnTags = false; bool queryOnTags = false;
int32_t ret = tscQueryOnlyMetricTags(pCmd, &queryOnTags); if (tscQueryOnlyMetricTags(pCmd, &queryOnTags) != TSDB_CODE_SUCCESS) {
if (ret != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
@ -5382,8 +5347,8 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
} }
} }
int16_t resType = 0; int16_t resType = 0;
int16_t resBytes = 0; int16_t resBytes = 0;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
@ -5398,6 +5363,27 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
} }
} }
static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) {
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
if (pExpr->functionId == TSDB_FUNC_PRJ) {
bool qualifiedCol = false;
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) {
qualifiedCol = true;
pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value
pExpr->numOfParams = 1;
break;
}
}
assert(qualifiedCol);
}
}
}
static bool tagColumnInGroupby(SSqlGroupbyExpr* pGroupbyExpr, int16_t columnId) { static bool tagColumnInGroupby(SSqlGroupbyExpr* pGroupbyExpr, int16_t columnId) {
for (int32_t j = 0; j < pGroupbyExpr->numOfGroupCols; ++j) { for (int32_t j = 0; j < pGroupbyExpr->numOfGroupCols; ++j) {
if (columnId == pGroupbyExpr->columnInfo[j].colId && pGroupbyExpr->columnInfo[j].flag == TSDB_COL_TAG) { if (columnId == pGroupbyExpr->columnInfo[j].colId && pGroupbyExpr->columnInfo[j].flag == TSDB_COL_TAG) {
@ -5462,9 +5448,10 @@ static void updateTagPrjFunction(SSqlCmd* pCmd) {
static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
const char* msg1 = "only one selectivity function allowed in presence of tags function"; const char* msg1 = "only one selectivity function allowed in presence of tags function";
const char* msg2 = "functions not allowed"; const char* msg2 = "functions not allowed";
const char* msg3 = "aggregation function should not be mixed up with projection";
bool tagColExists = false; bool tagColExists = false;
int16_t numOfTimestamp = 0; // primary timestamp column int16_t numOfTimestamp = 0; // primary timestamp column
int16_t numOfSelectivity = 0; int16_t numOfSelectivity = 0;
int16_t numOfAggregation = 0; int16_t numOfAggregation = 0;
@ -5477,23 +5464,23 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
} }
} }
if (tagColExists) { // check if the selectivity function exists for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { int16_t functionId = tscSqlExprGet(pCmd, i)->functionId;
int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS) {
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS) { continue;
continue;
}
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
numOfSelectivity++;
} else {
numOfAggregation++;
}
} }
if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
numOfSelectivity++;
} else {
numOfAggregation++;
}
}
if (tagColExists) { // check if the selectivity function exists
// When the tag projection function on tag column that is not in the group by clause, aggregation function and // When the tag projection function on tag column that is not in the group by clause, aggregation function and
// selectivity function exist in select clause is not allowed. // selectivity function exist in select clause is not allowed.
if(numOfAggregation > 0) { if (numOfAggregation > 0) {
setErrMsg(pCmd, msg1); setErrMsg(pCmd, msg1);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
@ -5503,6 +5490,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
*/ */
if (numOfSelectivity == 1) { if (numOfSelectivity == 1) {
doUpdateSqlFunctionForTagPrj(pCmd); doUpdateSqlFunctionForTagPrj(pCmd);
doUpdateSqlFunctionForColPrj(pCmd);
} else if (numOfSelectivity > 1) { } else if (numOfSelectivity > 1) {
/* /*
* If more than one selectivity functions exist, all the selectivity functions must be last_row. * If more than one selectivity functions exist, all the selectivity functions must be last_row.
@ -5521,6 +5509,20 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
} }
doUpdateSqlFunctionForTagPrj(pCmd); doUpdateSqlFunctionForTagPrj(pCmd);
doUpdateSqlFunctionForColPrj(pCmd);
}
} else {
if ((pCmd->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) == TSDB_QUERY_TYPE_PROJECTION_QUERY) {
if (numOfAggregation > 0 && pCmd->groupbyExpr.numOfGroupCols == 0) {
setErrMsg(pCmd, msg3);
return TSDB_CODE_INVALID_SQL;
}
if (numOfAggregation > 0 || numOfSelectivity > 0) {
// clear the projection type flag
pCmd->type &= (~TSDB_QUERY_TYPE_PROJECTION_QUERY);
doUpdateSqlFunctionForColPrj(pCmd);
}
} }
} }
@ -5598,14 +5600,14 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
const char* msg2 = "interval not allowed in group by normal column"; const char* msg2 = "interval not allowed in group by normal column";
const char* msg3 = "group by not allowed on projection query"; const char* msg3 = "group by not allowed on projection query";
const char* msg4 = "tags retrieve not compatible with group by"; const char* msg4 = "tags retrieve not compatible with group by";
const char* msg5 = "retrieve tags not compatible with group by "; const char* msg5 = "retrieve tags not compatible with group by or interval query";
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
// only retrieve tags, group by is not supportted // only retrieve tags, group by is not supportted
if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) {
if (pCmd->groupbyExpr.numOfGroupCols > 0) { if (pCmd->groupbyExpr.numOfGroupCols > 0 || pCmd->nAggTimeInterval > 0) {
setErrMsg(pCmd, msg5); setErrMsg(pCmd, msg5);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} else { } else {
@ -5634,7 +5636,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
* group by normal columns. * group by normal columns.
* Check if the column projection is identical to the group by column or not * Check if the column projection is identical to the group by column or not
*/ */
if (functId == TSDB_FUNC_PRJ) { if (functId == TSDB_FUNC_PRJ && pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
bool qualified = false; bool qualified = false;
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[j]; SColIndexEx* pColIndex = &pCmd->groupbyExpr.columnInfo[j];
@ -5650,7 +5652,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
} }
if (IS_MULTIOUTPUT(aAggs[functId].nStatus) && functId != TSDB_FUNC_TOP && functId != TSDB_FUNC_BOTTOM && if (IS_MULTIOUTPUT(aAggs[functId].nStatus) && functId != TSDB_FUNC_TOP && functId != TSDB_FUNC_BOTTOM &&
functId != TSDB_FUNC_TAGPRJ) { functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) {
setErrMsg(pCmd, msg1); setErrMsg(pCmd, msg1);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
@ -5678,6 +5680,8 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
setErrMsg(pCmd, msg3); setErrMsg(pCmd, msg3);
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS;
} else { } else {
return checkUpdateTagPrjFunctions(pCmd); return checkUpdateTagPrjFunctions(pCmd);
} }

View File

@ -13,13 +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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include "os.h" #include "os.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "tsql.h" #include "tsql.h"

View File

@ -13,10 +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 <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tschemautil.h" #include "tschemautil.h"

View File

@ -13,13 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <tsclient.h>
#include "tlosertree.h" #include "os.h"
#include "tlosertree.h" #include "tlosertree.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
#include "tscUtil.h" #include "tscUtil.h"
@ -437,11 +432,10 @@ void tscDestroyLocalReducer(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
// there is no more result, so we release all allocated resource // there is no more result, so we release all allocated resource
SLocalReducer *pLocalReducer = SLocalReducer *pLocalReducer = (SLocalReducer*)atomic_exchange_ptr(&pRes->pLocalReducer, NULL);
(SLocalReducer *)__sync_val_compare_and_swap_64(&pRes->pLocalReducer, pRes->pLocalReducer, 0);
if (pLocalReducer != NULL) { if (pLocalReducer != NULL) {
int32_t status = 0; int32_t status = 0;
while ((status = __sync_val_compare_and_swap_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, while ((status = atomic_val_compare_exchange_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY,
TSC_LOCALREDUCE_TOBE_FREED)) == TSC_LOCALREDUCE_IN_PROGRESS) { TSC_LOCALREDUCE_TOBE_FREED)) == TSC_LOCALREDUCE_IN_PROGRESS) {
taosMsleep(100); taosMsleep(100);
tscTrace("%p waiting for delete procedure, status: %d", pSql, status); tscTrace("%p waiting for delete procedure, status: %d", pSql, status);
@ -1333,7 +1327,7 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
// set the data merge in progress // set the data merge in progress
int32_t prevStatus = int32_t prevStatus =
__sync_val_compare_and_swap_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, TSC_LOCALREDUCE_IN_PROGRESS); atomic_val_compare_exchange_32(&pLocalReducer->status, TSC_LOCALREDUCE_READY, TSC_LOCALREDUCE_IN_PROGRESS);
if (prevStatus != TSC_LOCALREDUCE_READY || pLocalReducer == NULL) { if (prevStatus != TSC_LOCALREDUCE_READY || pLocalReducer == NULL) {
assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED); // it is in tscDestroyLocalReducer function already assert(prevStatus == TSC_LOCALREDUCE_TOBE_FREED); // it is in tscDestroyLocalReducer function already
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;

View File

@ -13,12 +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 <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include "os.h" #include "os.h"
#include "tcache.h" #include "tcache.h"
#include "trpc.h" #include "trpc.h"
@ -140,6 +134,7 @@ 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
@ -169,10 +164,11 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) {
connInit.spi = 1; connInit.spi = 1;
connInit.encrypt = 0; connInit.encrypt = 0;
connInit.secret = pSql->pTscObj->pass; connInit.secret = pSql->pTscObj->pass;
#ifdef CLUSTER #ifdef CLUSTER
connInit.peerIp = tscMgmtIpList.ipstr[pSql->index]; connInit.peerIp = tscMgmtIpList.ipstr[pSql->index];
#else #else
connInit.peerIp = tsServerIpStr; connInit.peerIp = tsServerIpStr;
#endif #endif
thandle = taosOpenRpcConn(&connInit, pCode); thandle = taosOpenRpcConn(&connInit, pCode);
} }
@ -228,7 +224,7 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
(pSql->index) = (pSql->index + 1) % TSDB_VNODES_SUPPORT; (pSql->index) = (pSql->index + 1) % TSDB_VNODES_SUPPORT;
continue; continue;
} }
*pCode = 0; *pCode = TSDB_CODE_SUCCESS;
void *thandle = void *thandle =
taosGetConnFromCache(tscConnCache, pVPeersDesc[pSql->index].ip, pVPeersDesc[pSql->index].vnode, pTscObj->user); taosGetConnFromCache(tscConnCache, pVPeersDesc[pSql->index].ip, pVPeersDesc[pSql->index].vnode, pTscObj->user);
@ -254,7 +250,7 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
pSql->thandle = thandle; pSql->thandle = thandle;
pSql->ip = pVPeersDesc[pSql->index].ip; pSql->ip = pVPeersDesc[pSql->index].ip;
pSql->vnode = pVPeersDesc[pSql->index].vnode; pSql->vnode = pVPeersDesc[pSql->index].vnode;
tscTrace("%p vnode:%d ip:0x%x index:%d is picked up, pConn:%p", pSql, pVPeersDesc[pSql->index].vnode, tscTrace("%p vnode:%d ip:%p index:%d is picked up, pConn:%p", pSql, pVPeersDesc[pSql->index].vnode,
pVPeersDesc[pSql->index].ip, pSql->index, pSql->thandle); pVPeersDesc[pSql->index].ip, pSql->index, pSql->thandle);
#else #else
*pCode = 0; *pCode = 0;
@ -284,6 +280,15 @@ void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) {
break; break;
} }
// 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);
}
} }
int tscSendMsgToServer(SSqlObj *pSql) { int tscSendMsgToServer(SSqlObj *pSql) {
@ -319,11 +324,19 @@ int tscSendMsgToServer(SSqlObj *pSql) {
char *pStart = taosBuildReqHeader(pSql->thandle, pSql->cmd.msgType, buf); char *pStart = taosBuildReqHeader(pSql->thandle, pSql->cmd.msgType, buf);
if (pStart) { if (pStart) {
/*
* this SQL object may be released by other thread due to the completion of this query even before the log
* is dumped to log file. So the signature needs to be kept in a local variable.
*/
uint64_t signature = (uint64_t) pSql->signature;
if (tscUpdateVnodeMsg[pSql->cmd.command]) (*tscUpdateVnodeMsg[pSql->cmd.command])(pSql, buf); if (tscUpdateVnodeMsg[pSql->cmd.command]) (*tscUpdateVnodeMsg[pSql->cmd.command])(pSql, buf);
int ret = taosSendMsgToPeerH(pSql->thandle, pStart, pSql->cmd.payloadLen, pSql);
if (ret >= 0) code = 0; int ret = taosSendMsgToPeerH(pSql->thandle, pStart, pSql->cmd.payloadLen, pSql);
tscTrace("%p send msg ret:%d code:%d sig:%p", pSql, ret, code, pSql->signature); if (ret >= 0) {
code = 0;
}
tscTrace("%p send msg ret:%d code:%d sig:%p", pSql, ret, code, signature);
} }
} }
@ -391,14 +404,11 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
// for single node situation, do NOT try next index // for single node situation, do NOT try next index
#endif #endif
pSql->thandle = NULL; pSql->thandle = NULL;
// todo taos_stop_query() in async model // todo taos_stop_query() in async model
/* /*
* in case of * in case of
* 1. query cancelled(pRes->code != TSDB_CODE_QUERY_CANCELLED), do NOT re-issue the * 1. query cancelled(pRes->code != TSDB_CODE_QUERY_CANCELLED), do NOT re-issue the request to server.
* request to server. * 2. retrieve, do NOT re-issue the retrieve request since the qhandle may have been released by server
* 2. retrieve, do NOT re-issue the retrieve request since the qhandle may
* have been released by server
*/ */
if (pCmd->command != TSDB_SQL_FETCH && pCmd->command != TSDB_SQL_RETRIEVE && pCmd->command != TSDB_SQL_KILL_QUERY && if (pCmd->command != TSDB_SQL_FETCH && pCmd->command != TSDB_SQL_RETRIEVE && pCmd->command != TSDB_SQL_KILL_QUERY &&
pRes->code != TSDB_CODE_QUERY_CANCELLED) { pRes->code != TSDB_CODE_QUERY_CANCELLED) {
@ -424,8 +434,11 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
} }
} }
} else { } else {
uint16_t rspCode = pMsg->content[0];
#ifdef CLUSTER #ifdef CLUSTER
if (pMsg->content[0] == TSDB_CODE_REDIRECT) {
if (rspCode == TSDB_CODE_REDIRECT) {
tscTrace("%p it shall be redirected!", pSql); tscTrace("%p it shall be redirected!", pSql);
taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user);
pSql->thandle = NULL; pSql->thandle = NULL;
@ -439,28 +452,23 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
code = tscSendMsgToServer(pSql); code = tscSendMsgToServer(pSql);
if (code == 0) return pSql; if (code == 0) return pSql;
msg = NULL; msg = NULL;
} else if (pMsg->content[0] == TSDB_CODE_NOT_ACTIVE_SESSION || pMsg->content[0] == TSDB_CODE_NETWORK_UNAVAIL || } else if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID ||
pMsg->content[0] == TSDB_CODE_INVALID_SESSION_ID) { rspCode == TSDB_CODE_INVALID_VNODE_ID || rspCode == TSDB_CODE_NOT_ACTIVE_VNODE ||
rspCode == TSDB_CODE_NETWORK_UNAVAIL) {
#else #else
if (pMsg->content[0] == TSDB_CODE_NOT_ACTIVE_SESSION || pMsg->content[0] == TSDB_CODE_NETWORK_UNAVAIL || if (rspCode == TSDB_CODE_NOT_ACTIVE_TABLE || rspCode == TSDB_CODE_INVALID_TABLE_ID ||
pMsg->content[0] == TSDB_CODE_INVALID_SESSION_ID) { rspCode == TSDB_CODE_INVALID_VNODE_ID || rspCode == TSDB_CODE_NOT_ACTIVE_VNODE ||
rspCode == TSDB_CODE_NETWORK_UNAVAIL) {
#endif #endif
pSql->thandle = NULL; pSql->thandle = NULL;
taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user);
if (pMeterMetaInfo != NULL && UTIL_METER_IS_METRIC(pMeterMetaInfo) && if ((pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_SELECT) &&
pMsg->content[0] == TSDB_CODE_NOT_ACTIVE_SESSION) { (rspCode == TSDB_CODE_INVALID_TABLE_ID || rspCode == TSDB_CODE_INVALID_VNODE_ID)) {
/* /*
* for metric query, in case of any meter missing during query, sub-query of metric query will failed, * In case of the insert/select operations, the invalid table(vnode) id means
* causing metric query failed, and return TSDB_CODE_METRICMETA_EXPIRED code to app * the submit/query msg is invalid, renew meter meta will not help to fix this problem,
*/ * so return the invalid_query_msg to client directly.
tscTrace("%p invalid meters id cause metric query failed, code:%d", pSql, pMsg->content[0]);
code = TSDB_CODE_METRICMETA_EXPIRED;
} else if ((pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_SELECT) &&
pMsg->content[0] == TSDB_CODE_INVALID_SESSION_ID) {
/*
* session id is invalid(e.g., less than 0 or larger than maximum session per
* vnode) in submit/query msg, no retry
*/ */
code = TSDB_CODE_INVALID_QUERY_MSG; code = TSDB_CODE_INVALID_QUERY_MSG;
} else if (pCmd->command == TSDB_SQL_CONNECT) { } else if (pCmd->command == TSDB_SQL_CONNECT) {
@ -468,8 +476,10 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
} else if (pCmd->command == TSDB_SQL_HB) { } else if (pCmd->command == TSDB_SQL_HB) {
code = TSDB_CODE_NOT_READY; code = TSDB_CODE_NOT_READY;
} else { } else {
tscTrace("%p it shall renew meter meta, code:%d", pSql, pMsg->content[0]); tscTrace("%p it shall renew meter meta, code:%d", pSql, rspCode);
pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; pSql->maxRetry = TSDB_VNODES_SUPPORT * 2;
pSql->res.code = (uint8_t) rspCode; // keep the previous error code
code = tscRenewMeterMeta(pSql, pMeterMetaInfo->name); code = tscRenewMeterMeta(pSql, pMeterMetaInfo->name);
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return pSql; if (code == TSDB_CODE_ACTION_IN_PROGRESS) return pSql;
@ -482,7 +492,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
msg = NULL; msg = NULL;
} else { // for other error set and return to invoker } else { // for other error set and return to invoker
code = pMsg->content[0]; code = rspCode;
} }
} }
@ -568,7 +578,7 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) {
void *taosres = tscKeepConn[command] ? pSql : NULL; void *taosres = tscKeepConn[command] ? pSql : NULL;
code = pRes->code ? -pRes->code : pRes->numOfRows; code = pRes->code ? -pRes->code : pRes->numOfRows;
tscTrace("%p Async SQL result:%d taosres:%p", pSql, code, taosres); tscTrace("%p Async SQL result:%d res:%p", pSql, code, taosres);
/* /*
* Whether to free sqlObj or not should be decided before call the user defined function, since this SqlObj * Whether to free sqlObj or not should be decided before call the user defined function, since this SqlObj
@ -729,9 +739,16 @@ int tscProcessSql(SSqlObj *pSql) {
#else #else
pSql->maxRetry = 2; pSql->maxRetry = 2;
#endif #endif
// the pMeterMetaInfo cannot be NULL
if (pMeterMetaInfo == NULL) {
pSql->res.code = TSDB_CODE_OTHERS;
return pSql->res.code;
}
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) { if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
pSql->index = pMeterMetaInfo->pMeterMeta->index; pSql->index = pMeterMetaInfo->pMeterMeta->index;
} else { // it must be the parent SSqlObj for metric query } else { // it must be the parent SSqlObj for super table query
if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) != 0) { if ((pSql->cmd.type & TSDB_QUERY_TYPE_SUBQUERY) != 0) {
int32_t idx = pSql->cmd.vnodeIdx; int32_t idx = pSql->cmd.vnodeIdx;
SVnodeSidList *pSidList = tscGetVnodeSidList(pMeterMetaInfo->pMetricMeta, idx); SVnodeSidList *pSidList = tscGetVnodeSidList(pMeterMetaInfo->pMetricMeta, idx);
@ -1029,13 +1046,13 @@ static void tscHandleSubRetrievalError(SRetrieveSupport *trsupport, SSqlObj *pSq
tscProcessSql(pNew); tscProcessSql(pNew);
return; return;
} else { // reach the maximum retry count, abort } else { // reach the maximum retry count, abort
__sync_val_compare_and_swap_32(&trsupport->pState->code, TSDB_CODE_SUCCESS, numOfRows); atomic_val_compare_exchange_32(&trsupport->pState->code, TSDB_CODE_SUCCESS, numOfRows);
tscError("%p sub:%p retrieve failed,code:%d,orderOfSub:%d failed.no more retry,set global code:%d", pPObj, pSql, tscError("%p sub:%p retrieve failed,code:%d,orderOfSub:%d failed.no more retry,set global code:%d", pPObj, pSql,
numOfRows, idx, trsupport->pState->code); numOfRows, idx, trsupport->pState->code);
} }
} }
if (__sync_add_and_fetch_32(&trsupport->pState->numOfCompleted, 1) < trsupport->pState->numOfTotal) { if (atomic_add_fetch_32(&trsupport->pState->numOfCompleted, 1) < trsupport->pState->numOfTotal) {
return tscFreeSubSqlObj(trsupport, pSql); return tscFreeSubSqlObj(trsupport, pSql);
} }
@ -1101,7 +1118,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
if (numOfRows > 0) { if (numOfRows > 0) {
assert(pRes->numOfRows == numOfRows); assert(pRes->numOfRows == numOfRows);
__sync_add_and_fetch_64(&trsupport->pState->numOfRetrievedRows, numOfRows); atomic_add_fetch_64(&trsupport->pState->numOfRetrievedRows, numOfRows);
tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%u,vid:%d,orderOfSub:%d", pPObj, pSql, tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%u,vid:%d,orderOfSub:%d", pPObj, pSql,
pRes->numOfRows, trsupport->pState->numOfRetrievedRows, pSvd->ip, pSvd->vnode, idx); pRes->numOfRows, trsupport->pState->numOfRetrievedRows, pSvd->ip, pSvd->vnode, idx);
@ -1160,7 +1177,7 @@ void tscRetrieveFromVnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
return tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); return tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE);
} }
if (__sync_add_and_fetch_32(&trsupport->pState->numOfCompleted, 1) < trsupport->pState->numOfTotal) { if (atomic_add_fetch_32(&trsupport->pState->numOfCompleted, 1) < trsupport->pState->numOfTotal) {
return tscFreeSubSqlObj(trsupport, pSql); return tscFreeSubSqlObj(trsupport, pSql);
} }
@ -1289,7 +1306,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
if (trsupport->numOfRetry++ >= MAX_NUM_OF_SUBQUERY_RETRY) { if (trsupport->numOfRetry++ >= MAX_NUM_OF_SUBQUERY_RETRY) {
tscTrace("%p sub:%p reach the max retry count,set global code:%d", trsupport->pParentSqlObj, pSql, code); tscTrace("%p sub:%p reach the max retry count,set global code:%d", trsupport->pParentSqlObj, pSql, code);
__sync_val_compare_and_swap_32(&trsupport->pState->code, 0, code); atomic_val_compare_exchange_32(&trsupport->pState->code, 0, code);
} else { // does not reach the maximum retry count, go on } else { // does not reach the maximum retry count, go on
tscTrace("%p sub:%p failed code:%d, retry:%d", trsupport->pParentSqlObj, pSql, code, trsupport->numOfRetry); tscTrace("%p sub:%p failed code:%d, retry:%d", trsupport->pParentSqlObj, pSql, code, trsupport->numOfRetry);
@ -1338,7 +1355,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql) {
*((uint64_t *)pMsg) = pSql->res.qhandle; *((uint64_t *)pMsg) = pSql->res.qhandle;
pMsg += sizeof(pSql->res.qhandle); pMsg += sizeof(pSql->res.qhandle);
*pMsg = htons(pSql->cmd.type); *((uint16_t*)pMsg) = htons(pSql->cmd.type);
pMsg += sizeof(pSql->cmd.type); pMsg += sizeof(pSql->cmd.type);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
@ -2466,10 +2483,10 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
*((uint64_t *)pMsg) = pSql->res.qhandle; *((uint64_t *) pMsg) = pSql->res.qhandle;
pMsg += sizeof(pSql->res.qhandle); pMsg += sizeof(pSql->res.qhandle);
*pMsg = htons(pCmd->type); *((uint16_t*) pMsg) = htons(pCmd->type);
pMsg += sizeof(pCmd->type); pMsg += sizeof(pCmd->type);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
@ -2848,7 +2865,7 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql) {
return msgLen; return msgLen;
} }
int tscEstimateBuildHeartBeatMsgLength(SSqlObj *pSql) { int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) {
int size = 0; int size = 0;
STscObj *pObj = pSql->pTscObj; STscObj *pObj = pSql->pTscObj;
@ -2881,7 +2898,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql) {
pthread_mutex_lock(&pObj->mutex); pthread_mutex_lock(&pObj->mutex);
size = tscEstimateBuildHeartBeatMsgLength(pSql); size = tscEstimateHeartBeatMsgLength(pSql);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for heartbeat msg", pSql); tscError("%p failed to malloc for heartbeat msg", pSql);
return -1; return -1;
@ -3456,7 +3473,13 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
tscSetResultPointer(pCmd, pRes); tscSetResultPointer(pCmd, pRes);
pRes->row = 0; pRes->row = 0;
if (pRes->numOfRows == 0 && !(tscProjectionQueryOnMetric(pCmd) && pRes->offset > 0)) { /**
* If the query result is exhausted, or current query is to free resource at server side,
* the connection will be recycled.
*/
if ((pRes->numOfRows == 0 && !(tscProjectionQueryOnMetric(pCmd) && pRes->offset > 0)) ||
((pCmd->type & TSDB_QUERY_TYPE_FREE_RESOURCE) == TSDB_QUERY_TYPE_FREE_RESOURCE)) {
tscTrace("%p no result or free resource, recycle connection", pSql);
taosAddConnIntoCache(tscConnCache, pSql->thandle, pSql->ip, pSql->vnode, pObj->user); taosAddConnIntoCache(tscConnCache, pSql->thandle, pSql->ip, pSql->vnode, pObj->user);
pSql->thandle = NULL; pSql->thandle = NULL;
} else { } else {
@ -3613,7 +3636,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
code = tscDoGetMeterMeta(pSql, meterId, 0); // todo ?? code = tscDoGetMeterMeta(pSql, meterId, 0); // todo ??
} else { } else {
tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%d, addr:%p", pSql, tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%lld, addr:%p", pSql,
pMeterMetaInfo->pMeterMeta->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid, pMeterMetaInfo->pMeterMeta->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid,
pMeterMetaInfo->pMeterMeta); pMeterMetaInfo->pMeterMeta);
} }
@ -3770,7 +3793,7 @@ void tscInitMsgs() {
tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp; tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiMeterMetaRsp;
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromMgmt; 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_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;

View File

@ -13,9 +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 <stdio.h>
#include <stdlib.h>
#include "os.h" #include "os.h"
#include "tcache.h" #include "tcache.h"
#include "tlog.h" #include "tlog.h"
@ -650,11 +647,8 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
pCmd->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal; pCmd->limit.limit = pSql->cmd.globalLimit - pRes->numOfTotal;
pCmd->limit.offset = pRes->offset; pCmd->limit.offset = pRes->offset;
#ifdef CLUSTER
if ((++pSql->cmd.vnodeIdx) <= pMeterMetaInfo->pMetricMeta->numOfVnodes) {
#else
if ((++pSql->cmd.vnodeIdx) < pMeterMetaInfo->pMetricMeta->numOfVnodes) { if ((++pSql->cmd.vnodeIdx) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
#endif
pSql->cmd.command = TSDB_SQL_SELECT; pSql->cmd.command = TSDB_SQL_SELECT;
assert(pSql->fp == NULL); assert(pSql->fp == NULL);
tscProcessSql(pSql); tscProcessSql(pSql);

View File

@ -546,7 +546,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
void taos_close_stream(TAOS_STREAM *handle) { void taos_close_stream(TAOS_STREAM *handle) {
SSqlStream *pStream = (SSqlStream *)handle; SSqlStream *pStream = (SSqlStream *)handle;
SSqlObj *pSql = (SSqlObj *)__sync_val_compare_and_swap_64(&pStream->pSql, pStream->pSql, 0); SSqlObj *pSql = (SSqlObj *)atomic_exchange_ptr(&pStream->pSql, 0);
if (pSql == NULL) { if (pSql == NULL) {
return; return;
} }

View File

@ -13,7 +13,7 @@
* 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 <signal.h> #include "os.h"
#include "shash.h" #include "shash.h"
#include "taos.h" #include "taos.h"

View File

@ -13,10 +13,7 @@
* 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 <assert.h> #include "os.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "tscSyntaxtreefunction.h" #include "tscSyntaxtreefunction.h"
#include "tsql.h" #include "tsql.h"

View File

@ -13,15 +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 <locale.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tcache.h" #include "tcache.h"
@ -92,6 +83,8 @@ void taos_init_imp() {
tscTrace("Local IP address is:%s", tsLocalIp); tscTrace("Local IP address is:%s", tsLocalIp);
} }
taosSetCoreDump();
#ifdef CLUSTER #ifdef CLUSTER
tscMgmtIpList.numOfIps = 2; tscMgmtIpList.numOfIps = 2;
strcpy(tscMgmtIpList.ipstr[0], tsMasterIp); strcpy(tscMgmtIpList.ipstr[0], tsMasterIp);
@ -185,57 +178,51 @@ void taos_init_imp() {
tscConnCache = taosOpenConnCache(tsMaxMeterConnections * 2, taosCloseRpcConn, tscTmr, tsShellActivityTimer * 1000); tscConnCache = taosOpenConnCache(tsMaxMeterConnections * 2, taosCloseRpcConn, tscTmr, tsShellActivityTimer * 1000);
initialized = 1; initialized = 1;
tscTrace("taos client is initialized successfully"); tscTrace("client is initialized successfully");
tsInsertHeadSize = tsRpcHeadSize + sizeof(SShellSubmitMsg); tsInsertHeadSize = tsRpcHeadSize + sizeof(SShellSubmitMsg);
} }
void taos_init() { pthread_once(&tscinit, taos_init_imp); } void taos_init() { pthread_once(&tscinit, taos_init_imp); }
int taos_options(TSDB_OPTION option, const void *arg, ...) { static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
char * pStr = NULL; SGlobalConfig *cfg = NULL;
SGlobalConfig *cfg_configDir = tsGetConfigOption("configDir");
SGlobalConfig *cfg_activetimer = tsGetConfigOption("shellActivityTimer");
SGlobalConfig *cfg_locale = tsGetConfigOption("locale");
SGlobalConfig *cfg_charset = tsGetConfigOption("charset");
SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone");
SGlobalConfig *cfg_socket = tsGetConfigOption("sockettype");
switch (option) { switch (option) {
case TSDB_OPTION_CONFIGDIR: case TSDB_OPTION_CONFIGDIR:
pStr = (char *)arg; cfg = tsGetConfigOption("configDir");
if (cfg_configDir && cfg_configDir->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
strncpy(configDir, pStr, TSDB_FILENAME_LEN); strncpy(configDir, pStr, TSDB_FILENAME_LEN);
cfg_configDir->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
tscPrint("set config file directory:%s", pStr); tscPrint("set config file directory:%s", pStr);
} else { } else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg_configDir->option, pStr, tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr,
tsCfgStatusStr[cfg_configDir->cfgStatus], (char *)cfg_configDir->ptr); tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
} }
break; break;
case TSDB_OPTION_SHELL_ACTIVITY_TIMER: case TSDB_OPTION_SHELL_ACTIVITY_TIMER:
if (cfg_activetimer && cfg_activetimer->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { cfg = tsGetConfigOption("shellActivityTimer");
tsShellActivityTimer = atoi((char *)arg); if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
tsShellActivityTimer = atoi(pStr);
if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; if (tsShellActivityTimer < 1) tsShellActivityTimer = 1;
if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600;
cfg_activetimer->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
tscPrint("set shellActivityTimer:%d", tsShellActivityTimer); tscPrint("set shellActivityTimer:%d", tsShellActivityTimer);
} else { } else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg_activetimer->option, pStr, tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr,
tsCfgStatusStr[cfg_activetimer->cfgStatus], (int32_t *)cfg_activetimer->ptr); tsCfgStatusStr[cfg->cfgStatus], (int32_t *)cfg->ptr);
} }
break; break;
case TSDB_OPTION_LOCALE: { // set locale case TSDB_OPTION_LOCALE: { // set locale
pStr = (char *)arg; cfg = tsGetConfigOption("locale");
size_t len = strlen(pStr); size_t len = strlen(pStr);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscPrint("Invalid locale:%s, use default", pStr); tscPrint("Invalid locale:%s, use default", pStr);
return -1; return -1;
} }
if (cfg_locale && cfg_charset && cfg_locale->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg && cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
char sep = '.'; char sep = '.';
if (strlen(tsLocale) == 0) { // locale does not set yet if (strlen(tsLocale) == 0) { // locale does not set yet
@ -248,7 +235,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
if (locale != NULL) { if (locale != NULL) {
tscPrint("locale set, prev locale:%s, new locale:%s", tsLocale, locale); tscPrint("locale set, prev locale:%s, new locale:%s", tsLocale, locale);
cfg_locale->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
} else { // set the user-specified localed failed, use default LC_CTYPE as current locale } else { // set the user-specified localed failed, use default LC_CTYPE as current locale
locale = setlocale(LC_CTYPE, tsLocale); locale = setlocale(LC_CTYPE, tsLocale);
tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale); tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale);
@ -270,7 +257,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
} }
strncpy(tsCharset, charset, tListLen(tsCharset)); strncpy(tsCharset, charset, tListLen(tsCharset));
cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
} else { } else {
tscPrint("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); tscPrint("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset);
@ -281,23 +268,22 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
tscPrint("charset remains:%s", tsCharset); tscPrint("charset remains:%s", tsCharset);
} }
} else { } else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg_locale->option, pStr, tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr,
tsCfgStatusStr[cfg_locale->cfgStatus], (char *)cfg_locale->ptr); tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
} }
break; break;
} }
case TSDB_OPTION_CHARSET: { case TSDB_OPTION_CHARSET: {
/* set charset will override the value of charset, assigned during system locale changed */ /* set charset will override the value of charset, assigned during system locale changed */
pStr = (char *)arg; cfg = tsGetConfigOption("charset");
size_t len = strlen(pStr); size_t len = strlen(pStr);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscPrint("failed to set charset:%s", pStr); tscPrint("failed to set charset:%s", pStr);
return -1; return -1;
} }
if (cfg_charset && cfg_charset->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
if (taosValidateEncodec(pStr)) { if (taosValidateEncodec(pStr)) {
if (strlen(tsCharset) == 0) { if (strlen(tsCharset) == 0) {
tscPrint("charset is set:%s", pStr); tscPrint("charset is set:%s", pStr);
@ -306,40 +292,41 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
} }
strncpy(tsCharset, pStr, tListLen(tsCharset)); strncpy(tsCharset, pStr, tListLen(tsCharset));
cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
} else { } else {
tscPrint("charset:%s not valid", pStr); tscPrint("charset:%s not valid", pStr);
} }
} else { } else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg_charset->option, pStr, tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr,
tsCfgStatusStr[cfg_charset->cfgStatus], (char *)cfg_charset->ptr); tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
} }
break; break;
} }
case TSDB_OPTION_TIMEZONE: case TSDB_OPTION_TIMEZONE:
pStr = (char *)arg; cfg = tsGetConfigOption("timezone");
if (cfg_timezone && cfg_timezone->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
strcpy(tsTimezone, pStr); strcpy(tsTimezone, pStr);
tsSetTimeZone(); tsSetTimeZone();
cfg_timezone->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr); tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr);
} else { } else {
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg_timezone->option, pStr, tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr,
tsCfgStatusStr[cfg_timezone->cfgStatus], (char *)cfg_timezone->ptr); tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
} }
break; break;
case TSDB_OPTION_SOCKET_TYPE: case TSDB_OPTION_SOCKET_TYPE:
if (cfg_socket && cfg_socket->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { cfg = tsGetConfigOption("sockettype");
if (strcasecmp(arg, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(arg, TAOS_SOCKET_TYPE_NAME_TCP) != 0) { if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
if (strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_TCP) != 0) {
tscError("only 'tcp' or 'udp' allowed for configuring the socket type"); tscError("only 'tcp' or 'udp' allowed for configuring the socket type");
return -1; return -1;
} }
strncpy(tsSocketType, arg, tListLen(tsSocketType)); strncpy(tsSocketType, pStr, tListLen(tsSocketType));
cfg_socket->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
tscPrint("socket type is set:%s", tsSocketType); tscPrint("socket type is set:%s", tsSocketType);
} }
break; break;
@ -351,3 +338,20 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
return 0; return 0;
} }
int taos_options(TSDB_OPTION option, const void *arg, ...) {
static int32_t lock = 0;
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
if (i % 1000 == 0) {
tscPrint("haven't acquire lock after spin %d times.", i);
sched_yield();
}
}
int ret = taos_options_imp(option, (const char*)arg);
atomic_store_32(&lock, 0);
return ret;
}

View File

@ -13,10 +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 <assert.h>
#include <math.h>
#include <time.h>
#include "os.h" #include "os.h"
#include "ihash.h" #include "ihash.h"
#include "taosmsg.h" #include "taosmsg.h"
@ -146,7 +142,6 @@ bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd) {
return false; return false;
} }
void tscGetDBInfoFromMeterId(char* meterId, char* db) { void tscGetDBInfoFromMeterId(char* meterId, char* db) {
char* st = strstr(meterId, TS_PATH_DELIMITER); char* st = strstr(meterId, TS_PATH_DELIMITER);
if (st != NULL) { if (st != NULL) {
@ -269,7 +264,7 @@ bool tscIsPointInterpQuery(SSqlCmd* pCmd) {
} }
bool tscIsTWAQuery(SSqlCmd* pCmd) { bool tscIsTWAQuery(SSqlCmd* pCmd) {
for(int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (pExpr == NULL) { if (pExpr == NULL) {
continue; continue;
@ -454,7 +449,8 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
tfree(pDataBlock); tfree(pDataBlock);
} }
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes, uint32_t offset) { SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes,
uint32_t offset) {
uint32_t needed = pDataBlock->numOfParams + 1; uint32_t needed = pDataBlock->numOfParams + 1;
if (needed > pDataBlock->numOfAllocedParams) { if (needed > pDataBlock->numOfAllocedParams) {
needed *= 2; needed *= 2;
@ -494,13 +490,13 @@ SDataBlockList* tscCreateBlockArrayList() {
return pDataBlockArrayList; return pDataBlockArrayList;
} }
void tscAppendDataBlock(SDataBlockList *pList, STableDataBlocks *pBlocks) { void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks) {
if (pList->nSize >= pList->nAlloc) { if (pList->nSize >= pList->nAlloc) {
pList->nAlloc = pList->nAlloc << 1; pList->nAlloc = pList->nAlloc << 1;
pList->pData = realloc(pList->pData, sizeof(void *) * (size_t)pList->nAlloc); pList->pData = realloc(pList->pData, sizeof(void*) * (size_t)pList->nAlloc);
// reset allocated memory // reset allocated memory
memset(pList->pData + pList->nSize, 0, sizeof(void *) * (pList->nAlloc - pList->nSize)); memset(pList->pData + pList->nSize, 0, sizeof(void*) * (pList->nAlloc - pList->nSize));
} }
pList->pData[pList->nSize++] = pBlocks; pList->pData[pList->nSize++] = pBlocks;
@ -557,7 +553,7 @@ void tscFreeUnusedDataBlocks(SDataBlockList* pList) {
} }
STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name) { STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name) {
STableDataBlocks *dataBuf = tscCreateDataBlock(size); STableDataBlocks* dataBuf = tscCreateDataBlock(size);
dataBuf->rowSize = rowSize; dataBuf->rowSize = rowSize;
dataBuf->size = startOffset; dataBuf->size = startOffset;
@ -577,7 +573,7 @@ STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pData
} }
if (dataBuf == NULL) { if (dataBuf == NULL) {
dataBuf = tscCreateDataBlockEx((size_t) size, rowSize, startOffset, tableId); dataBuf = tscCreateDataBlockEx((size_t)size, rowSize, startOffset, tableId);
dataBuf = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)&dataBuf); dataBuf = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)&dataBuf);
tscAppendDataBlock(pDataBlockList, dataBuf); tscAppendDataBlock(pDataBlockList, dataBuf);
} }
@ -608,7 +604,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
if (tmp != NULL) { if (tmp != NULL) {
dataBuf->pData = tmp; dataBuf->pData = tmp;
memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size); memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size);
} else { // failed to allocate memory, free already allocated memory and return error code } else { // failed to allocate memory, free already allocated memory and return error code
tscError("%p failed to allocate memory for merging submit block, size:%d", pSql, dataBuf->nAllocSize); tscError("%p failed to allocate memory for merging submit block, size:%d", pSql, dataBuf->nAllocSize);
taosCleanUpIntHash(pVnodeDataBlockHashList); taosCleanUpIntHash(pVnodeDataBlockHashList);
@ -873,11 +869,11 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo) {
static void _exprCheckSpace(SSqlExprInfo* pExprInfo, int32_t size) { static void _exprCheckSpace(SSqlExprInfo* pExprInfo, int32_t size) {
if (size > pExprInfo->numOfAlloc) { if (size > pExprInfo->numOfAlloc) {
int32_t oldSize = pExprInfo->numOfAlloc; uint32_t oldSize = pExprInfo->numOfAlloc;
int32_t newSize = (oldSize <= 0) ? 8 : (oldSize << 1); uint32_t newSize = (oldSize <= 0) ? 8 : (oldSize << 1U);
while (newSize < size) { while (newSize < size) {
newSize = (newSize << 1); newSize = (newSize << 1U);
} }
if (newSize > TSDB_MAX_COLUMNS) { if (newSize > TSDB_MAX_COLUMNS) {
@ -1165,7 +1161,7 @@ void tscColumnBaseInfoDestroy(SColumnBaseInfo* pColumnBaseInfo) {
assert(pColumnBaseInfo->numOfCols <= TSDB_MAX_COLUMNS); assert(pColumnBaseInfo->numOfCols <= TSDB_MAX_COLUMNS);
for (int32_t i = 0; i < pColumnBaseInfo->numOfCols; ++i) { for (int32_t i = 0; i < pColumnBaseInfo->numOfCols; ++i) {
SColumnBase *pColBase = &(pColumnBaseInfo->pColList[i]); SColumnBase* pColBase = &(pColumnBaseInfo->pColList[i]);
if (pColBase->numOfFilters > 0) { if (pColBase->numOfFilters > 0) {
for (int32_t j = 0; j < pColBase->numOfFilters; ++j) { for (int32_t j = 0; j < pColBase->numOfFilters; ++j) {
@ -1183,8 +1179,9 @@ void tscColumnBaseInfoDestroy(SColumnBaseInfo* pColumnBaseInfo) {
tfree(pColumnBaseInfo->pColList); tfree(pColumnBaseInfo->pColList);
} }
void tscColumnBaseInfoReserve(SColumnBaseInfo* pColumnBaseInfo, int32_t size) {
void tscColumnBaseInfoReserve(SColumnBaseInfo* pColumnBaseInfo, int32_t size) { _cf_ensureSpace(pColumnBaseInfo, size); } _cf_ensureSpace(pColumnBaseInfo, size);
}
/* /*
* 1. normal name, not a keyword or number * 1. normal name, not a keyword or number
@ -1232,16 +1229,16 @@ int32_t tscValidateName(SSQLToken* pToken) {
int len = tSQLGetToken(pToken->z, &pToken->type); int len = tSQLGetToken(pToken->z, &pToken->type);
// single token, validate it // single token, validate it
if (len == pToken->n){ if (len == pToken->n) {
return validateQuoteToken(pToken); return validateQuoteToken(pToken);
} else { } else {
sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
if (sep == NULL) { if (sep == NULL) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
return tscValidateName(pToken); return tscValidateName(pToken);
} }
} else { } else {
if (isNumber(pToken)) { if (isNumber(pToken)) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
@ -1620,8 +1617,8 @@ int32_t SStringAlloc(SString* pStr, int32_t size) {
#ifdef WINDOWS #ifdef WINDOWS
LPVOID lpMsgBuf; LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL); (LPTSTR)&lpMsgBuf, 0, NULL);
tscTrace("failed to allocate memory, reason:%s", lpMsgBuf); tscTrace("failed to allocate memory, reason:%s", lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
#else #else
@ -1656,12 +1653,11 @@ int32_t SStringEnsureRemain(SString* pStr, int32_t size) {
char* tmp = realloc(pStr->z, newsize); char* tmp = realloc(pStr->z, newsize);
if (tmp == NULL) { if (tmp == NULL) {
#ifdef WINDOWS #ifdef WINDOWS
LPVOID lpMsgBuf; LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL); (LPTSTR)&lpMsgBuf, 0, NULL);
tscTrace("failed to allocate memory, reason:%s", lpMsgBuf); tscTrace("failed to allocate memory, reason:%s", lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
#else #else
@ -1732,7 +1728,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex
if (pPrevSql != NULL) { if (pPrevSql != NULL) {
pNew->cmd.type = pPrevSql->cmd.type; pNew->cmd.type = pPrevSql->cmd.type;
} else { } else {
pNew->cmd.type |= TSDB_QUERY_TYPE_SUBQUERY; // it must be the subquery pNew->cmd.type |= TSDB_QUERY_TYPE_SUBQUERY; // it must be the subquery
} }
uint64_t uid = pMeterMetaInfo->pMeterMeta->uid; uint64_t uid = pMeterMetaInfo->pMeterMeta->uid;
@ -1764,7 +1760,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex
char key[TSDB_MAX_TAGS_LEN + 1] = {0}; char key[TSDB_MAX_TAGS_LEN + 1] = {0};
tscGetMetricMetaCacheKey(pCmd, key, pMetermetaInfo->pMeterMeta->uid); tscGetMetricMetaCacheKey(pCmd, key, pMetermetaInfo->pMeterMeta->uid);
char* name = pMeterMetaInfo->name; char* name = pMeterMetaInfo->name;
SMeterMetaInfo* pFinalInfo = NULL; SMeterMetaInfo* pFinalInfo = NULL;
if (pPrevSql == NULL) { if (pPrevSql == NULL) {
@ -1772,11 +1768,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex
SMetricMeta* pMetricMeta = taosGetDataFromCache(tscCacheHandle, key); SMetricMeta* pMetricMeta = taosGetDataFromCache(tscCacheHandle, key);
pFinalInfo = tscAddMeterMetaInfo(&pNew->cmd, name, pMeterMeta, pMetricMeta, pMeterMetaInfo->numOfTags, pFinalInfo = tscAddMeterMetaInfo(&pNew->cmd, name, pMeterMeta, pMetricMeta, pMeterMetaInfo->numOfTags,
pMeterMetaInfo->tagColumnIndex); pMeterMetaInfo->tagColumnIndex);
} else { } else {
SMeterMetaInfo* pPrevInfo = tscGetMeterMetaInfo(&pPrevSql->cmd, 0); SMeterMetaInfo* pPrevInfo = tscGetMeterMetaInfo(&pPrevSql->cmd, 0);
pFinalInfo = tscAddMeterMetaInfo(&pNew->cmd, name, pPrevInfo->pMeterMeta, pPrevInfo->pMetricMeta, pMeterMetaInfo->numOfTags, pFinalInfo = tscAddMeterMetaInfo(&pNew->cmd, name, pPrevInfo->pMeterMeta, pPrevInfo->pMetricMeta,
pMeterMetaInfo->tagColumnIndex); pMeterMetaInfo->numOfTags, pMeterMetaInfo->tagColumnIndex);
pPrevInfo->pMeterMeta = NULL; pPrevInfo->pMeterMeta = NULL;
pPrevInfo->pMetricMeta = NULL; pPrevInfo->pMetricMeta = NULL;
@ -1787,13 +1783,14 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int32_t vnodeIndex, int16_t tableIndex
assert(pFinalInfo->pMetricMeta != NULL); assert(pFinalInfo->pMetricMeta != NULL);
} }
tscTrace("%p new subquery %p, vnodeIdx:%d, tableIndex:%d, type:%d", pSql, pNew, vnodeIndex, tableIndex, pNew->cmd.type); tscTrace("%p new subquery %p, vnodeIdx:%d, tableIndex:%d, type:%d", pSql, pNew, vnodeIndex, tableIndex,
pNew->cmd.type);
return pNew; return pNew;
} }
void tscDoQuery(SSqlObj* pSql) { void tscDoQuery(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
void* fp = pSql->fp; void* fp = pSql->fp;
if (pCmd->command > TSDB_SQL_LOCAL) { if (pCmd->command > TSDB_SQL_LOCAL) {
tscProcessLocalCmd(pSql); tscProcessLocalCmd(pSql);
@ -1821,3 +1818,15 @@ int16_t tscGetJoinTagColIndexByUid(SSqlCmd* pCmd, uint64_t uid) {
return pTagCond->joinInfo.right.tagCol; return pTagCond->joinInfo.right.tagCol;
} }
} }
bool tscIsUpdateQuery(STscObj* pObj) {
if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED;
return TSDB_CODE_DISCONNECTED;
}
SSqlCmd* pCmd = &pObj->pSql->cmd;
return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) ||
TSDB_SQL_USE_DB == pCmd->command) ? 1 : 0;
}

View File

@ -29,46 +29,47 @@ import (
"unsafe" "unsafe"
) )
func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error){ func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsafe.Pointer, err error) {
cuser := C.CString(user) cuser := C.CString(user)
cpass := C.CString(pass) cpass := C.CString(pass)
cip := C.CString(ip) cip := C.CString(ip)
cdb := C.CString(db) cdb := C.CString(db)
defer C.free(unsafe.Pointer(cip)) defer C.free(unsafe.Pointer(cip))
defer C.free(unsafe.Pointer(cuser)) defer C.free(unsafe.Pointer(cuser))
defer C.free(unsafe.Pointer(cpass)) defer C.free(unsafe.Pointer(cpass))
defer C.free(unsafe.Pointer(cdb)) defer C.free(unsafe.Pointer(cdb))
taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.int)(port)) taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.int)(port))
if taosObj == nil { if taosObj == nil {
return nil, errors.New("taos_connect() fail!") return nil, errors.New("taos_connect() fail!")
} }
return (unsafe.Pointer)(taosObj), nil return (unsafe.Pointer)(taosObj), nil
} }
func (mc *taosConn) taosQuery(sqlstr string) (int, error) { func (mc *taosConn) taosQuery(sqlstr string) (int, error) {
taosLog.Printf("taosQuery() input sql:%s\n", sqlstr) //taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
csqlstr := C.CString(sqlstr) csqlstr := C.CString(sqlstr)
defer C.free(unsafe.Pointer(csqlstr)) defer C.free(unsafe.Pointer(csqlstr))
code := int(C.taos_query(mc.taos, csqlstr)) code := int(C.taos_query(mc.taos, csqlstr))
if 0 != code { if 0 != code {
mc.taos_error() mc.taos_error()
errStr := C.GoString(C.taos_errstr(mc.taos)) errStr := C.GoString(C.taos_errstr(mc.taos))
taosLog.Println("taos_query() failed:", errStr) taosLog.Println("taos_query() failed:", errStr)
return 0, errors.New(errStr) taosLog.Printf("taosQuery() input sql:%s\n", sqlstr)
} return 0, errors.New(errStr)
}
// read result and save into mc struct // read result and save into mc struct
num_fields := int(C.taos_field_count(mc.taos)) num_fields := int(C.taos_field_count(mc.taos))
if 0 == num_fields { // there are no select and show kinds of commands if 0 == num_fields { // there are no select and show kinds of commands
mc.affectedRows = int(C.taos_affected_rows(mc.taos)) mc.affectedRows = int(C.taos_affected_rows(mc.taos))
mc.insertId = 0 mc.insertId = 0
} }
return num_fields, nil return num_fields, nil
} }
func (mc *taosConn) taos_close() { func (mc *taosConn) taos_close() {
@ -76,8 +77,8 @@ func (mc *taosConn) taos_close() {
} }
func (mc *taosConn) taos_error() { func (mc *taosConn) taos_error() {
// free local resouce: allocated memory/metric-meta refcnt // free local resouce: allocated memory/metric-meta refcnt
//var pRes unsafe.Pointer //var pRes unsafe.Pointer
pRes := C.taos_use_result(mc.taos) pRes := C.taos_use_result(mc.taos)
C.taos_free_result(pRes) C.taos_free_result(pRes)
} }

View File

@ -134,7 +134,7 @@ public class TSDBJNIConnector {
} }
} }
// Try retrieving result set for the executed SQLusing the current connection pointer. If the executed // Try retrieving result set for the executed SQL using the current connection pointer. If the executed
// SQL is a DML/DDL which doesn't return a result set, then taosResultSetPointer should be 0L. Otherwise, // SQL is a DML/DDL which doesn't return a result set, then taosResultSetPointer should be 0L. Otherwise,
// taosResultSetPointer should be a non-zero value. // taosResultSetPointer should be a non-zero value.
taosResultSetPointer = this.getResultSetImp(this.taos); taosResultSetPointer = this.getResultSetImp(this.taos);

View File

@ -23,10 +23,10 @@ extern "C" {
#include "taosmsg.h" #include "taosmsg.h"
#include "tsdb.h" #include "tsdb.h"
extern short sdbPeerPort; extern short tsMgmtMgmtPort;
extern short sdbSyncPort; extern short tsMgmtSyncPort;
extern int sdbMaxNodes; extern int sdbMaxNodes;
extern int sdbHbTimer; // seconds extern int tsMgmtPeerHBTimer; // seconds
extern char sdbZone[]; extern char sdbZone[];
extern char sdbMasterIp[]; extern char sdbMasterIp[];
extern char sdbPrivateIp[]; extern char sdbPrivateIp[];

View File

@ -122,9 +122,6 @@ void taos_close_stream(TAOS_STREAM *tstr);
int taos_load_table_info(TAOS *taos, const char* tableNameList); int taos_load_table_info(TAOS *taos, const char* tableNameList);
// TODO: `configDir` should not be declared here
extern char configDir[]; // the path to global configuration
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

144
src/inc/taoserror.h Normal file
View File

@ -0,0 +1,144 @@
/*
* 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 TDENGINE_TAOSERROR_H
#define TDENGINE_TAOSERROR_H
#ifdef __cplusplus
extern "C" {
#endif
#define TSDB_CODE_SUCCESS 0
#define TSDB_CODE_ACTION_IN_PROGRESS 1
#define TSDB_CODE_LAST_SESSION_NOT_FINISHED 5
#define TSDB_CODE_INVALID_SESSION_ID 6
#define TSDB_CODE_INVALID_TRAN_ID 7
#define TSDB_CODE_INVALID_MSG_TYPE 8
#define TSDB_CODE_ALREADY_PROCESSED 9
#define TSDB_CODE_AUTH_FAILURE 10
#define TSDB_CODE_WRONG_MSG_SIZE 11
#define TSDB_CODE_UNEXPECTED_RESPONSE 12
#define TSDB_CODE_INVALID_RESPONSE_TYPE 13
#define TSDB_CODE_NO_RESOURCE 14
#define TSDB_CODE_INVALID_TIME_STAMP 15
#define TSDB_CODE_MISMATCHED_METER_ID 16
#define TSDB_CODE_ACTION_TRANS_NOT_FINISHED 17
#define TSDB_CODE_ACTION_NOT_ONLINE 18
#define TSDB_CODE_ACTION_SEND_FAILD 19
#define TSDB_CODE_NOT_ACTIVE_SESSION 20
#define TSDB_CODE_INVALID_VNODE_ID 21
#define TSDB_CODE_APP_ERROR 22
#define TSDB_CODE_INVALID_IE 23
#define TSDB_CODE_INVALID_VALUE 24
#define TSDB_CODE_REDIRECT 25
#define TSDB_CODE_ALREADY_THERE 26
#define TSDB_CODE_INVALID_METER_ID 27
#define TSDB_CODE_INVALID_SQL 28
#define TSDB_CODE_NETWORK_UNAVAIL 29
#define TSDB_CODE_INVALID_MSG_LEN 30
#define TSDB_CODE_INVALID_DB 31
#define TSDB_CODE_INVALID_TABLE 32
#define TSDB_CODE_DB_ALREADY_EXIST 33
#define TSDB_CODE_TABLE_ALREADY_EXIST 34
#define TSDB_CODE_INVALID_USER 35
#define TSDB_CODE_INVALID_ACCT 36
#define TSDB_CODE_INVALID_PASS 37
#define TSDB_CODE_DB_NOT_SELECTED 38
#define TSDB_CODE_MEMORY_CORRUPTED 39
#define TSDB_CODE_USER_ALREADY_EXIST 40
#define TSDB_CODE_NO_RIGHTS 41
#define TSDB_CODE_DISCONNECTED 42
#define TSDB_CODE_NO_MASTER 43
#define TSDB_CODE_NOT_CONFIGURED 44
#define TSDB_CODE_INVALID_OPTION 45
#define TSDB_CODE_NODE_OFFLINE 46
#define TSDB_CODE_SYNC_REQUIRED 47
#define TSDB_CODE_NO_ENOUGH_DNODES 48
#define TSDB_CODE_UNSYNCED 49
#define TSDB_CODE_TOO_SLOW 50
#define TSDB_CODE_OTHERS 51
#define TSDB_CODE_NO_REMOVE_MASTER 52
#define TSDB_CODE_WRONG_SCHEMA 53
#define TSDB_CODE_NOT_ACTIVE_VNODE 54
#define TSDB_CODE_TOO_MANY_USERS 55
#define TSDB_CODE_TOO_MANY_DATABSES 56
#define TSDB_CODE_TOO_MANY_TABLES 57
#define TSDB_CODE_TOO_MANY_DNODES 58
#define TSDB_CODE_TOO_MANY_ACCTS 59
#define TSDB_CODE_ACCT_ALREADY_EXIST 60
#define TSDB_CODE_DNODE_ALREADY_EXIST 61
#define TSDB_CODE_SDB_ERROR 62
#define TSDB_CODE_METRICMETA_EXPIRED 63 // local cached metric-meta expired causes error in metric query
#define TSDB_CODE_NOT_READY 64 // peer is not ready to process data
#define TSDB_CODE_MAX_SESSIONS 65 // too many sessions
#define TSDB_CODE_MAX_CONNECTIONS 66 // too many connections
#define TSDB_CODE_SESSION_ALREADY_EXIST 67
#define TSDB_CODE_NO_QSUMMARY 68
#define TSDB_CODE_SERV_OUT_OF_MEMORY 69
#define TSDB_CODE_INVALID_QHANDLE 70
#define TSDB_CODE_RELATED_TABLES_EXIST 71
#define TSDB_CODE_MONITOR_DB_FORBEIDDEN 72
#define TSDB_CODE_VG_COMMITLOG_INIT_FAILED 73
#define TSDB_CODE_VG_INIT_FAILED 74
#define TSDB_CODE_DATA_ALREADY_IMPORTED 75
#define TSDB_CODE_OPS_NOT_SUPPORT 76
#define TSDB_CODE_INVALID_QUERY_ID 77
#define TSDB_CODE_INVALID_STREAM_ID 78
#define TSDB_CODE_INVALID_CONNECTION 79
#define TSDB_CODE_ACTION_NOT_BALANCED 80
#define TSDB_CODE_CLI_OUT_OF_MEMORY 81
#define TSDB_CODE_DATA_OVERFLOW 82
#define TSDB_CODE_QUERY_CANCELLED 83
#define TSDB_CODE_GRANT_TIMESERIES_LIMITED 84
#define TSDB_CODE_GRANT_EXPIRED 85
#define TSDB_CODE_CLI_NO_DISKSPACE 86
#define TSDB_CODE_FILE_CORRUPTED 87
#define TSDB_CODE_INVALID_CLIENT_VERSION 88
#define TSDB_CODE_INVALID_ACCT_PARAMETER 89
#define TSDB_CODE_NOT_ENOUGH_TIME_SERIES 90
#define TSDB_CODE_NO_WRITE_ACCESS 91
#define TSDB_CODE_NO_READ_ACCESS 92
#define TSDB_CODE_GRANT_DB_LIMITED 93
#define TSDB_CODE_GRANT_USER_LIMITED 94
#define TSDB_CODE_GRANT_CONN_LIMITED 95
#define TSDB_CODE_GRANT_STREAM_LIMITED 96
#define TSDB_CODE_GRANT_SPEED_LIMITED 97
#define TSDB_CODE_GRANT_STORAGE_LIMITED 98
#define TSDB_CODE_GRANT_QUERYTIME_LIMITED 99
#define TSDB_CODE_GRANT_ACCT_LIMITED 100
#define TSDB_CODE_GRANT_DNODE_LIMITED 101
#define TSDB_CODE_GRANT_CPU_LIMITED 102
#define TSDB_CODE_SESSION_NOT_READY 103 // table NOT in ready state
#define TSDB_CODE_BATCH_SIZE_TOO_BIG 104
#define TSDB_CODE_TIMESTAMP_OUT_OF_RANGE 105
#define TSDB_CODE_INVALID_QUERY_MSG 106 // failed to validate the sql expression msg by vnode
#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered
#define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // commit log init failed
#define TSDB_CODE_SERVER_NO_SPACE 110
#define TSDB_CODE_NOT_SUPER_TABLE 111 // operation only available for super table
#define TSDB_CODE_DUPLICATE_TAGS 112 // tags value for join not unique
#define TSDB_CODE_INVALID_SUBMIT_MSG 113
#define TSDB_CODE_NOT_ACTIVE_TABLE 114
#define TSDB_CODE_INVALID_TABLE_ID 115
#define TSDB_CODE_INVALID_VNODE_STATUS 116
#define TSDB_CODE_FAILED_TO_LOCK_RESOURCES 117
#ifdef __cplusplus
}
#endif
#endif //TDENGINE_TAOSERROR_H

View File

@ -21,119 +21,7 @@ extern "C" {
#endif #endif
#include "tsdb.h" #include "tsdb.h"
#include "taoserror.h"
#define TSDB_CODE_SUCCESS 0
#define TSDB_CODE_ACTION_IN_PROGRESS 1
#define TSDB_CODE_LAST_SESSION_NOT_FINISHED 5
#define TSDB_CODE_INVALID_SESSION_ID 6
#define TSDB_CODE_INVALID_TRAN_ID 7
#define TSDB_CODE_INVALID_MSG_TYPE 8
#define TSDB_CODE_ALREADY_PROCESSED 9
#define TSDB_CODE_AUTH_FAILURE 10
#define TSDB_CODE_WRONG_MSG_SIZE 11
#define TSDB_CODE_UNEXPECTED_RESPONSE 12
#define TSDB_CODE_INVALID_RESPONSE_TYPE 13
#define TSDB_CODE_NO_RESOURCE 14
#define TSDB_CODE_INVALID_TIME_STAMP 15
#define TSDB_CODE_MISMATCHED_METER_ID 16
#define TSDB_CODE_ACTION_TRANS_NOT_FINISHED 17
#define TSDB_CODE_ACTION_NOT_ONLINE 18
#define TSDB_CODE_ACTION_SEND_FAILD 19
#define TSDB_CODE_NOT_ACTIVE_SESSION 20
#define TSDB_CODE_INSERT_FAILED 21
#define TSDB_CODE_APP_ERROR 22
#define TSDB_CODE_INVALID_IE 23
#define TSDB_CODE_INVALID_VALUE 24
#define TSDB_CODE_REDIRECT 25
#define TSDB_CODE_ALREADY_THERE 26
#define TSDB_CODE_INVALID_METER_ID 27
#define TSDB_CODE_INVALID_SQL 28
#define TSDB_CODE_NETWORK_UNAVAIL 29
#define TSDB_CODE_INVALID_MSG_LEN 30
#define TSDB_CODE_INVALID_DB 31
#define TSDB_CODE_INVALID_TABLE 32
#define TSDB_CODE_DB_ALREADY_EXIST 33
#define TSDB_CODE_TABLE_ALREADY_EXIST 34
#define TSDB_CODE_INVALID_USER 35
#define TSDB_CODE_INVALID_ACCT 36
#define TSDB_CODE_INVALID_PASS 37
#define TSDB_CODE_DB_NOT_SELECTED 38
#define TSDB_CODE_MEMORY_CORRUPTED 39
#define TSDB_CODE_USER_ALREADY_EXIST 40
#define TSDB_CODE_NO_RIGHTS 41
#define TSDB_CODE_DISCONNECTED 42
#define TSDB_CODE_NO_MASTER 43
#define TSDB_CODE_NOT_CONFIGURED 44
#define TSDB_CODE_INVALID_OPTION 45
#define TSDB_CODE_NODE_OFFLINE 46
#define TSDB_CODE_SYNC_REQUIRED 47
#define TSDB_CODE_NO_ENOUGH_DNODES 48
#define TSDB_CODE_UNSYNCED 49
#define TSDB_CODE_TOO_SLOW 50
#define TSDB_CODE_OTHERS 51
#define TSDB_CODE_NO_REMOVE_MASTER 52
#define TSDB_CODE_WRONG_SCHEMA 53
#define TSDB_CODE_NO_RESULT 54
#define TSDB_CODE_TOO_MANY_USERS 55
#define TSDB_CODE_TOO_MANY_DATABSES 56
#define TSDB_CODE_TOO_MANY_TABLES 57
#define TSDB_CODE_TOO_MANY_DNODES 58
#define TSDB_CODE_TOO_MANY_ACCTS 59
#define TSDB_CODE_ACCT_ALREADY_EXIST 60
#define TSDB_CODE_DNODE_ALREADY_EXIST 61
#define TSDB_CODE_SDB_ERROR 62
#define TSDB_CODE_METRICMETA_EXPIRED 63 // local cached metric-meta expired causes error in metric query
#define TSDB_CODE_NOT_READY 64 // peer is not ready to process data
#define TSDB_CODE_MAX_SESSIONS 65 // too many sessions
#define TSDB_CODE_MAX_CONNECTIONS 66 // too many connections
#define TSDB_CODE_SESSION_ALREADY_EXIST 67
#define TSDB_CODE_NO_QSUMMARY 68
#define TSDB_CODE_SERV_OUT_OF_MEMORY 69
#define TSDB_CODE_INVALID_QHANDLE 70
#define TSDB_CODE_RELATED_TABLES_EXIST 71
#define TSDB_CODE_MONITOR_DB_FORBEIDDEN 72
#define TSDB_CODE_VG_COMMITLOG_INIT_FAILED 73
#define TSDB_CODE_VG_INIT_FAILED 74
#define TSDB_CODE_DATA_ALREADY_IMPORTED 75
#define TSDB_CODE_OPS_NOT_SUPPORT 76
#define TSDB_CODE_INVALID_QUERY_ID 77
#define TSDB_CODE_INVALID_STREAM_ID 78
#define TSDB_CODE_INVALID_CONNECTION 79
#define TSDB_CODE_ACTION_NOT_BALANCED 80
#define TSDB_CODE_CLI_OUT_OF_MEMORY 81
#define TSDB_CODE_DATA_OVERFLOW 82
#define TSDB_CODE_QUERY_CANCELLED 83
#define TSDB_CODE_GRANT_TIMESERIES_LIMITED 84
#define TSDB_CODE_GRANT_EXPIRED 85
#define TSDB_CODE_CLI_NO_DISKSPACE 86
#define TSDB_CODE_FILE_CORRUPTED 87
#define TSDB_CODE_INVALID_CLIENT_VERSION 88
#define TSDB_CODE_INVALID_ACCT_PARAMETER 89
#define TSDB_CODE_NOT_ENOUGH_TIME_SERIES 90
#define TSDB_CODE_NO_WRITE_ACCESS 91
#define TSDB_CODE_NO_READ_ACCESS 92
#define TSDB_CODE_GRANT_DB_LIMITED 93
#define TSDB_CODE_GRANT_USER_LIMITED 94
#define TSDB_CODE_GRANT_CONN_LIMITED 95
#define TSDB_CODE_GRANT_STREAM_LIMITED 96
#define TSDB_CODE_GRANT_SPEED_LIMITED 97
#define TSDB_CODE_GRANT_STORAGE_LIMITED 98
#define TSDB_CODE_GRANT_QUERYTIME_LIMITED 99
#define TSDB_CODE_GRANT_ACCT_LIMITED 100
#define TSDB_CODE_GRANT_DNODE_LIMITED 101
#define TSDB_CODE_GRANT_CPU_LIMITED 102
#define TSDB_CODE_SESSION_NOT_READY 103 // table NOT in ready state
#define TSDB_CODE_BATCH_SIZE_TOO_BIG 104
#define TSDB_CODE_TIMESTAMP_OUT_OF_RANGE 105
#define TSDB_CODE_INVALID_QUERY_MSG 106 // failed to validate the sql expression msg by vnode
#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered
#define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // commit log init failed
#define TSDB_CODE_SERVER_NO_SPACE 110
#define TSDB_CODE_NOT_SUPER_TABLE 111 //
#define TSDB_CODE_DUPLICATE_TAGS 112 // tags value for join not unique
#define TSDB_CODE_INVALID_SUBMIT_MSG 113
// message type // message type
#define TSDB_MSG_TYPE_REG 1 #define TSDB_MSG_TYPE_REG 1
@ -673,7 +561,7 @@ typedef struct {
typedef struct { typedef struct {
uint64_t qhandle; uint64_t qhandle;
int16_t free; uint16_t free;
} SRetrieveMeterMsg; } SRetrieveMeterMsg;
typedef struct { typedef struct {

View File

@ -169,6 +169,8 @@ extern uint32_t debugFlag;
extern uint32_t odbcdebugFlag; extern uint32_t odbcdebugFlag;
extern uint32_t qdebugFlag; extern uint32_t qdebugFlag;
extern uint32_t taosMaxTmrCtrl;
extern int tsRpcTimer; extern int tsRpcTimer;
extern int tsRpcMaxTime; extern int tsRpcMaxTime;
extern int tsUdpDelay; extern int tsUdpDelay;
@ -245,7 +247,7 @@ typedef struct {
extern SGlobalConfig *tsGlobalConfig; extern SGlobalConfig *tsGlobalConfig;
extern int tsGlobalConfigNum; extern int tsGlobalConfigNum;
extern char * tsCfgStatusStr[]; extern char * tsCfgStatusStr[];
SGlobalConfig *tsGetConfigOption(char *option); SGlobalConfig *tsGetConfigOption(const char *option);
#define TSDB_CFG_MAX_NUM 110 #define TSDB_CFG_MAX_NUM 110
#define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_PRINT_LEN 23

View File

@ -25,7 +25,6 @@ extern "C" {
#define TAOS_CONN_UDPS 0 #define TAOS_CONN_UDPS 0
#define TAOS_CONN_UDPC 1 #define TAOS_CONN_UDPC 1
#define TAOS_CONN_UDP 1
#define TAOS_CONN_TCPS 2 #define TAOS_CONN_TCPS 2
#define TAOS_CONN_TCPC 3 #define TAOS_CONN_TCPC 3
#define TAOS_CONN_HTTPS 4 #define TAOS_CONN_HTTPS 4
@ -39,7 +38,7 @@ extern "C" {
#define TAOS_ID_REALLOCATE 2 #define TAOS_ID_REALLOCATE 2
#define TAOS_CONN_SOCKET_TYPE_S() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPS:TAOS_CONN_TCPS) #define TAOS_CONN_SOCKET_TYPE_S() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPS:TAOS_CONN_TCPS)
#define TAOS_CONN_SOCKET_TYPE_C() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDP:TAOS_CONN_TCPC) #define TAOS_CONN_SOCKET_TYPE_C() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPC:TAOS_CONN_TCPC)
#define taosSendMsgToPeer(x, y, z) taosSendMsgToPeerH(x, y, z, NULL) #define taosSendMsgToPeer(x, y, z) taosSendMsgToPeerH(x, y, z, NULL)
#define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x,y,z,NULL) #define taosOpenRpcChann(x, y, z) taosOpenRpcChannWithQ(x,y,z,NULL)

View File

@ -44,22 +44,40 @@ extern "C" {
#define TSDB_TIME_PRECISION_MILLI_STR "ms" #define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MICRO_STR "us" #define TSDB_TIME_PRECISION_MICRO_STR "us"
enum _status { enum _vnode_status {
TSDB_STATUS_OFFLINE, TSDB_VNODE_STATUS_OFFLINE,
TSDB_STATUS_CREATING, TSDB_VNODE_STATUS_CREATING,
TSDB_STATUS_UNSYNCED, TSDB_VNODE_STATUS_UNSYNCED,
TSDB_STATUS_SLAVE, TSDB_VNODE_STATUS_SLAVE,
TSDB_STATUS_MASTER, TSDB_VNODE_STATUS_MASTER,
TSDB_STATUS_READY, TSDB_VNODE_STATUS_CLOSING,
TSDB_VNODE_STATUS_DELETING,
}; };
enum _syncstatus { enum _vnode_sync_status {
STDB_SSTATUS_INIT, STDB_SSTATUS_INIT,
TSDB_SSTATUS_SYNCING, TSDB_SSTATUS_SYNCING,
TSDB_SSTATUS_SYNC_CACHE, TSDB_SSTATUS_SYNC_CACHE,
TSDB_SSTATUS_SYNC_FILE, TSDB_SSTATUS_SYNC_FILE,
}; };
enum _dnode_status {
TSDB_DNODE_STATUS_OFFLINE,
TSDB_DNODE_STATUS_READY
};
enum _dnode_balance_status {
LB_DNODE_STATE_BALANCED,
LB_DNODE_STATE_BALANCING,
LB_DNODE_STATE_OFFLINE_REMOVING,
LB_DNODE_STATE_SHELL_REMOVING
};
enum _vgroup_status {
LB_VGROUP_STATE_READY,
LB_VGROUP_STATE_UPDATE
};
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes #define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte #define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes #define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
@ -221,20 +239,20 @@ enum _syncstatus {
#define TSDB_MAX_RPC_THREADS 5 #define TSDB_MAX_RPC_THREADS 5
#define TSDB_QUERY_TYPE_QUERY 0 // normal query #define TSDB_QUERY_TYPE_QUERY 0 // normal query
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x1 // free qhandle at vnode #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01U // free qhandle at vnode
/* /*
* 1. ordinary sub query for select * from super_table * 1. ordinary sub query for select * from super_table
* 2. all sqlobj generated by createSubqueryObj with this flag * 2. all sqlobj generated by createSubqueryObj with this flag
*/ */
#define TSDB_QUERY_TYPE_SUBQUERY 0x2 #define TSDB_QUERY_TYPE_SUBQUERY 0x02U
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x4 // two-stage subquery for super table #define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04U // two-stage subquery for super table
#define TSDB_QUERY_TYPE_TABLE_QUERY 0x8 // query ordinary table; below only apply to client side #define TSDB_QUERY_TYPE_TABLE_QUERY 0x08U // query ordinary table; below only apply to client side
#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10 // query on super table #define TSDB_QUERY_TYPE_STABLE_QUERY 0x10U // query on super table
#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20 // join query #define TSDB_QUERY_TYPE_JOIN_QUERY 0x20U // join query
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40 // select *,columns... query #define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40U // select *,columns... query
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80 // join sub query at the second stage #define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80U // join sub query at the second stage
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,10 +20,11 @@
extern "C" { extern "C" {
#endif #endif
extern char *sdbDnodeStatusStr[]; const char* taosGetVnodeStatusStr(int vnodeStatus);
extern char *sdbDnodeBalanceStateStr[]; const char* taosGetDnodeStatusStr(int dnodeStatus);
extern char *sdbVnodeDropStateStr[]; const char* taosGetDnodeBalanceStateStr(int dnodeBalanceStatus);
extern char *sdbVnodeSyncStatusStr[]; const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus);
const char* taosGetVnodeDropStatusStr(int dropping);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,6 +25,7 @@ typedef void (*TAOS_TMR_CALLBACK)(void *, void *);
extern uint32_t tmrDebugFlag; extern uint32_t tmrDebugFlag;
extern int taosTmrThreads; extern int taosTmrThreads;
extern uint32_t taosMaxTmrCtrl;
#define tmrError(...) \ #define tmrError(...) \
do { if (tmrDebugFlag & DEBUG_ERROR) { \ do { if (tmrDebugFlag & DEBUG_ERROR) { \
@ -41,7 +42,6 @@ extern int taosTmrThreads;
tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \ tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \
} } while(0) } } while(0)
#define MAX_NUM_OF_TMRCTL 32
#define MSECONDS_PER_TICK 5 #define MSECONDS_PER_TICK 5
void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label); void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label);

View File

@ -89,7 +89,7 @@ extern "C" {
} else { \ } else { \
return (x) < (y) ? -1 : 1; \ return (x) < (y) ? -1 : 1; \
} \ } \
} while (0); } while (0)
#define GET_INT8_VAL(x) (*(int8_t *)(x)) #define GET_INT8_VAL(x) (*(int8_t *)(x))
#define GET_INT16_VAL(x) (*(int16_t *)(x)) #define GET_INT16_VAL(x) (*(int16_t *)(x))
@ -169,8 +169,6 @@ int32_t taosInitTimer(void (*callback)(int), int32_t ms);
*/ */
uint32_t MurmurHash3_32(const void *key, int32_t len); uint32_t MurmurHash3_32(const void *key, int32_t len);
bool taosCheckDbName(char *db, char *monitordb);
bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len); bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len);
bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);

View File

@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(./src SRC) AUX_SOURCE_DIRECTORY(./src SRC)
LIST(REMOVE_ITEM SRC ./src/shellWindows.c) LIST(REMOVE_ITEM SRC ./src/shellWindows.c)
ADD_EXECUTABLE(shell ${SRC}) ADD_EXECUTABLE(shell ${SRC})

View File

@ -13,16 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define __USE_XOPEN #define __USE_XOPEN
#include <wchar.h>
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"

View File

@ -16,16 +16,6 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <assert.h>
#include <pthread.h>
#include <regex.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
@ -445,7 +435,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
printf("%*lld|", l[i], *((int64_t *)row[i])); printf("%*lld|", l[i], *((int64_t *)row[i]));
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;
//memcpy(&fv, row[i], sizeof(float)); //memcpy(&fv, row[i], sizeof(float));
@ -454,8 +444,9 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
printf("%*.5f|", l[i], *((float *)row[i])); printf("%*.5f|", l[i], *((float *)row[i]));
#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;
//memcpy(&dv, row[i], sizeof(double)); //memcpy(&dv, row[i], sizeof(double));
@ -464,6 +455,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
printf("%*.9f|", l[i], *((double *)row[i])); printf("%*.9f|", l[i], *((double *)row[i]));
#endif #endif
}
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
@ -528,7 +520,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
printf("%lld\n", *((int64_t *)row[i])); printf("%lld\n", *((int64_t *)row[i]));
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;
//memcpy(&fv, row[i], sizeof(float)); //memcpy(&fv, row[i], sizeof(float));
@ -537,8 +529,9 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
printf("%.5f\n", *((float *)row[i])); printf("%.5f\n", *((float *)row[i]));
#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;
//memcpy(&dv, row[i], sizeof(double)); //memcpy(&dv, row[i], sizeof(double));
@ -547,7 +540,8 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
printf("%.9f\n", *((double *)row[i])); printf("%.9f\n", *((double *)row[i]));
#endif #endif
break; }
break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
memset(t_str, 0, TSDB_MAX_BYTES_PER_ROW); memset(t_str, 0, TSDB_MAX_BYTES_PER_ROW);
@ -614,7 +608,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
fprintf(fp, "%lld", *((int64_t *)row[i])); fprintf(fp, "%lld", *((int64_t *)row[i]));
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;
//memcpy(&fv, row[i], sizeof(float)); //memcpy(&fv, row[i], sizeof(float));
@ -623,8 +617,9 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
fprintf(fp, "%.5f", *((float *)row[i])); fprintf(fp, "%.5f", *((float *)row[i]));
#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;
//memcpy(&dv, row[i], sizeof(double)); //memcpy(&dv, row[i], sizeof(double));
@ -633,6 +628,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
#else #else
fprintf(fp, "%.9f", *((double *)row[i])); fprintf(fp, "%.9f", *((double *)row[i]));
#endif #endif
}
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
@ -840,7 +836,7 @@ void shellGetGrantInfo(void *con) {
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
TAOS_ROW row = taos_fetch_row(result); TAOS_ROW row = taos_fetch_row(result);
if (row == NULL) { if (row == NULL) {
fprintf(stderr, "\nGrant information is empty.\n"); fprintf(stderr, "\nFailed to get grant information from server. Abort.\n");
exit(0); exit(0);
} }

View File

@ -13,27 +13,9 @@
* 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 <argp.h>
#include <assert.h>
#include <assert.h>
#include <error.h>
#include <pwd.h>
#include <regex.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <wordexp.h>
#define __USE_XOPEN #define __USE_XOPEN
#include <wchar.h> #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"

View File

@ -13,13 +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 <locale.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "tsclient.h" #include "tsclient.h"

View File

@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdemo ${SRC}) ADD_EXECUTABLE(taosdemo ${SRC})
TARGET_LINK_LIBRARIES(taosdemo taos_static) TARGET_LINK_LIBRARIES(taosdemo taos_static)

View File

@ -30,6 +30,9 @@
#include <wordexp.h> #include <wordexp.h>
#include "taos.h" #include "taos.h"
extern char configDir[];
#pragma GCC diagnostic ignored "-Wmissing-braces" #pragma GCC diagnostic ignored "-Wmissing-braces"
#define BUFFER_SIZE 65536 #define BUFFER_SIZE 65536
@ -176,7 +179,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
fprintf(stderr, "Invalid path %s\n", arg); fprintf(stderr, "Invalid path %s\n", arg);
return -1; return -1;
} }
strcpy(configDir, full_path.we_wordv[0]); taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]);
wordfree(&full_path); wordfree(&full_path);
break; break;
case OPT_ABORT: case OPT_ABORT:

View File

@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taosdump ${SRC}) ADD_EXECUTABLE(taosdump ${SRC})
TARGET_LINK_LIBRARIES(taosdump taos_static) TARGET_LINK_LIBRARIES(taosdump taos_static)

View File

@ -1,7 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc)

View File

@ -13,23 +13,7 @@
* 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 <arpa/inet.h> #include "os.h"
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <syslog.h>
#include <unistd.h>
#include "taosmsg.h" #include "taosmsg.h"
#include "tlog.h" #include "tlog.h"
@ -72,7 +56,7 @@ void httpRemoveContextFromEpoll(HttpThread *pThread, HttpContext *pContext) {
} }
bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) { bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) {
return (__sync_val_compare_and_swap_32(&pContext->state, srcState, destState) == srcState); return (atomic_val_compare_exchange_32(&pContext->state, srcState, destState) == srcState);
} }
void httpFreeContext(HttpServer *pServer, HttpContext *pContext); void httpFreeContext(HttpServer *pServer, HttpContext *pContext);
@ -124,7 +108,7 @@ void httpCleanUpContextTimer(HttpContext *pContext) {
void httpCleanUpContext(HttpContext *pContext) { void httpCleanUpContext(HttpContext *pContext) {
httpTrace("context:%p, start the clean up operation", pContext); httpTrace("context:%p, start the clean up operation", pContext);
__sync_val_compare_and_swap_64(&pContext->signature, pContext, 0); atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0);
if (pContext->signature != NULL) { if (pContext->signature != NULL) {
httpTrace("context:%p is freed by another thread.", pContext); httpTrace("context:%p is freed by another thread.", pContext);
return; return;
@ -494,7 +478,7 @@ void httpProcessHttpData(void *param) {
} else { } else {
if (httpReadData(pThread, pContext)) { if (httpReadData(pThread, pContext)) {
(*(pThread->processData))(pContext); (*(pThread->processData))(pContext);
__sync_fetch_and_add(&pThread->pServer->requestNum, 1); atomic_fetch_add_32(&pThread->pServer->requestNum, 1);
} }
} }
} }

View File

@ -50,7 +50,7 @@ int httpInitSystem() {
httpServer = (HttpServer *)malloc(sizeof(HttpServer)); httpServer = (HttpServer *)malloc(sizeof(HttpServer));
memset(httpServer, 0, sizeof(HttpServer)); memset(httpServer, 0, sizeof(HttpServer));
strcpy(httpServer->label, "taosh"); strcpy(httpServer->label, "rest");
strcpy(httpServer->serverIp, tsHttpIp); strcpy(httpServer->serverIp, tsHttpIp);
httpServer->serverPort = tsHttpPort; httpServer->serverPort = tsHttpPort;
httpServer->cacheContext = tsHttpCacheSessions; httpServer->cacheContext = tsHttpCacheSessions;
@ -77,7 +77,7 @@ int httpStartSystem() {
if (httpServer == NULL) { if (httpServer == NULL) {
httpError("http server is null"); httpError("http server is null");
return -1; httpInitSystem();
} }
if (httpServer->pContextPool == NULL) { if (httpServer->pContextPool == NULL) {
@ -148,7 +148,7 @@ void httpCleanUpSystem() {
void httpGetReqCount(int32_t *httpReqestNum) { void httpGetReqCount(int32_t *httpReqestNum) {
if (httpServer != NULL) { if (httpServer != NULL) {
*httpReqestNum = __sync_fetch_and_and(&httpServer->requestNum, 0); *httpReqestNum = atomic_exchange_32(&httpServer->requestNum, 0);
} else { } else {
*httpReqestNum = 0; *httpReqestNum = 0;
} }

View File

@ -1,7 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)

View File

@ -95,6 +95,9 @@ int monitorInitSystem() {
} }
int monitorStartSystem() { int monitorStartSystem() {
if (monitor == NULL) {
monitorInitSystem();
}
taosTmrReset(monitorInitConn, 10, NULL, tscTmr, &monitor->initTimer); taosTmrReset(monitorInitConn, 10, NULL, tscTmr, &monitor->initTimer);
return 0; return 0;
} }
@ -131,7 +134,7 @@ void monitorInitConn(void *para, void *unused) {
void monitorInitConnCb(void *param, TAOS_RES *result, int code) { void monitorInitConnCb(void *param, TAOS_RES *result, int code) {
if (code < 0) { if (code < 0) {
monitorError("monitor:%p, connect to taosd failed, code:%d", monitor->conn, code); monitorError("monitor:%p, connect to database failed, code:%d", monitor->conn, code);
taos_close(monitor->conn); taos_close(monitor->conn);
monitor->conn = NULL; monitor->conn = NULL;
monitor->state = MONITOR_STATE_UN_INIT; monitor->state = MONITOR_STATE_UN_INIT;
@ -139,7 +142,7 @@ void monitorInitConnCb(void *param, TAOS_RES *result, int code) {
return; return;
} }
monitorTrace("monitor:%p, connect to taosd success, code:%d", monitor->conn, code); monitorTrace("monitor:%p, connect to database success, code:%d", monitor->conn, code);
monitorInitDatabase(); monitorInitDatabase();
} }

View File

@ -73,28 +73,71 @@
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) #define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) #define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
// TODO: update prefix of below macros to 'atomic' as '__' is reserved by compiler #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
// and GCC suggest new code to use '__atomic' builtins to replace '__sync' builtins. #define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap #define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap #define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_16 __sync_val_compare_and_swap #define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_8 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_ptr __sync_val_compare_and_swap
#define __sync_add_and_fetch_64 __sync_add_and_fetch #define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_32 __sync_add_and_fetch #define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_16 __sync_add_and_fetch #define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_8 __sync_add_and_fetch #define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_ptr __sync_add_and_fetch #define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_64 __sync_sub_and_fetch #define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_32 __sync_sub_and_fetch #define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_16 __sync_sub_and_fetch #define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_8 __sync_sub_and_fetch #define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_ptr __sync_sub_and_fetch #define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
int32_t __sync_val_load_32(int32_t *ptr); #define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
void __sync_val_restore_32(int32_t *ptr, int32_t newval); #define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define SWAP(a, b, c) \ #define SWAP(a, b, c) \
do { \ do { \

View File

@ -204,7 +204,6 @@ int taosOpenUDServerSocket(char *ip, short port) {
char name[128]; char name[128];
pTrace("open ud socket:%s", name); pTrace("open ud socket:%s", name);
// if (tsAllowLocalhost) ip = "0.0.0.0";
sprintf(name, "%s.%d", ip, port); sprintf(name, "%s.%d", ip, port);
bzero((char *)&serverAdd, sizeof(serverAdd)); bzero((char *)&serverAdd, sizeof(serverAdd));
@ -243,10 +242,6 @@ int taosInitTimer(void (*callback)(int), int ms) {
return setitimer(ITIMER_REAL, &tv, NULL); return setitimer(ITIMER_REAL, &tv, NULL);
} }
char *taosCharsetReplace(char *charsetstr) {
return charsetstr;
}
void taosGetSystemTimezone() { void taosGetSystemTimezone() {
// get and set default timezone // get and set default timezone
SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone");

View File

@ -1,7 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)

View File

@ -1,17 +1,17 @@
/* /*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
* *
* This program is free software: you can use, redistribute, and/or modify * 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 * it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation. * or later ("AGPL"), as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_PLATFORM_LINUX_H #ifndef TDENGINE_PLATFORM_LINUX_H
#define TDENGINE_PLATFORM_LINUX_H #define TDENGINE_PLATFORM_LINUX_H
@ -23,12 +23,18 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <argp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <endian.h> #include <endian.h>
#include <errno.h>
#include <float.h> #include <float.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <libgen.h>
#include <limits.h> #include <limits.h>
#include <locale.h>
#include <math.h> #include <math.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -37,29 +43,35 @@ extern "C" {
#include <netinet/udp.h> #include <netinet/udp.h>
#include <pthread.h> #include <pthread.h>
#include <pwd.h> #include <pwd.h>
#include <regex.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdbool.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/statvfs.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/mman.h>
#include <sys/un.h> #include <sys/un.h>
#include <syslog.h> #include <syslog.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <wordexp.h> #include <wordexp.h>
#include <locale.h> #include <wctype.h>
#include <dirent.h>
#define taosCloseSocket(x) \ #define taosCloseSocket(x) \
{ \ { \
@ -89,28 +101,71 @@ extern "C" {
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) #define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) #define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
// TODO: update prefix of below macros to 'atomic' as '__' is reserved by compiler #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
// and GCC suggest new code to use '__atomic' builtins to replace '__sync' builtins. #define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_64 __sync_val_compare_and_swap #define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_32 __sync_val_compare_and_swap #define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_16 __sync_val_compare_and_swap #define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_8 __sync_val_compare_and_swap
#define __sync_val_compare_and_swap_ptr __sync_val_compare_and_swap
#define __sync_add_and_fetch_64 __sync_add_and_fetch #define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_32 __sync_add_and_fetch #define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_16 __sync_add_and_fetch #define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_8 __sync_add_and_fetch #define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_add_and_fetch_ptr __sync_add_and_fetch #define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_64 __sync_sub_and_fetch #define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_32 __sync_sub_and_fetch #define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_16 __sync_sub_and_fetch #define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_8 __sync_sub_and_fetch #define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
#define __sync_sub_and_fetch_ptr __sync_sub_and_fetch #define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
int32_t __sync_val_load_32(int32_t *ptr); #define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
void __sync_val_restore_32(int32_t *ptr, int32_t newval); #define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
#define SWAP(a, b, c) \ #define SWAP(a, b, c) \
do { \ do { \
@ -167,10 +222,13 @@ bool taosSkipSocketCheck();
int64_t str2int64(char *str); int64_t str2int64(char *str);
void taosSetCoreDump();
#define BUILDIN_CLZL(val) __builtin_clzl(val) #define BUILDIN_CLZL(val) __builtin_clzl(val)
#define BUILDIN_CLZ(val) __builtin_clz(val) #define BUILDIN_CLZ(val) __builtin_clz(val)
#define BUILDIN_CTZL(val) __builtin_ctzl(val) #define BUILDIN_CTZL(val) __builtin_ctzl(val)
#define BUILDIN_CTZ(val) __builtin_ctz(val) #define BUILDIN_CTZ(val) __builtin_ctz(val)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -197,7 +197,6 @@ int taosOpenUDServerSocket(char *ip, short port) {
char name[128]; char name[128];
pTrace("open ud socket:%s", name); pTrace("open ud socket:%s", name);
// if (tsAllowLocalhost) ip = "0.0.0.0";
sprintf(name, "%s.%d", ip, port); sprintf(name, "%s.%d", ip, port);
bzero((char *)&serverAdd, sizeof(serverAdd)); bzero((char *)&serverAdd, sizeof(serverAdd));
@ -340,11 +339,3 @@ bool taosSkipSocketCheck() {
return false; return false;
} }
int32_t __sync_val_load_32(int32_t *ptr) {
return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
}
void __sync_val_restore_32(int32_t *ptr, int32_t newval) {
__atomic_store_n(ptr, newval, __ATOMIC_RELEASE);
}

View File

@ -25,6 +25,14 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sysctl.h>
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "tlog.h" #include "tlog.h"
@ -210,25 +218,6 @@ void taosGetSystemTimezone() {
pPrint("timezone not configured, set to system default:%s", tsTimezone); pPrint("timezone not configured, set to system default:%s", tsTimezone);
} }
typedef struct CharsetPair {
char *oldCharset;
char *newCharset;
} CharsetPair;
char *taosCharsetReplace(char *charsetstr) {
CharsetPair charsetRep[] = {
{"utf8", "UTF-8"}, {"936", "CP936"},
};
for (int32_t i = 0; i < tListLen(charsetRep); ++i) {
if (strcasecmp(charsetRep[i].oldCharset, charsetstr) == 0) {
return strdup(charsetRep[i].newCharset);
}
}
return strdup(charsetstr);
}
/* /*
* POSIX format locale string: * POSIX format locale string:
* (Language Strings)_(Country/Region Strings).(code_page) * (Language Strings)_(Country/Region Strings).(code_page)
@ -596,3 +585,122 @@ void taosKillSystem() {
pPrint("taosd will shut down soon"); pPrint("taosd will shut down soon");
kill(tsProcId, 2); kill(tsProcId, 2);
} }
int _sysctl(struct __sysctl_args *args );
void taosSetCoreDump() {
// 1. set ulimit -c unlimited
struct rlimit rlim;
struct rlimit rlim_new;
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
pPrint("the old unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max);
rlim_new.rlim_cur = RLIM_INFINITY;
rlim_new.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
pPrint("set unlimited fail, error: %s", strerror(errno));
rlim_new.rlim_cur = rlim.rlim_max;
rlim_new.rlim_max = rlim.rlim_max;
(void)setrlimit(RLIMIT_CORE, &rlim_new);
}
}
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
pPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max);
}
// 2. set the path for saving core file
struct __sysctl_args args;
int old_usespid = 0;
size_t old_len = 0;
int new_usespid = 1;
size_t new_len = sizeof(new_usespid);
int name[] = {CTL_KERN, KERN_CORE_USES_PID};
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = &old_usespid;
args.oldlenp = &old_len;
args.newval = &new_usespid;
args.newlen = new_len;
old_len = sizeof(old_usespid);
if (syscall(SYS__sysctl, &args) == -1) {
pPrint("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
}
pPrint("The old core_uses_pid[%d]: %d", old_len, old_usespid);
old_usespid = 0;
old_len = 0;
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = &old_usespid;
args.oldlenp = &old_len;
old_len = sizeof(old_usespid);
if (syscall(SYS__sysctl, &args) == -1) {
pPrint("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
}
pPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid);
#if 0
// 3. set the path for saving core file
int status;
char coredump_dir[32] = "/var/log/taosdump";
if (opendir(coredump_dir) == NULL) {
status = mkdir(coredump_dir, S_IRWXU | S_IRWXG | S_IRWXO);
if (status) {
pPrint("mkdir fail, error: %s\n", strerror(errno));
}
}
// 4. set kernel.core_pattern
struct __sysctl_args args;
char old_corefile[128];
size_t old_len;
char new_corefile[128] = "/var/log/taosdump/core-%e-%p";
size_t new_len = sizeof(new_corefile);
int name[] = {CTL_KERN, KERN_CORE_PATTERN};
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = old_corefile;
args.oldlenp = &old_len;
args.newval = new_corefile;
args.newlen = new_len;
old_len = sizeof(old_corefile);
if (syscall(SYS__sysctl, &args) == -1) {
pPrint("_sysctl(kern_core_pattern) set fail: %s", strerror(errno));
}
pPrint("The old kern_core_pattern: %*s\n", old_len, old_corefile);
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = old_corefile;
args.oldlenp = &old_len;
old_len = sizeof(old_corefile);
if (syscall(SYS__sysctl, &args) == -1) {
pPrint("_sysctl(kern_core_pattern) get fail: %s", strerror(errno));
}
pPrint("The new kern_core_pattern: %*s\n", old_len, old_corefile);
#endif
}

View File

@ -81,6 +81,10 @@ extern "C" {
#if defined(_M_ARM) || defined(_M_ARM64) #if defined(_M_ARM) || defined(_M_ARM64)
/* the '__iso_volatile' functions does not use a memory fence, so these
* definitions are incorrect, comment out as we don't support Windows on
* ARM at present.
#define atomic_load_8(ptr) __iso_volatile_load8((const volatile __int8*)(ptr)) #define atomic_load_8(ptr) __iso_volatile_load8((const volatile __int8*)(ptr))
#define atomic_load_16(ptr) __iso_volatile_load16((const volatile __int16*)(ptr)) #define atomic_load_16(ptr) __iso_volatile_load16((const volatile __int16*)(ptr))
#define atomic_load_32(ptr) __iso_volatile_load32((const volatile __int32*)(ptr)) #define atomic_load_32(ptr) __iso_volatile_load32((const volatile __int32*)(ptr))
@ -98,7 +102,7 @@ extern "C" {
#define atomic_load_ptr atomic_load_32 #define atomic_load_ptr atomic_load_32
#define atomic_store_ptr atomic_store_32 #define atomic_store_ptr atomic_store_32
#endif #endif
*/
#else #else
#define atomic_load_8(ptr) (*(char volatile*)(ptr)) #define atomic_load_8(ptr) (*(char volatile*)(ptr))
@ -121,35 +125,152 @@ extern "C" {
#define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val)) #define atomic_exchange_64(ptr, val) _InterlockedExchange64((__int64 volatile*)(ptr), (__int64)(val))
#define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)) #define atomic_exchange_ptr(ptr, val) _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val))
#define __sync_val_compare_and_swap_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval)) #define atomic_val_compare_exchange_8(ptr, oldval, newval) _InterlockedCompareExchange8((char volatile*)(ptr), (char)(newval), (char)(oldval))
#define __sync_val_compare_and_swap_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval)) #define atomic_val_compare_exchange_16(ptr, oldval, newval) _InterlockedCompareExchange16((short volatile*)(ptr), (short)(newval), (short)(oldval))
#define __sync_val_compare_and_swap_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval)) #define atomic_val_compare_exchange_32(ptr, oldval, newval) _InterlockedCompareExchange((long volatile*)(ptr), (long)(newval), (long)(oldval))
#define __sync_val_compare_and_swap_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval)) #define atomic_val_compare_exchange_64(ptr, oldval, newval) _InterlockedCompareExchange64((__int64 volatile*)(ptr), (__int64)(newval), (__int64)(oldval))
#define __sync_val_compare_and_swap_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)) #define atomic_val_compare_exchange_ptr(ptr, oldval, newval) _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval))
char interlocked_add_8(char volatile *ptr, char val); char interlocked_add_fetch_8(char volatile *ptr, char val);
short interlocked_add_16(short volatile *ptr, short val); short interlocked_add_fetch_16(short volatile *ptr, short val);
long interlocked_add_32(long volatile *ptr, long val); long interlocked_add_fetch_32(long volatile *ptr, long val);
__int64 interlocked_add_64(__int64 volatile *ptr, __int64 val); __int64 interlocked_add_fetch_64(__int64 volatile *ptr, __int64 val);
#define __sync_add_and_fetch_8(ptr, val) interlocked_add_8((char volatile*)(ptr), (char)(val)) #define atomic_add_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), (char)(val))
#define __sync_add_and_fetch_16(ptr, val) interlocked_add_16((short volatile*)(ptr), (short)(val)) #define atomic_add_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), (short)(val))
#define __sync_add_and_fetch_32(ptr, val) interlocked_add_32((long volatile*)(ptr), (long)(val)) #define atomic_add_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), (long)(val))
#define __sync_add_and_fetch_64(ptr, val) interlocked_add_64((__int64 volatile*)(ptr), (__int64)(val)) #define atomic_add_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64 #ifdef _WIN64
#define __sync_add_and_fetch_ptr __sync_add_and_fetch_64 #define atomic_add_fetch_ptr atomic_add_fetch_64
#else #else
#define __sync_add_and_fetch_ptr __sync_add_and_fetch_32 #define atomic_add_fetch_ptr atomic_add_fetch_32
#endif #endif
#define __sync_sub_and_fetch_8(ptr, val) __sync_add_and_fetch_8((ptr), -(val)) #define atomic_fetch_add_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), (char)(val))
#define __sync_sub_and_fetch_16(ptr, val) __sync_add_and_fetch_16((ptr), -(val)) #define atomic_fetch_add_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), (short)(val))
#define __sync_sub_and_fetch_32(ptr, val) __sync_add_and_fetch_32((ptr), -(val)) #define atomic_fetch_add_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), (long)(val))
#define __sync_sub_and_fetch_64(ptr, val) __sync_add_and_fetch_64((ptr), -(val)) #define atomic_fetch_add_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), (__int64)(val))
#define __sync_sub_and_fetch_ptr(ptr, val) __sync_add_and_fetch_ptr((ptr), -(val)) #ifdef _WIN64
#define atomic_fetch_add_ptr atomic_fetch_add_64
#else
#define atomic_fetch_add_ptr atomic_fetch_add_32
#endif
int32_t __sync_val_load_32(int32_t *ptr); #define atomic_sub_fetch_8(ptr, val) interlocked_add_fetch_8((char volatile*)(ptr), -(char)(val))
void __sync_val_restore_32(int32_t *ptr, int32_t newval); #define atomic_sub_fetch_16(ptr, val) interlocked_add_fetch_16((short volatile*)(ptr), -(short)(val))
#define atomic_sub_fetch_32(ptr, val) interlocked_add_fetch_32((long volatile*)(ptr), -(long)(val))
#define atomic_sub_fetch_64(ptr, val) interlocked_add_fetch_64((__int64 volatile*)(ptr), -(__int64)(val))
#ifdef _WIN64
#define atomic_sub_fetch_ptr atomic_sub_fetch_64
#else
#define atomic_sub_fetch_ptr atomic_sub_fetch_32
#endif
#define atomic_fetch_sub_8(ptr, val) _InterlockedExchangeAdd8((char volatile*)(ptr), -(char)(val))
#define atomic_fetch_sub_16(ptr, val) _InterlockedExchangeAdd16((short volatile*)(ptr), -(short)(val))
#define atomic_fetch_sub_32(ptr, val) _InterlockedExchangeAdd((long volatile*)(ptr), -(long)(val))
#define atomic_fetch_sub_64(ptr, val) _InterlockedExchangeAdd64((__int64 volatile*)(ptr), -(__int64)(val))
#ifdef _WIN64
#define atomic_fetch_sub_ptr atomic_fetch_sub_64
#else
#define atomic_fetch_sub_ptr atomic_fetch_sub_32
#endif
char interlocked_and_fetch_8(char volatile* ptr, char val);
short interlocked_and_fetch_16(short volatile* ptr, short val);
long interlocked_and_fetch_32(long volatile* ptr, long val);
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_and_fetch_8(ptr, val) interlocked_and_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_and_fetch_16(ptr, val) interlocked_and_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_and_fetch_32(ptr, val) interlocked_and_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_and_fetch_64(ptr, val) interlocked_and_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_and_fetch_ptr atomic_and_fetch_64
#else
#define atomic_and_fetch_ptr atomic_and_fetch_32
#endif
#define atomic_fetch_and_8(ptr, val) _InterlockedAnd8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_and_16(ptr, val) _InterlockedAnd16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_and_32(ptr, val) _InterlockedAnd((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val);
#define atomic_fetch_and_64(ptr, val) interlocked_fetch_and_64((__int64 volatile*)(ptr), (__int64)(val))
#else
#define atomic_fetch_and_64(ptr, val) _InterlockedAnd64((__int64 volatile*)(ptr), (__int64)(val))
#endif
#ifdef _WIN64
#define atomic_fetch_and_ptr atomic_fetch_and_64
#else
#define atomic_fetch_and_ptr atomic_fetch_and_32
#endif
char interlocked_or_fetch_8(char volatile* ptr, char val);
short interlocked_or_fetch_16(short volatile* ptr, short val);
long interlocked_or_fetch_32(long volatile* ptr, long val);
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_or_fetch_8(ptr, val) interlocked_or_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_or_fetch_16(ptr, val) interlocked_or_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_or_fetch_32(ptr, val) interlocked_or_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_or_fetch_64(ptr, val) interlocked_or_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_or_fetch_ptr atomic_or_fetch_64
#else
#define atomic_or_fetch_ptr atomic_or_fetch_32
#endif
#define atomic_fetch_or_8(ptr, val) _InterlockedOr8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_or_16(ptr, val) _InterlockedOr16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_or_32(ptr, val) _InterlockedOr((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86
__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val);
#define atomic_fetch_or_64(ptr, val) interlocked_fetch_or_64((__int64 volatile*)(ptr), (__int64)(val))
#else
#define atomic_fetch_or_64(ptr, val) _InterlockedOr64((__int64 volatile*)(ptr), (__int64)(val))
#endif
#ifdef _WIN64
#define atomic_fetch_or_ptr atomic_fetch_or_64
#else
#define atomic_fetch_or_ptr atomic_fetch_or_32
#endif
char interlocked_xor_fetch_8(char volatile* ptr, char val);
short interlocked_xor_fetch_16(short volatile* ptr, short val);
long interlocked_xor_fetch_32(long volatile* ptr, long val);
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val);
#define atomic_xor_fetch_8(ptr, val) interlocked_xor_fetch_8((char volatile*)(ptr), (char)(val))
#define atomic_xor_fetch_16(ptr, val) interlocked_xor_fetch_16((short volatile*)(ptr), (short)(val))
#define atomic_xor_fetch_32(ptr, val) interlocked_xor_fetch_32((long volatile*)(ptr), (long)(val))
#define atomic_xor_fetch_64(ptr, val) interlocked_xor_fetch_64((__int64 volatile*)(ptr), (__int64)(val))
#ifdef _WIN64
#define atomic_xor_fetch_ptr atomic_xor_fetch_64
#else
#define atomic_xor_fetch_ptr atomic_xor_fetch_32
#endif
#define atomic_fetch_xor_8(ptr, val) _InterlockedXor8((char volatile*)(ptr), (char)(val))
#define atomic_fetch_xor_16(ptr, val) _InterlockedXor16((short volatile*)(ptr), (short)(val))
#define atomic_fetch_xor_32(ptr, val) _InterlockedXor((long volatile*)(ptr), (long)(val))
#ifdef _M_IX86
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val);
#define atomic_fetch_xor_64(ptr, val) interlocked_fetch_xor_64((__int64 volatile*)(ptr), (__int64)(val))
#else
#define atomic_fetch_xor_64(ptr, val) _InterlockedXor64((__int64 volatile*)(ptr), (__int64)(val))
#endif
#ifdef _WIN64
#define atomic_fetch_xor_ptr atomic_fetch_xor_64
#else
#define atomic_fetch_xor_ptr atomic_fetch_xor_32
#endif
#define SWAP(a, b, c) \ #define SWAP(a, b, c) \
do { \ do { \

View File

@ -66,37 +66,145 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle
return setsockopt(socketfd, level, optname, optval, optlen); return setsockopt(socketfd, level, optname, optval, optlen);
} }
// add
char interlocked_add_8(char volatile* ptr, char val) { char interlocked_add_fetch_8(char volatile* ptr, char val) {
return _InterlockedExchangeAdd8(ptr, val) + val; return _InterlockedExchangeAdd8(ptr, val) + val;
} }
short interlocked_add_16(short volatile* ptr, short val) { short interlocked_add_fetch_16(short volatile* ptr, short val) {
return _InterlockedExchangeAdd16(ptr, val) + val; return _InterlockedExchangeAdd16(ptr, val) + val;
} }
long interlocked_add_32(long volatile* ptr, long val) { long interlocked_add_fetch_32(long volatile* ptr, long val) {
return _InterlockedExchangeAdd(ptr, val) + val; return _InterlockedExchangeAdd(ptr, val) + val;
} }
__int64 interlocked_add_64(__int64 volatile* ptr, __int64 val) { __int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
return _InterlockedExchangeAdd64(ptr, val) + val; return _InterlockedExchangeAdd64(ptr, val) + val;
} }
int32_t __sync_val_load_32(int32_t *ptr) { // and
return InterlockedOr(ptr, 0); char interlocked_and_fetch_8(char volatile* ptr, char val) {
return _InterlockedAnd8(ptr, val) & val;
} }
void __sync_val_restore_32(int32_t *ptr, int32_t newval) { short interlocked_and_fetch_16(short volatile* ptr, short val) {
InterlockedCompareExchange(ptr, *ptr, newval); return _InterlockedAnd16(ptr, val) & val;
} }
long interlocked_and_fetch_32(long volatile* ptr, long val) {
return _InterlockedAnd(ptr, val) & val;
}
#ifndef _M_IX86
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) {
return _InterlockedAnd64(ptr, val) & val;
}
#else
__int64 interlocked_and_fetch_64(__int64 volatile* ptr, __int64 val) {
__int64 old, res;
do {
old = *ptr;
res = old & val;
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
return res;
}
__int64 interlocked_fetch_and_64(__int64 volatile* ptr, __int64 val) {
__int64 old;
do {
old = *ptr;
} while(_InterlockedCompareExchange64(ptr, old & val, old) != old);
return old;
}
#endif
// or
char interlocked_or_fetch_8(char volatile* ptr, char val) {
return _InterlockedOr8(ptr, val) | val;
}
short interlocked_or_fetch_16(short volatile* ptr, short val) {
return _InterlockedOr16(ptr, val) | val;
}
long interlocked_or_fetch_32(long volatile* ptr, long val) {
return _InterlockedOr(ptr, val) | val;
}
#ifndef _M_IX86
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) {
return _InterlockedOr64(ptr, val) & val;
}
#else
__int64 interlocked_or_fetch_64(__int64 volatile* ptr, __int64 val) {
__int64 old, res;
do {
old = *ptr;
res = old | val;
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
return res;
}
__int64 interlocked_fetch_or_64(__int64 volatile* ptr, __int64 val) {
__int64 old;
do {
old = *ptr;
} while(_InterlockedCompareExchange64(ptr, old | val, old) != old);
return old;
}
#endif
// xor
char interlocked_xor_fetch_8(char volatile* ptr, char val) {
return _InterlockedXor8(ptr, val) ^ val;
}
short interlocked_xor_fetch_16(short volatile* ptr, short val) {
return _InterlockedXor16(ptr, val) ^ val;
}
long interlocked_xor_fetch_32(long volatile* ptr, long val) {
return _InterlockedXor(ptr, val) ^ val;
}
#ifndef _M_IX86
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) {
return _InterlockedXor64(ptr, val) ^ val;
}
#else
__int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val) {
__int64 old, res;
do {
old = *ptr;
res = old ^ val;
} while(_InterlockedCompareExchange64(ptr, res, old) != old);
return res;
}
__int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) {
__int64 old;
do {
old = *ptr;
} while(_InterlockedCompareExchange64(ptr, old ^ val, old) != old);
return old;
}
#endif
void tsPrintOsInfo() {} void tsPrintOsInfo() {}
char *taosCharsetReplace(char *charsetstr) {
return charsetstr;
}
void taosGetSystemTimezone() { void taosGetSystemTimezone() {
// get and set default timezone // get and set default timezone
SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone");

View File

@ -5,7 +5,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(./src SRC) AUX_SOURCE_DIRECTORY(./src SRC)
ELSEIF (TD_DARWIN_64) ELSEIF (TD_DARWIN_64)
LIST(APPEND SRC ./src/thaship.c) LIST(APPEND SRC ./src/thaship.c)

View File

@ -13,14 +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 <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "os.h" #include "os.h"
#include "tlog.h" #include "tlog.h"
#include "tmempool.h" #include "tmempool.h"

View File

@ -13,10 +13,7 @@
* 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 <netinet/in.h> #include "os.h"
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
void taosFreeMsgHdr(void *hdr) { void taosFreeMsgHdr(void *hdr) {
struct msghdr *msgHdr = (struct msghdr *)hdr; struct msghdr *msgHdr = (struct msghdr *)hdr;

View File

@ -13,16 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "os.h" #include "os.h"
#include "shash.h" #include "shash.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tidpool.h" #include "tidpool.h"
@ -164,8 +156,8 @@ char *taosBuildReqHeader(void *param, char type, char *msg) {
pHeader->spi = 0; pHeader->spi = 0;
pHeader->tcp = 0; pHeader->tcp = 0;
pHeader->encrypt = 0; pHeader->encrypt = 0;
pHeader->tranId = __sync_add_and_fetch_32(&pConn->tranId, 1); pHeader->tranId = atomic_add_fetch_32(&pConn->tranId, 1);
if (pHeader->tranId == 0) pHeader->tranId = __sync_add_and_fetch_32(&pConn->tranId, 1); if (pHeader->tranId == 0) pHeader->tranId = atomic_add_fetch_32(&pConn->tranId, 1);
pHeader->sourceId = pConn->ownId; pHeader->sourceId = pConn->ownId;
pHeader->destId = pConn->peerId; pHeader->destId = pConn->peerId;
@ -196,8 +188,8 @@ char *taosBuildReqMsgWithSize(void *param, char type, int size) {
pHeader->spi = 0; pHeader->spi = 0;
pHeader->tcp = 0; pHeader->tcp = 0;
pHeader->encrypt = 0; pHeader->encrypt = 0;
pHeader->tranId = __sync_add_and_fetch_32(&pConn->tranId, 1); pHeader->tranId = atomic_add_fetch_32(&pConn->tranId, 1);
if (pHeader->tranId == 0) pHeader->tranId = __sync_add_and_fetch_32(&pConn->tranId, 1); if (pHeader->tranId == 0) pHeader->tranId = atomic_add_fetch_32(&pConn->tranId, 1);
pHeader->sourceId = pConn->ownId; pHeader->sourceId = pConn->ownId;
pHeader->destId = pConn->peerId; pHeader->destId = pConn->peerId;
@ -362,6 +354,8 @@ int taosOpenRpcChannWithQ(void *handle, int cid, int sessions, void *qhandle) {
STaosRpc * pServer = (STaosRpc *)handle; STaosRpc * pServer = (STaosRpc *)handle;
SRpcChann *pChann; SRpcChann *pChann;
tTrace("cid:%d, handle:%p open rpc chann", cid, handle);
if (pServer == NULL) return -1; if (pServer == NULL) return -1;
if (cid >= pServer->numOfChanns || cid < 0) { if (cid >= pServer->numOfChanns || cid < 0) {
tError("%s: cid:%d, chann is out of range, max:%d", pServer->label, cid, pServer->numOfChanns); tError("%s: cid:%d, chann is out of range, max:%d", pServer->label, cid, pServer->numOfChanns);
@ -410,6 +404,8 @@ void taosCloseRpcChann(void *handle, int cid) {
STaosRpc * pServer = (STaosRpc *)handle; STaosRpc * pServer = (STaosRpc *)handle;
SRpcChann *pChann; SRpcChann *pChann;
tTrace("cid:%d, handle:%p close rpc chann", cid, handle);
if (pServer == NULL) return; if (pServer == NULL) return;
if (cid >= pServer->numOfChanns || cid < 0) { if (cid >= pServer->numOfChanns || cid < 0) {
tError("%s cid:%d, chann is out of range, max:%d", pServer->label, cid, pServer->numOfChanns); tError("%s cid:%d, chann is out of range, max:%d", pServer->label, cid, pServer->numOfChanns);

View File

@ -145,7 +145,7 @@ char *tsError[] = {"success",
"not online", "not online",
"send failed", "send failed",
"not active session", // 20 "not active session", // 20
"insert failed", "invalid vnode id",
"App error", "App error",
"invalid IE", "invalid IE",
"invalid value", "invalid value",
@ -178,7 +178,7 @@ char *tsError[] = {"success",
"others", "others",
"can't remove dnode which is master", "can't remove dnode which is master",
"wrong schema", "wrong schema",
"no results", "vnode not active(not created yet or dropped already)",
"num of users execeed maxUsers", //55 "num of users execeed maxUsers", //55
"num of databases execeed maxDbs", "num of databases execeed maxDbs",
"num of tables execeed maxTables", "num of tables execeed maxTables",
@ -233,9 +233,13 @@ char *tsError[] = {"success",
"invalid query message", "invalid query message",
"timestamp disordered in cache block", "timestamp disordered in cache block",
"timestamp disordered in file block", "timestamp disordered in file block",
"invalid commit log", //110 "invalid commit log",
"server no disk space", "server no disk space", //110
"only super table has metric meta info", "only super table has metric meta info",
"tags value not unique for join", "tags value not unique for join",
"invalid submit message", "invalid submit message",
"not active table(not created yet or deleted already)", //114
"invalid table id",
"invalid vnode status", //116
"failed to lock resources",
}; };

View File

@ -13,15 +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 <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tlog.h" #include "tlog.h"

View File

@ -13,16 +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 <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tlog.h" #include "tlog.h"
@ -195,8 +185,9 @@ static void taosProcessTcpData(void *param) {
void *buffer = malloc(1024); void *buffer = malloc(1024);
int headLen = taosReadMsg(pFdObj->fd, buffer, sizeof(STaosHeader)); int headLen = taosReadMsg(pFdObj->fd, buffer, sizeof(STaosHeader));
if (headLen != sizeof(STaosHeader)) { if (headLen != sizeof(STaosHeader)) {
tError("%s read error, headLen:%d", pThreadObj->label, headLen); tError("%s read error, headLen:%d, errno:%d", pThreadObj->label, headLen, errno);
taosCleanUpFdObj(pFdObj); taosCleanUpFdObj(pFdObj);
tfree(buffer); tfree(buffer);
continue; continue;

View File

@ -13,15 +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 <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "thash.h" #include "thash.h"

View File

@ -5,7 +5,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(sdb ${SRC}) ADD_LIBRARY(sdb ${SRC})
TARGET_LINK_LIBRARIES(sdb trpc) TARGET_LINK_LIBRARIES(sdb trpc)

View File

@ -13,13 +13,7 @@
* 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 <pthread.h> #include "os.h"
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tsdb.h" #include "tsdb.h"
#define MAX_STR_LEN 40 #define MAX_STR_LEN 40

View File

@ -13,19 +13,7 @@
* 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 <arpa/inet.h> #include "os.h"
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "sdb.h" #include "sdb.h"
#include "sdbint.h" #include "sdbint.h"

View File

@ -1,7 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/modules/http/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/modules/http/inc)

View File

@ -20,11 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <errno.h> #include "os.h"
#include <pthread.h>
#include <semaphore.h>
#include <syslog.h>
#include <stdint.h>
#include "sdb.h" #include "sdb.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"
@ -34,7 +30,6 @@ extern "C" {
#include "tmempool.h" #include "tmempool.h"
#include "trpc.h" #include "trpc.h"
#include "tsdb.h" #include "tsdb.h"
#include "tsdb.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tsocket.h" #include "tsocket.h"
#include "ttime.h" #include "ttime.h"

View File

@ -20,9 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <pthread.h> #include "os.h"
#include <semaphore.h>
#include <stdbool.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mgmt.h"
@ -30,15 +28,6 @@ extern "C" {
#include "tstatus.h" #include "tstatus.h"
#include "ttime.h" #include "ttime.h"
enum {
LB_DNODE_STATE_BALANCED,
LB_DNODE_STATE_BALANCING,
LB_DNODE_STATE_OFFLINE_REMOVING,
LB_DNODE_STATE_SHELL_REMOVING
};
enum { LB_VGROUP_STATE_READY, LB_VGROUP_STATE_UPDATE };
void mgmtCreateDnodeOrderList(); void mgmtCreateDnodeOrderList();
void mgmtReleaseDnodeOrderList(); void mgmtReleaseDnodeOrderList();

View File

@ -20,8 +20,6 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
int mgmtInitRedirect(); int mgmtInitRedirect();
void mgmtCleanUpRedirect(); void mgmtCleanUpRedirect();

View File

@ -30,6 +30,7 @@ char* mgmtMeterGetTag(STabObj* pMeter, int32_t col, SSchema* pTagColSchema);
int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName); int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName);
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col); int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col);
bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes); int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes); int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);

View File

@ -20,11 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <errno.h> #include "os.h"
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>
#include <syslog.h>
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "tidpool.h" #include "tidpool.h"
@ -33,7 +29,6 @@ extern "C" {
#include "trpc.h" #include "trpc.h"
#include "tsclient.h" #include "tsclient.h"
#include "tsdb.h" #include "tsdb.h"
#include "tsdb.h"
#include "tsocket.h" #include "tsocket.h"
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
@ -97,7 +92,7 @@ typedef struct {
SVPeerDesc vpeers[TSDB_VNODES_SUPPORT]; SVPeerDesc vpeers[TSDB_VNODES_SUPPORT];
SVnodePeer * peerInfo[TSDB_VNODES_SUPPORT]; SVnodePeer * peerInfo[TSDB_VNODES_SUPPORT];
char selfIndex; char selfIndex;
char status; char vnodeStatus;
char accessState; // Vnode access state, Readable/Writable char accessState; // Vnode access state, Readable/Writable
char syncStatus; char syncStatus;
char commitInProcess; char commitInProcess;
@ -218,15 +213,15 @@ typedef struct {
* Only the QInfo.signature == QInfo, this structure can be released safely. * Only the QInfo.signature == QInfo, this structure can be released safely.
*/ */
#define TSDB_QINFO_QUERY_FLAG 0x1 #define TSDB_QINFO_QUERY_FLAG 0x1
#define TSDB_QINFO_RESET_SIG(x) ((x)->signature = (uint64_t)(x)) #define TSDB_QINFO_RESET_SIG(x) atomic_store_64(&((x)->signature), (uint64_t)(x))
#define TSDB_QINFO_SET_QUERY_FLAG(x) \ #define TSDB_QINFO_SET_QUERY_FLAG(x) \
__sync_val_compare_and_swap(&((x)->signature), (uint64_t)(x), TSDB_QINFO_QUERY_FLAG); atomic_val_compare_exchange_64(&((x)->signature), (uint64_t)(x), TSDB_QINFO_QUERY_FLAG);
// live lock: wait for query reaching a safe-point, release all resources // live lock: wait for query reaching a safe-point, release all resources
// belongs to this query // belongs to this query
#define TSDB_WAIT_TO_SAFE_DROP_QINFO(x) \ #define TSDB_WAIT_TO_SAFE_DROP_QINFO(x) \
{ \ { \
while (__sync_val_compare_and_swap(&((x)->signature), (x), 0) == TSDB_QINFO_QUERY_FLAG) { \ while (atomic_val_compare_exchange_64(&((x)->signature), (x), 0) == TSDB_QINFO_QUERY_FLAG) { \
taosMsleep(1); \ taosMsleep(1); \
} \ } \
} }

View File

@ -16,7 +16,7 @@
#ifndef TDENGINE_VNODEPEER_H #ifndef TDENGINE_VNODEPEER_H
#define TDENGINE_VNODEPEER_H #define TDENGINE_VNODEPEER_H
#include <stdint.h> #include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -20,8 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <stdio.h> #include "os.h"
#include <stdlib.h>
#include "ihash.h" #include "ihash.h"

View File

@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h> #include "os.h"
#include "tinterpolation.h" #include "tinterpolation.h"
#include "vnodeTagMgmt.h" #include "vnodeTagMgmt.h"

View File

@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h> #include "os.h"
typedef struct { typedef struct {
int sid; int sid;

View File

@ -16,8 +16,6 @@
#ifndef TDENGINE_VNODESTORE_H #ifndef TDENGINE_VNODESTORE_H
#define TDENGINE_VNODESTORE_H #define TDENGINE_VNODESTORE_H
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -16,8 +16,6 @@
#ifndef TDENGINE_VNODESYSTEM_H #ifndef TDENGINE_VNODESYSTEM_H
#define TDENGINE_VNODESYSTEM_H #define TDENGINE_VNODESYSTEM_H
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -14,9 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <arpa/inet.h>
#include <assert.h> #include "os.h"
#include <unistd.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "taosmsg.h" #include "taosmsg.h"
@ -27,6 +26,7 @@
#include "vnodeMgmt.h" #include "vnodeMgmt.h"
#include "vnodeSystem.h" #include "vnodeSystem.h"
#include "vnodeUtil.h" #include "vnodeUtil.h"
#include "tstatus.h"
SMgmtObj mgmtObj; SMgmtObj mgmtObj;
extern uint64_t tsCreatedTime; extern uint64_t tsCreatedTime;
@ -105,14 +105,14 @@ int vnodeProcessCreateMeterRequest(char *pMsg, int msgLen, SMgmtObj *pObj) {
if (vid >= TSDB_MAX_VNODES || vid < 0) { if (vid >= TSDB_MAX_VNODES || vid < 0) {
dError("vid:%d, vnode is out of range", vid); dError("vid:%d, vnode is out of range", vid);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_INVALID_VNODE_ID;
goto _over; goto _over;
} }
pVnode = vnodeList + vid; pVnode = vnodeList + vid;
if (pVnode->cfg.maxSessions <= 0) { if (pVnode->cfg.maxSessions <= 0) {
dError("vid:%d, not activated", vid); dError("vid:%d, not activated", vid);
code = TSDB_CODE_NOT_ACTIVE_SESSION; code = TSDB_CODE_NOT_ACTIVE_VNODE;
goto _over; goto _over;
} }
@ -141,27 +141,27 @@ int vnodeProcessAlterStreamRequest(char *pMsg, int msgLen, SMgmtObj *pObj) {
if (vid >= TSDB_MAX_VNODES || vid < 0) { if (vid >= TSDB_MAX_VNODES || vid < 0) {
dError("vid:%d, vnode is out of range", vid); dError("vid:%d, vnode is out of range", vid);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_INVALID_VNODE_ID;
goto _over; goto _over;
} }
pVnode = vnodeList + vid; pVnode = vnodeList + vid;
if (pVnode->cfg.maxSessions <= 0 || pVnode->pCachePool == NULL) { if (pVnode->cfg.maxSessions <= 0 || pVnode->pCachePool == NULL) {
dError("vid:%d is not activated yet", pAlter->vnode); dError("vid:%d is not activated yet", pAlter->vnode);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_NOT_ACTIVE_VNODE;
goto _over; goto _over;
} }
if (pAlter->sid >= pVnode->cfg.maxSessions || pAlter->sid < 0) { if (pAlter->sid >= pVnode->cfg.maxSessions || pAlter->sid < 0) {
dError("vid:%d sid:%d uid:%ld, sid is out of range", pAlter->vnode, pAlter->sid, pAlter->uid); dError("vid:%d sid:%d uid:%ld, sid is out of range", pAlter->vnode, pAlter->sid, pAlter->uid);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_INVALID_TABLE_ID;
goto _over; goto _over;
} }
SMeterObj *pMeterObj = vnodeList[vid].meterList[sid]; SMeterObj *pMeterObj = vnodeList[vid].meterList[sid];
if (pMeterObj == NULL || sid != pMeterObj->sid || vid != pMeterObj->vnode) { if (pMeterObj == NULL || sid != pMeterObj->sid || vid != pMeterObj->vnode) {
dError("vid:%d sid:%d, no active session", vid, sid); dError("vid:%d sid:%d, no active table", vid, sid);
code = TSDB_CODE_NOT_ACTIVE_SESSION; code = TSDB_CODE_NOT_ACTIVE_TABLE;
goto _over; goto _over;
} }
@ -195,7 +195,7 @@ int vnodeProcessCreateMeterMsg(char *pMsg, int msgLen) {
if (pCreate->vnode >= TSDB_MAX_VNODES || pCreate->vnode < 0) { if (pCreate->vnode >= TSDB_MAX_VNODES || pCreate->vnode < 0) {
dError("vid:%d is out of range", pCreate->vnode); dError("vid:%d is out of range", pCreate->vnode);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_INVALID_VNODE_ID;
goto _create_over; goto _create_over;
} }
@ -203,13 +203,13 @@ int vnodeProcessCreateMeterMsg(char *pMsg, int msgLen) {
if (pVnode->pCachePool == NULL) { if (pVnode->pCachePool == NULL) {
dError("vid:%d is not activated yet", pCreate->vnode); dError("vid:%d is not activated yet", pCreate->vnode);
vnodeSendVpeerCfgMsg(pCreate->vnode); vnodeSendVpeerCfgMsg(pCreate->vnode);
code = TSDB_CODE_NOT_ACTIVE_SESSION; code = TSDB_CODE_NOT_ACTIVE_VNODE;
goto _create_over; goto _create_over;
} }
if (pCreate->sid >= pVnode->cfg.maxSessions || pCreate->sid < 0) { if (pCreate->sid >= pVnode->cfg.maxSessions || pCreate->sid < 0) {
dError("vid:%d sid:%d id:%s, sid is out of range", pCreate->vnode, pCreate->sid, pCreate->meterId); dError("vid:%d sid:%d id:%s, sid is out of range", pCreate->vnode, pCreate->sid, pCreate->meterId);
code = TSDB_CODE_INVALID_SESSION_ID; code = TSDB_CODE_INVALID_TABLE_ID;
goto _create_over; goto _create_over;
} }
@ -331,7 +331,7 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) {
return -1; return -1;
} }
if (vnodeList[vnode].status == TSDB_STATUS_CREATING) { if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_CREATING) {
dTrace("vid:%d, vnode is still under creating", vnode); dTrace("vid:%d, vnode is still under creating", vnode);
return 0; return 0;
} }
@ -360,13 +360,27 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) {
} }
if (vnodeList[vnode].cfg.maxSessions == 0) { if (vnodeList[vnode].cfg.maxSessions == 0) {
dTrace("vid:%d, vnode is empty", vnode);
if (pCfg->maxSessions > 0) { if (pCfg->maxSessions > 0) {
return vnodeCreateVnode(vnode, pCfg, pMsg->vpeerDesc); if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_OFFLINE) {
dTrace("vid:%d, status:%s, start to create vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus));
return vnodeCreateVnode(vnode, pCfg, pMsg->vpeerDesc);
} else {
dTrace("vid:%d, status:%s, cannot preform create vnode operation", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus));
return TSDB_CODE_INVALID_VNODE_STATUS;
}
} }
} else { } else {
dTrace("vid:%d, vnode is not empty", vnode);
if (pCfg->maxSessions > 0) { if (pCfg->maxSessions > 0) {
if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_DELETING) {
dTrace("vid:%d, status:%s, wait vnode delete finished", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus));
} else {
dTrace("vid:%d, status:%s, start to update vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus));
}
/*
if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) {
vnodeCleanUpOneVnode(vnode); vnodeCleanUpOneVnode(vnode);
} }
vnodeConfigVPeers(vnode, pCfg->replications, pMsg->vpeerDesc); vnodeConfigVPeers(vnode, pCfg->replications, pMsg->vpeerDesc);
@ -377,7 +391,10 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) {
vnodeList[vnode].cfg.maxSessions = pCfg->maxSessions; vnodeList[vnode].cfg.maxSessions = pCfg->maxSessions;
vnodeOpenVnode(vnode); vnodeOpenVnode(vnode);
} }
*/
return 0;
} else { } else {
dTrace("vid:%d, status:%s, start to delete vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus));
vnodeRemoveVnode(vnode); vnodeRemoveVnode(vnode);
} }
} }
@ -435,11 +452,11 @@ int vnodeProcessFreeVnodeRequest(char *pMsg, int msgLen, SMgmtObj *pMgmtObj) {
pFree->vnode = htons(pFree->vnode); pFree->vnode = htons(pFree->vnode);
if (pFree->vnode < 0 || pFree->vnode >= TSDB_MAX_VNODES) { if (pFree->vnode < 0 || pFree->vnode >= TSDB_MAX_VNODES) {
dWarn("vid:%d out of range", pFree->vnode); dWarn("vid:%d, out of range", pFree->vnode);
return -1; return -1;
} }
dTrace("vid:%d receive free vnode message", pFree->vnode); dTrace("vid:%d, receive free vnode message", pFree->vnode);
int32_t code = vnodeRemoveVnode(pFree->vnode); int32_t code = vnodeRemoveVnode(pFree->vnode);
assert(code == TSDB_CODE_SUCCESS || code == TSDB_CODE_ACTION_IN_PROGRESS); assert(code == TSDB_CODE_SUCCESS || code == TSDB_CODE_ACTION_IN_PROGRESS);

View File

@ -14,20 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <errno.h>
#include <fcntl.h> #include "os.h"
#include <locale.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
#include <unistd.h>
#include <wordexp.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"

View File

@ -14,11 +14,7 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <pthread.h> #include "os.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "mgmt.h" #include "mgmt.h"
#include "vnode.h" #include "vnode.h"
@ -33,8 +29,8 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverflow" #pragma GCC diagnostic ignored "-Woverflow"
SModule tsModule[TSDB_MOD_MAX]; SModule tsModule[TSDB_MOD_MAX] = {0};
uint32_t tsModuleStatus; uint32_t tsModuleStatus = 0;
pthread_mutex_t dmutex; pthread_mutex_t dmutex;
extern int vnodeSelectReqNum; extern int vnodeSelectReqNum;
extern int vnodeInsertReqNum; extern int vnodeInsertReqNum;
@ -143,6 +139,8 @@ int dnodeInitSystem() {
tsPrintGlobalConfig(); tsPrintGlobalConfig();
dPrint("Server IP address is:%s", tsInternalIp); dPrint("Server IP address is:%s", tsInternalIp);
taosSetCoreDump();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
dnodeInitModules(); dnodeInitModules();
@ -216,8 +214,8 @@ void dnodeResetSystem() {
void dnodeCountRequest(SCountInfo *info) { void dnodeCountRequest(SCountInfo *info) {
httpGetReqCount(&info->httpReqNum); httpGetReqCount(&info->httpReqNum);
info->selectReqNum = __sync_fetch_and_and(&vnodeSelectReqNum, 0); info->selectReqNum = atomic_exchange_32(&vnodeSelectReqNum, 0);
info->insertReqNum = __sync_fetch_and_and(&vnodeInsertReqNum, 0); info->insertReqNum = atomic_exchange_32(&vnodeInsertReqNum, 0);
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -14,7 +14,7 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <arpa/inet.h> #include "os.h"
#include "mgmt.h" #include "mgmt.h"
#include "tschemautil.h" #include "tschemautil.h"

View File

@ -14,8 +14,10 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h"
#include "mgmt.h" #include "mgmt.h"
#include <arpa/inet.h>
#include "taosmsg.h" #include "taosmsg.h"
#include "tschemautil.h" #include "tschemautil.h"

View File

@ -14,9 +14,11 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h"
#include "mgmt.h" #include "mgmt.h"
#include <arpa/inet.h>
#include "mgmtBalance.h" #include "mgmtBalance.h"
#include "mgmtUtil.h"
#include "tschemautil.h" #include "tschemautil.h"
void *dbSdb = NULL; void *dbSdb = NULL;
@ -139,11 +141,10 @@ int mgmtCheckDbParams(SCreateDbMsg *pCreate) {
if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; // if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; //
//-1 for balance //-1 for balance
#ifdef CLUSTER if (pCreate->replications <= 0 || pCreate->replications > TSDB_REPLICA_MAX_NUM) {
if (pCreate->replications > TSDB_VNODES_SUPPORT - 1) pCreate->replications = TSDB_VNODES_SUPPORT - 1; mTrace("invalid db option replications: %d", pCreate->replications);
#else return TSDB_CODE_INVALID_OPTION;
pCreate->replications = 1; }
#endif
if (pCreate->commitLog < 0 || pCreate->commitLog > 1) { if (pCreate->commitLog < 0 || pCreate->commitLog > 1) {
mTrace("invalid db option commitLog: %d", pCreate->commitLog); mTrace("invalid db option commitLog: %d", pCreate->commitLog);
@ -314,7 +315,7 @@ bool mgmtCheckDropDbFinished(SDbObj *pDb) {
SDnodeObj *pDnode = mgmtGetDnode(pVnodeGid->ip); SDnodeObj *pDnode = mgmtGetDnode(pVnodeGid->ip);
if (pDnode == NULL) continue; if (pDnode == NULL) continue;
if (pDnode->status == TSDB_STATUS_OFFLINE) continue; if (pDnode->status == TSDB_DNODE_STATUS_OFFLINE) continue;
SVnodeLoad *pVload = &pDnode->vload[pVnodeGid->vnode]; SVnodeLoad *pVload = &pDnode->vload[pVnodeGid->vnode];
if (pVload->dropStatus == TSDB_VN_STATUS_DROPPING) { if (pVload->dropStatus == TSDB_VN_STATUS_DROPPING) {
@ -373,10 +374,12 @@ int mgmtDropDbByName(SAcctObj *pAcct, char *name) {
if (pDb == NULL) { if (pDb == NULL) {
mWarn("db:%s is not there", name); mWarn("db:%s is not there", name);
// return TSDB_CODE_INVALID_DB; // return TSDB_CODE_INVALID_DB;
return 0; return TSDB_CODE_SUCCESS;
} }
if (taosCheckDbName(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN; if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
}
return mgmtDropDb(pDb); return mgmtDropDb(pDb);
} }

View File

@ -15,14 +15,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <arpa/inet.h> #include "os.h"
#include <endian.h>
#include <stdbool.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mgmt.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tstatus.h" #include "tstatus.h"
#include "tstatus.h"
bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int moduleType); bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int moduleType);
int mgmtGetDnodesNum(); int mgmtGetDnodesNum();
@ -45,9 +44,9 @@ void mgmtSetDnodeMaxVnodes(SDnodeObj *pDnode) {
pDnode->openVnodes = 0; pDnode->openVnodes = 0;
#ifdef CLUSTER #ifdef CLUSTER
pDnode->status = TSDB_STATUS_OFFLINE; pDnode->status = TSDB_DNODE_STATUS_OFFLINE;
#else #else
pDnode->status = TSDB_STATUS_READY; pDnode->status = TSDB_DNODE_STATUS_READY;
#endif #endif
} }
@ -59,9 +58,9 @@ void mgmtCalcNumOfFreeVnodes(SDnodeObj *pDnode) {
if (pVload->vgId != 0) { if (pVload->vgId != 0) {
mTrace("dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s", mTrace("dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s",
taosIpStr(pDnode->privateIp), i, pVload->vgId, taosIpStr(pDnode->privateIp), i, pVload->vgId,
pVload->status, sdbDnodeStatusStr[pVload->status], pVload->status, taosGetDnodeStatusStr(pVload->status),
pVload->dropStatus, sdbVnodeDropStateStr[pVload->dropStatus], pVload->dropStatus, taosGetVnodeDropStatusStr(pVload->dropStatus),
pVload->syncStatus, sdbVnodeSyncStatusStr[pVload->syncStatus]); pVload->syncStatus, taosGetVnodeSyncStatusStr(pVload->syncStatus));
totalVnodes++; totalVnodes++;
} }
} }
@ -198,11 +197,11 @@ int mgmtRetrieveDnodes(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, sdbDnodeStatusStr[pDnode->status]); strcpy(pWrite, taosGetDnodeStatusStr(pDnode->status) );
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, sdbDnodeBalanceStateStr[pDnode->lbState]); strcpy(pWrite, taosGetDnodeBalanceStateStr(pDnode->lbState));
cols++; cols++;
tinet_ntoa(ipstr, pDnode->publicIp); tinet_ntoa(ipstr, pDnode->publicIp);
@ -294,7 +293,7 @@ int mgmtRetrieveModules(SShowObj *pShow, char *data, int rows, SConnObj *pConn)
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, sdbDnodeStatusStr[pDnode->status]); strcpy(pWrite, taosGetDnodeStatusStr(pDnode->status) );
cols++; cols++;
numOfRows++; numOfRows++;

Some files were not shown because too many files have changed in this diff Show More