diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..53798c8db90f96c92744cca3f1de6969e7fae6bb --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,70 @@ +pipeline { + agent any + stages { + stage('build TDengine') { + steps { + sh '''cd ${WORKSPACE} +export TZ=Asia/Harbin +date +rm -rf ${WORKSPACE}/debug +mkdir debug +cd debug +cmake .. > /dev/null +make > /dev/null +cd ${WORKSPACE}/debug''' + } + } + + stage('test_tsim') { + parallel { + stage('test') { + steps { + sh '''cd ${WORKSPACE}/tests +#./test-all.sh smoke +sudo ./test-all.sh full''' + } + } + + stage('test_crash_gen') { + steps { + sh '''cd ${WORKSPACE}/tests/pytest +sudo ./crash_gen.sh -a -p -t 4 -s 2000''' + } + } + + stage('test_valgrind') { + steps { + sh '''cd ${WORKSPACE}/tests/pytest +sudo ./valgrind-test.sh 2>&1 > mem-error-out.log +grep \'start to execute\\|ERROR SUMMARY\' mem-error-out.log|grep -v \'grep\'|uniq|tee uniq-mem-error-out.log + +for memError in `grep \'ERROR SUMMARY\' uniq-mem-error-out.log | awk \'{print $4}\'` +do + if [ -n "$memError" ]; then + if [ "$memError" -gt 12 ]; then + echo -e "${RED} ## Memory errors number valgrind reports is $memError.\\ + More than our threshold! ## ${NC}" + travis_terminate $memError + fi + fi +done + +grep \'start to execute\\|definitely lost:\' mem-error-out.log|grep -v \'grep\'|uniq|tee uniq-definitely-lost-out.log +for defiMemError in `grep \'definitely lost:\' uniq-definitely-lost-out.log | awk \'{print $7}\'` +do + if [ -n "$defiMemError" ]; then + if [ "$defiMemError" -gt 13 ]; then + echo -e "${RED} ## Memory errors number valgrind reports \\ + Definitely lost is $defiMemError. More than our threshold! ## ${NC}" + travis_terminate $defiMemError + fi + fi +done''' + } + } + + } + } + + } +} \ No newline at end of file diff --git a/cmake/define.inc b/cmake/define.inc index 7cc8dc7a26a10584349ba67d560720e5464e58ab..6e64c2709abee366856a61916c6905363ea2002d 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -72,18 +72,21 @@ ENDIF () IF (TD_ARM_32) ADD_DEFINITIONS(-D_TD_ARM_32) ADD_DEFINITIONS(-D_TD_ARM_) + ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "arm32 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types ") ENDIF () IF (TD_MIPS_64) ADD_DEFINITIONS(-D_TD_MIPS_64_) + ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "mips64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () IF (TD_MIPS_32) ADD_DEFINITIONS(-D_TD_MIPS_32_) + ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "mips32 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () diff --git a/documentation20/webdocs/markdowndocs/Getting Started-ch.md b/documentation20/webdocs/markdowndocs/Getting Started-ch.md index 210f0921bab40990ddb7b18e3a60586c028b58d2..0e751d8cd59603ddaf85330b0fe309f4373e5c09 100644 --- a/documentation20/webdocs/markdowndocs/Getting Started-ch.md +++ b/documentation20/webdocs/markdowndocs/Getting Started-ch.md @@ -68,7 +68,7 @@ systemctl status taosd taos ``` -如果TDengine终端链接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考[FAQ](https://www.taosdata.com/cn/faq/)来解决终端链接服务端失败的问题)。TDengine终端的提示符号如下: +如果TDengine终端连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考[FAQ](https://www.taosdata.com/cn/faq/)来解决终端连接服务端失败的问题)。TDengine终端的提示符号如下: ```cmd taos> @@ -99,8 +99,8 @@ Query OK, 2 row(s) in set (0.001700s) - -c, --config-dir: 指定配置文件目录,默认为_/etc/taos_ - -h, --host: 指定服务的IP地址,默认为本地服务 - -s, --commands: 在不进入终端的情况下运行TDengine命令 -- -u, -- user: 链接TDengine服务器的用户名,缺省为root -- -p, --password: 链接TDengine服务器的密码,缺省为taosdata +- -u, -- user: 连接TDengine服务器的用户名,缺省为root +- -p, --password: 连接TDengine服务器的密码,缺省为taosdata - -?, --help: 打印出所有命令行参数 示例: diff --git a/documentation20/webdocs/markdowndocs/Model-ch.md b/documentation20/webdocs/markdowndocs/Model-ch.md index bf04ce8388145d5b66d9658897744a9a93cdfaf0..d698e3daaf60c02a76da8470d11fc292b93df058 100644 --- a/documentation20/webdocs/markdowndocs/Model-ch.md +++ b/documentation20/webdocs/markdowndocs/Model-ch.md @@ -19,7 +19,7 @@ CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 4; USE power; ``` -就当前链接里操作的库换为power,否则对具体表操作前,需要使用“库名.表名”来指定库的名字。 +就当前连接里操作的库换为power,否则对具体表操作前,需要使用“库名.表名”来指定库的名字。 **注意:** diff --git a/documentation20/webdocs/markdowndocs/More on System Architecture-ch.md b/documentation20/webdocs/markdowndocs/More on System Architecture-ch.md index 8e5eeee1c5a6c96ddda1281110766a12a56b8d12..44d572268de04662c190a6a5975c784b38aad117 100644 --- a/documentation20/webdocs/markdowndocs/More on System Architecture-ch.md +++ b/documentation20/webdocs/markdowndocs/More on System Architecture-ch.md @@ -196,7 +196,7 @@ TDengine是基于硬件、软件系统不可靠、一定会有故障的假设进 **对外服务地址**:TDengine集群可以容纳单台、多台甚至几千台物理节点。应用只需要向集群中任何一个物理节点的publicIp发起连接即可。启动CLI应用taos时,选项-h需要提供的就是publicIp。 -**master/secondIp**:每一个dnode都需要配置一个masterIp。dnode启动后,将对配置的masterIp发起加入集群的连接请求。masterIp是已经创建的集群中的任何一个节点的privateIp,对于集群中的第一个节点,就是它自己的privateIp。为保证连接成功,每个dnode还可配置secondIp, 该IP地址也是已创建的集群中的任何一个节点的privateIp。如果一个节点连接masterIp失败,它将试图链接secondIp。 +**master/secondIp**:每一个dnode都需要配置一个masterIp。dnode启动后,将对配置的masterIp发起加入集群的连接请求。masterIp是已经创建的集群中的任何一个节点的privateIp,对于集群中的第一个节点,就是它自己的privateIp。为保证连接成功,每个dnode还可配置secondIp, 该IP地址也是已创建的集群中的任何一个节点的privateIp。如果一个节点连接masterIp失败,它将试图连接secondIp。 dnode启动后,会获知集群的mnode IP列表,并且定时向mnode发送状态信息。 @@ -245,4 +245,4 @@ vnode(虚拟数据节点)保存采集的时序数据,而且查询、计算都 -**Note:**目前集群功能仅仅限于企业版 \ No newline at end of file +**Note:**目前集群功能仅仅限于企业版 diff --git a/documentation20/webdocs/markdowndocs/administrator-ch.md b/documentation20/webdocs/markdowndocs/administrator-ch.md index ee978aa79a7c71c9e5d249dd5887dda73ce1516f..cc1beb10423ec4f09ce92d90daf3a8a76d8e8a8a 100644 --- a/documentation20/webdocs/markdowndocs/administrator-ch.md +++ b/documentation20/webdocs/markdowndocs/administrator-ch.md @@ -130,9 +130,25 @@ TDengine集群中加入一个新的dnode时,涉及集群相关的一些参数 - statusInterval: dnode向mnode报告状态时长。单位为秒,默认值:1。 - maxTablesPerVnode: 每个vnode中能够创建的最大表个数。默认值:1000000。 - maxVgroupsPerDb: 每个数据库中能够使用的最大vnode个数。 -- arbitrator: 系统中裁决器的end point,缺省为空 +- arbitrator: 系统中裁决器的end point,缺省为空。 - timezone、locale、charset 的配置见客户端配置。 +为方便调试,可通过SQL语句临时调整每个dnode的日志配置,系统重启后会失效: + +```mysql +ALTER DNODE +``` + +- dnode_id: 可以通过SQL语句"SHOW DNODES"命令获取 +- config: 要调整的日志参数,在如下列表中取值 + > resetlog 截断旧日志文件,创建一个新日志文件 + > debugFlag < 131 | 135 | 143 > 设置debugFlag为131、135或者143 + +例如: +``` + alter dnode 1 debugFlag 135; +``` + ## 客户端配置 TDengine系统的前台交互客户端应用程序为taos,它与taosd共享同一个配置文件taos.cfg。运行taos时,使用参数-c指定配置文件目录,如taos -c /home/cfg,表示使用/home/cfg/目录下的taos.cfg配置文件中的参数,缺省目录是/etc/taos。本节主要说明 taos 客户端应用在配置文件 taos.cfg 文件中使用到的参数。 @@ -234,10 +250,10 @@ ALTER USER PASS <'password'>; 修改用户密码, 为避免被转换为小写,密码需要用单引号引用,单引号为英文半角 ``` -ALTER USER PRIVILEDGE <'super'|'write'|'read'>; +ALTER USER PRIVILEDGE ; ``` -修改用户权限为:super/write/read。 为避免被转换为小写,密码需要用单引号引用,单引号为英文半角 +修改用户权限为:super/write/read,不需要添加单引号 ``` SHOW USERS; @@ -392,5 +408,5 @@ TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下 您可以通过修改系统配置文件taos.cfg来配置不同的数据目录和日志目录。 - +## diff --git a/documentation20/webdocs/markdowndocs/architecture-ch.md b/documentation20/webdocs/markdowndocs/architecture-ch.md index 7dfff1f21faed52487f442ecb79ec5b14b6a569f..c7f3eba9efa7ff34cafef9b52b32dec5b113da60 100644 --- a/documentation20/webdocs/markdowndocs/architecture-ch.md +++ b/documentation20/webdocs/markdowndocs/architecture-ch.md @@ -84,17 +84,17 @@ TDengine 分布式架构的逻辑结构图如下: **FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。 -**端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP链接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。使用时,需要确保防火墙将这些端口打开。每个数据节点可以配置不同的serverPort。 +**端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。使用时,需要确保防火墙将这些端口打开。每个数据节点可以配置不同的serverPort。 -**集群对外链接:** TDengine集群可以容纳单个、多个甚至几千个数据节点。应用只需要向集群中任何一个数据节点发起连接即可,链接需要提供的网络参数是一数据节点的End Point(FQDN加配置的端口号)。通过命令行CLI启动应用taos时,可以通过选项-h来指定数据节点的FQDN, -P来指定其配置的端口号,如果端口不配置,将采用TDengine的系统配置参数serverPort。 +**集群对外连接:** TDengine集群可以容纳单个、多个甚至几千个数据节点。应用只需要向集群中任何一个数据节点发起连接即可,连接需要提供的网络参数是一数据节点的End Point(FQDN加配置的端口号)。通过命令行CLI启动应用taos时,可以通过选项-h来指定数据节点的FQDN, -P来指定其配置的端口号,如果端口不配置,将采用TDengine的系统配置参数serverPort。 -**集群内部通讯**: 各个数据节点之间通过TCP/UDP进行链接。一个数据节点启动时,将获取mnode所在的dnode的EP信息,然后与系统中的mnode建立起链接,交换信息。获取mnode的EP信息有三步,1:检查mnodeEpList文件是否存在,如果不存在或不能正常打开获得mnode EP信息,进入第二步;2:检查系统配置文件taos.cfg, 获取mnode EP配置参数first, second,如果不存在或者taos.cfg里没有这两个配置参数,或无效,进入第三步;3:将自己的EP设为mnode EP, 并独立运行起来。获取mnode EP列表后,数据节点发起链接,如果链接成功,则成功加入进工作的集群,如果不成功,则尝试mnode EP列表中的下一个。如果都尝试了,但链接都仍然失败,则休眠几秒后,再进行尝试。 +**集群内部通讯**: 各个数据节点之间通过TCP/UDP进行连接。一个数据节点启动时,将获取mnode所在的dnode的EP信息,然后与系统中的mnode建立起连接,交换信息。获取mnode的EP信息有三步,1:检查mnodeEpList文件是否存在,如果不存在或不能正常打开获得mnode EP信息,进入第二步;2:检查系统配置文件taos.cfg, 获取mnode EP配置参数first, second,如果不存在或者taos.cfg里没有这两个配置参数,或无效,进入第三步;3:将自己的EP设为mnode EP, 并独立运行起来。获取mnode EP列表后,数据节点发起连接,如果连接成功,则成功加入进工作的集群,如果不成功,则尝试mnode EP列表中的下一个。如果都尝试了,但连接都仍然失败,则休眠几秒后,再进行尝试。 **MNODE的选择:** TDengine逻辑上有管理节点,但没有单独的执行代码,服务器侧只有一套执行代码taosd。那么哪个数据节点会是管理节点呢?这是系统自动决定的,无需任何人工干预。原则如下:一个数据节点启动时,会检查自己的End Point, 并与获取的mnode EP List进行比对,如果在其中,该数据节点认为自己应该启动mnode模块,成为mnode。如果自己的EP不在mnode EP List里,则不启动mnode模块。在系统的运行过程中,由于负载均衡、宕机等原因,mnode有可能迁移至新的dnode,但一切都是透明的,无需人工干预,配置参数的修改,是mnode自己根据资源做出的决定。 -**新数据节点的加入**:系统有了一个数据节点后,就已经成为一个工作的系统。添加新的节点进集群时,有两个步骤,第一步:使用TDengine CLI链接到现有工作的数据节点,然后用命令”create dnode"将新的数据节点的End Point添加进去; 第二步:在新的数据节点的系统配置参数文件taos.cfg里,将first, second参数设置为现有集群中任意两个数据节点的EP即可。具体添加的详细步骤请见详细的用户手册。这样就把集群一步一步的建立起来。 +**新数据节点的加入**:系统有了一个数据节点后,就已经成为一个工作的系统。添加新的节点进集群时,有两个步骤,第一步:使用TDengine CLI连接到现有工作的数据节点,然后用命令”create dnode"将新的数据节点的End Point添加进去; 第二步:在新的数据节点的系统配置参数文件taos.cfg里,将first, second参数设置为现有集群中任意两个数据节点的EP即可。具体添加的详细步骤请见详细的用户手册。这样就把集群一步一步的建立起来。 -**重定向**:无论是dnode还是taosc,最先都是要发起与mnode的链接,但mnode是系统自动创建并维护的,因此对于用户来说,并不知道哪个dnode在运行mnode。TDengine只要求向系统中任何一个工作的dnode发起链接即可。因为任何一个正在运行的dnode,都维护有目前运行的mnode EP List。当收到一个来自新启动的dnode或taosc的链接请求,如果自己不是mnode,则将mnode EP List回复给对方,taosc或新启动的dnode收到这个list, 就重新尝试建立链接。当mnode EP List发生改变,通过节点之间的消息交互,各个数据节点就很快获取最新列表,并通知taosc。 +**重定向**:无论是dnode还是taosc,最先都是要发起与mnode的连接,但mnode是系统自动创建并维护的,因此对于用户来说,并不知道哪个dnode在运行mnode。TDengine只要求向系统中任何一个工作的dnode发起连接即可。因为任何一个正在运行的dnode,都维护有目前运行的mnode EP List。当收到一个来自新启动的dnode或taosc的连接请求,如果自己不是mnode,则将mnode EP List回复给对方,taosc或新启动的dnode收到这个list, 就重新尝试建立连接。当mnode EP List发生改变,通过节点之间的消息交互,各个数据节点就很快获取最新列表,并通知taosc。 ### 一个典型的消息流程 为解释vnode, mnode, taosc和应用之间的关系以及各自扮演的角色,下面对写入数据这个典型操作的流程进行剖析。 @@ -197,7 +197,7 @@ Master Vnode遵循下面的写入流程: ### 主从选择 Vnode会保持一个数据版本号(Version),对内存数据进行持久化存储时,对该版本号也进行持久化存储。每个数据更新操作,无论是采集的时序数据还是元数据,这个版本号将增一。 -一个vnode启动时,角色(master、slave) 是不定的,数据是处于未同步状态,它需要与虚拟节点组内其他节点建立TCP链接,并互相交换status,其中包括version和自己的角色。通过status的交换,系统进入选主流程,规则如下: +一个vnode启动时,角色(master、slave) 是不定的,数据是处于未同步状态,它需要与虚拟节点组内其他节点建立TCP连接,并互相交换status,其中包括version和自己的角色。通过status的交换,系统进入选主流程,规则如下: 1. 如果只有一个副本,该副本永远就是master 2. 所有副本都在线时,版本最高的被选为master diff --git a/documentation20/webdocs/markdowndocs/connector-ch.md b/documentation20/webdocs/markdowndocs/connector-ch.md index 7b6afb75a7ad75d6b94b519cc1e1b438ecbf3b6f..0e29b324871e61d184fde17710c863f06b60bdcc 100644 --- a/documentation20/webdocs/markdowndocs/connector-ch.md +++ b/documentation20/webdocs/markdowndocs/connector-ch.md @@ -142,7 +142,7 @@ C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine 获取最近一次API调用失败的原因,返回值为错误代码。 -**注意**:对于单个数据库连接,在同一时刻只能有一个线程使用该链接调用API,否则会有未定义的行为出现并可能导致客户端crash。客户端应用可以通过建立多个连接进行多线程的数据写入或查询处理。 +**注意**:对于单个数据库连接,在同一时刻只能有一个线程使用该连接调用API,否则会有未定义的行为出现并可能导致客户端crash。客户端应用可以通过建立多个连接进行多线程的数据写入或查询处理。 ### 异步查询API diff --git a/documentation20/webdocs/markdowndocs/faq-ch.md b/documentation20/webdocs/markdowndocs/faq-ch.md index 7bbf7531c805eed1b3711cbe67a6dcfbc7fae3a1..80deb889ef0eee8e9b47f86b5e58a76c6c070d5b 100644 --- a/documentation20/webdocs/markdowndocs/faq-ch.md +++ b/documentation20/webdocs/markdowndocs/faq-ch.md @@ -21,7 +21,7 @@ ## 5. 遇到错误"Unable to establish connection", 我怎么办? -客户端遇到链接故障,请按照下面的步骤进行检查: +客户端遇到连接故障,请按照下面的步骤进行检查: 1. 检查网络环境 * 云服务器:检查云服务器的安全组是否打开TCP/UDP 端口6030-6042的访问权限 @@ -45,7 +45,7 @@ 9. 如果仍不能排除连接故障,请使用命令行工具nc来分别判断指定端口的TCP和UDP连接是否通畅 检查UDP端口连接是否工作:`nc -vuz {hostIP} {port} ` 检查服务器侧TCP端口连接是否工作:`nc -l {port}` - 检查客户端侧TCP端口链接是否工作:`nc {hostIP} {port}` + 检查客户端侧TCP端口连接是否工作:`nc {hostIP} {port}` 10. 也可以使用taos程序内嵌的网络连通检测功能,来验证服务器和客户端之间指定的端口连接是否通畅(包括TCP和UDP):[TDengine 内嵌网络检测工具使用指南](https://www.taosdata.com/blog/2020/09/08/1816.html)。 @@ -57,7 +57,7 @@ 1. 请检查连接的服务器的FQDN是否正确,FQDN配置参考:[一篇文章说清楚TDengine的FQDN](https://www.taosdata.com/blog/2020/09/11/1824.html)。 2. 如果网络配置有DNS server, 请检查是否正常工作 3. 如果网络没有配置DNS server, 请检查客户端所在机器的hosts文件,查看该FQDN是否配置,并是否有正确的IP地址。 -4. 如果网络配置OK,从客户端所在机器,你需要能Ping该连接的FQDN,否则客户端是无法链接服务器的 +4. 如果网络配置OK,从客户端所在机器,你需要能Ping该连接的FQDN,否则客户端是无法连接服务器的 ## 7. 虽然语法正确,为什么我还是得到 "Invalid SQL" 错误 @@ -108,4 +108,8 @@ Connection = DriverManager.getConnection(url, properties); 附上必要的问题描述,以及发生该问题的执行操作,出现问题的表征及大概的时间,在 GitHub提交Issue。 -为了保证有足够的debug信息,如果问题能够重复,请修改/etc/taos/taos.cfg文件,最后面添加一行“debugFlag 135"(不带引号本身),然后重启taosd, 重复问题,然后再递交。但系统正常运行时,请一定将debugFlag设置为131,否则会产生大量的日志信息,降低系统效率。 +为了保证有足够的debug信息,如果问题能够重复,请修改/etc/taos/taos.cfg文件,最后面添加一行“debugFlag 135"(不带引号本身),然后重启taosd, 重复问题,然后再递交。也可以通过如下SQL语句,临时设置taosd的日志级别。 +``` + alter dnode debugFlag 135; +``` +但系统正常运行时,请一定将debugFlag设置为131,否则会产生大量的日志信息,降低系统效率。 diff --git a/documentation20/webdocs/markdowndocs/replica-ch.md b/documentation20/webdocs/markdowndocs/replica-ch.md index c32928b42d806c66b3e8bfe66943d4b199c34acc..1d80174455913a5de55678151811218e6f3d749c 100644 --- a/documentation20/webdocs/markdowndocs/replica-ch.md +++ b/documentation20/webdocs/markdowndocs/replica-ch.md @@ -66,21 +66,21 @@ TDengine采取的是Master-Slave模式进行同步,与流行的RAFT一致性 数据实时复制有三个主要流程:选主、数据转发、数据恢复。后续做详细讨论。 -## 虚拟节点之间的网络链接 +## 虚拟节点之间的网络连接 -虚拟节点之间通过TCP进行链接,节点之间的状态交换、数据包的转发都是通过这个TCP链接(peerFd)进行。为避免竞争,两个虚拟节点之间的TCP链接,总是由IP地址(UINT32)小的节点作为TCP客户端发起。一旦TCP链接被中断,虚拟节点能通过TCP socket自动检测到,将对方标为offline。如果监测到任何错误(比如数据恢复流程),虚拟节点将主动重置该链接。 +虚拟节点之间通过TCP进行连接,节点之间的状态交换、数据包的转发都是通过这个TCP连接(peerFd)进行。为避免竞争,两个虚拟节点之间的TCP连接,总是由IP地址(UINT32)小的节点作为TCP客户端发起。一旦TCP连接被中断,虚拟节点能通过TCP socket自动检测到,将对方标为offline。如果监测到任何错误(比如数据恢复流程),虚拟节点将主动重置该连接。 -一旦作为客户端的节点链接不成或中断,它将周期性的每隔一秒钟去试图去链接一次。因为TCP本身有心跳机制,虚拟节点之间不再另行提供心跳。 +一旦作为客户端的节点连接不成或中断,它将周期性的每隔一秒钟去试图去连接一次。因为TCP本身有心跳机制,虚拟节点之间不再另行提供心跳。 -如果一个unsynced节点要发起数据恢复流程,它与Master将建立起专有的TCP链接(syncFd)。数据恢复完成后,该链接会被关闭。而且为限制资源的使用,系统只容许一定数量(配置参数tsMaxSyncNum)的数据恢复的socket存在。如果超过这个数字,系统会将新的数据恢复请求延后处理。 +如果一个unsynced节点要发起数据恢复流程,它与Master将建立起专有的TCP连接(syncFd)。数据恢复完成后,该连接会被关闭。而且为限制资源的使用,系统只容许一定数量(配置参数tsMaxSyncNum)的数据恢复的socket存在。如果超过这个数字,系统会将新的数据恢复请求延后处理。 -任意一个节点,无论有多少虚拟节点,都会启动而且只会启动一个TCP server, 来接受来自其他虚拟节点的上述两类TCP的链接请求。当TCP socket建立起来,客户端侧发送的消息体里会带有vgId(全局唯一的vgroup ID), TCP 服务器侧会检查该vgId是否已经在该节点启动运行。如果已经启动运行,就接受其请求。如果不存在,就直接将链接请求关闭。在TDengine代码里,mnode group的vgId设置为1。 +任意一个节点,无论有多少虚拟节点,都会启动而且只会启动一个TCP server, 来接受来自其他虚拟节点的上述两类TCP的连接请求。当TCP socket建立起来,客户端侧发送的消息体里会带有vgId(全局唯一的vgroup ID), TCP 服务器侧会检查该vgId是否已经在该节点启动运行。如果已经启动运行,就接受其请求。如果不存在,就直接将连接请求关闭。在TDengine代码里,mnode group的vgId设置为1。 ## 选主流程 当同一组的两个虚拟节点之间(vnode A, vnode B)建立连接后,他们互换status消息。status消息里包含本地存储的同一虚拟节点组内所有虚拟节点的role和version。 -如果一个虚拟节点(vnode A)检测到与同一虚拟节点组内另外一虚拟节点(vnode B)的链接中断,vnode A将立即把vnode B的role设置为offline。无论是接收到另外一虚拟节点发来的status消息,还是检测与另外一虚拟节点的链接中断,该虚拟节点都将进入状态处理流程。状态处理流程的规则如下: +如果一个虚拟节点(vnode A)检测到与同一虚拟节点组内另外一虚拟节点(vnode B)的连接中断,vnode A将立即把vnode B的role设置为offline。无论是接收到另外一虚拟节点发来的status消息,还是检测与另外一虚拟节点的连接中断,该虚拟节点都将进入状态处理流程。状态处理流程的规则如下: 1. 如果检测到在线的节点数没有超过一半,则将自己的状态设置为unsynced. 2. 如果在线的虚拟节点数超过一半,会检查master节点是否存在,如果存在,则会决定是否将自己状态改为slave或启动数据恢复流程 @@ -118,7 +118,7 @@ TDengine采取的是Master-Slave模式进行同步,与流行的RAFT一致性 9. 如果quorum为1,上述6,7,8步不会发生。 10. 如果要等待slave的确认,master会启动2秒的定时器(可配置),如果超时,则认为失败。 -对于回复确认,sync模块提供的是异步回调函数,因此APP在调用syncForwardToPeer之后,无需等待,可以处理下一个操作。在Master与Slave的TCP链接管道里,可能有多个Forward消息,这些消息是严格按照应用提供的顺序排好的。对于Forward Response也是一样,TCP管道里存在多个,但都是排序好的。这个顺序,SYNC模块并没有做特别的事情,是由APP单线程顺序写来保证的(TDengine里每个vnode的写数据,都是单线程)。 +对于回复确认,sync模块提供的是异步回调函数,因此APP在调用syncForwardToPeer之后,无需等待,可以处理下一个操作。在Master与Slave的TCP连接管道里,可能有多个Forward消息,这些消息是严格按照应用提供的顺序排好的。对于Forward Response也是一样,TCP管道里存在多个,但都是排序好的。这个顺序,SYNC模块并没有做特别的事情,是由APP单线程顺序写来保证的(TDengine里每个vnode的写数据,都是单线程)。 ## 数据恢复流程 @@ -142,9 +142,9 @@ TDengine采取的是Master-Slave模式进行同步,与流行的RAFT一致性
-1. 通过已经建立的TCP链接,发送sync req给master节点 -2. master收到sync req后,以client的身份,向vnode B主动建立一新的专用于同步的TCP链接(syncFd) -3. 新的TCP链接建立成功后,master将开始retrieve流程,对应的,vnode B将同步启动restore流程 +1. 通过已经建立的TCP连接,发送sync req给master节点 +2. master收到sync req后,以client的身份,向vnode B主动建立一新的专用于同步的TCP连接(syncFd) +3. 新的TCP连接建立成功后,master将开始retrieve流程,对应的,vnode B将同步启动restore流程 4. Retrieve/Restore流程里,先处理所有archived data (vnode里的data, head, last文件),后处理WAL data。 5. 对于archived data,master将通过回调函数getFileInfo获取数据文件的基本信息,包括文件名、magic以及文件大小。 6. master 将获得的文件名、magic以及文件大小发给vnode B @@ -157,7 +157,7 @@ TDengine采取的是Master-Slave模式进行同步,与流行的RAFT一致性 1. master节点调用回调函数getWalInfo,获取WAL的文件名。 2. 如果getWalInfo返回值大于0,表示该文件还不是最后一个WAL,因此master调用sendfile一下把该文件发送给vnode B 3. 如果getWalInfo返回时为0,表示该文件是最后一个WAL,因为文件可能还处于写的状态中,sync模块要根据WAL Head的定义逐条读出记录,然后发往vnode B。 -4. vnode A读取TCP链接传来的数据,按照WAL Head,逐条读取,如果版本号比现有的大,调用回调函数writeToCache,交给应用处理。如果小,直接扔掉。 +4. vnode A读取TCP连接传来的数据,按照WAL Head,逐条读取,如果版本号比现有的大,调用回调函数writeToCache,交给应用处理。如果小,直接扔掉。 5. 上述流程循环,直到所有WAL文件都被处理完。处理完后,master就会将新来的数据包通过Forward消息转发给slave。 从同步文件启动起,sync模块会通过inotify监控所有处理过的file以及wal。一旦发现被处理过的文件有更新变化,同步流程将中止,会重新启动。因为有可能落盘操作正在进行(比如历史数据导入,内存数据落盘),把已经处理过的文件进行了修改,需要重新同步才行。 @@ -194,15 +194,15 @@ sync模块通过inotify监控LastWal文件的更新和关闭操作。而且在 因为写入失败,客户端会重新写入数据。但对于TDengine而言,是OK的。因为时序数据都是有时间戳的,时间戳相同的数据更新操作,第一次会执行,但第二次会自动扔掉。对于Meta Data(增加、删除库、表等等)的操作,也是OK的。一张表、库已经被创建或删除,再创建或删除,不会被执行的。 -在TDengine的设计里,虚拟节点与虚拟节点之间,是一个TCP链接,是一个pipeline,数据块一个接一个按顺序在这个pipeline里等待处理。一旦某个数据块的处理失败,这个链接会被重置,后续的数据块的处理都会失败。因此不会存在Pipeline里一个数据块更新失败,但下一个数据块成功的可能。 +在TDengine的设计里,虚拟节点与虚拟节点之间,是一个TCP连接,是一个pipeline,数据块一个接一个按顺序在这个pipeline里等待处理。一旦某个数据块的处理失败,这个连接会被重置,后续的数据块的处理都会失败。因此不会存在Pipeline里一个数据块更新失败,但下一个数据块成功的可能。 ## Split Brain的问题 选举流程中,有个强制要求,那就是一定有超过半数的虚拟节点在线。但是如果replication正好是偶数,这个时候,完全可能存在splt brain问题。 -为解决这个问题,TDengine提供Arbitrator的解决方法。Arbitrator是一个节点,它的任务就是接受任何虚拟节点的链接请求,并保持它。 +为解决这个问题,TDengine提供Arbitrator的解决方法。Arbitrator是一个节点,它的任务就是接受任何虚拟节点的连接请求,并保持它。 -在启动复制模块实例时,在配置参数中,应用可以提供Arbitrator的IP地址。如果是奇数个副本,复制模块不会与这个arbitrator去建立链接,但如果是偶数个副本,就会主动去建立链接。 +在启动复制模块实例时,在配置参数中,应用可以提供Arbitrator的IP地址。如果是奇数个副本,复制模块不会与这个arbitrator去建立连接,但如果是偶数个副本,就会主动去建立连接。 Arbitrator的程序tarbitrator.c在复制模块的同一目录, 编译整个系统时,会在bin目录生成。命令行参数“-?”查看可以配置的参数,比如绑定的IP地址,监听的端口号。 diff --git a/documentation20/webdocs/markdowndocs/taosd-ch.md b/documentation20/webdocs/markdowndocs/taosd-ch.md index 8143137c795ece91eace923d8c4945bc36c27e9b..e90bc2233ffb3efc62a39ca5239bd590136b4125 100644 --- a/documentation20/webdocs/markdowndocs/taosd-ch.md +++ b/documentation20/webdocs/markdowndocs/taosd-ch.md @@ -13,7 +13,7 @@ taosd的启动入口是dnode模块,dnode然后启动其他模块,包括可 该模块负责taosd与taosc, 以及其他数据节点之间的通讯。TDengine没有采取标准的HTTP或gRPC等第三方工具,而是实现了自己的通讯模块RPC。 -考虑到物联网场景下,数据写入的包一般不大,因此除支持TCP链接之外,RPC还支持UDP链接。当数据包小于15K时,RPC将采用UDP方式进行链接,否则将采用TCP链接。对于查询类的消息,RPC不管包的大小,总是采取TCP链接。对于UDP链接,RPC实现了自己的超时、重传、顺序检查等机制,以保证数据可靠传输。 +考虑到物联网场景下,数据写入的包一般不大,因此除支持TCP连接之外,RPC还支持UDP连接。当数据包小于15K时,RPC将采用UDP方式进行连接,否则将采用TCP连接。对于查询类的消息,RPC不管包的大小,总是采取TCP连接。对于UDP连接,RPC实现了自己的超时、重传、顺序检查等机制,以保证数据可靠传输。 RPC模块还提供数据压缩功能,如果数据包的字节数超过系统配置参数compressMsgSize, RPC在传输中将自动压缩数据,以节省带宽。 @@ -25,7 +25,7 @@ RPC模块还提供数据压缩功能,如果数据包的字节数超过系统 - 系统的初始化,包括 - 从文件taos.cfg读取系统配置参数,从文件dnodeCfg.json读取数据节点的配置参数; - - 启动RPC模块,并建立起与taosc通讯的server链接,与其他数据节点通讯的server链接; + - 启动RPC模块,并建立起与taosc通讯的server连接,与其他数据节点通讯的server连接; - 启动并初始化dnode的内部管理, 该模块将扫描该数据节点已有的vnode,并打开它们; - 初始化可配置的模块,如mnode, http, monitor等。 - 数据节点的管理,包括 diff --git a/packaging/tools/makearbi.sh b/packaging/tools/makearbi.sh index bc6179eff2de84086144ef20aae5b5dde00b6470..82808bcae962b2c90d1811d512e18c90419f7211 100755 --- a/packaging/tools/makearbi.sh +++ b/packaging/tools/makearbi.sh @@ -25,9 +25,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/TDengine-enterprise-arbitrator" + install_dir="${release_dir}/TDengine-enterprise-arbitrator-${version}" else - install_dir="${release_dir}/TDengine-arbitrator" + install_dir="${release_dir}/TDengine-arbitrator-${version}" fi # Directories and files. @@ -48,9 +48,9 @@ mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_rpm} ${install_dir} cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/packaging/tools/makearbi_power.sh b/packaging/tools/makearbi_power.sh index 5296cc8e3f334c0ed0f8e5ca30137e367b021929..fd50ecd43878de08e7bb94249da8cb64c3630e6e 100755 --- a/packaging/tools/makearbi_power.sh +++ b/packaging/tools/makearbi_power.sh @@ -25,9 +25,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/PowerDB-enterprise-arbitrator" + install_dir="${release_dir}/PowerDB-enterprise-arbitrator-${version}" else - install_dir="${release_dir}/PowerDB-arbitrator" + install_dir="${release_dir}/PowerDB-arbitrator-${version}" fi # Directories and files. @@ -48,9 +48,9 @@ mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_rpm} ${install_dir} cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index d69a8e6007cb3b7c57214a2cbab555059c757526..e17c678f263cb6b7a0ccbc32250265b9bc5cbd0e 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -32,9 +32,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/TDengine-enterprise-client" + install_dir="${release_dir}/TDengine-enterprise-client-${version}" else - install_dir="${release_dir}/TDengine-client" + install_dir="${release_dir}/TDengine-client-${version}" fi # Directories and files. @@ -125,9 +125,9 @@ fi cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/packaging/tools/makeclient_power.sh b/packaging/tools/makeclient_power.sh index d4be52f67911ee22f6d914cdc6bc6de9c7b0fb06..b4416a68bb30751d5e9b02f5e83186d750d5a935 100755 --- a/packaging/tools/makeclient_power.sh +++ b/packaging/tools/makeclient_power.sh @@ -32,9 +32,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/PowerDB-enterprise-client" + install_dir="${release_dir}/PowerDB-enterprise-client-${version}" else - install_dir="${release_dir}/PowerDB-client" + install_dir="${release_dir}/PowerDB-client-${version}" fi # Directories and files. @@ -164,9 +164,9 @@ fi cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 3958cff53b414d7f1b045d9e73bcfd373d09dbe3..75b45b544e0a4abbf709cc4c5b3a3b55dc315f0f 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -25,9 +25,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/TDengine-enterprise-server" + install_dir="${release_dir}/TDengine-enterprise-server-${version}" else - install_dir="${release_dir}/TDengine-server" + install_dir="${release_dir}/TDengine-server-${version}" fi # Directories and files. @@ -138,9 +138,9 @@ fi cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/packaging/tools/makepkg_power.sh b/packaging/tools/makepkg_power.sh index 744f78e514611125bd0ecce1d53e5534656924c9..3d625900c9d912ff835092c7c5675d618b42b06d 100755 --- a/packaging/tools/makepkg_power.sh +++ b/packaging/tools/makepkg_power.sh @@ -25,9 +25,9 @@ release_dir="${top_dir}/release" #package_name='linux' if [ "$verMode" == "cluster" ]; then - install_dir="${release_dir}/PowerDB-enterprise-server" + install_dir="${release_dir}/PowerDB-enterprise-server-${version}" else - install_dir="${release_dir}/PowerDB-server" + install_dir="${release_dir}/PowerDB-server-${version}" fi # Directories and files. @@ -184,9 +184,9 @@ fi cd ${release_dir} if [ "$verMode" == "cluster" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} elif [ "$verMode" == "edge" ]; then - pkg_name=${install_dir}-${version}-${osType}-${cpuType} + pkg_name=${install_dir}-${osType}-${cpuType} else echo "unknow verMode, nor cluster or edge" exit 1 diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 9368faa0ee961fb8af98df2ddaecf1e9e748bd31..4e2272eb0566569754df5ef6201f3d190f2789c1 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -490,13 +490,13 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn (*env)->CallVoidMethod(env, rowobj, g_rowdataSetBooleanFp, i, (jboolean)(*((char *)row[i]) == 1)); break; case TSDB_DATA_TYPE_TINYINT: - (*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((char *)row[i])); + (*env)->CallVoidMethod(env, rowobj, g_rowdataSetByteFp, i, (jbyte) * ((int8_t *)row[i])); break; case TSDB_DATA_TYPE_SMALLINT: - (*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((short *)row[i])); + (*env)->CallVoidMethod(env, rowobj, g_rowdataSetShortFp, i, (jshort) * ((int16_t *)row[i])); break; case TSDB_DATA_TYPE_INT: - (*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int *)row[i]); + (*env)->CallVoidMethod(env, rowobj, g_rowdataSetIntFp, i, (jint) * (int32_t *)row[i]); break; case TSDB_DATA_TYPE_BIGINT: (*env)->CallVoidMethod(env, rowobj, g_rowdataSetLongFp, i, (jlong) * ((int64_t *)row[i])); diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index be38a7af71ed8b97f9deb001b7bbc4fef80104e6..60e9596ec41ce41f5d727d3016663b752dc32fd0 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -525,7 +525,7 @@ static void do_sum(SQLFunctionCtx *pCtx) { *retVal += pCtx->preAggVals.statis.sum; } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { double *retVal = (double*) pCtx->aOutputBuf; - *retVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.sum)); + *retVal += GET_DOUBLE_VAL((const char*)&(pCtx->preAggVals.statis.sum)); } } else { // computing based on the true data block void *pData = GET_INPUT_CHAR(pCtx); @@ -768,7 +768,7 @@ static void avg_function(SQLFunctionCtx *pCtx) { if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) { *pVal += pCtx->preAggVals.statis.sum; } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { - *pVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.sum)); + *pVal += GET_DOUBLE_VAL((const char *)&(pCtx->preAggVals.statis.sum)); } } else { void *pData = GET_INPUT_CHAR(pCtx); @@ -3516,12 +3516,12 @@ static void spread_function(SQLFunctionCtx *pCtx) { pInfo->max = (double)pCtx->preAggVals.statis.max; } } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { - if (pInfo->min > GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.min))) { - pInfo->min = GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.min)); + if (pInfo->min > GET_DOUBLE_VAL((const char *)&(pCtx->preAggVals.statis.min))) { + pInfo->min = GET_DOUBLE_VAL((const char *)&(pCtx->preAggVals.statis.min)); } - if (pInfo->max < GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.max))) { - pInfo->max = GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.max)); + if (pInfo->max < GET_DOUBLE_VAL((const char *)&(pCtx->preAggVals.statis.max))) { + pInfo->max = GET_DOUBLE_VAL((const char *)&(pCtx->preAggVals.statis.max)); } } diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 590c2829d0b70522467cb48127e0fdde6f1448d6..a15673bdb1edf97fda23d879ab69839fd500549e 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -306,16 +306,16 @@ static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengt switch (type) { case TSDB_DATA_TYPE_BOOL: - sprintf(result, "%s", ((((int)(*((char *)val))) == 1) ? "true" : "false")); + sprintf(result, "%s", ((((int32_t)(*((char *)val))) == 1) ? "true" : "false")); break; case TSDB_DATA_TYPE_TINYINT: - sprintf(result, "%d", (int)(*((char *)val))); + sprintf(result, "%d", *((int8_t *)val)); break; case TSDB_DATA_TYPE_SMALLINT: - sprintf(result, "%d", (int)(*((short *)val))); + sprintf(result, "%d", *((int16_t *)val)); break; case TSDB_DATA_TYPE_INT: - sprintf(result, "%d", *((int *)val)); + sprintf(result, "%d", *((int32_t *)val)); break; case TSDB_DATA_TYPE_BIGINT: sprintf(result, "%"PRId64, *((int64_t *)val)); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 6be547265acf85a20530e58912edd083bf526200..b65d7b7112f27358bab82308d4891b99c6f8daa3 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1688,7 +1688,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col if (pItem->pNode->pParam != NULL) { tSQLExprItem* pParamElem = &pItem->pNode->pParam->a[0]; SStrToken* pToken = &pParamElem->pNode->colInfo; - short sqlOptr = pParamElem->pNode->nSQLOptr; + int16_t sqlOptr = pParamElem->pNode->nSQLOptr; if ((pToken->z == NULL || pToken->n == 0) && (TK_INTEGER != sqlOptr)) /*select count(1) from table*/ { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e84217b38b05581018ca7b61f694d866fe1bd29e..ad677c2194630fb1cc44a3cf7e1d8d68e424159b 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -245,9 +245,8 @@ int tscSendMsgToServer(SSqlObj *pSql) { } void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { - uint64_t handle = (uint64_t) rpcMsg->ahandle; - - void** p = taosCacheAcquireByKey(tscObjCache, &handle, sizeof(uint64_t)); + TSDB_CACHE_PTR_TYPE handle = (TSDB_CACHE_PTR_TYPE) rpcMsg->ahandle; + void** p = taosCacheAcquireByKey(tscObjCache, &handle, sizeof(TSDB_CACHE_PTR_TYPE)); if (p == NULL) { rpcFreeCont(rpcMsg->pCont); return; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index acc93530e3e8f49534aa0c1a8bfb0a22987c9bdd..ac7081ba700cfd9a65069e5d268ea7157ca3727b 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -720,15 +720,15 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) switch (fields[i].type) { case TSDB_DATA_TYPE_TINYINT: - len += sprintf(str + len, "%d", *((char *)row[i])); + len += sprintf(str + len, "%d", *((int8_t *)row[i])); break; case TSDB_DATA_TYPE_SMALLINT: - len += sprintf(str + len, "%d", *((short *)row[i])); + len += sprintf(str + len, "%d", *((int16_t *)row[i])); break; case TSDB_DATA_TYPE_INT: - len += sprintf(str + len, "%d", *((int *)row[i])); + len += sprintf(str + len, "%d", *((int32_t *)row[i])); break; case TSDB_DATA_TYPE_BIGINT: diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 620fe13a9fd37c44b9fa9d25183d5134304a08c3..85c8a5705864ee5dde9a141743d55eb61bc09593 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -141,7 +141,7 @@ void taos_init_imp(void) { int64_t refreshTime = 10; // 10 seconds by default if (tscMetaCache == NULL) { tscMetaCache = taosCacheInit(TSDB_DATA_TYPE_BINARY, refreshTime, false, NULL, "tableMeta"); - tscObjCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, refreshTime/2, false, tscFreeSqlObjInCache, "sqlObj"); + tscObjCache = taosCacheInit(TSDB_CACHE_PTR_KEY, refreshTime / 2, false, tscFreeSqlObjInCache, "sqlObj"); } tscDebug("client is initialized successfully"); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a98b0272b6fe800ba61c1d8dcdac85ae85e8ee8f..d00b39e68beba06945df465ff862e2515938bb26 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1788,8 +1788,8 @@ void registerSqlObj(SSqlObj* pSql) { int32_t ref = T_REF_INC(pSql->pTscObj); tscDebug("%p add to tscObj:%p, ref:%d", pSql, pSql->pTscObj, ref); - uint64_t p = (uint64_t) pSql; - pSql->self = taosCachePut(tscObjCache, &p, sizeof(uint64_t), &p, sizeof(uint64_t), DEFAULT_LIFE_TIME); + TSDB_CACHE_PTR_TYPE p = (TSDB_CACHE_PTR_TYPE) pSql; + pSql->self = taosCachePut(tscObjCache, &p, sizeof(TSDB_CACHE_PTR_TYPE), &p, sizeof(TSDB_CACHE_PTR_TYPE), DEFAULT_LIFE_TIME); } SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cmd) { diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 45ec20ce4533c6bf9a81b045f6f07f02bbe53121..50554ce08e3fb659c1a5915c4c50b09f950324b4 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -219,7 +219,7 @@ static void getStatics_f(const TSKEY *primaryKey, const void *pData, int32_t num } float fv = 0; - fv = GET_FLOAT_VAL(&(data[i])); + fv = GET_FLOAT_VAL((const char*)&(data[i])); dsum += fv; if (fmin > fv) { fmin = fv; @@ -233,17 +233,12 @@ static void getStatics_f(const TSKEY *primaryKey, const void *pData, int32_t num } double csum = 0; - csum = GET_DOUBLE_VAL(sum); + csum = GET_DOUBLE_VAL((const char *)sum); csum += dsum; -#ifdef _TD_ARM_32 - SET_DOUBLE_VAL_ALIGN(sum, &csum); - SET_DOUBLE_VAL_ALIGN(max, &fmax); - SET_DOUBLE_VAL_ALIGN(min, &fmin); -#else - *(double*)sum = csum; - *(double*)max = fmax; - *(double*)min = fmin; -#endif + + SET_DOUBLE_VAL(sum, csum); + SET_DOUBLE_VAL(max, fmax); + SET_DOUBLE_VAL(min, fmin); } static void getStatics_d(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, @@ -264,7 +259,7 @@ static void getStatics_d(const TSKEY *primaryKey, const void *pData, int32_t num } double dv = 0; - dv = GET_DOUBLE_VAL(&(data[i])); + dv = GET_DOUBLE_VAL((const char*)&(data[i])); dsum += dv; if (dmin > dv) { dmin = dv; @@ -278,19 +273,12 @@ static void getStatics_d(const TSKEY *primaryKey, const void *pData, int32_t num } double csum = 0; - csum = GET_DOUBLE_VAL(sum); + csum = GET_DOUBLE_VAL((const char *)sum); csum += dsum; - -#ifdef _TD_ARM_32 - SET_DOUBLE_VAL_ALIGN(sum, &csum); - SET_DOUBLE_VAL_ALIGN(max, &dmax); - SET_DOUBLE_VAL_ALIGN(min, &dmin); -#else - *(double*) sum = csum; - *(double*) max = dmax; - *(double*) min = dmin; -#endif + SET_DOUBLE_PTR(sum, &csum); + SET_DOUBLE_PTR(max, &dmax); + SET_DOUBLE_PTR(min, &dmin); } static void getStatics_bin(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, @@ -493,46 +481,29 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { *((int32_t *)val) = GET_INT32_VAL(src); break; } - case TSDB_DATA_TYPE_FLOAT: { -#ifdef _TD_ARM_32 - float fv = GET_FLOAT_VAL(src); - SET_FLOAT_VAL_ALIGN(val, &fv); -#else - *((float *)val) = GET_FLOAT_VAL(src); -#endif + case TSDB_DATA_TYPE_FLOAT: + SET_FLOAT_VAL(val, GET_FLOAT_VAL(src)); break; - }; - case TSDB_DATA_TYPE_DOUBLE: { -#ifdef _TD_ARM_32 - double dv = GET_DOUBLE_VAL(src); - SET_DOUBLE_VAL_ALIGN(val, &dv); -#else - *((double *)val) = GET_DOUBLE_VAL(src); -#endif + case TSDB_DATA_TYPE_DOUBLE: + SET_DOUBLE_VAL(val, GET_DOUBLE_VAL(src)); break; - }; case TSDB_DATA_TYPE_TIMESTAMP: - case TSDB_DATA_TYPE_BIGINT: { + case TSDB_DATA_TYPE_BIGINT: *((int64_t *)val) = GET_INT64_VAL(src); break; - }; - case TSDB_DATA_TYPE_SMALLINT: { + case TSDB_DATA_TYPE_SMALLINT: *((int16_t *)val) = GET_INT16_VAL(src); break; - }; case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: { + case TSDB_DATA_TYPE_TINYINT: *((int8_t *)val) = GET_INT8_VAL(src); break; - }; - case TSDB_DATA_TYPE_BINARY: { + case TSDB_DATA_TYPE_BINARY: varDataCopy(val, src); break; - }; - case TSDB_DATA_TYPE_NCHAR: { + case TSDB_DATA_TYPE_NCHAR: varDataCopy(val, src); break; - }; default: { memcpy(val, src, len); break; @@ -579,4 +550,4 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf break; } } -} \ No newline at end of file +} diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index ba118d2ccb05152b3d59dcc53fcb81ac0b4b62ce..005def6dc597361436b03c15535840af2bd3461e 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -709,46 +709,21 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu return -1; } -#ifdef _TD_ARM_32 - //memcpy(&payload, &value, sizeof(float)); - float fv = (float)value; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = (float)value; -#endif + SET_FLOAT_VAL(payload, value); } } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { -#ifdef _TD_ARM_32 - //memcpy(&payload, &pVariant->i64Key, sizeof(float)); - float fv = (float)pVariant->i64Key; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = (float)pVariant->i64Key; -#endif + SET_FLOAT_VAL(payload, pVariant->i64Key); } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { -#ifdef _TD_ARM_32 - //memcpy(&payload, &pVariant->dKey, sizeof(float)); - float fv = (float)pVariant->dKey; - SET_FLOAT_VAL_ALIGN(payload, &fv); -#else - *((float *)payload) = (float)pVariant->dKey; -#endif + SET_FLOAT_VAL(payload, pVariant->dKey); } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; return 0; } -#ifdef _TD_ARM_32 float fv = GET_FLOAT_VAL(payload); if (isinf(fv) || isnan(fv) || fv > FLT_MAX || fv < -FLT_MAX) { return -1; } -#else - if (isinf(*((float *)payload)) || isnan(*((float *)payload)) || *((float *)payload) > FLT_MAX || - *((float *)payload) < -FLT_MAX) { - return -1; - } -#endif break; } case TSDB_DATA_TYPE_DOUBLE: { @@ -765,42 +740,21 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu return -1; } -#ifdef _TD_ARM_32 - SET_DOUBLE_VAL_ALIGN(payload, &value); -#else - *((double *)payload) = value; -#endif + SET_DOUBLE_VAL(payload, value); } } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { -#ifdef _TD_ARM_32 - double dv = (double)(pVariant->i64Key); - SET_DOUBLE_VAL_ALIGN(payload, &dv); -#else - *((double *)payload) = (double)pVariant->i64Key; -#endif + SET_DOUBLE_VAL(payload, pVariant->i64Key); } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { -#ifdef _TD_ARM_32 - double dv = (double)(pVariant->dKey); - SET_DOUBLE_VAL_ALIGN(payload, &dv); -#else - *((double *)payload) = pVariant->dKey; -#endif + SET_DOUBLE_VAL(payload, pVariant->dKey); } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; return 0; } -#ifdef _TD_ARM_32 double dv = GET_DOUBLE_VAL(payload); if (isinf(dv) || isnan(dv) || dv > DBL_MAX || dv < -DBL_MAX) { return -1; } -#else - if (isinf(*((double *)payload)) || isnan(*((double *)payload)) || *((double *)payload) > DBL_MAX || - *((double *)payload) < -DBL_MAX) { - return -1; - } -#endif break; } diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 36e2fa426b7647b4b2a3543ffa8470c310dc82b2..99409fe27722fb43f9d9fa50a0c0f17b5c1f76be 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -55,6 +55,7 @@ 4.13 test + diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java index 86938031f6e4a6001bca2c8f2911e6a8f0284cc4..f82c064e751c195eb6327580c285a815346c917b 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java @@ -67,14 +67,23 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public boolean next() throws SQLException { +// boolean ret = false; +// if (rowDataList.size() > 0) { +// ret = rowDataList.iterator().hasNext(); +// if (ret) { +// rowCursor = rowDataList.iterator().next(); +// cursorRowNumber++; +// } +// } +// return ret; + + /**** add by zyyang 2020-09-29 ****************/ boolean ret = false; - if (rowDataList.size() > 0) { - ret = rowDataList.iterator().hasNext(); - if (ret) { - rowCursor = rowDataList.iterator().next(); - cursorRowNumber++; - } + if (!rowDataList.isEmpty() && cursorRowNumber < rowDataList.size()) { + rowCursor = rowDataList.get(cursorRowNumber++); + ret = true; } + return ret; } @@ -91,7 +100,8 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public String getString(int columnIndex) throws SQLException { columnIndex--; - return rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex).getColType(); + return rowCursor.getString(columnIndex, colType); } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java index 15f66fa2029e7c1bf8a3ecf8ec68b53a8455c648..e5515c24b7a298f0d82f5ad5f880fc1a166f9a3f 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java @@ -20,519 +20,519 @@ import java.util.List; public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { - private String dbProductName = null; - private String url = null; - private String userName = null; - private Connection conn = null; - - public TSDBDatabaseMetaData(String dbProductName, String url, String userName) { - this.dbProductName = dbProductName; - this.url = url; - this.userName = userName; - } + private String dbProductName = null; + private String url = null; + private String userName = null; + private Connection conn = null; + + public TSDBDatabaseMetaData(String dbProductName, String url, String userName) { + this.dbProductName = dbProductName; + this.url = url; + this.userName = userName; + } - public void setConnection(Connection conn) { - this.conn = conn; - } + public void setConnection(Connection conn) { + this.conn = conn; + } - public T unwrap(Class iface) throws SQLException { - return null; - } + public T unwrap(Class iface) throws SQLException { + return null; + } - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } - public boolean allProceduresAreCallable() throws SQLException { - return false; - } + public boolean allProceduresAreCallable() throws SQLException { + return false; + } - public boolean allTablesAreSelectable() throws SQLException { - return false; - } + public boolean allTablesAreSelectable() throws SQLException { + return false; + } - public String getURL() throws SQLException { - return this.url; - } + public String getURL() throws SQLException { + return this.url; + } - public String getUserName() throws SQLException { - return this.userName; - } + public String getUserName() throws SQLException { + return this.userName; + } - public boolean isReadOnly() throws SQLException { - return false; - } + public boolean isReadOnly() throws SQLException { + return false; + } - public boolean nullsAreSortedHigh() throws SQLException { - return false; - } + public boolean nullsAreSortedHigh() throws SQLException { + return false; + } - public boolean nullsAreSortedLow() throws SQLException { - return !nullsAreSortedHigh(); - } + public boolean nullsAreSortedLow() throws SQLException { + return !nullsAreSortedHigh(); + } - public boolean nullsAreSortedAtStart() throws SQLException { - return true; - } + public boolean nullsAreSortedAtStart() throws SQLException { + return true; + } - public boolean nullsAreSortedAtEnd() throws SQLException { - return !nullsAreSortedAtStart(); - } + public boolean nullsAreSortedAtEnd() throws SQLException { + return !nullsAreSortedAtStart(); + } - public String getDatabaseProductName() throws SQLException { - return this.dbProductName; - } + public String getDatabaseProductName() throws SQLException { + return this.dbProductName; + } - public String getDatabaseProductVersion() throws SQLException { - return "1.5.1"; - } + public String getDatabaseProductVersion() throws SQLException { + return "1.5.1"; + } - public String getDriverName() throws SQLException { - return TSDBDriver.class.getName(); - } + public String getDriverName() throws SQLException { + return TSDBDriver.class.getName(); + } - public String getDriverVersion() throws SQLException { - return "1.0.0"; - } + public String getDriverVersion() throws SQLException { + return "1.0.0"; + } - public int getDriverMajorVersion() { - return 0; - } + public int getDriverMajorVersion() { + return 0; + } - public int getDriverMinorVersion() { - return 0; - } + public int getDriverMinorVersion() { + return 0; + } - public boolean usesLocalFiles() throws SQLException { - return false; - } + public boolean usesLocalFiles() throws SQLException { + return false; + } - public boolean usesLocalFilePerTable() throws SQLException { - return false; - } + public boolean usesLocalFilePerTable() throws SQLException { + return false; + } - public boolean supportsMixedCaseIdentifiers() throws SQLException { - return false; - } + public boolean supportsMixedCaseIdentifiers() throws SQLException { + return false; + } - public boolean storesUpperCaseIdentifiers() throws SQLException { - return false; - } + public boolean storesUpperCaseIdentifiers() throws SQLException { + return false; + } - public boolean storesLowerCaseIdentifiers() throws SQLException { - return false; - } + public boolean storesLowerCaseIdentifiers() throws SQLException { + return false; + } - public boolean storesMixedCaseIdentifiers() throws SQLException { - return false; - } + public boolean storesMixedCaseIdentifiers() throws SQLException { + return false; + } - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - return false; - } + public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - return false; - } + public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { + return false; + } - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - return false; - } + public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { + return false; + } - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - return false; - } + public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } - public String getIdentifierQuoteString() throws SQLException { - return " "; - } + public String getIdentifierQuoteString() throws SQLException { + return " "; + } - public String getSQLKeywords() throws SQLException { - return null; - } + public String getSQLKeywords() throws SQLException { + return null; + } - public String getNumericFunctions() throws SQLException { - return null; - } + public String getNumericFunctions() throws SQLException { + return null; + } - public String getStringFunctions() throws SQLException { - return null; - } + public String getStringFunctions() throws SQLException { + return null; + } - public String getSystemFunctions() throws SQLException { - return null; - } + public String getSystemFunctions() throws SQLException { + return null; + } - public String getTimeDateFunctions() throws SQLException { - return null; - } + public String getTimeDateFunctions() throws SQLException { + return null; + } - public String getSearchStringEscape() throws SQLException { - return null; - } + public String getSearchStringEscape() throws SQLException { + return null; + } - public String getExtraNameCharacters() throws SQLException { - return null; - } + public String getExtraNameCharacters() throws SQLException { + return null; + } - public boolean supportsAlterTableWithAddColumn() throws SQLException { - return true; - } + public boolean supportsAlterTableWithAddColumn() throws SQLException { + return true; + } - public boolean supportsAlterTableWithDropColumn() throws SQLException { - return true; - } + public boolean supportsAlterTableWithDropColumn() throws SQLException { + return true; + } - public boolean supportsColumnAliasing() throws SQLException { - return true; - } + public boolean supportsColumnAliasing() throws SQLException { + return true; + } - public boolean nullPlusNonNullIsNull() throws SQLException { - return false; - } + public boolean nullPlusNonNullIsNull() throws SQLException { + return false; + } - public boolean supportsConvert() throws SQLException { - return false; - } + public boolean supportsConvert() throws SQLException { + return false; + } - public boolean supportsConvert(int fromType, int toType) throws SQLException { - return false; - } + public boolean supportsConvert(int fromType, int toType) throws SQLException { + return false; + } - public boolean supportsTableCorrelationNames() throws SQLException { - return false; - } + public boolean supportsTableCorrelationNames() throws SQLException { + return false; + } - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - return false; - } + public boolean supportsDifferentTableCorrelationNames() throws SQLException { + return false; + } - public boolean supportsExpressionsInOrderBy() throws SQLException { - return false; - } + public boolean supportsExpressionsInOrderBy() throws SQLException { + return false; + } - public boolean supportsOrderByUnrelated() throws SQLException { - return false; - } + public boolean supportsOrderByUnrelated() throws SQLException { + return false; + } - public boolean supportsGroupBy() throws SQLException { - return false; - } + public boolean supportsGroupBy() throws SQLException { + return false; + } - public boolean supportsGroupByUnrelated() throws SQLException { - return false; - } + public boolean supportsGroupByUnrelated() throws SQLException { + return false; + } - public boolean supportsGroupByBeyondSelect() throws SQLException { - return false; - } + public boolean supportsGroupByBeyondSelect() throws SQLException { + return false; + } - public boolean supportsLikeEscapeClause() throws SQLException { - return false; - } + public boolean supportsLikeEscapeClause() throws SQLException { + return false; + } - public boolean supportsMultipleResultSets() throws SQLException { - return false; - } + public boolean supportsMultipleResultSets() throws SQLException { + return false; + } - public boolean supportsMultipleTransactions() throws SQLException { - return false; - } + public boolean supportsMultipleTransactions() throws SQLException { + return false; + } - public boolean supportsNonNullableColumns() throws SQLException { - return false; - } + public boolean supportsNonNullableColumns() throws SQLException { + return false; + } - public boolean supportsMinimumSQLGrammar() throws SQLException { - return false; - } + public boolean supportsMinimumSQLGrammar() throws SQLException { + return false; + } - public boolean supportsCoreSQLGrammar() throws SQLException { - return false; - } + public boolean supportsCoreSQLGrammar() throws SQLException { + return false; + } - public boolean supportsExtendedSQLGrammar() throws SQLException { - return false; - } + public boolean supportsExtendedSQLGrammar() throws SQLException { + return false; + } - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - return false; - } + public boolean supportsANSI92EntryLevelSQL() throws SQLException { + return false; + } - public boolean supportsANSI92IntermediateSQL() throws SQLException { - return false; - } + public boolean supportsANSI92IntermediateSQL() throws SQLException { + return false; + } - public boolean supportsANSI92FullSQL() throws SQLException { - return false; - } + public boolean supportsANSI92FullSQL() throws SQLException { + return false; + } - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - return false; - } + public boolean supportsIntegrityEnhancementFacility() throws SQLException { + return false; + } - public boolean supportsOuterJoins() throws SQLException { - return false; - } + public boolean supportsOuterJoins() throws SQLException { + return false; + } - public boolean supportsFullOuterJoins() throws SQLException { - return false; - } + public boolean supportsFullOuterJoins() throws SQLException { + return false; + } - public boolean supportsLimitedOuterJoins() throws SQLException { - return false; - } + public boolean supportsLimitedOuterJoins() throws SQLException { + return false; + } - public String getSchemaTerm() throws SQLException { - return null; - } + public String getSchemaTerm() throws SQLException { + return null; + } - public String getProcedureTerm() throws SQLException { - return null; - } + public String getProcedureTerm() throws SQLException { + return null; + } - public String getCatalogTerm() throws SQLException { - return "database"; - } + public String getCatalogTerm() throws SQLException { + return "database"; + } - public boolean isCatalogAtStart() throws SQLException { - return true; - } + public boolean isCatalogAtStart() throws SQLException { + return true; + } - public String getCatalogSeparator() throws SQLException { - return "."; - } + public String getCatalogSeparator() throws SQLException { + return "."; + } - public boolean supportsSchemasInDataManipulation() throws SQLException { - return false; - } + public boolean supportsSchemasInDataManipulation() throws SQLException { + return false; + } - public boolean supportsSchemasInProcedureCalls() throws SQLException { - return false; - } + public boolean supportsSchemasInProcedureCalls() throws SQLException { + return false; + } - public boolean supportsSchemasInTableDefinitions() throws SQLException { - return false; - } + public boolean supportsSchemasInTableDefinitions() throws SQLException { + return false; + } - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - return false; - } + public boolean supportsSchemasInIndexDefinitions() throws SQLException { + return false; + } - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return false; - } + public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { + return false; + } - public boolean supportsCatalogsInDataManipulation() throws SQLException { - return true; - } + public boolean supportsCatalogsInDataManipulation() throws SQLException { + return true; + } - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - return false; - } + public boolean supportsCatalogsInProcedureCalls() throws SQLException { + return false; + } - public boolean supportsCatalogsInTableDefinitions() throws SQLException { - return false; - } + public boolean supportsCatalogsInTableDefinitions() throws SQLException { + return false; + } - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return false; - } + public boolean supportsCatalogsInIndexDefinitions() throws SQLException { + return false; + } - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return false; - } + public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { + return false; + } - public boolean supportsPositionedDelete() throws SQLException { - return false; - } + public boolean supportsPositionedDelete() throws SQLException { + return false; + } - public boolean supportsPositionedUpdate() throws SQLException { - return false; - } + public boolean supportsPositionedUpdate() throws SQLException { + return false; + } - public boolean supportsSelectForUpdate() throws SQLException { - return false; - } + public boolean supportsSelectForUpdate() throws SQLException { + return false; + } - public boolean supportsStoredProcedures() throws SQLException { - return false; - } + public boolean supportsStoredProcedures() throws SQLException { + return false; + } - public boolean supportsSubqueriesInComparisons() throws SQLException { - return false; - } + public boolean supportsSubqueriesInComparisons() throws SQLException { + return false; + } - public boolean supportsSubqueriesInExists() throws SQLException { - return false; - } + public boolean supportsSubqueriesInExists() throws SQLException { + return false; + } - public boolean supportsSubqueriesInIns() throws SQLException { - return false; - } + public boolean supportsSubqueriesInIns() throws SQLException { + return false; + } - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - return false; - } + public boolean supportsSubqueriesInQuantifieds() throws SQLException { + return false; + } - public boolean supportsCorrelatedSubqueries() throws SQLException { - return false; - } + public boolean supportsCorrelatedSubqueries() throws SQLException { + return false; + } - public boolean supportsUnion() throws SQLException { - return false; - } + public boolean supportsUnion() throws SQLException { + return false; + } - public boolean supportsUnionAll() throws SQLException { - return false; - } + public boolean supportsUnionAll() throws SQLException { + return false; + } - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - return false; - } + public boolean supportsOpenCursorsAcrossCommit() throws SQLException { + return false; + } - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - return false; - } + public boolean supportsOpenCursorsAcrossRollback() throws SQLException { + return false; + } - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - return false; - } + public boolean supportsOpenStatementsAcrossCommit() throws SQLException { + return false; + } - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - return false; - } + public boolean supportsOpenStatementsAcrossRollback() throws SQLException { + return false; + } - public int getMaxBinaryLiteralLength() throws SQLException { - return 0; - } + public int getMaxBinaryLiteralLength() throws SQLException { + return 0; + } - public int getMaxCharLiteralLength() throws SQLException { - return 0; - } + public int getMaxCharLiteralLength() throws SQLException { + return 0; + } - public int getMaxColumnNameLength() throws SQLException { - return 0; - } + public int getMaxColumnNameLength() throws SQLException { + return 0; + } - public int getMaxColumnsInGroupBy() throws SQLException { - return 0; - } + public int getMaxColumnsInGroupBy() throws SQLException { + return 0; + } - public int getMaxColumnsInIndex() throws SQLException { - return 0; - } + public int getMaxColumnsInIndex() throws SQLException { + return 0; + } - public int getMaxColumnsInOrderBy() throws SQLException { - return 0; - } + public int getMaxColumnsInOrderBy() throws SQLException { + return 0; + } - public int getMaxColumnsInSelect() throws SQLException { - return 0; - } - - public int getMaxColumnsInTable() throws SQLException { - return 0; - } - - public int getMaxConnections() throws SQLException { - return 0; - } - - public int getMaxCursorNameLength() throws SQLException { - return 0; - } - - public int getMaxIndexLength() throws SQLException { - return 0; - } - - public int getMaxSchemaNameLength() throws SQLException { - return 0; - } - - public int getMaxProcedureNameLength() throws SQLException { - return 0; - } - - public int getMaxCatalogNameLength() throws SQLException { - return 0; - } - - public int getMaxRowSize() throws SQLException { - return 0; - } - - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - return false; - } - - public int getMaxStatementLength() throws SQLException { - return 0; - } - - public int getMaxStatements() throws SQLException { - return 0; - } - - public int getMaxTableNameLength() throws SQLException { - return 0; - } - - public int getMaxTablesInSelect() throws SQLException { - return 0; - } - - public int getMaxUserNameLength() throws SQLException { - return 0; - } - - public int getDefaultTransactionIsolation() throws SQLException { - return 0; - } - - public boolean supportsTransactions() throws SQLException { - return false; - } - - public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - return false; - } - - public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - return false; - } - - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - return false; - } - - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - return false; - } - - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - return false; - } - - public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) - throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, - String columnNamePattern) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); - } - - public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) - throws SQLException { - Statement stmt = null; - if (null != conn && !conn.isClosed()) { - stmt = conn.createStatement(); - if (catalog == null || catalog.length() < 1) { - catalog = conn.getCatalog(); - } + public int getMaxColumnsInSelect() throws SQLException { + return 0; + } + + public int getMaxColumnsInTable() throws SQLException { + return 0; + } + + public int getMaxConnections() throws SQLException { + return 0; + } + + public int getMaxCursorNameLength() throws SQLException { + return 0; + } + + public int getMaxIndexLength() throws SQLException { + return 0; + } + + public int getMaxSchemaNameLength() throws SQLException { + return 0; + } + + public int getMaxProcedureNameLength() throws SQLException { + return 0; + } + + public int getMaxCatalogNameLength() throws SQLException { + return 0; + } + + public int getMaxRowSize() throws SQLException { + return 0; + } + + public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { + return false; + } + + public int getMaxStatementLength() throws SQLException { + return 0; + } + + public int getMaxStatements() throws SQLException { + return 0; + } + + public int getMaxTableNameLength() throws SQLException { + return 0; + } + + public int getMaxTablesInSelect() throws SQLException { + return 0; + } + + public int getMaxUserNameLength() throws SQLException { + return 0; + } + + public int getDefaultTransactionIsolation() throws SQLException { + return 0; + } + + public boolean supportsTransactions() throws SQLException { + return false; + } + + public boolean supportsTransactionIsolationLevel(int level) throws SQLException { + return false; + } + + public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + return false; + } + + public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + return false; + } + + public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + return false; + } + + public boolean dataDefinitionIgnoredInTransactions() throws SQLException { + return false; + } + + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) + throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, + String columnNamePattern) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException { + Statement stmt = null; + if (null != conn && !conn.isClosed()) { + stmt = conn.createStatement(); + if (catalog == null || catalog.length() < 1) { + catalog = conn.getCatalog(); + } stmt.executeUpdate("use " + catalog); ResultSet resultSet0 = stmt.executeQuery("show tables"); GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types); @@ -540,29 +540,29 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { } else { throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); } - } + } - public ResultSet getSchemas() throws SQLException { - return getEmptyResultSet(); - } + public ResultSet getSchemas() throws SQLException { + return getEmptyResultSet(); + } - public ResultSet getCatalogs() throws SQLException { + public ResultSet getCatalogs() throws SQLException { - if (conn != null && !conn.isClosed()) { - Statement stmt = conn.createStatement(); - ResultSet resultSet0 = stmt.executeQuery("show databases"); - CatalogResultSet resultSet = new CatalogResultSet(resultSet0); - return resultSet; - } else { - return getEmptyResultSet(); + if (conn != null && !conn.isClosed()) { + Statement stmt = conn.createStatement(); + ResultSet resultSet0 = stmt.executeQuery("show databases"); + CatalogResultSet resultSet = new CatalogResultSet(resultSet0); + return resultSet; + } else { + return getEmptyResultSet(); } - } + } - public ResultSet getTableTypes() throws SQLException { - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + public ResultSet getTableTypes() throws SQLException { + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList(1); + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList(1); ColumnMetaData colMetaData = new ColumnMetaData(); colMetaData.setColIndex(0); colMetaData.setColName("TABLE_TYPE"); @@ -582,220 +582,384 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { resultSet.setColumnMetaDataList(columnMetaDataList); resultSet.setRowDataList(rowDataList); return resultSet; - } - - public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) - throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) - throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) - throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) - throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, - String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getTypeInfo() throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) - throws SQLException { - return getEmptyResultSet(); - } - - public boolean supportsResultSetType(int type) throws SQLException { - return false; - } - - public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { - return false; - } - - public boolean ownUpdatesAreVisible(int type) throws SQLException { - return false; - } - - public boolean ownDeletesAreVisible(int type) throws SQLException { - return false; - } - - public boolean ownInsertsAreVisible(int type) throws SQLException { - return false; - } - - public boolean othersUpdatesAreVisible(int type) throws SQLException { - return false; - } - - public boolean othersDeletesAreVisible(int type) throws SQLException { - return false; - } - - public boolean othersInsertsAreVisible(int type) throws SQLException { - return false; - } - - public boolean updatesAreDetected(int type) throws SQLException { - return false; - } - - public boolean deletesAreDetected(int type) throws SQLException { - return false; - } - - public boolean insertsAreDetected(int type) throws SQLException { - return false; - } - - public boolean supportsBatchUpdates() throws SQLException { - return false; - } - - public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) - throws SQLException { - return getEmptyResultSet(); - } - - public Connection getConnection() throws SQLException { - return null; - } - - public boolean supportsSavepoints() throws SQLException { - return false; - } - - public boolean supportsNamedParameters() throws SQLException { - return false; - } - - public boolean supportsMultipleOpenResults() throws SQLException { - return false; - } - - public boolean supportsGetGeneratedKeys() throws SQLException { - return false; - } - - public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, - String attributeNamePattern) throws SQLException { - return getEmptyResultSet(); - } - - public boolean supportsResultSetHoldability(int holdability) throws SQLException { - return false; - } - - public int getResultSetHoldability() throws SQLException { - return 0; - } - - public int getDatabaseMajorVersion() throws SQLException { - return 0; - } - - public int getDatabaseMinorVersion() throws SQLException { - return 0; - } - - public int getJDBCMajorVersion() throws SQLException { - return 0; - } - - public int getJDBCMinorVersion() throws SQLException { - return 0; - } - - public int getSQLStateType() throws SQLException { - return 0; - } - - public boolean locatorsUpdateCopy() throws SQLException { - return false; - } - - public boolean supportsStatementPooling() throws SQLException { - return false; - } - - public RowIdLifetime getRowIdLifetime() throws SQLException { - return null; - } - - public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - return null; - } - - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - return false; - } - - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - return false; - } - - public ResultSet getClientInfoProperties() throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) - throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, - String columnNamePattern) throws SQLException { - return getEmptyResultSet(); - } - - public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, - String columnNamePattern) throws SQLException { - return getEmptyResultSet(); - } - - public boolean generatedKeyAlwaysReturned() throws SQLException { - return false; - } - - private ResultSet getEmptyResultSet() { - return new EmptyResultSet(); - } + } + + public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { + + + /** add by zyyang **********/ + Statement stmt = null; + if (null != conn && !conn.isClosed()) { + stmt = conn.createStatement(); + if (catalog == null || catalog.length() < 1) { + catalog = conn.getCatalog(); + } + stmt.executeUpdate("use " + catalog); + + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList<>(24); + columnMetaDataList.add(null); + columnMetaDataList.add(null); + // add TABLE_NAME + ColumnMetaData colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(3); + colMetaData.setColName("TABLE_NAME"); + colMetaData.setColSize(193); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add COLUMN_NAME + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(4); + colMetaData.setColName("COLUMN_NAME"); + colMetaData.setColSize(65); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add DATA_TYPE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(5); + colMetaData.setColName("DATA_TYPE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add TYPE_NAME + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(6); + colMetaData.setColName("TYPE_NAME"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add COLUMN_SIZE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(7); + colMetaData.setColName("COLUMN_SIZE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add BUFFER_LENGTH ,not used + columnMetaDataList.add(null); + // add DECIMAL_DIGITS + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(9); + colMetaData.setColName("DECIMAL_DIGITS"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add NUM_PREC_RADIX + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(10); + colMetaData.setColName("NUM_PREC_RADIX"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add NULLABLE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(11); + colMetaData.setColName("NULLABLE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + + resultSet.setColumnMetaDataList(columnMetaDataList); + + // set up rowDataList + ResultSet resultSet0 = stmt.executeQuery("describe " + tableNamePattern); + List rowDataList = new ArrayList<>(); + int index = 0; + while (resultSet0.next()) { + TSDBResultSetRowData rowData = new TSDBResultSetRowData(24); + // set TABLE_NAME + rowData.setString(2, tableNamePattern); + // set COLUMN_NAME + rowData.setString(3, resultSet0.getString(1)); + // set DATA_TYPE + String typeName = resultSet0.getString(2); + rowData.setInt(4, getDataType(typeName)); + // set TYPE_NAME + rowData.setString(5, typeName); + // set COLUMN_SIZE + int length = resultSet0.getInt(3); + rowData.setInt(6, getColumnSize(typeName, length)); + // set DECIMAL_DIGITS + rowData.setInt(8, getDecimalDigits(typeName)); + // set NUM_PREC_RADIX + rowData.setInt(9, 10); + // set NULLABLE + rowData.setInt(10, getNullable(index, typeName)); + rowDataList.add(rowData); + index++; + } + resultSet.setRowDataList(rowDataList); + +// GetColumnsResultSet getColumnsResultSet = new GetColumnsResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, columnNamePattern); +// return getColumnsResultSet; +// DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + return resultSet; + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } + + /*************************/ + +// return getEmptyResultSet(); + } + + private int getNullable(int index, String typeName) { + if (index == 0 && "TIMESTAMP".equals(typeName)) + return DatabaseMetaData.columnNoNulls; + return DatabaseMetaData.columnNullable; + } + + private int getColumnSize(String typeName, int length) { + switch (typeName) { + case "TIMESTAMP": + return 23; + + default: + return 0; + } + } + + private int getDecimalDigits(String typeName) { + switch (typeName) { + case "FLOAT": + return 5; + case "DOUBLE": + return 9; + default: + return 0; + } + } + + private int getDataType(String typeName) { + switch (typeName) { + case "TIMESTAMP": + return Types.TIMESTAMP; + case "INT": + return Types.INTEGER; + case "BIGINT": + return Types.BIGINT; + case "FLOAT": + return Types.FLOAT; + case "DOUBLE": + return Types.DOUBLE; + case "BINARY": + return Types.BINARY; + case "SMALLINT": + return Types.SMALLINT; + case "TINYINT": + return Types.TINYINT; + case "BOOL": + return Types.BOOLEAN; + case "NCHAR": + return Types.NCHAR; + default: + return Types.NULL; + } + } + + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, + String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTypeInfo() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetType(int type) throws SQLException { + return false; + } + + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + return false; + } + + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean updatesAreDetected(int type) throws SQLException { + return false; + } + + public boolean deletesAreDetected(int type) throws SQLException { + return false; + } + + public boolean insertsAreDetected(int type) throws SQLException { + return false; + } + + public boolean supportsBatchUpdates() throws SQLException { + return false; + } + + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return getEmptyResultSet(); + } + + public Connection getConnection() throws SQLException { + return null; + } + + public boolean supportsSavepoints() throws SQLException { + return false; + } + + public boolean supportsNamedParameters() throws SQLException { + return false; + } + + public boolean supportsMultipleOpenResults() throws SQLException { + return false; + } + + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; + } + + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, + String attributeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + return false; + } + + public int getResultSetHoldability() throws SQLException { + return 0; + } + + public int getDatabaseMajorVersion() throws SQLException { + return 0; + } + + public int getDatabaseMinorVersion() throws SQLException { + return 0; + } + + public int getJDBCMajorVersion() throws SQLException { + return 0; + } + + public int getJDBCMinorVersion() throws SQLException { + return 0; + } + + public int getSQLStateType() throws SQLException { + return 0; + } + + public boolean locatorsUpdateCopy() throws SQLException { + return false; + } + + public boolean supportsStatementPooling() throws SQLException { + return false; + } + + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; + } + + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; + } + + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; + } + + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; + } + + public ResultSet getClientInfoProperties() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean generatedKeyAlwaysReturned() throws SQLException { + return false; + } + + private ResultSet getEmptyResultSet() { + return new EmptyResultSet(); + } } \ No newline at end of file diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index c968246a68e0f8db8c55f8964a9332b17a30fdcc..8f87a45fb724b667236e7ebb5a47460975dac362 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -464,7 +464,14 @@ void dnodeUpdateMnodeEpSetForPeer(SRpcEpSet *pEpSet) { dInfo("mnode EP list for peer is changed, numOfEps:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse); for (int i = 0; i < pEpSet->numOfEps; ++i) { pEpSet->port[i] -= TSDB_PORT_DNODEDNODE; - dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]) + dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]); + + if (!mnodeIsRunning()) { + if (strcmp(pEpSet->fqdn[i], tsLocalFqdn) == 0 && pEpSet->port[i] == tsServerPort) { + dInfo("mnode index:%d %s:%u should work as master", i, pEpSet->fqdn[i], pEpSet->port[i]); + sdbUpdateSync(); + } + } } tsDMnodeEpSet = *pEpSet; diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index f636cde8e5bc66314152a74a91a005551f4b9ec1..25814a748e4bb1a1951c93979e26daabeffe6e2e 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -64,7 +64,7 @@ extern const int32_t TYPE_BYTES[11]; // TODO: replace and remove code below #define CHAR_BYTES sizeof(char) #define SHORT_BYTES sizeof(int16_t) -#define INT_BYTES sizeof(int) +#define INT_BYTES sizeof(int32_t) #define LONG_BYTES sizeof(int64_t) #define FLOAT_BYTES sizeof(float) #define DOUBLE_BYTES sizeof(double) @@ -73,7 +73,7 @@ extern const int32_t TYPE_BYTES[11]; #define TSDB_DATA_BOOL_NULL 0x02 #define TSDB_DATA_TINYINT_NULL 0x80 #define TSDB_DATA_SMALLINT_NULL 0x8000 -#define TSDB_DATA_INT_NULL 0x80000000 +#define TSDB_DATA_INT_NULL 0x80000000L #define TSDB_DATA_BIGINT_NULL 0x8000000000000000L #define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN @@ -132,21 +132,30 @@ do { \ #define GET_INT32_VAL(x) (*(int32_t *)(x)) #define GET_INT64_VAL(x) (*(int64_t *)(x)) #ifdef _TD_ARM_32 - #define GET_FLOAT_VAL(x) taos_align_get_float(x) - #define GET_DOUBLE_VAL(x) taos_align_get_double(x) - - float taos_align_get_float(const char* pBuf); - double taos_align_get_double(const char* pBuf); //#define __float_align_declear() float __underlyFloat = 0.0; //#define __float_align_declear() //#define GET_FLOAT_VAL_ALIGN(x) (*(int32_t*)&(__underlyFloat) = *(int32_t*)(x); __underlyFloat); // notes: src must be float or double type variable !!! - #define SET_FLOAT_VAL_ALIGN(dst, src) (*(int32_t*) dst = *(int32_t*)src); - #define SET_DOUBLE_VAL_ALIGN(dst, src) (*(int64_t*) dst = *(int64_t*)src); + //#define SET_FLOAT_VAL_ALIGN(dst, src) (*(int32_t*) dst = *(int32_t*)src); + //#define SET_DOUBLE_VAL_ALIGN(dst, src) (*(int64_t*) dst = *(int64_t*)src); + + float taos_align_get_float(const char* pBuf); + double taos_align_get_double(const char* pBuf); + + #define GET_FLOAT_VAL(x) taos_align_get_float(x) + #define GET_DOUBLE_VAL(x) taos_align_get_double(x) + #define SET_FLOAT_VAL(x, y) { float z = (float)(y); (*(int32_t*) x = *(int32_t*)(&z)); } + #define SET_DOUBLE_VAL(x, y) { double z = (double)(y); (*(int64_t*) x = *(int64_t*)(&z)); } + #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); } + #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); } #else - #define GET_FLOAT_VAL(x) (*(float *)(x)) - #define GET_DOUBLE_VAL(x) (*(double *)(x)) + #define GET_FLOAT_VAL(x) (*(float *)(x)) + #define GET_DOUBLE_VAL(x) (*(double *)(x)) + #define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); } + #define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); } + #define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); } + #define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); } #endif typedef struct tDataTypeDescriptor { @@ -295,7 +304,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf #define TSDB_MIN_VNODES 64 #define TSDB_MAX_VNODES 2048 #define TSDB_MIN_VNODES_PER_DB 2 -#define TSDB_MAX_VNODES_PER_DB 16 +#define TSDB_MAX_VNODES_PER_DB 64 #define TSDB_DNODE_ROLE_ANY 0 #define TSDB_DNODE_ROLE_MGMT 1 diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 781b5897a19e77ab10a6959614658cba9ea4f798..b5d22ea80c2c0a9f338b537c3452929d0141e6e5 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -248,6 +248,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "Sync modul // wal TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal") +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, 0, 0x1001, "WAL file is corrupted") // http TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_SERVER_OFFLINE, 0, 0x1100, "http server is not onlin") diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 1d1ca1c42bbb921adef67b63511d4c70be8ccf2e..d5e826fbaabfbf76dfac0256935f3222b53cd70a 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -419,16 +419,16 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { case TSDB_DATA_TYPE_BOOL: - fprintf(fp, "%d", ((((int)(*((char *)val))) == 1) ? 1 : 0)); + fprintf(fp, "%d", ((((int32_t)(*((char *)val))) == 1) ? 1 : 0)); break; case TSDB_DATA_TYPE_TINYINT: - fprintf(fp, "%d", (int)(*((char *)val))); + fprintf(fp, "%d", *((int8_t *)val)); break; case TSDB_DATA_TYPE_SMALLINT: - fprintf(fp, "%d", (int)(*((short *)val))); + fprintf(fp, "%d", *((int16_t *)val)); break; case TSDB_DATA_TYPE_INT: - fprintf(fp, "%d", *((int *)val)); + fprintf(fp, "%d", *((int32_t *)val)); break; case TSDB_DATA_TYPE_BIGINT: fprintf(fp, "%" PRId64, *((int64_t *)val)); @@ -559,16 +559,16 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { case TSDB_DATA_TYPE_BOOL: - printf("%*s", width, ((((int)(*((char *)val))) == 1) ? "true" : "false")); + printf("%*s", width, ((((int32_t)(*((char *)val))) == 1) ? "true" : "false")); break; case TSDB_DATA_TYPE_TINYINT: - printf("%*d", width, (int)(*((char *)val))); + printf("%*d", width, *((int8_t *)val)); break; case TSDB_DATA_TYPE_SMALLINT: - printf("%*d", width, (int)(*((short *)val))); + printf("%*d", width, *((int16_t *)val)); break; case TSDB_DATA_TYPE_INT: - printf("%*d", width, *((int *)val)); + printf("%*d", width, *((int32_t *)val)); break; case TSDB_DATA_TYPE_BIGINT: printf("%*" PRId64, width, *((int64_t *)val)); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 646c17b2b8b64344afb7c5117f2bd83b3da89dab..4c672eb557427d76f0989a4d8975eb7f7856c39e 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -185,7 +185,11 @@ static int32_t sdbInitWal() { } sdbInfo("open sdb wal for restore"); - walRestore(tsSdbObj.wal, NULL, sdbWrite); + int code = walRestore(tsSdbObj.wal, NULL, sdbWrite); + if (code != TSDB_CODE_SUCCESS) { + sdbError("failed to open wal for restore, reason:%s", tstrerror(code)); + return -1; + } return 0; } diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index f2caf30564439c0a93e6a333df08dab261cb6143..e587758e465d7a138275862ad411af884c0b78ec 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -65,7 +65,7 @@ int32_t mnodeInitShow() { mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg); - tsMnodeShowCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, 5, true, mnodeFreeShowObj, "show"); + tsMnodeShowCache = taosCacheInit(TSDB_CACHE_PTR_KEY, 5, true, mnodeFreeShowObj, "show"); return 0; } @@ -378,8 +378,8 @@ static bool mnodeCheckShowFinished(SShowObj *pShow) { } static bool mnodeAccquireShowObj(SShowObj *pShow) { - uint64_t handleVal = (uint64_t)pShow; - SShowObj **ppShow = taosCacheAcquireByKey(tsMnodeShowCache, &handleVal, sizeof(int64_t)); + TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pShow; + SShowObj **ppShow = taosCacheAcquireByKey(tsMnodeShowCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE)); if (ppShow) { mDebug("%p, show is accquired from cache, data:%p, index:%d", pShow, ppShow, pShow->index); return true; @@ -393,8 +393,8 @@ static void* mnodePutShowObj(SShowObj *pShow) { if (tsMnodeShowCache != NULL) { pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1); - uint64_t handleVal = (uint64_t)pShow; - SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(int64_t), &pShow, sizeof(int64_t), DEFAULT_SHOWHANDLE_LIFE_SPAN); + TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pShow; + SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE), &pShow, sizeof(TSDB_CACHE_PTR_TYPE), DEFAULT_SHOWHANDLE_LIFE_SPAN); pShow->ppShow = (void**)ppShow; mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index); return pShow; diff --git a/src/os/inc/osDir.h b/src/os/inc/osDir.h index 4a522dadb590bdeebe130850ad4bd73cfc37bb8d..67cfdb3b530a7db17b834a1443d681e1cd5361a7 100644 --- a/src/os/inc/osDir.h +++ b/src/os/inc/osDir.h @@ -20,6 +20,8 @@ extern "C" { #endif +#include + // TAOS_OS_FUNC_DIR void taosRemoveDir(char *rootDir); int taosMkDir(const char *pathname, mode_t mode); diff --git a/src/plugins/http/src/httpGcJson.c b/src/plugins/http/src/httpGcJson.c index fde8ae2176007b1f042393d8d1fc112198c3ff64..80e4ae3bc2b51387d5573af00aa1e91d2c1cd663 100644 --- a/src/plugins/http/src/httpGcJson.c +++ b/src/plugins/http/src/httpGcJson.c @@ -148,10 +148,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%" PRId64, fields[i].name, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, *((float *)row[i])); + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, GET_FLOAT_VAL(row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, *((double *)row[i])); + len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: @@ -210,10 +210,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, httpJsonInt64(jsonBuf, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT: - httpJsonFloat(jsonBuf, *((float *)row[i])); + httpJsonFloat(jsonBuf, GET_FLOAT_VAL(row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - httpJsonDouble(jsonBuf, *((double *)row[i])); + httpJsonDouble(jsonBuf, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: diff --git a/src/plugins/http/src/httpRestJson.c b/src/plugins/http/src/httpRestJson.c index f8912331a367d2f5fe0e5b659bd6b4a4ad1f43ae..954678c24c8fb4597ef3184d2d65060c6d159aa1 100644 --- a/src/plugins/http/src/httpRestJson.c +++ b/src/plugins/http/src/httpRestJson.c @@ -124,10 +124,10 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, httpJsonInt64(jsonBuf, *((int64_t *)row[i])); break; case TSDB_DATA_TYPE_FLOAT: - httpJsonFloat(jsonBuf, *((float *)row[i])); + httpJsonFloat(jsonBuf, GET_FLOAT_VAL(row[i])); break; case TSDB_DATA_TYPE_DOUBLE: - httpJsonDouble(jsonBuf, *((double *)row[i])); + httpJsonDouble(jsonBuf, GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 9d887db9cd8887020a912d29d8291f2139ea0e50..77a402c7bef84157c6188c9482086e8f62310882 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7046,7 +7046,7 @@ void* qOpenQueryMgmt(int32_t vgId) { return NULL; } - pQueryMgmt->qinfoPool = taosCacheInit(TSDB_DATA_TYPE_BIGINT, REFRESH_HANDLE_INTERVAL, true, freeqinfoFn, cacheName); + pQueryMgmt->qinfoPool = taosCacheInit(TSDB_CACHE_PTR_KEY, REFRESH_HANDLE_INTERVAL, true, freeqinfoFn, cacheName); pQueryMgmt->closed = false; pQueryMgmt->vgId = vgId; @@ -7115,23 +7115,23 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) { qError("QInfo:%p failed to add qhandle into cache, since qMgmt is colsing", (void *)qInfo); return NULL; } else { - uint64_t handleVal = (uint64_t) qInfo; - - void** handle = taosCachePut(pQueryMgmt->qinfoPool, &handleVal, sizeof(int64_t), &qInfo, POINTER_BYTES, DEFAULT_QHANDLE_LIFE_SPAN); + TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE) qInfo; + void** handle = taosCachePut(pQueryMgmt->qinfoPool, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE), &qInfo, sizeof(TSDB_CACHE_PTR_TYPE), DEFAULT_QHANDLE_LIFE_SPAN); // pthread_mutex_unlock(&pQueryMgmt->lock); return handle; } } -void** qAcquireQInfo(void* pMgmt, uint64_t key) { +void** qAcquireQInfo(void* pMgmt, uint64_t _key) { SQueryMgmt *pQueryMgmt = pMgmt; if (pQueryMgmt->qinfoPool == NULL || pQueryMgmt->closed) { return NULL; } - void** handle = taosCacheAcquireByKey(pQueryMgmt->qinfoPool, &key, sizeof(uint64_t)); + TSDB_CACHE_PTR_TYPE key = (TSDB_CACHE_PTR_TYPE)_key; + void** handle = taosCacheAcquireByKey(pQueryMgmt->qinfoPool, &key, sizeof(TSDB_CACHE_PTR_TYPE)); if (handle == NULL || *handle == NULL) { return NULL; } else { diff --git a/src/rpc/src/rpcCache.c b/src/rpc/src/rpcCache.c index 751f03e52ac3d8b4cb1a36f7330bbd4c7faef328..46b0d4e3bb9428f98c1022556f2f57c6ec0e9a14 100644 --- a/src/rpc/src/rpcCache.c +++ b/src/rpc/src/rpcCache.c @@ -216,6 +216,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) { if (pCache == NULL || pCache->maxSessions == 0) return; if (pCache->pTimer != tmrId) return; + pthread_mutex_lock(&pCache->mutex); uint64_t time = taosGetTimestampMs(); for (hash = 0; hash < pCache->maxSessions; ++hash) { @@ -227,6 +228,7 @@ static void rpcCleanConnCache(void *handle, void *tmrId) { // tTrace("timer, total connections in cache:%d", pCache->total); taosTmrReset(rpcCleanConnCache, (int32_t)(pCache->keepTimer * 2), pCache, pCache->tmrCtrl, &pCache->pTimer); + pthread_mutex_unlock(&pCache->mutex); } static void rpcRemoveExpiredNodes(SConnCache *pCache, SConnHash *pNode, int hash, uint64_t time) { diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index c7b8959926949b4ddfa4030c024402dd9d726a3f..0daf0b962060e9c9fc40d101d13eab200262c40a 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -491,7 +491,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) { uint32_t ip = taosGetIpFromFqdn(pInfo->nodeFqdn); if (ip == -1) return NULL; - SSyncPeer *pPeer = (SSyncPeer *)calloc(1, sizeof(SSyncPeer)); + SSyncPeer *pPeer = calloc(1, sizeof(SSyncPeer)); if (pPeer == NULL) return NULL; pPeer->nodeId = pInfo->nodeId; @@ -499,7 +499,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) { pPeer->ip = ip; pPeer->port = pInfo->nodePort; pPeer->fqdn[sizeof(pPeer->fqdn) - 1] = 0; - snprintf(pPeer->id, sizeof(pPeer->id), "vgId:%d peer:%s:%d", pNode->vgId, pPeer->fqdn, pPeer->port); + snprintf(pPeer->id, sizeof(pPeer->id), "vgId:%d peer:%s:%u", pNode->vgId, pPeer->fqdn, pPeer->port); pPeer->peerFd = -1; pPeer->syncFd = -1; diff --git a/src/sync/test/syncServer.c b/src/sync/test/syncServer.c index aa07779845bfaea3195a05b91a0ee75b9946f2a7..380b971fa89bd1726e138c973a974bc995500693 100644 --- a/src/sync/test/syncServer.c +++ b/src/sync/test/syncServer.c @@ -109,7 +109,6 @@ int processRpcMsg(void *item) { if (pCfg->quorum <= 1) { rpcFreeCont(pMsg->pCont); - taosFreeQitem(item); SRpcMsg rpcMsg = {0}; rpcMsg.pCont = rpcMallocCont(msgSize); @@ -117,6 +116,7 @@ int processRpcMsg(void *item) { rpcMsg.handle = pMsg->handle; rpcMsg.code = code; rpcSendResponse(&rpcMsg); + taosFreeQitem(item); } return code; diff --git a/src/util/inc/tscompression.h b/src/util/inc/tscompression.h index 37d1e7b5909cf68f4dc7a25803f94442dc2cf7b0..cca6d6e25054e7736ea28590fa4cb5ab788d6b07 100644 --- a/src/util/inc/tscompression.h +++ b/src/util/inc/tscompression.h @@ -26,7 +26,7 @@ extern "C" { #define COMP_OVERFLOW_BYTES 2 #define BITS_PER_BYTE 8 // Masks -#define INT64MASK(_x) ((1ul << _x) - 1) +#define INT64MASK(_x) ((((uint64_t)1) << _x) - 1) #define INT32MASK(_x) (((uint32_t)1 << _x) - 1) #define INT8MASK(_x) (((uint8_t)1 << _x) - 1) // Compression algorithm diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index a90c1b171c2c492a029ec0b56810518de1532f51..1cdf34930bbd36769fc703c075588340de266d2d 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -385,9 +385,10 @@ static void walRelease(SWal *pWal) { static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) { char *name = pWal->name; + int size = 1024 * 1024; // default 1M buffer size terrno = 0; - char *buffer = malloc(1024000); // size for one record + char *buffer = malloc(size); if (buffer == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; @@ -395,7 +396,7 @@ static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) { SWalHead *pHead = (SWalHead *)buffer; - int fd = open(name, O_RDONLY); + int fd = open(name, O_RDWR); if (fd < 0) { wError("wal:%s, failed to open for restore(%s)", name, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); @@ -405,29 +406,58 @@ static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) { wDebug("wal:%s, start to restore", name); + size_t offset = 0; while (1) { int ret = taosTRead(fd, pHead, sizeof(SWalHead)); - if ( ret == 0) break; + if (ret == 0) break; - if (ret != sizeof(SWalHead)) { - wWarn("wal:%s, failed to read head, skip, ret:%d(%s)", name, ret, strerror(errno)); + if (ret < 0) { + wError("wal:%s, failed to read wal head part since %s", name, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); break; } + if (ret < sizeof(SWalHead)) { + wError("wal:%s, failed to read head, ret:%d, skip the rest of file", name, ret); + taosFtruncate(fd, offset); + fsync(fd); + break; + } + if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) { wWarn("wal:%s, cksum is messed up, skip the rest of file", name); - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + ASSERT(false); break; - } + } + + if (pHead->len > size - sizeof(SWalHead)) { + size = sizeof(SWalHead) + pHead->len; + buffer = realloc(buffer, size); + if (buffer == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + break; + } + + pHead = (SWalHead *)buffer; + } ret = taosTRead(fd, pHead->cont, pHead->len); - if ( ret != pHead->len) { - wWarn("wal:%s, failed to read body, skip, len:%d ret:%d", name, pHead->len, ret); + if (ret < 0) { + wError("wal:%s failed to read wal body part since %s", name, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); break; } + if (ret < pHead->len) { + wError("wal:%s, failed to read body, len:%d ret:%d, skip the rest of file", name, pHead->len, ret); + taosFtruncate(fd, offset); + fsync(fd); + break; + } + + offset = offset + sizeof(SWalHead) + pHead->len; + if (pWal->keep) pWal->version = pHead->version; (*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL); } diff --git a/tests/pytest/query/queryInterval.py b/tests/pytest/query/queryInterval.py index db2c3fdeec3370779d1452e8a3875e3149f57bee..99222016048f71ae66768665fb70522d466b248b 100644 --- a/tests/pytest/query/queryInterval.py +++ b/tests/pytest/query/queryInterval.py @@ -23,35 +23,39 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) - self.ts = 1538548685000 + self.ts = 1593548685000 def run(self): tdSql.prepare() tdSql.execute("create table st (ts timestamp, voltage int) tags (loc nchar(30))") - tdSql.execute("insert into t0 using st tags('beijing') values(now, 220) (now - 15d, 221) (now - 30d, 225) (now - 35d, 228) (now - 45d, 222)") - tdSql.execute("insert into t1 using st tags('shanghai') values(now, 220) (now - 60d, 221) (now - 50d, 225) (now - 40d, 228) (now - 20d, 222)") + tdSql.execute("insert into t0 using st tags('beijing') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)" + % (self.ts, self.ts + 1000000000, self.ts + 2000000000, self.ts + 3000000000, self.ts + 6000000000)) + tdSql.execute("insert into t1 using st tags('shanghai') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)" + % (self.ts, self.ts + 2000000000, self.ts + 4000000000, self.ts + 5000000000, self.ts + 7000000000)) tdSql.query("select avg(voltage) from st interval(1n)") tdSql.checkRows(3) - tdSql.checkData(0, 1, 223.0) - tdSql.checkData(1, 1, 225.0) - tdSql.checkData(2, 1, 220.333333) + tdSql.checkData(0, 1, 221.4) + tdSql.checkData(1, 1, 227.0) + tdSql.checkData(2, 1, 222.0) tdSql.query("select avg(voltage) from st interval(1n, 15d)") - tdSql.checkRows(3) - tdSql.checkData(0, 1, 224.8) - tdSql.checkData(1, 1, 222.666666) - tdSql.checkData(2, 1, 220.0) + tdSql.checkRows(4) + tdSql.checkData(0, 1, 220.333333) + tdSql.checkData(1, 1, 224.666666) + tdSql.checkData(2, 1, 225.0) + tdSql.checkData(3, 1, 222.0) tdSql.query("select avg(voltage) from st interval(1n, 15d) group by loc") - tdSql.checkRows(6) - tdSql.checkData(0, 1, 225.0) - tdSql.checkData(1, 1, 223.0) - tdSql.checkData(2, 1, 220.0) - tdSql.checkData(3, 1, 224.666666) - tdSql.checkData(4, 1, 222.0) - tdSql.checkData(5, 1, 220.0) + tdSql.checkRows(7) + tdSql.checkData(0, 1, 220.5) + tdSql.checkData(1, 1, 226.5) + tdSql.checkData(2, 1, 222.0) + tdSql.checkData(3, 1, 220.0) + tdSql.checkData(4, 1, 221.0) + tdSql.checkData(5, 1, 226.5) + tdSql.checkData(6, 1, 222.0) def stop(self): tdSql.close() diff --git a/tests/script/general/parser/first_last_query.sim b/tests/script/general/parser/first_last_query.sim index 8127c1923015e130a85a98a50cd8d4bca23fedb3..d43cd528781cb900f239e4e7549da91ace2d0e5c 100644 --- a/tests/script/general/parser/first_last_query.sim +++ b/tests/script/general/parser/first_last_query.sim @@ -14,12 +14,14 @@ $i = 0 $db = $dbPrefix . $i $stb = $stbPrefix . $i +print use $db sql use $db ##### select first/last from table ## TBASE-331 print ====== select first/last from table $tb = $tbPrefix . 0 +print select first(*) from $tb sql select first(*) from $tb if $rows != 1 then return -1 @@ -58,6 +60,7 @@ if $data09 != NCHAR then return -1 endi +print select last(*) from $tb sql select last(*) from $tb if $rows != 1 then return -1 diff --git a/tests/script/general/parser/where.sim b/tests/script/general/parser/where.sim index bfbeddf93a1c5f3d80598f9df96c8761608de659..e609dda652304846081c28a43ed6745be3806eb3 100644 --- a/tests/script/general/parser/where.sim +++ b/tests/script/general/parser/where.sim @@ -94,7 +94,11 @@ endi ## select specified columns +print select c1 from $mt sql select c1 from $mt + +print rows $rows +print totalNum $totalNum if $rows != $totalNum then return -1 endi diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 000d36c17865630a0fa0557a50724e352a8ce1b0..977ef452ab4836aadba330634d9183fc9414b080 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -303,8 +303,8 @@ cd ../../../debug; make ./test.sh -f unique/mnode/mgmt22.sim ./test.sh -f unique/mnode/mgmt23.sim ./test.sh -f unique/mnode/mgmt24.sim -#./test.sh -f unique/mnode/mgmt25.sim -#./test.sh -f unique/mnode/mgmt26.sim +./test.sh -f unique/mnode/mgmt25.sim +./test.sh -f unique/mnode/mgmt26.sim ./test.sh -f unique/mnode/mgmt33.sim ./test.sh -f unique/mnode/mgmt34.sim ./test.sh -f unique/mnode/mgmtr2.sim diff --git a/tests/script/unique/mnode/mgmt23.sim b/tests/script/unique/mnode/mgmt23.sim index 7e60ab908b81dd0ad88e550b4b487123e8204b2d..485187286059289f67ab0c82241b049c71f68230 100644 --- a/tests/script/unique/mnode/mgmt23.sim +++ b/tests/script/unique/mnode/mgmt23.sim @@ -65,7 +65,7 @@ endi print ============== step4 sql drop dnode $hostname2 -sleep 8000 +sleep 16000 sql show mnodes $dnode1Role = $data2_1 diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 4bb0cbe86f2186a7a94ee256822935296721d00a..7f786dfaa9de5f6a93d3a181ddd53e37e8694310 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -739,36 +739,22 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ((((int)(*((char *)row[i]))) == 1) ? "1" : "0")); break; case TSDB_DATA_TYPE_TINYINT: - sprintf(value, "%d", (int)(*((char *)row[i]))); + sprintf(value, "%d", *((int8_t *)row[i])); break; case TSDB_DATA_TYPE_SMALLINT: - sprintf(value, "%d", (int)(*((short *)row[i]))); + sprintf(value, "%d", *((int16_t *)row[i])); break; case TSDB_DATA_TYPE_INT: - sprintf(value, "%d", *((int *)row[i])); + sprintf(value, "%d", *((int32_t *)row[i])); break; case TSDB_DATA_TYPE_BIGINT: sprintf(value, "%" PRId64, *((int64_t *)row[i])); break; - case TSDB_DATA_TYPE_FLOAT:{ -#ifdef _TD_ARM_32 - float fv = 0; - *(int32_t*)(&fv) = *(int32_t*)row[i]; - sprintf(value, "%.5f", fv); -#else - sprintf(value, "%.5f", *((float *)row[i])); -#endif - } + case TSDB_DATA_TYPE_FLOAT: + sprintf(value, "%.5f", GET_FLOAT_VAL(row[i])); break; - case TSDB_DATA_TYPE_DOUBLE: { -#ifdef _TD_ARM_32 - double dv = 0; - *(int64_t*)(&dv) = *(int64_t*)row[i]; - sprintf(value, "%.9lf", dv); -#else - sprintf(value, "%.9lf", *((double *)row[i])); -#endif - } + case TSDB_DATA_TYPE_DOUBLE: + sprintf(value, "%.9lf", GET_DOUBLE_VAL(row[i])); break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: